Skip to content

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 #1928

Closed

Description

@dezren39

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):

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:

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

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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    queue/queuedHas a queued task in the Supabase agent queue
    app/aiPackage: ai (pkgs/ or apps/ in this repo)
    on Nov 7, 2026
  2. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    🤖 Agent note · filed

    • Agent: new-issue-creator-opencode (new-issue-creator job)
    • Session / ID: cron new-issue-creator-opencode, run 2026-11-07T07:35Z (America/Chicago 01:35)
    • Found via: filed this run
    • Task: Triage the deepseek negative-balance fallback defect — verified this run with a laptop probe (negative-only USD/CNY publishes a negative credits_balance label with ok:true); decide the negative disposition (sibling precedent: read as absent / no-data).
    • Expectation: effort/s — done when the acceptance criteria in the issue body are met and pinned in quota.test.ts.
    • Links: probe ~/git/fleet/probe-2026-11-07-creator-0135/probe-deepseek-negative.ts (laptop worktree, kept); body file hidden_files/bodies/opencode-deepseek-negative-balance-fallback.md
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    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 while repo-worker-opencode posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  4. added
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 7, 2026
  5. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    🤖 Agent note · adopted as design phase 2 by repo design architect (opencode pass 2026-11-07)

  6. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    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 while repo-worker-opencode posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  7. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    Progress from repo-worker-opencode: verified: open, no hard-stop labels; fix spec clear; next: branch_created

  8. dezren39 commented on Nov 8, 2026

    @dezren39
    Author

    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 session ses_e5e44e936e9ffey9wS4XDbXEuX on the pooled route opencode-route/workhorse (model record verified: id workhorse / providerID opencode-route; session content-verified engaging the bound worktree).

    Worktree: ~/git/fleet/11069-1928-deepseek-negative on branch queue/11069-1928-deepseek-negative at origin/main 649f5d9. Pre-launch, the conductor verified the defect code is present on current main: the no-positive fallback in packages/ai/src/quota/providers/deepseek.ts re-reads the unfiltered balanceInfos list 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.

  9. dezren39 commented on Nov 8, 2026

    @dezren39
    Author

    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:

    • bun test test/quota.test.ts in packages/ai: 177 pass, 0 fail; 10 reruns: 1,770 pass.
    • bun run typecheck in packages/ai: passed.
    • Push-hook workspace typecheck: 36/36 packages passed.
    • Provider probe: zero USD $0.00; positive USD $42.00; negative USD/CNY plus positive EUR selects EUR 10.00.
    • PR fix(ai): reject negative DeepSeek balances #2124 was mergeable with no blockers or open findings; Copilot approved. No PR checks were reported (0/0).

    PR: #2124 — merged as 1f322f2 (head 56d540a).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/aiPackage: ai (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/claimedA queue worker has claimed the task for this itemsource/creatorFiled by the new-issue-creator jobstatus/in-progressActively being workedtask/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedAn agent holds this item via the queue (claimed task)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions