Skip to content

feat(terminal-bench): support Codex in task sandboxes - #4064

Closed
yaoyu-33 wants to merge 39 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/codex-tb21-native
Closed

yaoyu-33 wants to merge 39 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/codex-tb21-native

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

Superseded by #3902, which now contains both Pi and Codex Terminal-Bench 2.1 support on main. Both original branch histories, recipes, and harness README links are retained in bf898f5b99a496c9b81a393d99c399e2be201ae5. Closing this duplicate at the author’s request.

The original description and validation evidence follow for provenance.


Enable Codex for Terminal-Bench 2.1 using Resources-owned task sandboxes and the shared agent-session lifecycle. Resources prepares and grades the task; EnvironmentServer closes the agent before verification and closes Resources afterward.

Targets main at 8908cb24dccb1d97411f32bc1dee541ad5961dce after #3640 merged. Inherited harness/core code matches main; the PR contains only the five TB integration files. No separate issue is needed for this requested pairing and dependency refresh.

Changes

No dataset, prompt, reward or verifier changes. This enables the pairing; it does not establish benchmark accuracy.

Validation at e3e34c9277beb2d2e199fd277bc041b22588049c

  • macOS / Python 3.13.14, checkout-first imports: 715 passed, 56 skipped, 3 warnings in 90.57s (0:01:30).
  • Canonical TB tests and example-data validation: 55 passed, 1 warning in 3.97s.
  • Full pre-commit run --all-files: Passed. DCO, PR-diff whitespace and relative README links checked.
  • Documented YAML blocks resolve against current schemas and correct Resources/agent/model bindings. Shared TB app/session tests are unchanged from the earlier children and byte-identical across all four PRs.
python -m pytest tests/unit_tests/test_sandbox_session.py tests/unit_tests/test_sandbox_supervisor_client.py tests/unit_tests/test_sandbox_supervisor_bootstrap.py tests/unit_tests/test_process_supervisor.py tests/unit_tests/test_sandbox_stop_retry.py tests/unit_tests/test_sandbox_connect.py tests/unit_tests/test_agent_sessions.py tests/unit_tests/test_agent_session_retries.py tests/unit_tests/test_base_responses_api_agent.py tests/unit_tests/test_global_config.py tests/unit_tests/test_add_legacy_agent_environment_servers.py tests/unit_tests/test_session_contract_repo.py environment_servers/single_agent_turn/tests environment_servers/single_agent_turn_legacy/tests resources_servers/swebench_pro/tests responses_api_agents/codex_agent/tests --import-mode=importlib -q -o addopts= -o log_cli=false --tb=short -rs
gym env test +entrypoint=resources_servers/terminal_bench_2_1 +should_validate_data=true ++skip_venv_if_present=true
pre-commit run --all-files

This is the targeted local selection, not full core/server CI. Labels and draft status are retained.

A signed empty commit refreshed CI after retargeting; its file tree exactly matches the tested merge commit.

Rollout evidence and limits

Earlier local-model TB smoke at 4fc57b26692ed68790b8b92df9f5bdbc00364ea4 reached real verification with an unmasked zero reward and inspected agent/tool/artifact handoff. That evidence remains pinned to its original revision. No fresh model rollout was run for this dependency synchronization; current inherited parent/main changes are covered by the deterministic checks above. TB implementation/verifier behavior is unchanged by this refresh.

Keep draft. The shared supervisor stops agent-started descendant services before grading, so service-dependent tasks remain a known limitation. File-producing smoke does not validate service lifetime. Replay remains process/session-local; full benchmark baselining and training-token parity remain outside this PR.

Move the existing upstream HTTP error handler into the shared model base and let buffered Responses errors reach it before SSE begins. Preserve the terminal-SSE fallback for non-HTTP failures. Reject metadata.extra_body before sandbox activation, including malformed or empty override payloads.

Validation: 1054 relevant tests passed, 39 platform/optional-runtime skips; pre-commit run --all-files and git diff --check passed. Seven regression cases failed before the fixes. No fresh real-model rollout or Linux process validation was performed for this follow-up.
Signed-off-by: yaoyu-33 <[email protected]>
Integrate the approved #10 changes. Route Hermes-specific callers and tests to NVIDIA-NeMo#3961.

Signed-off-by: yaoyu-33 <[email protected]>
Shared CleanupReceipt and RunnerRuntimeInfo integration is already present. Align Linux cancellation expectation with the shared supervisor. Validation: 643 passed, 48 skipped; full pre-commit passed. Linux-specific tests and fresh model rollouts remain pending.

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Oct 5, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 5, 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 changed the title feat(terminal-bench): support Codex in native task sandboxes feat(terminal-bench): support Codex in task sandboxes Oct 5, 2026
Port the shared lifecycle from NVIDIA-NeMo#3961 at 614a08b and Codex adapter capture from NVIDIA-NeMo#4064 at 7322fb3. Keep cleanup proof separate from diagnostics, preserve captured output and tolerate HarnessAgent requests without scope.

Signed-off-by: yaoyu-33 <[email protected]>
The updated SWE-Pro parent now owns the shared NVIDIA-NeMo#3961 infrastructure and Codex adapter migration. Preserve the TB composition documentation and align optional worker diagnostics with the parent contract.

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33
yaoyu-33 force-pushed the codex/codex-tb21-native branch from 7322fb3 to f12a27f Compare October 6, 2026 01:47
Port common helpers and tests from NVIDIA-NeMo#3961 at 2093960. Let the session stage its supervisor and expose protocol logs; retain adapter-owned runtime diagnostics and capture-before-release behavior.

Signed-off-by: yaoyu-33 <[email protected]>
The Codex bridge already preserves ClientResponseError status and body. Check that contract and retain diagnostic logging assertions; runtime behavior is unchanged.

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33
yaoyu-33 changed the base branch from codex/codex-native-sessions to main October 9, 2026 02:37
@yaoyu-33 yaoyu-33 closed this Oct 9, 2026
ananthsub pushed a commit to ananthsub/Gym that referenced this pull request Oct 14, 2026
…A-NeMo#3902)

Enable Pi, Codex, OpenCode and OpenClaw on Terminal-Bench 2.1 through
the shared Resources/Agent session protocol. Resources prepares one task
sandbox, the harness borrows it, verification runs in that same sandbox,
and Resources closes it afterward.

Consolidates NVIDIA-NeMo#4064, NVIDIA-NeMo#4241 and NVIDIA-NeMo#4242 into NVIDIA-NeMo#3902 after their parent
integrations merged into main. Those sibling PRs remain closed; these
review repairs stay in this PR. The existing benchmark integration and
author-requested consolidation do not need another feature issue. Legacy
lifecycle retirement is tracked in NVIDIA-NeMo#4570 under NVIDIA-NeMo#2763.

## Changes and compatibility

- One TB Resources session implementation and one benchmark recipe
selecting any of the four harnesses. The recipe uses taskset routing,
`materialize_task`, and `single_agent_turn`. Existing direct-agent
recipes remain available.
- Session seed/verification replay validates task identity; Resources
keeps ownership through grading and retries failed stops. Completed
close records expire after `session_close_retry_window_seconds` (default
300 seconds); retries do not extend it. Close fences slow setup before
waiting for its lock, and late setup attempts bounded cleanup; failed
stops retain ownership. After a cancelled final close and failed late
stop, no durable automatic retry is scheduled: explicit close retry or
shutdown can use the retained handle, while provider TTL can stop the
sandbox but does not purge the in-memory record.
- The Linux supervisor stops live harness-group processes and reaps its
children. Before timeout/close, it snapshots already adopted children,
typically services from completed tools. After stopping the harness, it
repeatedly kills/reaps newly adopted children, including in-flight tools
in separate sessions, within the existing cleanup budget. Previously
adopted services outside the group remain for the sandbox owner.
Zombie-only groups held by another live parent do not falsely fail
termination. There is no `preserve_descendants_on_success` policy
switch.
- A valid final negative termination receipt fails activation and skips
capture/verification, but permits borrowed-session release so Resources
can tear down the sandbox. Missing or inconclusive termination evidence
stays retryable; positive confirmation tolerates malformed optional
diagnostics. Each final cleanup callback gets its own deadline, so an
unresponsive agent close cannot consume the Resources owner's close
attempt.
- Task shell HOME is preserved. Pi/Codex/OpenClaw use their
harness-specific state locations. OpenCode keeps private CLI HOME/XDG
state and restores task HOME/XDG for shell commands through its
`shell.env` hook. A fresh successful-initialization receipt is required
before accepting a gradable result; missing/invalid receipt fails
activation even when the CLI ignored a plugin error. This check prevents
grading, not earlier execution. Borrowed agent close removes the private
session directory; Resources retains the task sandbox.
- OpenClaw sets `OPENCLAW_NO_RESPAWN=1` so its pinned CLI does not
detach the agent during non-TTY startup. Compile-cache wrappers may
still spawn within the supervised group.
- Removed `keep_sandbox_for_close`. Session verification grades the
existing sandbox; legacy `verify` owns its bounded cleanup; golden
verification owns a separate sandbox and bounded `finally` cleanup. A
legacy seed created before golden verification is also closed.
- Direct sandboxed Hermes redirects inherited stdout/stderr to a session
log, preventing detached services from holding the provider exec pipe
open. It downloads only a bounded 1 MiB tail, including a truncation
marker, for diagnostics. Shared caller docs and Linux regressions cover
Hermes and SWE-Pro as well as the four TB harnesses.

