feat: turn-level timeout — bound Codex turn await (port from openai#376, closes #25)#26
Merged
Conversation
Closes fork#25. If Codex CLI can't reach the OpenAI API (network down, DNS misconfigured), captureTurn's 'await state.completion' hangs forever — no turn-level timeout, rejectCompletion was dead code (zero call sites). Ported from @russjhammond's openai#376: - Wire rejectCompletion to client.exitPromise: app-server death after startRequest rejects the await immediately instead of hanging. - Add deadline via Promise.race: hard per-turn budget (default 600s bg, 110s foreground — just below Claude Code Bash tool ceiling). - resolveTurnTimeoutMs reads CODEX_TURN_TIMEOUT_MS at CALL time, not import time (companion sets env after import — import-time read was inert). - applyForegroundTurnBudget: foreground commands get 110s budget so a stalled turn returns a structured error instead of being SIGKILLed. - --turn-timeout-ms flag on review/adversarial-review/task for manual override. Verified: 166 tests, 162 pass / 4 pre-existing (unchanged). Refs fork#25, openai#49, openai#489, openai#376 (@russjhammond). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
|
Cycle 1 triage: Codex found 3 extensions (not bugs — the port is faithful and correct). Claude APPROVE (all 5 concerns verified: exitPromise wiring no race, deadline no leak, env parsing correct, fg/bg split correct, edge cases handled). Codex findings are real but all are FUTURE improvements:
The port solves the stated problem (hang forever → bounded timeout with structured error). Extensions tracked separately. Merge ready. |
axisrow
added a commit
that referenced
this pull request
Jul 20, 2026
…y guards) Simplify review of PR #26 found exitRaceSettled redundant: JS promises silently ignore any settle after the first, so rejectCompletion on an already-settled promise is a no-op. state.completed is the load-bearing guard (protects against late-arriving exit after normal completion); exitRaceSettled was the weaker half. Skipped: S1 (options.turnTimeoutMs dead code — altitude-AGNT recommends threading the value through options instead of env side-channel, but that's a refactor changing 4 signatures, not a simplify); S3 (handleTask missing background guard — already safe via early-return at line 882); S4 (Number.isFinite duplication — 3 lines, not worth a lib/timing.mjs module). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 20, 2026
axisrow
added a commit
that referenced
this pull request
Jul 20, 2026
…st, thread through options (closes #27) Three gaps from Codex cycle-review of PR #26: 1. Timed-out turn not interrupted: deadline rejected the await but turn/interrupt was never sent. The broker kept executing a write-capable turn after it was reported failed. Fix: catch deadline rejection, best-effort interruptAppServerTurn(cwd, {threadId, turnId}), re-throw. 2. Deadline armed after turn/start response: a stalled turn/start (app-server alive but not responding) was unbounded. Fix: arm the deadline BEFORE startRequest, race the entire lifecycle (startRequest + completion) against it. If the deadline fires during startRequest, there's no turnId to interrupt, but the process no longer hangs. 3. --turn-timeout-ms ignored for background: applyForegroundTurnBudget was foreground-only (env side-channel gated by if(!options.background)). Replaced with options threading: resolveTurnTimeoutMsFromOptions resolves the value from the flag/env/default (foreground=110s, background=600s), passes it through buildTaskRequest → handleTaskWorker → executeTaskRun → runAppServerTurn → captureTurn → resolveTurnTimeoutMs. Deleted applyForegroundTurnBudget (env side-channel gone). Env fallback (CODEX_TURN_TIMEOUT_MS) remains for operator-configured overrides. Also threads cwd into captureTurn options (needed by the interrupt path). Verified: 166 tests, 162 pass / 4 pre-existing (unchanged). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
axisrow
added a commit
that referenced
this pull request
Jul 20, 2026
…st, thread through options (closes #27) (#28) Three gaps from Codex cycle-review of PR #26: 1. Timed-out turn not interrupted: deadline rejected the await but turn/interrupt was never sent. The broker kept executing a write-capable turn after it was reported failed. Fix: catch deadline rejection, best-effort interruptAppServerTurn(cwd, {threadId, turnId}), re-throw. 2. Deadline armed after turn/start response: a stalled turn/start (app-server alive but not responding) was unbounded. Fix: arm the deadline BEFORE startRequest, race the entire lifecycle (startRequest + completion) against it. If the deadline fires during startRequest, there's no turnId to interrupt, but the process no longer hangs. 3. --turn-timeout-ms ignored for background: applyForegroundTurnBudget was foreground-only (env side-channel gated by if(!options.background)). Replaced with options threading: resolveTurnTimeoutMsFromOptions resolves the value from the flag/env/default (foreground=110s, background=600s), passes it through buildTaskRequest → handleTaskWorker → executeTaskRun → runAppServerTurn → captureTurn → resolveTurnTimeoutMs. Deleted applyForegroundTurnBudget (env side-channel gone). Env fallback (CODEX_TURN_TIMEOUT_MS) remains for operator-configured overrides. Also threads cwd into captureTurn options (needed by the interrupt path). Verified: 166 tests, 162 pass / 4 pre-existing (unchanged). Co-authored-by: axisrow <axisrow@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes fork#25. Port of @russjhammond's openai#376.
If Codex CLI can't reach the OpenAI API, captureTurn hangs forever — rejectCompletion was dead code. This PR wires it to exitPromise + adds a deadline (Promise.race). Foreground budget 110s (below Bash ceiling), background 600s, configurable via CODEX_TURN_TIMEOUT_MS or --turn-timeout-ms. 166 tests, 162 pass / 4 pre-existing.