Commit Graph
6 Commits
Author SHA1 Message Date
Callum Styan 1a96da2b6a perf(coderd/x/chatd): make chat stream reads lock-free (#30266) 2026-10-05 11:47:24 -07:00
Thomas Kosiewski e3446c9c21 fix(coderd/x/chatd): drop late preview parts after a chat error (#30279)
When a generation attempt fails without a retry (`FinishError`), the chat moves to `error` but keeps its `history_version` and `generation_attempt`, and `retry_state` stays null. The stream loop therefore did not retire the attempt, and a part of the failed attempt that the relay delivered after the `error` event was still forwarded. The frontend clears its preview on `error` (`useChatStore.ts`), so the user saw a mid-message fragment appear under the error.

This is the error-path variant of the issue fixed in #30241 for retries. The stream loop now also retires the current attempt when a sync observes `status = error`, so its late parts are dropped. Every generation attempt increments `generation_attempt` before it creates its part episode (`beginGenerationAttempt`), so the next run after an error starts a fresh preview as before. Other statuses that leave `running` (`interrupting`, `requires_action`, `waiting`) are unchanged: the frontend does not clear the preview for them. The frontend contract is unchanged.

`TestStreamLoopLatePartAfterError` fails on main and passes with the fix; its subtests also cover the next attempt after an error and an interrupt that keeps streaming.

A separate docs commit updates step 7 of the sync algorithm in `ARCHITECTURE.md` and corrects the `preview_reset` description, which said it is emitted when the LLM call fails mid-way. The code emits it only when the history version changes or a new generation attempt starts.

The bug was found by a TLA+ model of the chat stream and confirmed with a Go reproduction.

Refs #30241

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
2026-10-02 13:02:41 +02:00
Thomas Kosiewski 9ac4628947 fix(coderd): stop announcing stale chat retries and fence retried attempts (#30241)
Stop announcing a pending chat retry once the chat leaves running, and stop streaming preview parts of a failed generation attempt after its retry is recorded. UpdateChatExecutionState now clears retry_state on every non-running status write (the trigger advances retry_state_version), the stream loop only emits retry while the chat is running, and it retires the current attempt once it observes a retry payload or an advanced retry_state_version within an unchanged episode. Regression tests cover the error, interrupt and requires_action exits, late parts after a retry, and a retry cleared before the stream syncs; ARCHITECTURE.md documents the new rules.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
2026-10-01 14:10:00 +02:00
Mathias Fredriksson fa5bac6e77 feat: send tool call IDs and cancel unresolved calls on interrupt (#29954)
Retries and replica takeovers ran tool calls again, and an interrupt
recorded the same generic result whether a call had finished, was
still running, or never started.

chatd now derives a tool call ID from the chat, the committed
assistant message, and the provider tool call ID, and sends it with
execute starts, edit_files, and write_file. Every replica and retry
computes the same ID, so the agent returns the first result instead
of running the tool again, and a retried foreground execute waits
only for the rest of its timeout.

On interrupt, chatd cancels the unresolved calls of those tools on
the agent before committing, within 30 seconds, and records what
happened: "tool call was canceled before it ran; no changes were
made", the output of a command canceled while running, or the real
result. The UI shows a canceled command with the existing killed
marker. If the cancel fails, including an old agent's 404, the result
stays the generic interrupted text.

Calls whose provider tool call ID is empty or repeats in the message
get no ID and behave as before.

Fixes CODAGT-757
2026-09-30 14:31:52 +03:00
Michael Suchacz 680b2f59cd refactor: remove obsolete chatd code and tests (#29228)
Chatd still carries an unreachable interruption flush path, unused state
and options, an uncalled workspace MCP cache invalidation callback, and
a stream-buffer-drop counter that production never increments. Remove
these paths and their dedicated assertions, and update the generated
metrics inventory and documentation.

Consolidate duplicate publication and rollback tests and move fixture
writers and test-only inspection helpers into test files. Retain the
interruption persistence, state-machine matrix, legacy message format,
and provider compatibility coverage.
2026-09-14 10:51:22 +02:00
Hugo Dutka 4debd23cbb fix: chatd refactor (#26270)
Implements the chatd stabilization RFC.

Combines:
- https://github.com/coder/coder/pull/25908
- https://github.com/coder/coder/pull/25923
- https://github.com/coder/coder/pull/26109
- https://github.com/coder/coder/pull/26110
- https://github.com/coder/coder/pull/26111
- https://github.com/coder/coder/pull/26112
2026-06-12 13:33:12 +02:00