Skip to content

fix(#682): harden callers comment scanning edge cases - #684

Merged
justrach merged 8 commits into
release/0.2.5833-mcp2026from
fix/issue-682-comment-edge-cases
Aug 5, 2026
Merged

fix(#682): harden callers comment scanning edge cases#684
justrach merged 8 commits into
release/0.2.5833-mcp2026from
fix/issue-682-comment-edge-cases

Conversation

@justrach

@justrach justrach commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Closes #682.

What changed

  • replaces the split comment-prefix/string matcher with one allocation-free, language-aware code scan
  • handles PHP and Swift line comments, PHP 8 #[...] attributes, and shell comments after unescaped operators
  • ignores marker-like text in Go/JavaScript backticks, Rust raw strings, regex literals, and complete inline block comments without hiding real calls later on the line
  • preserves calls inside JavaScript ${...} template expressions and R backtick-quoted callable identifiers
  • caps template-expression recursion to bound stack use and worst-case rescanning
  • adds regression coverage for each positive and negative case

Why

  • Problem/failure mode: Post-merge review of fix(#682): callers stops counting trailing-comment mentions as call sites #683 found that lineCodePrefix could drop genuine callers after https:// in Go raw strings or JavaScript templates, while PHP/Swift trailing comments were still reported. A first follow-up exposed a second failure mode: skipping those spans only in the prefix pass could re-admit names that existed solely inside literals/comments.
  • Reason for this approach: A single lexical matcher makes span handling consistent: the same scan decides both where comments start and whether a whole-word match is executable code. It stays line-local and allocation-free, matching the existing callers heuristic without introducing parser state into ranked search results.
  • Constraints/trade-offs: Search results contain isolated lines, so comments or literals opened on prior lines remain intentionally out of scope. JavaScript template recursion is capped at 16 levels to keep hostile input bounded; deeper nested templates are treated conservatively as literal text. The extra lexical work is linear for ordinary lines and will be checked by the paired 10% benchmark gate.
  • Rejected alternatives: Truncating blindly at /* loses real calls after a closed inline block comment. Treating all backticks as inert loses JavaScript ${renderX()} and R `renderX`(...) calls. Keeping separate prefix and match passes allowed the two scans to disagree and trade false negatives for false positives.

Verification

  • zig build test -Dtest-filter=issue-682
  • zig build test
  • zig build && python3 scripts/e2e_mcp_test.py --binary zig-out/bin/codedb --project "$(pwd)" — 20/20
  • zig build bench

justrach and others added 8 commits August 5, 2026 10:21
Add failing coverage for PHP and Swift trailing comments, shell comments after operators, and real calls following marker-like text in backtick, raw-string, and inline block-comment spans. These cases show why the merged prefix scanner is not yet safe to promote unchanged.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Prevent line-comment markers inside backtick/raw literals and complete inline block comments from truncating away real callers later on the line. Cover PHP and Swift markers, preserve PHP 8 attributes, and recognize shell comments after unescaped operators while keeping parameter-expansion hashes live.

This keeps the scan line-local and allocation-free, preserving the existing conservative behavior for block-comment mentions while removing regressions introduced by the initial trailing-comment filter.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Cover negative-only raw, backtick, and inline block-comment spans so scanner fixes cannot trade false negatives for false callers. Preserve JavaScript template-expression calls and exercise unquoted shell parameter expansion.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Unify literal and comment handling in the whole-word caller scan so marker-like text cannot hide later code or re-admit mentions from skipped spans. Raw strings, backticks, complete inline block comments, and line comments are scanned allocation-free; JavaScript template text is ignored while ${...} expressions remain searchable.

This replaces the prefix-then-match split that handled the same spans inconsistently and traded false negatives for false positives.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Add failing caller coverage for braces inside JavaScript regex literals, callable R backtick identifiers, and hash-bearing R identifiers before a real call.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Cap recursive JavaScript template analysis to bound stack and worst-case rescanning on hostile single-line input. Skip regex literals while locating interpolation braces, and preserve R backtick identifiers as callable symbols without treating embedded hashes as comments.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Add failing coverage for a symbol appearing only in a JavaScript regex literal after return, where punctuation-only regex context detection scans the pattern as code.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>
Treat regex literals after expression-leading JavaScript keywords such as return, throw, yield, and await as non-code spans, preventing pattern text from becoming false caller matches.

Co-Authored-By: Codegraff <blackfloofie@codegraff.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 154fb86bf6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp.zig
}
return false;
}
if (stringLiteralEnd(line, i)) |end| {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Go raw strings ending in backslash

For Go, raw backtick strings do not use backslash escapes, but this branch uses stringLiteralEnd (which skips \\ plus the next byte) to locate every non-template backtick literal. On a valid Go line like s := `\`; renderX() the closing backtick after the backslash is skipped, so the scanner takes the unclosed-literal path and codedb_callers drops the real call that follows.

Useful? React with 👍 / 👎.

@justrach
justrach merged commit 516d72a into release/0.2.5833-mcp2026 Aug 5, 2026
1 check passed
@justrach
justrach deleted the fix/issue-682-comment-edge-cases branch August 5, 2026 03:01
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.

1 participant