From de89882c7f9b5715b10a04d9782bf57593d76349 Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Mon, 9 Feb 2026 10:02:37 +0900 Subject: [PATCH] =?UTF-8?q?Codex=20abort=20=E6=99=82=E3=81=AE=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=82=92=E3=82=BF=E3=82=A4=E3=83=A0=E3=82=A2=E3=82=A6=E3=83=88?= =?UTF-8?q?=E3=81=A8=E5=A4=96=E9=83=A8=E4=B8=AD=E6=96=AD=E3=81=A7=E5=8C=BA?= =?UTF-8?q?=E5=88=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/infra/codex/client.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/infra/codex/client.ts b/src/infra/codex/client.ts index 5c5d2b1..aed7248 100644 --- a/src/infra/codex/client.ts +++ b/src/infra/codex/client.ts @@ -24,6 +24,7 @@ export type { CodexCallOptions } from './types.js'; const log = createLogger('codex-sdk'); const CODEX_STREAM_IDLE_TIMEOUT_MS = 10 * 60 * 1000; +const CODEX_STREAM_ABORTED_MESSAGE = 'Codex execution aborted'; /** * Client for Codex SDK agent interactions. @@ -58,18 +59,21 @@ export class CodexClient { let idleTimeoutId: ReturnType | undefined; const streamAbortController = new AbortController(); - const abortMessage = `Codex stream timed out after ${Math.floor(CODEX_STREAM_IDLE_TIMEOUT_MS / 60000)} minutes of inactivity`; + const timeoutMessage = `Codex stream timed out after ${Math.floor(CODEX_STREAM_IDLE_TIMEOUT_MS / 60000)} minutes of inactivity`; + let abortCause: 'timeout' | 'external' | undefined; const resetIdleTimeout = (): void => { if (idleTimeoutId !== undefined) { clearTimeout(idleTimeoutId); } idleTimeoutId = setTimeout(() => { + abortCause = 'timeout'; streamAbortController.abort(); }, CODEX_STREAM_IDLE_TIMEOUT_MS); }; const onExternalAbort = (): void => { + abortCause = 'external'; streamAbortController.abort(); }; @@ -202,7 +206,11 @@ export class CodexClient { }; } catch (error) { const message = getErrorMessage(error); - const errorMessage = streamAbortController.signal.aborted ? abortMessage : message; + const errorMessage = streamAbortController.signal.aborted + ? abortCause === 'timeout' + ? timeoutMessage + : CODEX_STREAM_ABORTED_MESSAGE + : message; emitResult(options.onStream, false, errorMessage, threadId); return {