Skip to content

Commit 5fe2b70

Browse files
committed
fix(client): _handle_chat coerces None handler result to empty text
A chat_handler that forgets `return` returns None. The single-shot else branch called `str(result)`, shipping the literal three-character string "None" over the wire as the assistant reply. Special-case None → empty text so the common publisher-side mistake fails quiet, not embarrassingly. Matches the JS port's `String(awaited ?? '')`.
1 parent f31e34d commit 5fe2b70

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

zhub/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ async def _handle_chat(pub: ZhubPublication, ws, env: Envelope) -> None:
425425
payload = dict(result)
426426
payload.setdefault("finish_reason", "stop")
427427
payload.setdefault("text", "")
428+
elif result is None:
429+
# Handler forgot `return` (function body ran a `print` then fell off
430+
# the end). Emit an empty response, not `str(None) == "None"`, which
431+
# would ship the literal three-character string "None" over the
432+
# wire as the assistant reply. Matches the JS port.
433+
payload = {"text": "", "finish_reason": "stop"}
428434
else:
429435
payload = {"text": str(result), "finish_reason": "stop"}
430436
await ws.send(Envelope(

0 commit comments

Comments
 (0)