From dc2e709d31ff4d282572e059bbdace60d412e261 Mon Sep 17 00:00:00 2001 From: javis-bot Date: Tue, 10 Nov 2026 07:04:38 +0900 Subject: [PATCH] fix(m0): keep Strata's engine log when an LLM start fails The first gaming-PC run failed the recommended model with only Strata's one-line reason ("no CUDA-capable device"), which is the picture reader's side message, not the cause. The engine log stayed on the PC. A launch that does not become ready now copies the newest *.engine.log (scrubbed, last 200 KB) into logs/, which the results zip already packs. Co-Authored-By: Claude Opus 5.5 --- scripts/m0/m0lib/llm.py | 13 +++++++++++++ tests/test_m0_kit.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/scripts/m0/m0lib/llm.py b/scripts/m0/m0lib/llm.py index 53e8a88..1b12496 100644 --- a/scripts/m0/m0lib/llm.py +++ b/scripts/m0/m0lib/llm.py @@ -125,10 +125,23 @@ class Strata: # Only a successful launch counts: after a failed one, whatever still # answers on the port is not the model that was asked for. ready = wait_ready(f"http://127.0.0.1:{PORT}", timeout=1800) if rc == 0 else None + if ready is None: + self.keep_engine_log() return {"args": scrub(" ".join(args)), "dropped_flags": dropped, "exit": rc, "command_seconds": round(t_cmd, 1), "ready": ready is not None, "ready_seconds": round(time.perf_counter() - t0, 1) if ready is not None else None} + def keep_engine_log(self) -> None: + """Copy the newest engine log (scrubbed, its end) next to our log so the results zip carries it: + Strata's one-line reason can name a side effect, not the cause.""" + found = sorted(self.home.rglob("*.engine.log"), key=lambda p: p.stat().st_mtime) + if not found: + return + src = found[-1] + text = src.read_text(encoding="utf-8", errors="replace")[-200_000:] + dest = self.log.with_name(f"{self.log.stem}_engine_{src.name.removesuffix('.engine.log')}.log") + dest.write_text(scrub(text), encoding="utf-8") + def stop(self) -> None: run_logged(self.cmd("launch", "--stop"), self.log, timeout=300, env=self.env) time.sleep(3) diff --git a/tests/test_m0_kit.py b/tests/test_m0_kit.py index e6fa1aa..37abec0 100644 --- a/tests/test_m0_kit.py +++ b/tests/test_m0_kit.py @@ -157,3 +157,24 @@ def test_strata_launch_that_fails_is_not_ready_even_if_a_server_answers(tmp_path s = llm.Strata(tmp_path, tmp_path / "strata.log") monkeypatch.setattr(s, "supported_flags", lambda: set()) assert s.launch(llm.PRESETS["fast"], 32768, parallel=1)["ready"] is False + + +def test_failed_strata_launch_keeps_the_engine_log_for_the_zip(tmp_path, monkeypatch): + # Strata's one-line reason can be misleading (the picture reader's "no CUDA-capable device"), + # so the engine's own log must reach the results zip, which packs logs/*.log. + monkeypatch.setattr(llm, "run_logged", lambda *a, **k: 6) + logs = tmp_path / "logs" + logs.mkdir() + s = llm.Strata(tmp_path, logs / "strata_recommended.log") + monkeypatch.setattr(s, "supported_flags", lambda: set()) + engine_dir = tmp_path / "strata" / "localappdata" / "Strata" / "launch" + engine_dir.mkdir(parents=True, exist_ok=True) + home = str(Path.home()) + (engine_dir / "q2_0-32k.engine.log").write_text( + f"loading {home}/model.gguf\ncudaMalloc failed: out of memory\n", encoding="utf-8") + assert s.launch(llm.PRESETS["recommended"], 32768, parallel=1)["ready"] is False + kept = [p for p in logs.glob("*.log") if p.name != "strata_recommended.log"] + assert len(kept) == 1 + text = kept[0].read_text(encoding="utf-8") + assert "out of memory" in text + assert home not in text