Repository navigation
fix(quota): decode fractional quota percentages from usage dashboard - #193
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The iOS client showed "cannot parse usage dashboard API response". The usage dashboard backend changed
used_percentage/remaining_percentagefrominttofloat(ai_usage_dashboard PR #51), soGET /api/v1/quotasnow returns fractional values such as1.6,18.9,0.70968, and9.606333333333334.AIUsageQuotadecoded these fields asInt. Swift'sJSONDecoderfails the entirequotasarray on any fractional number, so one provider with a fractional percentage (ollama, antigravity, cursor) broke the whole response.Fix
Doubleand round toInt, preserving the existing display types and clamping behavior.Testing
./scripts/test_unit.shwithOPENCODE_TEST_ONLY='OpenCodeClientTests/AIUsageQuotaTests': 12/12 pass, including the two new cases.