Skip to content

feat: add the manage_automations chat tool switch and read actions - #30214

Merged
ThomasK33 merged 26 commits into
tk/codagt-1214b-automations-webhook-editorfrom
tk/codagt-1212-automations-tool
Oct 2, 2026
Merged

ThomasK33 merged 26 commits into
tk/codagt-1214b-automations-webhook-editorfrom
tk/codagt-1212-automations-tool

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Adds the manage_automations chat tool with its read and stop actions (list, get, disable, delete), gated by an interim per-chat switch. Tool sets have not landed, so this ships chats.manage_automations_enabled as the RFC describes for that case; tool sets later replace it and migrate its values.

Part of CODAGT-1212 (slice 12a of 3). Part of CODAGT-1135.

What changes

  • Switch. Migration 000611 adds chats.manage_automations_enabled (default off). It is set through POST /api/v2/chats and PATCH /api/v2/chats/{chat}. After creation only the chat owner may send the field (403 otherwise). Turning it on returns 400 when the chat-automations experiment is off for the chat owner (POST checks the resolved owner_id, not the caller) or when the chat is a sub-agent chat. Turning it off is always accepted. The audit table tracks it.
  • Offering. The tool is offered only in root chats, outside plan mode and explore mode, with the switch on, and with the experiment on for the chat owner (decided once per turn, like mcp-tool-search). It is not on the plan-mode or explore allowlists, and sub-agent chats are created with the switch off.
  • Per-call recheck. Every call reloads the chat and checks all rules again, with a fresh experiment evaluation, before doing anything.
  • Scoping. Owner and organization come from the chat, never from arguments. Reads run as the owner through a new query that filters on organization and owner. Other members' automations are "not found", even when the chat owner is an organization admin.
  • Automation-reached turns. Detected at call time from the full history (compaction replays user rows without automation_id, so the prompt window is not enough). In such turns only automations that target the chat or created it (chats.automation_id) are visible.
  • Visibility of prompts and deletes. list leaves out prompts (tool results stay in the chat, which may be shared); get returns the prompt of the automation it names. In a turn an automation reached, delete only removes the triggering automation; the others can still be disabled.
  • Audit. disable and delete go through the management service and write a background audit entry with chat_id, plus the triggering automation_id and input_id in reached turns. Results use the API shape and never contain a secret or secret hash.

create, update, enable, and run_now come in the next PR and return "not available in this version" here.

Follow-up: CODAGT-1270 (bound the history read that reached-turn detection does on each call).

Size

About 1,380 hand-written lines: about 460 production, 680 tests, and 240 SQL that has to be there (the chats_expanded view rebuilt in both migrations and the 17 inline column lists). Generated: +649/-280 (sqlc, dbmock, dbmetrics, dump.sql, apidoc, API and audit docs, typesGenerated.ts).

Validation

  • Unit and DB tests for every rule above (switch 403/400 cases, offering rules, per-call recheck, owner/org scoping with an org-admin owner, reached-turn detection including compaction replay, audit fields, secret scan), plus a separate test audit. Full make pre-push passed before push.
  • Remote dogfood UAT passed on this slice: switch API cases, tool absent with the switch off, in plan mode, in sub-agents and with the experiment off for the owner (checked in the server's per-step tool lists), list/get/disable/delete, and a secret scan of all tool output. 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

Stacked on the Automations for Coder Agents stack (30085 ... 1214b). Next: slice 12b (write actions), then 12c (composer toggle).


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

Add the interim chats.manage_automations_enabled switch (default off).
POST /api/v2/chats and PATCH /api/v2/chats/{chat} set it. Only the
chat owner may change it after creation, enabling it requires the
chat-automations experiment for the chat owner, sub-agent chats cannot
enable it, and disabling is always accepted.

Offer the built-in manage_automations tool only to root chats outside
plan and explore mode whose switch is on and whose owner has the
experiment, and check every rule again at each call. The tool supports
list, get, disable, and delete, scoped to the chat owner and
organization. A turn an automation reached only sees automations that
target the chat or created it. disable and delete write audit entries
with the chat ID and, in reached turns, the triggering automation and
input IDs.
Simplify the manage_automations tool without changing behavior: inline
the single-use reached() helper, collapse the turn walk-back loop, use
slices.Contains for later actions, drop a redundant root-chat check at
the offer site, and tighten comments and ARCHITECTURE.md prose.

Make the explore-mode recheck case use a root chat so it exercises the
explore rule instead of the sub-agent rule, and merge the two create
subtests of the switch API test.
…ook-editor' into tk/codagt-1212-automations-tool
@linear-code

linear-code Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

CODAGT-1135

CODAGT-1212

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@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-02T14:36:28.045301Z d7d0434 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

Copy link
Copy Markdown

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

Reviewed commit: 709ef9f80a

ℹ️ 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".

…mit delete in automation turns

Tool results stay in the chat, which may be shared, so list leaves prompts out. In a turn an automation started, delete only removes the triggering automation; others can still be disabled.
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

CI for head cd575ed was dispatched manually because pushes to existing stacked PRs start no pull_request run: https://github.com/coder/coder/actions/runs/36789662215

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: cd575ed15c

ℹ️ 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".

…ook-editor' into tk/codagt-1212-automations-tool
@ThomasK33

Copy link
Copy Markdown
Member Author

Merged 11b (#30207) final head e10022a into this branch; head is now 0bb6fd5 (clean merge; affected chatd/coderd automation tests and AgentAutomationsPage vitest pass; full pre-push hook passed). CI dispatched on the exact head: https://github.com/coder/coder/actions/runs/36795978517 (headSha 0bb6fd5).

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 0bb6fd54b5

ℹ️ 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".

…tk/codagt-1212-automations-tool

No content conflicts. The parent now carries the automation migrations
as 000606 and 000607 after main's 000605, so
000607_chat_manage_automations_enabled moves to 000608 unchanged. Main
did not change chats_expanded, so the view this migration recreates
still matches. make gen produced no diff beyond the rename.

---
_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; 000607_chat_manage_automations_enabled renumbered to 000608; make gen produced no diff


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

@ThomasK33
ThomasK33 marked this pull request as ready for review October 1, 2026 09:39
@coderagents

coderagents Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/agents/architecture.md (open) - Add the manage_automations tool to the built-in tool tables. Addressed in the stacked docs PR #30220, which adds a manage_automations row to the Platform tools table on this page, alongside the existing index.md row.

Automated review via Coder Agents

@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 switch, offering rules, per-call recheck, owner and organization scoping, reached-turn visibility, and audit wiring all check out against CODAGT-1212 and the code. One small observability gap is left in the tool's read paths.

Verdict: no blocking issues

Severity: P0 0, P1 0, P2 1, P3 1

Nits:

  • PR description: "Migration 000607 adds..." no longer matches the migration file (currently 000608_chat_manage_automations_enabled, and the in-progress main merge will shift it again); update the number once the stack is restacked.
Review coverage
  • code-review Standards: 3 findings; 1 kept (P2 unlogged DB errors), 2 dropped (ARCHITECTURE.md prose is the owner's work per AGENTS.md Chatd and adds no TODOs; raw action strings are a style preference with no defect)
  • code-review Spec: 1 finding dropped (reached-turn delete limit stays within the spec's "may only" bound and is documented in the PR, tool description, and ARCHITECTURE.md)
  • frontend-review (generated site/src/api/typesGenerated.ts only): FE2 PASS, FE1 and FE3 to FE10 N/A
  • coder-frontend-review types-and-naming: PASS, no findings

Comment on lines +133 to +136
chat, err := p.db.GetChatByID(chatdCtx, chatID)
if err != nil {
return nil, xerrors.New("failed to load this chat")
}

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.

P2: Tool database errors are discarded without logging

Every failure path in runManageAutomations replaces the error with a fixed string and never logs it: GetChatByID (L135), automationOwnerSubject (L147), GetChatMessagesByChatID (L153), the list query (L163), GetChatAutomationByID (L187), and the manageAutomationsError fallback (L251). The model gets the generic text, which is fine, but operators see only a tool error with no cause; p.logger is used only for the audit helper. Compare subagent.go, which logs before returning failed to load parent chat. #30217 adds a Warn to the write fallback, but the read paths stay silent through the top of the stack.

Fix: Keep the generic messages, and log the original error first, for example p.logger.Warn(ctx, "manage_automations failed to load chat", slog.F("chat_id", chatID), slog.Error(err)), at each of these sites (or once in a small helper).

@ThomasK33 ThomasK33 Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 57d6d94: runManageAutomations builds one logger with chat_id and action (plus automation_id once it parses) and logs the underlying error at Warn before returning the fixed message, on the chat, chat history, list and automation-load paths and in the manageAutomationsError fallback. An inactive chat owner is an expected refusal, so it logs at Debug. Not-found and not-authorized automation lookups, and the refusals manageAutomationsError already maps, are not logged. No test: the tool tests run against a real database fixture with no cheap way to inject a failure.


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

…tk/codagt-1212-automations-tool

Renumber 000608_chat_manage_automations_enabled to 000609 because main
added migration 000606 and the parent layers moved to 000607 and 000608.
No content conflicts. make gen produced no other diff.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
The tool returns fixed messages to the model, so log the underlying error
with chat ID, action, and automation ID first for operators.

---
_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 #30207; renumbered the manage_automations_enabled migration to 000609; addressed Mike's review (log the underlying error on each manage_automations failure path)


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

…tk/codagt-1212-automations-tool

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 #30207 (migration renumbered to 000610_chat_manage_automations_enabled; chats_expanded views and column lists carry main's project_id); dropped the testpackage suppression from the tool test


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

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 62a8743519

ℹ️ 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".

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

The reported test-package suppression is removed. Earlier logging and migration-description fixes remain intact. The project-aware schema and generated scanner changes preserve the tool's offering, owner/organization, persisted switch, reached-turn, and child boundaries.

Fresh, uncached focused Go checks passed on this head: 7 roots and 38 PASS entries across the tool, switch/storage, archive query, child, and guarded queue paths. Current-head CI is green, including required. The unchanged generated frontend contract was checked; no new browser/Pixel, full local suite, or remote UAT was run.

The existing public tool-inventory omission remains a nonblocking documentation follow-up and is not claimed fixed. Accepted ticket deferrals remain accepted. This approval covers this layer, not unresolved findings elsewhere in the stack.

…tk/codagt-1212-automations-tool

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 #30207 (story and test review fixes only)


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

…tk/codagt-1212-automations-tool

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 #30207 (story follow-up only)


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

…tk/codagt-1212-automations-tool

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 #30207 (main 15382eb)


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

…tk/codagt-1212-automations-tool

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 #30207 (main dc07908)


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

…tk/codagt-1212-automations-tool

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 #30207


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

…tk/codagt-1212-automations-tool

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 #30207 (no conflicts).


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

@ThomasK33

Copy link
Copy Markdown
Member Author

Documentation Check: manage_automations is now in the platform tools table of docs/ai-coder/agents/architecture.md. The docs for this stack live in the docs layer #30220, so the change is there: 9675918 (head cc508e0).


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

…automations-tool

Brings main ff158c0. Main added migration 000608_chat_title_source and
the lower layers moved to 000609 and 000610, so this layer's migration is
now 000611_chat_manage_automations_enabled. Its chats_expanded view keeps
main's title_source and title_updated_at columns before automation_id and
manage_automations_enabled, and its down migration restores the 000609 view.

Resolved conflicts:
- chats.sql: column lists take main's title columns, then automation_id and
  manage_automations_enabled. UpdateChatByID and UpdateChatTitleByIDIfTitle
  are gone on main. UpdateChatManageAutomationsEnabledByID is kept.
- chatd.go CreateOptions and chatstate CreateChatInput: main's TitleSource
  replaces TitleDerivedFromContent; ManageAutomationsEnabled stays.
- exp_chats.go patchChat: the manage_automations_enabled checks stay before
  main's title normalization.
- ARCHITECTURE.md: both new paragraphs are kept, main's first.
- Generated files come from make gen.

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

Brings the new_chat automation title source fix from #30134.

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d7d04342c9

ℹ️ 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".

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

Revalidated head d7d04342c9c1 against base 95cb3b3bb258. Independent Standards and Spec renewal found no new blockers; the original accepted exclusions remain unchanged.

Re-reviewed migration 611 and preserved title/provenance/switch projections. Tool offering, authorization, schema/switch/SDK, native migration-chain and inherited title-persistence checks passed.

Approval is scoped to this layer and the reviewed inherited interactions. No full-repository suite, fresh Pixel screenshots or remote UAT claimed.

@ThomasK33
ThomasK33 merged commit fb0951b into main Oct 2, 2026
36 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
@ThomasK33
ThomasK33 deleted the tk/codagt-1212-automations-tool 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