Skip to content

Base-image fallback scans every remote release tag before selecting the newest reachable one #7249

Description

@dfernandez365-rgb

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:

  1. runs git ls-remote --tags origin v*;
  2. normalizes and peels every release tag;
  3. launches git merge-base --is-ancestor once for every normalized tag;
  4. sorts all reachable tags;
  5. 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

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

  1. added
    area: install
    area: onboarding
    area: performance
    area: sandbox
    on Jul 20, 2026
  2. wscurran commented on Jul 20, 2026

    @wscurran
    Contributor

    ✨ Thanks for the detailed performance analysis. This is a clear optimization opportunity for the base-image fallback path.


    Related open PRs:


    Related open issues:

  3. dfernandez365-rgb commented on Jul 20, 2026

    @dfernandez365-rgb
    Author

    Measurement correction from a fresh count on current main (70d7d287f03f82355eafccfc8084de3741069281):

    • git ls-remote --tags origin 'v*' returns 163 ref lines.
    • Those lines represent 91 distinct raw tag names, including 72 annotated tags.
    • backup/v0.0.49-original-20260522032905 is rejected by the existing normalizeVersionTag() contract.
    • The current exhaustive implementation therefore evaluates 90 normalized candidates and launches 90 merge-base --is-ancestor probes, not 91.
    • Including the initial 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.88 should 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.

  4. dfernandez365-rgb commented on Jul 20, 2026

    @dfernandez365-rgb
    Author

    Implementation candidate: 0e1a0e59b1bbc7fcfbd9c2a906263d81aca2cbed

    The candidate is a GitHub-verified commit based directly on current main 70d7d287f03f82355eafccfc8084de3741069281: one commit ahead, zero behind, and limited to:

    • src/lib/sandbox-base-image/source-identity.ts
    • src/lib/sandbox-base-image/source-identity.test.ts

    Behavior

    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 describe fallback, annotated-tag peeling, stable/prerelease precedence, and comparator-equivalent insertion order remain covered.

    Deterministic verification on the signed commit

    • Focused Vitest: 26/26 passed
    • Exact probe assertions:
      • newest reachable: 1 probe
      • newest unreachable, second reachable: 2 probes in SHA order
      • annotated tag: peeled commit SHA, 1 probe
      • all remote candidates unreachable: complete exhaustion then local fallback
      • remote lookup failure: 0 reachability probes then local fallback
      • comparator-equivalent versions: stable existing order
      • stable release over prerelease: 1 probe
    • npm run build:cli: passed
    • npm run check:diff: passed after the clean checkout generated its required dist artifacts via build:cli
      • pre-commit hooks, Biome, repository checks, env-doc gate, gitleaks, source/test budgets, commitlint, and CLI TypeScript all passed
    • git diff origin/main...HEAD --check: passed
    • Diff: 2 files, 119 insertions, 12 deletions

    The 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 main with a separately verified single commit whose message and full diff gate pass.

    Supplementary timing

    Earlier exhaustive baseline on the same host (36e646dedbbf719c6fc43547ad3fd4cfb1e8bb65):

    • 10 calls: 4.104-4.659 seconds
    • median: 4.292 seconds

    Candidate on current main:

    • 10 calls: 353.4-436.3 ms
    • median: 392.6 ms
    • selected tag: v0.0.88
    • traced reachability probes: 10 total for 10 calls, exactly 1 per call

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

  5. kagura-chen commented on Jul 22, 2026

    @kagura-chen
    Contributor

    I'd like to work on this. The fix is straightforward — sort the candidates by compareVersionTagsDesc before 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.

  6. added a commit that references this issue on Jul 26, 2026
    d525e15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: installarea: onboardingarea: performancearea: sandbox

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions