Skip to content

Commit 0d9ce1f

Browse files
committed
fix: clamp output token count to prevent negative values
When a provider reports reasoningTokens > outputTokens (observed with kimi-k2.5 thinking variant via Kilo gateway), the subtraction in getUsage produces a negative output token count. This propagates into the TUI, extension UI, session exports, and lifetime stats. Clamp the result to zero to prevent negative display values. Fixes #9168 Made-with: Cursor
1 parent f0dd035 commit 0d9ce1f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/opencode/src/session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export namespace Session {
316316
const tokens = {
317317
total,
318318
input: adjustedInputTokens,
319-
output: safe(outputTokens - reasoningTokens),
319+
output: Math.max(0, safe(outputTokens - reasoningTokens)),
320320
reasoning: reasoningTokens,
321321
cache: {
322322
write: cacheWriteInputTokens,

0 commit comments

Comments
 (0)