Skip to content

loom route: resolve a card weight by its lock's size + sha256 (rc1 option b, Inkling's _Old drafter) - #3396

Merged
bong-water-water-bong merged 1 commit into
mainfrom
loomfun/link-by-sha
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
loomfun/link-by-sha

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #3394, which merged as the refusal backstop. This implements the orchestrator's rc1 option (b) for the Inkling drafter swap risk (23 Nov ~14:2xZ).

Context:

  • unsloth/Inkling-2-Mini-GGUF (head 13bbdd72) keeps the drafter card r8 was built for as dspark-Inkling-2-Mini-Q8_0_Old.gguf: sha 2ec78510…, 402,278,560 B, identical today to dspark-Inkling-2-Mini-Q8_0.gguf.
  • The name the card uses is expected to get a new layout.
  • The Lemonade entry Inkling-2-Mini-1bit now pulls the _Old name as its draft (fork commit 3762d87, in the catalogue PR).
  • So the card's parameter/dspark-Inkling-2-Mini-Q8_0.gguf must be resolved by the card's lock, not by file name.

Change (loom_link_card_parameters): the function now reads both size and sha256 from the card's model.json.lock.

  1. Already linked: a link that resolves to a file of the lock's size is kept. Nothing is hashed on a normal start.
  2. Same name: the file under the card's name, beside the model, at the lock's size is linked as before, unhashed.
  3. Otherwise: every file beside the model with the lock's size is hashed once, and the one whose sha256 equals the lock's is linked (the _Old drafter).
  4. No match: if no file matches, loom route: refuse a card whose weight beside the model is not the size its lock says (Inkling drafter swap) #3394's refusal holds (serve doesn't take the route) and the message names the origin, the size and that the sha didn't match. That case now includes a lock with a sha but no file at all.

Entries without a lock entry behave as before.

Tests: two new loom_route_test cases.

  • A drafter replaced under the card's name is found by sha under its other name, and a same-size file with other bytes loses.
  • A second call keeps the link without re-hashing.

loom_route_test passes all 81 checks. serve.cpp compiles against the new header (object rebuilt on ryzen). bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.

🤖 Generated with Claude Code

…n the file under the card's name is missing or another size (rc1 option b: unsloth's _Old drafter); an existing right-size link is kept without hashing

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Performance Bottleneck

The code introduces a loop over all files in the model directory to find a matching SHA256 when the lock contains a SHA256. This could be a performance bottleneck if the model directory contains many files, as it requires hashing each file once. This is especially concerning in a per-token loop context where performance is critical.

if (const auto sh = lock_sha.find(origin); sh != lock_sha.end())
    for (const auto& de : fs::directory_iterator(model_dir, ec))
        if (fits(de.path()) && sha256_of_file(de.path().string()) == sh->second) { found = de.path(); break; }
Incorrect Error Message

The error message constructed when no file matches the lock's size and SHA256 includes the string "the card's lock gives for" which is grammatically incorrect and confusing. It should be rephrased for clarity.

why += std::string(why.empty() ? "" : "; ") + "no file beside the model has the size (" +
       std::to_string(want) + ") and sha256 the card's lock gives for " + origin +
       ": the checkpoint changed under the card, not linked";

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-npuconc), from reading the code; I ran nothing. The sha256 search for the _Old drafter is right, and its test covers what matters: a same-size impostor loses on sha, and a found file is linked under the card's name.

Same point as my #3394 review, now on the two unhashed paths. Two paths still accept a file on size alone:

  1. An existing link that resolves to a file of the lock's size is kept, with continue before any hash.
  2. The file under the card's name at the lock's size is linked unhashed (fits(target)).

The risk in this PR's own context is an in-place replacement at the same size. Examples: a re-upload of the same layout, a re-quant with identical tensor shapes, or a metadata fix inside the GGUF. Path 1 then keeps the link to the new bytes, and path 2 links them on a fresh card. Neither hashes, so the lock's sha256 is never consulted.

  • One way to keep normal starts hash-free and still be exact: hash once and record the verdict, e.g. a small parameter/.verified with <name> <resolved path> <size> <mtime> <sha256>.
  • Re-hash only when size or mtime differ from the record. The cost is one hash per file per change: about 0.3 s for the 402 MB drafter.

Smaller:

  • The directory_iterator scan hashes every same-size file beside the model until it finds a match, and iteration order is unspecified. That is fine for correctness, since equal sha means equal bytes. It is worth a comment that only same-size candidates are hashed, so the main GGUF is never hashed here.
  • When found is empty and lock_sha has no entry for the origin, but target does not exist, the weight is skipped silently (no refused, no why). The card then lacks a file without saying so. Is that the intended "no lock, old behaviour" case?

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit d64d491 into main Nov 23, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the loomfun/link-by-sha branch November 23, 2026 14:48
bong-water-water-bong added a commit that referenced this pull request Nov 23, 2026
…ed by serve's own log (engine#3350 rc1) (#3431)

The rc1 test build exists to serve Inkling-2-Mini on the Loom route, and the release check had no row for it: chat-hrx
asks the first listed non-NPU -1bit model a fixed phrase, and 1bit serve's designed fallback (card not usable, a
weight beside the model not the card's: #3394/#3396) answers just as well on llama.cpp. So a green check proved
nothing about Loom.

New row chat-loom (os/mini/release-check.sh, after chat-hrx):
- the model is ONEBIT_CHECK_LOOM_MODEL (default Inkling-2-Mini-1bit); --fetch pulls it (about 17.6 GB), else SKIP
  'not downloaded'; no GPU -> SKIP (and it joins the footer's hardware-skip list).
- asks 'What is 17 * 23? Reply with the number only.' (max_tokens 1024: a reasoning model gets room), reads ONLY the
  Lemonade log lines written during the row, counts loom-serve processes while it is loaded, then unloads it.
- loom_verdict (pure, in --self-test): PASS only when serve logged '-> loom-serve card', logged no 'serving on the
  llama.cpp route', a loom-serve ran, and the answer has 391. A right answer through the fallback FAILs.

--self-test: PASS, 227 ok (+8) under bash and busybox sh; sh -n / ash -n ok.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant