From 447a03f89af3fee18fab75c2cd7577fea70fd032 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:14:07 -0700 Subject: [PATCH] fix(runtime): retire stale pane agent identity --- ...-provider-reattach-launch-identity.test.ts | 24 +++++++++++++++++++ src/main/runtime/orca-runtime.test.ts | 7 ++++++ src/main/runtime/orca-runtime.ts | 3 ++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts b/src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts index 8b836038265..a463dd75cf4 100644 --- a/src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts +++ b/src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts @@ -73,4 +73,28 @@ describe('provider reattach launch identity', () => { launchIncarnationId: null }) }) + + it('retires daemon launch identity when the agent command finishes', () => { + const runtime = new OrcaRuntimeService(null) + + runtime.registerPty('pty-finished-reattach', WORKTREE_ID, null, { + tabId: TAB_ID, + leafId: LEAF_ID, + incarnationId: INCARNATION_ID, + providerReattachLaunchIdentity: { + incarnationId: INCARNATION_ID, + launchAgent: 'codex' + } + }) + runtime.emitDaemonPtyTransientFact('pty-finished-reattach', { + kind: 'command-finished', + exitCode: 0 + }) + + expect(getPty(runtime, 'pty-finished-reattach')).toMatchObject({ + launchAgent: null, + launchToken: null, + launchIncarnationId: null + }) + }) }) diff --git a/src/main/runtime/orca-runtime.test.ts b/src/main/runtime/orca-runtime.test.ts index 7d28c1f9ee8..1f610cd581e 100644 --- a/src/main/runtime/orca-runtime.test.ts +++ b/src/main/runtime/orca-runtime.test.ts @@ -13330,6 +13330,7 @@ describe('OrcaRuntimeService', () => { const terminal = await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { command: 'codex', + launchAgent: 'codex', launchConfig: { agentCommand: 'codex', agentArgs: '', agentEnv: {} } }) const spawnEnv = @@ -13346,6 +13347,9 @@ describe('OrcaRuntimeService', () => { launchToken: spawnEnv.ORCA_AGENT_LAUNCH_TOKEN }) ).toBeDefined() + expect((await runtime.listTerminals()).terminals).toEqual([ + expect.objectContaining({ handle: terminal.handle, agentIdentity: 'codex' }) + ]) runtime.onPtyData('pty-authority', '\x1b]133;D;0\x07', 100) @@ -13356,6 +13360,9 @@ describe('OrcaRuntimeService', () => { launchToken: spawnEnv.ORCA_AGENT_LAUNCH_TOKEN }) ).toBeUndefined() + expect((await runtime.listTerminals()).terminals).toEqual([ + expect.not.objectContaining({ agentIdentity: expect.anything() }) + ]) }) it('retires only receipted restored PTY authority on command completion and exit', () => { diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index e3f670f4a10..e837d740087 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -14063,13 +14063,14 @@ export class OrcaRuntimeService { return } const receipt = this.restoredOrchestrationAuthorityByPtyId.get(ptyId) - if (!pty.launchToken && !receipt) { + if (!pty.launchToken && !receipt && !pty.launchAgent) { return } const paneKeys = this.collectPaneKeysForPty(ptyId) this.restoredOrchestrationAuthorityByPtyId.delete(ptyId) pty.launchToken = null pty.launchIncarnationId = null + pty.launchAgent = null for (const paneKey of paneKeys) { this.retireAgentHookCompatibilityAuthorityFn?.(paneKey) }