Skip to content

feat: show fan-out coverage next to sub-query count in the by-prompt view - #651

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
arambu1a:feature/fanout-coverage
Aug 7, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
arambu1a:feature/fanout-coverage

Conversation

@arambu1a

@arambu1a arambu1a commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

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

getQueryFanout now returns promptCoverage: { id, text, totalRuns, runsWithFanout }[], accumulated in the same single pass over prompt_results that 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 promptCoverage before the sub-query inversion, so every prompt with a run in the window gets a row. A new "Answers with fan-out" column renders 12 / 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:

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> with aria-expanded, and the By-prompt list has its own pager since it covers every tracked prompt rather than only those with fan-out.

Screenshot 2026-08-05 at 1 41 16 PM

Limitations

totalRuns spans 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.ts over a mocked Supabase client: 0 / N for 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.

…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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@gkhngyk
gkhngyk merged commit 3fe893a into ansvisor:main Aug 7, 2026
3 checks passed
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.

Fan-out by-prompt view: show run count / fan-out coverage next to sub-query count

2 participants