Repository navigation
fix(tracking): stop discarding runs whose first result lands late - #710
Merged
Merged
Conversation
The drain loop had one 60-minute budget measured from submission. On the largest brand Cloro's first callback landed 62-65 minutes after submission three nights running, so the worker gave up two to five minutes before the delivery it was waiting for. With zero results at stamp time the ledger row was deleted, and because the 24h anchor never moved, the dashboard and the pulse mail both stayed frozen on the previous day while ~1800 results landed minutes later. The same figures went out by email three times. Split the budget in two. Waiting for the first result and waiting out the tail are different situations, and only the second has anything to measure: the stall and ghost exits both compare successive pending counts, so they are meaningless before anything has come back. That phase now has its own allowance (CLORO_FIRST_RESULT_WAIT_MIN, default 90), and the tail is measured from the first result rather than from submission (CLORO_DRAIN_TAIL_MIN, default 60), so a slow queue start no longer eats the time the rest of the delivery needs. Stall and ghost detection only run once delivery has started. The drain now always logs how it ended — reason, elapsed time, and how long the first result took. The timed-out path used to fall out of the loop silently, which is why this took three mornings of database forensics to pin down. Also skip the Daily Pulse when a run wasn't stamped: such a run left the anchor on the previous run, so its pulse recomputes that window and mails figures the recipient already has. The catch-up sweep picks the day back up once a run does stamp. Closes #702
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
The drain loop had a single 60-minute budget measured from submission. On the largest brand, Cloro's first callback landed 62–65 minutes after submission three nights running, so the worker gave up two to five minutes before the delivery it was waiting for.
The consequences compounded: with zero results at stamp time the ledger row was deleted, the 24h anchor never moved, and both the dashboard and the pulse mail stayed frozen on the previous day while ~1800 results landed minutes later. The same figures went out by email three times.
Job durations confirm the cap was what fired, not the stall exit: 60.5 and 61.3 minutes on the two failing nights, with the first result arriving at 62 and 65 minutes. The brand tracks only scraper platforms, so there is no API-model phase to account for the time.
The fix splits the budget in two. Waiting for the first result and waiting out the tail are different situations, and only the second has anything to measure — the stall and ghost exits both compare successive pending counts, so they are meaningless before anything has come back. That phase gets its own allowance (
CLORO_FIRST_RESULT_WAIT_MIN, default 90), and the tail is measured from the first result rather than from submission (CLORO_DRAIN_TAIL_MIN, default 60), so a slow queue start no longer eats the time the rest of the delivery needs. Stall and ghost detection now only run once delivery has started.Two things came with it:
The time budget decision is extracted as a pure function so it is testable without a live drain.
Related issue
Closes #702
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Behaviour is timing-dependent, so the budget logic is covered by unit tests (
yarn testfromserver/, 179 passing, 5 new). What to check in production after the next nightly cycle:tracking_runsrow again, withresult_countmatching the day's results.cloro delivery startedappears in the logs withwaitedMs— that number is the thing this PR is about.cloro drain finished (drained)rather than(no_first_result).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)