Skip to content

fix(verifiers_agent): correlate the prefixed Responses route too - #3361

Merged
cmunley1 merged 1 commit into
wprazuch/verifiers-agent-capture-prefixfrom
wprazuch/verifiers-agent-capture-responses-route
Sep 14, 2026
Merged

cmunley1 merged 1 commit into
wprazuch/verifiers-agent-capture-prefixfrom
wprazuch/verifiers-agent-capture-responses-route

Conversation

@wprazuch

Copy link
Copy Markdown
Contributor

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.

Addresses the P2 review comment on #3321.

`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, and
agents get no `RolloutContextMiddleware` -- that is installed on resources
servers (`base_resources_server.py`), not on agents, which register explicit
prefixed routes -- so the contextvar is unset there. A call on that route
therefore built an unprefixed client and lost capture, which is the same
silent failure #3321 set out to fix, just on the other entry point.

`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` so a run with capture off keeps the shared
unprefixed client.

Tested at the route level rather than by patching `rollout_id_from_run`: the
tests POST through the real FastAPI app so the path parameter is populated by
the actual protocol. The prefixed-route test fails without this change with
`'http://policy/v1' != 'http://policy/ng-rollout/7-2/v1'`. The unprefixed route
and the capture-disabled case are covered as negative controls.

Note: `test_policy_client_never_replays_the_session_cookie` and
`test_a_default_openai_client_would_replay_the_session_cookie` fail in my
sandbox on the unmodified branch head as well -- they appear to need network
egress the sandbox denies, and are unrelated to this change.

Signed-off-by: Wojciech Prazuch <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Sep 14, 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.

@yaoyu-33 yaoyu-33 added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Sep 14, 2026
@cmunley1
cmunley1 merged commit d338c28 into wprazuch/verifiers-agent-capture-prefix Sep 14, 2026
10 checks passed
@cmunley1
cmunley1 deleted the wprazuch/verifiers-agent-capture-responses-route branch September 14, 2026 18:33
kajalj22 pushed a commit to kajalj22/Gym that referenced this pull request Oct 1, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working 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.

3 participants