Skip to content

fix(interactive_browser): drop a browser's record only after it closes - #6412

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/sandbox-stop-keep-record
Nov 19, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/sandbox-stop-keep-record

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

interactive_browser's _release dropped the session's record before awaiting the browser's close, so a close that failed, or that a disconnect cut short, left a browser that nothing tracked.

  • It now drops the record only once the close succeeded, and only the record of the browser it closed.
  • A close of the session answers 503 and is not fenced, so its retry closes the browser again. A close is acknowledged only once the session holds no browser, so a verify after it is a lost session.
  • A re-seed of the session first closes the browser it still holds, and answers 503 rather than replacing one that is still running. The shutdown stops it otherwise.

The close is shielded from the request's cancellation, without an overall time limit, because each of its teardown steps already has its own. Its real backends report no close failure, so there the shield is the change that matters; the kept record covers a backend that does raise.

This PR used to cover opencode_search too. #6211 has since moved opencode_search onto environment server sessions, which already keep an agent run's sandbox until its stop succeeds and stop what is left at shutdown, so only interactive_browser remains.

How it works

The release of a session's browser:

flowchart LR
  subgraph before["Before"]
    direction TB
    a1["release"] --> a2["pop the session's record"]
    a2 --> a3["await the close"]
    a3 -->|"cancelled or fails"| a4["running browser<br/>that nothing tracks"]
  end
  subgraph after["After"]
    direction TB
    b1["release"] --> b2["read the session's record"]
    b2 --> b3["await the close, shielded"]
    b3 -->|"succeeds"| b4["drop the record,<br/>if it still names what was closed"]
    b3 -->|"fails"| b5["keep the record"]
    b5 --> b6["the close answers 503, unfenced;<br/>its retry or a re-seed closes it again,<br/>or the shutdown does"]
  end
  before ~~~ after
Loading

Where this sits in the stack

This is one PR in a stack of PRs that implement Milestone 1 of the sandbox ownership design: every sandbox has one owner, the server that starts it, which stops it on every path, and every other user borrows it. Each PR is one commit, so each diff shows only that PR's change.

The highlighted box is this PR.

flowchart LR
  M["PR 5266<br/>sandbox checkpointer"]
  U1["PR 6410, merged<br/>shielded, bounded<br/>AsyncSandbox.stop"]
  U2["PR 6411, merged<br/>gdpval failed-seed<br/>sandbox"]
  U3["PR 6412<br/>browser record kept<br/>until it closes"]
  U4["PR 6413, merged<br/>vibench shielded<br/>scratch removal"]
  U5["PR 6414<br/>public<br/>OwnedSandboxes"]
  U6["PR 6415<br/>lifecycle<br/>under load"]
  U7["PR 6416<br/>typed<br/>network rule"]
  U8["PR 6417<br/>borrow and<br/>AgentSandboxConfig"]
  U1 --> U2
  U2 --> U3
  U2 --> U4
  U1 --> U5 --> U6 --> U7 --> U8
  M -.->|"PR 6414 rebases onto it"| U5
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef merged fill:#d1fae5,stroke:#047857,color:#1f2937
  class U1,U2,U4 merged
  class U3 this
Loading
  1. fix(sandbox): shield and bound AsyncSandbox.stop and the other releases #6410 (merged): fix(sandbox): shield and bound AsyncSandbox.stop and the other releases
  2. fix(gdpval): keep a failed seed's sandbox until a stop succeeds #6411 (merged): fix(gdpval): keep a failed seed's sandbox until a stop succeeds
  3. fix(interactive_browser): drop a browser's record only after it closes #6412 (ananthsub/sandbox-stop-keep-record): fix(interactive_browser): drop a browser's record only after it closes (this PR)
  4. fix(vibench): remove a released session's scratch files shielded #6413 (merged): fix(vibench): remove a released session's scratch files shielded
  5. feat(sandbox): expose the shared OwnedSandboxes owner #6414 (ananthsub/owned-sandboxes): feat(sandbox): make the sandbox checkpointer the public OwnedSandboxes
  6. feat(sandbox): stop, start and export owned sandboxes safely under load #6415 (ananthsub/owned-sandboxes-lifecycle): feat(sandbox): stop, start and export owned sandboxes safely under load
  7. feat(sandbox): apply typed network rules through owner capabilities #6416 (ananthsub/owned-sandboxes-network): feat(sandbox): typed network rule and provider capabilities for owners
  8. feat(sandbox): borrow lent sandboxes and share harness configuration #6417 (ananthsub/sandbox-borrow): feat(agents): borrow lent sandboxes and type the agent's own sandbox

