From b8256708e73ef29b7b6e25e0c1646ea07def4c8f Mon Sep 17 00:00:00 2001 From: solutionphil Date: Sat, 5 Sep 2026 10:22:16 +0200 Subject: [PATCH] Read the kit commit as root in the reconcile check too, and do not re-arm a running setup Since #114 ensure-imageid.sh calls apply-reconcile-check.sh as root, before every klipper start. That script compared the kit's HEAD against the stamp with a plain `git -C`, which root, with no HOME and against a clone owned by the printer user, refuses as dubious ownership -- so the fallback answered with the flat .kit-commit baked into the image, a value that never moves. The stamp could never match, the marker was armed on every start, and the full optimize-boot.sh run (about 60 s, 22 daemon-reloads) came with it: 56 runs in the reconcile log by 2026-09-05, three of them for one and the same kit commit within twenty minutes, on a printer that had not changed. Measured on the dev printer: Moonraker needing 46 s instead of 19 s to initialise and the display arriving 30-40 s late, every boot, since 2026-09-03. `-c safe.directory='*'` on the command line fixes it regardless of HOME, the same way optimize-boot.sh already reads the commit where it writes the stamp; and with .git present the flat file is never consulted again. Second, the same check runs twice per start: as root from drop-in 19, which starts the setup at once, and as the owner from drop-in 25 a few seconds later, while that run is still going and the stamp not yet written. Re-arming there bought a second full run on the next start, which is why most commits appear twice in the log. It now leaves an active arco-reconcile alone. Co-Authored-By: Claude Fable 5.1 --- scripts/apply-reconcile-check.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/apply-reconcile-check.sh b/scripts/apply-reconcile-check.sh index 28f5fcf..1e40697 100755 --- a/scripts/apply-reconcile-check.sh +++ b/scripts/apply-reconcile-check.sh @@ -39,7 +39,17 @@ STAMP="$DATA/.arco-reconcile-done" # If neither can say, do nothing -- guessing here would arm the reconcile on every boot for ever. cur="" if [ -d "$KIT/.git" ] && command -v git >/dev/null 2>&1; then - cur="$(git -C "$KIT" rev-parse HEAD 2>/dev/null || true)" + # -c safe.directory: this also runs as ROOT (ensure-imageid.sh, drop-in 19) against a clone owned by + # the printer user, and a plain `git -C` refuses that as dubious ownership. Without it the fallback + # below answered with the flat .kit-commit baked into the image -- a value that never moves -- so + # the stamp could never match and the root-side setup ran on EVERY klipper start: 56 runs in the + # log on 2026-09-05, three of them for one and the same kit commit within twenty minutes, each a + # 60 s run competing with Moonraker, Spoolman and the display for the two service cores. The same + # trap, fixed the same way, sits in optimize-boot.sh where the stamp is written. + cur="$(git -c safe.directory='*' -C "$KIT" rev-parse HEAD 2>/dev/null || true)" + # A clone git cannot read is a fault to leave alone, not a reason to compare against a constant: + # with .git present the flat file is never the truth. + [ -n "$cur" ] || exit 0 fi [ -n "$cur" ] || cur="$(tr -dc '0-9a-f' < "$KIT/.kit-commit" 2>/dev/null | head -c 40)" [ -n "$cur" ] || exit 0 @@ -47,6 +57,13 @@ fi last="$(head -c 40 "$STAMP" 2>/dev/null || true)" [ "$cur" = "$last" ] && exit 0 +# Drop-in 19 runs this as root and starts the setup at once; drop-in 25 runs it again as the owner a +# few seconds later, while that run is still going and the stamp is not yet written. Re-arming then +# buys a second full run on the next start -- the log showed most kit commits recorded twice. +if systemctl is-active --quiet arco-reconcile.service 2>/dev/null; then + exit 0 +fi + # No stamp at all is the interesting case rather than an error: it means optimize-boot.sh has never # recorded a run here, which is true of a printer updated from the web interface since before this guard # existed. Arm it once; from then on the stamp keeps it quiet.