Repository navigation
feat(action-center): hold tasks an agent writes without the page, the change, Done when or the check for review (AC-010, part 2) - #1562
Conversation
…d how we check it, and have the task writer fill them (AC-010) Co-Authored-By: Claude Opus 5.5 <[email protected]>
… change, Done when or the check for an admin's or a manager's review (AC-010) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Needs changes: one fix to 00293 before it's applied, on its grants, its policies and the approve function's first read. The rest are follow-ups.
What I checked:
-
Own change. The PR's second commit, fb096bf, on top of #1561's head (83f7588). That's 26 files: the migration, the task writer, the route, the review script, the Needs review tab and page, and the docs.
-
Merge.
- I made a temp base: #1561 squashed onto main (3b650fb), with parents 83f7588 and main. This branch merges onto it clean, and the result differs from that base by exactly this PR's own change.
- With #1557 (00291), only
schema.sqlconflicts, and a rebuild fixes it. - With #1564 there's one conflict in
web/messages/en.json, where both add a block beforetaskChecks. With #1565 there's also one indisplay.test.ts. Whichever lands second keeps both sides.
-
Migration 00293.
- No other PR uses 00293. Nothing on main or in an open PR uses 00292, so the gap in the numbering is fine.
- RLS is on.
- Select and delete are limited to admins and managers of the brand's organization. They use the same
profiles.role in ('admin', 'manager')check as 00229, 00233 and 00256, and the server'sdeleteAction. - There is no insert or update policy, so only the service role writes.
- The policies look up actions through their own RLS, so a deleted action's rows are hidden too.
on delete cascadefollows the action, and through it the brand.- The
(action_id)index covers the writer's delete and the join that both web reads use. - The checks on
missingandtitlematch what the writer stores. The writer's schema caps titles at 200, and a blank title is refused before it could be held.
-
The function.
- It's
security definerwithsearch_path = public, and every name it uses is qualified. - It checks the role against the action's organization and refuses a deleted or closed action, using the same
CLOSEDset as the writer. - It needs all four fields, with the same check values as
TASK_CHECKS. - Execute is revoked from
publicandanonand granted toauthenticated. - A second approve finds no row and returns null, and the row lock stops two approves from both adding the task.
- It can't race a Regenerate: the writer deletes the reviews before it reads the tasks, so an approve either commits first or finds nothing.
- It's
-
Roles.
- An analyst or an agency partner doesn't get the tab, reads no rows, can't approve (
not allowed) and deletes nothing. A member of another organization is in the same position. - The web actions rely on RLS and the function, as the Content tables' admin and manager actions do. They don't check the role in the app.
- An analyst or an agency partner doesn't get the tab, reads no rows, can't approve (
-
What a held task does. It lives in its own table, so it never shows up for anyone else:
- the task lists and their counts, progress, exports and MCP
get_action; - the runner, which works only from task templates;
- Content's task completion;
- Send to webhook, which loads a task by its
action_tasksid.
History's
tasks_generatedline carries only the number waiting. - the task lists and their counts, progress, exports and MCP
-
Approve.
- The task goes in as
todo,human/read, after the action's last task, withsource: 'reviewed'. keepsTaskthen keeps it on a Regenerate, andisTouchedtreats the plan as worked on.- The review row goes,
task_addedis logged with the reviewer as actor, and the action'supdated_atmoves. - The web merges the edit over what the writer stored, so the evidence refs stay.
- The task goes in as
-
Dismiss deletes the row through RLS, and nothing reaches the action.
-
Edit happens only inside Approve. A refused approve leaves the form open with the text.
-
The writer.
- Only the last round's refusals are held, and only when every problem is one of the four gaps.
- Held and accepted tasks together stay within six. A held task that repeats a kept one is dropped.
- A writing that keeps or holds anything first replaces the action's earlier AI reviews, before the tasks change.
- With only held tasks, the template tasks stay.
tasks_generated_atis set, so the night doesn't try again, and the action isn't bumped. - There are no extra model calls and the budget doesn't change.
- For a task that passes,
detailsOfstores whatreplaceTasksstored before.
-
The nightly engine. Library plans (
generate.jsand thefrom-*paths) insert their tasks directly and never reach the hold. Only AI-written tasks are held, at night (trigger: 'auto') as on Regenerate. -
review-action-tasks.jsisn't a backfill.- It's a dry run (
dryRun: true): no claim, no writes and no budget charge. The model calls are real. - It reads the latest open actions (20 by default, or
--limit/--brand) and writes a local Markdown file. That file now also lists the held titles, and the URL, change and check of each kept task.
- It's a dry run (
-
Web.
- The tab's count and the page read with the member's session, filtered to the brand and to open, undeleted actions.
- The count is read only for admins and managers, and kept per brand.
requireSpecasks for the same fields as the function, plus the title.- The four error codes map to their messages.
-
Tests. These fail without the change:
- the writer's two new cases;
taskGaps/onlyGapsandpageAddressreturning null;- the route's
reviews; action-task-reviews.test.ts, the tab and page tests, the two Regenerate toasts, the History line andaction-task-writer.test.ts.
The
keepsTaskcase forreviewedalready passes on #1561's head. It documents the behaviour. -
Generated files.
- The
schema.sqlchange is exactly the build script's block for 00293, appended after 00290, and CI's schema check passed. supabase.tsmatches the table and the function.
- The
-
Speed. This PR adds no pattern that runs on user text.
PAGE_ADDRESScomes from #1561 and runs on the model's URL, which is capped at 500 characters. -
Before the API deploy (00293 applied, web merged, API older):
- Admins and managers see a new Needs review tab, empty and without a count. Nobody else sees a change.
- The old API returns no
reviews, so the Regenerate toast and the History line read as today. - Nothing reads or writes the table until the new API is live. The table and the function are new and change nothing that already exists, so nothing breaks.
Before merge:
- Grants, re-runs and the approve function's first read (
supabase/migrations/00293_action_task_reviews.sql:38-62,:87-104). 00293 goes to prod before the merge, so this is the cheapest time to fix it.- Set the table's grants as the other new tables do (00265, 00283, 00286). Today it keeps the schema's default grants for every role.
alter table public.action_task_reviews enable row level security; revoke all on table public.action_task_reviews from anon, authenticated; grant select, delete on table public.action_task_reviews to authenticated; grant all on table public.action_task_reviews to service_role;
- Drop each policy before creating it. Today a second run stops at
create policy, though the table and index areif not exists:drop policy if exists "action_task_reviews: manager select" on public.action_task_reviews; create policy "action_task_reviews: manager select" ... drop policy if exists "action_task_reviews: manager delete" on public.action_task_reviews; create policy "action_task_reviews: manager delete" ...
- In
approve_action_task_review, check the role before the row is read and locked. Read the row only through the caller's organization, so a row outside it reads as not there:The org check that follows then becomes redundant, and the web's mapping stays as it is.if not exists ( select 1 from public.profiles p where p.id = auth.uid() and p.role in ('admin', 'manager') ) then raise exception 'not allowed' using errcode = '42501'; end if; select r.* into v_review from public.action_task_reviews r join public.actions a on a.id = r.action_id join public.brands b on b.id = a.brand_id join public.profiles p on p.organization_id = b.organization_id where r.id = p_review_id and p.id = auth.uid() for update of r; if not found then return null; end if;
- End with
notify pgrst, 'reload schema';, as 00283 and 00286 do, then rebuildschema.sql. - Smaller: nothing writes
updated_at. Drop it, or leave it for the edit-in-place you may add later.
- Set the table's grants as the other new tables do (00265, 00283, 00286). Today it keeps the schema's default grants for every role.
Follow-ups:
- Show the tab only where the writer runs (
web/src/components/action-center/action-center-tabs.tsx:65). Today only the writer fills the table. WhereACTION_TASKS_AIis off, every admin and manager gets a tab that never fills, plus a count read on each Action Center page. UsecanManage && taskWriterEnabled()(fromregenerate-tasks.tsx), and widen it when agents' tasks go through review too. - Hold the URL to a page address on approve (
task-detail.tsx:352-354,00293:116).- The writer refuses anything but
https://…,/…or a host and path. Approve takes any text, so "the pricing page" passes, and the task leaves review without the exact page AC-010 asks for. - Fix: test the URL in
requireSpecagainst the writer'sPAGE_ADDRESS(shared, or copied totask-details.ts), with a short hint under the field. Check it in the function too:or btrim(p_details->>'url') !~* '^(https?://\S+|/\S*|([a-z0-9-]+\.)+[a-z]{2,}([/?#]\S*)?)$'
- The writer refuses anything but
- Dismiss leaves no line in History, while Approve does (
web/src/lib/actions/action-task-reviews.ts:126-136). After a dismiss, History still says "2 wait for review", with no trace of who dropped what. Log an event with the title after the delete, e.g.task_review_dismissed. Members can already insert events, so no migration is needed. Add its message todrawer.events. - Smaller: when the list fails to load, the page shows "Nothing waits for review" under the error toast (
review/page.tsx:63-66). Show theloadFailedtext in place of the list instead.
Dry run on prod (00293 applied in a rolled-back transaction, with two reviews seeded on a test action): an analyst of the same organization, an admin of another one and anon see no rows and can't insert, update, delete or approve; the organization's admin sees both, an incomplete or unknown check is refused (incomplete task), the approve adds the task with source: reviewed, removes the review and logs task_added, and a second approve returns null. I'll run it again on the fixed file before applying it.
…ew-queue # Conflicts: # supabase/schema.sql
…prove check the role before it reads the row, through the caller's organization (ansvisor#1562 review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Fixed in d89fc88, after merging main in (1330ada; only 1. 00293
Checked on the dev DB, with the fixed file applied twice, in a rolled-back transaction with a seeded review:
Grants after the run: Also run on the merged head: web Follow-ups 2–5, and those on #1561 and #1564, go in follow-up PRs from main once the series is merged:
|
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
What I checked:
- The fix (d89fc88), against the before-merge item:
- Grants:
revoke all … from anon, authenticated, thenselect, deletetoauthenticatedandalltoservice_role, as 00265, 00283 and 00286 do. - Re-runs:
drop policy if existsbefore each policy. - The approve function: the role is checked first, before any row is read or locked, and the row is read only through the caller's organization (
for update of r), so another organization's row reads as not there and returns null. The closed-action and field checks are unchanged. notify pgrstends the file, andschema.sqlis rebuilt.
- Grants:
- The main merge (1330ada) differs from a re-merge of its parents only in
schema.sql, which conflicted and was rebuilt. - Dry run on prod of the fixed file, in a rolled-back transaction with two reviews seeded on a test action:
- an analyst of the same organization: no rows,
not allowedon approve, and insert, update and truncate refused; - an admin of another organization: no rows, approve returns null and the row stays;
- anon: every read and write refused, and no execute on the function;
- the organization's admin: both rows; an incomplete task or an unknown check refused; the approve adds the task as
todowithsource: reviewed, removes the review and logstask_added; a second approve returns null.
- an analyst of the same organization: no rows,
- Applied on prod just before this merge: RLS on, select and delete policies only,
authenticatedholds select and delete,anonholds nothing. - Merge: #1561 is squashed; this goes in through a temp base on #1561's head. The combined tree with #1563 and #1564 passes server and web tests, tsc, lint, Prettier and the schema build.
Follow-ups 2–5 from the first review stay open for the follow-up PR, as you said.
Summary
AC-010 ("Done when" on every task), part 2 of 4: the review queue.
Stacked on #1561. This branch includes its commit. Review the second commit, or merge #1561 first.
AC-010: a task an agent writes without the exact page, the change, Done when or how we check it doesn't reach the people doing the work. It waits for review. As decided for the rollout, admins and managers review it on a Needs review tab, and the nightly engine's library tasks are left as they are (part 3 fills their fields from templates).
Migration 00293 (needs the
needs-migrationlabel):action_task_reviews: one row per task waiting.title,details) and what it misses (missing:url,change,doneWhen,check).action_tasks(lists, counts, exports, MCP, the runner, Content's task completion) see none of these until one is approved.approve_action_task_review(review, title, details), security definer:modehuman,permissionread). Itssourcebecomesreviewed: the reviewer's task now, so Regenerate tasks keeps it, as it keeps a task someone added;task_addedin the trail and bumps the action'supdated_at.It returns null when the row is already gone.
The task writer (
task-writer/, behindACTION_TASKS_AI).onlyGaps,taskGaps) goes toaction_task_reviews, up to six tasks in all with the accepted ones.review-action-tasks.jsprints each task's URL, change and check, and the tasks waiting for review.Web.
getTaskReviewsandgetTaskReviewCount(none of a deleted or closed action),approveTaskReview(merges the edit into what the writer stored, so its evidence refs stay) anddismissTaskReview./dashboard/action-center/review), for admins and managers, with an amber count. The count updates when a task is approved or dismissed on the page itself.TaskDetailFormgetssubmitLabelandrequireSpec(the four fields arearia-required).web/src/types/supabase.tsentries for the table and the RPC.Tested on the dev database, with 00293 in a rolled-back transaction:
missingvalue is refused;incomplete task, and on a completed actionaction closed;sourcereviewed, deletes the review and logstask_added;not allowed) and can't delete.Agents (MCP).
create_improve_actiontakes no URL, change or check today, so its tasks stay as they are. @gkhngyk, should agent-created tasks get these inputs and go through review too? That would be a follow-up.Related issue
AC-010 (roadmap), part 2 of 4. Stacked on #1561.
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
cd server && npx vitest run src/lib/action-center/task-writer src/routes/action-center-tasks.test.jscd web && yarn vitest run src/lib/actions/action-task-reviews.test.ts 'src/app/[locale]/(dashboard)/dashboard/action-center/review' src/components/action-centerChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run: server
npm run format,npm run lint,npm test(225 files, 2,898 tests); webyarn test(430 files, 4,104 tests) andyarn build, all pass.Checked in the browser (light and dark, 1440 and 1024 px) with 00293 applied on dev and two test rows:
reviewed, and the count went to 1;I then removed the test task, its trail entry and the rows.
supabase/schema.sqlrebuilt withbuild-schema.sh. 00292 is kept for the Perception search PR (on #1542).🤖 Generated with Claude Code