Skip to content

fix(action-center): list an action's Affected rows from what it kept, as its count does (AC-009) - #1409

Merged
gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:fix/action-affected-entities
Oct 23, 2026
Merged

gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:fix/action-affected-entities

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

AC-009 follow-up (#1389's known limit): an action's Affected rows come from what it kept when it was created (action_entities), so the rows always agree with the count in the heading.

Stacked on #1389. Merge after it. Web only, no migration (00244 is on main).

On prod (gkhngyk's check of the 182 open prompt actions with signals), the drawer's rows came from the signals the nightly pass rewrites: 74 listed more prompts than their count and 47 fewer.

How the rows are built now (affected.ts, entity-counts.ts)

  • readKeptEntities(actionId): the action's action_entities rows, removed ones marked (one query on the primary key, members' RLS, limit 1000, ordered by label).
  • affectedOf(signals, payload, kept): with kept rows of the action's targetEntity:
    • each kept prompt or page still there is a row, with what the signals say of it (platforms, lost pages, leaders…);
    • one no signal names now is a plain row;
    • a row the action never had, or lost since, isn't listed. An action that lost them all lists none.
    • Competitors are the kept names.
    • Totals are the count (an action made before 00244 kept its first 50; its count says the rest).
  • Matching:
    • a prompt by its id;
    • a text-only row by the label kept for it, never a row with an id (copies of a text live in other topics);
    • a page by its address (protocol, www and trailing slash aside).
    • The same prompt named by id and by text is one row, with all both say.
  • A key is an id only when it is a UUID. Actions that kept prompts by their text (topic opportunities, opportunities without prompt ids) get rows without links or volume reads, never a text where an id goes.
  • When the list can't be read (no 00244, an error) or has no rows of that kind, the rows come from the signals as before. A database without 00244 does so quietly; any other error is logged.

Where

After review (2026-10-23):

  • The Why's demand also covers prompts the signals name outside the kept list, in the drawer and in the MCP export.
  • The list's Export CSV reads the kept lists too, one paged read per 100 actions, with the same quiet fallback before 00244.
  • Web only, 10 files, no migration.

Related issue

AC-009 "Single count source" (ROADMAP, Drive › Diğer); gkhngyk's review of #1389, item 3. No GitHub issue.

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. Open an action whose signals named more prompts after it was created. Its Affected tab lists the prompts the heading counts, no more.
  2. Pause one of its prompts: the heading says one fewer, and the row goes.
  3. A topic opportunity's prompts list without links, and the Volume column still reads for the others.

Not browser-checked locally: the dev DB has a kept list for only 2 actions (3 rows), so the drawer reads the signals there; prod has the lists (00244's backfill).

Tests (affected.test.ts):

  • the kept rows with the signals' details, a plain row for one no signal names, none the action never had;
  • an action that lost them all lists none;
  • text-kept prompts get no id; a text matches only a row without one;
  • one row for a prompt named by id and by text;
  • pages by address and removed ones left out; competitors by name;
  • the signals as before with no list, an empty one, or one of another kind.

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 6 warnings are in untouched files, as on main)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: web yarn test and yarn build.

🤖 Generated with Claude Code

cihan-gyk and others added 15 commits October 23, 2026 02:50
…nce, as its count

One action showed 13 prompts in its title, 12 in its detail and 13 in a
task: the title and tasks read the count saved at creation, the detail
and exports re-counted signals the nightly pass rewrites, and deleting
or pausing a prompt changed nothing. Migration 00244 keeps each action's
targets in action_entities when it is created (a trigger, so every way
an action is made keeps them alike), marks a prompt deleted or paused
and a competitor deleted as removed, and reads the counts per action
(action_entity_counts). Group signals now list every target's id beyond
the 50 they name, so an action counts and keeps the whole group, and
Site Audit's low pages count by their addresses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t each count counts

Review fixes on the action list (00244): a prompt kept by its text no
longer fails the uuid cast (which would have refused the action), the
insert trigger never refuses an action, and moves the target keys out of
the payload once kept. Each action sent by a person keeps the keys of
what its count counts (an opportunity's prompts, a topic opportunity's
suggestions, traffic pages by path); empty lists fall through. Nothing
is marked removed when a new action is made; only the backfill marks
prompts already gone. The counts RPC returns `total`; the limit is one
constant; priority still reads the first 50 prompts.

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

action_entity_counts also returns the removed targets' keys, so a list
of an action's prompts or pages can leave them out by id rather than by
name (two prompts can share a text, and only 20 names come back).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ce, everywhere

Every place now reads an action as action_entity_counts leaves it: the
count it was created with less the prompts deleted or paused and the
competitors deleted since. The list, the drawer, task titles, the
priority reason, History, the signal drawer's actions, the Affected list
and its story, Copy all, the exports, the list CSV and MCP agree, and
say "(1 prompt removed since this action was created)" with the names
on hover or focus. Removed items leave the Affected list by id; text
targets are listed; a count is never shown with nothing behind it; a
big group's target ids stay out of signal reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
action_entities.kept_at says when a list was written: as its action was
created, or by the backfill for one made before. The nightly count check
(AC-009 part 3) judges only lists kept at creation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes for AC-009 part 1:
- targetKeys gives the keys an action keeps as 00244 keeps them (trimmed,
  once, in order, at most 1,000, no empty key, object or list); every
  path that sets a counted list takes targetCount from it: targetPayload,
  an opportunity's prompts, a topic opportunity's suggestions (refused
  when none has words), g02, F01 (no longer the signal's raw count) and a
  topic gap's prompts.
- The backfill reads a topic opportunity's suggestions, not the tracked
  prompts it measures.
- The audit signal lists targetIds only past the 10 pages it shows.

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

A topic gap, mention review or content opportunity keeps its prompts by
id but lists them as texts, so a removed one stayed in the Affected list
while the count dropped: such a row is now matched by its text against
removedLabels (the first 20 the RPC names). A mention review no longer
lists its first prompt twice, and is no longer named after that prompt
once it is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as its count does

The Affected list is built from action_entities (what the action kept when
it was created and still has): each kept prompt or page with what the
signals say of it, one the signals no longer name as a plain row, and none
the action never had. The heading and the rows agree; an action made before
00244 keeps its count for the rest. Used by the drawer (and Copy/Markdown
from it) and the MCP export; without the list the rows come from the
signals as before.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk #1389's item 3, as promised: the drawer's Affected rows (and MCP get_action's export) are built from action_entities, so they always match the heading's count. Stacked on #1389. Prompts kept by text (topic opportunities…) get no id, so no broken links or volume reads; when the list can't be read or has none of the action's kind, the signals are used as before. The list CSV's item names and the History drawer still read the signals (counts already agree); say if you want them in this PR.

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

One fix before merge. Item 2 answers your question in the body.

  1. The Why's demand now leaves out prompts the Why names but the list doesn't.

    • The drawer reads demand for the Affected rows' ids (use-action-story.ts:59-62), and those rows are now the kept list.
    • The Why is still told from the signals (story.ts:235). It sums the demand of its own prompts from that map (story.ts:269-273) and silently skips a prompt with no entry.
    • So when the signals name prompts the action didn't keep, the "(12–18k AI searches a month, estimated)" range shrinks. When none of them is kept, it disappears.
    • Before this PR, demand was read for the signals' prompts, so the Why's range was whole.
    • On prod there are 178 open prompt actions whose signals name prompts by id:
      • 120 name some the action never kept (median 3, up to 40);
      • in 31, none of the prompts the signals name is still in the list.
    • The MCP export has the same gap (action-export.ts:296-300). The History drawer is fine because it passes no kept list.
    • Fix, in both places: read demand for the ids of affected.prompts plus those of affectedOf(evidence, payload) without kept.
    • Add a test where a signal's prompt outside the kept list still gets its demand in the Why.
  2. The list's Export CSV: yes, please take it in this PR.

    • getActionsAffected (action-center.ts:635) still lists the signals' prompts under the count of the kept list.
    • So the CSV's count and names disagree in the same actions where the drawer used to, e.g. "5" over 8 names.
    • Fix: read action_entities once per chunk with .in('action_id', chunk) and pass each action's rows to affectedOf.
    • Page that read as readSignals does, because a chunk can hold more rows than one response returns.
    • It's cheap. The brand with the most actions (50 actions, 700 kept rows) reads all of its rows in 6.4 ms as a member.
    • The History drawer can stay on the signals. It shows no rows, only the Why, and its demand is right.

Checked and fine

  • Rows and count agree.
    • On prod, 362 of the 363 live prompt, page and competitor actions with a kept list now list as many rows as their count.
    • The other one is the content opportunity that counts 20 and keeps 18 (two duplicate texts), as before.
    • The 24 actions with no list (15 page and 9 prompt actions) read the signals as before.
    • The 7 that lost all their prompts list none, under a count of 0.
  • Matching, on prod data:
    • Prompts: 1,514 of the 1,907 live kept prompts in actions with signals get the signals' details. The other 393 show as plain rows, because their signals have moved on.
    • Text-target actions: every kept label equals the payload's text. Topic gap and mention review rows match by label and gain their prompt's id, so they get a link and a volume.
    • Pages: 386 of 558 kept pages match a signal row by address. None match only by path (an absolute URL against a path), so no row is dropped over its format.
    • Labels: no live kept prompt or competitor has a null label, so no id shows as a name.
  • Fallbacks:
    • A database without 00244 (PGRST205 / 42P01) falls back to the signals quietly. Any other error is logged, then falls back.
    • An action with no rows of its kind also reads the signals, as in #1389.
  • Auth:
    • The drawer reads through the member's client, under the table's member policy. A member of another organization reads none of an action's rows.
    • The MCP export uses the admin client, but only after checking the action belongs to the key's organization.
  • Cost:
    • Each drawer open adds one query on the primary key.
    • As a member, on the brand with the most actions, its biggest list (50 rows) reads in 0.6 ms (6 ms with planning).
  • Merge and deploy:
    • One commit on top of #1389. It merges cleanly on main (76c87361).
    • Web only (7 files), no migration. 00244 is on prod, so it can deploy on merge.
  • CI and tests:
    • CI is green.
    • CI doesn't run the web tests. The PR reports them passing.

cihan-gyk and others added 2 commits October 23, 2026 23:14
… and the list's CSV the kept rows

The drawer and the MCP export read demand for the Affected rows' prompts
and for those the signals name (affectedOf without the kept list): the Why
is told from the signals, which can name prompts the action didn't keep,
so its range no longer shrinks or disappears for them.

The actions list's Export CSV reads action_entities once per chunk of
actions, page by page, and builds each action's names from its kept list,
as the drawer does: the count and the names agree. A database without
00244 falls back to the signals quietly; any other failure is logged and
falls back too.

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

Main squash-merged ansvisor#1389 (this branch's parent): this is main with this
branch's own two commits on top.
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed, and main merged (main with this branch's two commits on top; #1389 is squash-merged below it).

  1. The Why's demand. demandPromptIds(affected, signals, payload) gives the Affected rows' ids plus those of affectedOf(evidence, payload) without kept, each once. The drawer (use-action-story.ts) and the MCP export (action-export.ts) both read demand for those.
    • Tests in affected.test.ts, action-export.test.ts and action-drawer.test.tsx: a signal's prompt outside the kept list still gets its demand in the Why ("2 prompts (8.2–13.8k …)"). They fail on the old code.
    • The export test's mock had no .limit(), so it never read the kept list before; it does now.
  2. The list's Export CSV. readKeptEntityLists(client, actionIds) reads action_entities once per chunk with .in('action_id', chunk), paged 1,000 rows at a time as readSignals does.
    • It keeps the drawer's row order.
    • On a database without 00244 (PGRST205 / 42P01) it returns null quietly; any other error is logged.
    • getActionsAffected passes each action's rows to affectedOf. An action with no list, or a chunk that couldn't be read, falls back to the signals.
    • Tests: count and names agree, one read per chunk, paging across 1,001 rows, the quiet and the logged fallback.

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

All items done. Looks good.

  1. The Why's demand: done. demandPromptIds reads the Affected rows' prompts plus the ones the signals name, each once. The drawer (use-action-story.ts) and the MCP export (action-export.ts) both use it now.
    • The Why tells its prompts from affectedOf(mine, removedOnly(payload)). mine is a subset of the signals, and the removed keys are the same, so every prompt the Why sums is in the read.
    • Tests cover it in all three places.
  2. The list's Export CSV: done. readKeptEntityLists reads each chunk of 100 actions once, a page of 1,000 rows at a time.
    • Its sort ends on the primary key, so pages never overlap or skip rows.
    • An action with no list, or a chunk that fails to read, falls back to the signals. The fallback is quiet without 00244 and logged on any other error.
    • Tests check that the count and names agree, one read per chunk, paging past 1,001 rows, and both fallbacks.

Checked

  • Merge of main (04125b2): the PR's diff on main is identical to its own two commits on top of #1389, blob for blob, so resolving the conflicts with #1389's squash hid nothing.
  • Merge state: merges cleanly on main (8cde68c).
  • Deploy: web only, no migration. 00244 is on prod, so this can deploy on merge.
  • CI: green. CI doesn't run the web tests; the PR reports them passing.

@gkhngyk
gkhngyk merged commit 17f1924 into ansvisor:main Oct 23, 2026
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