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: the engine-exited-before-READY error shows this start's last 20 log lines (#496)
Niko12213af82092d696
diff --git a/serve/server.py b/serve/server.pyindex 542ce8f40..3913b1f27 100644--- a/serve/server.py+++ b/serve/server.py@@ -174,6 +174,27 @@ def start_failure_hint(log: str | None, offset: int) -> str:return ". mtp: " + DRAFT_HEAD_FAIL + ". " + (" ".join(said) if said else "Hint: " + DRAFT_HEAD_HINT)+def start_log_tail(log: str | None, offset: int, n: int = 20) -> str:+ """#496: the last n lines this start wrote to the engine log, for the error when the engine ended before READY -+ whatever the failure, the engine's own reason is in them (people posted the traceback without the log). "" when+ there is no log or nothing in it from this start."""+ if not log:+ return ""+ try:+ with open(log, "rb") as f:+ f.seek(0, 2)+ start = max(offset, f.tell() - 64 * 1024) # enough for 20 lines, never an earlier start's+ f.seek(start)+ text = f.read().decode("utf-8", "replace")+ except (OSError, ValueError):+ return ""+ lines = text.splitlines()[1 if start > offset else 0:] # not a line cut in half+ lines = [x.rstrip() for x in lines if x.strip()][-n:]+ if not lines:+ return ""+ return "\nthe engine log's last lines:\n" + "\n".join(" " + x for x in lines)++def echo_requests(log_path: str, offset: int) -> None:"""STRATA_REQUEST_LINES=1: one stdout line per finished request, from the engine's own summary in its log.@@ -307,8 +328,16 @@ class StrataEngine:breakloading.set()if self.max_context <= 0:+ try: # its pipes and our handle on its log (the log stays)+ self.proc.wait(timeout=5)+ self.proc.stdin.close()+ self.proc.stdout.close()+ if log:+ self.log.close()+ except (OSError, subprocess.TimeoutExpired):+ passraise RuntimeError("the engine exited before it was ready" + (f" (see {log})" if log else "") +- start_failure_hint(log, log_start))+ start_failure_hint(log, log_start) + start_log_tail(log, log_start))# (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 onesif self.info.get("engine"):diff --git a/serve/test_server.py b/serve/test_server.pyindex 2099ba9af..2497455ed 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -876,6 +876,48 @@ class DraftHeadHint(unittest.TestCase):self.assertEqual(start_failure_hint(str(Path(tempfile.mkdtemp()) / "missing.log"), 0), "")+class StartFailureLog(unittest.TestCase):+ """#496: whatever stopped the engine before READY, the error carries this start's last log lines."""++ def test_the_last_lines_of_this_start(self):+ from serve.server import start_log_tail+ d = tempfile.mkdtemp()+ p = Path(d) / "engine.log"+ before = "strata serve: an earlier start's line\n"+ p.write_text(before + "".join(f"strata serve: line {i}\n" for i in range(30)) + "\n"+ "strata serve: cannot open the pack\n", encoding="utf-8")+ tail = start_log_tail(str(p), len(before.encode()))+ self.assertIn("the engine log's last lines:", tail)+ self.assertIn("cannot open the pack", tail)+ self.assertIn("line 29", tail)+ self.assertNotIn("line 10\n", tail + "\n") # 20 lines: 11..29 and the last one+ self.assertIn("line 11", tail)+ self.assertNotIn("earlier start", tail)+ short = start_log_tail(str(p), len(before.encode()), n=3)+ self.assertEqual(short.count("\n "), 3)+ self.assertEqual(start_log_tail(str(p), p.stat().st_size), "") # nothing from this start+ self.assertEqual(start_log_tail(None, 0), "")+ self.assertEqual(start_log_tail(str(Path(d) / "missing.log"), 0), "")++ def test_the_start_error_has_them(self):+ import serve.server as server+ fake = "import sys\nsys.stderr.write('strata serve: cannot open the pack packs/x\\n')\nsys.exit(2)\n"+ with tempfile.TemporaryDirectory() as d:+ script, log = Path(d) / "fake_strata.py", Path(d) / "strata.log"+ script.write_text(fake, encoding="utf-8")+ log.write_text("an earlier start\n", encoding="utf-8")+ real = server.subprocess.Popen+ 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):+ with self.assertRaises(RuntimeError) as cm:+ StrataEngine("strata", [], log=str(log))+ text = str(cm.exception)+ self.assertIn("exited before it was ready", text)+ self.assertIn("cannot open the pack packs/x", text)+ self.assertNotIn("an earlier start", text)++class CancelledRead(unittest.TestCase):"""#471: a request cancelled while its prompt was read is recorded with the tokens the engine read (the DONEline's 15th field), not the whole prompt; an older engine's line (no such field) keeps the whole prompt."""