Skip to content

Port upstream 0.67.0: Grok product usage breakdown (stacked on #652) - #656

Closed
Finesssee wants to merge 2 commits into
port/micro-0.67.0-grok-credits-proxyfrom
port/micro-0.67.0-grok-product-usage
Closed

Finesssee wants to merge 2 commits into
port/micro-0.67.0-grok-credits-proxyfrom
port/micro-0.67.0-grok-product-usage

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Stacked on #652 (port/micro-0.67.0-grok-credits-proxy); base is that branch, so the diff shows only the breakdown.

Summary

Grok bearer logins now show the per-product breakdown that the credits proxy carries in config.productUsage (for example Grok Chat 4%, Grok Build 2%) as plain detail rows next to the single weekly bar. Shares are slices of the same credit pool as the total, so they never become a bar or a rate window and never change the total, period, or plan.

Behavior:

  • Parse config.productUsage: [{product, usagePercent}]. The list is kept only when the primary percent came from the wire creditUsagePercent of the same payload and the shares sum to that raw (unclamped) percent within 1.0 point (120 with one 120 share is kept; the bar still clamps to 100).
  • A single malformed entry (non-string or blank product, missing, non-numeric, or negative percent), a non-array value, null, or an empty list drops the whole breakdown, so a partial list cannot pass the sum check. Total, period, and plan are untouched.
  • The on-demand fallback, a period-only answer, and a percent adopted from the grok.com gRPC fallback all carry no breakdown.
  • Rows: sorted by share descending (ties keep wire order), zero-share rows omitted, value is the percent (4%, <1% below one point), no bar or secondary value. Labels: GrokBuild "Grok Build", GrokChat "Grok Chat", GrokImagine "Grok Imagine", GrokAppBuilder "Grok App Builder"; unknown names verbatim (trimmed). Row ids are grok.product.<name>.
  • Reset-credit enrichment adds inventory only, so it preserves the breakdown.
  • Cookie path unchanged.

Upstream reference

  • Release: CodexBar v0.67.0, "Grok: product usage shares" (bbeb03cd9, feat(grok): show product usage breakdown under the weekly bar steipete/CodexBar#3975).
  • Tag-pinned (v0.67.0): Providers/Grok/GrokCreditsProxyFetcher.swift (composingProducts, LossyProductUsageArray, LossyProductUsage), GrokStatusProbe.swift (GrokProductUsageDetails.sections, toUsageSnapshot), docs/grok.md "Usage breakdown by product", Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift (live multi-product payloads, malformed-entry, composition, raw overage, on-demand, and gRPC-borrow cases).

Ported / Deferred

Ported: parsing, composition rule, all-or-nothing malformed handling, labels, ordering, and rows.

Deferred / different:

  • "Usage breakdown" section heading: local ProviderDisplayDetail rows have no section concept, and adding one would touch the UI in every provider surface. Rows use ids grok.product.<name> so a later grouping change can key on them. Titles are the product labels.
  • An out-of-range number inside a product entry (upstream test usagePercent: 1e400) makes serde_json reject the whole payload, so it falls back to the gRPC path instead of only dropping the breakdown. Not a real server shape; handling it would need a second lenient parse pass.
  • Two entries with the same product name render one row (display detail ids are unique); upstream would render both. Not observed on the wire.
  • Existing base issue, not touched: MenuCardDetails.tsx renders the displayDetails block twice (two adjacent identical <section> blocks), so these rows will repeat in the tray card until that is fixed separately.

Validation

Pinned toolchain +1.98.0, E-cores, build slot-6.

  • cargo +1.98.0 fmt --all clean
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings pass
  • cargo +1.98.0 test -p codexbar grok -- --test-threads=4 73 passed, 0 failed (13 new in product_usage_tests.rs)
  • cargo +1.98.0 test -p codexbar-desktop-tauri grok -- --test-threads=4 8 passed, 0 failed

Files: product_usage.rs (new, 113 lines), product_usage_tests.rs (new, 338), credits_proxy.rs (250 to 265), mod.rs (839 to 851). No file over 1000 lines. No new dependencies.

Affected areas

  • Provider-specific behavior
  • Tray panel / Settings UI / CLI / installer / startup (not touched; rows flow through the existing display-detail renderer)

UI proof

Not applicable for code changes; the rows reuse the existing display-detail renderer. Pending: coordinator may capture a CUA smoke on a fresh build with CODEXBAR_SEED_USAGE_JSON if desired.

@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: 2957c9c9-9dd6-4c24-aa84-407fd956095a

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.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

Thermo-nuclear review of this PR:

  • P2 grok/product_usage.rs format_share: product shares above 100% were clamped, hiding overage; the spec clamps only the overall percentage. Fix: show the actual value.
  • P2 grok/product_usage.rs display_details: repeated product names produced duplicate detail ids, so later rows were silently dropped. Fix: unique grok.product.row.<n> ids for repeated names.
  • P3 grok/credits_proxy.rs: an out-of-range percent such as 1e400 fails parsing of the whole billing response. Not fixed here: the Codex fix needed the serde_json raw_value feature in rust/Cargo.toml, and the spec says no dependency changes.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Follow-up: fixed the two P2 findings (unclamped shares, unique row ids) with a new regression test. Left the 1e400 parse finding because it needs a Cargo feature change (spec: no new dependency). Commands run: cargo +1.98.0 fmt --all; clippy --workspace --all-targets -D warnings; cargo test -p codexbar grok (74 passed).

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
…reakdown on the grok.com billing fallback (stacked on nesszer#656; keeps the nesszer#656 repeated-name test next to the nesszer#692 gRPC breakdown tests)
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