Skip to content

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: an engine that exits after an unread ERR line says why (#997 #890)

Chen Cheng5b5455982f9d
diff --git a/serve/server.py b/serve/server.py
index 92d11cfce..8357b42b9 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -540,6 +540,7 @@ class StrataEngine:
"""
silence_s = ENGINE_SILENCE_S # #481: main() sets the config's engine_silence_s (survives restart())
silent_note = None # #481: why the server ended a silent engine (death_note says it)
+ last_err = None # #997: an ERR that was its last stdout line (death_note says it)
batch = 0 # --batch: the engine's batch slots (0: one request at a time)
# `last`: the figures of the engine's last DONE line. With batch slots several requests run at once, each on its
@@ -577,6 +578,7 @@ class StrataEngine:
self.progress_ms = 0 # PP's own milliseconds since the prompt started (its third field)
self.reused = 0 # RESUME: prompt tokens not read again (a client takes them out of the work)
self.silent_note = None
+ self.last_err = None
try: # a ready-made engine's BUILD.json says its version
self.info["version"] = json.loads((Path(exe).parent / "BUILD.json").read_text()).get("version")
except (OSError, ValueError):
@@ -668,6 +670,7 @@ class StrataEngine:
def _pump(self):
proc, lines = self.proc, self.lines # this process's: a restart replaces both (#344)
slot_q = self.slot_q
+ line = None
for line in proc.stdout:
# checked before batch routing: a fatal line is never a slot's own
if line.startswith(FATAL_PREFIXES):
@@ -690,6 +693,8 @@ class StrataEngine:
lines.put(line)
if self.proc is proc: # a killed engine's pump must not mark its successor dead
self.ended = True # its output closed: it is gone, even before the OS says so
+ if line and line.startswith("ERR"): # #997 #890: why it exited, though no request may read it
+ self.last_err = line[4:].strip() # (a failed batch window: every request reads its slot)
lines.put(None)
for q in slot_q:
q.put(None)
@@ -711,6 +716,9 @@ class StrataEngine:
return ("The engine stopped itself because it had stopped making progress - a hang it caught. Its log "
"line: " + line.strip() + " - please report it at github.com/Niko1221/Strata/issues.")
rc = self.proc.poll()
+ if rc is not None and rc >= 0 and self.last_err: # its own last words on stdout: they say why
+ return (f"The engine exited (code {rc}) after it reported: {self.last_err} - please report it at "
+ "github.com/Niko1221/Strata/issues with the log.")
last = next((x.strip() for x in reversed(tail.splitlines()) if x.strip().startswith(("strata", "ERR"))), "")
if rc is not None and rc >= 0 and last: # it ended by itself: its own last words say why (#215)
return (f"The engine exited (code {rc}). Its last log line: {last} - if that does not explain it, please "
diff --git a/serve/test_parallel.py b/serve/test_parallel.py
index 87171ac79..ed935ba6f 100644
--- a/serve/test_parallel.py
+++ b/serve/test_parallel.py
@@ -10,6 +10,7 @@ import tempfile
import threading
import time
import unittest
+import urllib.error
import urllib.request
from pathlib import Path
from unittest import mock
@@ -24,6 +25,7 @@ FAKE_BATCH = r'''import queue, sys, threading, time
args = sys.argv[1:]
slots = int(args[args.index("--batch") + 1]) if "--batch" in args else 0
fit = int(args[args.index("--fit") + 1]) if "--fit" in args else slots
+fail = "--fail-window" in args # #997: the first window over two slots fails
STEP = 0.02
CH = 32
lines, stop = queue.Queue(), threading.Event()
@@ -49,6 +51,9 @@ def reply(ids): # the rest of the reply after what the prompt already
active = {} # slot -> [tokens left, max_new, produced]
stopped = set() # BSTOPped slots: they end "cancel"
def window(): # one batch window: every active slot one token
+ if fail and len(active) >= 2: # as the engine: the reason on stdout, then exit code 1
+ print("ERR verify batch: layer 34 never rang (graph finished)", flush=True)
+ sys.exit(1)
for b in sorted(active):
left, max_new, produced = active[b]
t = left.pop(0) if left else 257
@@ -216,7 +221,7 @@ class PickSlot(unittest.TestCase):
class ParallelService(unittest.TestCase):
"""The real StrataEngine and Service over HTTP, the fake engine behind them."""
- def start(self, slots, fit=None, slot_cache=False):
+ def start(self, slots, fit=None, slot_cache=False, fail=False):
import serve.server as server
self.tmp = tempfile.TemporaryDirectory()
script = Path(self.tmp.name) / "fake_strata.py"
@@ -225,6 +230,7 @@ class ParallelService(unittest.TestCase):
real = server.subprocess.Popen
extra = ["--batch", str(slots)] + (["--fit", str(fit)] if fit is not None else []) + ["--log", str(self.log)]
extra += ["--slotcache"] if slot_cache else []
+ extra += ["--fail-window"] if fail else []
with mock.patch.object(server.subprocess, "Popen",
lambda cmd, **kw: real([sys.executable, str(script), *cmd[1:]], **kw)):
self.engine = StrataEngine("strata", extra)
@@ -413,6 +419,29 @@ class ParallelService(unittest.TestCase):
self.assertEqual(self.engine.pick_slot(mine[0] + [10, 11]), slot)
self.assertEqual(first["choices"][0]["message"]["content"], "ok, done.")
+ def test_a_failed_window_names_its_error(self):
+ # #997 #890: a batch window fails while every request reads its own slot's lines, so no request reads the
+ # engine's ERR line before it exits; the server's note on the death gives it instead of a guess
+ self.start(2, fail=True)
+ errors = []
+
+ def go(t):
+ try:
+ self.chat(t)
+ except urllib.error.HTTPError as e:
+ errors.append(e.code)
+
+ threads = [threading.Thread(target=go, args=(t,)) for t in ("first question LONGREPLY", "second question")]
+ for th in threads:
+ th.start()
+ time.sleep(0.05)
+ for th in threads:
+ th.join(30)
+ self.assertEqual(len(errors), 2, errors)
+ note = self.engine.death_note()
+ self.assertIn("exited (code 1)", note)
+ self.assertIn("verify batch: layer 34 never rang (graph finished)", note)
+
if __name__ == "__main__":
unittest.main()