Skip to content

Commit f9e8934

Browse files
rajbosCopilot
andcommitted
fix: use actualTokens (API-reported) when uploading, matching extension display
The extension shows actualTokens > 0 ? actualTokens : estimatedTokens (calculateDetailedStats line 1558). The sync service was only reading cachedData.tokens (text-estimated ~20M) instead of cachedData.actualTokens (API-reported ~1.2B), causing a ~57x undercounting on the server dashboard. Apply the same preference: prefer actualTokens when available, fall back to text-estimated tokens for files without API usage data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0a4c482 commit f9e8934

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

vscode-extension/src/backend/services/syncService.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,15 @@ export class SyncService {
511511
// combination gets a share of the total proportional to how many interactions it had.
512512
// For the input/output split we use the output fraction from modelUsage (output tokens are
513513
// not inflated by context the same way input tokens are).
514-
const displayTokens: number = (typeof (cachedData as any).tokens === 'number' && (cachedData as any).tokens > 0)
515-
? (cachedData as any).tokens as number
516-
: 0;
514+
// Mirror the extension's own token preference: prefer actual API-reported tokens when
515+
// available (same logic as calculateDetailedStats: actualTokens > 0 ? actualTokens : estimatedTokens).
516+
// Text-estimated tokens (~20M) are far smaller than API-actual numbers (~1.2B) because
517+
// the estimators only measure visible conversation text, not the full context window.
518+
const estimatedTokens: number = typeof (cachedData as any).tokens === 'number'
519+
? (cachedData as any).tokens as number : 0;
520+
const cachedActualTokens: number = typeof (cachedData as any).actualTokens === 'number'
521+
? (cachedData as any).actualTokens as number : 0;
522+
const displayTokens: number = cachedActualTokens > 0 ? cachedActualTokens : estimatedTokens;
517523
const totalAllInteractions = Array.from(dayModelInteractions.values())
518524
.reduce((sum, m) => { m.forEach(c => { sum += c; }); return sum; }, 0);
519525

0 commit comments

Comments
 (0)