Skip to content

fix(simple-agent): preserve session cookies across response deltas - #3928

Draft
rawsh wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
rawsh:feature/simple-agent-cookie-deltas
Draft

rawsh wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
rawsh:feature/simple-agent-cookie-deltas

Conversation

@rawsh

@rawsh rawsh commented Oct 2, 2026

Copy link
Copy Markdown

A tool response without Set-Cookie currently discards the seeded resource session, causing the later verifier request to fail with HTTP 409. Merge cookie deltas at the model response, tool response, seed, and agent response boundaries. Responses that rotate a cookie update its value while other session cookies remain available.

Three real HTTP regressions cover tool HTTP 500, successful tools without cookie headers, and cookie rotation. They use SimpleAgent, ServerClient, and a disabled implicit client cookie jar. Existing unit fixtures use real SimpleCookie objects so they exercise the transport contract. This standalone bug has a direct regression reproduction, so a separate issue is unnecessary. The self-dispatch and optional trajectory behavior described in #2293 remains covered by the existing component tests.

Validation against the final signed-off commit:

  • Python 3.13.14 with uv sync --frozen --extra dev: 23 SimpleAgent tests passed, 0 skipped. The unmodified upstream base fails two new HTTP cases with verifier 409; its rotation control passes.
  • gym env test +entrypoint=responses_api_agents/simple_agent +should_validate_data=true: 23 passed, 0 skipped, in the normal isolated component environment.
  • pre-commit run --all-files: all applicable hooks passed; the Markdown filename hook had no matching files.
  • Two native real-model smoke rollouts through a qualified ZAYA 8B endpoint called get_weather(city=Paris). Cookie-free tool 200 and 500 both reached same-session verification and returned run 200. The actual model reported cold weather and tool unavailability respectively; total usage was 829 and 797 tokens. The controlled resource fixture is diagnostic smoke, with raw agent/tool/verifier results inspected; it does not qualify a production training shape.

Existing configurations need no migration. Previously invalid session-loss episodes can now reach verification, which can change benchmark completion and reward statistics. Hosted CI and maintainer review remain pending; downstream pins and production rollout are separate.

@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Oct 2, 2026
@rawsh
rawsh marked this pull request as ready for review October 2, 2026 12:56
@yaoyu-33 yaoyu-33 added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 2, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Oct 4, 2026
@yaoyu-33 yaoyu-33 removed the needs-review PR is ready for code review and waiting on a reviewer label Oct 4, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 5, 2026
@zyzhou5

zyzhou5 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@rawsh Could you rebase onto main and update the patch for the current cookie handling? The tool-response cookie merge is already covered by #3784.

@zyzhou5 zyzhou5 added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 9, 2026
Ashish-Soni08 pushed a commit to Ashish-Soni08/Gym that referenced this pull request Oct 10, 2026
…nt holds no cookie jar (NVIDIA-NeMo#4449)

## What changed

Under `single_agent_turn`, the environment server seeds the resources
server and keeps the session cookie from that seed. It sends that cookie
to `/verify` and `/close_session`, and a stateful resources server finds
the episode's state by it.

`SimpleAgent` closed every agent session with `resources_cookies={}`
when the session had no direct HTTP tool grant. That is the default,
because `resources_tool_transports` on `single_agent_turn` is empty.
`single_agent_turn` replaced its cookie jar with any value that was not
`None`, so `/verify` and `/close_session` went out with no session
cookie. A resources server that keys per-rollout state by the session
cookie (sandboxes, tool environments, session dictionaries) then could
not find the episode during verify, and close could not release it.

- `SimpleAgent` now reports `resources_cookies=None` when the session
never held the resources cookie jar, and only tracks the jar when the
session has a direct HTTP grant.
- `single_agent_turn` keeps the jar from the resources seed when the
agent returns `None` or an empty jar. `nemo_user_sim` already behaves
this way.
- The `resources_cookies` field on `AgentCloseSessionResponse` now
documents that `None` or an empty jar leaves the environment server's
jar unchanged.

Related: NVIDIA-NeMo#3928 fixes cookie loss when a tool response on
the legacy `/run` path carries no `Set-Cookie`. This change covers the
agent session path when the session has no tool grant, so the two do not
overlap.

No issue: this is a standalone bug with a direct regression test.

## Validation

- `pytest environment_servers/single_agent_turn/tests/test_app.py
responses_api_agents/simple_agent/tests/test_app.py` passed.
- The new `single_agent_turn` test closes the agent with an empty jar
and with no jar, and checks that `/verify` and `/close_session` carry
the seed's cookie.
- The new `SimpleAgent` test seeds a session without a grant, runs one
activation, and checks that close reports no cookie jar.
- Both regression cases fail on the code before this change.
- `pytest -n 16 tests/unit_tests` shows the same failures with and
without this change, in `test_opensandbox_compose.py`,
`test_reward_profile.py`, `test_dataset_orchestrator.py`,
`test_sandbox_stop_retry.py` and `test_exporters.py`. None of those
touch agent sessions.
- `pre-commit run` on the changed files passed.

## Rollout evidence

N/A: the change only decides which resources cookie the environment
server forwards to `/verify` and `/close_session`. Model inputs and
outputs are unchanged, and the cookie routing is covered by the tests
above.

## Compatibility

Agents that return a non-empty `resources_cookies` jar behave as before.
An agent that returned `{}` to clear the jar now leaves the seed's jar
in place; no agent in the repository relies on that.

Signed-off-by: Ananth Subramaniam <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Oct 29, 2026
@yaoyu-33
yaoyu-33 marked this pull request as draft November 18, 2026 02:18
@yaoyu-33

Copy link
Copy Markdown
Contributor

We’re doing some cleanup of the open PR list. This PR has had no activity for over a month, so I’ve moved it back to draft.

If this change is still needed, please resolve any merge conflicts and mark the PR ready for review again when it’s ready to merge. Thanks!

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 18, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 18, 2026

This branch has not been deployed

No deployments
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 community-request Issue reported or requested by someone from the community complexity:low Localized change in one scope with a small, straightforward review surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants