From 9af81f05b3b178e2bb52d6b284dbe88d20d7e444 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 00:11:35 -0400 Subject: [PATCH 1/4] tools: kernel-set-check.sh, so a shipped set says whether it is self-consistent and in one form (engine#2106) --- CMakeLists.txt | 3 + scripts/kernel-set-check.sh | 143 +++++++++++++++++++++++++++++++++ tests/kernel_set_check_test.sh | 115 ++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100755 scripts/kernel-set-check.sh create mode 100755 tests/kernel_set_check_test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 610142905..c310a4b58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,9 @@ add_test(NAME serve_hangup COMMAND ${CMAKE_SOURCE_DIR}/tests/serve_hangup_test.s # engine#1945: scripts/bump-hrx-sync.sh tells AMD's own commit from a line AMD rebased apart from a commit that # is not AMD's. Local git repositories only: no network, no GPU. add_test(NAME bump_hrx_sync COMMAND bash ${CMAKE_SOURCE_DIR}/tests/bump_hrx_sync_test.sh ${CMAKE_SOURCE_DIR}/scripts/bump-hrx-sync.sh) +# engine#2106: a shipped kernel set's own consistency -- manifest vs bytes, one form or none, name vs directory. The +# refusal this pre-empts ("differ in size") needed private-repo archaeology to diagnose; the symptom is checkable here. +add_test(NAME kernel_set_check COMMAND bash ${CMAKE_SOURCE_DIR}/tests/kernel_set_check_test.sh) add_test(NAME bump_hrx_report COMMAND bash ${CMAKE_SOURCE_DIR}/tests/bump_hrx_report_test.sh ${CMAKE_SOURCE_DIR}/scripts/bump-hrx-report.sh) add_test(NAME metrics_serve COMMAND ${CMAKE_SOURCE_DIR}/tests/metrics_serve.sh $) # serve --print-backend: the llama-server Lemonade starts itself, one hop (docs/serve.md): no GPU. diff --git a/scripts/kernel-set-check.sh b/scripts/kernel-set-check.sh new file mode 100755 index 000000000..6068ff467 --- /dev/null +++ b/scripts/kernel-set-check.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# Copyright 2026 bong-water-water-bong +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# kernel-set-check.sh: is a shipped kernel set self-consistent, and in which form? (engine#2106) +# +# scripts/kernel-set-check.sh [ ...] +# +# Why this exists: the release candidate serves small models at 87-101 tok/s with the set that ships beside it, and a +# build of current main refused that same set with "layer ELFs: the NB 2 and 3 builds differ in size". Neither the set +# nor the kernels were wrong — the two sides came from different revisions of the private repository, one on each side of +# its protection change, so the binary read sealed files as plain ELFs and compared their lengths. That diagnosis took a +# private-repo archaeology session; the *symptom* is checkable from the set alone, without a device and without the +# private repo, which is what this script does. +# +# It answers three questions a release run should ask before a device row: +# 1. does the manifest match the bytes? (every listed file present, with the listed size and sha256, and nothing +# listed that is absent — a set that fails this cannot be trusted to describe itself); +# 2. is the set in ONE form? (every kernel entry either starts with \x7fELF or does not; a mixed set is the exact +# state in which one side reads the other side's files and sees "differ in size"); +# 3. does the set's own name agree with its directory? (a set copied to the wrong geometry name loads and mis-answers). +# +# Exit: 0 the set is consistent, 1 it is not, 2 the argument is not a set (no manifest.json). + +set -uo pipefail + +fail=0 + +check_set() { + local dir=${1%/} name + name=$(basename "$dir") + if [ ! -f "$dir/manifest.json" ]; then + printf 'FAIL %s: no manifest.json, so this is not a set this script can judge\n' "$dir" + return 2 + fi + + # The manifest is the set's own description: format, set name, and one entry per file with size and sha256. + local info + if ! info=$(python3 - "$dir" <<'PY' +import json, os, re, sys + +root = sys.argv[1] +path = os.path.join(root, "manifest.json") +try: + with open(path) as handle: + manifest = json.load(handle) +except Exception as exc: # noqa: BLE001 - any parse failure is the finding + print(f"FAIL {path}: not readable as JSON ({exc})") + raise SystemExit(1) + +problems = [] +files = manifest.get("files") +if not isinstance(files, list) or not files: + problems.append("the manifest lists no files") + files = [] +if manifest.get("set") and manifest["set"] != os.path.basename(root): + problems.append(f"the manifest names set {manifest['set']!r} but the directory is {os.path.basename(root)!r}") + +listed = set() +forms = {} +for entry in files: + rel = entry.get("path") + if not rel: + problems.append("an entry has no path") + continue + listed.add(rel) + full = os.path.join(root, rel) + if not os.path.isfile(full): + problems.append(f"{rel}: listed but absent") + continue + size = os.path.getsize(full) + if "size" in entry and size != entry["size"]: + problems.append(f"{rel}: manifest says {entry['size']} B, the file is {size} B") + if "sha256" in entry: + import hashlib + digest = hashlib.sha256() + with open(full, "rb") as handle: + for block in iter(lambda: handle.read(1 << 20), b""): + digest.update(block) + if digest.hexdigest() != entry["sha256"]: + problems.append(f"{rel}: sha256 differs from the manifest") + with open(full, "rb") as handle: + head = handle.read(4) + forms.setdefault("elf" if head == b"\x7fELF" else "sealed", []).append(rel) + +# Kernels the manifest forgot: a layer1.elf on disk that nothing lists is one a loader may still pick up. +for current, _, names in os.walk(root): + for name in names: + full = os.path.join(current, name) + rel = os.path.relpath(full, root) + if rel in ("manifest.json", "manifest.sig", "layout.json") or rel in listed: + continue + if not rel.endswith((".elf", ".bin")): + continue + problems.append(f"{rel}: on disk but not in the manifest") + +for rel, kind in (("elf", "plain ELF"), ("sealed", "sealed/opaque")): + if forms.get(rel): + print(f"OK {os.path.basename(root)}: {len(forms[rel])} file(s) in {kind} form") + +if len(forms) > 1: + problems.append( + "MIXED FORMS: " + + ", ".join(f"{len(v)} {k}" for k, v in sorted(forms.items())) + + " -- a build reads one form and compares the other's lengths, which is the 'differ in size' refusal") + +for problem in problems: + print(f"FAIL {os.path.basename(root)}: {problem}") +raise SystemExit(0 if not problems else 1) +PY + ); then + fail=1 + fi + printf '%s\n' "$info" + +} + +if [ $# -eq 0 ]; then + printf 'usage: %s [ ...]\n' "$0" >&2 + exit 2 +fi + +rc=0 +for dir in "$@"; do + check_set "$dir" || { rc=$?; [ "$rc" -gt 1 ] && rc=2; } +done + +if [ "$fail" != 0 ]; then + [ "$rc" -eq 0 ] && rc=1 +fi +exit "$rc" diff --git a/tests/kernel_set_check_test.sh b/tests/kernel_set_check_test.sh new file mode 100755 index 000000000..ef6570a82 --- /dev/null +++ b/tests/kernel_set_check_test.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# Copyright 2026 bong-water-water-bong +# SPDX-License-Identifier: Apache-2.0 +# +# tests/kernel_set_check_test.sh -- scripts/kernel-set-check.sh against fixture sets (engine#2106). No device, no private +# repository, no real kernel bytes: every fixture is a byte string with a readable head and a manifest that describes it. + +set -uo pipefail + +root=$(cd -- "$(dirname -- "$0")/.." && pwd) +script="$root/scripts/kernel-set-check.sh" +fails=0 +tmp=$(mktemp -d) +trap 'rm -rf -- "$tmp"' EXIT + +check() { # check + if [ "$1" = ok ]; then + printf 'ok %s\n' "$2" + else + printf 'FAIL %s\n' "$2" + fails=$((fails + 1)) + fi +} + +has() { grep -qF -- "$2" "$1"; } + +# mk_set [size-delta] [sha-broken] +mk_set() { + local dir=$1 name=$2 count=$3 kind=$4 delta=${5:-0} broken=${6:-0} + mkdir -p "$dir" + python3 - "$dir" "$name" "$count" "$kind" "$delta" "$broken" <<'PY' +import hashlib, json, os, sys +root, name, count, kind, delta, broken = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4], int(sys.argv[5]), int(sys.argv[6]) +files = [] +for i in range(count): + rel = f"layer1_{100 + i}/layer1.elf" + os.makedirs(os.path.join(root, os.path.dirname(rel)), exist_ok=True) + body = (b"\x7fELF" if (kind == "elf" or (kind == "mixed" and i % 2 == 0)) else b"SEALED01") + bytes([i]) * 64 + with open(os.path.join(root, rel), "wb") as handle: + handle.write(body) + digest = hashlib.sha256(body).hexdigest() + if broken == 1 and i == 0: + digest = "0" * 64 + files.append({"path": rel, "size": len(body) + (delta if i == 0 else 0), "sha256": digest}) +with open(os.path.join(root, "manifest.json"), "w") as handle: + json.dump({"format": 1, "set": name, "files": files}, handle, indent=1) +PY +} + +# 1. a set in one form, described correctly -> PASS in both forms +mk_set "$tmp/set-elf/1024x3072x16x8" 1024x3072x16x8 3 elf +"$script" "$tmp/set-elf/1024x3072x16x8" > "$tmp/out1" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "consistent ELF set: rc 0" +check $(has "$tmp/out1" "3 file(s) in plain ELF form" && echo ok || echo fail) "... and it names the form and the count" + +mk_set "$tmp/set-sealed/1024x3072x16x8" 1024x3072x16x8 3 sealed +"$script" "$tmp/set-sealed/1024x3072x16x8" > "$tmp/out2" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "consistent sealed set: rc 0" +check $(has "$tmp/out2" "sealed/opaque" && echo ok || echo fail) "... and it says sealed, not ELF" + +# 2. THE CASE #2106 WAS: one set, two forms -> the state where a build compares the other side's lengths +mk_set "$tmp/set-mixed/1024x3072x16x8" 1024x3072x16x8 4 mixed +"$script" "$tmp/set-mixed/1024x3072x16x8" > "$tmp/out3" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "MIXED forms: rc 1" +check $(has "$tmp/out3" "MIXED FORMS" && echo ok || echo fail) "... and the reason is named" +check $(has "$tmp/out3" "differ in size" && echo ok || echo fail) "... quoting the refusal this is meant to pre-empt" + +# 3. the manifest's own claims +mk_set "$tmp/set-size/1024x3072x16x8" 1024x3072x16x8 2 elf 3 +"$script" "$tmp/set-size/1024x3072x16x8" > "$tmp/out4" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "size disagrees with the manifest: rc 1" +check $(has "$tmp/out4" "manifest says" && echo ok || echo fail) "... naming both numbers" + +mk_set "$tmp/set-sha/1024x3072x16x8" 1024x3072x16x8 2 elf 0 1 +"$script" "$tmp/set-sha/1024x3072x16x8" > "$tmp/out5" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "sha256 disagrees with the manifest: rc 1" +check $(has "$tmp/out5" "sha256 differs" && echo ok || echo fail) "... named as a sha difference" + +# 4. presence both ways: listed-but-absent, and on-disk-but-unlisted +mk_set "$tmp/set-absent/1024x3072x16x8" 1024x3072x16x8 2 elf +rm -rf "$tmp/set-absent/1024x3072x16x8/layer1_101" +"$script" "$tmp/set-absent/1024x3072x16x8" > "$tmp/out6" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "a listed file that is absent: rc 1" +check $(has "$tmp/out6" "listed but absent" && echo ok || echo fail) "... named" + +mk_set "$tmp/set-extra/1024x3072x16x8" 1024x3072x16x8 2 elf +mkdir -p "$tmp/set-extra/1024x3072x16x8/layer1_999" +printf 'SEALED01extra' > "$tmp/set-extra/1024x3072x16x8/layer1_999/layer1.elf" +"$script" "$tmp/set-extra/1024x3072x16x8" > "$tmp/out7" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "an ELF on disk that the manifest does not list: rc 1" +check $(has "$tmp/out7" "not in the manifest" && echo ok || echo fail) "... named (a loader may still pick it up)" + +# 5. the set's own name must agree with its directory +mk_set "$tmp/set-name/2048x3072x16x8" 1024x3072x16x8 1 elf +"$script" "$tmp/set-name/2048x3072x16x8" > "$tmp/out8" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "a set filed under the wrong geometry name: rc 1" +check $(has "$tmp/out8" "but the directory is" && echo ok || echo fail) "... naming both" + +# 6. not a set at all is a different answer from a bad set +mkdir -p "$tmp/not-a-set" +"$script" "$tmp/not-a-set" > "$tmp/out9" 2>&1 +check $([ $? -eq 2 ] && echo ok || echo fail) "a directory with no manifest: rc 2 (not the same as rc 1)" +check $(has "$tmp/out9" "no manifest.json" && echo ok || echo fail) "... and it says why" + +# 7. several sets in one call: the worst one decides +"$script" "$tmp/set-elf/1024x3072x16x8" "$tmp/set-mixed/1024x3072x16x8" > "$tmp/out10" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "two sets, one bad: rc 1" +check $(has "$tmp/out10" "OK " && has "$tmp/out10" "MIXED FORMS" && echo ok || echo fail) \ + "... both are reported, the good one included" + +if [ "$fails" -ne 0 ]; then + printf 'kernel_set_check: %d failure(s)\n' "$fails" + exit 1 +fi +printf 'kernel_set_check: all cases ok\n' From 496d66ff071b8ff4419f30bafc2646c8061f8994 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 03:00:52 -0400 Subject: [PATCH 2/4] kernel-set-check: name the naming scheme too, so a binary/set mismatch is visible (engine#2106) --- scripts/kernel-set-check.sh | 17 +++++++++++++++++ tests/kernel_set_check_test.sh | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/scripts/kernel-set-check.sh b/scripts/kernel-set-check.sh index 6068ff467..4a5188f0d 100755 --- a/scripts/kernel-set-check.sh +++ b/scripts/kernel-set-check.sh @@ -110,6 +110,23 @@ for rel, kind in (("elf", "plain ELF"), ("sealed", "sealed/opaque")): if forms.get(rel): print(f"OK {os.path.basename(root)}: {len(forms[rel])} file(s) in {kind} form") +# How the files are NAMED, because that is the other half of a binary/set mismatch: a current-main plan asks for a +# role-named ELF (`full_i8_QKV_K1024_N4096.elf`) while a set built before the private repo's protection change carries +# per-layer files (`layer1_2081/layer1.elf`). engine#2106 measured exactly that refusal, and it is visible from the names +# alone -- no plan, no device, and no copy of the forward's naming rule (which is why this classifies rather than predicts). +role_named = sum(1 for rel in listed if re.search(r"(^|/)full_i8_[A-Za-z0-9_]+_K\d+", rel)) +layer_indexed = sum(1 for rel in listed if re.search(r"(^|/)layer\d+_\d+/", rel)) +other_named = len(listed) - role_named - layer_indexed +if listed: + kinds = [n for n, c in (("role-named full_i8_*.elf", role_named), ("layer-indexed layerN_M/…", layer_indexed), + ("other", other_named)) if c] + print(f"OK {os.path.basename(root)}: names: " + ", ".join( + f"{c} {n}" for n, c in (("role-named full_i8_*.elf", role_named), ("layer-indexed layerN_M/…", layer_indexed), + ("other", other_named)) if c)) + if role_named and layer_indexed: + problems.append("MIXED NAMING: the set has both role-named and layer-indexed files, so a plan written for one " + "scheme will not find the other") + if len(forms) > 1: problems.append( "MIXED FORMS: " diff --git a/tests/kernel_set_check_test.sh b/tests/kernel_set_check_test.sh index ef6570a82..6398bebd2 100755 --- a/tests/kernel_set_check_test.sh +++ b/tests/kernel_set_check_test.sh @@ -108,6 +108,41 @@ check $([ $? -eq 1 ] && echo ok || echo fail) "two sets, one bad: rc 1" check $(has "$tmp/out10" "OK " && has "$tmp/out10" "MIXED FORMS" && echo ok || echo fail) \ "... both are reported, the good one included" + +# 8. the naming scheme, which is the other half of a binary/set mismatch (engine#2106): a current-main plan asks for +# role-named full_i8_*.elf, a pre-change set carries layerN_M/layer1.elf, and a set with both is refused +mk_named() { # mk_named + mkdir -p "$1"; python3 - "$1" "$2" "$3" "$4" <<'PY2' +import hashlib, json, os, sys +root, name, nrole, nlayer = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) +files = [] +def put(rel): + full = os.path.join(root, rel); os.makedirs(os.path.dirname(full) or root, exist_ok=True) + body = b"\x7fELF" + rel.encode() + open(full, "wb").write(body) + files.append({"path": rel, "size": len(body), "sha256": hashlib.sha256(body).hexdigest()}) +for i in range(nrole): + put(f"full_i8_QKV_K1024_N{4096 + i}.elf") +for i in range(nlayer): + put(f"layer1_{100 + i}/layer1.elf") +json.dump({"format": 1, "set": name, "files": files}, open(os.path.join(root, "manifest.json"), "w")) +PY2 +} +mk_named "$tmp/n-role/1024x3072x16x8" 1024x3072x16x8 2 0 +"$script" "$tmp/n-role/1024x3072x16x8" > "$tmp/out11" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "role-named set: rc 0" +check $(has "$tmp/out11" "2 role-named full_i8_*.elf" && echo ok || echo fail) "... and the naming is named" + +mk_named "$tmp/n-layer/1024x3072x16x8" 1024x3072x16x8 0 3 +"$script" "$tmp/n-layer/1024x3072x16x8" > "$tmp/out12" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "layer-indexed set: rc 0 on its own" +check $(has "$tmp/out12" "3 layer-indexed" && echo ok || echo fail) "... and the naming is named" + +mk_named "$tmp/n-mixed/1024x3072x16x8" 1024x3072x16x8 1 2 +"$script" "$tmp/n-mixed/1024x3072x16x8" > "$tmp/out13" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "a set with BOTH naming schemes: rc 1" +check $(has "$tmp/out13" "MIXED NAMING" && echo ok || echo fail) "... and the reason is named" + if [ "$fails" -ne 0 ]; then printf 'kernel_set_check: %d failure(s)\n' "$fails" exit 1 From a319324f4250b3d118dab2bea99f902e42bbb4e1 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 07:41:36 -0400 Subject: [PATCH 3/4] kernel-set-check: --pack reads the wide/narrow set names, so a no-op naming is visible (engine#2128) --- scripts/kernel-set-check.sh | 76 +++++++++++++++++++++++++++++++++- tests/kernel_set_check_test.sh | 36 ++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/scripts/kernel-set-check.sh b/scripts/kernel-set-check.sh index 4a5188f0d..e72e9731e 100755 --- a/scripts/kernel-set-check.sh +++ b/scripts/kernel-set-check.sh @@ -16,7 +16,7 @@ # # kernel-set-check.sh: is a shipped kernel set self-consistent, and in which form? (engine#2106) # -# scripts/kernel-set-check.sh [ ...] +# scripts/kernel-set-check.sh [--pack ] [ ...] # # Why this exists: the release candidate serves small models at 87-101 tok/s with the set that ships beside it, and a # build of current main refused that same set with "layer ELFs: the NB 2 and 3 builds differ in size". Neither the set @@ -36,6 +36,18 @@ set -uo pipefail +# --pack is the only option: everything else is a set directory. Parsed before the work so a set named like an +# option cannot be mistaken for one, and so `pack` is always defined under `set -u`. +pack="" +args=() +while [ $# -gt 0 ]; do + case "$1" in + --pack) pack="${2:-}"; shift 2 ;; + *) args+=("$1"); shift ;; + esac +done +set -- "${args[@]}" + fail=0 check_set() { @@ -144,6 +156,59 @@ PY } +# engine#2128: a pack that names the wide/narrow sealed sets must name files that are actually there. The naming lives in +# `config.json` (`q4nx_t2s_sealed_wide_elf`, `q4nx_sealed_wide_rows`, `q4nx_t2s_sealed_narrow_elf`, `q4nx_sealed_narrow_rows`) +# or in `plan.json` (`prefill.sealed_elf`, `decode.narrow_elf`). A name that does not exist is *logged* at run time and the serve +# stays on the 16-row set -- correct, and invisible until someone reads a log. This says it before a ticket: naming is a decision, +# and a decision whose file is missing is a no-op that reads like a win. +check_pack_naming() { + local dir=${1%/} + shift + python3 - "$dir" "$@" <<'PYPACK' +import json, os, sys +root = sys.argv[1] +sets = sys.argv[2:] +problems, named = [], {} +def load(name): + path = os.path.join(root, name) + if not os.path.isfile(path): + return {} + try: + with open(path) as handle: + return json.load(handle) + except Exception: + return {} +config, plan = load("config.json"), load("plan.json") +keys = { + "wide": [("config.json", config.get("q4nx_t2s_sealed_wide_elf")), + ("plan.json", (plan.get("prefill") or {}).get("sealed_elf"))], + "narrow": [("config.json", config.get("q4nx_t2s_sealed_narrow_elf")), + ("plan.json", (plan.get("decode") or {}).get("narrow_elf"))], +} +for kind, sources in keys.items(): + for where, value in sources: + if not value: + continue + named[kind] = (where, value) + base = os.path.basename(str(value)) + found = [] + for s in sets: + for cur, _, names in os.walk(s): + if base in names: + found.append(os.path.join(cur, base)) + if not found: + problems.append(f"{kind} set named in {where} as {value!r}, which is in none of the sets given " + f"({', '.join(os.path.basename(x) or x for x in sets)}) -- the serve would log it and stay on the 16-row set") + else: + print(f"OK {os.path.basename(root)}: {kind} set {base} named in {where} is present") +if not named: + print(f"OK {os.path.basename(root)}: names no wide/narrow set (16-row set only)") +for problem in problems: + print(f"FAIL {os.path.basename(root)}: {problem}") +raise SystemExit(0 if not problems else 1) +PYPACK +} + if [ $# -eq 0 ]; then printf 'usage: %s [ ...]\n' "$0" >&2 exit 2 @@ -154,6 +219,15 @@ for dir in "$@"; do check_set "$dir" || { rc=$?; [ "$rc" -gt 1 ] && rc=2; } done +if [ -n "$pack" ]; then + if [ ! -d "$pack" ]; then + printf 'FAIL %s: --pack is not a directory\n' "$pack" + fail=1 + elif ! check_pack_naming "$pack" "$@"; then + fail=1 + fi +fi + if [ "$fail" != 0 ]; then [ "$rc" -eq 0 ] && rc=1 fi diff --git a/tests/kernel_set_check_test.sh b/tests/kernel_set_check_test.sh index 6398bebd2..1e8505307 100755 --- a/tests/kernel_set_check_test.sh +++ b/tests/kernel_set_check_test.sh @@ -143,6 +143,42 @@ mk_named "$tmp/n-mixed/1024x3072x16x8" 1024x3072x16x8 1 2 check $([ $? -eq 1 ] && echo ok || echo fail) "a set with BOTH naming schemes: rc 1" check $(has "$tmp/out13" "MIXED NAMING" && echo ok || echo fail) "... and the reason is named" + +# 9. engine#2128: a pack that names the wide/narrow sealed sets must name files that are there +mk_pack() { # mk_pack [ ] + mkdir -p "$1" + python3 - "$@" <<'PYP' +import json, os, sys +root, kind, *pairs = sys.argv[1:] +if kind == "config": + body = {pairs[i]: pairs[i + 1] for i in range(0, len(pairs), 2)} +else: + body = {"prefill": {}, "decode": {}} + for i in range(0, len(pairs), 2): + key, value = pairs[i], pairs[i + 1] + body["prefill" if key == "sealed_elf" else "decode"][key] = value +json.dump(body, open(os.path.join(root, kind + ".json"), "w")) +PYP +} +mk_set "$tmp/named/1024x3072x16x8" 1024x3072x16x8 1 elf +ln -sf "$tmp/named/1024x3072x16x8/layer1_100/layer1.elf" "$tmp/named/1024x3072x16x8/wide32.elf" 2>/dev/null || true +mk_pack "$tmp/pack-named" config q4nx_t2s_sealed_wide_elf wide32.elf +"$script" --pack "$tmp/pack-named" "$tmp/named/1024x3072x16x8" > "$tmp/out14" 2>&1 +check $(has "$tmp/out14" "wide set wide32.elf named in config.json is present" && echo ok || echo fail) \ + "a pack naming a wide set that exists: named and present" +mk_pack "$tmp/pack-missing" config q4nx_t2s_sealed_wide_elf absent32.elf +"$script" --pack "$tmp/pack-missing" "$tmp/named/1024x3072x16x8" > "$tmp/out15" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "a pack naming a set that is ABSENT: rc 1" +check $(has "$tmp/out15" "stay on the 16-row set" && echo ok || echo fail) "... and says what the serve would do instead" +mk_pack "$tmp/pack-plan" plan sealed_elf wide32.elf narrow_elf gone4.elf +"$script" --pack "$tmp/pack-plan" "$tmp/named/1024x3072x16x8" > "$tmp/out16" 2>&1 +check $([ $? -eq 1 ] && echo ok || echo fail) "naming from plan.json is read too (the narrow file is absent)" +check $(has "$tmp/out16" "narrow set named in plan.json" && echo ok || echo fail) "... and the missing one is named" +mk_pack "$tmp/pack-none" config unused 1 +"$script" --pack "$tmp/pack-none" "$tmp/named/1024x3072x16x8" > "$tmp/out17" 2>&1 +check $(has "$tmp/out17" "names no wide/narrow set (16-row set only)" && echo ok || echo fail) \ + "a pack naming nothing: said explicitly, not silently" + if [ "$fails" -ne 0 ]; then printf 'kernel_set_check: %d failure(s)\n' "$fails" exit 1 From 7468391367b30d4fe5dc0975297fd27c43858f88 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 09:51:38 -0400 Subject: [PATCH 4/4] kernel-set-check: only kernels have a form, suffixed layer dirs are layer-indexed, full notice on the test Three points open on #2120 across four heads: the test carried a two-line notice (CI's copyright step failed), a listed layout.json was classified as a sealed kernel so a correct plain-ELF set failed as MIXED FORMS, and layerN_Mnp/ directories were counted as other. Five new arms; three fail on the script before this change. Co-Authored-By: Claude Fable 5.2 --- scripts/kernel-set-check.sh | 7 ++++- tests/kernel_set_check_test.sh | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/scripts/kernel-set-check.sh b/scripts/kernel-set-check.sh index e72e9731e..242862275 100755 --- a/scripts/kernel-set-check.sh +++ b/scripts/kernel-set-check.sh @@ -103,6 +103,10 @@ for entry in files: digest.update(block) if digest.hexdigest() != entry["sha256"]: problems.append(f"{rel}: sha256 differs from the manifest") + # Only kernels have a form. A manifest also lists what travels with them (every shipped one lists layout.json), and a + # JSON file is neither a plain ELF nor a sealed one: counting it would call a correct plain-ELF set mixed. + if not rel.endswith((".elf", ".bin")): + continue with open(full, "rb") as handle: head = handle.read(4) forms.setdefault("elf" if head == b"\x7fELF" else "sealed", []).append(rel) @@ -126,8 +130,9 @@ for rel, kind in (("elf", "plain ELF"), ("sealed", "sealed/opaque")): # role-named ELF (`full_i8_QKV_K1024_N4096.elf`) while a set built before the private repo's protection change carries # per-layer files (`layer1_2081/layer1.elf`). engine#2106 measured exactly that refusal, and it is visible from the names # alone -- no plan, no device, and no copy of the forward's naming rule (which is why this classifies rather than predicts). +# A layer directory may carry a lower-case suffix after its number (`layer1_2081np/`); it is still layer-indexed. role_named = sum(1 for rel in listed if re.search(r"(^|/)full_i8_[A-Za-z0-9_]+_K\d+", rel)) -layer_indexed = sum(1 for rel in listed if re.search(r"(^|/)layer\d+_\d+/", rel)) +layer_indexed = sum(1 for rel in listed if re.search(r"(^|/)layer\d+_\d+[a-z]*/", rel)) other_named = len(listed) - role_named - layer_indexed if listed: kinds = [n for n, c in (("role-named full_i8_*.elf", role_named), ("layer-indexed layerN_M/…", layer_indexed), diff --git a/tests/kernel_set_check_test.sh b/tests/kernel_set_check_test.sh index 1e8505307..3b3a24ad1 100755 --- a/tests/kernel_set_check_test.sh +++ b/tests/kernel_set_check_test.sh @@ -2,6 +2,18 @@ # Copyright 2026 bong-water-water-bong # SPDX-License-Identifier: Apache-2.0 # +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# # tests/kernel_set_check_test.sh -- scripts/kernel-set-check.sh against fixture sets (engine#2106). No device, no private # repository, no real kernel bytes: every fixture is a byte string with a readable head and a manifest that describes it. @@ -179,6 +191,46 @@ mk_pack "$tmp/pack-none" config unused 1 check $(has "$tmp/out17" "names no wide/narrow set (16-row set only)" && echo ok || echo fail) \ "a pack naming nothing: said explicitly, not silently" +# 10. a manifest lists more than kernels: every shipped one lists layout.json. Only .elf/.bin entries have a form, so a +# correct plain-ELF set that lists its layout.json is one form, not two. +mk_set "$tmp/set-layout/1024x3072x16x8" 1024x3072x16x8 3 elf +python3 - "$tmp/set-layout/1024x3072x16x8" <<'PYL' +import hashlib, json, os, sys +root = sys.argv[1] +body = b'{"layers": 3}\n' +open(os.path.join(root, "layout.json"), "wb").write(body) +path = os.path.join(root, "manifest.json") +manifest = json.load(open(path)) +manifest["files"].append({"path": "layout.json", "size": len(body), "sha256": hashlib.sha256(body).hexdigest()}) +json.dump(manifest, open(path, "w")) +PYL +"$script" "$tmp/set-layout/1024x3072x16x8" > "$tmp/out18" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "a plain-ELF set that lists its layout.json: rc 0" +check $(has "$tmp/out18" "3 file(s) in plain ELF form" && ! has "$tmp/out18" "MIXED FORMS" && echo ok || echo fail) \ + "... three kernels in one form, the JSON not counted" +# ... and the listed JSON is still held to its size and sha256 like any other entry +printf 'x' >> "$tmp/set-layout/1024x3072x16x8/layout.json" +"$script" "$tmp/set-layout/1024x3072x16x8" > "$tmp/out19" 2>&1 +check $([ $? -eq 1 ] && has "$tmp/out19" "layout.json: manifest says" && echo ok || echo fail) \ + "... but a listed layout.json that changed is still caught: rc 1" + +# 11. a layer directory with a suffix after its number (layer1_100np/) is still layer-indexed, not "other" +mkdir -p "$tmp/n-suffix/1024x3072x16x8" +python3 - "$tmp/n-suffix/1024x3072x16x8" <<'PYS' +import hashlib, json, os, sys +root, files = sys.argv[1], [] +for rel in ("layer1_100/layer1.elf", "layer1_101np/layer1.elf", "layer2_102np/layer2.elf"): + full = os.path.join(root, rel); os.makedirs(os.path.dirname(full), exist_ok=True) + body = b"\x7fELF" + rel.encode() + open(full, "wb").write(body) + files.append({"path": rel, "size": len(body), "sha256": hashlib.sha256(body).hexdigest()}) +json.dump({"format": 1, "set": "1024x3072x16x8", "files": files}, open(os.path.join(root, "manifest.json"), "w")) +PYS +"$script" "$tmp/n-suffix/1024x3072x16x8" > "$tmp/out20" 2>&1 +check $([ $? -eq 0 ] && echo ok || echo fail) "layer directories with a suffix: rc 0" +check $(has "$tmp/out20" "3 layer-indexed" && ! has "$tmp/out20" "other" && echo ok || echo fail) \ + "... all three counted as layer-indexed, none as other" + if [ "$fails" -ne 0 ]; then printf 'kernel_set_check: %d failure(s)\n' "$fails" exit 1