Skip to content

[Bug] 修复 reasoning_content 传回错误 #223

Description

@9Rebels

What happened? / 问题描述

为什么昨天没修好
昨天的判断是对的,但不完整。改的是 compat 开关(只认 provider=="deepseek" 或 baseUrl 含 deepseek.com,中转站不匹配)。可真正补空串的那行还有第二道锁:

if (compat.requiresReasoningContentOnAssistantMessages && model.reasoning && ...)
^^^^^^^^^^^^^^^ 卡在这
model.reasoning 在中转站场景是 false(模型不在 models.dev 目录里,拿不到 thinkingLevels)。所以开关开了也没用,补空串一次都没跑过。

证据链:

补丁文件 21:42 写入,sidecar 21:44 才启动 → 代码确实加载了
但错误在 21:43 之后继续出现,今天 13:45 / 13:51 / 13:54 / 13:58 又出现 4 次
这个会话失败前有 1146 条 assistant 消息,其中 575 条有思考、124 条有正文但没思考 —— 那 124 条缺 reasoning_content,历史变成「部分覆盖」
服务端规则我实测过(同一分钟内):部分覆盖 → 400,补全 → 200,全不带 → 200。PI-Desktop 正好卡在最坏的那档。

昨天我重放的脚本里手动做了补全 —— 那验证的是服务端的规则,没验证客户端会不会真的补。这是我漏的一步。

现在的修复
resources/agent-runtime/sidecar.js,三处:

A compat 开关认得「模型 ID 含 deepseek」的中转站模型(昨天的改动,保留)
B 补空串改成由「历史里出现过思考」触发,彻底不依赖 model.reasoning,顺手把 null 也当缺失:
const isDeepSeekTarget = compat.requiresReasoningContentOnAssistantMessages || /deepseek/i.test(model.id);
const historyHasThinking = transformedMessages.some(m => m.role === "assistant" && Array.isArray(m.content)
&& m.content.some(b => isThinkingContentBlock(b) && b.thinking.trim().length > 0));
const backfillReasoningContent = isDeepSeekTarget && (model.reasoning === true || historyHasThinking);
C 临时诊断日志,每次请求往 %TEMP%\pi-reasoning-debug.jsonl 写一行请求形状
只对 deepseek 系模型生效,glm / claude / gpt 一律不受影响。

Steps to reproduce / 复现步骤

看上面

Expected behavior / 预期行为

看上面

Actual behavior / 实际行为

看上面 不知道你之前的修正包含了这个没有

App version / 应用版本

0.14.6

Operating system / 操作系统

Windows

Extra environment / 其他环境信息

PI-Desktop 0.14.6 · win32 x64 · protocol 11 · host 0.14.6

Logs / 日志

Screenshots / 截图

No response

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions