Repository navigation
perf(ai-vault): reuse session list identity on reminted scannedAt - #14245
Conversation
Refocus after the host-cache TTL remints scannedAt even when every session row is unchanged, and all-host merge always stamped Date.now(). The panel only skipped apply on scannedAt equality, so Agent History rebuilt sessionProjectById and the worktree path map on every alt-tab. Reconcile nested session rows structurally before setState, and keep the latest input scannedAt on merge so a cache-hit all-host result stays a no-op. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughAI Vault list merging now preserves the latest valid, non-future input Mergeability Score: 🟡 Moderate · up to The PR improves session identity reuse, but timestamp handling can still misorder or incorrectly accept session-list scans when timestamps include offsets, leading to stale or incorrect merged results. This should be corrected and covered by regression tests before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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.
🧹 Nitpick comments (1)
src/renderer/src/components/right-sidebar/ai-vault-session-identity.ts (1)
5-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace stale refresh rationale.
These comments describe reminted
scannedAtas the only no-op mechanism. This PR adds structural identity reuse, andmergeAiVaultListResultsno longer remints all-host timestamps. Keep each comment to one current invariant.
src/renderer/src/components/right-sidebar/ai-vault-session-identity.ts#L5-L11: remove the claim that all-host merges always remintscannedAt.src/main/ai-vault/session-list-results.ts#L78-L80: remove the claim that the renderer only skips apply whenscannedAtmatches.As per coding guidelines, comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 16dc060d-0bab-4e00-8322-a6b982ef7419
📒 Files selected for processing (6)
src/main/ai-vault/session-list-results.test.tssrc/main/ai-vault/session-list-results.tssrc/renderer/src/components/right-sidebar/ai-vault-session-identity.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-identity.tssrc/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
…esult A remote leg whose clock is ahead, or whose stamp is not ISO, would pin the all-host max above every local rescan and freeze the renderer's scannedAt equality guard — including a manual force refresh. Ignore future and unparsable stamps. Also drop the duplicate sessions useState so apply walks the list once and sessions === scanResult.sessions again. Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/ai-vault/session-list-results.ts (1)
78-100: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winCompare parsed timestamps instead of timestamp strings.
Date.parse(stamp)validates an instant, butstamp > nowandstamp > latestcompare text. A future offset timestamp can pass the future check, and a past offset timestamp can be skipped or selected incorrectly. Compare parsed millisecond values and add offset-form regression cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 467dcfd3-1597-4721-8aa6-8a58838343c7
📒 Files selected for processing (6)
src/main/ai-vault/session-list-results.test.tssrc/main/ai-vault/session-list-results.tssrc/renderer/src/components/right-sidebar/ai-vault-session-identity.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-identity.tssrc/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/components/right-sidebar/ai-vault-session-identity.test.ts
- src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
- src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts
…#14261) Follow-up to #14245. That PR made `scannedAt` meaningful again by keeping the newest leg stamp on an all-host merge instead of reminting it, and made the renderer reconcile session rows structurally. Three loose ends: - An 'all' result is a merge of legs on independent clocks stamped with the newest leg, so the renderer's `scannedAt` equality guard could hard-skip a real change: a paired host whose clock lags the desktop can return new sessions while the merged stamp repeats, hiding them for up to the local leg's 60s TTL. Restrict the guard to single-host scopes, where the stamp is minted by one scanner at scan completion and equality does imply equal content. Merged scopes now let the structural reconcile decide, which costs one deep compare per refocus and keeps the identity reuse intact. The scope test routes through `normalizeExecutionHostScope` so it matches what the main process merges on, including an empty or unrecognized scope. - `latestAiVaultScannedAt` compared stamps lexicographically after only checking `Date.parse` validity. `scannedAt` is `z.string()` on the wire, so a legal ISO variant orders wrongly: '...:05Z' sorts after '...:05.500Z', and a '-05:00' offset five hours in the future sorts below the local stamp and would have been accepted. Compare parsed instants instead. - `EMPTY_AI_VAULT_SESSIONS` is shared by every mounted hook; freeze it and return `readonly AiVaultSession[]` so no consumer can mutate the sentinel. Each test fails against the pre-fix logic.
…ablyai#14245) * perf(ai-vault): reuse session list identity on reminted scannedAt Refocus after the host-cache TTL remints scannedAt even when every session row is unchanged, and all-host merge always stamped Date.now(). The panel only skipped apply on scannedAt equality, so Agent History rebuilt sessionProjectById and the worktree path map on every alt-tab. Reconcile nested session rows structurally before setState, and keep the latest input scannedAt on merge so a cache-hit all-host result stays a no-op. Co-authored-by: Orca <[email protected]> * perf(ai-vault): clamp merged scannedAt and derive sessions from scanResult A remote leg whose clock is ahead, or whose stamp is not ISO, would pin the all-host max above every local rescan and freeze the renderer's scannedAt equality guard — including a manual force refresh. Ignore future and unparsable stamps. Also drop the duplicate sessions useState so apply walks the list once and sessions === scanResult.sessions again. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
…stablyai#14261) Follow-up to stablyai#14245. That PR made `scannedAt` meaningful again by keeping the newest leg stamp on an all-host merge instead of reminting it, and made the renderer reconcile session rows structurally. Three loose ends: - An 'all' result is a merge of legs on independent clocks stamped with the newest leg, so the renderer's `scannedAt` equality guard could hard-skip a real change: a paired host whose clock lags the desktop can return new sessions while the merged stamp repeats, hiding them for up to the local leg's 60s TTL. Restrict the guard to single-host scopes, where the stamp is minted by one scanner at scan completion and equality does imply equal content. Merged scopes now let the structural reconcile decide, which costs one deep compare per refocus and keeps the identity reuse intact. The scope test routes through `normalizeExecutionHostScope` so it matches what the main process merges on, including an empty or unrecognized scope. - `latestAiVaultScannedAt` compared stamps lexicographically after only checking `Date.parse` validity. `scannedAt` is `z.string()` on the wire, so a legal ISO variant orders wrongly: '...:05Z' sorts after '...:05.500Z', and a '-05:00' offset five hours in the future sorts below the local stamp and would have been accepted. Compare parsed instants instead. - `EMPTY_AI_VAULT_SESSIONS` is shared by every mounted hook; freeze it and return `readonly AiVaultSession[]` so no consumer can mutate the sentinel. Each test fails against the pre-fix logic.
Summary
Agent History (
useAiVaultSessionRefresh) only skipped apply whenscannedAtmatched. That stamp is a wall-clock scan time, not a content fingerprint:listSessionsalways structured-clones nested rows (previewMessages,subagent).scannedAteven when every transcript is unchanged.mergeAiVaultListResultsthen stampednew Date().toISOString()on every all-host merge, so a cache-hit'all'result looked fresh even inside per-leg TTL.Alt-tab with the vault panel open therefore always
setSessions'd a new array.AiVaultPaneldepends onsessionsforsessionProjectById,useAiVaultSessionWorktreeMap(path-match per session × worktree), filter/sort/groups, and the virtual list.This reconciles nested session rows structurally before
setStateand keeps the latest inputscannedAton merge. A reminted no-op keeps the previous result, row, andpreviewMessagesrefs so those memos stay cold.Follow-up to the store-catalog identity work in #13744 / #14211–#14217.
Why a partial fix is inert
Identity has to survive every link from fetch to
setState:scannedAteven when every leg was a cache hit.scannedAt.Fixing only (2) still misses a TTL-expired rescan of identical disk contents. Fixing only (3) with
Object.isnever matches after structuredClone. The apply path has to structurally reuse rows (and the whole result when nothing moved).scannedAtis not shown in the UI. Keeping the previous result object on a no-op (old stamp included) is what makes React bail out.lastAppliedScanRefstill records the incoming stamp so the cheap string guard works on the next identical-stamp hit.Reference compare fails on IPC clones
AiVaultSessionis deeply nested. AfterstructuredClone,sessions === previousandrow === previousRownever hold even when every field is unchanged. The write path usesreuseEqualCatalogRows/areValuesEqualand returnscurrentwhen sessions, issues, andcancelledare unchanged.Tests
src/renderer/src/components/right-sidebar/ai-vault-session-identity.test.tsandai-vault-session-refresh.test.ts:previewMessages[],subagent,previewMessagesTruncated) cloned as distinct objects viastructuredClonewith a remintedscannedAt.scanResult === previous,sessions === previous, and nestedpreviewMessagesidentity.previewMessages[0].text) produces a new array but reuses the unchanged sibling row.src/main/ai-vault/session-list-results.test.ts:scannedAtinstead of restampingDate.now().Scalar
{id, title}fixtures are not the only coverage. Reverting the reuse write or the merge stamp makes these assertions go red.Measured impact
How often the churn fired. Every window focus /
visibilitychangewhile the panel is open re-issueslistSessions, and pre-change the only thing standing between that and a full re-apply wasscannedAtequality:cached-session-list.ts:20) replays its original stamp on a hit, so the list only churned when a refocus landed past that TTL.ai-vault-host-leg-cache.ts:8), but every fresh merge restampedDate.now(). So any alt-tab back more than 15s after the last one re-applied the whole list, even when every leg was a cache hit and nothing on disk had changed. For someone tabbing between Orca and a browser while agents run, that is effectively every return — order of 100-200 times per hour of active use.What each churn cost. Marginal cost, excluding the
structuredClonethe IPC boundary pays either way:sessionProjectByIdThe shape matters more than the absolute numbers. Both maps are O(sessions x worktree candidates) —
resolveWorktreeInfoFromCandidatesruns two full.filter()passes plus a.sort()over every candidate, per session — while the reconcile is O(sessions x fields). So the gain is roughly 2x at the default limit and widens fast for heavy users.Two caveats: this covers only the two map memos, and the part users actually feel — the React re-render and re-measure of the virtualized list plus every row's props — is not in the table, so the real saving is larger than it shows.
Made with Orca 🐋