Publish live Grok tokens and xAI spend into Usage & Spend - #3085
Publish live Grok tokens and xAI spend into Usage & Spend#3085Chipagosfinest wants to merge 8 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26fd232eef
ℹ️ 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".
|
Codex review: needs changes before merge. Reviewed August 20, 2026, 4:07 AM ET / 08:07 UTC. ClawSweeper reviewWhat this changesThe PR adds Grok local-session token activity and xAI Management API daily spend as sources for CodexBar’s shared Usage & Spend catalog. Merge readinessThe prior cache-path blocker remains on the current head: Grok session files are still rescanned after refresh while constructing the shared catalog. The PR otherwise has adequate redacted real-behavior proof and no security concern. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherProvider refreshes produce token/spend snapshots that the shared catalog publishes to both the Overview menu and the Usage & Spend dashboard. Grok data comes from local session logs, while xAI data comes from the Management API’s daily billing history. flowchart LR
A[Grok local session logs] --> B[Provider refresh]
C[xAI daily billing history] --> B
B --> D[Published provider snapshots]
D --> E[Shared Usage and Spend catalog]
E --> F[Overview menu]
E --> G[Settings dashboard]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Publish Grok’s scan once during provider refresh, retain it as the current provider snapshot/publication, and have catalog construction read only that cached value. Do we have a high-confidence way to reproduce the issue? Yes, from source: enable Grok with a large local session tree, trigger shared catalog capture, and the current mapper synchronously calls the local scanner after refresh. Is this the best way to solve the issue? No: the existing refresh snapshot already contains the Grok-derived cost usage, so rescanning during catalog capture is avoidable and violates the cache-only boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 84a4ca725d5d. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
Addressed the ClawSweeper/Codex source-state findings on the current head:
Focused tests: Redacted local Grok proof from this machine after the fix (no identity): @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Enabled Grok and xAI now join the shared spend catalog instead of only inflating the unavailable denominator. xAI contributes vendor-metered daily USD from the Management API chart; Grok contributes local session tokens. SuperGrok credits and xAI prepaid balance stay quotas, not spend.
Wrap no-data copy under 120 characters and drop a redundant throws on the prepaid-balance mapping test.
Preserve xAI analytics failures as unavailable instead of known-zero spend, publish local Grok tokens when remote billing fails, pin Today to the current UTC/local day, and keep xAI history as a 30-day source.
steipete#3086 scoped localizedProviderDetails to DeepSeek and z.ai, so generic OpenRouter details keep canonical English. The merge test still expected zh-Hant "API 金鑰" and failed macOS shard 0.
c44ec7a to
c48d4a2
Compare
|
@clawsweeper re-review Exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Peter restored generic title/row L() localization in 84a4ca7 after steipete#3086 scoped it away. The merge kept the canonical-English assertion from the earlier CI fix; match the restored shared catalog instead.
|
@clawsweeper re-review Exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Summary
~/.grok/sessions/**/signals.jsoninto per-day token buckets. SuperGrok/X Premium+ credits stay a quota window and are never converted into dollars.This continues the Overview spend work in #3023, #3054, #3063, and #3067: every enabled subscription should contribute the strongest truthful signal instead of silently dropping out.
Why this slice
#2759 / #2855 were closed so review could happen concern-by-concern. After #3067, Grok and xAI were still
supportsTokenCost: false, so they inflated Overview coverage (x of y subscriptions have spend) without publishing live data.Test plan
GrokLocalSessionScannerTests— daily local buckets, no invented dollars, empty home publishes nothing, and local scan time owns TodayXAICostUsageMappingTests— chart → vendor-metered catalog; prepaid balance alone is not spend; partial history stays estimatedGrokXAISpendCatalogTests— both providers are snapshot-backed spend sources plus opt-in redacted live catalog proofXAIProviderTests— existing golden balance/chart behavior unchanged; malformed successful history stays unavailableGrokMenuCardModelTests— credit-bar presentation unchangedPopupLocalizationTests— OpenRouter generic details localize titles/row labels via L() after 84a4ca7, while values and chart points stay canonicalExact-head verification
Verified on
a4f80675a4d1a2d1d76beafd335be6e2a5267002after rebase onto main and Peter's merge of84a4ca725:Redacted after-fix output from the real local Grok scanner through
SpendDashboardModel.build:No paths, account identifiers, session identifiers, prompts, or model names are included in this proof.
Residual risk
$0.