Repository navigation
fix(runtime): refuse to silently wake a deliberately slept pane (STA-3465) - #12672
Conversation
`activateMobileSessionTab` decided whether to materialize a pane from
`publicTab.status !== 'ready'` alone. A pane the user put to sleep publishes
`pending-handle` indefinitely, so it was indistinguishable there from a pane
whose PTY was lost and is awaiting reconnect — and activating it respawned it
with a freshly re-resolved agent launch the user never asked for.
Gate materialization on the durable sleeping record's `origin`. Only a
worktree-owned capture ('worktree-sleep', written by workspace sleep and by
completed-agent hibernation) records a deliberate takedown; 'live' and 'quit'
captures describe a pane that was still running, so reconnect-driven
materialization (#11542) is unchanged for them.
|
Warning Review limit reached
Next review available in: 43 seconds You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (14)
📝 WalkthroughWalkthroughThe runtime now skips pending terminal materialization for panes with matching 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
The park guard refused every activation of a `worktree-sleep` pane, but opening the tab is the documented wake gesture for exactly those records (#11598) — and three of the four sleep topologies never clear the record, so the pane was stranded `pending-handle` forever. Carry the caller's intent explicitly instead of inferring it. `intent` is an additive optional field on `session.tabs.activate`; absent means user intent, so a client that predates it keeps today's behavior. Only an `automatic` activation consults the park guard. Intent is set honestly at every sender: mobile tab taps and the pending- terminal follow-up, the paired desktop/web tab click, and the renderer's pane-open attach are 'user'; the reconnect probe in `waitForResubscribeHostSessionHandle` (#11542) is 'automatic'. Also pin the host-partitioned sleeping-record lookup: the workspace-session test stub answered for any host id, so hardcoding 'local' left the suite green. It now answers for one partition, and three SSH reattach tests that silently relied on the loose stub were corrected to their real partition.
Rework: refuse only automatic wakes, not the user's tapThe independent review was right to block this. Thanks — the finding was decisive and the fix below is a direct response to it. What was wrongThe guard refused activation for any pane whose
Whether anything else clears the record first depends on topology, and three of four never do:
So in three of four topologies the pane was stranded What the rework doesThe underlying bug is still real and still fixed: Mechanism — an additive optional The guard is now Every call site, labelled honestly:
Test evidenceNew/reworked coverage in
Plus The test gap the review found
Fixing the stub exposed three existing SSH reattach tests that had been relying on the loose behavior (their session lived in the Mutation results
Verification
|
…3465) (stablyai#12672) `activateMobileSessionTab` gated only on `publicTab.status !== 'ready'`. A deliberately slept pane publishes as `pending-handle` indefinitely — indistinguishable at that call site from a pane awaiting reconnect — so the reconnect probe added by stablyai#11542 respawned it with a re-resolved agent launch, waking something the user had deliberately put to sleep. The first attempt refused activation for any pane with a `worktree-sleep` record, applied to every path. Independent review found that broke the documented wake gesture: opening the tab IS how those panes are meant to cold-restore (`wake-sleeping-agents-in-background.ts`: "Those panes cold-restore --resume when their own tab is opened"). A mobile tap sends the byte-identical call the reproduction test used, and in three of four topologies no wake clears the record first — so the tap became a permanent no-op with no feedback. This carries intent explicitly instead of inferring it. A new shared `TabActivationIntent` ('user' | 'automatic') rides the existing ActivateTab schema as an optional additive field; `isAutomaticTabActivation` returns true only for an explicit 'automatic', so an absent value is permissive BY CONSTRUCTION in one place — an older client that does not send it keeps today's behavior rather than silently losing its wake gesture. The field is required on the mobile helper's params, so no call site can be added without declaring who asked. Every user path (mobile tab switches, paired tab clicks, shortcuts, palette, the pane's own open) is labelled 'user'. The only automatic sender in the codebase is `waitForResubscribeHostSessionHandle`, the stablyai#11542 reconnect probe. Verified per topology: user activation materializes a parked pane under headless serve, a paired runtime client, a completed agent with restoreOnTabOpenOnly, and a running agent whose wake cleared the record. The automatic probe is refused without retiring the surface, and stablyai#11542's reconnect tests stay green. Also fixes a test fixture that made a real bug untestable: the store stub ignored the host id, so mutating the partition lookup to 'local' left the suite green. Correcting it exposed three existing SSH reattach tests that had been relying on that looseness — their workspace session sat in the local partition while their repo was SSH-hosted, a store production would never read. Production was always right; the tests described an impossible world. Fixes STA-3465.
Fixes STA-3465.
Symptom
A pane the user deliberately put to sleep (workspace sleep, or automatic completed-agent hibernation) can be respawned behind their back, with a freshly re-resolved agent launch, by a background reconnect probe. The user never asked for it and never sees it coming.
Cause
OrcaRuntimeService.activateMobileSessionTabdecides whether to materialize a PTY from the published status alone:pending-handleis produced by exactly one predicate — no connected leaf PTY and no connected matched PTY (toMobileSessionTabsResult). Sleeping a workspace intentionally keeps the tab and its pty-id bindings and kills only the process, so a slept pane publishespending-handleindefinitely and is, at this call site, byte-for-byte indistinguishable from a pane whose PTY was lost and is awaiting reconnect.With
navigation: 'caller'— which is what #11542's reconnect recovery loop sends (activateHostSessionSurfaceinremote-runtime-pty-transport.ts) —targetsHostis false, so the first disjunct short-circuits and materialization is unconditional.This is not new: the initial-attach path already called activate before #11542. #11542's reconnect fix depends on that respawn working for genuinely-awaiting panes, which is why it was not treated as blocking.
Did a positive "deliberately slept" marker already exist?
Partly, and this is the crux, so it is worth being precise.
sleeping-record-park-exemption.ts,use-terminal-tab-cold-parking.ts) is ephemeral React state. It is never persisted and is invisible to main. It is a hidden-view unmount optimization, a different concept from a slept pane.hasWorktreeSleepIntentis an in-memory renderer module-levelSet, cleared in afinally. Also invisible to main.SleepingAgentSessionRecordinsleepingAgentSessionsByPaneKeyon the partitioned workspace session — which main already reads elsewhere. Itsoriginfield is the usable marker:'worktree-sleep'is written only bycaptureMode: 'manual-worktree-sleep'(user sleep) and'completed-agent-hibernation', i.e. only by a deliberate takedown.'live'and'quit'captures describe a pane that was still running.So a positive marker for "this pane's PTY was deliberately taken down" does exist and is reachable from this call site; it was simply never consulted. The codebase already treats it this way — see the comment on its own write path: "hibernated completions are intentional worktree-owned records."
Fix
Gate materialization on that marker instead of inferring intent from
pending-handle:isDeliberatelyParkedPanelooks the record up by pane key in the pane's own host partition (getWorkspaceSessionForWorktree) and returns true only fororigin === 'worktree-sleep'with a matching worktree id.This follows the established rule that an ambiguous state must never authorize a surprising action — except that here the state is not ambiguous, it is positively provable, so we can refuse precisely and only when we have proof.
Verification
Six new tests in
src/main/runtime/orca-runtime.test.tsunderdeliberately parked pane activation (STA-3465). All assert the spawn call itself, not timing.Reproduction (red on
origin/main, green after):navigation: 'caller')Negative tests protecting #11542 (green before and after the fix, i.e. they prove nothing was broken):
origin: 'live')origin: 'quit')Mutation checks:
!this.isDeliberatelyParkedPane(...)conjunct: 2 failed / 4 passed (the two reproductions go red).record !== undefined) instead of the park origin: 3 failed / 3 passed — thelive,quitand foreign-worktree cases go red. This is the important one: it demonstrates the negative tests have teeth and that a naive "has a sleeping record" gate would have broken fix(remote-runtime): materialize the host surface when reconnecting a terminal pane #11542.Suites:
src/main+src/shared23240 passed; the 6 failures (ssh-connection-sftp-namespace,pty-subprocess,port-scan-command-execution) reproduce identically on cleanorigin/mainin this environment and are unrelated.pnpm run typecheck,oxlint,oxfmt --checkclean.Deliberate trade-off, please sanity-check
The guard applies to every activate path, not only the
navigation: 'caller'reconnect probe. I chose that over keying offnavigationbecause a navigation-routing flag is a weak proxy for user intent, and because the headlessorca servetopology (nofocusTerminalnotifier) would otherwise still let a background probe through the second disjunct.The consequence: tapping a slept pane on a mobile client no longer respawns it through this path. The dedicated wake flows (
resume-sleeping-agent-session,sleeping-agent-session-launch,wake-sleeping-agents-in-background) are unaffected — they clear the record before relaunching, and they do not route throughactivateMobileSessionTab.Known residual gap (deliberately not fixed here)
A deliberately slept plain shell pane, or an agent pane with no captured provider session, leaves no durable record at all —
sleepingRecordFromEntryonly produces one for a resumable TUI agent with a provider session id. Those panes remain indistinguishable from awaiting-reconnect panes and will still be materialized.Closing that gap properly needs a new pane-scoped durable marker written by
shutdownWorktreeTerminalsfor every pane it kills undershutdownReason: 'manual-sleep'(schema + renderer store + hydration + clear-on-wake), which is a materially larger change than this one and is not needed for the reported harm. The harm called out in STA-3465 is specifically "respawns it with a re-resolved agent launch", and that is exactly the case that does carry a record. Happy to file the follow-up if you want the general case covered.