Skip to content

refactor(auth): one OAuth grant contract and device-poll loop for every provider (ENG-1066) - #376

Merged
lg2m merged 5 commits into
mainfrom
refactor/eng-1066-ap8-oauth-grants
Oct 20, 2026
Merged

lg2m merged 5 commits into
mainfrom
refactor/eng-1066-ap8-oauth-grants

Conversation

@lg2m

@lg2m lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Slice AP8 of the auth-providers plan (ENG-1066), after #373.

What changed

No user-visible change. OAuth grants in qq-auth no longer have one client per provider:

  • One transport. CodexTokenClient, CodexDeviceClient, XaiTokenClient and their three fields on CredentialStore become one oauth::OAuthTransport (post(OAuthRequest) -> OAuthResponse | TransportError). Every token exchange, refresh, device start and device poll goes through it. OAuthResponse carries the status and a bounded body (None when unreadable or oversized). SystemTransport is the HTTPS client from before (https-only, no redirects, same timeouts).
  • Providers keep only endpoint specs and response mapping. codex.rs and xai.rs build their requests: Codex sends a form exchange and a JSON refresh, its device endpoints take JSON, and xAI uses forms. Each decodes into its own unchanged error enum, so error variants and text stay the same.
  • One RFC 8628 poll loop. oauth::poll_device takes an injectable clock, cancellation and sleep, and handles pending, slow_down (+5s, capped), denied, expired, deadline and cancellation. It checks cancellation and the deadline around every wait and poll. xAI's XaiLogin::complete now runs on it instead of its own thread::sleep loop. Codex's non-standard device flow (403/404 means pending, then a PKCE exchange) stays a Codex grant: it uses the shared loop for polling and the shared exchange afterwards, with every deadline and cancellation check it had.
  • Derived locks. A provider's operation lock is {provider}.lock (CredentialPaths::provider_lock_file, CredentialStore::lock_provider_file), which reproduces openai-codex.lock and xai.lock. A new OAuth provider needs no lock definition.
  • The loopback PKCE callback stays Codex-local. CredentialStore::offline() and OfflineTokenCalls (used by the perf fixtures) implement the transport and still count every refused call.

Verification

  • All 88 existing qq-auth tests keep their scenarios and assertions. Their fakes keep their names and recorded calls, now as test-only traits behind one FakeOAuth transport that decodes each request and encodes the response the real endpoint would send.
  • New: device_polling_waits_one_interval_per_pending_poll_then_completes, …_slows_down_by_five_seconds_up_to_the_cap, …_reports_denial_and_expiry, …_stops_at_the_deadline_without_oversleeping, …_stops_when_cancelled_without_polling_again, lock_files_are_derived_from_the_provider_name, and a_new_provider_serialises_independent_stores_through_its_derived_lock (a fixture-oauth provider with no legacy file; a second store waits on the derived lock while the legacy locks stay free).
  • oauth_operations_lock_the_published_per_provider_files still pins both legacy names.
  • cargo xtask check passed; cargo xtask smoke 9/9; xtask credential perf fixtures pass.

Known differences

  • xAI login now also checks the deadline after each poll returns, as Codex already did. A poll that completes after the device code's lifetime is reported as timed out instead of being stored.
  • The shared loop has a cancellation hook. The CLI never cancels an xAI login; a cancelled runtime would report it as timed out.
  • xtask/src/legacy-sleeps.txt: one existing entry moved lines; no new sleeps.

…ry provider (ENG-1066)

The Codex token, Codex device and xAI token client traits, and their three
fields on CredentialStore, become one OAuthTransport that every exchange,
refresh, device start and device poll goes through. Codex and xAI keep
only their endpoint specs and response mapping. xAI's device login and
Codex's device flow run on one RFC 8628 poll loop with an injectable
clock, cancellation and sleep. Operation lock files are derived as
{provider}.lock, which keeps openai-codex.lock and xai.lock.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T07:12:39.973155Z f8d8234 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1951729cbf

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-auth/src/xai.rs Resolved
…NG-1066)

A stalled token endpoint could hold an xAI login past its device code's
lifetime and end it as a failed request. Each poll now carries the time
left as its request timeout, and a poll that runs it out ends the login
as AuthorizationTimedOut.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ecd759b6f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-auth/src/oauth.rs Resolved
Comment thread crates/qq-auth/src/lib.rs Resolved
…ep body timeouts (ENG-1066)

OAuthProvider becomes a table of rows (name and lock error), so set,
remove and refresh find a new provider's {provider}.lock from its
credential prefix without per-variant matches. A response body that
stalls past the request timeout is now TransportError::TimedOut instead
of an unreadable body.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54996f1f58

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-auth/src/xai.rs Resolved
Comment thread crates/qq-auth/src/codex.rs Resolved
…deadline errors (ENG-1066)

A request's deadline now only shortens the transport's 60-second cap, so a
stalled xAI poll with a long device lifetime still fails at the cap. Only
a timeout the request's own shorter deadline caused is DeadlineReached;
the browser Codex exchange carries none, so a stalled body there is an
ordinary exchange failure, not a device-authorization timeout.
@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a9233445d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-auth/src/oauth.rs Resolved
Comment thread crates/qq-auth/src/oauth.rs Resolved
… rejection statuses (ENG-1066)

A timeout is DeadlineReached only when the call actually ran out the
caller's shorter deadline; a connect-timeout or the transport cap firing
first is an ordinary failure. A non-success response keeps its status
when its body stalls, so providers map it from the status as before.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: f8d8234d3f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lg2m
lg2m merged commit 130b279 into main Oct 20, 2026
6 checks passed
@lg2m
lg2m deleted the refactor/eng-1066-ap8-oauth-grants branch October 20, 2026 07:22
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