Skip to content

fix: preserve opaque reasoning through Anthropic replay - #4615

Merged
RyaliNvidia merged 4 commits into
NVIDIA-NeMo:mainfrom
RyaliNvidia:codex/preserve-opaque-anthropic-reasoning
Nov 2, 2026
Merged

RyaliNvidia merged 4 commits into
NVIDIA-NeMo:mainfrom
RyaliNvidia:codex/preserve-opaque-anthropic-reasoning

Conversation

@RyaliNvidia

@RyaliNvidia RyaliNvidia commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Preserve opaque Responses reasoning when an Anthropic client replays a tool result through Gym's /v1/messages bridge. A Gym-owned nemo_gym_responses_reasoning: marker carries nonempty ciphertext verbatim in a thinking signature or, without readable summaries, redacted-thinking data.

Emit one block per reasoning item, joining summary text with \n\n. Streaming emits signature deltas and redacted blocks. Ingress accepts only marked, nonempty ciphertext, explicitly supplies summaries, and skips unsupported redacted history. Unmarked Anthropic signatures retain readable thinking without becoming Responses ciphertext. Native Anthropic provider conversion remains unchanged.

Incorporates current main c69f3b15ff794d6cb49418117748bb16be195cbb. Use main's reasoning input type from #5024 to omit invented replay IDs: Anthropic history has no original Responses item ID, and providers can reject ciphertext paired with a fabricated ID. No new carrier format or schema relaxation.

This converter bug has direct reproductions, so a separate tracking issue is unnecessary. Related: #4461 (signature streaming) and #2507 (broader conversion design).

Validation

Runtime tests below ran after the b36c37b1 integration. Main then advanced by three unrelated KiloCode/comparison/Gymnasium commits. The final c69f3b15 merge changes none of this PR's feature code or tests; independent reviews verified equivalence and that the fixes remain necessary. Full hooks were repeated on the final tree.

  • Current-main necessity audit: substituting main's converter into the feature regressions produces 36 failures, 3 passes. Main still loses opaque-only reasoning, splits summaries, accepts unmarked ciphertext, invents replay IDs, and omits signature deltas. No obsolete feature hunks were retained.
  • Final reasoning, Anthropic bridge, response-type and Responses converter suites: 839 passed. Independent final review: 89 targeted checks passed. Both full and exclude_unset=True serialized replay omit invented IDs, retain explicit summaries and preserve exact ciphertext after revalidation.
  • Reinstating the prior ID-generating constructors makes 6 regression cases fail. Native provider conversion methods are AST-identical to current main.
  • The 10 previously failing Pi workspace/setup cases pass locally. Main already includes test(pi): isolate workspace tests from runtime installation #4870's runtime-installation isolation and test(terminus-2): clear PROMPT_COMMAND before the interrupt-exit scenario #4966's Terminus fixture correction; this PR adds no separate patches for those failures.
  • Exact incorporated main's Linux run 41483371332 passed core, all eight server shards, and the required CI gate. This is upstream baseline evidence, not a CI result for this new head.
  • pre-commit run --all-files, Ruff/format and scoped git diff --check passed. The private guardwords scan was skipped because its catalog was unavailable. Independent verifier and simplifier found no remaining defects or redundant production code.

Compatibility and limits

The required Responses summary schema and native provider path remain unchanged. Multiple summaries normalize into one joined summary per item. No dependency, authentication, retention, benchmark or scoring change. Fixtures are synthetic; commits have DCO sign-off.

Live model rollout: N/A for this transport correction. Full core/all-server suites, the Linux/tmux-only Terminus test and Linux-only harness probes were not rerun locally on macOS. The earlier upstream baseline had an optional KiloCode conformance failure; final main includes a subsequent KiloCode fix, whose CI outcome is not claimed here. New-head CI still needs the normal maintainer trust approval; no approval comment or review reply was posted.

Proposed maintainer labels: bug, area:model, needs-review.

@copy-pr-bot

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

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Oct 14, 2026
@yaoyu-33 yaoyu-33 added area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:medium Single-domain change with interacting parts or a moderate review surface needs-review PR is ready for code review and waiting on a reviewer and removed community-request Issue reported or requested by someone from the community labels Oct 14, 2026

@ananthsub ananthsub 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.

Thanks for tracking this down. Carrying the ciphertext opaquely through the Anthropic client is the right mechanism, and keeping it on the shared /v1/messages route is the right layer: every model server inherits that route, and the carrier only activates when the backend actually returned encrypted_content, so vLLM-backed servers are unaffected. It does not need to become a per-server setting.

The inline comments ask for changes in three areas.

  1. Wire correctness. Encrypted-only items replayed from the client are forwarded without summary, and multi-summary reasoning comes back as several items with encrypted_content="".
  2. Prefix ownership. litellm_encrypted_reasoning: is a LiteLLM internal tag that LiteLLM strips before forwarding to an Anthropic provider, so a Gym-owned prefix avoids a silent-loss path.
  3. Scope. The Anthropic provider path has no production caller and can stay out of this PR.
flowchart LR
    client["Anthropic client"] --> route["Shared /v1/messages route"]
    route --> ingress["Ingress: strip carrier"]
    ingress --> server["Model server"]
    server --> backend["Responses backend"]
    backend --> server
    server --> egress["Egress: wrap ciphertext in carrier"]
    egress --> client
Loading

Interaction with other open PRs. #4461 emits signature_delta only when the signature is non-empty and adds an unmarked placeholder signature. #2507 treats redacted_thinking data as raw ciphertext with no prefix. The three PRs need one shared rule. The suggestion inline: only carrier-tagged values become encrypted_content, and everything else is treated as having no ciphertext.

Per-backend decision. No Gym server or config requests include=["reasoning.encrypted_content"] today, so this path only activates when a user adds it. A short note in the PR description on which setup produces encrypted reasoning without a summary would help reviewers. So would a smoke run against a real Responses provider at this head.

Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/anthropic_converter.py Resolved
Comment thread nemo_gym/openai_utils.py Resolved
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Oct 15, 2026
@yaoyu-33 yaoyu-33 removed the needs-review PR is ready for code review and waiting on a reviewer label Oct 16, 2026
@RyaliNvidia

Copy link
Copy Markdown
Contributor Author

Hi @ananthsub . Can you please review this again? I just addressed your comments

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Oct 27, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added needs-review PR is ready for code review and waiting on a reviewer waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Oct 27, 2026
yaoyu-33
yaoyu-33 previously approved these changes Oct 30, 2026

@yaoyu-33 yaoyu-33 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.

LGTM. The earlier replay/prefix concerns are addressed; 300 focused tests and SDK replay checks passed. Full CI is still required.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 30, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Oct 30, 2026
@weijiac0619

Copy link
Copy Markdown
Contributor

/ok to test 450f523

@nemo-automation-bot nemo-automation-bot Bot removed the community-request Issue reported or requested by someone from the community label Oct 30, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 30, 2026 18:52
@github-actions

Copy link
Copy Markdown
Contributor

@weijiac0619

Copy link
Copy Markdown
Contributor

could @RyaliNvidia merge main?

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 1, 2026
@RyaliNvidia

Copy link
Copy Markdown
Contributor Author

Yep. Merging main and then reverifying the test

@RyaliNvidia

Copy link
Copy Markdown
Contributor Author

/ok to test b2a86cc

Signed-off-by: RyaliNvidia <[email protected]>
@RyaliNvidia
RyaliNvidia enabled auto-merge November 2, 2026 18:10
@RyaliNvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 3efefb8

@yaoyu-33 yaoyu-33 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.

Reapproved after checking the main integration and reasoning-ID correction. 317 focused converter/replay/streaming tests passed; no new blocking issue found. The required CI gate passes at this head. The KiloCode conformance check still fails and is explicitly non-blocking.

@RyaliNvidia
RyaliNvidia added this pull request to the merge queue Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41510023316

Merged via the queue into NVIDIA-NeMo:main with commit 5768f20 Nov 2, 2026
55 of 58 checks passed
@RyaliNvidia
RyaliNvidia deleted the codex/preserve-opaque-anthropic-reasoning branch November 2, 2026 20:07
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 2, 2026
AdamRajfer added a commit that referenced this pull request Nov 2, 2026
Brings in main up to 94545e7 (#5141, #5384, #5144, #4615, #4954, #5001,
#5175).

Textual conflict: nemo_gym/cli/env.py, imports only. This branch imports
PIPE from subprocess (the server start error capture); main imports SIGKILL
from signal (#5141, the shutdown drain). Both are kept:
"from signal import SIGINT, SIGKILL" and
"from subprocess import PIPE, Popen, TimeoutExpired".

Semantic conflict: #5141 starts each server in its own session
(run_command(..., start_new_session=True)) so shutdown can signal its
process group, while this branch starts servers through
RunHelper._spawn_server, which keeps the tail of the error stream. The
merged call passed start_new_session to _spawn_server, which did not accept
it (11 test_cli failures). _spawn_server now takes start_new_session and
forwards it to run_command, so both behaviours hold. The dry-run path keeps
this branch's process.wait(): the tail thread of _spawn_server owns the
piped stream, so main's communicate() would compete with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 3efefb87 Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9236
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:medium Single-domain change with interacting parts or a moderate review surface ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants