Skip to content

fix(claude-cli): recognise paid usage and recheck stale plan limits - #8599

Open
nickdavis wants to merge 1 commit into
lidge-jun:devfrom
nickdavis:codex/claude-cli-paid-credits
Open

nickdavis wants to merge 1 commit into
lidge-jun:devfrom
nickdavis:codex/claude-cli-paid-credits

Conversation

@nickdavis

@nickdavis nickdavis commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8597.

  • Recheck stale measured Claude CLI exhaustion after the existing one-minute cache interval. A top-up, reset or plan change can then reach the normal usage probe rather than remaining blocked until an old weekly reset.
  • Preserve the closed extra-usage entitlement/cap state from the usage response. When included quota is exhausted but extra usage is explicitly enabled and no reported cap is exhausted, admit as unknown and let the official CLI enforce wallet funds and spend limits. A remaining monthly allowance is never presented as a funded balance.
  • Preserve explicit CLI-refusal cooldowns, account/model isolation, account changes and refusal races, cache-only dashboard reads and secret-free persisted state. Usable included quota remains available after a reset even when the paid cap is exhausted.

No billing, credential, account, spend-limit or workflow settings change. This is separate from combo fallback in #8588.

Verification

  • Regression reproduced against unpatched published 2.100.1 source 00c02163e4352be5beb5633a3b6cc3b0be94ec8a; 2.100.2 still has the same defect.
  • Rebased onto dev at 9fec48a1f8bc1012fdf64dc089aeace597632782, retaining its newer display-window separation and validation.
  • bun test tests/providers/claude-cli-usage-admission.test.ts tests/providers/provider-anthropic-usage-windows.test.ts: 94 pass, 0 fail.
  • bun test tests/providers/provider-quota-claude-cli.test.ts: 27 pass, 0 fail, including inactive display rows and malformed allowance validation.
  • Pinned Bun 1.4.4: typecheck 2,435 files, structure check and privacy scan pass. The declared frozen dependencies were materialised without lifecycle scripts.
  • Documentation build: 665 pages, 96,231 internal links checked.
  • Independent review of the rebased final diff passed. An isolated published-package copy with the four-file repair completed a real Opus request while the measured weekly plan was exhausted and extra usage was enabled. The dev build was not installed.
  • bun scripts/test.ts --changed=origin/dev: 43,941 pass, 108 skip, 94 fail, 7 setup errors, across 1,860 files in 467.69 seconds. This broad run is not green. All 84 initial named failures reproduced on an unpatched release control. Two additional failures reproduced by exact name on unpatched current dev (missing generated launcher and retained-sync fixture). The remaining clean-home CLI-status case hit its five-second timeout; the unpatched control instead timed out in the adjacent dead-owner case through the same unchanged subprocess path. This supports fixture timing instability, not an exact reproduction of that case. Six setup errors concern absent release-tree fixtures; the seventh is an unrun Bun postinstall.
  • Local scope exception under AGENTS.md/CONTRIBUTING.md: the changed-import run already covers over 44,000 tests and took nearly eight minutes; extending this into a separate full local run during concurrent worktree activity is disproportionate. The 121 focused provider tests, type/structure/privacy/docs checks, independent review and unpatched controls cover this repair. Remaining platform/generated-artifact integration coverage is left to required CI on this exact head, which must pass before merge. No failing broad check is treated as passing.
  • Codex and CodeRabbit reviews completed on 3cc650af2a with no findings/actionable comments. Independent final-diff and baseline-failure review passed with the timing qualification above.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Usage Handling
    • Claude CLI subscription usage checks are cached for up to one minute. When included plan usage is exhausted, explicitly enabled extra usage can defer the decision to the CLI, but does not guarantee funds are available.
    • Explicitly disabled or exhausted extra usage does not bypass exhausted plan limits. CLI-reported refusals remain in effect until reset, with exhausted plans reported as a cooldown.
  • Documentation
    • Updated guidance on usage checks, caching, extra usage, and quota-limit behavior.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Claude CLI usage probes now record extra-usage status in quota snapshots. Admission logic distinguishes enabled extra usage from exhausted included quota, preserves active CLI refusals, and validates cached status values. Tests and documentation cover the updated behavior.

Changes: Claude CLI usage admission

