Skip to content

🤖 fix: report an unreadable 2xx create answer as an uncertain 504 - #241

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/uncertain-create-2xx
Oct 13, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/uncertain-create-2xx

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

When a create of a coderworkspace or a codertemplate gets a 2xx answer from Coder that the SDK cannot read, the aggregated API server now returns 504 with an "uncertain, re-read before you retry" message. It used to return a plain 500 that contained the Coder URL. This is note (b) from the final review of #163.

Refs #163

Background

Since codersdk v2.37 (#163), a 2xx response whose body is not JSON is a *codersdk.Error with that 2xx status. For example, a proxy in front of Coder can send an HTML page. A non-201 2xx on a POST that expects 201 was already such an error before. MapCoderError sends any 5xx-or-other status to its default branch, so a create answered this way became 500 InternalError, with err.Error() as its text (POST https://<coder>/api/v2/...: invalid API response (status code 200) ...).

But a 2xx means the POST got through. Coder can have created the object. A plain 500 does not tell the client to check that before it retries. The docs already promise "After a 504 on a write, the result is not certain. Re-read the object with kubectl get before you retry". Workspace start and stop already answer an uncertain 504 for the same 2xx case (isUncertainStatus in workspace_transition.go, #163).

Note (a) from the same review is not in this PR. It does not apply, because go-sdk v1.7.0 marks StreamableHTTPOptions.CrossOriginProtection Deprecated and recommends the outer http.NewCrossOriginProtection().Handler(...) wrapper that internal/app/mcpapp/http.go already uses (vendor/github.com/modelcontextprotocol/go-sdk/mcp/streamable.go:184-196).

Implementation

  • New coder.MapCoderCreateError (internal/aggregated/coder/errors.go). A *codersdk.Error with a 2xx status becomes apierrors.NewTimeoutError(..., 0): 504, reason Timeout. The message names the resource, the object and the status, and says that the result is uncertain and that the client must re-read the object before it retries. It leaves out the Coder URL. RetryAfterSeconds is 0, so the server sends no Retry-After header and client-go does not send the create again on its own. Every other error maps exactly as in MapCoderError.
  • It is used at the three Coder POSTs that create the Kubernetes object: CreateUserWorkspace and both CreateTemplate calls (with and without spec.files). Server-side apply create-on-update calls the same Create, so it is covered too.
  • The file upload and the template-version POST before CreateTemplate are unchanged. When they fail, the template does not exist yet, so a retry cannot duplicate it.
  • Docs: the "Coder timeouts" section and its summary row in docs/reference/aggregated-api-behavior.md describe the new 504.

Validation

  • TestMapCoderCreateError: 200, 201 and 204 map to 504 with the uncertain message, without the URL and without Retry-After. 409, 400, 502, 300 and a transport error map the same as MapCoderError.
  • TestCreateWithUnreadable2xxAnswerIsUncertain: a test proxy lets the mock Coder create the object, then answers 200 or 201 with an HTML page. For a workspace, a template without files and a template with files, the create returns the uncertain 504, and the object exists in the mock Coder. On main, each case fails with Internal error occurred: POST http://127.0.0.1:<port>/api/v2/.... I also reverted each of the three call sites alone and saw its case fail.

Risks

Low. Only creates whose Coder answer is a 2xx *codersdk.Error change, from 500 to 504. Both are server errors, and neither carries Retry-After. The status reason changes from InternalError to Timeout.


Generated with mux • Model: anthropic:claude-opus-5-5 • Thinking: high

#163)

Change-Id: Idb95ec07d36db8f82ba80ead3a0bcdc6f6c233f8
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T14:18:16.778320Z 52d51bc Manual request
🔒 Security Review ✅ Completed 2026-10-13T14:16:49.774940Z 52d51bc Manual request
ℹ️ 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.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: aebc7778d1

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: aebc7778d1

ℹ️ 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 internal/aggregated/coder/errors.go
Comment thread internal/aggregated/coder/errors.go
…reate docs

Change-Id: I43e7fae2c7dde08c7ac7be4dfb2cb1fedd0009db
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0350910c0d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 0350910c0d

ℹ️ 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 docs/reference/aggregated-api-behavior.md Outdated
Comment thread internal/aggregated/coder/errors.go
Change-Id: I58136a816d42bfbae8247eaf8b1492d1213474b3
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 52d51bc5ec

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 52d51bc5ec

ℹ️ 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 docs/reference/aggregated-api-behavior.md
@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit f9198ca Oct 13, 2026
13 checks passed
@ThomasK33
ThomasK33 deleted the fix/uncertain-create-2xx branch October 13, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant