CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Grok: zero-usage weeks show a red "usage unavailable" error — the gRPC zero-usage 0% is parsed but never adopted

Open zhulijin1991 opened this issue 3 months ago • 2 comments

Summary

For Grok accounts on unified-billing consumer plans, CodexBar renders the red diagnostic

Grok usage is unavailable because its billing sources did not report a usage percentage.

for the entire first stretch of every weekly period while usage is still zero. The data is actually fine — weekly window, reset time, and plan metadata all arrive — but no usage bar can be shown because the zero-usage 0% is parsed and then deliberately discarded during billing-source merging. Another tool that ported this exact parser (cc-switch 3.20.0) shows "Weekly: 0% · resets in 6d21h" for the same account, same credentials, same endpoint.

Verified against CodexBar 0.55.1 (130) and current main (612f2f0fb); the merge logic is identical in both.

What I verified (all tested live)

1. The CLI ACP x.ai/billing method is gone. grok agent stdio (both 1.0.4 and 1.0.5) answers {"code":-32601,"message":"Method not found"} for x.ai/billing after a normal initialize. The method string still exists inside the CLI binary, but the stdio agent no longer registers it, so GrokCLIFetchStrategy always throws on current CLIs and the pipeline always falls through to the next strategy.

2. The CLI proxy billing endpoint no longer publishes a percentage for unified-billing plans. GET https://cli-chat-proxy.grok.com/v1/billing?format=credits with the ~/.grok/auth.json Bearer token returns HTTP 200:

{"config":{"currentPeriod":{"type":"USAGE_PERIOD_TYPE_WEEKLY","start":"<period start>","end":"<period end>"},"onDemandCap":{"val":0},"onDemandUsed":{"val":0},"isUnifiedBillingUser":true,"prepaidBalance":{"val":0},"billingPeriodStart":"<period start>","billingPeriodEnd":"<period end>"}}

No creditUsagePercent, and onDemandCap/onDemandUsed are 0, so GrokCreditsProxyFetcher.parseSnapshot correctly yields usedPercent: nil with a valid resetsAt (the #3157 "unknown usage" state). Making a real completion right after the period rollover still returns the same shape — usage rounds to 0 and proto3 omits the field.

3. The grok.com gRPC endpoint works with just the Bearer token. POST https://grok.com/grok_api_v2.GrokBuildBilling/GetGrokCreditsConfig with Authorization: Bearer <auth.json token> (no browser, no cookies) returns HTTP 200 with grpc-status: 0:

00000000440a4212001a00220b0887a8c6d40610f0d7dd142a0b08879debd40610f0d7dd14
421c0802120b0887a8c6d40610f0d7dd141a0b08879debd40610f0d7dd1458016200680180
0000000f677270632d7374617475733a300d0a

Decoded: no fixed32 (float) fields at all, a reset timestamp at path [1,5,1], and a usage-period marker [1,8,1] = 2. GrokWebBillingFetcher.parseGRPCWebResponse handles exactly this shape: noUsageYet → usedPercent: 0 with usedPercentIsWirePublished: false.

4. But the merge step rejects that 0%. GrokOAuthFetchStrategy.resolvingUnknownUsage only adopts the gRPC enrichment when usedPercentIsWirePublished is true, so the zero-usage 0% is dropped, the proxy answer (unknown) wins, and the fetch finishes with usageUnavailableMessage.

Why this matters

  • The state is genuinely knowable. proto3 omits zero-valued fields, so "period + reset markers + no percent on the wire" is the server's "0% used" representation for this plan family. parseGRPCWebResponse already encodes that knowledge — it is thrown away one layer up.
  • The red-error window is long: essentially the whole start of every weekly period, until usage is large enough for xAI to publish a non-zero float.
  • The behavior is also inconsistent inside CodexBar itself: a snapshot carrying the zero-usage 0% that arrives via GrokWebFetchStrategy is displayed as a 0% bar (that path only errors on usedPercent == nil). Whether the user sees a red error or a 0% bar depends purely on which strategy wins the auto pipeline.

For reference: cc-switch 3.20.0 ported parseGRPCWebResponse including the zero-usage read and adopts it, so it displays "Weekly 0% / resets in 6d21h" for the same account while CodexBar shows the red error.

Suggested fixes (either would remove the red error)

  1. Adopt the zero-usage 0% in resolvingUnknownUsage. Have the parser expose the noUsageYet outcome distinctly (e.g. usedPercentIsZeroUsage, instead of conflating it with usedPercentIsWirePublished: false), and accept a gRPC snapshot that has resetsAt != nil and a zero-usage 0%. This keeps the #3157 protection for genuinely unknown percents while treating the server's explicit "no usage yet" frame as what it is.
  2. Or keep "unknown" but stop rendering it as an error. When the winning snapshot has period metadata (resetsAt, plan) but no percent, show the reset countdown with a neutral "xAI hasn't published usage yet" note instead of the red usageUnavailableMessage.

Option 1 matches what users see on grok.com and cc-switch (0%); option 2 is the conservative UX-only fix.

Happy to test a build.

zhulijin1991 avatar Aug 29 '26 03:08 zhulijin1991

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 28, 2026, 11:06 PM ET / August 29, 2026, 03:06 UTC.

Summary Keep open for a maintainer decision on Grok billing semantics: current main deliberately drops the parser’s structured, inferred 0% result, producing the reported unavailable diagnostic, but broadly adopting omitted-wire values could undo the safety policy from the related report.

Reproducibility: yes. —source-reproducible with high confidence: the parser fixture yields inferred 0% with non-wire provenance, and the merge test proves that result is discarded. No live provider probe was run because it would require account credentials.

Maintainer decision needed

Question Recommendation
Should the exact gRPC frame with a future reset, usage-period marker, and no percentage field be displayed as confirmed 0%, or remain unavailable until xAI publishes a percentage? Adopt the exact no-usage-yet frame: Carry distinct parser provenance and display 0% only for the validated gRPC shape while preserving unknown usage for proxy-only and other omitted-field responses.

Why: Current tests and comments deliberately treat non-wire percentages as untrusted, while the parser separately recognizes this structural no-usage-yet shape; choosing which external representation is authoritative changes the provider’s user-visible correctness policy.

Next step A small repair is technically apparent, but a maintainer must first approve whether the upstream no-wire gRPC frame is a confirmed zero or an unknown value.

Review details

Best possible solution:

Represent the parser’s exact no-usage-yet provenance separately, adopt only that approved gRPC shape during enrichment, and retain unavailable usage for all other missing-percentage responses.

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

Yes—source-reproducible with high confidence: the parser fixture yields inferred 0% with non-wire provenance, and the merge test proves that result is discarded. No live provider probe was run because it would require account credentials.

Is this the best way to solve the issue?

Unclear until the maintainer selects the provider-data policy; an explicit no-usage-yet provenance signal is the narrowest implementation if the structured gRPC frame is approved as authoritative.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • Promoting every gRPC response that omits a percentage as 0% would undermine the fail-closed policy established by https://github.com/steipete/CodexBar/issues/3157; the accepted structural signals must remain narrowly defined and tested.

Codex review notes: model internal, reasoning high; reviewed against 69df3415adf9.

Label changes

Label changes:

  • add P2: A current provider usage view can show an avoidable unavailable error, but the report identifies a bounded behavior and no availability or security failure.
  • add impact:ux-friction: The provider has reset metadata yet presents a red unavailable state, creating misleading user-facing feedback without blocking setup or recovery.
  • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
  • add clawsweeper:source-repro: Current issue advisory state selects this label.
  • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
  • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.
  • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.

Label justifications:

  • P2: A current provider usage view can show an avoidable unavailable error, but the report identifies a bounded behavior and no availability or security failure.
  • impact:ux-friction: The provider has reset metadata yet presents a red unavailable state, creating misleading user-facing feedback without blocking setup or recovery.
Evidence reviewed

What I checked:

  • Current merge rejects the parsed inferred zero: When proxy billing has no percentage, enrichment returns the gRPC result only if it has a percentage that was wire-published; the parser’s inferred zero therefore falls back to the proxy snapshot and later produces the unavailable diagnostic. (Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swift:318, 69df3415adf9)
  • Parser and fixture encode the reported frame: The gRPC parser identifies a no-usage-yet frame from a future reset and usage-period markers, returns 0%, and marks it not wire-published; the focused fixture asserts that exact outcome. (Sources/CodexBarCore/Providers/Grok/GrokWebBillingFetcher.swift:304, 69df3415adf9)
  • Existing regression coverage intentionally preserves unknown usage: The current focused test supplies an inferred gRPC zero with no wire-published percentage and expects the proxy result to remain nil, confirming this is an intentional policy rather than an accidental failure path. (Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift:504, 69df3415adf9)
  • Related report has a narrower but opposing safety contract: The closed related report https://github.com/steipete/CodexBar/issues/3157 established that missing proxy usage fields must not imply 0%; current source comments explicitly retain that protection while attempting gRPC enrichment. (Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swift:284, fc1bd0d797e2)
  • Release and feature-history provenance: The relevant Grok usage-repair history includes Olddonkey’s merged repair commit, and the current behavior is present in the latest released baseline: v0.56.0 contains fc1bd0d7 while current main is 69df3415. (Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swift:300, 0194d88de2d4)
  • Maturity scorecard unavailable in this checkout: The required maturity shortlist helper was run from the target checkout but could not find qa/maturity-scores.yaml, so no maturity label is asserted.

Likely related people:

  • Peter Steinberger: Current blame attributes the merge-policy block to the v0.56.0 release baseline, and recent Grok performance work is also in the feature history. (role: recent area contributor; confidence: high; commits: fc1bd0d797e2, 41d904fd6d88; files: Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swift, Sources/CodexBarCore/Providers/Grok/GrokWebBillingFetcher.swift)
  • Olddonkey: Authored the recent merged Grok usage restoration and the earlier period-only usage repair that form the immediate history around the disputed inference policy. (role: earlier Grok usage repair author; confidence: high; commits: 0194d88de2d4, 23f1288e501a; files: Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swift, Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift)
How this review workflow works
  • 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.

clawsweeper[bot] avatar Aug 29 '26 03:08 clawsweeper[bot]

Fixed on main by #3325, squash commit e7d0011a837e1c6271924ec00fce8fba2087e99e. The parser now proves that an omitted percentage belongs to a complete, active billing period before the resolver accepts zero; malformed or inactive data remains unavailable.

Validation: 91 focused Grok tests, make check, independent review, and all nine checks including both full macOS test shards passed (CI). Local broad coverage passed 861 selections; unrelated process-fixture failures and filesystem timeouts are recorded in #3325 and are not counted as passes. Thanks @sf-jin-ku and @olddonkey for the implementations and reproduction evidence.

steipete avatar Sep 01 '26 06:09 steipete