Repository navigation
fix(server): count run results from the DB when stamping tracking_runs - #583
Merged
Merged
Conversation
The zero-result guard read the worker's own insertedCount, but in webhook mode scraper results are inserted by the /cloro/callback handler — the counter only sees the API-model phase. On scraper-only brands every successful run ended with insertedCount 0, so the guard deleted the just-finished run's ledger row and tracking_runs stayed empty: the insights 24h anchor never advanced past the backfill and the Daily Pulse/dashboard mismatch resurfaced. Stamp from a prompt_results count scoped to the run's started_at instead, keep the delete only for genuinely zero-result runs, leave the row uncompleted on a count error, and log the stamp so the next diagnosis takes one grep.
The daily pulse compared wall-clock [now-24h] windows, which double-counts whenever two runs land within 24h of each other — the morning after the cron moved from 06:00 to 02:00 UTC, the email summed both runs' mentions while the dashboard showed one run. Resolve the current/previous KPI windows from tracking_runs exactly like the Insights 24h view does, so the email and the dashboard read the same window by construction. Weekly pulses, the trend detectors and brands without a completed run keep the clock-based windows.
Contributor
Author
|
Added a second commit: the Daily Pulse's daily KPI windows now resolve from the tracking_runs ledger too — the same windows the Insights 24h view uses — so the email and the dashboard read identical ranges by construction. Wall-clock windows double-counted on the cron-time transition day (522 vs 278). Weekly pulses, detectors, and brands with no completed run keep clock-based windows. |
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
Urgent follow-up to #578. This morning's cron ran on the new code but
tracking_runsended the day empty, so the insights 24h anchor never advanced past the backfill (the dashboard kept showing yesterday's run) and the Daily Pulse email disagreed with the product again.Root cause: the zero-result guard read the worker's own
insertedCount— but in webhook mode the scraper results are inserted by the/cloro/callbackhandler, not by the worker. The counter only sees the API-model phase, so on scraper-only brands every successful run ended withinsertedCount === 0and the guard deleted the just-completed run's ledger row.Fix:
prompt_resultscount scoped to the run'sstarted_at(insert-path-agnostic) —result_countnow reflects the real run size.tracking run stampedinfo log so the next diagnosis is one grep away.Today's missing run rows were repaired directly in the ledger (synthetic completed rows for the 20 brands that ran), so dashboards are already showing today's data — this PR makes tomorrow's 05:00 TR run stamp itself correctly.
Related issue
Follow-up to #578 (no tracked issue).
Type of change
fix— Bug fixHow to test
tracking_runsgains a completed row whoseresult_countmatches the run'sprompt_resultsrows, and the server logstracking run stamped.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)