You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched existing issues and did not find a duplicate.
I verified this on the current production released OpenCode version, or I explain why not below.
OpenCode version tested
1.18.30
opencode-quota version tested
4.9.0
Bug summary
For CREDIT_LIMIT quota windows (bigmodel.cn credit plans), percentRemaining is computed as 100 - limit.percentage, but the API's percentage field is integer-rounded. In the raw response below, percentage: 4 while exact usage is currentValue: 569 / usage: 12000 = 4.74% — so the sidebar shows 96% remaining when the exact value is 95.25%. The same response carries exact fields (usage, currentValue, remaining) that the calculation ignores.
#255 / #221 covered CREDIT_LIMIT windows being dropped entirely; once those windows are accepted (already fixed on main), this rounding is what the display shows. The rounding itself is still present on main.
Read the raw response for the 5h window: { "type": "CREDIT_LIMIT", "unit": 3, "usage": 12000, "currentValue": 569, "remaining": 11430, "percentage": 4 } — exact used = 569/12000 = 4.74%, but percentage is integer-rounded to 4.
matching remaining/usage = 11430/12000. Weekly window: 59430/60000 = 99.05% → 99. Only fall back to 100 - percentage when the absolute fields are missing.
Actual behavior
percentRemaining = clampPercent(100 - limit.percentage) = 96 — about a point off here, purely from the API's integer rounding of percentage.
Pre-flight checks
OpenCode version tested
1.18.30
opencode-quota version tested
4.9.0
Bug summary
For
CREDIT_LIMITquota windows (bigmodel.cn credit plans),percentRemainingis computed as100 - limit.percentage, but the API'spercentagefield is integer-rounded. In the raw response below,percentage: 4while exact usage iscurrentValue: 569 / usage: 12000= 4.74% — so the sidebar shows 96% remaining when the exact value is 95.25%. The same response carries exact fields (usage,currentValue,remaining) that the calculation ignores.#255 / #221 covered
CREDIT_LIMITwindows being dropped entirely; once those windows are accepted (already fixed on main), this rounding is what the display shows. The rounding itself is still present on main.Steps to reproduce
percentageis integer-rounded to 4.Expected behavior
When
usageandcurrentValueare present, percentRemaining should be derived from the exact absolute values:clampPercent(((limit.usage - limit.currentValue) / limit.usage) * 100) = 95.25 → 95
matching remaining/usage = 11430/12000. Weekly window: 59430/60000 = 99.05% → 99. Only fall back to
100 - percentagewhen the absolute fields are missing.Actual behavior
percentRemaining = clampPercent(100 - limit.percentage) = 96 — about a point off here, purely from the API's integer rounding of
percentage.Root cause
src/lib/glm-coding-plan.ts(unchanged on main):limit.percentageis the API's rounded value; the exactusage/currentValuefields in the same response are ignored.Suggested fix
Prefer exact absolute values for
CREDIT_LIMIT, falling back topercentageonly when they are missing:Applied locally and verified: 5h window shows 95 (exact 95.25%), weekly 99 (exact 99.05%), matching remaining/usage exactly (11430/12000, 59430/60000).
Context: #255 / #221 covered
CREDIT_LIMITwindows being dropped entirely; this is the precision issue that remains once those windows are accepted.Relevant logs/output
GET https://bigmodel.cn/api/monitor/usage/quota/limit (raw response): { "code": 200, "msg": "操作成功", "data": { "limits": [ { "type": "CREDIT_LIMIT", "unit": 3, "usage": 12000, "currentValue": 569, "remaining": 11430, "percentage": 4, "nextResetTime": 1789108583924 }, { "type": "CREDIT_LIMIT", "unit": 6, "usage": 60000, "currentValue": 569, "remaining": 59430, "percentage": 1, "nextResetTime": 1789694887987 } ] }, "success": true } 5h window, rounded vs exact: 100 - percentage(4) = 96 (current code) (12000 - 569) / 12000 * 100 = 95.25 (exact) weekly window: 100 - percentage(1) = 99 (current code) (60000 - 569) / 60000 * 100 = 99.05 (exact)If not tested on current production OpenCode, explain why
No response