Skip to content

fix(opencodego): keep API percent in 0..=100 units - #407

Merged
Finesssee merged 1 commit into
nesszer:mainfrom
496577liuyang-hue:fix/opencodego-api-percent-units
Aug 31, 2026
Merged

fix(opencodego): keep API percent in 0..=100 units#407
Finesssee merged 1 commit into
nesszer:mainfrom
496577liuyang-hue:fix/opencodego-api-percent-units

Conversation

@496577liuyang-hue

@496577liuyang-hue 496577liuyang-hue commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Test plan

  • Added regression tests for percent: 1, 0.5, and full 100
  • cargo test --lib providers::opencodego::usage_api
  • Live: codexbar-cli usage -p opencodego matches https://opencode.ai/zen/go/v1/usage and the Go dashboard when rolling is exactly 1%

Summary by CodeRabbit

  • Bug Fixes

    • Corrected OpenCode Go usage percentage reporting.
    • Usage values are now interpreted and displayed accurately, including exact whole-number values such as 1% and fractional values such as 0.5%.
    • Prevented percentage values from being incorrectly rescaled, improving accuracy for all supported usage levels.
  • Tests

    • Added coverage for whole-number and fractional usage percentages.

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>
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c8cc5830-a7ab-4a9a-a57a-08519970af21

📥 Commits

Reviewing files that changed from the base of the PR and between ddaefd6 and c81fdc7.

📒 Files selected for processing (1)
  • rust/src/providers/opencodego/usage_api.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

OpenCode Go usage parsing now treats API values as percentages in the 0..=100 range. Tests verify that 1% and 0.5% remain unchanged.

Changes

OpenCode Go usage parsing

Layer / File(s) Summary
Preserve percentage values
rust/src/providers/opencodego/usage_api.rs
The parser no longer rescales values from 0..=1. It clamps values to 0..=100. Tests cover exact and fractional percentages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c81fd

This localized API percentage-unit fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Suggested reviewers: finesssee

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving OpenCode Go API percentages in the 0..=100 range.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator

Thanks for the PR, I will review this ASAP.

@Finesssee

Copy link
Copy Markdown
Collaborator

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai review --preview-config to test the unmerged CodeRabbit configuration on a draft PR. The requester must have repository write access; preview results are non-authoritative.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues in the current review thread, or all unresolved review comments when used in the PR conversation.
  • @coderabbitai fix-ci to automatically fix failing CI checks in a stacked pull request.
  • @coderabbitai fix-ci commit to automatically fix failing CI checks by committing fixes to the current branch.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@Finesssee

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@Finesssee

Copy link
Copy Markdown
Collaborator

@coderabbitai autofix

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Autofix skipped. No unresolved review comments with fix instructions found.

@Finesssee Finesssee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_api on 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.

Finesssee added a commit that referenced this pull request Aug 31, 2026
* 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.
@Finesssee
Finesssee merged commit cfa3e96 into nesszer:main Aug 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants