Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: emit runtime fingerprint at mflux LoRA trainer startup (#1329)

Adam Eivyd7d9a2393ba8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index f1c964f265..e846d129f3 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -140,3 +140,5 @@
- **[issue-1395] Universe canon section-local renders now persist durably even if the page unmounts mid-render.** A single reference/clean-plate render fired from the Universe canon section round-tripped a client `updateUniverse` PATCH to append the new filename onto the entry's `imageRefs[]` — so a render that completed *after* the user navigated away, refreshed, or switched universes silently lost its attachment (the image reached the media library, but no `imageRefs[]` row was ever written). These renders now carry the same durable `universeRun.entryRef` job tag the batch path uses, so the server-side completion hook (`universeBuilderCollectionHook`) appends `imageRefs[]` independent of any mounted client — converging the section-local and batch surfaces onto one durable path (mirrors the catalog hook from #1359). The hook fires the `appendEntryImageRef` even when the render carries no collection (and the route preserves `entryRef` through a gallery-collection provisioning failure, so the imageRefs append never depends on the collection existing). The client `handleRefCompleted` keeps its optimistic/immediate-refresh role (no PATCH); the hook is idempotent against it (`mapAppendImageRef` dedupes by filename). Backbone the durable path depends on: `updateUniverse` now preserves canon-entry `imageRefs[]` per-id across a stale whole-array PATCH (an inline canon edit/add/lock that round-trips a snapshot loaded before the render landed no longer clobbers the freshly-appended filename — the same guard variations and composite sheets already had); `purgeImageRefFromAllUniverses` switches to the trusted mutator form so its intentional ref-removal isn't undone by that guard; and the route rejects an `entryRef` missing its locating key (canon→`kindKey`, variation→`categoryKey`) instead of silently no-opping the append. (`server/services/universeBuilderCollectionHook.js`, `server/routes/imageGen.js`, `server/services/universeBuilder.js`, `server/services/universeCanon.js`, `client/src/components/universe/UniverseCanonSection.jsx`, #1395)
- **[issue-1403] Chunked LLM editorial checks now also carry clean cross-chapter *setup* between chunks, not just prior findings.** The #1383 prior-findings digest stops a later chunk from re-flagging a problem an earlier chunk recorded — but clean setup produces no finding, so a payoff in chunk 2 could still be mis-flagged "missing setup" when chunk 1 cleanly established it, and `style.conformance` had no signal of which tense/POV chapter 1 set when judging chapter 3. `objects.unmotivated-interaction` and `style.conformance` now additionally opt into a **cross-chunk clean-setup digest** (`crossChunkSetup` + a per-check `setupFocus`): after each non-final chunk, one extra **stage-scoped** inline summarization call (`ctx.callStageScopedInlineLLM`, tagged `pipeline-editorial-setup-digest`, built by `buildSetupDigestPrompt`) rolls a short "setup so far" summary forward, and `editorialSetupDigest` prepends it to later chunks alongside the findings digest — riding INSIDE the manuscript var (no stage-prompt change). The summary call resolves the **same provider the check's stage is pinned to** (a new `runStageScopedInlineLLM` in `stageRunner.js`), so manuscript text never routes to a different (e.g. cloud) provider than the stage chose. Both digests **yield to manuscript coverage**: the setup digest is fitted *after* the findings digest into whatever spare room remains, so a tight chunk drops the digest rather than the manuscript. A single-chunk (whole-fits) run never summarizes, so the common case pays nothing; the stored summary is capped (so a verbose response can't compound across chunks) and a summarizer failure keeps the prior summary and never aborts the check. When the reverse-outline (#1349) or continuity-bible (#1305) artifacts land, either could feed this context more cheaply than a per-chunk call. (`server/lib/editorial/checkRegistry.js`, #1403)
+
+- **[issue-1329] The mflux LoRA trainer now logs a one-line runtime fingerprint at startup, so every run log (and any future GPU-watchdog paniclog) self-documents the exact numerical stack it ran on.** The macOS GPU watchdog kernel panics that hard-reboot the box during long mflux runs (`docs/research/2026-06-13-mflux-training-watchdog-panic.md`) are version-specific to the mflux/mlx/mlx-metal/mlx-lm trio, and PortOS installs `mflux>=0.17` as a *floor* (`scripts/setup-image-video.sh`) — so the stack can drift silently and a paniclog couldn't say which versions were live. `train_mflux_lora.py` now emits a single `STATUS:` line at the top of `main()` (`runtime · mflux X · mlx Y · mlx-metal Z · mlx-lm W · <chip> · <os> · python <v>`) reusing the shared `_runner_common.build_runtime_fingerprint` (the same definition the video-gen `/status` probe uses, so the two never drift). Best-effort: a fingerprint failure logs an "unavailable" line and never aborts a training run. This is the code half of #1329; the *bisect + pin a validated trio* half is a human M5 bench session (each failing candidate hard-reboots the machine) and stays open. (`scripts/train_mflux_lora.py`, #1329)
diff --git a/scripts/train_mflux_lora.py b/scripts/train_mflux_lora.py
index 066b1d9e1c..e079ff6f56 100644
--- a/scripts/train_mflux_lora.py
+++ b/scripts/train_mflux_lora.py
@@ -66,11 +66,50 @@ STOP_REQUESTED = False
# real error, not just the exit code). See the loop in main().
OUTPUT_TAIL_LINES = 40
+# Packages whose resolved versions form the LoRA-training stack fingerprint. The
+# macOS GPU watchdog kernel panics (docs/research/2026-06-13-mflux-training-watchdog-panic.md)
+# are version-specific to this trio + mlx-lm, so emitting them at startup makes
+# every run log and any future paniclog self-document the exact stack it ran on
+# (mirrors the video-gen runtime fingerprint — _runner_common.emit_runtime_fingerprint).
+RUNTIME_FINGERPRINT_PACKAGES = ["mflux", "mlx", "mlx-metal", "mlx-lm"]
+
def log(msg: str) -> None:
print(msg, flush=True)
+def format_runtime_fingerprint_line(fp: dict) -> str:
+ """Render a build_runtime_fingerprint() dict to the one-line STATUS string
+ the trainer logs at startup. Pure (no I/O) so it is unit-testable without a
+ real mflux/mlx install. Absent packages are simply omitted from `versions`
+ by the builder, so they never appear here."""
+ versions = fp.get("versions") or {}
+ parts = [f"{name} {ver}" for name, ver in versions.items()] or ["versions unavailable"]
+ for field in ("chip", "os", "python"):
+ val = fp.get(field)
+ if val:
+ parts.append(f"{field} {val}" if field == "python" else str(val))
+ return "STATUS:runtime · " + " · ".join(parts)
+
+
+def emit_runtime_fingerprint() -> dict:
+ """Log a one-line runtime fingerprint (mflux/mlx/mlx-metal/mlx-lm versions +
+ Apple chip + macOS + python) at trainer startup. Best-effort: a fingerprint
+ failure must never abort a training run, so all of it is guarded. Reuses the
+ shared _runner_common.build_runtime_fingerprint so the trainer log and the
+ video-gen /status probe never drift. Returns the dict it emitted (or {})."""
+ try:
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
+ from _runner_common import build_runtime_fingerprint # noqa: PLC0415
+
+ fp = build_runtime_fingerprint("mflux-lora", RUNTIME_FINGERPRINT_PACKAGES)
+ log(format_runtime_fingerprint_line(fp))
+ return fp
+ except Exception as err: # pragma: no cover - defensive; never abort a run
+ log(f"STATUS:runtime fingerprint unavailable ({err})")
+ return {}
+
+
def _on_sigterm(_sig, _frame):
global STOP_REQUESTED
STOP_REQUESTED = True
@@ -574,6 +613,9 @@ def run_segment(cmd, *, segment_target, state, last_reported, output_tail,
def main():
args = parse_args()
+ # Self-document the exact numerical stack BEFORE anything can fail — the run
+ # log + any watchdog paniclog then carry the mflux/mlx/mlx-metal trio inline.
+ emit_runtime_fingerprint()
output_dir = Path(args.output_dir)
samples_dir = output_dir / "samples"
samples_dir.mkdir(parents=True, exist_ok=True)
diff --git a/scripts/train_mflux_lora_test.py b/scripts/train_mflux_lora_test.py
index c8d43ab613..99efd3cd35 100644
--- a/scripts/train_mflux_lora_test.py
+++ b/scripts/train_mflux_lora_test.py
@@ -12,6 +12,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
from train_mflux_lora import ( # noqa: E402
is_preview_progress_bar,
compute_effective_total,
+ format_runtime_fingerprint_line,
TQDM_RE,
STEP_LOSS_RE,
)
@@ -100,6 +101,34 @@ with tempfile.TemporaryDirectory() as d:
check("compute_effective_total falls back on bad config",
compute_effective_total({}, 777) == 777)
+# --- format_runtime_fingerprint_line: one-line startup stack fingerprint -------
+# Full stack as the M5 panic reports capture it.
+full_fp = {
+ "runtime": "mflux-lora",
+ "versions": {"mflux": "0.17.5", "mlx": "0.30.6", "mlx-metal": "0.30.6", "mlx-lm": "0.29.1"},
+ "chip": "Apple M5 Max",
+ "os": "macOS-26.5.1-arm64-arm-64bit",
+ "python": "3.11.9",
+}
+full_line = format_runtime_fingerprint_line(full_fp)
+check("fingerprint line is a single STATUS line",
+ full_line.startswith("STATUS:runtime · ") and "\n" not in full_line)
+check("fingerprint line carries the mflux/mlx/mlx-metal/mlx-lm versions",
+ all(s in full_line for s in ("mflux 0.17.5", "mlx 0.30.6", "mlx-metal 0.30.6", "mlx-lm 0.29.1")))
+check("fingerprint line carries chip/os/python",
+ all(s in full_line for s in ("Apple M5 Max", "macOS-26.5.1-arm64-arm-64bit", "python 3.11.9")))
+
+# Absent packages omitted by the builder → line still renders, no crash, no empty
+# fragment for the missing pin.
+partial_line = format_runtime_fingerprint_line({"versions": {"mflux": "0.17.5"}, "chip": "Apple M5 Max"})
+check("partial fingerprint omits absent packages cleanly",
+ "mflux 0.17.5" in partial_line and "mlx " not in partial_line and "· ·" not in partial_line)
+
+# Empty dict (everything failed to resolve) → still a single, non-throwing line.
+empty_line = format_runtime_fingerprint_line({})
+check("empty fingerprint degrades to a 'versions unavailable' line",
+ empty_line == "STATUS:runtime · versions unavailable")
+
print()
if FAILS:
print(f"❌ {len(FAILS)} failure(s): {FAILS}")