Skip to content

fix(agent): honor task timeouts and install sandbox dependencies - #4653

Merged
yaoyu-33 merged 5 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/harness-task-timeout-deps
Oct 16, 2026
Merged

yaoyu-33 merged 5 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/harness-task-timeout-deps

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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 sandbox extra 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

  • Three fresh Python 3.13.14 component venvs, each installed from its own requirements.txt: all three SDK checks pass. A separate fresh venv using the original [dev] declaration fails all three checks with No module named 'opensandbox'.
  • Focused adapter/session and timeout tests: 871 passed, 12 Linux-only skips on macOS. Added cases cover actual Harbor materialization through HTTP validation into supervisor budgets, local propagation, invalid/default/capped budgets, fractional OpenClaw arguments, and rejection without consuming the session activation.
  • pre-commit run --all-files: passed, including all new tracked files.
  • git diff --check: passed. Commit has DCO sign-off.
  • Follow-up commit 13073d2 (budget recorded in response metadata): on macOS, Python 3.13, the full test directories of Codex/Pi/OpenCode/OpenClaw/Hermes gave 1551 passed, 155 Linux-only skips, and the focused suite above plus Hermes gave 1259 passed, 48 skipped; pre-commit run --files on the changed files passed. No new rollouts: the change adds a metadata key and does not alter execution.
  • Follow-up commit 232cdf4 (pi_sandboxed_agent accepts and applies the task budget; fixes the CI TypeError in its _run_pi override): responses_api_agents/pi_sandboxed_agent/tests gave 49 passed on macOS, Python 3.13, including new cases for absent, shorter and capped budgets; pre-commit run --files on the changed files passed. No new rollouts.
  • Final Linux focused adapter/session/shared-supervisor suite: 999 passed, 3 skipped (three Pi JavaScript extension tests: Node absent from that SSH PATH; these passed in the macOS run). All changed-source hashes matched the reviewed commit.

Dependency checks run from each component directory:

uv venv --python 3.13.14 "$VENV"
uv pip install --python "$VENV/bin/python" -r requirements.txt
"$VENV/bin/python" -m pytest -o addopts= -q tests/test_runtime_dependencies.py

Final Linux suite (Python 3.13.14; reviewed source explicitly first on PYTHONPATH, isolated component site-packages, -S to 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.py

Rollouts

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_task produced each request from task.toml; the configured agent ceiling was 300s. The model was Qwen/Qwen2.5-7B-Instruct at a09a35458c702b33eeacc393d103063234e8bc28, served locally by vLLM 0.8.5 / transformers 4.51.3.

Harness Normal task budget / result Deadline task budget / result Retained output items at deadline
Codex 0.144.4 120s / completed, reward 1 5.5s / incomplete, reward 1 2
Pi 0.80.2 120s / completed, reward 1 20.5s / incomplete, reward 1 1
OpenCode 1.17.11 120s / completed, reward 1 20.5s / incomplete, reward 1 2
OpenClaw 2026.6.11 120s / completed, reward 1 20.5s / incomplete, reward 1 3

The model was instructed to write 42 to a file using its shell tool. Deadline cases then ran sleep 90; verification checked the retained file after agent close. All eight had evaluation_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 shared resolve_agent_timeout helper with unchanged behavior, and Codex no longer writes its unused timeout/cleanup_timeout fields into the sandbox runner's input.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 configured timeout). 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:45
Loading
gantt
    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:45
Loading
ID Timer Starts Ends
① Episode deadline Environment enters the episode run() returns, after verify
② Provider hard cap, 2×(P+60)+30 OpenSandbox _dispatch() begins dispatch returns, including retries
③ SDK operation, P+60 per attempt each SDK call begins that call returns; a retry gets a new ③
④ Remote command, P = T+C+30 the remote service starts the supervisor the supervisor exits
⑤ Harness budget T supervisor Popen() starts the runner runner exits, a stop arrives, or T passes (then SIGTERM)
⑥ Cleanup phases, C/3 each TERM grace, direct reap, group reap each phase separately
⑦ Stop confirmation, C stop_harness() begins termination is confirmed
⑧ Artifact collection, C _collect() begins collection finishes

② 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 single asyncio.wait_for(..., timeout=T) that starts once the subprocess is launched; ② to ④ and ⑥ to ⑧ do not apply there.

Checklist

  • I have read the contributing guidelines.
  • The change is focused.
  • Tests added and focused macOS/Linux checks pass with the skips recorded above.
  • Documentation N/A: repair of an existing materialized request contract; compatibility is described above.
  • Pre-commit checks pass locally.
  • New source files include the required SPDX header.
  • All commits have DCO sign-off.

@yaoyu-33 yaoyu-33 added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Oct 15, 2026
@copy-pr-bot

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

@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 15, 2026 21:20
@yaoyu-33 yaoyu-33 added the needs-review PR is ready for code review and waiting on a reviewer label Oct 15, 2026
yaoyu-33 and others added 2 commits October 15, 2026 16:11
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
ffrujeri previously approved these changes Oct 15, 2026

@ffrujeri ffrujeri 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 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.py plus 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.py only reads directory, prompt, command, cwd and env, so dropping timeout/cleanup_timeout from 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.py is renamed to test_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"

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.

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),

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.

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

Copy link
Copy Markdown
Contributor Author

/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]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 232cdf4

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

Merged via the queue into NVIDIA-NeMo:main with commit 6f295d7 Oct 16, 2026
47 of 52 checks passed
@yaoyu-33
yaoyu-33 deleted the codex/harness-task-timeout-deps branch October 16, 2026 05:05
oyilmaz-nvidia pushed a commit to anushaknvidia/Indic_Gym that referenced this pull request Oct 20, 2026
* 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]>

This branch was previously deployed

1 inactive deployment
public — 232cdf4f Deployed Oct 16, 2026 by copy-pr-bot[bot] via release / finalize / notify #5597
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 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