Skip to content

refactor(core): read and build every rollout path through the correlation module - #5255

Open
pthombre wants to merge 2 commits into
pranav/agent-instance-06-per-agent-resultsfrom
pranav/agent-instance-07-migrate-readers
Open

pthombre wants to merge 2 commits into
pranav/agent-instance-06-per-agent-resultsfrom
pranav/agent-instance-07-migrate-readers

Conversation

@pthombre

@pthombre pthombre commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

PR 1 moved the model server's and the trace middleware's readers onto nemo_gym.correlation. A few readers and builders still parsed or spelled out /ng-rollout/... by hand, each with its own idea of a valid capture key. After this PR no code parses or builds the path by hand; FastAPI route templates still spell out the prefix, since they cannot use the module.

Readers moved onto resolve:

  • the checkpoint policy admission middleware (_checkpoint/model.py);
  • Switchyard's rollout session middleware (switchyard_model/app.py);
  • Simple Agent's activation reader;
  • RolloutContextMiddleware, used by resources servers, which now strips the whole prefix;
  • url_path_for_request, which carries the inbound training tag and agent instance name (an inbound name wins over the session's) through a new inbound_correlation(request) helper. A stand-in request without an ASGI scope is read from its URL path, then from a rollout_id path parameter, so agents and their tests that pass such requests keep working.

Key rule. resolve adopts ROLLOUT_ID_PATTERN (now defined in correlation, re-exported from rollout_correlation), the rule documented for every reader. The model server's capture reader, the trace reader and the checkpoint admission reader used to accept anything up to the next /; Switchyard and resources servers already applied the pattern. Session routing's seed and close matcher is a route pattern and is left as is. The change is deliberate and tested.

Builders moved onto rollout_path_prefix: the Harbor and Single Agent Turn environment servers' activation paths (nemo_user_sim and SWE-Together moved in PR 5).

ServerClient. For a model generation path a caller already prefixed without a name, the name set with agent_instance_context is inserted with encode, so a name set in context is never silently dropped; a path that names an agent instance keeps it. PR 4's rule that a caller building its own prefix must pass the name no longer applies.

How it works

Where this PR sits in the overall flow; the highlighted part is what this PR changes.

flowchart LR
  ENV["Environment server<br/>seeds and activates agent sessions"]
  AG["Agent server<br/>session bound to its agent instance"]
  RS["Resources server<br/>verify(), judges"]
  MS["Model server<br/>capture middleware"]
  CM["nemo_gym.correlation<br/>resolve / encode"]
  LG[("Capture ledger and token store<br/>rows carry agent_instance, model_ref")]
  DL["Delivery and manifest<br/>chains and outcomes per agent instance"]
  RR["Episode result<br/>agent_instances map"]
  ENV -->|"/ng-rollout/k/ng-agent-instance/user/v1/responses"| AG
  AG -->|"model calls named user"| MS
  RS -->|"verify.&lt;id&gt; and judge calls"| MS
  MS --> CM
  MS --> LG --> DL --> RR
  ENV --> RR
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class CM this
Loading
flowchart LR
  subgraph Before
    R1["capture regex"] & R2["trace regex"] & R3["checkpoint regex"] & R4["Switchyard regex"] & R5["RolloutContextMiddleware._PREFIX"] & R6["path_params + substring"] & B1["f'/ng-rollout/...' builders"]
  end
  subgraph After
    C["nemo_gym.correlation<br/>resolve / encode<br/>ROLLOUT_ID_PATTERN"]
  end
  Before --> C
Loading

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
  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 (this PR)

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.
  • Core suite on this branch (the top of the stack): 32 failed, 12,363 passed, 4 errors, all in the baseline set (one flaky docker-compose test passed).
  • Server suites on this branch: SWE-Together 204 passed, simple_agent 89 passed (its baseline), nemo_user_sim 36, Harbor 620, single_agent_turn 121, Switchyard 49, tau2 44, pinchbench 88, proof_jury_judge 23, conversational_tool_use_simulation 86, all passed. A first run caught simple_agent tests whose stand-in requests carry only path_params; inbound_correlation reads those, and they pass unchanged.
  • test_correlation.py: a capture key outside ROLLOUT_ID_PATTERN raises; resources servers strip a whole named prefix and see its rollout.
  • test_base_responses_api_model.py: accepted explicit ids round-trip through the module; a capture key outside the rule gets 400 from the model server; url_path_for_request carries the inbound prefix from the request's scope.
  • test_rollout_correlation.py: ServerClient inserts the context name into a caller-prefixed generation path, keeps a path that already names one, and leaves non-generation and resources-server paths alone.
  • test_agent_session_instances.py: an inbound name wins over the session's when carrying the path; an unnamed inbound path takes the session's name.

Rollout evidence

N/A beyond the stack's: every migrated reader and builder gives the same result for every path shape Gym builds; the only behavior changes are the 400 for an invalid capture key and the name inserted into caller-prefixed paths, both covered above.

Compatibility

  • Capture keys outside ROLLOUT_ID_PATTERN (^[A-Za-z0-9][A-Za-z0-9._-]*$) are refused with 400 by every Gym server. Gym never builds such keys; maybe_rollout_id_from_run_body already rejects them.
  • Resources servers strip a whole correlation prefix; they never receive an agent instance name from Gym's own callers.
  • ServerClient adds the context's agent instance name to caller-prefixed model generation paths.

🤖 Generated with Claude Code

@pthombre pthombre added area:core Shared APIs, servers, telemetry, health, and registries 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
pthombre added this pull request to stack #5256 October 29, 2026 02:07
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the feature New capabilities, enhancements, or enablement work label Oct 29, 2026
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch from d438941 to 553b2c2 Compare October 29, 2026 02:19
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch 2 times, most recently from eb5c726 to dfe85d5 Compare November 3, 2026 00:03
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch from dfe85d5 to e8ac194 Compare November 3, 2026 14:13
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch 2 times, most recently from 2306198 to 851461e Compare November 3, 2026 15:22
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch from 851461e to 05b8f20 Compare November 4, 2026 00:50
pthombre and others added 2 commits November 17, 2026 01:08
…tion module

After this change no code parses or builds the /ng-rollout path by hand;
FastAPI route templates still spell out the prefix.

Readers moved onto nemo_gym.core.correlation.resolve: the checkpoint policy
admission middleware, the Switchyard rollout session middleware, Simple
Agent's activation reader, RolloutContextMiddleware (used by resources
servers, which now strip the whole prefix), and url_path_for_request, which
carries the inbound training tag and agent instance name (an inbound name
wins over the session's).

Key rule: resolve adopts ROLLOUT_ID_PATTERN, the rule documented for every
reader. The model server's capture reader, the trace reader, the checkpoint
admission reader and session routing used to accept anything up to the next
`/`; a capture key outside the rule is now refused with 400.

Builders moved onto rollout_path_prefix: the Harbor and Single Agent Turn
environment servers' activation paths.

ServerClient: for a model path a caller already prefixed without a name,
the name set with agent_instance_context is inserted, so it is never
dropped; a path that names an agent instance keeps it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
…he migrated readers on named paths

- correlation: the capture key must match the rollout id rule in full, so a key with a trailing line break is refused again by the resources and Switchyard readers this stack moved onto the shared rule
- tests: the checkpoint admission reader on named, tagged and malformed paths, ServerClient keeping the query and trace segment of a path it names, and the Harbor activation path's training tag

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
@pthombre
pthombre force-pushed the pranav/agent-instance-07-migrate-readers branch from 8a4ccda to b1ff961 Compare November 17, 2026 09:45
@pthombre
pthombre marked this pull request as ready for review November 20, 2026 18:00
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 20, 2026

@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

I checked all 21 changed files and traced the affected correlation paths across server boundaries. No qualifying issues found.

This was a source-only review. I did not execute tests.

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.

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:core Shared APIs, servers, telemetry, health, and registries 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.

2 participants