Repository navigation
fix(verifiers_agent): carry the rollout capture prefix on the model client - #3321
Conversation
…lient Model-call capture is keyed by the `/ng-rollout/<id>` URL prefix, but `_get_client` built its base URL straight from the model server's host and port, so no call was ever attributed to a rollout. The capture store stayed empty, the projected trajectory came back with `model_call_capture_no_records` and `model_calls_unavailable`, and every rollout-health check degraded to `unobserved`. That matters because an unobserved verdict is not loud: the run still prints a score, `failure_reason` stays null and `rollouts_failures.jsonl` stays empty. A systematically broken run is then indistinguishable from a healthy low-scoring one, and the checks that would have caught it -- `agent_turn_hollow`, `model_call_zero_completion_tokens`, `model_call_failed`, `model_call_runaway_generation` -- are exactly the ones that go dark. Resolve the base URL through `resolve_model_base_url`, which applies the prefix, and key the client cache by (model server, rollout id) so one rollout's prefix is not pinned onto every later rollout. `rollout_id_from_run` returns None when capture is disabled, which collapses this back to the previous unprefixed URL and a single cache entry. Measured on a real `gym eval run` against a remote endpoint: capture files written per rollout go from 0 to 1, trajectory `model_calls` from 0 to 2, and reported tokens from 0/0 to 3153 prompt / 966 completion. This is the first half. Turn-level checks stay unobserved until the agent also emits `ng_agent_observations`; that needs a conversation/model-call projection out of the verifiers trajectory and is left to a follow-up. Signed-off-by: Wojciech Prazuch <[email protected]>
… capture path The matrix row was all `X`, which is correct for the broken path but stale once model calls are correlated again. With the capture prefix applied, the environment's own calls route through the Gym Model Server and are captured, so C1 (per-call token statistics and response metadata), C2 (token counts) and C4 (model-visible history reconstructable from the rollout JSONL) hold on that path. Measured on a real `gym eval run` against a remote endpoint: 4 captured calls with per-call request and response payloads, 3153 prompt / 966 completion tokens, and 4 model calls projected into `ng_trajectory`. C3, C5 and C6 stay `X`: the agent emits no `ng_agent_observations`, so there are no turns and no tool attempt status or timing, and the rollout-health checks that read agent turns or bound calls remain unobserved. C7 is left unchanged because this PR does not affect it. Signed-off-by: Wojciech Prazuch <[email protected]>
|
Added the capability-matrix row for
C1/C2/C4 are the capture-derived criteria this PR restores — measured on a real Two things I would value a review on from whoever owns the matrix:
That second one is what currently keeps all eight turn- and call-level health checks |
|
🌿 Preview your docs: https://nvidia-preview-wprazuch-verifiers-agent-capture-prefix.docs.buildwithfern.com/nemo/gym Here are the markdown pages you've updated: |
|
Correcting something I wrote above: I said reaching
Two consequences:
Grepping for So OpenCode rollouts should also return Which means this PR alone brings Stated as falsifiable: this is a code-path argument plus the test fixtures, not an observed OpenCode run. If anyone has an OpenCode The open question is therefore broader than I first framed it: is |
| client_cache: dict[str, NeMoRLChatCompletionsClient] = Field(default_factory=dict) | ||
| # Keyed by (model-server name, rollout id): the rollout id selects the | ||
| # capture prefix baked into the client's base_url. | ||
| client_cache: dict[tuple[str, Optional[str]], NeMoRLChatCompletionsClient] = Field(default_factory=dict) |
There was a problem hiding this comment.
[P1] Avoid retaining one HTTP client per rollout
This cache is now keyed by a rollout ID that is effectively unique for every attempt, so a persistent agent process accumulates one NeMoRLChatCompletionsClient and one underlying AsyncOpenAI transport/connection pool per rollout. Nothing evicts or closes these clients. Large or repeated evaluations can therefore grow memory, sockets, and connection pools without bound; this also amplifies the httpx high-concurrency issue called out in the repository guidance. Please keep one shared transport and create only a lightweight per-run client/view with the prefixed base_url, or scope each per-run client to run_group() and close it in finally, rather than caching clients indefinitely by rollout ID.
There was a problem hiding this comment.
Yes, that is correct, thanks for fixing that!
| them. ``rollout_id_from_run`` returns ``None`` when capture is disabled, | ||
| which collapses this back to the unprefixed URL and a single cache entry. | ||
| """ | ||
| rollout_id = self.rollout_id_from_run(body) if body is not None else None |
There was a problem hiding this comment.
[P2] Recover correlation from the prefixed Responses route too
rollout_id_from_run(body) covers /run because rollout collection injects _ng_rollout_id into that request body. It does not cover a direct /ng-rollout/{rollout_id}/v1/responses call, where the correlation ID lives in request.path_params and is not normally present in the body. That supported prefixed route will still construct an unprefixed model client and lose capture. Please resolve the ID from the request path/current rollout context as well as the run body (and pass the resolved ID into _get_client). A route-level regression test would catch this; the new unit test currently patches rollout_id_from_run to read a synthetic body.rollout_id, so it does not exercise the real protocol.
There was a problem hiding this comment.
Added an implementation here: #3361, let me know if this implements what you described.
Signed-off-by: yaoyu-33 <[email protected]>
|
Beside the unbounded growth of the cache, there's also a functional issue. I previously attempted to use one client per rollout and ran into the following issue:
The proposed solution is similar to @yaoyu-33 suggestion:
Something along the lines of: def _get_client(self, body=None) -> NeMoRLChatCompletionsClient:
shared = self._shared_openai_client() # built once, DefaultAsyncHttpxClient(cookies=_NoStoreCookieJar())
rollout_id = self.rollout_id_from_run(body) if body is not None else None
if rollout_id is None:
return NeMoRLChatCompletionsClient(shared)
prefixed = shared.with_options(base_url=self.resolve_model_base_url(self.config.model_server.name, rollout_id))
return NeMoRLChatCompletionsClient(prefixed) # no cache needed; no pool, no jar, no sockets of its ownwith caveat that the NeMoRLChatCompletionsClient should never call |
The per-run copy shares the cached client's httpx transport, so closing it closes the pool every later rollout is still using. `Client.close()` does `await self.client.close()`, and the wrapper looks disposable, which is exactly the shape of mistake that lands in a `finally`. Nothing on the current path closes it -- not this agent, not `run_group`/`generate` on the verifiers legacy API, and every `.close()` call site in verifiers sits under `verifiers/v1/`, which this agent does not use. The rule is written into the docstring rather than enforced by a test on purpose: I could not build one I can prove catches the regression. With the copy deliberately replaced by a fresh `AsyncOpenAI`, the per-run client still reports the shared `_client` and the `_NoStoreCookieJar`, while the same two discriminators do separate borrowed from fresh on bare openai objects. Until that is understood, a green test here would assert nothing -- and note the same doubt applies to the existing `second.client._client is first.client._client` assertion. Signed-off-by: Wojciech Prazuch <[email protected]>
|
@d-molinari I have not seen such a scenario in my runs, so probably your case is something else, which this PR does not cover. On your |
Addresses the **P2** review comment on #3321. Targets that branch rather than `main`, so the diff here is only the route fix and it lands together with the prefix work. ## The gap `rollout_id_from_run` only covers `/run`, where rollout collection injects `_ng_rollout_id` into the request body. The supported `/ng-rollout/<id>/v1/responses` route carries the id in the **path** instead. There is no `RolloutContextMiddleware` on agents to recover it either — that is installed on resources servers (`base_resources_server.py:152`); agents register explicit prefixed routes (`base_responses_api_agent.py:81`) and nothing sets the contextvar on them. So `current_rollout_id()` is `None` on that route. A call on the prefixed Responses route therefore built an **unprefixed** client and lost capture — the same silent failure #3321 set out to fix, on the other entry point. ## The fix `responses` already receives the `Request`, so resolve the id from the run body first and fall back to `request.path_params`. Gated on the same `_capture_correlation_enabled` as the body path, so a run with capture off keeps the shared unprefixed client and nothing changes for it. ## Tests Driven through the **real FastAPI routes**, not by patching `rollout_id_from_run` — the earlier unit test read a synthetic `body.rollout_id` and so never exercised the protocol, which was the second half of the P2 comment. These POST through the app so the path parameter is populated the way the server populates it. | test | asserts | |---|---| | `test_prefixed_route_correlates_the_model_client` | `/ng-rollout/7-2/v1/responses` → `http://policy/ng-rollout/7-2/v1` | | `test_unprefixed_route_stays_unprefixed` | `/v1/responses` → `http://policy/v1` | | `test_prefixed_route_is_inert_when_capture_is_disabled` | capture off → shared unprefixed client | The first fails without this change with `'http://policy/v1' != 'http://policy/ng-rollout/7-2/v1'`. The other two are negative controls and pass either way by design. ## One thing to be aware of `test_policy_client_never_replays_the_session_cookie` and `test_a_default_openai_client_would_replay_the_session_cookie` (from #3316) fail in my sandbox — but they fail on the **unmodified branch head** too, so they are not caused by this change. They look like they need network egress my sandbox denies. Worth a second pair of eyes in a normal environment. Signed-off-by: Wojciech Prazuch <[email protected]>
|
/ok to test 52a3dff |
…l URL (NVIDIA-NeMo#3397) <!-- Thanks for contributing to NeMo Gym! Please fill out the sections below. --> ## What does this PR do? <!-- Briefly describe the change and the motivation. Link any related issue, e.g. "Closes #123". --> Passes `token_capture=self._token_id_capture_enabled()` where `anyterminal_agent` builds the model URL for the task container, so training-token capture records the rollout. Same class of silent failure as `verifiers_agent` in NVIDIA-NeMo#3321. Training-token capture is keyed by the `/ng-rollout/<id>/training-token-capture` URL prefix that an agent hands its model client, see `rollout_path_prefix` in `nemo_gym/server_utils.py` and its callers in `nemo_gym/base_responses_api_agent.py`. `anyterminal_agent/app.py:_setup_params` builds the model URL for the task container without it: ```python server_config["model_server_url"] = apply_rollout_prefix(server_config["model_server_url"], rollout_id) ``` `apply_rollout_prefix` in `nemo_gym/server_utils.py` takes a keyword-only `token_capture` that defaults to `False`, so the container gets the evaluation prefix `/ng-rollout/<id>` and the model server records no training tokens for the rollout. With `token_id_capture.enabled: true` and `token_id_capture: true` on the agent, the configuration validates and the run completes normally. Every rollout comes back with `_ng_token_capture.n_calls == 0` and `mask_sample: true`. No error, no warning. A run that captured nothing looks like a healthy one until the trainer masks every sample. The base class passes the keyword in `url_path_for_run`, `base_url_for_run`, and `resolve_model_base_url`, and `claude_code_agent` and `swe_agents` pass it since NVIDIA-NeMo#2124. The anyterminal wrapper builds its URL on its own path, and that path did not get the keyword. With capture off, `_token_id_capture_enabled()` is `False` and the URL is unchanged, so evaluation runs do not move. ## Tests Two tests in `TestSetupParams`. They call `_setup_params` with a real global config dict instead of patching the capture protocol. | test | asserts | |---|---| | `test_model_server_url_carries_the_training_capture_prefix` | capture on gives `http://policy:8000/ng-rollout/7-2/training-token-capture` | | `test_model_server_url_keeps_the_plain_rollout_prefix_without_capture` | capture off gives `http://policy:8000/ng-rollout/7-2` | The first fails on `main` with `'http://policy:8000/ng-rollout/7-2' != '.../training-token-capture'`. The second is a negative control. ``` pytest responses_api_agents/anyterminal_agent/tests/test_app.py ``` 81 passed. `pre-commit run --all-files` clean. ### On real rollouts `gym eval run` on three Terminal-Bench 2 tasks, Codex CLI 0.144.4 running inside the task container through `anyterminal_agent`, Qwen3-8B served by vLLM on one GPU, `token_id_capture.enabled: true` with the agent opted in. Both arms use the same overlay, the same task list, and the same vLLM process. The only difference is this keyword. Gym is `main` @ `5b34fcdac` in both arms. | | without the keyword (`main`) | with the keyword | |---|---|---| | task containers handed a `/training-token-capture` prefix, per `params.json` | 0 of 3 | 3 of 3 | | rollouts with `_ng_token_capture.n_calls > 0` | 0 | 3 | | rollouts with `mask_sample: true` | 3 of 3 | 0 of 3 | | captured model calls | 0 | 147 | | generation tokens delivered | 0 | 14,449 | | `function_call` items Codex produced | 136 | 145 | The last row shows Codex ran normally in both arms. The difference is only in what the model server recorded. On the unfixed arm `gym eval run` also prints `Rollout health: 3 checked, 0 healthy, 0 unhealthy, 3 unobserved`. Both arms also carry local workarounds for NVIDIA-NeMo#3312 and NVIDIA-NeMo#3313, which Codex needs to complete a turn against a chat-backed model server. They touch the Responses converter and the streaming event, not the URL path. ## Checklist - [x] I have read the [contributing guidelines](https://docs.nvidia.com/nemo/gym/latest/contribute/development-setup). - [x] The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs. - [x] Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable). - [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so CI lint/format/copyright pass). - [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check passes). Signed-off-by: jiwasawa <[email protected]>
…VIDIA-NeMo#3403) ## What A run of any `verifiers_agent` benchmark reports `0 healthy, 0 unhealthy, N unobserved`. 10 of the 13 rollout health checks have nothing to read, so an infra outage and a model genuinely scoring zero look identical in the run summary. This makes the agent emit the evidence those checks need. Measured on a 2-task `automationbench` run against a remote endpoint: | | before | after | |---|---|---| | `Rollout health:` | `2 checked, 0 healthy, 0 unhealthy, 2 unobserved` | `2 checked, 2 healthy, 0 unhealthy, 0 unobserved` | | checks with no input | 10 | 0 | Newly evaluated: `model_call_failed`, `model_call_zero_completion_tokens`, `model_call_missing_token_counts`, `model_call_runaway_generation`, `agent_turn_hollow`, `rollout_missing_agent_turns`, `trajectory_capture_mismatch`, `task_no_successful_model_calls`, `rollout_token_count_mismatch`, `task_consistently_unhealthy`. ## Why it needed a different approach than `simple_agent` Turns reach the checks only through a producer-supplied `ng_trajectory` (`rollout_collection.py:_build_trajectory_record`) — `ng_agent_observations` never supplies them. With no turns, `_canonical_model_call_references` finds no references and the bound-call checks go unobserved too. So the agent has to produce a `TrajectoryRecord`, and only 2 of 47 agents currently do. `simple_agent` builds its `ModelCallRef`s from `model_response.id` because it issues the calls itself. Here `verifiers` owns the call loop and hands back only a rollout summary, so the agent never sees a response. The client is the one seam it does own: every call passes through `get_native_response`, so `_ResponseIdRecordingClient` records ids and accumulates usage there. No change is needed in `verifiers`. The evidence rides on the response object rather than on `self`, because rollouts run concurrently. ## Details worth a look - **One turn per recorded response, each claiming only its own call.** The checks read `turns[*].model_calls`; an invocation-level list binds but leaves every per-call finding unattributable. - **Turn answers are sliced per turn.** Handing every turn the whole rollout's items makes each turn look non-hollow as long as any one turn spoke, so `agent_turn_hollow` could never fire. - **The `msg_empty` placeholder is not counted as a turn.** `_convert_trajectory_to_output` appends it whenever no token ids came back, which is every rollout served by a remote endpoint (`vllm_model.yaml` sets `return_token_id_information: false`). Counting it would dress the one case worth catching — a call that produced nothing — as a turn that spoke. - **A rollout whose calls all failed** records no ids and reports a `model_call_reference_unavailable` gap rather than an empty trajectory. - **`response.usage` was null for every verifiers rollout**; it now carries the summed token totals. ## Testing `gym eval run --benchmark automationbench --limit 2` against a remote endpoint, observability on, before and after — the table above. Per-turn output from the "after" run: ``` turn 1 answer: ['message', 'function_call'] step_count: 1 calls: ['chatcmpl-80ee9f79edc7954a'] turn 2 answer: ['message', 'function_call'] step_count: 1 calls: ['chatcmpl-bfa942bd8fe3aa2e'] verdict: healthy unobserved: [] findings: [] ``` 6 unit tests in `tests/test_app.py`. Each was mutation-checked: the corresponding invariant was broken in `app.py` and the test confirmed to fail. One of them was vacuous on the first pass (it passed with the invariant removed) and was rewritten against the case that actually distinguishes. `pre-commit run --all-files` clean; `tests/unit_tests/test_rollout_{observability,health,collection}.py` 284 passed. ## Known gap this does not close A negative control — same run with an invalid API key, so all 6 model calls return `403 auth` — still reports `2 checked, 0 healthy, 0 unhealthy, 2 unobserved` and reward 0.0. The capture holds the evidence (`status_code: 403`, `error_category: auth`), and the agent correctly reports the `model_call_reference_unavailable` gap, but the gate cannot use either: - `model_call_failed` reads `OWNED_MODEL_CALLS`, and a failed call has no `response_id`, so it can never bind. Catching it needs a check that reads the capture rows directly rather than through bindings. - `rollout_missing_agent_turns` reads `AGENT_TURNS`, and `rollout_health.py:159` marks any `AGENT_TURNS` check unobserved when no turns were observed — so the check meant to catch "this rollout has no turns" is skipped exactly when there are none. Both are in the health gate, not in this agent, so they are out of scope here. Flagging for whoever owns `rollout_health` — happy to open a separate PR if that is wanted. This matters in practice: a 600-task run had 75 failed calls across 61 rollouts, 25 of which ended on error, and every one was reported as an ordinary zero. ## Related - NVIDIA-NeMo#3321 restored the `/ng-rollout/<id>` capture prefix in this agent (capture files 0 → 1 per rollout). - NVIDIA-NeMo#3361 extends that to the prefixed Responses route. This PR is the next layer: capture now happens, and the trajectory that binds to it exists. --------- Signed-off-by: Wojciech Prazuch <[email protected]>
Model-call capture is keyed by the
/ng-rollout/<id>URL prefix(
nemo_gym/base_responses_api_model.py,_CaptureMiddleware). Butverifiers_agent/app.py:_get_clientbuilt its base URL straight from the modelserver's host and port:
so no model call was ever attributed to a rollout. Downstream: capture store
empty → trajectory carries
model_call_capture_no_recordsandmodel_calls_unavailable→ every rollout-health check degrades tounobserved.The client cache was also keyed by model-server name alone, so even with the
prefix applied the first rollout's client would have been reused for every
later rollout.
Why this is worth fixing rather than tolerating
An
unobservedverdict is quiet. The run still prints a score,failure_reasonstays
null, androllouts_failures.jsonlstays empty (0 bytes). Asystematically broken run is then indistinguishable from a healthy low-scoring
one — and the checks that go dark are precisely the ones that would catch it:
agent_turn_hollow,model_call_zero_completion_tokens,model_call_failed,model_call_runaway_generation.Fix
Resolve through the base class's
resolve_model_base_url(name, rollout_id),which applies the prefix, and key the cache by
(model server, rollout id).rollout_id_from_runreturnsNonewhen capture is disabled, which collapsesthis back to the previous unprefixed URL and a single cache entry — so the
no-observability path is unchanged.
Verification
Real
gym eval run --benchmark automationbench --model-type vllm_modelagainsta remote OpenAI-compatible endpoint, with
observability_enabled=true:model_callsmodel_call_capture_no_records,model_calls_unavailable,turns_unavailable,conversation_unavailableturns_unavailable,conversation_unavailableTwo regression tests added; both fail on
mainand pass with the fix.pre-commitclean.Scope — this is half the fix
Turn-level checks (
AGENT_TURNS, andBOUND_CALLSvia_canonical_model_call_references) stayunobserveduntil the agent also emitsng_agent_observationswith anAgentInvocationcarryingconversationandmodel_calls: list[ModelCallRef]. The conversation is already reconstructed in_convert_trajectory_to_output, but correlating verifiers' internal completionsback to captured
model_call_ids needs design input. Proposed as a follow-uprather than bolted on here.
Open question for reviewers
observability_enableddefaults toFalse, and no EFB gym recipe sets it(
grep -rn observability_enabled configs/ reviewed_configs/→ nothing). Soevery gym benchmark on the EFB path currently runs health-blind, not just this
one. Should the harness warn when health checking runs with observability off,
instead of reporting
0 healthy, 0 unhealthy, N unobservedas if it were apass? Happy to open that separately.