Skip to content

perf(mobile): reopen agent session history from memory - #39387

Merged
AmoabaKelvin merged 5 commits into
mainfrom
agent-history-from-memory
Nov 7, 2026
Merged

AmoabaKelvin merged 5 commits into
mainfrom
agent-history-from-memory

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29 $\color{#cf222e}{\Huge{\mathbf{−}}}$​332 $\color{#cf222e}{\Huge{\mathbf{−}}}$​303
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2789 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1844 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​945

What Changed

Before: the history hook kept its rows in component state.

  • Every open started empty and showed the spinner.
  • Every open sent status.get (a live read that never reuses an answer) and only then aiVault.listSessions, one after the other.
  • Association changes from the agent status feed reloaded through a hand-rolled pending-load queue.

After: aiVault.listSessions is 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 refetchOnWindowFocus revalidates on foreground (per the design table: no desktop signal exists for new transcripts).

  • No status.get on open: the aiVault.v1 gate 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.ts now keys the per-connection status on a query read view's base client (readViewBase in host-read-client.ts). Before, a query's read view kept its own empty entry, so the first query read in a page document re-sent status.get even 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 before worktree.ps lands. The query and explicit refresh both wait for the worktree list, as before.

  • Pull to refresh: sends force: true through readHostQueryLive, 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 refreshing line 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:

  • The query layer no longer retries a 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 listSessions and no status.get after 30 s), refresh (force: true replaces cached rows), association (a feed snapshot rereads and applies the chat name). host-status-query.test.ts covers the shared status. agent-history-association.test.tsx is deleted: it pinned call sequences, and its behaviours are now in the association recording and agent-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:

  • Scan paths in the key. A revisit can't know the key until worktree.ps lands, so it would always spin.
  • Keep the live status.get on 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.
  • afterFingerprint conditional 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's advance), 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. Base 11cad934212.

Phone calls Base Head Change
Reopen within 30 s: status.get 1 0 -1
Reopen within 30 s: aiVault.listSessions 1 0 -1
Reopen after 30 s: status.get 1 0 -1
Reopen after 30 s: aiVault.listSessions 1 (rows wait for it) 1 (behind cached rows) 0
Serial round trips before rows on a reopen 2 (status.get then listSessions) 0 -2
First open in a page document whose connection already has a status status.get 1 + listSessions 1 listSessions 1 -1
Pull to refresh status.get 1 + listSessions 1 listSessions 1 -1
Burst of N association events during a read 1 follow-up 1 follow-up 0
Resume a session in a terminal 0 status.get (used the open's) 1 live status.get (joins one already out) +1

worktree.ps (the panel's own read, 1 per open) is unchanged.

Page bundle (pnpm build:mobile-web, base vs head):

Base Head Limit
bytes excluding the approved font 9,723,070 9,724,247 (+1,177) 9,961,472
assets 191 192 (+1) 193
chunks 110 111 (+1) 112

Worse:

  • +1 chunk / +1 asset: 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.
  • Resume pays one status.get at 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 typecheck and pnpm typecheck:tests in mobile/: 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: every connectionHostStatusRead caller 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 (so failWhenDisconnected still 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. The BridgeReplyRefusedError no-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.ps cached 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: other useHostQuery callers that pass enabled: connState === 'connected' (Source Control settings, Review diff loading) have the same lost-edge gap; fixing it in useHostQuery needs 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

  • 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

  • Older desktops: the capability gate is unchanged (aiVault.v1); only where the status comes from changed.
  • Remote/SSH: the key includes the execution host, so workspaces on different servers never share rows.
  • Folder workspaces: no git assumption; the scan uses worktree.ps paths as before.

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)

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f77b77d7-8ead-42a8-9297-b221dcbd2341
Commits

Reviewing files that changed from the base of the PR and between 8004bfd and 85eb68b.

Files selected for processing: 25

  • mobile/rpc-foundation/goldens/aivault-history-scan-association.json
  • mobile/rpc-foundation/goldens/aivault-history-scan-fulfilled.json
  • mobile/rpc-foundation/goldens/aivault-history-scan-refresh.json
  • mobile/rpc-foundation/goldens/aivault-history-scan-revisit.json
  • mobile/rpc-foundation/goldens/aivault-history-scan-unsupported.json
  • mobile/rpc-foundation/goldens/aivault-history-scan-worktrees-late.json
  • mobile/rpc-foundation/goldens/aivault-history-screen-listed.json
  • mobile/rpc-foundation/goldens/aivault-history-screen-worktrees.json
  • mobile/rpc-foundation/goldens/matrix-aivault.history-aivault.listsessions-1.json
  • mobile/rpc-foundation/goldens/matrix-aivault.history-screen-platform-status.json
  • mobile/rpc-foundation/goldens/matrix-aivault.history-screen-worktree.ps-1.json
  • mobile/rpc-foundation/goldens/matrix-aivault.history-status.get-1.json
  • mobile/rpc-foundation/pilot-scenarios.json
  • mobile/src/agent-history/MobileAgentSessionHistoryPanel.tsx
  • mobile/src/agent-history/agent-history-association.test.tsx
  • mobile/src/agent-history/agent-history-pending-resume-ownership.test.tsx
  • mobile/src/agent-history/mobile-agent-history-operations.ts
  • mobile/src/agent-history/use-mobile-agent-history-state.ts
  • mobile/src/query/host-query-errors.ts
  • mobile/src/query/host-read-client.ts
  • mobile/src/query/host-status-query.test.ts
  • mobile/src/query/host-status-query.ts
  • mobile/src/test-support/bridged-parity/c5-page-closure.ts
  • mobile/src/test-support/bridged-parity/divergence-classes.ts
  • mobile/src/test-support/rpc-recording/adapters/agent-history-mount-adapters.ts
  • 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.

Share

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