Skip to content

fix: correct cache hit rate calculation and improve display format#776

Merged
FL4TLiN3 merged 3 commits intomainfrom
fix/cache-hit-rate-calculation
Mar 13, 2026
Merged

fix: correct cache hit rate calculation and improve display format#776
FL4TLiN3 merged 3 commits intomainfrom
fix/cache-hit-rate-calculation

Conversation

@FL4TLiN3
Copy link
Contributor

Summary

  • Fix cache hit rate formula that was double-counting cached tokens in the denominator. inputTokens (from AI SDK's prompt_tokens) already includes cached tokens, so the old formula cached / (input + cached) was reporting ~47% when the actual rate was ~88%.
  • Restructure token display to show cache info as a parenthetical breakdown of input tokens, making the relationship clear: In 525.1k (Cached 461.3K, Cache Hit 87.85%) · Out 5.1k

Test plan

  • bun run test --filter @perstack/tui-components passes (68 tests)
  • bun run validate:changeset passes
  • Visual check: run perstack with a cached provider and confirm the new format renders correctly

🤖 Generated with Claude Code

FL4TLiN3 and others added 3 commits March 13, 2026 18:44
The cache hit rate formula was double-counting cached tokens because
inputTokens (from AI SDK's prompt_tokens) already includes cached
tokens. The old formula `cached / (input + cached)` produced ~47%
when the actual rate was ~88%.

Also restructures the token display from:
  Tokens: In 525.1k · Out 5.1k · Cache 461.3k/46.77%
To:
  Tokens: In 525.1k (Cached 461.3K, Cache Hit 87.85%) · Out 5.1k

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@FL4TLiN3 FL4TLiN3 merged commit de15c78 into main Mar 13, 2026
11 checks passed
@FL4TLiN3 FL4TLiN3 deleted the fix/cache-hit-rate-calculation branch March 13, 2026 18:49
@FL4TLiN3 FL4TLiN3 mentioned this pull request Mar 13, 2026
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