Skip to content

fix(codex): trust zero-credit usage response#481

Merged
robinebers merged 1 commit into
mainfrom
cursor/1fb9aed3
May 22, 2026
Merged

fix(codex): trust zero-credit usage response#481
robinebers merged 1 commit into
mainfrom
cursor/1fb9aed3

Conversation

@robinebers
Copy link
Copy Markdown
Owner

@robinebers robinebers commented May 22, 2026

Summary

  • Trust Codex credits.balance from the usage response body when credits data is present.
  • Preserve the credits header as a fallback for responses without body credits.
  • Add a regression test for accounts with has_credits: false and balance: "0".

Fixes #465

Test plan

  • bunx vitest run plugins/codex/plugin.test.js

Made with Cursor


Note

Low Risk
Low risk: small, localized change to how the Codex plugin derives remaining credits, plus a regression test to lock in behavior for zero-credit accounts.

Overview
Fixes Codex credit reporting to trust credits in the usage response body when present (including correctly treating has_credits: false / balance: "0" as zero), while keeping the x-codex-credits-balance header as a fallback when body credits are missing.

Adds a regression test covering the no-credits account case where the header reports a non-zero balance but the response body indicates zero credits.

Reviewed by Cursor Bugbot for commit efa6f36. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes Codex credit parsing to trust the usage response body when present, so zero-credit accounts show correct usage. Keeps the header as a fallback to avoid regressions.

  • Bug Fixes
    • Read credits.balance from the body when available; if has_credits: false, treat as 0.
    • Fallback to x-codex-credits-balance header when body credits are missing.
    • Add a regression test for has_credits: false with balance: "0".

Written for commit efa6f36. Summary will update on new commits. Review in cubic

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@robinebers robinebers merged commit 7c83829 into main May 22, 2026
4 checks passed
PowerUserZ added a commit to PowerUserZ/OpenTokenUsage that referenced this pull request May 22, 2026
Sync the Windows fork to upstream v0.6.24, preserving fork identity (crate
opentokenusage, productName OpenTokenUsage, com.sunstory.openusage, winreg
dep, createUpdaterArtifacts=false) and all Windows security hardening.

Conflict resolutions:
- host_api.rs: keep the fork's is_valid_date_param command-injection guard
  AND adopt upstream's append_ccusage_common_args(provider, flavor)
  multi-provider refactor (non-overlapping, both retained).
- settings.ts / app-preferences-store / hooks: keep the fork's tray
  provider/metric/percent-color settings and MenubarIconStyle vocabulary
  (icon/percent/bars), add upstream's 12h/24h/auto time-format setting.
- version files set to 0.6.24 (package.json, Cargo.toml, Cargo.lock,
  tauri.conf.json).

Post-merge semantic fix:
- Adapt upstream's new codex zero-credit test to this fork's text credit
  display; still verifies robinebers#481 (body's zero balance beats the stale
  x-codex-credits-balance header).

New upstream work adopted: Grok usage plugin, claude keychain-first
credentials (integrates with the fork's hashed service names), ccusage nvm
bin-path resolution + release-age cost fallback, perplexity missing-group
fix, dependency bumps (tauri 2.11.1, sha2 0.11, tauri-plugin-store 2.4.3,
libc 0.2.186).

Verify gate green: bun build (0 type errors), 1104 frontend tests, 95 Rust
lib tests (incl. 18 redaction). Windows hardening verified intact; no
vulnerabilities or redaction gaps introduced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
barramee27 pushed a commit to barramee27/crossusage that referenced this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex Shows Incorrect Available Credits Value

1 participant