Repository navigation
Conversation
4f0ece6 to
718f767
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
HOLD — 1 BLOCKER, 5 RISKs and 1 NOTE.
The three-topic static review covered all changed files and their directly affected session, capture, checkpoint and environment contracts. The principal failure is that the default SWE-Together Claude Code judge still emits unnamed model calls after moving into the episode's capture key. Additional findings concern instance-specific training tags and uniqueness across lifecycle transitions and workers.
RISK — Provide representative real-model smoke evidence
The PR explicitly says the smoke rollouts have not run. Trusted repository guidance requires representative real-model rollouts for behavior-changing environment or agent work; mocked session/path tests do not establish end-to-end capture and cleanup correctness.
Could you attach commands, configuration, tested revision and inspected artifacts for one representative rollout of each environment? Acceptance should demonstrate:
- UserSim records identify
userandassistant; SWE-Together records identifyassistantandjudge, with the judge under the episode capture key rather than<key>-judge. - Model-call records retain the correct
model_ref; default training-token capture includes only the assistant. - UserSim still verifies its result and closes both participant sessions. SWE-Together closes the judge before reading its verdict, preserves a valid verdict despite a lost response, and distinguishes an unmeasured judge failure from a measured zero.
- The planned checkpoint/retire exercise during judge work stops that episode's judge execution and releases its session.
This is a request for representative smoke evidence, not a new full reward baseline. No tests or rollouts were executed during this read-only review. Suggested patches and acceptance checks below are source-reasoned proposals and must be verified before adoption.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Inline comments (escaped v1):
-
responses_api_agents/claude_code_agent/app.pyline 191: BLOCKER — Carry the judge identity through Claude Code's model URL.The default SWE-Together recipe uses this adapter. This PR now seeds it as
judgein the episode itself, but _sandbox_response calls this resolver, which bypasses all three changed base-agent URL helpers. It still builds.../ng-rollout/r, not.../ng-rollout/r/ng-agent-instance/judge. The model middleware derives identity solely from that URL, so successful judge calls are silently recorded withagent_instance=None, notjudge. Moving off the separater-judgekey makes this an attribution regression on the supplied recipe.Could you update
_resolve_call_base_url? Add thecurrent_agent_instanceimport fromnemo_gym.rollout_correlation, then replace its configured-Gym-model branch with:if base_url and self.config.model_server: agent_instance = current_agent_instance() base_url = apply_rollout_prefix( base_url, rollout_id, token_capture=self.training_tag_for(agent_instance), agent_instance=agent_instance, )
This restores both identity and the named-instance training-selection contract for this independent resolver.
Preserve: direct external Anthropic URLs must remain untouched; unnamed legacy calls must retain their current rollout/training prefixes; trace propagation and judge output/cleanup semantics must not change.
Proposed checks, not run: activate a named
judgesession against a capture-enabled stub model and assert the stagedANTHROPIC_BASE_URLnamesjudgeand the resulting model-call record does too. With capture enabled, assert default judge untagged, explicitly selected judge tagged, and unnamed opted-in calls still tagged. Retain the concrete external-URL and unnamed-prefix assertions in TestRolloutCorrelation. -
nemo_gym/base_responses_api_agent.pyline 1138: RISK — Apply instance selection when these helpers choose the training tag.resolve_model_base_urlandbase_url_for_runnow inherit a session's name, but their defaulttoken_capturestill uses only_token_id_capture_enabled(). For capture enabled withall_agents: true, a directory, and defaulttraining_agent_instances: [assistant], calling either helper inagent_instance_context("user")produces a named training-tagged User URL. The expected URL is named but untagged. Real harness callers such as OpenCode's session activation rebuild their model URL this way, so an untagged environment activation does not enforce the selected-instance policy.Could you make the following change in both
base_url_for_runandresolve_model_base_url? Resolve the effective name beforeapply_rollout_prefix:agent_instance = agent_instance if agent_instance is not None else current_agent_instance()
and pass:
token_capture=self.training_tag_for(agent_instance) if token_capture is None else token_capture, agent_instance=agent_instance,
Update their
token_capture=Nonedocumentation accordingly. The invariant is that implicit URL tags require both agent capture enablement and selection of the effective instance.Preserve: an explicit name still overrides context; explicit
token_capture=True/Falsestill overrides the default; unnamed agents retain their previous opt-in behavior; no rollout ID still means no rollout/name prefix. Do not replaceurl_path_for_request's inbound-tag preservation with this default-selection rule.Proposed checks, not run: exercise both helpers during named seed and activation with default selection: assistant tagged, user/judge untagged. Select
userand assert it becomes tagged; test an indexed kind selection such asdebater.1; assert explicit tag overrides and explicit-name precedence. Retain the unnamed model-endpoint assertion and acceptance of an explicitly tagged named activation. -
nemo_gym/base_responses_api_agent.pyline 720: RISK — Keep the instance reserved until close actually completes.This exclusion releases the name as soon as
_close_session_statesetsrecord.closing=True, before it awaits activation termination and harness cleanup. Reproduce by seedings1as(episode r, assistant), blocking its close hook, and seedings2with the same episode/name while close waits:s2succeeds. The original harness can still be running; a failed close also leaves its resources retained while permitting the replacement. That violates the stated release-on-close binding and can interleave calls from two sessions under one identity. See the close transition.Could you remove only the closing exemption, leaving the predicate as:
if ( session_id != body.agent_session_id and record.close_response is None and record.episode_id == body.episode_id and record.agent_instance == body.agent_instance ): return session_id
A closing or partially initialized session must retain its reservation until successful close or confirmed release removes its state; it must remain unavailable for activation as today.
Proposed checks, not run: while an event blocks
s1cleanup, a fresh-cookies2seed of the same episode/name must return 409. Repeat after cleanup raises, then retry close successfully and asserts2succeeds. Also retain rejection during seed setup, acceptance of different names/episodes and multiple unnamed sessions, identical-seed replay, and the current post-close reuse assertion. Preserve the failed-close state retention exercised by the existing retry test. -
nemo_gym/base_responses_api_agent.pyline 916: RISK — Restore the record's instance binding along with its session state.The new conflict check reads
record.agent_instance, but this restore constructor leaves it atNoneeven whenstate.request.agent_instanceis named. SimpleAgent's restore preserves the name in the request and installs it here. After restorings1asassistantinto attemptr-a1, a fresh seeds2for the same attempt/name therefore succeeds. Both sessions can activate as assistant, although a normally seeded record would rejects2.Could you replace the assignment with:
self._session_records[agent_session_id] = _AgentSessionRecord( state=state, episode_id=state.request.episode_id, agent_instance=state.request.agent_instance, )
The invariant is that restored and normally seeded records expose the same episode/name reservation.
Proposed regression, not run: export a named SimpleAgent session, install it into a replacement attempt, resume admission, then POST a different session ID with the restored episode/name and expect 409. Activate the restored session with its cookie and matching named replacement path and expect its saved reply or continuation, not a new unrelated session. Close it and verify that a fresh session can then reuse the name.
Preserve: unnamed restore behavior, acceptance of another instance in the same attempt, and attempt rewriting. In particular, retain the existing restored-session assertions that stale/unprefixed requests execute no model call and that the replacement attempt can replay or continue.
-
nemo_gym/base_responses_api_agent.pyline 716: RISK — The uniqueness check is worker-local on a multi-worker agent server._session_recordsis process-local. Withnum_workers=2, seeds1as(r, assistant)on worker A, then seed a different IDs2with the same episode/name on worker B: both scans see no conflict and both seeds succeed. Existing session routing claims/routes by session ID, so it intentionally does not bring these distinct IDs to the same worker. Multi-worker agents are a supported configuration. The advertised episode/name uniqueness contract therefore disappears when the server scales beyond one worker.Could you enforce an atomic server-wide reservation for
(episode capture_key, agent_instance)before setup, coordinated through the existing server-runtime/session-claim ownership mechanism? Release it only after confirmed close/release, restore it for restored sessions, and release a rejected seed's unused reservation. If that ownership work is deferred, explicitly reject named sessions with multiple workers rather than claiming to enforce uniqueness there. The exact shared-claim implementation needs an ownership decision, so a process-local lock or speculative patch would not be a complete fix.Preserve: routing of identical session-ID retries to their owner, close-retry receipts, independent instances/episodes, unnamed sessions, and cleanup/claim release after failed setup. Do not route every episode to a single worker merely to hide this conflict.
Proposed acceptance, not run: extend the existing two-worker AgentWorker fixture. Send distinct IDs with one named identity to different workers, sequentially and concurrently: exactly one seed must succeed, or named multi-worker operation must be explicitly refused. Different names and episodes must still succeed; successful close must allow reuse from the other worker. Retain the existing owner-routing checks.
-
resources_servers/nemo_user_sim/README.mdline 47: NOTE — Update the User capture eligibility contract.This paragraph still says only Assistant calls are eligible for training-token capture. The changed activation-path builder now permits User capture when
training_agent_instancesselectsuser. For example, capture enabled withall_agents: trueandtraining_agent_instances: [assistant, user]produces a tagged User activation. The documentation incorrectly describes that supported configuration as ineligible.Could you replace the eligibility sentence with:
Only the Assistant receives sandbox access. Participant training-token capture requires capture to be enabled for the target Agent Server and selection by `token_id_capture.training_agent_instances`, which defaults to `[assistant]`. Selecting `[assistant, user]` enables both participants; conversation support-model calls do not carry the training tag.Preserve: distinguish sandbox access, training capture and ordinary model-call observability. Selecting
usermust not grant a sandbox; default participant training capture remains assistant-only.Acceptance — static check, not executed: compare the revised paragraph with the seed's assistant-only sandbox branch and the path builder's target-capture/instance-selection conjunction. Proposed path cases should assert default User untagged, explicitly selected User tagged and default Assistant tagged when its target captures.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
4b5883a to
455cf68
Compare
455cf68 to
dd85689
Compare
dd85689 to
c6e833f
Compare
5cf561c to
b25d661
Compare
b25d661 to
83757ed
Compare
83757ed to
00ad408
Compare
b27ae96 to
8ef484c
Compare
…t instance and model server
A group is the calls of one agent instance on one model server; a
single-agent episode is one group. Lineage never crosses a group:
- Parent search runs within the request's group: LineageIndex and the
incremental and file stores keep one RolloutLineage per group inside each
episode's cache entry, FileLineageStore filters its shared custody rows by
group, and source-history candidates come from the group's manifest rows.
resolve() and has_rows() take a keyword-only identity.
- A request whose only match was served by another model server for the
same agent instance is a root with root_reason "model_server_changed".
- `ambiguous_candidate` now means ambiguous within one agent instance and
one model server.
Chains and terminal calls: delivery builds each group with the existing
builder and terminal attribution, so retries are grouped and terminals chosen
within a group, and a declared terminal naming another agent instance's call
is masked (declared_terminal_not_captured). The top-level build is the
primary agent instance's (the unnamed agent, else `assistant`, else the only
one); a named episode also returns every agent instance's build under
`agent_instances`. select_terminal_calls selects per group from a manifest.
Outcomes: TokenCaptureSnapshot reports incomplete_agent_instances and
incomplete_episode beside the aggregate `incomplete`. An agent instance is
masked by its own lost calls or by an episode-wide mark, never by another
agent instance's, under both values of mask_incomplete_when_attributed.
Manifest: manifest() and GET /rollouts/{capture_key}/manifest filter by
agent_instance, agent_kind and model_ref; episode-wide failures are returned
under every filter. Delivery and the manifest share nemo_gym.models.token_capture.groups.
Retire and delete clear every group's cached lineage. Model servers refuse a
run whose capturing servers would write to different capture directories;
a custom sink is exempt.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
…wide marks and conflicts, and scope the conformance resolver probes - consumer: an agent instance that lost every call takes part in choosing the primary and gets a failed build, so another agent instance's chain is never delivered in its place - local store: a mark that names no call stays episode-wide beside a named mark, and a conflicting write stays episode-wide - conformance kit: resolve probes pass the call's identity and check that another agent instance's request does not resolve - tests: per-group parent search, admission, terminal attribution, outcomes, manifest filters, and the fixes above Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
Agent instances that call a model server directly now name themselves in the path (`/ng-agent-instance/<name>`): - rollout_path_prefix and apply_rollout_prefix take keyword-only `agent_instance`. agent_instance_context(name) (nemo_gym.core) names the calls inside a block; ServerClient puts that name in the path whenever it adds the rollout prefix itself. Resources-server calls are unchanged. - base_url_for_run and resolve_model_base_url take keyword-only `agent_instance` and `token_capture` (None keeps the agent's flag). - The training tag is chosen per agent instance by `token_id_capture.training_agent_instances` (default ["assistant"]), matched by name or agent kind; the unnamed agent keeps today's behavior. - call_judge takes `agent_instance`; precedence is the argument, then the context name, then `judge`. Verifier runs are the agent instance `verify.<invocation id>`: observe_verifier mints a uuid hex id and names every model call of the run, and the model server derives `verifier_invocation_id` from that name, so ng_verifier_invocations and exclude_verifier_model_calls are unchanged. The `x-ng-verifier-invocation-id` header is no longer sent (the constant stays importable); the path is the only carrier. Environments: tau2 names `assistant` and `user`; pinchbench `assistant` and `judge`; nemo_user_sim's support calls `judge`, `summary`, `tool_simulation`; conversational_tool_use_simulation `user`, `tool_simulation`, `judge`; proof_jury_judge's jurors `judge.<i>` outside a verifier run (inside one, the run's name stands so it owns every juror call). Only the assistant carries the training tag by default. Docs: external-agent-harnesses documents the URL grammar. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Prashant Thombre <[email protected]>
…and update the tests the verifier name change left stale - capture: a lone captured agent instance other than assistant is no longer the primary, so a training selection without the assistant cannot deliver another agent instance's tokens as the scored response - tests: false_statement_judge, swebench_pro and miniswe_sandboxed_agent assert the verifier run's name and bare-hex id instead of the removed header and the verify- prefix - tests: cover URL helper naming, the training selection, verify-kind ids, moved judge names, and the simulator and pinchbench call sites Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
The component that starts an agent session names it in the episode seed,
the agent server checks the name on every activation, and the session's
model calls carry it.
- AgentSeedSessionRequest gains `agent_instance`, validated against the
name grammar and omitted from the serialized seed when unset.
- One open session per agent instance of an episode: a second seed of the
same episode and agent instance is refused with 409 until the first
session closes. The binding is session state, so nothing outlives the
episode. Environment servers check that the names they seed are distinct
(require_distinct_agent_instances).
- Activation routes also accept /ng-rollout/{key}/ng-agent-instance/{name}
[/training-token-capture]/v1/responses. Every /v1/responses route checks,
through nemo_gym.core.correlation, that the path names the session's agent
instance (an unnamed path must reach an unnamed session) and answers a
mismatch with 409.
- While a named session seeds or activates, agent_instance_context is set,
and url_path_for_request, base_url_for_run and resolve_model_base_url fall
back to it, so agents built on these helpers carry the name without
per-agent changes. An explicit name wins.
- The restart-only checkpoint middleware reads the path through resolve.
Environments: nemo_user_sim seeds and activates `assistant` and `user`;
SWE-Together seeds and activates its agent as `assistant`, and its judge
moves from its own `<key>-judge-<session>` episode onto the episode's capture
key as `judge`, so the episode's retire covers it. Judge evidence
(judge_evidence.collect_judge_evidence) reads only the `judge` agent
instance's rows of that capture; the verification record names it in
`judge_agent_instance`. Only the assistant carries the
training tag by default (token_id_capture.training_agent_instances).
Compatibility: SWE-Together judge records move from `<key>-judge-<session>`
to the episode's key under `judge`; anything looking for the `-judge` suffix
must change. Written against the session code on main; #5083
(AgentSessionConflictError) needs a rebase of this change when it merges.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
… agent instance - claude_code: the CLI model URL carries the agent instance a session was seeded as (else the name the request runs under) and takes its training tag from training_tag_for, so the SWE-Together judge's calls are recorded as judge and its evidence is kept - tests: the Claude Code URL for named and unnamed sessions, the episode scope of the one-session-per-name refusal, resolve_model_base_url carrying the session's name, and the SWE-Together candidate and judge activation paths Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
8ef484c to
71a8dc1
Compare
What changed and why
Agent instances that run as agent sessions (nemo_user_sim's user simulator and assistant, SWE-Together's candidate and judge) are started by an environment server, which is the component that should name them (G3). This PR binds a session to its agent instance at seed time: the agent server checks the name on every activation, and the session's model calls carry it.
Seed
AgentSeedSessionRequest.agent_instance(optional), validated against the name grammar and omitted from the serialized seed when unset, ascontinuationis.require_distinct_agent_instanceslets an environment server check its names before seeding.Activation
/ng-rollout/{capture_key}/ng-agent-instance/{agent_instance}[/training-token-capture]/v1/responses./v1/responsesroute checks, throughnemo_gym.correlation, that the path names the session's agent instance: a mismatch, a named path on an unnamed session, and an unnamed path on a named session are refused with 409. It is a FastAPI dependency on the base agent's routes, so every session agent gets it without per-agent code.resolve.Outbound model calls. While a named session seeds or activates,
agent_instance_contextis set, andurl_path_for_request,base_url_for_runandresolve_model_base_urlfall back to it, so the ~75 agents built on these helpers carry the name with no per-agent change. Setting it during the seed covers harnesses that receive their model URL when the session starts. An explicit name wins.Environments
environment_servers/nemo_user_simassistantanduser;responses_pathbuilds named activation paths throughrollout_path_prefix; the training tag followstraining_agent_instances(default: the assistant only, as today).environment_servers/swe_togetherassistant. The judge moves from its own<key>-judgeepisode onto the episode's capture key asjudge(training tag default off), so the episode's checkpoint retire now covers it.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.<id> and judge calls"| MS MS --> CM MS --> LG --> DL --> RR ENV --> RR classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937 class ENV,AG thissequenceDiagram participant E as Environment server participant A as Agent server participant M as Model server E->>A: POST /v1/agent_sessions {episode k, agent_instance "user"} Note over A: refuses 409 if k already has an open "user" session,<br/>seeds with agent_instance_context("user") E->>A: POST /ng-rollout/k/ng-agent-instance/user/v1/responses (session cookie) Note over A: path name == seeded name, else 409,<br/>runs the activation as "user" A->>M: model calls via base_url_for_run / url_path_for_request -> /ng-rollout/k/ng-agent-instance/user/... E->>A: POST /v1/agent_sessions/close Note over A: binding released, "user" can be seeded againWhere 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
/runnames no agent instance, and its records differ frommainonly by the newmodel_refcolumn.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.
pranav/agent-instance-00-capture-key-rename): refactor(capture): name capture keys capture_key on the ledger control surfacepranav/agent-instance-01-correlation-module): feat(core): add a correlation module that reads and builds the rollout pathpranav/agent-instance-02-record-identity): feat(model): record agent instance, agent kind and model server on every capture and model-call recordpranav/agent-instance-03-per-agent-capture): feat(capture): compute lineage, terminal chains and outcomes per agent instance and model serverpranav/agent-instance-04-direct-call-names): feat(core): let callers name an agent instance on model callspranav/agent-instance-05-agent-session-binding): feat(agent): bind agent sessions to an agent instance at seed time (this PR)pranav/agent-instance-06-per-agent-results): feat(episode): report terminal calls and rewards per agent instancepranav/agent-instance-07-migrate-readers): refactor(core): read and build every rollout path through the correlation moduleThe 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_prefixdetects an existing prefix withresolveand takes the name fromagent_instance_context.The NeMo RL follow-up (selecting agent instances to train on, one
RolloutReceiptper 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.nightlycontainer), each branch against a baseline worktree ofmain@0b8783981: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.requirements.txtorpyproject.toml, asgym env testdoes.pre-commitcould not fetch its hook repositories from the build environment, soruff check --fix,ruff check --select I --fixandruff formatran 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.Signed-off-byline._activation_pathsignature, now updated); nemo_user_sim 36 passed on PR 7's branch, which contains this commit.test_agent_session_instances.py(new), through the real agent app and session cookies:main; a named one round-trips; an invalid name is refused;userandassistant, and the assistant's activation path names it.judge, activated and closed under the episode's capture key; activation paths nameassistant(tagged) andjudge(tagged only when selected).Rollout evidence
Not yet run. Before this leaves draft: nemo_user_sim and SWE-Together smoke rollouts with capture on, checking
agent_instanceandmodel_refin the ledger and model-call records, that with default configuration only the assistant's calls are captured, and that SWE-Together's judge calls sit under the episode's capture key asjudge(including a checkpoint restore and retire during the judge's activation).Compatibility
<key>-judgecapture key to the episode's key under the agent instancejudge. Anything downstream that looks for the-judgesuffix must change.refactor(sessions): one name per session lifecycle concept), which is still open. This PR is written against the session code onmainand refuses conflicts withHTTPException(409); once refactor(sessions): one name per session lifecycle concept before release #5083 merges it is rebased ontoAgentSessionConflictErrorand the code that PR renames. It stays a draft until then.🤖 Generated with Claude Code