You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(session-history): stop re-reading every transcript after a cache format change or build switch - #41091
Session History keeps a cache of every agent session it has already read, so reopening it should be quick. Two things kept making it slow again. Any update that changed the cache format deleted the whole cache, and so did switching between Orca builds that share a data folder. After that, the next open re-read every transcript (29,000 files for the reporter). Even when nothing had changed, the "Checking N / 29,154" bar sat on screen for seconds while Orca confirmed every file was still cached.
Files
Added
Deleted
Net
Test
2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$78
$\color{#cf222e}{\Huge{\mathbf{−}}}$2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$76
Prod
12
$\color{#1a7f37}{\Huge{\mathbf{+}}}$121
$\color{#cf222e}{\Huge{\mathbf{−}}}$10
$\color{#1a7f37}{\Huge{\mathbf{+}}}$111
What Changed
The cache is kept across format changes and build switches. Each cache format version now has its own file (session-parse-cache.v9.sqlite instead of one shared session-parse-cache.sqlite), so opening a build on another version no longer deletes it.
The first start after this change begins with an empty versioned cache: one full re-read, the same cost as any format change today. Copying the old file over was tried and dropped: on a multi-GB cache it could block the scanner past its request deadline.
On disk, Orca keeps this version and the most recently used other one, and deletes the rest. A file another running build still has open is skipped.
Cached rescans no longer show the "Checking" bar. The scanner now reports how many transcript bytes a scan actually read from disk. Main keeps showing the last finished strip ("Scanned N files ✓"), or nothing, until a scan has read 64 MB. Rescans the cache answers stay quiet, including ones where a few live agents' transcripts grew. Real re-reads still show progress: a cold scan reads hundreds of MB.
A scan that fails or is cancelled before it was ever shown no longer leaves a frozen partial strip behind.
Why
The cache was never per-workspace, contrary to the guess in the report. I ran the real scanner over a 29,000-file history: reopening, switching workspaces and restarting all reused it (0 re-reads, about 1.5 s to re-check every file). The full rescans came from openVersionedCacheDatabase deleting the whole file on any version mismatch, newer or older. The format version was bumped 5 times between Oct 22 and Nov 3, one of them hours before the report. And builds on different versions that share a data folder (dev builds from worktrees on different commits, or a downgrade) wiped each other on every switch.
Alternatives considered:
Skip the per-file check by looking at folder timestamps. Rejected: resumed Codex sessions append to old rollout files, which doesn't change the folder's timestamp.
Show the bar only after the scan has run for a few seconds. Rejected: a 29k-file cached rescan takes 1.5–3 s or more on slower disks, so the bar would still appear. Bytes read measures the work that makes a scan slow.
Carry the old cache over on upgrade (rename, or a SQLite snapshot copy). Rejected: renaming or deleting a SQLite file another build has open breaks that build's writes (review reproduced disk I/O error), and a snapshot copy can block the scanner for seconds on large caches.
Linked Issue
Linear: STA-13607 (no GitHub issue)
Visual Proof
N/A. The strip component itself is unchanged; the change is that it no longer appears during cached rescans. I checked the trigger by running the real scanner on my own history and on a synthetic 29,000-file Codex history, reading the bytes each scan reported against the 64 MB threshold:
Scan
Bytes read
Strip
Cold (no cache)
198 MB – 804 MB
shown
Warm rescan, nothing changed
0 – 395 B
hidden
Warm after restart, 8 live transcripts changed
29 MB
hidden
Testing
Reproduced on main before the fix:
Cache wipe: with main's code, a build on another schema version that shares the folder makes the next scan fully reparse every transcript. Main's isStaleSchema deletes the file on any version mismatch. The new "keeps its rows" test fails on main with fullParses: 1.
Bar on cached rescans: the real scanner on a synthetic 29,000-file Codex history re-checked every file on each warm rescan (about 1.4 s, 0 parses). Main published that whole re-check as the active "Checking N / 29,000" progress. The new quiet-rule test fails on main.
Confirmed after: the same harness on this branch:
Switching builds: after switching workspaces, a restart, or another build's file appearing, the cache was reused with only changed files re-read (7–9 files).
Quiet rule: warm rescans reported 0–395 bytes read, so the strip stayed hidden.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Real scanner runs on macOS, against my own history (5,000 files) and a synthetic 29,000-file Codex history:
New tests, each confirmed to fail with its part of the change reverted:
Version files (session-parse-cache-persistence.test.ts): rows survive another build's file. Pruning keeps one other version plus any version still open.
Quiet rule (ai-vault-local-scan-progress.test.ts): the last finished strip stays until a rescan reads 64 MB.
Focused ai-vault tests and their dependents pass, as do check:code-quality:changed and the main sync-fs ratchet. pnpm check:changed passed 37 of 38 checks. The unit-test check failed only in server-antigravity-resume-identity.test.ts (agent hooks, unrelated), which passes 5/5 on its own.
Performance
This is a perf fix. Cached rescans no longer re-read every transcript after a cache format change or build switch. The only new work is one directory listing plus a stat and a SQLite open per other-version cache file, once per scanner-child database open, off Electron main. Disk use is at most two cache files (this version and the most recently used other one, plus any version another running build has open).
Risk
The riskiest part is the cache-file handling on first start.
Where it runs: pruning runs once, when the scanner child first opens its database. Every failure is caught.
First start: one full rescan after upgrading, the same cost as today's schema bump.
Disk: at most two cache files (this version and one other, plus any version another running build has open). After an upgrade the old file stays as that "other" until the next format change, so it keeps an older build warm.
Progress strip: a slow cached rescan (for example over a slow network or WSL disk) now shows no live strip. The header's loading spinner and the list's loading label still show.
Back out: a plain revert. The .vN files would stay on disk unused, and the reverted build goes back to the unversioned file.
Level: Medium
AI Disclosure
Review
Two review rounds (Codex + Claude). Accepted and fixed:
Sync filesystem ratchet: added a baseline entry for the one-shot scanner-child startup use.
Old cache adoption (two rounds, plus a CodeRabbit Major): moving the old file disturbed a build still using it, and a snapshot copy could block the scanner on large caches. Adoption is removed.
Pruning: it could delete a version another running build had open. Now it skips files it can't lock exclusively.
Quiet rule threshold: a count of files read didn't track scan time, so it now counts bytes read.
Failed scans: a scan that failed before being shown no longer leaves a partial strip.
Declined:
Hiding the strip during a cold scan's file-listing stage. That's the agreed behaviour: show progress only once real reading starts.
Strip during a scope switch: it keeps showing the previous scope's finished strip during a quiet scan for a never-scanned scope (P3).
Prune race: a very narrow window between checking a stale file and deleting it (P3).
Follow-ups:
The session search index (ai-vault-search) has the same wipe-on-any-version-mismatch behaviour in openVersionedCacheDatabase and would benefit from the same per-version treatment.
OpenCode/zcode SQLite-backed parses report 0 bytes to the quiet rule.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Windows: renaming or deleting a held file throws and is caught, and pruning also checks exclusivity first.
SSH, mobile and remote hosts: they don't read local scan progress. The new progress field only travels from the scanner child to main in the same build.
WSL: WSL rows are unchanged.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
Scan progress now records transcript and scope-probe bytes read. Local progress uses a 64 MiB threshold before it replaces existing displayed progress. Session parse-cache databases now use schema-versioned paths, and initialization prunes older cache files while retaining the current database and eligible older files.
Merge Risk: Low · up to ced96
Session History progress may appear late or too early for very large transcripts. The versioned parse-cache change itself looks safe to merge. The remaining issues are minor and can be addressed in a follow-up.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: stopping full transcript re-reads after a cache format change or build switch. The conventional-commit prefix fix(session-history): matches the Session History scope…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, Agent skill upstream boundary, N…
Full details: Title check
Explanation
The title names the main change: stopping full transcript re-reads after a cache format change or build switch. The conventional-commit prefix fix(session-history): matches the Session History scope. The title is specific and accurate for the changeset, which covers versioned cache files, pruning, and the bytes-read progress rule.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. The ELI5 explains the cache-wipe and slow-bar problems in plain language. What Changed covers the versioned cache files, pruning, and the 64 MB quiet rule. Why explains the root cause and rejected alternatives. Risk names the riskiest part (first-start cache handling and progress-strip visibility), states the level (Medium), and gives a back-out path. Performance has a substantive explanation rather than a one-liner. Visual Proof is marked N/A with a reason and supporting measurements. Testing lists manual runs, reproductions on main, and new tests. Minor gaps: the Performance section's 'None, because' sentence is replaced by a full explanation, which is acceptable. The Linked Issue is a Linear ticket with no GitHub issue, which the template says outside contributors must avoid, though the author appears to be a maintainer. The final lint/typecheck/test/build checklist item is unchecked. The AI Disclosure section is empty, and the template asks for AI model details unless the author is a StablyAI team member, so the author's status should be confirmed.
Finishing Touches
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Give each adoption exclusive staging and publication.
If a scanner is retired during a slow adoption, a replacement can start before it exits. One scanner can remove the other's staging file. On POSIX, a later renameSync can also replace a destination that the other scanner has already opened, losing cached writes and causing transcripts to be reparsed.
Use a private staging file for each adoption and publish it atomically only if the destination is still absent. If another scanner has created the destination, open that file instead.
SQLite how to corrupt database unlink open database different processes unix sqlite database file
Result:
Sources consulted:
- [sqlite] Error 1032: SQLITE_READONLY_DBMOVED with one writer and one reader process — https://www.mail-archive.com/[email protected]/msg90531.html
- Is it ok to replace a sqlite file while a program has an open db connection to it? — https://stackoverflow.com/questions/4550272/is-it-ok-to-replace-a-sqlite-file-while-a-program-has-an-open-db-connection-to-i
- How To Corrupt An SQLite Database File — https://sqlite.org/howtocorrupt.html
- Different databases with the same name: SQLite WAL and POSIX unlink|HOO Works — https://note.com/hooworks/n/ne4b03e9306ae?hl=en
- SQLite User Forum: Renaming a database — https://sqlite.org/forum/forumpost/33ff5204bc3bec85?t=c
cat -n src/main/ai-vault/parse-cache/session-parse-cache-database.ts | sed -n '100,235p'
cat -n src/main/ai-vault/scan-service/session-scanner-service-client-state.ts | sed -n '96,145p'
cat -n src/main/ai-vault/parse-cache/session-parse-cache-persistence.test.ts | sed -n '300,455p'
Repository: stablyai/orca
Length of output: 14587
Prevent pruning a cache that opens after the probe.
After the main process exits, its scanner can still open the cache while it finishes work. If that happens between openElsewhere and removal, pruning can unlink an active cache on POSIX. Cache writes can fail or be lost, requiring a cold rescan.
Keep pruning disabled unless ownership protection covers the probe through removal and also covers older scanners that may still open the file. Add a test for an open between the probe and removal.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Heavy lift
Report bytes while the transcript is being read.
If one transcript exceeds 64 MiB, consumeCompleteJsonlLines can read and parse the entire file before this call reports any bytes. The live strip therefore stays hidden throughout that work. If the read fails or is cancelled, this call is never reached. Report bytes from the streaming read path instead.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Heavy lift
Count bytes after they are read.
This call counts the stat size before parseAgentSessionFile opens the transcript. An unreadable or deleted file can therefore make progress visible without any content being read. If sizeBytes is unavailable, a successful read contributes zero instead. Count actual bytes at the read sites.
… stay quiet on cached rescans
A cache format bump or switching between builds that share a data folder
deleted the whole parse cache, so the next open re-read every transcript.
Each format version now gets its own file, and the progress strip stays
hidden until a scan has read 64 MB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Session History keeps a cache of every agent session it has already read, so reopening it should be quick. Two things kept making it slow again. Any update that changed the cache format deleted the whole cache, and so did switching between Orca builds that share a data folder. After that, the next open re-read every transcript (29,000 files for the reporter). Even when nothing had changed, the "Checking N / 29,154" bar sat on screen for seconds while Orca confirmed every file was still cached.
What Changed
session-parse-cache.v9.sqliteinstead of one sharedsession-parse-cache.sqlite), so opening a build on another version no longer deletes it.Why
The cache was never per-workspace, contrary to the guess in the report. I ran the real scanner over a 29,000-file history: reopening, switching workspaces and restarting all reused it (0 re-reads, about 1.5 s to re-check every file). The full rescans came from
openVersionedCacheDatabasedeleting the whole file on any version mismatch, newer or older. The format version was bumped 5 times between Oct 22 and Nov 3, one of them hours before the report. And builds on different versions that share a data folder (dev builds from worktrees on different commits, or a downgrade) wiped each other on every switch.Alternatives considered:
disk I/O error), and a snapshot copy can block the scanner for seconds on large caches.Linked Issue
Linear: STA-13607 (no GitHub issue)
Visual Proof
N/A. The strip component itself is unchanged; the change is that it no longer appears during cached rescans. I checked the trigger by running the real scanner on my own history and on a synthetic 29,000-file Codex history, reading the bytes each scan reported against the 64 MB threshold:
Testing
Reproduced on main before the fix:
isStaleSchemadeletes the file on any version mismatch. The new "keeps its rows" test fails on main withfullParses: 1.Confirmed after: the same harness on this branch:
Switching builds: after switching workspaces, a restart, or another build's file appearing, the cache was reused with only changed files re-read (7–9 files).
Quiet rule: warm rescans reported 0–395 bytes read, so the strip stayed hidden.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Real scanner runs on macOS, against my own history (5,000 files) and a synthetic 29,000-file Codex history:
New tests, each confirmed to fail with its part of the change reverted:
session-parse-cache-persistence.test.ts): rows survive another build's file. Pruning keeps one other version plus any version still open.ai-vault-local-scan-progress.test.ts): the last finished strip stays until a rescan reads 64 MB.Focused ai-vault tests and their dependents pass, as do
check:code-quality:changedand the main sync-fs ratchet.pnpm check:changedpassed 37 of 38 checks. The unit-test check failed only inserver-antigravity-resume-identity.test.ts(agent hooks, unrelated), which passes 5/5 on its own.Performance
This is a perf fix. Cached rescans no longer re-read every transcript after a cache format change or build switch. The only new work is one directory listing plus a stat and a SQLite open per other-version cache file, once per scanner-child database open, off Electron main. Disk use is at most two cache files (this version and the most recently used other one, plus any version another running build has open).
Risk
The riskiest part is the cache-file handling on first start.
.vNfiles would stay on disk unused, and the reverted build goes back to the unversioned file.Level: Medium
AI Disclosure
Review
Two review rounds (Codex + Claude). Accepted and fixed:
Declined:
Follow-ups:
ai-vault-search) has the same wipe-on-any-version-mismatch behaviour inopenVersionedCacheDatabaseand would benefit from the same per-version treatment.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)