Skip to content

fix(billing): prefer funded balance over CNY in display fallback - #8412

Open
hakimonr wants to merge 2 commits into
esengine:main-v2from
hakimonr:fix/billing-funded-balance-fallback
Open

fix(billing): prefer funded balance over CNY in display fallback#8412
hakimonr wants to merge 2 commits into
esengine:main-v2from
hakimonr:fix/billing-funded-balance-fallback

Conversation

@hakimonr

@hakimonr hakimonr commented Aug 11, 2026

Copy link
Copy Markdown

Fixes #8107

Problem

The CLI/TUI footer and /status always show the CNY entry (¥0.00) for a
DeepSeek account whose real (funded) balance is USD — even with
[desktop] currency = "USD" / language = "en" set. DisplayForCurrency("")
fell back to a legacy CNY-first pick, and DeepSeek now returns a zero CNY
entry alongside the funded USD entry in non-deterministic order, so the
status line deterministically showed ¥0.00.

The serve balance diagnostics and the HTTP /status balance display also
ignored the display-currency preference entirely (balance.Display()).

Root cause

  • CNY-first fallback in internal/billing/balance.go — a zero CNY entry
    always wins over a funded USD entry.
  • CLI surfaces calling Display() without the resolved currency
    (internal/cli/serve_frontend.go, internal/serve/serve.go).

Fix

  • internal/billing/balance.go: fall back to the entry with the largest
    funded balance instead of CNY-first, so a zero CNY entry can never hide a
    funded USD balance. Explicit preferences still win even when their own
    balance is zero (e.g. DisplayForCurrency("CNY") on a CNY 0.00 / USD 9.82
    wallet renders ¥0.00).
  • internal/cli/serve_frontend.go + internal/serve/serve.go: thread
    the explicit display currency into the balance readout
    (DisplayForCurrency(currency)), matching the TUI footer behavior.

Verification

  • go test ./internal/billing ./internal/cli ./internal/serve — pass
  • go vet ./internal/billing ./internal/cli ./internal/serve — clean
  • gofmt — clean
  • New tests cover both entry orders (CNY 0.00 / USD funded), USD-only
    wallets under every preference, unknown preferences, and malformed totals.

Related

Documentation-impact: none - display-only behavior change in the CLI status line and serve balance readout; no docs/*.md documents the CNY-first fallback, and the new fixtures cover the behavior in unit tests.

Problem: the CLI/TUI footer and /status always show the CNY entry
(¥0.00) even for USD-funded DeepSeek accounts. DisplayForCurrency("")
fell back to a legacy CNY-first pick, and DeepSeek now returns a zero CNY
entry alongside the funded USD entry in non-deterministic order, so the
status line deterministically showed ¥0.00. The serve diagnostics and
HTTP /status surfaces also ignored the display-currency preference
entirely.

Root cause: the CNY-first fallback in internal/billing/balance.go, and
CLI surfaces calling Display() without the resolved currency.

Fix: fall back to the entry with the largest funded balance instead of
CNY-first, and thread the explicit display currency into the serve
balance diagnostics and HTTP /status balance display. Explicit
preferences still win even when their own balance is zero.

Verification: go test ./internal/billing ./internal/cli ./internal/serve;
gofmt; go vet. New fixtures cover both entry orders, USD-only wallets,
unknown preferences, and malformed totals.

Refs: esengine#8107
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development tui Terminal UI / CLI (internal/cli, internal/control) labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tui Terminal UI / CLI (internal/cli, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

1 participant