Repository navigation
fix(mobile): keep polling session tabs while an active terminal is pending-handle (STA-4256) - #14623
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe change adds 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
Independent visual QA (iOS Simulator)Reproduced STA-4256 on this branch and confirmed the pending-handle spinner recovers from a client-initiated Platform: macOS host + iOS Simulator BEFORE — active AFTER — host flipped to Same-session recovery evidence (no remount)While the session screen stayed open:
Metro / app logs
Code reviewNo blocking issues. The new predicate mirrors Screenshots were not committed. |
…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.


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
hasSessionTabsRecoveryNeedin the mobile session route now also returnstruewhile the active session tab is a terminal the host published asstatus: 'pending-handle'(no PTY handle yet).mobile/src/session/pending-terminal-handle-recovery.ts, mirroring the route's existingactivePendingTerminalTabderivation exactly — so it istrueprecisely when the spinner is on screen.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: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:session.tabs.listsession.tabs.activateterminal.listSo 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.listfiring 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
readyin both frames, and no stream event was pushed.BEFORE — 90s after the host started answering
ready, still spinning:AFTER — recovers within one poll (~2s) of the handle becoming available:
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→readywithout pushing a stream event, so recovery can only come from a client-initiatedsession.tabs.list):status: 'pending-handle'→ spinner + tab title. Reproduced.ready. Before: 0 furthersession.tabs.listin 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 realMobileSessionTabsStreamHealththrough subscribe → snapshot → updated (certifying the streamlive) and assertpoll()still issuessession.tabs.listwhile 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 intohasRecoveryNeed, so it cannot become dead code.Non-vacuity check: with
hasRecoveryNeedforced tofalse, the 2 behavioural tests fail withexpected null not to be null— the exact live symptom.Not run: full-repo typecheck (OOM risk on this machine); desktop suites are untouched by this change.
Review
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
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 publishespending-handlesimply never trips it.useFocusEffectalready suspends it when the screen is unfocused or the app is backgrounded.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 —
getWorktreeStatusinmobile/src/worktree/workspace-list-ordering.tsderiving'active'fromliveTerminalCount > 0/hasHostSidebarActivityon 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred) — scoped mobile lint/format/typecheck/tests run locally; full-repo typecheck and build left to CIAuthor