Repository navigation
fix(session-search): try phrase and AND routes for prose queries before OR - #20754
Conversation
…re OR An exact sentence pasted out of a transcript was not returned. The route ladder only ran the phrase and AND rungs for a literal-looking query, so prose fell straight to OR, where the sentence's common words filled the candidate limit with recent sessions and the old session holding the sentence never reached ranking. The planner now carries a `phrase` candidate: the query's tokens in order with stop words kept, which is what the sentence is actually indexed as. The ladder runs phrase then AND over those tokens for every query of two or more tokens. A one-token query still takes the rung only when it looked literal. `incomplete` is reported by the rung that answered rather than accumulated across every rung tried.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe query planner now preserves all query-order tokens in Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The updated typo-repair path retains phrase matching behavior without an identified merge-blocking risk. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the bug, root cause, implementation, tests, performance impact, and verification results. However, it omits several required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Restructure the description to include all required template sections. Add a valid linked issue after “Fixes #”. Add Visual Proof with ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 98d20b33-b2d4-40c5-b791-cb282d5d2599
📒 Files selected for processing (5)
docs/reference/agent-session-search-query-tuning.mdsrc/main/ai-vault-search/session-search-engine.test.tssrc/main/ai-vault-search/session-search-query-planner.test.tssrc/main/ai-vault-search/session-search-query-planner.tssrc/main/ai-vault-search/session-search-retrieval.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Planner keeps the query as typed.
SessionSearchQueryPlan.phraseholds the query-order tokens with stop words retained, capped atMAX_BODY_TERMSvia the existingrawslice;bodyis unchanged, so a literal'sphraseandbodyare identical and literal retrieval is untouched. - Ladder runs phrase/AND for prose.
literal()becomesphraseThenAnd()and gates on token count rather thanplan.literal, so every two-or-more-token query tries phrase then AND overplan.phrase; a single-token prose query still goes straight to OR. - Truncation is per rung.
incomplete ||=becomes an assignment insidematch, so the notice describes the rung whose rows were returned; docs updated to match. - Tests cover the planner's stop-word retention and quoted expression, and the engine's 650-session scenario (phrase route first,
truncated.candidatesfalse vs true, prose falling to AND, single word staying on OR).
I verified the load-bearing reasoning rather than taking the description on faith: the ladder's superset ordering holds at the raw-row level (phrase ⊆ AND ⊆ OR), so a discarded cap-filling rung is always followed by one that also fills it — the new incomplete assignment is equivalent-or-more-accurate, and it reads the pre-eligibility row count so operator filters still report the cap. The repair branch re-tokenizes body.join(' '), so its phrase is stop-word-stripped exactly as the old body-based phrase was. The FTS schema uses unicode61 tokenchars '_.-/+' with no stopword list, confirming stop words are indexed, and the route vocabulary in the wire contract is unchanged, so there is no remote-wire impact.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
A phrase hit was highlighted with the OR expression over the stop-word stripped terms, so an exact sentence rendered as scattered bold words with its stop words plain. The snippet now uses the expression the route matched by: one run for a phrase, every typed word for AND, the terms for OR.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Rebuild repaired prose queries from the full token sequence. · src/main/ai-vault-search/session-search-retrieval.ts:199-205
199-205: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRebuild repaired prose queries from the full token sequence. After the initial
phraseThenAndattempt,SessionSearchRetrieval.runrepairsplan.body, which excludes prose stop words. The repairedphraseThenAndthen uses that shortened sequence for both phrase and AND searches. The phrase search cannot match the original sentence, and the broader AND search can return a capped result set that excludes the intended sentence.Rebuild the repaired plan from the original full token sequence and replace only corrected spellings. This is separate from the initial unrepaired phrase/AND retrieval.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 644ef2d5-a802-46c1-bd10-93aa3f6bd175
📒 Files selected for processing (5)
src/main/ai-vault-search/session-search-engine.test.tssrc/main/ai-vault-search/session-search-engine.tssrc/main/ai-vault-search/session-search-orphan-rows.test.tssrc/main/ai-vault-search/session-search-snippet-marks.test.tssrc/main/ai-vault-search/session-search-snippet.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/ai-vault-search/session-search-engine.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Snippet marking follows the retrieving route.
sessionSearchSnippetnow takesretrieved.routeand picks its FTS expression through a newrouteExpressionhelper: a*phraseroute marks one contiguous run overplan.phrase, a*androute marks every typed token, and theor/typo+orroutes keeporExpression(plan.terms). Previously every hit was marked with the plan's OR form, so an exact phrase rendered as scattered bold words and an AND hit left stop words plain. - Row typing. The pre-existing
as Record<string, string> | undefinedcast on the snippet row is replaced with anisSnippetRowtype guard. - Tests. Two new snippet cases pin a phrase hit rendering as a single
[[...]]run with stop words included, and an AND hit marking each typed word, both driven through the engine.
I traced the snippet expression against retrieval for all six routes rather than assuming consistency: un-repaired phrase/and use the original plan's phrase, the typo+ variants use the effective (repaired) plan's phrase, and both OR routes fall through to plan.terms — identical to what retrieval matched each row with, so the snippet re-query always matches and a previously-empty snippet cannot regress. The stricter isSnippetRow guard is safe because FTS columns are always inserted as strings ('' for non-matching roles) and the existing identifier-only fallback test already exercises columns with no match. pnpm test src/main/ai-vault-search is green (511 tests) and pnpm run typecheck:node exits clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…words Typo repair re-planned the query from `plan.body`, which prose has already had its stop words removed from. `relay is droppng frames` therefore came back as the plan for `relay dropping frames`, and the phrase rung searched for a sentence nobody wrote: the transcript holds `relay is dropping frames`, so the exact match fell through to AND. The repair now maps over `plan.phrase`, the tokens as typed, and re-plans from those. Only terms the body holds are offered to the corrector, so a stop word is still never repaired, and the re-plan recomputes the body from the corrected sentence exactly as before.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Repaired prose phrases keep their stop words.
repair()insession-search-retrieval.tsnow maps overplan.phraseinstead ofplan.body, offering a token to the typo corrector only when its lowercase is inplan.body, then re-plans from the corrected phrase.relay is droppng framestherefore answers ontypo+phraseover the sentence actually indexed, instead of re-planning torelay dropping framesand falling to AND. - Regression test.
session-search-engine.test.tsaddskeeps the stop words a repaired prose phrase was typed with; I confirmed it fails on the parent commit withexpected 'typo+and' to be 'typo+phrase'.
This addresses the one actionable CodeRabbit thread (repair re-planning from the stop-word-stripped body), which is now marked resolved. The literal path is unchanged (body === phrase, so every token remains repairable), and only body terms are corrected, so stop words are still never repaired. pnpm test src/main/ai-vault-search is green (43 files, 512 tests) and pnpm tc:node exits clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, stablyai#20986), so that layer is now upstream's: `searchAllExecutionHosts` over `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…re OR (stablyai#20754) * fix(session-search): try phrase and AND routes for prose queries before OR An exact sentence pasted out of a transcript was not returned. The route ladder only ran the phrase and AND rungs for a literal-looking query, so prose fell straight to OR, where the sentence's common words filled the candidate limit with recent sessions and the old session holding the sentence never reached ranking. The planner now carries a `phrase` candidate: the query's tokens in order with stop words kept, which is what the sentence is actually indexed as. The ladder runs phrase then AND over those tokens for every query of two or more tokens. A one-token query still takes the rung only when it looked literal. `incomplete` is reported by the rung that answered rather than accumulated across every rung tried. * fix(session-search): mark a snippet with the route that retrieved it A phrase hit was highlighted with the OR expression over the stop-word stripped terms, so an exact sentence rendered as scattered bold words with its stop words plain. The snippet now uses the expression the route matched by: one run for a phrase, every typed word for AND, the terms for OR. * fix(session-search): repair a prose phrase without dropping its stop words Typo repair re-planned the query from `plan.body`, which prose has already had its stop words removed from. `relay is droppng frames` therefore came back as the plan for `relay dropping frames`, and the phrase rung searched for a sentence nobody wrote: the transcript holds `relay is dropping frames`, so the exact match fell through to AND. The repair now maps over `plan.phrase`, the tokens as typed, and re-plans from those. Only terms the body holds are offered to the corrector, so a stop word is still never repaired, and the re-plan recomputes the body from the corrected sentence exactly as before.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.
…on index Agent Session History was a filesystem walk plus a parse of every transcript it found, so one load cost O(corpus) in readdirs, stats and reads on every scan. The index already holds one row per session with everything a row renders, so a list is now one indexed read. The scanner stays as the fallback for a host where no pass has completed or `node:sqlite` is absent, and it now applies the same plain-text query the index would, because an unfiltered answer would read as "everything matches". Search gains a metadata tier: - Metadata (a `sessions` row plus `sessions_fts` over titles, working directories, branches and agent names) is always indexed and answers with `evidence: null` — there is no transcript text to quote and none is fabricated. Content (`messages`, `messages_fts`) stays opt-in. The pre-tier `enabled` flag named that same consent, so a profile that recorded it keeps it as `contentEnabled` rather than having the question silently re-opened, and `status.enabled` now means only that an index exists and runs. The index writer takes that consent as `storeContent`, so a metadata-only index stores no message rows at all rather than storing and hiding them, and drops the `sessions_fts` row wherever it drops the session row. The scanner service protocol grows `refresh` and `query` so a host can answer the panel's list itself; both sides call `aiVaultHostListQuery`, so what the client sends and what the host accepts cannot drift. Remote scanning gains a Copilot source that walks a session directory without descending into the artifact trees beside `events.jsonl`, which hold no sessions and cost a readdir each. Rebased onto upstream 2026-09-18. Upstream landed its own all-computers search merge in these same files (stablyai#20582, stablyai#20753, stablyai#20754, stablyai#20870, stablyai#20886, stablyai#20887, `SessionSearchHostLeg`s, walking each host page by page and merging on recency and round-robin ranking with an encoded merged cursor. This commit's own fan-out was dropped rather than left to diverge with it — `ai-vault-search-all-hosts.ts`, `-host-fanout.ts` and their tests now follow upstream, and the fork's `ai-vault-search-merged-order.ts`, `ai-vault-search-status-aggregation.ts`, `session-search-rank-fusion.ts` and their tests are gone. What survives is what upstream has no equivalent of: the metadata FTS tier, the indexed list, the service `query`/`refresh` protocol, and the Copilot source. `contentEnabled` stays as an additive, optional status field. Re-porting per-host status vocabularies and reciprocal-rank fusion onto upstream's engine is deliberately left open, not lost. Wire compatibility: `contentEnabled` is additive and optional, so an older peer ignores it, and a host that predates the list `query` answers the scan request it already understood. See docs/reference/agent-session-search-contract.md and docs/reference/remote-wire-compatibility.md.

