Skip to content

fix(insights): open a model's whole family from a one-slug link, on Insights and Citations - #1824

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/model-filter-family
Oct 30, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/model-filter-family

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Found in the W1-28 review (#1807). Insights' and Citations' AI Model filter holds a family of slugs, such as chatgpt-web,gpt-5-chat-latest. A link with one slug (?model=chatgpt-web, as Chat's open_page builds) showed "ChatGPT" in the picker but counted only the web scraper's rows. So opening a page from Chat could give different numbers than picking ChatGPT by hand.

What changes

  • New web/src/lib/model-families.ts: the grouping that each page had written on its own (modelLabel, modelFamilies) moves here, plus modelFamilyValue, which turns one slug into its family's value. Citations' getPlatformDisplayLabel uses modelLabel too, so both pages name models the same way.
  • Insights and Citations look up the brand's models once for a single slug in the URL (getBrandFilterOptions, once per slug, before the first data read). The filter and the URL move to the family. The data is read once, so no narrower numbers flash first.
  • Existing bug fixed: Citations' platform Select cleared a value that wasn't among its options (onValueChange(null)). The options come from that window's rows, so platform=chatgpt-web from a link was silently dropped, and so was a family only partly answered in that window. The chosen platform is now always among the options (platformChoices, labelled by getGroupedPlatformLabel).

Related issue

Follow-up to #1807.

Type of change

  • fix — Bug fix

How to test

  1. /dashboard/insights?model=chatgpt-web: the picker shows ChatGPT, and the URL becomes the family.

  2. /dashboard/citations?platform=chatgpt-web&preset=24h: the filter stays, the URL holds the family, and the picker shows "ChatGPT".

  3. Tests: model-families.test.ts (3), and two new scenarios in Citations' page.test.tsx:

    • a single slug leads to one family read, and the picker shows "ChatGPT";
    • a family, or a one-slug family, is kept as is with no extra read.

    11/11.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: eslint and prettier clean, the related tests pass (typecheck left to CI)
  • Tests added

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 30, 2026 01:55
…bility and Citations

Both pages' model filter offers one entry per name, and its value is the
family's slugs ("chatgpt-web,gpt-5-chat-latest"). A link with one slug,
such as Chat's open_page (model=chatgpt-web, platform=chatgpt-web), read
only that slug. Brand Visibility counted fewer answers than picking ChatGPT
in the dropdown, and Citations dropped the filter: its dropdown clears a
value it doesn't list.

- lib/model-families.ts holds the grouping both pages used inline
  (modelLabel, modelFamilies) and modelFamilyValue: one slug of a family
  reads as the family.
- Before its first read, each page asks the brand's models once
  (getBrandFilterOptions) for a single slug, and moves the filter and the
  address to the family. The numbers are read once, for the family.
- Citations always lists the platform asked for among its choices. They
  come from the rows read, so a family partly answered in the window was
  dropped too.
- Tests: the helpers, and Citations from a link (one slug, a family, a
  family of one).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChatGPT's web answers store the model Cloro names (gpt-5-...), not
chatgpt-web, so a link's model=chatgpt-web matched no family and opened
an empty page under a ChatGPT chip. A known platform id with no stored
answers now reads as the family of the same name. An unknown slug is
kept, since its fallback name would be ChatGPT's.

@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.

Looks good with 2718c5b (one commit on this branch). Sharing the grouping between the two pages is a good cleanup, and the Citations Select fix is a real bug fixed. The commit covers the one open case below.

Fixed: a platform id, not a stored slug

modelFamilyValue finds the family that contains the slug. That works when answers were stored under chatgpt-web. But ChatGPT's web answers store the model Cloro returns (cloro-scraper.js: model = result.model || scraperId, so gpt-5-3-mini, gpt-5-5, …). The page's own comment names that family "gpt-5-3-mini" + "gpt-5-5". For such a brand, ?model=chatgpt-web (Insights) or ?platform=chatgpt-web (Citations, which #1807 builds) matches no family and stays as is. The page shows a "ChatGPT" chip over an empty page. The tests use chatgpt-web,gpt-5-chat-latest, so they don't hit this.

The commit: when no family contains it, a known slug (one in MODEL_PROVIDER_LABELS / PLATFORM_LABELS) reads as the family shown by the same name, the way the dropdown groups it. An unknown slug is kept, because resolveAIProvider falls back to OpenAI, so ?model=anything would otherwise open ChatGPT's numbers. Both pages call the same function, so both get the fix. A new test case fails without it (chatgpt-web → gpt-5-3-mini,gpt-5-5, perplexity-web → sonar-pro, an unknown slug and a two-slug value kept).

With this, #1807's open_page could pass the platform to Insights again (as model=). Follow-up there.

Checked, fine

  • URL values. An unknown slug costs one getBrandFilterOptions call, then the read uses it as is (empty result). A comma list isn't single, so no extra read, and it goes to .in() as before. Values reach PostgREST only through .eq/.in or the RPCs' text[] args. Nothing is interpolated.
  • Scope. Families come from the brand's own stored answers (insights_filter_options, the caller's client). A slug outside the plan's engines only narrows the brand's own rows. No other brand's data is reached.
  • One read. The family lookup happens once per slug (familyRead), before the first data read. On Citations the load returns and the filter change starts the read. On Insights the read continues with the family. A failed lookup keeps the slug.
  • Both pages now label models with modelLabel, and the Citations picker keeps a value it doesn't list (platformChoices).
  • Build. model-families.ts imports only ai-provider-avatar and platform-labels, no server modules. plan-row.test.ts passes.

Non-blocking

  • Insights: a brand switch during the family lookup could put brand A's family back after the switch cleared the model. Citations has stale() there, but Insights has no equivalent. It's rare, and the next pick fixes it.
  • An unknown slug still shows "ChatGPT" in both pickers, because of the same resolveAIProvider fallback. This was already the case before.
  • gemini-web is labelled "Google Gemini", but gemini-* model slugs show as "Gemini" or "Gemini 2.5 Flash". So a gemini-web link maps only if Gemini answers were stored under gemini-web. The labels already don't match today; aligning them would fix the link too.

Merge

  • Based on current main and merges clean. No migrations.
  • Conflicts with #1843 (and #1844, stacked on it) in insights/page.tsx. #1843 adds its own modelName() with the same three-way lookup. Resolve by keeping #1843's modelName as a call to modelLabel(value.split(',')[0]), and drop the old imports.
  • Clean with #1807.

Tests

  • model-families.test.ts (5, incl. the new case), Citations page.test.tsx, src/app, src/lib/guards (incl. plan-row.test.ts), src/config: 189 files, 1765 tests pass with the fix.
  • tsc is clean. eslint has no errors (only existing warnings), and prettier is clean on the changed files.

@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.

Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.

@gkhngyk
gkhngyk merged commit 1630e0a into ansvisor:main Oct 30, 2026
4 of 5 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.

2 participants