Repository navigation
Avoid downloading unchanged paired-runtime session history - #27383
Conversation
Keep selected finite-depth history refreshes content-conditional while preserving scans, full old-peer replies, force refreshes and the existing cache lifetime. Co-authored-by: mmarabel <[email protected]>
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Session history refreshes should work as intended. One unlikely edge case could return an empty session list from the cache instead of rescanning. It is easy to guard against, and the risk is low. Pre-merge checks |
|
# Conflicts: # src/main/ipc/ai-vault-host-leg-cache-retention.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/ipc/ai-vault-host-leg-cache.ts (1)
75-76: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueNormalize
afterFingerprintbefore comparing it withresult.fingerprint.
afterFingerprintcan benullorundefined.result.fingerprintisstring | undefined. When a cached compact result has nofingerprint,undefined === undefinedis true for a fingerprint-less request. The cache then returns the emptyunchangedbody to a reader that never asked for a conditional reply. The host RPC always sets a fingerprint onunchangedresults, so this is unlikely in practice. The cache should still not depend on that.Require a truthy fingerprint in both checks.
Proposed fix
- (!cached.result.unchanged || - (cached.depth === args.depth && cached.result.fingerprint === args.afterFingerprint)) + (!cached.result.unchanged || + (cached.depth === args.depth && + !!args.afterFingerprint && + cached.result.fingerprint === args.afterFingerprint))- (!current.result.unchanged || - (current.depth === args.depth && current.result.fingerprint === args.afterFingerprint)) + (!current.result.unchanged || + (current.depth === args.depth && + !!args.afterFingerprint && + current.result.fingerprint === args.afterFingerprint))Also applies to: 100-101
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fa958303-d809-49db-bd30-e37297532be9
📒 Files selected for processing (3)
src/main/ipc/ai-vault-host-leg-cache-retention.test.tssrc/main/ipc/ai-vault-host-leg-cache.tssrc/main/ipc/ai-vault.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
ELI5
Refreshing Agent Session History at a finite history depth on a selected paired runtime now sends a small confirmation when its contents have not changed, so an idle refresh does not compete with terminal traffic for a multi-megabyte download.
What Changed
The host scans with the existing freshness policy, then fingerprints the complete projected reply except its scan timestamp. An opted-in caller with the same fingerprint receives an unchanged confirmation and reuses the exact history it already displays. The existing 15-second main-process cache also holds compact confirmations for matching callers, without retaining another history body or changing its expiry.
Older clients receive the existing full reply. Older hosts ignore the optional request field and return full history. Force refreshes still rescan and return full history. Host, project and depth changes start with a full reply; unlimited-depth, all-host, local and SSH views keep their current path.
Why
A read-only scan of 1,000 actual local sessions produced a 1,854,465-byte full reply and a 164-byte unchanged reply: 99.99% fewer bytes. Fingerprinting the complete result took 4.12 ms median / 4.39 ms p95 locally. This removes redundant transfer while preserving previews, titles, structured ownership, warnings and scan freshness. Raising cache lifetimes would retain more memory or stale data; compressing the connection would still resend unchanged history.
Thanks to @mmarabel for the measurements and proposal in #27277; credited as a commit co-author.
Linked Issue
Fixes #27277
Visual Proof
The history contents, layout and interactions stay the same. Attached fixture screenshots show the full reply and compact unchanged reply preserving the same expanded history. Hidden Electron/CDP validation checks unchanged refreshes retain rows and previews, changed content updates, and host/depth switches use full replies. This rendered check used scripted IPC replies and synthetic visibility events; the protocol is covered by focused tests, without a live paired-network check.
Testing
Review
Independent wire review and additional real-hook lifecycle checks passed. The content fingerprint is stateless and computed after caller-specific projection, so it does not depend on process lifetime or share another client's cache body.
Agent skill upstream boundary
Notes
The optimization currently applies to a selected paired-runtime host. No negative user-facing trade-offs identified. A changed list costs one additional JSON/hash pass before its full transfer; legacy and unlimited-history calls do not compute a fingerprint.
Checklist