This changes shared process-lifetime behavior. Services from completed
tools must use task-owned files and avoid retaining transport streams;
the pinned harnesses already run shell tools in separate sessions.
Natural CLI exit has no stop-time cutoff, so unfinished detached tools
cannot be distinguished from services and may still change task files.
Adoption timing, PID reuse and later service forks also limit the
forced-stop rule. A positive receipt does not guarantee an idle sandbox
and is not a security boundary. SWE-Pro still extracts a patch and
grades it in a fresh sandbox; TB grades the original task state. No
original TB task prompt, dataset, scoring formula, or default permission
profile is changed. Sessions remain process-local and require one
worker.

## Lifecycle

The Agent and Resources servers run outside the task sandbox. Normal
gradable completion is:

```mermaid
sequenceDiagram
    participant E as Environment server
    participant R as Resources server
    participant A as Agent server
    participant S as Task sandbox
    E->>R: Seed Resources session
    R->>S: Create and set up sandbox
    R-->>E: Sandbox access
    E->>A: Seed agent with sandbox access
    E->>A: Run agent
    A->>S: Harness CLI and tools
    Note over A,S: Stop live harness-group processes and reap children
    Note over A,S: On timeout/close, also drain newly adopted tools
    Note over A,S: Confirm termination, then capture artifacts
    A-->>E: Gradable agent response
    E->>A: Close agent session
    A->>S: Remove private harness session files
    A-->>E: Release borrowed connection
    Note over R,S: Task files and preserved services remain
    E->>R: Verify
    R->>S: Run task tests in this same sandbox
    R-->>E: Verdict
    E->>R: Final cleanup
    R->>S: Stop sandbox and remaining processes
```

On failure or cancellation, final cleanup still attempts each registered
owner. Successful session release alone does not make a failed
activation gradable. Confirmed harness termination permits capture, not
a passing reward. Golden verification creates and closes its own sandbox
and has no agent session.

## Validation — current review repair

Runtime repair
[`8d8809e13`](NVIDIA-NeMo@8d8809e13),
merged with main `e085a1d2a` in `6f6f9ac3e`; final test-only follow-up
[`ab9f3cc27`](NVIDIA-NeMo@ab9f3cc27).
Three independent agents implemented, challenged and cross-reviewed the
nine comment fixes over multiple rounds. No additional PR was created.

- Final Linux/Python 3.13.14 affected suite: **2,012 passed, 0
skipped**, tree `7765f9bcac97fd7a7f81e398ff9286c0329896bf`. Includes
shared supervisor/session/environment/checkpoint lifecycle, both
environment adapters, TB/SWE-Pro, four harness suites and affected
Hermes suites. Pinned CLI tests were enabled, not skipped.
- The first full attempt retained **2,011 passed, 1 failed**: a Codex
fixture modeled an in-flight child as a completed-tool service. The
corrected fixture preserves the original alive-service/dead-CLI
assertions; its whole session file passes 133 tests before the complete
rerun.
- All eight new detached-writer regressions fail against the previous
supervisor; all 40 isolated supervisor tests pass after repair. Pinned
OpenClaw non-TTY startup reaches a held model request in one group and
stops; changing only `OPENCLAW_NO_RESPAWN` to 0 fails its PGID
assertion. Pinned OpenCode loader tests reproduce ignored plugin
failures with no receipt. Final pinned-runtime selection: 13 passed, 0
skipped (overlaps the full suite).
- Removing only the second final-negative-receipt check fails the new
regression; restoring unbounded Hermes output fails its diagnostic test.
- Final `pre-commit run --all-files`, Ruff and diff checks pass; Fern
`npm run check`: zero errors, one warning. All three new commits have
DCO sign-off.

