Repository navigation
feat(harbor): gym eval prepare for Harbor targets, with resumable, rate-limit-safe image records - #5064
feat(harbor): gym eval prepare for Harbor targets, with resumable, rate-limit-safe image records#5064adil-a wants to merge 6 commits into
gym eval prepare for Harbor targets, with resumable, rate-limit-safe image records#5064Conversation
|
/ok to test b7dda7e |
b7dda7e to
2fe54c6
Compare
|
/ok to test 2fe54c6 |
|
/ok to test 75e9889 |
2fe54c6 to
75e9889
Compare
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40562196807 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40567102146 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40596417156 |
75e9889 to
50e09f2
Compare
|
/ok to test 50e09f2 |
…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]>
50e09f2 to
ea2ca72
Compare
|
/ok to test ea2ca72 |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
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.
| 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}") |
There was a problem hiding this comment.
[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.
| quoted = shlex.quote(args.target) | ||
| print(f"Next: gym eval run {quoted} --agent <harness> ... (the records are complete; no registry request)") |
There was a problem hiding this comment.
[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.
| 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 |
There was a problem hiding this comment.
[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.
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:gym eval run. The native path hasgym eval prepare --benchmark, whose prepare scripts retry 429 and resume from partial output, and_prepare_datasetsskips 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'sRetry-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; aRetry-Afterpast it fails at once). The first retry of an image is logged once at WARNING. The final failure stays anImageConfigErrornaming 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 (retriesnow defaults to 7;max_wait_sis new and keyword-only).Resumable, shared records (
nemo_gym/tasks/harbor/image_configs.py,nemo_gym/tasks/harbor/records.py). Each image is merged intocompose-images.jsonas 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 optionalresolved_nowlist reports what a call resolved.gym eval prepare <target>(nemo_gym/cli/main.py,nemo_gym/tasks/harbor/cli.py;nemo_gym/cli/eval.pyuntouched). The command takes the targetsgym eval runtakes (a task folder, a folder of task folders,harbor:<dataset>[@ver]) with--only-tasks/--exclude-tasks, and runsprepare_targetalone: 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. Agym eval runorgym dataset validateon a prepared target finds the records complete and constructs no registry client.--benchmarkworks as before.Docs: the Harbor tasks page gains a
gym eval preparesection 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 attributescompose-images.jsontogym 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 honouringRetry-After, 5xx then 200 with backoff, permanent 429 bounded with the status and attempts in the error,Retry-Afteras an HTTP date, aRetry-Afterpast 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 disjointresolved_nowand 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-taskslimits what is recorded; errors are usage errors naming the image;gym eval runafter a complete prepare constructs no registry client.test_harbor_validation.pyfailures come from a localenv.yamlmodel block and pass with it absent);environment_servers/harbor/tests -n 4: 302 passed;ruff check,ruff format --checkandpre-commitclean on the touched files.🤖 Generated with Claude Code