Repository navigation
Bug: thinking 模式偶发 400 —— 空 reasoning_content/thinking 占位即可通过,附 pi-ai 与 llm-deepseek 两条链路的修复位置 #11029
CoCoCoDeDeDe
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
摘要
DSH 0.2.1-rc.2 在 DeepSeek thinking 模式下偶发 400:
本文补上 #3857 缺失的一块边界:校验接受空值。只要 assistant 消息上存在
reasoning_content字段(哪怕是""),或 Messages 协议下存在thinking块(哪怕内容为空),请求就能通过。因此修复不需要恢复原始思考文本,只需要给缺失的 assistant 消息补一个空占位。我们在两条 provider 链路上都复现并验证了这一点:OpenAI 兼容网关(pi-ai)和官方 Messages API(dsh-llm-deepseek)。
环境
0.2.1-rc.21.3.0deepseek-v4.1-flash-1017(自建 OpenAI 兼容网关,thinking 模式);deepseek-flash(官方api.deepseek.com/anthropic)复现与实测
OpenAI 兼容链路(pi-ai /
openai-completions)用失败请求的真实历史离线重放(56 条消息,最后以两条 tool 结果结尾):
reasoning_content的 assistant 保持缺失)400 The reasoning_content in the thinking mode must be passed backreasoning_content: ""200""200注意:在长历史里,触发校验的不一定是最后一条 assistant。我们这次是倒数第二条(带
tool_calls、缺reasoning_content)导致 400;只补最后一条不够。官方 Messages 链路(dsh-llm-deepseek)
直连
POST https://api.deepseek.com/anthropic/v1/messages:tool_use,没有thinking块400 The content[].thinking in the thinking mode must be passed backthinking: ""+tool_use200thinking: ""+ 普通text(无 tool_use)200(thinking enabled 与 disabled 都通过)根因
requiresReasoningContentOnAssistantMessages兼容开关默认只对deepseek.comURL 自动开启;经自建网关(URL 不含deepseek.com)时不开启,于是不补空串。assistant()序列化时没有 reasoning 块就什么都不加,Messages API 因此收不到thinking。修复建议
1.
packages/llm/llm-deepseek(官方链路)在
serialize的assistant()中,若message.content不含reasoning块,补一个空 thinking 块:我们已在本地对
0.2.1-rc.2的lib/index.js做该改动,并用官方 API 实测通过。2. pi-ai /
llm-pi-ai(OpenAI 兼容链路)对已知的 DeepSeek 后端(包括自建网关)启用:
或在
llm-pi-ai中允许按 provider 声明「后端是 DeepSeek」,避免必须靠 URL 猜测。3. 持久化侧(可选,但更彻底)
在写入 assistant 消息时就记录「本轮无 reasoning」,重放时统一补空占位;这样两条链路都不再依赖各自序列化逻辑的补丁。
与 #3857 的关系
#3857 描述了同样的 400,并指出
llm-deepseek丢字段。本文补充:附:一次真实失败
sr-gateway/deepseek-v4.1-flash-10178da6d5cb-d9f3-49ab-ba85-44437d428842(另有763b6ca1-e26e-43aa-ab26-f9b429577003)reasoning_content后重放同一请求返回 200。All reactions