Skip to content

feat(action-center): link signals and actions both ways and keep priority current - #1074

Merged
gkhngyk merged 45 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-signal-traceability
Oct 17, 2026
Merged

gkhngyk merged 45 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-signal-traceability

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AC-007: signal ↔ action traceability.

  • An action now keeps every signal it has taken as evidence, both ways.
  • "Why this action?" says how many signals support the action and lists them.
  • Resolving or dismissing a signal updates its action's priority at once.

Stacked on #1072 (AC-006 web), which sits on #1071, #1070 and #1058. Please review the last commit, feat(action-center): link signals and actions both ways and keep priority current, or merge those first. It reads the priority columns #1071 adds.

Spec: AC-007-signal-action-traceability.md and AC-spec-priority-score-signal-intelligence.md §10–12.

What was missing

signals.action_id held one action per signal and was written once:

  • A still-open signal never started a new action. If the signal stayed open after its action closed, it kept pointing at the closed action, and the generator counted it as "claimed".
  • One action per signal. A signal could not be shown as used by more than one action.
  • Newcomers dropped out of the queue. Signals linked to an active action after it was created were meant to stay queued for the next cycle (Action Engine — build plan and phase tracker #818 phase 6). After the first night they counted as claimed, and the candidate went stale.
  • Counts included closed signals. The list counted resolved and dismissed signals as support.
  • Priority updated only at night. Resolving a signal changed nothing until the next run.

Database: migration 00145_action_signals.sql

  • New table: action_signals (action_id, signal_id, linked_at) holds every link and keeps it after either side closes.
  • Backfill: existing links are copied from signals.action_id.
  • Access: members can read. Only the server (service role) writes, so there are no write policies.
  • signals.action_id stays as the signal's current action, which the signals list, its filters and the API already read.
  • Also updated: schema.sql and web/src/types/supabase.ts.

Server

  • The nightly generator (generate.js):
    • Linking: it writes the link row first, then points the signal at the action. If the second write fails, the signal is linked again the next night instead of being taken with no link.
    • Taken: a signal counts as taken only while an active action holds it. A still-open signal whose action closed can start the definition's next cycle, after the rest window, as the module's own lifecycle comment says.
    • Queue: the queue holds the matched signals that are not in an active action's scope, meaning the signals the action was created from (baseline.signals). Newcomers linked as evidence stay queued on every night after they were linked.
  • Clustering (§12) is the existing model, now pinned by a test.
    • Each definition is one response to one kind of finding, and a brand has one active action per definition.
    • So two similar prompts with the same root cause ("best AI rank tracker" and "most accurate AI rank tracker tools") are two signals of one kind, and they make one action.
    • We chose this over semantic clustering with embeddings: it costs nothing and meets the acceptance criterion.
  • Rescoring at once:
    • rescoreAction and rescoreActionsForSignal in priority-data.js score the active actions a signal supports, from their open signals, as the nightly pass does. Like the nightly pass, they are best effort.
    • They are exposed as POST /api/action-center/signals/:id/rescore (new routes/action-center.js). The route validates the id with Zod and checks the signal's brand against the caller's organization.

Web

  • "Why this action?" now ends with a supporting-signals block. It replaces the old "Primary signals" block, which listed any 3 signals.
    • The count: "3 signals support this action" counts the open signals the action holds now.
    • The rows: up to 5 open signals, each by type · platform · subject, e.g. "Citation · Lost — ChatGPT · Which tools track…". Clicking a row opens the signal.
    • "All signals (n)" opens the Signals tab, which still lists resolved and dismissed signals and ones that moved on.
    • When none remain open: "No open signal supports this action any more."
  • The list's "n signals" tag and the CSV's signal_count count only open signals.
  • Reads go through action_signals: the drawer, History (sources and "Consolidated from n signals") and MCP get_action. A closed action keeps the signals that later moved to a new action.
  • When a signal changes status:
    • If it opens or closes (resolve, dismiss, reopen), updateSignalStatus asks the server to rescore its actions, with after(), so the click doesn't wait.
    • Acknowledging leaves the signal open, so nothing is asked.
  • Small move: signalTypeLabel ("Citation · Lost") is a shared helper now, also used by Copy Data and the exports.

Not in this PR

Review

I ran a code review before opening this. Six of eight findings are fixed:

  • History read a closed action's signals by action_id, so it lost the ones that moved on.
  • The link row was written after action_id, so a failed write could hide a signal for good.
  • A closed action's drawer counted signals that now support a later action.
  • The status change waited for the rescore.
  • Acknowledging also triggered a rescore.
  • Tests were missing for the web reads and for the rescore call.

Two are left as is:

  • The 1,000-row cap. The list's open-signal count is one brand-wide read, so it is subject to PostgREST's 1,000-row cap. This was already the case before, and the open-only filter makes it smaller.
  • The · separator in the supporting line is written in code, as it is in Copy Data and the exports.

Related issue

None. Product spec AC-007 (Action Center).

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 00145_action_signals.sql.
  2. Run a signal pass for a brand (node src/scripts/backfill-signals.js <brandId>), or wait for the nightly one. The actions it opens have rows in action_signals.
  3. Open a detected action, e.g. Recover lost citations:
    • Under Why this action? you see "n signals support this action" and the rows.
    • Clicking a row opens the signal. All signals opens the Signals tab.
  4. On Signals, resolve one of its signals.
    • The action's priority_updated_at moves at once.
    • The drawer says one signal fewer, and All signals still counts it.
  5. Acknowledge a signal: no rescore request is sent.
  6. Move the action to In progress and open it on History: "Consolidated from n signals" and its sources come from action_signals.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not 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: 619/619. New tests:
    • supporting-signals.test.tsx: the count, the rows, moved-on signals, and "All signals".
    • signal-status-rescore.test.ts: rescore only when a linked signal opens or closes, and a status change that survives a failed request.
    • action-signals.test.ts: the open-only count and the read through action_signals.
  • yarn build: passes.
  • server: npm run format, npm run lint (clean) and npm test 1205/1205. New and changed tests:
    • generate.test.js:
      • link rows written before action_id;
      • two similar prompts make one action;
      • a still-open signal whose action closed starts the next cycle;
      • newcomers stay queued on later nights;
      • in-scope signals aren't queued.
    • rescore.test.js:
      • only active linked actions are rescored;
      • confidence drops when a confirming source resolves;
      • a failed save doesn't fail;
      • the route's 404 and 403.
  • bash supabase/build-schema.sh: run.
  • Against the dev database:
    • Migration: applied 00145 after a rolled-back trial.
    • Generator: with sample signals, it opened 5 actions with their links. Recover lost citations took 3 signals on 3 prompts as one action.
    • Rescore: resolving one of them in the browser rescored the action at once.
    • Pages: the drawer showed 3, then 2 supporting signals, and History read through the table.
    • Cleanup: the sample data was removed afterwards.
  • In the browser: the drawer at 1440px and 1024px, in the light and dark themes.

🤖 Generated with Claude Code

cihan-gyk and others added 8 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]>
Every action's drawer gets Copy Data, Export CSV and Export Excel
(AC-005). Copy Data opens the whole action as Markdown, every tab of the
drawer, to copy a part or all of it with one click; the copy falls back
to the browser's copy command where the clipboard API is blocked. The
CSV (action-AC-52.csv, UTF-8 with a BOM) has a row per task and per
signal marked by a section column; the Excel workbook has a sheet each
for the action, its tasks, its signals and its history. Adds the
write-excel-file package, loaded only when a workbook is asked for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each action gets a priority score from 0 to 100 with a level (critical,
high, medium, low), and the facts behind it for "Why this priority?"
(AC-006). The score weighs impact, the demand of the most searched
prompts, queries or pages, how severe the change is, commercial intent,
independent kinds and sources of evidence, whether the ground was held
before, and how recent it is, never how many signals repeat. It is
worked out when an action is created and again every night, stored in
new columns (migration 00144), and orders the queue of waiting findings
too, with a little added for each day waited.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The actions list sorts by the server's priority score by default, shows the
score beside Impact, and the Top Actions card counts the five highest-priority
open actions. The drawer explains the score in "Why this priority?", and Copy
Data and the exports carry it. MCP list_actions and get_action return the
priority, and list_actions can sort by it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mpact

