From 66d4b98ceb1ac9fcae3b7d2563ecd9c66ff200fc Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 05:48:56 -0800 Subject: [PATCH] fix(cline): keep a recorded zero cost at zero A request Cline recorded at cost 0 (a free model) was re-priced from tokens into a positive charge. Any recorded cost, zero included, is now kept; only a request with no cost field is priced from its tokens. --- src/providers/vscode-cline-parser.ts | 7 ++++--- tests/reported-cost-cache.test.ts | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/providers/vscode-cline-parser.ts b/src/providers/vscode-cline-parser.ts index ce3032b2..34f32c06 100644 --- a/src/providers/vscode-cline-parser.ts +++ b/src/providers/vscode-cline-parser.ts @@ -207,9 +207,10 @@ export function createClineParser(source: SessionSource, seenKeys: Set, const tsDate = entry.ts ? new Date(entry.ts) : null const timestamp = tsDate && !Number.isNaN(tsDate.getTime()) ? tsDate.toISOString() : '' // Cline's `cost` is what the request was billed on its real route - // (cache writes and gateway prices included); a token re-price would - // replace it with a list price for a model the task may not even name. - const isReported = typeof cost === 'number' && Number.isFinite(cost) && cost > 0 + // (cache writes and gateway prices included, 0 for a free model); a + // token re-price would replace it with a list price for a model the + // task may not even name. Only a missing cost is priced from tokens. + const isReported = typeof cost === 'number' && Number.isFinite(cost) && cost >= 0 const costUSD = isReported ? cost! : calculateCost(model, tokensIn, tokensOut, cacheWrites, cacheReads, 0) yield { diff --git a/tests/reported-cost-cache.test.ts b/tests/reported-cost-cache.test.ts index aab1b125..4a32e154 100644 --- a/tests/reported-cost-cache.test.ts +++ b/tests/reported-cost-cache.test.ts @@ -256,7 +256,7 @@ it('holds the reported-cost provider set to its documented membership', async () ]) }) -it('keeps a Cline request cost cold and warm, and re-prices requests without one', async () => { +it('keeps a Cline request cost, including a recorded zero, cold and warm, and re-prices requests without one', async () => { const tasks = join(HOME, '.cline', 'data', 'tasks') const writeTask = async (id: string, usage: Record) => { await mkdir(join(tasks, id), { recursive: true }) @@ -269,6 +269,7 @@ it('keeps a Cline request cost cold and warm, and re-prices requests without one } await writeTask('reported', { tokensIn: 1000, tokensOut: 200, cost: 0.5 }) await writeTask('unreported', { tokensIn: 1000, tokensOut: 200 }) + await writeTask('free', { tokensIn: 1000, tokensOut: 200, cost: 0 }) const { clearSessionCache, parseAllSessions } = await import('../src/parser.js') clearSessionCache() @@ -276,6 +277,7 @@ it('keeps a Cline request cost cold and warm, and re-prices requests without one clearSessionCache() const warm = (await parseAllSessions(undefined, 'cline')).reduce((s, p) => s + p.totalCostUSD, 0) + // The free request's recorded $0 stays $0; only the one without a cost is priced. const floor = 1000 * 3e-6 + 200 * 15e-6 expect(cold).toBeCloseTo(0.5 + floor, 10) expect(warm).toBeCloseTo(cold, 10)