opencode-mystatus
opencode-mystatus copied to clipboard
Bug:find() only shows first TOKENS_LIMIT, hides exhausted quota pool
Bug Description
The find() in plugin/lib/zhipu.ts only picks the first TOKENS_LIMIT, so when the API returns multiple token quota windows, only the most lenient one is shown. The potentially exhausted limit pool is silently hidden.
Steps to Reproduce
- Use GLM Coding Plan Pro tier
- Call
/mystatus - Observe output — only one Token limit shown
Actual API Response
API returns two TOKENS_LIMIT entries:
{
"code": 200,
"data": {
"limits": [
{ "type": "TOKENS_LIMIT", "unit": 3, "number": 5, "percentage": 22 },
{ "type": "TOKENS_LIMIT", "unit": 6, "number": 1, "percentage": 81 },
{ "type": "TIME_LIMIT", "unit": 5, "number": 1, "usage": 1000, "currentValue": 160, "percentage": 16 }
],
"level": "pro"
}
}
Root Cause
In formatZhipuUsage:
const tokensLimit = limits.find((l) => l.type === "TOKENS_LIMIT");
find() returns only the first match (3h window, 22% used), ignoring the second (6h window, 81% used, near exhaustion).
Users see optimistic quota info and cannot anticipate imminent rate limiting.
Suggested Fix
Option A: Show all TOKENS_LIMIT entries
const tokensLimits = limits.filter((l) => l.type === "TOKENS_LIMIT");
Option B: Pick the highest percentage (most urgent)
const tokensLimit = limits
.filter((l) => l.type === "TOKENS_LIMIT")
.reduce((max, l) => l.percentage > max.percentage ? l : max);
Environment
- Plan: GLM Coding Plan Pro
- opencode-mystatus: latest (npm)
- OS: Windows 11