Files
coder/coderd
Kyle Carberry 9f99a7bc0b fix(coderd): stabilize TestPatchChatMessage/ChangesModel flaky test (#25306)
Fixes coder/internal#1535

## Problem

`TestPatchChatMessage/ChangesModel` is flaky because it races with the
chat daemon's background processing.

`CreateChat` sets the chat to `pending` and the daemon picks it up
asynchronously. The test immediately calls `EditChatMessage` (which
changes the model to an override) while the first processing round is
still running. The `InsertChatMessages` SQL CTE unconditionally updates
`chats.last_model_config_id` to the model of the last inserted message.
When the daemon's in-flight message insertions commit after the edit
transaction, they overwrite `last_model_config_id` back to the default
model.

Similarly, after the edit sets the chat back to `pending`, the daemon
re-processes it. The test's `GetChat` call could race with this second
round.

## Fix

Poll for the chat to reach `waiting` (or `error`) status:
1. **Before editing**: wait for the initial processing round to complete
2. **After editing**: wait for the second processing round (triggered by
the edit) to complete

Then assert `last_model_config_id`, which is now stable.

> Generated with [Coder Agents](https://coder.com/agents) by @kylecarbs
2026-05-15 09:33:54 -04:00
..