Skip to content

fix(quota): decode fractional quota percentages from usage dashboard - #193

Merged
grapeot merged 1 commit into
masterfrom
fix/quota-fractional-percentage-decode
Oct 9, 2026
Merged

grapeot merged 1 commit into
masterfrom
fix/quota-fractional-percentage-decode

Conversation

@grapeot

@grapeot grapeot commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Problem

The iOS client showed "cannot parse usage dashboard API response". The usage dashboard backend changed used_percentage / remaining_percentage from int to float (ai_usage_dashboard PR #51), so GET /api/v1/quotas now returns fractional values such as 1.6, 18.9, 0.70968, and 9.606333333333334.

AIUsageQuota decoded these fields as Int. Swift's JSONDecoder fails the entire quotas array on any fractional number, so one provider with a fractional percentage (ollama, antigravity, cursor) broke the whole response.

Fix

  • Decode the percentage fields as Double and round to Int, preserving the existing display types and clamping behavior.
  • Guard against non-finite or out-of-range values so a malformed payload throws a typed decoding error instead of trapping.
  • Add regression tests for fractional values and whole-number-as-float values.

Testing

./scripts/test_unit.sh with OPENCODE_TEST_ONLY='OpenCodeClientTests/AIUsageQuotaTests': 12/12 pass, including the two new cases.

The usage dashboard now emits fractional percentage fields
(used_percentage/remaining_percentage), e.g. 1.6 and 9.606, after the
server changed them from int to float. AIUsageQuota decoded these as Int,
so JSONDecoder failed the entire quotas array and the client surfaced
"cannot parse usage dashboard API response".

Decode the percentage fields as Double and round to Int, with a finite
and in-range guard so a malformed value throws a typed decoding error
instead of trapping. Add regression tests for fractional and
whole-number-as-float payloads.
@grapeot
grapeot merged commit 7c669cf into master Oct 9, 2026
@grapeot
grapeot deleted the fix/quota-fractional-percentage-decode branch October 9, 2026 00:41
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