Files
coder/coderd
Michael Suchacz 0a737cd857 refactor(coderd)!: retire the V0 chat message content decoder (#30998)
This PR breaks compatibility with chat messages stored in the legacy
content format (`chat_messages.content_version = 0`). No release stored
such messages, because Coder Agents (#22290) and `content_version`
(#23042) first shipped together in v2.32.0. Only deployments that ran a
preview build of `main` between 2026-02-27 and 2026-03-13 (in practice,
dogfood) have them: migration 000434 (#23042) stamped every row that
existed then with version 0, and nothing converts them later. The PR
deletes the legacy decoder from `chatprompt`: `ContentVersionV0`,
`parseLegacyContent` and its per-role parsers, the fantasy envelope
detector `isFantasyEnvelopeFormat`, `ExtractFileID`, and the legacy
tool-row type `toolResultRaw`. Coder Agents is experimental
(`coderd/x`), so we drop legacy persisted shapes and the helpers that
parse them outright instead of carrying a migration.

What happens to those messages: `ParseContent` now returns `unsupported
content version 0`. Throwaway API tests on this head show the effect on
a chat with version 0 rows:

- `GET /api/v2/chats/{chat}/messages` returns 200, but the version 0
messages have no content.
- A send to a waiting or errored chat, and an edit, first parse the last
assistant message (for an edit, the last one before the edited message)
to cancel its pending tool calls. If it is version 0, they return 500
(`Failed to create chat message.` or `Failed to edit chat message.`,
detail `execute transaction: parse assistant message: unsupported
content version 0`). By code reading, promote does the same.
- Otherwise they return 200, and an edit deletes the edited message and
every later one. If a version 0 row remains before the new message, the
turn fails in the worker (`build chat prompt: unsupported content
version 0`) and the chat goes to error.
- Recovery: editing the first user message deletes it and every later
row, so a new turn runs; another send alone leaves the chat in error.
Chats created through the API on those preview builds cannot recover
this way: each starts with its system prompt stored as a version 0 row,
which no edit deletes, so their users must start a new chat.

Chats with only version 1 rows do not change.

**Why it is safe**

- New content is always written as `CurrentContentVersion` (1), and
`content_version` is `NOT NULL` with no default, so no new row gets
version 0.
- The layer below removed the tests of the legacy encodings. This PR
handles the last version 0 test cases. It moves the six cases of
current-format parts in `TestParseContent_BackwardCompat` to version 1
rows in `TestParseContent_V1`, and their checks do not change. It
deletes the version 0 malformed-input cases of
`TestParseContent_ErrorPaths`; the version 1 cases with the same input
stay. Every mutant that `main` catches, out of the 17 listed in #30996,
is still caught on this head.
- `git grep` for each removed symbol across the repository, including
`site/`, `enterprise/`, `cli/`, `docs/` and `scripts/`, finds nothing on
this head. Before this PR, the only hit outside `chatprompt.go` was
`coderd/exp_chats_test.go`, which now writes the version as a literal
`0`. That test checks that the SQL `jsonb_typeof` guard skips scalar
JSON rows.

**Review focus**

Version 0 rows now take the existing `unsupported content version`
branch of `ParseContent`; the PR adds no new error path.

**Validation**

- `go test ./coderd/x/chatd/... ./coderd/database/db2sdk/ -count=1 -p 4
-parallel 4`: ok
- `go test ./coderd/ ./enterprise/coderd/ -run
'(?i)chat|agent|mcp|skill' -count=1 -p 4 -parallel 4`: ok
- `golangci-lint run --fix=false ./coderd/x/chatd/chatprompt/...`: 0
issues; pre-commit hook: passed
- Throwaway API tests (not committed) of GET, send and edit with version
0 rows: results above

**Stack**

This stack retires chatd compatibility paths for chat data that older
Coder versions stored.

1. #30996 stamp chat message fixtures with the current content version
2. #30997 drop tests of the legacy content codec
3. #30998 retire the V0 chat message content decoder (this PR)
4. #31000 inline the model config provider identity
5. #31005 retire the `close_agent` tool alias

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-30 01:00:48 +00:00
..