Skip to content

fix(codex): resend only model failures that may clear - #5912

Draft
yaoyu-33 wants to merge 5 commits into
mainfrom
fix/codex-model-retries
Draft

yaoyu-33 wants to merge 5 commits into
mainfrom
fix/codex-model-retries

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Codex 0.144.4 has no per-status retry setting. Its turn-level retry (stream_max_retries, default 5) resends failed requests for statuses other than 400 and 429, including 500. Its request-level retry (request_max_retries, default 4) also resends 5xx and transport errors. A persistent 401, 409 or 422 therefore costs six requests, while a persistent 500 or 503 can cost 30. It never retries a 429 or reads Retry-After.

Gym's existing forwarders now own the harness retry rule:

  • Behind the forwarder, unset/null Codex retry settings become 0/0; explicit values remain unchanged.
  • Resend HTTP 408, 425, 429 and 5xx at most twice. Honor numeric Retry-After up to 10 seconds, otherwise wait 1 and 2 seconds.
  • Retry temporary connection failures. The Node launcher allow-lists connection error codes and does not retry HTTP parser or TLS certificate errors, or its idle timeout before response headers. The host forwarder makes one shared-client connection attempt per try and does not resend a connection timeout.
  • A truncated retryable error body does not discard the retryable HTTP status. Caller disconnects stop further resends.
  • Other HTTP statuses reach Codex immediately. Forwarded attempts retain the invocation identity. The forwarders are named model_retry_proxy and modelRetryProxy.

The host path is retained, including its shorter recovery window described below. The review fixes also repair the renamed import in the core keepalive-report tests and add boundary coverage and pinned-CLI cleanup.

Issue: no separate issue is needed; this implements the team's retry rule across harnesses. Related retry PRs: #5910, #5911 and #5913. This preserves the Node launcher/attempt-record boundary introduced in #5153.

Score and compatibility impact

  • Sandbox sessions, including Terminal-Bench-Science codex and codex_deepseek_flash, now interpret null retries as 0/0. They no longer inherit Codex's request/stream defaults.
  • A rejected 401, 403, 404, 409 or 422 reaches Codex after one request. A persistent 503 reaches it after three requests, with 3 seconds of default backoff, instead of 30 requests and roughly 25 seconds of backoff.
  • Output caps: the first response.incomplete ends the turn as graded incomplete. Codex no longer resamples the model after max_output_tokens, which can change benchmark scores.
  • Failures inside HTTP 200 streams: a dropped stream or response.failed event is not resent by the forwarder. Gym model servers can emit failures inside 200 streams for non-HTTP failures or after stream_keepalive_s opens the stream. The default session outcome policy retries the episode for infrastructure failures. The TB-Science DeepSeek keepalive preset can therefore repeat hours of preceding task work instead of resending one model request.
  • Deprecated host /run: it already sends an empty assistant response to verification when Codex fails, which can score 0. The shorter retry window can expose an outage of a few seconds to that behavior sooner. It has the shared client's connection timeout (from fix(client): bound retries between Gym servers and the TCP handshake #6013), but no per-request header/body idle deadline; the overall agent timeout still bounds the run. Session infrastructure-failure classification is preferred.
  • Explicit retry settings remain effective. For TB-Science, ++tbsci_codex_stream_max_retries=5 restores Codex's turn resends, including rejected 4xx requests and output-cap resampling. Request retries above 0 multiply the forwarder's attempts.

Validation

Workstation: Python 3.13.15, aiohttp 3.14.4, Node 22.22.2, Codex 0.144.4; dependencies synced with uv sync --python 3.13 --frozen from the adapter directory (uv 0.13.7).

  • CODEX_TEST_BIN=<pinned 0.144.4> RAY_TMPDIR=/tmp responses_api_agents/codex_agent/.venv/bin/python -m pytest responses_api_agents/codex_agent/tests tests/unit_tests/core/test_streamed_failure_reports.py -q: 644 passed, no skips, one dependency deprecation warning, 114.30 seconds. Includes output-cap forwarder/no-forwarder variants, actual HTTP transport and Retry-After tests, caller cancellation, and core keepalive failure-report propagation.
  • pre-commit run --files <12 touched files>: passed. node --check responses_api_agents/codex_agent/sandbox_launcher.mjs and git diff --check: passed.
  • Repository search: no remaining rate_limit_proxy or rateLimitProxy references.
  • New regressions reproduced four failures before the fixes: truncated 429 and 503 bodies, host resends after caller disconnect, and malformed HTTP replies retried by Node.
  • Latest base b06f0245b70939517f8897fcbd2eef0658e6a948 was merged first; merge and repair commits have DCO sign-off. No rebase or force-push.

Exact commands, logs, review dispositions and diff: /home/yuya/Projects/pr-flow/runs/20261117-011429-pr5912-fix (machine-local). CI is requested separately for the pushed head; no full-repository CI pass is claimed.

Smoke evidence and remaining gate

The earlier scripted-model conformance comparison used Codex 0.144.4, the outcome-ladder stack (#5873, #5877, #5875, #5879, #5880), and this PR together with the other retry PRs. These are historical results from 2026-11-09, not validation of this repaired head:

Scenario Before retry changes With retry changes
model_401 6 requests → rejected → fail 1 request → same outcome
model_503 30 requests → transient failure → retry episode 3 requests → same outcome
model_error (400) 1 request → rejected → fail same
retry_429, retry_500 completed → verify same
context_overflow incomplete → verify same

That scripted endpoint used Retry-After: 0 and did not cover keepalive or output caps. Fresh real-model rollouts remain required at the smoke stage: session presets, output-cap outcomes, episode retries whose last model attempt was HTTP 200, and request counts per failed call. The PR remains a draft until that evidence is attached.

Harness-side model retries may cover only 408, 425, 429, 5xx and transport
errors, with a bounded total wait. Codex 0.144.4 has no per-status setting:
its turn-level retry resends every status but 400, 429 and 500 five more
times (a scripted 401 was sent six times), a persistent 503 cost 30 requests
and about 25 s, and it never reads Retry-After.

Gym's forwarder already sits in front of Codex in every sandbox session and
in host runs with a rollout and a model server, so it now owns the rule:

- request_max_retries and stream_max_retries default to 0 there (an explicit
  value still wins);
- the forwarder (transport.py on the host, sandbox_launcher.mjs in the
  sandbox) resends a 408, 425, 429 or 5xx and a refused or dropped
  connection at most twice, waiting Retry-After capped at 10 s, else 1 s and
  2 s; every other status reaches Codex on the first attempt;
- the forwarders are renamed for what they now do.

A stream that drops after its headers is no longer resent; Gym model
servers send the whole stream at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test dd402e7

@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Nov 16, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test cd81c82

This branch was previously deployed

1 inactive (outdated) deployment
public — dd402e79 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants