Skip to content

fix(claude_code_agent): emit a capture-attributable transcript; keep partial output on CLI timeout - #4015

Merged
pthombre merged 3 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/claude-code-capture-transcript
Oct 16, 2026
Merged

pthombre merged 3 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/claude-code-capture-transcript

Conversation

@linj-glitch

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

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fix Claude Code's capture transcript so Gym can corroborate the parent conversation's terminal model call. With training-token capture enabled, thinking stays in separate reasoning items, the last non-empty main-thread served ID becomes response.id, and subagent assistant/tool-result frames are excluded from the parent transcript. Subagent token usage is still counted.

Tool calls enter the capture transcript in model order and remain incomplete until their result arrives. A timeout therefore retains pending calls even when parallel tools finish out of order. The partial transcript is returned with run metadata status="incomplete" and error_type="timeout". The internal terminal_response_id is not exported as a declared terminal ID on /run; attribution still corroborates the response against independent witnesses.

Without capture, thinking remains folded into <think> text, unmatched tool calls remain omitted, and the response retains a generated ID. Timeout responses now retain partial output; verifiers that inspect assistant text can consequently score that partial work.

No separate issue is needed: this PR documents and fixes the existing capture-attribution and timeout failures.

Validation

Validated fix commit 2a537a91a142c842d1782d0d1df1d73b0e566a94.

  • gym env test +entrypoint=responses_api_agents/claude_code_agent +should_validate_data=true: 87 passed, reusing the validated Python 3.13.14 environment with skip_venv_if_present=true and uv_venv_dir overrides.
  • python -m pytest -q -o addopts= responses_api_agents/claude_code_agent/tests tests/unit_tests/test_terminal_attribution.py tests/unit_tests/test_conversation_fingerprint.py: 135 passed (Python 3.13.14).
  • The 19 capture-focused cases include real _create_response → _run_claude_code success/timeout paths with capture on/off, with only the subprocess boundary replaced. The timeout uses the real asyncio timeout path.
  • Converter → continuation stamping → transcript → terminal-attribution regressions verify that pending tool-only and thinking-plus-tool calls select the parent, including interleaved subagent events. Response-ID, item-ID, and cumulative-content witnesses agree.
  • In-memory mutation checks: seven new regressions fail on the prior PR head; all six review-mentioned mutations are detected (both capture-wiring call sites, first-ID-wins, dropped thinking-only event, empty-ID overwrite, and missing ID stringification).
  • pre-commit run --all-files: passed.
  • Additive fix commit has DCO sign-off.

Rollouts and remaining gates

The original author-reported evidence was internal GRPO training through the real Claude Code CLI: with this patch's initial representation/ID changes plus the tool-call lineage fallback, capture attribution succeeded over several thousand rollouts. No public rollout numbers were supplied.

That historical report does not validate this revision's subagent and pending-tool fixes. A fresh representative real model/verifier smoke rollout was not run in this review environment; the unit tests use synthetic CLI frames. That rollout evidence, current-head CI, and Ananth's shared capture review remain outstanding before merge. Complete Claude Code training attribution also depends on the still-open #4014.

@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:agent Agent harnesses and Responses API agent behavior 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 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/claude-code-capture-transcript branch from 2133cf5 to e6b8038 Compare October 8, 2026 00:15
…partial output on CLI timeout

With training-token capture on, Gym joins the finished transcript to one
captured model call by hashing the model-authored text and, failing that, by
response id. The agent folded the model's thinking into the message text as
`<think>...</think>` and named the response with a random `resp_<uuid>`, so
neither reading could match (`response_id_no_match,no_content_match`) and
every captured rollout was masked even with a single verified chain.

When capture is enabled, `parse_stream_json(..., fold_thinking=False)` emits
thinking as a separate `reasoning` item (which the fingerprint ignores by
design) and keeps the message text bare. The last assistant message's served
id is reported as `terminal_response_id` in the run metadata and, under
capture, used as the response id. Behavior without capture is unchanged.

A CLI timeout returned `[]` and dropped the transcript already streamed, so
there was nothing to grade or attribute. Return the parsed partial output.

Signed-off-by: Lin Jia <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@linj-glitch
linj-glitch force-pushed the linj/claude-code-capture-transcript branch from e6b8038 to 1a0f57b Compare October 8, 2026 00:20
@linj-glitch
linj-glitch marked this pull request as ready for review October 13, 2026 23:08
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 14, 2026
@pthombre
pthombre self-requested a review October 15, 2026 18:59
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 15, 2026
Keep capture transcripts on the main conversation and retain pending tool
calls in model order. Complete calls when their results arrive, preserving
evaluation behavior while avoiding timeout witness disagreements.

Exercise the real execution and timeout wiring, terminal witnesses, and
missing response IDs. Clarify capture setup and terminal ID semantics.

Signed-off-by: Lin Jia <[email protected]>
@linj-glitch
linj-glitch requested a review from ananthsub October 16, 2026 04:18
@pthombre

Copy link
Copy Markdown
Contributor

/ok to test 8286b38

@pthombre
pthombre added this pull request to the merge queue Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into NVIDIA-NeMo:main with commit 9ef5ed0 Oct 16, 2026
41 of 46 checks passed

This branch was previously deployed

1 inactive deployment
public — 8286b38a Deployed Oct 16, 2026 by copy-pr-bot[bot] via release / finalize / notify #5626
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 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