Repository navigation
fix(chat): read the Topics table, Query Fan-outs, a competitor head to head, Overview's map and Opportunities, AI bots and Search Console pages - #2466
Merged
Conversation
…o head, Overview's map and Opportunities, AI bots and Search Console pages Chat opened on Prompts, Competitors, Visibility or AI Traffic now reads what those pages show that no read gave it (step 6c of "Chat must read everything a page shows"). Seven reads in a new registry file, each on the page's own function or database function, after brandAllowed, from daily rollups or one aggregate in the database; none reads the tracked answers: - get_topics_overview: Prompts › Topics, getTopicsOverview (topics_overview_window), highest AI Visibility Score first, paged. - get_query_fanouts: Query Fan-outs for a plain question, outside a skill: sub-queries, the By prompt view and gaps, 7 days by default, 30 at most. - get_competitor_head_to_head: getHeadToHeadComparison and the competitor timeline; the competitor by id, name or domain, not_found otherwise. - get_topics_vs_competitors and get_visibility_opportunities: the Overview's heat map, trend markers and Opportunities card. - get_ai_bots and get_gsc_pages: getTrafficBots and getTrafficGooglePages, the bot report locked on Starter as on the page. The page loaders these reuse read through dbClient() so Chat runs them with the service role. Citations › Gaps needs a migration (its functions refuse the service role) and is left out. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
approved these changes
Nov 17, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Cost note: getQueryFanoutsFor (queries view) runs three raw aggregates over prompt_results (brand_prompt_fanout_queries with p_min_answers 1 and an unlimited jsonb_agg, report_query_fanout, report_query_fanout_engines) even to show one page of 50; consider p_min_answers 2 or a limit, taking times_searched from report_query_fanout, or marking it costlier.
This was referenced Nov 17, 2026
feat(chat): read Citations › Gaps; the citation functions let the service role through (00541)
#2469
Merged
gkhngyk
pushed a commit
that referenced
this pull request
Nov 18, 2026
…erge The merged base runs #2462's page periods over the reads #2464 and #2466 add: Prompts › Tracked's locations, the Topics tab, and AI Referral Traffic's bots and Search Console pages cut a preset as their pages do (the last N × 24 hours to today), and the eval set now has rows 38 (Today's first action) and 39 (losses to a competitor). Their tests say so. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
pushed a commit
that referenced
this pull request
Nov 18, 2026
…vice role through (00541) Chat's reads run with the service role after brandAllowed, but the citation functions (00426) refuse it: can_access_brand answers no without a person, so they return nothing (the Gaps list empty, its totals at zero). #2466 left Citations › Gaps out for this reason. - 00541 (number provisional): citation_gap_domains(_daily), citation_competitor_sources(_daily), citations_window_stats, citations_domains, citations_urls, citations_urls_daily, citation_url_candidates and citation_url_occurrences let the service role through, as 00434 and 00435 do. Each is its 00426 definition with only the check changed; a person still needs can_access_brand. Functions and comments only, no data touched; schema.sql regenerated. - get_citation_gaps: the Gaps tab's own read (getCitationGaps, now on dbClient()) under asService after brandAllowed: the Gap list strongest first, or one competitor's sources (By competitor), 50 a page; the person's range as whole UTC days, all time with none; a topic or competitor of another brand is not found. - brand-access-functions.test.ts checks each 00541 definition against 00426. - Chat Help: ask which sites cite your competitors but not you. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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.
Summary
Step 6c of the owner's plan "Chat must read everything a page shows".
Chat opened on Prompts, Competitors, Visibility or AI Traffic can now read the tables those pages show that no read gave it. Before this, Chat had no read for the Topics table, Query Fan-outs outside a skill, a competitor's head to head, the Overview's heat map and Opportunities card, AI bots, or Search Console pages. So it answered "I couldn't read it".
Seven new reads, in a new registry file. Each one calls the page's own function or database function. Each reads daily rollups or runs one aggregate in the database. None reads tracked answers (
prompt_results) row by row.Citations › Gaps is not in this PR. Its database functions refuse Chat's service-role client, so the read needs a migration (see the last section).
Changes
get_topics_overviewgetTopicsOverview→topics_overview_window(rollups, 00536)get_query_fanoutsviewqueries: sub-queries, most searched first, with engines, answers, prompts, tracked.prompts: the By prompt view.gaps: sub-queries whose answers never named the brand. 7 days by default, 30 at most, 50 a page.brand_prompt_fanout_queries,report_query_fanout(_engines),ae_fanout_gapsget_competitor_head_to_headsidelosing (biggest gap first), winning or all. Weekly mentions and the competitor's page events.getHeadToHeadComparison→head_to_head_daily(rollups, 00169);getCompetitorTimeline(daily rollups)not_foundotherwise.get_topics_vs_competitorsinsights_topic_competitors_daily(rollups),insights_trend_markers,kpi_definitionsmodel).get_visibility_opportunitiesprompt_suggestionsand the same rollup as the mapget_ai_botsgetTrafficBots→ai_bot_report(daily bot rollups)get_gsc_pagesgetTrafficGooglePages→ai_traffic_google_pages(Search Console daily figures)Other changes:
getTopicsOverview,getCompetitorTimeline,getTrafficBotsandgetTrafficGooglePagesread throughdbClient()instead ofcreateClient(). The page reads exactly as before. Chat runs them with the service role afterbrandAllowed, as it already does for other loaders.sourcesOfingoogle-reads.tsis exported (the same one-line change feat(chat): customers and revenue from AI visits, with the setup each answer needs #2451 makes).scope.ts: the fan-out read opens on the tab's 7 days when no range is set.get_query_fanouts.brand_id,date_from,date_to,model,region,competitor_id,days), so fix(chat): read over the page's dates and filters in the side panel #2459's page filters fill them once it lands.en.json; one Chat Help section;approved-articles.jsonregenerated.Safety
brandAllowed. A brand of another workspace, or one not shared with the person, reads as not found. Nothing else of it is read and no database function runs.prompt_setson the brand. A competitor id of another brand isnot_found.prompt_results. A test runs every read and checks.'use server'export changed.chat-thread-view.tsx,page-pane.tsx,page-open.ts, the content editor or Action Center site-type files.How to test
Checks
npx tsc --noEmit -p .: clean.src/lib/chat,src/lib/mcp,src/components/chat, the Prompts, Visibility (Overview, Mentions, Citations), Citation URL, Competitors and Traffic pages,src/lib/help,src/i18n,use-server-exports,subscription-guard-coverage, the topic, traffic and competitor-timeline tests andsrc/app/api/traffic: 392 files, 5,119 passed, 1 skipped.prompt_results), 9 on the registry rows (inputs, scope, plan, brand access), 7brand-scope.test.tsrows, and a scripted eval scenario (row 38) with 2 harness tests: on Competitors, "Acme CRM'e karşı hangi promptlarda kaybediyoruz?" must read the head-to-head and name the prompts.git merge-tree --write-tree HEAD upstream/main: clean. Also clean against feat(chat): customers and revenue from AI visits, with the setup each answer needs #2451 and fix(chat): read over the page's dates and filters in the side panel #2459. With fix(chat): read Today, your agents and their runs, History over a range, and the Signals summary #2465 (Today), both add eval scenario "row 38": whichever lands second renumbers its row whenmainis merged in.Not in this PR / Needs a migration
get_citation_gaps): needs a migration.citation_gap_domains(_daily)andcitation_competitor_sources(_daily)refuse the service role (00426). Through them, Chat would read "no gaps" for every brand. Reading their rollup tables directly instead could mean tens of thousands of rows a month for a large brand, summed in the app. The proposed SQL lets the service role through the four functions, as 00434 and 00435 did for the others. It is schema only. Once it is applied,get_citation_gapsisasService(getCitationGaps), withgetCitationGapsondbClient(). The maintainer gives the migration number; it can go together with the citations aggregate migration fix(chat): rank and count as the pages do #2462 names.list_citationsurlslookup already returns the prompts whose answers cite a page, with how many answers each. Positions per answer are not in it.get_fanoutskeeps inside skills.Choices made
get_fanouts/get_fanout_gapskeep to the plan's platforms, as before.Generated by Claude Code