fix(opencodego): keep API percent in 0..=100 units - #407
Conversation
The /zen/go/v1/usage contract returns whole percentages. Rescaling values in (0, 1] as fractions turned a real 1% rolling window into a false 100% exhausted state (same class of bug as steipete#247 / upstream steipete#3216). Co-authored-by: Cursor <cursoragent@cursor.com>
|
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. 📝 WalkthroughWalkthroughOpenCode Go usage parsing now treats API values as percentages in the ChangesOpenCode Go usage parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized API percentage-unit fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Thanks for the PR, I will review this ASAP. |
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai autofix |
|
Autofix skipped. No unresolved review comments with fix instructions found. |
Finesssee
left a comment
There was a problem hiding this comment.
Thermo-nuclear review — approve
Verdict: Approve. This PR deletes complexity instead of moving it.
What was reviewed
Full change set (main...HEAD, one commit c81fdc79c): one file, rust/src/providers/opencodego/usage_api.rs, +37/−5.
Findings
1. Structural — the fix is the right direction. The removed heuristic (if (0.0..=1.0).contains(&percent) { percent *= 100.0 }) was inherently ambiguous: a real 1% from the Go API is indistinguishable from a 1.0 fraction under that rule, so a true 1% became a false 100% / Exhausted. Replacing an ambiguous rescale with an explicit unit contract (0..=100) + comment referencing #247 / upstream steipete#3216 is the direct, boring, correct replacement.
2. Consistency. The web-scrape path (rust/src/providers/opencodego/mod.rs, extract_window) already dropped fraction scaling with the same #247 reference. Before this PR the two paths inside the same provider disagreed on units; now they don't.
3. No spaghetti growth. The let percent = ... .clamp(0.0, 100.0) shadowing is cleaner than the old let mut + conditional mutation + reassignment. No new conditionals enter any shared or unrelated path.
4. Tests. Both regression tests pin the actual bug (percent: 1 stays 1, 0.5 stays 0.5) plus the 100 boundary, deterministic, co-located, matching existing assertion style.
Verification performed
cargo test --manifest-path rust/Cargo.toml --lib providers::opencodego::usage_apion the PR head: 4/4 pass, including both new regression tests. This was the unchecked box in the test plan.- Remaining unchecked box is the live API comparison — needs a real Go key; could not be run here.
Follow-up (separate issue)
rust/src/providers/chutes/mod.rs still carries the same ambiguous heuristic (if v <= 1.0 { v * 100.0 } else { v }). Pre-existing and outside this diff — a follow-up issue will be filed rather than expanding this PR's scope.
* test(chutes): pin whole-percent unit contract for usage keys * fix(chutes): keep usage percent in 0..=100 units 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.
Summary
GET /zen/go/v1/usagereturns whole percentages (percent: 1means 1%).usage_api.rsstill rescaled values in(0, 1]as fractions, so a real 1% rolling window became a false 100% / Exhausted.Test plan
percent: 1,0.5, and full100cargo test --lib providers::opencodego::usage_apicodexbar-cli usage -p opencodegomatcheshttps://opencode.ai/zen/go/v1/usageand the Go dashboard when rolling is exactly 1%Summary by CodeRabbit
Bug Fixes
Tests