残缺或孤立的 tool_calls 记录导致 DeepSeek 接口返回 400 #4843
Replies: 2 comments
|
这个定位方向成立,尤其是 建议修复时把验收边界再收紧一些:
我把 rc.7 → rc.2 → alpha.1 的生产、Turn closure、compaction、wire containment 四层边界和恢复流程合并到了现有 runbook(revision 3): |
|
If you need a fix that works without patching the harness — on a build that still has this bug, or for a session that's already been poisoned — I wrote a plugin-level safety net:
dsh plugin --profile web add dsh-messages-sanitizerSource: https://github.com/Leeminjing/dsh-messages-sanitizer · on npm: It's complementary to, not a replacement for, the harness-side fix: it works on the 如果你需要的是一个不改 harness 源码就能落地的方案——比如跑的还是带这个 bug 的版本,或会话已经被污染了——我写了一个插件层安全网:
dsh plugin --profile web add dsh-messages-sanitizer源码:https://github.com/Leeminjing/dsh-messages-sanitizer · npm: 它与 harness 侧的修复互补、而非替代:它在运行时作用于 |
Uh oh!
There was an error while loading. Please reload this page.
会话历史中存在无配对 result 或 id/name/arguments 残缺的 tool_calls 时,DeepSeek chat-completions 接口返回 400。
复现、预期与验收
insufficient tool messages following tool_calls message或tool_call_id。tool_calls合法。@deepseek-ai/dsh-llm-deepseek适配器。定位与修复建议(附 patch)
根因是三处对「残缺 tool_calls 记录」缺少容错:
packages/core/agent-loop/src/agent.ts—— 拼历史时只剥离孤儿调用,未校验空 id、空 name、非法 JSON arguments 的畸形调用;packages/llm/llm-deepseek/src/translate.ts—— provider 未下发 id 时兜底成空字符串 id(空 id 可能与其他空 id result 误配对);packages/compaction/compaction/src/tool-pairing.ts—— 裁剪边界的配对平衡按「计数」而非 callId,识别不了「数量相等但 callId 错配」。修复改动拆成 4 个 commit(含单元测试),验证结果:
agent-loop340 测试、llm-deepseek151 测试、compaction195 测试全过;完整改动见我的 fork 分支:
https://github.com/bozhang1214/deepseek-harness/tree/fix/tool-call-pairing-harden(fork 后可见);也可直接使用附件中的 patch 文件。All reactions