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: a <tool_call> in the reasoning that never closes stops holding the thinking back after 32 KiB (#804)
Niko1221ee412cd776c3
diff --git a/serve/frontend.py b/serve/frontend.pyindex 500ceeb0b..716e64f80 100644--- a/serve/frontend.py+++ b/serve/frontend.py@@ -538,6 +538,9 @@ def parse_tool_call(body: str, schema: dict | None = None) -> ToolCall:return ToolCall(name=name, arguments=args)+RCALL_MAX = 32768 # the most of a `<tool_call>` inside the reasoning that is held while waiting for its end (#804)++class OutputParser:"""Incremental parser of the model's text. Feed deltas; get events. A tag split across deltas is held backuntil it is complete, so clients never see `<tool_` or `</thi`."""@@ -701,6 +704,10 @@ class OutputParser:out.append(Event("reasoning", self.buf[:len(CALL_START) + think]))self.buf = body[think:]self.state = "reasoning"+ elif len(body) > RCALL_MAX: # a tag in the prose that never closes: stop holding the thinking back+ out.append(Event("reasoning", self.buf))+ self.buf = ""+ self.state = "reasoning"else:return outelif self.state == "reasoning":diff --git a/serve/test_reasoning_tools.py b/serve/test_reasoning_tools.pyindex a75adcd1d..4468fbd35 100644--- a/serve/test_reasoning_tools.py+++ b/serve/test_reasoning_tools.py@@ -10,6 +10,7 @@ from __future__ import annotationsimport jsonimport sysimport unittest+import unittest.mockimport urllib.requestfrom pathlib import Path@@ -93,6 +94,16 @@ class Parser(unittest.TestCase):self.assertEqual(len([e for e in evs if e.kind == "tool_call"]), 1)self.assertEqual(joined(evs, "reasoning"), "think")+ def test_a_tag_that_never_closes_does_not_hold_the_thinking_back(self):+ from serve import frontend+ text = "a <tool_call> " + "thinking on and on " * 3000 + "</think>\n\nanswer"+ with unittest.mock.patch.object(frontend, "RCALL_MAX", 1000):+ evs = run(text, 50)+ first_reasoning_at = next(i for i, e in enumerate(evs) if e.kind == "reasoning" and len(e.text) > 100)+ self.assertLess(first_reasoning_at, 100) # streamed, not kept until </think>+ self.assertEqual(joined(evs, "reasoning"), text.split("</think>")[0])+ self.assertEqual(joined(evs, "content"), "answer")+def test_a_partial_tag_is_held(self):p = OutputParser(thinking=True, tools=TOOLS)evs = p.feed("hello <tool_c")