Skip to content

fix(provider): preserve reasoning_content on second interleaved pass (#24146 follow-up)#24443

Open
claudianus wants to merge 2 commits intoanomalyco:devfrom
claudianus:fix/interleaved-reasoning-preserve-existing
Open

fix(provider): preserve reasoning_content on second interleaved pass (#24146 follow-up)#24443
claudianus wants to merge 2 commits intoanomalyco:devfrom
claudianus:fix/interleaved-reasoning-preserve-existing

Conversation

@claudianus
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #24442

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes a regression from PR #24146 where reasoning_content is lost on the second pass through the interleaved transform.

Root cause: The interleaved transform runs on every request. First pass extracts reasoning from content → stores in providerOptions ✅. Second pass (after DB round-trip) finds no reasoning in content (already extracted), so reasoningText = "" → unconditionally overwrites providerOptions.reasoning_content → DeepSeek 400 error.

Changes

  1. transform.ts: When reasoningText is empty, fall back to existing providerOptions[sdk][field] value before defaulting to empty string. This preserves non-empty reasoning from the first pass.
const existingField = msg.providerOptions?.[sdk]?.[field]
const resolvedText = reasoningText || existingField || ""
  1. provider.ts: Default interleaved: { field: "reasoning_content" } for reasoning models in fromModelsDevModel() when models.dev has reasoning: true but no explicit interleaved config.

  2. transform.ts: Use dynamic SDK key ([sdk]) instead of hardcoded openaiCompatible for non-standard providers (e.g., OpenRouter).

How did you verify your code works?

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

PR anomalyco#24146 unconditionally sets reasoning_content to the extracted value.
On the second pass through transform (after DB storage), content parts
no longer have reasoning (already extracted in first pass), so the
extracted value is empty. This overwrites the previously correct
providerOptions.reasoning_content, causing DeepSeek 400:

  The 'reasoning_content' in the thinking mode must be passed
  back to the API.

Fix: when reasoningText is empty, fall back to the existing
providerOptions[sdk][field] value before defaulting to empty
string. This preserves non-empty reasoning from the first pass
while still sending empty reasoning_content when DeepSeek requires
it (the case PR anomalyco#24146 was fixing).

Also use dynamic SDK key ([sdk]) instead of hardcoded
openaiCompatible for provider flexibility.
Models.dev may have reasoning:true but no explicit interleaved config.
Default interleaved to {field: 'reasoning_content'} so the transform
pipeline correctly extracts reasoning parts into providerOptions.
Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request Apr 26, 2026
…ode shell continuations

- anomalyco/opencode#24443 merge-after-nits: preserve reasoning_content on
  second interleaved transform pass (DeepSeek 400 fix); flag scoped
  catch-all blast radius
- anomalyco/opencode#24320 merge-as-is: project-relative pattern in Read
  tool ctx.ask so user-config deny rules actually fire
- qwen-code#3600 merge-after-nits: backslash-LF continuation handling
  in splitCommands, with CRLF security-invariant test
@claudianus
Copy link
Copy Markdown
Contributor Author

cubic review 분석 (PRR_kwDOQheEEc749AeS, 2026-04-26 09:03Z)

결과: ✅ PR 변경 파일(provider.ts, transform.ts)에서 0개 이슈 발견

cubic이 "Auto-approval blocked by 1 unresolved issue"로 표시한 이슈는 src/agents/builtin-agents/resolve-file-uri.ts:22 (Windows drive-root non-terminating loop, P1) 입니다. 그러나 이 파일은 본 PR의 diff에 포함되지 않은 upstream 파일입니다:

$ git diff origin/dev...HEAD --name-only
packages/opencode/src/provider/provider.ts
packages/opencode/src/provider/transform.ts

따라서 이 unresolved 이슈는 본 PR(#24443, DeepSeek reasoning_content second-pass fix)의 scope가 아닌 upstream 관심사입니다. 본 PR의 실질적 변경사항(2개 파일, +53/-9 lines)에서는 cubic이 0개 신규 이슈를 발견했습니다.

조치: 별도 upstream PR이나 이슈로 resolve-file-uri.ts 버그를 리포팅하는 것이 적절하며, 본 PR 머지와는 무관합니다.

cc @cubic-dev-ai

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeek V4: reasoning_content lost on second interleaved pass (regression from #24146)

1 participant