Skip to content

fix(resources): move swebench_pro and interactive_browser onto the session contract - #4692

Merged
yaoyu-33 merged 18 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:fix/resources-session-fence-migration
Oct 26, 2026
Merged

yaoyu-33 merged 18 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:fix/resources-session-fence-migration

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #4679, which defines the contract: ResourcesSessionFence, the refusal errors, lost_session_verification, ResourcesSessionLostError, and the stricter check_resources_session_contract. This PR is stacked on it. Its base is yaoyu-33/resources-session-close-contract, which holds #4679's commits, so the diff here shows only this PR's change. After #4679 merges, this PR is retargeted to main.

nemo_user_sim was part of this PR; it moved into #4679 because #4679's stricter check fails without its fix.

What changed

Two servers move onto the resources sessions contract from #4679.

swebench_pro

  • _session_locks and _closed_sessions grew for the life of the process. They are replaced by a ResourcesSessionFence, so a closed ID is remembered for the server's session_close_retry_window_seconds (300 s by default).

  • Conflicting seeds, mismatched closes, and seeds for a closed session get 409; task_data that is not an instance, or a TaskId that does not match it, gets 422. All of these were a ValueError, so a 500 that was retried.

  • A non-golden /verify for a session with no task sandbox returns a masked session_lost sample. That covers a sandbox an earlier verify consumed, one a close released, and a session this process never held: a resent verify of a /run session, or a session from before a restart. Before:

    • a repeated typed verify raised a 500, and the episode was retried;
    • every other case graded an empty patch: it started an eval sandbox and returned an unmasked reward 0.

    A failed patch extraction from a live sandbox, such as "not a git repository", stays an unmasked failure, because the agent can cause it. A graded verify sets mask_sample, failure_kind and failure_reason itself, so stale values a caller sends are not passed through.

interactive_browser

  • _typed_locks and _typed_closed are replaced by a ResourcesSessionFence.
  • Conflicting seeds and mismatched closes get 409 instead of a ValueError (500), and task_data that is not a browser task gets 422.
  • /verify with no browser returns a masked session_lost sample. It used to return an unmasked reward 0.
  • A tool call with no browser gets 404 session_lost. It used to return a 200 observation saying the session was gone. The 404 marks the call failed in the trajectory. It does not end the turn: simple_agent still shows the body to the model and keeps going, so the masked verify is what keeps the sample out of the score.

Both servers bind the session cookie only after a seed succeeds. Before, a refused seed's 409 or 422 reply pointed the caller's cookie at the session it was refused, which may belong to another episode.

Both servers' tests now run check_resources_session_contract(..., keeps_state=True, holds_state=..., verify_body=...). The check covers seed, re-seed, a conflicting seed, close, a cookie-less close after a lost seed reply, late seeds, and a masked verify after close.

Where the changes apply

sequenceDiagram
    participant E as Environment server
    participant A as Agent server
    participant R as swebench_pro / interactive_browser
    E->>R: POST /seed_session
    R-->>E: 200, or 409 conflict/closed, 422 bad task_data (was 500)
    A->>R: browser tool call
    R-->>A: 404 session_lost when the browser is gone (was an in-band observation)
    E->>R: POST /verify
    R-->>E: masked session_lost sample when the sandbox or browser is gone (was 500 or reward 0)
    E->>R: POST /close_session (cookie optional)
    R-->>E: 200, released by ID, fenced for session_close_retry_window_seconds
Loading

Linked issues

Validation

  • pytest resources_servers/swebench_pro/tests in a venv built from its requirements.txt: 105 passed. New tests: an unknown session and a resent /run verify are masked without starting an eval sandbox; a golden-patch verify of a closed session is still graded; caller-sent response fields are ignored; seed 422s start no sandbox; a refused seed leaves the client's cookie alone; a close naming another episode gets 409 over HTTP while open and after close; shutdown clears the fence. Includes the contract check with verify_body; the repeated-verify test now expects a masked session_lost sample, and the extraction-failure tests still expect an unmasked failure.
  • pytest tests from resources_servers/interactive_browser in a venv built from its requirements.txt: 62 passed. Includes the contract check with verify_body; every browser tool gets 404 session_lost without a browser; 409 for a conflicting seed and for mismatched closes (open and closed); 422 for bad task_data; a refused seed leaves the client's cookie alone; caller-sent response fields are ignored on the lost and graded verify paths.
  • pre-commit run --files <changed files>: passed.

Rollout evidence

Not run yet; the smoke rollouts run before merge, and their results will be added here. Verify behavior changes for lost sessions, so the rollouts should cover:

  • swebench_pro under single_agent_turn: episodes verify normally, and a repeated verify is masked;
  • interactive_browser under single_agent_turn: a browser episode verifies normally.

