Skip to content

Port upstream 0.66.0: Command Code granted monthly credits - #632

Open
Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-commandcode-granted-credits
Open

Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-commandcode-granted-credits

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Command Code now sizes the monthly credits row from the grant the credits response reports (credits.monthlyCredits is the remaining balance, credits.monthlyCreditsGranted the size of the grant).

  • Total = monthlyCreditsGranted when finite and > 0, else the plan catalog value. 0, negative and Infinity (and NaN) fall back to the plan/free-tier logic.
  • Usage is always computed from the fresh monthlyCredits.
  • Failed subscription lookup (HTTP error, timeout): a valid grant keeps the monthly row, with no reset time (the period end only comes from the subscription). With no grant and no remembered plan the monthly row is unavailable instead of an untouched 0% bar. Rolling 5-hour and weekly rows are unaffected. A remembered plan still sizes the row when the grant is absent; a grant wins over a remembered plan.
  • Login method uses the granted size: plan individual-go with granted 12 and 9 remaining gives Go · $3.00 of $12.00; a grant with no plan gives $6.00 of $10.00.
  • Monthly cost snapshot (used / limit) uses the same total, so the fixture (4 remaining of 10) reports 6 / 10 instead of 0 / 4.
  • With no rolling limit and no sized grant, the required primary lane is now an informational balance line (8.78 monthly credits remaining) rather than a 0% quota bar, matching upstream where every lane is nil in that case. This also applies to a fully empty account.

Change stays inside rust/src/providers/commandcode/; plan_cache.rs is untouched (the lookup outcome is derived in fetch_web from the subscription result, independent of the remembered plan, like upstream subscriptionEnrichmentUnavailable).

Upstream reference

  • Release bullet (v0.66.0, Fixed): "Command Code: size monthly usage from the grant reported with credits, keep the row when the optional subscription lookup fails" (fix(commandcode): size the monthly grant from the credits response steipete/CodexBar#3939, commit 49e7ff3e).
  • Tag-pinned (v0.66.0): Sources/CodexBarCore/Providers/CommandCode/CommandCodeUsageFetcher.swift (parseCredits), CommandCodeUsageSnapshot.swift (monthlyCreditsTotal, monthlyCreditsUsed, makeMonthlyWindow, makeLoginMethod), Tests/CodexBarTests/CommandCodeUsageFetcherTests.swift, docs/command-code.md.

Ported / Deferred

Ported: every rule above, plus upstream test cases: parses granted monthly credits fixture, subscription failure in a fresh process sizes the monthly window from granted credits ((4, 60%), (0, 100%) with windowLimits fiveHour used 2.5 / cap 10 and weekly used 30 / cap 100, reset nil), granted credits size the monthly window over the plan catalog, unusable granted credits keep the free tier reading (0, -5, Infinity), subscription failure leaves the projected monthly window unavailable.

Deferred (pre-existing gaps, not part of steipete#3939, left out to keep this PR one behavior):

  • Upstream parseSubscription treats a 200 response with success != true, a missing data, or a missing planId as a failed lookup. Local fetch_web treats any 200 JSON body as an answered lookup (a {"success":false} envelope reads as free tier and clears the remembered plan). Worth a separate micro PR.
  • Upstream raises unknownPlan for an active subscription with an unrecognized plan id; local silently continues.
  • Upstream keeps an already-proven depleted monthly row while enrichment is unavailable (app-side commandCodeMonthlyGrantDepleted state); no local counterpart in this provider.

Validation

Toolchain cargo +1.98.0, process-local CARGO_TARGET_DIR (pwsh was refused in the worktree, so the target dir was set manually outside every worktree).

  • cargo +1.98.0 fmt --all: clean.
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass, no warnings.
  • cargo +1.98.0 test -p codexbar commandcode: 39 passed, 0 failed (11 new in granted_credits_tests.rs, 28 existing; the six existing call sites of result_from_payloads only gained the SubscriptionLookup::Answered argument and still assert the same values).

Affected areas

  • Provider (Command Code parsing / snapshot mapping)
  • Settings / CLI / Tauri shell / React UI / tray / float bar: not touched

UI proof

Not applicable. No UI code changed; the existing monthly lane and login-method line receive different values.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 171412b8-7f8e-4f3b-84c5-74693ab7c5ec

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

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

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.

1 participant