Skip to content

registry_build: --from-tarball answers the content question in one command (engine#3212) - #3215

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-3212-tarball
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-3212-tarball

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3212. The content question — did the fork's architecture tables move with this pin? — has been answered by hand on every bump: download the pinned sha's source tarball, extract it, call this tool's own hf_to_gguf()/runtime_archs() on the result, compare with the committed file. Three times in one session, ~40 MB each. It is now one command.

tools/registry_build.py --check --from-tarball

What it does, and the four constraints the issue named

  • the sha comes from pin(HRX) — the index, not from the fetched tree, so a bump staged but not committed cannot be laundered into a matching registry;
  • the slug comes from .gitmodules (fork_slug(), matched on the path = line), never a guessed default;
  • the tarball is fetched once into ~/.cache/1bit-registry-tarballs/<sha>/ (--from-tarball prints the URL, the size and the cache path; ONEBIT_REGISTRY_TARBALL_CACHE overrides the location);
  • the derivation is build(tree), i.e. the same code path the submodule case runs — no second implementation to drift.

Measured here, not asserted

--check --from-tarball      fetch 38 MB, extract, derive, compare      rc 0, 7.19 s
second run                  "tarball already extracted", no fetch      rc 0
known answer, three pins    a87cc5a74  -> 350 classes / 9 npu / 350 architectures / 350 mapped
                            a9c849c6a  -> the same
                            7737fa364  -> the same
a sha the fork does not carry   404  ->  rc 2 "cannot tell, not a pass"
committed registry edited by hand (counts 351)  ->  rc 1 "is stale"

Those three pins and those figures are the issue's own table, which its author produced by hand — so the command reproduces the manual answer, on the same three inputs, and the mutant shows it still fails when the committed file disagrees.

The default is untouched, on purpose

Without the flag, registry_content still prints

registry_build: third_party/llama.cpp is not checked out (…): the content checks skip here, they do not pass

and exits 77 — verified in this branch's own checkout, which has no submodule. A networked row would make a deterministic gate depend on the network, which is the trade the issue explicitly refused.

Arms

--self-test, wired as the registry_build_self row, covers the three offline fail paths: no pinned sha → no tree; no .gitmodules → the slug is unknown rather than guessed; a cache entry that exists but has no src/ → still cannot-tell. 4/4, and every failure is asserted to have said why.

What I did not make a row: the fetch itself. It needs the network, and a networked ctest row is exactly what the default's 77 exists to avoid; its known-answer run is the three pins above, recorded here.

pre-pr-checks on this branch: 16 green / 3 skipped / 0 could not be told.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

One cost worth knowing before a lane uses this, measured: the cache is ~240 MB per pin.

38 MB   <sha>.tar.gz
200 MB  <sha>/            (extracted source tree: src/, ggml/src/, gguf-py/, tests/)

So the first --from-tarball on a new pin costs 39 MB of network and 239 MB of disk, and the second run is free. I trimmed my own cache back to the current pin (a9c849c6a) after the known-answer run, leaving 239 MB — but a fleet that bumps twice an hour will accumulate one tree per sha unless something prunes it.

Options, and the one I would pick: keep only the latest extracted tree and delete the previous one on a new fetch (--keep 1, the default), with --keep all for anyone who wants the history. I have not implemented pruning — it is a policy question about a shared cache directory, not a mechanical fix, and it is exactly the kind of thing that should be decided by whoever owns ~/.cache conventions rather than added silently in a bump-adjacent PR. If a reviewer prefers, I will add it to this PR in the same push rather than a follow-up.

The tarballs are also cheap to re-fetch (39 MB, ~1 s on this box's link) — so a --no-cache flag is an alternative shape if the fleet would rather not hold 240 MB per pin at all. Same decision, and I would rather ask than guess.

Comment thread tools/registry_build.py
top = tf.getnames()[0].split("/")[0]
tmp = dest + ".part"
os.makedirs(tmp, exist_ok=True)
tf.extractall(tmp)
…mmand (engine#3212)

`registry_content` derives the registry from third_party/llama.cpp and answers 77
where that submodule is absent -- which is most of the fleet's checkouts. That is
right (a skip is not a pass) but it means "did the fork's architecture tables move
with this pin?" has been answered by hand on every bump: download the pinned sha's
source tarball, extract it, call this tool's own hf_to_gguf()/runtime_archs() on the
result, compare with the committed file. Three times in one session, ~40 MB each.

  tools/registry_build.py --check --from-tarball

does it instead: the sha comes from `pin(HRX)` (the INDEX, so a staged-but-not-
committed bump cannot be laundered), the slug from `.gitmodules`, the tarball is
fetched once into ~/.cache/1bit-registry-tarballs/<sha> (ONEBIT_REGISTRY_TARBALL_CACHE
overrides), extracted, and the same derivation runs against it. The cache keeps ONE
pin: a new sha prunes the previous tree+tarball, on a fetch AND on a cache hit
(ONEBIT_REGISTRY_TARBALL_KEEP=all keeps the history) -- ~240 MB per pin otherwise,
which would grow on every bump.

Measured on this box:
  --check --from-tarball      fetch 38 MB, extract, derive, compare -> rc 0, 7.19 s
  second run                  "tarball already extracted", no fetch, rc 0
  known answer, three pins    a87cc5a74, a9c849c6a, 7737fa364 each derive
                              350 classes / 9 npu / 350 architectures / 350 mapped --
                              the same figures the three bump PRs committed by hand
  a sha the fork does not carry  404 -> rc 2 "cannot tell, not a pass"
  committed registry edited by hand -> rc 1 "is stale"

Default unchanged, deliberately: without the flag the row still prints its 77 skip
message and touches no network. A failed fetch, or a cache entry that is not the
fork's tree, is cannot-tell (2), never clean.

--self-test covers the three offline fail paths (no pinned sha, no slug in
.gitmodules, a cached dir without src/), wired as the `registry_build_self` row.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing into #3214 — it was opened eleven minutes before mine and does the same thing, and I should have run gh pr list --search 3212 before opening. The two halves mine had that #3214 does not (a bounded cache: an extracted tree is ~200 MB per pin and an unbounded cache grows on every bump; and a ctest row so the self-test actually runs) are handed over in its thread as exact code. Nothing is lost, one copy lands, and the duplicate gate goes back to green when this closes.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3212 - Partially compliant

Compliant requirements:

  • The --from-tarball option is implemented and fetches tarballs from the correct GitHub URL derived from .gitmodules
  • The default behavior remains unchanged with no network dependency for the main test
  • Failed fetches return exit code 2 ("cannot tell") instead of passing
  • The tarball cache location is configurable via ONEBIT_REGISTRY_TARBALL_CACHE
  • The pin comes from the index (pin(HRX)) and not from the fetched tree
  • A --self-test option is added to test offline failure paths

Non-compliant requirements:

  • The documentation in the PR description mentions that the implementation should be measured on hardware, but no specific measurements are provided in the code diff

Requires further human verification:

  • The PR description states that the implementation should be measured on hardware, but no specific measurements are provided in the code diff
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential cache cleanup race condition

The prune function in tarball_tree may have a race condition when multiple processes try to prune the cache simultaneously. If one process is pruning while another is extracting a new tarball, it could potentially remove the directory that's currently being extracted, leading to inconsistent state. This is particularly concerning in multi-user or parallel build environments.

def prune(cache, sha, say):
    """Keep this run's pin and drop the previous one's, unless ONEBIT_REGISTRY_TARBALL_KEEP=all.

    engine#3212: an extracted tree is ~200 MB beside its 39 MB tarball, so an unbounded cache grows by that on every
    pin. Called on BOTH paths -- a cache HIT can also be the run that should prune the sibling, which my first
    version missed because the early return skipped it.
    """
    if os.environ.get("ONEBIT_REGISTRY_TARBALL_KEEP", "1") == "all":
        return
    for name in sorted(os.listdir(cache)):
        stale = os.path.join(cache, name)
        if name.startswith(sha):
            continue
        if os.path.isdir(stale):
            shutil.rmtree(stale, ignore_errors=True)
        elif name.endswith((".tar.gz", ".part")):
            os.unlink(stale)
        else:
            continue
        say(f"pruned the previous pin's {name} (ONEBIT_REGISTRY_TARBALL_KEEP=all keeps them)")
Error handling for tarball extraction

The tarball_tree function catches tarfile.TarError and OSError during extraction, but does not handle the case where the tarball is corrupted or incomplete. If the extraction fails due to a corrupted tarball, it will return None and print an error message, but there's no mechanism to retry or mark the cache entry as invalid for future use.

except (tarfile.TarError, OSError) as e:
    say(f"could not extract {tar_path}: {e}")
    return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pins: the content axis needs a source tarball at the pinned sha, by hand, on every bump — 3 repetitions in one session

2 participants