fix(chutes): keep usage percent in 0..=100 units - #409
Conversation
The quota key scan treated values in (0, 1] as 0..=1 fractions and rescaled them, turning a real 1% into a false 100% exhausted state (#408; same class as #247 / upstream steipete#3216, fixed for opencodego in #407). Chutes returns whole percentages; clamp instead of rescale.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughChutes usage parsing now treats provider values as percentages from ChangesChutes usage reporting
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change corrects Chutes usage percentages so values such as 1% and 0.5% are no longer overstated, while preserving the existing bounded 0–100% behavior. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
VerdictApprove. The change deletes an ambiguous heuristic instead of rearranging complexity — the right shape for a unit-contract bug. StructuralRemoved the No spaghetti growthOne file, +34/−3 across the two commits. The Test disciplineThree regression tests were committed first and observed failing (1 → 100 and 0.5 → 50 reproduced the bug before the fix), then pass after — proper test-first sequencing. All 7 chutes tests pass on the head commit. Evidence honestyThe PR body states plainly that the Chutes docs are silent on percent fields (empty response schema in the OpenAPI spec; the documented payload carries only counts) and names the residual risk if a genuine fraction field ever appears. That is the right call — the previous heuristic was strictly worse regardless. Reviewer verificationFocused suite Note: a formal GitHub "Approve" review is not possible here — the review identity is the PR author ( |
Why
percent_from_objectinrust/src/providers/chutes/mod.rsapplied an ambiguous fraction heuristic: any value<= 1.0found under theusage_percent/usagePercent/percent_used/percentUsedkeys was rescaled by 100. A real whole 1% satisfiedv <= 1.0and became a false 100% exhausted state; a real 0.5% became 50%. This is the same bug class already fixed for the OpenCode Go API path in #407 (and #247 / upstream steipete#3216 before that).Fixes #408.
Unit-contract evidence
https://api.chutes.ai/openapi.json) definesGET /users/me/subscription_usagebut leaves its 200 response schema empty ({}); no schema incomponents/schemascontains a percent-named field. The official docs (https://chutes.ai/docs/api-reference/users,https://chutes.ai/llms-full.txt) likewise document no percent field for any usage/quota endpoint."four_hour": {"usage": 0.86, "cap": 4.17, "remaining": 3.31, "reset_at": ...}(USD-denominated usage vs cap) — no percent keys at all.percent_from_objectis reached viacollect_windows, which recursively scans arbitrary nested JSON, the key list may fire on payloads the docs never mention; the comment at the parse site states this explicitly. Values are now clamped to0..=100instead of rescaled.Scope
rust/src/providers/chutes/mod.rsonly: dropped theif v <= 1.0 { v * 100.0 }rescale inpercent_from_object, replaced withv.clamp(0.0, 100.0)plus a unit-contract comment citing chutes: same ambiguous 0..=1 fraction rescale heuristic as #407 (real 1% becomes 100%) #408 / fix(opencodego): keep API percent in 0..=100 units #407 / [Bug] OpenCode Go: rolling 5-hour usage shows 100% / "Exhausted Weekly" when opencode.ai reports 1% #247 / upstream OpenCode Go: weekly usage shows 100% when the true value is 1% (fraction heuristic misreads whole-percent API values) steipete/CodexBar#3216. Kept the existing four-key scan unchanged.mod tests:usage_percentof1stays 1,0.5stays 0.5,100stays 100 (nested inside a quota object, matching existing test style).Tradeoffs
Blast Radius
Verification
cargo test --manifest-path rust/Cargo.toml --lib providers::chutes— all 7 chutes tests pass, including the 3 new regression tests (test-first: they were committed failing, with1 → 100and0.5 → 50reproducing the bug before the fix).cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings— exit 0, no warnings.cargo fmt --allapplied;git diff --statshows onlyrust/src/providers/chutes/mod.rs(+13/−3 across both commits).Summary by CodeRabbit