Skip to content

feat(harbor): TB2.1 minimum hardening for the harbor environment server (M6) - #3706

Merged
adil-a merged 2 commits into
mainfrom
adasif/harbor-m6-tb21-hardening
Oct 21, 2026
Merged

adil-a merged 2 commits into
mainfrom
adasif/harbor-m6-tb21-hardening

Conversation

@adil-a

@adil-a adil-a commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

M6 of the Harbor tasks RFC (GitLab MR 340, MR 354): the minimum hardening the harbor environment server (environment_servers/harbor) needs to run Terminal Bench 2.1 tasks. Stacked on #3675 (M5 was folded into #3674). Followed by M7 (Terminus 2 sessions) and M8 (the TB2.1 taskset and parity run).

  • Working directory. Use the image's own WORKDIR when a task declares none (all 89 TB2.1 tasks declare none). The server reads it with pwd in the fresh sandbox. The old /app default is gone.
  • Long commands. test.sh runs as one plain exec bounded by the task budget plus a grace period, with timeout --signal=KILL inside the container as the cap on the command itself. The provider keeps the exec alive for that long (OpenSandbox polls a background command, Docker streams), so hour-long verifiers need no detached launch. A run that leaves no reward scores 0 with harbor:verifier_timeout when the provider timed out or the wrapper's exit record shows 137 after the whole budget elapsed. A reward written before a late kill still counts, and a 137 from a killed helper inside test.sh is not taken for the timer. An image without timeout or bash is masked as a verifier error instead of scored. A first version in this branch launched the command under setsid and polled for its exit code. On OpenSandbox Cell-3 a process left running after a command returns is reaped, so that never completed. Verified on Cell-3 with a 400 s command in both provider modes.
  • Operator knobs. sandbox_resources_override (replaces only the keys it names, so a GPU task keeps its gpu request under a CPU or memory override). sandbox_env (the task's own [environment.env] wins). derive_cpu_env (on by default: exports OMP_NUM_THREADS and the other CPU-count variables matching the sandbox CPU limit, nothing when the task sets no CPU limit). sandbox_setup_commands with sandbox_setup_timeout_s (root commands run in every new sandbox before the agent sees it, for repairs the operator owns such as pointing Debian 11 at its final security snapshot. A failing command stops the sandbox and fails the seed with a 503). verifier_grace_s (default 30 s).
  • Verifier evidence. Logs are downloaded even when the verifier times out. The timeout message carries the tail of test-stdout.txt. The response carries verifier_seconds.
  • harbor_oracle_agent. Runs solve.sh the same bounded way (timeout --signal=KILL inside the container, 60 s grace on the exec). Output is captured to /logs/agent/oracle.txt (Harbor's name) and its tail goes into the oracle status. A missing timeout or bash reports oracle_error_type=wrapper.

Review fixes (2026-10-04)

  • sandbox_resources_override merges over the task's resources instead of replacing the whole dict. A GPU task routed to the GPU provider lost its gpu request under a CPU or memory override. Also drops an import left unused when the setsid runner was removed.

Validation

  • pytest environment_servers/harbor/tests responses_api_agents/harbor_oracle_agent/tests tests/unit_tests/test_harbor_validation.py tests/unit_tests/test_harbor_tasks.py tests/unit_tests/test_sandbox.py tests/unit_tests/test_task_data.py: 810 passed, 13 skipped at 68cadce (reviewer rerun).
  • ruff check and ruff format --check clean on the changed files at the rebased head. pre-commit run --files <changed files> was clean before the rebase.

Rollouts

Exercised by the TB2.1 parity run in the M8 PR of this stack: 89 tasks through gym dataset validate (oracle) and through Terminus 2, both on x86 OpenSandbox. See that PR for the tables. Those runs predate the move to the environment server and the rebase onto #3675.

Compatibility and benchmark impact

Tasks that declare a working directory keep it. Two defaults change behaviour for every task: test.sh now runs under an in-container timeout with a 30 s grace period, and a sandbox with a CPU limit gets the CPU-count env vars unless derive_cpu_env is off. The other knobs are empty by default. The reward and failure-kind rules are unchanged.

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, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Sep 28, 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.

@adil-a
adil-a added this pull request to stack #3678 September 28, 2026 13:03
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 574a040 to d982104 Compare September 28, 2026 17:56
@adil-a adil-a changed the title feat(harbor): run Terminal Bench 2.1 on the Harbor task shape (M6–M8) feat(harbor): TB2.1 minimum hardening for the harbor resources server (M6) Sep 28, 2026
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from d982104 to 998606b Compare September 28, 2026 19:35
@adil-a
adil-a removed this pull request from stack #3678 September 28, 2026 19:35
@adil-a
adil-a added this pull request to stack #3733 September 28, 2026 19:36
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 998606b to 020b736 Compare September 28, 2026 20:10
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 012c55a to 294bf41 Compare September 30, 2026 03:48
@adil-a
adil-a removed this pull request from stack #3733 September 30, 2026 03:50
@adil-a
adil-a added this pull request to stack #3806 September 30, 2026 03:51
@adil-a
adil-a removed this pull request from stack #3806 September 30, 2026 04:12
@adil-a
adil-a added this pull request to stack #3808 September 30, 2026 04:12
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 294bf41 to 416294e Compare October 4, 2026 23:19
Comment thread environment_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 416294e to 996809b Compare October 9, 2026 20:08
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from 996809b to a62d40e Compare October 9, 2026 20:20

@yuhezhang-ai yuhezhang-ai 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.

Two additional issues to address: exit code 137 can incorrectly discard a valid reward, and oracle log-directory setup can prevent a reference solution from running in a non-root image. I also left three nonblocking suggestions for ownership handling, diagnostic coverage, and configuration wording.

Comment thread resources_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
@adil-a
adil-a removed this pull request from stack #3808 October 14, 2026 00:54
@adil-a
adil-a added this pull request to stack #4583 October 14, 2026 00:55
@adil-a
adil-a force-pushed the adasif/harbor-m6-tb21-hardening branch from a62d40e to 900fbe8 Compare October 14, 2026 01:06
@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b4446fa

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 23ec55b

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1fd051f

@github-actions

Copy link
Copy Markdown
Contributor

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Status at the new head 1fd051f, now based directly on #3675 since M5 was folded into #3674.

Your four correctness threads each carry the fix and its tests inline:

  • timeout portability: both call sites use timeout -s KILL, preceded by TIMEOUT_WRAPPER_GUARD, which exits 127 before any redirection when timeout or bash is missing, so the verifier masks the sample and the oracle reports oracle_error_type=wrapper rather than scoring a zero.
  • fractional time limits: the budget is max(1, ceil(seconds)) in the verifier and in the oracle.
  • exit code 137: the wrapper writes an exit record with the start and end seconds, a 137 counts as the timer only when the elapsed time reached the budget, and a reward written before a late exit still counts.
  • oracle log directory: mkdir -p, chmod 777 and test -w on /logs/agent run as root, and a failure is reported as oracle_error_type=transfer, not as a solution failure. That version lands in feat(harbor): Compose groups, GPU routing, healthchecks and task tool context (M13) #3754 (M13), where exec_as_root exists, so on this PR alone the directory is still prepared with a plain exec.

The withdrawn ownership thread keeps its guard anyway: _prepare_workdir neither creates nor chowns a working directory of /. The other two nonblocking items are done, the oracle fake models stderr and the provider error type, and the grace comment describes extra provider waiting time. The verifier half of this code moved into environment_servers/harbor/verifier.py in the rebase.

yuhezhang-ai
yuhezhang-ai previously approved these changes Oct 20, 2026

@yuhezhang-ai yuhezhang-ai 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 addressing the review. Rechecked 1fd051f and verified the oracle log-directory fix in #3754 and OpenSandbox cancellation cleanup in #3807. With those included in the planned stack landing, I have no remaining blocking findings for this PR. The timeout-policy/documentation follow-up is nonblocking.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9dcbe69

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3f00ba5

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 68cadce

ffrujeri
ffrujeri previously approved these changes Oct 21, 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.

Approving 68cadce7. I checked the verifier timeout path: the exit record is written after test.sh into a directory cleared before verification, elapsed >= budget cannot miss a fired timer with whole-second date, and a reward written before a late kill still counts. Harbor, Oracle, validation and sandbox suites pass locally (810 passed, 13 skipped); CI is green apart from the non-blocking harness conformance probes. The Oracle log-directory fix for non-root images lands in #3754, as Yu noted, so this should land with the stack. Title and body updated to the environment-server layout and the current 137 handling.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 91d34c5

ffrujeri
ffrujeri previously approved these changes Oct 21, 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.

Re-approving 91d34c5d after the restack: git range-diff against the approved 68cadce7 shows the same patch. Stack tests pass locally; CI was still running at approval time.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f42f3f3

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test abd09ba

adil-a and others added 2 commits October 21, 2026 11:31
…bor tasks

Adds `responses_api_agents/harbor_oracle_agent` (M3 of the Harbor tasks RFC). The oracle is
an ordinary agent harness that runs a task's reference solution instead of a model: it
borrows the sandbox the `harbor` environment server seeded, where that server placed the
task's `solution/`, and runs `bash /solution/solve.sh` in the task's working directory as the
task user. Verification then scores the result like any rollout. Tasks without
`solution/solve.sh` return a response tagged `oracle=unvalidated` and are never failed.

The oracle contract lives in the seed. The environment server recognises the oracle by the
implementation name of the agent instance it serves: the one key under that instance's
`responses_api_agents` block in the merged run config (`ORACLE_AGENT`, `harbor_oracle_agent`),
read from the same block the token-capture lookup already uses. For that harness alone, after
the sandbox seed and before the agent session opens, it uploads the task snapshot's
`solution/` to `/solution` as root (where Harbor's oracle copies it) and resolves the task's
`[solution].env` on its host; any other harness never sees the solution, and a task without
`solution/` uploads nothing. `SandboxAccess` gains `user` (the task's `[agent].user`, `None`
for the sandbox's default) and `env` (the owner's resolved environment for the harness's
commands), and `AgentSeedSessionRequest` gains `agent_timeout_sec`, the task's
`[agent].timeout_sec`, which the server now sends with every seed. The oracle reads nothing
else: no `environment_server` reference, taskset mapping, task folder or digest check. Its
solve budget is the seed's `agent_timeout_sec` under `max_solve_timeout_s`, it runs as the
sandbox access's user with its env, and it probes `/solution/solve.sh` as that user first,
reporting `unvalidated` when the script is absent and failing the episode as retryable when
the probe itself hits a provider error.

`gym dataset validate <folder | harbor:dataset> [--sandbox <provider>]` prepares the taskset,
runs it with the oracle through the normal end-to-end collection (with a placeholder policy
model block, since the oracle calls no model), and prints one line per task with its reward
or why there is none. It exits non-zero when a validated task scores below 1.0, is masked, or
fails. The generated run config sets `use_absolute_ip` for harnesses that call the model
server from inside the sandbox.

Squashed from the previous oracle branch, review fixes included: every selected task and
repeat is accounted for, validation artifacts stay apart from model evaluation, resumed
validation is rejected when task digests or the selection changed, solution environment
templates resolve on the server's host at seed, the oracle serves sessions through the base
agent hooks, `ray_enabled` is declared, custom provider execution compatibility is preserved,
and validate reads rollouts in the collector's stored shape.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…er (M6)

M6 of the Harbor tasks RFC, sized for the 89 Terminal Bench 2.1 tasks:

- use the image's own WORKDIR when a task sets none;
- run `test.sh` under an in-container `timeout` with a grace period on the exec, so hour-long
  verifiers survive a provider's per-request limit and a killed verifier is a measured zero;
- keep verifier logs on timeout and report `verifier_seconds`;
- optional `sandbox_resources_override`, `sandbox_env` and `derive_cpu_env`, so a benchmark can
  run at fixed resources for a like-for-like comparison;
- operator `sandbox_setup_commands`, run as root in every new sandbox before the harness sees it
  (for repairs the operator owns rather than the task, such as pointing an end-of-life Debian at
  its signed final snapshot); a failing command is a retryable seed failure. They go through the
  root-first exec helper, so sandboxes that cannot switch identities still work;
- `oracle_agent`: run `solve.sh` the same bounded way with its output captured to a file.

Squashed from the resources-server branch and re-applied onto the environment server.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e28457c

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

Re-approving e28457c3 after the restack. git range-diff shows the patch is identical to the 91d34c5d I approved.

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

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

This branch was previously deployed

1 inactive deployment
public — e28457c3 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6368
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 complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer QA_verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants