Skip to content

fix(pulse): wait for the brand's Cloro queue to drain before computing - #570

Merged
gkhngyk merged 1 commit into
mainfrom
fix/pulse-wait-for-cloro-drain
Jul 31, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/pulse-wait-for-cloro-drain

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Daily Pulse emails could carry partial-window numbers that contradicted the dashboard. In webhook mode a tracking job can "complete" while Cloro is still delivering results: the worker's drain loop gives up after 10 minutes without progress (40 polls × 15s), but Cloro's real delivery latency is 30–80 minutes. The pulse trigger fires on job completion, so on days when the stall-abort hit, the digest was computed from whatever had landed by then — in one observed run, 859 of the day's results arrived after the pulse went out, and the emailed visibility rate differed from the dashboard by 5 points.

Fix: generatePulseForBrand now waits for the brand's cloro_pending_tasks queue to drain before computing (60s poll, 90-minute cap so an orphaned task row can't block the pulse forever — cleanupStalePendingTasks sweeps those after 2h). The metrics window anchors to the actual compute time after the wait. The engine already runs fire-and-forget off the job runner, so waiting holds no tracking concurrency slot.

Verified on the test brand: after the fix, the regenerated pulse matches the dashboard exactly for the same window.

Related issue

—

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. With cloro_pending_tasks rows present for a brand, trigger node src/scripts/test-pulse.js <brandId> — the engine polls until the queue drains, then computes.
  2. With an empty queue, the pulse generates immediately (no added latency).
  3. KPI numbers in the generated payload match the dashboard for the same window.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • 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 1c7a571 into main Jul 31, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the fix/pulse-wait-for-cloro-drain branch July 31, 2026 16:23
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