Repository navigation
feat: show fan-out coverage next to sub-query count in the by-prompt view - #651
Merged
Merged
Conversation
…view The By-prompt table showed only a sub-query count, with no denominator: "8 sub-queries" read identically whether it came from 10 tracked answers or 500. A prompt the engines never search for was invisible entirely, since the table was built by inverting sub-queries -> prompts and a prompt with zero fan-out had nothing to hang a row on. getQueryFanout now returns promptCoverage, accumulated in the same single pass over prompt_results that already builds the sub-query list, so numerator and denominator describe the same window by construction and no extra queries are issued. The table is seeded from it before the inversion, so every prompt with a run in the window gets a row. Also fixes two pre-existing silent truncations found while wiring this up: the tracked-prompt lookup was un-paginated (PostgREST capped it at 1000 rows), and fetchFanoutRows hit its row ceiling without reporting it.
The fixture had no prompt with zero observed sub-queries, which is the case the By-prompt coverage column exists for: prompt 807 is tracked only on engines that answer a factual question from parametric knowledge, so its 15 results carry no search_queries and it reads 0 / 15 in the tab. The generator stamps created_at at 6h intervals ordered by prompt id, so the last prompt's rows land ~26-30 days back and outside the windows the tab offers. Re-stamp 807's rows into the recent past so the row is actually visible.
gkhngyk
approved these changes
Aug 7, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Excellent work — this is exactly what #543 asked for, and then some. The coverage counters accumulating in the same pass that builds the sub-query list means the two views can never disagree, seeding the table from coverage makes the 0/N rows finally visible, and catching the two silent-truncation bugs (un-paginated tracked-prompt map, ceiling exit with no signal) along the way is a real bonus. The test suite pins all the right contracts. Thanks!
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.
Closes #543
Problem
In Prompts → Fan-out → By prompt, each row showed only the number of distinct sub-queries, with no denominator. "8 sub-queries" read identically whether it came from 10 tracked answers or 500 — and a prompt the engines never search for was invisible entirely, because the table was built by inverting sub-queries → prompts, so a prompt with zero fan-out produced no row at all.
What changed
getQueryFanoutnow returnspromptCoverage: { id, text, totalRuns, runsWithFanout }[], accumulated in the same single pass overprompt_resultsthat already builds the sub-query list. Numerator and denominator therefore describe the same window by construction — the two views cannot disagree, and there are no extra queries.The By-prompt table is seeded from
promptCoveragebefore the sub-query inversion, so every prompt with a run in the window gets a row. A new "Answers with fan-out" column renders12 / 500 · 2%, with a tooltip: "Of N tracked answers in this window, X triggered live searches." Zero-fan-out rows are inert (no expand chevron) rather than opening an empty panel.Two pre-existing silent-truncation bugs surfaced while wiring this up and are fixed here:
fetchFanoutRowshit its row ceiling and returned with no signal. It now reportstruncated, and the tab says counts are a lower bound instead of presenting a confident wrong ratio.Net effect on query count is a reduction: one roster read now serves both prompt-text resolution and the tracked-prompt map (3 reads → 2 in the common case), with the residual
.in('id', …)chunk skipped entirely when the roster covers every prompt.Also: the expand chevron is now a real focusable
<button>witharia-expanded, and the By-prompt list has its own pager since it covers every tracked prompt rather than only those with fan-out.Limitations
totalRunsspans all platforms. A prompt tracked on ChatGPT + Perplexity where Perplexity fans out every time reads as ~50%, which reflects engine mix more than search behaviour. Per-engine coverage breakdown is the v2 noted in the issue.Testing
14 tests in
fanout.test.tsover a mocked Supabase client:0 / Nfor a prompt that ran but never searched, partial coverage, per-answer dedup, blank/non-string sub-queries counting toward the denominator only,runsWithFanout ≤ totalRuns, paused prompts included in coverage but not marked "Tracked ✓", the one-roster-read contract, fail-loud on a residual chunk error, and both truncation branches.