Skip to content

fix(runtime): retire an exited pane's surface in its owning host partition (STA-3463) - #12671

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/retire-terminal-surface-in-owning-host-partition
Aug 5, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/retire-terminal-surface-in-owning-host-partition

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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.retireMobileSessionSurfacesForPty read and wrote the workspace session with no execution-host id:

const session = this.store?.getWorkspaceSession?.()   // -> always the local partition
...
this.store.setWorkspaceSession(nextSession)           // -> always writes the local partition

Workspace sessions are partitioned per execution host (local, ssh:<connectionId>, runtime:<envId>). The sibling routine in src/main/ipc/pty.ts, retirePersistedStablePaneOwner, already scopes correctly via toSshExecutionHostId(connectionId); the runtime path did not.

Because retireTerminalSurfaceFromPersistence still 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/main before the fix, for an SSH pane whose PTY exits cleanly:

observation before after
host id passed to setWorkspaceSession undefined (local) ssh:conn-1
SSH partition's persisted pane still bound to the dead PTY retired
local partition terminalTopologyRevisionByRepoId { "ssh-repo": 1 } untouched
published tabs tab::right plus a resurrected leaf tab::right only

Both tests assert both partitions, including the negative safety assertion that the non-owning partition is not even reallocated (toBe identity).

  • Mutation check: replacing the resolved host id with LOCAL_EXECUTION_HOST_ID (the old behavior) turns the suite red — 1 failed / 1 passed; restored: 2 passed.
  • Two existing assertions in orca-runtime-terminal-retirement.test.ts were updated to assert the explicit LOCAL_EXECUTION_HOST_ID argument 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 clean origin/main in 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.

…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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the runtime fix for retiring exited panes in their owning host partition.
Description check ✅ Passed The description clearly explains the symptom, cause, fix, testing, regression coverage, and known unrelated failures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/main/runtime/orca-runtime-terminal-retirement-host-partition.test.ts (2)

102-132: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Type the mock store instead of never, and drop the unused reads field.

store: never makes the field unusable without another cast. The second test already works around this with ...(harness.store as object) at Line 250. Use unknown in the harness type and keep a single cast at the constructor call site. This also keeps the mock shape visible to type checking.

reads is 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 value

Parameterize syncSshSplit instead of duplicating the window-graph setup.

Lines 258-307 restate the structure of syncSshSplit with local ids. If the syncWindowGraph payload 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

📥 Commits

Reviewing files that changed from the base of the PR and between c4d5a53 and e127a7c.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime-terminal-retirement-host-partition.test.ts
  • src/main/runtime/orca-runtime-terminal-retirement.test.ts
  • src/main/runtime/orca-runtime.ts

@Jinwoo-H
Jinwoo-H merged commit 9509856 into main Aug 5, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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