fix(opencode): bill session-level reasoning tokens at the output rate - #1342
Open
ozymandiashh wants to merge 2 commits into
Open
fix(opencode): bill session-level reasoning tokens at the output rate#1342ozymandiashh wants to merge 2 commits into
ozymandiashh wants to merge 2 commits into
Conversation
When none of a session's messages produce a priced call, the SQLite parser falls back to the totals on OpenCode's session row. That path passed tokens_output alone to calculateCost and dropped tokens_reasoning, while still reporting reasoningTokens, so thinking tokens were shown but never charged. OpenCode bills reasoning at the output rate and the per-message path already did the same. Route both the fallback and buildAssistantCall through billableOutputTokens so they share one rule with the cache-rehydration path. The per-message change is behaviour-neutral for opencode and kilo-code; it only removes the hand-rolled sum that let the fallback drift. Refs getagentseal#1334
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While looking into #1334 I found that the SQLite session-level fallback in the OpenCode parser priced
tokens_outputand droppedtokens_reasoning, while still reporting the reasoning tokens. OpenCode bills reasoning at the output rate, and our per-message path already did, so a session that fell back to the session row showed thinking tokens but never charged for them.Both the fallback and
buildAssistantCallnow go throughbillableOutputTokens, the same rule the cache-rehydration path uses. For the per-message path that's behaviour-neutral; it just removes the duplicate sum that let the fallback drift. Displayed token totals don't change.Tests: a failing fixture test for the session-level fallback, plus regression locks for per-message reasoning pricing in both the SQLite and JSON parsers. With the fix reverted the new fallback test fails ($0.04965 vs $0.10965); with it in place the OpenCode, OpenCode-file, Kilo and models suites pass and tsc is clean.
This does not close #1334. That report has matching tokens and a different cost, which comes down to per-token rates rather than reasoning. I've asked for a per-model breakdown there.
Refs #1334