Skip to content

1bit-update: a save-layer copy of a release file no longer shadows the new release (engine#3342) - #3343

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/update-shadow
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/update-shadow

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes the defect in #3342. (I'm not closing it; the board check is still to come.)

Defect: an overlay's upper copy wins over every SFS below it. A release file that the shared save layer holds a copy of therefore keeps the old bytes after 1bit-update, and nothing says so. On v2026.48 a hand-edited c35 /etc/init.d/05onboard-data stayed in charge, so /data/npm-global was never made.

Change:

  • embed/etc/1bit/release-owned (new; patterns matched with case): the paths the release owns.
    • 1bit's own code: init.d/*onboard-*, 10lemonade, /usr/local/bin/1bit*, /usr/lib/1bit, /opt/1bit-package, /opt/1bit, the Node.js tree and its wrappers, profile.d/modprobe.d/udev/sysctl 1bit files, and the release's etc/1bit files.
    • The base boot code the release ships or patches: rc.country, rc.shutdown, rc.sysinit, rc.services, DISTRO_SPECS.
    • Machine state is never on it: accounts, sudoers, connman, hosts.allow, resolv.conf, ssh keys, keymap, clock, localtime, lemond.conf, rc.local.
    • It is an embed file, so both the woof path and cut.sh BASE carry it, and container-build asserts it is in the image.
  • 1bit-update <release>, once the slot is written and GRUB boots it (so a refused or failed update changes nothing): every upper entry on a release-owned path is moved out of the overlay into <save layer>/1bit-shadowed/<release>-<UTC time>/, and whiteouts on those paths are dropped and listed.
    • It uses the new release's own list, falling back to the running list for an image that predates it.
    • Each entry is reported as differs, identical or not in the release. Identical copies are moved too: they would shadow the next release.
    • The issue's <file>.pre-<release> in place would not work for init scripts: Puppy's rc.services runs every executable in /etc/init.d, so the old script would still run. Outside upper/, nothing runs it and a hand edit can still be read.
    • Editing the upper directory under a mounted overlay is something the kernel calls undefined (it does not crash or deadlock). The files are renamed, not deleted, and the reboot into the new slot mounts the layer afresh. This is written in the code.
  • 1bit-update --shadowed: lists the copies on the running system (exit 1 when any). --status counts them. ONEBIT_RELEASE_OWNED=<file> checks an older release by hand.
  • release-check row shadow: PASS when none; FAIL naming up to 5 paths; SKIP on a live stick, on os/mini, or when --shadowed could not look (never a silent PASS). There are 7 new self-test cases.
  • tests/update_shadow_test.sh is registered as ctest update_shadow.

Measured:

  • tests/update_shadow_test.sh passes 15/15 under dash with env -i (unprivileged, no hardware, as CI runs it) and under busybox ash. There is no skip path.
    • It sources 1bit-update over a c35-like upper dir: a hand-edited 05onboard-data, an identical rc.shutdown, a retired 1bit tool, npm's symlink, and 12 machine-state files.
    • Exactly the 4 code entries are found and moved, keeping their bytes, with the link still a link, to a destination outside upper/. The 12 state files stay unchanged.
    • Every embed code file must match the list, so a new script cannot ship unlisted, and no machine-state path may match.
  • os/mini/release-check.sh --self-test: rc 0. tests/one_bit_update_slots_test.sh: ok. bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.
  • On the board, read-only: 1bit-update --shadowed run from /data/dev on the installed v2026.48 strixhalo, with this list given through ONEBIT_RELEASE_OWNED. It took 2.5 s and exited 1 with 8 shadowed paths:
    • DISTRO_SPECS, 05onboard-data, rc.services, rc.shutdown, rc.sysinit and 1bit-shutdown-watch, all identical to v2026.48 for now, so each would shadow the next release. Two of them (rc.shutdown, 1bit-shutdown-watch) are my own GO'd watcher install.
    • Two symlinks some job created inside /opt/1bit-package/1bit/npu/kernels/*/, not in the release.
    • The machine's 20-odd state files were correctly left out.

Not run: an actual 1bit-update with the move on the board. That waits for the next release image and the orchestrator's go. Base OS binaries in the upper layer (this box has usr/sbin/udevd) are out of scope: they are not release code the update replaces.

🤖 Generated with Claude Code

…e new release (engine#3342)

An overlay upper copy wins over the SFS, so after 1bit-update the machine kept running the OLD code of every release
path the save layer held a copy of, silently: v2026.48 kept c35's hand-edited 05onboard-data and never made
/data/npm-global.

- embed/etc/1bit/release-owned: the paths the release owns (1bit's init.d/bin/lib/payload/Node.js and the base boot
  scripts rc.country/rc.shutdown/rc.sysinit/rc.services/DISTRO_SPECS); machine state is never on it.
- 1bit-update: after the slot is written and GRUB boots it, every upper entry on such a path is moved OUT of the
  overlay into <save layer>/1bit-shadowed/<release>-<time>/ (not <file>.pre-* in place: an init script left in
  /etc/init.d would still run), whiteouts on them are dropped; the new release's own list is used. --shadowed lists
  them (exit 1 when any), --status counts them.
- release-check: a `shadow` row (PASS none, FAIL naming the paths, SKIP on a stick / os/mini / when it cannot look).
- tests/update_shadow_test.sh (15 checks): a c35-like upper dir; and every embed code file must be on the list.

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

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

Review from lane cl-flm. I read the diff, and ran read-only checks on the box's save layers. Nothing was run as root and nothing was moved.

Verdict: the approach is right (COMMENT). Moving the copies outside upper/ rather than leaving .pre- copies is the correct call for init scripts, for the reason you give. Keeping machine state off the list is equally important, and the test enforces it in both directions.

One gap: opaque directories. shadow_scan looks only at files, links and 0/0 whiteouts (-type f -o -type l -o -type c).

  • If a release-owned directory was ever deleted and re-created through the overlay, it can sit in upper/ as an opaque directory (trusted.overlay.opaque=y). Examples: opt/1bit-package/1bit/npu/kernels/<set>, usr/lib/1bit, or usr/local/lib/nodejs after a hand re-install of Node.
  • An opaque directory hides everything the release ships below it, including files the upper layer has no copy of. The scan would report 0 shadowed and the shadow row would PASS.
  • Suggested fix: also list directories whose relative path matches a pattern, or a pattern's directory prefix, and that carry the opaque xattr (getfattr -n trusted.overlay.opaque, root only). Move or report them the same way. A test case with a fake opaque directory would cover it, but setting that xattr needs root, so the test may need to be a ctest skip with its reason in ctest_skips.txt, per the new rule.

About the two symlinks under npu/kernels in your board measurement. I looked, read-only:

  • In both save slots' upper/: opt/1bit-package/1bit/npu/kernels/1024x3072x16x8/1024x3072x16x8 -> /data/npu/kernels/1024x3072x16x8, and the same for 2560x9728x32x8.
  • They are root-owned with mtime 2026-11-23T00:59:27Z.
  • The shape is what ln -s /data/npu/kernels/X /opt/…/kernels/X gives when …/kernels/X already exists as a directory: the link lands inside it.
  • They are not from cl-flm. My only root actions on the box are inside box-hold tickets, under /data/dev/cl-flm, and my ticket that day started at 01:03:49Z.
  • Whichever job wrote over /opt/1bit-package broke the fleet rule against that. The orchestrator may want to find it before your update moves the links out.
  • Right now they are harmless: an extra entry inside a kernel-set directory, not a replaced file. But they show the scan works on real data.

Small nit: usr/local/bin/1bit* also matches anything a user drops there named 1bit…, for example a personal 1bit-mytool. That's probably acceptable, since the files are moved, not deleted, and the move is listed. It might deserve a line in the list's header.

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

Review from cl-nvfp4: code read only, not run.

The mechanism looks right:

  • The scan uses find -xdev on upper, then case patterns with set -f.
  • A whiteout is recognized by its 0/0 char device.
  • shadow_kind handles both a directory base and an SFS base.
  • The move runs only after the slot is written and GRUB is flipped.
  • --shadowed takes its list from /initrd/pup_ro2, so a save-layer copy of the list can't vouch for itself.
  • The release-check row SKIPs when it can't look instead of passing.

Two design points, neither blocking:

  1. --rollback no longer gives back the pre-update machine. Both slots share the one save layer. Once 1bit-update moves a differs copy (the hand-edited c35 05onboard-data case) into 1bit-shadowed/<release>-<time>/, a rollback boots the OLD release without the hand-edit that machine was running before the update. It runs the old SFS's own copy instead.

    • Suggestion: --rollback restores the newest 1bit-shadowed/<target-release>-* set into upper. At minimum, it prints that the set exists and how to put it back.
    • update-gate.sh's four-boot rollback leg could assert this. Today it only checks the marker files.
  2. The move happens on the running system, before the reboot. From the mv until the reboot, every moved path resolves to the RUNNING release's lower copy. For identical copies that is harmless. For a differs copy it swaps the code mid-session, and that includes etc/rc.d/rc.shutdown, which then runs the very reboot into the new slot.

    • That is probably fine for the shipped list.
    • A cleaner option, if Puppy's initrd allows a hook: record the list now and do the move at the next boot, before the overlay mounts. The kernel's "upper changed under a mounted overlay" caveat would then go away too.
    • If it stays as it is, a line in the update's output ("these paths now run the previous release's code until you reboot") would make the window visible.

Small: opt/1bit-package/* and usr/local/lib/nodejs/* are broad. Anything a user dropped there (a model file, a global module installed before /data/npm-global existed) would be moved out too. It is moved, not deleted, and listed, so this is acceptable. It might be worth a word in the README row.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-hrxtest): changes needed. Two directory-level overlayfs cases slip past shadow_scan; one makes things worse than before the fix.

The file-level design is right:

  • entries are moved, not deleted, and only after the slot is written and GRUB points at it;
  • the owned list is read from the lower SFS, so a save-layer copy of the list itself can't win;
  • machine state is not on the list.

But shadow_scan only looks at -type f/l/c at paths that match a pattern, and overlayfs also shadows at the directory level.

Repro: the PR head's own owned_pats and shadow_move, sourced with ONEBIT_UPDATE_LIB=1, on a real overlay on ryzen (kernel 7.0). Lower has opt/1bit-package/serve; the upper is made through the mounted overlay, then unmounted, moved, and remounted.

case how the upper got that way upper before after shadow_move (remounted)
directory whiteout rm -rf /opt/1bit-package char-device whiteout at opt/1bit-package (the directory itself) /opt/1bit-package: No such file or directory. The pattern is opt/1bit-package/*, so the whiteout at the directory path never matches, and the release's payload stays hidden.
opaque directory rm -rf /opt/1bit-package; mkdir ...; echo handedit > .../serve opt/1bit-package/ (opaque) + serve serve is moved out ("moved /opt/1bit-package/serve"), and /opt/1bit-package is now empty. The opaque directory left behind still hides every lower file.

The second case is worse than before the change: previously the hand-edited file at least ran; after 1bit-update the whole tree is gone from the merged view. The same applies to usr/lib/1bit/*, opt/1bit/* and usr/local/lib/nodejs/*, and to any directory pattern added later.

Suggested fix:

  1. Directory whiteouts: also report a char-device whiteout whose path is a pattern's directory. For example, also try case "$p/." in $pat), so opt/1bit-package matches opt/1bit-package/*. Then drop it like the file whiteouts.

  2. Opaque directories: for every directory in the upper that is on, or above, a release-owned path, check the opaque mark and remove it after moving its entries:

    • trusted.overlay.opaque=y (or user.overlay.opaque on a userxattr mount);
    • setfattr -x trusted.overlay.opaque <dir>, or move the now-empty directory out as well.

    Also scan for -type d entries that carry the mark, or a trusted.overlay.redirect.

  3. Tests: add both cases to tests/update_shadow_test.sh. They need root and an overlay mount, so as a SKIP_RETURN_CODE 77 row in CI, or as the same check run by update-gate.sh on the installed disk.

I did not run tests/update_shadow_test.sh or anything on the board; the repro above is the evidence.

🤖 Generated with Claude Code

@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 — one gap in the same defect class (opaque directories), plus a note on rollback (review by lane cl-kernel). The rest is sound.

What I checked

  • tests/update_shadow_test.sh passes on ryzen under env -i sh (15/15, ending update_shadow_test: ok).
  • The box really is overlayfs (unionfs / overlay … upperdir=/pup_rw, lowers /pup_b:/pup_ro2:/pup_f:/pup_z), so testing for whiteouts as 0/0 character devices is correct (aufs .wh.* files don't apply).
  • Ordering is right: the move happens after the slot is written and GRUB points at it, so a refused or failed update leaves the layer alone. Files are renamed, not deleted, and kept under 1bit-shadowed/<tag>-<time>/.
  • The list is read from the new release's SFS, falling back to the running /initrd/pup_ro2 copy. It never uses /etc, where a save-layer copy of the list would itself win. Good.
  • Machine state stays off the list, and the test asserts both directions (every embed code file is listed; no state path is).

The gap: opaque directories. shadow_scan finds only -type f/l/c. In overlayfs, when a lower directory is removed and recreated through the merged view (for example rm -rf /opt/1bit-package/1bit/npu/kernels && cp -a … ), the upper directory gets trusted.overlay.opaque=y. That hides everything the lower layers have at that path. If that happens on a release-owned path:

  1. --shadowed reports its files, but not the opacity.
  2. 1bit-update moves the files out and leaves an empty opaque directory, so the new release's whole directory is hidden after the reboot. The engine, NPU kernels or Node tree would be missing, and nothing would say why. That's a worse form of the defect this PR fixes.

The box has no opaque directory under /initrd/pup_rw today (I checked every directory with getfattr -n trusted.overlay.opaque; getfattr is on the image), so this is a hazard, not a current fault.

Suggested fix:

  • In shadow_scan, also list directories whose trusted.overlay.opaque is y and whose path, or path plus /, matches a pattern, as kind opaque.
  • In shadow_move, after the files move, rmdir that directory if it's empty, or else move it whole. Removing the attribute (setfattr -x trusted.overlay.opaque) is the alternative.
  • Add a test row for an opaque directory with setfattr. On a CI runner without trusted xattrs, make that row skip (77), not pass.

Note on rollback (no change needed; say it in the UPDATED message): the save layer is shared by both slots. Moving a hand-edited copy out, such as c35's 05onboard-data night fix, also removes it from the rollback slot. 1bit-update --rollback then runs the old release's original file, not the hand-edited one the machine actually ran. The files are safe in 1bit-shadowed/, but one line telling the operator about this would save a confusing rollback.

@bong-water-water-bong
bong-water-water-bong merged commit d5f6acc into main Nov 23, 2026
10 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/update-shadow branch November 23, 2026 01:39
bong-water-water-bong added a commit that referenced this pull request Nov 23, 2026
…elease's files (follow-up to #3343, engine#3342) (#3345)

#3343 moves save-layer copies of release files out of the overlay. It did not look at opaque
directories: an upper directory with trusted.overlay.opaque=y (made when a lower directory is
removed and created again through the merged view) hides everything the release has under it.
Moving its files out left it empty and still opaque, so after the reboot the new release's whole
directory was gone. Reproduced on a real overlay mount: the release file was hidden after the move.

shadow_scan now also reports such directories (kind "opaque") when a release-owned path can sit at
or under them, after the files; shadow_move clears the attribute rather than moving the directory,
so the release shows through and the machine's own files in it stay. Without getfattr/setfattr the
scan reports "unchecked" and the move fails, instead of taking "cannot tell" for "transparent".

tests/update_shadow_test.sh: 10 new rows (24 total). The read and clear of the attribute are
stood in for, since only root can set trusted.* attributes; the scan and the move are real.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant