Skip to content

fix(mcp): hint regex=true when codedb_search query has regex metachars#296

Merged
justrach merged 1 commit intomainfrom
fix/search-regex-meta-hint
Apr 18, 2026
Merged

fix(mcp): hint regex=true when codedb_search query has regex metachars#296
justrach merged 1 commit intomainfrom
fix/search-regex-meta-hint

Conversation

@justrach
Copy link
Copy Markdown
Owner

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/call invocation against a real repo. Rather than chase a crash that no longer reproduces on current main, this PR does two things:

  1. Regression tests. Add Explorer-level tests at src/tests.zig:6817 that run the two offending queries (test-case and timestamp|activity|filter) through searchContent with regex=false. They lock in the current non-crashing behavior so any future regression fails CI immediately.

  2. Address the actual UX gap behind Critical Bug: Running codedb_search with "|" operator without regex=true crashes MCP server #292. When query contains regex metachars (|, parens, brackets, ?+*, ^, $) and regex=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 generic scope=true guidance for a targeted hint in that case so callers get steered toward regex=true.

Implementation: src/mcp.zig:2394mcpGenerateGuidance gets a small metachar check before the existing scope=true nudge.

Test plan

  • zig build test393/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
  • Verified end-to-end: echo '{...tools/call codedb_search query=timestamp|activity|filter}' | codedb mcp completes cleanly.

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 519419 525371 +1.15% OK
codedb_changes 111671 92027 -17.59% OK
codedb_deps 42420 42175 -0.58% OK
codedb_edit 15785 17338 +9.84% OK
codedb_find 80230 81053 +1.03% OK
codedb_hot 128274 132544 +3.33% OK
codedb_outline 302820 323080 +6.69% OK
codedb_read 117040 119321 +1.95% OK
codedb_search 220121 223993 +1.76% OK
codedb_snapshot 3773786 3742071 -0.84% OK
codedb_status 232183 249442 +7.43% OK
codedb_symbol 88874 89681 +0.91% OK
codedb_tree 87719 93747 +6.87% OK
codedb_word 117256 121346 +3.49% OK

@justrach justrach merged commit 1679c15 into main Apr 18, 2026
1 check passed
@justrach justrach deleted the fix/search-regex-meta-hint branch April 18, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Critical Bug: "-" character in codedb_search crashes the mcp server

1 participant