Skip to content

Commit 304fd58

Browse files
DmitryGvozd12claude
authored andcommitted
fix(magnitude-core): fix cumulative token counting in ModelHarness._reportUsage()
The _reportUsage() method was incorrectly overwriting prevTotalInputTokens and prevTotalOutputTokens instead of accumulating them. This caused the tokensUsed event to emit inflated token counts (10-15x higher than actual API usage) when using non-Anthropic providers (e.g., openai-generic). Changed assignment operators from = to += to properly track cumulative token usage across multiple LLM calls. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dedb7c6 commit 304fd58

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/magnitude-core/src/ai/modelHarness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ export class ModelHarness {
170170
this.events.emit('tokensUsed', usage);
171171
//console.log("Usage:", usage);
172172

173-
this.prevTotalInputTokens = inputTokens;
174-
this.prevTotalOutputTokens = outputTokens;
173+
this.prevTotalInputTokens += inputTokens;
174+
this.prevTotalOutputTokens += outputTokens;
175175
}
176176

177177
async partialAct<T>(

0 commit comments

Comments
 (0)