Files
Sas SwartandClaude Opus 5.5 1ec94c74dc fix(coderd): return 500, not 403, when AI Gateway authorization hits a database error (#31617)
When coderd's `IsAuthorized` hits a database error, the AI Gateway
answers 403. A coderd outage therefore looks to clients like a
permission problem. The gateway can't tell coderd's own failures from
rejected requests, because coderd returns both as plain errors. Worse,
the API key and user lookups turn any database error into
`ErrUnknownKey` or `ErrUnknownUser`.

coderd now marks each database failure in `IsAuthorized` with the dRPC
error code `proto.ErrCodeInternal`, where the failure happens. This
covers the key, user, workspace, organization membership and effective
group lookups. The key and user lookups return `ErrUnknownKey` and
`ErrUnknownUser` only for `sql.ErrNoRows`. Rejections carry no code. The
gateway answers a coded error with 500 and every other error with 403.

dRPC sends the code with the error, so the protocol version doesn't
change. A gateway and coderd on different versions keep today's 403,
because the older side neither sets nor reads the code.

A connection that drops during the `IsAuthorized` call still gets a 403.
That's left for a follow-up.

`TestAuthorization_InternalErrors` covers each database failure and each
rejection on the direct, workspace token and delegated paths.
`TestServeHTTP_FailureModes` covers the gateway's status codes.

Refs AIGOV-737

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 07:39:54 +02:00
..