fix(regional-briefs): bypass weekly cooldown when last run failed coverage#4164
Conversation
…erage seed-bundle-regional gates the weekly brief sub-run behind a 6.5-day cooldown read from seed-meta:intelligence:regional-briefs. When a briefs run fails coverage (e.g. a transient OpenRouter-credits outage makes every region return an empty brief → skipped, failed===0), seed-regional-briefs deliberately writes recordCount=0 (+ coverageOk:false) so /api/health flips to EMPTY_DATA instead of hiding partial failure (PR #2989). The trap: that EMPTY_DATA crit then persists for the remainder of the ~6.5-day cooldown with no retry — even though re-running once credits are restored would clear it on the next 6h tick. Live incident 2026-06-06: "[bundle] briefs: last run 1.6 days ago, skipping (cooldown 6.5d)". Fix: in shouldRunBriefs, bypass the cooldown when the last run's recordCount===0. recordCount lives in the bare-shape seed-meta and is exactly the field that drives /api/health's EMPTY_DATA verdict, so it is the authoritative "last run failed coverage" signal — a successful run writes a positive count and keeps the normal weekly cooldown. This turns a transient failure into a self-healing retry-next-tick instead of a multi-day stuck crit. Coverage logic in seed-regional-briefs is unchanged. Adds an isMain guard + exports shouldRunBriefs so the bypass can be behaviorally tested without executing the bundle on import.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Greptile SummaryThis PR adds a cooldown bypass to
Confidence Score: 4/5Safe to merge; the bypass logic is narrowly scoped to the recordCount=0 path already written by the briefs seeder on coverage failure, and the isMain guard matches the established pattern. The change is small and matches both the bare-shape format that writeSeedMeta writes and the existing unwrapEnvelope read pattern. One source-text regex assertion in the test is coupled to the implementation's exact expression, which would break on valid refactors without a behavioral regression. No files require special attention — both changed files are internally consistent and align with existing codebase patterns. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A([6h Railway cron tick]) --> B[runSnapshots]
B -- success --> C{shouldRunBriefs?}
B -- throws --> X[log error\nskip briefs\nexit 1]
C --> D[GET seed-meta:intelligence:regional-briefs from Redis]
D -- Redis non-ok / throws --> E[return true\ndefensive run]
D -- key missing --> F[return true\nfirst run]
D -- key exists --> G{age >= 6.5d?}
G -- yes --> H[return true\nnormal cadence]
G -- no --> I{recordCount === 0?}
I -- yes --> J[return true\nBYPASS: coverage failed\nself-heal on next tick]
I -- no --> K[return false\nskip within cooldown]
E & F & H & J --> L[runBriefs]
K --> M([Done])
L -- success, coverageOk --> N[writeSeedMeta recordCount=generated > 0\nnormal cooldown resumes]
L -- success, coverageOk=false --> O[writeSeedMeta recordCount=0\nhealth: EMPTY_DATA\nbypass fires next tick]
L -- throws / failed>0 --> P[meta NOT updated\ncooldown expires naturally]
N & O & P --> M
Reviews (1): Last reviewed commit: "fix(regional-briefs): bypass weekly cool..." | Re-trigger Greptile |
Summary
/api/healthshowedregionalBriefs= EMPTY_DATA (crit), recordCount=0, and it would have stayed that way for ~5 days.This is the interaction of two intentional behaviors:
seed-regional-briefs.mjsdeliberately writesrecordCount=0(+ payloadcoverageOk:false) when fewer thanexpectedRegions-1briefs generate — so partial failure surfaces as EMPTY_DATA instead of being hidden (PR Phase 3 PR2: Weekly regional briefs (LLM seeder + RPC) #2989). A transient OpenRouter-credits outage makes every region return an empty brief →skipped,failed===0,recordCount=0.seed-bundle-regional.mjsgates the weekly briefs sub-run behind a 6.5-day cooldown read fromseed-meta:intelligence:regional-briefs. Live bundle log:[bundle] briefs: last run 1.6 days ago, skipping (cooldown 6.5d).The trap: once a briefs run fails coverage, the EMPTY_DATA crit is pinned for the remainder of the cooldown with no retry — even though re-running once credits are restored would clear it on the very next 6h tick.
Fix
In
shouldRunBriefs, bypass the cooldown when the last run failed coverage (recordCount === 0). A successful run writes a positive count and keeps the normal weekly cadence. This turns a transient failure into a self-healing retry-next-tick instead of a multi-day stuck crit.recordCountis read from the bare-shape seed-meta (seed-meta:intelligence:regional-briefs) — the exact field that drives/api/health's EMPTY_DATA verdict, so it is the authoritative "last run failed coverage" signal. (Note: when a briefs run throws, seed-metafetchedAtisn't updated, so the cooldown naturally expires already — this fix covers thefailed===0+coverageOk:falsecase, which is precisely the persistent-crit scenario.)seed-regional-briefs.mjsis unchanged.isMainguard + exportedshouldRunBriefsso the bypass can be tested without executing the bundle on import (matches the existingseed-regional-briefs.mjspattern).Test plan
node --check scripts/seed-bundle-regional.mjs scripts/seed-regional-briefs.mjs— cleannpm run typecheck— cleantests/seed-bundle-regional-briefs-cooldown.test.mjs(source-assertion + behavioral, 9 cases): missing key → run; cooldown expired → run; fresh + recordCount>0 → skip; fresh + recordCount=0 → bypass/retry; missing recordCount within cooldown → retry; Redis non-ok → run defensively. All pass viatsx --test(the repo's runner).