Skip to content

fix(usage): guard malformed DeepSeek balance payloads - #110785

Merged
steipete merged 1 commit into
openclaw:mainfrom
Leon-SK668:fix/deepseek-usage-null-guard-20260718
Jul 29, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
Leon-SK668:fix/deepseek-usage-null-guard-20260718

Conversation

@Leon-SK668

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users viewing DeepSeek usage could hit an uncaught TypeError when the balance endpoint returned a successful JSON payload with a non-object top-level shape such as null or an array.

Why This Change Was Made

The usage parser now accepts only record-shaped successful payloads before reading balance fields. Non-object payloads follow the existing No balance data snapshot contract, while valid balance records and unavailable-account handling remain unchanged.

User Impact

DeepSeek usage refreshes degrade to a stable empty usage result instead of rejecting when the upstream returns a malformed successful payload. The endpoint's documented object/balance_infos shape remains unchanged: https://api-docs.deepseek.com/api/get-user-balance/

Evidence

  • Submission base: upstream/main@faf3dbdda833b36d4cccf465a40aabe2d1675d3d
  • node scripts/run-vitest.mjs src/infra/provider-usage.fetch.deepseek.test.ts - 1 file / 7 tests passed.
  • oxfmt --check src/infra/provider-usage.fetch.deepseek.ts src/infra/provider-usage.fetch.deepseek.test.ts - passed.
  • Focused oxlint for both changed files - passed.
  • git diff --check - passed.
  • Production-path runtime proof using a real node:http loopback server returning HTTP 200 null (no DeepSeek credential or external provider call):
{
  "transport": "real-node-http-loopback",
  "request": {"method": "GET", "url": "/user/balance", "authHeaderPresent": true},
  "result": {"provider": "deepseek", "windows": 0, "error": "No balance data"}
}
  • Claude autoreview after the final fix: clean, no accepted/actionable findings. Codex autoreview was attempted but the local endpoint was unavailable.

AI-assisted contribution; the behavior, owner boundary, and validation were reviewed before submission.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 26, 2026, 3:51 AM ET / 07:51 UTC.

ClawSweeper review

What this changes

The PR guards DeepSeek balance parsing so successful null or array JSON responses produce the existing empty-usage result instead of accessing balance fields as an object.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This is still a useful, unmerged two-file hardening fix for malformed successful DeepSeek responses. The supplied regression coverage and real loopback HTTP result support ordinary maintainer review; no concrete patch defect or security concern is visible in the provided current-head evidence.

Priority: P2
Reviewed head: 2c602765f37aff5018919bad9e3681e498811124

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, proof-backed defensive fix with matching regression coverage and no actionable correctness finding in the supplied review evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides an after-fix terminal result from a real Node HTTP loopback call returning HTTP 200 with null, directly demonstrating the changed malformed-response path; private values should remain redacted in any future proof updates.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides an after-fix terminal result from a real Node HTTP loopback call returning HTTP 200 with null, directly demonstrating the changed malformed-response path; private values should remain redacted in any future proof updates.
Evidence reviewed 4 items Current PR patch: The current head checks the parsed successful payload with isRecord before reading balance_infos or is_available, so JSON null and arrays follow the existing no-balance-data path.
Regression coverage: The PR adds parameterized cases for successful null and array payloads and asserts the stable No balance data result with no usage windows.
Real behavior proof: The PR body includes after-fix terminal output from a real Node HTTP loopback response returning HTTP 200 with null; it reports a DeepSeek snapshot with zero windows and No balance data.
Findings None None.
Security None None.

How this fits together

OpenClaw’s provider-usage fetchers call provider billing endpoints and normalize their responses into usage snapshots for downstream usage displays. This DeepSeek adapter converts a successful balance response into summary, billing, and availability fields while preserving a stable empty snapshot when balance data is unavailable.

flowchart LR
  A[Usage refresh] --> B[DeepSeek balance endpoint]
  B --> C[HTTP response parser]
  C --> D{Record-shaped payload?}
  D -->|Yes| E[Normalize balance fields]
  D -->|No| F[Empty usage snapshot]
  E --> G[Usage display consumers]
  F --> G[Usage display consumers]
Loading

Before merge

  • Complete next step (P2) - No mechanical repair is identified; retain this PR for ordinary maintainer review of the current head.
Agent review details

Security

None.

PR surface

Source +1, Tests +12. Total +13 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 3 +1
Tests 1 12 0 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 3 +13

Review metrics

None.

Technical review

Best possible solution:

Keep the record-shape guard and its regression cases, then land it once a maintainer is satisfied with the current-head review and required checks.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: a successful DeepSeek HTTP response whose JSON root is null or an array reaches the balance-field reads; the PR’s loopback HTTP proof shows the guarded result after the fix. I did not independently execute the current-main path in this read-only environment.

Is this the best way to solve the issue?

Yes. Validating the top-level parsed value at the provider adapter boundary is the narrowest maintainable fix and retains the established empty-snapshot behavior for absent balance data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5347285d6bc4.

Labels

Label justifications:

  • P2: A malformed upstream usage response can currently disrupt a provider-usage refresh, but the bounded failure path has limited blast radius and a focused repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides an after-fix terminal result from a real Node HTTP loopback call returning HTTP 200 with null, directly demonstrating the changed malformed-response path; private values should remain redacted in any future proof updates.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix terminal result from a real Node HTTP loopback call returning HTTP 200 with null, directly demonstrating the changed malformed-response path; private values should remain redacted in any future proof updates.

Evidence

What I checked:

  • Current PR patch: The current head checks the parsed successful payload with isRecord before reading balance_infos or is_available, so JSON null and arrays follow the existing no-balance-data path. (src/infra/provider-usage.fetch.deepseek.ts:87, 2c602765f37a)
  • Regression coverage: The PR adds parameterized cases for successful null and array payloads and asserts the stable No balance data result with no usage windows. (src/infra/provider-usage.fetch.deepseek.test.ts:88, 2c602765f37a)
  • Real behavior proof: The PR body includes after-fix terminal output from a real Node HTTP loopback response returning HTTP 200 with null; it reports a DeepSeek snapshot with zero windows and No balance data. (2c602765f37a)
  • Still-needed check: The GitHub context identifies this PR as open and unmerged, with a current-main SHA distinct from the PR head; it supplies no merged/current-main implementation that would make this narrow fix obsolete. (5347285d6bc4)

Likely related people:

  • Leon-SK668: The supplied PR history identifies this account as the current-head author; current-main feature-history inspection was unavailable in the read-only review environment, so this is only a low-confidence routing fallback rather than an ownership finding. (role: patch contributor; confidence: low; commits: 2c602765f37a; files: src/infra/provider-usage.fetch.deepseek.ts, src/infra/provider-usage.fetch.deepseek.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-18T15:54:40.358Z sha 89c4142b5cae40701dde67f5da1460617c2db298 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T03:14:42.538Z sha 059ae2dec547f4dc4b7c093e047bc65d5a9516ac :: needs maintainer review before merge. :: none

@Leon-SK668
Leon-SK668 force-pushed the fix/deepseek-usage-null-guard-20260718 branch 2 times, most recently from 059ae2d to 8d339b4 Compare July 26, 2026 07:26
@Leon-SK668
Leon-SK668 force-pushed the fix/deepseek-usage-null-guard-20260718 branch from 8d339b4 to 2c60276 Compare July 26, 2026 07:47
@steipete
steipete merged commit 7c024ca into openclaw:main Jul 29, 2026
137 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit to yetval/openclaw that referenced this pull request Jul 29, 2026
* origin/main: (224 commits)
  fix(memory): preserve Windows session ownership (openclaw#115851)
  fix(compaction): drop context-engine fallback on codex ownership skip (openclaw#114155) (openclaw#115666)
  fix(msteams): ignore blank certificate settings (openclaw#109112)
  fix(usage): guard malformed DeepSeek payloads (openclaw#110785)
  docs(agents): reword imported review rules in repo voice
  docs(agents): add context-budget, tool-description, cache-invalidation, and review-premise rules
  docs(agents): mock-gateway proof satisfies gate without discouraging live proof
  docs(agents): add vitest in-flight edit rule and mock-gateway proof recipe
  docs(agents): restructure root AGENTS.md around product doctrine and deduped policy
  fix(codex): keep completed answers over audit gaps (openclaw#115849)
  test(cli): isolate unknown-command process validation (openclaw#115848)
  fix(memory-host-sdk): resolve stable execPath for worker fork to survive Homebrew Node upgrades (openclaw#99318)
  feat(ui): add composer capability menu (openclaw#115800)
  fix(synology-chat): stop fabricating send message ids (openclaw#110770)
  fix(feishu): reply to direct messages by chat id (openclaw#109637)
  fix(acp): attach error listener to spawned ACP agent process (openclaw#109529)
  fix(sessions): deliver agent announcements to direct message sessions (openclaw#115811)
  fix(nextcloud-talk): reject reactions for disabled or unconfigured accounts (openclaw#112675)
  refactor(ui): move Agent Defaults entry from the sidebar into the Agents page (openclaw#115836)
  feat(gateway): push session PR indicators to subscribed clients (openclaw#115643)
  ...

# Conflicts:
#	src/agents/apply-patch.ts
#	src/agents/sandbox/fs-bridge-mutation-helper.ts
pull Bot pushed a commit to yann0001/openclaw that referenced this pull request Jul 29, 2026
* origin/main:
  fix(usage): guard malformed DeepSeek payloads (openclaw#110785)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* origin/main:
  fix(usage): guard malformed DeepSeek payloads (openclaw#110785)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants