Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(site/src/pages/AgentsPage): clear streamed message when a chat errors - #28277

Merged
DanielleMaywood merged 8 commits into
mainfrom
fix/chat-error-clears-stream
Aug 20, 2026
Merged

fix(site/src/pages/AgentsPage): clear streamed message when a chat errors#28277
DanielleMaywood merged 8 commits into
mainfrom
fix/chat-error-clears-stream

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Fixes CODAGT-622

When a chat stopped with an error, the streamed message and its running status stayed on screen instead of clearing. A chat that hit "Response failed: The chat session ended unexpectedly" while "Creating workspace..." kept showing a spinner. Refreshing showed the correct status because the stream state is transient, confirming it was frontend-only.

The WebSocket error handler set the chat status and stored the error but never cleared the in-flight streamState. A tool call with no result yet keeps a derived running status, so the leftover row kept spinning. Treat the error event as a terminal turn boundary: discard buffered parts, gate late parts from the finished turn, and clear the stream state. The error callout still surfaces the failure.

On this error path the partial output is not committed durably server-side (partial persistence only runs on the interrupt path), so clearing the preview converges the live UI with what a refresh already shows.

Implementation plan and fix evaluation

Root cause was confirmed with a store-level test that fails the moment clearStreamState() runs on the error path. Four independent fix designs were evaluated (clear streamState; finalize orphaned tools to error; render-layer-only; combinations). All rejected the render-layer-only fix because isStreaming/isChatCompleted in ChatPageContent derive from streamState !== null and would stay wrong. Chosen approach clears streamState and adds hardening against a pending flush timer or same-frame message_part re-populating the stream after the clear.

Backend verification: flushActiveState partial persistence in coderd/x/chatd/chatloop/chatloop.go runs only on ErrInterrupted, not on the "stream closed unexpectedly" provider-error path (chaterror/classify.go), so the partial output is not recoverable server-side here and discarding the transient preview matches the refreshed view.

Generated by Coder Agents.

…rors

When a chat stopped with an error, the WebSocket error handler set the
chat status and stored the error but never cleared the in-flight stream
state. A tool call that had no result yet kept its running status, so
the partial output (for example "Creating workspace...") kept showing a
spinner even though the chat had errored. Refreshing showed the correct
status because the stream state is transient.

Treat the error event as a terminal turn boundary. Discard buffered
parts, gate late parts from the finished turn, and clear the stream
state. The error callout still surfaces the failure.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14850273e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatConversation/chatStore.test.tsx Outdated
…r clearing stream

Add a ChatPageContent story that streams a create_workspace tool call and
applies the terminal error, asserting the running row is removed and the
failure callout stays. Also drop test comments that restated the
assertions below them.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0edc5931c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatPageContent.stories.tsx Outdated
Comment thread site/src/pages/AgentsPage/components/ChatPageContent.stories.tsx Outdated
… story

Mount the running tool state, then trigger the terminal error during play
and assert the running row is removed while the failure callout remains.
Previously the story set the cleared state before mount, so it passed even
if the error path stopped clearing the stream.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: a5133968e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review August 19, 2026 14:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5133968e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts Outdated
A prior commit set streamReportedWaiting on the error path so late parts
from the errored turn would be dropped. The gate is only reopened by a
status event, and the server delivers parts and status on separate
unordered paths, so a new turn's first part can arrive before its running
status and be silently dropped, corrupting the response.

Drop the gate and keep clearing the stream state and buffered parts.
This preserves the fix for the leftover spinning tool while never
dropping a part that belongs to the next turn. A part already queued
from the errored turn can still briefly reappear afterward, which is a
cosmetic race that the next status event or a refresh resolves.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2528d230b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatPageContent.stories.tsx
…at error

A part already queued from an errored turn can arrive after the error and
repopulate the cleared stream. Render the failed state without that
leftover so it does not show as a live row, and clear the stored error
when a new turn's status arrives so the next stream renders. Also reset
the story store between runs so the error transition is exercised each
time.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d56144c66e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatConversation/liveStatusModel.ts Outdated
…inal errors

The render suppression forced hasAccumulatedOutput off whenever streamError
was set, but request and parse errors set streamError while the stream is
intentionally still running. Gate the suppression on the chat status being
error, which only the terminal stream error sets, so a genuinely live
assistant row keeps rendering for non-terminal errors.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce7ad11499

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts Outdated
Comment thread site/src/pages/AgentsPage/components/ChatConversation/liveStatusModel.ts Outdated
…to terminal status

Clear the stored stream error only when an errored chat begins a new
turn, so a status from a still-running turn does not wipe an unrelated
request-failure callout. Suppress stream output whenever the chat status
is error, not only while the error is set, so a stale leftover does not
reappear as a streaming row while a retry is in flight.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d8182fe40

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/pages/AgentsPage/components/ChatConversation/liveStatusModel.ts Outdated
…connect phases

The retry and reconnect branches still passed the unsuppressed
accumulated-output flag, so a stale leftover from a failed turn could
render under a reconnect banner while the chat status is error. Pass the
terminally suppressed value through those branches too, and tighten the
comment to state only the non-obvious invariant.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: cca5f12fc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@linear-code

linear-code Bot commented Aug 19, 2026

Copy link
Copy Markdown

CODAGT-622

@DanielleMaywood
DanielleMaywood merged commit eed420a into main Aug 20, 2026
29 of 30 checks passed
@DanielleMaywood
DanielleMaywood deleted the fix/chat-error-clears-stream branch August 20, 2026 10:56
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants