Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Qwen and MiMo: bind the request log's name, so a stream does not cost the client its connection
MangetsuC1ea5dd57da99
diff --git a/tools/mimo/serve.py b/tools/mimo/serve.pyindex f2bb61a..e5e97b5 100644--- a/tools/mimo/serve.py+++ b/tools/mimo/serve.py@@ -514,8 +514,11 @@ def create_app(engine: Any, model_id: str, template: str) -> web.Application:# SSE keep-alive: off unless KYOJIN_SSE_PING_S names an interval (see tools/strix_halo/serve_ping.py).# A request copies this pinger, so its timers are its own; the start-up line reports the setting.app.update(ping=ServePing.from_env())- # Request log: off unless KYOJIN_REQLOG names a path (numbers and event names only).- app.update(reqlog=ReqLog.from_env(server="mimo"))+ # Request log: off unless KYOJIN_REQLOG names a path (numbers and event names only). The name is+ # bound here, not only stored on the app: the streaming route logs from inside its own scope, and+ # an unbound name there raises after the reply is complete, which costs the client its connection.+ reqlog = ReqLog.from_env(server="mimo")+ app.update(reqlog=reqlog)def observe(st: dict[str, Any], prompt_tokens: int) -> None:accepted = int(st.get("accepted_draft_tokens", 0))diff --git a/tools/mimo/test_serve.py b/tools/mimo/test_serve.pyindex e51e1f8..845bb5d 100644--- a/tools/mimo/test_serve.py+++ b/tools/mimo/test_serve.py@@ -676,6 +676,35 @@ class SSEKeepAliveTests(unittest.TestCase):self.assertLess(body.index(b": waiting"), body.index(b"hello")) # before the first tokenself.assertTrue(body.rstrip().endswith(b"data: [DONE]")) # the stream still ends the OpenAI way+ def test_a_streaming_reply_does_not_cost_the_client_its_connection(self):+ """The streaming route logs its summary while the reply is being closed: a name that is not+ bound there raises after the body is complete, and the client loses the connection it was+ reusing (the next request on it dies with ServerDisconnectedError, and the server logs a+ traceback per stream). Three streams on one client session must all succeed."""+ from aiohttp.test_utils import TestClient, TestServer++ class Slow(FakeEngine):+ async def generate(self, prompt, **kwargs):+ await asyncio.sleep(0.3)+ async for piece in FakeEngine.generate(self, prompt, **kwargs):+ yield piece++ async def check():+ client = TestClient(TestServer(serve.create_app(Slow("hello"), "m", TEMPLATE)))+ await client.start_server()+ dropped = 0+ for _ in range(3):+ try:+ response = await client.post("/v1/chat/completions", json={+ "model": "m", "stream": True, "messages": [{"role": "user", "content": "hi"}]})+ await response.read()+ except Exception: # noqa: BLE001 the bug drops the socket+ dropped += 1+ await client.close()+ return dropped++ self.assertEqual(run(check()), 0)+def test_nothing_is_written_when_the_switch_is_off(self):from aiohttp.test_utils import TestClient, TestServerdiff --git a/tools/qwen/serve.py b/tools/qwen/serve.pyindex 74193f1..9bf4ae1 100644--- a/tools/qwen/serve.py+++ b/tools/qwen/serve.py@@ -1268,8 +1268,11 @@ def create_app(engine: Any, model_id: str, template: str, defaults: dict[str, An# SSE keep-alive: off unless KYOJIN_SSE_PING_S names an interval (see tools/strix_halo/serve_ping.py).# A request copies this pinger, so its timers are its own; the start-up line reports the setting.app.update(ping=ServePing.from_env())- # Request log: off unless KYOJIN_REQLOG names a path (numbers and event names only).- app.update(reqlog=ReqLog.from_env(server="qwen"))+ # Request log: off unless KYOJIN_REQLOG names a path (numbers and event names only). The name is+ # bound here, not only stored on the app: the streaming routes log from inside their own scope, and+ # an unbound name there raises after the reply is complete, which costs the client its connection.+ reqlog = ReqLog.from_env(server="qwen")+ app.update(reqlog=reqlog)def err(status: int, message: str) -> web.Response:return web.json_response({"error": {"message": message, "type": "invalid_request_error", "code": status}},diff --git a/tools/qwen/test_serve.py b/tools/qwen/test_serve.pyindex 7b12afe..a9a2390 100644--- a/tools/qwen/test_serve.py+++ b/tools/qwen/test_serve.py@@ -1020,6 +1020,35 @@ class SSEKeepAliveTests(unittest.TestCase):self.assertLess(body.index(b": waiting"), body.index(b"hel")) # before the first tokenself.assertTrue(body.rstrip().endswith(b"data: [DONE]")) # the stream still ends the OpenAI way+ def test_a_streaming_reply_does_not_cost_the_client_its_connection(self):+ """The streaming route logs its summary while the reply is being closed: a name that is not+ bound there raises after the body is complete, and the client loses the connection it was+ reusing (the next request on it dies with ServerDisconnectedError, and the server logs a+ traceback per stream). Three streams on one client session must all succeed."""+ from aiohttp.test_utils import TestClient, TestServer++ class Slow(FakeEngine):+ async def generate(self, prompt, **kwargs):+ await asyncio.sleep(0.3)+ async for piece in FakeEngine.generate(self, prompt, **kwargs):+ yield piece++ async def check():+ client = TestClient(TestServer(serve.create_app(Slow("hello"), "m", "{{ messages[0].content }}")))+ await client.start_server()+ dropped = 0+ for _ in range(3):+ try:+ response = await client.post("/v1/chat/completions", json={+ "model": "m", "stream": True, "messages": [{"role": "user", "content": "hi"}]})+ await response.read()+ except Exception: # noqa: BLE001 the bug drops the socket+ dropped += 1+ await client.close()+ return dropped++ self.assertEqual(run(check()), 0)+def test_nothing_is_written_when_the_switch_is_off(self):class Slow(FakeEngine):async def generate(self, prompt, **kw):