Repository navigation
fix(agent): honor task timeouts and install sandbox dependencies - #4653
Conversation
Signed-off-by: yaoyu-33 <[email protected]>
Codex, Pi, OpenCode and OpenClaw now cap the run by the task's agent_timeout_sec, but their responses did not say which budget was applied. Record it as response metadata on sandbox and local paths, as Hermes already does, so runs with different effective budgets can be told apart. Hermes now delegates to the shared resolve_agent_timeout helper instead of keeping its own copy. Codex no longer writes timeout fields into input.json: its sandbox runner never read them, and the supervisor's arguments enforce the budget. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
The file covers Codex's sandbox session lifecycle. "native" was ambiguous next to the sandbox/local execution split; the new name matches opencode_agent/tests/test_sandbox_sessions.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
ffrujeri
left a comment
There was a problem hiding this comment.
Thanks for this! It closes the gaps we hit in the TB2.1 parity runs. With this PR, Codex, Pi, OpenCode and OpenClaw accept the Harbor agent_timeout_sec metadata and apply it on both the sandbox and local paths, never exceeding the configured timeout, and Codex, Pi and OpenClaw get the sandbox extra.
Validation on my side
tests/unit_tests/test_task_timeout.pyplus the Codex, Pi, OpenClaw and OpenCode test folders, in a fresh venv built from this branch: 1397 passed, 18 skipped.- Hermes tests, in a venv built from its
requirements.txt: 305 passed. - I confirmed
codex_agent/sandbox_runner.pyonly readsdirectory,prompt,command,cwdandenv, so droppingtimeout/cleanup_timeoutfrom the runner's input file is safe.
Non-blocking questions and notes
- Benchmark impact: on Harbor, these four harnesses will now stop at the task budget (for example 900 s) whenever it is below the config
timeout, so scores may shift compared to earlier runs. Would you mind adding a sentence about this to the PR description? Main's TB2.1 rows carry no metadata, so I don't expect any change there. - Test rename:
test_native_sessions.pyis renamed totest_sandbox_sessions.py. That's fine with me; just checking it was intentional and not left over from another branch. - CI: only lint, copyright, secrets and DCO have run so far. It might be worth adding the unit-test CI label so the agent tests run on CI, ideally after a rebase, since the branch is one commit behind
main.
None of these block the merge. Approving.
|
|
||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| AGENT_TIMEOUT_METADATA_KEY = "agent_timeout_sec" |
There was a problem hiding this comment.
nit / question: the Harbor branch's materialize.py defines the same "agent_timeout_sec" string on the producer side. When Harbor lands, should it import this constant so both sides share one definition? No change needed here.
| "harness_execution": "sandbox", | ||
| **({"harness_hostname": runtime.hostname, "harness_pid": str(runtime.pid)} if runtime else {}), | ||
| "pi_version": self.config.pi_version, | ||
| AGENT_TIMEOUT_METADATA_KEY: str(timeout), |
There was a problem hiding this comment.
Nice touch recording the timeout that was actually applied. Just flagging that responses now carry a new metadata.agent_timeout_sec key (Codex, OpenClaw and OpenCode do the same). Do you know of anything downstream that compares response metadata exactly? I don't, so I'm only mentioning it.
The runtime-dependency tests for Codex, Pi and OpenClaw called the private OpenSandboxProvider._connection_config. Build the SDK's public ConnectionConfig directly instead. The import stays inside the test so a venv without the sandbox extra reports a test failure rather than a collection error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test a413940 |
PiAgent._create_episode now passes the resolved task budget to _run_pi, which PiSandboxedAgent overrides without that keyword, so every sandboxed Pi run raised TypeError. Accept it and bound the Pi execution with it, so the budget recorded in the response is the one applied. Sandbox setup commands keep the configured timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 232cdf4 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38852364338 |
* docs(agent): add harness onboarding and upgrade guide Add a contributor guide for integrating or updating an agent harness that runs in a task sandbox: independent benchmark and agent composition, the episode lifecycle and sandbox lifetime policies, the Agent Server contracts, configuration, a worked experiment with a Hermes to Pi and a SWE-bench Pro to Terminal Bench 2.1 swap, the agent_utils session helpers, input and error mapping, retry and close safety, and per-pairing validation. The page content is the guide from NVIDIA-NeMo#3917 at 3955a97, unchanged. It is split out so the architecture change and the agent-server page structure can be reviewed separately. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]> * docs(agent): bring the harness guide up to date with main - Step 3 resolves the time budget with resolve_agent_timeout(), runs under the adapter's concurrency semaphore, and names the session lookup helpers; list agent_utils/task_timeout.py, and note that Pi accepts metadata.agent_timeout_sec (NVIDIA-NeMo#4653). - Pass --allow-unsupported-pairing only to gym eval run, which checks the pairing at dispatch; prepare and resolve do not accept it. - Set cleanup_timeout_seconds: 360 in the run.yaml example so Pi's close fits, and note that the benchmark sandbox ttl_s is a separate limit. - Close the provider when AsyncSandbox.connect() fails in the borrower snippet. - Correct the OpenCode version pin, the Hermes 500 cases, the migration note, and the SWE-bench Pro empty-patch path; add the requirements.txt row with the sandbox extra. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]> --------- Signed-off-by: yaoyu-33 <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
What does this PR do?
Fresh Codex, Pi and OpenClaw environments omit the OpenSandbox SDK, so sandbox sessions fail when the provider first imports it. Add the existing
sandboxextra to their requirements and an unmocked SDK initialization test in each agent's isolated test environment.Harbor materializes
metadata.agent_timeout_sec, but Pi/OpenCode/OpenClaw reject it and Codex ignores it. Accept this one metadata key in the strict adapters and apply the task budget in all four adapters' sandbox supervisors and local subprocess waits. Reuse the policy established by Hermes in #4270: a positive finite task budget is capped by the configured timeout; absent/invalid values retain that configured timeout. OpenClaw receives integer CLI seconds, with the supervisor enforcing the precise fractional limit.No separate issue is needed: this focused bug fix includes reproductions for both reported failures. Execution, cleanup and failure classification stay with the existing runtime; replacing the Environment Server's RPC wait with an outer timeout would require a separate partial-result retrieval contract.
CI missed the dependency defect because session tests mock provider connection, bypassing the lazy SDK import. Conformance uses the local provider. The new unskipped tests exercise the installed SDK without contacting a sandbox service.
Validation
requirements.txt: all three SDK checks pass. A separate fresh venv using the original[dev]declaration fails all three checks withNo module named 'opensandbox'.pre-commit run --all-files: passed, including all new tracked files.git diff --check: passed. Commit has DCO sign-off.pre-commit run --fileson the changed files passed. No new rollouts: the change adds a metadata key and does not alter execution.pi_sandboxed_agentaccepts and applies the task budget; fixes the CITypeErrorin its_run_pioverride):responses_api_agents/pi_sandboxed_agent/testsgave 49 passed on macOS, Python 3.13, including new cases for absent, shorter and capped budgets;pre-commit run --fileson the changed files passed. No new rollouts.Dependency checks run from each component directory:
Final Linux suite (Python 3.13.14; reviewed source explicitly first on
PYTHONPATH, isolated component site-packages,-Sto exclude editable-import hooks):python -S -m pytest --import-mode=importlib -q -o log_cli=false -o addopts= \ tests/unit_tests/test_task_timeout.py \ responses_api_agents/{codex,pi,openclaw,opencode}_agent/tests/test_app.py \ responses_api_agents/codex_agent/tests/test_sandbox_sessions.py \ responses_api_agents/{pi,openclaw}_agent/tests/test_sandbox.py \ responses_api_agents/opencode_agent/tests/test_sandbox_sessions.py \ responses_api_agents/{codex,pi,openclaw}_agent/tests/test_runtime_dependencies.py \ tests/unit_tests/test_process_supervisor.py \ tests/unit_tests/test_sandbox_session.py \ tests/unit_tests/test_sandbox_supervisor_client.pyRollouts
Executed eight synthetic episodes against this commit with the real pinned CLIs, Gym model/Environment servers, Docker execution, and a file verifier. Harbor
load_task/materialize_taskproduced each request fromtask.toml; the configured agent ceiling was 300s. The model was Qwen/Qwen2.5-7B-Instruct ata09a35458c702b33eeacc393d103063234e8bc28, served locally by vLLM 0.8.5 / transformers 4.51.3.The model was instructed to write
42to a file using its shell tool. Deadline cases then ransleep 90; verification checked the retained file after agent close. All eight hadevaluation_completed=true,mask_sample=false, retained tool calls, and no fallback container removal. Codex's initial 20.5s case completed early, so the 5.5s case separately exercised actual expiration. These are synthetic contract checks, not benchmark scores. OpenSandbox was checked through clean SDK installation/initialization; the real-model runs used Docker. Complete training token-ID round trips were not asserted.The task model and containers were stopped afterward; cleanup confirmed no remaining task containers and a closed model port.
Compatibility and benchmark impact
Rows without timeout metadata retain their configured budget. Codex still accepts ordinary metadata; the strict adapters still reject unrelated metadata. Task budgets may shorten runs and change benchmark results: for example, task 900s/config 1800s now runs at 900s; task 900s/config 600s remains capped at 600s. Historical runs with different effective budgets should not be compared as equal-budget results. This does not redesign existing timeout response/artifact semantics or move agent budgets into the session control protocol.
Responses from Codex, Pi, OpenCode and OpenClaw now record the applied budget as
metadata.agent_timeout_sec(seconds as a string, after capping), on both sandbox and local paths, matching Hermes sandbox responses. Consumers that compare response metadata exactly will see this new key. Unlike these four adapters' local paths, Hermes host execution still does not apply the task budget. Hermes now uses the sharedresolve_agent_timeouthelper with unchanged behavior, and Codex no longer writes its unusedtimeout/cleanup_timeoutfields into the sandbox runner'sinput.json.pi_sandboxed_agent, which inherits Pi's request handling, now also bounds its Pi run by the task budget; its sandbox setup commands keep the configured timeout.Timeout boundaries
Where each timer starts and ends in one foreground sandbox episode that reaches the task budget, with T = 900 s and C =
session_close_timeout_seconds= 60 s. This PR only changes how T is chosen (the task budget, capped by the configuredtimeout). P, ③ and ② are computed from T, so they shrink with it. Durations after the deadline are illustrative; each label gives its limit.gantt title Whole episode (mm:ss), deadline case, T=900s, C=60s dateFormat HH:mm:ss axisFormat %M:%S section Gym host ① Episode deadline :e1, 00:00:00, 00:16:40 ② Provider hard cap (limit 2130s) :p2, 00:00:40, 00:15:58 ③ SDK operation (limit 1050s/attempt) :p3, 00:00:40, 00:15:57 section Sandbox ④ Remote command (limit P=990s) :s4, 00:00:42, 00:15:56 ⑤ Harness budget T=min(task, ceiling) :active, s5, 00:00:45, 00:15:45 OpenClaw CLI --timeout ceil(T) :done, oc, 00:00:50, 00:15:45gantt title Zoom on T deadline to episode end (mm:ss) dateFormat HH:mm:ss axisFormat %M:%S section Gym host ① Episode deadline (continues) :e1, 00:15:40, 00:16:40 ② Provider hard cap ends :p2, 00:15:40, 00:15:58 ③ SDK operation ends :p3, 00:15:40, 00:15:57 ⑦ Stop confirmation (limit C) :p7, 00:16:00, 00:16:05 ⑧ Artifact collection (limit C) :p8, 00:16:05, 00:16:15 Close, verify :cv, 00:16:15, 00:16:40 section Sandbox ⑤ Harness budget ends, SIGTERM :active, s5, 00:15:40, 00:15:45 ⑥ TERM grace (up to C/3) :s6a, 00:15:45, 00:15:50 ⑥ Direct reap (up to C/3) :s6b, 00:15:50, 00:15:52 ⑥ Group reap (up to C/3) :s6c, 00:15:52, 00:15:54 ④ Remote command ends :s4, 00:15:40, 00:15:56 OpenClaw CLI timer, killed before ceil(T) :done, oc, 00:15:40, 00:15:45run()returns, after verify_dispatch()beginsPopen()starts the runnerstop_harness()begins_collect()begins② and ③ start together at provider dispatch, and with one successful attempt they also end together. OpenClaw's own
--timeout ceil(T)starts after Node boots and is never shorter than T, so the supervisor always stops the run first. Local (non-sandbox) runs use a singleasyncio.wait_for(..., timeout=T)that starts once the subprocess is launched; ② to ④ and ⑥ to ⑧ do not apply there.Checklist