Skip to content

fix(routing): keep a resources session's owner while the server keeps its state - #6061

Draft
ananthsub wants to merge 1 commit into
mainfrom
ananthsub/routing-held-session-state
Draft

ananthsub wants to merge 1 commit into
mainfrom
ananthsub/routing-held-session-state

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed and why

Session routing decided how long a worker owns a resources session only from the requests that worker served. A session that is not open kept its owner for session_close_retry_window_seconds (300 s by default) after its last request.

Several servers keep a sandbox, tool worker or workspace after a failed seed, verify or close whose own teardown also failed, so that a later close can retry the teardown. If that close arrived after the window, it reached another worker, which fenced the session ID and answered 200. The resource on the first worker then lived until shutdown or the provider TTL.

This PR lets the server tell routing that it still holds something a close must reach:

  • SimpleResourcesServer gains a synchronous keeps_session_state(session_id) hook, passed to routing through owned_session_routing().
  • When a session's window passes, the ownership sweep asks the hook. While it returns True, ownership lasts another window.
    • Ownership stays bounded: it ends one window after the server releases the state.
    • A release by a request starts a new window. A release outside a request, such as shutdown or a server's own expiry, is noticed at the next check.
  • A hook that raises releases ownership, as before the hook existed, so a faulty override cannot keep every session owned. The warning names the session, and the traceback is logged once per worker.
  • __init_subclass__ rejects an async override.
  • The base hook reports live state (has_session_state) and sessions whose failed initialization left something to release.
  • Servers that keep resources in their own maps override the hook to report those maps, and leave out plain records with nothing to release:
  • session_release_pending keeps its meaning: a verification's cleanup is pending. /verify ownership and the checkpoint tracker read it unchanged.
  • The same callable serves as holds_state for check_resources_session_contract. The conformance tests of officeqa, vibench, swebench_pro and deepswe now pass it.
  • The resources server guide and the session_close_retry_window_seconds description now describe the longer ownership.
flowchart TD
    A[Window since the last request passes] --> B{keeps_session_state}
    B -- True --> C[Keep ownership for another window]
    C --> A
    B -- False --> D[Release ownership]
    B -- raises --> E[Log a warning and release ownership]
Loading

Issue

No issue. This was found in the team review of #5988, which records it as a known edge of running these servers with several workers.

Compatibility

  • A server that keeps its own session lifecycle, outside the three state hooks, must override keeps_session_state to stay safe with several workers. Otherwise a late close after a failed teardown can still reach another worker. The docs and the session_close_retry_window_seconds description now say so.
  • Servers that use only the three state hooks need no change.
  • Ownership can now last longer than one window, but only while the server holds resources for the session.
  • Known edge, not a regression: when swebench's own expiry stops an abandoned sandbox, ownership can end before that session's fence does. This matches main's behavior for that path.
  • Expect a rebase overlap with feat(server): run servers whose sessions routing reaches with several workers #5988 in the officeqa, vibench and agentic_if app.py files.

Validation

  • Routing unit tests cover:
    • ownership kept while state exists and released one window after it is gone, with one expiry entry per session even when a request arrives in a kept window;
    • release when the hook raises, with one traceback per worker;
    • two real workers, where a failed seed's late close reaches the worker that kept its state.
  • Lifecycle unit tests cover:
    • the rejection of an async hook;
    • server wiring that keeps ownership both for a failed initialization's leftover cleanup and for live state that outlives the session.
  • Each server override has assertions that the hook reports the kept resource before the retried close and nothing after it. Removing any override makes its assertions fail.
  • Mutation checks: dropping the base hook's live-state clause and re-arming without the expiry queue's duplicate check each fail a test.

Commands, run from this branch's worktree with a venv built by uv sync --extra dev plus the browsecomp_advanced_harness server dependencies:

pytest -n 8 tests/unit_tests/server_runtime/test_session_routing.py tests/unit_tests/server_runtime/test_resources_session_lifecycle.py
  • The routing, lifecycle, resources session and checkpoint unit tests under tests/unit_tests/.
  • pytest resources_servers/<server>/tests, one directory at a time, for swebench_pro, rna_design, swe_atlas_qa, browsecomp_advanced_harness, agentic_if, officeqa, vibench, terminal_bench_2_1, scale_swe and deepswe, plus resources_servers/swebench/tests/test_sandbox_sessions.py.
  • pre-commit run --files on the changed files.

Rollout evidence

N/A. The change affects only how long a worker keeps ownership of a session after a failed teardown. It does not change agent turns, tools or verification. A unit test runs two real workers and checks that a late close reaches the worker that kept the state.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

@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

LGTM — no concerns found. I reviewed all 28 changed files and traced ownership expiry, cleanup retries, verification, and checkpoint interactions. This was a static review; I didn't execute tests.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

… its state

Session routing judged how long a worker owns a resources session only from
the requests it served: a session that is not open kept its owner for
session_close_retry_window_seconds after the last request. Several servers
keep a sandbox after a failed seed, verify or close whose stop also failed,
so that a later close can retry the stop. If that close arrived after the
window, it reached another worker, which fenced the ID and answered 200, and
the sandbox on the first worker lived until shutdown or the provider TTL.
scale_swe, terminal_bench_2_1, swebench_pro, swe_atlas_qa, rna_design,
browsecomp_advanced_harness and the servers built on swebench's
SandboxSessionResourcesServer (swebench, swe_gym, r2e_gym, deepswe,
deepswe_external1) can already run with several workers.

SimpleResourcesServer gains a synchronous keeps_session_state hook, passed to
routing through owned_session_routing. When a session's window passes, the
ownership sweep asks it whether the server still keeps state for the session
and, if so, keeps ownership for another window. A release by a request starts
a new window; a release outside one, such as shutdown or a server's own
expiry, is noticed at the next check. A hook that raises releases ownership,
as before the hook existed, so a buggy override cannot keep every session
owned; the warning names the session and logs the traceback once.

The base hook reports live state and what a failed initialization's release
left. Servers that keep sandboxes, tool workers or workspaces in their own maps
override it to report those maps: scale_swe, terminal_bench_2_1,
swebench_pro, swe_atlas_qa, rna_design, browsecomp_advanced_harness,
SandboxSessionResourcesServer, and officeqa, vibench and agentic_if, which
run with several workers once their refusals are lifted. scale_swe leaves out its session records, which a
cancelled close can leave behind with nothing to release. The same callable
serves as holds_state for check_resources_session_contract.
session_release_pending keeps its meaning: a verification's cleanup is
pending. The resources server guide and the close retry window description
now describe the longer ownership.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/routing-held-session-state branch from d8bcd2a to b84f326 Compare November 13, 2026 20:31
@yaoyu-33
yaoyu-33 requested review from gchlebus and removed request for cynthiagao-nv November 16, 2026 00:16
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026
@ananthsub
ananthsub marked this pull request as draft November 17, 2026 16:01
@copy-pr-bot

copy-pr-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 17, 2026

This branch had an error being deployed

1 failed (outdated) deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries 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