Skip to content

Look up the Claude OAuth email in the background - #923

Merged
Finesssee merged 5 commits into
mainfrom
fix/claude-oauth-email-background
Oct 20, 2026
Merged

Finesssee merged 5 commits into
mainfrom
fix/claude-oauth-email-background

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Claude OAuth account email no longer delays a usage refresh.

  • Before: fetch_with_credentials awaited GET /api/oauth/profile inline after the usage request, with a 5-second timeout, before it returned the result. A slow profile endpoint held back the quota refresh by up to 5 s. A failed lookup was retried every 15 minutes.
  • After: profile::display_email never waits. The first call for an access token starts one background lookup on the current Tokio runtime, bounded to 2 seconds for connect, response and body, and returns None. Later calls return the cached result. The lookup starts before the usage request, so a quick profile answer can still label the same refresh.
  • Ordering: the expiry and user:profile scope checks now run before the lookup starts (check_usage_credentials, shared with fetch_usage). Upstream validates the token before its profile lookup, so an expired or scope-less token sends no /profile request. The error returned for those tokens is unchanged.
  • Both outcomes are cached in memory, keyed by the token fingerprint: a found email for the life of the process, and a failure (error status, transport error, missing email, or timeout) until the token changes or CodexBar restarts. A new token never borrows another token's email.
  • The first refresh after launch, or after a token change, may show no email until the next refresh. This was accepted as a trade-off (decision D-4 in the gap report), as upstream does.
  • The email stays Claude-only. It is set only on the Claude OAuth UsageSnapshot for the same token, and the cache is private to providers/claude/oauth/profile.rs. No provider registration or shared code changed. Saved accounts (Show usage for every saved Claude account in the tray #910) each use their own token, so each gets its own email.
  • If there is no Tokio runtime, no lookup starts and nothing is cached.

Test seam

The profile URL is https://api.anthropic.com/api/oauth/profile. In tests only, a thread-local override (TEST_PROFILE_URL) points it at the mockito server, so the tests can count /profile requests. Production has no override path.

Upstream reference

  • Upstream v0.76.0 fix(claude): cache display email during OAuth refresh steipete/CodexBar#4538, commit 21dc8b66457813e98970573fda5c3b2bb22d726d (fix(claude): show the OAuth account email on ordinary refreshes; fixes Claude OAuth source still shows no account email (#567 regression / never fixed) — profile email is fetched but discarded steipete/CodexBar#4493). New ClaudeOAuthDisplayProfileCache.swift, wired from ClaudeUsageFetcher.swift.
  • Upstream check order in ClaudeUsageFetcher.swift (v0.77.0): validateRequiredOAuthScope, then the display-profile lookup, then fetchOAuthUsage.
  • Tests mirror Tests/CodexBarTests/ClaudeOAuthProfileIdentityTests.swift at 21dc8b664: same-token email cached and reused with one request, credential changes cannot borrow another token's email, a failed lookup is not retried for the same token, and a stalled lookup returns before its deadline and fails soft at the timeout with no retry. These run against a mockito server, plus a local TCP listener that accepts connections and never answers.
  • New tests on this head: expired_or_scope_less_tokens_send_no_profile_request (mockito expect(0) on /api/oauth/profile, with a 200 ms settle so a regression that starts a lookup would be caught) and its control a_valid_token_reaches_the_profile_endpoint (the same mock sees one request for a valid token).
  • Upstream's widget-owner verification path (A6) has no Windows counterpart and is out of scope.

Docs

No doc in docs/ describes the email lookup or a 15-minute email retry, so no doc changed. The CHANGELOG bullet now says the lookup runs only for a token that passes the expiry and scope checks. The CHANGELOG conflict from the newer origin/main was resolved by keeping both this bullet and main's new Settings bullet (settings.json unreadable file, #917).

Commands run

Head f54c5bf36 (merges origin/main through 60b589ec8, which includes #917; the ordering change is in 1c2a7340e):

  • cargo fmt --all -- --check: clean
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: clean
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings: clean
  • cargo test --manifest-path rust/Cargo.toml claude: 412 passed, 0 failed, 1 ignored (includes oauth::profile and the 2 new tests)

Earlier on the previous head 1c2a7340e: oauth::profile 10 passed; claude 412 passed on rerun. The first claude run there had 2 flakes outside the profile and fetch path (providers::claude::accounts::tests::same_email_and_different_organizations_remain_distinct, providers::claude::oauth::usage_gate::tests::consecutive_429s_escalate_even_after_the_block_expired); both passed alone and on rerun, and neither appeared on f54c5bf36. Full runs on the pre-merge head (not repeated on the newest head): cargo test --manifest-path rust/Cargo.toml 4795 passed; cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml 689 passed.

UI impact

No layout or frontend change. The Claude card's email row, which already exists, may be empty on the first OAuth refresh for a token and filled in from the next refresh on. Refreshes no longer wait for the profile lookup.

Merge note

This branch and #919 (Claude OAuth reset credits) both branch from bcdf20dd2. Both add a CHANGELOG.md bullet at the top of ## [Windows] Unreleased, and both edit fetch_with_credentials in rust/src/providers/claude/oauth/mod.rs in adjacent lines. Expect a small text conflict for whichever merges second. This branch was re-merged with origin/main after 60b589ec8 landed; #919 has not yet been merged into this branch, so it is expected to need a re-merge once #919 lands.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: nesszer/Win-CodexBar/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5e823a87-4f9f-4ecf-bde4-5988d6cb1d20
📥 Commits

Reviewing files that changed from the base of the PR and between 1ec6083 and cfcf6b1.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • rust/src/providers/claude/oauth/mod.rs
  • rust/src/providers/claude/oauth/profile.rs
+---------------------------------------+
| Execute order 66...to purge the bugs. |
+---------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Factory Agent added 3 commits October 19, 2026 02:22
The profile lookup now starts after the token's expiry and user:profile scope checks, as upstream validates before its lookup, so an expired or scope-less token sends no /profile request. The checks move into check_usage_credentials, which fetch_usage still runs. Tests assert no profile request for those tokens and that a valid token's lookup reaches the endpoint.
@Finesssee
Finesssee merged commit 7ce99dc into main Oct 20, 2026
1 of 3 checks passed
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.

Claude OAuth source still shows no account email (#567 regression / never fixed) — profile email is fetched but discarded

1 participant