Skip to content

fix(parser): implement request dedup and deltaize for token accuracy#13

Merged
hmenzagh merged 4 commits into
betafrom
fix/parser/dedup-and-deltaize
Apr 13, 2026
Merged

fix(parser): implement request dedup and deltaize for token accuracy#13
hmenzagh merged 4 commits into
betafrom
fix/parser/dedup-and-deltaize

Conversation

@hmenzagh
Copy link
Copy Markdown
Owner

Summary

Implements comprehensive token and cost accuracy fixes:

Commits

  • fix(parser): implement request dedup and deltaize for token accuracy
  • fix(data): add versioned cache schema with automatic invalidation
  • feat(ui): add cache-state banner and update dashboard styling
  • docs: document accurate token counting methodology in README

Changes

Token & cost accuracy — Claude Code logs the same API response in multiple places (streaming chunks, sub-agent mirrors, /compact retries). CCMeter now dedupes by requestId (Anthropic's billing unit), eliminating the 2–3× over-counting previously observed on days with heavy sub-agent activity.

Multi-minute timeline accuracy — long streaming responses (extended thinking + large outputs) now correctly distribute their tokens across the minutes they actually spanned, instead of collapsing onto the final completion minute.

Cache schema versioning — new versioned cache with automatic invalidation on schema changes, eliminating manual intervention needed when upgrading.

Cache-state banner — UI now displays recovery banners on startup when cache is rebuilt or unreadable.

Documentation — README updated with 'Accurate token counting' section explaining the dedup methodology.

- Deduplicate API responses by requestId to eliminate 2-3x overcounting
  from streaming chunks, sub-agent mirrors, and compact retries
- Implement deltaize algorithm to correctly distribute tokens across
  minutes for long streaming responses with extended thinking
- Preserve code metrics on partial-overlap streams using ghost markers
- Fix ghost event filtering in model breakdowns

Fixes token and cost accuracy issues observed with heavy sub-agent usage.
- Implement schema_version tracking in history.json
- Auto-invalidate and rebuild cache on version mismatch
- Fixes cache migration without manual user intervention
- Display cache state banner on startup (rebuilt or unreadable)
- Add CCMETER_FORCE_BANNER env var for testing
- Update dashboard styling for rate tracking components
- Include new rate-tracking asset
- Add 'Accurate token counting' section explaining dedup approach
- Update version to 2.0.0-beta.3
- Document all fixes and new features in CHANGELOG
@hmenzagh hmenzagh changed the base branch from main to beta April 13, 2026 20:15
@hmenzagh hmenzagh merged commit 6bacef6 into beta Apr 13, 2026
11 checks passed
@hmenzagh hmenzagh deleted the fix/parser/dedup-and-deltaize branch April 13, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant