Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
serve: a crashed engine start is not retried as a GPU runtime start; the start error names how the process ended (signal / NTSTATUS) and the CPU's AVX flags after an illegal instruction (#2324)
Niko1221d981a5101393
diff --git a/serve/server.py b/serve/server.pyindex bebc6bb6c..e500bdd54 100644--- a/serve/server.py+++ b/serve/server.py@@ -435,6 +435,87 @@ def start_log_tail(log: str | None, offset: int, n: int = 20) -> str:return "\nthe engine log's last lines:\n" + "\n".join(" " + x for x in lines)+# Windows NTSTATUS exit codes of a process the system ended (a crash, not an error the engine reported)+_WIN_CRASH = {0xC000001D: "illegal instruction (the CPU lacks an instruction the program uses)",+ 0xC0000005: "access violation", 0xC0000409: "stack buffer overrun / fast-fail",+ 0xC0000135: "a DLL the program needs was not found", 0xC0000139: "entry point not found in a DLL",+ 0xC0000142: "a DLL failed to initialize", 0xC000007B: "bad image (32-bit / 64-bit mix-up)",+ 0xC00000FD: "stack overflow", 0xC0000094: "integer division by zero", 0xC0000096: "privileged instruction"}+++def engine_exit_words(rc: int | None) -> str:+ """What a process's exit status says, in words: "killed by signal 4 (SIGILL, Illegal instruction)" (a negative status+ on Linux / macOS), a Windows NTSTATUS crash code, or "exit code N". "" when there is no status."""+ if rc is None:+ return ""+ if rc < 0 and os.name != "nt":+ try:+ sig = signal.Signals(-rc)+ return f"killed by signal {-rc} ({sig.name}, {signal.strsignal(sig) or sig.name})"+ except (ValueError, AttributeError):+ return f"killed by signal {-rc}"+ code = rc & 0xFFFFFFFF+ if code in _WIN_CRASH:+ return f"exit code 0x{code:08X}: {_WIN_CRASH[code]}"+ if 0xC0000000 <= code < 0xD0000000:+ return f"exit code 0x{code:08X} (a system error status)"+ return f"exit code {rc}"+++def engine_crashed(rc: int | None) -> bool:+ """True when the engine process was ended by the system (an illegal instruction, a bad memory access, the+ out-of-memory killer, a missing DLL ...) rather than leaving by itself: nothing a second try fixes."""+ if rc is None:+ return False+ if rc < 0 and os.name != "nt":+ return -rc in {int(getattr(signal, n)) for n in ("SIGILL", "SIGSEGV", "SIGBUS", "SIGFPE", "SIGKILL")+ if hasattr(signal, n)}+ return 0xC0000000 <= (rc & 0xFFFFFFFF) < 0xD0000000 # an NTSTATUS error code+++def cpu_isa_words() -> str:+ """The CPU's model and which of AVX / AVX2 / FMA / F16C it reports (Linux: /proc/cpuinfo), for an illegal-instruction+ exit. "" where it cannot be read."""+ try:+ text = Path("/proc/cpuinfo").read_text(errors="replace")+ except OSError:+ return ""+ model = next((x.split(":", 1)[1].strip() for x in text.splitlines() if x.lower().startswith("model name")), "")+ flags = next((x.split(":", 1)[1].split() for x in text.splitlines() if x.lower().startswith("flags")), [])+ have = ", ".join(f"{f} {'yes' if f in flags else 'NO'}" for f in ("avx", "avx2", "fma", "f16c", "avx512f"))+ return f"{model or 'this CPU'} ({have})"+++def start_exit_note(rc: int | None) -> str:+ """The sentence the start error carries about how the engine process ended (the engine log is silent when the+ system ends it): "" without a status, else a line, with the CPU's features after an illegal instruction."""+ words = engine_exit_words(rc)+ if not words:+ return ""+ note = f"\nthe engine process ended: {words}"+ if rc is not None and ((rc < 0 and os.name != "nt" and -rc == int(getattr(signal, "SIGILL", 4))) or+ (rc & 0xFFFFFFFF) == 0xC000001D):+ isa = cpu_isa_words()+ note += ("\n An illegal instruction means this CPU lacks an instruction the engine was built to use"+ + (f": {isa}" if isa else "") + ". Please report it with the CPU model "+ "(github.com/Niko1221/Strata/issues).")+ return note+++def start_log_marks(log: str | None, offset: int) -> list:+ """The GPU runtime failure texts (TRANSIENT_START_MARKS) this start wrote to the log: what lets a retry notice say the+ GPU runtime failed. [] when none, or no log."""+ if not log:+ return []+ try:+ with open(log, "rb") as f:+ f.seek(offset)+ text = f.read(64 * 1024).decode("utf-8", "replace")+ except (OSError, ValueError):+ return []+ return [m for m in TRANSIENT_START_MARKS if m in text]++# A start that ends at once with the GPU runtime's own failure and none of the engine's lines: on ROCm, a start right# after the previous engine exited can fail inside the runtime's device/queue set-up while the old process's queues are# still being torn down ("terminate called after throwing an instance of 'rocr::AMD::hsa_exception'", or an exit with@@ -460,7 +541,11 @@ def transient_start_failure(log: str | None, offset: int, elapsed_s: float, rc:if any(m in text for m in TRANSIENT_START_MARKS):return all(x.startswith("terminate called") or x.startswith("what()") orany(m in x for m in TRANSIENT_START_MARKS) for x in engine_lines)- return not engine_lines and rc != 1 # it exited without writing a single line of its own+ # it exited without writing a single line of its own - but not when the system ended it (an illegal instruction, a+ # bad memory access, the OOM killer, a missing DLL): that is a crash a second try repeats, and the retry notice+ # must not call it a GPU runtime start (#2324: an old CPU's illegal instruction was retried 3 times as "GPU+ # runtime" and the real reason never shown)+ return not engine_lines and rc != 1 and not engine_crashed(rc)def echo_requests(log_path: str, offset: int) -> None:@@ -774,9 +859,17 @@ class StrataEngine:if not timed_out and _attempt < START_RETRIES and \transient_start_failure(log, log_start, time.monotonic() - spawned_at, self.proc.returncode):wait_s = 2.0 * (2 ** _attempt) # 2, 4, 8 s: the previous process's GPU queues go away- print(f"[strata] the engine stopped while the GPU runtime was starting (most often right after another "- f"engine exited, whose GPU queues were still being released): starting it again in {wait_s:.0f} s "- f"(try {_attempt + 2} of {START_RETRIES + 1})", flush=True)+ exit_words = engine_exit_words(self.proc.returncode)+ if start_log_marks(log, log_start): # the runtime said so itself (hsa_exception ...)+ print(f"[strata] the engine stopped while the GPU runtime was starting (most often right after "+ f"another engine exited, whose GPU queues were still being released"+ f"{'; ' + exit_words if exit_words else ''}): starting it again in {wait_s:.0f} s "+ f"(try {_attempt + 2} of {START_RETRIES + 1})", flush=True)+ else: # an exit with nothing in the log: say only what is known+ print(f"[strata] the engine exited before it wrote anything to its log"+ f"{' (' + exit_words + ')' if exit_words else ''}; it may be a GPU runtime that was not "+ f"ready yet: starting it again in {wait_s:.0f} s (try {_attempt + 2} of {START_RETRIES + 1})",+ flush=True)time.sleep(wait_s)StrataEngine.__init__(self, exe, args, cwd, log, env, lazy, cpus, _attempt + 1)return@@ -784,8 +877,13 @@ class StrataEngine:"the engine exited before it was ready")# EngineDied, not bare RuntimeError: a request waiting on this load must end with a 503# through the request path's handler - a RuntimeError there left the turn with no answer (#1527)- raise EngineDied(why + (f" (see {log})" if log else "") +- start_failure_hint(log, log_start) + start_log_tail(log, log_start))+ note = "" if timed_out else start_exit_note(self.proc.returncode)+ tail = start_log_tail(log, log_start)+ lines = [x for x in tail.split("\n")[2:] if x.strip()]+ if tail and lines and all(x.strip().startswith("[strata]") for x in lines):+ tail += "\n (those are the launcher's own lines: the engine itself wrote nothing)"+ raise EngineDied(why + (f" (see {log})" if log else "") + note ++ start_failure_hint(log, log_start) + tail)self.known_ctx = self.max_context # survives a failed restart: requests keep their limit and restart it# (from PR #41, midhatn) a locally built engine can sit next to another release's BUILD.json: engines that# report their own version (INFO engine=, 0.1.8+) win, the manifest stays the fallback for older onesdiff --git a/serve/test_server.py b/serve/test_server.pyindex 93dcb26d7..a6999221f 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -2367,6 +2367,92 @@ class StartFailureLog(unittest.TestCase):self.assertNotIn("an earlier start", text)+class StartCrashReported(unittest.TestCase):+ """#2324: an engine the system ends at the start (SIGILL on a CPU without AVX, a bad memory access, the OOM killer)+ writes nothing to its log. It used to be retried 3 times as "stopped while the GPU runtime was starting" and the+ error showed only the launcher's own line. Now a crash is not retried, and the error names how the process ended."""++ def run_fake(self, code, retries=3):+ import contextlib+ import io+ import serve.server as server+ with tempfile.TemporaryDirectory() as d:+ script, log = Path(d) / "fake_strata.py", Path(d) / "strata.log"+ script.write_text(code, encoding="utf-8")+ real = server.subprocess.Popen+ out = io.StringIO()+ with mock.patch.object(server.subprocess, "Popen",+ lambda cmd, **kw: real([sys.executable, str(script), *cmd[1:]], **kw)), \+ mock.patch.object(server, "narrate_start", lambda *a, **k: None), \+ mock.patch.object(server, "START_RETRIES", retries), \+ mock.patch.object(server.time, "sleep", lambda s: None), \+ contextlib.redirect_stdout(out):+ with self.assertRaises(RuntimeError) as cm:+ StrataEngine("strata", [], log=str(log))+ return str(cm.exception), out.getvalue()++ def test_status_words(self):+ from serve.server import engine_crashed, engine_exit_words+ self.assertEqual(engine_exit_words(None), "")+ self.assertEqual(engine_exit_words(2), "exit code 2")+ self.assertIn("illegal instruction", engine_exit_words(0xC000001D).lower())+ self.assertIn("DLL", engine_exit_words(0xC0000135))+ self.assertTrue(engine_crashed(0xC000001D) and engine_crashed(0xC0000005))+ self.assertFalse(engine_crashed(0) or engine_crashed(1) or engine_crashed(2) or engine_crashed(None))+ if os.name != "nt":+ import signal+ self.assertIn("signal 4 (SIGILL", engine_exit_words(-int(signal.SIGILL)))+ for sig in (signal.SIGILL, signal.SIGSEGV, signal.SIGBUS, signal.SIGFPE, signal.SIGKILL):+ self.assertTrue(engine_crashed(-int(sig)), sig)+ self.assertFalse(engine_crashed(-int(signal.SIGABRT))) # the ROCm teardown abort stays a retry+ self.assertFalse(engine_crashed(-int(signal.SIGTERM)))++ def test_a_crash_is_not_a_transient_start(self):+ from serve.server import transient_start_failure+ d = tempfile.mkdtemp()+ p = Path(d) / "engine.log"+ p.write_text("[strata] 2026-10-13 17:49:15 engine started: /x/strata --serve\n", encoding="utf-8")+ self.assertTrue(transient_start_failure(str(p), 0, 3.0, 0)) # a silent plain exit: the old retry+ self.assertTrue(transient_start_failure(str(p), 0, 3.0, -6)) # SIGABRT (ROCm teardown)+ self.assertFalse(transient_start_failure(str(p), 0, 3.0, 1)) # the engine's own error exit+ self.assertFalse(transient_start_failure(str(p), 0, 3.0, 0xC000001D))+ if os.name != "nt":+ import signal+ for sig in (signal.SIGILL, signal.SIGSEGV, signal.SIGBUS, signal.SIGKILL):+ self.assertFalse(transient_start_failure(str(p), 0, 3.0, -int(sig)), sig)+ # the runtime's own words keep it a retry whatever the status+ p.write_text("[strata] x engine started\nterminate called after throwing an instance of "+ "'rocr::AMD::hsa_exception'\n", encoding="utf-8")+ self.assertTrue(transient_start_failure(str(p), 0, 3.0, -6))++ @unittest.skipIf(os.name == "nt", "signals")+ def test_sigill_is_reported_not_retried(self):+ text, said = self.run_fake("import os, signal\nos.kill(os.getpid(), signal.SIGILL)\n")+ self.assertIn("exited before it was ready", text)+ self.assertIn("the engine process ended: killed by signal 4 (SIGILL", text)+ self.assertIn("illegal instruction means this CPU lacks an instruction", text)+ self.assertIn("the engine itself wrote nothing", text)+ self.assertNotIn("starting it again", said) # not retried+ self.assertNotIn("GPU runtime", text + said) # and never called a GPU runtime start++ @unittest.skipIf(os.name == "nt", "signals")+ def test_a_silent_exit_is_retried_without_claiming_the_gpu_runtime(self):+ text, said = self.run_fake("import sys\nsys.exit(0)\n", retries=2)+ self.assertEqual(said.count("starting it again"), 2)+ self.assertIn("the engine exited before it wrote anything to its log (exit code 0)", said)+ self.assertNotIn("stopped while the GPU runtime was starting", said)+ self.assertIn("the engine process ended: exit code 0", text)++ @unittest.skipIf(os.name == "nt", "signals")+ def test_the_runtimes_own_failure_is_named(self):+ code = ("import os, sys\nsys.stderr.write(\"terminate called after throwing an instance of 'rocr::AMD::hsa_exception'"+ "\\n\")\nsys.stderr.flush()\nos._exit(134)\n")+ text, said = self.run_fake(code, retries=1)+ self.assertEqual(said.count("starting it again"), 1)+ self.assertIn("stopped while the GPU runtime was starting", said)+ self.assertIn("hsa_exception", text) # the engine's own last line is in the error++class StartNarrator(unittest.TestCase):"""#505: the start's words say what happens to the experts - --mmap-experts loads nothing into RAM up front."""