magpie icon indicating copy to clipboard operation
magpie copied to clipboard

gateway, provider: Command Code 拒绝压缩输入后 Magpie 不降级,三次失败后锁定会话

Open Edward4226 opened this issue 1 month ago • 2 comments

现象

Command Code 拒绝 Codex 的压缩输入后,Magpie 没有降级成纯文本摘要,而是把 400 原样交给 Codex;同一会话连续失败 3 次后,5 分钟压缩保护再返回 400,线程在保护期内无法继续压缩。

直接拒绝请求的是 Command Code,触发条件是 Responses input 里有它不支持的 item;但这个 provider 兼容问题变成会话级故障,是 codexCompact 没识别这个明确的 400,以及 compactFails 继续累计失败造成的。

  • Magpie v0.1.2762,commit 173b7e2742530dc6c9b7cd14f63cbf8eafc79f9c
  • 2026-11-03 14:14 和 2026-11-04 03:31、05:17 三次出现同一错误
  • Codex 经 /backend-api/codex 直接使用 commandcode/deepseek/deepseek-v4.1-flash
  • 同一时段普通请求仍返回 200,不是账号、密钥或模型整体不可用

Command Code 返回:

{"error":{"message":"input items may be messages, function calls, function call outputs and reasoning. Item references need stored responses, which are not kept.","type":"invalid_request_error","param":"input","code":"unsupported_input_item"}}

本地日志随后出现:

codex compaction: commandcode/deepseek/deepseek-v4.1-flash failed to summarise this conversation 3 times in a row
(last: Command Code: ... "code":"unsupported_input_item")
magpie doesn't ask it again for 5m0s

用本地 Magpie 重放合成的压缩历史时,普通消息、reasoning、function call/output、custom tool、web search、developer/system 角色都返回过 200。因此这不是“Command Code 完全不接受 Codex 历史”,也不能据此认定 Codex 发送了非法请求。

#2790 的最后错误是 Chat 消息里的 tool 没有前置 tool_calls;#5134 是 keepalive 把上游 400 变成 SSE error,导致原有兜底没有触发。本 issue 是 Responses 的 unsupported_input_item 在进入纯文本兜底前就被返回,三者不是同一个触发条件。

自动复现使用 fake provider:结构化请求包含 item_reference 时返回上面的完整 400,纯文本请求返回正常摘要。在父提交 5957223d89bd 上,TestCodexCompactUnsupportedInputItemAsksAgainAsText 返回 400,且只问上游一次:

--- FAIL: TestCodexCompactUnsupportedInputItemAsksAgainAsText
    400 {"error":{"code":"unsupported_input_item",...}}

改动

codexCompact 现在只对下面这一种拒绝先做一次 plainCompact:

  • HTTP 400
  • error.code == "unsupported_input_item"
  • error.param == "input",或以 input[、input. 开头

纯文本请求只包含 messages,不再携带原来的 item references。第二次成功则返回模型摘要;第二次仍失败则使用 localSummary,返回 Magpie 自己的 compaction item,并记录 provider 的原始拒绝原因。这样一次可恢复的形状拒绝不会再累计到 5 分钟保护。

其他 400、401、403、429 和真正的摘要生成失败保持原行为。新增 unsupportedInputItem 的边界测试,并保留 TestCodexCompactOtherRefusalStays、TestCodexCompactOther400Stays 作为负向对照。

补丁

采纳:

git fetch https://github.com/Edward4226/magpie.git codex/commandcode-compact-unsupported-input
git cherry-pick FETCH_HEAD

yetone/magpie 的 PR policy 是 collaborators_only,因此没有开 PR。

跑过什么

  • 父提交 5957223d89bd:反向红测真实失败,错误为 400,上游只被问一次。
  • 聚焦测试:TestUnsupportedInputItem、TestCodexCompactUnsupportedInputItemAsksAgainAsText、TestCodexCompactOtherRefusalStays、TestCodexCompactOther400Stays,通过。
  • 全部 TestCodexCompact*,通过,12.613s。
  • gofmt -l:无输出。
  • go vet ./...、GOOS=linux go vet -tags nogui ./...、GOOS=windows go vet ./...:通过。
  • native、GOOS=linux -tags nogui、GOOS=windows build:通过。
  • git diff --check:通过。
  • 全量 Windows 套件没有绿:internal/agent 在 TestClaudeOwnTierStaysThroughTheMainModel 超时,internal/gateway 在 TestQueuedStreamKeptAliveOnceSentToItsVendor 超时,另有既有 platform/path 测试失败。这些都不在本次压缩改动路径内,但没有在父提交逐项复跑归因。

Not tried

  • 修复后的二进制没有部署,也没有在原始失败会话上复测。
  • 没有拿到完整的原始压缩请求体,因此具体被拒绝的是 item_reference、另一个 Codex item 类型,还是它们的组合,仍未确认。
  • 没有用真实 Command Code 账户跑最小化请求;自动测试中的 400 是按报告原文做的 fake provider。
  • 没有在父提交上逐项复跑完整 Windows 套件来归因所有既有红项。

Edward4226 avatar Nov 04 '26 06:11 Edward4226

补一条:补丁已基于 main 的 583fe707516ceeb4093c9b2dd29fc695892ab3d4 重做,最终提交是 dbb7fa84bcc0ef353573bb3a5c7d09843c880a26,定向测试和构建已在这个提交上重跑。

结果

改动仍是三处:unsupportedInputItem 只识别 HTTP 400、error.code == "unsupported_input_item"、且 error.param 是 input 或以 input[、input. 开头;命中后 codexCompact 用纯文本重问一次,第二次仍失败才用 localSummary。其他 400、401、403、429 和真正的摘要生成失败保持原行为,compactFails 的 5 分钟保护没有改。

证据

检查 结果
原父提交 5957223d89bd 的反向红测 FAIL,返回 400,上游只被问一次(正文已给)
聚焦测试 TestUnsupportedInputItem、TestCodexCompactUnsupportedInputItemAsksAgainAsText、TestCodexCompactOtherRefusalStays、TestCodexCompactOther400Stays ok github.com/yetone/magpie/internal/gateway 2.816s
全部 TestCodexCompact* ok github.com/yetone/magpie/internal/gateway 11.443s
gofmt -l / git diff --check 无输出 / 通过
go vet ./...、GOOS=linux go vet -tags nogui ./...、GOOS=windows go vet ./... 通过
native、GOOS=windows、GOOS=linux -tags nogui build 通过

边界

这不是把所有 provider 的 400 都改成纯文本重问,也不是提前删掉所有 item reference。只有这个明确的 code 和 input 参数位置命中时才走一次兜底;请求仍然先按原样发,失败原因也会保留。

Not tried

  • 修复版二进制没有部署,也没有在原始失败会话上复测。
  • 没有拿到完整的原始压缩请求体,因此具体被拒绝的是 item_reference、另一个 Codex item 类型,还是它们的组合,仍未确认。
  • 没有用真实 Command Code 账户跑最小化请求;自动测试中的 400 是按报告原文构造的 fake provider。
  • 没有在 583fe707 上跑完整 Windows 套件。2026-11-04 在旧基线上的全量套件有既有超时和平台失败,未逐项归因到本补丁。

动作

维护者可以直接按上面的 compare 或 patch 检查并 cherry-pick。需要继续抓完整压缩请求体或用真实账户复测,我再补结果。没有关闭 issue,也没有催 review。

Edward4226 avatar Nov 05 '26 04:11 Edward4226

Fixed in ff415f39c, released as v0.1.3139.

What changed: when the compaction request is refused with unsupported_input_item (or Grok's 422 "unknown item type"), magpie now asks for the summary again with the conversation as plain text, which Command Code accepts. This applies to the 400 itself, to a 400 or 502 from another magpie in front, and to the same error inside a stream (error / response.failed). Before, the 400 went back to Codex, and after three of them the conversation was held for 5 minutes. If the text request is refused too, magpie writes the summary itself and Codex carries on. A subagent's agent_message items (its task and follow-ups) are now included in that text as the user's turns. A 401, 403 or 429 with the same words is still returned as it came.

The Command Code plugin is unchanged. The fix is in magpie's gateway, so it covers every subscription that refuses an input item this way.

Tests: built from the refusal quoted here and from #5259 subagent compaction (agent_message, custom_tool_call, compaction_trigger). They fail on the old code. Not tried: a real Command Code account. Please update and tell us whether compaction works now. I'm leaving this open until you confirm.

yetone avatar Nov 06 '26 08:11 yetone