Files
coder/coderd/x/chatd/chatstate/doc.go
T
Mathias Fredriksson c0f7663e95 feat: support editing queued chat messages (#29215)
The owner of a chat can edit a queued message through
`PATCH /api/v2/chats/{chat}/queue/{queuedMessage}`. chatd never sends
a row under edit (`editing_since`): rows ahead of it still send in
order, and a turn that ends at it puts the chat in the new `paused`
status. Ending the head's edit, deleting it, or promoting a queued row
continues the chat. Interrupting sends still run ahead of the queue.

The chat state machine classifies a queue whose head is under edit as
its own sub-state (R1P, I1P, A1P, E1P, XE1P, P), so every path to
`paused` is in the transition matrix. A chat whose family has a paused
member cannot be archived, and auto-archive skips that family. Queue
edit and delete are owner-only, because both can send the next message
with the owner's credentials.

`ChatQueuedMessage` gains `editing_since` and `reasoning_effort`, and
`ChatStatus` gains `paused`.

Closes CODAGT-1028
Refs CODAGT-971
2026-10-30 15:52:22 +02:00

32 lines
1.6 KiB
Go

// Package chatstate owns the durable execution-state transitions for
// the chatd subsystem. It implements the chat execution state model.
//
// The package exposes two top-level entry points:
//
// - [CreateChat] creates a brand new chat with its initial history
// in a single transaction. It is standalone because no chat-scoped
// state machine instance can exist before the chat row is written.
// - [ChatMachine] wraps an existing chat. Callers use it to apply
// one or more transitions atomically via [ChatMachine.Update], or
// to read related rows while holding the chat row lock via
// [ChatMachine.Lock].
//
// Every successful [ChatMachine.Update] call locks the chat row,
// advances `snapshot_version` exactly once, applies transition methods
// in order, and (on commit) publishes a single typed `chat:update`
// pubsub message describing the post-transition snapshot. Optional
// `chat:ownership` hints are published only when the post-transition
// state is runnable and ownership is missing or stale. Stream side
// effects are handled by `chat:update` consumers, and ownership hints
// wake chat workers.
//
// Transition methods are explicit, typed wrappers around the durable
// mutations needed to move between states. Each transition reads the
// current chat row and queue state, classifies the resulting
// execution state, validates it against the transition model, and
// rejects with an [*TransitionError] wrapping [ErrTransitionNotAllowed]
// when the transition is not legal from that state. The package owns
// transition validation, durable chat row and queue mutations, and
// post-commit pubsub publication.
package chatstate