Validation

  • pre-commit run --files <changed files> on the unit's diff (ruff, ruff-format, import-linter, guardwords).
  • pytest -n 16 tests/unit_tests, in a venv with CI's extras, with the same failures as on main.
  • Server tests: interactive_browser.
  • New tests cover a close in a cancelled request, a typed and an empty-body close whose browser close fails (503, not fenced, another episode still refused, the retry closes it, and a later verify is a lost session), a failed close kept for a re-seed or the shutdown, the re-seed refusal and release, and the identity check. Each fails with its protection removed.

Rollouts

Smoke rollouts of this PR's head (3c6f2b6) with a model, as Slurm job 2074708 on a CPU node:

  • The configuration was resources_servers/interactive_browser/configs/interactive_browser.yaml with interactive_browser_simple_agent, the local Playwright backend (headless Chromium) and the hosted eccn-gpt-6-luna model through openai_model.
  • It ran all the bundled tasks in data/example.jsonl: navigating to the about and index pages, the login form (dom_contains: Welcome neo), the form page, and an answer task (answer_equals: ALPHA-42).
  • Every rollout drove the browser with 2 to 5 tool calls, scored reward 1.0, and was not masked. gym eval run exited 0, with no missing, masked or unscored rollouts.

The failure paths this PR changes (a failed close, a close cut short by cancellation, a re-seed over a failed close) do not occur in a healthy run, so the unit tests cover them.

Compatibility and benchmark impact

A re-seed of a session whose previous browser could not be closed now gets a 503 instead of silently replacing it and leaking the old one.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally.
  • Documentation added or updated, or N/A with justification. N/A: no user-facing behavior to document.
  • Pre-commit checks pass locally, run on this unit's changed files.
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s).

@copy-pr-bot

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

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:mid Autobot PR risk: mid label Nov 18, 2026
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 0e18a88 to 7c30750 Compare November 18, 2026 23:19
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from ff2e211 to 4886429 Compare November 18, 2026 23:19
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:sandbox Sandbox providers, isolation, and sandbox runtime contracts labels Nov 18, 2026
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from 4886429 to 77078c1 Compare November 19, 2026 05:51
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 7c30750 to 0d0324f Compare November 19, 2026 05:51
@ananthsub ananthsub changed the title fix(sandbox): forget a browser or sandbox only after it stops fix(sandbox): drop a browser's or sandbox's record only after it stops Nov 19, 2026
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from 77078c1 to bd640ef Compare November 19, 2026 15:03
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 0d0324f to 0aa8151 Compare November 19, 2026 15:03
@ananthsub ananthsub changed the title fix(sandbox): drop a browser's or sandbox's record only after it stops fix(interactive_browser): drop a browser's record only after it closes Nov 19, 2026
@ananthsub
ananthsub marked this pull request as ready for review November 19, 2026 15:03
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 19, 2026 15:04
@yaoyu-33
yaoyu-33 requested a review from ffrujeri November 19, 2026 15:07
@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

@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

The close endpoints have one correctness RISK, reported inline.

RISK: Provide the required model-backed smoke evidence

The PR marks rollouts N/A, but this changes environment lifecycle behavior. The protected AGENTS.md quality bar requires representative real smoke rollouts with a model and inspection of agent and verifier behavior. Unit tests cover the failure paths, but they do not supply that integration evidence.

Could you run representative bundled tasks through the configured pairing and add the commands, model/configuration, rollout outcomes and inspected artifacts to the PR? The README provides the rollout commands. Proposed acceptance: inspect a navigation task and a form-submission task for meaningful browser tool calls, correct task rewards and completed cleanup. Keep the cancellation and failed-close regression tests; a successful model rollout does not replace those checks. This addresses missing validation evidence, not a demonstrated normal-rollout failure.

I inspected both changed files and traced the affected lifecycle callers and backend teardown contracts. One delegated report was unavailable, so I covered its test, dependency and validation-policy scope directly. This was static review; I did not execute tests.


Inline comments (escaped v1):

  • resources_servers/interactive_browser/app.py line 276: ### RISK: Do not acknowledge and fence a close while its browser is still held

    The new _release failure branch keeps the browser but returns normally. This caller then clears its episode identity, fences the session and returns 200. A repeated typed close takes the fenced early return, so it never retries teardown.

    The retained record also introduces an observable regression after that acknowledged close. Seed with answer_equals: "42", finish with 42, and use a backend whose first close() raises. /close_session returns 200, but /verify with the saved cookie still finds the record and returns reward 1 without masking. In the base implementation, the record was removed, so verification after the acknowledged close reported masked session_lost. This affects backends that surface close exceptions, including registered extensions; the shipped backends swallow ordinary teardown failures.

    Could both branches of close_resources_session reject the close when _release leaves a record? Insert this immediately after each await self._release(session_id), before clearing identity, fencing or acknowledging closure:

    if session_id in self._session_id_to_state:
        raise HTTPException(503, "The session's browser could not be closed; close it again to retry")

    The invariant is that a successful close acknowledgement means the session holds no browser. Failed teardown must keep its ownership and remain retryable. This insertion leaves verification's score handling and shutdown's best-effort cleanup unchanged. Verify the suggested code before adopting it.

    Proposed regression checks, not executed: use a backend whose first close raises and second succeeds. The first typed close must return 503, keep the browser and episode identity, and install no fence. Another episode's close must still return 409. The owner's second close must return 200 and remove the record; a third close must remain idempotent. Verification with the saved cookie after successful closure must return reward 0 with mask_sample=True and failure_kind=session_lost. Cover failure/retry through the empty-body cookie close too. Retain the existing close-before-seed refusal, successful-close behavior, failed-reseed refusal and replacement-state identity assertions in the session tests.

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

