Add Hugging Face billing and prepaid Credits - #3399
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 9:26 AM ET / 13:26 UTC (Revision 33). ClawSweeper reviewWhat this changesAdds Hugging Face billing spend and prepaid browser-session Credits to the app and CLI, with source settings, account attribution, presentation, documentation, and tests. Merge readiness✅ Ready for maintainer review The contribution remains useful and unshipped. The newly recorded A/B execution addresses the previous proof blocker, and no blocking introduced defect was found. The related inference-quota proposal does not supersede this work. Priority: P2 Review scores
Verification
How this fits togetherCodexBar’s provider pipeline turns authenticated billing responses into menu and CLI usage displays. This addition combines bearer-token spending data with a browser wallet only when account identities match, otherwise presenting the wallet separately. flowchart TD
A[API token] --> C[Billing spend and API identity]
B[Browser session] --> D[Prepaid wallet and browser identity]
C --> E{Unique identity match}
D --> E
E -->|Yes| F[Account spend with wallet]
E -->|No| G[Separate browser wallet]
F --> H[Menu and CLI display]
G --> H
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Preserve distinct spend and prepaid-wallet semantics through the existing provider infrastructure, with account composition governed by verified identity and separate browser attribution otherwise. Do we have a high-confidence way to reproduce the issue? Not applicable as an existing-behavior bug: this adds a provider. Contributor evidence exercises the new runtime paths, while this review inspected source without executing them. Is this the best way to solve the issue? Yes: the implementation reuses the provider plugin, credential, cookie, and presentation infrastructure while keeping billing spend separate from prepaid Credits; no equivalent supported implementation exists on the reviewed main. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 928166f89947. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (32 earlier review cycles; latest 8 shown)
|
8994865 to
b094379
Compare
Exact-head validation report (final integration head)Head: Merged fork PRs
Portability note: the HF web credits parser needed CI (fork PR #1 at FP-167 head
|
|
🦞🧹 I asked ClawSweeper to review this item again. |
7730295 to
8d81e10
Compare
d554780 to
72a10c9
Compare
36f0028 to
0d557f8
Compare
b7fa531 to
4be9b09
Compare
4be9b09 to
5201562
Compare
Decide wallet attribution once per Auto batch through a shared HuggingFaceWalletBatchReconciliation so multiple matching accounts strip compositions and render one provider-level wallet, a unique match renders no provider-level duplicate, and zero matches or single-account runs render one unverified provider-level wallet. Bypass token-account enumeration for explicit and persisted Hugging Face Web mode with one provider-level Web result and no account label or cache key. Record the browser wallet published by successful Web-kind snapshots, clear stale auxiliary wallet state on that publication, and keep validated Credits visible with browser-session attribution when a later Auto/API refresh fails. Preserve the initiating caller's browser-access task-locals through the wallet batch single-flight. Align docs/providers.md and the changelog with the dual-source Auto contract.
Render the provider-level browser wallet in compact token-account menus, carry it on the live card when no API base snapshot exists, and restrict .webSession failure recovery to Auto/API refreshes that provably displaced a live Web-owned snapshot.
…to-show-api-spend-and-prepaid-balance-2 Tighten Hugging Face wallet presentation tests
20c5843 to
b25a9d8
Compare
|
@clawsweeper re-review FP-181 safe contained live-proof authorization is now in place. Please refresh the review against the current PR head before live credential work begins; no source, merge, or CI mutation is requested. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review The PR body now contains the sanitized current-head FP-181 evidence from exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Recorded execution evidence for the contained A/B final-publication harness is now in the PR body for exact head Focused result: PASS (1 test). The run exercised the production CodexBar URLSession/ProviderHTTPClient, bundled Hugging Face plugin, identity cache, Auto reconciliation, UsageStore publication, and final menu-card projection with synthetic contract-valid A/B principals intercepted by URLProtocol. After populated A/A state, browser B remained separate, account A lost the old composed wallet and |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Summary
Adds Hugging Face as a first-class CodexBar provider for two distinct billing concepts that can be shown together when safely attributable:
Ordinary Auto mode treats API spend as authoritative and retrieves the browser wallet as auxiliary data when browser-session billing is safely available. CodexBar composes the wallet onto an API account only after an exact cross-authority identity match. Otherwise the API result and browser wallet remain separate and explicitly labeled.
Explicit API and Web selections remain isolated diagnostic/source modes.
Billing behavior
API billing
Bearer-token authentication uses:
/api/whoami-v2for account identity./api/settings/billing/usagefor the current billing period and reported category spend.The provider exposes the spend returned by Hugging Face for that billing period. It does not claim to represent all possible Hugging Face account spending.
Token-only refresh does not trigger browser or Keychain access solely to perform identity matching.
Prepaid Credits
The prepaid wallet is separate from API billing usage.
Hugging Face currently renders this value on
/settings/billingfrom structured server-rendered data. CodexBar parses:entity.currentBalanceUsdas the current wallet value.invoiceCreditsCentsonly as a legacy compatibility fallback.A valid upstream zero is preserved as
$0.00. Missing authentication, redirects to login, malformed data, or an unavailable wallet remain unavailable rather than being converted into zero.The browser wallet is one provider-level browser-session value. It is never duplicated or cached as multiple token-account wallet snapshots.
Auto mode and account safety
API-token identity and browser-session identity are resolved independently through
/api/whoami-v2.Composition requires:
type == "user"on both identities; andid.CodexBar does not use billing-page names, email, organization membership, display names, or wallet values as ownership proof.
Auto behavior:
A browser wallet retained after a failed Auto/API replacement is presented as browser-session data with no implication that it belongs to the current API account.
Explicit API and Web modes
Explicit API remains API-only.
Explicit or persisted Web remains browser-session-only:
Cookie source Refresh validates the Web path first. Its best-effort Auto follow-up may then restore the ordinary dual-source view. If that follow-up fails after displacing a validated Web snapshot, the wallet remains visible once at provider level with browser-session attribution.
Cancellation still propagates.
Browser-session handling
Hugging Face uses CodexBar's existing shared browser-cookie infrastructure rather than a provider-specific cookie scraper.
Automatic browser-session handling:
Manual Cookie and Off modes remain available through the standard provider settings UI.
UI and CLI integration
The change includes:
Intentionally out of scope
This PR does not add or claim:
/usage-v2inference allowance as the primary balance;Prepaid Credits, reported billing spend, and any included inference allowance are treated as distinct concepts.
Validation
Current canonical contribution head:
a940f5f1b23654d75e4f934f0f633c8b3716b2c0, based on upstream928166f899471bbdcb72210641cdec91324d0154.Exact-head validation passed with full Xcode selected via
DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer:make test: 1,056 selections across 88/88 groupsmake format: 0 files formattedmake check: SwiftLint 0 violationsgit diff --checkThe only delta from the previously reviewed production head
544aa4e3588ccebc9a5159c88540df983e09d00cis the test-only final-publication harness. No production source changed.Live verification
A contained public-safe live-proof pass was run on production head
544aa4e3588ccebc9a5159c88540df983e09d00cusing a freshly built release app. Production code is unchanged at the current head, so these observations remain applicable.Artifact provenance:
0.57.1, build141544aa4e35649111db2452c3e9c663237b09c49200dac63adf8f5cfc14d636668a9a4ed893Confirmed on that production head:
api+webwith both API billing data and browser Credits present. The wallet remains Web-derived authority data; CLI presents it as a separate provider-level Web field by design while account-level UI uses the matching/reconciliation rules described above.A true two-account mismatch using two server-issued Hugging Face credentials was not run because no secondary account/credential exists. No second account or token was created for the proof.
The live pass did not perform logout, browser-account switching, direct Keychain inspection, cookie extraction, real credential revocation, account/token creation, or source mutation. No tokens, cookies, account identifiers, balances, spend values, authenticated payloads, or private browser data are included here.
Contained A/B final-publication proof
Current head
a940f5f1b23654d75e4f934f0f633c8b3716b2c0adds a test-only contained proof inTests/CodexBarTests/HuggingFaceRealTransportFinalPublicationTests.swift.This is not described as live Hugging Face account proof. It uses synthetic contract-valid A/B principals and synthetic server responses intercepted by
URLProtocol, while exercising the production CodexBarURLSession/ProviderHTTPClient, bundled Hugging Face plugin, identity cache, Auto reconciliation,UsageStorepublication, and finalStatusItemController.menuCardModel(for:)path.Recorded execution result on the exact current head: PASS (1 test).
The two-phase assertion sequence demonstrated:
api+webpublication.api+webattribution; the browser wallet was published separately with.unverifiedauthority; the final menu-card model presented the browser-session wallet separately asUnverified against this API token; and no wallet remained attributed to account A.This execution used no live Hugging Face credentials, browser cookies, Keychain data, account creation, account switching, purchased Credits, or real secondary credentials.
The deterministic partial-cancellation timing edge remains covered by the exact-head regression suite rather than invasive live-network manipulation.
Privacy and security
The submitted diff contains no real:
Tests use synthetic fixtures and sanitized data only.
UI Proof / Screenshots
The following screenshots were captured during the public-safe live verification described above.
They show the implemented Hugging Face surface end to end:
api+webresult, browser-cookie cache, API-token configuration, and Auto usage source.These screenshots demonstrate the user-visible implementation and source controls. They supplement the live verification above. The cross-authority identity and mismatch safety properties are established separately by the contained A/A → A/B final-publication proof below.
Combined billing and prepaid Credits
Provider settings
First-class provider registration
Cookie source selection
Usage source selection
Related work
There is an existing Hugging Face PR, #3322, exploring a different scope around
/usage-v2, inference credits, and ZeroGPU.This PR remains billing-oriented: reported billing spend from
/api/settings/billing/usageplus the explicit prepaid Credits wallet from the authenticated billing page, with bounded identity-based composition and safe separate-authority fallback.