Skip to content

refactor(capture): name capture keys capture_key on the ledger control surface - #5248

Merged
ananthsub merged 3 commits into
mainfrom
pranav/agent-instance-00-capture-key-rename
Nov 4, 2026
Merged

ananthsub merged 3 commits into
mainfrom
pranav/agent-instance-00-capture-key-rename

Conversation

@pthombre

@pthombre pthombre commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Gym #4128 renamed the staging wire models to capture_key / source_capture_key, the close-admission route and the refusal header. The rest of the training-token-capture control surface still said rollout_id. This PR finishes that rename, so that the following PRs, which add agent instance identity to exactly these signatures, touch each one once.

  • Manifest route: the parameter of GET /training-token-capture/control/rollouts/{capture_key}/manifest is capture_key. The URL does not change.
  • Retire and delete body: LedgerBatchRequest.capture_keys. The routes still accept rollout_ids for one release (validation_alias=AliasChoices("capture_keys", "rollout_ids")); RolloutControlClient sends the new name.
  • Protocols: CaptureLedger.record_failure, manifest, retire and delete, and TokenSink.mark_incomplete, name their parameter capture_key / capture_keys, as do the same methods on InMemoryLineageStore, FileLineageStore and TokenCaptureStore, and RolloutControlClient.manifest / retire / delete.
  • Context and snapshot: CaptureContext.rollout_id and TokenCaptureSnapshot.rollout_id are capture_key, with every call site, including the vLLM model server's measurement context.
  • Token record: TokenEntry.rollout_id is capture_key, and TOKEN_ENTRY_RECORD_SCHEMA_VERSION is 2. A row marked schema_version: 1 that names the key rollout_id is still read, so a run upgraded with unconsumed captures on disk keeps them.
  • Batch validator: validate_rollout_ids is validate_capture_keys, and its import-surface entry is refreshed.
  • Docs: model-call-capture.mdx shows the new body field and the alias.

mark_external_staging_committed(rollout_id=...) keeps its public keyword.

How it works

Two things change outside a process. On the wire, the retire and delete body field keeps its earlier name as an alias. On disk, token records are written as schema version 2 with capture_key, and version 1 rows are still read: a before-validator on TokenEntry reads rollout_id as capture_key only for a row marked schema_version: 1, so a version 2 row or a TokenEntry(rollout_id=...) call is rejected. Lineage ledgers, token state files, file names and rollout checkpoint records do not change. The rest of the rename is mechanical: every keyword and attribute use moved together, and a test pins the protocol's keyword names on both ledger stores.

Where this sits in the stack

This is one PR in a stack of draft PRs that implements agent instance identity from the Gym capture identity design (draft 2): several agent instances (assistant, judge, simulated user, debaters) can call model servers in one episode, every record says which one made each call, capture computes lineage and outcomes per agent instance, and the trainer chooses which agent instances it trains on. Gym records; trainers select. Single-agent episodes do not change: an agent's own /run names no agent instance, and its records differ from main only by the new model_ref column.

Each PR is one commit, and its base is the branch of the PR before it, so each diff shows only that PR's change.

  1. refactor(capture): name capture keys capture_key on the ledger control surface #5248 (pranav/agent-instance-00-capture-key-rename): refactor(capture): name capture keys capture_key on the ledger control surface (this PR)
  2. feat(core): add a correlation module that reads and builds the rollout path #5249 (pranav/agent-instance-01-correlation-module): feat(core): add a correlation module that reads and builds the rollout path
  3. feat(model): record agent instance, agent kind and model server on every capture and model-call record #5250 (pranav/agent-instance-02-record-identity): feat(model): record agent instance, agent kind and model server on every capture and model-call record
  4. feat(capture): compute lineage, terminal chains and outcomes per agent instance and model server #5251 (pranav/agent-instance-03-per-agent-capture): feat(capture): compute lineage, terminal chains and outcomes per agent instance and model server
  5. feat(core): let callers name an agent instance on model calls #5252 (pranav/agent-instance-04-direct-call-names): feat(core): let callers name an agent instance on model calls
  6. feat(agent): bind agent sessions to an agent instance at seed time #5253 (pranav/agent-instance-05-agent-session-binding): feat(agent): bind agent sessions to an agent instance at seed time
  7. feat(episode): report terminal calls and rewards per agent instance #5254 (pranav/agent-instance-06-per-agent-results): feat(episode): report terminal calls and rewards per agent instance
  8. refactor(core): read and build every rollout path through the correlation module #5255 (pranav/agent-instance-07-migrate-readers): refactor(core): read and build every rollout path through the correlation module

The first PR's base is main @ 0b8783981. External dependencies: #5083 (session lifecycle names, open) for PR 5. #4969 (rollout prefix hooks for fixed-base-URL clients, open) needs one small change in whichever of #4969 and PRs 1 and 4 lands second: with_rollout_prefix detects an existing prefix with resolve and takes the name from agent_instance_context.

The NeMo RL follow-up (selecting agent instances to train on, one RolloutReceipt per selected agent instance, per-agent rewards) is separate; until NeMo RL bumps its Gym pin, none of these PRs affect NeMo RL training runs.

Issue

No tracking issue exists; the work follows the Gym capture identity design (draft 2) and its implementation plan.

Validation

Tests ran on Slurm (one node, rl-gym.nightly container), each branch against a baseline worktree of main @ 0b8783981:

  • Baseline core suite (python -m pytest -n 32 tests/unit_tests): 33 failed, 12,191 passed, 4 errors. Every one is environmental in this container (docker-compose, OpenSandbox compose, Harbor compose overlay, eval resubmit, reward profile, dataset orchestrator and sandbox supervisor tests, and four exporter modules that fail to import), and the same set fails on every branch of the stack. The docker-compose tests are flaky: one or two of them pass or fail from run to run.
  • Server-local suites ran in one venv per server built from its requirements.txt or pyproject.toml, as gym env test does.
  • pre-commit could not fetch its hook repositories from the build environment, so ruff check --fix, ruff check --select I --fix and ruff format ran with ruff 0.9.9 (the hook's pinned version) on every changed file. The guardwords and end-of-file hooks did not run here; CI runs them.
  • Every commit carries a Signed-off-by line.
  • The full core suite of PR 1, whose branch contains this commit, fails exactly the baseline set (33 failed, 12,271 passed, 4 errors).
  • test_token_capture_control_routes.py: both body field names accepted; the client sends capture_keys and splits large batches.
  • test_token_capture_ledger.py: the ledger methods take capture_key / capture_keys by keyword on FileLineageStore and InMemoryLineageStore.
  • Review follow-up (7b573678b), run in this sandbox against the PR's first commit 408c0e40c: ruff check and ruff format --check (ruff 0.9.9) pass on every changed file. The vllm_model, switchyard_model and claude_code_agent suites: 1,111 passed, 6 skipped. The core suite (python -m pytest -n 24 tests/unit_tests): 14,756 passed and 311 failed or errored. One docker-compose test hung, so the run was killed before pytest printed its summary. I reran the 28 files with failures on both commits: 293 fail with this commit and 294 on 408c0e40c, and every failure with this commit also fails on 408c0e40c (missing opensandbox/mlflow, read-only /raid/scratch, buildah/tar, worker sockets).
  • test_token_capture.py: a version 1 row written to a token file next to a version 2 row is read back by freeze_now with its capture_key; a row that names the key rollout_id is accepted only when marked version 1.
  • The capture suites that build CaptureContext and TokenCaptureSnapshot (test_token_id_capture.py, test_framework_context_capture.py, test_checkpoint_model.py, test_external_capture_handlers.py, test_token_capture_staging_worker.py, test_trajectory_builder.py, test_token_capture_conformance.py, test_rollout_collection.py, test_base_responses_api_model.py) pass.

Rollout evidence

N/A: no rollout behavior changes. The retire and delete body field keeps an alias, and the token record schema bump keeps reading version 1 rows; both are covered by unit tests above.

Compatibility

  • LedgerBatchRequest accepts rollout_ids for one release; RolloutControlClient sends capture_keys, so a framework on this Gym talking to an older Gym server is not supported (one Gym version per training run, as the staging wire models already require).
  • Token records are written as schema version 2. This Gym reads version 1 records; an older Gym refuses version 2 records with its "Upgrade the reader" error rather than misreading them, so the model server and the framework reading its token files must run this Gym or newer.
  • validate_rollout_ids is removed from nemo_gym.models.token_capture.store (and its old path nemo_gym.token_id_capture.store); use validate_capture_keys. Code that builds TokenEntry(rollout_id=...) or reads entry.rollout_id must use capture_key.
  • Callers that pass rollout_id= / rollout_ids= by keyword to manifest, retire, delete, record_failure or mark_incomplete, or read CaptureContext.rollout_id / TokenCaptureSnapshot.rollout_id, must use the new names. The NeMo RL sources checked make no such keyword calls; NeMo RL's pinned Gym predates feat(capture): support framework-owned context reconstruction #4128 and needs its own catch-up before it bumps Gym.

🤖 Generated with Claude Code

@pthombre pthombre added area:model Model servers, inference providers, and model adapters area:training Training framework integrations and training-data interfaces complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 29, 2026
@copy-pr-bot

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

@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test c8ade95

@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 — LGTM — no concerns found.

Reviewed all 23 changed files and their directly affected contracts and consumers. The capture-key rename is consistent across control routes, ledger implementations, capture contexts, snapshots, vLLM integration, and checkpoint restoration. The legacy HTTP body alias, persisted TokenEntry.rollout_id, and public staging-acknowledgement keyword remain intact.

Static review 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 full review. Request a full review with /review reset=true.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

cmunley1
cmunley1 previously approved these changes Oct 29, 2026

@cmunley1 cmunley1 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, one comment, CaptureContext.rollout_id and the rollout_id= keywords on manifest/retire/delete/record_failure/mark_incomplete are renamed with no deprecated alias. #5317 kept read-only aliases with a one-time FutureWarning for the record fields. Doing the same here would spare outside callers a hard break. Nothing in Gym or NeMo RL uses the old names today, so fine either way.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 30, 2026
@pthombre

pthombre commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1f7f429

pthombre and others added 3 commits November 3, 2026 17:02
…l surface

Finish the capture-key rename on the training-token-capture control surface:

- The manifest route parameter is `capture_key`; the URL is unchanged.
- The retire and delete body field is `capture_keys`. The routes still
  accept `rollout_ids` for one release; RolloutControlClient sends the new
  name.
- CaptureLedger.record_failure/manifest/retire/delete and
  TokenSink.mark_incomplete name their parameter `capture_key(s)`, as do the
  InMemoryLineageStore, FileLineageStore and TokenCaptureStore methods and
  RolloutControlClient.manifest/retire/delete.
- CaptureContext.rollout_id and TokenCaptureSnapshot.rollout_id are
  `capture_key`.

TokenEntry.rollout_id is an on-disk field and is not renamed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
…re key

Review follow-up. TokenEntry.rollout_id holds the capture key (one attempt
of one rollout), so rename it to capture_key and bump the token record
schema to version 2. Version 1 rows, which name the key rollout_id, are
still read, so a run upgraded with unconsumed captures on disk keeps them.

Rename validate_rollout_ids to validate_capture_keys, the batch validator
behind retire and delete, and refresh its import-surface entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
Finish the review follow-up on the removal surface. TokenSource.retire and
delete, TokenCaptureStore.retire/retire_now/delete/delete_now, and
CheckpointableLedger.retire/delete_unstarted with its lineage-store
implementations take capture_keys, matching CaptureLedger. Every caller
passes the batch positionally. validate_capture_keys now says "capture
keys" in its error, and the external harness docs show the new name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
@pthombre
pthombre requested a review from ananthsub November 4, 2026 01:22
@pthombre
pthombre force-pushed the pranav/agent-instance-00-capture-key-rename branch from 1f7f429 to 3e8bbcd Compare November 4, 2026 01:33
@pthombre

pthombre commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3e8bbcd

@ananthsub
ananthsub added this pull request to the merge queue Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

This branch was previously deployed

1 inactive deployment
public — 3e8bbcd9 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #9853
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 area:training Training framework integrations and training-data interfaces complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work 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.

4 participants