Skip to content

fix(hermes): upload a uv build that matches the sandbox architecture - #3676

Closed
adil-a wants to merge 14 commits into
adasif/harbor-m3-oracle-clifrom
adasif/harbor-m4-hermes
Closed

adil-a wants to merge 14 commits into
adasif/harbor-m3-oracle-clifrom
adasif/harbor-m4-hermes

Conversation

@adil-a

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

Copy link
Copy Markdown
Contributor

What does this PR do?

M4 of the Harbor tasks RFC: let Hermes borrow Harbor sandboxes from a host whose CPU architecture differs from the sandbox's.

Rebased onto main 128eab4 (2026-10-04). The review fixes from that date are listed below.

Hermes installs its sandbox runtime by uploading the agent host's uv binary. On an aarch64 login node driving x86_64 OpenSandbox nodes that binary cannot run and every session fails at install. This PR probes uname -m in the sandbox first. When the architectures match it reuses the host binary. Otherwise it fetches the host's uv version for the sandbox target from the uv release archive once into uv_cache_dir (default ~/.cache/nemo_gym/uv) and uploads that.

Review fixes (2026-10-04)

  • 3c299caa2 test(hermes): account for the uv architecture probe in the failed-setup test: main added test_failed_setup_retains_handle_until_cleanup_confirmed with four fake sandbox execs. The architecture probe adds one exec before install, so the sequence now has five.
  • 531e64d6b fix(hermes): refuse a loopback model URL on remote sandboxes: new is_loopback_host and assert_model_url_reachable_from_sandbox in nemo_gym/base_responses_api_agent.py. Hermes calls the check at seed time with the resolved Model Server URL and the sandbox provider name. On a remote provider (OpenSandbox, E2B, Daytona) a loopback URL fails seeding with the fix named: ++use_absolute_ip=true or a reachable model URL. The local provider passes and docker only warns. Before this a run with the default URL scored 0 without being masked.

Validation

  • pytest responses_api_agents/hermes_agent/tests (228 tests, new in this PR: same-arch reuse, cross-arch download once, unknown arch, missing uv, version parsing, archive extraction, loopback URL refused on a remote provider, loopback allowed with a warning on local Docker).
  • pytest tests/unit_tests/test_base_responses_api_agent.py (loopback detection for IPv4, IPv6 and localhost, unparseable hosts, the per-provider raise, warn or pass rule).
  • pre-commit run --files <changed files> clean.

Rollouts