Layer / File(s) Summary
Extra-usage quota state
src/providers/quota-types.ts, src/providers/claude-cli-usage.ts, src/providers/claude-cli-usage-state.ts
ProviderQuota now supports enabled, disabled, and exhausted extra-usage states. The probe derives that state from the usage response and adds it to the quota when available. Snapshot loading rejects other defined values.
Quota admission and refusal handling
src/adapters/claude-cli/usage-admission.ts
When extra usage is enabled, exhausted plan windows do not by themselves produce an exhausted result. An active CLI refusal still applies. The cached-snapshot path now preserves an active refusal independently of the computed admission state.
Regression coverage and behavior documentation
tests/providers/claude-cli-usage-admission.test.ts, docs-site/src/content/docs/guides/providers.md, structure/providers/claude-cli-replay.md
Tests cover stale quota rechecks, extra-usage states, available included quota, refusal races, and account switches. The documentation describes the cache, extra-usage conditions, CLI-enforced limits, and failure behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • lidge-jun/opencodex#7916: Adds the Claude usage snapshot type and loader that this change extends with extra-usage validation.

Suggested reviewers: lidge-jun, ingwannu

Merge Risk: Minimal · up to 3cc65

The change recognizes paid extra usage and rechecks stale exhausted limits for the Claude CLI. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: recognising paid (extra) usage in Claude CLI admission and rechecking stale plan-window exhaustion. The raw summary shows changes to usage-admission.ts, claude-cl…
Linked Issues check Passed The only linked issue, #8597, is closed and completed. Under the assessment rules, it supplies background only. No active directly linked targets remain, so no linked-issue coding requirements apply. …
Out of Scope Changes check Passed All changed files relate to the PR's stated intent: Claude CLI usage admission and its quota state. The files are src/adapters/claude-cli/usage-admission.ts, src/providers/claude-cli-usage.ts, src/pro…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the two main changes: recognising paid (extra) usage in Claude CLI admission and rechecking stale plan-window exhaustion. The raw summary shows changes to usage-admission.ts, claude-cli-usage.ts, quota-types.ts, claude-cli-usage-state.ts, docs, and tests that match both parts. The title is specific, under 70 characters, and avoids vague wording. No unrelated changes were described.

Full details: Linked Issues check

Explanation

The only linked issue, #8597, is closed and completed. Under the assessment rules, it supplies background only. No active directly linked targets remain, so no linked-issue coding requirements apply. For reference, the PR changes address the issue's stated defects: (1) src/adapters/claude-cli/usage-admission.ts returns an active refusalUntil immediately and admits full plan windows as non-exhausting when claudeExtraUsage is "enabled"; (2) src/providers/claude-cli-usage.ts maps extra_usage to a closed claudeExtraUsage state; (3) src/providers/claude-cli-usage-state.ts rejects unknown claudeExtraUsage values; (4) tests/providers/claude-cli-usage-admission.test.ts adds coverage for these paths. These observations are informational and do not change the result.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the PR's stated intent: Claude CLI usage admission and its quota state. The files are src/adapters/claude-cli/usage-admission.ts, src/providers/claude-cli-usage.ts, src/providers/claude-cli-usage-state.ts, src/providers/quota-types.ts (one optional field), tests/providers/claude-cli-usage-admission.test.ts, the provider guide docs-site/src/content/docs/guides/providers.md, and structure/providers/claude-cli-replay.md. The docs and tests support the code change. The PR description states no billing, credential, account, spend-limit, or workflow changes, and the summary shows none. Combo fallback (#8588) is not touched. The evidence came from the AI-generated change summary and the PR description. I did not read the raw diff, so this verdict rests on that summary. No unrelated change was demonstrated.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9fec48a and 3cc650a.

Files selected for processing: 7

  • docs-site/src/content/docs/guides/providers.md
  • src/adapters/claude-cli/usage-admission.ts
  • src/providers/claude-cli-usage-state.ts
  • src/providers/claude-cli-usage.ts
  • src/providers/quota-types.ts
  • structure/providers/claude-cli-replay.md
  • tests/providers/claude-cli-usage-admission.test.ts

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers notified: @lidge-jun @Ingwannu

Hygiene

✅ Deterministic PR hygiene checks passed.

@nickdavis

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@nickdavis

Copy link
Copy Markdown
Contributor Author

@codex review

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T17:27:56.597689Z 3cc650a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 3cc650af2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude CLI preflight retains stale exhausted plan quota and ignores paid extra usage

1 participant