Bug
Paste an exact sentence an agent said a month ago, for example
The sol review says the PR is not quite merge-ready yet, but not because of the implementation.The session is indexed, the words are all there, and the search comes back
without it. The panel shows the "results were limited" notice on top.
Root cause
Two things in
src/main/ai-vault-search/, and both had to hold for the sentenceto go missing.
The route ladder in
session-search-retrieval.tsonly ran the phrase and ANDrungs when
plan.literalwas true, andisLiteralQueryis true foridentifier-shaped or code-shaped input, not for prose. An ordinary sentence went
to typo repair and then to the OR rung. OR retrieval is capped at
candidateLimit(600) sessions ordered by score or recency, so the sentence'scommon words filled the cap and the old session never reached ranking. The cap
filling is also what set
incomplete, which is the notice the panel showed.Even a phrase built for prose would have missed, because the planner strips stop
words from
body."sol review says PR quite merge-ready"is not adjacent inany transcript. The FTS tokenizer (
unicode61) indexes stop words, so thephrase has to keep them.
Fix
Planner (
session-search-query-planner.ts). A newphrasefield on theplan: the query's tokens in order, exactly as typed, stop words kept, capped at
MAX_BODY_TERMSlikebody.bodyis unchanged, so the OR fallback stilldrops stop words. For a literal query the two lists are identical, so nothing
about literal retrieval moves.
Ladder (
session-search-retrieval.ts).literalbecomesphraseThenAndand runs for every query of two or more tokens, literal or not, over
plan.phrase. A phrase or AND hit returns immediately withroute: 'phrase'or
'and'as before. A one-token query still takes the rung only when it lookedliteral, so a single prose word goes straight to OR. Escaping is unchanged:
phraseExpressionalready quotes the joined tokens throughquoteFtsTerm.Truncation.
incompleteis assigned per rung rather than accumulated with||=, so it describes the rung whose rows the page was built from. Each rungmatches a superset of the one before it, so a rung that filled its cap with no
eligible sessions is still followed by one that fills it too, and a genuinely
full candidate set stays explicit.
docs/reference/agent-session-search-query-tuning.mdis updated where it described the old accumulation.
repairedTermsandroutereporting are untouched; the repaired plan goesthrough the same rung, so a repaired prose query can now answer on
typo+phraseinstead of walking OR.Tests
session-search-query-planner.test.tsphrasekeeps the stop wordsbodydropsphraseequalsbodyfor a literalsession-search-engine.test.ts, with 650 recent sessions carrying thesentence's common words and one older session carrying the sentence
truncated.candidatesis false when the phrase rung answered, and still truefor a query that really did fill the cap
Verified as a regression test: with the
!plan.literalgate put back, the threeengine cases fail with
expected 'or' to be 'phrase',expected true to be false, andexpected 'or' to be 'and'.Numbers
config/scripts/session-search-query-benchmark.tsover the 40-transcript,10.5 MB, 9,600-message synthetic corpus. Four runs each side, median of the
per-query p50. The machine was running other work, and the run-to-run drift is
large enough to swamp the effect, so the second table normalises each query
against the same run's
common-termp50, which is a single prose token andcannot gain a rung.
Scope
all, p50 ms, median of 4:"terminal reattach"resolveTerminalPathNormalised to the same run's
common-termp50:allconversationallconversation"terminal reattach"allresolveTerminalPathallThe worst case is a prose query where both new rungs miss and OR answers
anyway: the benchmark's
why is the daemon snapshot stale, at 1.35x to 1.44x ofthe baseline query in
alland 1.43x to 1.50x inconversation. That is abouthalf a millisecond on a nine-millisecond query, and it is the same size as the
movement on the two literal queries whose code path this PR does not touch, so
it sits inside the harness's noise. Two FTS queries that match nothing are
cheap. The typo query moved for a real reason: the repaired plan now answers on
the phrase rung instead of walking OR.
The route change is visible in the benchmark's own report: the typo query goes
from
typo+ortotypo+phrase, and every other query keeps its route.Gates
Snippet highlight (second commit)
A phrase hit was highlighted with the OR expression over the stop-word stripped terms, so an exact sentence rendered as scattered bold words with "the", "has", "for" left plain.
sessionSearchSnippetnow takes the route and marks with the expression that retrieved the row: one contiguous run for a phrase, every typed word for AND, the terms for OR. The pre-existing row cast in that file is replaced with a type guard. Two snippet tests pin the phrase run and the AND words.