Repository navigation
feat(mobile): draw the last known tab strip while a session reconnects (mobile pass) - #19281
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This mobile pass reintroduces the cached tab-strip reconnect feature, now carrying the CodeRabbit fix from #19258 (cached-strip deletion failures are surfaced and awaited).
- Per-workspace tab-strip cache (
session-tab-strip-cache.ts) — a single AsyncStorage key storing onlyid/type/title/agentIdper tab, rebuilt field-by-field, with LRU eviction (12 workspaces), 24-tab and 64-char caps, and 250 ms debounced writes. - Privacy redaction — terminal titles collapse to the agent display name or
Terminal, browser titles toBrowser, and the workspace id is SHA-256-digested so no filesystem path persists. Scrubbing runs on both write and read; unknown tab types are dropped. - Reconnect view-state selector (
mobile-session-reconnect-view-state.ts) —live | reconnecting-with-cache | offline | blockingwith the documented precedence; cached rows render disabled at the same de-emphasis as the existing disabled tab-bar buttons. - Deletion wiring — the cache is removed from both
removeHostAndCloseClient(awaited, non-fatal) and the unpaired-credential sweep, and aforgottenHoststombstone blocks a racing save from resurrecting a removed host. - Parity ratchet — session-route hashes/counts re-pinned with the new hook attributed.
I traced the privacy claims through the host-side tab builders: file/markdown titles are basenames (mobile-session-editor-tabs.ts splits relativePath), and filePath/relativePath/launchDraft are never projected into storage. The header refactor is behavior-preserving for live tabs (same getMobileSessionTabTitle/resolveMobileTerminalTabAgentId behind the new entry projection), and the empty-workspace write is guarded by terminalsLoaded + !activeHandle, matching the existing showEmptyState semantics so a transient gap can't clobber a good strip.
ℹ️ forgottenHosts outlives a re-pair within the same launch
Un-pairing and re-pairing the same host in one app session suppresses that host's strip caching until the next launch, because the tombstone set is never cleared. The trade-off is documented in session-tab-strip-cache.ts, and it errs in the safe direction (no stale plaintext survives a deletion the user asked for), so this is an informational note rather than a change request.
ℹ️ Cold-start reconnect paints a blocking frame before the async cache load resolves
readCachedSessionTabStrip returns null synchronously until memoryCache has been populated, so a reconnect after a fresh app launch shows the blocking spinner for one frame until loadCachedSessionTabStrip resolves. In practice the local read resolves faster than the reconnect verdict, but if the blocking flash is noticeable on slow devices it would be worth pre-warming the load earlier in the session route.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughAdds a redacted, debounced AsyncStorage cache for workspace tab-strip previews. Adds reconnect view-state selection and cached tab-row rendering in mobile sessions. Cached rows remain disabled until live tabs are available. Host removal and unpaired credential cleanup now delete the related cached previews. Tests cover storage limits, redaction, concurrency, reconnect states, rendering, and cleanup behavior. Merge Risk: 🟡 Moderate · up to This change adds persisted tab previews during reconnection, but a storage deletion failure during unpaired-host cleanup may leave cleanup incomplete after credentials are removed. Resolve or explicitly accept this cleanup-path risk before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the change, rationale, implementation, privacy controls, cleanup paths, and verification. It does not follow the required template because it lacks a valid Linked Issue, required Visual Proof or an explicit N/A explanation, the Testing checklist, and the remaining required checklist sections. Resolution Add the required template sections. Provide a valid
✨ 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: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: b6af4789-6a7e-4f34-858a-09ef1f1f1673
📒 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; 1 remains after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This delta fixes the write-ordering race that could let a stale blob restore a forgotten host after a purge: the cache now serializes writes through a FIFO chain instead of a single in-flight handle.
enqueueWritewrite chain (session-tab-strip-cache.ts) — every write queues behind the tail of the chain, so an oldersetItemcan never settle after a newer one. Snapshots are taken at execution time, and a rejected link is caught (queued.catch(() => {})) so it can't break the chain for writes queued behind it.- Purge enqueued last (
deleteCachedSessionTabStripForHost) — the deletion nowawait enqueueWrite(cache)instead of racing the in-flight handle, guaranteeing the host-stripped map is the last word on disk;forgottenHostsstill blocks a racing save from re-inserting the host. - Non-fatal purge in the unpaired sweep (
unpaired-host-credential-deletion.ts) — a failed cache delete now warns and continues, so a storage failure can't strand the write revision after every credential is already gone. - Regression tests —
cannot let an older overlapping write commit after the purge(gate-controlledsetItemmock releasing newest-first) andfinishes the cleanup when the cache purge fails.
I traced the new chain against the deletion path: an in-flight debounced write snapshotted before the forget settles strictly before the purge's writeFile runs, and the tombstone prevents any post-delete save from re-adding the host, so the purge is reliably the last write. Both new tests fail under the prior single-handle implementation and pass under the chain, so they guard the actual regression.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
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.
…disk Review finding on this PR, fixed here so it rides along with the rest. writeFile swallowed its own rejection, so deleteCachedSessionTabStripForHost resolved successfully while the unpaired host's plaintext tab titles stayed on disk, and removeHostAndCloseClient discarded the promise with void so nothing could have observed the failure anyway. The write now throws. The debounced save keeps a best-effort catch, since a dropped cache refresh costs one repaint and the next save rewrites the whole map, so only the deletion path needs the failure. Host removal awaits the deletion and logs a failure but never rethrows: the metadata removal has committed and the client is closed by that point, so reporting a finished removal as failed would be wrong. The unpaired-host credential sweep already awaited the deletion and now sees the rejection, consistent with its sibling credential deletions. Two ways the rows could come back are closed as well. The cache refuses saves for a host it has been told to forget, so a snapshot racing the deletion cannot re-insert it, and the deletion awaits any debounced write already on the wire, since that write built its blob from the map as it was and would otherwise race the purge for the last word on disk. The refusal lasts for the process, so re-pairing the same host caches again from the next app launch, which is the cheap direction for a deletion the user asked for.
…word Two debounced writes could sit on the AsyncStorage bridge at once, and the second replaced the in-flight handle. A host purge then awaited only the newer write, so the older blob -- snapshotted while the forgotten host was still in the map -- could commit after it and restore the host's titles to disk. Writes now queue behind one chain and the purge queues last. The unpaired-credential sweep also aborted on a cache-purge failure, stranding the write revision and onDeleted after every credential was already deleted. It now warns and finishes, as removeHostAndCloseClient already did.
c03cc17 to
8a7c0e9
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This delta reconciles the cached-strip branch with the pre-warmed terminal engine that #19260 merged to main while this PR was held, and fixes the header/content gating drift.
- Extended the terminal-engine prewarm to the loading and reconnecting states —
MobileSessionActiveContentnow bootsTerminalEnginePrewarminside the real terminal frame duringshowLoadingStateandreconnecting-with-cache, matching the existingactivePendingTerminalTabpath. - Unified tab-bar gating on
tabStripRows— the header mounts the tab bar (rendering cached preview rows disabled at 0.45 opacity off the same list) and the prewarm reads its height reservation from the same list, so the two can no longer drift. - Re-pinned the session-route parity ratchet and updated the source-geometry tests for the new condition.
I traced the new prewarm through measurePrewarmViewport: it is idempotent via the one-shot viewportMeasuredRef, and the reservation height is the exact complement of the header's tabStripRows.length > 0 gate across the cold, reconnect-with-cache, and empty-workspace cases, so the measurement always matches the pane the terminal will finally occupy.
ℹ️ The prewarm now boots a terminal WebView on every session open
showLoadingState is connected && !terminalsLoaded, so the prewarm (and its xterm bundle) now boots on every open — including workspaces that resolve to markdown or empty, where the engine is loaded and then discarded unused. The measurement is one-shot and reusable, so this is not a correctness issue, but it broadens the cost of #19260's prewarm from the terminal-specific path to every session. Informational only; the owner's mobile pass is the merge gate here anyway.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…aller, verified re-land (#19348) * Revert "feat(mobile): time relay dial stages so diagnostics say where a slow connect went (#19245)" This reverts commit 83b1558. * Revert "perf(mobile): race the direct and relay dials from t=0 on every reconnect (#19308)" This reverts commit ceafdca. * Revert "feat(mobile): draw the last known tab strip while a session reconnects (mobile pass) (#19281)" This reverts commit 643571d. * Revert "perf(mobile): open a session with parallel startup RPCs and a pre-warmed terminal engine (#19260)" This reverts commit c374132. * Revert "perf(mobile): cut the relay reconnect critical path and admit dead sockets faster (mobile pass) (#19280)" This reverts commit e628090. * chore: keep the react-doctor suppression for the startup timers The pattern it covers (a variable number of timers cleared through one cleanup) predates #19260 and is unchanged by the revert; dropping the entry only re-exposed a pre-existing finding to the changed-code gate.

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.