Skip to content

feat(capture): opt-in last output item on ordinary capture rows - #5447

Draft
yfw wants to merge 4 commits into
mainfrom
yifuw/capture-record-last-output-item
Draft

yfw wants to merge 4 commits into
mainfrom
yifuw/capture-record-last-output-item

Conversation

@yfw

@yfw yfw commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds the setting token_id_capture.record_last_output_item (default false). With external staging, each capture ledger row then records CallRecord.last_output_item in fingerprint mode too. The item is the call's last served output item (type, content text and summary text), as source_history already records it.

NeMo RL needs this item to support its message-level advantage penalties (grpo.malformed_thinking_advantage and grpo.invalid_tool_call_advantage) with token capture. On the echo path, RL runs its detector on the last output item of each model call. With capture, the finalizer has only the ledger rows, and ordinary rows do not carry that item today. RL side: NVIDIA-NeMo/RL#5022.

The default keeps model text out of ordinary ledgers, as before. source_history behavior does not change. The other source-history evidence (output_items, response_status, replay) stays off in fingerprint mode.

Changes:

  • nemo_gym/token_id_capture/config.py: the new field, and a check that it requires external_staging: true.
  • nemo_gym/base_responses_api_model.py and nemo_gym/token_id_capture/sink.py: the capture middleware passes the setting to each call's CaptureContext.
  • nemo_gym/token_id_capture/external_capture.py: when the context asks for it, the row records the last item from completion_items(served_payload), the same source that source_history uses.
  • fern/versions/latest/pages/model-server/model-call-capture.mdx: one paragraph about the setting.

Validation

  • New tests: test_record_last_output_item_persists_only_the_last_item_in_fingerprint_mode (vLLM and Megatron handlers) and test_record_last_output_item_requires_external_staging. The handler test fails without the change in external_capture.py.
  • pytest tests/unit_tests/test_external_capture_handlers.py tests/unit_tests/test_token_id_capture.py tests/unit_tests/test_completion_evidence.py: 285 passed.
  • pre-commit run --files <changed files>: passed.
  • The branch is on 5911d628c (NeMo RL main's Gym pin), so the RL PR can pin this commit alone. It rebases onto Gym main without conflicts.

Rollouts

N/A. The change adds one optional ledger field and changes no environment or agent behavior.

End to end: a NeMo RL run with the setting on (Super 3.5 video teacher, token capture, 32 GB200 nodes, 8 uvicorn workers on the policy model server) did 12 training steps with no errors. After 6 steps, all 16,384 ledger rows had last_output_item. The field was 7.5 MB of the 32.3 MB of row bytes (23%). The median item was 52 bytes. 43 rows ended inside reasoning (finish_reason: length), so their last item is the reasoning item with its summary text. These 43 rows held 2.3 MB of the field's bytes, up to 140,602 bytes in one row.

Compatibility and benchmark impact

None for existing configurations, because the default is false. A framework that sets the field needs a Gym with this change, because TokenIdCaptureSettings forbids unknown keys.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

Add token_id_capture.record_last_output_item. With external staging, each ledger row then records the call's last served output item (CallRecord.last_output_item) in fingerprint mode too, so a framework can run its output detectors on ordinary capture. source_history behavior is unchanged, and the default keeps model text out of ordinary ledgers.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 2, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:model Model servers, inference providers, and model adapters labels Nov 7, 2026
Main moved the capture code: nemo_gym/token_id_capture is now
nemo_gym/models/token_capture, and the capture middleware is now in
nemo_gym/models/model_call_capture.py. This merge moves the
record_last_output_item wiring into the new middleware file. It keeps
main's Dynamo staging check next to the new external_staging check, and
updates the two tests to TokenCaptureConfig and CaptureContext.capture_key.

Main also added _CAPTURE_PUBLIC_FIELDS, the capture settings that run
artifacts show unmasked. record_last_output_item is a boolean control, so
it joins that list, and the schema test passes again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 18, 2026
yfw added a commit to NVIDIA-NeMo/RL that referenced this pull request Nov 18, 2026
Main gained #4776, which adds a thinking_tags argument to
RolloutReassembler and RolloutReassemblerActorConfig for the malformed
think-tag reward penalty. This branch added an argument with the same name
for the message-level detector, and the auto-merge kept both. Both resolve
to env.nemo_gym.thinking_tags or the default, so one argument now serves
both checks: setup sets it when the think-tag penalty or a message-level
penalty is on.

Other conflicts: _spinup_gym keeps main's rollout-recovery arguments, and
the single-controller guide keeps main's reflowed text and drops its
"remain unsupported with capture" sentence for the new paragraph.

Also:
- Pin Gym to c3e5931262, NVIDIA-NeMo/Gym#5447 merged with Gym main. It
  descends from main's pin 9e2e5d0ad0, and Gym's dependencies and version
  did not change, so uv.lock stays valid.
- Every check reads the active algorithm block, so PPO gets the same
  support. Add a PPO validation test, and name both blocks in the guide.
- Shorten three in-function comments to two lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
yfw and others added 2 commits November 18, 2026 13:21
…, as last_output_item

For a Chat Completions reply, vllm_model puts the parsed reasoning back into
content as <think>...</think>answer, and completion_items keeps Chat text as
served. So last_output_item held the think block, and NeMo RL's
malformed-thinking detector flagged normal reasoning turns that the echo path
does not flag.

- detector_items() lifts a Chat reply's think blocks into a reasoning item,
  as the Chat Completions converter does for the agents. Only the
  record_last_output_item branch uses it; source_history rows and
  completion_items are unchanged.
- Handler test: a Chat reply with a think block records only the answer
  (vLLM, Megatron and Dynamo handlers).
- Test that token_id_capture.record_last_output_item reaches each call's
  CaptureContext, for both values.
- vllm_model integration test: with the setting on, the Chat and Responses
  routes record the same last item.
- Docs: keep the status sentences together, give the setting its own
  paragraph, and say that the stored text can include reasoning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
Main now has #5771 (allow_system_suffix), which touches the same lines in
secret_utils.py, model_call_capture.py, token_capture/config.py,
external_capture.py and sink.py. Both settings are kept. In
install_model_call_capture each argument keeps its own closing "),".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

This branch has not been deployed

No deployments
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 feature New capabilities, enhancements, or enablement work risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants