fix(rollups): register read-path warm-ups with the background registry

The mood rollup warm-up on the dashboard summary was started with a bare
`void`, so `settleBackgroundTasks()` never saw it. On a stale account the
warm-up started a full recompute that could still be writing when the
statement counter closed its window, and the hot-route budget read 30
against 28 depending on where it landed.

Every read-path start of that shape now goes through
`trackBackgroundTask(runDetached(...))`: the measurement and mood rollup
warm-ups (seven call sites), the dashboard's today-briefing warm, and the
two delegated-access bookkeeping writes in the record guard. A guard
refuses a bare `void` on any of them.

`trackBackgroundTask` now wraps its handle in `Promise.resolve`: a test
double that returns nothing used to leave `undefined` in the set, and
settle spun on it at full CPU.

The budget fixture mints the mood rollups in its seed, as it already did
for the measurement rollups. Eight serial runs of
query-budget-hot-routes read the same counts every time (dashboard
summary 28, snapshot 99, day 47, health-status 59, correlations 43).
This commit is contained in:
Marc-André Bombeck committed 2026-10-25 00:33:55 +02:00
1 parent 3984ceb01c
commit da2cd62876
14 files changed
+148 -21

No files matched your search

@@ -281,9 +281,15 @@ async function seed(): Promise<void> {
}),
});
// Both rollup tiers are minted here, the way a running account has them.
// Seeded rows without their rollups make the first read start a full
// recompute in the background, and that is a warm-up cost, not the read's.
const { recomputeUserRollups } =
await import("@/lib/rollups/measurement-rollups");
await recomputeUserRollups(USER_ID);
const { recomputeUserMoodRollups } =
await import("@/lib/rollups/mood-rollups");
await recomputeUserMoodRollups(USER_ID);
const session = await db.session.create({
data: { userId: USER_ID, expiresAt: new Date(Date.now() + 3_600_000) },