Skip to content

fix(coderd/x/chatd): return database errors from turn preparation - #30492

Merged
ethanndickson merged 1 commit into
ethanndickson/codagt-1330-createfrom
ethanndickson/codagt-1330-turn
Oct 11, 2026
Merged

ethanndickson merged 1 commit into
ethanndickson/codagt-1330-createfrom
ethanndickson/codagt-1330-turn

Conversation

@ethanndickson

Copy link
Copy Markdown
Member

Relates to CODAGT-1330

When chatd prepares a turn, it reads a bunch of things from the database: the user's custom prompt, plan mode instructions, personal skills, the advisor config, the user's compaction threshold override, MCP server configs, inline MCP servers, MCP user tokens and the pinned workspace MCP tools. If any of those reads failed, we'd log a warning and run the turn without them, so the model would quietly ignore the user's instructions or be missing tools for that turn.

To fix, we'll just return the error instead, so the prepare retry runs, and the chat shows an error if the reads keep failing. The provider switch history sanitizer and the cancel of deleted tool calls also return their database errors now. A model config that's unavailable, e.g. deleted, is still treated as foreign by the sanitizer like it is today.

An inline MCP server with invalid stored headers still shows up as a failed connect in the chat debug panel, but a failed read of the inline MCP servers themselves now fails the turn.

This PR is in a stack on top of #30449.

Turn preparation logged failed reads of the user prompt, plan mode
instructions, personal skills, advisor config, compaction threshold,
MCP server configs and MCP tokens, then ran the turn without them.
Return the errors instead, so the prepare retry runs and the chat
shows an error if the reads keep failing.

The provider switch history sanitizer and the cancel of deleted tool
calls also return their database errors now.

Part of CODAGT-1330
@linear-code

linear-code Bot commented Oct 8, 2026

Copy link
Copy Markdown

CODAGT-1330

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T01:42:24.281882Z 3f3fa22 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 3f3fa22bdd

ℹ️ 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 on lines +108 to 109
mcpConfigs, err = server.effectiveMCPServerConfigs(ctx, chat)
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep preparation database failures retryable

When the selected MCP-config read fails, this returns the raw database error; after retryGenerationPhase exhausts its three attempts, runGenerationStep does not recognize it as errTaskRetryable and calls finishGenerationError, permanently moving every affected chat to an error state during an outage. The same regression applies to the other newly propagated preparation reads. Database connection failures are required to be retried by the runner without a fixed limit (coderd/x/chatd/ARCHITECTURE.md:1008-1020), so exhausted preparation failures should be classified as task-retryable rather than persisted as user-visible chat errors.

AGENTS.md reference: AGENTS.md:L42-L43

Useful? React with 👍 / 👎.

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

The mechanics here are right, but this isn't new to this PR. prepareGeneration already returns raw database errors for the reads it had before (e.g. get chat messages for prompt and the model config lookups), and none of them are classified as errTaskRetryable, so those already go to finishGenerationError once retryGenerationPhase gives up. In a real outage those reads fail too, so the chat would end up in the same error state with or without this change. This PR just stops the newly propagated reads from silently running the turn without the data, and puts them on the same path.

I agree prepare doesn't follow the unlimited retry rule in ARCHITECTURE.md, but I don't think it should be fixed here. Wrapping these reads in normalizeTaskInfrastructureError would turn sql.ErrNoRows into an expected exit and retry everything else forever. Treating every exhausted prepare error as retryable would mean errors that never succeed on retry, like a bad config, never reach the user. The right fix is to retry only connection errors without a limit, and we don't have a helper to detect those in coderd/database yet. That covers every read in prepare, so I'll do it as a follow-up.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 3f3fa22bdd

ℹ️ 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 marked this pull request as ready for review October 8, 2026 01:40
@pr-queue-manager
pr-queue-manager Bot requested a review from ThomasK33 October 8, 2026 01:43
@ethanndickson
ethanndickson merged commit 4afd834 into main Oct 11, 2026
57 of 58 checks passed
@ethanndickson
ethanndickson deleted the ethanndickson/codagt-1330-turn branch October 11, 2026 22:53
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 11, 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