Skip to content

fix(daily-cache): stop a frozen under-read from outranking the sources on disk - #1304

Merged
iamtoruk merged 3 commits into
mainfrom
fix/daily-cache-underread-reconcile
Sep 12, 2026
Merged

iamtoruk merged 3 commits into
mainfrom
fix/daily-cache-underread-reconcile

Conversation

@iamtoruk

@iamtoruk iamtoruk commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Supersedes #1218. Same change by @therickfactr, rebased onto current main, plus two follow-ups. Fixes #1217.

The fix

A day is derived into the durable cache once and then frozen behind the watermark, while isPartialSurvival lets a fresh derivation shrink a day inside the settle window. One parse that missed sources became permanent, so the Overview headline read below the Daily Activity rows printed under it.

The read path already parses the dates it reports on, so it now reconciles the two derivations per (date, provider) and keeps whichever explains more calls, ties to the cache. Carry-forward is untouched: nothing live can outbid a day with no surviving source. The write path is unchanged.

Follow-ups on top of the original

Carried mark. The merge seeds each result day from the live parse, which has no provenance. The original passed markSecondaryCarried: true, which flagged every date the cache and the parse agree on (the common case) as preserved from expired logs. Passing false instead dropped the mark from every date both sides hold, including days only one of whose providers still has sources. Now the mark is re-asserted only where a cached slice brought calls the live parse could not produce. A day the sources fully explain drops it, a day with one expired provider keeps it. Regression test included.

Skip. Only dates where some provider's live slice has more calls than the cached one are handed to the merge. On a healthy cache that is none, so the lifetime period no longer clones every day it holds, and a date the cache already explains is served as written rather than rebuilt back to the same numbers.

Known caveat

The comparison is on calls, but the winning slice is adopted whole. If a live slice has more calls and less cost than the cached one, the day's cost follows the calls down. A richer parse normally costs more, so this needs a re-pricing (a price override, a flat-rate mark) landing at the same time as a parse that sees an extra call. On the real corpus below, zero days changed cost.

Verified against a real corpus

137 cached days, 258k calls, 15 providers, 95 of those days carried. Run on an isolated copy of the cache via CODEBURN_CACHE_DIR.

Unmodified cache, 7 day range ending yesterday. Headline and sum of the daily rows, on both builds:

main     3,192 calls   $663.55
branch   3,192 calls   $663.55

Then one provider slice on one day inside that range cut to a third (287 calls instead of 860), complete: true kept and the watermark left past it, which is #1217:

main     2,619 calls   $531.08    (and unchanged on every later run)
branch   3,192 calls   $663.55    matches the live parse

On the unmodified cache the two builds agree everywhere: lifetime totals identical, 0 of 137 days changed calls or cost, the carried footnote unchanged at $22,949.91, and the status --format menubar-json payload identical apart from live session state that drifts run to run. A healthy cache is left alone.

Cost: lifetime report is about 140ms slower on this corpus (2.65s to 2.79s), from the extra day aggregation of the live parse. week is within noise, 6ms.

npm test: 3,955 passed, 5 skipped, 0 failed. npx tsc --noEmit clean.

therickfactr and others added 3 commits September 12, 2026 04:41
…s on disk (#1217)

A day is derived into the durable cache once and then frozen behind the
watermark, while isPartialSurvival lets a fresh derivation SHRINK a day
inside the settle window. One parse that missed sources therefore became
permanent: the Overview headline sat 27% below the Daily Activity rows
printed underneath it, on days whose transcripts were intact the whole
time.

The read path already parses the dates it is reporting on, so let it
reconcile: per (date, provider) keep whichever derivation explains more
calls. A cached day whose transcripts have expired still wins, since
nothing live can outbid it, and an under-read cached row stops hiding
evidence that is sitting on disk. Ties go to the cache, so a re-pricing
still lands through the write path only.

The write path is untouched: what to freeze stays its decision, and a
still-settling day is still defined by its fresh parse.

Fixes #1217
The merge seeds each result day from `primary`, the live parse, which
carries no provenance. Marking every secondary day carried flagged every
date the cache and the parse agree on as preserved from expired logs;
not marking them at all silently dropped the mark from every date both
sides hold, including days only one of whose providers still has sources.

Re-assert it only where a secondary slice brought calls the primary could
not produce. An equal-call slice claims nothing, so a day the sources
fully explain drops the mark and a day with one expired provider keeps it.
Every historical day was cloned into the merge on every read, whether or
not anything needed healing. Pass only the dates where some provider's
live slice explains more calls than the cached one: on a healthy cache
that is none, and a date the cache already explains is served as it was
written rather than rebuilt from a live day back to the same numbers.
@iamtoruk
iamtoruk merged commit cfa0f9f into main Sep 12, 2026
20 checks passed
@iamtoruk
iamtoruk deleted the fix/daily-cache-underread-reconcile branch September 12, 2026 12:10
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.

bug: an under-read day inside the settle window is frozen forever — Overview headline stays below the sum of its own Daily Activity rows

2 participants