Repository navigation
feat(mobile): draw the last known tab strip while a session reconnects - #19258
Conversation
Reopening a workspace the phone has already visited threw away everything it knew. The route clears its tabs on mount, so until the reconnect lands and the first snapshot is applied the session screen has an empty header and a bare spinner, even though the strip it is about to be handed is the one it drew a minute ago. Persist the four fields the strip actually draws -- id, type, title, agent -- per host and workspace, and add a reconnecting-with-cache shape to the route state so those rows render immediately, disabled, under the ids the live snapshot will reuse. Live tabs always outrank the cache, so a mid-session drop keeps its mounted terminals; an exhausted retry loop or a rejected pairing outranks it the other way, because a strip the user cannot reach is worse than the existing offline affordance. With nothing cached the screen behaves exactly as before. The body stays a placeholder. Replaying stored scrollback into the terminal WebView would double-render the same rows once the live stream replays them, so the strip is the cached content and the body waits for the stream.
…ab strip Review of the reconnect strip cache found two ways it leaked. A terminal's title is whatever the shell last set, which is routinely the command line: a psql URL with an inline password, a curl with a bearer token. Both fit well inside the 64-character cap and both were written to plaintext AsyncStorage verbatim. Browser tabs carried their page title the same way. Terminals and browsers now collapse to a fixed label, with a resolved agent naming itself because that lookup is a closed enum. The rule lives in the storage module rather than its caller, so it holds for entries an older build already wrote, and a tab type this build cannot draw is dropped instead of having its title trusted. The cache also survived forgetting a host. Nothing expired an entry, and the module-global memory map meant a later save from any surviving host serialized the forgotten host's rows straight back to disk. Both cleanup paths now evict by host, dropping the in-memory rows and rewriting storage, with a pending debounced write cancelled so it cannot restore them. Also: the storage key digests the workspace id, which ended in a filesystem path, and cached rows carry the same de-emphasis as the disabled tab-bar buttons beside them, so an inert row does not pass for a live one.
📝 WalkthroughWalkthroughThe change adds a redacted, debounced, LRU session tab-strip cache backed by AsyncStorage. It projects live tabs into safe preview entries and restores them during reconnects. The session controller exposes reconnect view states and cached tab rows to the UI. Cached rows render as inactive until live tabs are available. Host removal and unpaired-host credential deletion now remove related cached strips. Tests cover caching, redaction, reconnect states, rendering projections, and cleanup. Merge Risk: 🟡 Moderate · up to If device storage rejects the cleanup write, removed or unpaired hosts can leave cached session metadata behind. This should be fixed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the motivation, implementation, privacy behavior, cleanup behavior, routing precedence, and verification results. However, it omits required template sections, including the linked issue, visual proof or an explicit N/A explanation, testing checkboxes, AI disclosure, review, boundary, notes, and checklist confirmations. Resolution Add all required template sections. Provide a valid issue reference after
✨ 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: fa384ef8-0f88-4b43-ae70-944c0bf011f0
📒 Files selected for processing (17)
mobile/src/cache/session-tab-strip-cache.test.tsmobile/src/cache/session-tab-strip-cache.tsmobile/src/session/MobileSessionActiveContent.tsxmobile/src/session/MobileSessionHeader.tsxmobile/src/session/mobile-session-frame-styles.tsmobile/src/session/mobile-session-reconnect-view-state.test.tsmobile/src/session/mobile-session-reconnect-view-state.tsmobile/src/session/mobile-session-route-parity.test.tsmobile/src/session/mobile-session-route-source-family.test-support.tsmobile/src/session/mobile-session-tab-strip-entries.tsmobile/src/session/use-mobile-session-controller.tsmobile/src/session/use-mobile-session-presentation.tsmobile/src/session/use-mobile-session-tab-strip-cache.tsmobile/src/transport/host-removal-lifecycle.test.tsmobile/src/transport/host-removal-lifecycle.tsmobile/src/transport/unpaired-host-credential-deletion.test.tsmobile/src/transport/unpaired-host-credential-deletion.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline, plus one scope question.
Reviewed changes
- Tab-strip cache —
mobile/src/cache/session-tab-strip-cache.tspersists the last-drawn strip per host/workspace under one AsyncStorage key, rebuilding each entry field-by-field and collapsing terminal/browser titles to fixed labels (scrubbed on both write and read), with LRU eviction (12 workspaces / 24 tabs), a 64-char title cap, and a 250ms debounced write. - Reconnect view state —
selectMobileSessionReconnectViewStateselectslive | reconnecting-with-cache | offline | blockingby precedence, andgetMobileSessionTabStripRowsswaps cached rows for live rows under stable ids. - Session wiring — new
useMobileSessionTabStripCachehook plus controller/presentation/header/content integration; cached rows are inert and drawn at reduced opacity. - Deletion plumbing — the cache is dropped for a host from both
removeHostAndCloseClientand the unpaired-credential sweep, including rows that exist only on disk. - Tests — the session-route parity ratchet is re-pinned; new unit tests cover redaction, eviction, host isolation, and both deletion paths.
ℹ️ Scope question: which titles persist verbatim is a human decision
getPersistableTabStripTitle scrubs terminal and browser titles but returns entry.title unchanged for file, markdown, and agent-session (capped at 64 chars). The terminal/browser line is clearly right (shell- and web-controlled), but an agent-session title is worth a second look: if it is ever auto-generated from the first user message, it would carry user-authored free text into plaintext storage — the same class of leak this PR is otherwise eliminating. Flagging for confirmation, not as a bug.
Technical details
# Confirm non-terminal/non-browser titles cannot embed sensitive content
## Affected sites
- mobile/src/session/mobile-session-tab-strip-entries.ts:84 — `getPersistableTabStripTitle` returns `entry.title` for `file` / `markdown` / `agent-session`.
## Open questions for the human
- Can an `agent-session` title embed user message content, or is it always an Orca-generated label?
- Are `file` / `markdown` titles guaranteed to be basenames (never absolute paths) on mobile?
## Required outcome
- Confirm the whitelist, or extend the scrub to cover any title that can carry untrusted text.DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| clearTimeout(writeTimer) | ||
| writeTimer = null | ||
| } | ||
| await writeFile(cache) |
There was a problem hiding this comment.
deleteCachedSessionTabStripForHost clears the pending debounce timer but not an already-fired write. If scheduleWrite's timer has already flushed (writeTimer = null; void writeFile(cache) at line 191), clearTimeout is a no-op and that write's setItem — whose payload was captured before the host's rows were removed — is still in flight. Both writes target the same storage key, so the stale write can land last and resurrect the unpaired host's rows: exactly the failure the surrounding comments promise to prevent.
Technical details
# Serialize cache writes so a host deletion can't be overtaken by an in-flight write
## Affected sites
- mobile/src/cache/session-tab-strip-cache.ts:114 — `await writeFile(cache)` races the debounce timer's `void writeFile(cache)` (line 191), which may have already spread a payload containing the deleted host's rows.
## Required outcome
- Once `deleteCachedSessionTabStripForHost` resolves, no earlier write may subsequently land that re-introduces the deleted host's rows.
## Suggested approach
- Route all writes through one module-level promise chain (e.g. `writeChain = writeChain.then(() => writeFile(cache))`) and have the delete enqueue/await that chain instead of writing directly, so the delete's write is always last. Alternatively track the in-flight `writeFile` promise and `await` it before the delete writes.
## Open questions for the human
- None — the existing `drops a pending debounced write` test covers only the not-yet-fired case; a case where the timer has fired and its write is in flight would pin this.stablyai#19258) * feat(mobile): draw the last known tab strip while a session reconnects Reopening a workspace the phone has already visited threw away everything it knew. The route clears its tabs on mount, so until the reconnect lands and the first snapshot is applied the session screen has an empty header and a bare spinner, even though the strip it is about to be handed is the one it drew a minute ago. Persist the four fields the strip actually draws -- id, type, title, agent -- per host and workspace, and add a reconnecting-with-cache shape to the route state so those rows render immediately, disabled, under the ids the live snapshot will reuse. Live tabs always outrank the cache, so a mid-session drop keeps its mounted terminals; an exhausted retry loop or a rejected pairing outranks it the other way, because a strip the user cannot reach is worse than the existing offline affordance. With nothing cached the screen behaves exactly as before. The body stays a placeholder. Replaying stored scrollback into the terminal WebView would double-render the same rows once the live stream replays them, so the strip is the cached content and the body waits for the stream. * fix(mobile): keep shell titles and unpaired hosts out of the cached tab strip Review of the reconnect strip cache found two ways it leaked. A terminal's title is whatever the shell last set, which is routinely the command line: a psql URL with an inline password, a curl with a bearer token. Both fit well inside the 64-character cap and both were written to plaintext AsyncStorage verbatim. Browser tabs carried their page title the same way. Terminals and browsers now collapse to a fixed label, with a resolved agent naming itself because that lookup is a closed enum. The rule lives in the storage module rather than its caller, so it holds for entries an older build already wrote, and a tab type this build cannot draw is dropped instead of having its title trusted. The cache also survived forgetting a host. Nothing expired an entry, and the module-global memory map meant a later save from any surviving host serialized the forgotten host's rows straight back to disk. Both cleanup paths now evict by host, dropping the in-memory rows and rewriting storage, with a pending debounced write cancelled so it cannot restore them. Also: the storage key digests the workspace id, which ended in a filesystem path, and cached rows carry the same de-emphasis as the disabled tab-bar buttons beside them, so an inert row does not pass for a live one.
…ct for a separate mobile pass (stablyai#19265) * Revert "feat(mobile): draw the last known tab strip while a session reconnects (stablyai#19258)" This reverts commit 0ba7f8d. * Revert "perf(mobile): cut the relay reconnect critical path and admit dead sockets faster (stablyai#19236)" This reverts commit 23df74d.

Why
When the phone reconnects to a desktop it has seen before, the session screen replaced everything with a blocking spinner until the startup RPCs finished, even though the last-known tab strip was already on the device. On a far relay cell that spinner lasted seconds.
What
mobile/src/cache/session-tab-strip-cache.ts, one AsyncStorage key). It stores only tab id, type, title, and agent id, rebuilt field by field. Caps: 12 workspaces with least-recently-written eviction, 24 tabs each, 64-character titles, 250 ms debounced writes.removeHostAndCloseClientand the unpaired-credential sweep), including rows that exist only on disk.live | reconnecting-with-cache | offline | blocking, with precedence: live tabs or an active handle, then a host-confirmed empty workspace (so a cleared workspace cannot resurrect old tabs), then an unreachable or auth-failed verdict, then the cache, then blocking. Cached rows are non-interactive and drawn at the same reduced opacity the disabled tab-bar buttons already use. Live rows replace cached rows under stable ids, so there is no flash. Cached scrollback is not resumed; the body keeps the existing placeholder.Verification
mobile:tsc --noEmit,vitest run(519 files, 4235 tests),oxlint,oxfmt --check;check:code-quality:changedandcheck:react-doctor:changedclean. Session-route parity ratchet re-pinned with each delta attributed.psqlURL with an inline password never reaching the payload or the rendered preview, and both delete call sites traced in code.Not for merge until the owner gives the go.