Skip to content

feat(pool): run Pool in task sandboxes - #5001

Merged
yaoyu-33 merged 12 commits into
mainfrom
codex/pool-sandbox-adapter
Nov 2, 2026
Merged

yaoyu-33 merged 12 commits into
mainfrom
codex/pool-sandbox-adapter

Conversation

@mk-0

@mk-0 mk-0 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

No separate issue; replaces #3614. Adds a Pool agent adapter using Gym's agent-session interface, following the Pi and KiloCode integrations. Pool runs inside the task sandbox, routes inference through Gym's model server, and returns its persisted root trajectory as Responses API output.

Child-agent observations are not supported. Pool is downloaded separately under Poolside’s EULA. Installation requires explicit opt-in via accept_pool_eula: true (defaults to false).

Validation:

  • Tests: 199 passed, 12 skipped on macOS at 19efca775.
  • SWE-bench Pro with Nemotron 3.5 Super: 49.16% across 731 tasks × 3 repeats (1,078/2,193 passed; 13 attempts unresolved).

@mk-0 mk-0 added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Oct 23, 2026
@copy-pr-bot

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

@mk-0
mk-0 marked this pull request as ready for review October 23, 2026 17:36
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 23, 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.

HOLD — one BLOCKER and two RISK findings.

Inspected all 14 changed files and traced the affected session, supervisor, model-routing, and environment contracts. This was a static review; tests were not executed. Suggested code below is unexecuted and must be verified before adoption.

RISK — Drain retained Pool sessions during server shutdown

Failure / blast radius: Seed an agent-owned sandbox, then shut down the Pool server before the environment closes its session. PoolAgent never installs a shutdown hook. Its inherited webserver setup does not drain sessions either. Consequently, the process loses the retained handle without calling PoolSession.close; the provisioned sandbox and any running work remain until provider reclamation. The default requested TTL is 2,400 seconds, rather than prompt teardown. This also violates the explicit trusted sandbox-lifecycle convention.

Correction: Add a lifespan finalizer in PoolAgent.setup_webserver, preserving the parent's lifespan. Fence new seeds/activations during shutdown and drain retained active and failed-setup sessions through the existing close hook under bounded timeouts; one failed close must not prevent attempts for the others. Include in-flight setup in that drain so a sandbox cannot finish provisioning after the shutdown snapshot. The invariant is that an owned sandbox's handle remains retained until teardown succeeds. The exact implementation depends on how racing seeds are fenced, so no drop-in patch is proposed.

Preservation: Use the existing ownership-aware close path: stop owned sandboxes, but only disconnect borrowed sandboxes so Resources can verify their files. Retain installation joining, confirmed termination before collection, and retryable failed cleanup; do not replace these with an unconditional provider-stop loop.

Acceptance — proposed, not executed: Enter and exit the application's lifespan with one seeded owned session and assert provider stop is awaited once. Repeat with a borrowed session and assert disconnect occurs without stop or task-file removal. Hold installation on an event while shutdown starts, then release it and assert shutdown subsequently closes that session. Make one close fail and assert another retained session is still closed. Keep the existing failed-cleanup retry assertion that a later close succeeds without losing the sandbox handle.

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.

Comment thread responses_api_agents/pool_agent/app.py Resolved
Comment thread responses_api_agents/pool_agent/app.py Resolved
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test d0ca2fd

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test d8c4577

@yaoyu-33 yaoyu-33 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.

Thanks for the Pool adapter and for the quick follow-up commits. This review is against d8c4577, so it includes both follow-up commits.

The adapter follows the Pi and KiloCode agent-session pattern closely: a shared install task, one activation per session, and ownership-aware close. It also keeps Pool's own state out of the task workdir. The follow-ups fix the Harbor metadata rejection and the recorded-model-error case, and add a well-tested shutdown drain plus host-side failure artifacts.

Verdict: hold for one fix. The new seed_agent_session override fails the repo-wide session-contract test, so the core unit tests go red (inline comment, with a way to keep the drain). After that, the main remaining item is the timeout status decision. A timed-out run in which no model call ever completed is still graded as a 0 (inline comment). The other comments are smaller.

Rollout evidence. We ran a small real-model smoke on d0ca2fd: Pool v1.0.16 inside OpenSandbox task sandboxes through single_agent_turn_legacy.

  • SWE-Bench Pro: 3 tasks, 2 passed. The failure was a real test assertion.
  • Terminal-Bench 2.1: 3 tasks, 3 passed.
  • All six runs completed normally, with confirmed cleanup.

