fix: honor Codex OAuth source for credits refresh#1054
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6755342a94
ℹ️ 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".
| let descriptor = self.providerSpecs[.codex]?.descriptor ?? ProviderDescriptorRegistry.descriptor(for: .codex) | ||
| let context = self.makeFetchContext(provider: .codex, override: nil, includeCredits: true) | ||
| let outcome = await descriptor.fetchOutcome(context: context) |
There was a problem hiding this comment.
Keep credits refresh from depending on usage snapshot
Routing credits refresh through descriptor.fetchOutcome makes the result hinge on strategies that require a non-nil usage snapshot, which regresses CLI-mode credits refresh when Codex RPC returns credits but no usage windows. In that case CodexCLIUsageStrategy.fetch throws UsageError.noRateLimitsFound even though credits exist, so refreshCreditsIfNeeded now fails where the previous direct loadLatestCredits() call succeeded; this affects users with explicit .cli (and some .auto fallback) source modes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bbb677e by preserving CLI credits-only refresh when RPC returns credits without rate-limit windows. Added regression coverage for that exact case in CodexBaselineCharacterizationTests.
Summary
Why
Normal Codex usage refreshes already honor the configured source mode, but credits refresh bypassed that path and called the CLI credits fetcher directly. That could still hit the CLI/RPC path even when Codex was configured for OAuth.
Fixes #1048
Validation
swift test --filter CodexAccountScopedRefreshTestsmake checkTZ=UTC swift test