Skip to content

feat(token-capture): preserve finish reasons and terminal truncation - #3973

Merged
alexandery-nvidia merged 6 commits into
mainfrom
alexandery/capture-finish-reason-and-incomplete-terminal
Oct 15, 2026
Merged

alexandery-nvidia merged 6 commits into
mainfrom
alexandery/capture-finish-reason-and-incomplete-terminal

Conversation

@alexandery-nvidia

@alexandery-nvidia alexandery-nvidia commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Three related changes in nemo_gym/token_id_capture, so that a consumer of a rollout record can tell a trajectory that ended at the output-token budget from one that ended on its own.

  1. Each locally captured record carries its call's finish reason. TokenEntry gains finish_reason, usually in the Chat Completions vocabulary (stop, length, tool_calls, content_filter; other engine values pass through unchanged). response_finish_reason in records.py derives it from either served payload shape: a chat payload states it directly as choices[0].finish_reason; a Responses payload carries no finish reason, so incomplete_details.reason is mapped back through the converter's own mapping (max_output_tokens to length, content_filter to itself), and a completed Responses payload stopped at a tool call (tool_calls) or at the end of its text (stop). capture_tokens in sink.py stamps it on every record written by the local capture path. A record written without the field reads as None, so existing stores stay readable, and the conformance kit's entry carries a non-default finish reason so a store that drops the field fails the round trip.
  2. The rebuilt response reports a cut terminal as incomplete. project_main_chain_response in builder.py sets status: "incomplete" with incomplete_details.reason: "max_output_tokens" when the delivered chain's terminal call stopped for length, and incomplete_details.reason: "content_filter" when it stopped for content_filter: the verdicts the Responses converter already gives a served chat completion that ended the same way. Only the terminal call decides: an earlier length stop was extended by a later call and does not end the chain. Any other finish reason leaves the status unset, as before. When terminal attribution chose the terminal call among token-identical retries by call-id order alone and those twins recorded different finish reasons, the verdict is withheld too (TerminalAttribution.finish_reason_resolved, passed to project_main_chain_response): the delivered tokens are the same either way, but the status would otherwise depend on which twin drew the smaller id. A witness that singles out one serving (an explicit id, or a response id, item id or content fingerprint matching exactly one entry) keeps that serving's verdict.
  3. Delivery carries that verdict onto the rollout record. finalize_rollout_token_capture in delivery.py replaced only response.output, so the builder's verdict never reached the record. It now also sets the harness response's status and incomplete_details from the rebuilt response when the harness reported completed or no status; a harness that already reported incomplete or failed keeps its own, more specific, verdict. The readers that see it without any change are Gym's own aggregate-metrics path, which reads response.incomplete_details, and the downstream NeMo RL fork, whose agent harness finalizes the capture in-process and reads the verdict there. Upstream NeMo RL does not see this verdict yet: at fix(nemo-gym): mark incomplete terminal responses as truncated RL#4449's head, NemoGym runs capture in receipt mode (external_staging: true, rebuild_response: false) and collects through run_examples, so finalize_rollout_token_capture never runs for it and fix(agent): keep the resources session cookie for verify when the agent holds no cookie jar #4449 counts only a status the harness set itself. Upstream RL gets the verdict once feat(token-capture): carry the finish reason through worker-custody staging #4366 carries the finish reason through worker-custody staging and RL's receipt consumer applies it.

Scope

The finish reason is recorded on the local capture path only. Under external staging (worker custody) capture_tokens returns before building a record, and the staged CallRecord, the ledger, and staging/rebuild.py carry no finish reason, so a chain rebuilt from staged records reports no verdict. Carrying the finish reason through the staging record is the follow-up #4366, stacked on this branch.

Issue

No issue filed; the missing status was found while training with agent harnesses under token-id capture, where a session cut at the output budget was indistinguishable from a completed one in the rebuilt response.

Validation

  • tests/unit_tests/test_terminal_attribution.py, tests/unit_tests/test_trajectory_builder.py: 97 passed, including the new tests for the content_filter verdict and for delivery with a harness status that is absent, completed, failed (left untouched), and incomplete for the harness's own reason (left untouched); the earlier tests for response_finish_reason on both payload shapes, the recorded reason on the /v1/responses and /v1/chat/completions capture routes, the store round trip with an older record lacking the field, and the terminal-versus-earlier length rule stay.
  • Full tests/unit_tests and every responses_api_models/*/tests suite on this branch: the only failures (opensandbox, telemetry, and the two servers that import vllm) are the same as on main f128d43 in the same environment.
  • ruff check and ruff format --check on the changed files: clean.
  • Rollout evidence: these changes have run for several weeks in a downstream fork training with OpenCode and Codex harnesses under token-id capture; the rebuilt responses of sessions cut at the output budget carry status: "incomplete", and the trainer's truncation count reflects them.

Review follow-up

Rebased onto main f128d43. The dependency edits that the validation merges had added to this branch live in #4362 now.

yaoyu-33's follow-up of 2026-10-12 (744e198): the finish-reason rule for token-identical retries described in item 2, with regression tests at the attribution level (both id orders; the explicit and response-id witnesses), through _assemble (both orders; twins that agree keep the verdict), and on the builder. tests/unit_tests/test_terminal_attribution.py, test_trajectory_builder.py, test_token_id_capture.py: 290 passed.

ananthsub's notes of 2026-10-15 (5ed1608): item 3 now names the readers that see the delivered verdict and the one that does not (upstream NeMo RL's receipt mode, which needs #4366 plus a receipt-consumer change on the RL side), the Scope section links #4366, and a delivery test where the harness reports incomplete for its own reason (result_missing) pins the second half of the guard. tests/unit_tests/test_terminal_attribution.py: 65 passed.

🤖 Generated with Claude Code

@copy-pr-bot

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

@linj-glitch linj-glitch changed the title feat(token-capture): record each call's finish reason and rebuild a length-cut terminal as incomplete feat(token-capture): preserve finish reasons and terminal truncation Oct 5, 2026
linj-glitch added a commit that referenced this pull request Oct 5, 2026
@linj-glitch linj-glitch added area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge labels Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as ready for review October 5, 2026 07:26
linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed capture recording, backward-compatible decoding, and rebuilt-response projection against current main and the converter contract. Only the delivered terminal call determines max-output-token truncation; earlier length stops followed by continuation do not. No blocking findings remain.

Validation: 290 focused tests passed across capture, trajectory building, terminal attribution, conformance, golden vectors, and vLLM capture integration. Full pre-commit suite and git diff --check passed. The additive main merge has an identical tree to the tested revision. GPU/model execution was not run locally; this is shared capture bookkeeping and HTTP integration validation.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test 7d2fb20

@linj-glitch
linj-glitch enabled auto-merge October 5, 2026 07:26
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 5, 2026 07:26
@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate review surface label Oct 5, 2026
@linj-glitch
linj-glitch added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 5, 2026
linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed capture recording, backward-compatible decoding, and rebuilt-response projection against current main and the converter contract. Only the delivered terminal call determines max-output-token truncation; earlier length stops followed by continuation do not. No blocking findings remain.

Validation after the final additive merge of current main: 829 focused regression tests passed; the full repository pre-commit suite and git diff --check passed. Author history is preserved. Model plugin imports were pinned to this review checkout in the shared dependency environment. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test 19e8307

linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed capture recording, backward-compatible decoding, and rebuilt-response projection against current main and the converter contract. Only the delivered terminal call determines max-output-token truncation; earlier length stops followed by continuation do not. No blocking findings remain.

Validation after the final additive merge of current main: 1017 focused regression tests passed; the full repository pre-commit suite and git diff --check passed. Author history is preserved. Model plugin imports were pinned to this review checkout in the shared dependency environment. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

Added focused compatibility bounds for full server CI: Hugging Face Hub below2 in the dev extra, and a datasets floor confined to Aviary. These avoid the reproduced SDK/cookie transport failures and legacy tokenizer/PyArrow resolution; all locked package versions remain unchanged. Ordinary server setup also selects dev. Fresh installs across GDPVal, OpenEnv, session-state, Aviary, LangGraph, and Fabric passed640 tests with1 intentional Docker skip. Final-head focused tests, full pre-commit, uv lock --offline --check, and git diff --check passed. The full GitHub server suite remains required before merging. No separate issue is needed for these narrow CI compatibility fixes.

linj-glitch
linj-glitch previously approved these changes Oct 14, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 98bf318. I pushed a focused, signed follow-up fixing two finish-attribution edge cases: conflicting unique witnesses must agree on the finish reason, and a unique item witness takes precedence over a shared response-ID representative. Safe token-equivalent capture is retained while unsupported finish verdicts are withheld.

Validation on the corrected candidate: 1,220 native tests and 34 adversarial probes passed, plus nine independent challenge cases and full pre-commit. The 14 new native regressions produced 12 failures before the fix and all pass afterward. No remaining code blocker found.

Ananth's final shared-code review and final-head CI/integration gates remain required before merge. The earlier P0 failures were reproduced on the older main baseline; #4450 fixes those harness issues but is absent from this branch. No fresh GPU/model or RL training run was performed.

…nish-reason-and-incomplete-terminal

Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 4cf9aac

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

Merged main 4518db9 into the branch (4cf9aac, no conflicts), so the branch now carries #4450's harness fix and the current staging series. @linj-glitch's attribution fix (98bf318) is on board, and the Gym unit suite plus every model-server test directory on this head match main's failures locally. CI is triggered on the new head. @ananthsub, with Lin's approval in, your look at the shared code (token_id_capture/terminal.py, records.py) is the remaining review step here; the re-request from 10/13 stands.

…ed incomplete itself

Delivery copies the capture's `incomplete` verdict onto a harness response that
said `completed` or nothing, and leaves a harness verdict of `failed` or
`incomplete` alone. Only the `failed` half was tested, so loosening the guard to
overwrite an `incomplete` the harness set for its own reason (`result_missing`)
would have passed. The new delivery case covers it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 5ed1608

@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, both items are in. Item 3 of the description now names the readers that see the delivered verdict and says upstream NeMo RL's receipt mode needs #4366 plus its own change, and the Scope section links #4366. test_finalize_keeps_a_harness_verdict_that_is_already_incomplete pins the second half of the guard. The unit tests pass on 5ed1608; the failing harness conformance checks fail the same way on main.

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

Re-reviewed 5ed1608: no blocking findings. The new harness-verdict preservation test passes and rejects the overwrite mutation (65 focused tests passed). Harness-conformance/P0 CI remains outstanding.

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Oct 15, 2026
@alexandery-nvidia
alexandery-nvidia added this pull request to the merge queue Oct 15, 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/38789529812

Merged via the queue into main with commit d5b2892 Oct 15, 2026
48 of 53 checks passed
@alexandery-nvidia
alexandery-nvidia deleted the alexandery/capture-finish-reason-and-incomplete-terminal branch October 15, 2026 19:11
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…nish-reason-through-staging

#3973 merged on main as d5b2892. The files both sides touched keep this branch's version,
which equals #3973's final tree plus this branch's lines, and #3973's last test sits next to
this branch's tests of the shared verdict helper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…gine-refusal-record

#3973 merged on main as d5b2892. The files both sides touched keep this branch's version,
which equals #3973's final tree plus this branch's lines, and #3973's last test sits next to
this branch's refusal tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
pthombre pushed a commit to linj-glitch/Gym that referenced this pull request Oct 16, 2026
…taging (NVIDIA-NeMo#4366)

> **Stacked PR.** This branch is built on NVIDIA-NeMo#3973 (the finish reason and
the incomplete terminal), whose `response_finish_reason` and verdict
table it reuses. NVIDIA-NeMo#3973 merged on 2026-10-15 as d5b2892 and `main` is
merged in since (3bc2a33), so the diff is this pull request's own
changes; the commit list still shows NVIDIA-NeMo#3973's commits (9c8bdf2,
ec2f7c3, 744e198, 78b05e8), whose content is on `main` now. Review
the three commits that are this branch's: `feat(token-capture): carry
the finish reason through worker-custody staging`, `fix(token-capture):
withhold the staged rebuild's truncation verdict when the finish reason
is unresolved` (the 2026-10-13 review follow-up), and
`feat(token-capture): apply the capture's truncation verdict through one
shared rule` (ananthsub's review of 2026-10-15). A merge of `main`
3d2e970 sits between them: the generation-cut staging series added
fields next to this branch's in `lineage.py`, `staging/records.py` and
`staging/rebuild.py`, and both sides are kept. It is independent of
NVIDIA-NeMo#3980, which edits neighboring lines of `builder.py`; whichever of the
two lands second merges `main` once more.

## What does this PR do?

NVIDIA-NeMo#3973 records each locally captured call's finish reason and marks a
rebuilt response whose terminal call stopped for `length` or
`content_filter` as `incomplete`. Under worker custody, where a
framework's inference worker keeps the tokens and the model server
records a token-free ledger row per call, no finish reason was recorded,
so a rollout rebuilt from staged records reported no truncation verdict:
a trainer's truncation rule saw every such rollout as complete.

1. **The ledger row carries the finish reason.** `CallRecord`
(`nemo_gym/token_id_capture/staging/records.py`) gains `finish_reason:
str | None` in the Chat Completions vocabulary (`stop`, `length`,
`tool_calls`, `content_filter`). It is a metadata column like
`response_id` and `admitted_at`, outside the staged digest, so no digest
or schema version changes; a row written before the column reads `None`.
Like every column of these wire models, it binds the model server and
the framework to one Gym version: the manifest route serializes it on
every row and `CallRecord` forbids unknown fields, so a framework whose
Gym predates the column rejects every manifest row as
`invalid_manifest_row` and masks the rollout, as `capture_key` (NVIDIA-NeMo#3884)
already does. Run the same Gym on both sides.
2. **The external capture handler stamps it.**
`_finalize_admitted_response`
(`nemo_gym/token_id_capture/external_capture.py`) reads it from the
served payload with `response_finish_reason`, which now also understands
the Anthropic Messages shape (`stop_reason`, the inverse of the table
the Anthropic converter applies when it serves a Responses payload as a
Messages response), so the chat, Responses, and Messages dialects record
the same reason.
3. **Both ledgers round-trip it.** `_custody_columns` and
`_manifest_from_rows` (`nemo_gym/token_id_capture/lineage.py`) store and
rebuild the column for the file-backed and the in-memory ledger; a
re-commit with a different finish reason is a conflict like any other
metadata field.
4. **The rebuild reports the terminal call's reason.** `LinearizedRow`
(`nemo_gym/token_id_capture/staging/rebuild.py`) gains
`terminal_finish_reason` and the property `incomplete_reason`, which
applies NVIDIA-NeMo#3973's table through `incomplete_reason_for_finish_reason`, now
a shared function in `records.py` that the local-path builder uses too.
Only the terminal call decides: an earlier `length` stop did not end the
chain, because a later call extended it. The rebuild also keeps NVIDIA-NeMo#3973's
abstention: when the receipt's `terminal_attribution_reason` carries
`finish_reason_disagreement` (attribution named one of several
token-identical calls that recorded different finish reasons, by call-id
order alone), `LinearizedRow.finish_reason_resolved` is `False` and
`incomplete_reason` is `None`, so the verdict cannot flip with the call
id the receipt names; the token is the shared constant
`FINISH_REASON_DISAGREEMENT_REASON` in `records.py`, which
`resolve_terminal` emits. A framework's receipt consumer puts the
property on the sample's response with
`apply_capture_incomplete_verdict` (`records.py`, exported from
`nemo_gym.token_id_capture`), the one precedence rule both capture
placements apply: a response that reported `completed` or no status
takes the verdict, and a harness that reported `incomplete` or `failed`
itself keeps its own, exactly as `finalize_rollout_token_capture` does
on the local path, which now calls the same helper. The NeMo RL consumer
is not open yet: it comes with the Gym pin bump that follows this merge,
because NeMo RL can only exercise `incomplete_reason` once its pinned
Gym has the column. The receipt-builder half, the switch to
`UNSERVED_CALL_FAILURE_REASONS` from NVIDIA-NeMo#3980, is NVIDIA-NeMo/RL#4749 and
is pin-agnostic.

## Review follow-up (2026-10-13)

yaoyu-33's question on `staging/rebuild.py`: with content-attributed,
token-identical calls whose finish reasons differ, swapping the call ids
changed `incomplete_reason` although the receipt reported
`finish_reason_disagreement`. The rebuild now withholds the verdict in
that case, as NVIDIA-NeMo#3973's projection does. The branch also carries a merge
of `main` 3d2e970.

## Review follow-up (2026-10-15)

ananthsub's two items (4c6c6b3): the
precedence rule that keeps a harness's own verdict moved into
`apply_capture_incomplete_verdict`, which
`finalize_rollout_token_capture` calls on the local path and a framework
consumer calls on `LinearizedRow.incomplete_reason` (its docstring
points there), with tests for a response that reported no status,
`completed`, `incomplete` for its own reason, and `failed`; and the
version coupling of the staging wire models is stated on the
`finish_reason` column, in the model-call capture docs, and in point 1.
After NVIDIA-NeMo#3973's squash, `main` was merged in as 3bc2a33 (no rebase, so
the review history stands); the files both sides touched keep this
branch's version, which equals NVIDIA-NeMo#3973's final tree plus this branch's
lines, and NVIDIA-NeMo#3973's last test,
`test_finalize_keeps_a_harness_verdict_that_is_already_incomplete`, sits
next to this branch's `apply_capture_incomplete_verdict` tests.
Validation of the merge head 3bc2a33: the unit suite
(`test_collect_downstream_junit.py` excluded) gave 9160 passed, 56
skipped, 29 failed, 20 errors; 48 of the failures and errors are the
environmental set of `main` (telemetry and opensandbox tests that need
packages this machine lacks) and the remaining one, a docker-compose
shell test, passes on rerun here and on `main`; every
`responses_api_models/*/tests` suite passed (vllm_model 534 passed),
with genrm_model and local_vllm_model erroring at collection as before.
Gate on 4c6c6b3: the unit suite (8754 passed, 56 skipped; the 28
failures and 20 errors are identical to the `main` 4518db9 baseline,
telemetry and opensandbox tests that need packages this machine lacks)
and every `responses_api_models/<server>/tests` session (`vllm_model`
492 passed; genrm and local_vllm collect errors for missing local
packages, as on `main`); the token-capture and staging unit files
together: 561 passed.

## Issue

No issue filed; found while training with NeMo RL's worker-custody
capture under a token budget, where every rollout rebuilt from staged
records counted as complete.

## Validation

- New tests: `response_finish_reason` for the Anthropic Messages shape
(five stop reasons); the ledger row round-trips `finish_reason` on both
ledgers, a row without the column reads `None`, and a re-commit with a
different reason conflicts; the external capture handler records
`length` for every dialect (chat completions, Responses, Messages,
compaction) and `stop` on the existing route tests;
`verify_and_linearize` reports the terminal row's reason and
`incomplete_reason` for `stop`, `length`, `content_filter`, and an
unstated reason; with two token-identical rows recording `length` and
`stop`, the `finish_reason_disagreement` token withholds the verdict
whichever row the receipt names while the recorded reason stays
reported, a trail without the token keeps the verdict, and a receipt
without a trail resolves as before.
- `tests/unit_tests/test_token_id_capture.py`,
`test_token_capture_ledger.py`, `test_token_capture_staging_rebuild.py`,
`test_token_capture_staging_core.py`, `test_trajectory_builder.py`,
`test_terminal_attribution.py`: 401 passed.
`responses_api_models/vllm_model/tests`: 409 passed.
- Unit suite (`pytest tests/unit_tests`, with
`test_collect_downstream_junit.py` excluded for a missing local
package), run on the branch tip 0067fd0
after the merge of `main` 3d2e970: 8463 passed, 56 skipped, 28 failed,
19 errors. The failures and errors are the same 47 as on `main`
3d2e970 (telemetry and opensandbox tests that need packages this
machine lacks). Each `responses_api_models/<server>/tests` directory as
its own session matches `main` apart from the new tests (`vllm_model`
418 passed).
- `ruff check` and `ruff format --check` on the changed files: clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: alexandery <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Lin Jia <[email protected]>
mpatel31415 pushed a commit to mpatel31415/Gym that referenced this pull request Oct 16, 2026
… ids (NVIDIA-NeMo#4014)

## What does this PR do?

Preserve token-capture ancestry when a harness echoes a complete served
model turn but rewrites its tool arguments, as Claude Code does for Bash
commands and Edit defaults. The fallback requires matching tool IDs,
names, order and non-tool assistant content, plus the recorded request
context; inserted, missing or changed model output and ambiguous token
sequences remain unresolved.

Both local token logs and external-staging custody ledgers now retain
this complete-turn key, return `tool_call_turn` when it supplies the
parent, and reuse the parent's original staged tokens. Existing custody
rows without the new optional key remain strict-only, identical replays
remain idempotent, and checkpoint import/export preserves new keys. This
deliberately narrows NVIDIA-NeMo#3301's rejection of edited echoes to permit
argument-only rewrites while continuing to reject text, tool-name, ID
and item changes.

Terminal attribution skips token-free custody rows for the
argument-insensitive reading, rejects IDs reused in earlier transcript
turns, and treats interleaved reasoning consistently. Strict witnesses
still take precedence, conflicting witnesses fail closed, and the merge
with NVIDIA-NeMo#3973 preserves the distinction between a uniquely identified
serving and token-identical retries with different finish reasons.
Custody-only terminal attribution still relies on its existing
IDs/fingerprints; this PR does not add output items to custody records.

The file-ledger implementation in NVIDIA-NeMo#4553 should be updated to use this
complete-turn key when that branch integrates NVIDIA-NeMo#4014, rather than
reintroducing its older ID-only match. No separate issue is needed for
the defects addressed by the inline review.

## Validation

- Source-bound native Python 3.13 run: **1,425 passed**, covering
`test_tool_call_turn_fallback.py`,
`test_tool_call_turn_lineage_store.py`, `test_token_id_capture.py`,
`test_terminal_attribution.py`, `test_conversation_fingerprint.py`,
`test_external_capture_handlers.py`, `test_trajectory_builder.py`, all
`test_token_capture_*.py`, and the complete
`responses_api_models/vllm_model/tests/` suite.
- New regression controls: **9 failed before / passed after** for
interleaved reasoning and reused terminal IDs; one additional
finish-reason identity regression failed before the main-integration
fix. Tests also exercise durable-store restart/checkpoint compatibility,
strict precedence, ambiguity, identical retries, version guards, and
HTTP continuations consuming the exact original staged token prefix.
- `pre-commit run --all-files` and `git diff --check`: passed; the
private guardwords catalog was unavailable, so that hook skipped its
private-catalog scan. The formatter changed one test file; its 65 cases
passed again on final head `a791afff6f875a53908420df5198cf30a9feeab7`.

## Rollouts and compatibility

No fresh live-model rollout was run for this revision; HTTP routing,
conversion, lineage, admission and worker capture helpers are exercised
with CPU generation/staging doubles. The earlier report of several
thousand Claude Code training rollouts is historical author-provided
evidence, not validation of this revised head. Argument-only echoes may
become trainable where they previously failed attribution; this changes
sample eligibility, not verifier scores, and requires Ananth's review
and required CI before merge.

---------

Signed-off-by: Lin Jia <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Pranav Prashant Thombre <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 5ed16088 Deployed Oct 15, 2026 by copy-pr-bot[bot] via release / finalize / notify #5521
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 complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants