Skip to content

feat(grok): show product usage breakdown - #3988

Merged
steipete merged 1 commit into
mainfrom
triage/20260921-new-prs-i
Sep 25, 2026
Merged

steipete merged 1 commit into
mainfrom
triage/20260921-new-prs-i

Conversation

@steipete

Copy link
Copy Markdown
Owner

Grok credits responses containing config.productUsage currently lose that breakdown during decoding. Preserve validated product shares from the same response as the published credit total, then render plain rows through the existing provider detail section. Reset-credit enrichment now preserves those rows. Malformed or inconsistent breakdowns are omitted without changing the main quota or period; there are no new requests or UI components.

Adopts @olddonkey's #3975 with contributor credit, documentation, the 0.66.1 Unreleased entry, and a reproducible synthetic render test. Production changes are 4 files, 115 insertions and 17 deletions (net +98).

Verification

Swift commands used CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1, CODEXBAR_TEST_CODEX_FILE_ISOLATION=1, and CODEXBAR_TEST_SESSION_FILE_ISOLATION=1. The green run additionally set CODEXBAR_GROK_PRODUCT_PROOF_DIR to its synthetic output directory.

  • swift test --jobs 2 --filter GrokProductUsageTests: before implementation, 1 test failed because usage.details.first was nil.
  • swift test --jobs 4 --filter 'Grok|ProviderArchitectureGatekeeperTests|ProviderDetailSectionTests|ProviderDetailSectionsContentTests': 269 Swift Testing tests passed, 1 live-only test skipped; XCTest synthetic render passed, 3 unrelated opt-in proof tests skipped; 0 failures. The previously failing regression passed.
  • make check: passed; 0/2658 files required formatting and 0 SwiftLint violations in 2657 files.
  • Independent Codex autoreview through P2: scoped-clean, no actionable findings.

The installed signed 0.65.0 CLI returned a Grok provider error, so there is no successful live product sample from this run. Verification uses contributor payload fixtures and synthetic rendering.

Synthetic before / after

Both images render the production card with a synthetic 6% total (Grok Chat 4%, Grok Build 2%). The before model clears the previously absent details. Light and dark captures were inspected; no account identity, credentials, desktop content, or private data is present.

Before After
Before: weekly quota only After: weekly quota with product breakdown

Related Linux assessment

No Linux code is adopted here. #3973 routes ordinary launch, --usage, and tray activation to Quick View and introduces a cost scan on open, so it needs the owner's default-window decision. Recommend an explicit --quick-view route and compactQuickView: false tray preference while retaining normal launch and --usage behavior. #3971 remains open.

Portable baseline checks passed: node --test Integrations/Omarchy/test.mjs Integrations/Omarchy/notifications.test.mjs (38), python3 Integrations/Linux/tests/test_package.py (3), and python3 Integrations/Omarchy/test_install.py (6). python3 Integrations/Linux/tests/test_desktop.py could not execute behavior: all 17 tests errored at startup because the Linux Qt executable is absent on this Mac.

Closes #3975
Refs #3973
Refs #3971

Preserve same-response product shares from the credits proxy and render
plain rows through the shared provider details. Keep reset-credit
enrichment from replacing product details and omit malformed breakdowns
without changing the main quota.

Adopt #3975 with parser, routing, card-model, and synthetic render proof.

Co-authored-by: olddonkey <olddonkeyblog@gmail.com>
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e372dc1a7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

windowMinutes: windowMinutes,
subscriptionTier: subscriptionTier)
subscriptionTier: subscriptionTier,
productUsage: Self.composingProducts(config.productUsage?.values ?? [], creditUsagePercent: percent))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject product details when the total is negative

When the proxy returns a negative creditUsagePercent, the primary total is clamped to 0, but product composition is still checked against the raw negative value. For example, a total of -0.5 with one product at 0.5 falls exactly within the one-point tolerance, so the UI shows a 0% total alongside a nonzero product row. Drop the breakdown for negative raw totals (or validate it against the normalized total) so malformed responses cannot present contradictory usage.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed September 25, 2026, 8:32 AM ET / 12:32 UTC.

ClawSweeper review

What this changes

The branch decodes Grok billing product percentages and displays them as text rows beneath the existing quota bar, with documentation and tests.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Current main and v0.66.0 do not show Grok product usage, so this owner-authored PR remains useful. The introduced composition guard can show a nonzero product row beside a 0% total; that focused defect blocks merge.

Priority: P2
Reviewed head: 0e372dc1a709c66ac7e4ef26864fd6f29b018849

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused tests and inspected renders support the feature, while a concrete zero-total display defect limits patch readiness.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its synthetic before/after images show the production card rendering product rows, and the related contributor PR records live Grok samples; this branch reports no successful live provider run. The new snapshot field is transient and changes no stored-data contract.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its synthetic before/after images show the production card rendering product rows, and the related contributor PR records live Grok samples; this branch reports no successful live provider run. The new snapshot field is transient and changes no stored-data contract.
Evidence reviewed 8 items Current main still lacks product rows: The base branch's Grok snapshot projection creates the quota window without product detail rows.
Latest release lacks the breakdown: The v0.66.0 credits parser reads the aggregate percentage but has no productUsage decoding.
Introduced zero-total contradiction: The parser clamps a negative aggregate to zero at line 68, but the new composition check compares product values with the negative raw aggregate. A -0.5 total and a 0.5 product pass its one-point tolerance.
Findings 1 actionable finding [P2] Reject positive product rows when the displayed total is zero
Security None None.

How this fits together

CodexBar's Grok provider converts billing responses into a usage snapshot. The CLI and menu card display its quota bar and supporting details.

flowchart TD
  A[Grok billing response] --> B[Decode total and products]
  B --> C{Products compose total?}
  C -->|Yes| D[Quota bar and product rows]
  C -->|No| E[Quota bar only]
  D --> F[CLI and menu card]
  E --> F
Loading

Before merge

  • Reject positive product rows when the displayed total is zero (P2) - The aggregate is clamped to 0%, but product composition is checked against its raw value. For creditUsagePercent: -0.5 and one product at 0.5, the difference is exactly the allowed one point, so the CLI and menu can show a 0% total beside a nonzero product row. A zero total with a 0.5 product also passes. Suppress those rows and cover both payloads in parser tests.
  • Complete next step (P2) - Reject positive product details beside a zero displayed total and add negative and zero-total parser regression cases before merge.

Findings

  • [P2] Reject positive product rows when the displayed total is zero — Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift:105
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +115/-17 lines; tests +543/-2 lines The bounded parser and presentation change has substantial focused coverage, though its zero-total edge case remains untested.

Technical review

Best possible solution:

Keep Grok's single quota bar and guarded product rows, but reject positive product details whenever the displayed aggregate is zero; add focused negative and zero-total cases.

Do we have a high-confidence way to reproduce the issue?

Yes for the review finding: a billing payload with total -0.5 and one product at 0.5 follows a clear source path to a 0% total with a nonzero detail row. The branch was not executed in this read-only review.

Is this the best way to solve the issue?

Yes, with the guard corrected: the existing detail section is a narrow fit for product shares without suggesting separate quotas.

Full review comments:

  • [P2] Reject positive product rows when the displayed total is zero — Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift:105
    The aggregate is clamped to 0%, but product composition is checked against its raw value. For creditUsagePercent: -0.5 and one product at 0.5, the difference is exactly the allowed one point, so the CLI and menu can show a 0% total beside a nonzero product row. A zero total with a 0.5 product also passes. Suppress those rows and cover both payloads in parser tests.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9f76e11944d1.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a limited Grok display improvement with a focused incorrect-row edge case.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its synthetic before/after images show the production card rendering product rows, and the related contributor PR records live Grok samples; this branch reports no successful live provider run. The new snapshot field is transient and changes no stored-data contract.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The owner-authored PR is exempt from the contributor proof gate. Its synthetic before/after images show the production card rendering product rows, and the related contributor PR records live Grok samples; this branch reports no successful live provider run. The new snapshot field is transient and changes no stored-data contract.

Evidence

Acceptance criteria:

  • [P1] swift test --filter GrokCreditsProxyFetcherTests.
  • [P1] make test.
  • [P1] make check.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • olddonkey: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Guard nonpositive displayed totals before attaching product rows, and add negative and zero-total parser cases.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit bbeb03c into main Sep 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant