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's clean-stop deadlines are named, and a test shows an engine that ignores STOP, QUIT and SIGTERM is killed
Niko12211d26952f724e
diff --git a/serve/server.py b/serve/server.pyindex 642497edb..606b70260 100644--- a/serve/server.py+++ b/serve/server.py@@ -92,6 +92,10 @@ def popen(what: str, args: list, role: str = "engine", **kw):raise+# How long close() gives the engine at each step of ending it (seconds). Module values so that a test can shorten them.+ENGINE_QUIT_WAIT_S, ENGINE_TERM_WAIT_S, ENGINE_KILL_WAIT_S = 20, 5, 20++def end_leftover_engines(exe: str) -> None:"""Before an engine starts: end the ones a lost server left running (strata_control/procs.py). Only a processthis install recorded whose starter is gone, or an orphan of exactly this executable running --serve, and only@@ -2351,8 +2355,9 @@ class StrataEngine:raise out_of_step(line)def close(self):- """End the engine process: QUIT first (the engine frees its memory itself - unpinning tens of GB can take- a while), then terminate, then kill, each given 20 s. Raises EngineStuck when it still runs after all three."""+ """End the engine process: STOP + QUIT first (the engine frees its memory itself - unpinning tens of GB can take+ a while; ENGINE_QUIT_WAIT_S), then terminate (ENGINE_TERM_WAIT_S), then kill (ENGINE_KILL_WAIT_S). Raises+ EngineStuck when it still runs after all three."""if self.proc is None:returntry:@@ -2363,14 +2368,14 @@ class StrataEngine:self.proc.stdin.write("STOP\nQUIT\n")self.proc.stdin.flush()self.proc.stdin.close() # Windows' detached stdin reader must see EOF before shutdown- self.proc.wait(timeout=20)+ self.proc.wait(timeout=ENGINE_QUIT_WAIT_S)except (OSError, ValueError, subprocess.TimeoutExpired):self.proc.terminate()- self.proc.wait(timeout=5)+ self.proc.wait(timeout=ENGINE_TERM_WAIT_S)except subprocess.TimeoutExpired:self.proc.kill()try:- self.proc.wait(timeout=20)+ self.proc.wait(timeout=ENGINE_KILL_WAIT_S)except subprocess.TimeoutExpired:raise EngineStuck("Strata is still releasing GPU/RAM; retry unloading after it exits") from Noneexcept OSError:diff --git a/serve/test_lifeline.py b/serve/test_lifeline.pyindex b85fc659d..73554097d 100644--- a/serve/test_lifeline.py+++ b/serve/test_lifeline.py@@ -136,3 +136,33 @@ class Lifeline(unittest.TestCase):if __name__ == "__main__":unittest.main()+++STUBBORN = (+ "import signal, sys, time\n"+ "if hasattr(signal, 'SIGTERM'): signal.signal(signal.SIGTERM, signal.SIG_IGN)\n"+ "print('READY 4096 stop', flush=True)\n"+ "time.sleep(600)\n" # never reads QUIT, never answers STOP, ignores SIGTERM+)+++class HardFallback(unittest.TestCase):+ """The clean stop has a deadline: an engine that ignores STOP, QUIT and SIGTERM is killed, and close() returns."""++ def test_an_engine_that_ignores_everything_is_killed(self):+ from unittest import mock+ from serve import server+ engine = server.StrataEngine("missing-executable", [], lazy=True)+ engine.proc = subprocess.Popen([sys.executable, "-c", STUBBORN], stdin=subprocess.PIPE, stdout=subprocess.PIPE,+ text=True, creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))+ engine.proc.stdout.readline()+ victim = engine.proc+ t0 = time.monotonic()+ with mock.patch.object(server, "ENGINE_QUIT_WAIT_S", 1), mock.patch.object(server, "ENGINE_TERM_WAIT_S", 1), \+ mock.patch.object(server, "ENGINE_KILL_WAIT_S", 10):+ engine.close()+ self.assertLess(time.monotonic() - t0, 12)+ self.assertIsNotNone(victim.poll(), "the engine is still running after close()")+ self.assertIsNone(engine.proc)+ if os.name == "posix":+ self.assertEqual(victim.returncode, -signal.SIGKILL, "it ignored SIGTERM, so only the kill ended it")