fix(grok): fail over OAuth credential errors safely#4212
Conversation
5c1b89d to
09cc482
Compare
|
Follow-up review for the newly reported Grok issues is now included in this draft.
The branch was rebased onto current |
c0ee592 to
7e27407
Compare
7e27407 to
678280c
Compare
678280c to
4c764d3
Compare
|
@Wei-Shaw This is ready for maintainer review. Revalidated head 4c764d3: CI and Security Scan green; exact-head tests plus combined full backend unit/integration, vet, frontend typecheck/lint/build, and 1,018 frontend tests passed. A private combined deployment passed separate Grok OAuth and API-key text plus image canaries with expected usage attribution. Recent #4254 and #4263 overlap only bounded slices and do not replace this PRs credential-failure, CAS, URL-policy, media, and cross-handler scope. Please review when convenient. |
Summary
This is the request-path half of the Grok OAuth incident fix in #4189, extended with the request-path defects confirmed in #4215 and #4213.
The verified #4189 failure mode was that Grok token acquisition returned ordinary errors, while handler account switching only recognized the upstream failover signal. A revoked OAuth credential could therefore be disabled but still terminate the request as a generic 502 instead of selecting another healthy account.
This draft:
account_authwith inferenceupstream_status=0, including recovered provider-health rows;Additional issue coverage
#4215 — fixed in this draft
(rate_limited_at, reset_at)Grok OAuth generation. The repository CAS rejects newer generations, shorter clear/re-arm generations, and rows retyped to API-key while the request was in flight.#4213 — fixed in this draft
Current
mainalready accepts public HTTPS custom Grok API-key hosts. This draft completes that support across live Responses/chat/media, account tests, and quota probes by applying the configured global URL policy consistently:cli-chat-proxy.grok.comand never inherit the API-key URL policy.#4199 — evidence gap, not claimed fixed
The report contains a redacted generic 502 but still lacks the auth type, failing hop, version, payload shape, and same-key/model/body direct-vs-Sub2API reproduction needed to prove a Sub2API defect. This draft includes adjacent API-key routing, auth-header, URL-policy, and 429 non-regression coverage, but #4199 should remain open pending reproducible evidence.
PR #4221 remains independent and unchanged; it covers proactive OAuth pool health rather than request-path behavior.
Safety boundaries
cli-chat-proxy.grok.com.Verification
All commands below passed locally after rebasing onto current
origin/main(74e78c3de0784747fe079d448f088a61a01ff29f):make test-unit;make test-integration;go test -race -tags=unit ./internal/service -run 'TestShouldStopOpenAIOAuth429Failover|TestUpdateGrokUsageFromResponse|TestForwardGrokResponsesNonStreamingUsesCacheIdentityAndCachedUsage|TestGrokQuotaServiceProbeUsageStoresNoHeadersState|TestGrokRateLimitResetAtForAccount' -count=1;go test -race -tags=unit ./internal/handler -run 'TestResponsesGrok429FailoverIsBounded|TestResponsesGrok429FailoverHandlesMixedStatuses|TestGrokMedia429FailoverIsBounded|TestGrokOAuthCredentialFailoverAcrossHTTPHandlers' -count=1;go test -race -tags=integration ./internal/repository -run 'TestAccountRepoSuite/TestClearRateLimitIfObservedProtectsRearmed429Generation' -count=1;go vet ./internal/pkg/xai ./internal/service ./internal/handler ./internal/repository;git diff --check origin/main...HEAD.Independent backend, SRE/concurrency, API-test, request-path, and final full-diff reviews found no remaining actionable issue.
Part of #4189. Fixes #4215. Fixes #4213.