Skip to content

fix(regional-briefs): bypass weekly cooldown when last run failed coverage#4164

Merged
koala73 merged 2 commits into
mainfrom
fix/regional-briefs-retry-on-coverage-fail
Jun 6, 2026
Merged

fix(regional-briefs): bypass weekly cooldown when last run failed coverage#4164
koala73 merged 2 commits into
mainfrom
fix/regional-briefs-retry-on-coverage-fail

Conversation

@koala73

@koala73 koala73 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

/api/health showed regionalBriefs = EMPTY_DATA (crit), recordCount=0, and it would have stayed that way for ~5 days.

This is the interaction of two intentional behaviors:

  1. seed-regional-briefs.mjs deliberately writes recordCount=0 (+ payload coverageOk:false) when fewer than expectedRegions-1 briefs 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.
  2. seed-bundle-regional.mjs gates the weekly briefs sub-run behind a 6.5-day cooldown read from seed-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.

  • recordCount is 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-meta fetchedAt isn't updated, so the cooldown naturally expires already — this fix covers the failed===0 + coverageOk:false case, which is precisely the persistent-crit scenario.)
  • Coverage logic in seed-regional-briefs.mjs is unchanged.
  • Added an isMain guard + exported shouldRunBriefs so the bypass can be tested without executing the bundle on import (matches the existing seed-regional-briefs.mjs pattern).

Test plan

  • node --check scripts/seed-bundle-regional.mjs scripts/seed-regional-briefs.mjs — clean
  • npm run typecheck — clean
  • New test tests/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 via tsx --test (the repo's runner).

…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.
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
worldmonitor Ignored Ignored Preview Jun 6, 2026 4:14pm

Request Review

@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a cooldown bypass to shouldRunBriefs in seed-bundle-regional.mjs so that a transient coverage failure (where seed-regional-briefs.mjs deliberately writes recordCount=0) self-heals on the next 6-hour tick rather than pinning an EMPTY_DATA health crit for the remainder of the 6.5-day cooldown window. It also adds an isMain guard and exports shouldRunBriefs, BRIEF_COOLDOWN_MS, and BRIEF_META_KEY so they can be tested without executing the bundle on import.

  • scripts/seed-bundle-regional.mjs: adds Number(meta?.recordCount ?? 0) === 0 bypass inside shouldRunBriefs, wraps the main() call in an isMain guard (matching the existing seed-regional-briefs.mjs pattern), and exports the three symbols.
  • tests/seed-bundle-regional-briefs-cooldown.test.mjs: adds 9 test cases — three source-text assertions that guard the bypass wiring, and six behavioral assertions that exercise shouldRunBriefs against a stubbed Redis fetch covering first-run, expired cooldown, fresh-success (skip), fresh-failure (bypass), missing recordCount (bypass), and non-ok Redis response (defensive run).

Confidence Score: 4/5

Safe 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

Filename Overview
scripts/seed-bundle-regional.mjs Adds recordCount===0 bypass to shouldRunBriefs, isMain guard, and exports; logic is correct, consistent with how writeSeedMeta writes the bare-shape key, and well-documented.
tests/seed-bundle-regional-briefs-cooldown.test.mjs 9 new test cases with correct Redis stub and env-var lifecycle management; three source-text regex assertions are intentionally fragile regression guards but add no behavioral coverage beyond the existing behavioral tests.

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
Loading

Reviews (1): Last reviewed commit: "fix(regional-briefs): bypass weekly cool..." | Re-trigger Greptile

Comment thread tests/seed-bundle-regional-briefs-cooldown.test.mjs
@koala73
koala73 merged commit c0a9454 into main Jun 6, 2026
17 checks passed
@koala73
koala73 deleted the fix/regional-briefs-retry-on-coverage-fail branch June 6, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant