Repository navigation
fix(tracking): stop waiting on ghost Cloro tasks and de-synchronise pulses - #690
Merged
Merged
Conversation
…ulses Cloro accepts tasks it never calls back on — routine for google-aio, which has nothing to return when a query has no AI Overview. Both the worker's drain loop and the pulse's drain wait counted those forever-pending rows, so every run burned its full stall window and every brand parked for the full 90-minute pulse cap. That cost more than time. Because the wait was a fixed duration, brands whose runs finished minutes apart woke in the same second and each fired a dozen aggregate queries in parallel; the largest brand's statements crossed PostgREST's 8s statement_timeout and its digest was discarded entirely. - worker: exit the drain when delivery has gone quiet AND every remaining task is older than 30 minutes. Both conditions are required — a quiet gap alone is normal mid-burst, and old tasks alone are fine while results are still landing. The partial-run stamp guard is untouched. - pulse: ignore pending tasks older than 45 minutes when waiting for the queue to drain, and don't read a failed poll as an empty queue. - pulse: run the metric queries sequentially. Nothing waits on this job interactively, so concurrency only multiplied peak database load. - pulse: retry a statement timeout twice before giving up, instead of throwing the whole digest away. - concurrency is now configurable via TRACKING_CONCURRENCY (default 2). Closes #687
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cloro accepts tasks it never calls back on — routine for
google-aio, which has nothing to return when a query has no AI Overview. Both drain loops counted those forever-pending rows, so every run burned its full stall window and every brand parked for the full 90-minute pulse cap.That cost more than time. Because the wait was a fixed duration, brands whose runs finished minutes apart woke in the same second, each firing a dozen aggregate queries in parallel. On 2026-08-10 the largest brand's statements crossed PostgREST's 8s
statement_timeoutand its digest was discarded entirely:Measured with the database otherwise idle, that same RPC takes 526 ms — it is not slow on its own, it becomes slow under the concurrency the wait manufactures. (
Buffers: shared hit=126238, spilling to disk atwork_mem=3500kB; that brand holds 41k of the table's 132k rows.)Observed wake-up waves:
What changed
MIN_STAMP_RATIOpartial-run guard is untouched, so a genuinely half-delivered run still refuses to stamp.TRACKING_CONCURRENCYenv (default 2) replaces the hardcoded ceiling inherited from the old Bull setup.Expected effect: per-brand wait drops from ~60 min to ~15 min, the nightly cycle shortens accordingly, and pulses land minutes after each run's stamp instead of on a synchronised 90-minute delay.
Related issue
Closes #687
Type of change
fix— Bug fixHow to test
12 new tests cover the parts worth pinning:
allTasksAreStale— true only when every pending task is past the cutoff; false for a mixed batch (the dangerous case: exiting there would abandon a task that is merely mid-burst), false for an empty list, false at the exact cutoff, and false when a row has nosubmitted_at(unknown age must not be guessed as old).series— never overlaps (asserted via a concurrency counter), preserves input order likePromise.all, and propagates failures without starting the remaining work.isTransientDbError— matches the production timeout string and deadlocks, and does not retry genuine errors like a missing column or a permission failure.In production, after deploy the log line to watch is
cloro tasks are ghosts — delivery quiet and every remaining task is stale; continuing, and pulsecreated_atvalues should sit minutes after each run'scompleted_atrather than clustering.Checklist
feature/,fix/,chore/,docs/)yarn lintpasses — server ESLint clean with--max-warnings=0yarn typecheckpasses — no web sources touchedyarn format:checkpassesDeployment note
No env changes are required; the defaults reproduce today's behaviour minus the ghost waits.
CLORO_GHOST_STALL_POLLS(default 60 ≈ 15 min) andTRACKING_CONCURRENCY(default 2) are documented inserver/.env.exampleif you want to tune the cycle further after watching one night.