Repository navigation
Conversation
70f0b3e to
eec331c
Compare
eec331c to
52adc3b
Compare
|
Rebased onto main and out of draft. Worth flagging what the rebase surfaced: six tests in One of the failures doubles as evidence for the design. When the release call itself fails, the episode logs and returns its result normally. A reclaim that can break a rollout is worse than the leak it fixes, so the failure path is a warning by construction. Also see #2750 (comment) on why a caller-driven release is necessary but not sufficient — the sweeper here is the part that survives a killed collector. |
52adc3b to
753c2fb
Compare
|
#2886 landed yesterday — That is the same shape as That is what the hook here is for — the same guarantee in one place, plus the idle sweeper for the cases no call can reach. |
d0ed159 to
99fc941
Compare
|
The lifecycle hook, agent finally block, TTL sweeper, and tests remain useful, but #2609 now owns a stricter wire contract: caller-created session identity, one-session close capability, seed deduplication and conflict detection, dedicated close outcomes, and idempotent recovery after lost responses. #3037 owns generic TTL and server adoption. This PR should be refactored or replaced against #2609 rather than merged as the final API. |
99fc941 to
a0f7e02
Compare
|
@ananthsub reworked against the #2609 contract rather than merging the old shape. What's in now: caller-created Three calls where the spec left room, all easy to overturn:
There is no A seed arriving for a released id returns 409 rather than replaying the stored response. Replaying it would hand the caller a session that no longer exists, so the id is treated as spent. Not spelled out either way in the design. Agent-side orchestration, the bounded cancellation shield, 27 tests over seven groups; 4318 unit tests pass. |
a0f7e02 to
9564a60
Compare
625df28 to
ecdf327
Compare
2924f80 to
448fd79
Compare
Built against NVIDIA-NeMo#2609's contract rather than patched onto the earlier shape. Caller-created `_ng_session_id` with a close capability stored as a digest. Seed deduplication replays the stored response on the same payload, 409s on a different one, and keeps a bounded tombstone for a released id. Four terminal close outcomes, with an unknown id and an already-released one answering identically so the endpoint cannot probe another rollout's session. `_close_session_endpoint` owns identity, conflict checks and idempotency; `release_session(session_id, reason)` owns only release. Concurrent closers join one release task. Expiry that active handlers suppress, plus an absolute lifetime they do not. Three calls where the spec left room, all easy to overturn: `release_session` is the hook name, per the design — `GymnasiumServer`, TALES and OpenAir already define `close_session` with a different signature, so a base method sharing it would silently override theirs. There is no `not_found` status. The design says an unknown id and an already-closed one must answer identically, which an explicit `not_found` would defeat. A seed arriving for a released id returns 409 rather than replaying the stored response: replaying it would hand the caller a session that no longer exists, so the id is treated as spent. Agent-side orchestration, the bounded cancellation shield, `X-NeMo-Gym-Cleanup-Status` and the collector's `_ng_run_info.cleanup` are a follow-up, per "Agent and resources-server adoption are separate". The TTL mechanism stays here as the reference implementation with NVIDIA-NeMo#3037 owning adoption. Signed-off-by: waple0820 <[email protected]>
448fd79 to
f6080ed
Compare
|
@ananthsub closing this in favour of #3717, which landed #2609 with the same shape this PR was arguing for: the caller assigns The caller half of this PR is now in Two pieces I'll pick up separately:
|
NVIDIA-NeMo#3812) ## What `interactive_browser` now serves the resources-session protocol an Environment Server uses (NVIDIA-NeMo#3717): a typed `/seed_session` under the caller's `resources_session_id`, and a `/close_session` that actually releases the browser. This is the follow-up I mentioned when closing NVIDIA-NeMo#2612. ## Why Two gaps under Environment Server episodes today: 1. **Typed seed is swallowed.** `BrowserSeedSessionRequest` allows extra fields, so a `ResourcesSeedSessionRequest` body validates as a legacy seed and gets an empty `{}` back. `single_agent_turn` then fails validating the seed response. 2. **Close is a no-op.** `/close_session` falls through to the base default, so an episode that ends before `verify` (timeout, cancelled agent) keeps its browser. With a remote provider that is a paid session held until the provider reclaims it. ## How Same shape as `swebench_pro`: - `seed_session` takes `Union[ResourcesSeedSessionRequest, BrowserSeedSessionRequest]` with `union_mode="left_to_right"`, so the typed body wins. It opens the browser from `task_data` under the caller's id and binds the cookie to that id, so direct-HTTP tool calls and the MCP token both land on that browser. A retried seed for the same `(episode_id, task_id)` returns the existing session; a different episode on the same id is rejected. - `close_resources_session` releases the browser, is idempotent, checks `episode_id`, and remembers closed ids. A seed that arrives after its close is rejected, so it can't open a browser nobody will close. An empty body still closes the cookie session for `/run` callers. - A per-id lock serializes seed and close. A close that arrives while the browser is still opening waits for it, then releases it. - `num_workers` other than 1 is refused, since browsers live in process. Legacy `/run` seeding is unchanged and still returns `{}`. ## Tests `tests/test_resources_sessions.py` (15 new): typed seed over HTTP, tool calls reaching the seeded browser over direct HTTP and over MCP, retried seed, id reuse across episodes, close before verify, double close, mismatched episode, malformed close (422), legacy seed and empty close, close during a slow seed, seed after close, `num_workers` guard, verify after close. ``` cd resources_servers/interactive_browser && pytest tests -q # 49 passed pytest tests/unit_tests/test_mcp_auto_exposure.py tests/unit_tests/test_base_resources_server.py -q # 60 passed ``` ## Not in this PR Idle expiry for sessions whose Environment Server never closes them (process killed mid-episode). I'll ask on NVIDIA-NeMo#3037 whether that belongs in the base class or per server before opening anything. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: waple0820 <[email protected]> Co-authored-by: waple0820 <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Closes #2609
/seed_sessionallocates a browser, container, sandbox or provider lease; nothing releases it. A rollout that fails, times out, is cancelled or loses its seed response leaves that resource alive, and a retry allocates another while the first stays unreachable.Identity comes from the caller
The caller creates
_ng_session_idbefore the first seed transmission, so the id survives a response that never arrives. The provider's own handle cannot serve here — it is learned from that response, which is exactly what goes missing. A separate_ng_session_close_tokenis stored only as a digest and authorizes releasing exactly that one session when the cookie is gone.Seeding deduplicates
The transport may repeat a seed it is not sure was delivered.
The last rule is not spelled out in the design. Replaying the stored response would hand the caller a session that no longer exists, so a released id is treated as spent.
The adapter owns everything that is not release
The hook is deliberately not named
close_session.GymnasiumServer, TALES and OpenAir already define that name with a different signature, and a base method sharing it would silently override theirs. Migration is one line, and is tested:We hit a version of that collision already:
close_sessionas a typed POST route meant MCP auto-exposure published it as a model-callable tool, so a policy could have ended its own episode's resources.Release runs once
The first closer creates the release task and concurrent closers await it, so provider cleanup does not run per caller. A failed release reports
release_failedwith 503 and leaves the session retryable rather than marking it closed.An unknown id and an already-released one answer identically. There is no
not_foundstatus — that would let the endpoint be used to probe whether another rollout's session exists. This follows the close-session design rather than the five outcomes listed in #2609's body.Expiry does not trust idle time alone
A rollout can sit in a model call for minutes without touching the resources server, so a session with handlers in flight is skipped. An absolute lifetime that activity does not suppress covers the case the first rule cannot: a handler that has hung.
active_session()marks a handler in flight and refuses to start one once release has begun, so close cannot tear a resource down while verification is still reading it. The base uses it on its own routes; broad adoption across environment tool routes is #3037.Scope
Agent-side orchestration, the bounded cancellation shield,
X-NeMo-Gym-Cleanup-Statusand the collector's_ng_run_info.cleanupare a follow-up, per "Agent and resources-server adoption are separate" in the design. The TTL mechanism stays here as the reference implementation; #3037 owns adoption across stateful servers.Tests
27 cases over seven groups: seed replay does not allocate twice, payload conflict is 409, a delayed seed cannot resurrect a tombstone; the four terminal outcomes, a cookie/id conflict releasing neither, unknown and already-closed responses being byte-identical, ten concurrent closes releasing once, a failed release staying retryable; capability match, mismatch, id-alone rejection, and the token never reaching the record; idle expiry, busy suppression, absolute lifetime overriding busy, tombstone cleanup; handler counting and refusal after close; the base not defining
close_sessionand the bridge working; route registration andrelease_sessionnever reaching the model.uv run --extra dev pytest tests/unit_tests -q→ 4367 passed.test_e2b_providerandtest_enroot_providerfail on a cleanupstream/maintoo.