From d6692e3a4b7efa351c2ed7c96a93e690d0db3e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 18 Jul 2026 23:46:34 +0200 Subject: [PATCH] fix(coach): compose deterministic memory facts in English by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deterministic fact-pattern pass fell back to German when no locale was passed, the same de-default polarity the narrative surface just lost. Fact text is model-facing memory, so English is the fallback for every locale without a reviewed body; German stays for German readers. Also correct the InsightNarrative.locale doc comment — the column holds any shipped UI locale, not just de/en. Comment only, no SQL change. --- prisma/schema.prisma | 3 ++- src/lib/ai/coach/facts.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ca42d421f..f62e1a639 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -5226,7 +5226,8 @@ model InsightNarrative { userId String @map("user_id") /// "week" | "month". period String - /// Resolved UI locale of the prose ("de" | "en"). + /// Resolved UI locale of the prose — any shipped UI locale, not just de/en: + /// the prose is generated per locale, so the row is keyed by it. locale String /// UTC YYYY-MM-DD boundary the narrative was generated for. dateKey String @map("date_key") diff --git a/src/lib/ai/coach/facts.ts b/src/lib/ai/coach/facts.ts index c210823f1..265598d64 100644 --- a/src/lib/ai/coach/facts.ts +++ b/src/lib/ai/coach/facts.ts @@ -558,7 +558,10 @@ function deterministicFactText( subject: string, locale: string | undefined, ): string { - const de = locale?.toLowerCase().startsWith("de") ?? true; + // German only for a German reader; every other locale — and an absent one — + // composes ENGLISH. The fact text is model-facing memory, so English is the + // fallback body; the previous `?? true` made an unknown locale German. + const de = locale?.toLowerCase().startsWith("de") ?? false; switch (kind) { case "allergy": return de