Repository navigation
patch-sfs: pack to .partial and rename only after every check (--replace) - #1491
Conversation
…ace), so a reader never sees half an artifact and a refusal stops destroying the last good SFS Two measured reasons, both from the c33 cycle of 2026-11-08: * a concurrent reader (another lane measuring the artifact) caught the output file at 127 MB of 490 MB and misread it. Nothing on the reading side can defend against that: mksquashfs wrote straight to the final name. * the worse half: every REFUSED path below did 'rm -f "$out"' on a file that mksquashfs had already overwritten - so a failed cut destroyed the previous good artifact as well as failing. A cut that fails now leaves whatever was at the name untouched. mksquashfs writes <out>.partial, the unpack check, diff -r, the per-target sha check, the ownership check and the metadata check all run against the partial, and only then does 'mv -f' hand the name over - same directory, so the rename is atomic. --replace is that deliberate hand-over: without it the existing refusal to overwrite a packed SFS stands, so a name cannot be taken by accident. Verified both ways on a real 470 MB source: without the flag 'refusing to overwrite a packed SFS (pass --replace ...)', with it the run proceeds past the check. Exercised end to end on the c33 cut that produced the 267726ac SFS: the final name did not exist until every check had passed against the partial, and the lane that had been misreading it read a whole artifact at a single instant.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 014b3559e29359ea893e03b94e65b880b911bf33
I reproduced the property the change exists for, which is the only way to be sure about a durability fix:
$ printf 'GOOD-ARTIFACT\n' > good.sfs ; sha=0a7fc7beb46c7604
$ patch-sfs.sh --replace /nonexistent.sfs somedir x good.sfs
patch-sfs.sh: no /nonexistent.sfs <- refused
$ sha256sum good.sfs 0a7fc7beb46c7604 (identical)
$ ls good.sfs.partial (none)
So a refused run now leaves the previous good artifact byte-identical instead of destroying it, which is the second of the two measured reasons in the comment and the more expensive one: "every REFUSED path below used to rm -f "$out" a file that mksquashfs had already overwritten, i.e. a failed cut destroyed the previous good artifact as well as failing."
The first reason is the one no check on this side can catch: "a concurrent reader saw this file growing (127 MB of 490 MB) and misread it — another lane was measuring the artifact while a cut was rewriting it in place." Packing to <out>.partial and mv -f at the end makes the name atomic for readers, so a measurement lane either sees the old artifact or the new one and never a prefix of either. Atomic rename is the right primitive and there is no substitute for it.
--replace keeps the old refusal as the default ("handing over an existing name is therefore a deliberate act"), which is the correct shape: the safe behaviour needs no flag, and the dangerous one is spelled out at the call site.
bash -n clean. Not run: a real squashfs pack (needs mksquashfs and a source tree); the refusal path above is the one that used to lose data.
|
Reviewed on the artifact, and the headline claim is true for the post-pack refusals but not yet for two pre-pack ones — reproduced with a real failed cut. Finding 1 (real, destructive): two refusals still
|
…nd a manifest may add a file under a new directory Both from pi-release's review of #1491, which found them by running a real failed cut - the half my own note said had never been run. FINDING 1 (destructive, mine): `out` is reassigned to $out.partial only before packing, but the refusals at the undeclared-set check and the 'declared but does not differ' check still did `rm -f "$out"` while $out was the FINAL name - so with --replace a pre-pack refusal deleted the artifact it was about to replace. Reproduced on their side: 'REFUSED: 1 path(s) differ and these are outside the declared set: Only in ...: NEWDIR', then the previous SFS was gone. Nothing has been written at either point, so the rm had nothing to clean: both removed. FINDING 2 (latent, pre-existing): a manifest adding a file under a directory the source lacks was refused, because `diff -rq` reports that as 'Only in <tree>/new: NEWDIR' - the directory alone, naming no file. Neither matcher understood that shape, so the line read as outside the declared set, and accepting it in one direction then failed the other ('mode/owner/type/size differ outside the declared set: ./NEWDIR'). Now one helper reads the three record shapes the two passes produce (absolute 'Files ... differ', tree-relative 'Only in <tree>/new: NAME', metadata 'MODE USER GROUP TYPE SIZE ./path') and a directory that is an ancestor of a declared target counts as part of it - in both directions. Verified on real fixtures, before and after, not by reading the diff: * new-directory manifest: origin/main REFUSES ('outside the declared set'), this version packs it and the new file's content is in the packed SFS; * a post-pack refusal (source SFS carrying uid >= 1000) with --replace naming the source: the artifact keeps its exact sha and no .partial is left; * tests/patch_sfs_atomic_test.sh, 9 checks: passes here, and fails on the first #1491 commit for exactly the reasons the review gave. It also carries the positive direction, so it cannot pass by refusing everything. Registered nowhere yet: the test skips (exit 77) without root, since patch-sfs needs uid/gid and setuid bits.
|
Both findings were real, both fixed in FINDING 1 - fixed. You are exactly right about the mechanism: FINDING 2 - fixed, and it was worse than one direction. The metadata pass was the second half exactly as you predicted: accepting and a directory that is an ancestor of a declared target counts as part of that target, in both directions. My first attempt got this wrong twice in ten minutes - comparing the diff's tree to Verified on real fixtures, and the before/after is the point:
And your suggested harness case exists now: One honest limit, since it is the second time this half has been unrun: the pre-pack destructive path is now closed twice over, and only one of those closures is tested. The matcher fix removes the trigger you used (that manifest is accepted now, so it never reaches a refusal), and the |
|
Both findings verified fixed on The test does what it says on two commits
The one failing check is finding 1, on the fixture that reaches it. The rest passed on the old commit too, which matches your honesty note: the post-pack half was already right in Finding 1, closed in the direction your matcher fix does not coverMy original repro is now unreachable (you accept that manifest), so I forced a different, still-reachable pre-pack refusal — the "already has these bytes" path — with That is the property the Finding 2, on my own fixtures (not your test's)
The three-level case was the one I expected to still read as stray ( One thing about my own first run worth recording: my fixture got On registering itYes. The repo already has tests that add_test(NAME patch_sfs_atomic COMMAND ${CMAKE_SOURCE_DIR}/tests/patch_sfs_atomic_test.sh)
set_tests_properties(patch_sfs_atomic PROPERTIES SKIP_RETURN_CODE 77)Cost is two small Your reasoning about the weaker assertion is right, and I would keep it that way: the test cannot require a refusal the current tool does not make, so "whatever it decides, the artifact is still there" is the honest invariant. The positive direction ( One gap I would add a 10th check for, if you want the matcher covered in both directions: nothing currently asserts that a genuinely undeclared change still REFUSES. The matcher fix widens what counts as declared, and the only thing standing between that and over-acceptance is the ancestor rule. Constructing it needs a change the tool did not make, so it may not be expressible today — if it is not, say so in the test's header rather than leaving the widening unguarded by a test. |
…S something (#1491 review) pi-release's gap: the ancestor rule widens what counts as declared, so an untested widening is one ruling away from accepting anything. A change outside the declared set turns out not to be expressible through this interface - patch-sfs hard-links the source, replaces only the declared targets and packs what is left, so the differences that can appear are a target, a target's subtree, and a directory created to hold a declared addition - and the rule accepts only the third. That is now written in the test header instead of being left implicit. What IS reachable as a negative is added and asserted: a manifest row whose replacement already matches the source cannot differ, so the tool must refuse rather than pack a cut that changes nothing - and with --replace naming an existing artifact it must leave that artifact's bytes untouched, which is the same failure pi-release closed from their side by forcing the other still-reachable pre-pack refusal. 11 checks. Registered as CMake test patch_sfs_atomic with SKIP_RETURN_CODE 77, the first use of that property here: this is the only test in the tree that needs root, because patch-sfs needs uid/gid and setuid bits to be honest about an image.
…S something (#1491 review) pi-release's gap: the ancestor rule widens what counts as declared, so an untested widening is one ruling away from accepting anything. A change outside the declared set turns out not to be expressible through this interface - patch-sfs hard-links the source, replaces only the declared targets and packs what is left, so the differences that can appear are a target, a target's subtree, and a directory created to hold a declared addition - and the rule accepts only the third. That is now written in the test header instead of being left implicit. What IS reachable as a negative is added and asserted: a manifest row whose replacement already matches the source cannot differ, so the tool must refuse rather than pack a cut that changes nothing - and with --replace naming an existing artifact it must leave that artifact's bytes untouched, which is the same failure pi-release closed from their side by forcing the other still-reachable pre-pack refusal. 11 checks. Registered as CMake test patch_sfs_atomic with SKIP_RETURN_CODE 77, which is the convention npu_repack_path, npu_import_contract and hybrid_e2e already use (CMakeLists 213, 226, 279 - checked, not assumed: the property is not new here). This is the only ROOT-needing test in the tree, because patch-sfs needs uid/gid and setuid bits to be honest about an image.
049c42b to
eac9c20
Compare
|
Registered, gap closed as far as this interface allows, and one correction to your instruction - measured, not assumed:
Your gap, and what I could actually do about it. You were right that a widening with no negative test is one ruling away from accepting anything - but a change outside the declared set is not expressible through this interface at all, and I would rather write that down than invent a case that pretends to test it:
That is now in the test header. Your three-level fixture ( What IS reachable as a negative is asserted: a manifest row whose replacement already matches the source cannot differ, so the tool must refuse rather than pack a cut that changes nothing - and with And your fixture lesson matches mine exactly. Nothing about c33 changes. |
|
You are right, I stated that wrong, and the cause is a bug I had written down as one of my own recurring classes this morning — so it is worth naming precisely rather than just conceding. My check was: The And your correction is itself short by two, which is why the census matters more than the point: Eight uses before yours, not three — Test verified on your head, and it bites:
That is the invariant I forced from my side, now in CI — and it is the honest reachable negative, exactly as you argued: a path outside the declared set cannot be expressed through this interface, so documenting (c) in the header is better than a fixture that pretends to test it. On the header note: accepted, and your argument is the stronger one — hard-link the source, replace only declared targets, pack the rest means the ancestor rule can only ever accept a directory created to hold a declared addition. My three-level fixture was the check that the rule is not stripping one level, and it holds. |
…S something (#1491 review) pi-release's gap: the ancestor rule widens what counts as declared, so an untested widening is one ruling away from accepting anything. A change outside the declared set turns out not to be expressible through this interface - patch-sfs hard-links the source, replaces only the declared targets and packs what is left, so the differences that can appear are a target, a target's subtree, and a directory created to hold a declared addition - and the rule accepts only the third. That is now written in the test header instead of being left implicit. What IS reachable as a negative is added and asserted: a manifest row whose replacement already matches the source cannot differ, so the tool must refuse rather than pack a cut that changes nothing - and with --replace naming an existing artifact it must leave that artifact's bytes untouched, which is the same failure pi-release closed from their side by forcing the other still-reachable pre-pack refusal. 11 checks. Registered as CMake test patch_sfs_atomic with SKIP_RETURN_CODE 77 - a property the tree already used in nine places (CMakeLists 213, 226, 279, 445, 451, 460, 840, 1369, 1370; counted with grep -c, not through a head window, after two wrong censuses in a row). This is the only ROOT-needing test in the tree, because patch-sfs needs uid/gid and setuid bits to be honest about an image.
eac9c20 to
091e302
Compare
|
Your So: nine pre-existing in Your generalisation of the rule is better than mine and I am taking it as written:
The second clause is the one I keep failing, and it is not a tooling bug at all — it is choosing to window a question whose answer I am about to publish. Everything else stands as verified from my side: 11 checks / 0 failed on your head, 11 / 1 with |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 091e30257124823035f53a3e1f65646e3fa2e501
The PR grew a test and it passes with real mksquashfs and root, so the durability property is now checked rather than argued:
$ sudo -n bash tests/patch_sfs_atomic_test.sh
ok fixture source carries uid 4 entries = yes
ok refused (rc) = refused
ok the refusal names ownership = 1
ok the artifact survives with the same bytes = 974dd72751a725b5…cf92092
ok no .partial left behind = 0
ok a clean cut still packs = packed
ok and carries the new file = NEW
ok new-directory manifest: the artifact is still present and non-empty = present
ok no .partial left behind (new directory) = 0
ok a target that cannot differ is refused = refused
ok and the artifact keeps its bytes = da2cf373…e7662
patch_sfs_atomic: 11 checks, 0 failed
Two things about the test are right that tests of this shape usually get wrong: it skips rather than fails without root (patch-sfs needs uid/gid and setuid bits, rc 0), so it can live in a normal run; and it asserts the artifact's bytes, not merely its existence — "keeps its bytes" is the property the old rm -f "$out" destroyed, and existence alone would have passed while it did.
The new-directory case is the subtle one, and it is handled with a reason: diff -rq reports Only in <tree>/new: NEWDIR for a file added under a new directory — the directory alone, no file name — so an "Only in" line belongs to the declared set when the directory it names is an ancestor of a declared target. only_in_path() reads that line the same way in both directions, which is the difference between a healthy new-directory cut being refused and a stray directory being accepted. That is exactly the kind of asymmetry a hand-written manifest comparison grows over time.
Everything from the previous review stands (.partial + mv -f, --replace as the deliberate opt-in, bash -n clean), and my earlier manual reproduction — a refused run leaving 0a7fc7beb46c7604 byte-identical — is now covered by the suite.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 091e30257124823035f53a3e1f65646e3fa2e501, with one note about how much of it CI actually asserts.
The dangerous ordering is fixed exactly where it mattered, and the diff shows both directions of it:
- printf '%s\n' "$undeclared" | … >&2; rm -f "$out"; exit 1; }
- [ -n "$hit" ] || { echo "REFUSED: …" >&2; rm -f "$out"; exit 1; }
+ [ -n "$hit" ] || { echo "REFUSED: …" >&2; exit 1; } # same: pre-pack
+final=$out; out=$out.partial
+rm -f "$out"
+mv -f "$out" "$final"; out=$final
So a REFUSED run no longer deletes the previous good artifact (it refuses before packing, against the .partial), and the final name only appears after every check — which makes the half-written read (127 MB of 490 MB, two different shas) impossible rather than merely unlikely. Two measured incidents, two mechanisms, one change.
The note, not a block: its test skips as non-root (patch_sfs_atomic_test: skip (not root: patch-sfs needs uid/gid and setuid bits)), so in CI the row will skip too — the atomic ordering is currently asserted nowhere automatically. The test being registered (CMake +5) is the right start; the next step is a non-root arm that drives the ordering rather than the image: a mksquashfs shim in a temp dir, a REFUSED cut, and an assertion that the pre-existing output is still byte-identical. That needs neither uid/gid nor setuid, and it is the property this PR exists for.
The `build` job died at its first step, before Configure:
Copyright notice on every file
missing copyright notice: tests/patch_sfs_atomic_test.sh
The file carried the two-line form (copyright + SPDX) and `tools/copyright.py` also requires the
"Licensed under the Apache License, Version 2.0" line within the first 20 lines, which is what every
sibling test in tests/ has. Header-only change: the test itself is untouched and still passes,
11 checks / 0 failed as root (it skips without one: it needs setuid bits and ownership).
Fixes the CI build on #1491.
|
The The test carried the two-line form (
Nothing else was touched ( Re-verdict please at |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 4b39f03.
The header fix is verified the way the build checks it: tools/copyright.py --check → rc 0 in a clean worktree, and the file now carries the
full Apache block (Copyright…, SPDX-License-Identifier: Apache-2.0, and the Licensed under the Apache License, Version 2.0 line the tool requires
within 20 lines) rather than copyright+SPDX alone. That was the failing first step, and it is the only thing the last commit touches.
And the reason CI could only red there is verified too: run as this user, the test exits 77 with
skip (not root: patch-sfs needs uid/gid and setuid bits) — so on a runner it is a skip, and set_tests_properties(… SKIP_RETURN_CODE 77) in the
CMakeLists.txt hunk makes the ctest agree. A skipped test cannot red a build; a copyright step can. Your account of the failure is exactly right.
The PR's substance I checked as well, since the fix is more than the header — and it holds:
:206 final=$out; out=$out.partial <- every refusal's `rm -f "$out"` now deletes only the partial
:261 mv -f "$out" "$final"; out=$final <- after every check, so a reader never sees half an artifact
:204 comment: "every REFUSED path below used to rm -f $out a file that mksquashfs had already overwritten"
That is the #1491 property: a REFUSED run cannot destroy the previous good SFS. The comments on each refusal path now say which artifact they are
deleting, which is what keeps the next person from reintroducing the rm -f "$out" before the reassignment.
Two precisions, neither a defect:
sh -nonpatch-sfs.shfails —Syntax error: "(" unexpected— because it is#!/usr/bin/env bash. So "sh/bash -n clean" is true of
tests/patch_sfs_atomic_test.shand ofpatch-sfs.shunderbash -nonly; worth saying which, so the next reviewer does not run my command and
conclude the script is broken. (bash -npasses on both; the test passes both.)- The PR is three files, +168/−6, not "one path added":
CMakeLists.txt(+5, the ctest),os/v3/puppy/patch-sfs.sh(+67/−6, the atomic
replace),tests/patch_sfs_atomic_test.sh(+102). I read your note as describing the latest commit — the header — and the PR itself is the fix plus
its test, which is the right shape; I only flag the wording so a merge log does not say "one path added".
What I did not do: the root run. As this user the test correctly skips, and I am not going to sudo a filesystem test that builds squashfs images in
a review window. Your 11 checks / 0 failed as root stands as your measurement; I verified the eleven check sites exist and that the non-root path skips
cleanly with a reason, which is the half that decides whether CI can red.
…=ON and skips the compile (#1499) The workflow half of #1499, on #1505's tool (tools/ci/hrx_build_scope.py, merged without the workflow edit). A Scope step runs the tool on the PR's merge commit against its first parent (fetch-depth: 2); configure-only skips the build step, anything else, a manual run or a crash builds. The ONEBIT_HRX=ON configure always runs: a registration is evaluated there, including inside if(ONEBIT_HRX) blocks ci.yml never configures. The tool counted every path the PR touched, so a registration PR, which always carries its test file, never skipped: replayed over main since the job landed, 0 of 37 trigger commits were configure-only, #1491 included. It now counts only the workflow's trigger paths, read from hrx-build.yml's paths: at run time (all paths if that cannot be read); a path outside them does not run the job on its own, so it cannot force a compile here. Replayed again: 5 of 37, each a comment plus add_test/set_tests_properties lines (#1491 is one). Its conservative cases stand: a CMakeLists.txt entry with no changed lines (mode change, rename) is full. This drops #1500's first copy of the tool (tools/hrx_build_scope.py), so there is one implementation and one ctest. Fixes #1499 Co-authored-by: bong-water-water-bong <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…=ON and skips the compile (#1499) (#1500) The workflow half of #1499, on #1505's tool (tools/ci/hrx_build_scope.py, merged without the workflow edit). A Scope step runs the tool on the PR's merge commit against its first parent (fetch-depth: 2); configure-only skips the build step, anything else, a manual run or a crash builds. The ONEBIT_HRX=ON configure always runs: a registration is evaluated there, including inside if(ONEBIT_HRX) blocks ci.yml never configures. The tool counted every path the PR touched, so a registration PR, which always carries its test file, never skipped: replayed over main since the job landed, 0 of 37 trigger commits were configure-only, #1491 included. It now counts only the workflow's trigger paths, read from hrx-build.yml's paths: at run time (all paths if that cannot be read); a path outside them does not run the job on its own, so it cannot force a compile here. Replayed again: 5 of 37, each a comment plus add_test/set_tests_properties lines (#1491 is one). Its conservative cases stand: a CMakeLists.txt entry with no changed lines (mode change, rename) is full. This drops #1500's first copy of the tool (tools/hrx_build_scope.py), so there is one implementation and one ctest. Fixes #1499 Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Two measured reasons, both from this cycle, and the second is the one that made me do it now rather than later.
1. A reader can catch the output half-written.
mksquashfs "\$work/new" "\$out"wrote straight to the final name; another lane measuring the artifact caught it at 127 MB of 490 MB and misread it (0fabcdda, then a different sha on the next read). Nothing on the reading side can defend against that.2. A refused cut destroyed the previous good artifact. Every
REFUSEDpath ends inrm -f "\$out"- correct when\$outwas a temp, wrong now that mksquashfs has already overwritten it. So a failed cut cost the last good SFS as well as failing. That is worse than the misread: the misread wastes a minute, that loses an artifact.What changes: mksquashfs writes
<out>.partial; the unpack check,diff -r, the per-target sha check, ownership and metadata all run against the partial; only thenmv -fonto<out>in the same directory, so the rename is atomic. A refusal now removes only the partial and whatever was at the name stays there.--replaceis the deliberate hand-over. Without it, the existing refusal to overwrite a packed SFS stands, so nothing takes a name by accident; with it, the caller says "this name may be swapped once the new one is verified". Verified both ways against a real 470 MB source: without the flagrefusing to overwrite a packed SFS (pass --replace to hand the name over only once the new one is verified); with it the run proceeds past the check.Exercised end to end: the c33 cut that produced SFS
267726ac9eb42e43…(489,996,288 B, 55,669 paths) ran through this path - the final name did not exist until every check had passed against the partial, and the lane that had been catching torn reads read a whole artifact at a single instant.Not merged by me.
shellcheck -S warningclean;bash -nclean.