Repository navigation
fix(mobile): bound pending-handle session-tab recovery polling (STA-4407) - #14916
Conversation
95cf399 to
f49cd86
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 1 remains after this review. 📝 WalkthroughWalkthroughPending-terminal handle recovery uses a context key and a five-attempt budget for each terminal context. Reconciliation gates recovery polling and resets the budget after connection, foregrounding, stream updates, context changes, or explicit retry. Exhausted recovery contexts are reported to the session route. The pending-terminal UI displays a timeout message and Retry button when recovery is parked. Tests cover budget behavior, lifecycle resets, polling limits, retry behavior, and session wiring. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 073cd8d4-bb7f-4115-8eea-d4984463fad2
📒 Files selected for processing (7)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/mobile-session-startup-source.test.tsmobile/src/session/mobile-session-tabs-stream-health.tsmobile/src/session/pending-terminal-handle-recovery-poll.test.tsmobile/src/session/pending-terminal-handle-recovery.test.tsmobile/src/session/pending-terminal-handle-recovery.tsmobile/src/session/use-mobile-session-tabs-reconciliation.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 50e14f8e-d430-4944-80c7-68f8a6bd8f84
📒 Files selected for processing (4)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/mobile-session-startup-source.test.tsmobile/src/session/mobile-session-tabs-stream-health.test.tsmobile/src/session/pending-terminal-handle-recovery-poll.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- mobile/src/session/mobile-session-startup-source.test.ts
- mobile/app/h/[hostId]/session/[worktreeId].tsx
- mobile/src/session/pending-terminal-handle-recovery-poll.test.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 2 remain after this review.
117ef01 to
259d7ea
Compare
259d7ea to
32b8544
Compare
Mobile emulator QA — partial pass, parked/Retry state NOT reachedPlatform: iOS Simulator, iPhone 17 Pro (iOS 26.5), UDID ✅ Verified: the app builds and loads cleanly on this branch
✅ Verified: the running bundle really is this PR's codeRather than take the branch checkout on faith, I pulled the bundle Metro actually served to the simulator and grepped it. This PR's symbols and copy are compiled in:
So the device was running the bounded-poll code, not ❌ NOT verified: session screen, terminal tab, and the parked/Retry stateI could not reach a live paired host, so I never opened a session, never rendered a terminal tab, and never saw the parked/Retry affordance this PR adds. No part of the changed UI was exercised on-device. Treat the visual coverage here as "the app boots and its unpaired surfaces render" and nothing more. Why it was unreachable — the machine had no usable pairing:
Independently of pairing, Defects observedNone attributable to this PR. The app booted clean and every state I did reach rendered correctly and truthfully — after the auth failure, the host row correctly re-labelled itself What would close the gapA host in Interaction was driven entirely through |
Mobile emulator QA — supersedes the earlier partial commentThis supersedes #14916 (comment). That run stopped at the unpaired host list because it could not mint a pairing code. This run launched an isolated Orca dev instance from this worktree, minted a LAN pairing offer from Settings → Mobile, paired the simulator, opened a session, and rendered a terminal tab. Platform: iOS Simulator, iPhone 17 Pro (iOS 26.5), UDID Pairing pathSettings → Mobile → LAN → advertise ✅ Verified: paired host, session screen, live terminal tabHost 64 (the isolated instance) listed this worktree. Opening it reached the session route ( ✅ Verified: the running bundle is this PR's codePulled the Metro-served iOS bundle (
❌ NOT verified: pending-handle spinner and parked / RetryI created a fresh terminal on the live host and watched the first ~15s (AX + screenshots at ~1.2s intervals). The host published a ready handle immediately. Metro diagnostics for every
This is not a host-level connection failure. The session stayed connected (green “1 tab”) the whole time. Defects observedNone attributable to this PR on the surfaces I reached. Pairing, session open, tab create, and the live terminal pane all rendered correctly. Remaining gapOn-device visual of the parked/Retry affordance still needs a host that actually publishes |
Mobile emulator QA — supersedes the previous two commentsThis supersedes #14916 (comment) and #14916 (comment). Platform: iOS Simulator, iPhone 17 Pro (iOS 26.5), UDID
How pending-handle was induced (not organic)This was host-side fault injection, not a natural race. A reader should not treat the captures below as an organic reproduction. I launched the isolated host with I used the same host-side park the e2e suite uses in [{ "title": "Terminal 2", "status": "pending-handle", "isActive": true, "terminal": null }]That ✅ Verified: pairing, session, live terminalLAN pairing via ❌ NOT verified: pending-handle spinner and parked / “Retry loading terminal”I never photographed the spinner, the “Terminal is taking longer than expected” copy, or the “Retry loading terminal” control. Those strings are in the bundle; they did not appear on-device. What I saw instead, while the host was still publishing AX at that moment: tab “Terminal 2”, “Type a command…”, no “Loading terminal”, no “taking longer than expected”, no “Retry”. The parked empty-state in Metro
Opening a parked desktop-owned tab from the worktree list rematerializes synchronously (next I did not get a Metro trace of Defects observed
What this does not proveOn-device visual of the parked/Retry affordance is still missing. The unit tests cover cadence and park. This run proves the host can publish Interaction via |
Mobile emulator QA — closing pass (supersedes the previous three)This supersedes #14916 (comment), #14916 (comment), and #14916 (comment). Platform: iOS Simulator, iPhone 17 Pro (iOS 26.5), UDID
How the pending-handle state was induced (not organic)This was host-side fault injection plus a first-observation ordering fix. Do not treat the captures as a natural race. Route A (preferred, remote ACK gate) did not land:
Route B is what produced the UI:
The last run's stale-handle / rematerialize-on-activate problems were avoided by (3) + (4). ✅ Verified: spinner / Loading while pendingImmediately after opening the parked tab, AX showed ActivityIndicator ( Paired host / worktree list before opening the session: ✅ Verified: parked copy + “Retry loading terminal”After the 5-attempt budget (~2s/4s/6s/8s/10s), AX and screenshot showed “Terminal is taking longer than expected” and a button with a11y label “Retry loading terminal” (visible label: Retry). Session stayed connected (green “1 tab”). This is the new parked empty-state, not the host-level reconnect row. ✅ Verified: tapping RetryTap on Retry loading terminal reset the budget: spinner returned (shot above). ~11s later the same parked copy / Retry control came back. Host was still Metro / host diagnosticsWhile the session was on the pending tab, Metro Host [{ "title": "Terminal 1", "status": "pending-handle", "terminal": null, "isActive": true }]Defects observedNone attributable to this PR on the surfaces I reached. Spinner, parked copy, Retry, and the Retry → spinner → re-park loop all rendered correctly. The previous comment's observation still stands as a product constraint, not a regression in this PR: if the client already holds a handle, or if What this does not prove
Interaction via |
…407) (#14916) * fix(mobile): bound pending terminal recovery polls * wip(mobile): partial STA-4407 bound pending-handle poll * fix(mobile): finish bounded pending-handle recovery * fix(mobile): preserve pending-handle recovery attempts on slow links * fix(mobile): retain pending-handle cadence budget semantics * test(mobile): pin pending recovery parked state resets * chore(mobile): drop the STA-4407 worker status logbook * fix(mobile): preserve pending recovery liveness * fix(mobile): coalesce repeated recovery retries * fix(mobile): memoize pending recovery context * fix(mobile): type the pending recovery poll test renderer explicitly * fix(mobile): type the poll test renderer without an any union * fix(mobile): keep recovery context refs current * test(mobile): tighten pending recovery coverage * test(mobile): preserve recovery-source liveness * fix(mobile): keep the poll test renderer union free of any * test(mobile): prove parked recovery isolation * fix(mobile): write the parked-recovery callback ref after commit * test(mobile): isolate recovery identity changes * test(mobile): prove recovery publication boundaries
The host has no timer and must not acquire one. These pin that the publication is driven by the addressability transition, at each position relative to the client's 5-attempt ~2s recovery budget (#14916): - before: PTY addressable first, so the tab publishes ready and nothing is owed — asserts no spurious materialization push - during: registration inside the window still publishes - after: registration 30s later still publishes, and beats the newest frame the client took rather than the first one, because intervening title/status churn bumps the version meanwhile Also covers reconnect — `paneWasAddressable` must not latch, so a pane that dies and comes back is owed the same publication — and old-client compatibility, via the same-epoch monotonic freshness gate every mirrored client applies. A push an old client cannot accept is a push that never happened. 3 of the 4 go RED against pre-fix source; the `before` case is a guard.
…407) (stablyai#14916) * fix(mobile): bound pending terminal recovery polls * wip(mobile): partial STA-4407 bound pending-handle poll * fix(mobile): finish bounded pending-handle recovery * fix(mobile): preserve pending-handle recovery attempts on slow links * fix(mobile): retain pending-handle cadence budget semantics * test(mobile): pin pending recovery parked state resets * chore(mobile): drop the STA-4407 worker status logbook * fix(mobile): preserve pending recovery liveness * fix(mobile): coalesce repeated recovery retries * fix(mobile): memoize pending recovery context * fix(mobile): type the pending recovery poll test renderer explicitly * fix(mobile): type the poll test renderer without an any union * fix(mobile): keep recovery context refs current * test(mobile): tighten pending recovery coverage * test(mobile): preserve recovery-source liveness * fix(mobile): keep the poll test renderer union free of any * test(mobile): prove parked recovery isolation * fix(mobile): write the parked-recovery callback ref after commit * test(mobile): isolate recovery identity changes * test(mobile): prove recovery publication boundaries












Fixes STA-4407. Bounds the recovery poll that #14623 introduced, without reverting its STA-4256 fix.
The defect
#14623 fixed STA-4256 by adding
hasPendingTerminalHandleRecoveryNeed()and OR-ing it into the mobile session route'shasSessionTabsRecoveryNeed. That predicate feedsMobileSessionTabsStreamHealth.poll(), whose park condition was:So while the active tab is a terminal whose
terminalfield is not a string (status: 'pending-handle'),poll()could never park.useFocusEffectinuse-mobile-session-tabs-reconciliation.tsrunsrefresh(false)on a 2000 mssetInterval, so a focused, foregrounded mobile session issuedsession.tabs.listevery 2 seconds indefinitely — no age cap, attempt cap, backoff, or failure state — while the pane sat on a spinner.pending-handleis a valid and potentially indefinite host state (src/main/runtime/orca-runtime.ts), so this is not a rare crash path. The cost is battery, cellular data, and host RPC load for as long as the pane stays open.Measured, before and after
A counting harness drove the real controller with the real predicate over a simulated hour:
session.tabs.listrequests / hourmain)Controls that rule out a vacuous measurement: an active tab whose terminal is already a string produces 0 requests/hour, and materializing the handle mid-run yields 1801 total then permanent silence.
Mechanism
PendingTerminalHandleRecoveryBudgetgrants five attempts per recovery context, keyed on the active pending-handle tab. When the budget is spent the poll parks and the pane swaps its indefinite spinner for an actionable Retry.Two boundaries are deliberate and both are pinned by tests:
livestream. On aprobingordegradedstream the 2-second poll is the only refresh path, so it keeps running indefinitely — matching pre-fix(mobile): keep polling session tabs while an active terminal is pending-handle (STA-4256) #14623 behaviour. Bounding it there would have stranded the pane harder than the bug this PR fixes.The budget resets on a new recovery context — terminal identity change, stream reconnect / subscription epoch, app foregrounding, focus, and explicit Retry — and never on the ordinary 2-second tick.
Validation
pnpm typecheck(tsc --noEmit) clean; targeted oxlint / oxfmt clean; React Doctor and changed-code-quality gates cleanhealth === 'live'gate withtrue— reintroducing the original over-bounding defect — fails 2 tests, confirming the non-live behaviour is genuinely pinned rather than incidentally passingScope
Deliberately narrow: 9 files, all under
mobile/, confined to the session/recovery surface. No controller refactor, no route restructuring, no desktop or host changes, no RPC wire changes. Roughly 620 of the added lines are tests.Reviewed across nine same-model review/mutation loops with readiness-checklist bookends, stopping only on a loop that returned clean with no changes. Rebased onto current
main.Does not merge or revert #14623.