Repository navigation
perf(mobile): reopen agent session history from memory - #39387
Merged
Merged
Conversation
…ing reads, and share the connection's status with query reads
… query can read, including after a failed scan
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 9 minutes. View limit details
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. |
…query on the connection
This was referenced Nov 8, 2026
9 of 11 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
When you leave Agent Session History and open it again, the phone used to forget the list, show "Loading agent sessions…" and ask the desktop twice in a row (first "what can you do?", then "list the sessions"). Now it remembers the list it already has and shows it straight away. It asks the desktop again only once the list is more than 30 seconds old, and then it does so behind the rows you can already see, with the thin refresh line under the header.
What Changed
Before: the history hook kept its rows in component state.
status.get(a live read that never reuses an answer) and only thenaiVault.listSessions, one after the other.After:
aiVault.listSessionsis one query on the TanStack query layer, keyed by host, execution host, workspace and scope.Reopen: rows paint on the first frame from the page document's cache. Stale after 30 s, kept 10 min, and
refetchOnWindowFocusrevalidates on foreground (per the design table: no desktop signal exists for new transcripts).No status.get on open: the
aiVault.v1gate reads the status the connection already received (connectionHostStatusRead, landed). The live read the resume path needs (the desktop's Windows shell setting can change while connected) moved to resume time in the panel.Query reads share the connection's status:
host-status-query.tsnow keys the per-connection status on a query read view's base client (readViewBaseinhost-read-client.ts). Before, a query's read view kept its own empty entry, so the first query read in a page document re-sentstatus.geteven when the host gate had just received one.Scope paths: the key leaves them out on purpose. They come from
worktree.ps, which the panel reads on every open; the cached rows carry the paths they were scanned for, so a revisit filters correctly beforeworktree.pslands. The query and explicit refresh both wait for the worktree list, as before.Pull to refresh: sends
force: truethroughreadHostQueryLive, replacing the cached rows.Association changes: each read records the feed's association revision it started at. A scope whose last read (landed or failed) started before the current revision reads once more when nothing is out. No more cancel-and-restart per feed event, and a burst of events costs one follow-up read.
Header: adopts Q1b's NavBar
refreshingline while cached rows revalidate (hidden during a user pull, which has its own spinner).Connection: the query is not gated on
connState, so it keeps the layer's connected-edge watcher through a disconnect (a gated query re-adds the watcher already connected and misses the edge). A read while the host is down fails fast and the screen shows the offline state, as Files does.Query layer fix found on the way:
BridgeReplyRefusedError. The shell refused an unreadable reply; a second read gets the same answer. Natively that reply is a plain refusal, so the page now matches.Tests: recordings re-recorded for the history family. New scenarios: revisit (cached rows on return, then one
listSessionsand nostatus.getafter 30 s), refresh (force: truereplaces cached rows), association (a feed snapshot rereads and applies the chat name).host-status-query.test.tscovers the shared status.agent-history-association.test.tsxis deleted: it pinned call sequences, and its behaviours are now in the association recording andagent-history-resume-target.test.ts.Why
History rescanned on every open, with a spinner each time and a serial capability round trip first. The query layer gives the list one owner for "is this still good". This is
query-layer.md§20 PR 15.Alternatives set aside:
worktree.pslands, so it would always spin.status.geton open, in parallel. Costs one read per open to protect a value only resume uses; reading it at resume time is both cheaper and fresher.afterFingerprintconditional lists (the desktop already uses them): would save bytes on revalidation but needs a capability check on older hosts. Left for a follow-up.Linked Issue
None. This is Q15 of the mobile speed build plan (
design/query-layer.md§9 and §20 PR 15).Visual Proof
N/A for captures in this PR. The only new visual is the existing Q1b refresh line (approved mock) on this header, and the cached list painting instead of the spinner on a reopen. Device captures were not taken: the shared machine was at 0% CPU idle with every heavy slot taken, so the simulator run was dropped. Happy to add them.
Numbers
Method: exact call counts from the RPC recordings in this PR (
aivault-history-scan-*, recorder clock, so "after 30 s" is the scenario'sadvance), read against main's code and goldens. Device timing (kit A/B) was not run: the machine was saturated (0% CPU idle, heavy slots full) during the PR, so timings would be noise. Base11cad934212.status.getaiVault.listSessionsstatus.getaiVault.listSessionsstatus.getthenlistSessions)status.get1 +listSessions1listSessions1status.get1 +listSessions1listSessions1status.get(used the open's)status.get(joins one already out)worktree.ps(the panel's own read, 1 per open) is unchanged.Page bundle (
pnpm build:mobile-web, base vs head):Worse:
refresh-hint.ts(904 B) is now used by two routes (Source Control and History), so the bundler splits it into its own shared chunk. Any second adopter of the refresh line causes this once; Q3 will reuse the same chunk.status.getat tap time instead of reusing the open's. It joins one already out and runs inside a flow that already makes several reads.Testing
npx vitest run src/agent-history src/query src/source-control src/files(mobile): pass.npx vitest run src/test-support/rpc-recording(mobile, includes bridged parity): pass.pnpm typecheckandpnpm typecheck:testsinmobile/: pass.pnpm check:changed: pass.Not run on a device (see Numbers).
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
Risk
The riskiest part is the shared-status keying in
host-status-query.ts: everyconnectionHostStatusReadcaller that reads through a query read view now reuses the connection's landed status instead of keeping its own. Sends still go through the view (sofailWhenDisconnectedstill applies) and reuse still requires the same connection epoch. If it went wrong, a screen could act on a status from a previous connection; the epoch check is what prevents that. TheBridgeReplyRefusedErrorno-retry change applies to every query read on the page; it only removes a second read of a reply the shell already refused.Kelvin's open #39306 (scope-first history scan) edits the same hook, scope paths and history goldens. Whichever lands second rebases; here it's swapping the scan call to
mobileAiVaultScanScopeArgs.Plain revert backs it out. No saved data or wire changes.
Level: Medium
AI Disclosure
Review
Two review rounds (Codex + Claude). Fixed: refresh before
worktree.pscached unscoped rows; association events cancelled and restarted reads (and could lose a reread after a failed scan or a disabled revisit); gating the query on the connection dropped its connected-edge watcher. Follow-up, not in this PR: otheruseHostQuerycallers that passenabled: connState === 'connected'(Source Control settings, Review diff loading) have the same lost-edge gap; fixing it inuseHostQueryneeds their tests' partial client fakes updated, so it gets its own PR. Settled, not changed: a first switch to a scope shows the spinner (one scope's rows can't stand in for another); a failed background refresh keeps rows silently, as on other query screens.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
aiVault.v1); only where the status comes from changed.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)