Repository navigation
fix(ai-vault): release retired search write fences - #20986
Conversation
📝 WalkthroughWalkthroughThe session-search writer now tracks active read lifetimes instead of permanent removal counters. It releases fences on commit, discard, failures, removal, and store close, and rejects new writes after closure. The consumer explicitly discards writes on failure and completion. New tests cover lifecycle behavior. Audit scripts and results compare the fix with a pinned baseline. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to During shutdown, an active search read can finish after the database closes, causing an error and leaving that read uncommitted. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, validation, and scope, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue with a Fixes reference, Visual Proof or N/A, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Complete the required template sections. Add the linked issue using the required Fixes # format, provide Visual Proof or state N/A with a reason, document testing platforms and checklist status, and complete the remaining review, compatibility, security, performance, and checklist sections.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
ℹ️ No critical issues — one optional nitpick below.
Reviewed changes
- Fence lifetime replaces the removal counter —
activeWritesnow tracks{ removed, readers }per path only while reads are open;removeFilemarks and evicts the live lifetime,discard()releases the last reader, andcurrent()checkslifetime.removed. - Every consumer exit releases its fence —
message()discards before reporting a failedadd, andfinish()discards in afinally, so an incomplete read or a throwing error reporter cannot leak a lifetime. - Store close shuts the writer first —
SessionSearchStore.close()callswriter.close()beforedb.close(), refusing new writes and invalidating in-flight ones. - Regression coverage — the new
session-search-write-lifetime.test.tsplus the writer/consumer tests pin removal before and after chunk commits, concurrent reads, new-generation protection, idempotentdiscard, throwing reporters, and close; the follow-up commit swaps hand-rolled stubs forvi.spyOnchecked mocks. - Audit artifacts —
docs/audits/session-search-write-fences/reproduces 1,000 index/retire cycles retaining 1,000 path entries before and 0 after.
ℹ️ Nitpicks
docs/audits/**has no allow-list entry in.gitignore. The three new files are tracked only because they were force-added, so a futuregit add docs/auditsfrom a clean checkout silently skips them; adding!docs/audits/and!docs/audits/**keeps the audit (and any laterdocs/audits/subdirectory) reproducible.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Await indexing work before closing the search database. · session-search-store.ts:364
src/main/ai-vault-search/session-search-store.ts:364
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winAwait indexing work before closing the search database.
SessionSearchIndexer.close()callsSessionSearchWorkLoop.close()and thenSessionSearchStore.close()without awaitingloop.settled. The loop aborts the active controller but does not wait forparseAgentSessionFileCached().TranscriptMessageChannel.beginRead()retains theSessionSearchIndexConsumerfor the active read afterunregister(), sofinish()can run afterSyncDatabase.close().finish()can then reachSessionSearchStore.setFileState()on the closednode:sqlitehandle, report the invalid-state error throughonError, and leave that read uncommitted. MakeSessionSearchIndexer.close()awaitloop.settledbefore closing the store, and await that shared close from every owner path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 75ebe171-45ca-4824-82ae-d1a9f6ec1984
📒 Files selected for processing (2)
src/main/ai-vault-search/session-search-index-consumer.tssrc/main/ai-vault-search/session-search-store.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/ai-vault-search/session-search-store.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…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.
* fix(ai-vault): release retired search write fences * test(ai-vault): use checked search writer mocks * test: use typed access in memory retention regressions --------- Co-authored-by: m4air <[email protected]> Co-authored-by: m4air <[email protected]>

Problem and change
The AI Vault search writer keeps a removal counter for every retired transcript path for the scanner process's lifetime. Repeated index/delete cycles therefore retain historical filenames after their database rows and readers are gone.
Track removal fences only while reads are active. Final commit, discard, failed/incomplete consumption, and store close release ownership. Deletion still fences a read opened before its source disappeared; old cleanup cannot remove a newer read's fence. Intermediate chunk commits retain their fence until the read finishes.
Validation
docs/audits/session-search-write-fences/.Existing retry bookkeeping can still recreate a failed file metadata row after removal; deleted sessions/messages remain absent. This preserves that status policy. The writer did not ship in v1.4.198, so this small scanner-child metadata leak is not an explanation for #19831 or #19768.