Repository navigation
feat(action-center): check every night that each action's count and its list agree (AC-009, 3/3) - #1390
Merged
Conversation
…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]>
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]>
…ts list agree AC-009 part 3. action_count_drift (00245) counts the open actions whose saved count and kept list disagree: an action made since lists are kept that kept none, a list kept at creation of a different size from its count (a list cut at the 1000-key cap aside), and a task naming a different count from its action's; with the newest few action numbers. The daily health e-mail raises any that isn't 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
5 of 12 tasks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
previously approved these changes
Oct 23, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. There's one optional follow-up and a note on apply order.
Checked and fine
- Security.
action_count_driftissecurity definerwithsearch_pathpinned.- It is revoked from
public,anonandauthenticated, and granted toservice_roleonly. - It is
stableand writes nothing, and it returns only counts and action numbers. - The server change only adds a section to the health e-mail, which goes to
HEALTH_REPORT_RECIPIENTS. Nothing user-visible is written.
- Cost on prod. I simulated 00244's backfill and ran a
pg_tempcopy of the function over it, in a rolled-back transaction.- It took 24 ms, and 23 ms on a second run.
- It checks 685 open actions.
- Every per-action read uses the primary key of
action_entitiesoraction_tasks_action_idx.
- Day one reads all zeros: checked 685, missing 0, mismatch 0, tasks 0.
- I also ran it with the
kept_at/sinceguards off, so every list is judged. That gives missing 19 (the 15 oldfix_low_scoresand 4convert_mentionsfrom #1388), mismatch 1 (the content opportunity with two duplicate prompt texts) and tasks 0. - So the guards hold back exactly the backfill's known leftovers.
- No task on prod names a count other than its action's.
- I also ran it with the
- Report. Each kind raises its own issue line, with up to 5 action numbers, newest first. A failed RPC becomes a "could not be checked" line rather than failing the e-mail. Tests cover each of these.
- Merges.
Low, optional follow-up
report.js:370prints "685 open actions checked", but on day one none of those lists is actually judged. Mismatch and tasks judge only lists kept at creation, and missing judges only actions made since 00244, so the line overstates what was checked until the old actions close.- Fix: return a
judgedcount from00245_action_count_drift.sql:84, the open actions whose list was kept at creation. - Then print it beside
checked, e.g. "685 open actions, 12 with a list kept at creation".
- Fix: return a
Apply order
- Apply 00245 after 00244. Its SQL body names
action_entities.kept_at, so it fails to create without it. - Apply 00245 before deploying this server. Otherwise the morning e-mail reads "Action counts could not be checked" until it is applied.
- Apply 00244 together with #1388's server, or after it (see #1388). Otherwise
fix_low_scoresactions made in between by the current server keep no list, and this check reports them as missing every night.
gkhngyk
approved these changes
Oct 23, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Re-approving after merging main into the branch. The merge only brings in the squashed parent PR; the tree matches the one tested (web and server tests, typecheck, lint, format).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AC-009, part 3 of 3: the daily health e-mail checks that every open action's count agrees with the list it kept, and names a few that don't. It should always read 0.
Migration 00245:
action_count_drift(p_examples). Service role only. It looks at open actions (not deleted, not completed or dismissed) that are about something (targetCount > 0, atargetEntity):Each comes back with its count and up to 5 action numbers, the newest first, so a new regression shows before long-open actions. Payload values that aren't numbers are skipped, never cast.
mismatchandtasksjudge only lists kept as their action was created (kept_atwithin a minute ofcreated_at). Part 1's backfill wrote older actions' lists from what their payload still named, and some older counts never matched it, so they'd make the e-mail permanently red.Server.
health/report.jsgains an "Action counts" section:On the dev DB (00244 + 00245 applied):
checked 2, missing 0, mismatch 0, tasks 0;Related issue
AC-009 "Single count source" (ROADMAP, Drive › Diğer): "A nightly check finds actions whose stored text and list disagree, and alerts the team (should be 0)". No GitHub issue.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
select action_count_drift();. Every count is 0 on a fresh database.targetCountis 5 while its payload names 2 targets, and a task whosetitle_params.countdiffers from its action's. The function names both. Roll back.POST /api/internal/health-report). The e-mail has an "Action counts" section.Tests:
health/report.test.jscovers the issue lines, the e-mail block, all zero, the RPC's arguments, and a check that couldn't run.Known edge: text keys are trimmed and deduplicated in SQL. A payload counting
["q", "q "]as 2 keeps 1, and the check rightly reports the mismatch.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): web not touchedyarn typecheckpasses (run fromweb/): web not touchedyarn format:checkpasses (run fromweb/): web not touchedAlso run:
npm run format,npm run lintandnpm test(2,056 tests);bash supabase/build-schema.sh.🤖 Generated with Claude Code