Repository navigation
fix(simple_agent): stay at the boundary until a held policy reply's body arrives - #4887
Merged
Merged
Conversation
…ody arrives The simple agent's turn loop wrapped only the policy `server_client.post` in `activation.awaiting_model()`. That post returns as soon as the reply's headers arrive, and the loop read the status and the JSON body afterwards, outside the boundary. The policy model server's checkpoint gate lets a reply's headers through and holds its body until resume. When the headers arrived after the model server prepared but before the agent server prepared, the agent session had already left its boundary and counted as running while it waited for a body that only resume would release. The agent server never reported ready, so prepare ran until its deadline and the commit was refused with `invalid_phase`. `_call_policy` now runs a call that posts, checks the status, and reads the JSON body and cookies, all inside `awaiting_model`. A reply held at a checkpoint now leaves the session parked at the boundary before the call, as a reply held before its headers already did. Without checkpointing the loop makes the same calls in the same order. Signed-off-by: Ananth Subramaniam <[email protected]>
macandro96
approved these changes
Oct 22, 2026
macandro96
left a comment
Contributor
There was a problem hiding this comment.
lgtm! thanks for catching this
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39697563920 |
This was referenced Oct 22, 2026
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 changed and why
The simple agent's turn loop wrapped only the policy
server_client.postcall inactivation.awaiting_model().That context tells the agent server's checkpoint participant that the session is waiting on the model from its last boundary.
The post returns as soon as the reply's headers arrive, and the loop checked the status and read the JSON body after leaving the context, so the session counted as running from that point on.
The policy model server's checkpoint gate (
PolicyAdmissionMiddlewareinnemo_gym/_checkpoint/model.py) passes a reply'shttp.response.startmessage straight through and holds only the first body chunk until resume.uvicorn writes the headers to the socket as soon as it receives that message.
A checkpoint prepares the model server before the agent server.
If a reply's headers reached the agent between those two prepares, the agent session had already left its boundary and was waiting for a body that only resume would release:
preparing;invalid_phase.Real-model saved-rollout runs hit this intermittently.
The failing prepare showed the policy model server prepared with every in-flight call held, and the agent server blocked on one or two sessions that were not at a boundary.
_call_policynow runs a call that posts, checks the status, and reads the JSON body and cookies, all insideawaiting_model.A reply held at a checkpoint now leaves the session at the boundary before the call, whether the gate held it before or after its headers were sent.
Prepare then counts the session as parked, and a restore calls the model again from that boundary.
Without checkpointing, the loop makes the same calls in the same order.
The simple agent is the only agent that uses
awaiting_model.A new simple agent test returns a reply's headers at once and holds its body until the model server resumes, then prepares the agent server while the body is held.
It checks that prepare finishes, that the exported boundary is the one before the call, and that the activation completes with the held reply after resume without calling the model again.
On the previous code, the same test leaves the agent server in
preparing.Issue
None needed: a small fix to the simple agent's checkpoint support, found by real-model checkpoint runs.
Validation
uv venv && uv sync --extra dev --extra mlflow --extra ray --extra sandbox --extra wandb --extra telemetry pytest responses_api_agents/simple_agent/tests tests/unit_tests/test_checkpoint_agent.py -n 16 pytest tests/unit_tests -n 16 NEMO_GYM_CHECKPOINT_E2E=1 pytest tests/e2e/checkpoint pre-commit run --files responses_api_agents/simple_agent/app.py responses_api_agents/simple_agent/tests/test_app.pyRollout evidence
Against vLLM 0.29.0 serving
Qwen/Qwen3-4B-Instruct-2507with Hermes tool calling, the real-model checkpoint scenarios ran repeatedly:NEMO_GYM_CHECKPOINT_E2E=1 NEMO_GYM_CHECKPOINT_VLLM_URL=http://127.0.0.1:8129/v1 \ NEMO_GYM_CHECKPOINT_VLLM_MODEL=Qwen/Qwen3-4B-Instruct-2507 pytest tests/e2e/checkpoint -k real_modelsimple_agent/app.pyon the same server, 2 of 16 runs failed in the saved-rollout scenario: prepare reached its deadline with the agent server still inpreparing, and the commit failed withagent: HTTP 409 invalid_phase 'not valid in phase preparing'.Compatibility
None.
The agent makes the same calls in the same order, and the change only moves the end of the boundary from the reply's headers to its body.