@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from bd640ef to ec990ad Compare November 19, 2026 15:31
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 0aa8151 to 1de460e Compare November 19, 2026 15:31
hemildesai
hemildesai previously approved these changes Nov 19, 2026

@hemildesai hemildesai 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

The record is kept until the close succeeds, and the is st check stops a close from dropping a browser that a re-seed installed meanwhile. The unbounded shield is fine, because each teardown step has its own time limit (_CLOSE_STEP_TIMEOUT_S in page.close, _RELEASE_TIMEOUT_S in lexmount release). The 503 on re-seed is right. Session tests pass locally (33 passed). One non-blocking NOTE inline.

@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from ec990ad to caa0d8b Compare November 19, 2026 15:54
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch 2 times, most recently from c8b292c to 5131416 Compare November 19, 2026 15:56
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch 2 times, most recently from 3d60596 to 44b3b7e Compare November 19, 2026 16:31
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 5131416 to 3c6f2b6 Compare November 19, 2026 16:31
@ananthsub

Copy link
Copy Markdown
Contributor Author

On the automated review's close RISK: fixed in 3c6f2b6, as suggested. Both close paths answer 503 when _release leaves the browser, before clearing the identity or fencing, so an acknowledged close means the session holds no browser. Tests use a backend whose first close raises:

  • The typed close returns 503 and keeps the browser and the episode identity, with no fence.
  • Another episode's close still gets 409.
  • The owner's retry returns 200 and removes the record, and a third close is idempotent.
  • A verify after that is a masked session_lost.
  • The empty-body close fails and is retried the same way.

@ananthsub

Copy link
Copy Markdown
Contributor Author

On the automated review's request for smoke evidence: I ran model-backed rollouts of 3c6f2b6 on a cluster node, with headless Chromium through the local Playwright backend and the hosted eccn-gpt-6-luna model.

  • The run covered all the bundled data/example.jsonl tasks: navigation to the about and index pages, the login form, the form page, and the ALPHA-42 answer task.
  • Each rollout made 2 to 5 browser tool calls, scored reward 1.0, and was not masked. The run had no missing or unscored rollouts.

The details are in the PR description's Rollouts section. The failure paths this PR changes do not occur in a healthy run, so the unit tests remain their coverage.

@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from 3c6f2b6 to bb422bb Compare November 19, 2026 16:43
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-untracked-owners branch from 44b3b7e to 33aba16 Compare November 19, 2026 16:43
Base automatically changed from ananthsub/sandbox-stop-untracked-owners to main November 19, 2026 17:33
@ananthsub
ananthsub dismissed hemildesai’s stale review November 19, 2026 17:33

The base branch was changed.

@hemildesai hemildesai 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.

Re-approving after the retarget to main (6411 merged). The PR's own change is the one I approved, including the 503-without-fence retry fix, and CI is green on bb422bb.

interactive_browser's _release dropped the session's record before awaiting
the browser's close. A close that failed, or that a cancelled request cut
short, left a running browser that nothing tracked.

It now drops the record only once the close succeeded, and only the record
of the browser it closed. A browser whose close failed stays with its
session:
- A close of the session answers 503 and is not fenced, so its retry
  closes the browser again. A close is acknowledged only once the session
  holds no browser, so a verify after it is a lost session.
- A re-seed of the session closes it first and answers 503 rather than
  replace one that is still running.
- The shutdown stops it otherwise.

The close is shielded from the request's cancellation, without an overall
time limit, because each of its teardown steps already has its own. The
real backends report no close failure, so there the shield is what
changes; the kept record covers a backend that does raise.

opencode_search, which this change also covered, already keeps an agent
run's sandbox until its stop succeeds and stops what is left at shutdown on
main.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-stop-keep-record branch from bb422bb to 1e19e37 Compare November 19, 2026 17:48
@ananthsub
ananthsub enabled auto-merge November 19, 2026 17:52
@ananthsub
ananthsub added this pull request to the merge queue Nov 19, 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/44583552463

@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/44584339679

Merged via the queue into main with commit 6693566 Nov 19, 2026
63 checks passed
@ananthsub
ananthsub deleted the ananthsub/sandbox-stop-keep-record branch November 19, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:mid Autobot PR risk: mid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants