Skip to content

fix(anthropic): keep unsigned thinking blocks as thinking on replay - #4461

Open
cmunley1 wants to merge 3 commits into
mainfrom
cmunley1/anthropic-thinking-signature
Open

cmunley1 wants to merge 3 commits into
mainfrom
cmunley1/anthropic-thinking-signature

Conversation

@cmunley1

@cmunley1 cmunley1 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

vLLM returns thinking blocks without a signature, and the synthesized Messages stream never sent a signature_delta. Some clients replay an unsigned thinking block as a text block, which rewrites the assistant turn on the next request. Token capture then starts a new training path for every model call (40-56 per rollout in a run, instead of ~1).

NEMO_GYM_ANTHROPIC_THINKING_SIGNATURE (off by default) puts a placeholder signature on unsigned thinking blocks, and the SSE synthesizer now streams signatures as signature_delta. In a small Gym eval this took affected clients from 170-240 paths to 4. Unit tests added.

@copy-pr-bot

copy-pr-bot Bot commented Oct 12, 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.

vLLM returns thinking blocks without a signature, and the synthesized
Messages stream never sent a signature_delta. Some clients turn an
unsigned thinking block into a text block when they replay history, so
the next request rewrites the assistant turn and token capture splits
every model call into its own training path.

Set NEMO_GYM_ANTHROPIC_THINKING_SIGNATURE to put a placeholder signature
on thinking blocks that have none, and stream any signature as a
signature_delta. Off by default.

Signed-off-by: Christian Munley <[email protected]>
@cmunley1
cmunley1 force-pushed the cmunley1/anthropic-thinking-signature branch from 727583f to 522aabf Compare October 12, 2026 08:17
@cmunley1
cmunley1 marked this pull request as ready for review October 15, 2026 07:21
@yaoyu-33 yaoyu-33 added area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 15, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 16, 2026
@cmunley1

Copy link
Copy Markdown
Contributor Author

/review

@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test 522aabf

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD — the placeholder signature breaks replay through Chat Completions-backed vLLM servers, and streamed observability captures discard the newly emitted signatures.

Reviewed both changed files and traced signature generation, SSE synthesis, request replay, and capture reconstruction. Two findings below. Validation was source-only; tests could not be executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex

"type": "thinking",
"thinking": summary["text"],
"signature": item.get("encrypted_content") or "",
"signature": item.get("encrypted_content") or _PLACEHOLDER_SIGNATURE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKER — Consume the placeholder signature on replay

Failure / blast radius: Start Gym with NEMO_GYM_ANTHROPIC_THINKING_SIGNATURE=gym-unsigned, obtain a thinking block from /v1/messages, and replay that block in the next request. The ingress thinking branch copies gym-unsigned into encrypted_content. VLLMModel.responses then downconverts through ResponsesConverter._format_reasoning, which rejects every nonempty encrypted_content. Thus clients that preserve thinking as intended now fail the next model call with NotImplementedError/HTTP 500 instead of continuing the rollout. Both streaming and non-streaming Messages replies introduce this sentinel.

Correction: Treat the configured placeholder as a reserved, wire-only sentinel. In _append_anthropic_blocks_as_items's thinking branch, replace the encrypted_content argument with:

encrypted_content=(
    None
    if _PLACEHOLDER_SIGNATURE
    and block.get("signature") == _PLACEHOLDER_SIGNATURE
    else block.get("signature")
),

Keep adding the placeholder on outbound Messages replies. Do not remove the shared Chat converter's guard or strip arbitrary signatures: genuine opaque reasoning must still be preserved or rejected rather than silently discarded. This targeted suggestion needs author verification.

Preservation / proposed acceptance checks: With the sentinel configured, render unsigned reasoning step plus text ok, replay the resulting thinking/text blocks through ingress, then downconvert with ResponsesConverter(return_token_id_information=False). Assert the replayed reasoning has encrypted_content is None and the assistant chat content is ok, without an exception. Cover the SSE-produced replay too. Retain the existing unsigned/default-empty behavior when the setting is unset and the placeholder emission assertions. A distinct real signature such as sig-1 must still survive ingress unchanged, as asserted by test_thinking_block_becomes_reasoning_item; the opaque-content rejection test must continue raising. These checks were not executed.

return [{"type": "thinking_delta", "thinking": block.get("thinking", "")}]
deltas = [{"type": "thinking_delta", "thinking": block.get("thinking", "")}]
if block.get("signature"):
deltas.append({"type": "signature_delta", "signature": block["signature"]})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK — Update capture reconstruction for the new signature delta

Failure / blast radius: Stream a thinking block with signature s through a rollout-correlated Messages endpoint with observability enabled. This new event delivers s to the client, but _reconstruct_anthropic_sse handles only text, thinking, and tool-input deltas. The capture middleware persists that reconstruction, so its parsed response contains signature: "" while the served response contains signature: "s". The same mismatch affects placeholder signatures. Raw SSE remains available, but consumers of the structured captured response lose the signature needed for faithful replay.

Correction: Add this branch to _reconstruct_anthropic_sse, adjacent to thinking_delta and before input_json_delta:

elif dtype == "signature_delta":
    block["signature"] = (block.get("signature") or "") + (
        delta.get("signature") or ""
    )

The invariant is that capture reconstructs the same thinking text and signature delivered on the wire, including fragmented signatures. Keep the signature in deltas rather than moving it into the start shell. Suggested code is source-reasoned, not executed; verify before adopting.

Preservation / proposed acceptance checks: Synthesize a complete message containing signed thinking, text, and a tool call, then pass the encoded SSE to _reconstruct_streamed_response(..., "messages"); assert reconstructed content equals the original content for both s and gym-unsigned. Also assert signature fragments a and b reconstruct as ab, and unsigned thinking remains unsigned. Preserve the existing capture regression assertions: input/output token counts remain 17/7, reasoning remains let me think, the tool arguments remain {"x": 1}, and response_raw remains identical to the forwarded SSE. These checks were not executed.

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 19, 2026
@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test 522aabf

@cmunley1

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD — both prior findings remain unresolved: placeholder replay still fails, and capture reconstruction still drops streamed signatures.

Same-head follow-up to review 5577278701. Rechecked both changed files and traced the directly affected replay and capture paths. There are no inter-review changes or verified fixes; no fresh whole-PR discovery was performed. Validation was source-only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

"type": "thinking",
"thinking": summary["text"],
"signature": item.get("encrypted_content") or "",
"signature": item.get("encrypted_content") or _PLACEHOLDER_SIGNATURE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKER — Consume the placeholder signature on replay

Still unresolved from review 5577278701, comment 4318466390.

Failure / blast radius: Set NEMO_GYM_ANTHROPIC_THINKING_SIGNATURE=gym-unsigned, obtain unsigned reasoning step plus text ok from /v1/messages, and replay the returned thinking/text blocks. The ingress thinking branch copies the placeholder into encrypted_content. VLLMModel.responses downconverts through ResponsesConverter._format_reasoning, which rejects nonempty encrypted content. Clients preserving thinking therefore fail their next model call with NotImplementedError/HTTP 500 instead of continuing. Both JSON and synthesized SSE replies introduce this sentinel.

Correction: Reserve the configured placeholder as a wire-only sentinel. In _append_anthropic_blocks_as_items's thinking branch, replace the encrypted_content argument with:

encrypted_content=(
    None
    if _PLACEHOLDER_SIGNATURE
    and block.get("signature") == _PLACEHOLDER_SIGNATURE
    else block.get("signature")
),

Keep outbound placeholder emission. Only the configured sentinel should be consumed; do not strip arbitrary signatures or weaken the shared Chat converter's opaque-content guard.

Preservation / proposed acceptance checks: With the sentinel configured, render unsigned step plus text ok, replay the JSON blocks and separately the client-assembled SSE blocks, then downconvert using ResponsesConverter(return_token_id_information=False). Assert the reasoning retains summary step, has encrypted_content is None, and produces assistant content ok without raising. With the setting unset, retain empty outbound signatures and no signature delta. Preserve the placeholder/default and genuine-signature output assertions. A distinct genuine signature sig-1 must still survive ingress unchanged, as in the existing ingress test, and opaque reasoning rejection must continue raising. Suggested code is source-reasoned, not executed; verify before adopting.

return [{"type": "thinking_delta", "thinking": block.get("thinking", "")}]
deltas = [{"type": "thinking_delta", "thinking": block.get("thinking", "")}]
if block.get("signature"):
deltas.append({"type": "signature_delta", "signature": block["signature"]})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK — Reconstruct signature deltas in streamed captures

Still unresolved from review 5577278701, comment 4318466398.

Failure / blast radius: Stream a thinking block with signature s through a rollout-correlated Messages endpoint with observability enabled. The client receives signature_delta, but _reconstruct_anthropic_sse handles only text, thinking, and tool-input deltas. The capture middleware persists that reconstruction, leaving signature: "" in the structured response instead of signature: "s". Placeholder signatures are also lost. Raw SSE remains intact, but structured captures cannot faithfully replay the served thinking block.

Correction: In _reconstruct_anthropic_sse, insert this branch after thinking_delta, before input_json_delta:

elif dtype == "signature_delta":
    block["signature"] = (block.get("signature") or "") + (
        delta.get("signature") or ""
    )

The invariant is that reconstruction preserves the signature delivered on the wire, including fragments. Keep the empty start shell and signature-delta protocol; do not move the signature into the shell to bypass reconstruction.

Preservation / proposed acceptance checks: Generate a complete thinking/text/tool response with anthropic_response_to_sse, encode it, and call _reconstruct_streamed_response(..., "messages"). Assert reconstructed content equals the original for signatures s, gym-unsigned, and ""; separately assert fragments a and b reconstruct as ab. Unsigned input with no signature field must remain without one when no signature delta occurs. Retain the stream tests' empty-shell, ordered-delta, and unsigned-no-delta assertions. Preserve the capture regression: token counts 17/7, reasoning let me think, tool arguments {"x": 1}, and response_raw identical to forwarded SSE. Suggested code and checks are source-reasoned, not executed; verify before adopting.

…signature deltas

The placeholder signature only exists on the wire. When a client replayed a
thinking block that carried it, ingress copied it into encrypted_content,
and the Chat Completions conversion behind vLLM rejects any encrypted
content, so the next model call failed. Ingress now treats the configured
placeholder as absent. Real signatures are still forwarded unchanged.

Streamed capture reconstruction ignored signature_delta events, so the
structured capture lost the signature the client received. It now appends
signature deltas to the block, including fragmented signatures.

Signed-off-by: Christian Munley <[email protected]>
@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test 522ab8a

@cmunley1

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP — both prior findings are fixed; no eligible regressions found in this follow-up.

  • Placeholder replay now clears only the configured sentinel in ingress conversion, retaining the reasoning summary and distinct genuine signatures. The new regression tests cover successful Chat conversion and genuine-signature preservation; the shared opaque-reasoning guard remains intact.
  • Streamed capture now accumulates signature deltas. The new reconstruction tests cover genuine, placeholder, empty, and fragmented signatures alongside thinking, text, and tool blocks.

Compared against the previous reviewed head, inspected all four changed files, and traced the directly affected replay and capture paths. This was a scoped follow-up, not a fresh whole-PR review. Validation was source-only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

This branch was previously deployed

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

Labels

area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants