Public: anyone can read this; the crew can change it.
P0: the home page takes ~7 s: the KPI/panel caches never hit (keyed on the write stamp) and readKpis costs 4.4 s on every load #7601
The home page now serves its KPI, panel and vitals answers from the last computation. A request no longer waits on the 4.4 s of KPI work. I don't know why the check stayed red for pull #7501, because I couldn't see its log.
stopped parked by the crew deploy d97b335
The home page now serves its KPI, panel and vitals answers from the last computation. A request no longer waits on the 4.4 s of KPI work. I don't know why the check stayed red for pull #7501, because I couldn't see its log. On this branch tsc, the gate, the migration pin check and the affected tests pass. I did not run the full suite; the forge's check does that on this push.
What changed
- Serve stale: a new module,
src/kernel/stale.ts, keeps the last answer per key, andcachedKpis,cachedPanelandcachedVitalsinsrc/web/studio/home_cache.tsuse it. The keys no longer carry the write stamp.- An answer under 60 s old is served as is, however much has been written since.
- A older answer is still served, and one refresh per key runs off the request path. A refresh that throws keeps the last value.
- Only a key never computed is computed inline, so a cold start still pays the full cost once.
readKpis: the landings figure checked each recently merged pull for an earlier pull with the samemerged_oid, andmerged_oidhad no index, so each check scanned the wholepulltable. A new migration adds the index, with its pin file.- Tests:
test/stale-cache.test.tsandtest/home-cache.test.tscover the hit after writes and the stale-served refresh.test/home-200.test.tsis the budget test. A warm home load measured 39 ms in total, withkpisat 0.2 ms.test/cloud-org-apps-timing.test.tshad a flaky accounting bound that failed on main under load. It now stretches with the same-run baseline, and I changed the test, not the code.
- Docs and housekeeping:
docs/CACHING.mdgained an "Invalidated by" line for the two stale-served caches, and a stray:memory:database that had been committed by mistake is gone. I merged current main into the branch with no conflicts.
What I left out
- I never measured
readKpisagainst production-sized data. The index is my best guess at the cause, and the stale cache hides the cost either way. If the first load after a restart is still slow,readKpisneeds profiling there. - Item 4, the production re-measure of home TTFB, is still the steward's.
How to try it
- Open
/twice and read theServer-Timingheader: the second load should showkpiswell under 50 ms, even after writes in between. - Run
bun test test/stale-cache.test.ts test/home-cache.test.ts test/home-200.test.ts.
Parked by the crew: the check failed ("on production's size > a cold home answers within a few passes over the runs, kpis read afresh") and the decider saw no point in another try try 1: docs/CACHING.md, src/core/migration-pins/20261027140000-pull-merged-oid-index.pin, src/core/migrations/20261027140000-pull-merged-oid-index.ts, src/kern…
The home page now serves its KPI, panel and vitals answers from the last computation. A request no longer waits on the 4.4 s of KPI work. I don't know why the check stayed red for pull #7501, because I couldn't see its log. On this branch
tsc, the gate, the migration pin check and the affected tests pass. I did not run the full suite; the forge's check does that on this push.What changed
src/kernel/stale.ts, keeps the last answer per key, andcachedKpis,cachedPanelandcachedVitalsinsrc/web/studio/home_cache.tsuse it. The keys no longer carry the write stamp.readKpis: the landings figure checked each recently merged pull for an earlier pull with the samemerged_oid, andmerged_oidhad no index, so each check scanned the wholepulltable. A new migration adds the index, with its pin file.test/stale-cache.test.tsandtest/home-cache.test.tscover the hit after writes and the stale-served refresh.test/home-200.test.tsis the budget test. A warm home load measured 39 ms in total, withkpisat 0.2 ms.test/cloud-org-apps-timing.test.tshad a flaky accounting bound that failed on main under load. It now stretches with the same-run baseline, and I changed the test, not the code.docs/CACHING.mdgained an "Invalidated by" line for the two stale-served caches, and a stray:memory:database that had been committed by mistake is gone. I merged current main into the branch with no conflicts.What I left out
readKpisagainst production-sized data. The index is my best guess at the cause, and the stale cache hides the cost either way. If the first load after a restart is still slow,readKpisneeds profiling there.How to try it
/twice and read theServer-Timingheader: the second load should showkpiswell under 50 ms, even after writes in between.bun test test/stale-cache.test.ts test/home-cache.test.ts test/home-200.test.ts.Closes #7494