This covers the normal path only. We haven't re-run it on the follow-up commits, which change the shutdown, timeout-budget, and failure paths.

Questions for maintainers.

  • install_pool.sh accepts Poolside's EULA unconditionally (POOL_INSTALL_ACCEPT_EULA=1). The README and PR body disclose this. Should operators opt in explicitly through config instead?
  • Every session fetches the installer script from a mutable, unpinned URL, and the download has no --retry. The Pi and KiloCode installers use --retry 3 with sha256 checks.

PR description.

  • Please list the exact validation: the test command and its counts, and for the SWE-Bench Pro run, the model, the number of tasks, and the results.
  • Link an issue, or say why one isn't needed.
  • The body says "Based on #3614". That PR is still open and adds a separate pool_sandboxed_agent. Does this PR replace it, and will #3614 be closed?

Comment thread responses_api_agents/pool_agent/app.py Resolved
Comment thread responses_api_agents/pool_agent/app.py Resolved
thread.start()
try:
with (directory / "stdout.jsonl").open("w") as stdout, (directory / "stderr.log").open("w") as stderr:
result = subprocess.run(

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.

sandbox_runner.py:140

The runner doesn't forward SIGTERM to Pool. On a deadline or close, the supervisor sends SIGTERM to the runner only, then SIGKILLs the process group (process_supervisor.py#L163-L179). With subprocess.run and no handler, the runner dies at once and exit.json is never written. Pool itself is then SIGKILLed without the chance to checkpoint that the SIGTERM is meant to give it.

Pi's runner forwards the signal (pi_agent/sandbox_runner.py#L23-L27, #L57-L59). Using Popen with a SIGTERM handler that calls terminate() and then waits a bounded time would match it. If this changes, the timeout checks in _activate must allow for both side effects: Pool may record its own interruption reason, and exit.json will now exist on timed-out runs.

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.

Thanks, verified at 700fe22. The runner now forwards SIGTERM to Pool, waits up to 5 s, then kills it, and still writes exit.json.

One thing to confirm with the real binary. The fake CLI in test_lifecycle.py writes session.exit(reason="exit_tool_called") when it receives SIGTERM, and that is what lets the timeout case return incomplete. Pool's exit reasons aren't documented. If v1.0.16 records a different reason on SIGTERM, _activate now raises for it (app.py#L344-L345), so every timed-out run would become an error instead of incomplete. That fails closed, so it isn't blocking. A run with POOL_TEST_BINARY and a short timeout would show which reason Pool writes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with Pool 1.0.16 on macOS. Sending SIGKILL 5 seconds after SIGTERM was necessary. The saved partial trajectory had no exit reason. Replaying it through the adapter with a confirmed timeout correctly returned incomplete, with no error. No code change needed for this case.

thread.join(timeout=5)


@pytest.mark.skipif(

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.

test_runner.py:115

The new shutdown, budget, and failure-artifact tests are good. The code that talks to the sandbox still runs only behind mocks in CI, though. Every _activate test patches SandboxSession.execute, and every seed test patches PoolSession.install. At this head that leaves coverage at 56% for sandbox_runner.py and 64% for sandbox.py. The following run only with POOL_TEST_BINARY, which CI never sets:

  • PoolSession.stage and _install
  • sandbox_runner.run(): env scrubbing, private HOME/XDG, the proxy rewrite, exit.json

Could you add hermetic tests like KiloCode's test_lifecycle_contract.py and Pi's test_sandbox_runner.py, using a fake bin/pool script? Cases worth covering:

  • a stage/collect round trip on a borrowed sandbox
  • close racing an in-flight activation
  • the symlink-resolving workdir check in _install
  • run() rewriting the env and config
  • SIGTERM handling, once it is added

Minor: test_bootstrap.py#L26-L28 errors instead of skipping when a host tool is missing.

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.

Thanks for test_lifecycle.py and test_install_pool.py. With real processes and a fake CLI, they cover the cases asked for here: stage, run, and collect; close during an activation; the symlinked-workdir check; run() rewriting the environment and config; and SIGTERM. test_bootstrap.py now skips when a host tool is missing.

Minor and non-blocking: on macOS, test_proxy_preserves_upstream_status_and_counts_only_successes failed in 10 of 15 local runs with a 502 Connection reset by peer instead of the upstream status. The fake upstream replies without reading the request body, so closing its socket sends a TCP reset. Linux CI passed it at 4f043dd. Reading the body first made it pass 15 of 15:

def do_POST(self):
    self.rfile.read(int(self.headers["Content-Length"]))
    self.send_response(status)

@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 4f043dd

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 28, 2026
yaoyu-33 and others added 2 commits October 28, 2026 16:08
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…isor

#5151 replaced SandboxCommand's python field with stdlib_runner and moved
the process supervisor to bash. Declare Pool's standard-library runner with
stdlib_runner=True and upload it as RUNNER_FILE, like Codex, so task-side
pkill patterns for python or .py cannot match it.

The bash supervisor reports a SIGKILLed harness as 137 rather than -9, and
Harbor's materialize_task now reads task_data, so build the Harbor test row
from a real task folder.

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

Copy link
Copy Markdown
Contributor

/ok to test 3ee8fdd

@weijiac0619

Copy link
Copy Markdown
Contributor

Hi @mk-0, could you merge main? It already includes the fix for the CI failures here (#5321, the harbor Docker Hub 429s). Thanks! I’ll authorize CI once it’s updated.

mk-0 and others added 2 commits October 30, 2026 22:52
Merge current main while preserving Pool's session-only configuration. Register Pool in the shared agent-session list, migrate its imports to the current package API, and cover Pool in migration and benchmark-composition regressions.

Signed-off-by: yaoyu-33 <[email protected]>

@yaoyu-33 yaoyu-33 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 at 98e8e95d1 after merging current main (b36c37b19) and independently reviewing the integration delta. The resolution keeps main's shared agent-session registry, registers Pool there, migrates Pool to the current public package imports, and extends migration/composition regression coverage. No blocking issue found.

Validation on macOS / Python 3.13.14:

  • Final affected rerun: 440 passed, 12 skipped. Command: python -m pytest responses_api_agents/pool_agent/tests tests/unit_tests/test_public_api_facades.py tests/unit_tests/config/test_global_config.py::TestComposeUnboundAgent::test_swap_to_agent_with_sessions_keeps_single_agent_turn_legacy tests/unit_tests/config/test_global_config.py::TestComposeUnboundAgent::test_agent_session_agent_types_match_the_agent_apps --import-mode=importlib -q -o addopts='' -o log_cli=false.
  • The broader sweep also passed the complete migration/configuration suites and repository session-contract checks; its one public-import failure was corrected and rechecked in the final run above.
  • pre-commit run --all-files, whitespace checks, and DCO sign-offs pass.

The 12 skips are Linux-only lifecycle and optional real-Pool-binary tests. No new model rollout was run for this registry/import integration repair; earlier feature smoke retains its original scope. Merge-queue CI remains required.

@yaoyu-33
yaoyu-33 enabled auto-merge November 2, 2026 17:32
@yaoyu-33

yaoyu-33 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

/ok to test 98e8e95

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41500446980

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41503469019

Merged via the queue into main with commit 057e952 Nov 2, 2026
56 of 59 checks passed
@yaoyu-33
yaoyu-33 deleted the codex/pool-sandbox-adapter branch November 2, 2026 19:26
AdamRajfer added a commit that referenced this pull request Nov 2, 2026
Brings in main up to 94545e7 (#5141, #5384, #5144, #4615, #4954, #5001,
#5175).

Textual conflict: nemo_gym/cli/env.py, imports only. This branch imports
PIPE from subprocess (the server start error capture); main imports SIGKILL
from signal (#5141, the shutdown drain). Both are kept:
"from signal import SIGINT, SIGKILL" and
"from subprocess import PIPE, Popen, TimeoutExpired".

Semantic conflict: #5141 starts each server in its own session
(run_command(..., start_new_session=True)) so shutdown can signal its
process group, while this branch starts servers through
RunHelper._spawn_server, which keeps the tail of the error stream. The
merged call passed start_new_session to _spawn_server, which did not accept
it (11 test_cli failures). _spawn_server now takes start_new_session and
forwards it to run_command, so both behaviours hold. The dry-run path keeps
this branch's process.wait(): the tail thread of _spawn_server owns the
piped stream, so main's communicate() would compete with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
AdamRajfer added a commit that referenced this pull request Nov 2, 2026
…ain's Pool test

The Pool agent arrived with main (#5001). Its lifecycle test expects a
RuntimeError when the cleanup receipt denies termination
(cleanup_confirmed false). On this branch the shared sandbox session reports
an unconfirmed harness termination as the typed NgFailureEvent
(harness_termination_unconfirmed), as it does for every other sandboxed
harness, so that case now expects NgFailureEvent. A malformed receipt
("true", 1) is still refused with RuntimeError. Test-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 98e8e95d Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9213
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 feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants