Skip to content

feat(coderd): add manage_automations write actions - #30217

Merged
ThomasK33 merged 24 commits into
tk/codagt-1212-automations-toolfrom
tk/codagt-1212b-automations-tool-writes
Oct 2, 2026
Merged

ThomasK33 merged 24 commits into
tk/codagt-1212-automations-toolfrom
tk/codagt-1212b-automations-tool-writes

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

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 • Model: anthropic:claude-opus-5-5 • Thinking: high

Add create, update, enable, and run_now to the manage_automations chat
tool, backed by CreateAutomation, UpdateAutomation, and RunAutomation
with the chat owner as the actor, so owner-only checks stay in the
service.

- Turns an automation reached refuse all four write actions before any
  other work.
- Containment: existing_chat automations must target the calling chat
  (create defaults to it); new_chat automations must use the calling
  chat's model config (the default) or one without provider tools.
  update and enable check the stored row and the merged result;
  run_now checks the stored row.
- create returns the webhook secret only for a single-use webhook that
  targets the calling chat in a human turn; multi-use secrets are never
  returned.
- create, update, and enable write automation audit entries with
  chat_id. run_now mirrors the run endpoint: a new_chat run writes the
  chat-create entry with created_by_chat_id, an existing_chat run writes
  nothing. auditAutomationCreatedChat gains an extra-fields parameter.
- ARCHITECTURE.md describes the final behavior.
Share target merging between create and update through
automationTarget.with, shorten comments that repeat ARCHITECTURE.md,
and reuse requireNoWebhookSecret in the list/get/disable test. No
behavior change.
Add one table subtest for the tool's field-rejection errors: create with
automation_id, update without fields, and enable with a prompt. Mutation
checks showed no test failed when any of these checkField branches was
removed, and each call otherwise succeeds and silently drops the field.
The other write-action tests were kept; mutation checks confirmed each
containment, secret, and reached-turn guard is caught by its test.
…utomations-tool-writes

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
#	coderd/x/chatd/automations_tool.go
#	coderd/x/chatd/automations_tool_internal_test.go
@ThomasK33
ThomasK33 added this pull request to stack #30097 September 30, 2026 23:32
@linear-code

linear-code Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

CODAGT-1135

CODAGT-1212

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T02:50:30.039639Z d9dada7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ecdf303781

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/automations_tool.go Resolved
Comment thread coderd/x/chatd/automations_tool.go Resolved
…cked automation

The manage_automations tool checked containment on the automation row it
had read, then called UpdateAutomation or RunAutomation, which reload and
lock the row themselves. An owner edit in between could make the tool
update, enable, or run an automation that now targets another chat or a
model config with provider tools.

UpdateAutomation and RunAutomation now take an optional AutomationGuard.
UpdateAutomation runs it on the locked stored row and on the row as the
update would leave it, before the write. RunAutomation runs it on the row
read before the send and, at admission, on the locked row whose input is
accepted, which must still name the target the input goes to. The tool
passes a guard that rechecks containment and reports a refusal with the
same error text as before. HTTP callers pass nil, so their behavior is
unchanged.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

Head is now 455d206: the TOCTOU fix 7f160e4 for both Codex P2 threads, plus a merge of 12a (0bb6fd5, which carries 11b #30207 final e10022a). Full pre-push hook passed. CI dispatched on the exact head: https://github.com/coder/coder/actions/runs/36797983509 (headSha 455d206).

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 455d206c00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/automations_tool.go Resolved
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 455d206c00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ions

Tool results stay in the chat, where read-shared users, the model
provider and compaction can see them, so a single-use secret returned to
a human-started turn let a read-only viewer deliver an event first.
create now returns the not-shown note for every webhook; the owner
rotates the secret in the automations UI to get one.
@ThomasK33

Copy link
Copy Markdown
Member Author

Head is now d9dada7: security pass #2 S1 fixed (manage_automations never returns a webhook secret; the WebhookSecrets test asserts no plaintext for single- and multi-use webhooks). The locked-row containment nit was already fixed in 7f160e4. Minimum schedule interval tracked in CODAGT-1272. Full pre-push hook passed. CI dispatched on the exact head: https://github.com/coder/coder/actions/runs/36807127563 (headSha d9dada7).

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9dada7e35

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/automations_tool.go Resolved
Comment thread coderd/x/chatd/automations_tool.go Resolved
Comment thread coderd/x/chatd/automations_tool.go Resolved
…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

sync with main d9c13dc: no content conflicts; make gen produced no diff


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xum (an AI coding agent) prepared and posted this review on behalf of Mike. Each finding came from automated review passes and was re-verified against the code; please push back on anything that looks wrong.

The write actions, the before and after containment checks, the locked-row guard in UpdateAutomation and RunAutomation admission, the reached-turn refusals, and the audit fields all match CODAGT-1212. I also traced the containment premise: a new_chat automation's chat gets only Force On MCP servers (MCPServerIDs: nil in publishAutomationNewChat), and the advisor and computer-use tools do not depend on the model config, so only provider tools can differ. No issues worth fixing were found in the code.

Verdict: no blocking issues
Severity: P0 0, P1 0, P2 0, P3 1 (folded below)

Nit:

  • coderd/x/chatd/automations_tool.go:378: the tool never returns a webhook secret, but CODAGT-1212 still lists the single-use, current-chat exception and a required check for it. The stricter rule makes sense for the reasons the PR description gives. Consider recording it in CODAGT-1212 (or CODAGT-1277) so the ticket matches the code.
Review coverage
  • code-review Standards: 1 finding, dropped (ARCHITECTURE.md prose: the PR discloses the user asked an agent to draft it, so AGENTS.md treats it as the owner's work, and it adds no TODOs)
  • code-review Spec: 1 finding, kept as a folded P3 nit
  • Adjudicator pass over the Go hunks: no additional issues; go test -run 'ManageAutomations|AutomationGuard' ./coderd/x/chatd/ passes at e780533
  • frontend-review: skipped (no files under site/)
  • coder-frontend-review: skipped (no files under site/)

…212b-automations-tool-writes

Resolved the manageAutomationsError conflict: kept this layer's method
(verb-specific message, more mapped refusals) and gave it the parent's
logger parameter, so the unexpected-error log keeps the chat and
automation fields and is written once. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

sync with main 35abc22: merged #30214 (resolved manageAutomationsError: one Warn with chat and automation fields); no other changes for Mike's review (his ticket nit is recorded on CODAGT-1212)


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33 ThomasK33 changed the title feat(coderd/x/chatd): add manage_automations write actions feat(coderd): add manage_automations write actions Oct 1, 2026
…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

sync with main 35abc22: merged #30214 to pick up 64cc207 (test-only); main not merged this pass


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

sync with main d11809f: merged #30214


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xum re-reviewed this PR on behalf of @ibetitsmike using GPT-6.1 Sol (high) Exec subagents.

Locked update/run containment and secret withholding remain intact after the restack. New findings: Standards 0, Spec 0; Frontend is not applicable. Existing capability-drift, audit-before-image, list-argument and queue-full-error deferrals remain on their original threads. The introducing-layer payload is unchanged; fresh tool/guard/history, startup and unowned-promotion tests passed with six roots and 50 PASS entries. No fresh race, full-suite, browser or full-CI verdict is claimed.

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xum validated this PR and approved it on behalf of @ibetitsmike.

Validated head a92decbd6b92. The unchanged write-tool layer preserves the locked update/run containment fixes and secret withholding. Fresh real write-tool, guard, history and concurrent-retarget tests passed; exact-head CI run 36899158655 completed successfully, including required. Accepted capability/audit/error follow-ups remain tracked. Pixel remains pending; this layer has no frontend edits, and this is not Pixel or full-stack merge approval.

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

sync with main a328bee: merged #30214


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

merged #30214


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

merged #30214


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

merged #30214 (main 15382eb)


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

merged #30214 (main dc07908)


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts. make gen produced no diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

merged #30214


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

…212b-automations-tool-writes

No conflicts.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

Merged #30214 (no conflicts).


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33
ThomasK33 merged commit 20ff7f1 into main Oct 2, 2026
29 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
@ThomasK33
ThomasK33 deleted the tk/codagt-1212b-automations-tool-writes branch October 2, 2026 15:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants