Skip to content

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

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/ac-010-review-queue
Oct 27, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/ac-010-review-queue

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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-migration label):

  • action_task_reviews: one row per task waiting.

    • It holds the task as written (title, details) and what it misses (missing: url, change, doneWhen, check).
    • It's a separate table, so the readers of action_tasks (lists, counts, exports, MCP, the runner, Content's task completion) see none of these until one is approved.
    • RLS: admins and managers of the brand's organization select and delete. Edits go into the task when it's approved. There's no client insert; the server writes them with the service role.
  • approve_action_task_review(review, title, details), security definer:

    • checks the caller is an admin or a manager, that the action is neither deleted nor closed, and that the four fields are filled;
    • adds the task after the action's last one (mode human, permission read). Its source becomes reviewed: the reviewer's task now, so Regenerate tasks keeps it, as it keeps a task someone added;
    • deletes the review row;
    • logs task_added in the trail and bumps the action's updated_at.

    It returns null when the row is already gone.

The task writer (task-writer/, behind ACTION_TASKS_AI).

  • After its one retry, a task the last round refused only for these gaps (onlyGaps, taskGaps) goes to action_task_reviews, up to six tasks in all with the accepted ones.
  • A new writing replaces the action's earlier AI reviews. The reviews are written before the tasks, so a failure there leaves the tasks as they were.
  • If no task passed but some wait, the action keeps its template tasks.
  • Regenerate tasks says how many wait: "… wait in Needs review" for an admin or a manager, "… wait for an admin or a manager to review" for anyone else. The History line says it too.
  • review-action-tasks.js prints each task's URL, change and check, and the tasks waiting for review.

