Repository navigation
feat(action-center): add Run agent to actions, starting a Chat run scoped to the action (W2-17) - #1895
Conversation
…(W2-16) The agent run driver hands a started agent run to Chat: a chat of its own (origin agent, agent_run_id) for the person it acts as (the clicker for Run now, the agent's owner now for a trigger, an Admin or a Manager still), after the checks before a run read again for them; a triggered agent pauses for the reason (owner_role, plan, brand_gone, cap). Nothing starts in a read-only workspace or with Chat off. The engine drives it headless; each step, the help answer's too, is held as the agent's within the run's cap: max_share of the plan's included monthly budget, worked out on the server (run_cap past it), the run's spend counting every part (own key, included budget, credits: a step's credit parts keep its agent run). The server keeps the run's usage_share on the same base, and the Agents list's shares now use it too. The agent run follows its Chat run: Needs you on a card, paused_cap at a limit (the month's pauses the agent), Stopped at its limit for a triggered run at its own cap or a run held at a limit for 7 days, No answer in 7 days, done or failed. Three failures in a row pause the agent; a run that shipped gets a Pending outcome. Triggers: the server's minute cron calls the web's internal tick (CHAT_INTERNAL_SECRET, constant-time compare) to fire due schedules in their time zone (no catch-up, claimed once) and to sweep (Chat's own sweep, lost and stale runs, failures, the AI limit's auto-resume, and the start of queued runs: never chained in a finished run's request). The signal pass tells the web which new signals feed which definitions, so Signal triggers fire; 15-minute coalescing, a 6-hour cooldown and the plan's daily event runs (UTC day) apply. Reads page past PostgREST's 1000 rows; each job, trigger and brand fails on its own. KPI and watch-rule triggers don't fire yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The driver now checks the agent's own monthly cap (max_month_share) before a run starts, not only when a trigger fires: a Run now on an agent paused at its cap stops before it starts, and a triggered run at the cap pauses the agent (cap). The cap comparison allows for floating point (0.18 + 0.02 is just under 0.2), here and in the sweep's resume.
…oped to the action (W2-17)
CHAT-21 §F and CHAT-09 item 21b (governance mockup #g-run-agent), on top of
the agent run driver (W2-16): Admins and Managers get Run agent on an open
action's row and at the top of its drawer, while the new Chat is on.
Analysts and Agency partners don't see it. No migration: 00419 already has
trigger 'action', action_id and stop_reason action_closed.
- Picker (run-agent-button.tsx; the picker's code loads when it opens):
the agents the person may run whose scope covers the action's brand,
last used on this kind of action first (GET /api/chat/agents/compatible),
Run with Chat (no agent) and "Create an agent for this kind of action"
(a skill that fits the category). A pick opens the run's chat in the side
panel (panel.openChat), or Chat's page where the panel isn't; a run that
waits for a slot says so; a refusal shows the out-of-permission card; a
read-only workspace gets the upgrade dialog.
- POST /api/chat/agents/{id}/run { actionId }: one run on the action's
brand, trigger 'action', the action as it was (number, title, category,
open tasks) in evidence_json, acting as the person who clicked; one run
per person, agent and action a minute (edge case 14); answers the run's
chat once it started.
- Driver: the run's chat is "{agent} · {action}", with an Action chip, the
action as an @ reference and its open tasks in the message. It doesn't
start on an action closed since the click, and stops when the action
closes while it runs (stop_reason action_closed, edge case 7).
- History (action_events, source chat, as the acting person): "Agent run
started · {agent}", "Agent run completed/failed/stopped · {agent}", and
"Chat started on this action" for Run with Chat.
- POST /api/chat/actions/{id}/chat: Run with Chat, the person's own run on
the action in their default mode, driven past the answer.
- Help: Action Center actions and Chat › Agents articles updated.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Run agent at 1024px (W2-17) With Run agent in the drawer's header, Copy Data, Export and "Action ID: AC-423" dropped to a second line in the 1024px drawer. - Run agent in the drawer is the size of Copy Data and Export beside it (h-7, text-xs, a 12px icon), still the primary button. - The top row is a container (@container, group/top): while it is narrower than 36rem and holds Run agent, "Action ID:" goes sr-only and the row shows "AC-423" alone; the full "Action ID: AC-423" stays as the title and for screen readers. Without Run agent, or in a wider drawer, the label shows as before. - Tests: the drawer keeps the full label (title and text), and Run agent in the drawer carries data-run-agent at the row's button height. Checked at 1024px in light and dark: one row, all three buttons 28px high. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne run per click, the closed-action stop (W2-17)
Pre-push review of W2-17.
- An action's title and tasks may come from outside: the run's message
names the action by number and category only; its title and open tasks
go in the scope, which the models read inside <untrusted_data>
(progress.scopeUntrusted), and the run starts tainted, every change a
card. startChatRun takes the server's own options for it (Run with
Chat); a browser's body can't set them.
- A second Run agent click on the same action within 60 seconds is the
first run, waiting or under way, whatever minute the clicks fall in.
With 3 runs waiting on other work, a click joins only a waiting run on
the same action, else it is refused: 409 queue_full ("3 runs already
wait for this agent on this brand").
- "Ready for review" leaves the run's words and the Help article until
set_task_ready_for_review lands (W2-10).
- A run that ended before it started says why ("The action was closed, so
the run didn't start."), and its action's History says "Agent run
stopped · action closed".
- A run not handed to Chat yet is left to its driver within the grace.
- When the action closes, the run's chat says "This action was closed.
Nothing more was changed." (stopChatRun's why, kept on the Chat run for
a driver in another request).
- Run with Chat: a second click by the same person within 60 seconds, or
two at once, open the same chat and start one run. It doesn't stop when
the action closes: it is the person's own chat (commented).
- aria-label starts with the visible words: "Run agent · {title}"; the
picker's ↑ ↓ and Esc are tested; a picker that finds the workspace
read-only opens the upgrade dialog; a deleted agent's History line ends
without an empty separator.
- The drawer's short ID no longer uses a container query that matched at
every width: beside Run agent the number alone, always.
- Tests: Agency partners refused, a brand not shared, settleAgentRun with
a finished Chat run, no chat yet and a failed stop, two Run with Chat
posts at once.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, approving as is (reviewed the commits after #1874's head: d03e97f, 1b21680, b07f2fa and the merge c46c55f).
What I checked:
- Who can run it: the button shows only for Admins and Managers, only on open actions, and only with Chat on. All three routes check the role again on the server. Analysts and Agency partners get the out-of-permission answer. With the flag off, every route answers 404 before reading a session.
- Scope: the action is read with the service role, then checked against the person's workspace and brand access (another workspace's action, a brand not shared with the person, a deleted action or a missing one all answer 404). Demo-brand actions get 402 and closed actions get 409. The agent has to be one the person may run (
agentForAct/runnableAgents), and its scope has to cover the action's brand. - Read-only, plan and limits:
writeRefusalruns first on both POST routes, and the picker opens the upgrade dialog. The agent path goes throughrunChecks(including the monthly cap from #1874), and Run with Chat goes throughstartChatRun's limits.subscription-guard-coverage,demo-gate-routesandplan-rowall pass. - Double clicks: a minute key plus a check for the same person's run on the same action in the last 60 seconds. A click past the 3 waiting runs joins only a run on the same action, or gets a 409 (
queue_full). It is never folded into another action's run. - Closed action: a run on an action that closed before it started ends
action_closed. While it runs, the minute sweep stops its Chat run with that reason. The reason is stored onchat_runs.error, which passes the column's check, so a driver in another request finishes with the same words. The run then writes "Agent run completed" to the action's History once. - Untrusted text: the action's title and tasks stay out of the message. They go into the scope, which is wrapped as
untrusted_datawhenscopeUntrustedis set, and both run types start tainted, so every change is a card. The publishing switch still applies, because the run acts as the person who clicked and goes through the same engine checks. - Database:
trigger_kind = 'action',stop_reason = 'action_closed'and the newaction_eventsevent names all pass the live constraints, so no migration is needed. The new reads have matching indexes. There are no new PostgREST embeds. - Client bundle: the client files import only types from the server modules.
Tests: vitest on src/lib/chat, src/components/chat, src/components/action-center, src/lib/action-center, src/app/api/chat, guards, subscription-guard-coverage, demo-gate-routes and help: 1828/1829 pass. The one failure is the known chat-menu clock case. tsc --noEmit, eslint and prettier on the touched files are clean.
Nits, none blocking:
- In
help/action-center/action-center-actions.md, "If the action is completed or dismissed, the run stops" reads as if it covers Run with Chat too, but only an agent's run stops. Run with Chat stays the person's own chat, asaction-chat.tssays. actionCenter.actionsPage.runAgent.toast.openRunisn't used anywhere.- Two clicks at the same moment that fall on either side of a minute boundary can still queue two runs, because each gets a different key and neither sees the other's row yet. This is rare and is the same gap Run now has.
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
#1986) actionCenter.actionsPage.runAgent.toast.openRun has no reader: the run opens beside the action, so no toast offers to open it (a follow-up from the #1895 review). Agent Center's own chatAgents.actions.openRun stays. The rest of that follow-up is already on main: the Help article says only an agent's run stops when the action closes, and the picker and the agent driver link to /dashboard/agents. Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Chat W2-17: Run agent on an Action Center action. It starts a Chat run scoped to that action, with one of the person's agents or with Chat itself (CHAT-21 §F, CHAT-09 item 21b, governance mockup
#g-run-agent). Stacked on #1874 (W2-16); review only the commits after its head. Everything stays behindCHAT_AGENTIC/CHAT_AGENTIC_ORGS. No migration: 00419 already has triggeraction,action_idand stop reasonaction_closed.Who sees it: Admins and Managers, on an open action's row and at the top of its drawer, while the new Chat is on. Analysts and Agency partners don't see it. The server refuses them too.
The picker (
run-agent-button.tsx, loaded when it opens):GET /api/chat/agents/compatible).Starting the run:
POST /api/chat/agents/{id}/run { actionId }.action, acting as the person who clicked.evidence_json: number, title, category and open tasks.AC-{no} ({category})).<untrusted_data>(progress.scopeUntrusted).startChatRuntakes these as the server's own options; a browser's body can't set them.queue_full.stop_reason action_closed). Its chat says "This action was closed. Nothing more was changed."stopChatRunkeeps the reason on the Chat run, so a driver in another request ends it with the same words.Drawer at 1024px:
Help:
help/action-center/action-center-actions.md(approved: false).Related issue
None. Chat Wave 2 (W2-17).
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
CHAT_AGENTIC=truein web and server (and the W2-16 setup from feat(chat): run agents from schedules and signals, within their caps (W2-16) #1874). Sign in as an Admin.agent-action,action-chat,agent-runs,agent-driver,engine.test;run-agent-button,action-drawer;chat/actions/[id]/chatandchat/agentsroutes.Checked in the browser at 1024px, light and dark: the drawer, the picker, History and the row's icon. The user approved the screens. Screenshots are available on request.
Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)On this branch (with #1874's head 540cbe0 merged in):
format:checkandtypecheckpass, and lint has 0 errors. 764 files / 7,725 tests: 7,724 pass. The one failure ischat-menu.test.tsx"Done · 08:02", a date-dependent case that fails on main today too and is fixed by fix(chat): give a chat row the menu's clock, so a run's time matches its day #1876.yarn buildpasses.format:checkand lint are clean, and 334 files / 4,603 tests pass (3 skipped).Follow-ups, not in this PR:
set_task_ready_for_reviewlands (W2-10)./dashboard/agents/new. The old address will redirect.🤖 Generated with Claude Code