fix(wallet): report the unified spendable balance managed mode debits#204
Closed
Aayam Bansal (aayambansal) wants to merge 1 commit into
Closed
fix(wallet): report the unified spendable balance managed mode debits#204Aayam Bansal (aayambansal) wants to merge 1 commit into
Aayam Bansal (aayambansal) wants to merge 1 commit into
Conversation
The CLI wallet read the CLI-only ledger (cli_balance_cents), but managed mode debits the UNIFIED wallet: Atlas charges every managed LLM call with category="unified", draining the subscription pool, then the Atlas-web ledger, then the CLI ledger. A user with any Atlas-ledger balance saw managed calls drain that pool first while the displayed CLI wallet never moved — reading as "credits aren't being deducted" even though the unified balance was decreasing normally (observed: unified $156.34, already down $3.99 over a session, while the CLI wallet sat frozen at $54.55). Report the unified spendable balance everywhere the CLI surfaces what a call can actually spend: - cliSpendableCents prefers unified_balance_cents (then the aggregate, then the CLI ledger as a last-resort fallback) - getBalance reads /api/credits; /api/cli/balance only exposes the CLI ledger, so it can never reflect Atlas-ledger spend - `openscience billing` shows that figure and labels it "Atlas wallet" Supersedes #157, whose "managed debits only the CLI wallet (category=cli)" premise no longer holds now that the backend routes managed spend through the unified wallet.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
Superseded by the approved single-wallet, exact-value billing redesign. Closing this display-only approach so the replacement can coordinate Atlas and OpenScience end to end. |
Aayam Bansal (aayambansal)
deleted the
fix/cli-wallet-shows-unified-spendable
branch
July 25, 2026 15:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Managed mode "isn't deducting my credits." The wallet balance in
openscience billingand the Settings → Wallet panel sat frozen at $54.55 across a whole session of managedopenrouter/claude-opus-4.8calls.Root cause
The gateway and billing are actually working — the freeze is a display bug. The CLI reported the CLI-only ledger (
cli_balance_cents), but managed mode debits the unified wallet:llm_proxy_servicecharges every managed call withcategory="unified".usage_service.charge(unified) drains subscription pool → Atlas-web ledger → CLI ledger, in that order.So a user who holds any Atlas-ledger balance has every managed call absorbed by the Atlas ledger first — the CLI ledger (the number we displayed) never moves, even though the spendable balance is dropping normally.
Confirmed against the live wallet for the affected account:
atlas_balance_centscli_balance_centsunified_balance_centslifetime_spent_centsmanaged_llm:openrouterholds, settled)The recent session's 6 managed calls settled cleanly (
pending_managed_debits→settled) and posted-$3.28tocredit_transactions, every cent drawn fromatlas_topup_share— i.e. the money left the unified balance exactly as designed; only the displayed pool was wrong.This supersedes the premise of #157 ("managed debits only the CLI wallet,
category=cli"). That was true when written, but the backend has since moved managed spend onto the unified wallet, which is why the CLI-only display went stale.Fix
Report the unified spendable balance everywhere the CLI answers "what can this call spend":
cliSpendableCents()prefersunified_balance_cents(then the aggregate, then the CLI ledger as a last-resort fallback).getBalance()reads/api/credits—/api/cli/balanceonly exposes the CLI ledger, so it can never reflect Atlas-ledger spend. Preserves the null-vs-zero distinction.openscience billingshows that figure, labelled Atlas wallet.Verification
bun test test/openscience— 35 pass (wallet-balance test updated to assert the unified preference + fallbacks).bun run typecheck— clean.openscience billingnow printsAtlas wallet : $156.34(was$54.55) and tracks real spend.Follow-ups (backend, not in this PR)
Client-side display is fixed; for full consistency the Atlas side still wants:
/api/cli/balanceand/api/cli/billing-modeshould return the unified spendable balance (today they return CLI-only), so any client reading them agrees without special-casing.require_managed_unlocked/require_cli_accessgate onbalances["cli"] > 0; that gate should move to the unified balance, or a user with Atlas-ledger-only credit gets blocked from managed mode despite having spendable funds.llm_usageaudit row, so the web dashboard's usage history shows nothing for these calls (onlycredit_transactionsrecords them).record_managed_usagealready writes one on the non-hold path — the hold path should too.