Web.

  • Server actions: getTaskReviews and getTaskReviewCount (none of a deleted or closed action), approveTaskReview (merges the edit into what the writer stored, so its evidence refs stay) and dismissTaskReview.
  • Needs review tab (/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.
    • Each task shows its action (Open AC-n), what it misses, and its details.
    • Edit opens the task form; Approve works only once URL, Change (after), Done when and How we check are filled.
    • Dismiss asks first.
  • TaskDetailForm gets submitLabel and requireSpec (the four fields are aria-required).
  • The web/src/types/supabase.ts entries for the table and the RPC.
  • Docs: the Action Center guide.

Tested on the dev database, with 00293 in a rolled-back transaction:

  • a bad missing value is refused;
  • approving with a field missing raises incomplete task, and on a completed action action closed;
  • approving puts the task third on the demo action, source reviewed, deletes the review and logs task_added;
  • a second approve returns null;
  • a member who isn't an admin or a manager sees no rows, can't approve (not allowed) and can't delete.

Agents (MCP). create_improve_action takes 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 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. Apply 00293. As the service role, insert a row:
    insert into public.action_task_reviews (action_id, title, details, missing)
    values ('<an action id>', 'Add a pricing FAQ to /pricing', '{"doneWhen": "FAQ present", "check": "auto"}', '{url,change}');
  2. As an admin or a manager, Action Center shows Needs review 1. The task lists Missing: URL, Change.
  3. Click Edit. Approve stays off until URL and Change (after) are filled. Approve: the task is last on its action, and History says it was added.
  4. As an analyst, the tab isn't there.
  5. cd server && npx vitest run src/lib/action-center/task-writer src/routes/action-center-tasks.test.js
  6. cd web && yarn vitest run src/lib/actions/action-task-reviews.test.ts 'src/app/[locale]/(dashboard)/dashboard/action-center/review' src/components/action-center

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: server npm run format, npm run lint, npm test (225 files, 2,898 tests); web yarn test (430 files, 4,104 tests) and yarn build, all pass.

Checked in the browser (light and dark, 1440 and 1024 px) with 00293 applied on dev and two test rows:

  • the tab read Needs review 2;
  • Approve stayed off until URL and Change were filled; once approved, the task went onto AC-3 as reviewed, and the count went to 1;
  • Dismiss asked first, then left the empty state.

I then removed the test task, its trail entry and the rows. supabase/schema.sql rebuilt with build-schema.sh. 00292 is kept for the Perception search PR (on #1542).

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 26, 2026 21:37
…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]>
@mintlify

mintlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 0944ec6.

Approve preview

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

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.sql conflicts, and a rebuild fixes it.
    • With #1564 there's one conflict in web/messages/en.json, where both add a block before taskChecks. With #1565 there's also one in display.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's deleteAction.
    • 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 cascade follows 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 missing and title match 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 definer with search_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 CLOSED set as the writer.
    • It needs all four fields, with the same check values as TASK_CHECKS.
    • Execute is revoked from public and anon and granted to authenticated.
    • 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.
  • 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.
  • 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_tasks id.

    History's tasks_generated line carries only the number waiting.

  • Approve.

    • The task goes in as todo, human/read, after the action's last task, with source: 'reviewed'.
    • keepsTask then keeps it on a Regenerate, and isTouched treats the plan as worked on.
    • The review row goes, task_added is logged with the reviewer as actor, and the action's updated_at moves.
    • The web merges the edit over what the writer stored, so the evidence refs stay.
  • 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_at is 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, detailsOf stores what replaceTasks stored before.
  • The nightly engine. Library plans (generate.js and the from-* 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.js isn'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.
  • 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.
    • requireSpec asks 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/onlyGaps and pageAddress returning null;
    • the route's reviews;
    • action-task-reviews.test.ts, the tab and page tests, the two Regenerate toasts, the History line and action-task-writer.test.ts.

    The keepsTask case for reviewed already passes on #1561's head. It documents the behaviour.

  • Generated files.

    • The schema.sql change is exactly the build script's block for 00293, appended after 00290, and CI's schema check passed.
    • supabase.ts matches the table and the function.
  • Speed. This PR adds no pattern that runs on user text. PAGE_ADDRESS comes 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:

  1. 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 are if 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:
      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;
      The org check that follows then becomes redundant, and the web's mapping stays as it is.
    • End with notify pgrst, 'reload schema';, as 00283 and 00286 do, then rebuild schema.sql.
    • Smaller: nothing writes updated_at. Drop it, or leave it for the edit-in-place you may add later.

Follow-ups:

  1. 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. Where ACTION_TASKS_AI is off, every admin and manager gets a tab that never fills, plus a count read on each Action Center page. Use canManage && taskWriterEnabled() (from regenerate-tasks.tsx), and widen it when agents' tasks go through review too.
  2. 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 requireSpec against the writer's PAGE_ADDRESS (shared, or copied to task-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*)?)$'
  3. 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 to drawer.events.
  4. Smaller: when the list fails to load, the page shows "Nothing waits for review" under the error toast (review/page.tsx:63-66). Show the loadFailed text 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.

cihan-gyk and others added 2 commits October 27, 2026 09:48
…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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks. Fixed in d89fc88, after merging main in (1330ada; only schema.sql conflicted, rebuilt).

1. 00293

  • Grants, as 00265, 00283 and 00286 set them: revoke all … from anon, authenticated, then select, delete to authenticated and all to service_role.
  • Re-runs: drop policy if exists before each policy. The file now runs twice in a row on the dev DB.
  • approve_action_task_review:
    • It checks the role first, before any row is read or locked.
    • Then it reads the row only through the caller's organization (join actions → brands → profiles … for update of r), so another organization's row reads as not there and returns null.
    • The org check that followed is gone. The closed-action and field checks are unchanged.
  • notify pgrst, 'reload schema'; ends the file. schema.sql is rebuilt.
  • updated_at: left in, for an edit in place later.

Checked on the dev DB, with the fixed file applied twice, in a rolled-back transaction with a seeded review:

Caller Result
Analyst of the same organization not allowed (42501), reads no rows
Admin of another organization null, reads no rows
The organization's admin, a field missing incomplete task (22023)
The organization's admin, all four fields Task added as todo with source: reviewed, review gone, task_added logged
Second approve null
anon permission denied for function

Grants after the run: anon has none, authenticated has select and delete, and service_role has all. Nothing stayed after the rollback.

Also run on the merged head: web yarn typecheck, yarn lint (0 errors) and yarn test (4,121 tests); server npm run lint and npm test (2,916 tests).

Follow-ups 2–5, and those on #1561 and #1564, go in follow-up PRs from main once the series is merged:

  • the tab only where the writer runs;
  • the URL held to a page address on approve, in requireSpec and the function;
  • a History line on dismiss;
  • the load-failed text in place of the empty list.

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

What I checked:

  • The fix (d89fc88), against the before-merge item:
    • Grants: revoke all … from anon, authenticated, then select, delete to authenticated and all to service_role, as 00265, 00283 and 00286 do.
    • Re-runs: drop policy if exists before 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 pgrst ends the file, and schema.sql is rebuilt.
  • 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 allowed on 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 todo with source: reviewed, removes the review and logs task_added; a second approve returns null.
  • Applied on prod just before this merge: RLS on, select and delete policies only, authenticated holds select and delete, anon holds 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.

@gkhngyk
gkhngyk merged commit f913673 into ansvisor:main Oct 27, 2026
5 of 6 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.

2 participants