Files
coder/coderd
Ethan e254086494 fix(coderd/x/chatd/chattool): return database errors from workspace tools (#30822)
Relates to CODAGT-1330

`create_workspace`, `start_workspace` and `stop_workspace` read a fair
bit from the database whilst they wait on a build: the chat workspace
TTL setting, the workspace's agents, the agent's lifecycle state, and
the chat row once the build is done. When one of those reads failed,
we'd log it (or just ignore it) and carry on as if it hadn't, e.g.
falling back to the template's TTL or leaving out the agent status, and
the tool still reported success. A failed write of the new build ID to
the chat binding was handled the same way.

To fix, we'll return a tool error for those database errors, so the
model knows the call failed and can retry. `start_workspace` and
`stop_workspace` now also re-bind the chat when its build is stale, so a
retried call repairs a binding write that failed. An invalid TTL
setting, a workspace with no build yet, and agent selection errors all
behave like they do today.

A tool error doesn't stop the build. The tools only watch the build and
the agent, so the build, the startup scripts and the turn all carry on.
If the model calls the tool again, `create_workspace` finds the
workspace through the chat binding, which #30663 commits with the
workspace, and waits on it again rather than creating a second one. It
only creates a replacement if the agent has since disconnected or timed
out, like it does today. `start_workspace` just waits on the latest
build again, and the other workspace tools find and dial the agent
themselves.

This follows on from #30663.
2026-10-19 14:02:47 +11:00
..