Skip to content

feat(harbor): add the environment server for Harbor-format tasks - #3674

Merged
ffrujeri merged 1 commit into
mainfrom
adasif/harbor-m2-resources-server
Oct 21, 2026
Merged

ffrujeri merged 1 commit into
mainfrom
adasif/harbor-m2-resources-server

Conversation

@adil-a

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

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds environment_servers/harbor, the environment server that runs Harbor-format task folders. Builds on #3673 (merged), which loads task folders and hub datasets into materialized rows; this is the next layer of the existing Harbor proposal, so no separate issue is needed.

One /run call owns one episode; no resources server takes part:

  • Seed: checks the row's _ng_digest against the taskset mapping, snapshots and re-hashes the task once per digest (concurrent episodes share it), starts the task image through the configured sandbox provider, and prepares the workdir.
  • Agent: seeds a session on the configured agent server with a SandboxAccess (the seed every sandboxed harness already accepts), posts the task's responses_create_params, then closes the session and keeps its observations.
  • Verify: unlinks symlinked verification roots, clears /tests and /logs/verifier, uploads the snapshot's tests/, runs bash /tests/test.sh in the same sandbox, downloads the reward first and diagnostic logs best-effort into a fresh server-generated directory.
  • Cleanup: stops the sandbox. Ownership is held until a stop succeeds; failed stops are retried by a redelivered episode and at shutdown.

Failures are staged (seed, agent, cleanup, verification) and carry the harness's observations and any usable response. Task or row defects are terminal; provider, transport and host-storage failures are retryable. When test.sh ran, the sample is measured: a missing, malformed or non-finite reward or a verifier timeout scores 0 with a harbor:* failure kind. Only Gym-side failures (sandbox lost, reward transfer failed, local log directory unusable) set mask_sample. A multi-key reward.json without a reward key is a terminal authoring error.

Supporting changes:

  • nemo_gym/sandbox/transfer.py: shared tar-based upload_dir/download_dir that run as root with a default-user fallback and extract with tarfile.data_filter.
  • nemo_gym/tasks/harbor: the generated run config now has an agent block (declaring the materialized rows as its dataset) and a per-taskset harbor environment server block that names that agent. The resources-server block is removed.
  • nemo_gym/train_data_utils.py: data preparation finds the task_data.py schema of the environment server that drives a self-contained agent, so gym data prepare validates Harbor rows against the schema the server enforces.
  • Five small example tasks under data/tasks/, with their materialized rows; secrets baseline entries for the example rollout files (no credentials).

Validation

  • pytest environment_servers/harbor/tests tests/unit_tests/test_harbor_tasks.py tests/unit_tests/test_sandbox_transfer.py tests/unit_tests/test_task_data.py at f55e0f3: 637 passed, 1 failed locally. The failure is test_transfer_preserves_target_permissions_and_task_file_modes, which only fails under a restrictive umask such as 027; it passes in CI.
  • CI at f55e0f3: Lint, Test, and server shards 0–4, 6 and 7 pass. Shard 5, which includes environment_servers/harbor, fails only in responses_api_agents/miniswe_sandboxed_agent (APIConnectionError to its mock model), which this PR does not touch. The codex/opencode/pi harness conformance failures also occur on main.
  • Regression tests cover: cancelled seed leaving the stop to the bounded cleanup; host-copy ENOSPC as a retryable seed failure; malformed task.toml as terminal; episode-ID containment for verifier log directories; symlinked verification roots; reward precedence and parsing; failed-stop ownership through retry and shutdown.

Rollouts

The checked-in data/example_rollouts.jsonl and data/example_metrics.json (Qwen2.5-0.5B-Instruct Q4_K_M, 5 tasks, mean reward 0.2, none masked) were produced on Oct 12 by the previous resources-server version of this layer, with a single-command smoke harness and an in-process sandbox handoff, because Enroot cannot serialize sandbox access. They exercise the carried-over verifier, transfer and cleanup logic in real Enroot ubuntu:24.04 sandboxes. They do not exercise this PR's /run episode flow, the agent-session SandboxAccess handoff, Hermes, or provider TTL expiration. verified remains false.

Compatibility and benchmark impact

