Skip to content

Commit f540bbb

Browse files
committed
fix(client): copy dict handler result before stamping defaults
_handle_chat's single-shot dict path did payload = result then setdefault'd text='' and finish_reason='stop' onto the same dict. A chat_handler that returns a class-attribute / cached response dict had those defaults baked into its template on every call, surprising the caller and bleeding state across invocations.
1 parent 59f8aed commit f540bbb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

zhub/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ async def _handle_chat(pub: ZhubPublication, ws, env: Envelope) -> None:
408408
if isinstance(result, str):
409409
payload = {"text": result, "finish_reason": "stop"}
410410
elif isinstance(result, dict):
411-
payload = result
411+
# Copy first — setdefault on the handler-supplied dict would mutate
412+
# a caller's template / cached response by adding text:"" + finish_reason:"stop".
413+
payload = dict(result)
412414
payload.setdefault("finish_reason", "stop")
413415
payload.setdefault("text", "")
414416
else:

0 commit comments

Comments
 (0)