Repository navigation
Conversation
…automations-api-create
Add --chat-max-automations-per-owner (default 50, 1 to MaxInt32) and --chat-min-automation-schedule-interval (default 5m, 1m to 24h). Both follow the other chat limits: a serpent option in ChatConfig and a range check in DeploymentValues.Validate. The create route reads them through chatautomation.Limits.
…a narrow subject InsertChatAutomation inserts only for an owner that is neither deleted nor a system user, and locks the owner row so that a concurrent soft delete of the owner waits and then removes the new row. AsChatAutomationCounter can read the automations of one owner across organizations and nothing else. dbauthz.IsWrapped lets the shared create function assert its store.
Add the create request and response, the client method, the limits that the create function enforces and its typed errors.
Add Creator.Create and the validation of a create request. Create authorizes the actor, validates every field without a database read, reads the chat, model configuration and project as the actor, then takes the owner lock, checks the per-owner limit as a narrow subject, generates the webhook secret for bearer and github, and inserts as the actor.
POST /api/experimental/organizations/{organization}/chats/automations
creates an automation behind the chat-automations experiment. The response
carries the generated webhook secret of a bearer or github webhook, once,
with Cache-Control: no-store. The audit log gets a create action.
An owner that is deleted, a system user or unknown gets no row, and a soft delete of the owner that starts while an insert is open waits for it.
Lists the create request and response types and the create action of chat automations.
…creating chat A time zone that cron.Standard rejects is reported on schedule_time_zone, not on schedule_cron. The creating chat of the agent tool is read before the insert, so that a missing one is not reported as a missing owner.
Pin the HTTP mapping of the create route (201 with no-store, 400, 403, 404, 409, 413 and the empty-detail 500), that a secret appears only in the create response of a bearer or github webhook, that a failed read after the commit keeps the secret, the audit entry (mock and enterprise auditor) and that a dbcrypt key encrypts the stored secret of every scheme.
Real PostgreSQL and a real authorizer. TestCreate compares every stored column, TestCreateRejected checks each field and reference rule and that a rejected request never inserts, and the other tests cover the per-owner limit (with a deterministic race on the owner lock), the owner guard, authorization before any store call, and the creating chat of the agent tool.
…/automations-api-create
Drop an unreachable branch from the create handler, say what a missing row from the insert can mean, give project_id its own refusal reason, inline the interval range, fix the flag text (no route changes a schedule yet), and cut test rows that repeat another row's branch.
Read the audit log as an auditor, return the header and status from the raw create helper, and mark the soft delete that must run outside the transaction.
InsertChatAutomation refuses a deleted owner, as the user soft delete trigger removes the automations of a deleted user.
…automations-base-api-create
…into tk/automations-api-create
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a5dec8401
ℹ️ 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".
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…/automations-api-create
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Docs previewLinks open this pull request's preview at https://pr-32096.docs.cdr-preview.dev, which updates with each push. 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. Preview sites for each built commit (2)Every built commit keeps its own preview, newest first. Previews aren't indexed by search engines and are deleted when this pull request is merged or closed. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…tk/automations-tool-read Conflict in coderd/chatautomations.go: the sync of #32079 edited the doc of loadChatAutomationRefs, which this PR moved to chatautomation.LoadRefs. The deletion stays. The create handler of #32096 now calls chatautomation.LoadRefs, and LoadRefs reads the chats through GetReadableChatsByIDs, the filtering read that #32079 renamed so that main's all-or-nothing GetChatsByIDs stays.
- Delete TestCreateOwner: the route race OwnerDeleted and TestInsertChatAutomationOwnerGuard own the owner guard. - Delete TestCreateTargetOwnership: the route row TargetChatOfAnotherUser owns the rule and now asserts its detail. - Delete TestCreateRejected rows Cron L loop, ZoneFactory, ScheduleOverStrict and TwoViolations: sibling rows, cron tests and the route row EmptyObject cover them. - Delete TestCreate/ScheduleAcrossDaylightSaving: cron TestSchedule_MinInterval_Limits owns MinInterval. - Delete TestCreate/RFCExample and its constant: the explicit enabled true moves into the ScheduleEnabled row. - Delete TestCreateReferenceDeleted/ChatBeforeRecheck: the route race TargetChatDeleted covers the same window. - Delete TestCreateScheduleNeedsNow: the guard has no caller that passes a zero time. - Delete TestCreateAuthorization/MemberWithoutAgentsAccess: the route row NoAgentsAccess now sends an invalid body. - Merge recorder, recordingStore and insertHook into one hookStore, and drop the call-name assertions. - Move TestCreateCap/DeletedOrganizationStillCounts into the database count test. - Delete the read loop and the GitHubNewChat row of TestCreateChatAutomation: db2sdk.ChatAutomation never reads the secret. - Delete the route rows SecretForBearer, InvalidJSON and the five role rows: the Creator row and the role matrix cover them. - Delete enterprise TestChatAutomationCreateEncrypted: dbcrypt TestChatAutomations/KeysSet covers encryption, also in a transaction. - Delete enterprise TestChatAutomationCreateAuditEntry: Test_chatAutomationSecretsMasked covers the masking.
…irst uses it - Remove CreateParams.CreatedByChatID, its checkReferences block, its foreign key in the insert error mapping and its comments from create.go: the API never sets it and no other caller exists. - Keep an explicit zero CreatedByChatID in insertParams, because the exhaustruct linter needs every field of InsertChatAutomationParams set. - Delete TestCreateCreatingChat, the CreatingChat row of TestCreateReferenceDeletedWhileInserting and its CreateParams argument, and the createdBy wiring in TestCreate.
- F1: TestCreateChatAutomationRejected counts the rows of the caller before and after each rejected request, so a create that stores a row and still answers 400 turns TargetChatOfAnotherUser red. - M1: TestCreateReferenceDeleted asserts again that the answer is not ErrOwnerUnavailable, so a trigger or foreign key error that also carries ErrOwnerUnavailable turns both rows red. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
|
Review-cap waiver, recorded before the push: the operator approved this push on 2026-11-13. It removes tests that repeat other tests or cannot fail, keeps the guards a verifier named, moves the Generated with |
…/automations-api-create Conflicts, both in test files that A2a cut and this branch extends: - coderd/chatautomations_test.go: drop TestChatAutomationsDeleteQueuedMessage, keep the create tests. - coderd/database/chatautomations_test.go: drop TestChatAutomationColumnsOnChats and the imports it needed, keep the owner guard tests and the dbtime import. A2a dropped the third parameter of newFixture, so the create tests call newFixture(t, db). --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Users, and later the agent tool, cannot create a chat automation yet (RFC: Automations for Coder Agents). This PR adds the create route behind the
chat-automationsexperiment, the one create function that the route and the tool share, and the two limits that an operator sets. It is the first code that writes a webhook secret and the only route that returns one. Part of CODAGT-1135.Stacked on #32079. Review only this diff. It merges after #32079.
What changed
POST /api/experimental/organizations/{organization}/chats/automationsanswers 201 with the automation and, for abearerorgithubwebhook, the secret that Coder generated, once, withCache-Control: no-store. Forstandard_webhooksthe caller supplies thewhsec_secret and no response returns it. Get and list have no secret field, so no later read returns one.chatautomation.Creator.Createauthorizes the actor, validates every field, reads the target chat, model configuration and project as the actor, takes a per-owner advisory lock, counts the owner's automations, generates the secret and inserts as the actor. Every CHECK and NOT NULL condition ofchat_automationsis validated in Go first, because a failed constraint writes the whole row, secret included, to the PostgreSQL log. No error text quotes the prompt or a secret, and every 5xx has an empty detail, because the request logger logs 5xx bodies.--chat-max-automations-per-owner(default 50, 1 to MaxInt32) caps one owner across organizations. The count runs as a subject that can only read that owner's automations (AsChatAutomationCounter) and never reaches the insert. Automations of a deleted organization still count: its last member can still create there.--chat-min-automation-schedule-interval(default 5m, 1m to 24h) is checked againstSchedule.MinInterval().InsertChatAutomationrefuses a deleted or system owner and holds a shared lock on the owner row, so a soft delete that starts during an insert waits and then removes the new row.ChatAutomationis audited for create, withpromptandwebhook_secretmasked.TestServerDBCrypt(the test of feat: encrypt the webhook secret of a chat automation with dbcrypt #32076) now seeds chat automations for live users only. The insert refuses a deleted owner, and the soft delete trigger already removes a deleted user's automations.Suggested reading order:
coderd/x/chatd/chatautomation/create.goandvalidate.go,coderd/chatautomations.go, the query and dbauthz changes, then the tests. The rest is generated code and docs.Scope
Tradeoffs
existing_chattarget must be a chat that the automation's owner owns. The RFC checksupdateon the target chat (line 459) and says that no handler or tool checks ownership in code (line 422), butupdateis not enough: an organization admin who holdsagents-accesshasupdateon every chat of the organization, and main forbids that admin to send a message to a member's chat because chat processing forwards the owner's credentials to external services (checkSendChatMessageincoderd/exp_chats.go). A run into a member's chat would do the same.Creator.Createrefuses it with a 400 ontarget_chat_id, so the agent tool and the update route inherit the rule. It narrows what RBAC grants.Createmaps both to the same 409. A model configuration deleted after the insert's own read of it is only soft deleted, so the create answers 201 and the row names a soft-deleted model configuration, which the run path must refuse.--chat-min-automation-schedule-intervalusesSchedule.MinInterval()(feat(coderd/schedule/cron): add Standard schedule constructor #32063), which compares the times of day of a schedule and nothing else. It can refuse a schedule whose runs near midnight fall on different days, and it does not see clock changes. The flag text says so.Live check
On a local enterprise build with its own PostgreSQL and encryption keys set, with the experiment on for one user: one automation of each kind and scheme was created, and each generated secret appeared once, in its own create response, and 0 times in the get and list bodies, the audit log, the raw
webhook_secretcolumn (stored as ciphertext), the server log and the PostgreSQL log. A user with the experiment off got 404, and the cap, the validation errors and an oversized body answered 409, 400 and 413. An owner at the cap also got 409 for a create in a second organization and in a soft-deleted one. An organization admin withagents-accesswho targeted a member's chat got 400 and no row.Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh