Claude Enterprise web usage: support org/member overage limits and hide empty session metrics#405
Claude Enterprise web usage: support org/member overage limits and hide empty session metrics#405mkkim417 wants to merge 3 commits intosteipete:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08ba0ad64a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| var sessionPercent: Double = 0 | ||
| var sessionResets: Date? | ||
| if let fiveHour = json["five_hour"] as? [String: Any] { | ||
| if let utilization = fiveHour["utilization"] as? Int { | ||
| sessionPercent = Double(utilization) | ||
| if let utilization = fiveHour["utilization"] as? NSNumber { | ||
| sessionPercent = utilization.doubleValue | ||
| } |
There was a problem hiding this comment.
Validate session window before accepting web usage payload
In ClaudeWebAPIFetcher.parseUsageResponse, sessionPercent now defaults to 0 and the function no longer rejects responses missing five_hour.utilization, so any HTTP 200 JSON body without usage windows is treated as successful usage data. In auto mode this suppresses the intended fallback path and can surface fabricated 0% used metrics instead of an error/fallback result, which is a regression from the previous invalidResponse behavior for malformed payloads.
Useful? React with 👍 / 👎.
| guard usage.primary.usedPercent == 0 else { return false } | ||
| guard usage.primary.resetsAt == nil, usage.primary.resetDescription == nil else { return false } | ||
| // Web path provides account identity; OAuth generally does not. | ||
| guard usage.accountEmail != nil else { return false } |
There was a problem hiding this comment.
Do not gate null-window hiding on account email availability
shouldHideUsageMetrics requires accountEmail != nil, but account info is fetched best-effort and can independently fail even when /usage succeeds with all-null enterprise windows. In that case the new parser still maps usage to 0 while this guard prevents suppression, so users continue to see the misleading session metric this change is trying to eliminate; the condition should be based on the usage-window shape/source, not whether /account happened to return email.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9932f67a5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
|
|
||
| @Test | ||
| func parsesClaudeWebAPIUsageResponseWhenAllUsageWindowsAreNull() throws { |
There was a problem hiding this comment.
Preserve @test annotation for overage spend limit case
This insertion reuses the existing @Test attribute for the new parsesClaudeWebAPIUsageResponseWhenAllUsageWindowsAreNull method, which leaves the following parsesClaudeWebAPIOverageSpendLimit function unannotated and therefore undiscovered by Swift Testing. In practice, that baseline overage parsing check silently stops running in CI, so regressions in _parseOverageSpendLimitForTesting can slip through without signal.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary
This PR improves Claude Enterprise behavior in the web data source path.
What was happening
For some Enterprise accounts, CodexBar showed:
Invalid response from Claude API, or200but all usage windows werenull.Root cause
GET /api/organizations/{orgId}/usagecan return all usage windows asnullfor Enterprise contexts.GET /api/organizations/{orgId}/overage_spend_limitwithoutaccount_uuidcan return organization-level values (limit_type=organization) instead of member-specific values.What changed
usageresponses where session/weekly windows arenullwithout failing the fetch.GET /api/account.GET /api/organizations/{orgId}/overage_spend_limit?account_uuid={accountUUID}Before / After
Before
Invalid response from Claude APIin Enterprise cases, or usage bars shown with no real usage window data.After
account_uuidis available.Screenshots
Validation
swift test --filter ClaudeUsageTests./Scripts/compile_and_run.sh(run locally)Notes