Skip to content

fix(competitors): serve the comparison from the daily rollups - #824

Merged
gkhngyk merged 1 commit into
mainfrom
fix/competitors-comparison-timeout
Sep 17, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/competitors-comparison-timeout

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The /dashboard/competitors page failed to load for brands with a large result history. It called getCompetitorComparison(brand.id) with no options, which routes to the raw all-time competitor_aggregates RPC — the exact scan the daily rollups (00066) were introduced to replace. Past ~55k results that scan exceeds the authenticated role's 8s statement timeout, so the RPC returned 500 on every visit and the page showed the load-error toast with no data.

Confirmed in production logs: each page visit produced a POST 500 /rest/v1/rpc/competitor_aggregates with matching canceling statement due to statement timeout entries in the Postgres logs.

The fix passes the empty all-time day window ({ days: {} }) — the same shape the Insights All-time preset uses — so the comparison is answered from the daily rollup tables with unchanged semantics. Cost now scales with days in the window instead of accumulated results.

Related issue

None — found via a production report today.

Type of change

  • Bug fix

How to test

  1. Open /dashboard/competitors for a brand with a long tracking history.
  2. The page loads the comparison table instead of the "failed to load" toast.
  3. Scores match the Insights page's All-time competitor leaderboard.

Checklist

  • yarn build passes from web/
  • yarn format:check passes
  • No new dependencies

Note: the head-to-head section's getHeadToHeadComparison still reads prompt_results with an unbounded select('*') — a separate latent risk on large brands, left out of this one-line fix.

The standalone Competitors page called getCompetitorComparison with no
options, which routes to the raw all-time competitor_aggregates scan.
On brands with a large result history that scan exceeds the 8s
statement timeout, so every page load died with a 500 and the load
error toast. Insights already avoids this by passing a day window;
pass the empty all-time window here so the same rollup path answers
with unchanged semantics.
@gkhngyk
gkhngyk merged commit 8a1efb7 into main Sep 17, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/competitors-comparison-timeout branch September 17, 2026 10:34
gkhngyk added a commit that referenced this pull request Sep 25, 2026
…most (#829)

The Action Center went stale on the largest brand: no new action for six
days, while its tracking ran every night and stamped every night.

`recordSignalsForBrand` calls `computePulseMetrics`, and two of that
function's aggregate RPCs rescan every result a brand has ever collected.
Past roughly 25k results they cross PostgREST's 8s statement timeout. On the
largest brand they crossed it on every call — reproduced against production:
103 seconds, four statement timeouts, two retries exhausted. The pass threw,
the `.catch` logged, and the night was gone. Nothing said so; the page simply
showed week-old work.

The pulse shares that function and survived, because it has retries AND a
catch-up sweep. Signals had the retries and nothing else, so a lost night was
lost permanently.

Both halves are fixed.

Windows measured in days now read from the daily rollups (00066), which is
what the dashboard already does for the same reason (#824) — so they are
expressed in whole UTC days, on the convention the dashboard's own delta math
uses. The 24-hour window stays raw: it is anchored to the tracking-run ledger
rather than to midnight, and it is cheap for the same reason the wide ones
are not. Same brand, same window, after: 14 seconds, no statement over 336ms,
and the same warnings and highlights out the other end.

`signal_runs` records one row per finished pass, and a sweep re-runs whatever
stamped but has no row. The row is written last and only on success, so a
pass that threw is exactly what the sweep finds. It also answers a question
that had no answer this week: did the pass run last night? Across 23 brands
it had left no trace on 14 to 16 of them on most recent nights, which is the
ground every detector in #818 was calibrated on.

Refs #818


Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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