Repository navigation
feat(model): record agent instance, agent kind and model server on every capture and model-call record - #5250
Conversation
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
Two RISK findings: checkpoint export loses inherited failure identity, and the transport conformance kit still accepts write signatures that runtime no longer supports.
Reviewed all 21 changed files and their directly affected contracts, callers, and failure paths. This was static source review; tests and smoke rollouts were not executed.
Inline comments (escaped v1):
-
nemo_gym/_checkpoint/model.pyline 648: RISK — Preserve inherited failure identity across checkpoint exportFailure: On a
FileLineageStore, runbegin_call("r1", "j1", identity=CallIdentity("judge.1", ModelRef(name="policy"))), thenrecord_failure("r1", "j1", "worker_capture_failed")without identity. The live manifest attributes the failure correctly through the new intent fallback. However,export_model_records(store, [EpisodeId(rollout_id="r1")], [], {})discards the intent here but retains the identity-free failure. Afterimport_model_recordsinto a fresh ledger, the failure loses its agent instance, kind, and model reference and becomes episode-wide. This affects checkpointed failures using the documented optional-identity contract.Correction: Could export materialize the manifest's inherited identity onto retained rows before removing intents? Keep removing intents—restoring them would resurrect dead calls as pending. Suggested replacement for the
rows = [...]block in export_model_records, withCallIdentityimported from the capture records module:live_rows = ledger.export_rows(key) intent_identity = { row["model_call_id"]: CallIdentity.from_columns(row).columns() for row in live_rows if row.get("intent") } rows = [ { **row, **intent_identity.get(row.get("model_call_id"), {}), **CallIdentity.from_columns(row).columns(), } if row.get("agent_instance") is None else row for row in live_rows if not row.get("intent") and not row.get("admissions_closed") and row.get("model_call_id") not in undelivered ]
This preserves the existing fallback precedence without mutating the live ledger. Please verify the suggested code before adopting it.
Preservation and proposed acceptance checks: Export/import the setup above and assert the restored failure identity is
("judge.1", "judge", ModelRef(name="policy")). Check separately that an explicitly named failure keeps its own identity, a model-only failure inherits the intent's agent while retaining its explicit model reference, and a failure without identity or intent stays episode-wide. Retain the existing checkpoint regression: restored pending IDs remain empty, the live ledger still reports"undelivered", and the delivered row keepssource_capture_key == "r1". These checks are proposed, not executed. -
nemo_gym/token_id_capture/conformance.pyline 256: RISK — Exercise the new write keyword in transport conformance checksFailure: An otherwise conforming external adapter retaining
begin_call(rollout_id, model_call_id)ormark_incomplete(rollout_id, model_call_id="")can still passrun_conformance, because its write probes omitidentity. But register_call_intent now always supplies the keyword, causing an old-signature adapter to raiseTypeErrorbefore generation. Likewise, _mark_incomplete cannot persist a failure through an old-signature adapter. The protocol break is intentional; the defect is that the verification kit still certifies incompatible implementations.Correction: Could the existing probes mirror runtime arguments? Import
CallIdentityandModelRef, and define:_CALL_IDENTITY = CallIdentity( agent_instance="judge.1", model_ref=ModelRef(name="conformance-model") )
Replace this call with:
await sink.mark_incomplete(rollout_id, "call-2", identity=_CALL_IDENTITY)
Also supply
identity=_CALL_IDENTITYto themark(...)andbegin(...)probes in retirement checks and intent/refusal checks. Passing the kit must require accepting the write arguments Gym actually sends.Preservation: Keep
begin_calloptional, so sinks without it still skip those checks. Do not add this keyword torecord_engine_refusal, whose contract did not change. Preserve retirement fences, refusal resolution, and stale-snapshot version assertions.Proposed acceptance checks: Wrap the working file store with an override
async def begin_call(self, rollout_id, model_call_id)that forwards to the store; the kit must reject it withConformanceError. Separately override the working memory sink'smark_incompletewith its old signature; the kit must reject it atmark_incomplete_durability. The updated file and memory backends must still pass. Preserve the memory test's skipped-extension assertions and the intent-only sink's successful custody check plus refusal warning. These are source-derived proposed checks, not executed results; verify the suggested changes before adopting them.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
cmunley1
left a comment
There was a problem hiding this comment.
This breaks test_cancelled_chat_keepalive_retains_uncertain_capture[True] in responses_api_models/vllm_model/tests/test_framework_context.py (passes on the base commit, fails at this head). Its stub delayed_failure(*args) replaces ledger.record_failure and now gets identity=. The TypeError is swallowed in _fail_uncommitted_external_call and logged as "Could not poison uncommitted call", so no failure row is written. The test fix is *args, **kwargs. The silent swallow is the same pattern as the conformance gap: a wrapper that drops a new keyword loses the failure instead of failing loudly.
|
/ok to test 3c5f4fc |
3c5f4fc to
6d74fc6
Compare
60a071c to
54ede9d
Compare
54ede9d to
87e9475
Compare
…ery capture and model-call record Every capture and model-call record now says who made the call and which model server served it: - `agent_instance` and `agent_kind` come from the `/ng-agent-instance/<name>` path segment and are written only when a name is present, so single-agent rows carry no null columns. - `model_ref` comes from the serving model server's own configuration, never from the request, and is written on every row. It has the shape and value of the `model_ref` on model-call records. They are carried on CaptureContext and written onto TokenEntry, CallRecord, ManifestFailure, ledger intent, refusal and failure rows, the local store's intent and incomplete marks, and model-call records (ModelCallRecord reads them). begin_call, refuse_call, record_failure and mark_incomplete take a keyword-only `identity` (CallIdentity). A manifest failure written without an identity inherits it from its call's intent row; a failure with neither applies to the whole episode. RolloutReceipt gains an optional `agent_instance`; `None` means the receipt covers the whole episode and serializes as before. None of the new fields enter the staging digest. The `x-session-id` header name and its read move into nemo_gym.correlation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Prashant Thombre <[email protected]>
…nt line, and test every identity write site - conformance kit: pass an identity on its begin_call and mark_incomplete probes, as Gym does at runtime - local store: read a torn JSON intent line as an unresolved call, so the rollout freezes incomplete instead of raising - tests: cover each site that writes the call identity, and the two fixes above Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
87e9475 to
7655146
Compare
…nd carry agent_kind on trajectory model calls - checkpoint: export copies the identity a row reads from its call's intent onto the row, since the intents stay with the old attempt; a restored failure no longer turns episode-wide - trajectory: TrajectoryModelCall has agent_kind beside agent_instance, the collector copies it from the captured call, and the 1.0 projection drops it - docs: say which records leave out the identity of an unnamed agent and which write null, and that rollout_id and capture_key are one value Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
|
Reply to the automated review (both RISK findings), now at 613ae73, rebased onto current 1. Checkpoint export loses inherited failure identity — fixed in 613ae73. 2. Conformance kit does not exercise the new write keyword — fixed in 7655146. Every Validation: the core unit suite at this head, run on Slurm against |
|
@cmunley1 thanks for catching this.
The branch is rebased onto current |
|
@marcromeyn thanks, all three are in 613ae73:
If the health checks or EvalRDL would be simpler with |
|
/ok to test 613ae73 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44022114561 |
What changed and why
Several agent instances can call one model server in an episode, but nothing recorded which one made a call or which model server served it. This PR puts that identity on every record, so capture (PR 3) can keep agent instances apart and a trainer can select them. It is the design's "identity on every record", for the fields Gym has a source for today.
agent_instanceTokenEntry,CallRecord,ManifestFailure, ledger intent, refusal and failure rows, the local store's intent and incomplete marksagent_kindmodel_refTokenEntry,CallRecord,ManifestFailure, ledger rows and marks (model-call records already carry it)CallIdentity(agent_instance+ModelRef) is carried onCaptureContext, which the capture middleware builds from the resolved path and the server's name.ModelRefhas the shape and value ofconfig_types.ModelServerRef; it lives intoken_id_capture/records.pyso capture records stay importable without Gym's configuration stack.begin_call,refuse_call,record_failureandmark_incompletetake a keyword-onlyidentity, and every caller in the sink, the external capture handlers, the model server and the vLLM model server passes the call's identity.commit_entrystamps it on everyTokenEntry.TokenEntry,CallRecord,ManifestFailureandRolloutReceiptomitagent_instance,agent_kindandmodel_refwhen unset, so a single-agent row serializes exactly as onmainexcept formodel_ref. The local store's intent and incomplete marks stay bare call ids unless the call has an identity.RolloutReceipt.agent_instance(optional):Nonemeans the receipt covers the whole episode, as today. A trainer that builds one receipt per selected agent instance sets it.compute_staging_digest, so the digest version does not change.x-session-id: the header name and its read move intonemo_gym.correlation; it is still recorded asclient_session_idand not interpreted.ModelCallRecordreadsagent_instanceandagent_kind.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 MS,LG thisWhere 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 record (this PR)pranav/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 timepranav/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.test_checkpoint_model.py::test_a_failed_publication_poisons_the_call_and_sends_no_answer, asserted a failure row withoutmodel_ref; its expectation now includes the call's identity, and the core suite of PR 3, whose branch contains the fixed commit, fails only the baseline set.test_token_capture_ledger.py: on both ledger stores, unnamed rows carry onlymodel_ref; one episode withassistantandjudge.1names its agent instance and agent kind on every row (calls, failures, intents, refusals); a failure written without a name inherits its intent's identity; a failure with neither stays episode-wide.test_token_id_capture.py: two agent instances on one model server name every token entry, intent and model-call record; an unnamed call records only the model server, and its token entry, model-call record and intent line matchmainexcept formodel_ref.test_token_capture_staging_core.py: aRolloutReceiptwithoutagent_instancevalidates and serializes as onmain; one with it validates; the identity fields are not part of aCallRecord's digest and are omitted when unset.test_correlation.py:x-session-idis read only when it has one non-empty value.Rollout evidence
Not yet run. Before this leaves draft: smoke rollouts with capture on for one single-agent example and one multi-agent environment, checking
agent_instanceandmodel_refin the ledger and model-call records.Compatibility
model_ref. Like every column of the staging wire models (extra="forbid"), the new fields bind the model server and the framework to one Gym version, assource_capture_keyandfinish_reasonalready do.CaptureLedgerorTokenSinkmust accept the keyword-onlyidentityonbegin_call,refuse_call,record_failureandmark_incomplete. The in-repo implementations and conformance fakes are updated.🤖 Generated with Claude Code