Hermes on harbor:hello-world from an aarch64 host to x86_64 OpenSandbox nodes: runtime installed, 3 tool calls, reward 1.0 (details in #3677).

Compatibility and benchmark impact

Same-architecture hosts behave exactly as before (host binary reused, one extra uname -m exec per session). New optional config uv_cache_dir. A Hermes session on a remote sandbox provider with a loopback Model Server URL now fails at seed instead of scoring 0. gym eval run on a Harbor target already sets use_absolute_ip for Hermes (#3675). Other launchers pass ++use_absolute_ip=true or a reachable model URL.

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 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-m4-hermes branch from 360f248 to d87fd1b Compare September 24, 2026 08:52
@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch from caa5866 to 0ca054d Compare September 24, 2026 08:52
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch from d87fd1b to ec2cb9b Compare September 24, 2026 09:00
@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch 2 times, most recently from 1a7d02a to cc5fd6c Compare September 24, 2026 09:15
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch 2 times, most recently from c4e41c6 to f444bcc Compare September 28, 2026 19:35
@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch from cc5fd6c to c199385 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-m4-hermes branch from f444bcc to 7c8a8d3 Compare September 28, 2026 20:10
@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch 2 times, most recently from 4aade10 to ac39be0 Compare September 30, 2026 03:48
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch from 7c8a8d3 to b025138 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-m3-oracle-cli branch from ac39be0 to 8646d47 Compare October 4, 2026 23:19
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch from b025138 to 531e64d Compare October 4, 2026 23:19

# Sandbox providers whose processes share the host network namespace, so a loopback model URL still resolves
# to the host. Docker only does so when the daemon runs on the host and the container uses host networking.
_HOST_NETWORK_SANDBOX_PROVIDERS = frozenset({"local"})

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.

This guard breaks existing Apptainer and Enroot users. A Slurm user running Hermes (or miniSWE) with sandbox_provider: apptainer and the default loopback model URL worked before this PR and now fails every seed with "loopback address ... cannot reach". Neither provider creates a network namespace: Apptainer starts the instance without --net (nemo_gym/sandbox/providers/apptainer/provider.py:446-462) and Enroot only mounts and sets the environment (providers/enroot/provider.py:478-504), so 127.0.0.1 inside them is the host. The guard also misses 0.0.0.0, which inside a remote sandbox is the sandbox itself. Could both be handled, and the change noted under compatibility?

Suggested fix:

_HOST_NETWORK_SANDBOX_PROVIDERS = frozenset({"local", "apptainer", "enroot"})
...
ip = ipaddress.ip_address(host)
return ip.is_loopback or ip.is_unspecified

return parts[1]


def _download_uv(version: str, target: str, destination: Path) -> None:

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.

The uv download is not verified. The release archive is fetched and later executed inside the sandbox without checking the .sha256 file uv publishes next to each archive, and air-gapped compute nodes have no mirror setting. Also, the architecture check (around line 617) compares only uname -m, so on an x86_64 macOS host the Mach-O binary is reused for a Linux sandbox, and an empty probe silently falls back to the host binary. Could the download verify the checksum, accept a base-URL override, and reuse the host binary only when sys.platform == "linux" and the probe succeeded? (_host_uv_version also needs errors="replace" per CLAUDE.md.)

workdir = body.sandbox_access.workdir

provider_config = resolve_provider_config(provider_ref, get_global_config_dict())
# The runner inside the sandbox calls the Model Server itself, so a loopback URL (the default

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.

Question for the Harbor path this stack opens: Hermes bounds its run by sandbox_runner_timeout_seconds (21600 s by default) and never reads the row's agent_timeout_sec, so a task with [agent].timeout_sec = 900 can run far longer than in Harbor, or until the sandbox's lifetime ends mid-episode. Terminus 2 and miniSWE already use the row's value. Could Hermes take the smaller of the two, or should the README note that this waits for RFC M19?

@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, nonblocking follow-ups on concurrent downloads and setup documentation.

version = await asyncio.to_thread(_host_uv_version, host_uv)
cached = Path(self.config.uv_cache_dir).expanduser() / version / target / "uv"
if not cached.is_file():
await asyncio.to_thread(_download_uv, version, target, cached)

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.

Nonblocking: share the initial uv download between concurrent sessions. Could we serialize cache population per version/target and recheck the file after acquiring the lock? With an empty cache, each session can pass cached.is_file() before the first download completes and start its own download. In a focused reproduction with the downloader stubbed, eight overlapping _uv_for_sandbox calls invoked it eight times. os.replace protects the completed file but does not share the download. The existing test checks sequential reuse; a concurrent test would cover this startup case.

sandbox_install_timeout_seconds: float = Field(default=900, gt=0, allow_inf_nan=False)
sandbox_runner_timeout_seconds: float = Field(default=21600, gt=0, allow_inf_nan=False)
# Where uv builds for sandbox architectures other than the host's are cached.
uv_cache_dir: str = "~/.cache/nemo_gym/uv"

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.

Nonblocking: update the Hermes setup documentation for this capability. Could we update the README's sandbox-mode requirements and configuration table alongside this change? The current requirements still require matching host/sandbox CPU architectures, and the table does not list uv_cache_dir. Please document the supported GNU/Linux targets, the cache option, and the agent host's need to reach GitHub releases when the matching binary is not cached.

@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch from 8646d47 to f2f7002 Compare October 9, 2026 20:07
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch from 531e64d to 6436b17 Compare October 9, 2026 20:07
adil-a and others added 3 commits October 9, 2026 13:12
Adds `resources_servers/harbor` (M2 of the Harbor tasks RFC), serving the
tasksets the loader materializes:

- `/seed_session` checks the row digest against the taskset mapping and the
  folder on disk, starts the task image as a sandbox sized from `task.toml`,
  creates the working directory, and returns a `SandboxAccess` for the agent.
- `/verify` uploads `tests/` into the same sandbox (Harbor's shared verifier
  mode), runs `bash /tests/test.sh` under `[verifier]` timeout and env, and
  reads `/logs/verifier/reward.json` or `reward.txt` with Harbor's key rule.
- `/close_session` stops the sandbox; shutdown stops what is left.

Reward rule: a run of `test.sh` is a measurement, so a missing or invalid
reward scores 0 with a `failure_kind`; only Gym-side failures mask the sample.
Sandbox creation failures surface as 503 so the collector can retry.

The generated run config now inherits the shipped `harbor_resources_server`
block instead of spelling out server settings.

Signed-off-by: Adil Asif <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
The Episode Architecture stack removed `ResourcesVerifyResponse` and lets
each resources server declare its own verify response. `HarborVerifyResponse`
types what the Harbor verifier adds to the base fields: the parsed
`reward.json`, the `test.sh` exit code and the downloaded logs folder.
Without the declaration Pydantic would drop them silently.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…e event loop

- shared-mode prepare runs as root so non-root images verify
- /verify holds the session lock and replays its stored outcome on a retry
- folder digest and archive work run in a thread, parsed tasks cached per digest
- invalid reward.json falls back to reward.txt, reward files decoded with errors="replace"

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
adil-a and others added 11 commits October 9, 2026 13:12
main now requires every shipped server class to set ray_enabled.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
main now requires every resources server to describe its dataset rows.
A Harbor row's only task-owned field is the folder digest the server
checks against its taskset mapping; the wire key `_ng_digest` is reached
by alias because pydantic forbids leading-underscore field names.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
The row's verifier_logs_dir was the configured artifacts_dir joined with the session id,
relative when the config was relative. The server process runs from its own folder, so
the recorded path did not resolve from the directory the run was launched in.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…bor tasks

Adds `responses_api_agents/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` resources server
seeded, locates the task folder through that server's taskset mapping in the
run config, checks the digest, uploads `solution/` and runs `solve.sh` in the
task's working directory as the task's agent user. Verification then scores
the result like any rollout. Tasks without `solution/solve.sh` return a
response tagged `oracle=unvalidated` and are never failed.

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

Signed-off-by: Adil Asif <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Rollout collection now stores an environment server's result as
returned: the row is the verify response itself with the collector's
`_ng_task_id` stamp, and an episode that failed before verification is
a failures-sidecar row. `gym dataset validate` reads both.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
In-sandbox harnesses call the Gym model server from the container, where
127.0.0.1 is the container itself. The generated run config now sets
use_absolute_ip for agents that run inside the sandbox unless the caller
set it, so the documented command works on remote providers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
main now requires every shipped server class to set ray_enabled.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…ugh the base hooks)

main's session contract (#3784) makes the base agent own seed and close bookkeeping; an agent implements only
_seed_agent_session_state and _close_agent_session_state. The oracle agent keeps its behavior (sandbox connect at
seed, disconnect at close, 404 for an unseeded /v1/responses) but no longer overrides the routes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Hermes installs its sandbox runtime by uploading the agent host's `uv`
binary. When the host and the sandbox differ in CPU architecture (an
aarch64 login node driving x86_64 OpenSandbox nodes) the binary cannot run
and every session fails at install. Probe `uname -m` in the sandbox first;
reuse the host binary when the architectures match, otherwise fetch the
host's uv version for the sandbox target from the uv release archive once
into `uv_cache_dir` and upload that.

Part of the Harbor tasks PoC (M4): Hermes borrowing Harbor sandboxes.

Signed-off-by: Adil Asif <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…up test

main added test_failed_setup_retains_handle_until_cleanup_confirmed with
four fake sandbox execs. M4 probes the sandbox architecture with one
more exec before installing, so the sequence needs five.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Inside a container on OpenSandbox or E2B, 127.0.0.1 is the container
itself, so a Hermes run with the default model URL scores 0 without being
masked. Seeding now fails with the fix named (++use_absolute_ip=true or
a reachable model URL). Local Docker only warns.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the adasif/harbor-m3-oracle-cli branch from f2f7002 to 762ed7b Compare October 9, 2026 20:19
@adil-a
adil-a force-pushed the adasif/harbor-m4-hermes branch from 6436b17 to efc6f7c Compare October 9, 2026 20:19
@yuhezhang-ai
yuhezhang-ai force-pushed the adasif/harbor-m3-oracle-cli branch 3 times, most recently from 5c0a1dd to e567c71 Compare October 13, 2026 16:47
@adil-a

adil-a commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Superseded. The uv architecture fix landed on main through #4270 (shared uv_bootstrap), and the loopback model URL guard now comes to main on its own as #4582. The stack carries that guard at the base of M11 (#3745) only until #4582 merges, because the miniSWE sandboxed agent imports it. M5 (#3677) is rebased directly onto M3.

@adil-a adil-a closed this Oct 14, 2026
@adil-a
adil-a removed this pull request from stack #3808 October 14, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants