Repository navigation
feat(chat): approve all of a draft's pending changes at once - #2377
Conversation
When several agents each leave a run waiting on the same Content draft, the Inbox's Needs you now shows one card for the draft with an Approve all button. Each run is approved through prepareResume and goes on in the background; a change that can't be approved is listed and the others still go on. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
left a comment
There was a problem hiding this comment.
Approve all resumes every run in the group at once, but update_draft sends the whole page and updateContentDraft has no version check, so the runs (all built from the same starting page) overwrite each other and only one change lands, though the card says N were approved. Please run a group's runs one after another (or allow Approve all only when one card rewrites the page). Also, the runs go on via after() in the inbox page's action with no maxDuration (the single approve route sets 300), so a run cut off mid-step stays 'running'.
…one; runs get 300 s An approved run makes the change its card stored (resumePending runs the call's own input, bound to the card's digest); it never goes back to the model. update_draft's input is the whole page, written from the page its run read, so two such changes overwrite each other even one after another. - A draft's group is approved together only when at most one change rewrites the page (update_draft, optimize_draft; set_draft_ready and suggest_draft_changes leave it). Otherwise the card says "Approve these one by one", offers no Approve all and links each change to its chat; the server refuses such a group too (one_by_one). - Drivers start inside the action, as streamRun starts them, and the action waits for each card's change (driveRun's new onCard). The result counts the changes made; one approved but not made is listed, not counted. - The Inbox page sets maxDuration = 300 (RUN_REQUEST_MS), as the approve route does; the 'use server' file exports async functions only. A run its request leaves unfinished times out through sweepChatRuns, as on the single path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
left a comment
There was a problem hiding this comment.
CI is red: chat-home, chat-all-chats, chat-menu and page-pane tests fail to load with 'supabaseUrl is required' from src/lib/supabase/admin.ts, so a chat component now imports a module that pulls in the admin client at load. Please keep the admin client out of the components' import graph (server-only module behind the action).
The Inbox's draft groups import the Approve all actions, and the action file loaded the admin client, the engine and the pending approvals at load. Every test that loads chat-inbox.tsx (Chat Home, All chats, the chat menu, the page pane through the shell) then failed to load with "supabaseUrl is required". The work moves to lib/chat/approve-all.ts, a plain server-only module with the service role. The 'use server' file keeps only the subscription guard and the result types at load, and imports the module when an action is called, as chat-agent-calls.ts and chat-uploads.ts do. It still exports async functions only. Approve all behaves as before: the plan is checked first, a group with more than one page rewrite is refused, each card's change is made before the answer, and the Inbox page's 300 s maxDuration is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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
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
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
Brings in ansvisor#2446 (no row counts), ansvisor#2442, ansvisor#2447, ansvisor#2441 and ansvisor#2377. Conflicts: - help/chat/chat.md: front matter only; took the later last_checked (2026-11-16), updated stays 2026-11-16. Both sides' sections are kept: main's "Watch the work" (no row counts) and this branch's "Open and close Settings in the chat menu" (98 words). approved-articles.json merged cleanly and is current (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
Summary
Several agents can each propose changes to the same content draft. Each one leaves its own waiting run with its own approval, so people approved the same page again and again. Chat's Inbox now groups the waiting changes by draft. A group shows "N changes from M agents" with one Approve all button, when they can be approved together. Approving one change at a time still works as before.
Review fixes (CI, 16 Nov)
supabaseUrl is required.chat-inbox.tsx→inbox-draft-groups.tsx→lib/actions/chat-approve-all.tsloaded the admin client (directly, and throughlib/chat/engine.tsandlib/chat/pending-approvals.ts) at load time.web/src/lib/chat/approve-all.ts, a plain server-only module (not'use server'). The'use server'file (lib/actions/chat-approve-all.ts) keeps only the subscription guard and the result types. It loads that module when an action is called, aschat-agent-calls.tsandchat-uploads.tsalready do.approveGroupstill awaitsassertWritable({ brandId })first.inbox-draft-groups.tsxis unchanged.chat-inbox.tsx,inbox-draft-groups.tsxand the action file finds no path toadmin.ts.one_by_one);maxDuration.mainis merged in (clean).Review fixes (13 Nov)
update_draftsends the whole page, and a resumed run doesn't re-read the draft:resumePendingreplays the stored input, andchangeDraftreplaces the whole page. So two page rewrites of the same draft overwrite each other, even one after the other. A new engine test shows this.set_draft_readyandsuggest_draft_changescount as leaving the page alone.update_draft,optimize_draftand any future draft write count as rewrites.one_by_one), before approving anything.driveRungets anonCard(made)callback). A change that was approved but not made is listed, not counted.export const maxDuration = 300, the same as the single approve route. This is onpage.tsx, not the'use server'file. A run cut off by that limit is ended as timed out by the existingsweepChatRuns.Changes
web/src/lib/chat/pending-approvals.ts(new). Reads the person's waiting runs for a brand and groups them by the content draft they would change.askwrite cards oncontent_draftstools are included. Go-live tools (publish, CMS send, webhook) and cost cards are left out on purpose, so Approve all can never publish.togetherOfholds the at-most-one-rewrite rule.togetherand each item'schatId.chat_agent_runs, thenchat_agents. A plain chat shows as "Chat".web/src/lib/actions/chat-approve-all.ts(new'use server'file, async exports only), with the work inweb/src/lib/chat/approve-all.ts(plain server-only module, loaded inside the actions).listDraftApprovalGroups(brandId).approveGroup(brandId, key, version). It reads the group again on the server and matches it only by the server's own key.one_by_onegroups.versionis a fingerprint of the cards' digests. If any card changed since the list was shown, the call is refused withchanged.{ made, failed }.prepareResume, and its driver starts inside the action and stays alive throughafter().read_onlyback instead of an error.web/src/lib/chat/engine.ts:driveRuntakes an optionalonCard(made)callback.chat/inbox/page.tsx):export const maxDuration = 300.web/src/components/chat/inbox-draft-groups.tsx(new), plus small hooks inchat-inbox.tsxandchat-inbox-page.tsx. Shows the groups, their items, Approve all or the one-by-one note, and the result ("N changes made to …", with any that weren't made listed).web/messages/en.json. One paragraph is inhelp/chat/agents.md(137 words), and Help is regenerated.Tenant scoping
user_idandorganization_id, andprogress.brandIdmust equal the brand.organization_id; chats are also read withuser_id.brand_id. A draft outside the brand reads as not found, and its runs are dropped.SUPABASE_SERVICE_ROLE_KEY, falling back toCRON_SECRET. If neither is set, it throws.Migration
None.
How to test
update_draft) and one Mark ready. Open Chat's Inbox. One group shows "2 changes from 2 agents" with Approve all.Checks
engine.test.ts, on lines this PR doesn't change.src/components/chat,src/lib/chat,chat-approve-all.test.ts(14 tests), the Inbox page test,use-server-exports,subscription-guard-coverage,src/lib/helpandsrc/i18n: 256 files, 3,619 tests pass, 1 skipped.maxDurationis set on the Inbox page;chat-thread-view.tsx,page-pane.tsx,page-open.ts, editor-folder or lockfile changes.Generated by Claude Code