Skip to content

fix(claude_code): send each model request once - #5911

Draft
yaoyu-33 wants to merge 1 commit into
mainfrom
fix/claude-code-model-retries
Draft

yaoyu-33 wants to merge 1 commit into
mainfrom
fix/claude-code-model-retries

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

What and why

The team's rule for harness-side model retries: resend a failed model request only after a 408, 425, 429, 5xx or a transport error, never after any other 4xx, and keep the total wait bounded.

Claude Code 2.1.108 (read from its npm bundle) resends a failed model request ten times, waiting min(500 ms × 2^(n−1), 32 s) plus jitter, 160–200 s in all. It treats 401 (meant for refreshing an OAuth token or apiKeyHelper key, but unconditional) and 409 like a 5xx. A scripted-model smoke saw a persistent 401 sent 11 times over about 180 s, and a persistent 503 tried 11 times over about 192 s. The CLI has no setting that leaves statuses out: CLAUDE_CODE_MAX_RETRIES only sets the count. So both launch paths (host /run and sandbox sessions) now set CLAUDE_CODE_MAX_RETRIES=0: each model request is sent once. The Model Server still retries its own upstream failures (a single upstream 503 is absorbed there; see the smoke), and the Environment Server retries the episode after a 408, 425, 429 or 5xx.

One native resend remains, documented in the README: after a 404 when the stream is created, or a stream that fails midway, the CLI sends the request once more without streaming.

Not done here: the CLI honours an x-should-retry: false response header before its 401/409 rules. A Gym model server that sent that header on every 4xx other than 408/425/429 would let Claude Code (and every OpenAI/Anthropic SDK client) keep a few retries for 5xx while never resending a rejected request. That is a Model Server change and would be its own PR.

Issue: no public issue; this implements the retry rule the team agreed for all harnesses. The other harness groups are in separate PRs (Codex; OpenCode and Kilo Code; NOOA, Hermes and Stirrup).

Related: #5910 (NOOA, Hermes, Stirrup), #5911 (Claude Code), #5912 (Codex), #5913 (OpenCode, Kilo Code).

Score and compatibility impact

  • A persistent 401/409/5xx now ends the run after one CLI attempt instead of about three minutes of resends. The reported outcome is unchanged, so the Environment Server takes the same action, sooner.
  • A transient model-server 5xx or dropped connection that the CLI used to ride out now ends the run, and the Environment Server retries the episode. The Model Server's own upstream retries are unchanged.

Validation

  • claude_code_agent/tests on a Linux workstation in the adapter's uv sync --frozen venv: 197 passed. Both env tests now assert CLAUDE_CODE_MAX_RETRIES=0.
  • pre-commit run --files <changed files>: passed. Commit signed off.

Smoke evidence

Scripted-model smoke (no real model), Linux workstation, 2026-11-09. Claude Code is not in the conformance registry, so this uses the chain the outcome-ladder smokes used: a driver seeds and activates an agent session (local sandbox provider, pinned runtime 2.1.108) → Claude Code → a real Gym vllm_model → a scripted chat-completions endpoint. A = the outcome-ladder stack (#5873 with #5877, #5875, #5879 and #5880 merged), which carries #5877's Claude Code adapter; B = A plus this commit and the other three retry PRs' commits. The Environment Server action is computed with agent_response_action.

Scenario A B
answer completed → verify same
400 on the first request 1 request → failed model_request_rejected → fail same
persistent 401 11 CLI requests over 185 s (the model server stops forwarding after the first 401) → failed model_request_rejected → fail 1 request, 0.7 s → same
persistent 503 33 endpoint calls (11 CLI attempts × 3 vllm_model tries), 207 s → failed model_request_error 503 → retry 3 endpoint calls (1 CLI attempt × 3 vllm_model tries), 1.5 s → same
one 503, then an answer vllm_model retries it; completed → verify (1.6 s) same (0.8 s)

Real-model rollouts: not run yet; this PR stays a draft until they are.

🤖 Generated with Claude Code

Harness-side model retries may cover only 408, 425, 429, 5xx and transport
errors, with a bounded total wait. Claude Code 2.1.108 resends a failed
model request ten times, 0.5 s to 32 s apart (160-200 s in all), and treats
401 and 409 like a 5xx: a scripted 401 was sent 11 times over about 180 s.
It has no setting that leaves those statuses out, so both launch paths now
set CLAUDE_CODE_MAX_RETRIES=0. The Model Server still retries its upstream,
and the Environment Server retries the episode after a 408/425/429/5xx.

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 a559edf

@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

This branch was previously deployed

1 inactive deployment
public — a559edf0 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11284
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