Repository navigation
fix(insights): anchor the 24h view to the last completed tracking run - #578
Merged
Merged
Conversation
Every morning the rolling [now-24h, now] window emptied and refilled while the daily run streamed in: users saw a 'no results for the last 24 hrs' flash, then the tracked-prompt count shrinking as yesterday's results aged out one by one. - 00044 migration: tracking_runs ledger (brand_id, source, started_at, completed_at, result_count) + RLS member select + a synthetic backfilled run per brand so the fix applies immediately - worker: FULL runs (cron or manual Run All) insert a ledger row up front and stamp completed_at after the drain loop finishes — by then this run's results are all inserted, so no webhook-side bookkeeping. Zero-result runs delete their row instead of moving the anchor onto an empty window; single/subset-prompt runs never stamp - insights 24h preset resolves its window from the ledger: (previous completed run, latest completed run] — always full, frozen between runs, swapped atomically when the next run completes. Brands with no completed run yet (fresh onboarding) keep the live rolling window, where regression is impossible - new ServerRunBanner: cron/teammate-started runs now show an in-progress banner (the old one only knew jobs this browser started via localStorage); a 60s ledger poll also reloads the page silently the moment the active run completes
…oard shows The chart capped competitors by period-average of the daily points while the leaderboard sorts by the window score, so on short ranges (24h) a competitor could rank 2nd on the leaderboard yet be missing from the chart. Rank by the last point's value instead — the rolling window makes that equal the leaderboard's window score, so both surfaces always show the same brands (average kept only as tie-break).
7 tasks done
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
Every morning while the daily run streamed in, the Insights 24h view briefly showed "no results for the last 24 hrs" and then a shrinking tracked-prompt count: the rolling
[now − 24h, now]window was dropping yesterday's results second by second while today's arrived over ~an hour.This PR anchors the 24h view to the last completed tracking run:
00044migration —tracking_runsledger (brand_id,source,started_at,completed_at,result_count) with member-select RLS, plus a synthetic backfilled run per brand so the fix applies immediately. Already applied to the hosted DB. Readsprompt_resultsonly — no existing data is modified and nothing is re-scraped.completed_atafter the drain loop finishes; by then the run's results are all inserted, so no webhook-side bookkeeping is needed. Zero-result runs delete their row (the anchor never moves onto an empty window); single/subset-prompt runs never stamp.(previous completed run, latest completed run]: always full, frozen between runs, and swapped atomically when the next run completes. Brands with no completed run yet (fresh onboarding) keep the live rolling window, where regression is impossible because nothing is older than 24h. Other presets are untouched.ServerRunBanner— cron/teammate-started runs now show an in-progress banner (the old banner only knew about jobs started from that browser via localStorage, which is why users saw nothing during the morning run). A 60s ledger poll reloads the page silently the moment the active run completes.Related issue
Fixes the customer-reported morning flash/regression on the Insights 24h view (no tracked issue).
Type of change
fix— Bug fixHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)