Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 34 additions & 2 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion coderd/database/queries/chats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ LIMIT
-- entry. The jsonb_typeof guard skips legacy V0 rows whose content is
-- a scalar JSON string (predates migration 000434) so the lateral
-- jsonb_array_elements never raises "cannot extract elements from a
-- scalar". Backed by idx_chat_messages_user_prompts.
-- scalar". Rows carrying a sender-chat part were written by another
-- chat's agent rather than typed by the user and are excluded. Backed by
-- idx_chat_messages_user_prompts.
SELECT
cm.id,
string_agg(part->>'text', '' ORDER BY ordinality)::text AS text
Expand All @@ -610,6 +612,7 @@ WHERE
AND cm.deleted = false
AND cm.visibility IN ('user', 'both')
AND jsonb_typeof(cm.content) = 'array'
AND NOT (cm.content @> '[{"type":"sender-chat"}]'::jsonb)
AND part->>'type' = 'text'
GROUP BY
cm.id
Expand Down
10 changes: 10 additions & 0 deletions coderd/exp_chats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,16 @@ func TestGetChatUserPrompts(t *testing.T) {
database.ChatMessageVisibilityBoth, true,
)

// Prompt delivered by another chat's agent (sender-chat part);
// must not appear since the user did not type it.
insertUserMessage(t, ctx, db, chat.ID, modelConfig.ID, user.UserID,
[]codersdk.ChatMessagePart{
codersdk.ChatMessageSenderChat(uuid.New(), "Parent", codersdk.ChatSenderChatRelationParent, 1),
{Type: codersdk.ChatMessagePartTypeText, Text: "relayed by agent"},
},
database.ChatMessageVisibilityBoth, false,
)

// Model-only visibility prompt; must not appear (composer
// only shows what the user actually typed).
insertUserMessage(t, ctx, db, chat.ID, modelConfig.ID, user.UserID,
Expand Down
8 changes: 8 additions & 0 deletions coderd/x/chatd/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ For `busy_behavior=interrupt`, `SendMessage(m, interrupt)` supports:

When `SendMessage(m, interrupt)` lands in `I1`, the queued message is promoted later by `FinishInterruption(partial?)` after the interrupted suffix is finalized.

TODO (chat-tree): the `send_chat_message` builtin tool is a second producer of `SendMessage(m, queue|interrupt)`, run as the chat owner from inside the sending chat's turn. `m` is a user row whose first part is `sender-chat` (sender id, title, relation, `relay_hop`), followed by the text. `interrupt` is downgraded to `queue` when the target is in `A0`/`A1` (`requires_action`). Describe it here.

Other input states are not supported.

### `PATCH /api/experimental/chats/{chat}/messages/{message}`
Expand Down Expand Up @@ -892,12 +894,14 @@ The generation goroutine supports:
- subagents (`spawn_agent`, `wait_agent`, `message_agent`, `interrupt_agent`, `list_agents`, `list_subagent_models`)
- TODO (chat-tree): these tools target only `kind = subagent` direct children of the calling chat; named tree children (`kind = chat` with a parent) are not addressable through them.
- `close_agent` is a deprecated alias that dispatches to `interrupt_agent`, so historical tool calls in chat history still resolve
- TODO (chat-tree): chat tree messaging (`send_chat_message`, `list_chat_tree`), appended only for `kind IN (root, chat)` chats when the `chat-tree` experiment is enabled; targets are the direct parent or direct `kind = chat` children only. Describe it here.
- file links
- workspace binding
- plan mode
- respecting model configuration
- provider-specific tools like web search and computer use
- turn limit after a user message (the LLM shouldn't be able to spin forever in loop)
- TODO (chat-tree): the turn limit does not bound agent-to-agent relay chains, because each delivered message starts a new turn on the target. Those are bounded by the `relay_hop` cap carried in the `sender-chat` part (a turn started by a relayed prompt sends `1 + max relay_hop` of its starting prompts) and by a per-turn `send_chat_message` budget that is smaller for relayed turns. Describe it here.
- and other things

##### Reasoning effort
Expand Down Expand Up @@ -1023,6 +1027,8 @@ The worker periodically archives old, unused chats.

TODO (chat-tree): candidates are `kind = chat` rows only (tree roots are never archived), a candidate is inactive only when its whole recursive subtree is inactive, and the cascade archives that subtree.

TODO (chat-tree): a `send_chat_message` relay chain keeps every chat it touches active, so a subtree exchanging messages is never an auto-archive candidate while the chain runs. Describe it here.

## Manual compaction

Compaction reduces the LLM prompt size by summarizing older history into a compressed boundary. It normally runs automatically: while preparing a generation, the worker compares the latest known token usage against the model's compaction threshold, and when the threshold is exceeded it makes a non-streaming LLM call to produce a summary and commits it as a compressed message triplet (a hidden model-only summary boundary, a visible `chat_summarized` tool call, and its tool result). Prompt queries prune history at the newest boundary.
Expand Down Expand Up @@ -1052,6 +1058,8 @@ Concurrent dispatches are capped per replica, and each dispatch declares whether

Coder stores no hook-specific dispatch or decision state. Delivery is best-effort and can duplicate, and a failed dispatch is never redelivered, so the consumer owns durable policy state, audit records, and deduplication based on stable event identifiers.

TODO (chat-tree): `send_chat_message` submits a `user_prompt_submit` admission for the target chat from inside the sender's running turn, like a subagent spawn. A denial is returned to the sending model as a tool error; a dispatch failure fails the sender's turn and parks a `waiting` target in `E0`. The `sender-chat` part travels in `Parts`. Describe it here.

# Stream loop

The stream loop powers the `GET /api/experimental/chats/{chat}/stream` endpoint. It is scoped to one chat and one client WebSocket. It's responsible for delivering a stream of chat updates to the client, including:
Expand Down
Loading
Loading