Compatibility

  • Seeds and closes: a conflicting or late seed, or a mismatched close, now returns 409 instead of 500 for both servers; bad task_data for swebench_pro returns 422. These are final instead of retried.
  • Verify on a lost session: it is now a masked sample, so it counts toward coverage but not quality metrics, where it used to be a 500 or an unmasked 0. For swebench_pro this includes a resent /run verify and a verify after a restart.
  • Cookies: a refused seed (409 or 422) no longer sets the session cookie.
  • interactive_browser seeds: task_data that is not a browser task returns 422 instead of a retried 500.
  • Tool calls: an interactive_browser tool call without a browser returns 404 instead of a 200 observation.
  • Retention: a closed ID is forgotten after session_close_retry_window_seconds (300 s by default) instead of at shutdown.

🤖 Generated with Claude Code

@copy-pr-bot

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

@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 19, 2026 21:00
@yaoyu-33
yaoyu-33 changed the base branch from main to yaoyu-33/resources-session-close-contract October 19, 2026 22:57
yaoyu-33 and others added 2 commits October 19, 2026 16:17
…ess close

Add ResourcesSessionFence, which serializes seed and close per
resources_session_id and remembers closed sessions for
CLOSED_SESSION_RETENTION_S instead of until shutdown. A seed for a closed
session gets 409, which single_agent_turn does not retry.

State that close must release state by resources_session_id when the
request carries no cookie, as after a lost seed reply, and check it in
check_resources_session_contract with an optional holds_state probe.
Move example_single_tool_call onto the fence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…s at verify

Seed and close refusals that no retry can fix were plain ValueErrors, so
they became a 500 and single_agent_turn dispatched the whole episode again.
Add ResourcesSeedRejectedError (422) for input that fails validation and
ResourcesSessionConflictError (409) for an ID bound to another episode, a
close for another episode, or a closed session.

A verify for a session the server no longer holds returned reward 0 (a
policy failure) or an error. Add lost_session_verification, which builds
a masked sample with failure_kind session_lost or session_expired, and
ResourcesSessionLostError (404) for tool calls on such a session.

check_resources_session_contract now requires 409 for a conflicting or
late seed and, with verify_body, a masked verify after close. Move
gdpval and nemo_user_sim, which already run the check, onto these rules;
nemo_user_sim also maps resources_session_id to its cookie session so a
cookie-less close releases it and a conflicting seed is caught.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33
yaoyu-33 force-pushed the fix/resources-session-fence-migration branch from 6b1dc1d to f5a71af Compare October 19, 2026 23:35
@yaoyu-33
yaoyu-33 requested a review from a team as a code owner October 19, 2026 23:35
@yaoyu-33
yaoyu-33 force-pushed the yaoyu-33/resources-session-close-contract branch from 1275512 to 9fab94c Compare October 19, 2026 23:36
@yaoyu-33 yaoyu-33 added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working complexity:high Cross-component or shared-contract change with a large review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 19, 2026
@yaoyu-33 yaoyu-33 changed the title fix(resources): move swebench_pro, interactive_browser, and nemo_user_sim onto the session close contract fix(resources): move swebench_pro and interactive_browser onto the session contract Oct 19, 2026
…completion

A verify for a session gdpval no longer holds now returns a masked
session_lost sample instead of a 409. The multistage orchestrator decides
success by the failure class alone, so it counted that sample as a judged
success: a final stage with half its tasks judged reported complete with a
headline ELO, and a partial earlier stage was coverage-blocked and never
retried.

tag_results now turns a session_lost or session_expired result into the
terminal verification failure the 409 used to produce, so routing, success,
resume gating and partial-stage acceptance behave as before. aggregate_metrics
also leaves such a row out of its stage's observed rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33
yaoyu-33 force-pushed the fix/resources-session-fence-migration branch from f5a71af to 72876b5 Compare October 20, 2026 02:49
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 20, 2026
yaoyu-33 and others added 5 commits October 20, 2026 18:02
…view

- gdpval: bind the session cookie only after a seed's checks pass, so a
  refused 409 or 422 reply no longer hands the caller another episode's
  session.
- example_single_tool_call and nemo_user_sim: a close of a closed session
  that names another episode gets 409, and check_resources_session_contract
  now checks it (keeps_state only). nemo_user_sim records the closing episode.
- nemo_user_sim: a seed dropped after session_ttl_seconds verifies as a
  masked session_expired sample instead of session_lost.
- lost_session_verification logs a warning, since a masked sample is
  otherwise visible only in coverage metrics, and documents the dict merge
  that avoids a duplicate-keyword TypeError with extra="allow" requests.
- ResourcesSessionLostError says what each harness does with the 404 and
  validates its failure_kind.
- Tests: fence locks are per session, clear() forgets records, the contract
  check rejects a 500 late seed, refusals reach the wire as 422/404, a masked
  sample is kept for coverage and dropped from quality, gdpval TaskData 422
  and judged-not-masked gone session, nemo_user_sim close by ID first.
- Docs: the resources server tutorial and the nemo_user_sim README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ssion fence

swebench_pro and interactive_browser kept their own per-session locks and
closed-session records for the life of the process. Use
ResourcesSessionFence instead, so closed records expire after
CLOSED_SESSION_RETENTION_S and a seed for a closed session gets 409, which
single_agent_turn does not retry, instead of a 500.

Each server's tests now run check_resources_session_contract with a
holds_state probe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ench_pro and interactive_browser

Apply the rest of the session contract from the base:

- conflicting seeds and closes raise ResourcesSessionConflictError (409)
  and task_data that is not an instance raises ResourcesSeedRejectedError
  (422), instead of a ValueError that became a retried 500;
- swebench_pro answers a verify for a typed session whose sandbox is gone
  (consumed by an earlier verify, or closed) with a masked session_lost
  sample, instead of a 500 or a graded empty patch; a failed extraction
  from a live sandbox stays an unmasked failure;
- interactive_browser masks a verify with no browser, and a tool call with
  no browser gets 404 session_lost instead of an observation the model
  would act on.

Both contract checks now pass verify_body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…y does

simple_agent passes a tool's 404 body to the model and keeps going, so the
404 does not end the turn. It marks the call failed in the trajectory, and the
masked verify keeps the sample out of the score. Say that in the comment, the
tool section header and the test docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
… and bind cookies only on success

- swebench_pro: a non-golden verify whose session holds no task sandbox
  (consumed, closed, never held: a resent or repeated /run verify, or an
  unknown session after a restart) is a masked session_lost sample. It used
  to grade an empty patch as an unmasked 0. The graded path now sets
  mask_sample, failure_kind and failure_reason itself.
- swebench_pro and interactive_browser bind the session cookie only after a
  seed succeeds, so a refused 409 or 422 reply no longer points the caller at
  another episode's session.
- interactive_browser: task_data that is not a browser task gets 422 instead
  of a retried 500.
- Tests pin the 409/422 refusals over HTTP, every browser tool's 404,
  response-owned fields a caller sends, the golden-patch path and shutdown.
- README: the closed-session window and how a lost browser is reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33
yaoyu-33 force-pushed the fix/resources-session-fence-migration branch from 72876b5 to 5199c24 Compare October 21, 2026 01:03
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 5199c24

weijiac0619
weijiac0619 previously approved these changes Oct 26, 2026
Wait for the agent tool call as well as the resources in-flight count so
a slow seed cannot start checkpoint preparation before the activation.
Hold the sbatch stub until the competing resubmit is refused instead of
assuming a one-second sleep makes the two calls overlap.

Validation: 195 tests passed across test_checkpoint_agent.py,
test_checkpoint_resources.py, test_checkpoint_coordination.py,
test_eval_resubmit.py, and test_slurm_executor.py. The old checkpoint wait
fails with delayed seeds in both modes; the fixed wait passes. Removing
the submission lock makes the strengthened test fail, and 30 repetitions
with the real lock pass. pre-commit run --all-files passed.

Rollout evidence: N/A; only test synchronization changes.

Signed-off-by: yaoyu-33 <[email protected]>
Merge origin/main at 8666d32. Keep main's comment wording for the
checkpoint synchronization fix, which now has identical behavior on both
branches. Preserve the deterministic resubmit concurrency test alongside
main's O_EXCL lock fix.

Validation: 258 tests passed across test_checkpoint_agent.py,
test_checkpoint_resources.py, test_checkpoint_coordination.py,
test_eval_resubmit.py, test_slurm_executor.py,
test_base_resources_server.py, and test_session_contract_repo.py.
pre-commit run --all-files passed. The PR diff against main passes
git diff --check.

Rollouts: N/A for the comment-only conflict resolution.
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 3e2c556

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Oct 26, 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/40359287013

This branch was previously deployed

1 inactive deployment
public — 3e2c5567 Deployed Oct 26, 2026 by copy-pr-bot[bot] via release / finalize / notify #7290
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working complexity:high Cross-component or shared-contract change with a large review surface 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.

3 participants