Repository navigation
Description
fix(ai): deepseek quota publishes a negative balance — the no-positive fallback bypasses its own >0 filter, so a negative-only payload returns "$-5.00" with ok:true
Verified 2026-11-07 on origin/main 9c02ef62d1, in a laptop worktree (~/git/fleet/probe-2026-11-07-creator-0135, kept).
The defect
packages/ai/src/quota/providers/deepseek.ts, the balance selection (:72-110):
positiveBalancesfilterstotal_balance > 0(:74-77) — the fix(ai): deepseek quota balance selection discards a positive balance — a non-USD/CNY balance is ignored, and a zero/negative USD entry wins over a positive one #1800 selection rule.- The fallback chain then re-reads the UNFILTERED list:
balanceInfos.find(currency === "USD") ?? balanceInfos.find(currency === "CNY")(:85-86). When no positive balance exists, a negative USD/CNY entry is selected anyway. totalBalanceis only null-checked (:89-103); a negative value flows toformatMoneyand the label`$${formatMoney(totalBalance)}`(:105-110), publishing acredits_balancewindow withok: true.
A negative balance is a figure that cannot exist as spendable credit. Sibling balance parsers in this same module read a negative amount as absent: meta's parseBillingBanner returns null for minor < 0 (meta.ts), opencode-go's toMicroCents returns null for amount < 0 (opencode-go.ts), turso's numNonNegative. The existing deepseek test "keeps the non-positive USD fallback when no positive balance exists" pins only ZERO (total_balance: 0 → "$0.00", quota.test.ts in the #1800 describe) — zero is a real empty account; negative is not, and no test exercises a negative-only payload.
Runtime probe (laptop worktree, probe-deepseek-negative.ts, kept in the worktree)
Driving the real provider.fetchQuota with a mocked 200 fetch:
{balance_infos:[{currency:"USD", total_balance:"-5.00"}]}→ok:true, sole windowcredits_balancelabel"$-5.00".- Same with numeric
-5→"$-5.00";{currency:"CNY", total_balance:"-7"}→"¥-7.00",ok:true. - Controls:
0→"$0.00"(correct, pinned, must stay);42→"$42.00"; negative USD + positive EUR10→"EUR 10.00"(the fix(ai): deepseek quota balance selection discards a positive balance — a non-USD/CNY balance is ignored, and a zero/negative USD entry wins over a positive one #1800 positive-selection rule, correct and unchanged).
Why it matters
The credits_balance window is the DeepSeek balance figure downstream pool decisions read. Publishing an impossible negative balance as a successful read — in the negative-only case as the provider's ONLY result, defeating the module's "No quota data in response" contract in spirit — teaches consumers a figure that cannot be true, in the money/balance shape where this module has repeatedly chosen "bad data reads as absent" over fabrication (cf. codex credits #1924, openrouter spend #1913, claude spend #1919 — each a different provider/file).
Acceptance criteria
- A negative-only
balance_infospayload publishes nocredits_balancewindow and reaches the existing "No quota data in response" error (ok:false), instead ofok:truewith a negative label. - Negative USD/CNY entries never publish a negative label in any mix; a positive entry in any currency still wins per fix(ai): deepseek quota balance selection discards a positive balance — a non-USD/CNY balance is ignored, and a zero/negative USD entry wins over a positive one #1800.
- Zero and positive balances are unchanged (
"$0.00","$42.00"controls; the pinned zero-fallback test stays green). -
packages/ai/test/quota.test.tspins the negative-only USD and CNY cases beside the existing deepseek fix(ai): deepseek quota balance selection discards a positive balance — a non-USD/CNY balance is ignored, and a zero/negative USD entry wins over a positive one #1800 describe. - Existing quota suite stays green.
Dedup
Searched open + closed issues this run for deepseek balance / negative: #1800 (closed) is deepseek's balance selection discarding a positive balance — it introduced the >0 filter whose fallback this issue is about, and its tests pin only the zero fallback. #1924 (open) is codex credits, #1913 openrouter spend, #1919 claude spend — different providers and files. No issue covers a negative-only deepseek payload.
Activity
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
~/git/fleet/probe-2026-11-07-creator-0135/probe-deepseek-negative.ts(laptop worktree, kept); body filehidden_files/bodies/opencode-deepseek-negative-balance-fallback.mddezren39 commentedon Nov 7, 2026
Picked up by
repo-worker-opencode— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-opencodeposts progress markers; after 30 minutes of silence any other worker may pick this up.)dezren39 commentedon Nov 7, 2026
🤖 Agent note · adopted as design phase 2 by repo design architect (opencode pass 2026-11-07)
dezren39 commentedon Nov 7, 2026
Picked up by
repo-worker-opencode— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-opencodeposts progress markers; after 30 minutes of silence any other worker may pick this up.)dezren39 commentedon Nov 7, 2026
Progress from
repo-worker-opencode: verified: open, no hard-stop labels; fix spec clear; next: branch_createddezren39 commentedon Nov 8, 2026
agent-note:v1 — conductor dispatch binding (2026-11-08 ~06:17 CST)
Queue task 11069 (
repo-health-opencode-pilot, triage) claimed atomically by the OpenChamber conductor as repo-worker-code and dispatched to OpenChamber sessionses_e5e44e936e9ffey9wS4XDbXEuXon the pooled routeopencode-route/workhorse(model record verified: id workhorse / providerID opencode-route; session content-verified engaging the bound worktree).Worktree:
~/git/fleet/11069-1928-deepseek-negativeon branchqueue/11069-1928-deepseek-negativeat origin/main 649f5d9. Pre-launch, the conductor verified the defect code is present on current main: the no-positive fallback inpackages/ai/src/quota/providers/deepseek.tsre-reads the unfilteredbalanceInfoslist for USD/CNY.The session is instructed to re-verify/reproduce, implement the smallest fix with the packet's pinned negative-only USD/CNY tests if triage confirms, run the quota suite under the fleet build lock, open and (after verification) merge a PR referencing this issue, and complete task 11069 with the evidence — or post evidence here if the defect is not reproducible. Lane ledger row 4841 records the session↔task binding.
dezren39 commentedon Nov 8, 2026
agent-note:v1 — terminal outcome: fixed and merged
Queue task 11069 was triaged against current main in /home/user/git/fleet/11069-1928-deepseek-negative at 649f5d9. Reproduction confirmed negative-only USD string and CNY numeric payloads returned ok:true with $-5.00 / ¥-7.00; zero USD remained $0.00. Both negative-only regression tests failed before the fix, each receiving true instead of false.
Change: packages/ai/src/quota/providers/deepseek.ts now permits only zero USD/CNY fallback entries when no positive balance exists. Positive selection stays unchanged. Added negative-only USD and CNY pins in packages/ai/test/quota.test.ts.
Verification:
PR: #2124 — merged as 1f322f2 (head 56d540a).