Skip to content

feat(harbor): environment server and loader generalization (M27) - #4663

Merged
adil-a merged 1 commit into
adasif/harbor-m24-compose-buildsfrom
adasif/harbor-m27-generalization
Oct 26, 2026
Merged

adil-a merged 1 commit into
adasif/harbor-m24-compose-buildsfrom
adasif/harbor-m27-generalization

Conversation

@adil-a

@adil-a adil-a commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Generalizes the harbor environment server and the loader beyond the two
Terminal Bench datasets, per the M27 row of the gym-harbor-tasks RFC.

Shipped:

  • Operator secrets on the server config reach the test.sh process only:
    they fill ${NAME} templates in [verifier].env and are exported into
    that process; sandbox creation and the agent turn never see them.
  • ATIF v1.7 trajectory.json written to /logs/agent before every verify
    (shared and separate mode), exported from the Gym transcript by the new
    nemo_gym.atif_export.transcript_to_atif; a failed export masks the
    turn (harbor:trajectory_export_failed); Terminus user turns become the
    previous step's observation (exporter extension).
  • In-server image pull retries (image_pull_retries, jittered backoff,
    per-server gate) before a retryable seed failure.
  • Recursive dataset discovery: task folders may sit in subfolders;
    dataset.toml and recorded image configs are read from the dataset root;
    the taskset mapping records nested tasks under paths, which the server
    and the oracle agent resolve.
  • gym dataset validate reports verify time (verify_s) and the network
    the verifier ran under (network) per task; results carry
    verifier_network.
  • SandboxAccess.user filled from the task's [agent].user.
  • A slow agent-session close that fails only by timeout no longer
    discards the finished turn; it is verified with observations unset.
  • Per-task episode deadline enforced by default (enforce_task_timeouts,
    harness_setup_allowance_s); the sandbox lifetime follows the task
    budget; overruns fail with harbor:task_deadline.
  • EpisodeFailure.step, forwarded by the collector as _ng_failure_step.
  • [gym.tasks."<id>"] gains verifier overrides and artifacts
    additions, applied by the loader like the environment overrides.
  • separate_verifier_for_artifacts forces separate mode for tasks that
    declare artifacts.
  • The task's [agent].timeout_sec travels in the agent-session seed as
    agent_timeout_sec (the row metadata stays until harnesses read it).

Already on the branch and left as is: taskset mapping with per-task
digests, strict rejection of Windows and TPU tasks, tool grants as the
tool_accesses list, the reward.txt fallback, mask_sample on Gym-side
failures and the reward.json rule.

Review fixes (Devil's Advocate on this commit): the ATIF live profile
exports model-caused shapes as partial trajectories instead of masking
them (a reasoning item no answer follows becomes an agent step with an
empty message and extra.nemo_gym.incomplete = max_output_tokens; several
reasoning segments join with newlines; empty or encrypted reasoning and
non-object tool arguments export with a note under extra.nemo_gym), and
still raises for what ATIF cannot represent; test.sh receives only the
[verifier].env the task resolves, never the whole secrets block; the
per-task deadline starts when the sandbox is ready, so image pull
retries are not charged against it (_post_seed_budget_s; the sandbox
TTL keeps the full budget); Compose groups and separate verifier
sandboxes get the same in-server pull retries (_start_with_pull_retries);
prepare records compose-images.json at the dataset root for nested
tasks; and duplicate task IDs are rejected by the folder walk itself,
before base-image recording and Dockerfile builds; the pull-failure check
walks exception groups (a Compose group whose cleanup failed too) and
the separate verifier's retry path has committed tests.

🤖 Generated with Claude Code

@adil-a

adil-a commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8426282

@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 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 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f0cb73a

@adil-a
adil-a force-pushed the adasif/harbor-m27-generalization branch from f0cb73a to dba7440 Compare October 16, 2026 16:53
@adil-a
adil-a changed the base branch from adasif/harbor-m20-dockerfile-builds to adasif/harbor-m24-compose-builds October 16, 2026 16:53
@adil-a

adil-a commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test dba7440

@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 dba74403 against the immediate stack parent #4689 (b8c94f17). The ownership split makes sense: Gym owns setup, grading and cleanup, and the agent borrows the sandbox. The inline comments cover five concrete issues affecting grading, task discovery or credential handling.

Representative end-to-end validation can proceed in parallel with these fixes; a P2 here is not a blanket reason to stop validation. Runs that exercise an affected path need its issue resolved before their results support an acceptance claim. Relevant tests and focused reproductions were run, but this review did not include a real-model, live-container rollout.

Nonblocking suggestions:

  • nemo_gym/tasks/harbor/task.py:383-397: Please pass the dataset root through the two build-required error helpers. For ds/group/task, they still name ds/group/built-images.json, although the new root-aware loader reads ds/built-images.json.
  • environment_servers/harbor/tests/test_app.py::test_seed_time_is_not_charged_against_the_task_deadline: Please avoid a 0.2-second real deadline around the full post-seed path, including filesystem work. The test failed under load and passed on focused idle reruns. A controlled clock or narrower fake verification step would preserve the invariant without depending on runner load.
  • nemo_gym/rollout_collection.py::_episode_record: Please preserve failure.failure_kind alongside the new step. Harbor now emits harbor:task_deadline, but this conversion drops the kind before the failures sidecar and metrics consume it. Add an assertion through the response-to-record path.
  • Secret-template tests in environment_servers/harbor/tests/test_app.py: Please cover a same-named value present in both os.environ and configured secrets, asserting the configured secret wins. The implementation is correct today, but reversing this precedence survived the focused mutation check.

Comment thread environment_servers/harbor/app.py Resolved
Comment thread nemo_gym/atif_export.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread nemo_gym/tasks/harbor/task.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
@adil-a

adil-a commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test dda3d6d

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 208b086

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 10c3ff7

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c4cc0a9

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e25da83

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4a567f0

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 33f3c35

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6010e95

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c912a37

@adil-a

adil-a commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 041848a

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0fea08e

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

HOLD — two BLOCKER grading defects, one RISK in override validation, and one NOTE about the generated image list.

Reviewed all 33 changed files and traced the affected sandbox, transfer, loader, and collector contracts. Current source addresses the earlier refusal-export, reserved-trajectory cleanup, collect-hook budget, and secret-map redaction failures; newly created fetch staging directories are hidden.

Validation was static source and regression-test inspection only. I could not execute tests or perform a live-model/container rollout. The inline findings include proposed acceptance checks; suggested code must be verified before adoption.

Note: formal approval is not available for this request, so this review is posted as a comment only.


Inline comments (escaped v1):

  • environment_servers/harbor/sandboxes.py line 432: BLOCKER — Restore the overlay workdir when running the forced-separate verifier

    Failure / blast radius: For a shared task forced into separate mode, use FROM ubuntu:24.04\nWORKDIR /app\nRUN true, declare artifacts = ["/app/result.txt"], and have the package's test check relative result.txt. Creation correctly leaves the workdir unset so the overlay can create it, but applying the overlay never updates the sandbox spec. The separate verifier exec also supplies no cwd. Consequently, AsyncSandbox runs the test in the base image's directory (/ here), not /app, silently scoring a correct artifact as missing.

    Correction: Keep this creation-time None; setting it to /app would reintroduce the root-owned WORKDIR bug. In _run_separate_verifier, add this argument to the final verifier.exec:

    cwd=task.workdir if _verifier_gets_overlay(task, True) else None,

    The invariant is that overlay creation remains deferred, while grading uses the task's resolved runtime workdir. Declared separate verifiers in their own images must continue using their own spec/image workdir, not the agent's.

    Acceptance (proposed, not run): Extend the forced-overlay regression through verification: assert creation receives workdir=None, a non-root overlay RUN still succeeds in its owned directory, and test -f result.txt grades the restored /app/result.txt as reward 1 without masking. Retain the non-overlay /home/node/app spec assertion and verify that an explicit verifier image with workdir /grade still grades in /grade.

  • environment_servers/harbor/verifier.py line 893: BLOCKER — Make the generated sandbox trajectory readable by the verifier user

    Failure / blast radius: With server umask 077 and a non-root [verifier].user, write_bytes creates the new trajectory as 0600. upload_path preserves that mode and extracts as root. Thus /logs/agent/trajectory.json is root-owned 0600, and a legitimate non-root grader cannot read the transcript this PR promises it. A test that catches the read failure and writes reward 0 silently misgrades the episode. This affects both verifier modes; current filesystem tests run their shell without enforcing the requested user.

    Correction: Preserve the host copy's umask and the package tests' original permissions, but explicitly make this generated sandbox file readable. After await upload_path(sandbox, host, target), a narrowly scoped suggested addition is:

    readable = await exec_as_root(
        sandbox, f"chmod a+r -- {target}", timeout_s=60
    )
    if readable.return_code != 0:
        raise RuntimeError(
            f"Could not make {target} readable: {readable.stderr or readable.stdout}"
        )

    target is the fixed reserved path here. Do not widen the entire tests/log tree. Keep the existing unlink-before-upload ordering for planted links and directories.

    Acceptance (proposed, not run): Under umask 077, grade as a non-root user with a trusted test that reads and parses the trajectory; expect valid ATIF and reward 1, unmasked, in shared and separate modes. Assert the host copy remains 0600 while the sandbox copy is readable by that user. Retain the package-permission assertions, and retain the planted-entry cases' successful grading and preservation of other agent logs.

  • nemo_gym/tasks/harbor/dataset_config.py line 152: RISK — Validate verifier env overrides before calling dict()

    Failure / blast radius: A dataset containing [gym.tasks."bad".verifier]\nenv = 1 passes the outer dict[str, Any] override model, then raises TypeError at dict(value). The base-image scan catches ValueError, not TypeError, so one malformed override aborts preparation of every otherwise valid task instead of producing the normal named, per-task load error. The existing environment override helper already validates this contract before merging.

    Correction: Insert this guard before constructing merged in _override_verifier:

    if "env" in override:
        env = override["env"]
        if not isinstance(env, dict) or not all(isinstance(v, str) for v in env.values()):
            raise ValueError(
                f'[gym.tasks."{task_id}".verifier].env must be a table of strings'
            )

    This keeps invalid dataset data in the loader's handled ValueError path while retaining key-wise merging for valid env tables.

    Acceptance (proposed, not run): Prepare a dataset with good and bad tasks and the override above. Expect only good in the prepared tasks, bad in skipped with verifier].env must be a table of strings, and no uncaught exception. Direct load_task(bad) should raise HarborTaskError. Retain the existing merge regression: MODE becomes strict, KEEP stays 1, and nested verifier-environment env tables retain both A and B.

  • nemo_gym/tasks/harbor/cli.py line 216: NOTE — Use the dataset root for the generated pre-pull image list too

    The record is now correctly written at dataset_root, but the later image-list calculation still reads tasks[0].path.parent. If the first selected task is nested, it reads the group directory rather than the root record. run_images then emits a sidecar's mutable tag instead of the recorded digest actually used at runtime. Operators pre-pulling from images.json cache the wrong reference.

    Correction: Replace that calculation with:

    distinct = run_images(tasks, read_image_configs(dataset_root))

    This preserves existing flat-dataset and single-task behavior because dataset_root already resolves to their record directory.

    Acceptance (proposed, not run): Extend the nested Compose preparation test so the fake registry records redis:7-alpine as a distinct redis@sha256:<digest> reference. Assert both prepared.images and images.json contain that digest, not the tag. Repeat with a flat task and a single-task target; both should retain the same pinned reference.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@adil-a

adil-a commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e7ef699

@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 the thorough follow-through on yuhezhang-ai's findings; they look fixed at e7ef699, with tests. The latest push looks like a rebase onto the new M24 head, so the four findings from the codex review on 0fea08e still seem to apply: the forced-separate overlay cwd, trajectory readability under a strict umask, the unvalidated verifier.env override, and the images.json record folder. I left questions inline; could you take a look or say why they're fine? Required CI is green; only the non-blocking kilocode conformance probe fails.

nemo_gym/tasks/harbor/cli.py (around line 244): Could images.json list a sidecar's mutable tag instead of its pinned digest when the first selected task is nested (ds/group/task)? It looks like the images are now recorded at dataset_root, but this still reads read_image_configs(tasks[0].path.parent). Would read_image_configs(dataset_root) be the intended source, with the nested Compose prepare test asserting the digest in images.json?

Comment thread environment_servers/harbor/verifier.py Resolved
Comment thread environment_servers/harbor/verifier.py Resolved
Comment thread nemo_gym/tasks/harbor/dataset_config.py Resolved
@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6fc7bff

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bd43b5f

Generalizes the harbor environment server and the loader beyond the two
Terminal Bench datasets, per the M27 row of the gym-harbor-tasks RFC.

Shipped:
- Operator `secrets` on the server config reach the test.sh process only:
  they fill `${NAME}` templates in `[verifier].env` and are exported into
  that process; sandbox creation and the agent turn never see them.
- ATIF v1.7 `trajectory.json` written to /logs/agent before every verify
  (shared and separate mode), exported from the Gym transcript by the new
  `nemo_gym.atif_export.transcript_to_atif`; a failed export masks the
  turn (`harbor:trajectory_export_failed`); Terminus user turns become the
  previous step's observation (exporter extension).
- In-server image pull retries (`image_pull_retries`, jittered backoff,
  per-server gate) before a retryable seed failure.
- Recursive dataset discovery: task folders may sit in subfolders;
  dataset.toml and recorded image configs are read from the dataset root;
  the taskset mapping records nested tasks under `paths`, which the server
  and the oracle agent resolve.
- `gym dataset validate` reports verify time (`verify_s`) and the network
  the verifier ran under (`network`) per task; results carry
  `verifier_network`.
- `SandboxAccess.user` filled from the task's `[agent].user`.
- A slow agent-session close that fails only by timeout no longer
  discards the finished turn; it is verified with observations unset.
- Per-task episode deadline enforced by default (`enforce_task_timeouts`,
  `harness_setup_allowance_s`); the sandbox lifetime follows the task
  budget; overruns fail with `harbor:task_deadline`.
- `EpisodeFailure.step`, forwarded by the collector as `_ng_failure_step`.
- `[gym.tasks."<id>"]` gains `verifier` overrides and `artifacts`
  additions, applied by the loader like the `environment` overrides.
- `separate_verifier_for_artifacts` forces separate mode for tasks that
  declare artifacts.
- The task's `[agent].timeout_sec` travels in the agent-session seed as
  `agent_timeout_sec` (the row metadata stays until harnesses read it).

Already on the branch and left as is: taskset mapping with per-task
digests, strict rejection of Windows and TPU tasks, tool grants as the
`tool_accesses` list, the reward.txt fallback, mask_sample on Gym-side
failures and the reward.json rule.

Review fixes (Devil's Advocate on this commit): the ATIF live profile
exports model-caused shapes as partial trajectories instead of masking
them (a reasoning item no answer follows becomes an agent step with an
empty message and extra.nemo_gym.incomplete = max_output_tokens; several
reasoning segments join with newlines; empty or encrypted reasoning and
non-object tool arguments export with a note under extra.nemo_gym), and
still raises for what ATIF cannot represent; test.sh receives only the
`[verifier].env` the task resolves, never the whole secrets block; the
per-task deadline starts when the sandbox is ready, so image pull
retries are not charged against it (`_post_seed_budget_s`; the sandbox
TTL keeps the full budget); Compose groups and separate verifier
sandboxes get the same in-server pull retries (`_start_with_pull_retries`);
prepare records compose-images.json at the dataset root for nested
tasks; and duplicate task IDs are rejected by the folder walk itself,
before base-image recording and Dockerfile builds; the pull-failure check
walks exception groups (a Compose group whose cleanup failed too) and
the separate verifier's retry path has committed tests.

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

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 78e630e

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

Approving #4663 for the combined Harbor stack, including the working-directory fix in #4819.

Rechecked 78e630e1 against its current M24 parent (9fd2b1ae). The earlier runtime fixes remain intact. The transcript-permission and malformed verifier-env fixes check out. The original forced-separate working-directory case is fixed here; I also verified the additional directory-creation fix in #4819 at 7310fc25, so I count that as addressed for the combined stack.

One nonblocking follow-up remains: when the first selected task is nested, images.json still lists the sidecar's mutable tag instead of its recorded digest. I reproduced this here and at #4819, with flat-dataset and single-task controls passing. Please use read_image_configs(dataset_root) in the image-list calculation in nemo_gym/tasks/harbor/cli.py and cover the emitted list with a registry fixture that returns a distinct pinned digest.

Validation: 94 focused regression tests passed on this PR, with 12 optional checks skipped; six downstream checks passed. Separate preparation probes confirmed that malformed overrides skip only the bad task and that the image-list issue remains. Core/server CI, lint, docs and DCO pass; the nonblocking Kilocode conformance failure also occurs on the parent. This recheck did not include a live-model/container rollout.

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

This branch was previously deployed

1 inactive deployment
public — 78e630e1 Deployed Oct 25, 2026 by copy-pr-bot[bot] via release / finalize / notify #7166
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 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.

5 participants