codeburn/scripts
iamtoruk 12c8cb7790 fix(copilot): re-derive migrated copilot day slices, count the compaction row's output
Two defects from @kelchm's two-machine validation of #946.

1. The daily-cache migration carried the copilot slice of every existing day
   entry verbatim instead of re-deriving it, so `overview` on a migrated cache
   kept serving pre-store numbers (2,980,804 tokens for a day whose fresh
   derivation is 74,811,412; 21,608 calls vs 16,326) while export/models/audit
   served the corrected ones off the same cache.

   Root cause is the partial-survival guard (e9d922ca), not the migration: it
   keeps a settled baseline slice whenever the fresh derivation reports FEWER
   calls, reading that as aged-out sources. This change's whole point is that
   copilot's supplementary accounting calls stop counting as api calls, so
   every store-era day shrinks in calls and got pinned to its pre-store value.
   The guard's own TRADE-OFF note predicted exactly this case.

   A migration from an older cache version now grants copilot ONE
   guarded-shrink-exempt re-derivation (`pendingRederive`), spent by the first
   COMPLETE parse. It fires only where that parse actually produced a slice for
   the (day, provider), so a day whose sources are gone still carries forward
   whole - never-lose is unchanged in both directions - and no other provider
   is exempt.

   The daily cache moves 21 -> 25: 21-24 landed on main during validation, and
   only a number the validators' own daily-cache.v21.json cannot claim gets
   their stale carried slices re-derived.

2. The `initiator='compaction'` store row was ingested with outputTokens 0. Its
   output has no assistant.message anywhere in events.jsonl, so that row is the
   only place those tokens exist - dropping them was the sole token discrepancy
   (-3,085) across a 30-session store-matched comparison. It is now read (on the
   same optional-select rung as `initiator`, which is what identifies the row),
   counted and priced; every other row keeps output 0 because a per-turn call
   owns it. The copilot parse version moves to session-store-v3 so cached v2
   rows re-parse; the dedup key is deliberately unchanged.

Settle window stays at 24 h - the three-machine evidence for tightening it is
recorded next to the constant, but shortening it is a product call.
2026-08-22 02:26:35 -07:00
..
upgrade-path fix(copilot): re-derive migrated copilot day slices, count the compaction row's output 2026-08-22 02:26:35 -07:00
bundle-litellm.mjs fix(pricing): restore Mythos 5 pricing dropped by gap-fill cleanup 2026-06-10 00:09:31 +02:00