New server, so no existing benchmark results change. Generated Harbor run configs change shape: they no longer contain a harbor_*_resources_server block, and the environment server is harbor, not single_agent_turn. Hand-written configs from the earlier resources-server layer must be regenerated.

Unsupported task modes are rejected at seed rather than silently ignored: separate verification, explicit [agent].user/Dockerfile USER, Dockerfile builds, sandbox-less tasks and restricted networking. Clearing /tests before verification intentionally differs from Harbor's shared mode, which merges tests; helpers baked into an image's /tests must ship in the task's tests/. Consumers should read verifier_logs_dir from the result rather than deriving it from the episode ID. See environment_servers/harbor/README.md.

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.
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s).

@copy-pr-bot

copy-pr-bot Bot commented Sep 24, 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 24, 2026 08:49
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch from 914b8a6 to 0d18371 Compare September 24, 2026 08:52
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch from 0d18371 to 1948e57 Compare September 24, 2026 09:00
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch 2 times, most recently from 3dd9dd9 to ac3e67a 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-m2-resources-server branch from ac3e67a to 563d6b5 Compare September 28, 2026 20:10
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch from 563d6b5 to bffd9ec 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-m2-resources-server branch from bffd9ec to e33e106 Compare October 4, 2026 23:19
@adil-a
adil-a marked this pull request as ready for review October 7, 2026 16:45
yuhezhang-ai

This comment was marked as resolved.

Comment thread resources_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/app.py Resolved
Comment thread resources_servers/harbor/task_data.py Resolved
Comment thread resources_servers/harbor/README.md Resolved
@yaoyu-33 yaoyu-33 added 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 waiting-on-customer Waiting on the original author to respond labels Oct 7, 2026
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch from e33e106 to 18428fa Compare October 9, 2026 20:07
Base automatically changed from adasif/harbor-m1-loader to main October 15, 2026 04:51
@adil-a
adil-a force-pushed the adasif/harbor-m2-resources-server branch from d2ae8c0 to 1042727 Compare October 15, 2026 04:51
@adil-a

adil-a commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1042727

@adil-a

adil-a commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e339084

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f55e0f3

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cf44a4b

@ffrujeri

Copy link
Copy Markdown
Contributor

@adil-a thanks for the schema fix, I checked it on cf44a4be and the tau2 wrapper layout validates against its own schema again.

