fix(mcp): hint regex=true when codedb_search query has regex metachars#296
Merged
fix(mcp): hint regex=true when codedb_search query has regex metachars#296
Conversation
Issues #290 and #292 reported that running codedb_search with queries like "test-case" (#290) or "timestamp|activity|filter" (#292) crashed the MCP server on codedb 0.2.571 when used from opencode. After the 0.16 migration + perf passes (0.2.572 → 0.2.578) the crash is no longer reproducible against the current main from either CLI or a direct MCP JSON-RPC tools/call invocation. This commit does two things: 1. Add regression tests at the Explorer level that exercise the non-regex search path with both the hyphen and pipe queries from the reports. They exist to catch any future regression that reintroduces the crash. 2. Address the actual UX gap behind #292: when query contains regex metachars (|, parens, brackets, ?+*, ^, $) and regex=false, the search runs as a literal substring match and quietly returns nothing, instead of suggesting that the caller may want regex=true. Replace the generic scope=true guidance with a targeted hint in that case so agents like Kimi K2.5 get steered toward the right argument. Tests: - zig build test → 393/393 pass (388 baseline + 5 new) - issue-290: searchContent with hyphen query does not crash - issue-292: searchContent with pipe query does not crash - issue-292: codedb_search guidance hints regex=true on metachar query - issue-292: codedb_search guidance does not warn when regex=true is set - issue-290: codedb_search guidance does not warn on plain hyphen Closes #290 Closes #292 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Benchmark Regression ReportThreshold: 10.00%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #290 and #292.
Both were reported against codedb 0.2.571. After the 0.16 migration + perf passes (0.2.572 → 0.2.578) I could not reproduce the server-level crash from either the CLI or a direct MCP JSON-RPC
tools/callinvocation against a real repo. Rather than chase a crash that no longer reproduces on current main, this PR does two things:Regression tests. Add
Explorer-level tests at src/tests.zig:6817 that run the two offending queries (test-caseandtimestamp|activity|filter) throughsearchContentwithregex=false. They lock in the current non-crashing behavior so any future regression fails CI immediately.Address the actual UX gap behind Critical Bug: Running codedb_search with "|" operator without regex=true crashes MCP server #292. When
querycontains regex metachars (|, parens, brackets,?+*,^,$) andregex=false, the search quietly runs as a literal substring match and returns nothing — exactly the failure mode the reporter described ("the expected behaviour should be it returns the result but sends a friendly reminder that if it wants to actually do an OR search it must set regex=true"). Swap the genericscope=trueguidance for a targeted hint in that case so callers get steered towardregex=true.Implementation: src/mcp.zig:2394 —
mcpGenerateGuidancegets a small metachar check before the existingscope=truenudge.Test plan
zig build test— 393/393 pass (388 baseline + 5 new)issue-290: searchContent with hyphen query does not crashissue-292: searchContent with pipe query does not crashissue-292: codedb_search guidance hints regex=true on metachar queryissue-292: codedb_search guidance does not warn when regex=true is setissue-290: codedb_search guidance does not warn on plain hyphenecho '{...tools/call codedb_search query=timestamp|activity|filter}' | codedb mcpcompletes cleanly.🤖 Generated with Claude Code