Skip to content

fix(mobile): keep polling session tabs while an active terminal is pending-handle (STA-4256) - #14623

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/mobile-agent-view-4256
Aug 15, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/mobile-agent-view-4256

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On the phone, opening an agent session sometimes shows a spinner that never goes away. The phone was waiting to be told the terminal was ready — but it had stopped asking. Now it keeps asking until the terminal shows up, then stops asking again.

What Changed

hasSessionTabsRecoveryNeed in the mobile session route now also returns true while the active session tab is a terminal the host published as status: 'pending-handle' (no PTY handle yet).

  • New pure predicate mobile/src/session/pending-terminal-handle-recovery.ts, mirroring the route's existing activePendingTerminalTab derivation exactly — so it is true precisely when the spinner is on screen.
  • Wired into the existing recovery-need option that MobileSessionTabsStreamHealth.poll() already consults every 2s.

Client-only. No RPC, frame, opcode, or published-content change — it reuses session.tabs.list, so remote wire compatibility Rules 1–3 are untouched.

Why

A terminal tab with no handle renders the session screen's ActivityIndicator + tab title. Leaving that state requires a snapshot carrying the materialized handle.

The tabs reconciler stops asking for one once the subscription is certified live:

// mobile-session-tabs-stream-health.ts
poll(): Promise<void> | null {
  if (!this.reconciliationActive ||
      (this.health === 'live' && !this.options.hasRecoveryNeed() &&
       this.requirementRevision <= this.satisfiedRevision)) {
    return null   // <- parked
  }
  ...
}

hasRecoveryNeed() covered close-tombstones, pending browser focus, and native-chat handle rearm — but not a pending terminal. So a host that mints the handle without emitting a new tabs publication was never asked again, and the pane spun forever.

The fix is the same shape as the native-chat case already in that predicate ("keep polling until a replacement handle arrives"), applied to the plain terminal view.

Which failure mode this is

Measured on the emulator with the session screen open and the host answering ready, over 90s:

RPC count
session.tabs.list 2 (both from initial load)
session.tabs.activate 1 (fired once, never retried)
terminal.list ~45 (every 2s)

So it is not a request that never resolves (both list calls completed) and not a re-render loop (no churn). It is a status that never settles: the client stops asking, and terminal.list firing on the same 2s interval proves the app was alive and foregrounded the whole time.

Linked Issue

Addresses #14421

Visual Proof

Both frames: iOS Simulator, session screen open, host publishing the active terminal tab. Between them nothing changed but the code — the host answers ready in both frames, and no stream event was pushed.

BEFORE — 90s after the host started answering ready, still spinning:

BEFORE-stuck-spinner.png

AFTER — recovers within one poll (~2s) of the handle becoming available:

AFTER-recovered.png

Testing

Platforms: macOS host + iOS Simulator (iPhone 17 Pro, iOS 26.5). All mobile UI interaction driven through orca emulator, by accessibility label — never fixed coordinates, never computer-use.

Live A/B (mock host publishing the active terminal tab, flipped pending-handle → ready without pushing a stream event, so recovery can only come from a client-initiated session.tabs.list):

  1. Open a workspace session while the host publishes status: 'pending-handle' → spinner + tab title. Reproduced.
  2. Flip the host to ready. Before: 0 further session.tabs.list in 90s; still spinning. After: ~15 polls / 30s while pending, recovery within ~10s of the flip, then polling parks again (30 → 31 calls, i.e. one more poll, then quiet).

Automated (mobile/vitest.config.ts):

  • mobile/src/session/pending-terminal-handle-recovery.test.ts — 7 tests. 4 cover the predicate; 3 drive the real MobileSessionTabsStreamHealth through subscribe → snapshot → updated (certifying the stream live) and assert poll() still issues session.tabs.list while pending, stops once a snapshot carries the handle, and never fires when the handle is already there.
  • mobile/src/session/mobile-session-startup-source.test.ts — asserts the route actually passes the predicate into hasRecoveryNeed, so it cannot become dead code.

Non-vacuity check: with hasRecoveryNeed forced to false, the 2 behavioural tests fail with expected null not to be null — the exact live symptom.

mobile/src/session  128 files | 1126 tests  passed
oxlint + oxfmt      clean on changed files
tsc -p mobile/tsconfig.json   clean (plus a scoped pass over the new test files,
                              which that tsconfig excludes)

Not run: full-repo typecheck (OOM risk on this machine); desktop suites are untouched by this change.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Wire/backcompat: no wire change. Reuses session.tabs.list, which every paired host already serves; the predicate reads a field (terminal) the client has always read. An older host that never publishes pending-handle simply never trips it.
  • Performance: the poll is bounded by the state it recovers from — it runs only while the spinner is on screen and stops on the first snapshot carrying the handle (verified live: 30 → 31 calls after recovery). It rides the reconciler's existing 2s interval, adds no timer, and useFocusEffect already suspends it when the screen is unfocused or the app is backgrounded.
  • SSH / remote / folder workspaces: the predicate is transport- and workspace-agnostic; it reads the published tab shape only.
  • Cross-platform: no platform-conditional code, no paths, no shortcuts.

Scope note

STA-517 (incorrect ACTIVE status for SSH worktrees on mobile) was investigated alongside this and is deliberately not in this PR. It is a different root cause — getWorktreeStatus in mobile/src/worktree/workspace-list-ordering.ts deriving 'active' from liveTerminalCount > 0 / hasHostSidebarActivity on the workspace list, not the session tab's handle state. Bundling them would have been a guess, and STA-517 has no reproduction details to verify a fix against.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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) — scoped mobile lint/format/typecheck/tests run locally; full-repo typecheck and build left to CI

Author

  • X / Twitter: @BrennanKB5

…nding-handle (STA-4256)

A terminal tab published as `status: 'pending-handle'` renders the session
screen's spinner. Leaving it requires a snapshot that carries the materialized
handle, but a certified-live tabs stream parks `poll()` unless
`hasRecoveryNeed()` says otherwise — and that predicate never considered a
pending terminal. A host that mints the handle without republishing therefore
stranded the pane on its spinner forever: measured live, zero further
`session.tabs.list` calls over 90s while `terminal.list` kept firing every 2s.

Mirrors the existing native-chat recovery-need pattern. Client-only; no wire
change.
@coderabbitai

coderabbitai Bot commented Aug 14, 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: Pro Plus

Run ID: f8fedfd2-2e2d-4174-8351-05d1bd6cd4a1

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb8836 and 7ad3760.

📒 Files selected for processing (4)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-session-startup-source.test.ts
  • mobile/src/session/pending-terminal-handle-recovery.test.ts
  • mobile/src/session/pending-terminal-handle-recovery.ts

📝 Walkthrough

Walkthrough

The change adds hasPendingTerminalHandleRecoveryNeed to detect active terminal tabs without materialized PTY handles. Session-tab recovery now uses this predicate to continue polling until the handle appears. Tests cover active, recovered, inactive, missing, and unknown tabs, plus stream-health behavior before and after handle materialization.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR directly addresses the mobile session-loading failure described in issue [#14421] by recovering pending terminal handles.
Out of Scope Changes check ✅ Passed The changes are limited to pending terminal-handle recovery, related tests, and route integration; no unrelated code changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely identifies the mobile polling fix for active terminals awaiting handle materialization.
Description check ✅ Passed The description covers the required sections, explains the fix, links issue #14421, includes visual proof, testing details, and scope considerations.
✨ Finishing Touches
📝 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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent visual QA (iOS Simulator)

Reproduced STA-4256 on this branch and confirmed the pending-handle spinner recovers from a client-initiated session.tabs.list after the host flips to ready without pushing a tabs stream event.

Platform: macOS host + iOS Simulator iPhone 17 Pro (UDID 50FD514C-96F6-446E-AC90-D07A24CAB3A0), iOS 26.5. Interaction via orca emulator (AX labels / frame centers). Screenshots via Computer Use of Simulator.app only. Electron was not used: the repro requires a mock host that can withhold stream events, and port 6768 is the user's live Orca.

BEFORE — active zsh tab published as pending-handle; session pane shows spinner + tab title. No pairing codes / tokens / QR.

BEFORE-pending-handle-spinner.png

AFTER — host flipped to ready with terminal: term-1 and zero extra stream frames. Spinner gone; mock PTY scrollback rendered.

AFTER-recovered-terminal.png

Same-session recovery evidence (no remount)

While the session screen stayed open:

moment session.tabs.list stream frames recovery pushes host status
spinner on screen 18 2 (initial snapshot+updated only) 0 pending-handle
5s after silent flip to ready 19 2 0 ready
4s later (poll parked) 19 2 0 ready

session.tabs.activate fired once (still pending). terminal.subscribe started only after the post-flip list. terminal.list kept firing every ~2s the whole time (app alive / focused).

Metro / app logs

  • Bundle: iOS Bundled 1853ms (4679 modules). No redbox, no Could not connect to development server.
  • No ERROR / TypeError / ReferenceError in Metro.
  • Expected diagnostics only: transient stream-skipped (no-webview-ref) then webview-ready / stream-first-event scrollback on term-1.

Code review

No blocking issues. The new predicate mirrors activePendingTerminalTab (type === 'terminal' && typeof terminal !== 'string'), so it is true exactly while the spinner is on screen. Wiring into the existing hasRecoveryNeed option is the same shape as native-chat recovery and is guarded by the source test. Tests drive the real MobileSessionTabsStreamHealth through subscribe → snapshot → updated (live) and assert poll continues while pending and parks once the handle lands. Client-only; reuses session.tabs.list; no wire change.

Screenshots were not committed.

@brennanb2025
brennanb2025 merged commit e570cad into main Aug 15, 2026
46 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…nding-handle (STA-4256) (stablyai#14623)

A terminal tab published as `status: 'pending-handle'` renders the session
screen's spinner. Leaving it requires a snapshot that carries the materialized
handle, but a certified-live tabs stream parks `poll()` unless
`hasRecoveryNeed()` says otherwise — and that predicate never considered a
pending terminal. A host that mints the handle without republishing therefore
stranded the pane on its spinner forever: measured live, zero further
`session.tabs.list` calls over 90s while `terminal.list` kept firing every 2s.

Mirrors the existing native-chat recovery-need pattern. Client-only; no wire
change.
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