One thing came in with the re-fold: against main, the commit now also deletes 34 files outside Harbor. Was that intentional? They're tracked files that match .gitignore patterns (*.jsonl, **/data/*_metrics.json, temp*), so they look like they dropped out while the commit was rebuilt. For example:

  • benchmark metrics under benchmarks/*/data/ (aime24, gpqa, mmlu_pro, scicode, ...)
  • benchmarks/osworld/data/* and benchmarks/automationbench/data/*
  • resources_servers/indirect_prompt_injection/data/example_{metrics.json,rollouts.jsonl}. Server shard 2 now fails data validation on this one.
  • resources_servers/structured_outputs/misc/data_generation/structured_outputs_v3/templates.py, which generators/direct.py and generators/error_correction.py import.

If they weren't meant to go, this restores them from the base:

git checkout 8073346931cc646e1fe1f72dd5f101d9a5936219 -- \
  $(git diff --name-only --diff-filter=D 8073346931cc646e1fe1f72dd5f101d9a5936219 HEAD | grep -v harbor)

git diff --name-status 8073346931cc646e1fe1f72dd5f101d9a5936219 HEAD | grep -v harbor lists all 34.

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 901c9a1

@ffrujeri

Copy link
Copy Markdown
Contributor

Thanks for restoring the files, @adil-a. On 901c9a1a, all 34 are back and identical to the base, and the PR now only touches Harbor plus the shared transfer and data-prep code. Server shard 2 passes again.

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f1e36c7

ffrujeri
ffrujeri previously approved these changes Oct 20, 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 f1e36c76. All review threads are resolved, the unrelated files are restored, and the rebase onto main only adds environment_servers/harbor/.gitignore and a test fixture rename. The Harbor and data-prep tests pass, and CI is green apart from the non-blocking harness conformance probes.

Follow-ups, none blocking:

  • A fresh smoke rollout through the environment server and agent-session handoff. The checked-in example rollouts predate the rewrite.
  • A reply to Yu's Oct 15 question about reusing upstream Harbor parsing and reward handling.

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I checked this against the installed harbor 0.22.0. The overlap is small and the coupling is large. What we copy from Harbor is a few hundred lines of pure code: the task.toml models, the whole-value ${VAR} template rule, the verifier mode resolution, the packager digest and the reward file precedence. The one place where byte identity matters, the content hash that names images, is already vendored unmodified. Everything Harbor builds on those pieces is bound to its trial runtime. BaseEnvironment takes trial paths and a session id, Verifier takes a Task plus an environment and uploads, execs and downloads through it, and the Docker code writes Compose override files for docker compose. Gym's sandbox providers, Compose adapter, deadlines, cleanup and failure classification have nothing to plug into there, so importing those modules means adapting them, and installing harbor would add litellm, supabase and typer to the core package. So we keep the Gym implementations and pin behaviour with tests, without taking harbor as a dependency. Today the parity coverage is Gym-side fixtures (the verbatim 0.22.0 build Compose file, the vendored hash, reward, canary and deprecated field cases) plus two importorskip tests that run Harbor's own models when the package happens to be installed. I propose adding, as a follow-up commit on this PR, golden fixtures taken from Harbor 0.22.0 (task.toml cases, template resolution, verifier mode, digest and reward files) with the expected results recorded in the test, and one README table of the intentional differences (the 28800 s default timeout, finite rewards only, the empty reward object, leading blank lines without a canary, the Gym-only [gym] table).

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Status note: this PR is unchanged since f1e36c7, the commit Felipe approved, which already carries the one line from M5 (#3677, now closed) in environment_servers/harbor/.gitignore. The rest of the stack is rebased on it, on top of main dc709bc, with #3675 as the next PR. The reuse assessment from 15 Oct is in the comment above.

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.

Reviewed f1e36c76. The three earlier findings are fixed: cancellation reaches bounded cleanup, host snapshot I/O failures remain retryable, and schema lookup preserves the agent's validator when its environment wrapper has none. All 12 focused tests passed; the full preparation path accepts a valid tau2 row and rejects one missing seed. I have no remaining blocking code finding from this follow-up.

The reuse assessment makes sense. Keeping Gym's execution lifecycle and selectively reusing small Harbor components is reasonable; the proposed fixed-version compatibility fixtures and intentional-differences table remain a nonblocking follow-up.

Please record a fresh model rollout through the current environment-server flow before merging; the existing rollout evidence covers the previous implementation.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d0f4c21

@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 d0f4c216 after the rebase onto main (968e069c5). The only change from the approved f1e36c76 is the .secrets.baseline merge: it adds just the two Harbor entries and leaves every main entry untouched. CI is green apart from the non-blocking harness conformance probes.

One environment server, `environment_servers/harbor`, runs Harbor task folders: its `/run`
owns the whole episode. It checks the row's digest against the taskset mapping, snapshots
the task once per digest, starts the task image through the configured sandbox provider,
hands the harness a `SandboxAccess` through the agent session seed every sandboxed harness
already accepts, posts the task's `responses_create_params`, closes the agent session,
runs `tests/test.sh` in the same sandbox and reads the reward it wrote, then stops the
sandbox. No resources server takes part; harnesses never see a sandbox handle.

Failures are staged episode failures: `seed` (terminal when the task or row is at fault,
retryable when the provider failed), `agent`, `cleanup` and `verification`, with the
harness's observations and any usable response attached. A missing or invalid reward file
is a measured zero with a namespaced `failure_kind`; only a Gym-side failure masks the
sample. Verifier logs land in a fresh folder under the results root per verification.

Carried from the resources-server review: snapshots under a temporary directory with the
digest checked on the copy, sandbox ownership kept until a stop succeeds (retried by the
episode's final cleanup and at shutdown), environment templates resolved at use and never
written to rows or snapshots, episode-based sandbox TTL, root-first transfers with a
default-user fallback, reward download before optional logs with unsafe members skipped,
and verifier roots unlinked before preparation.

The generated run config now holds an agent block (which declares the materialized rows as
its validation dataset, where rollout collection looks for datasets) and a per-taskset
`harbor` environment server block that names that agent.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@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/39638648657

This branch was previously deployed

1 inactive deployment
public — 863e9fc4 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6291
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 QA_verified waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants