Skip to content

feat(harbor): gym eval prepare for Harbor targets, with resumable, rate-limit-safe image records - #5064

Open
adil-a wants to merge 6 commits into
mainfrom
adasif/harbor-eval-prepare
Open

adil-a wants to merge 6 commits into
mainfrom
adasif/harbor-eval-prepare

Conversation

@adil-a

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

Copy link
Copy Markdown
Contributor

Problem

Preparing a Harbor dataset records each base image's and Compose sidecar's configuration from its OCI registry into compose-images.json (about two requests per image). Running SWE-bench Pro through the Harbor path (731 images, 7 Slurm jobs sharing a login node's IP) failed at full scale for three reasons:

  1. The registry client did not retry HTTP 429. Docker Hub's anonymous limit is 100 pulls per hour per IP, so the first rate-limited image failed the whole preparation.
  2. The record was written only after every image resolved, so a preparation that died lost all progress, and seven concurrent jobs each started from zero and raced for the same budget.
  3. There was no command that does only this preparation once ahead of a fan-out; it ran inside every gym eval run. The native path has gym eval prepare --benchmark, whose prepare scripts retry 429 and resume from partial output, and _prepare_datasets skips an existing JSONL.

Change

Registry client retries (nemo_gym/tasks/harbor/registry.py). Requests that fail for the moment (connection errors and timeouts, HTTP 429 and 5xx) are retried with exponential backoff (1 s doubling, capped at 60 s) or the registry's Retry-After (seconds or HTTP date) when it names one, within bounded attempts (8 by default) and a per-request wait budget (900 s by default; a Retry-After past it fails at once). The first retry of an image is logged once at WARNING. The final failure stays an ImageConfigError naming the status and the attempts; 401/403/404 are still final with their old messages. The token endpoint is retried the same way. Public signatures are unchanged (retries now defaults to 7; max_wait_s is new and keyword-only).

Resumable, shared records (nemo_gym/tasks/harbor/image_configs.py, nemo_gym/tasks/harbor/records.py). Each image is merged into compose-images.json as soon as the registry answers for it, with the existing atomic temp-file-and-rename write under the record's lock. A failure after N images leaves N records on disk and the next run resolves only the rest. Each image is resolved under its own sidecar lock (compose-images.json.<sha256(reference)[:16]>.lock), held from reading the record to writing the entry, so preparations running at the same time on one folder never ask the registry for the same image twice: a preparation takes the images nobody else holds first, then comes back to the held ones, waits for each and finds it in the record. N images cost N lookups however many preparations run, and they spread over different images instead of queueing on the same one (measured with a simulated registry: 2, 3 and 7 simultaneous preparations of 30 images each made 30 lookups in all; before the per-image lock they made 57, 83 and 167). The per-image lock file is removed once its entry is recorded. A lone preparation behaves as before. Record contents and file names are unchanged, so the loader and the server read them as before. The new optional resolved_now list reports what a call resolved.

gym eval prepare <target> (nemo_gym/cli/main.py, nemo_gym/tasks/harbor/cli.py; nemo_gym/cli/eval.py untouched). The command takes the targets gym eval run takes (a task folder, a folder of task folders, harbor:<dataset>[@ver]) with --only-tasks/--exclude-tasks, and runs prepare_target alone: fetch, image configuration records, builds, rows and image list, then a summary of what was recorded, built and skipped, and where. No servers, no rollouts. A gym eval run or gym dataset validate on a prepared target finds the records complete and constructs no registry client. --benchmark works as before.

Docs: the Harbor tasks page gains a gym eval prepare section with the prepare-first workflow and a registry rate-limit note; the CLI reference documents the TARGET form; the Harbor environment server README describes the per-image records and locks, the retry and the prepare-once advice (and no longer attributes compose-images.json to gym dataset fetch).

How verified

Unit tests, no network (fake registry server / monkeypatched opener / counting fake clients):

  • tests/unit_tests/test_harbor_image_configs.py: 429 then 200 honouring Retry-After, 5xx then 200 with backoff, permanent 429 bounded with the status and attempts in the error, Retry-After as an HTTP date, a Retry-After past the wait budget, 404 not retried, token endpoint retried, one WARNING per image; exception after k images leaves k records and the next run resolves only the rest (the failed image's lock file stays until then); partial record on disk means only the missing images are fetched; a second preparation takes the free images while the first's lookup is in flight, then waits for it and asks for nothing more (3 images, 3 lookups); 2 and 7 equally fast preparations started together on 12 images with jittered latency make 12 lookups in all with disjoint resolved_now and one consistent record; each image is on disk before the next lookup and is the only one locked while it is asked for; no lock or temporary file remains.
  • tests/unit_tests/test_harbor_records.py: the per-entry lock is per key, answers a non-blocking request at once, serialises a blocking one, and is discarded by its holder.
  • tests/unit_tests/test_harbor_cli_prepare.py (new): gym eval prepare <folder> through the CLI parser records the images and writes the rows; a second invocation constructs no registry client; --only-tasks limits what is recorded; errors are usage errors naming the image; gym eval run after a complete prepare constructs no registry client.
  • Runs: the listed harbor and CLI unit test files, 857 passed (2 pre-existing test_harbor_validation.py failures come from a local env.yaml model block and pass with it absent); environment_servers/harbor/tests -n 4: 302 passed; ruff check, ruff format --check and pre-commit clean on the touched files.

🤖 Generated with Claude Code

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b7dda7e

@copy-pr-bot

copy-pr-bot Bot commented Oct 25, 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.

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 25, 2026 09:16
@svcnvidia-nemo-ci svcnvidia-nemo-ci added 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 labels Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 26, 2026
@adil-a
adil-a force-pushed the adasif/harbor-eval-prepare branch from b7dda7e to 2fe54c6 Compare October 26, 2026 18:40
@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2fe54c6

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

LGTM.

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 26, 2026
@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 75e9889

@ffrujeri
ffrujeri added this pull request to the merge queue Oct 27, 2026
@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/40562196807

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 27, 2026
@adil-a
adil-a added this pull request to the merge queue Oct 27, 2026
@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/40596417156

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 27, 2026
@adil-a
adil-a force-pushed the adasif/harbor-eval-prepare branch from 75e9889 to 50e09f2 Compare October 28, 2026 00:46
@adil-a

adil-a commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 50e09f2

adil-a and others added 6 commits October 29, 2026 09:30
…After

The OCI registry client retried connection failures only. Docker Hub's
anonymous pull limit (100 manifests per hour per IP, shared by every job on
a login node) answers HTTP 429, which failed the whole preparation at the
first rate-limited image. The request path now retries 429 and 5xx as well
as connection errors and timeouts, with exponential backoff (1 s doubling,
capped at 60 s) or the registry's Retry-After (seconds or HTTP date) when
it names one, within bounded attempts (8 by default) and a per-request wait
budget (900 s by default). The first retry of an image is logged once at
WARNING; the final failure stays an ImageConfigError that names the status
and the attempts. The token endpoint is retried the same way. Public
signatures are unchanged (retries now defaults to 7, max_wait_s is new and
keyword-only).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
record_image_configs resolved every missing image before writing
compose-images.json once, so a preparation that died (a rate-limited
registry, a Slurm time limit) lost all progress and concurrent
preparations of one folder each started from zero. Each image is now
merged into the record under its sidecar lock as soon as the registry
answers for it, with the same atomic temp-file-and-rename write; the
file is read again before each lookup so an image another preparation
recorded meanwhile is skipped without a registry request, and under the
lock the first recording of a reference is kept. A failure after N
images leaves N records on disk and the next run resolves only the rest.
Record contents and file names are unchanged; the new optional
resolved_now list reports what a call resolved. The racing-writer test
now merges under the lock as every Gym writer does, instead of
replacing the whole file.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
`gym eval prepare` took only `--benchmark`; the Harbor path's preparation
(fetch, image configuration records, builds, rows) ran inside every
`gym eval run`, so a fan-out of jobs on one dataset each recorded the
images itself and raced for the same registry budget. The command now
takes the targets `gym eval run` takes (a task folder, a folder of task
folders, `harbor:<dataset>[@ver]`) with `--only-tasks`/`--exclude-tasks`,
and runs `prepare_target` alone through the new `prepare_only` entry
point: no servers, no rollouts, and a summary of what was recorded,
materialized and skipped, and where. The record lines now say how many
images were resolved from the registry and how many were reused. A
`gym eval run` or `gym dataset validate` on a prepared target finds the
records complete and constructs no registry client (verified by test).
`--benchmark` works as before; a bare Hydra override in the TARGET slot
is restored as for `gym eval run`.

Docs: the Harbor tasks page gains a `gym eval prepare` section with the
prepare-first workflow and the registry rate-limit note, the CLI
reference documents the TARGET form, and the environment server README
describes the per-image records and the prepare-once advice.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…ares never ask twice

Concurrent preparations of one folder still raced for every image whose
lookup was in flight: each process computed the missing images once and
re-read the record only before its own next lookup, so processes of similar
speed fell into lockstep and all asked the registry for every image (two
preparations of 30 images made 57 lookups, seven made 167). The record stayed
consistent (first write wins under the record lock), but the registry budget
the brief is about was spent several times over.

`record_image_configs` now resolves each image under a per-image sidecar
flock (`compose-images.json.<sha256(reference)[:16]>.lock`, `entry_lock` in
records.py) held from the re-read of the record to the write of the entry. A
preparation first takes the images nobody else holds (non-blocking lock
attempt, in order), then comes back to the ones it found held, waits for
each, re-reads the record and finds it there, so N images cost N lookups
however many preparations run, and they spread over different images instead
of queueing on the same one. The lock file is removed by the holder once the
entry is on disk; one stays behind only for an image no preparation managed
to record. A lone preparation behaves exactly as before (same order, same
log lines); the record lock and the file format are unchanged.

Tests: the entry lock primitive (per key, non-blocking answer, discard); a
second preparation takes the free images while the first's lookup is in
flight, then waits for it and asks for nothing more (3 images, 3 lookups);
2 and 7 equally fast preparations started together on 12 images with
jittered latency make 12 lookups in all with disjoint resolved_now; the
image being asked for is the only one locked and no lock file remains; a
failed image's lock file stays until the next run records it. The previous
interleaving test held one client until the other had finished every image
and so never exercised two in-flight preparers; it is replaced.

Docs (harbor-tasks.mdx, environment_servers/harbor/README.md) now say what
the code does: an image another preparation is fetching is waited for and
read from the record, never asked for twice.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Since #4861, `gym eval run` fingerprints the rollouts path before dispatch
and writes a run summary afterwards, so a bare object() no longer stands in
for the resolved collection in the prepare-then-run test. Give the stub an
output_jsonl_fpath and stub the summary writer and split lookup, which are
the run's own machinery, not what this test covers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Preparing a task records its base images through RegistryClient, and the shared
write_task helper writes FROM ubuntu:24.04. The fake-registry guard lived in
test_harbor_tasks.py and covered only the modules that imported it, so
test_harbor_manifest.py's TestPrepareRecordsIdentity reached Docker Hub and failed
CI on its rate limit (HTTP 429).

The guard now lives in tests/unit_tests/conftest.py and covers every test_harbor_*
module. A test that fakes the registry at the HTTP layer (patch_opener) still gets
the real client, which then talks to that fake. With outbound HTTPS cut off, the
Harbor unit tests go from 12 failures to 0, apart from the real buildah build test,
which is skipped where buildah is not installed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the adasif/harbor-eval-prepare branch from 50e09f2 to ea2ca72 Compare October 29, 2026 16:53
@adil-a

adil-a commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ea2ca72

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

The incremental records and preparation command look useful. Please preserve the new image-lock files during template rendering before merging: concurrent preparations can currently lose their shared lock or fail during cleanup. I also left two small suggestions about the follow-up command and the documented rate-limit window.

Comment on lines +85 to +89
def entry_lock_path(path: Path, key: str) -> Path:
"""The sidecar lock file for one entry of the record at ``path``: ``<file>.<sha256(key)[:16]>.lock``."""
path = Path(path)
digest = hashlib.sha256(key.encode("utf-8")).hexdigest()[:16]
return path.with_name(f"{path.name}.{digest}{RECORD_LOCK_SUFFIX}")

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.

[P2] Preserve per-image locks during template rendering

Please teach parameterized.is_record_file() to preserve these new per-image lock names. Every prepare_target() of a template calls render_template_folder(), whose cleanup currently keeps compose-images.json.lock but deletes compose-images.json.<hash>.lock. A second prepare can therefore remove the first prepare's active lock and acquire a newly created file, causing duplicate registry lookups. I reproduced two lookups for one image while the first was still in flight. If the image writer discards its completed lock after the renderer lists it but before cleanup, the renderer instead raises FileNotFoundError; a controlled reproduction confirms that too. Please add coverage for rendering while an image is being recorded and while its lock is released.

Comment on lines +1021 to +1022
quoted = shlex.quote(args.target)
print(f"Next: gym eval run {quoted} --agent <harness> ... (the records are complete; no registry request)")

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.

[P3] Preserve task selection in the suggested run command

Could the suggested run command retain --only-tasks/--exclude-tasks, and make the reuse claim conditional on using the same preparation settings? After preparing only task A in a dataset containing A and B, this printed command omits the filter. Its preparation then fetches B's image, despite the message promising no registry request. A two-task fake-registry reproduction confirms the extra lookup.

Comment on lines +489 to +490
Recording an image's configuration takes about two registry requests. Docker Hub's anonymous limit is 100 pulls
per hour and per IP address, which a login node's jobs share, so a dataset of hundreds of images runs into

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.

[P3] Correct the Docker Hub quota window

Docker's current documentation gives the anonymous limit as 100 pulls per six hours, per IPv4 address or IPv6 /64 subnet: https://docs.docker.com/docker-hub/usage/. Please correct the hourly figure here and in the matching registry.py comment. That distinction matters when readers estimate when a rate-limited preparation can resume.

@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Nov 2, 2026

This branch was previously deployed

1 inactive deployment
public — ea2ca72b Deployed Oct 29, 2026 by copy-pr-bot[bot] via release / finalize / notify #8315
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 sla:author-overdue Author response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants