Skip to content

perf(competitors): send head-to-head as per-engine summaries and load runs on demand - #942

Merged
gkhngyk merged 1 commit into
mainfrom
fix/head-to-head-sql-aggregate
Oct 5, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/head-to-head-sql-aggregate

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

First part of #923. getHeadToHeadComparison returned one row per tracked answer — each with its full answer text and citations — and the Competitors page grouped them in the browser. The page never displays the answer text or citations; the eye button links to the result's own page.

  • Summaries instead of rows. The server action now returns one summary per (prompt, engine, model, region): run count, brand and competitor averages, diff, latest run time. The aggregation lives in a pure module, web/src/lib/head-to-head.ts, with unit tests.
  • Runs on demand. New getHeadToHeadRuns loads a group's newest runs (max 50) when the user expands it, and the eye button fetches the latest run when clicked.
  • Gaps / strengths rank those summaries instead of single runs, so one outlier run no longer fills the list.
  • Unchanged: the overall averages and per-provider table keep their semantics — the competitor average only counts answers that list the competitor, and group averages count a missing competitor as 0, as before.

Behaviour changes worth noting:

  • the latest-sentiment badge moved from the collapsed group header into the expanded run list;
  • groups are keyed by the raw platform/model_used/region, so two raw platforms that resolve to the same provider show as two rows.

Not in this PR: the data source is still a single page of raw results (PostgREST's 1,000-row cap), so large brands are still summarised from their newest answers. Moving the summaries onto the daily rollups depends on #867 and is the remaining part of #923.

Related issue

Part of #923

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Competitors, pick a competitor — the head-to-head loads as before.
  2. Expand a prompt, then an engine row — Previous runs shows a short spinner, then dates, scores and sentiment.
  3. The eye icon on an engine row opens the latest answer's result page.
  4. Gaps and Strengths tabs list prompts with their engine.
  5. yarn test src/lib/head-to-head.test.ts from web/.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

… runs on demand (#923)

getHeadToHeadComparison returned one row per tracked answer, each with its
full answer text and citations, which the Competitors page never displays.
It now returns one summary per (prompt, engine, model, region) with run
counts and averages; a group's individual runs load via getHeadToHeadRuns
when the user opens it or views its latest answer. Gaps and strengths rank
those summaries instead of single runs.

The data source is unchanged (one page of raw results), so large brands are
still summarised from their newest answers; moving it onto the daily
rollups is the remaining part of #923.
@gkhngyk
gkhngyk merged commit 106c5ff into main Oct 5, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/head-to-head-sql-aggregate branch October 5, 2026 19:13
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