Repository navigation
Description
Problem Statement
On a sandbox base-image cache miss or unusable resolution hint, NemoClaw scans remote release tags to select the newest tag reachable from the current checkout.
gitRemoteReachableVersionTag() currently:
- runs git ls-remote --tags origin v*;
- normalizes and peels every release tag;
- launches git merge-base --is-ancestor once for every normalized tag;
- sorts all reachable tags;
- returns the newest one.
At origin/main commit 36e646d, the NVIDIA/NemoClaw remote exposes 163 matching ref lines representing 91 unique release tags, 72 of them annotated. Therefore each fallback resolution launches 91 reachability subprocesses even when the newest semantic-version candidate is reachable.
Ten direct calls to getNearestVersionedBaseImageTags() returned v0.0.88 in 4.104-4.659 seconds, with a 4.292-second median. A standalone git ls-remote --tags origin v* took 0.489 seconds in the same environment. The eager reachability fan-out dominates the remaining path.
This behavior was introduced by #6624. It is not covered by the warm-resolution cache work in #4680/#6254: that work avoids resolution when a valid hint can be reused, while this issue concerns the required fallback scan after a miss or invalid hint. Open PR #6884 touches source revision provenance in the same module but does not alter this scan.
Desired Behavior
Preserve the exact current release-selection result while stopping reachability checks as soon as the newest semantically ordered reachable tag is found.
The implementation should:
- parse the complete ls-remote result before selecting a candidate;
- preserve peeled commits for annotated tags;
- sort candidates with the existing semantic-version comparator;
- run merge-base --is-ancestor newest-first;
- return immediately on the first reachable candidate;
- retain the existing nearest-local-tag fallback when the remote lookup fails or no remote tag is reachable.
For the current upstream tag set, selecting reachable v0.0.88 should require one reachability probe rather than 91.
Acceptance criteria:
- The selected tag is identical to the current exhaustive algorithm for stable releases, prereleases, annotated tags, lightweight tags, unreachable newer tags, and comparator-equivalent textual tags.
- A reachable newest candidate causes exactly one reachability probe.
- If the newest candidate is unreachable and the next candidate is reachable, exactly two probes occur and the second candidate is selected.
- Annotated tags are tested using their peeled commit, not their tag-object SHA.
- Stable releases continue to outrank prereleases for the same core version regardless of tag creation or remote-output order.
- No reachable remote tag preserves the current local git describe --tags --abbrev=0 --match v* fallback.
- Remote failure and timeout behavior remain fail-safe.
- A deterministic test constrains probe count; wall-clock timing is supplementary evidence, not a flaky CI assertion.
- Before/after measurement records tag count, reachability-probe count, selected tag, and elapsed time.
Constraints and Non-goals
- Do not change release tag normalization or semantic-version precedence.
- Do not change the warm resolution-hint contract from perf(onboard): cache and prefetch sandbox base image resolution #4680/perf(cli): reuse validated sandbox base images #6254.
- Do not change published image trust, digest pinning, or override provenance from fix(images): require trusted base image overrides #6884.
- Do not assume git ls-remote is returned in semantic-version order.
- Do not fetch missing tag objects or mutate repository refs.
- Do not add dependencies merely to avoid a small ordered loop.
Implementation Idea
After constructing the existing map from tag to peeled commit, sort its entries with compareVersionTagsDesc. Iterate that sorted array and run:
git merge-base --is-ancestor <peeled-commit> HEAD
Return the first tag whose command exits 0; return null if none do.
This is semantically equivalent to the current eager filter, sort, and first-element implementation but short-circuits after the winning candidate. Keep full response parsing before iteration so an annotated tag's peeled record has replaced its tag-object SHA.
Extend source-identity.test.ts with deterministic command instrumentation for one-probe success, two-probe fallback, complete exhaustion, annotated tags, and stable/prerelease ordering.
Category
Feature
Checklist
- I searched existing issues and this is not a duplicate
- I described the problem and desired behavior
Activity
wscurran commentedon Jul 20, 2026
✨ Thanks for the detailed performance analysis. This is a clear optimization opportunity for the base-image fallback path.
Related open PRs:
Related open issues:
dfernandez365-rgb commentedon Jul 20, 2026
Measurement correction from a fresh count on current
main(70d7d287f03f82355eafccfc8084de3741069281):git ls-remote --tags origin 'v*'returns 163 ref lines.backup/v0.0.49-original-20260522032905is rejected by the existingnormalizeVersionTag()contract.merge-base --is-ancestorprobes, not 91.ls-remote, that is 91 Git subprocesses total.The issue body's “91 reachability subprocesses/probes” wording is one too high for the current live tag set. The acceptance target is unchanged: reachable
v0.0.88should require one reachability probe after full remote-response parsing. I am recording the distinction between raw names, normalized candidates, reachability probes, and total Git subprocesses so the benchmark remains reproducible rather than flattering.perf(base-image): short-circuit reachable tag scan
perf(base-image): short-circuit reachable tag scan
dfernandez365-rgb commentedon Jul 20, 2026
Implementation candidate:
0e1a0e59b1bbc7fcfbd9c2a906263d81aca2cbedThe candidate is a GitHub-verified commit based directly on current
main70d7d287f03f82355eafccfc8084de3741069281: one commit ahead, zero behind, and limited to:src/lib/sandbox-base-image/source-identity.tssrc/lib/sandbox-base-image/source-identity.test.tsBehavior
The implementation fully parses and peels the remote tag response, stable-sorts normalized candidates with the existing comparator, then probes reachability newest-first and returns immediately at the first reachable commit. Remote failure, complete exhaustion, local
git describefallback, annotated-tag peeling, stable/prerelease precedence, and comparator-equivalent insertion order remain covered.Deterministic verification on the signed commit
npm run build:cli: passednpm run check:diff: passed after the clean checkout generated its requireddistartifacts viabuild:cligit diff origin/main...HEAD --check: passedThe first immutable draft commit used one commit-body line over the repository's 100-character limit. I did not rewrite or force-push it. This v2 branch was recreated from
mainwith a separately verified single commit whose message and full diff gate pass.Supplementary timing
Earlier exhaustive baseline on the same host (
36e646dedbbf719c6fc43547ad3fd4cfb1e8bb65):Candidate on current
main:v0.0.88That is approximately a 10.9x median reduction in this environment. Timing is deliberately supplementary because the base commit advanced; deterministic probe-count tests are the durable performance contract.
PR #6884 still overlaps both files and is substantially behind current
main, so a final rebase/overlap review remains prudent before PR publication.kagura-chen commentedon Jul 22, 2026
I'd like to work on this. The fix is straightforward — sort the candidates by
compareVersionTagsDescbefore iterating, then return on the first reachable tag (early exit). This preserves the existing selection semantics while short-circuiting from O(n) probes to O(1) in the common case.I'll also add deterministic tests for probe count (one-probe success, two-probe fallback, complete exhaustion, annotated tags, and stable/prerelease ordering) as specified in the acceptance criteria.
perf(images): short-circuit reachable tag scan (#7566)