From 7923d75afe0256b1dadd8da5b2a9616bcc0f6241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 4 Jun 2026 12:59:38 +0200 Subject: [PATCH] chore: clear v1.11.2 QA-low cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop the unused `now` field from the coach `ExtractOpts` type; fact extraction never read it (conversation-summary keeps its own `now`). - Correct the no-ladder tiebreak docstring in measurement-read: the collapse picks the alphabetically smallest source name, matching the live-SQL `ORDER BY … source` tiebreak, not max count. - Replace the hand-inlined canonical-source subquery in the summaries rollup-path narrows query with `canonicalMeasurementsFrom(rank, "90 days")` for live/rollup parity with its siblings. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/lib/ai/coach/facts.ts | 1 - src/lib/analytics/summaries-slice.ts | 22 +--------------------- src/lib/rollups/measurement-read.ts | 5 +++-- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/lib/ai/coach/facts.ts b/src/lib/ai/coach/facts.ts index 52c1d0b4e..a1045d112 100644 --- a/src/lib/ai/coach/facts.ts +++ b/src/lib/ai/coach/facts.ts @@ -58,7 +58,6 @@ type RunCompletionFn = typeof runStatusCompletion; type PrismaLike = Pick; interface ExtractOpts { - now?: Date; runCompletion?: RunCompletionFn; prisma?: PrismaLike; locale?: string; diff --git a/src/lib/analytics/summaries-slice.ts b/src/lib/analytics/summaries-slice.ts index 1c5f16dc6..08ce29746 100644 --- a/src/lib/analytics/summaries-slice.ts +++ b/src/lib/analytics/summaries-slice.ts @@ -348,27 +348,7 @@ async function computeFromRollups(userId: string): Promise { ) FILTER ( WHERE m."measured_at" >= NOW() - INTERVAL '90 days' )::double precision AS r2_90 - FROM ( - SELECT mm.* - FROM measurements mm - JOIN ( - SELECT DISTINCT ON ("type", date_trunc('day', "measured_at")) - "type" AS t, - date_trunc('day', "measured_at") AS d, - "source" AS canon - FROM measurements - WHERE "user_id" = $1 - AND "deleted_at" IS NULL - AND "measured_at" >= NOW() - INTERVAL '90 days' - ORDER BY "type", date_trunc('day', "measured_at"), (${rankUnqualified}), "source" - ) c - ON c.t = mm."type" - AND c.d = date_trunc('day', mm."measured_at") - AND c.canon = mm."source" - WHERE mm."user_id" = $1 - AND mm."deleted_at" IS NULL - AND mm."measured_at" >= NOW() - INTERVAL '90 days' - ) m + FROM ${canonicalMeasurementsFrom(rankUnqualified, "90 days")} GROUP BY m."type" `, userId, diff --git a/src/lib/rollups/measurement-read.ts b/src/lib/rollups/measurement-read.ts index 67d657470..c43bd7386 100644 --- a/src/lib/rollups/measurement-read.ts +++ b/src/lib/rollups/measurement-read.ts @@ -73,8 +73,9 @@ export interface SourcedBucketRow { * Resolution per bucket: * 1. the first source in the metric's ladder that is present → canonical; * 2. no ladder match (an unlisted source, or a type with no ladder) → the - * row with the most readings (max `count`), tie-broken by source name, - * so the bucket neither doubles nor goes dark. + * row with the alphabetically smallest source name, so the bucket + * neither doubles nor goes dark AND the pick matches the live-SQL + * paths' `ORDER BY … source` tiebreak. * * Input order is preserved (buckets emit in first-seen order). A single-source * day (the common case) short-circuits to the row unchanged.