Skip to content

fix: recover pulses lost to process death with a daily catch-up sweep - #654

Merged
gkhngyk merged 1 commit into
mainfrom
fix/pulse-catchup
Aug 7, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/pulse-catchup

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

A production brand's Daily Pulse silently disappeared for a day: its tracking run completed and stamped, but the per-brand pulse trigger — fire-and-forget at the end of the tracking job — died with the process (memory pressure on a 1 GB host). The stamp survives in the DB; the in-memory trigger doesn't. No error, no mail, nothing to retry.

Fix: a catch-up sweep at the start of every daily cycle.

  • runPulseCatchUp() scans the last 36h of completed tracking_runs; any brand whose latest completed run has no sent_pulses row created after it gets a recovery pulse.
  • The recovered pulse is dated to the missed run's completion day (generatePulseForBrand gains an optional pulseDate override), so it claims that day's dedupe slot — today's real pulse, fired when today's run completes, keeps its own date and is never suppressed.
  • Double-sends are impossible: the existing sent_pulses (brand_id, pulse_date) unique constraint remains the race-safe claim.
  • Non-blocking (fire-and-forget with logging), mirroring the GSC sync step: the sweep can never delay or fail the tracking cycle. All existing eligibility skips (inactive brand/subscription, frequency off/weekly-day, no fresh results) apply unchanged.

Related issue

None — production incident fix (missed pulse after an OOM-killed trigger).

Type of change

  • fix — Bug fix

How to test

  1. Simulate a missed pulse: complete a run for a brand, delete its sent_pulses row for that date, then invoke runPulseCatchUp() — a recovery pulse is generated dated to the run's completion day ([pulse] catch-up pulse sent log).
  2. Run the sweep again — the brand is skipped (already_sent via the unique key).
  3. Brands whose latest run was already pulsed are untouched; the daily cycle timing is unaffected (sweep is fire-and-forget).

Checklist

  • Branch follows the naming convention (fix/)
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

@gkhngyk
gkhngyk merged commit e1515ad into main Aug 7, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the fix/pulse-catchup branch August 7, 2026 09:57
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