The score already weighs impact in, so showing both read as two answers to
one question. The Actions and History lists drop their Impact column for a
Priority Score column (score and level), filter and sort by priority, and the
Potential Impact card becomes Highest Priority. The drawers' headers, Copy
Data and Excel show the priority instead of impact, and MCP list_actions now
lists the highest priority first by default (sort "updated" for the old
order). Signals keep their own impact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rity-score

# Conflicts:
#	supabase/schema.sql
…rity current

AC-007. Every signal an action takes as evidence is now kept in a new
action_signals table (00145), so an action lists its signals after they move
on to a later cycle and a signal can be used by more than one action.

- The nightly generator writes the link, treats a signal as taken only while
  an active action holds it (a still-open signal whose action closed can
  start the next cycle), and keeps newcomers queued on the nights after they
  were linked, not only the first.
- Resolving, dismissing or reopening a signal scores its active actions again
  at once, through POST /api/action-center/signals/:id/rescore.
- "Why this action?" says how many open signals support the action and lists
  them by type, platform and subject. The list counts only those, and the
  drawer, History and MCP get_action read through the new table.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is ready for review. It's AC-007 (signal ↔ action traceability), stacked on #1072 and the PRs under it. Until those merge, this part is the last commit.

Things to look at:

  • New migration 00145_action_signals.sql: a link table keeping every signal an action took, both ways, backfilled from signals.action_id (which stays as the signal's current action).
  • Generator behaviour change: a still-open signal whose action closed can now start the next cycle (after the rest window), and newcomers linked to an active action stay queued past their first night. Both were the documented intent; the code had drifted from it.
  • New route POST /api/action-center/signals/:id/rescore: the dashboard calls it (after the response) when a linked signal opens or closes, so the action's priority updates at once.
  • Clustering: kept the existing one-action-per-definition model and pinned it with a test, instead of semantic clustering.

Code review (6 of 8 findings fixed, the rest noted in the description). Web tests (619/619), server tests (1205/1205), lint, typecheck and build pass; checked end to end against the dev database with sample signals, then cleaned up.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 15, 2026
cihan-gyk and others added 19 commits October 16, 2026 00:26
# Conflicts:
#	web/src/components/action-center/action-drawer.tsx
# Conflicts:
#	server/src/lib/action-center/from-prompt-improve.js
#	supabase/schema.sql
#	web/src/types/supabase.ts
…rity-ui

# Conflicts:
#	web/src/lib/actions/action-center.ts
#	web/src/lib/actions/action-history.ts
…traceability

# Conflicts:
#	web/src/components/action-center/action-drawer.tsx
…traceability

# Conflicts:
#	supabase/schema.sql
…traceability

# Conflicts:
#	supabase/schema.sql
…ure/action-priority-score

# Conflicts:
#	supabase/schema.sql

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

Reviewed. Migration 00145 is applied to production (2,688 existing links backfilled; checked under RLS as a member and as a user of another organization). Merged main into the branch: updateSignalStatus now moves a set of signal ids at once, so the rescore reads before and after for the whole set; each drawer branch keeps its own separator. The rescore route checks brand access before scoring.

@gkhngyk
gkhngyk merged commit b526bde into ansvisor:main Oct 17, 2026
4 of 5 checks passed
gkhngyk added a commit that referenced this pull request Oct 17, 2026
* feat(action-center): show where each signal happened and filter signals 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]>

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

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]>

* feat(action-center): show where a signal happened, what changed and what it rests on

The signal drawer showed bare numbers ("0 → 251 +167") and no platform,
location, page or action. Part one of AC-001: the drawer has three blocks.

- Where: the fields the spec asks per category (prompt, topic, platforms,
  locations, domain, competitor, pages, queries, and for a lost citation
  the page cited before and who is cited now). A field no detector records
  yet says "Not available"; platforms read from a signal's prompts say
  "Tracked on".
- What changed: every figure with its metric, whose or which window, and
  unit, over its period: "Mention rate · previous 7 days 34% → last 7 days
  18%, −16 pts". A source domain's three counts are named instead of read
  as a before and after. A fall in the brand's own numbers is red, a
  competitor's rise too (the old colouring showed drops as good news).
- Evidence and links: the page behind the signal (the prompt's answers, the
  topic, Citations…), first and last detection, and the actions using it.

MCP list_signals returns the same detail per signal (where, change,
evidence, used_by_actions) beside the raw row, from lib/signals/detail.ts.

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

* feat(action-center): copy or export everything an action shows

Every action's drawer gets Copy Data, Export CSV and Export Excel
(AC-005). Copy Data opens the whole action as Markdown, every tab of the
drawer, to copy a part or all of it with one click; the copy falls back
to the browser's copy command where the clipboard API is blocked. The
CSV (action-AC-52.csv, UTF-8 with a BOM) has a row per task and per
signal marked by a section column; the Excel workbook has a sheet each
for the action, its tasks, its signals and its history. Adds the
write-excel-file package, loaded only when a workbook is asked for.

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

