Conversation
This commit adds the database schema and backend API infrastructure for the
AI Agents (Chats) feature. The feature allows users to interact with AI
coding agents that run in their workspaces.
Database Schema:
- Added 'chats' table with status tracking, workspace association, and
multi-replica locking fields (worker_id, started_at)
- Added 'chat_messages' table for conversation history storage
- Added 'chat_status' enum for tracking chat processing state
Backend API (coderd/chats.go):
- GET /api/v2/chats - List user's chats
- POST /api/v2/chats - Create new chat
- GET /api/v2/chats/{chat} - Get chat with messages
- DELETE /api/v2/chats/{chat} - Delete chat
- POST /api/v2/chats/{chat}/messages - Add message to chat
Multi-Replica Safety (Milestone 2):
- AcquireChat: Uses FOR UPDATE SKIP LOCKED to safely acquire pending chats
- UpdateChatStatus: Update status with worker tracking
- GetStaleChats: Find abandoned chats for recovery
RBAC:
- Added 'chat' resource type with create/read/update/delete actions
- Chat owners have full control over their chats
The frontend components and chat processing loop will be added in
subsequent commits.
This commit completes the full implementation of the AI Agents page feature,
which allows users to interact with AI coding agents in their workspaces.
Milestone 3 - Chat Processing Loop:
- Added coderd/chats/processor.go with background chat processor
- Polls for pending chats using FOR UPDATE SKIP LOCKED
- Recovers stale chats on startup
- Integrated into coderd startup
Milestone 4 - Frontend Chat UI:
- Added AgentsPage at /agents with sidebar and chat area
- AgentsSidebar component for listing chats
- AgentDetail component for viewing chat messages
- Added API query helpers in site/src/api/queries/chats.ts
- Added TypeScript types for Chat, ChatMessage, etc.
- Added navigation link to navbar
Milestone 5 - Git State Tracking:
- Added chat_git_changes table via migration 000415
- API endpoint GET /chats/{chat}/git-changes
- SDK types and client methods for git changes
Milestone 6 - Polish & Testing:
- FilesChangedPanel component for showing file changes
- Updated AgentDetail with sidebar layout for files
- Added coderd/chats_test.go with comprehensive test suite
All backend and frontend components build successfully.
ChatMessage.Content and ChatMessage.ToolCalls are nullable JSONB columns. Using json.RawMessage caused 'invalid input syntax for type json' errors when inserting NULL values. Switch to pqtype.NullRawMessage which properly handles SQL NULL for JSONB columns.
Add authorization test cases for all chat database methods: - AcquireChat, GetStaleChats (system-level ResourceChat assertions) - GetChatByID, GetChatsByOwnerID (fetch/fetchWithPostFilter) - GetChatMessageByID, GetChatMessagesByChatID, GetChatGitChangesByChatID (parent chat read authorization) - InsertChat (insert with owner) - InsertChatMessage, InsertChatGitChange (parent chat update) - UpdateChatByID, UpdateChatStatus (fetch + update) - DeleteChatByID, DeleteChatMessagesByChatID (fetch + delete) - DeleteChatGitChangesByChatID (fetch + update)
querier.go was accidentally deleted from the working tree. Restored it from git (it contains the sqlcQuerier interface needed by db.go). Removed duplicate ChatGitChange struct from chats.go since it is already defined in models.go.
The project uses react-router v7, which exports directly from "react-router". The "react-router-dom" package is not installed.
The project uses dayjs, not date-fns. Replace formatDistanceToNow with the existing relativeTime helper from utils/time.
johnstcn
approved these changes
Feb 26, 2026
Member
johnstcn
left a comment
There was a problem hiding this comment.
Conditional approval pending some final code cleanup and last-minute smoke test
47edc60 to
996f17c
Compare
State updates from setIsPublishingDialogOpen, setLastSuccessfulPublishedVersion, and navigation were firing after waitFor resolved, causing sporadic act() warnings and timeouts in the publish template version tests. Fixes coder/internal#1369 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Contributor
Documentation CheckNew Documentation Needed
Notes
Automated review via Coder Tasks |
# Conflicts: # site/src/index.css
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
feat: add AI chat system with agent tools and chat UI
Introduce the chatd subsystem and Agents UI for AI-powered chat
within Coder workspaces.
management, and LLM provider integration (OpenAI, Anthropic)
edit files, execute commands
durable reconnection
providers, and chat model configs
list, diff viewer, and model configuration panel
chatd unit tests, and Storybook stories