A Claude account's model list fetches models.dev again every 45
minutes (catalog.Asked), most often to the same bytes. Each fetch
rewrote models.json, so its mtime changed, and usage keyed its request
index, the index's file on disk (requests-v1.bin, heat, page, effort)
and its priced summaries on that mtime: the next usage query dropped
every chunk and read every session file again. On the acctp history
(15.7k session files) a start that rebuilds takes ~15 s of CPU in its
first 30 s, against ~2 s for one that keeps the index. Each fetch also
forgot the parsed catalog and told every agent to rewrite its list
(catalog.Changed), for nothing changed.
- catalog.CacheKey names models.json and labs.json by a hash of their
bytes, kept by their stat so a key costs a stat until a file changes.
Usage's request meta and price key use it in place of the mtime, as
liveListKey already did for the providers' lists.
- Sync writes models.json and labs.json only when their bytes changed;
the same bytes are dated now (Stale, Missing and Asked read the time),
and Reset and Touched run only when either file changed.
Tests: TestSameCatalogFetchedAgainChangesNothing (catalog) and
TestRequestStateKeptAcrossACatalogFetchedAgain (usage). Broken by hand:
with keepFetched always writing, the catalog test is red (told the
agents on the same bytes); with usage keyed on statKey again, the usage
test is red (meta and price key changed).