Files
HealthLog/prisma/migrations/0480_status_note_failure_streak/migration.sql
T
Marc-André Bombeck 17c1518b35 fix(insights): back a failing status note off, and let no path skip the wait
A status note whose generation stalled or failed opened a fixed five-minute
negative window, and only the read path honoured it. The ingest
invalidator counted only a stored note as fresh, so every data sync
re-enqueued each note whose last generation had just failed, and the
worker generated it again whatever the window said. With a model that
never answers, every sync bought another round of calls per note.

The window now grows with the generations in a row that ended without a
note (failure_streak, migration 0480): five minutes, doubling per failure,
up to two hours. A written or re-dated note resets it. A failure inside an
open window neither moves nor counts it.

runStatusCompletion waits the window out before any provider work,
whichever path selected the note again (a sync, a warm pass, a queued
job), and the ingest invalidator no longer enqueues a note inside its
window. A derived-score assessment that fails now opens the same window.
The person's own regenerate closes the record's windows first, and saving
the AI provider settings closes them and forgets the provider's health
rows, so a fixed setup does not sit out a pause the old one earned.

The window code moves to status-negative-window.ts; the status parity
golden records that the mood note screened earlier in the same minute is
no longer generated again inside its window.

Refs #1279
2026-10-24 21:08:45 +02:00

12 lines
642 B
SQL

-- Count the generations in a row that ended without a note, per status note.
--
-- A note whose generation failed opened a fixed five-minute negative window.
-- A model that never answers kept failing every five minutes per note, and a
-- note re-selected by the next data sync ignored the window altogether. The
-- streak sets the next window: five minutes, doubling per failure in a row,
-- up to two hours. A written or re-dated note resets it to zero.
--
-- Existing rows start at zero, which is the five-minute window they had.
ALTER TABLE "insight_status_caches"
ADD COLUMN IF NOT EXISTS "failure_streak" INTEGER NOT NULL DEFAULT 0;