fix(provider): narrow DeepSeek reasoning history cleanup

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-05-01 19:52:38 +08:00
committed by Xubin Ren
parent 8ca575bdeb
commit 43a58335f6
2 changed files with 67 additions and 9 deletions
+13 -5
View File
@@ -452,6 +452,7 @@ class OpenAICompatProvider(LLMProvider):
def _drop_deepseek_incomplete_reasoning_history(
self,
messages: list[dict[str, Any]],
model_name: str,
reasoning_effort: str | None,
) -> list[dict[str, Any]]:
if (
@@ -460,13 +461,19 @@ class OpenAICompatProvider(LLMProvider):
):
return messages
# For DeepSeek models, always check for incomplete reasoning history
# when thinking mode might be active. reasoning_effort may not be set
# explicitly but the model could still be using thinking mode by default.
# Only skip this check when reasoning_effort is explicitly set to "none".
if reasoning_effort is not None and reasoning_effort.lower() == "none":
semantic_effort = reasoning_effort.lower() if isinstance(reasoning_effort, str) else None
if semantic_effort in {"none", "minimal", "minimum"}:
return messages
# DeepSeek-V4 can require reasoning_content even when the config did
# not explicitly request reasoning_effort. Keep that implicit-thinking
# cleanup scoped to known thinking-capable DeepSeek models so normal
# deepseek-chat history is not trimmed.
if semantic_effort is None:
model_lower = model_name.lower()
if not any(token in model_lower for token in ("deepseek-v4", "deepseek-reasoner")):
return messages
bad_idx = None
for idx, msg in enumerate(messages):
if (
@@ -537,6 +544,7 @@ class OpenAICompatProvider(LLMProvider):
messages = self._drop_deepseek_incomplete_reasoning_history(
messages,
model_name,
reasoning_effort,
)
kwargs: dict[str, Any] = {