Skip to content

fix(checkpoint): close agent-run resources sessions by their seeded ID - #6421

Merged
ananthsub merged 2 commits into
mainfrom
amahishi/fix-legacy-resources-session-close-20261118
Nov 20, 2026
Merged

ananthsub merged 2 commits into
mainfrom
amahishi/fix-legacy-resources-session-close-20261118

Conversation

@macandro96

Copy link
Copy Markdown
Contributor

Summary

  • Report the cookie-bound resources session ID on successful checkpoint-enabled seeds using x-ng-resources-session-id (percent-encoded for HTTP headers).
  • Have Simple Agent and Tool Simulation Agent retain that ID in their legacy /run continuations and use it for /close_session, including after restore.

An agent-run seed does not assign a resources session ID. Cleanup previously sent the agent's run:<capture_key> key alongside a cookie naming the actual resources session, so session routing correctly rejected the close with HTTP 409. The warning was caught and the reward returned, but the resources participant could retain the session after replayable verification.

This fixes that mismatch without weakening cookie/body validation, changing close timing, dropping cookies, or changing attempt fencing. Related lifecycle/routing contracts: #3888 and #3909. No separate issue: the bug and its reproduction are contained in this PR.

Compatibility

  • No configuration or model-input/output changes; checkpointing-disabled behavior is unchanged.
  • The seed header and continuation field are additive. Older servers and snapshots lacking the ID retain the previous fallback; this does not retroactively repair cleanup of an older snapshot missing that metadata.
  • Regression coverage includes fresh closes, verify/return restores, successive Tool Simulation Agent restores, replaced seed IDs, unchanged 409 enforcement, checkpointing disabled, and header encoding.

Validation

  • 277 affected agent/resources tests passed.
  • 93 checkpoint-control tests passed.
  • 90 session-routing tests passed (local sockets enabled).
  • pre-commit run --all-files passed, including package layering; checks on the final staged files also passed.
  • Regression tests against untouched main reproduced the wrong close ID and missing restored ID: 2 expected failures, 3 compatibility cases passed.
  • Final combined validation of the exact pushed commit (including public-API checks): 1,570 passed, 6 warnings. This ran in a node-local checkout with Git metadata and local test sockets enabled.

Rollout evidence / readiness

Draft pending a representative live-model smoke rollout. The local tests use controlled model replies, a real verifier, and the real resources/session-routing middleware; no new GPU job was launched. Reward/convergence changes are not claimed.

Documentation: protocol metadata and fallback behavior are documented inline; there is no new user configuration.

@macandro96 macandro96 added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working labels Nov 19, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 19, 2026
@macandro96
macandro96 marked this pull request as ready for review November 19, 2026 00:32
@macandro96
macandro96 requested a review from ananthsub November 19, 2026 00:36

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

RISK: Required real-model smoke evidence is still missing

The PR description explicitly leaves the representative live-model smoke rollout pending. This changes cleanup behavior in both Simple Agent and Tool Simulation Agent, so the real-model smoke requirement in AGENTS.md applies. Controlled model replies do not satisfy that requirement. This is a validation gap, not a demonstrated code defect.

Could you run a representative checkpoint-enabled /run smoke for each changed agent using a real model and replayable resources server through session routing, then record the configuration, revision, reward and cleanup outcome? Include a restored replacement attempt. Expected outcomes: fresh and restored runs return the verifier result, /close_session receives the decoded ID matching the resources cookie, and the close succeeds without the caught warning or a session left tracked by the checkpoint participant. No code change is requested unless the smoke exposes a failure.

Keep the neighboring contracts intact: the Simple Agent restore test must still return trajectory rollout ID 0-0-a1 and close the same resources ID under attempts 0 and 1; the successive Tool Simulation Agent restore test must still return reward 1.0 with one successful close. The routed-close regression must still reject run:r with HTTP 409 before accepting the reported ID. Servers and snapshots without the added metadata must keep the documented fallback.

I inspected all nine changed files and traced the affected session routing and continuation paths. I found no code defect in that inspection. I did not execute tests or independently verify the reported test results.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 19, 2026
ananthsub
ananthsub previously approved these changes Nov 19, 2026
Comment thread nemo_gym/server_runtime/__init__.py Resolved
Comment on lines +1291 to +1293
async def _close_legacy_resources_session(
self, body: SimpleAgentRunRequest, cookies: Any, *, resources_session_id: str | None = None
) -> None:

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.

Both agents now repeat the same four pieces:

  • reading the ID from the seed reply
  • adding it to every boundary
  • the close with its run: fallback
  • _LEGACY_SESSION_PREFIX

The copy in tool_simulation_agent is at L197-L232 and L302-L317. The next agent that adopts LegacyRun has to copy all four, or it brings this bug back.

A LegacyRun method in _checkpoint/agent.py could record the seed reply, add the ID to each boundary, and build the close request. Every agent's own /run would then use one mechanism. A follow-up PR is fine; this does not block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I will move this into a shared LegacyRun method in a follow-up PR, so this one stays focused on the fix.

@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test b980611

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 19, 2026 22:41
macandro96 and others added 2 commits November 19, 2026 15:13
- Rename the seed-reply header to x-ng-checkpoint-resources-session-id,
  matching its x-ng-checkpoint-* siblings, and keep its constant private;
  seed_resources_session_id stays the public reader.
- Say that every successful seed reports the ID, and that the run: fallback
  close is refused by session routing and cannot release the session.
- Test on a server with the base close and session-state hooks, routed as a
  worker, that the reported ID releases the session state and that the
  worker's ownership then expires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96
macandro96 force-pushed the amahishi/fix-legacy-resources-session-close-20261118 branch from b980611 to ae635c8 Compare November 19, 2026 23:19
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test ae635c8

@macandro96
macandro96 requested a review from ananthsub November 19, 2026 23:21
@ananthsub
ananthsub added this pull request to the merge queue Nov 20, 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/44656991491

Merged via the queue into main with commit 1233821 Nov 20, 2026
79 of 84 checks passed
@ananthsub
ananthsub deleted the amahishi/fix-legacy-resources-session-close-20261118 branch November 20, 2026 02:08
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 risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants