Draft
Conversation
Adds a new 'autochat' system that allows users to create automations
that trigger chat creation via webhooks or cron schedules. This enables
use cases like CI failure remediation, scheduled code audits, and
event-driven agent workflows.
Key components:
- Database: chat_automations and chat_automation_runs tables, plus
automation_id column on chats for filtering automation-spawned chats
out of the normal chat list.
- API: Full CRUD under /api/v2/chats/automations with webhook ingress
at /api/v2/chats/automations/{id}/webhook (unauthenticated, secured
by HMAC-SHA256 signature verification).
- autochat package (coderd/chatd/autochat/):
- executor.go: Core Fire() function that checks concurrency limits,
renders prompt templates, and creates chats via chatd.
- webhook.go: HMAC-SHA256 signature verification supporting both
X-Hub-Signature-256 (GitHub) and X-Coder-Signature headers.
- render.go: Go text/template prompt rendering with restricted
funcmap for webhook body/headers and cron schedule data.
- cron.go: Background executor on a 30s ticker that fires due
cron-triggered automations.
- SDK types and client methods in codersdk/chatautomations.go.
- Middleware for extracting automation params from URL.
Automation-spawned chats run as the automation creator (OwnerID),
inheriting their RBAC permissions. The existing chatd.Server background
loop picks up pending chats with zero changes to the chat runtime.
david-fraley
added a commit
that referenced
this pull request
Mar 17, 2026
Covers four improvement areas: 1. Granular status reporting (needs_user_attention, message, uri) 2. Outbound webhook subscriptions (building on #23184 infra) 3. Structured output for iterative development 4. Admin API and governance gaps Grounded in customer feedback from CoreWeave, QRT, Figma, Schonfeld, BMW, MDA, and OCBC.
Move all chat automation HTTP handlers from the standalone
chatautomations.go into chats.go to keep the chat API surface in
one file, matching the project convention.
Fixes from code review:
- Add dbauthz.AsSystemRestricted(ctx) for the unauthenticated
webhook endpoint's DB call.
- Add cron schedule validation via cron.Weekly() in create handler.
- Fix swagger: update [patch] → [put], 201 → 202 on webhook.
- Add EXPERIMENTAL comments to all automation handlers.
- Use dbtime.Now() instead of time.Now() in executor.
- Remove dead ChatCreator interface from executor.go.
- Log errors instead of silently discarding in executor failure path.
- Name executor logger ("autochat").
- Validate non-empty webhook secret in VerifyWebhookSignature.
- Normalize hex case in signature verification.
- Convert promptFuncMap from mutable package-level var to function.
- Use literal expected value in FuncPipeline test.
- Add empty-string test case for MaskSecret.
- Fix collapsed lines and indentation in coderd.go (gofmt).
- Implement all 11 dbauthz methods for chat automations using rbac.ResourceChat scoped to the automation owner. No more panics. - Thread AutomationID from autochat.CreateChatOptions through chatd.CreateOptions to database.InsertChatParams so automation- spawned chats are properly tagged. - Add watchRunCompletion goroutine that subscribes to chat status change events via pubsub and marks runs as completed/failed when the chat reaches a terminal state. - Pass pubsub to autochat.Executor for event subscription.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new autochat system that allows users to create automations that trigger chat creation via webhooks or cron schedules.
Why
Enables use cases like:
How
Database
chat_automationstable: stores automation definitions (trigger type, webhook secret, cron schedule, model config, prompt template).chat_automation_runstable: tracks individual executions with status lifecycle (pending → running → completed/failed).automation_idcolumn onchats: links automation-spawned chats back to their automation. Default query excludes these from the normal chat list.API Routes
All under
/api/v2/chats/automations:///{id}/{id}/{id}/{id}/trigger/{id}/rotate-secret/{id}/runs/{id}/webhookCore Package:
coderd/chatd/autochat/Fire()checks concurrency limits, renders prompt template, creates chat viachatd.CreateChat(), records run.X-Hub-Signature-256(GitHub native) andX-Coder-Signature.text/templatewith restricted funcmap. Webhook data:{{.Body}},{{.Headers}}. Cron data:{{.ScheduledAt}}.quartz.Clockfor testability.Security
hmac.Equalto prevent timing attacks.Permissions
Automation-spawned chats run as
automation.OwnerID— same RBAC as if the creator typed the message in the UI. No privilege escalation.Tests
autochat/render_test.go: 10 tests covering substitution, nested maps, error cases, funcmap.autochat/webhook_test.go: 10 tests covering HMAC verification, header fallback, secret generation, masking.