Skip to content

feat(action-center): number each brand's actions from AC-1 - #2422

Merged
gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-brand-numbers
Nov 16, 2026
Merged

gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:feature/action-brand-numbers

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Merged with main again (16 Nov, evening): the updated #2420 is merged in, and with it main at d6ed27377 (#2446, #2442, #2447, #2441, #2377). The only conflict was the generated approved-articles.json, which was regenerated. "Watch the work" in help/chat/chat.md keeps both sides' text (148 words). Typecheck is clean, and 328 test files (4,715 tests) pass. The branch merges cleanly on main.

Summary

The owner asked for each brand's actions to be numbered from 1. Today an action's code is its global actions.action_no, a single counter shared by every workspace. A brand with 53 actions shows codes like "AC-648" next to "AC-251". Those codes look unrelated to the brand's own list, and they hint at how many actions other customers have.

From now on, each brand numbers its actions from 1 and shows them padded to two digits: AC-01, AC-02 … AC-53. An action keeps its number for life. Numbers are never reused, so a brand's list keeps gaps where actions were done, dismissed or removed. That is by design.

Signals get the same per-brand numbers in the same migration and backfill. Their display (S-01 …) is in the stacked branch feature/signal-brand-numbers.

This branch merges #2418 (fix/action-center-date-sort, actionCode / matchesActionCode) and fix/chat-reads-all-actions (actionRef), and extends their helpers. Merge it after both.

Merged with main (16 Nov)

main is merged in, through the updated #2420. The conflicts were in from-chat.js (its JSDoc), coverage.js, schema.sql (regenerated), library.json and Help (regenerated).

One addition is in its own commit, c02324304, so it's easy to review or revert. Ads' Earn card (merged since) creates actions through from-chat.js, but it passed on only the global number. Its button would read "Open AC-1300" while the Action Center shows the brand's code.

  • server/src/lib/ads/earn.js now passes brandNo back when Earn:
    • sends a fix;
    • sends the same fix again;
    • finds an action that already covers the prompt;
    • reads the covering action for the drawer.
  • AdsActionRef in web/src/lib/ads/api.ts gains an optional brandNo.
  • _earn-card.tsx uses actionCodeNo. The button reads "Open AC-03" once the brand is numbered, and the old code until then.
  • Tests were added in earn.test.js and _opportunity-drawer.test.tsx.

After the merge, these checks pass:

Release applies missing migrations in number order (scripts/release/migrations.mjs), so 00534 applies even though 00540 is already on production.

What customers will see

  • Codes change once. Each action shows its brand's own code (AC-07) instead of the old one. This happens per brand, when the backfill reaches it. Until then the brand keeps its old codes. A brand never shows a mix of old and new codes.
  • Old links still open the right action. A link made before (/dashboard/action-center/actions/AC-648 in Slack, email, History or a note) still means the old number, within the person's own workspace.
  • Old messages and exports still show the old codes. Text that was already written is not rewritten.
  • The old code stays findable. The action's drawer shows "Previously AC-648" in small, muted text beside the new code. The Actions list search matches both: "AC-648" finds the action by its old code, and "AC-07" or "7" finds it by its new one. When the two match different actions, the list shows both.
  • A code in a Chat answer never guesses. "AC-07" in an answer opens the one action that has that code or that old number. If both match different actions, it opens the list filtered to that code, showing both.

Changes

  • Migration 00534_actions_brand_number.sql. Schema and functions only. It applies in seconds and numbers nothing that already exists.
    • Adds brand_no integer to actions and signals.
    • Adds brand_number_counters (brand_id, kind, last_no), one row per brand and kind (action or signal). It is server-only: RLS is on, there are no member grants, and the counters are removed when their brand is deleted.
    • Adds a before insert trigger, set_brand_no. It gives each new row the next number, taken under the counter row's lock, so two inserts can't get the same number. A failed insert gives its number back. An upsert over an existing row (the demo rebuild) keeps that row's number.
      • A brand with no rows yet starts at 1.
      • A brand whose old rows aren't numbered yet leaves new rows unnumbered too; the backfill numbers them with the rest.
      • Every action has a brand (brand_id is not null), so there's no organization-level case.
    • Adds backfill_brand_numbers(kind, brand), which numbers one brand's unnumbered rows per call.
      • Order: actions by created_at, then action_no; signals by created_at, then id (a signal's detected_at moves when it reopens).
      • Numbering starts after the brand's highest number, and the counter is then set to the maximum.
      • It takes a per-brand lock that the trigger waits on, so a row inserted during the backfill is either numbered by it or gets the next number after it.
    • Adds brand_numbers_backfill_brands(kind), the list of brands the script walks.
    • The unique indexes on (brand_id, brand_no) are built after the backfill (see the runbook). The migration builds them only on a table that is still empty, such as a new install.
  • Backfill script. server/src/scripts/backfill-brand-numbers.js and server/src/lib/brand-numbers-backfill.js, modelled on fix(db): split 00536 into a quick migration and a chunked backfill #2352's fast-rollups backfill.
    • Processes one brand and one kind per call, with a pause between calls.
    • Options: --dry-run, --kind action|signal, --brand, --from-brand, --pause-ms.
    • Idempotent and resumable: on a failure it prints the --kind and --from-brand to resume with.
  • One formatter.
    • Web: actionCode / actionCodeNo in web/src/lib/action-center/action-ref.ts. They return "AC-03", or the old "AC-648" while brand_no is null, and actionRef stays the single "AC-" prefixer. previousActionCode supplies the "Previously" code.
    • Server: actionCode in server/src/lib/action-center/action-code.js.
    • Used by:
      • Action Center: the list (from fix(action-center): one date sort, most recent first by default, a clickable Updated column, AC numbers on rows, and no tab or menu counts #2418), drawer, exports, History table, drawer and search, the Needs review page, Run agent, Start now, and a signal's linked actions.
      • Chat: tool results (a code beside action_no and brand_no), the sent and added cards, Undo and Activity lines, the agent run's scope and prompt, Inbox suggestions, and Chat's own list of actions.
      • MCP: list_actions, get_action, list_action_history, task reviews, and a signal's linked actions now include a code. action_no is kept, so the change is additive.
      • Reports (impact report and its CSV), Content (the opportunity basket, "From a task in", the Content page's scope chip, and the editor's action chips through the draft reads), Prompts (Improving and Sent), Products (sent and recheck results), the send toasts on Site Audit, AI Traffic, Mentions and Insights, and Ads' Earn card. For these, the server's send endpoints now return brandNo once the brand is numbered.
  • Links.
    • The old one-action path actions/AC-n keeps its old meaning: global action_no, read with the person's own access.
    • A code written in Chat's text links to the new actions/code/AC-n route. It opens the single action of the workspace with that brand number or old number; otherwise it opens the list searched for the code. It never picks between two.
    • The Business Hub card now links by id. Other links the app builds already point by id (?action=).
  • Slack, Pulse and email. These builders print no action codes; they link by id. Nothing to change.
  • Help:
    • Action Center actions: a new "Action codes" section.
    • Chat: answer links.
    • Help is regenerated.
  • Demo coverage: brand_number_counters is listed as skipped, since the trigger fills it as the demo's rows are written.

Migration and backfill

Runbook for Gökhan, in this order:

  1. Apply 00534 before this code reaches production. The new code reads brand_no.

    • Use Release, supabase db push or the SQL Editor.
    • It applies in seconds: two nullable columns, one small table, functions and triggers.
    • On production it skips the indexes, because the tables have rows.
    • It's safe to apply twice.
  2. Deploy. Every existing brand keeps showing its old codes. A brand created from now on is numbered from AC-01 straight away.

  3. Run the backfill, dry run first. From server/:

    node src/scripts/backfill-brand-numbers.js --dry-run
    node src/scripts/backfill-brand-numbers.js
    
    • It numbers actions first, then signals, one brand per call, 100 ms apart.
    • It's safe to stop and run again: it skips brands that are already numbered.
    • On a failure it prints Resume with: --kind … --from-brand ….
    • To redo a single brand: --kind action --brand <id>. This changes nothing if the brand is already numbered.
  4. Check that nothing was missed. All four counts should be 0.

    select count(*) from public.actions where brand_no is null;
    select count(*) from public.signals where brand_no is null;
    select count(*) from (select 1 from public.actions where brand_no is not null group by brand_id, brand_no having count(*) > 1) d;
    select count(*) from (select 1 from public.signals where brand_no is not null group by brand_id, brand_no having count(*) > 1) d;
  5. Build the unique indexes without blocking writes, by hand, one statement at a time:

    create unique index concurrently if not exists actions_brand_no_key
      on public.actions (brand_id, brand_no) where brand_no is not null;
    create unique index concurrently if not exists signals_brand_no_key
      on public.signals (brand_id, brand_no) where brand_no is not null;

    A concurrent build that fails leaves an invalid index with that name, and if not exists would keep it. If that happens, drop the index and build it again.

How to test

  1. Apply 00534 to a local database that already has actions.
    • The Actions list, drawer and Chat show the old codes.
    • Create an action on a brand with no actions yet: it gets AC-01.
  2. Run node src/scripts/backfill-brand-numbers.js --dry-run, then run it without --dry-run.
    • Each brand's actions read AC-01, AC-02 … in creation order.
    • The drawer shows "Previously AC-…".
    • Run it again: it reports 0 calls.
  3. Search the list for the new code ("AC-03", "3") and for the old one ("AC-648"). Both find the action.
  4. Open /dashboard/action-center/actions/AC-<old number>: it opens that old action.
  5. In Chat, ask about your actions.
    • Each action is named with its new code, and the code opens it.
    • Where a new code equals another action's old number, the code opens the list showing both.
  6. Send something to the Action Center from Site Audit, AI Traffic, Mentions, Insights or Ads' Earn card. The toast or button names the new code.
  7. MCP: list_actions and get_action return code.

Checks

  • Scratch Postgres 16 (stub tables):
    • 00534 applied twice; the first apply took 0.05 s.
    • The trigger numbers each brand from 1.
    • Concurrency: 8 sessions × 100 inserts on each of 3 brands (one numbered, one new, one backfilled while the inserts ran). Result: 2,404 rows, no duplicates, no gaps, no nulls.
    • The backfill numbers by creation order. A second run numbered 0 rows.
    • An upsert keeps its number, and a failed insert gives its number back.
    • The indexes build concurrently after the backfill and are used by the lookup. A fresh database builds them inside the migration.
  • Server vitest: 176 files, 2,420 tests passed. This covers Action Center, the action routes, Slack, Pulse, Chat suggestions, Chat emails, brand-access*, demo coverage, health and the backfill.
  • Web:
    • tsc --noEmit is clean.
    • vitest passed 747 files and 9,020 tests. This covers Action Center lib, components and pages, src/lib/chat, Chat components, MCP, src/lib/actions, Content, Reports, Prompts, signals, Products, AI Traffic, Site Audit, Help and use-server-exports.
  • ESLint: no errors on the changed files. One warning in audit/[id]/page.tsx was already there.
  • Prettier: applied.
  • Help: regenerated with yarn vitest run -u src/lib/help.
  • Lockfiles: no lockfile changes and no new dependencies.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

…numbers

Brings in actionCode and matchesActionCode (action-ref.ts), which this
branch extends with each brand's own numbers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
… actions by title

The owner asked Chat "what are the most important actions?" on a brand
with 53 actions. Chat read 10 (its row default for the Action Center
read), judged only those, and named actions by bare numbers ("AC-251,
249, 250") that the Actions list doesn't show.

- list_action_center_tasks reads a page from a new Chat read,
  listActionsPageFor: every open action (New, In progress, On hold) is
  counted and ranked on the server by Priority Score, 50 to a page with
  the total, next_offset and a "Showing N of M" note; offset pages on.
  Rows are compact: ref, title (as the Actions list words it), category,
  status, score and level, stale_since, due, assignee, tasks, updated.
  Still scoped to the caller's organization and brand access.
- The page is never probed for one more row (it counts itself) and gets
  a 20,000-character result share, so all 50 rows reach the model.
- The writer's rules and the tool's description require a title with
  the linked number ("**Title** (AC-12)"), never a number alone, a run of
  bare numbers or a range, and saying "the top 50 of 53" when a read
  didn't cover them all. The 30-day plan skill names actions the same way.
- Every action code Chat shows or links comes from actionRef (the
  action-ref helper), examples included, so a change of numbering only
  changes its input.
- The agents' eval flags an answer with a bare "AC-251" (must check).
- Help: "Ask about your actions" in Use Chat.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…umbers

Brings in actionRef and Chat's own list of actions, which this branch
names by each brand's code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
The owner asked for each brand's actions to be numbered from 1 instead of
the global action_no, which hinted at other customers' volume and read as
unrelated to the brand's list ("AC-648" beside "AC-251"). Signals get their
own brand numbers too (schema and backfill here; their codes come next).

- 00534: actions.brand_no and signals.brand_no, a server-only counter per
  brand and kind (brand_number_counters), and a before-insert trigger that
  gives the next number under the counter's row lock. Schema and functions
  only; nothing existing is numbered in the migration. The unique indexes
  are built after the backfill (only on an empty table in the migration).
- backfill_brand_numbers numbers one brand's rows per call by creation
  order, idempotent and resumable, run by src/scripts/backfill-brand-numbers.js
  (--dry-run, --kind, --brand, --from-brand). Until a brand is numbered its
  new rows wait too, so a brand never mixes old and new codes.
- One formatter: actionCode / actionCodeNo (web action-ref.ts, server
  action-code.js): "AC-03", padded to two digits, falling back to the old
  "AC-648" while brand_no is null. Used by the Action Center (list, drawer,
  exports, History, review, run agent), Chat (tool results, cards, Undo,
  agent run scope and prompt, Inbox suggestions, its list of actions), the
  MCP tools (a `code` beside action_no), Reports, Content, Products,
  Prompts and the send toasts.
- Old links keep their meaning: actions/AC-n still opens the old global
  number, in the person's workspace. A code in Chat's text links to
  actions/code/AC-n, which opens the one action with that code or old
  number and otherwise the list searched for it, never a guess. Other new
  links point by id.
- The drawer shows "Previously AC-648" beside the new code, and the list
  search matches the old number as well as the new code.
- Help: Action Center actions (Action codes) and Chat.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 14, 2026
gkhngyk
gkhngyk previously approved these changes Nov 15, 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.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 15, 2026 07:29

The merge-base changed after approval.

Conflicts:
- help/chat/chat.md: main's keywords (Settings in the chat menu) plus this
  branch's (most important actions, top actions, action title); main's new
  text and this branch's "Ask about your actions" section both kept.
- action-ref.test.ts: both sets of tests (actionRef from this branch;
  actionCode, searchedActionNo and matchesActionCode from main's ansvisor#2418).
  actionCode now builds its code with actionRef, so one formatter remains.
- web/src/lib/chat/skills/library.json: regenerated from skills/*/SKILL.md
  (yarn vitest run -u src/lib/chat/skills).
- approved-articles.json: regenerated (yarn vitest run -u src/lib/help).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…umbers

Brings the updated ansvisor#2420, which carries upstream main.

Conflicts:
- action-ref.ts and action-ref.test.ts: this branch's versions (actionCode
  from the brand's number via actionCodeNo, with every test from both
  branches and ansvisor#2418).
- server/src/lib/action-center/from-chat.js: main's Ads source (`source`
  param, verifiedPlace without a conversation for Ads) and this branch's
  `brandNo` in the answer and actionCode in the duplicate message.
- from-chat.test.js: main's Ads test now expects the answer's brandNo
  for the same key again (this branch's answer shape).
- server/src/lib/demo/coverage.js: both SKIPPED entries,
  brand_number_counters (00534) and mentions_terms_packed_ready (00540).
- supabase/schema.sql: regenerated (bash supabase/build-schema.sh); 00534
  sits before 00535-00540 by file order.
- library.json and approved-articles.json: regenerated, unchanged from
  the automatic merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Earn (from main) sends through from-chat.js and answered only the old
global number, so its card read "Open AC-1300" while the Action Center
shows the brand's code. It now also answers brandNo (sent, the same key
again, the duplicate, and the covering action the drawer reads), and the
card shows actionCodeNo: "Open AC-03", or the old number until the brand
is numbered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 16, 2026
…-numbers

Brings the updated ansvisor#2422 (with ansvisor#2420 and upstream main). No conflicts;
schema.sql, library.json and approved-articles.json regenerated and
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 16, 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.

LGTM.

Brings in ansvisor#2446 (no row counts), ansvisor#2442, ansvisor#2447, ansvisor#2441 and ansvisor#2377.

Conflicts:
- approved-articles.json: regenerated (yarn vitest run -u src/lib/help).

help/chat/chat.md merged cleanly: main's "Watch the work" text (no row
counts) and this branch's action-title line are both kept (132 words);
updated stays 2026-11-16, last_checked 2026-11-15.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Takes the updated ansvisor#2420, which now includes upstream main (ansvisor#2446 no row
counts, ansvisor#2442, ansvisor#2447, ansvisor#2441, ansvisor#2377).

Conflicts:
- approved-articles.json: regenerated (yarn vitest run -u src/lib/help).

help/chat/chat.md merged cleanly: updated 2026-11-16, last_checked
2026-11-15.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 16, 2026
Takes the updated ansvisor#2422, which now includes ansvisor#2420 and upstream main
(ansvisor#2446 no row counts, ansvisor#2442, ansvisor#2447, ansvisor#2441, ansvisor#2377). No conflicts;
approved-articles.json checked with yarn vitest run -u src/lib/help
(no change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 16, 2026
Takes the updated ansvisor#2423, which now includes ansvisor#2422, ansvisor#2420 and upstream
main (ansvisor#2446 no row counts, ansvisor#2442, ansvisor#2447, ansvisor#2441, ansvisor#2377).

Conflicts:
- help/chat/chat.md: front matter only; took the later last_checked
  (2026-11-16). Both sides' text is kept: main's "Watch the work" (no
  row counts, 148 words) and this branch's look-up-by-code paragraph in
  "Ask about your actions" (146 words).
- approved-articles.json: regenerated (yarn vitest run -u src/lib/help).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 16, 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.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 16, 2026 16:36

The merge-base changed after approval.

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

LGTM.

@gkhngyk
gkhngyk merged commit e52cf28 into ansvisor:main Nov 16, 2026
12 checks passed
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.

3 participants