Skip to content

fix(action-center): show an action's count, less what was removed since, everywhere (AC-009, 2/3) - #1389

Merged
gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/action-count-display
Oct 23, 2026
Merged

gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/action-count-display

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

AC-009, part 2 of 3: every place shows one count for an action, the count it was created with less what was removed since, and says "(1 prompt removed since this action was created)". Hover or focus names the removed items.

Stacked on #1388 (part 1: migration 00244, action_entities + action_entity_counts). This PR's own change is d41bd64. Merge after #1388. Part 3 adds the nightly drift check.

One source. lib/action-center/entity-counts.ts:

  • readEntityCounts(client, ids) calls the RPC in batches of 500. A database without 00244, or a failed read, leaves the actions as they were.

  • withEntityCounts(payload, rows) rewrites the payload as the action reads now:

    • targetCount (and a promptCount / pageCount that counted the same list) becomes the count left;
    • it adds createdTargetCount, removedCount, removedLabels (up to 20, for the hover) and removedKeys.

    Because every surface already reads the payload, they all follow.

  • currentTaskParams: a planned task that named the action's count ("across 13 prompts") names the count left. With none left it names no count, so it reads as its plain title.

  • currentPriorityReason: "Why this priority?" ("Lost ground on 13 prompts") names the count left too.

Where it's applied

  • Actions list and drawer: getActions, getActionDetail (task titles), via actionItemFromRow.
  • History: getActionHistory.
  • The signal drawer's "Used by" titles: getSignalActions.
  • The actions-list CSV: getActionsAffected.
  • MCP get_action: payload, task title_params, priority reason.
  • MCP export: title, tasks, story.

The Affected list agrees with the count (affectedOf):

  • What was removed since isn't listed. Prompts are matched by id (or text where a target has no id), pages by URL, competitors by name.
  • The prompt and page totals are the action's count, but only when there are rows behind it. A count is never shown with nothing to open.
  • Targets given as text (topic gaps and opportunities, mentions) are now listed when the action has no signals. Before, they were skipped.
  • The Why/Goal story leaves removed items out the same way.

UI

  • RemovedNote sits beside the count in the list row and the drawer header. It's a button with a tooltip, so focus shows the names as hover does; clicking it doesn't open the drawer. Copy: "(1 prompt removed since this action was created)".
  • Copy all, Markdown and CSV exports carry the same note as a tag.

Also

  • MCP get_action / list_signals and the drawer's signal reads drop a big group's targetIds (up to 1,000 ids), which no reader needs.
  • mention_review with every prompt removed reads its generic title, not "0 prompts".
  • Review fixes (2026-10-23): a text-only prompt row (topic gaps, mention reviews, content opportunities) is matched by its text against removedLabels too (the RPC names the first 20); a mention review lists its first prompt once; a review whose first prompt was removed reads titleMany; MCP list_actions gives the current count in priority.reason, as get_action does.

Known limits

  • Actions made before 00244 kept only the first 50 targets of a bigger group. Their count is the saved count less what was removed among those 50.
  • Rows still come from the action's signals, while the heading reads the action's count. On prod (gkhngyk's check of the 182 open prompt actions with signals, 2026-10-23):
    • 74 list more prompts than their count (median 3 more, at most 30), e.g. "5 prompts" over 8 rows;
    • 47 list fewer, so the heading counts prompts the tab can't show.
    • Before this PR the tab agreed with itself and not with the title; now it agrees with the title and not with its own rows in about two of every five open actions.
    • The fix is building the rows from action_entities (members can already read it). It is taken next, as its own PR right after this one, not left open.

Related issue

AC-009 "Single count source" (ROADMAP, Drive › Diğer). 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. With 00244 applied (fix(action-center): keep an action's prompts, pages and competitors once, as its count (AC-009, 1/3) #1388), take an action about 4 prompts and pause one of them. Then:
    • the list row and the drawer read "… across 3 prompts", with a "3 prompts" chip and "(1 prompt removed since this action was created)";
    • focusing or hovering the note names the paused prompt;
    • the Affected tab lists 3;
    • Copy Data and Export carry the same note.
  2. Resume the prompt: the note goes and the count is 4 again.
  3. Without 00244, everything reads as before.

I checked step 1 in the browser on the dev DB with a temporary action (deleted afterwards, and the prompt resumed), at 1024 px and phone width, in light and dark themes.

Tests:

  • entity-counts.test.ts: the count left, nothing below 0, task titles (including none left), priority reason, removed rows left out by id, text targets, no count without rows, reads in batches of 500, a missing RPC, withoutTargetIds;
  • action-table.test.tsx: the note, and that its click doesn't open the drawer;
  • actions-affected.test.ts: the list CSV count;
  • display.test.ts: mention_review with none left;
  • updated mocks in action-signals, action-export and action-priority.

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 4 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]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk AC-009 part 2/3 (web), stacked on #1388: one count everywhere, '(1 prompt removed since this action was created)' with the names on hover/focus. #1388 also gained removed_keys in action_entity_counts (44ec1e5) so the Affected list leaves removed prompts out by id. A follow-up idea in the body: build the Affected list from action_entities.

cihan-gyk and others added 2 commits October 23, 2026 09:30
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]>
cihan-gyk and others added 3 commits October 23, 2026 09:53
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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Merged #1388's review fixes forward (1f06172). bbfb70a adds action_entities and action_entity_counts to web/src/types/supabase.ts, as your merge note asked. On the 19 old actions with no list: withEntityCounts never reads total; it shows payload.targetCount less the rows removed, so they keep their saved count. Web: 2,908 tests, typecheck, lint, format and build pass.

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

A few fixes before merge. Both are in the new text-target branch of affectedOf, and both show on prod as soon as 00244 runs.

  1. A removed prompt stays in the Affected list when the action's targets are texts.

    • Topic gaps, mention reviews and content opportunities keep their prompts by id (promptIds), but their targets are texts. affectedFromPayload now lists those as rows with id: null.
    • affected.ts:100 matches row.id ?? row.text against removedKeys, so it compares a text with prompt ids and never matches. Nothing is left out.
    • The count still drops, so the heading and the CSV disagree with the rows.
    • On prod today, the open topic gap action has 9 prompts and 6 of them are paused. The backfill marks those 6 removed. It would then read "3 prompts (6 prompts removed since this action was created)" over all 9 rows, and the list CSV would say 3 with 9 names.
    • Fix: for a row without an id, also match its text against removedLabels. 00244 stores the prompt's text as the label for these (coalesce(n.label, pr.text)).
      • The RPC caps labels at 20. Either accept that, or return every removed label and keep the 20 slice for the hover only (00244 isn't on prod yet).
    • Add a test with text targets plus removedKeys/removedLabels.
  2. Mention reviews now list their first prompt twice.

    • affected.ts:298 adds the promptText row (no promptId in this payload, so id: null).
    • Then :311 adds every text in targets, and that list starts with the same prompt.
    • A review of 3 prompts shows 4 rows under "3 prompts". affected-tab.tsx:114 keys rows by row.id ?? row.text, so two rows get the same key.
    • Before this PR, text targets were skipped, so this is new. There are no mention reviews on prod yet, but every new send from Mentions hits it.
    • Fix: in affectedFromPayload, skip a target whose id ?? text is already listed.
  3. The known limit is common. Decide whether it ships as is.

    • affected.ts:103 sets the prompt total to the action's count whenever any row is listed. The rows still come from the signals.
    • I compared them on prod for the 182 open prompt actions that have signals. I took the prompt ids from their supporting signals, falling back to all linked signals, as the drawer does. This only approximates what the tab lists.
      • 74 list more prompts than their count (median 3 more, at most 30). The heading says "5 prompts" over 8 rows.
      • 47 list fewer, so the heading counts prompts the tab can't show.
    • Before this PR, the tab agreed with itself and disagreed with the title. Now it agrees with the title and disagrees with its own rows in about two of every five open actions.
    • Building the rows from action_entities (the follow-up you propose) fixes both. Members can already read that table under its policy.
    • If that waits, say so in the body with these numbers, so it's taken next and not left open.
  4. Low: a mention review left with 1 prompt can be named after the removed one.

    • display.ts:136 names promptText, which is the first prompt.
    • If that prompt is the one paused and one other is left, the title names the paused prompt.
    • Fix: use promptText only when promptIds[0] isn't in removedKeys. Otherwise use titleMany.
  5. Low, fine as a follow-up: MCP list_actions still gives the created count in priority.reason.

    • data.ts:2934 doesn't adjust it, while get_action does (currentPriorityReason).
    • One readEntityCounts call for the up-to-200 ids would make the two agree.

Checked and fine:

  • Every place that shows the count reads it the same way:

    • the list (getActions);
    • the drawer's header, chips, tasks and Affected tab;
    • History;
    • the signal drawer's "Used by";
    • the list CSV;
    • Copy Data, Markdown and CSV;
    • MCP get_action and the MCP export.

    Nothing else in the web or the server renders an action's count, and there are no emails or digests with one.

  • One batched call per page, never one per row:

    • getActions (at most 1,000 actions, so at most 2 calls of 500) runs it in parallel with its other reads;
    • the CSV export, History, the drawer and MCP make one call each.
  • Arithmetic:

    • The count left is the saved targetCount less what was removed, clamped at 0. total isn't read.
    • An action with no rows, like the 19 from the earlier review, keeps its saved count, as asked.
    • With none left, tasks fall back to their plain title, the priority reason drops its count, and generic titles read titleGeneric.
  • Without 00244: a missing function (PGRST202) or any read error leaves the payloads as stored, and the page still renders.

    • The web can deploy before 00244 is applied. Only items 1–3 change what it shows then, through the payload count.
  • web/src/types/supabase.ts matches 00244: the columns, nullability, insert defaults, FK name, RPC args and return columns.

  • RemovedNote: a button with a tooltip. It stops the row click and has a focus ring.

  • i18n: all copy is in en.json, the only locale.

  • Merges: 66b4c4ec, 96e386d0 and 1f06172f re-merge to identical trees, so they carry no hidden changes.

    • It contains #1388 and merges cleanly on current main (c4568814).
    • It adds no migration or server change of its own.

cihan-gyk and others added 3 commits October 23, 2026 14:45
…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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed, after merging main (only schema.sql conflicted; rebuilt, identical to main's):

  1. Text-named prompts (abb9622): a row with no id is also matched by its text against removedLabels (00244's coalesce(n.label, pr.text)), so a paused prompt of a topic gap, mention review or content opportunity leaves the list with the count. The RPC names the first 20; that limit is in a comment (00244 is on main now, so it stays). Test with text targets plus removedKeys/removedLabels.
  2. Mention reviews' first prompt once: affectedFromPayload skips a target whose id ?? text is already listed. Test.
  3. The known limit: stated in the body with your numbers (74 list more, 47 fewer of 182). Building the rows from action_entities is the next PR, stacked on this one, already in progress.
  4. (low) A mention review whose first prompt was removed reads titleMany. Test.
  5. (low) MCP list_actions gives the count left in priority.reason (329c51a): one readEntityCounts call for the listed ids, then currentPriorityReason, as get_action does. Test.

Web 2,919 tests + build, lint, typecheck, format pass.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026

@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. All five items from the last review are done or answered.

Earlier items

  1. A removed text-named prompt stayed listed: done.
    • affected.ts:106 now also matches a row without an id by its text against removedLabels.
    • On prod the labels line up. All 9 kept labels of the open topic gap (6 removed) equal its payload texts exactly. It now lists 3 rows under "3 prompts".
    • The 20-label cap doesn't matter today. That topic gap is the only text-target action with removed prompts.
    • Tests are in affected.test.ts and entity-counts.test.ts.
  2. A mention review listed its first prompt twice: done.
    • affected.ts:319 and :330 skip a target whose id ?? text is already listed.
    • There's a test.
  3. The known limit: answered.
    • The body states it with the numbers.
    • #1409 builds the rows from action_entities.
  4. Low: a mention review named after a removed prompt: done.
    • display.ts:136 reads titleMany once promptIds[0] is in removedKeys.
    • The test covers both the first prompt and another one removed.
  5. Low: MCP list_actions priority reason: done.
    • data.ts:2922 makes one readEntityCounts call for the listed ids. There are at most 200, so it's one call.
    • :2943 applies the same currentPriorityReason as get_action.
    • There's a test.

Checked

  • Merge dc17bcc9 (main into the branch):
    • Re-merging its parents conflicts only in schema.sql.
    • The commit's schema.sql is main's at f7c42fe0.
    • It carries no hidden changes.
  • Merge state:
    • It merges cleanly on current main (76c87361).
    • On top of main it changes only web files (25 files). It adds no migration and no server change.
    • The #1388 commits it still carries are on main as the squash, so they drop out of the diff.
  • Auth and cost, as a member, on the brand with the most actions (50):
    • action_entity_counts for all 50 ids takes 7.8 ms.
    • A member of another organization reads none of that brand's action_entities rows.
  • Deploy:
    • Web only, so it deploys on merge.
    • 00244 is on prod, so there's no ordering issue.
  • CI and tests:
    • CI is green: format, lint and typecheck.
    • CI doesn't run the web tests. The PR reports 2,919 passing.

@gkhngyk
gkhngyk merged commit 2baaddb into ansvisor:main Oct 23, 2026
5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…t-steps-server

Main squash-merged ansvisor#1389 and ansvisor#1393–ansvisor#1399; its tree is ansvisor#1399's last head
(b84e724), so this is that merge: this branch's changes on top of it.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…-entities

Main squash-merged ansvisor#1389 (this branch's parent): this is main with this
branch's own two commits on top.
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