Skip to content

Commit 763bf64

Browse files
committed
fix(session): clamp output token count to prevent negative values (#9168)
1 parent b24baf9 commit 763bf64

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/opencode/src/session/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,22 @@ export namespace Session {
316316
const tokens = {
317317
total,
318318
input: adjustedInputTokens,
319-
output: safe(outputTokens - reasoningTokens),
319+
output: safe(Math.max(0, outputTokens - reasoningTokens)),
320320
reasoning: reasoningTokens,
321321
cache: {
322322
write: cacheWriteInputTokens,
323323
read: cacheReadInputTokens,
324324
},
325325
}
326326

327+
if (reasoningTokens > outputTokens) {
328+
log.warn("reasoningTokens exceeds outputTokens", {
329+
model: input.model.id,
330+
outputTokens,
331+
reasoningTokens,
332+
})
333+
}
334+
327335
// kilocode_change start - Use provider-reported cost when available for OpenRouter/Kilo
328336
const reported = KiloSession.providerCost({
329337
metadata: input.metadata,

0 commit comments

Comments
 (0)