Adds the write actions of the `manage_automations` chat tool: `create`,
`update`, `enable`, and `run_now`. They call the same management methods
as the API (`CreateAutomation`, `UpdateAutomation`, `RunAutomation`)
with the chat owner as the actor, so owner-only checks stay in the
service.
Part of CODAGT-1212 (slice 12b of 3). Part of CODAGT-1135.
## Rules
- **Target containment.** An `existing_chat` automation must target the
calling chat: `create` defaults `target_chat_id` to it (a heartbeat) and
refuses any other chat, even another root chat of the same owner. A
`new_chat` automation may not give new chats more tools than the calling
chat has. Until tool sets land, the only tools that differ between such
a chat and the calling chat are the model config's provider tools, so
`new_chat_model_config_id` defaults to the calling chat's config and any
other config is accepted only when it has no provider tools. Force On
MCP servers apply to both chats because the tool is offered only in
root, non-explore chats. `update` and `enable` check containment on the
stored automation and on the result; `run_now` checks the stored
automation.
- **Automation-reached turns.** `create`, `update`, `enable`, and
`run_now` are refused before any other work.
- **Secrets.** The tool never returns a webhook secret, single-use or
multi-use: tool results stay in the chat, where read-shared users, the
model provider and compaction can see them. `create` of a webhook
returns a note that the owner rotates the secret in the automations UI
to get one.
- **Audit.** `create`, `update`, and `enable` write the automation audit
entry with `chat_id`. `run_now` records what the run endpoint records:
nothing for `existing_chat` (a run changes no configuration), and for
`new_chat` the same chat-create entry with `automation_id` and
`input_id`, plus `created_by_chat_id`.
- **Locked-row recheck.** The tool's containment check runs again inside
the service on the locked automation row (`UpdateAutomation` before the
write, `RunAutomation` at admission), so a concurrent owner edit between
the tool's read and the write cannot slip past it.
- **Known limitation.** Containment holds for tool-initiated operations.
Later scheduled and webhook runs use the current model configuration, so
a later admin change that enables provider tools on that config is not
rechecked. Tracked in CODAGT-1271.
- **Schedule interval.** Like the API, the tool accepts any cron
expression, including every minute. A minimum interval is tracked in
CODAGT-1272.
- **Deferred review nits.** Codex round 4: the update audit diff uses
the pre-lock row as its before-image (CODAGT-1273); `list` ignores
`automation_id` and `run_now` reports a full message queue as a generic
error (CODAGT-1274).
- `create` records the calling chat as `created_by_chat_id`. `kind`,
`target_mode`, and `webhook_use` cannot be updated, like the API. Fields
that do not apply to an action are rejected instead of dropped.
Lower-layer changes: `auditAutomationCreatedChat` (scheduler, 1211)
takes an optional map of extra audit fields, and `UpdateAutomation` and
`RunAutomation` (1209/1211) take an optional `AutomationGuard`. The
scheduler and the HTTP handlers pass `nil`, so their behavior is
unchanged.
## Size
About 780 hand-written lines (about 380 production, 390 tests, docs). No
generated changes.
## Validation
- Tests cover each rule: heartbeat create, cross-chat create refused,
model-config containment, before and after refusals for update and
enable leaving the row unchanged, run_now containment, reached-turn
refusals with no side effects, the secret matrix, audit fields, field
rejection, and the org-admin owner case. Separate test audit
(code-removal checks) passed. Full `make pre-push` passed before push.
- Remote dogfood UAT passed: a heartbeat created by asking the agent to
"check back every five minutes" appeared in the automation list and kept
firing every five minutes with the browser closed; automation-started
turns could not create, update, enable or run; creating an automation
aimed at another chat was refused; no multi-use secret appeared in any
tool output; `new_chat` containment behaved as above. Audit entries are
verified in Go tests only.
> [!NOTE]
> ARCHITECTURE.md prose was drafted by an agent at the user's request;
the user will review it.
## Stack
On top of slice 12a. Next: slice 12c (composer toggle).
---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `high`_