diff --git a/src/main/runtime/orca-runtime-tests/worker-recovery-releases-conversation.test.ts b/src/main/runtime/orca-runtime-tests/worker-recovery-releases-conversation.test.ts index bf1d62bc008..eb2bdf71f46 100644 --- a/src/main/runtime/orca-runtime-tests/worker-recovery-releases-conversation.test.ts +++ b/src/main/runtime/orca-runtime-tests/worker-recovery-releases-conversation.test.ts @@ -72,6 +72,7 @@ describe('worker terminal recovery after a crash', () => { hasPty: () => false, listProcesses: async () => [] }) + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: recovery calls only this notifier method. runtime.setNotifier({ resolveLegacyWorkerTerminalRecovery: vi.fn() } as never) await expect(runtime.reconcileLegacyWorkerTerminals()).resolves.toMatchObject({ diff --git a/src/main/runtime/orchestration/terminal-authority/legacy-worker-terminal-surface.ts b/src/main/runtime/orchestration/terminal-authority/legacy-worker-terminal-surface.ts index ad35bd1b190..9fd717c67e4 100644 --- a/src/main/runtime/orchestration/terminal-authority/legacy-worker-terminal-surface.ts +++ b/src/main/runtime/orchestration/terminal-authority/legacy-worker-terminal-surface.ts @@ -78,8 +78,17 @@ export abstract class LegacyWorkerTerminalSurface extends OrcaRuntimeWithRestore if (pty && this.paneOfPty(pty).tabId === candidate.tabId) { forgetPtySurface(this.terminalIdentity, pty) } - // Why: an exit this run never saw leaves the pane's restored hook row holding the conversation. - this.reconcileAgentStatusForEndedProcessFn?.([candidate.paneKey]) + // Why: an exit this run never saw leaves the pane's restored hook row holding the conversation; + // a newer terminal already in the pane owns that row. + const paneTakenOver = + (leaf?.ptyId && leaf.ptyId !== candidate.ptyId) || + [...this.ptysById.values()].some( + (other) => + other.ptyId !== candidate.ptyId && this.paneOfPty(other).paneKey === candidate.paneKey + ) + if (!paneTakenOver) { + this.reconcileAgentStatusForEndedProcessFn?.([candidate.paneKey]) + } this.notifier?.resolveLegacyWorkerTerminalRecovery?.( candidate.paneKey, 'rolled_back',