Repository navigation
fix(verifiers_agent): never store the policy server's session cookie - #3316
Merged
Merged
Conversation
vllm_model picks a vLLM engine per session (sha256(session_id) % len(base_urls) in _resolve_client) and mints the session id per cookie jar (server_utils.setup_session_middleware). openai.AsyncOpenAI sits on an httpx client that persists cookies, so the single client this agent shares across every rollout in its process was one session and therefore one engine: on CMH job 3670120 (2026-09-10) 512 concurrent rollouts ran on 6 of 48 engines while 42 sat idle, and the router's outbound connection table showed exactly those six. Keep the shared client -- the pool has to stay hot -- and give it a CookieJar whose set_cookie is a no-op. Every request is then cookie-less, the router mints a fresh session id per request, and sha256 spreads them over every engine. This is what Gym's own aiohttp client already does with a DummyCookieJar. Pass the bare CookieJar: httpx.Cookies adopts a CookieJar instance as-is but copies an httpx.Cookies into a fresh stdlib jar, which would silently discard the no-store behaviour. A client per rollout also spreads the load (CMH 3670792 reached 48 of 48 engines) but is the wrong fix: each rollout's single pooled connection sat idle through its tool phases, the router's uvicorn closes idle connections after 30 s, and the next turn raced that close -- 468 of 512 rollouts aborted with APIConnectionError -> ReadError(BrokenResourceError), where the shared-client runs had zero. Tested by driving the client through an httpx.MockTransport that sets Set-Cookie on every reply: three consecutive chat completions send no Cookie header, the jar is _NoStoreCookieJar, and _get_client() returns one shared client. A positive control shows a stock AsyncOpenAI does replay the cookie from the second request on, so the suite is known to be sensitive; the cookie test fails if the cookies= argument is dropped. Squashed from 19bfe25, a100181 and 2e7b26a, without the configurable client timeouts those carried; those land separately. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Daniele Molinari <[email protected]>
d-molinari
marked this pull request as ready for review
September 11, 2026 15:51
cmunley1
approved these changes
Sep 11, 2026
Contributor
|
/ok to test ec9dc16 |
cmunley1
pushed a commit
that referenced
this pull request
Sep 14, 2026
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]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
fixes severe rollout routing unbalance when training with verifiers_agent
Context
vllm_model picks a vLLM engine per session (sha256(session_id) % len(base_urls) in _resolve_client) and mints the session id per cookie jar (server_utils.setup_session_middleware). openai.AsyncOpenAI sits on an httpx client that persists cookies, so the single client this agent shares across every rollout in its process was one session and therefore one engine.
Keep the shared client -- the pool has to stay hot -- and give it a CookieJar whose set_cookie is a no-op. Every request is then cookie-less, the router mints a fresh session id per request, and sha256 spreads them over every engine. This is what Gym's own aiohttp client already does with a DummyCookieJar. Pass the bare CookieJar: httpx.Cookies adopts a CookieJar instance as-is but copies an httpx.Cookies into a fresh stdlib jar, which would silently discard the no-store behaviour.
A client per rollout also spreads the load but each rollout's single pooled connection sat idle through its tool phases, the router's uvicorn closes idle connections after 30 s, and the next turn raced that close.
Tested by driving the client through an httpx.MockTransport that sets Set-Cookie on every reply: three consecutive chat completions send no Cookie header, the jar is _NoStoreCookieJar, and _get_client() returns one shared client. A positive control shows a stock AsyncOpenAI does replay the cookie from the second request on, so the suite is known to be sensitive; the cookie test fails if the cookies= argument is dropped.
Squashed from 19bfe25, a100181 and 2e7b26a, without the configurable client timeouts those carried; those land separately.
Checklist
pre-commit run --all-files) (so CI lint/format/copyright pass).git commit -s) (so the DCO check passes).