From 22c179ac92630b640debfce0782231d50d0b3b1f Mon Sep 17 00:00:00 2001 From: ZakWork Date: Thu, 13 Nov 2025 00:56:25 +0000 Subject: [PATCH] fix: handle None input_other in token usage Add defensive handling for cases where result.usage.input_other is None by setting it to 0. This prevents potential issues when provider returns token counts as None and ensures the app does not crash. --- src/kimi_cli/soul/kimisoul.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kimi_cli/soul/kimisoul.py b/src/kimi_cli/soul/kimisoul.py index ac902cb0..a35f6782 100644 --- a/src/kimi_cli/soul/kimisoul.py +++ b/src/kimi_cli/soul/kimisoul.py @@ -4,7 +4,7 @@ from collections.abc import Sequence from functools import partial from typing import TYPE_CHECKING - +from dataclasses import replace import kosong import tenacity from kosong import StepResult @@ -233,6 +233,12 @@ async def _kosong_step_with_retry() -> StepResult: logger.debug("Got step result: {result}", result=result) if result.usage is not None: # mark the token count for the context before the step + if result.usage.input_other is None: + logger.warning("input_other is None in token usage, setting to 0") + # Create new usage with input_other=0 + new_usage = replace(result.usage, input_other=0) + # Create new StepResult with updated usage + result = replace(result, usage=new_usage) await self._context.update_token_count(result.usage.input) wire_send(StatusUpdate(status=self.status))