Skip to content

feat: disable, re-enable, and rotate chat automations with schedule preview - #30117

Merged
ThomasK33 merged 17 commits into
tk/codagt-1209-automations-mgmt-routesfrom
tk/codagt-1209b-automations-disable-rotate
Oct 2, 2026
Merged

ThomasK33 merged 17 commits into
tk/codagt-1209-automations-mgmt-routesfrom
tk/codagt-1209b-automations-disable-rotate

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Completes the chat automations management API from RFC step 3: disable and re-enable, delete that disables first, webhook secret rotation, and a server-side schedule preview. Stacked on #30112.

  • Disable (PATCH with {"enabled": false}) runs in two steps. A short transaction that touches only the automation row sets enabled = false and increments queue_generation, the cutoff. After it commits, the automation's queued rows below the cutoff are deleted one chat at a time through chatd's existing DeleteQueued transition, run as chatd, so queue versions and stream updates match a manual delete. If a row is missed, for example after a crash between the steps, the queue promotion guard from feat(coderd): add chatd automation admission seam and queue promotion guard #30096 discards it, because its generation is stale. Running turns are not interrupted.
  • Delete deletes the row and then removes all of the automation's queued rows the same way. Deleting the row is itself the cutoff, because the promotion guard discards rows whose automation no longer exists. So delete needs only delete permission, not update. This differs from the RFC's "disable, then delete" order, with the same outcome.
  • Re-enable ({"enabled": true}) moves a schedule's cursor to the next future cron time, so the disabled period is not replayed. The generation never resets.
  • Permissions: only the owner can enable, edit, or rotate. Organization admins and site owners can send exactly {"enabled": false} (anything combined with it is 403), and can still list, read, and delete.
  • Rotation: POST .../chat-automations/{automation}/secret/rotate (owner only, webhooks only) returns the new secret once and increments webhook_secret_version. Only the SHA-256 hash is stored, and the rotation is audited with the hash redacted.
  • Preview: POST .../chat-automations/schedule-preview evaluates an unsaved cron expression and time zone with create's rules and returns the next five run times, or 400.
  • coderd/x/chatd/ARCHITECTURE.md gets a TODO (CODAGT-1209) note about disable using the delete-queued transition. Author action before merge: replace that TODO with the architecture prose (agents do not write that document).

Known gap, tracked in CODAGT-1227: when the target chat is archived, disable and delete cannot remove its queued automation rows, because DeleteQueuedMessage is not allowed from archived states. The rows never run, since the promotion guard discards them, but they stay visible after the chat is unarchived. The fix needs a chatstate transition from the lower layer.

Dogfood UAT ran on a real dev instance and passed. It covered disable removing only that automation's queued rows (the chat API agreed), delete, re-enable without replay, the permission matrix for an organization admin and the site owner, rotation (the stored hash matches the new secret, and neither secret appears in get or list), preview, and a runtime experiment rule. It also checked that a leftover row is discarded on promotion.

Closes CODAGT-1209
Part of CODAGT-1135
Refs CODAGT-1217

Stack: PR 3b of the Automations for Coder Agents stack, on top of #30112 (PR 3a), #30096, and #30085.

This PR was written by an AI agent (xum) and reviewed by the agent's own test audit and UAT. A human has not reviewed it yet.


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

…review

PATCH `enabled` now disables and re-enables chat automations:

- Disabling bumps queue_generation in a short automation-only
  transaction, then deletes the automation's queued messages below the
  new cutoff as chatd through the DeleteQueuedMessage transition, like a
  manual delete. Rows the cleanup misses are discarded by the promotion
  guard. Running turns are not interrupted.
- Anyone allowed to update an automation may send a request that only
  disables it; enabling and every other change stay owner-only.
- Re-enabling a schedule moves its cursor to the next future occurrence,
  so missed occurrences never run.
- DELETE disables first, so queued messages are removed before the row.

Add POST .../chat-automations/{automation}/secret/rotate (owner only,
webhooks only), which returns the new secret once and increments
webhook_secret_version, and POST .../chat-automations/schedule-preview,
which validates a schedule like create and returns its next run times.
Re-enabling a webhook automation sets no schedule cursor, and disabling
an automation that is already disabled still removes queued messages an
earlier cleanup missed. Neither path had a test.

Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33
ThomasK33 added this pull request to stack #30097 September 29, 2026 18:18
@linear-code

linear-code Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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-09-29T21:00:37.252289Z 2a29c5a 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: 490c9b7133

ℹ️ 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/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/automations.go Resolved
A disabled automation has no pending occurrence, so disable now clears
schedule_next_run_at instead of leaving the old cursor in responses.
Re-enabling already computes the next future occurrence.

---
_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 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: 93986645a5

ℹ️ 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.go Resolved
Delete no longer runs the disable update first, which required update
permission. It deletes the row and then removes every queued message
of the automation; the promotion guard discards any message whose
automation no longer exists, so deleting the row is the cutoff.

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

@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: 93986645a5

ℹ️ 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.go Resolved
---
_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. Keep it up!

Reviewed commit: 1545c74e88

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

…1209b-automations-disable-rotate

# Conflicts:
#	codersdk/chatautomations.go
#	docs/reference/api/schemas.md
@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: 22c6e1aa9f

ℹ️ 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.go Resolved
UpdateAutomation read the clock before waiting for the automation row
lock, so a re-enable that waited across a cron boundary could store a
cursor that was already in the past. Read it after the lock.

---
_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 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: 88d5f8964b

ℹ️ 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.go Resolved
Comment thread coderd/x/chatd/automations.go Resolved
…cking

Create computed its timestamps and first schedule cursor before waiting
for the per-owner lock, and rotation read the clock before the row lock.
Read both after the lock, like updates already do, so a stored cursor is
never already in the past and updated_at never moves backward.

---
_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. Swish!

Reviewed commit: 2a29c5afe1

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

@ThomasK33

Copy link
Copy Markdown
Member Author

Readiness record (agent): ready, with follow-ups tracked.

  • Final head: 2a29c5a. CI: 32 of 32 checks green. Unresolved threads: 0.
  • Codex: 6 rounds, the cap. Round 6 was clean on 2a29c5a. Fixed on the way: clearing the cursor on disable, delete without update permission, and clock reads after row locks. Declined: replacing the ARCHITECTURE.md TODO, because under repository policy the human author writes that prose. Deferred: archived-chat queue cleanup, CODAGT-1227.
  • Dogfood UAT passed on 2a3f05a. The later fixes are covered by Go tests, including an enterprise custom-role test for delete.
  • An independent clean-context review recommended ready with tracked follow-ups and found no repeat UAT necessary.
  • Author action before merge: replace the TODO (CODAGT-1209) in coderd/x/chatd/ARCHITECTURE.md.

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

…odagt-1209b-automations-disable-rotate

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

spacexm406-web
spacexm406-web previously approved these changes Oct 1, 2026
@ThomasK33
ThomasK33 marked this pull request as ready for review October 1, 2026 09:38
@ThomasK33
ThomasK33 dismissed spacexm406-web’s stale review October 1, 2026 10:06

Dismissing: approval from an account outside the Coder organization with no review content.

…odagt-1209b-automations-disable-rotate

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

No issues worth fixing were found. Disable, re-enable, delete, secret rotation, and schedule preview match the CODAGT-1209 scope, the earlier Codex threads are fixed at this head, and go test ./coderd -run TestChatAutomation passes locally. The TODO (CODAGT-1209) note in coderd/x/chatd/ARCHITECTURE.md was already flagged in an earlier thread and is listed as an author action. Later in the stack it is replaced with prose, so it needs no new comment.

Verdict: no blocking issues

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

Review coverage
  • code-review Standards: 1 finding (ARCHITECTURE.md TODO), dropped because an earlier thread already raised it and a later layer replaces it with prose
  • code-review Spec: CODAGT-1209 disable, re-enable, delete, rotate, and preview PASS, 0 findings
  • 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, 0 findings; other roles N/A (generated file only)

…odagt-1209b-automations-disable-rotate

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


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.

Rechecked the earlier cursor, delete-permission and post-lock clock fixes, with the architecture note resolved later in the stack. New findings: Standards 0, Spec 0, Frontend 0 across all eight frontend lanes. Archived-chat cleanup remains an accepted CODAGT-1227 deferral in the existing thread, without a duplicate inline comment. Verified final fresh-head OSS/enterprise automation, promotion/interrupt and capacity tests passed with GOMAXPROCS=4 and go test -p 2, as did diff and generated-contract checks; race/UAT were not rerun, and frozen Storybook CI remains failed with stack Pixel snapshot-report HTTP 500 evidence, not a demonstrated source defect.

…odagt-1209b-automations-disable-rotate

Resolved conflicts in coderd/apidoc/docs.go, coderd/apidoc/swagger.json and
dbauthz_test.go: dbauthz_test.go keeps both sides, the apidoc files come
from make gen.

---
_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 #30112


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 validated this PR and approved it on behalf of @ibetitsmike.

Validated head b88411b73087. Prior cursor, delete-permission and post-lock clock findings remain fixed after the restack. Fresh real management/enterprise authorization-and-redaction plus queue/interrupt guard tests passed, and generated contracts are preserved. Current required CI passed. Archived-chat cleanup remains the accepted CODAGT-1227 follow-up, not a claimed fix; approval is limited to this layer.

…odagt-1209b-automations-disable-rotate

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


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

…odagt-1209b-automations-disable-rotate

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 #30112 (experiment display-name test fix)


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

…odagt-1209b-automations-disable-rotate

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


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

…omations-disable-rotate

Brings main ff158c0 into this layer. No conflicts.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33
ThomasK33 merged commit 5c1662e into main Oct 2, 2026
31 of 32 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
@ThomasK33
ThomasK33 deleted the tk/codagt-1209b-automations-disable-rotate 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.

3 participants