Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(serve): a tool call whose arguments are not an object answered 500
kevin9327b97d103ece8c
diff --git a/c/openai_server.py b/c/openai_server.pyindex 59890c21..5079aaa6 100644--- a/c/openai_server.py+++ b/c/openai_server.py@@ -1608,8 +1608,17 @@ def render_chat(messages, enable_thinking=False, reasoning_effort=None, tools=Noargs = json.loads(args)except (json.JSONDecodeError, TypeError):args = {}+ if not isinstance(args, dict):+ # `arguments` that is valid JSON but not an object ("[1,2]",+ # "5", a bare list) reached .items() and raised+ # AttributeError, which do_POST answers with HTTP 500. The+ # same field is already tolerated when it does not parse at+ # all, and every sibling renderer renders the call without+ # arguments instead of failing; this is the one branch that+ # was never completed.+ args = {}prompt.append(BOX_START + (fn.get("name") or ""))- for key, value in (args or {}).items():+ for key, value in args.items():prompt.append(f"<arg_key>{key}</arg_key><arg_value>"+ (value if isinstance(value, str)else json.dumps(value, ensure_ascii=False)) + "</arg_value>")@@ -1905,8 +1914,10 @@ def _glm53_tool_calls(calls):arguments = json.loads(arguments)except ValueError:arguments = {}+ if not isinstance(arguments, dict):+ arguments = {} # same gap as render_chat abovepieces = [f"<tool_call>{name}"]- for key, value in (arguments or {}).items():+ for key, value in arguments.items():rendered = value if isinstance(value, str) else json.dumps(value, ensure_ascii=False)pieces.append(f"<arg_key>{key}</arg_key><arg_value>{rendered}</arg_value>")pieces.append("</tool_call>")diff --git a/c/tests/test_openai_server.py b/c/tests/test_openai_server.pyindex fa525d86..d85a00de 100644--- a/c/tests/test_openai_server.py+++ b/c/tests/test_openai_server.py@@ -255,6 +255,42 @@ class TemplateTest(unittest.TestCase):"name": "fn", "arguments": "not json"}}]}])self.assertIn("J 2 8\nfnnot json", prompt)+ def test_glm_renders_a_tool_call_whose_arguments_are_not_an_object(self):+ """`arguments` that parses but is not an object must not kill the request.++ Both GLM renderers already tolerate `arguments` that does not parse at+ all -- the except branch sets {} -- and every sibling renderer (Kimi+ above, Qwen3.8, DeepSeek V4/V4.1) renders the call without arguments+ rather than failing. Only the "parsed, but not an object" case reached+ .items(), raised AttributeError, and came back as HTTP 500 "The colibri+ engine failed to process the request." on a request the engine never+ saw.+ """+ import openai_server as srv+ for arguments in ('[1, 2]', '"text"', '5', [1, 2], 7):+ with self.subTest(arguments=arguments):+ messages = [+ {"role": "user", "content": "run it"},+ {"role": "assistant", "content": "", "tool_calls": [+ {"id": "x", "type": "function",+ "function": {"name": "fn", "arguments": arguments}}]},+ {"role": "tool", "content": "done"},+ ]+ glm = render_chat(list(messages))+ self.assertIn("fn", glm)+ self.assertNotIn("<arg_key>", glm)+ glm53 = srv.render_chat_glm53(list(messages))+ self.assertIn("<tool_call>fn", glm53)+ self.assertNotIn("<arg_key>", glm53)+ # An object still renders its arguments, on both renderers.+ renders = [{"role": "assistant", "content": "", "tool_calls": [+ {"id": "x", "type": "function",+ "function": {"name": "fn", "arguments": '{"city": "Rome"}'}}]}]+ self.assertIn("<arg_key>city</arg_key><arg_value>Rome</arg_value>",+ render_chat(list(renders)))+ self.assertIn("<arg_key>city</arg_key><arg_value>Rome</arg_value>",+ srv.render_chat_glm53(list(renders)))+def test_kimi_still_rejects_unknown_roles(self):with self.assertRaisesRegex(APIError, "Unsupported role"):render_chat_kimi([{"role": "critic", "content": "hm"}])@@ -1539,6 +1575,26 @@ class HTTPTest(unittest.TestCase):self.addCleanup(caught.exception.close)self.assertEqual(caught.exception.code, 400)+ def test_tool_call_arguments_that_are_not_an_object_do_not_fail_the_request(self):+ """A replayed tool call with `arguments: "[1, 2]"` answered HTTP 500.++ render_chat reached `(args or {}).items()` with a parsed list, and the+ AttributeError became do_POST's catch-all 500 "The colibri engine failed+ to process the request." -- which OpenAI SDKs retry, against an engine+ that was never asked anything.+ """+ body = {"model": "test-model", "messages": [+ {"role": "user", "content": "run it"},+ {"role": "assistant", "content": "", "tool_calls": [+ {"id": "x", "type": "function",+ "function": {"name": "fn", "arguments": "[1, 2]"}}]},+ {"role": "tool", "tool_call_id": "x", "content": "done"},+ {"role": "user", "content": "and now?"},+ ]}+ with self.request("/v1/chat/completions", body) as response:+ self.assertEqual(response.status, 200)+ self.assertEqual(json.load(response)["object"], "chat.completion")+class ClientHangupTest(unittest.TestCase):"""A client that disconnects mid-response must not print a traceback.