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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
apply mlx #3267 AGX_RELAX_CDM_CTXSTORE_TIMEOUT fix for the LoRA-training GPU watchdog panic
[._.]/ Adam Eivycaeb82fbaf8f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex abf5e7b7a3..552d10f3a4 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,8 @@## Local model stack-- **[issue-1329] Pinned a validated mlx/mlx-metal trio for LoRA training so the GPU-watchdog stack can't silently drift back to the known-bad build.** The three M5 Max kernel panics during FLUX.2 LoRA training all happened on mlx/mlx-metal 0.30.6, but `setup-image-video.sh` installed `mflux>=0.17` as a *floor* and let pip resolve mlx under mflux's `mlx<0.32` cap — so a reinstall could land back on a panicking build. The setup script now pins the bisect-validated trio **mflux 0.17.5 · mlx 0.31.2 · mlx-metal 0.31.2**, proven by run `d36562a0` completing a full LoRA training to adapter extraction (flux2-klein-4b, bf16, 768px, segmentation on) on the panicking M5 Max with no panic or reboot. The runtime-fingerprint half shipped earlier (#1406). The pure segmentation-OFF 9B verdict and the upstream mflux/MLX issue filing stay deferred — both need a destructive sustained-GPU repro that risks a hard reboot. (`scripts/setup-image-video.sh`, `docs/research/2026-06-13-mflux-training-watchdog-panic.md`)+- **[issue-1329] Pinned a validated mlx/mlx-metal trio for LoRA training so the GPU-watchdog stack can't silently drift back to the known-bad build.** The three M5 Max kernel panics during FLUX.2 LoRA training all happened on mlx/mlx-metal 0.30.6, but `setup-image-video.sh` installed `mflux>=0.17` as a *floor* and let pip resolve mlx under mflux's `mlx<0.32` cap — so a reinstall could land back on a panicking build. The setup script now pins the bisect-validated trio **mflux 0.17.5 · mlx 0.31.2 · mlx-metal 0.31.2**, proven by run `d36562a0` completing a full LoRA training to adapter extraction (flux2-klein-4b, bf16, 768px, segmentation on) on the panicking M5 Max with no panic or reboot. The runtime-fingerprint half shipped earlier (#1406). (`scripts/setup-image-video.sh`, `docs/research/2026-06-13-mflux-training-watchdog-panic.md`)+- **[issue-1329] Applied the upstream-confirmed fix for the LoRA-training GPU watchdog panic.** A search of the MLX tracker turned up the root cause: [mlx #3267](https://github.com/ml-explore/mlx/issues/3267) — the Metal GPU watchdog kills sustained LoRA training whose command buffers compete with active-display compositing (escalating to a `watchdogd` kernel panic + hard reboot on M5-class silicon). The MLX maintainer's confirmed workaround is the `AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1` env var, which PortOS now sets automatically in the trainer (it propagates to the `mflux-train` child; set it to `0` to disable). The trainer logs `STATUS:watchdog mitigation · AGX_RELAX_CDM_CTXSTORE_TIMEOUT=…` so a paniclog records whether it was active. Notably, per #3267 the kill is at the IOGPU layer *above* the process boundary — so process-teardown segmentation alone does not prevent it, and the strongest user-side mitigation is to train with the display asleep / lid closed under `caffeinate -s` or over SSH. No fresh upstream issue was filed (it would duplicate #3267 / #3186); the draft is retained for a possible data-point comment on the panic tracker. (`scripts/train_mflux_lora.py`, `docs/TROUBLESHOOTING.md`, `docs/research/2026-06-13-mflux-training-watchdog-panic.md`)## Mood boardsdiff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 65a93d774c..ea115196be 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -297,7 +297,33 @@ force-rebooted it. On new Apple Silicon (M5 / `Mac17,7`) under sustained Metal/Gload this is most likely a GPU/Metal driver hang; thermal/power or severe swapthrash are secondary possibilities. First observed 2026-06-13 (twice in one day).+**Upstream root cause (mlx #3267 / #3186)**: This is an Apple Metal/IOGPU driver+behavior, confirmed across M2/M3/M4/M5 hardware, not a PortOS bug. Two related+forms: the GPU watchdog kills a training process whose command buffers compete+with **active-display WindowServer compositing**+([mlx #3267](https://github.com/ml-explore/mlx/issues/3267),+`kIOGPUCommandBufferCallbackErrorImpactingInteractivity`), escalating on M5-class+silicon to the full `watchdogd` kernel panic above; and a separate IOGPU+memory-management panic ([mlx #3186](https://github.com/ml-explore/mlx/issues/3186),+filed with Apple as FB22091885). The MLX maintainer's confirmed workaround is the+`AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1` env var — **PortOS now sets this automatically**+for the trainer (`scripts/train_mflux_lora.py`). Note per #3267 the kill is at the+IOGPU layer *above* the process boundary, so process-teardown segmentation alone+does not prevent it; the env var attacks the actual cause.++**Strongest user-side mitigation — keep the display off the GPU.** The watchdog+fires hardest when training competes with the active display. Run training with the+display asleep / lid closed under `caffeinate -s &`, or drive the box headless over+SSH from another machine. With no WindowServer compositing the watchdog has nothing+to protect and largely stops firing.+**Mitigations already in place**:+- `AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1` is set automatically by the trainer (the+ maintainer-confirmed workaround for mlx #3267); the run log shows+ `STATUS:watchdog mitigation · AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1` so a paniclog+ records whether it was active. Set it to `0` in the environment to disable.+- The mlx/mlx-metal backend is pinned to the validated 0.31.2 trio in+ `scripts/setup-image-video.sh` (the original panics were on 0.30.6).- Training checkpoints at least every `ceil(totalSteps/4)` steps(`MFLUX_MIN_CHECKPOINTS`), so a crash loses at most ~¼ of a run. Resume from thenewest `checkpoints/*.zip` via the UI's resume action or `--resume-checkpoint`.diff --git a/docs/research/2026-06-13-mflux-training-watchdog-panic.md b/docs/research/2026-06-13-mflux-training-watchdog-panic.mdindex cdc8ed452f..1fbdb87d8e 100644--- a/docs/research/2026-06-13-mflux-training-watchdog-panic.md+++ b/docs/research/2026-06-13-mflux-training-watchdog-panic.md@@ -5,6 +5,47 @@**Affected:** `Mac17,7` (Apple Silicon, `T6050` SoC), macOS 26.5 (`Darwin 25.5.0`, `xnu-12377.121.6~2`)**Trigger:** Sustained GPU compute during mflux FLUX.2 LoRA training (`scripts/train_mflux_lora.py` → `mflux-train`)+## Upstream root cause + fix (2026-06-27, #1329)++Searched the mflux and MLX trackers. **mflux has no relevant issue**; **MLX has two+open ones that together explain this incident**, so we did NOT file a duplicate:++- **[mlx #3267](https://github.com/ml-explore/mlx/issues/3267)** (open, `wontfix`) —+ *"Metal GPU watchdog kills LoRA training when display is active."* The watchdog+ fires when MLX command buffers compete with **active-display WindowServer+ compositing** (`kIOGPUCommandBufferCallbackErrorImpactingInteractivity`). The+ MLX maintainer (@zcbenz) gave a confirmed workaround — set+ **`AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1`** (relax the AGX CDM context-store timeout+ so a long command buffer isn't judged interactivity-impacting); the reporter:+ "Completely resolved." `wontfix` only because the policy is OS-controlled, not+ because the workaround fails. **Crucial caveat: the kill is at the IOGPU layer+ *above the process boundary*, so subprocess isolation / process-teardown+ segmentation does NOT prevent it** — re-spawning the worker just gets killed+ again. Other confirmed user-side mitigations: `caffeinate -s` + lid closed,+ display-sleep, or SSH headless (no WindowServer GPU contention).+- **[mlx #3186](https://github.com/ml-explore/mlx/issues/3186)** (open; Apple+ `FB22091885`) — a separate IOGPU **kernel panic** (`completeMemory() prepare+ count underflow` @IOGPUMemory.cpp:550), an Apple `IOGPU.kext` memory-management+ bug. Corroborated on M4 Max, M3 Ultra, M1 Ultra, Mac mini M4, **and M5** ("system+ reboots to a black screen"). No fix yet; zcbenz is "checking internally."++**Our signature differs from both** (`watchdog timeout: no checkins from watchdogd`+vs #3267's process-kill exception and #3186's `completeMemory` panic), but it is+the same family: a system-level GPU/Metal driver stall under sustained ML load on+new Apple Silicon, escalating to a `watchdogd` reboot on M5. So our exact panic+string may be a third manifestation — worth adding as a data-point comment on+#3186 (the panic tracker) when convenient, rather than a fresh issue.++**Action taken (#1329):** PortOS now sets `AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1`+automatically in `scripts/train_mflux_lora.py` (mirrors the `generate_ltx2.py`+env-knob pattern; propagates to the `mflux-train` child Popen). The trainer logs+`STATUS:watchdog mitigation · AGX_RELAX_CDM_CTXSTORE_TIMEOUT=…` so a paniclog+records whether it was active. The pinned 0.31.2 trio (this same PR's predecessor+#1746) stands. The destructive seg-OFF version-bisect is now **lower priority** —+the env-var fix attacks the actual cause and is far cheaper to validate than a+version sweep; validate by running a sustained (seg-OFF) job with the display+asleep and the env var set, before concluding anything about versions.+## SummaryThe machine hard-rebooted twice in one day, both times while a LoRA training rundiff --git a/docs/research/2026-06-14-upstream-issue-draft-m5-watchdog.md b/docs/research/2026-06-14-upstream-issue-draft-m5-watchdog.mdindex 1b7b280d7d..b2cb0db451 100644--- a/docs/research/2026-06-14-upstream-issue-draft-m5-watchdog.md+++ b/docs/research/2026-06-14-upstream-issue-draft-m5-watchdog.md@@ -1,8 +1,15 @@# Draft upstream issue — M5 Max GPU watchdog kernel panic under sustained MLX LoRA training-Copy-paste target: file against **mflux** (https://github.com/filipstrand/mflux/issues)-and/or **mlx** (https://github.com/ml-explore/mlx/issues). Not yet filed — pending a-telemetry-captured repro to disambiguate thermal vs driver (see incident doc).+> **DO NOT FILE AS A NEW ISSUE (updated 2026-06-27, #1329).** A tracker search found+> existing open MLX issues that cover this — **[mlx #3267](https://github.com/ml-explore/mlx/issues/3267)**+> (watchdog kills LoRA training when the display is active; confirmed workaround+> `AGX_RELAX_CDM_CTXSTORE_TIMEOUT=1`) and **[mlx #3186](https://github.com/ml-explore/mlx/issues/3186)**+> (IOGPU `completeMemory()` kernel panic, filed with Apple as FB22091885). mflux+> itself has no relevant issue. Our `watchdogd`-timeout signature differs slightly+> from both, so the right contribution is a **data-point comment on #3186** (the+> kernel-panic tracker), not a fresh issue. Keep the environment/symptom material+> below as the body of that comment if/when posting. See the "Upstream root cause+> + fix" section of the incident doc.---diff --git a/scripts/train_mflux_lora.py b/scripts/train_mflux_lora.pyindex e079ff6f56..3d06e4c012 100644--- a/scripts/train_mflux_lora.py+++ b/scripts/train_mflux_lora.py@@ -58,6 +58,20 @@ from collections import dequefrom datetime import datetimefrom pathlib import Path+# macOS GPU-watchdog mitigation (mlx #3267). The Metal/AGX driver kills sustained+# LoRA training under the GPU watchdog ("Impacting Interactivity" → process kill,+# and on M5-class silicon escalating to a `watchdogd` kernel panic + hard reboot;+# see docs/research/2026-06-13-mflux-training-watchdog-panic.md). The MLX+# maintainer's confirmed workaround is to relax the AGX CDM context-store timeout+# so a long command buffer isn't treated as a stuck/interactivity-impacting one.+# It is read by the driver at Metal context creation, so it MUST be set before+# mlx initializes — we set it here at module load, and since the mflux-train+# child Popen (below) inherits this process env, the child gets it too. setdefault+# lets an explicit override (or =0 to disable) still win. NOTE: per mlx #3267 the+# kill is at the IOGPU layer *above* the process boundary, so process-teardown+# segmentation alone does NOT prevent it — this env var attacks the actual cause.+os.environ.setdefault("AGX_RELAX_CDM_CTXSTORE_TIMEOUT", "1")+CHILD = NoneSTOP_REQUESTED = False@@ -616,6 +630,9 @@ def main():# 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()+ # Self-document the GPU-watchdog mitigation too (mlx #3267) so a paniclog+ # shows whether the AGX timeout relaxation was active for the crashed run.+ log(f"STATUS:watchdog mitigation · AGX_RELAX_CDM_CTXSTORE_TIMEOUT={os.environ.get('AGX_RELAX_CDM_CTXSTORE_TIMEOUT', 'unset')}")output_dir = Path(args.output_dir)samples_dir = output_dir / "samples"samples_dir.mkdir(parents=True, exist_ok=True)