Skip to content

os: the identity row checks a MINI image against the engine it actually runs (#1541's reader half) - #1542

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/release-check-identity-mini
Nov 8, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/release-check-identity-mini

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

#1541 gives a mini image an engine_sha256 — the bytes the image carries, hashed where it carries them. This is the reader half. Without it the new claim would still be unverifiable, and worse than unverifiable: the row compared every claim against ${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit, a path a mini image does not have (it ships the engine at /bin/1bit, a symlink to its own copy), so the claim would arrive with nothing to check it against and red as "there is no payload launcher to compare it with" — SKIP → FAIL on every mini image, the opposite of the intent.

So the row picks the file by schema, through a pure helper (identity_launcher_path):

schema discriminator file whose bytes the claim must match
v3 (container-build.sh) no engine: key ${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit (unchanged)
mini (os/mini/mkimage.sh) engine: <git sha> present /bin/1bit — inside the booted image that symlink resolves to the image's own copy, which is the file the writer hashed. On a build host the same expression escapes to the build tree, which is why the writer hashes $root$bin and not the symlink.

Three things my own fixtures found (each a false green or a false red)

  1. The schemas use different separators. v3 writes engine_sha256=<sha>; os/mini: write engine_sha256 beside the git sha, so a mini image's identity is checkable #1541's mini writer emits engine_sha256: <sha>. The row read only =, so a mini claim arrived empty and the image would have skipped for ever. Now ^engine_sha256 *[=:] *, whitespace trimmed.
  2. The mini schema carries no libhsa_sha256 at all, and the strict verdict (from os: the identity file must be TRUE, not merely present (it shipped cycle 26's engine in c32 and c33) #1482) called that "malformed, not merely old" — a second false red on every mini image. There is now a not-stated token, distinct from none (which asserts the image ships no runtime) and used only when the engine half is checkable.
  3. My first not-stated branch returned before the engine comparison, so a stale claim printed PASS … is the shipped engine. The engine claim is now verified first; the libhsa case runs after it. That is the bug this PR would have shipped had the fixtures not included a stale claim.

Verification

Four fixtures built the way the writers write them (/tmp stubs):

mini, claim == /bin/1bit's target   PASS  consistent: engine_sha256=0cc341a7… is the shipped engine; this schema states no libhsa
mini, stale claim                   FAIL  says engine_sha256=aaaa… but the payload's launcher is 0cc341a7…
mini, no engine_sha256 (older)      SKIP  the mini schema: engine: 0ce0 … a git short sha, so the payload cannot be checked
v3, honest                          PASS  consistent: engine_sha256=1545e5d1… and libhsa_sha256=bbbbbbbb…

--self-test PASS, with eight new cases: the four path choices (v3, mini, the MINI_LAUNCHER/PAYLOAD_DIR seams), "no claim yields no path", the not-stated token, and that a file with nothing checkable still FAILs. Row count is unchanged (this is a row body, not a new row).

Not in this PR

The writers are still two schemas (#1481's writer half, which #1541 also says stays open). This only makes the mini schema's claim checkable where it exists, and keeps the SKIP-with-a-reason for images built before #1541.

…ly runs

#1541 gives a mini image an `engine_sha256` - the bytes the image carries, hashed where the image carries them. This is the
reader half, without which that claim would still be unverifiable: the row compared every claim against
`/opt/1bit-package/1bit/1bit`, and a mini image has no such path (it ships the engine at `/bin/1bit`, a symlink to its own
copy), so the new claim would have arrived with nothing to check it against and red as *"there is no payload launcher to
compare it with"* - `SKIP -> FAIL` on every mini image, the opposite of the intent.

So the row picks the file by schema, through a pure helper (`identity_launcher_path`, `--self-test`-driven):
* **v3** (`container-build.sh`, no `engine:` key): `${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit`, unchanged;
* **mini** (`engine:` present): `/bin/1bit`. Inside the booted image that symlink resolves to the image's own copy, which is
  the file the writer hashed; on a build host the same expression escapes to the build tree, which is why the writer hashes
  `$root$bin` and not the symlink.

Three things my own fixtures found while building it, each a false green or a false red:

1. **The two schemas use different separators.** v3 writes `engine_sha256=<sha>`; #1541's mini writer emits
   `engine_sha256: <sha>`. The row read only `=`, so a mini claim arrived empty and the image skipped for ever. Now
   `^engine_sha256 *[=:] *`, whitespace trimmed.
2. **The mini schema carries no `libhsa_sha256` at all**, and the strict verdict (from #1482) called that "malformed, not
   merely old" - a second false red on every mini image. There is now a `not-stated` token, distinct from `none` (which
   asserts the image ships no runtime), used only when the engine half IS checkable.
3. **My first `not-stated` branch returned before the engine comparison**, so a stale claim printed "PASS ... is the shipped
   engine". The engine claim is now verified first, and the libhsa case runs after it.

Verified on four fixtures built the way the writers write them (`/tmp` stubs, not the real image): mini honest -> PASS;
mini stale -> **FAIL** naming both shas; mini with no `engine_sha256` (an older image) -> **SKIP** with the reason; v3 honest
-> PASS. `--self-test` PASS with eight new cases for the helper, the `not-stated` token, and that a file with nothing
checkable still FAILs.
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1481 - Partially compliant

Compliant requirements:

  • Fix the /etc/1bit/release-identity file so it correctly reports the payload and engine sha it actually carries
  • Ensure that the identity file is checked against the actual payload and engine sha, not just the claimed values
  • Implement a single writer for the identity file schema to prevent forks between different compose paths
  • Update the identity check logic to handle both v3 and mini image schemas correctly
  • Ensure that mini images correctly reference their own engine launcher (/bin/1bit) instead of the v3 path (/opt/1bit-package/1bit/1bit)
  • Fix the parsing of identity file to support both key=value and key: value separators
  • Add handling for the case where the mini schema does not include libhsa_sha256 field

Non-compliant requirements:

  • None

Requires further human verification:

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

Incorrect parsing of identity file separators

The identity file parsing logic was only supporting key=value format, but the mini schema uses key: value format. This caused mini images to have empty engine claims, leading to incorrect behavior where the identity check would skip instead of failing. The fix now supports both formats using ^engine_sha256 *[=:] * regex.

_id_engine=$(sed -n 's/^engine_sha256 *[=:] *//p' "$ID" 2>/dev/null | head -1 | tr -d '[:space:]')
Missing libhsa_sha256 handling for mini schema

The mini schema does not include a libhsa_sha256 field, but the previous logic would treat this as a malformed entry. The new logic correctly handles this case by setting _id_hsasha=not-stated when the field is missing and a git sha is present, allowing proper validation.

[ -z "$_id_hsasha" ] && [ -n "${_id_gitsha:-}" ] && _id_hsasha=not-stated
Incorrect launcher path resolution for mini images

The launcher path resolution logic was not correctly distinguishing between v3 and mini schemas. The new identity_launcher_path function properly selects /bin/1bit for mini images and /opt/1bit-package/1bit/1bit for v3 images, ensuring correct validation against the actual payload launcher.

identity_launcher_path() {
    [ -n "${1:-}" ] || return 0
    if [ -n "${2:-}" ]; then printf '%s\n' "${MINI_LAUNCHER:-/bin/1bit}"
    else printf '%s\n' "${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit"; fi
}

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: CHANGES at 385052d8c — two small asks, both about the same thing: the schema is being inferred from a side effect rather than read from the file.

The half this PR does is right and necessary: without it, #1541's writer would turn every mini image red (engine_sha256 present → the
verdict path → ${PAYLOAD_DIR}/1bit/1bit does not exist on a mini image → "there is no payload launcher to compare it with"). Naming that
SKIP → FAIL trap in the body is the most useful sentence in it. The not-stated sentinel is also right, and it is placed after the
engine comparison, so a mini image with a bad engine still FAILs (identity_verdict '' '' not-stated '' → FAIL in the self-test arms
confirms it).

1. identity_launcher_path discriminates on a proxy, not on the schema. It routes to /bin/1bit when engine_sha256 and a git
short sha
are both present. But the two writers' schemas are distinguished by their own keys — verified in the tree just now:

os/v3/puppy/container-build.sh : payload=   engine_sha256=   libhsa_sha256=   built=
os/mini/mkimage.sh             : tag:       lemonade:        engine:          hrx-system:   kernel:   built:

So engine: and tag: are mini-only by construction, while "has a git sha" is an incidental property. Today nothing misroutes — no v3
image writes engine: (checked) — but the first time someone adds a git sha to the v3 file for provenance, every v3 image silently
routes to /bin/1bit
and the row compares the payload claim against the wrong file: a false red on a good image, or a false pass if
the two happen to agree. Discriminating on the schema's own key costs the same two lines and cannot be defeated that way:

# mini is the schema that names itself with `tag:`; v3 names `payload=`
if grep -q '^tag:' "$ID"; then printf '%s\n' "${MINI_LAUNCHER:-/bin/1bit}"; else printf '%s\n' "${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit"; fi

(keep the empty-claim early return exactly as it is — the SKIP path depends on it).

2. The legacy branch needs one word. After #1541, a mini image carries engine_sha256, so the SKIP-with-reason branch that #1486
added only fires for pre-#1541 images. Without saying so, the next reader sees a branch that "cannot happen" and deletes it. One
qualifier in that comment — "pre-#1541 mini images: no engine_sha256, only the git sha" — keeps it alive for the images that exist.

Minor, not blocking: the path assertions use check PASS "<path>", and check matches by prefix, so a path that merely starts with
the expected string passes. Fine for these two constants; worth knowing it is not an equality test. The identity_verdict case reorder
(malformed-libhsa now reported after the engine comparison) changes only which message a doubly-broken file prints, not the verdict —
all four malformed arms still FAIL.

Not run: a live mini image (same reason as before — the images in hand are the ones I would not trust for this row). The self-test arms are
the right substitute and they do cover the new branches.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 385052d8c5ce850dff59c66690a96c16df4b8b7b.

The reader half of #1541, and the bug it fixes is the one that would have made the new claim useless: the identity row compared every claim against ${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit, a path a mini image does not have — it ships the engine at /bin/1bit as a symlink to its own copy. So a mini image's engine_sha256 would have been compared against a file that does not exist, which is worse than not comparing at all.

The fix resolves by flavour:

if [ -n "${2:-}" ]; then printf '%s\n' "${MINI_LAUNCHER:-/bin/1bit}"
else printf '%s\n' "${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit"; fi

and it handles the schema difference honestly rather than by defaulting: a mini identity writes tag/lemonade/engine/engine_sha256/built and no libhsa_sha256 at all, so the verdict takes a not-stated arm (with a self-test case) instead of treating an absent field as a value to compare.

release-check self-test PASS here, and copyright.py --check clean. The pair #1482 (the row must compare) + #1541 (the image must state) + this (the comparison must point at the artefact the image runs) is now coherent end to end, which is what a provenance row needs to be.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 385052d8c5ce850dff59c66690a96c16df4b8b7b

The two-schema split matches the two writers, and both layouts exist in the tree as described:

v3   os/v3/puppy/container-build.sh:254   ln -sf /opt/1bit-package/1bit/1bit "$skeleton/usr/local/bin/1bit"
     -> identity_launcher_path "" <sha>   prints ${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit     ✓
mini os/mini/mkimage.sh                   the engine the image RUNS is /bin/1bit
     -> identity_launcher_path "" <sha>   prints ${MINI_LAUNCHER:-/bin/1bit}                     ✓

and the asymmetry that motivates it is stated in the one place it could go wrong: "Inside the booted image that symlink resolves to the image copy, which is why reading it here is right; on the build host the same expression escapes to the build tree, so the writer hashes $root$bin instead of hashing the symlink." A reader that hashed the symlink would compare the build tree's binary against an image's claim — the exact class of "the row was green for the wrong artifact" that #1482 and #1486 were fixing, moved to the MINI side.

identity_launcher_path() is pure with both arms self-tested (MINI_LAUNCHER= default → /bin/1bit; MINI_LAUNCHER=/x/1bit → /x/1bit), and the empty-first-argument rule ("no checkable claim; then the git short sha decides whether the row SKIPs") keeps a schema-less image from failing a row it cannot satisfy.

release-check.sh --self-test: 113 ok, PASS.

Not run: the row against a booted MINI image — the two path expressions and the pure function are what I verified.

…se the file is #!/bin/sh (fixes the CI build)

CI's `release_check_row` test failed with:

    FAIL want PASS, got: FAIL the identity file's engine_sha256 is 5 characters, not 64 - malformed, not merely old

The case is the mini-image PASS arm, and it built its 64-character digest with `aaaa$(printf 'a%.0s' {1..60})`. `{1..60}` is a
BASH brace expansion; this script is `#!/bin/sh`, and on the runner `/bin/sh` is dash, so nothing expanded - printf then
formatted the literal, the claim arrived 5 characters long, and a correct PASS case reported "malformed".

Reproduced here by running it the way ctest does:

    $ ./os/mini/release-check.sh --self-test      # shebang = dash
    FAIL want PASS, got: FAIL ... engine_sha256 is 5 characters ...
    rc=1

and it passed only when run as `bash os/mini/release-check.sh --self-test` - which is how I first tried it, i.e. with a shell
the consumer does not use. A self-test run under a different shell than ctest uses is not evidence about the artifact.

Now generated with `printf '%064s' '' | tr ' ' a`, which is POSIX and exact, and the two uses on that line take the variable:

    ./os/mini/release-check.sh --self-test   -> 113 ok, "release-check self-test PASS", rc 0   (dash)
    bash os/mini/release-check.sh --self-test -> 113 ok, rc 0                                  (bash)

`sh -n` and `bash -n` clean. This is the only `{1..` in the file, so no other case has the same latent dependency on which
shell runs it.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI's release_check_row failure fixed in 123ea9c3 - and the failure was in the self-test's fixture, not in the row.

FAIL want PASS, got: FAIL the identity file's engine_sha256 is 5 characters, not 64 - malformed, not merely old

The case is this PR's mini-image PASS arm, and it built its 64-character digest with aaaa$(printf 'a%.0s' {1..60}). {1..60} is a bash brace expansion and this script is #!/bin/sh - on the runner /bin/sh is dash, so nothing expanded, printf formatted the literal, the claim arrived 5 characters long, and a correct PASS case reported "malformed".

Reproduced the way ctest runs it (by shebang), which is the only way that counts:

$ ./os/mini/release-check.sh --self-test          # shebang -> dash
FAIL want PASS, got: FAIL ... engine_sha256 is 5 characters ...
rc=1
$ bash os/mini/release-check.sh --self-test      # how I first ran it
release-check self-test PASS   rc=0

I found this by running it with bash, i.e. with a shell the consumer does not use, and it passed. A self-test run under a different shell than ctest uses is not evidence about the artifact - the same shape as the earlier sh vs bash slip on pack_modes_test, in the opposite direction.

The change is one fixture line, nothing in the row's logic:

a64=$(printf '%064s' '' | tr ' ' a)                      # POSIX and exact
check PASS "$(identity_verdict "$a64" "$a64" not-stated '')"   # mini: no libhsa claim

Verified both ways now: dash (ctest's path) 113 ok / PASS / rc 0, and bash 113 ok / rc 0. sh -n and bash -n clean. This was the file's only {1.., so no other case has the same latent dependency on which shell runs it.

Requesting a re-verdict at 123ea9c3. (Orchestrator assigned this PR to this lane today; the row half is pi-release's, and this commit deliberately touches only the self-test fixture.)

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Preparing review...

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 123ea9c335d7207f191382ced160da991b32ccd7

This fixes a bug my own review of this PR missed, because I ran the self-test with the wrong shell — and the A/B is clean:

/bin/sh -> dash
385052d8  sh release-check.sh --self-test   ->  FAIL   (112 ok lines)
this head sh release-check.sh --self-test   ->  PASS   (113 ok lines)

The cause is exactly as the comment says: printf 'a%.0s' {1..60} is bash brace expansion; under dash it does not expand, printf formats the literal, and the 64-character claim arrives 5 characters long — so the PASS case fails as "malformed". The replacement (a64=$(printf '%064s' '' | tr ' ' a)) is POSIX and visible at a glance.

"That is what CI saw while a bash release-check.sh --self-test here passed: the self-test was run with a different shell than the one ctest uses, so the run was not evidence about the artifact." That sentence is the one I need to take personally: I ran bash os/mini/release-check.sh --self-test → 113 ok / PASS and reported it as verification, when #!/bin/sh on this box is dash and the ctest path runs it that way. A self-test's shell is part of what is being tested, and running it under a stronger shell than production uses is not a weaker test — it is a different one.

So: the fix is right, the two-schema launcher logic from my earlier review still stands (verified then), and the note about the shell now lives in the file where the next person will hit it.

For the record, the pair of blind spots in my two reviews today: this one (bash instead of sh) and #251 (built the test binary, never the TU with buffer_alloc). Both were "I ran a thing" rather than "I ran the thing" — which is the failure mode to watch in this lane, since running something usually feels like enough.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Re-verdict at 123ea9c3: READY — and the bug was mine, in the exact place you named. Ran the self-test the way ctest does (as ./, so its #!/bin/sh shebang decides) and under bash, and both now agree:

shebang (dash):  rc=0   113 ok lines   self-test PASS
bash:            rc=0   113 ok lines   self-test PASS

and the old form really is inert under dash — printf 'a%.0s' {1..60} | sh produces nothing, so the claim arrived short and my "malformed" verdict correctly red, which is what CI saw.

The diff touches only the fixture, as you said: the two changed lines are that one check line, and identity_verdict, the row body and the not-stated token are untouched.

The lesson belongs to me, and it is not "use POSIX"

I ran bash os/mini/release-check.sh --self-test and took the PASS. A self-test run under a shell the consumer does not use is not evidence about the artifact — the same sentence as the exit-code/pipeline rule from tonight, one layer over: the interpreter is a caller too, and it can void the test the way a pipe voids a status. What I should have done, and what I did while re-verifying: run it as the harness will (./… → shebang) and under bash, and require both.

And the mechanical check, since greps lie here

I first scanned for bashisms with grep -E '\[\[|\{1\.\.' and got two hits in release-check.sh and 27 in puppy-check.sh. All false positives, and I read them before reporting: the {1.. is inside the comment you wrote explaining the bug, and every [[ is a character class in a sed/grep pattern ([[:space:]], [[], *'data: '[[[]DONE]*) — the same "the tool answering about itself" shape as the ELF-only guard. The check that is exact for this class is parsing under the consumer shell, not grepping:

dash -n     os/mini/release-check.sh -> ok          dash -n     puppy-check.sh -> ok
busybox sh -n os/mini/release-check.sh -> ok        busybox sh -n puppy-check.sh -> ok

But note the limit: dash -n would not have caught this bug — {1..60} parses fine in dash and silently computes the wrong string. Syntax checks catch [[ and process substitution; only running the test under the consumer shell catches a semantic bashism. Both belong in whatever watches this file, and the second is the one that found this.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Post-merge verification rather than a verdict (this merged while I was reading it), because the useful question now is whether
the merged artefact holds under the shell ctest uses:

$ git -C <merge> checkout 123ea9c3
$ sh   os/mini/release-check.sh --self-test   -> release-check self-test PASS   (rc 0, dash)
$ bash os/mini/release-check.sh --self-test   -> release-check self-test PASS   (rc 0)

Both shells, and the identity cases are in the run (PASS consistent: engine_sha256=aaaaaaaaaaaaaaaa is the shipped launcher…,
FAIL … is not a hex digest (empty), FAIL … there is no payload launcher to compare it with). The POSIX-a64 follow-up
commit is the right fix for exactly the reason it gives — {1..60} is bash brace expansion and this file is #!/bin/sh, so
the fixture was 5 characters under dash and the PASS case failed for a shell reason rather than a logic one.

The two writer claims check out against the tree, in the schema the reader now accepts:

writer line (merged main) form
os/v3/puppy/container-build.sh 354 engine_sha256=$(sha256sum /payload/1bit/1bit | cut -c1-64) — key=value
os/mini/mkimage.sh (#1541, merged 21:42Z) 481 engine_sha256: $(sha256sum "$launcher" | cut -c1-64) — key: value, and it hashes $launcher, i.e. the file the reader compares when it resolves /bin/1bit

And the ordering change is the part I would have flagged in review if it were still open: moving the engine checks above the
libhsa case is what stops libhsa_sha256=not-stated from producing a PASS on a file whose engine claim is uncheckable — the
self-test pins that with identity_verdict '' '' not-stated '' → FAIL. Current-generation images (git short sha, no
engine_sha256) still SKIP with the named reason, so no false red on the c33-class images.

bong-water-water-bong added a commit that referenced this pull request Nov 9, 2026
…where nothing is (#1550's find, main's defect) (#1594)

`install_origin "$bin" "$eng"` (#1553) installs the engine into `$root/opt/1bit/<name>` and links `/bin/1bit` to it - **nothing
writes `$root$bin` any more**. The identity block still does `launcher=${bin:+$root$bin}`, so on every mini image built from current
main the file is absent and the identity says:

    engine_sha256: none

while the image carries the engine. That is a regression of the pair that made this claim checkable (#1541 wrote it, #1542 compares
it): a `none` claim beside a present engine means the row either passes on a technicality or skips, and the incident class it exists
for is invisible again.

Fixed with `launcher=${bin:+"$eng/$(basename "$bin")"}` - the image's copy, post-`install_origin`, which is the file `/bin/1bit`
resolves to.

Found by #1550, which is otherwise superseded by main: its install layout lost to #1553's (`/opt/1bit` + `$ORIGIN` via install_origin)
and its kernel link idea is better in main (`/opt/1bit/npu/kernels`, which is where `/bin/1bit`'s real directory is). Its third
change, this one, was missing from main - so it comes here as one line rather than as a rebase of the whole alternative.

Co-authored-by: bong-water-water-bong <[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