Description
What happens
The harness spend figure shown as \Spent so far: \ on this session's model calls (N tokens)\ adds \ okens.reasoning\ on top of \ okens.input + tokens.output.
Why it is wrong
\ ooling/util/src/token-usage.ts\ states the contract the rest of the codebase follows:
\\ s
/**
- Normalized model usage follows the AI SDK contract: \output\ already
- includes reasoning tokens.
easoning\ is a displayed subset of \output, - never an additional quantity to bill or add to a context total.
*/
\\
\src/session/usage.ts\ therefore uses \TokenUsage.total, which excludes
easoning. The harness did not, so a reasoning model reported more tokens than the provider billed.
Impact
\harness.cost.max_usd\ is a soft ceiling. \Cost.attribute/the \env.lines\ hook compares the inflated token figure's companion cost against that ceiling, so a long reasoning session can cross the ceiling while real spend is well under it, triggering a wrap-up reminder that ends the work early. The figure is also what the model reads, so it reasons about a wrong total.
Reproduction
A single assistant message with \ okens: { input: 1000, output: 2000, reasoning: 1500, cache: { read: 0, write: 0 } }\ should count 3,000 tokens. Current code reports 4,500.
\\ s
await Session.updateMessage({ ... tokens: { input: 1_000, output: 2_000, reasoning: 1_500, cache: { read: 0, write: 0 } } })
// then seed and read HarnessState.get(id).spend.tokens -> 4500
\\
Suggested fix
Use \TokenUsage.uncached(tokens)\ in both places in \src/harness/cost.ts. That is exactly \input + output, and it is the canonical helper for the quantity.
Activity