Skip to content

feat(mobile): draw the last known tab strip while a session reconnects (mobile pass) - #19281

Merged
Jinwoo-H merged 4 commits into
mainfrom
mobile/cache-first-reconnect
Sep 7, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
mobile/cache-first-reconnect

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Re-opened for the separate mobile review pass after #19265 reverted the first merge. Now includes the review fix for the CodeRabbit finding on #19258 (commit a58ee4e): cached tab-strip deletion failures are surfaced and awaited.

Held: do not merge without the owner's mobile-pass go.

Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​728 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​710
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​603 $\color{#cf222e}{\Huge{\mathbf{−}}}$​39 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​564

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

  • New per-host, per-workspace tab-strip cache (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.
  • Privacy: terminal titles (shell-controlled, often a command line) and browser titles never reach storage; they collapse to the agent's display name or a generic label. The scrub runs on write and on read, so entries an older build wrote are cleaned as they load. Unknown tab types are dropped. The storage key uses the host id plus a truncated SHA-256 of the workspace id, so no filesystem path is persisted.
  • The cache is deleted for a host from both cleanup paths (removeHostAndCloseClient and the unpaired-credential sweep), including rows that exist only on disk.
  • Route state 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.
  • Cold start with no cache is unchanged.

Verification

  • mobile: tsc --noEmit, vitest run (519 files, 4235 tests), oxlint, oxfmt --check; check:code-quality:changed and check:react-doctor:changed clean. Session-route parity ratchet re-pinned with each delta attributed.
  • Independent adversarial review, two rounds. Round 1 found terminal titles cached verbatim and the cache surviving an unpair; both fixed and re-verified, including a psql URL 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 only id/type/title/agentId per 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 to Browser, 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 | blocking with 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 a forgottenHosts tombstone 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: ac77e2e6-3b7d-4fa4-9178-1645ad4e41c3

📥 Commits

Reviewing files that changed from the base of the PR and between c03cc17 and 8a7c0e9.

📒 Files selected for processing (5)
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/mobile-session-frame-styles.ts
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-session-startup-source.test.ts
  • mobile/src/session/terminal-prewarm-frame-geometry.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Adds 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 8a7c0

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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, requi… Add the required template sections. Provide a valid Fixes #<issue> reference, attach before-and-after visual proof or state N/A with a reason, complete the Testing checklist, and address the AI Disclosure, Review, Agent skill upstream b…
Docstring Coverage ⚠️ Warning Docstring coverage is 28.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: rendering the last-known mobile tab strip during session reconnects.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Fixes #&lt;issue&gt; reference, attach before-and-after visual proof or state N/A with a reason, complete the Testing checklist, and address the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: b6af4789-6a7e-4f34-858a-09ef1f1f1673

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf3067 and 5e6a74c.

📒 Files selected for processing (17)
  • mobile/src/cache/session-tab-strip-cache.test.ts
  • mobile/src/cache/session-tab-strip-cache.ts
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/MobileSessionHeader.tsx
  • mobile/src/session/mobile-session-frame-styles.ts
  • mobile/src/session/mobile-session-reconnect-view-state.test.ts
  • mobile/src/session/mobile-session-reconnect-view-state.ts
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-session-route-source-family.test-support.ts
  • mobile/src/session/mobile-session-tab-strip-entries.ts
  • mobile/src/session/use-mobile-session-controller.ts
  • mobile/src/session/use-mobile-session-presentation.ts
  • mobile/src/session/use-mobile-session-tab-strip-cache.ts
  • mobile/src/transport/host-removal-lifecycle.test.ts
  • mobile/src/transport/host-removal-lifecycle.ts
  • mobile/src/transport/unpaired-host-credential-deletion.test.ts
  • mobile/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

  • enqueueWrite write chain (session-tab-strip-cache.ts) — every write queues behind the tail of the chain, so an older setItem can 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 now await enqueueWrite(cache) instead of racing the in-flight handle, guaranteeing the host-stripped map is the last word on disk; forgottenHosts still 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-controlled setItem mock releasing newest-first) and finishes 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.

Pullfrog  | View workflow run | Using 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.
@Jinwoo-H
Jinwoo-H force-pushed the mobile/cache-first-reconnect branch from c03cc17 to 8a7c0e9 Compare September 7, 2026 17:24

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — MobileSessionActiveContent now boots TerminalEnginePrewarm inside the real terminal frame during showLoadingState and reconnecting-with-cache, matching the existing activePendingTerminalTab path.
  • 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 643571d into main Sep 7, 2026
22 checks passed
@Jinwoo-H
Jinwoo-H deleted the mobile/cache-first-reconnect branch September 7, 2026 17:40
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
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