Skip to content

fix(ai-vault): release retired search write fences - #20986

Merged
OrcaWin merged 4 commits into
mainfrom
np-oom-scan-search-write-fences
Sep 18, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
np-oom-scan-search-write-fences

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​226 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​234 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​219

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

  • 59 writer/consumer tests pass, including deletion before/after chunk commits, incomplete reads, throwing error reporters, replacement generations, and close.
  • Actual production writer with real SQLite: 1,000 complete index/retire cycles retain 1,000 paths before and zero after. Both versions reject a stale commit after a never-indexed source is removed.
  • Independent lifecycle review, full desktop typecheck, lint and formatting pass.
  • Reproduction and source hashes: 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.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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 03bb5

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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, Visua… 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, compatibil…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: releasing retired search write fences.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one optional nitpick below.

Reviewed changes

  • Fence lifetime replaces the removal counter — activeWrites now tracks { removed, readers } per path only while reads are open; removeFile marks and evicts the live lifetime, discard() releases the last reader, and current() checks lifetime.removed.
  • Every consumer exit releases its fence — message() discards before reporting a failed add, and finish() discards in a finally, so an incomplete read or a throwing error reporter cannot leak a lifetime.
  • Store close shuts the writer first — SessionSearchStore.close() calls writer.close() before db.close(), refusing new writes and invalidating in-flight ones.
  • Regression coverage — the new session-search-write-lifetime.test.ts plus the writer/consumer tests pin removal before and after chunk commits, concurrent reads, new-generation protection, idempotent discard, throwing reporters, and close; the follow-up commit swaps hand-rolled stubs for vi.spyOn checked 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 future git add docs/audits from a clean checkout silently skips them; adding !docs/audits/ and !docs/audits/** keeps the audit (and any later docs/audits/ subdirectory) reproducible.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 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 win

Await indexing work before closing the search database. SessionSearchIndexer.close() calls SessionSearchWorkLoop.close() and then SessionSearchStore.close() without awaiting loop.settled. The loop aborts the active controller but does not wait for parseAgentSessionFileCached(). TranscriptMessageChannel.beginRead() retains the SessionSearchIndexConsumer for the active read after unregister(), so finish() can run after SyncDatabase.close(). finish() can then reach SessionSearchStore.setFileState() on the closed node:sqlite handle, report the invalid-state error through onError, and leave that read uncommitted. Make SessionSearchIndexer.close() await loop.settled before 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0327063 and 03bb5c6.

📒 Files selected for processing (2)
  • src/main/ai-vault-search/session-search-index-consumer.ts
  • src/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.

@OrcaWin
OrcaWin merged commit a037180 into main Sep 18, 2026
28 checks passed
nplez1 added a commit to nplez1/orca that referenced this pull request Sep 18, 2026
…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.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
* 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]>
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