Skip to content

feat(action-center): group copies of one signal and count them once - #1059

Merged
gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/signals-grouping
Oct 17, 2026
Merged

gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/signals-grouping

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Part two of AC-002 (Signals list). Stacked on #1058: this branch contains #1058's commit, so please review the second commit, feat(action-center): group copies of one signal and count them once, or merge #1058 first.

The problem

On production, one pass on Oct 8 wrote about ten identical rows, "Citations lost for 'Which tools track AI search visibility and answer engine optimization performance over time?'".

  • They are not one row per platform or location. The brand tracks that exact text as 11 separate prompts, spread over different topics, and the detector writes one signal per prompt.
  • What it caused: the list read as duplicates, and every count (tabs, badge, the four cards) counted each copy.

What changes

  • One row per group:
    • Rule: signals of one kind, about one prompt text (case, spacing and the closing "?" ignored), found in one pass.
    • Group row: shows "N prompts", the union of the copies' platforms and locations, the most open status, and a ×N grouped toggle.
    • Opened: it lists each copy with its topic, place and status.
    • Each copy keeps its own drawer and menu.
  • Group menu: acts on the copies each choice applies to. "Mark resolved" resolves the open copies and leaves resolved ones alone; "Reopen" reopens the closed ones.
  • Counts: the category tabs, the Action Center tab badge and the four summary cards count groups. An info icon explains it whenever grouping collapsed rows.
  • Deep links: a drawer opened from a link to a copy (an action's evidence) opens that copy's group, so its row is visible.
  • Export CSV still has one row per signal, as the spec asks.

Migration 00141_signal_groups.sql

  • signal_group_key(id, kind, detected_at, payload): the same rule as web/src/lib/signals/group.ts. Signals not about a prompt are their own group.
  • signals_summary: 00080's function, counting groups instead of rows. A group is:
    • detected when its first copy was;
    • high impact when any copy is;
    • resolved only once every copy is, so an open finding never shows as resolved.
  • signals_new_count(p_brand_id): the badge's count of untriaged groups. It returns one number, where the old head count of every row now has to group.

schema.sql is regenerated. On the dev database, the dry run and then the applied migration gave these numbers for the demo brand, which has 16 signals including 4 copies of one lost citation:

Total Important Resolved Citation Badge
Before 16 8 2 5 13
After 13 5 1 2 11

Review

I ran a code review before opening this. Fixed:

  • a group counted as resolved while copies were open;
  • the badge reading every new row on each navigation, where it now uses the RPC;
  • TS/SQL whitespace handling differing on non-ASCII spaces (both now use ASCII whitespace only);
  • a deep-linked copy staying hidden in a closed group;
  • the toggle's accessible name;
  • the shared empty where object (now readonly).

Left as is:

  • The rule exists twice, in TS for the filtered list and in SQL for the counts. Each points to the other.
  • The root cause is the brand's duplicate prompts. A warning when adding a prompt whose text is already tracked would be a separate change.

Related issue

None. Product spec AC-002 (Action Center), part 2 of 2.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Apply 00141_signal_groups.sql.
  2. Have a brand with the same prompt text tracked as two or more prompts, and a lost citation on them in one pass.
  3. Open Action Center → Signals:
    • the copies are one row with "×N grouped";
    • "All" and the category tabs count it once;
    • the four cards count it once, with the info icon;
    • the tab badge counts it once.
  4. Click the row or the toggle: each copy shows its topic, platforms and locations, and status. Click a copy to open its drawer.
  5. On the group's menu, Mark resolved: the open copies resolve, and Resolved Signals counts the group only once every copy is resolved.
  6. From an action's Signals tab, open a copy: the list opens its group.
  7. Check light and dark mode, and 1024px.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 7 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • yarn test: 573/573, new and updated tests:
    • group.test.ts: the key, normalisation, ordering, group status and place.
    • where.test.ts: topics and the merged place.
    • signal-table.test.tsx: a group opens onto its copies, a copy opens its drawer, a selected copy opens its group, and the group menu resolves only the open copies.
  • yarn build: passed.
  • bash supabase/build-schema.sh: schema.sql is up to date.
  • In the browser: on the demo brand with sample signals shaped like production's, in light and dark mode, at 1440px and 1024px.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 15, 2026 14:20
…ls by platform

The Signals list never said which AI platform or location a signal was
about, and named platforms by their raw ids ("Visibility dropped on
gemini-web", "Weak in JP"). Part one of AC-002:

- Each row's Affected cell gets a line with the engines and locations the
  signal is about: from the payload for platform and country signals, and
  from the prompts' tracked platforms and locations for prompt and topic
  signals. A line rather than a column keeps the table within the page
  beside a pinned sidebar.
- Platforms and locations read as people know them ("Gemini", "Japan").
- Descriptions carry the measured fact instead of a generic sentence, e.g.
  "Your mention rate fell from 34% to 18% against the week before."
- A Platform filter, search over platform and location names, and
  platforms and locations columns in the CSV export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand can track the same prompt text as several prompts, and the
detectors write one signal per prompt: on production one pass wrote ten
identical "Citations lost for '…'" rows, which read as duplicates and
inflated every count. Part two of AC-002:

- Signals of one kind, about one prompt text (case, spacing and the
  closing "?" ignored), found in one pass are one row with a "×N grouped"
  toggle. Opened, it lists each copy with its topic, place and status; each
  copy keeps its own drawer and menu, and the group's menu acts on the
  copies it applies to.
- The category tabs, the tab badge and the summary cards count groups.
  Migration 00141 adds signal_group_key (the same rule as
  lib/signals/group.ts), counts signals_summary over groups, where a group
  is resolved only once every copy is, and adds signals_new_count for the
  badge.
- A drawer opened from a link to a copy opens its group.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Part 2 of AC-002, stacked on #1058 (please review the second commit or merge #1058 first). Copies of one signal (the same prompt text tracked as several prompts) are now one row with a ×N toggle, and the tabs, badge and cards count them once. Migration 00141 changes signals_summary and adds signals_new_count; it is applied on my dev database.

cihan-gyk and others added 15 commits October 16, 2026 00:19
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
…ure/signals-grouping

# Conflicts:
#	supabase/schema.sql
main carries ansvisor#1058 as a squash, so its files come from main and this branch keeps only its own commit on top; schema.sql is regenerated. The export fixtures from ansvisor#1070 gain SignalWhere's new topics field.

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

Thanks, approving. 00141 is applied on production. On the largest brand the 30-day cards go from 394 total, 131 important and 212 resolved to 383, 120 and 203, and the badge from 182 to 180: 407 signals fall into 396 groups, three of them with copies, the largest with 10. The new signals_summary takes 30 ms over 90 days.

I merged main into the branch. With #1058 squashed there, its files come from main and the branch keeps only its own commit; schema.sql is regenerated. One change outside this PR's files: SignalWhere now requires topics, and #1070's two export test fixtures didn't set it, so main would have failed the typecheck after this merge. Both fixtures now pass topics: []. CI is green.

@gkhngyk
gkhngyk merged commit 9b41228 into ansvisor:main Oct 17, 2026
5 checks passed
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 17, 2026
…-where

main carries ansvisor#1058 and ansvisor#1059 as squashes, so their files come from main and this branch keeps only its own commit on top. The MCP data imports keep both main's prompt-usage helpers and this branch's signal helpers.
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 17, 2026
…-evidence

main carries ansvisor#1058 and ansvisor#1059 as squashes; this branch keeps ansvisor#1060's commit and its own on top.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants