Skip to content

fix(deepseek): strip reasoning_content when extra_body disables thinking#74403

Closed
SymbolStar wants to merge 1 commit into
openclaw:mainfrom
SymbolStar:fix/deepseek-reasoning-strip-74374
Closed

fix(deepseek): strip reasoning_content when extra_body disables thinking#74403
SymbolStar wants to merge 1 commit into
openclaw:mainfrom
SymbolStar:fix/deepseek-reasoning-strip-74374

Conversation

@SymbolStar

Copy link
Copy Markdown
Contributor

Root Cause

The extra_body wrapper (createOpenAICompletionsExtraBodyWrapper) runs after the DeepSeek V4 provider wrapper. When thinkingLevel is not explicitly off/none (e.g. user sets params.thinking: false which isn't recognized as a string level), the provider wrapper backfills reasoning_content: "" on assistant messages and sets thinking: { type: "enabled" }. Then extra_body overwrites thinking to { type: "disabled" }, leaving stale reasoning_content on messages — causing DeepSeek to reject with 400.

Fix

After applying extra_body to the payload, check if the resulting thinking.type === "disabled". If so, strip reasoning_content from all messages in the payload. This ensures no provider-wrapper backfill or model-response remnant leaks into a disabled-thinking request.

Changed Files

  • src/agents/pi-embedded-runner/extra-params.ts — strip logic after Object.assign(payloadObj, extraBody)
  • src/agents/pi-embedded-runner-extraparams.test.ts — regression test

Fixes #74374

When extra_body sets thinking.type to 'disabled', the extra_body wrapper
runs after the DeepSeek provider wrapper which may have already backfilled
reasoning_content on assistant messages. The stale reasoning_content then
causes DeepSeek to reject the payload with 400.

Strip reasoning_content from all messages after extra_body is applied
whenever the final payload has thinking.type === 'disabled'.

Fixes openclaw#74374
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 29, 2026
@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a DeepSeek 400 error that occurs when extra_body disables thinking (thinking: { type: "disabled" }) after the DeepSeek V4 provider wrapper has already backfilled reasoning_content on assistant messages. The fix strips reasoning_content from all messages in the payload after applying extra_body, and includes a regression test covering the reported scenario.

Confidence Score: 5/5

Safe to merge — the fix is minimal, narrowly scoped to the disabled-thinking path, and consistent with how other payload patches are applied in this codebase.

No correctness issues found. The guard conditions are thorough (type-checks thinking, checks Array.isArray(messages), and null-guards each message before deleting). The fix fires only when thinking.type === "disabled", which matches the only known problematic value in DeepSeek's API. The new test exercises the exact failure scenario from issue #74374.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(deepseek): strip reasoning_content w..." | Re-trigger Greptile

@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the patch targets a real DeepSeek disabled-thinking bug and current main still lacks post-extra_body reasoning_content cleanup, but the PR is dirty against current main, lacks after-fix real behavior proof, and needs maintainer confirmation on whether the cleanup should be generic or DeepSeek-scoped.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, source inspection gives a high-confidence path: current main can enable/backfill DeepSeek reasoning_content, then the later extra_body wrapper can overwrite thinking to disabled without cleanup. I did not run a live DeepSeek request in this read-only review.

Is this the best way to solve the issue?

Unclear as submitted. The cleanup direction matches the DeepSeek failure, but maintainers should decide whether this belongs in the generic extra_body wrapper or should be gated to DeepSeek-compatible payloads before merge.

Security review:

Security review cleared: The diff only changes TypeScript runtime payload cleanup and a regression test; it does not touch workflows, dependencies, lockfiles, secrets, publishing, downloads, or generated/vendor code.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-04-29T14:37:09Z, is older than 30 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • @steipete: Authored the OpenAI-compatible extra_body hardening and recent DeepSeek V4 reasoning replay work that this PR composes with. (role: recent area contributor; confidence: high; commits: 49f72b332f5d, 62997f7fcec1, 577438ca73a2; files: src/agents/pi-embedded-runner/extra-params.ts, src/plugin-sdk/provider-stream-shared.ts, docs/providers/deepseek.md)
  • lsdsjy: Introduced DeepSeek V4 model support and the initial provider-owned thinking wrapper surface that this patch depends on. (role: introduced DeepSeek V4 surface; confidence: medium; commits: 7d1891e6e63d; files: extensions/deepseek/index.ts, extensions/deepseek/stream.ts, extensions/deepseek/index.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against b9933b2ec119.

@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes:

This PR adds post-extra_body cleanup in the OpenAI-completions extra-params wrapper to delete reasoning_content from messages when the final payload has thinking.type: "disabled", plus a DeepSeek V4 regression test.

Maintainer follow-up before merge:

This is already an open implementation PR for a narrow regression; the next action is maintainer review of the generic cleanup scope and targeted validation, not a separate ClawSweeper repair PR.

Review details

Best possible solution:

Land a narrow, tested fix that makes DeepSeek V4 disabled-thinking payloads consistent whether disabled thinking comes from OpenClaw's thinking level or from params.extra_body, while preserving enabled-thinking replay behavior.

Acceptance criteria:

  • pnpm test src/agents/pi-embedded-runner-extraparams.test.ts
  • pnpm test extensions/deepseek/index.test.ts
  • pnpm check:changed

What I checked:

Likely related people:

  • @steipete: Authored the generic OpenAI-completions payload hardening that added extra_body, and also authored recent DeepSeek V4 reasoning replay, tests, and docs changes around this exact behavior. (role: recent maintainer; confidence: high; commits: 49f72b332f5d, 62997f7fcec1, 577438ca73a2; files: src/agents/pi-embedded-runner/extra-params.ts, src/agents/pi-embedded-runner-extraparams.test.ts, src/plugin-sdk/provider-stream-shared.ts)
  • @lsdsjy: Introduced DeepSeek V4 Flash/Pro support and the initial provider-owned thinking wrapper that strips reasoning_content for explicit disabled thinking levels. (role: introduced DeepSeek V4 surface; confidence: medium; commits: 7d1891e6e63d; files: extensions/deepseek/index.ts, extensions/deepseek/stream.ts, extensions/deepseek/index.test.ts)

Remaining risk / open question:

  • The proposed cleanup lives in the generic OpenAI-completions extra_body wrapper, so maintainer review should confirm that all providers using extra_body.thinking.type: "disabled" should drop reasoning_content, or narrow the cleanup to DeepSeek-compatible payloads.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8cf724a381a3.

@SymbolStar

Copy link
Copy Markdown
Contributor Author

Hi @steipete — friendly ping 🙏 CI is green now (rebased on latest main). Would appreciate a look when you get a chance!

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 30, 2026
@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label May 30, 2026
@barnacle-openclaw barnacle-openclaw Bot removed the stale Marked as stale due to inactivity label May 30, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 30, 2026
@SymbolStar

Copy link
Copy Markdown
Contributor Author

Closing per author cleanup — this PR has been waiting on review for 14+ days. Happy to reopen if a maintainer wants to pick it up; otherwise the fix can be re-proposed if the underlying issue resurfaces.

@SymbolStar SymbolStar closed this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DeepSeek v4-pro: 400 "reasoning_content must be passed back" with thinking=disabled

1 participant