Skip to content

feat(model-server): opt-in HTTP 529 retry for thinking-only /v1/messages turns - #4027

Open
linj-glitch wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/anthropic-thinking-only-retry
Open

linj-glitch wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/anthropic-thinking-only-retry

Conversation

@linj-glitch

@linj-glitch linj-glitch commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Add the default-off anthropic_thinking_only_max_retries option to the shared /v1/messages adapter: a completed end_turn with no visible text or tool call returns HTTP 529 with x-should-retry: true, so an Anthropic SDK can retry the unchanged request; truncations and other terminal outcomes return normally.

Retry budgets are private to each model instance and keyed by rollout ID plus request-body digest, require the stable /ng-rollout/<rollout-id>/v1/messages path, expire after one idle hour, and cap at 4096 active identities without evicting existing budgets; unprefixed requests fall through normally, visible or other terminal responses and exhausted-budget fallbacks clear the allowance, and sampled generations are finalized before 529 so capture calls are committed.

Retries are per process and resample failed-visible-output turns at the cost of extra model calls, so benchmark configurations must record the option and the client's retry allowance must cover the server limit; clients that do not retry 529 receive the error, and default zero retains existing behavior.

Validated head 565a1b8149a765db85add07edf9ce6d4ba2def98 additively merges main f70bf75c3c3eef60484044fc0cd992ff97f12029: the import conflict resolution retains this PR's OrderedDict retry budget and main's Awaitable streaming support from #5155. Independent review confirms the existing retry helpers, main's keepalive streaming, and capture behavior are preserved. Python 3.13 source-bound Anthropic, model, streaming, checkpoint-model, and token-capture tests pass 998 cases; pre-commit run --all-files, final diff/body guardwords, and git diff --check pass.

Earlier independent-rollout and visible-reset regressions failed on the prior implementation and pass with the fix, while the Anthropic SDK 0.109.2 loopback smoke used deterministic thinking-only then visible responses and confirmed identical-request retries, two model calls, visible output, and cleared accounting for JSON and SSE; that smoke and the original motivating Claude Code run were not rerun for this main integration, and no fresh real-model or benchmark-quality result is claimed.

This focused PR defines the opt-in retry contract without a separate issue, includes documentation and DCO sign-off, and was developed with AI assistance; current-head required CI and normal repository approval gates still apply.

@copy-pr-bot

copy-pr-bot Bot commented Oct 4, 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 yaoyu-33 added area:model Model servers, inference providers, and model adapters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as draft October 5, 2026 06:11
@linj-glitch
linj-glitch force-pushed the linj/anthropic-thinking-only-retry branch 2 times, most recently from d083ece to 997792a Compare October 8, 2026 00:20
@linj-glitch
linj-glitch marked this pull request as ready for review October 13, 2026 23:27
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 15, 2026
linj-glitch and others added 2 commits October 17, 2026 22:51
…ges turns

A reasoning model sometimes ends a generation inside an unclosed <think>:
the reasoning parser yields reasoning but no content and no tool call, and
/v1/messages returns a message whose only block is "thinking" with
stop_reason end_turn. Claude Code then appends "[Your previous response had
no visible output. Please continue and produce a user-visible response.]"
and re-sends the history with the earlier thinking stripped. For RL this is
doubly bad: the trajectory gets a synthetic user turn, and the re-rendered
history no longer extends the prompt of the previous call, so token-capture
lineage breaks. In one Claude Code RL run about 30% of rollouts hit this by
step 48.

With anthropic_thinking_only_max_retries=N the server answers such a turn
with HTTP 529 overloaded_error (x-should-retry: true, retry-after: 1). The
Anthropic SDK retries 529, so the client re-issues the unchanged request.
After N retries for the same request body (digest-keyed, bounded,
per-process tally) the thinking-only message is served as before, so a
model that keeps doing this still terminates. The sampled generation is
finalized before the 529 so external token staging does not leave an
uncommitted call behind. Default 0 keeps today's behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
@linj-glitch
linj-glitch force-pushed the linj/anthropic-thinking-only-retry branch from 3593ca9 to c9d977f Compare October 19, 2026 04:37
@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test c9d977f

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test 25d670f

@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test bb8120b

@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test b9f7705

@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test 2f40670

@linj-glitch

Copy link
Copy Markdown
Collaborator Author

/ok to test 565a1b8

This branch was previously deployed

1 inactive deployment
public — 565a1b81 Deployed Oct 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #8021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer sla:triage-overdue Review assignment is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants