fix(grep): send synonym alternations to the embedding daemon - #446
eastagiletracker wants to merge 1 commit into
Conversation
patternIsSemanticFriendly counted `|` as a regex metacharacter, so any pattern with two or more alternatives (`data loss|concurrent writer|race condition`) was rejected and grep fell back to lexical-only search, even though a list of synonyms is the case embeddings answer best. Stop counting `|` toward the metachar limit in both the pre-tool-use fast path (grep-direct) and the virtual shell interceptor, and cap the number of alternatives at 8 so a pathological many-clause pattern still goes lexical. Patterns with more than one other metachar are unchanged.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: activeloopai/hivemind/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughBoth grep paths now allow semantic embedding for patterns with up to eight pipe-separated alternatives, subject to the existing short-pattern and metacharacter checks. Tests cover alternation limits and embedding behavior. ChangesSemantic grep eligibility
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change enables semantic search for bounded synonym patterns. No issue identified here requires resolution before merge. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Bounded synonym searches can now return semantically related records. With the default semantic-output behavior, even a filename-only or count-only search can return record text. The searches remain scoped to requested paths, but this wider exposure merits design review. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This PR proposes sending synonym alternations like
data loss|concurrent writer|race conditionto the embedding daemon instead of falling back to lexical-only grep (Fixes #86). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/747. You can sign in with your GitHub ID to claim ownership of the project.What changed
patternIsSemanticFriendlycounted|as a regex metacharacter and rejected any pattern with more than one, so a grep with two or more alternatives never reachedEmbedClient.embed()andsearchDeeplakeTablesran the lexicalLIKE/ILIKEbranch only. A list of synonyms is exactly the query semantic recall is meant to answer, so paraphrase matches were being lost. This follows the fix proposed in #86:|no longer counts toward the metacharacter limit, patterns with more than one other metacharacter (e.g.(foo|bar)\+) are still skipped, and alternations are capped at 8 alternatives so a many-clause pattern still goes lexical. The change is applied to both copies of the function,src/hooks/grep-direct.ts(the grep fast path used by the pre-tool-use hooks) andsrc/shell/grep-interceptor.ts(the virtual shell), and keeps the two in sync. No version bump is included, so you can decide whether it goes into a release.Reproduction at current
main(e054fb1): a vitest case with the embed client stubbed callshandleGrepDirect(api, "memory", "sessions", { pattern: "silent data loss|concurrent writer|race condition", ... })and gets 0embed()calls, with no<#>operator in the generated SQL (lexical-only).Verification:
npx vitest runbefore and after the change gives the same failure set (4 tests that also fail on a cleanmainin this environment:embeddings-clientwarmup auto-spawn, twoplugin-cachermSync/rename cases, andspawn-detachedreal-process; all spawn or filesystem permission related, none touch grep). After: 5861 passed, the 9 new tests included.tsc --noEmitandjscpd srcare clean. New tests: a newgrep-direct-semantic.test.tscovershandleGrepDirect(alternation embeds and produces the hybrid<#>query, the 8-alternative limit on both sides, regex-heavy patterns containing|still skip, patterns shorter than 2 characters still skip), andgrep-interceptor.test.tsgains the same cases for the shell interceptor. With the source change reverted, the 4 alternation-embedding tests fail and the skip cases stay green.How this was managed
This work was tracked as https://eastagiletracker.com/projects/747/stories/776572 on https://eastagiletracker.com/projects/747, a board imported from this repo's issues and pull requests (425 stories) and used to manage this change.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com
Summary by CodeRabbit