Files
codex-proxy-rs/docs
47ccdeb737 fix(openai): preserve OAuth recovery and token rotation (#853)
* fix(openai): refresh OAuth tokens rejected before expiry

A 401 on a model request marked a refreshable OAuth account Expired when
its access token had not reached its expiry. Expired accounts are left out
of both selection and scheduled refresh, so the account stayed out of
rotation until it was refreshed by hand, even though the refresh token was
still valid.

Expire the rejected access token instead and let the OAuth worker renew
it, as quota refresh already does for token_revoked. A renewed token that
is rejected again before any successful request still marks the account
Expired.

Constraint: Accounts without a refresh token or a known expiry keep the existing Expired outcome
Rejected: Match the "status=503" text inside the 401 body | free-text matching, and other 401s on unexpired tokens would still strand the account
Rejected: Refresh on every 401 without a bound | an account whose renewed tokens keep failing would refresh in a loop
Confidence: high
Scope-risk: narrow
Tested: Rust 1.99.1 fmt --check; clippy -p provider-openai --all-targets --all-features -D warnings; provider-openai tests (1264 passed); the new selector case and the adapter case fail without the selector change
Not-tested: A live upstream 401 against this build; workspace-wide clippy and tests are left to CI

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(openai): preserve OAuth recovery across concurrent feedback

Report success from native endpoints and upstream adapters, and keep stale
responses from clearing the current OAuth recovery bound. Serialize model
401 and Cookie feedback with token refresh through the account lease.
Recheck credential revisions after acquiring scheduled and manual refresh
leases so a queued snapshot cannot resend an already rotated refresh token.

Cookie feedback skips writes while refresh owns the lease; a later response
can capture cookies without discarding successfully exchanged tokens.

Validated: workspace fmt and strict Clippy; 1265 provider-openai tests;
48 gateway architecture and bootstrap tests. Real upstream and store service
integration remain for live verification and CI.

Co-authored-by: Codex <noreply@openai.com>

* fix(openai): retain token recovery across cookie revisions

Use the access token and revision that were sent upstream to recognize a successful OAuth request after a concurrent cookie write. Keep account and quota recovery fenced by revision, and preserve newer rejection records and replies from superseded tokens.

Co-authored-by: Codex <noreply@openai.com>

* fix(openai): preserve account feedback across cookie writes

Reset consecutive Cloudflare failures on a successful request using the current access token. Keep quota and account state fenced by the response revision. A model 401 can shorten expiry while the cookie writer holds the refresh lease; a conflicting write is retried only for the same token.

Co-authored-by: Codex <noreply@openai.com>

* test(openai): separate risk counters from OAuth rejection

Verify that a successful request using the rejected token breaks a path-block streak without allowing a refreshed token to be rejected indefinitely.

Co-authored-by: Codex <noreply@openai.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
2026-12-05 14:00:11 +08:00
..