Skip to content

feat: add deepseek thinking mode support with reasoning_content and s…#7

Open
YoungSx wants to merge 1 commit intoshantoislamdev:mainfrom
YoungSx:hotfix/deepseek-v4
Open

feat: add deepseek thinking mode support with reasoning_content and s…#7
YoungSx wants to merge 1 commit intoshantoislamdev:mainfrom
YoungSx:hotfix/deepseek-v4

Conversation

@YoungSx
Copy link
Copy Markdown

@YoungSx YoungSx commented Apr 29, 2026

Description

This PR fixes reasoning-content bridging for OpenAI-compatible providers (especially DeepSeek thinking/tool-call flows) with
minimal, non-breaking adapter changes.

It now preserves reasoning context bidirectionally, aligns streaming behavior with Anthropic thinking events, and adds a safe
one-time fallback when upstream providers reject reasoning fields.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Related Issues

Fixes #N/A

Changes Made

  • Implemented request conversion from Anthropic thinking blocks to OpenAI-compatible reasoning_content (and
    reasoning_signature when available).
  • Implemented response conversion from reasoning_content back to Anthropic thinking blocks, including signature round-trip.
  • Added streaming support for:
    • reasoning_content -> thinking_delta
    • reasoning signature -> signature_delta
  • Added one-time automatic fallback: if provider rejects reasoning fields with compatible validation errors (400/422), retry
    once after stripping reasoning fields.
  • Updated type definitions for thinking/signature blocks and new delta fields.
  • Added/expanded tests for request/response/streaming/fallback paths, including block switching and non-trigger fallback
    scenarios.

Testing

Describe how you tested these changes:

  • Unit tests added/updated
  • Manual testing performed
  • All existing tests pass

Commands executed:

  • npm test -- reasoningContent.request.test.ts reasoningContent.response.test.ts reasoningContent.streaming.test.ts handlers.test.ts
  • npm run build

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have updated the documentation accordingly
  • I have added tests that prove my fix/feature works
  • New and existing unit tests pass locally
  • I have updated CHANGELOG.md

Screenshots (if applicable)

N/A (backend adapter + tests only)

Additional Notes

  • The fallback is intentionally minimal and conservative:
    • triggers only once
    • only on 400/422 reasoning-related validation patterns
    • avoids broad retry behavior that could hide unrelated request issues.
  • This keeps compatibility improvements without adding provider/baseURL hardcoding or extra runtime config complexity.

…ignature handling

- implement request conversion for thinking blocks to reasoning_content
- add response conversion for reasoning_content to thinking blocks
- support streaming of reasoning deltas and signatures
- add automatic fallback when providers reject reasoning_content
- update types for new content block types and deltas
- add comprehensive test coverage for reasoning content handling
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

result.push({
role: 'assistant',
content: fullContent
});

P1 Badge Preserve reasoning fields in XML-mode assistant history

In XML tool mode, assistant history is rebuilt with only content and drops the extracted thinking data, so follow-up turns lose reasoning_content/signature replay entirely. This means the DeepSeek thinking-mode continuity fix does not apply when toolFormat is xml (the recommended mode for DeepSeek in this repo), causing the same 400 "must be passed back" class of failures on multi-turn conversations.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/handlers.ts
Comment on lines +260 to +264
if (merged.includes('reasoning_content') && (
merged.includes('unknown field') ||
merged.includes('invalid') ||
merged.includes('not allowed') ||
merged.includes('should not include')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retry when providers reject reasoning_signature fields

The fallback classifier only treats errors as retryable when the message mentions reasoning_content, so requests that fail on reasoning_signature/signature (for example, unknown field reasoning_signature) will not be retried even though stripReasoningContent is designed to remove those fields. This leaves a real compatibility regression for providers that accept chat completions but reject signature fields, and the request fails instead of taking the intended one-time downgrade path.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant