Drop max_tokens cap on codegen; qwen3 reasoning truncation left content empty

qwen38-iq3s reasons extensively before emitting the skill body. A max_tokens
cap truncated the hidden reasoning (finish_reason: length) leaving content
empty, so the body write failed with 'skill body is empty'. Omit max_tokens
so the model runs to completion (~7 min); reasoning is filtered automatically
since only content is read. Client timeout default raised to 1200s.
This commit is contained in:
Denton Social
2026-09-24 01:20:18 -05:00
parent 440e49e76e
commit 9e365446a3
4 changed files with 64 additions and 20 deletions
+29 -3
View File
@@ -163,10 +163,12 @@ def test_merge_skill_bodies_creates_missing_category(tmp_path):
class _FakeOpenAI(BaseHTTPRequestHandler):
reply: str = GOOD_BODY
received: list = []
def do_POST(self):
length = int(self.headers.get("Content-Length") or 0)
self.rfile.read(length)
raw = self.rfile.read(length).decode("utf-8")
type(self).received.append(json.loads(raw))
body = json.dumps({"choices": [{"message": {"content": self.reply}}]}).encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "application/json")
@@ -179,7 +181,7 @@ class _FakeOpenAI(BaseHTTPRequestHandler):
def _fake_server(reply: str) -> tuple[ThreadingHTTPServer, str]:
handler = type("Handler", (_FakeOpenAI,), {"reply": reply})
handler = type("Handler", (_FakeOpenAI,), {"reply": reply, "received": []})
httpd = ThreadingHTTPServer(("127.0.0.1", 0), handler)
threading.Thread(target=httpd.serve_forever, daemon=True).start()
return httpd, f"http://127.0.0.1:{httpd.server_address[1]}/v1"
@@ -216,4 +218,28 @@ def test_codegen_client_unreachable_raises(tmp_path):
tree = build_tree(build_skills({"skills": {}}))
draft = SkillDraft(name="probe", description="Probe the service.")
with pytest.raises(Exception):
generate_skill_body(client, Request("is the service up?"), "tracking", draft, tree)
generate_skill_body(client, Request("is the service up?"), "tracking", draft, tree)
def test_chat_omits_max_tokens_by_default():
httpd, base = _fake_server(GOOD_BODY)
try:
client = CodegenClient(base_url=base, model="test", timeout=10)
client.chat([{"role": "user", "content": "hi"}])
body = httpd.RequestHandlerClass.received[0]
assert "max_tokens" not in body
finally:
httpd.shutdown()
httpd.server_close()
def test_chat_includes_max_tokens_when_set():
httpd, base = _fake_server(GOOD_BODY)
try:
client = CodegenClient(base_url=base, model="test", timeout=10)
client.chat([{"role": "user", "content": "hi"}], max_tokens=512)
body = httpd.RequestHandlerClass.received[0]
assert body["max_tokens"] == 512
finally:
httpd.shutdown()
httpd.server_close()