diff --git a/electron/ipc/pty.test.ts b/electron/ipc/pty.test.ts index 8b7f2d420..cf3b18047 100644 --- a/electron/ipc/pty.test.ts +++ b/electron/ipc/pty.test.ts @@ -1255,6 +1255,21 @@ describe('spawnAgent output batching', () => { expect(expected[expected.length - 1]).toBe(lines[99]); }); + it.each([ + { name: 'a clean exit (signal 0)', exitCode: 0, signal: 0, expected: null }, + { name: 'no signal', exitCode: 1, signal: undefined, expected: null }, + { name: 'a kill', exitCode: 0, signal: 15, expected: '15' }, + ])('reports $name as signal $expected', async ({ exitCode, signal, expected }) => { + const { notify, proc } = await launch(`agent-exit-signal-${String(signal)}`); + proc.emitExit({ exitCode, signal }); + + const exit = vi + .mocked(notify) + .mock.calls.map(([, message]) => message as { type: string; data?: unknown }) + .find((payload) => payload.type === 'Exit'); + expect(exit?.data).toMatchObject({ exit_code: exitCode, signal: expected }); + }); + it('sends raw bytes to the window and base64 to subscribers', async () => { const { notify, proc } = await launch('agent-batch-subscriber'); const sub = vi.fn(); diff --git a/electron/ipc/pty.ts b/electron/ipc/pty.ts index 867cd0cb7..358d0879f 100644 --- a/electron/ipc/pty.ts +++ b/electron/ipc/pty.ts @@ -748,7 +748,9 @@ function attachPtyOutputHandlers( type: 'Exit', data: { exit_code: exitCode, - signal: signal !== undefined ? String(signal) : null, + // node-pty reports signal 0 for a normal exit on Unix; only a real + // signal number is one, or the renderer reads a clean exit as killed. + signal: signal ? String(signal) : null, last_output: lines, }, }); diff --git a/src/components/TaskAITerminal.tsx b/src/components/TaskAITerminal.tsx index 701b03f9a..15eba9e03 100644 --- a/src/components/TaskAITerminal.tsx +++ b/src/components/TaskAITerminal.tsx @@ -957,7 +957,7 @@ function AgentTerminalPane(props: { props.task.codexChatHandoff ) { const threadId = - code.exit_code === 0 && (!code.signal || code.signal === '0') + code.exit_code === 0 && !code.signal ? codexResumeId(code.last_output.join('\n')) : undefined; // /new and /model in the CLI may change the session or its settings.