* feat(action-center): score every action's priority on the server

Each action gets a priority score from 0 to 100 with a level (critical,
high, medium, low), and the facts behind it for "Why this priority?"
(AC-006). The score weighs impact, the demand of the most searched
prompts, queries or pages, how severe the change is, commercial intent,
independent kinds and sources of evidence, whether the ground was held
before, and how recent it is, never how many signals repeat. It is
worked out when an action is created and again every night, stored in
new columns (migration 00144), and orders the queue of waiting findings
too, with a little added for each day waited.

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

* feat(action-center): show each action's priority and work the list by it

The actions list sorts by the server's priority score by default, shows the
score beside Impact, and the Top Actions card counts the five highest-priority
open actions. The drawer explains the score in "Why this priority?", and Copy
Data and the exports carry it. MCP list_actions and get_action return the
priority, and list_actions can sort by it.

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

* feat(action-center): use the priority score wherever actions showed impact

The score already weighs impact in, so showing both read as two answers to
one question. The Actions and History lists drop their Impact column for a
Priority Score column (score and level), filter and sort by priority, and the
Potential Impact card becomes Highest Priority. The drawers' headers, Copy
Data and Excel show the priority instead of impact, and MCP list_actions now
lists the highest priority first by default (sort "updated" for the old
order). Signals keep their own impact.

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

* feat(action-center): link signals and actions both ways and keep priority current

AC-007. Every signal an action takes as evidence is now kept in a new
action_signals table (00145), so an action lists its signals after they move
on to a later cycle and a signal can be used by more than one action.

- The nightly generator writes the link, treats a signal as taken only while
  an active action holds it (a still-open signal whose action closed can
  start the next cycle), and keeps newcomers queued on the nights after they
  were linked, not only the first.
- Resolving, dismissing or reopening a signal scores its active actions again
  at once, through POST /api/action-center/signals/:id/rescore.
- "Why this action?" says how many open signals support the action and lists
  them by type, platform and subject. The list counts only those, and the
  drawer, History and MCP get_action read through the new table.

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

* test(action-center): read the 30-day position result through the shared event text

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

* test(action-center): let the action-signals mock answer the detail's outcome read

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

* test(action-center): follow the merged signal changes in the AC-007 tests

#1060 moves updateSignalStatus to a list of signal ids (a group's copies
move together) and gives SignalWhere its topics; #1074's tests still called
it with one id and built where without topics. They now do as #1076's merge
of the same two stacks does.

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

* feat(action-center): list every action a signal was used by

A signal drawer's "Used by actions" and list_signals' used_by_actions read
the signal's action_id, its current action only. Once a signal outlived its
action and supported the next cycle's, the earlier action dropped out.

Both now read the signal's links in action_signals (AC-007): every action it
was used by, closed ones included. The current action leads, then the rest
by their latest link, and the drawer shows each action's status. list_signals
reads the links in chunks of 100 signals, so a full page stays within the
request line, and a failed read still costs used_by_actions only.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
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