Repository navigation
fix(runtime): retire an exited pane's surface in its owning host partition (STA-3463) - #12671
Conversation
…ition `retireMobileSessionSurfacesForPty` read and wrote the workspace session without a host id, so every retirement landed in the local partition. For a pane on an SSH connection that means the local partition absorbed the write (bumping the SSH repo's topology revision there) while the SSH partition kept its stale surface, resurrecting the dead pane on the next hydrate. Group the retired surfaces by the execution host that owns each worktree and apply each group to that host's own session partition, matching what `retirePersistedStablePaneOwner` already does in src/main/ipc/pty.ts.
📝 WalkthroughWalkthroughThe runtime now groups retired terminal surfaces by execution host and persists each group to its host-specific workspace session. It tracks surfaces without sessions as unpersisted, handles unavailable persistence or write failures, and publishes only accepted or unpersisted surfaces. Tests cover SSH and local partition updates, published mobile tabs, unchanged unrelated partitions, and host-specific persistence arguments. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (2)
src/main/runtime/orca-runtime-terminal-retirement-host-partition.test.ts (2)
102-132: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueType the mock store instead of
never, and drop the unusedreadsfield.
store: nevermakes the field unusable without another cast. The second test already works around this with...(harness.store as object)at Line 250. Useunknownin the harness type and keep a single cast at the constructor call site. This also keeps the mock shape visible to type checking.
readsis recorded but no test asserts it. Remove it, or add an assertion that each host partition is read once.♻️ Proposed refactor
type PartitionedStoreHarness = { - store: never + store: unknown sessions: Map<ExecutionHostId, WorkspaceSessionState> writes: { hostId: ExecutionHostId | undefined; session: WorkspaceSessionState }[] - reads: (ExecutionHostId | undefined)[] } @@ const writes: { hostId: ExecutionHostId | undefined; session: WorkspaceSessionState }[] = [] - const reads: (ExecutionHostId | undefined)[] = [] const store = { getRepos: () => [SSH_REPO], getRepo: (id: string) => (id === SSH_REPO_ID ? SSH_REPO : undefined), getWorkspaceSessionHostIds: () => [...sessions.keys()], getWorkspaceSession: (hostId?: ExecutionHostId) => { - reads.push(hostId) return sessions.get(hostId ?? LOCAL_EXECUTION_HOST_ID) ?? getDefaultWorkspaceSession() }, setWorkspaceSession: (session: WorkspaceSessionState, hostId?: ExecutionHostId) => { writes.push({ hostId, session }) sessions.set(hostId ?? LOCAL_EXECUTION_HOST_ID, session) }, flushOrThrow: vi.fn() - } as never - return { store, sessions, writes, reads } + } + return { store, sessions, writes } }Then cast at each construction site, for example
new OrcaRuntimeService(harness.store as never).
258-307: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueParameterize
syncSshSplitinstead of duplicating the window-graph setup.Lines 258-307 restate the structure of
syncSshSplitwith local ids. If thesyncWindowGraphpayload shape changes, both copies need the same edit. Extend the helper with worktree id and pty ids, then call it from both tests.♻️ Proposed refactor
-function syncSshSplit(runtime: OrcaRuntimeService, snapshot: RuntimeMobileSessionTabsSnapshot) { +function syncTerminalSplit( + runtime: OrcaRuntimeService, + snapshot: RuntimeMobileSessionTabsSnapshot, + worktreeId: string, + ptyIds: { left: string; right: string } +) { runtime.syncWindowGraph(1, { tabs: [ { tabId: 'tab', - worktreeId: SSH_WORKTREE_ID, + worktreeId, title: 'Terminal', activeLeafId: 'left', layout: snapshot.tabs[0]?.type === 'terminal' ? (snapshot.tabs[0].parentLayout?.root ?? null) : null } ], leaves: [ - { tabId: 'tab', worktreeId: SSH_WORKTREE_ID, leafId: 'left', paneRuntimeId: 1, ptyId: SSH_PTY_LEFT }, - { tabId: 'tab', worktreeId: SSH_WORKTREE_ID, leafId: 'right', paneRuntimeId: 2, ptyId: SSH_PTY_RIGHT } + { tabId: 'tab', worktreeId, leafId: 'left', paneRuntimeId: 1, ptyId: ptyIds.left }, + { tabId: 'tab', worktreeId, leafId: 'right', paneRuntimeId: 2, ptyId: ptyIds.right } ], mobileSessionTabs: [snapshot] }) }The local test then builds its local snapshot and calls
syncTerminalSplit(runtime, localSnapshot, localWorktreeId, { left: 'pty-left', right: 'pty-right' }).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dcd1e313-7480-4abd-a9ad-0c4e749ca5e8
📒 Files selected for processing (3)
src/main/runtime/orca-runtime-terminal-retirement-host-partition.test.tssrc/main/runtime/orca-runtime-terminal-retirement.test.tssrc/main/runtime/orca-runtime.ts
…ition (stablyai#12671) `retireMobileSessionSurfacesForPty` called `getWorkspaceSession()` / `setWorkspaceSession()` with no host id, so every retirement wrote to the LOCAL partition — while its sibling `retirePersistedStablePaneOwner` correctly scopes to the SSH execution host. For an SSH pane exiting cleanly this is not a harmless misdirected write. Measured on main: the write went to the local partition instead of `ssh:conn-1`; the SSH partition still held the dead PTY binding; the local partition gained a bogus topology revision for an SSH repo; and the published tab list contained a RESURRECTED leaf hydrated back from the stale SSH partition. The wrong-partition write was accepted — a tombstone recorded and the revision advanced for a surface that could not be found. Found during independent review of stablyai#11542; pre-existing, not caused by it. Fixes STA-3463.
Fixes STA-3463.
Symptom
When a terminal pane on an SSH connection exits, its surface is never removed from that connection's persisted workspace session. The dead pane comes back as a ghost on the next hydrate. As a side effect, the local partition is mutated instead: it gains a topology-revision bump for a repo that lives on a different host.
Pre-existing; not caused by #11542.
Cause
OrcaRuntimeService.retireMobileSessionSurfacesForPtyread and wrote the workspace session with no execution-host id:Workspace sessions are partitioned per execution host (
local,ssh:<connectionId>,runtime:<envId>). The sibling routine insrc/main/ipc/pty.ts,retirePersistedStablePaneOwner, already scopes correctly viatoSshExecutionHostId(connectionId); the runtime path did not.Because
retireTerminalSurfaceFromPersistencestill records a tombstone and advances the topology revision for a surface it cannot find, the unqualified write was accepted against the local partition rather than being a harmless no-op — so the wrong partition was mutated and the right one was left stale.Fix
Group the retired surfaces by the execution host that owns each surface's worktree (
tryGetWorkspaceSessionHostIdForWorktree, the same resolver the rest of the runtime uses, which handles SSH repos, runtime environments, and folder workspaces), then read, apply and write each group against that host's own session partition.Extracted as
persistTerminalSurfaceRetirements. All prior semantics are preserved: the "no store API" and "flush failed" paths still publish nothing, and only surfaces individually accepted by persistence become publishable.Verification
New:
src/main/runtime/orca-runtime-terminal-retirement-host-partition.test.ts, driving a store with a real two-partition (local+ssh:conn-1) session map.Measured on
origin/mainbefore the fix, for an SSH pane whose PTY exits cleanly:setWorkspaceSessionundefined(local)ssh:conn-1terminalTopologyRevisionByRepoId{ "ssh-repo": 1 }tab::rightplus a resurrected leaftab::rightonlyBoth tests assert both partitions, including the negative safety assertion that the non-owning partition is not even reallocated (
toBeidentity).LOCAL_EXECUTION_HOST_ID(the old behavior) turns the suite red — 1 failed / 1 passed; restored: 2 passed.orca-runtime-terminal-retirement.test.tswere updated to assert the explicitLOCAL_EXECUTION_HOST_IDargument that local retirements now carry.src/main/runtime+src/main/ipc: 6420 passed / 0 failed.src/main+src/shared: 23240 passed. The only failures (ssh-connection-sftp-namespace,pty-subprocess,port-scan-command-execution, 6 tests) reproduce identically on cleanorigin/mainin this environment and are unrelated.pnpm run typecheck,oxlint,oxfmt --check: clean.Note for the reviewer
This is deliberately separate from the STA-3465 park-guard PR even though both live in
orca-runtime.ts. They touch different methods, have no textual overlap, and have very different risk profiles — this one is unambiguous bug-fixing and can land on its own.