Repository navigation
Description
Problem
#562 switched the All Prompts Visibility column to the prompt-level Visibility Rate because averaging visibility_score across all runs lets zero-visibility runs dilute heavily-mentioned prompts into misleading single digits. The Reports feature still uses the old formula in two sections — and renders the 0–100 score with a % sign, as if it were a percentage:
getPromptPerformance(web/src/lib/actions/reports.ts, ~line 208) — ranks best/worst prompts byavg(visibility_score)over all runsgetTopicPerformance(~line 334) — same all-runs average per topic, with a points change vs the previous window- Rendering: report detail page (
{tp.avgVisibility}%,{p.avgVisibility}%) and_report-pdf.tsx(lines ~215, ~463)
There is also an adjacent correctness bug in the same two functions: their prompt_results selects are un-paginated, so PostgREST silently caps them at 1000 rows (the #430/#464 defect family — the comment above getPromptVisibilitySummaries in tracking.ts documents this exact hazard). Busy brands get best/worst lists computed from a truncated window. getTopicPerformance spans two windows in one select, so it hits the cap even sooner.
Fix
getPromptPerformance: also selectcitation_count; page the scan at 1000 rows/page (the paged-loop pattern already exists later in the same file for the citation-evidence scan); accumulatevisibleRuns(rows withmention_count > 0 || citation_count > 0); addvisibilityRatetoReportPromptPerf—Math.round((visibleRuns / runs) * 1000) / 10, the exact rounding used ingetPromptVisibilitySummaries(fix(prompts): show prompt-level visibility rate instead of zero-diluted average score #562); rank best/worst by the rate (tie-break by mentions). KeepavgVisibilityin the payload.getTopicPerformance: same — per-windowvisibleRuns, topicvisibilityRate, andchangebecomes rate points vs the previous window. Page the scan here too. KeepavgVisibility.- Rendering (detail page + PDF): show the rate with the
%sign (it genuinely is a percentage now). Old stored reports must keep rendering: reports are immutable snapshots, so payloads generated before this change won't havevisibilityRate— fall back to the existingavgVisibilitycell (without adding a misleading%, e.g. renderNNorNN/100for legacy payloads). The competitor table on the detail page already does exactly this dance for its own rate switch (hasCompetitorVisibilityRate ? c.visibilityRate : c.avgVisibilityScore) — mirror it. - No migration needed — reports compute at creation time and store the payload.
Acceptance
- A newly created report ranks best/worst prompts and topics by visibility rate and labels the values as percentages.
- Reports created before the change still render without errors, showing their stored score values.
- A brand with more than 1000 results in the report window gets numbers computed from the full window, not a truncated page.
yarn lint,yarn typecheck,yarn format:checkpass fromweb/.
Activity
arambu1a commentedon Jul 30, 2026
Hi @gkhngyk I'll work on this
fix(reports): rank prompt/topic performance by visibility rate, not d…