Repository navigation
fix(daily-cache): stop a frozen under-read from outranking the sources on disk - #1304
Merged
Merged
Conversation
…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.
3 tasks done
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
isPartialSurvivallets 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. Passingfalseinstead 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:
Then one provider slice on one day inside that range cut to a third (287 calls instead of 860),
complete: truekept and the watermark left past it, which is #1217: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-jsonpayload identical apart from live session state that drifts run to run. A healthy cache is left alone.Cost: lifetime
reportis about 140ms slower on this corpus (2.65s to 2.79s), from the extra day aggregation of the live parse.weekis within noise, 6ms.npm test: 3,955 passed, 5 skipped, 0 failed.npx tsc --noEmitclean.