From 99cbebe30e6510189e3ccf25224cb2e027a004f8 Mon Sep 17 00:00:00 2001 From: Hafiz Ahmad Ashfaq Date: Thu, 18 Jun 2026 01:55:10 +0500 Subject: [PATCH] fix(llm): coerce None output_tokens to 0 in completion_result_to_response (#809) Some providers return output_tokens=None on certain completions (observed with Gemini on tool-loop completions). HonchoLLMCallResponse types output_tokens as int, so the None propagates into a Pydantic validation error that aborts the call. In practice this surfaces in the Dreamer: a dream starts, deduction succeeds, then induction crashes before inductive conclusions are persisted. Coerce None -> 0 so token accounting degrades gracefully (under-counts rather than crashing) for providers that omit output token counts. Co-authored-by: Claude Opus 4.8 (1M context) --- src/llm/executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llm/executor.py b/src/llm/executor.py index 87db8dd0..99c73c70 100644 --- a/src/llm/executor.py +++ b/src/llm/executor.py @@ -167,7 +167,7 @@ def completion_result_to_response( return HonchoLLMCallResponse( content=result.content, input_tokens=result.input_tokens, - output_tokens=result.output_tokens, + output_tokens=result.output_tokens or 0, cache_creation_input_tokens=result.cache_creation_input_tokens, cache_read_input_tokens=result.cache_read_input_tokens, finish_reasons=[result.finish_reason] if result.finish_reason else [],