Skip to content

fix(daily-cache): stop token-only slices inflating day totals on merge - #1788

Open
iamtoruk wants to merge 1 commit into
mainfrom
fix/daily-cache-token-inflation
Open

iamtoruk wants to merge 1 commit into
mainfrom
fix/daily-cache-token-inflation

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Token totals on some days grow with every cache version bump.

A slice with tokens but no calls, cost or savings (a Hermes or Copilot session total) was treated as a placeholder. On every adoption or re-derive merge it was replaced while its tokens were added to the day and model rows again, so each bump multiplied them by the number of older cache files holding that day.

  • hasSliceData counts tokens as slice data.
  • subtractSlice drops a token-only remainder: it is drift between two scans of the same calls, not usage.
  • On load, day and model-row tokens are capped at the sum of the slices for days whose slices all carry token figures, so caches already inflated heal without a version bump.

A newer token-only slice now wins over an older one with calls, as the newer-wins rule intends, instead of the two being added.

No cache version bump, so this does not collide with #1786 or #1787.

Tests: two new cases in tests/daily-cache-carry-forward.test.ts; typecheck and the daily-cache suites pass.

A slice with tokens but no calls, cost or savings (a Hermes or Copilot
session total) read as a placeholder, so every adoption or re-derive merge
replaced it while adding its tokens to the day and model rows again. Each
version bump multiplied them by the number of older cache files holding
the day. Count tokens as slice data, and cap day and model-row tokens at
the slices' sum on load for days whose slices all carry token figures.
A newer token-only slice now wins over an older one with calls, as the
newer-wins rule intends, instead of the two being added.

This branch has not been deployed

No deployments
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