Files
alzeo/engine-inputs.py
T
Hasan BasbunarandClaude Opus 5.5 5d43992522 flash-local: a start without its checkpoint or a table copy stays failed
A start missing what the unit mounts made runc create it, owned by root
(proved on the reference box with the lane's image, a fake cache and the
unit's mount lines, 2026-10-20): with the checkpoint gone, its folders inside
the Hugging Face cache, which install.sh then read as a lane begun, and with
a copy of the table gone, a folder in its place. flash-local-files.sh, the
head of the unit's ExecStart (after the memory guard every lane runs)
and so its main process, checks the checkpoint's index at the pinned
revision and each copy the mounts name before the engine runs, each a file and not empty, gives a cache on a disk
mounted late at boot 30 tries of 3 s, and exits 78, which stops the
restarts: RestartPreventExitStatus holds for the main process only, never
for an ExecStartPre. It is a script of its own, as flash-ats-check.sh is the
flash lane's, left out of what the engine reads, so a new wording of it asks
no serving lane to restart; the lane's installer puts it in with the unit
and --uninstall removes it. With the check itself gone, the unit stops with
78 and its line too, where bash's 127 was started again every 15 s.

Its line, "preflight: <unit> lacks its files", names the missing file, and a
disk not mounted among the causes, to be mounted before the Load, which
would fetch the checkpoint onto the system's disk with it away. The cockpit shows it on the lane's card,
broken inside the card on a phone, and in its banner, apart from the flash
lane's ATS refusal, with what brings the file back: the lane's Load, whose
switch now runs for a lane that cannot start as installed even as the boot
lane, or ./switch-model.sh flash-local. The cockpit holds a Start back on an
empty copy, or on a unit whose check is gone, so that its Load runs the
switch, whose stage puts it back. ple-table.py mounts a copy only when it is
a file of its original's size: an empty or cut one was written into the
unit. The copy removes an empty folder left in a
copy's place, on which its rename failed after copying the file whole, at
every Load (proved with a folder made by root through Docker, 2026-10-20),
and a copies folder made by root, which no copy can write into, is said
with the command that gives it back, where the copy ended in a traceback.
The unit's comment no longer says the allocator's setting met no refusal,
and both docs say the check, its line and its 78. The check reads every file the checkpoint's index names, a fetch cut short
leaving the index first, and each copy at its original's size, as
ple-table.py and the cockpit read a copy too. Each copy is synced to the
disk before it takes its name, so a power cut no longer leaves a renamed
copy empty or cut short. A copies folder that cannot be made or written into
is said with the remedy that fits its cause, and the Load's step for a boot
lane that lacks a file says it fetches and copies. The tests fail on the old
unit, page, cockpit and copy (found in four reviews, 2026-10-20).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 22:14:49 +02:00

182 lines
9.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""What an engine reads when it starts, and whether the running one already has it.
Usage: engine-inputs.py fingerprint <unit file> <config dir> <hf cache> [REPO@REV ...]
engine-inputs.py running <unit file> <config dir> <hf cache> [REPO@REV ...]
install.sh restarted the engine on every run, so an update that changed nothing the engine
reads still cost a full boot (8 min on the 27B, 12 on flash, reference box 2026-09-23).
It now restarts it only when this says it has to.
The inputs are found, not listed: the unit and its drop-ins; any script of the config dir
the unit runs (the flash lane's launcher); every file of the config dir those name, directly
or through the /out mount (chat template, token map, API key); the config.json of each
checkpoint given as REPO@REV (install.sh patches YaRN into it in place); and the image ID
of every image they name, since a local tag can move.
fingerprint prints a sha256 over all of it, by content: a file rewritten identically does
not change it. running prints "yes" when the unit is active, started after every input was
last written, and its container runs one of the images the inputs name; otherwise "no: "
and why. Both always exit 0 on a readable unit, so a shell can read the answer.
"""
import glob
import hashlib
import os
import re
import subprocess
import sys
def _read(path):
try:
with open(path, encoding="utf-8", errors="replace") as f:
return f.read()
except OSError:
return ""
# Scripts a unit runs that the engine never reads: the guards run before it starts and are
# no input to it (engine-preflight.sh, flash-ats-check.sh, which the flash launcher asks before
# it runs the image, and flash-local-files.sh, which the Flash FP4-Local unit asks before it), so a
# new guard never restarts a healthy engine.
NOT_INPUTS = {"engine-preflight.sh", "flash-ats-check.sh", "flash-local-files.sh"}
# The [Unit] lines that name the other lanes order and exclude them, and systemd applies them at
# its daemon-reload: the engine reads none of them. A lane added to the box changes them in every
# other unit, and the update that brought it restarted the text lane that served, 5 to 15 min, for
# nothing it runs (found in review, 2026-10-15). They are left out of the unit's content here, and
# lanes.sh's unit_put keeps the unit's date when only they change (its UNIT_DEP_KEYS, the same keys).
UNIT_DEP_KEYS = re.compile(r"^(Description|Documentation|Wants|Requires|Requisite|BindsTo|PartOf|Conflicts|After|Before)=")
def _unit_text(raw):
"""A unit's or a drop-in's bytes, without the lines that only order and exclude other units."""
return b"".join(ln for ln in raw.splitlines(keepends=True) if not UNIT_DEP_KEYS.match(ln.decode("utf-8", "replace")))
def inputs(unit, config_dir, hf_cache, ckpts):
"""(files, image refs, container names) the engine of this unit reads at start."""
config_dir = config_dir.rstrip("/")
files = [unit] + sorted(glob.glob(unit + ".d/*.conf"))
texts = [_read(f) for f in files]
cfg = re.escape(config_dir)
for script in sorted(set(re.findall(cfg + r"/[A-Za-z0-9._-]+\.sh", "\n".join(texts)))):
if os.path.isfile(script) and os.path.basename(script) not in NOT_INPUTS:
files.append(script)
texts.append(_read(script))
body = "\n".join(texts)
for name in sorted(set(re.findall(r"(?:/out|" + cfg + r")/([A-Za-z0-9._-]+)", body))):
path = f"{config_dir}/{name}"
if os.path.isfile(path) and path not in files and name not in NOT_INPUTS:
files.append(path)
for ck in ckpts:
repo, _, rev = ck.partition("@")
if not repo or not rev:
continue
repo_dir = os.path.join(hf_cache, "hub", "models--" + repo.replace("/", "--"))
ref = os.path.join(repo_dir, "refs", rev)
if os.path.isfile(ref):
# A branch or a tag (MODEL_REV=main): its snapshot is the commit the ref names,
# and the ref itself is an input, since a download that moves it changes what
# the engine serves at its next start. snapshots/main never exists, so neither
# the config nor the ref counted, and a moved main or a YaRN patch kept the
# engine with "nothing it reads changed" (found in review, 2026-09-24).
files.append(ref)
rev = _read(ref).strip() or rev
path = os.path.join(repo_dir, "snapshots", rev, "config.json")
if os.path.exists(path):
files.append(path)
# Every image the units name, however they name it: by digest, by the local tags this
# repo gives them, and whatever reference sits where the image goes, right before the
# server command. A moving tag (IMAGE=lmsysorg/sglang:v0.5.19, a local SERVE_IMAGE)
# matched neither of the first two, so a pull that moved it kept the engine.
images = sorted(set(re.findall(r"[a-z0-9][a-z0-9./_-]*@sha256:[0-9a-f]{64}", body))
| set(re.findall(r"\bqwen38-[a-z0-9-]+:[A-Za-z0-9._-]+", body))
| set(re.findall(r"(?m)([^\s\\]+)\s*\\?\s*\n?\s*python3 -m sglang\.launch_server", body)))
containers = sorted(set(re.findall(r"--name[ =]([A-Za-z0-9._-]+)", body)))
return files, images, containers
def _image_id(ref, timeout=None):
r = subprocess.run(["docker", "image", "inspect", "--format", "{{.Id}}", ref],
capture_output=True, text=True, timeout=timeout)
return r.stdout.strip() if r.returncode == 0 else "absent"
def fingerprint(unit, config_dir, hf_cache, ckpts):
files, images, _ = inputs(unit, config_dir, hf_cache, ckpts)
units = {unit} | set(glob.glob(unit + ".d/*.conf"))
h = hashlib.sha256()
for f in files:
try:
with open(f, "rb") as fh:
raw = fh.read()
digest = hashlib.sha256(_unit_text(raw) if f in units else raw).hexdigest()
except OSError:
digest = "unreadable"
h.update(f"{f}\0{digest}\n".encode())
for ref in images:
h.update(f"{ref}\0{_image_id(ref)}\n".encode())
return h.hexdigest()
def running(unit, config_dir, hf_cache, ckpts, extra=(), timeout=None):
"""extra: files the engine reads that its unit does not name (the vLLM lanes' auth
middleware, mounted from a folder: vllm-lane.sh's LANE_FILES). timeout: seconds for each
systemctl or docker call. None, the installers' way, waits as before; the cockpit passes
one, since a docker that no longer answers held its whole tier with it (found in review,
2026-10-16). A call over it raises subprocess.TimeoutExpired, for the caller to handle."""
name = os.path.basename(unit)
r = subprocess.run(["systemctl", "show", name, "--timestamp=unix",
"-p", "ActiveState", "-p", "ExecMainStartTimestamp"],
capture_output=True, text=True, timeout=timeout)
props = dict(line.split("=", 1) for line in r.stdout.splitlines() if "=" in line)
if props.get("ActiveState") != "active":
return f"no: {name} is {props.get('ActiveState') or 'unknown'}"
started = props.get("ExecMainStartTimestamp", "").lstrip("@")
if not started.isdigit():
return f"no: {name} has no start time"
files, images, containers = inputs(unit, config_dir, hf_cache, ckpts)
files += [f for f in extra if os.path.exists(f) and f not in files]
# Whole seconds on both sides, as install.sh's stale_since compares them: systemd gives
# the start in whole seconds, and the installer writes the unit, then restarts the
# engine in the same second. Compared with the file's fraction, that write read as a
# change made after the start, and the run after every first install restarted an
# engine that had everything (the reference box, 2026-09-30: an 8-minute boot, and
# opencode-web restarted for the limits of the new pool).
for f in files:
try:
if int(os.stat(f).st_mtime) > int(started):
return f"no: {f} changed after {name} started"
except OSError:
return f"no: {f} is unreadable"
ids = {_image_id(ref, timeout) for ref in images} - {"absent"}
for c in containers:
r = subprocess.run(["docker", "inspect", "--format", "{{.Image}}", c], capture_output=True, text=True,
timeout=timeout)
if r.returncode != 0:
return f"no: container {c} is not running"
if ids and r.stdout.strip() not in ids:
return f"no: container {c} runs another image than the one its unit names"
if not containers:
return "no: found no container name to check the image against"
return "yes"
def main(argv):
if len(argv) < 5 or argv[1] not in ("fingerprint", "running"):
print(__doc__.strip(), file=sys.stderr)
return 2
mode, unit, config_dir, hf_cache, ckpts = argv[1], argv[2], argv[3], argv[4], argv[5:]
if not os.path.isfile(unit):
print(f"no unit at {unit}", file=sys.stderr)
return 1
if mode == "fingerprint":
print(fingerprint(unit, config_dir, hf_cache, ckpts))
else:
print(running(unit, config_dir, hf_cache, ckpts))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))