docs(coderd/x/chatd): resolve ARCHITECTURE.md TODOs for idle chats and workspace files (#30039)
Resolves the four TODO notes that #27079 and #27111 left in `coderd/x/chatd/ARCHITECTURE.md`. Each note pointed at a real change in documented behavior, so each is replaced with a short description that keeps the architectural facts and drops the implementation detail the notes carried (part field lists, the agent upload path, the prompt text format, helper names). - `Create` takes an explicit initial status that defaults to `running`, matching `chatstate.CreateChat`; callers request `waiting` for an idle chat. The execution state diagram gains the `N --> W: Create(waiting)` edge, and the `POST /api/v2/chats` section documents that empty `content` creates an idle chat, so clients can use the chat ID (for example to upload workspace files) before the first turn. The child-chat locking bullet from #30240 now uses the same `Create(initialMessages, initialStatus)` signature. - Files uploaded into the chat's workspace get no file links, so the attachment cap and eviction do not apply to them. A message can reference only a file in the chat's upload directory in the currently bound workspace, and the model gets the reference as text, never the bytes. - `POST /api/v2/chats/{chat}/workspace-files` is owner-only and needs SSH access to the workspace. It uses no transition, rejects archived chats, and works in every other execution state. It prefers the chat's bound agent and otherwise uses the worker's deterministic agent selection without binding the chat. Testing: - Docs-only change, rebased onto `main` at `8245457c8a5`. All four TODO notes were still on `main`, and each statement above was rechecked against the code there. - `make pre-commit-light` passes (markdown format and lint, `typos`, the dash check). `markdownlint-cli2` reports the same 10 pre-existing findings on `main` and on this branch. - The existing tests that pin each documented behavior pass on the rebased head: `TestCreateChat_AllowsNoUserMessages`, `TestCreateChat_RejectsInvalidInitialStatus`, `TestTransitionCreate_NToW`, `TestCreateChatWithoutInitialUserContent`, `TestPostChats_EmptyContent`, `TestWorkspaceFilePartToText`, `TestWorkspaceFilePartToTextStaleWorkspace`, `TestPostChatWorkspaceFile` (including `NotOwner`, `Archived`, `SharedWorkspaceRequiresSSH`), `TestCreateChatMessageWorkspaceFilePartRejectsInvalidPath`, and `TestCreateChatMessageWorkspaceFileWorkspaceValidation`. Review record: - Codex round 1 on `e3c5053`: 3 P2 findings (explicit `Create` status, model sees more than the path, missing owner-only constraint). All confirmed against existing tests and fixed in `41c40a2`. - Codex round 2 on `41c40a2`: 3 P2 findings (SSH requirement, `running` default for the initial status, per-chat reference path rule). All confirmed against existing tests and fixed in `5a55996`. - Codex round 3 on `5a55996`: no findings. - Codex round 4 on `46f94d0`, the head rebased onto `main` (review started by marking the PR ready): no findings. The rebase changed no reviewed text; it only updated the signature in the child-chat bullet that `main` added since. Refs #27079, #27111 > Xum, an AI coding agent, prepared this PR on behalf of @ibetitsmike.
This commit is contained in:
1 parent
8e76aecf42
commit
ea287daf71
1 file changed
+10
-9
@@ -55,7 +55,7 @@ File links are metadata, but they are written inside transitions: if a transitio
|
||||
|
||||
Eviction means that a persisted message may reference a file that no longer exists. That's expected: the UI shows the attachment as expired, and when the history is sent to the model, an evicted user upload is replaced with a short placeholder saying the content has expired, while evicted assistant and tool files are dropped. Editing a message that still references an evicted file is refused until the attachment is removed from the edit.
|
||||
|
||||
TODO (#27079): messages can now carry a `workspace-file-reference` part (path, name, size, media type, workspace ID) for files uploaded into the chat's workspace. It is metadata only: no file link is written, coderd validates that the path is scoped to the chat's upload directory and that the workspace ID matches the chat's current binding, and prompt conversion renders the reference as text (`[workspace file: <name> (<size>) at <path>]`) so the bytes never reach the model. Describe this here.
|
||||
Files uploaded into the chat's workspace through `POST /api/v2/chats/{chat}/workspace-files` get no file links, so they don't count toward the cap and are never evicted. Their bytes live in the workspace, not in coderd, and a message refers to one with a `workspace-file-reference` part that describes the file, including its path and the workspace it was uploaded to. A message can include a reference only if its path names a file in this chat's upload directory and its workspace is the one the chat is currently bound to. The model gets the description as text, never the bytes, and reads the file with its workspace tools. After the chat's workspace binding changes, existing references are shown to the model as no longer accessible.
|
||||
|
||||
Project instructions are optional context injected into all chats in a project. Stored in `chat_project_instructions`. Subagents have no `project_id`, so they use the root chat's project. A root chat can move into a project, between projects, or out of its project after it's created. The move is written inside the `SetProject` transition so that it happens only while no step of the chat runs.
|
||||
|
||||
@@ -120,9 +120,8 @@ I don't recommend reading the rest of section thoroughly if this is your first t
|
||||
|
||||
### Transitions used by the HTTP endpoints
|
||||
|
||||
- `Create(initialMessages)` creates a new chat, initializes `snapshot_version` to 1, inserts its initial history, and lands in `running`. The inserted initial history sets `history_version` to 1. Since the queue has not changed, `queue_version` remains 0. This transition is a special case: since the chat does not exist at the time it's run, the chat row cannot be locked before the transition is applied.
|
||||
- TODO (#27111): `Create(initialMessages)` now lands in `waiting` instead of `running` when the initial history carries no user message (system messages only); such a chat enters `running` through its first `SendMessage`. The state diagram below needs the matching `N --> W: Create` edge. Describe this here.
|
||||
- When `Create(initialMessages)` creates a child chat, it first locks the family's root chat row with `FOR SHARE` and fails if the root is archived, so a new child never joins an archived family.
|
||||
- `Create(initialMessages, initialStatus)` creates a new chat, initializes `snapshot_version` to 1, inserts its initial history, and lands in `initialStatus`. The initial status defaults to `running`; a caller can request `waiting` instead to create an idle chat, which starts running with its first `SendMessage`. The inserted initial history sets `history_version` to 1. Since the queue has not changed, `queue_version` remains 0. This transition is a special case: since the chat does not exist at the time it's run, the chat row cannot be locked before the transition is applied.
|
||||
- When `Create(initialMessages, initialStatus)` creates a child chat, it first locks the family's root chat row with `FOR SHARE` and fails if the root is archived, so a new child never joins an archived family.
|
||||
- `SetArchived(archived)` sets or clears the archived marker for one chat.
|
||||
- `SetProject(project)` sets or clears the project of one chat without changing its execution state. A move of a root chat applies it to the root and each descendant in one transaction, and fails without changing any chat if one of them isn't in `W`, `E0` or `E1`. Only the root's `project_id` changes; subagents go through `SetProject` only so that their execution state is checked too. As in a family archive, the root row is locked first, so a concurrent child creation either joins the move or waits for it. A move to the root's current project applies no transition.
|
||||
- `SendMessage(m, busy_behavior)` inserts a user message directly when the chat is idle, or queues it when the chat is busy. `busy_behavior` must be either `queue` or `interrupt`. With `busy_behavior=interrupt`, it also requests interruption, or cancels a pending dynamic-tool action and inserts the message directly.
|
||||
@@ -162,7 +161,8 @@ stateDiagram-v2
|
||||
|
||||
[*] --> N
|
||||
|
||||
N --> R0: Create
|
||||
N --> R0: Create(running)
|
||||
N --> W: Create(waiting)
|
||||
|
||||
W --> R0: SendMessage
|
||||
W --> R0: EditMessage
|
||||
@@ -459,11 +459,12 @@ The write paths maintain exactly one default whenever an organization has at lea
|
||||
|
||||
### `POST /api/v2/chats`
|
||||
|
||||
This endpoint uses `Create(initialMessages)`:
|
||||
This endpoint uses `Create(initialMessages, initialStatus)`:
|
||||
|
||||
- `N -> Create(initialMessages) -> R0`
|
||||
- `N -> Create(initialMessages, running) -> R0` if `content` is non-empty
|
||||
- `N -> Create(initialMessages, waiting) -> W` if `content` is empty
|
||||
|
||||
TODO (#27111): a request with an empty `content` array now takes `N -> Create(initialMessages) -> W`: the chat is created idle with system messages only and no worker picks it up, so clients can use the chat ID (for example for workspace file uploads) before the first `POST /api/v2/chats/{chat}/messages` starts generation. Describe this here.
|
||||
With empty `content`, the chat starts idle with only system messages. This lets a client get the chat ID before the first turn, for example to upload files into the chat's workspace, and then start generation with its first `POST /api/v2/chats/{chat}/messages`.
|
||||
|
||||
No other input states are supported.
|
||||
|
||||
@@ -630,7 +631,7 @@ No other input states are supported: generating chats and chats with queued mess
|
||||
|
||||
### `POST /api/v2/chats/{chat}/workspace-files`
|
||||
|
||||
TODO (#27079): this owner-only endpoint uses no transition. It streams the raw request body to the chat's workspace agent (`/api/v0/upload-chat-file`), preferring the bound agent and otherwise falling back to `agentselect.FindChatAgent` without persisting a binding, and returns the final path so the client can attach a `workspace-file-reference` part to its next message. Describe this here.
|
||||
This endpoint uses no transition and writes nothing to the chat. Only the chat owner can upload, and they must have SSH access to the chat's workspace. It rejects archived chats and works in every other execution state, including while a turn is running. It streams the request body into the chat's workspace through a workspace agent and returns the file's path for the client to reference from a later message. The upload prefers the agent the chat is bound to. Otherwise it picks one with the chat worker's deterministic agent selection without binding the chat, so the file lands on the agent whose tools will read it.
|
||||
|
||||
## Pubsub
|
||||
|
||||
|
||||
Reference in new issue
Block a user