Skip to content

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

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

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

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​561 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​548
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​558 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​524

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.

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.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 02f8c

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the motivation, implementation, privacy behavior, cleanup behavior, routing precedence, and verification results. However, it omits required template sections, including the l… Add all required template sections. Provide a valid issue reference after Fixes #. Attach before-and-after visual proof, or write N/A with a brief reason if no visual or interaction change exists. Complete the Testing, AI Disclosure, Re…
Docstring Coverage ⚠️ Warning Docstring coverage is 25.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 17 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 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 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 Fixes #. Attach before-and-after visual proof, or write N/A with a brief reason if no visual or interaction change exists. Complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, including the required test and compatibility confirmations.

  • 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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: fa384ef8-0f88-4b43-ae70-944c0bf011f0

📥 Commits

Reviewing files that changed from the base of the PR and between ffff6ea and 02f8c93.

📒 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; 0 remain 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 critical issues — one minor suggestion inline, plus one scope question.

Reviewed changes

  • Tab-strip cache — mobile/src/cache/session-tab-strip-cache.ts persists 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 — selectMobileSessionReconnectViewState selects live | reconnecting-with-cache | offline | blocking by precedence, and getMobileSessionTabStripRows swaps cached rows for live rows under stable ids.
  • Session wiring — new useMobileSessionTabStripCache hook 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 removeHostAndCloseClient and 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

clearTimeout(writeTimer)
writeTimer = null
}
await writeFile(cache)

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.

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.

@Jinwoo-H
Jinwoo-H merged commit 0ba7f8d into main Sep 7, 2026
23 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…ct for a separate mobile pass (#19265)

* Revert "feat(mobile): draw the last known tab strip while a session reconnects (#19258)"

This reverts commit 0ba7f8d.

* Revert "perf(mobile): cut the relay reconnect critical path and admit dead sockets faster (#19236)"

This reverts commit 23df74d.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 7, 2026
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.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 7, 2026
…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.
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