Fresh real-model smoke: Qwen2.5-7B-Instruct revision
`a09a35458c702b33eeacc393d103063234e8bc28`, vLLM 0.8.5 on RTX A6000;
temperature 0, 32,768 context, 4,096 provider output tokens/call, 300s
harness/verifier, 1,200s episode, 1,800s sandbox TTL, 2 CPU/4,096 MiB.
Dataset `7131e4375048a0e408a8fb404b5f499d726b695b`; original task/test
bytes and images retained, current taskset routing and default harness
permissions unchanged.

| Harness | Original certificate task | Original log-summary task |
Synthetic HOME/XDG/service control |
| --- | --- | --- | --- |
| Pi 0.80.2 | graded 0 | graded 0 | reward 1 |
| Codex 0.144.4 | graded 0 | graded 0 | reward 1 |
| OpenCode 1.17.11 | graded 0 | graded 0 | reward 1 |
| OpenClaw 2026.6.11 | graded 0 | graded 0 | reward 1 |

**12/12 attempts graded; no failed activation or missing row; all four
strict 3/3 profiles pass.** Four synthetic controls each contain an
actual native tool call and verify task HOME/custom XDG markers, an HTTP
service alive after agent close, removed private session directories,
and unchanged task OpenCode config. Eight original-task zeros have
`evaluation_completed=true` and task-test failures, not verifier
infrastructure exceptions. These scores are not benchmark successes.

Native responses include five completed and seven incomplete results. Pi
log-summary and OpenClaw certificate/log-summary have no actual tool
calls despite textual tool markup. Pi/Codex/OpenCode certificate runs
exercise partial-result grading after time limits. Native
observations/token joins have gaps; strict profile completion does not
certify rollout quality or full training-token parity. Automated health
reports Codex 2 unhealthy/1 unobserved (failed model endings, including
output/context limits) and OpenCode 1 unhealthy/2 healthy (token-count
mismatch). Pi and OpenClaw are 3 healthy each; that does not imply task
success. The explicitly detached control service does not establish
compatibility for every service-launch recipe.

Smoke source is tree `4f455a30592b106eafba853cf64db193a5e3c4e6`
(`6f6f9ac3e`). The only later changes are three test files in
`ab9f3cc27`; all runtime/docs bytes match. Each arm's source hashes
stayed unchanged. All 12 containers have normal destroy events, no
fallback removal or forced Gym stop; task-owned model/Gym processes,
control image and ports are cleaned, and raw evidence is archived.
Existing unrelated workloads were preserved.

## Historical evidence and remaining gates

Earlier repair `c2a6dec84` had 1,926 Linux passes plus a 397-test
OpenCode follow-up. Its 16 retained model attempts included one OpenCode
startup failure before any model call; a separate repeat graded zero but
did not explain or erase that failure. [Earlier repair
report](NVIDIA-NeMo#3902 (comment)).
That evidence and the October 12 `06bd366b5` smoke predate the current
adoption-cutoff policy. The new Pi/Codex/OpenCode certificate runs
exercise deadline drain under a real model. Preserving a service already
adopted before a forced stop is covered by the Linux regressions only;
the synthetic service controls cover normal completion and do not
establish that forced-stop preservation behavior.

The full PR touches shared core code and requires full CI and maintainer
review. Earlier CI at `3dd3ae027` passed core/server shards but reported
a Hermes P0 `model_error` conformance failure; this local validation
does not claim to clear that scenario. Exact-current-head CI remains a
separate gate. No trust-gate command was posted.

- NVIDIA-NeMo#4570 is attached as an actual sub-issue of NVIDIA-NeMo#2763 and tracks retiring
legacy direct-agent ownership; removing only `single_agent_turn_legacy`
does not retire those agents.
- NVIDIA-NeMo#4571 tracks inherited verifier infrastructure failures recorded as
unmasked zero; this lifecycle repair does not change that scoring
contract.
- SWE-Pro/Hermes and benchmark-owner review remain relevant because the
supervisor is shared.

---------

Signed-off-by: yaoyu-33 <[email protected]>
Co-authored-by: Adil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant