Skip to content

fix: normalize cache token usage semantics - #1390

Merged
tiann merged 1 commit into
tiann:mainfrom
KorenKrita:fix/usage-cache-semantics
Aug 6, 2026
Merged

fix: normalize cache token usage semantics#1390
tiann merged 1 commit into
tiann:mainfrom
KorenKrita:fix/usage-cache-semantics

Conversation

@KorenKrita

Copy link
Copy Markdown
Contributor

Summary

  • define a self-describing usage marker for producers whose input totals include cache reads and writes
  • normalize historical and current usage into one inclusive-input contract before storing derived usage events
  • handle cumulative snapshot resets consistently and preserve primary input/output usage when cache partitions are malformed
  • rebuild derived usage indexes through the v21 migration

Historical compatibility

  • Claude assistant usage is normalized from cache-exclusive input
  • Codex and Kimi cumulative/provider totals retain inclusive input semantics
  • Pi imports and current generic ACP producers use explicit markers
  • dashboard-era generic ACP messages with their own model property remain inclusive
  • older unmarked generic ACP messages are conservatively normalized from cache-exclusive input

Validation

  • bun run typecheck
  • Hub usage and migration tests
  • Codex, Kimi, Pi, and generic producer tests
  • full Hub test suite
  • independent adversarial review of cumulative resets, malformed cache partitions, migration behavior, and mixed old/new events

Closes #1389

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • No actionable findings.

Summary
Review mode: initial

No correctness, security, regression, data-loss, performance, or maintainability issues were found in the modified lines. Residual risk: schema v21 reindexes historical usage using producer-shape heuristics, so a provider payload variant absent from the fixtures could still be misclassified.

Testing

  • Not run (automation; PR content was not executed). GitHub test check passed for head 3fa9cae7.

HAPI Bot

Normalize usage input at parse time, mark inclusive producers, rebuild derived usage indexes, and preserve valid primary usage when cache partitions are malformed.

Fixes tiann#1389
@KorenKrita
KorenKrita force-pushed the fix/usage-cache-semantics branch from 3fa9cae to cb29000 Compare August 6, 2026 04:23

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • No actionable findings.

Summary
Review mode: follow-up after new commits

No correctness, security, regression, data-loss, performance, or maintainability issues were found in the modified lines. Residual risk: cumulative reset handling and legacy input-semantics reconstruction still depend on provider-shaped historical fixtures; the current CI test check has not completed yet.

Testing

  • Not run (automation; PR content was not executed). GitHub test check is in progress for head cb29000d.

HAPI Bot

@tiann
tiann merged commit 256ad98 into tiann:main Aug 6, 2026
2 checks passed
heavygee added a commit to heavygee/hapi that referenced this pull request Aug 6, 2026
Absorb tiann#1376 session-summary hub toggle (opt-in) + tiann#1388/tiann#1390/tiann#1391.
Keep soup Overseer/FUE/PR-awareness/runners on Settings → General.

Co-authored-by: Cursor <cursoragent@cursor.com>
heavygee added a commit to heavygee/hapi that referenced this pull request Aug 6, 2026
Rebase union onto tip-forward remat after upstream/main (tiann#1390 owns
schema v21 usage semantics). Keep pin column as idempotent v21→v22.

Co-authored-by: Cursor <cursoragent@cursor.com>
heavygee added a commit to heavygee/hapi that referenced this pull request Aug 6, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

fix: cache hit rate can exceed 100% due to mixed input token semantics

2 participants