Skip to content

fix!: persist structured chat errors#24919

Merged
ethanndickson merged 8 commits into
mainfrom
chat-errors-persisted
May 5, 2026
Merged

fix!: persist structured chat errors#24919
ethanndickson merged 8 commits into
mainfrom
chat-errors-persisted

Conversation

@ethanndickson
Copy link
Copy Markdown
Member

@ethanndickson ethanndickson commented May 4, 2026

Breaking change for changelog:

codersdk.Chat.last_error now returns a structured ChatError object ({message, kind, provider, retryable, status_code, detail}) instead of a plain string. The chats API is experimental (/api/experimental/chats), so this ships without a deprecation cycle; consumers reading chat.last_error as a string must update to read chat.last_error.message. SDK/generated TypeScript terminal error payloads now use the single ChatError type; the live stream error payload type is renamed from ChatStreamError to ChatError.

Persisted chat errors now carry the same provider-specific detail (kind, provider, retryable, HTTP status, optional detail) as the live stream, so refreshing a failed chat rehydrates with the full structured error instead of a one-line headline.

Existing rows are migrated in place: legacy text errors are wrapped into {message, kind: "generic"} so already-errored chats still render, and rows with last_error IS NULL stay NULL. Internally, persisted fallback decoding now reuses the existing chaterror.KindGeneric constant, with no JSON value change.

Closes CODAGT-239

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Docs preview

📖 View docs preview for docs/ai-coder/agents/chats-api.md

@ethanndickson ethanndickson marked this pull request as ready for review May 4, 2026 07:25
@github-actions github-actions Bot added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label May 4, 2026
@ethanndickson ethanndickson requested a review from deansheather May 4, 2026 07:57
Comment thread coderd/database/db2sdk/db2sdk.go Outdated
Comment thread codersdk/chats.go Outdated
Drop the legacy `last_error` headline string and rename `last_error_payload` to `last_error` so chats expose a single structured error object. Make persisted decode lossless, share one frontend normalizer between live and persisted paths, guard the HTTP chip on positive status codes, and align tests, stories, fixtures, and docs.
Removes leftover compatibility scaffolding from the chat last-error
redesign:

- normalizeChatErrorPayload no longer takes a fallbackMessage option;
  the live-stream "Chat processing failed." default lives at the only
  caller that needs it, and the redundant statusCode > 0 check in
  ChatStatusCallout is gone now that the normalizer filters bad codes.
- Deletes chaterror.StreamErrorPayload, which was a thin alias for
  TerminalErrorPayload, and inlines the chatLastErrorMessage helper in
  cli/agents_list.go to match the file's existing nil-check style.
- Renames legacyPayload to wantPayload in chatd_test.go and corrects
  stale "migration 474" comments in the chat last-error fixtures.
- Adds a structured last_error example to docs/ai-coder/agents/chats-api.md.

decodeChatLastError, the cached-error precedence in AgentChatPage, the
encodeChatLastErrorPayload helper, and the LastError clears on chat
status transitions are intentionally unchanged.
@ethanndickson ethanndickson force-pushed the chat-errors-persisted branch from 2a579b2 to 0b82b79 Compare May 5, 2026 02:38
@ethanndickson
Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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".

@ethanndickson ethanndickson merged commit 4751416 into main May 5, 2026
31 checks passed
@ethanndickson ethanndickson deleted the chat-errors-persisted branch May 5, 2026 02:56
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release/breaking This label is applied to PRs to detect breaking changes as part of the release process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants