Repository navigation
Commit 3372652
authored
🤖 fix: trust only Coder's own 404 on the CoderAIProvider create lookups (#350)
## Summary
The `CoderAIProvider` create path now trusts only Coder's own 404 on its
name lookups, as the delete path (#325) and the sync and disable paths
(#335) already do.
Fixes #338
Refs #154
## Why
A 404 that Coder did not send (an HTML page from a proxy, or Coder's
`Route not found.` for a wrong base URL) counted as "no such provider"
in two places in `internal/controller/coderaiprovider_create.go`:
1. The name lookup before a create, which also confirms a pending create
(`createOrConfirm`). With a create marker, such a 404 could clear the
marker of a create that committed. A delete at that point released the
finalizer without a delete in Coder, and Coder kept a provider that
holds the key. Coder created that provider with `enabled: false`, so it
did not use the key.
2. The read after a rejected create (`confirmRejectedCreate`). Such a
404 cleared the marker in the same way.
## What
Both lookups use `isCoderResourceNotFound`: a 404 whose message is
Coder's fixed `Resource not found or you do not have access to this
resource`. Any other answer falls through to the existing waits. The
lookup waits with `CoderUnavailable` (30 s), keeps the marker and sends
no create. After a rejected create, the object waits with
`ConfirmingRejectedCreate` and keeps the marker.
Docs nit from #338: the credential kill switch paragraph in
`docs/how-to/manage-ai-providers.md` now says that a failed Coder call
for the disable, including a 404 that Coder did not send, retries every
30 seconds with a message that starts with `Coder can still send the
key`.
## Tests
- `TestCoderAIProviderCreateLookupNotCoder404`: an HTML 404 and `Route
not found.` on the name lookup, for a new create and for a pending
create whose create committed. Each one waits with `CoderUnavailable`,
sends no create, and a pending create keeps its marker. The next
reconcile is `Ready`, with one provider in Coder.
- `TestCoderAIProviderRejectedCreateNotCoder404`: after a 400 create
answer, a non-Coder 404 on the confirmation read keeps the marker
(`ConfirmingRejectedCreate`). The next read stalls with `CoderRejected`,
and the create is not sent again.
- The existing name-conflict test now injects Coder's own 404 message.
Mutation checks (each one breaks a named test, then I reverted it):
`isCoderNotFound` back on the name lookup, and on the read after a
rejected create.
Local gates on the pushed tree, exit 0 each: `make verify-vendor`, `make
test`, `make test-integration`, `make build`, `make lint`, `go tool
govulncheck ./...`, `go test -race ./internal/controller/`, `make
codegen manifests build-installer docs-reference` with no diff, and
`make docs-check`. Before the rebase, two runs of `make test` and one
race run failed with envtest timeouts (`timeout waiting for process
kube-apiserver to stop`) while the host load average was about 130.
Those runs failed outside this change, and all gates pass on this tree.
---
_Generated with `mux` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$129.14`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=129.14 -->
Signed-off-by: Thomas Kosiewski <tk@coder.com>1 parent 06ce2b9 commit 3372652
3 files changed
Lines changed: 70 additions & 4 deletions
File tree
- docs/how-to
- internal/controller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
195 | | - | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
287 | | - | |
| 289 | + | |
288 | 290 | | |
289 | 291 | | |
290 | 292 | | |
| |||
371 | 373 | | |
372 | 374 | | |
373 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
0 commit comments