Gate unclean-boot-images: an Immich bump cannot quietly switch the power-cut repair off (R-1007)
gates / gates (push) Successful in 4s
gates / gates (push) Successful in 4s
The after_unclean_boot block's images: must list the image its service runs in the compose and in each steps/ file carrying the block. Before, the controller only skipped the repair on an unproven image, in the box's own log. 11 decoys; five mutations red-proofed.
This commit is contained in:
1 parent
74c8e84232
commit
8f5ad8ae83
7 files changed
+301
-11
No files matched your search
@@ -29,6 +29,8 @@ Gates, in order (all must pass; **non-zero exit on any failure**):
|
||||
service's deploy.resources.limits.memory, and every service has one (R-758)
|
||||
12. data-key static, instant, whole repo — every data-encrypting key carries data_key: true (name rule
|
||||
or REGISTRY), and no flag is unexplained (R-127)
|
||||
13. unclean-boot-images static, instant, whole repo — an after_unclean_boot block lists the image its service
|
||||
runs (R-1007): an Immich bump without a re-proven repair is refused, not silently skipped
|
||||
4. engine-major static, needs GIT HISTORY — no database engine pin crosses a MAJOR version
|
||||
(operator ruling 2026-09-13; expires when Slice 4 / R-448 ships). Runs in the
|
||||
pre-push hook, which has the full clone; on a SHALLOW clone (CI fetches at
|
||||
@@ -128,6 +130,10 @@ GATES = [
|
||||
# R-127 leg (a) (2026-10-05): every data-encrypting key carries `data_key: true` (by its NAME, or by a registry
|
||||
# entry with its reason) and every flag is accounted for — the restore's fail-closed gate reads only that flag.
|
||||
("data-key", "check-data-key.py", True, True, False),
|
||||
# R-1007 (2026-10-14, decision 236): an `after_unclean_boot:` block's `images:` must list the image its service
|
||||
# runs in the compose (and in each steps/ file that carries the block). The repair uses the app's internals, so the
|
||||
# controller SKIPS it on an unproven image and nobody is told — this refuses the image bump that would do that.
|
||||
("unclean-boot-images", "check-unclean-boot-images.py", True, True, False),
|
||||
]
|
||||
|
||||
# 3 (R-605): the gate's HARNESS refused to run — its canary failed or it had nothing to judge — so NO app was
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""check-unclean-boot-images.py — an app's power-cut repair runs only on the images it was PROVEN on (R-1007, decision 236).
|
||||
|
||||
WHAT GOES WRONG WITHOUT IT. A template's `after_unclean_boot:` block lists the images the repair was proven on
|
||||
(`images:`). The repair uses the app's INTERNALS (Immich: its BullMQ queue `thumbnailGeneration`, the job
|
||||
`AssetGenerateThumbnails`, the `integrity_report` table), so the controller runs it only when the installed image of
|
||||
`after_unclean_boot.service` is in that list; any other image is SKIPPED, with a reason in the box's log and the app
|
||||
record only (controller `internal/stacks/after_unclean_boot.go`). An image bump in the compose that forgets the list
|
||||
therefore turns the repair off on every box that updates — and nobody is told. This gate refuses that push.
|
||||
|
||||
THE FACT, and the labels that are not it:
|
||||
* The fact is the `image:` line of the service NAMED by `after_unclean_boot.service`, directly under that service's
|
||||
key in the compose's top-level `services:` (the controller keys `installed_images` by the compose service name),
|
||||
and the `images:` list INSIDE the top-level, uncommented `after_unclean_boot:` block.
|
||||
* NOT the fact: the image in a COMMENT, the image of ANOTHER service (immich-machine-learning moves with the server,
|
||||
but the repair never runs in it), a block that is commented out (an older controller would not read it either).
|
||||
* The same rule for each `steps/<key>.felhom.yml` that carries the block, against its own `steps/<key>.yml` (the
|
||||
update ladder: a box pinned to a step reads that step's files).
|
||||
* A block the gate cannot read (no `service:`, no `images:`, the service absent from the compose, a service with no
|
||||
`image:`) is refused too — a list nobody can match is not a proof.
|
||||
|
||||
stdlib only, a line reader: the catalog CI has no PyYAML.
|
||||
|
||||
USAGE
|
||||
python3 scripts/check-unclean-boot-images.py # every template directory
|
||||
python3 scripts/check-unclean-boot-images.py immich # only these
|
||||
python3 scripts/check-unclean-boot-images.py --root=<dir> # judge another checkout (the decoy suite)
|
||||
(`--all` is accepted and changes nothing.)
|
||||
Exit 0 clean · 1 refused. Decoys: scripts/test_gate_decoys.py `unclean_boot_cases` (COVERS "unclean-boot-images").
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
TOP_BLOCK = re.compile(r"^after_unclean_boot:\s*(#.*)?$")
|
||||
TOP_KEY = re.compile(r"^\S")
|
||||
CHILD = re.compile(r"^(\s+)([A-Za-z_][A-Za-z0-9_]*):\s*(.*?)\s*$")
|
||||
ITEM = re.compile(r'^\s+-\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s#]+))\s*(#.*)?$')
|
||||
FLOW_ITEM = re.compile(r'"([^"]*)"|\'([^\']*)\'|([^,\s\[\]"\']+)')
|
||||
METHOD = "felhom.eu/documentation/audits/immich-repair-2026-10-14/"
|
||||
|
||||
|
||||
def strip_comment(v):
|
||||
"""A value with its trailing ` # comment` removed (quotes respected)."""
|
||||
out, q = [], None
|
||||
for i, c in enumerate(v):
|
||||
if q:
|
||||
if c == q:
|
||||
q = None
|
||||
elif c in "\"'":
|
||||
q = c
|
||||
elif c == "#" and (i == 0 or v[i - 1].isspace()):
|
||||
break
|
||||
out.append(c)
|
||||
return "".join(out).strip()
|
||||
|
||||
|
||||
def unquote(v):
|
||||
v = v.strip()
|
||||
if len(v) >= 2 and v[0] == v[-1] and v[0] in "\"'":
|
||||
return v[1:-1]
|
||||
return v
|
||||
|
||||
|
||||
def parse_block(text):
|
||||
"""(present, service, images or None) from a .felhom.yml text. Only the top-level, uncommented block counts."""
|
||||
lines = text.splitlines()
|
||||
for i, ln in enumerate(lines):
|
||||
if not TOP_BLOCK.match(ln):
|
||||
continue
|
||||
body = []
|
||||
for nxt in lines[i + 1:]:
|
||||
if nxt.strip() and TOP_KEY.match(nxt):
|
||||
break
|
||||
body.append(nxt)
|
||||
indent = None
|
||||
for b in body:
|
||||
if b.strip() and not b.lstrip().startswith("#"):
|
||||
indent = len(b) - len(b.lstrip())
|
||||
break
|
||||
service, images = None, None
|
||||
for j, b in enumerate(body):
|
||||
m = CHILD.match(b)
|
||||
if not m or len(m.group(1)) != indent:
|
||||
continue
|
||||
key, val = m.group(2), strip_comment(m.group(3))
|
||||
if key == "service":
|
||||
service = unquote(val) or None
|
||||
elif key == "images":
|
||||
if val.startswith("["):
|
||||
images = [next(g for g in t if g) for t in FLOW_ITEM.findall(val.strip("[]"))]
|
||||
elif val == "":
|
||||
images = []
|
||||
for nxt in body[j + 1:]:
|
||||
if not nxt.strip() or nxt.lstrip().startswith("#"):
|
||||
continue
|
||||
mi = ITEM.match(nxt)
|
||||
if not mi or len(nxt) - len(nxt.lstrip()) <= indent:
|
||||
break
|
||||
images.append(next(g for g in mi.groups()[:3] if g is not None))
|
||||
return True, service, images
|
||||
return False, None, None
|
||||
|
||||
|
||||
def service_image(text, service):
|
||||
"""The `image:` of `services.<service>` in a compose text, or None."""
|
||||
lines = text.splitlines()
|
||||
in_services, svc_indent, in_svc, key_indent = False, None, False, None
|
||||
for ln in lines:
|
||||
if not ln.strip() or ln.lstrip().startswith("#"):
|
||||
continue
|
||||
ind = len(ln) - len(ln.lstrip())
|
||||
if ind == 0:
|
||||
in_services = ln.rstrip().split("#")[0].strip() == "services:"
|
||||
in_svc = False
|
||||
continue
|
||||
if not in_services:
|
||||
continue
|
||||
m = CHILD.match(ln) or re.match(r"^(\s+)([A-Za-z0-9_.-]+):\s*(.*?)\s*$", ln)
|
||||
if svc_indent is None:
|
||||
svc_indent = ind
|
||||
if ind == svc_indent:
|
||||
name = unquote(ln.strip().rstrip(":").split(":")[0])
|
||||
in_svc = name == service
|
||||
key_indent = None
|
||||
continue
|
||||
if in_svc and ind > svc_indent:
|
||||
if key_indent is None:
|
||||
key_indent = ind
|
||||
if ind == key_indent and m and m.group(2) == "image":
|
||||
return unquote(strip_comment(m.group(3)))
|
||||
return None
|
||||
|
||||
|
||||
def judge(app, label, felhom_text, compose_text, compose_name):
|
||||
present, service, images = parse_block(felhom_text)
|
||||
if not present:
|
||||
return None, []
|
||||
fails = []
|
||||
if not service:
|
||||
fails.append("%s (%s): the after_unclean_boot block names no `service:` — the repair cannot be matched to an "
|
||||
"image" % (app, label))
|
||||
return True, fails
|
||||
if not images:
|
||||
fails.append("%s (%s): the after_unclean_boot block lists no `images:` — the repair was proven on nothing" % (app, label))
|
||||
return True, fails
|
||||
if compose_text is None:
|
||||
fails.append("%s (%s): no %s to read the image of %s from" % (app, label, compose_name, service))
|
||||
return True, fails
|
||||
img = service_image(compose_text, service)
|
||||
if img is None:
|
||||
fails.append("%s (%s): %s has no service %r with an `image:` — the block names a service the app does not "
|
||||
"run" % (app, label, compose_name, service))
|
||||
elif img not in images:
|
||||
fails.append("%s (%s): the repair after a power cut was proven on %s; the compose now runs %s. Re-prove the "
|
||||
"repair on 9202 (the method in %s), then add the image."
|
||||
% (app, label, ", ".join(images), img, METHOD))
|
||||
return True, fails
|
||||
|
||||
|
||||
def read(path):
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
return io.open(path, encoding="utf-8").read()
|
||||
|
||||
|
||||
def main(argv):
|
||||
root = os.getcwd()
|
||||
for a in argv:
|
||||
if a.startswith("--root="):
|
||||
root = a.split("=", 1)[1]
|
||||
names = [a for a in argv if not a.startswith("-")]
|
||||
tdir = os.path.join(root, "templates")
|
||||
apps = names or sorted(os.listdir(tdir))
|
||||
fails, carriers = [], []
|
||||
for app in apps:
|
||||
d = os.path.join(tdir, app)
|
||||
fy = read(os.path.join(d, ".felhom.yml"))
|
||||
if fy is not None:
|
||||
has, f = judge(app, "template", fy, read(os.path.join(d, "docker-compose.yml")), "docker-compose.yml")
|
||||
if has:
|
||||
carriers.append(app)
|
||||
fails += f
|
||||
sd = os.path.join(d, "steps")
|
||||
if os.path.isdir(sd):
|
||||
for fn in sorted(os.listdir(sd)):
|
||||
if not fn.endswith(".felhom.yml"):
|
||||
continue
|
||||
key = fn[:-len(".felhom.yml")]
|
||||
has, f = judge(app, "steps/" + fn, read(os.path.join(sd, fn)), read(os.path.join(sd, key + ".yml")),
|
||||
"steps/" + key + ".yml")
|
||||
if has:
|
||||
carriers.append("%s/steps/%s" % (app, key))
|
||||
fails += f
|
||||
for f in fails:
|
||||
print(" REFUSED " + f)
|
||||
if fails:
|
||||
print("unclean-boot-images gate: %d refusal(s)" % len(fails))
|
||||
return 1
|
||||
print("unclean-boot-images gate OK: %d after_unclean_boot block(s) on a proven image %s" % (len(carriers), carriers))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -66,7 +66,9 @@ class CatalogGatesFastTest(unittest.TestCase):
|
||||
# 12 since family-gate joined — STALE AGAIN until 2026-10-05 (found by the burn-down, round 2).
|
||||
# 13 since 2026-10-05: mem-limit-sum (R-758), fast and history-free, so it runs in CI too.
|
||||
# 14 since the same night: data-key (R-127 leg a).
|
||||
self.assertEqual(len(mod.GATES), 14)
|
||||
# 15 since 2026-10-14: unclean-boot-images (R-1007) — fast, no history, so the hook AND CI.
|
||||
self.assertEqual(len(mod.GATES), 15)
|
||||
self.assertIn("unclean-boot-images", [g[0] for g in mod.GATES if g[3] and not g[4]])
|
||||
self.assertIn("data-key", [g[0] for g in mod.GATES if g[3] and not g[4]])
|
||||
self.assertIn("mem-limit-sum", [g[0] for g in mod.GATES if g[3] and not g[4]])
|
||||
self.assertIn("onboarding", [g[0] for g in mod.GATES if g[3] and not g[4]])
|
||||
|
||||
@@ -62,6 +62,7 @@ COVERS = {
|
||||
"onboarding": "a NEW template with no record; a record missing an id, or carrying it only inside an HTML comment; a `done` whose path does not exist, is an EMPTY directory (the mkdir shape, R-410) or names an absent sibling-repo file; an `n/a` with an empty or two-word reason; an `open` row; `opened:` backdated before the checklist; the template a new app copies lacking a new id - vs a complete record, an id added after `opened:`, and an exempt app's record with open rows (NEW-APP-CHECKLIST.md)",
|
||||
"mem-limit-sum": "the right figure only in a COMMENT (the compose header's 'mem_limit: 640M', the .felhom.yml arithmetic) while the field is wrong; a `memory:` under reservations: (not a limit) making the sum come out right; a `mem_limit:` outside resources:; a steps/ file with the old figure (not judged) - vs the facts: a field under the sum, a service with no limit, an unreadable size (R-758)",
|
||||
"data-key": "a data_key: true only in a COMMENT or inside the i18n: block (not the field); an 'Encryption key' LABEL on a signing secret (copy, not the fact - must pass unflagged) - vs the facts: an *_ENCRYPTION_KEY field unflagged, a REGISTERED field unflagged, an unexplained flag, a stale registry entry, a non-boolean flag (R-127)",
|
||||
"unclean-boot-images": "the new image only in a compose COMMENT, on ANOTHER service (machine-learning), or under a COMMENTED-OUT block; a template with no block - each passes; vs the facts: the repair's service bumped with the list unchanged, the same in a steps/ file (the ladder), a block naming a service the compose does not run, a block with an empty images: list; and the genuine bump with the list updated (flow and block list) passes (R-1007, decision 236)",
|
||||
"copy-i18n": "Hungarian edited in a COMMENT/README/display_name (label, not copy) vs a real frozen string changed; an English block that is not English, is not matched to a Hungarian twin, or rewrites a credential (R-560). A retrieval promise REGISTERED in ALLOWLIST_EN passes only for its own app+path+sentence with a real reason; an entry for another app, a rewritten sentence, a stale entry or a two-word reason convicts (R-594). Also the DEGRADED mode CI actually runs — PyYAML shadowed out, freeze only (R-595)",
|
||||
}
|
||||
|
||||
@@ -696,6 +697,54 @@ def family_gate_cases():
|
||||
shutil.rmtree(ws, ignore_errors=True)
|
||||
|
||||
|
||||
def unclean_boot_cases():
|
||||
"""check-unclean-boot-images.py reads FILES: templates/*/.felhom.yml + docker-compose.yml (+ steps/), via --root (R-1007)."""
|
||||
global ran
|
||||
import tempfile
|
||||
ws = tempfile.mkdtemp(prefix="catalog-uncleanboot-")
|
||||
try:
|
||||
OLD, NEW = "ghcr.io/immich-app/immich-server:v3.2.4", "ghcr.io/immich-app/immich-server:v3.3.0"
|
||||
def compose(server=OLD, ml="ghcr.io/immich-app/immich-machine-learning:v3.2.4", comment=""):
|
||||
return ("# header\n%s\nservices:\n immich-server:\n image: %s\n container_name: immich-server\n"
|
||||
" immich-machine-learning:\n image: %s\nvolumes:\n x:\n" % (comment, server, ml))
|
||||
def block(images='["%s"]' % OLD, service="immich-server", commented=False):
|
||||
b = ("after_unclean_boot:\n service: %s\n images: %s\n empty_files:\n under: \"${HDD_PATH}/t\"\n"
|
||||
" repair:\n success: OK\n" % (service, images))
|
||||
if commented:
|
||||
b = "".join("# " + ln + "\n" for ln in b.splitlines())
|
||||
return 'display_name: "Immich"\n' + b + "resources:\n mem_limit: 1M\n"
|
||||
def run(name, files, expect_rc, must=()):
|
||||
global ran
|
||||
cat = os.path.join(ws, "cat")
|
||||
shutil.rmtree(cat, ignore_errors=True)
|
||||
for rel, body in files.items():
|
||||
p = os.path.join(cat, "templates", rel)
|
||||
os.makedirs(os.path.dirname(p), exist_ok=True)
|
||||
io.open(p, "w", encoding="utf-8").write(body)
|
||||
r = sh([sys.executable, os.path.join(ROOT, "scripts", "check-unclean-boot-images.py"), "--root=" + cat], ROOT)
|
||||
out = r.stdout + r.stderr; ran += 1
|
||||
ok = r.returncode == expect_rc and all(m in out for m in must)
|
||||
print(" %s %-70s rc=%d (expected %d)" % ("ok" if ok else "XX", name, r.returncode, expect_rc))
|
||||
if not ok:
|
||||
fails.append("%s: rc=%d expected %d; missing %s\n%s" % (name, r.returncode, expect_rc, [m for m in must if m not in out], out[-400:]))
|
||||
print("\n-- unclean-boot-images: genuine and decoys")
|
||||
run("GENUINE: the block lists the server's image", {"immich/.felhom.yml": block(), "immich/docker-compose.yml": compose()}, 0, ("1 after_unclean_boot",))
|
||||
run("GENUINE: bumped AND the list updated (flow list)", {"immich/.felhom.yml": block('["%s", "%s"]' % (OLD, NEW)), "immich/docker-compose.yml": compose(NEW)}, 0, ("gate OK",))
|
||||
run("GENUINE: bumped AND the list updated (block list)", {"immich/.felhom.yml": block('\n - "%s" # proven 2026-10-20\n - %s' % (OLD, NEW)), "immich/docker-compose.yml": compose(NEW)}, 0, ("gate OK",))
|
||||
run("DECOY: the new image only in a compose COMMENT", {"immich/.felhom.yml": block(), "immich/docker-compose.yml": compose(comment="# image: " + NEW)}, 0, ("gate OK",))
|
||||
run("DECOY: ANOTHER service bumped (machine-learning)", {"immich/.felhom.yml": block(), "immich/docker-compose.yml": compose(ml="ghcr.io/immich-app/immich-machine-learning:v3.3.0")}, 0, ("gate OK",))
|
||||
run("DECOY: the block COMMENTED OUT, server bumped (no block, nothing owed)", {"immich/.felhom.yml": block(commented=True), "immich/docker-compose.yml": compose(NEW)}, 0, ("0 after_unclean_boot",))
|
||||
run("DECOY: a template with no block", {"demo/.felhom.yml": 'display_name: "D"\n', "demo/docker-compose.yml": compose(NEW)}, 0, ("0 after_unclean_boot",))
|
||||
print("-- unclean-boot-images: the facts (each MUST be refused)")
|
||||
run("FACT: the server bumped, the list unchanged", {"immich/.felhom.yml": block(), "immich/docker-compose.yml": compose(NEW)}, 1, ("was proven on " + OLD, "the compose now runs " + NEW, "Re-prove the repair on 9202"))
|
||||
run("FACT: the same in a steps/ file (the ladder)", {"immich/.felhom.yml": block(), "immich/docker-compose.yml": compose(),
|
||||
"immich/steps/abc.felhom.yml": block(), "immich/steps/abc.yml": compose(NEW)}, 1, ("steps/abc.felhom.yml",))
|
||||
run("FACT: the block names a service the compose does not run", {"immich/.felhom.yml": block(service="immich"), "immich/docker-compose.yml": compose()}, 1, ("does not run",))
|
||||
run("FACT: the block lists no images", {"immich/.felhom.yml": block("[]"), "immich/docker-compose.yml": compose()}, 1, ("proven on nothing",))
|
||||
finally:
|
||||
shutil.rmtree(ws, ignore_errors=True)
|
||||
|
||||
|
||||
def image_pins_cases():
|
||||
"""check-image-pins.py reads templates/*/docker-compose.yml under --root (R-426).
|
||||
|
||||
@@ -1547,6 +1596,7 @@ i18n:
|
||||
family_gate_cases()
|
||||
mem_sum_cases()
|
||||
data_key_cases()
|
||||
unclean_boot_cases()
|
||||
|
||||
if fails:
|
||||
print()
|
||||
|
||||
Reference in new issue
Block a user