Skip to content

🤖 fix: trust only Coder's own 404 when deleting AI Gateway keys - #341

Merged
ThomasK33 merged 1 commit into
mainfrom
feat/ai-gateway-key-delete-404
Oct 14, 2026
Merged

ThomasK33 merged 1 commit into
mainfrom
feat/ai-gateway-key-delete-404

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

K10a of #156: a gate before activation. When the controller deletes an AI Gateway key, only Coder's own 404 now proves that the key is gone. The controller is still unregistered. K10 (activation) follows on top of this branch.

What changes

  1. Only Coder's own 404 counts as gone. The sweep, the retire step and the deletion path (deleteOwnKey and deleteKeys) used to accept any 404 except Route not found.. An HTML 404 from a proxy, or any other 404, counted as "the key is gone". The controller then dropped a retiring key from status, or released the finalizer, while the key could still work. These calls now use isCoderResourceNotFound (from 🤖 fix: check a CoderAIProvider's provider ID before Coder calls, and trust only Coder's own delete 404 #325). It accepts only Coder's Resource not found or you do not have access to this resource answer, which DELETE /api/v2/ai-gateway/keys/{key} sends for a missing key (enterprise/coderd/aigatewaykeys.go:178-180 in v2.37.3). Any other 404 is CoderUnavailable and retries. Route not found. is still the NotSupported stall, as before. coderRouteMissing is gone.
  2. The bounded pass names what it left (K9 notes item p). While the control plane is being deleted, a failed pass now logs the IDs of the keys that its own LIST showed and that it did not delete (listedKeyIDs), next to the key IDs from status.
  3. A test for K9 notes item (t). After a kill-switch re-arm, a mismatched create answer blocks every later create in that generation, also across a failed LIST and the settle window.

Tests

  • TestCoderAIGatewayKeyProxyNotFoundDeletesNothing: an HTML 404 on a sweep DELETE keeps the orphan, and the next reconcile deletes it. An HTML 404 on a retire DELETE keeps the key in retiringKeys, and the next reconcile deletes it.
  • TestCoderAIGatewayKeyDeleteRetries has a new "proxy 404" case: the finalizer stays, with CoderUnavailable and a 60 s requeue, and the next reconcile releases it.
  • TestCoderAIGatewayKeyDeleteWithControlPlaneGoing: in the failing namespace-deletion case, the release log names an orphan that only the pass's LIST knows.
  • TestCoderAIGatewayKeyRearmKeepsAnswerMismatchGate (item t).

Mutations that the tests catch:

  • isCoderNotFound (any 404) in deleteOwnKey;
  • isCoderNotFound in deleteKeys;
  • the release log without the pass's leftover IDs.

Size: 130 lines added and 34 removed, of which about 95 are tests.

Local gates on the head:

  • make verify-vendor, make build, make lint, make test, make test-integration.
  • go tool govulncheck ./....
  • go test -race ./internal/controller/....
  • make codegen, make build-installer and make docs-reference leave no drift.

Refs #156


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $136.24

Change-Id: I9e7b6f5ea04db940c6bd982d0a861a9a811ee0f6
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T07:39:13.041935Z 6a14d5b PR opened
🔒 Security Review ✅ Completed 2026-10-14T07:41:46.870224Z 6a14d5b 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: 6a14d5bb52

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.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit a7be8b4 Oct 14, 2026
10 checks passed
@ThomasK33
ThomasK33 deleted the feat/ai-gateway-key-delete-404 branch October 14, 2026 11:47
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