Skip to content

[Bug] Native Chat passthrough bypasses autoToolChoiceOnlyModels; DeepSeek thinking rejects forced tool_choice #4631

Closed as not planned

Description

@RHODIZSECURITY

Client or integration

OpenAI-compatible POST /v1/chat/completions through OpenCodex native Chat routing.

Provider or upstream service

Official DeepSeek API (https://api.deepseek.com), model deepseek-flash in thinking mode. The same defect is model-contract scoped and can affect any provider/model listed in autoToolChoiceOnlyModels when the request takes the native Chat passthrough lane.

OpenCodex version

2.54.0 on Linux, reproduced 2026-09-14.

Current behaviour

A provider/model can correctly declare autoToolChoiceOnlyModels, and the translated createOpenAIChatAdapter(...).buildRequest() path correctly coerces forced/required tool choice to auto, but the native Chat passthrough path does not apply that contract.

handleNativeChatCompletions() builds the upstream body through buildOpenAIChatPassthroughRequest(). That helper copies tool_choice from CHAT_PASSTHROUGH_FIELDS verbatim and applies several model capability gates, but not autoToolChoiceOnlyModels.

With DeepSeek thinking enabled, an exact/forced tool selector reaches upstream unchanged and DeepSeek returns:

Provider error 400: Thinking mode does not support this tool_choice

Minimal reproduction

Provider config (credential omitted):

{
  "DeepSeek": {
    "adapter": "openai-chat",
    "baseUrl": "https://api.deepseek.com",
    "models": ["deepseek-flash"],
    "autoToolChoiceOnlyModels": ["deepseek-flash"]
  }
}

Request:

{
  "model": "DeepSeek/deepseek-flash",
  "messages": [{"role":"user","content":"Call ping once with value ok."}],
  "tools": [{
    "type":"function",
    "function": {
      "name":"ping",
      "description":"Return a value",
      "parameters": {
        "type":"object",
        "properties":{"value":{"type":"string"}},
        "required":["value"],
        "additionalProperties":false
      }
    }
  }],
  "tool_choice":{"type":"function","function":{"name":"ping"}},
  "reasoning_effort":"high",
  "max_tokens":128,
  "stream":false
}

Before the fix: HTTP 400 with Thinking mode does not support this tool_choice.

Root cause

The two OpenAI Chat wire builders have diverged:

  • translated adapter path: applies autoToolChoiceOnlyModels and emits none or auto;
  • buildOpenAIChatPassthroughRequest: copies raw tool_choice and never applies that model gate.

The passthrough path already applies noReasoningModels, noTemperatureModels, noTopPModels, noPenaltyModels, noStructuredOutputModels, noJsonSchemaModels, Fast policy, and parallel-tool policy, so tool-choice capability belongs at the same boundary.

Suggested fix

In buildOpenAIChatPassthroughRequest, after copying the whitelisted fields and only when tools are present:

  • if the model is in autoToolChoiceOnlyModels and tool_choice === "none", preserve none;
  • otherwise, if a tool choice is present, emit auto;
  • leave unlisted models untouched;
  • do not mutate the caller-owned raw body.

Regression coverage

A focused local patch adds cases for:

  • required → auto;
  • exact function selector → auto;
  • none → none;
  • unlisted sibling → unchanged;
  • caller body remains unchanged.

Focused verification: 171 tests passed, 0 failed across OpenAI Chat hardening + DeepSeek reasoning replay + OrcaRouter provider tests.

Live verification against the same local 2.54.0 installation after applying the bounded patch:

HTTP 200
model=deepseek-flash
finish_reason=tool_calls
reasoning_content present
ping tool call emitted with {"value":"ok"}

Checks

  • I searched existing issues for the exact upstream error and tool_choice symptom.
  • No credentials, account IDs, conversation bodies, or private paths are included.
  • The report distinguishes the native Chat passthrough path from the already-correct translated adapter path.

Activity

  1. added
    provider
    on Sep 14, 2026
  2. github-actions commented on Sep 14, 2026

    @github-actions
    Contributor

    Issue closed: use an issue template

    Thanks for taking the time to submit this issue. It was closed automatically because it was not opened with a recognized issue template (Bug report, Feature request, Documentation, or Provider compatibility). Freeform and API-opened issues cannot skip this check.

    • This issue does not use a recognized issue template.

    Please edit the issue to add:

    • Open a new issue with the Bug report, Feature request, Documentation, or Provider compatibility template.
    • Or edit this issue so the body uses the template section headings for the kind of report you are filing.

    See the Contributing guide for details.

    Once the report passes the automated checks, it will be reopened automatically unless a maintainer has changed its state.

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

    provider

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions