Skip to content

fix(simple_agent): stay at the boundary until a held policy reply's body arrives - #4887

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/simple-agent-held-reply-boundary
Oct 22, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/simple-agent-held-reply-boundary

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed and why

The simple agent's turn loop wrapped only the policy server_client.post call in activation.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 (PolicyAdmissionMiddleware in nemo_gym/_checkpoint/model.py) passes a reply's http.response.start message 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:

  • the agent server never reported ready;
  • prepare ran until its deadline with the agent server still in preparing;
  • the commit was refused with 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_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 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.py
  • The simple agent tests and the checkpoint agent tests pass.
  • The full unit suite passes, except the benchmark listing check, which fails on the development host because its hostname resolves to a loopback address; it is unrelated to this change.
  • Every fake-backend checkpoint end-to-end scenario passes.
  • Pre-commit passes on the changed files.

Rollout evidence

Against vLLM 0.29.0 serving Qwen/Qwen3-4B-Instruct-2507 with 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_model
  • Each run covers both real-model scenarios: saved rollouts continued after a crash and restore, and restarts.
  • With this change, all 32 consecutive runs passed.
  • With the previous simple_agent/app.py on the same server, 2 of 16 runs failed in the saved-rollout scenario: prepare reached its deadline with the agent server still in preparing, and the commit failed with agent: 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.

…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]>
@ananthsub ananthsub added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Oct 21, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 21, 2026 22:19
@ananthsub
ananthsub requested a review from macandro96 October 21, 2026 22:28

@macandro96 macandro96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks for catching this

@ananthsub
ananthsub added this pull request to the merge queue Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39697563920

Merged via the queue into main with commit 9240708 Oct 22, 2026
46 of 52 checks passed
@ananthsub
ananthsub deleted the ananthsub/simple-agent-held-reply-boundary branch October 22, 2026 00:29

This branch was previously deployed

1 inactive deployment
public — bbfd2137 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6495
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.

2 participants