Skip to content

[Bug] 外部 Harness 线程拒绝纯图片消息(turn/start must contain text input),并级联导致排队卡死、编辑失败、0 秒停止 #174

Closed as not planned

Description

@wosnxn123

症状(用户截图)

  • 新建线程只贴截图(无文字)发送:红色 toast「创建聊天时出错 / turn/start must contain text input」,并留下一个空僵尸线程;
  • 已有线程只贴截图发送:transcript 内联错误项 turn/start must contain text input,图片缩略图出现但 turn 从未运行;
  • 随后排队的文字消息("hi")卡住:tooltip「这条排队中的消息未能发送 / 重试、编辑或删除该消息以继续发送排队的消息」,重试永远失败;
  • 点编辑弹「无法编辑消息」红色 toast(可叠多个);
  • 失败 turn 显示"你在 0秒 后停止了"。

环境

codexhost 0.5.0(main @ 1d021a6),Windows,Codex Desktop;全部 7 个外部 harness 均受影响;官方 Codex 线程不受影响(帧被原样转发给真实 app-server,app-server-host.ts:1155-1156)。

根因链

  1. Codex Desktop 的剪贴板截图在 turn/start wire 上是 {type:"localImage", path}(Codex UserInput union:text / image / localImage / audio / …),不含任何 text 元素。
  2. 外部 harness 线程走 #startExternalTurn(app-server-host.ts:1018-1036),其中 requestText()(:391-400)只保留 type === "text" 的 item,join 后为空即抛 turn/start must contain text input(:398,全仓唯一出处)→ :3115-3121 回 -32602 并 return。图片在 host 层即被丢弃;即使 text+图混发,:3189-3193 也会把命令重包成 input:[{type:"text", text}],harness 永远看不到图。
  3. 契约层本就无图片输入:harness-adapter/src/text-session.ts:118-127 的 turn input 仅 text;shared-contracts/src/harness-models.ts:159-186 能力 schema 无图片声明位,命令 schema .strict() 且测试明确拒绝 acceptsImages(shared-contracts/test/harness-commands.test.ts:36-53);图片输入在 openspec/changes/archive/2026-07-28-implement-harness-adapter-text-slice/design.md:19 被划为 out-of-scope。
  4. 七个适配器各自再做一次 flatten + 空文本守卫:claude-code claude-code-adapter.ts:691-701、pi :706-717、omp :897-908、grok :449-460、opencode :618-628、antigravity :549-558、deepseek legacy :763-774 / modern :888-903。即便只放宽 host,适配器仍会各自拒绝。
  5. 级联:
    • 队列在 Desktop 侧,按自身规则不越过未决失败项;重试重发同一 image-only 帧 → requestText 确定性再抛 → 永久卡住;
    • 编辑 = thread/revert:失败消息从未产生 turn mapping,边界检查必败(external-thread-rollback.ts:228-236,-32080;僵尸线程 turnMappings.length===0 → -32076,:114-119);另有 latent 缺陷 app-server-host.ts:2788 硬编码 numTurns: 1,健康线程编辑非末条消息同样失败;
    • pre-start 拒绝不发任何 turn 生命周期事件(:3118-3120 直接 return;对照 mid-turn 失败会投影 turn/completed{status:"failed"},codex-ui-projector.ts:575-591),Desktop 只能把乐观 turn 渲染成"用户停止、0 秒";清理用 turn/interrupt 也会被 -32074 弹回(:3218-3227)。

修复建议

  1. Host:用解析 Desktop UserInput union 的 requestInput() 取代 requestText():保留 text;接受 image(data-URL)与 localImage(读文件转 base64、设大小上限);仅当 text 与 image 皆无时才拒绝;把结构化 input 传给 session.execute(:3189-3193)。
  2. 契约:HostTurnInput 扩为 union(text | image{mimeType,base64Data,path?});harnessSessionCapabilitiesSchema 增加 input.image 能力位。
  3. 降级路径:对无图片能力的适配器,把图片落盘临时文件并在文本追加 [Image attached: <path>](Claude Code CLI 原生识别提示词中的文件路径)——仅此即可端到端修复 Claude Code;claude-code 适配器进一步可把 SDK user message 建成 content-block 数组(sdk-transport.ts:539-543 现为纯字符串,而 Claude Agent SDK 支持 image block)。
  4. 投影/历史:userMessage item 用 projector 已有的 {type:"inputImage", imageUrl:"data:…"} 形态回显图片(codex-ui-projector.ts:414-424,于 #projectInput :1168-1179 与 projectHistoricalTurn :617),并在 claude-history.ts 持久化,使缩略图重载后不消失。
  5. Revert 健壮性:beforeTurnId 匹配不到 mapping 且其后无已映射 turn(幻影/失败消息在尾部)时返回 no-op 成功(+ thread/reverted),让 Desktop 能编辑/删除失败项、队列得以排空;numTurns 按边界索引计算而非硬编码 1。

验证建议

单测 requestInput:[{type:"localImage",path}]、[{type:"text",text:""},{type:"image",url}]、[];host 级测试仿 app-server-host.test.ts:4713-4735 覆盖对未映射尾 turn 的 revert;适配器测试断言 Claude SDK 收到 image content block。

Activity

  1. wosnxn123 commented on Sep 6, 2026

    @wosnxn123
    Author

    【状态:已修复,待合并】PR: #182 (契约 commit + fix(host-runtime) + fix(claude-code) + fix(protocol-core))

    修复内容:

    1. 契约:新增 HostImageInput {type:"image",mimeType,base64Data,sourcePath?} 与 HostTurnInput union;TurnStartCommand.input/snapshot/autonomous input 改为 union;能力 schema 增加 input:{image:boolean};
    2. host:requestText → requestInput——保留 text,接受 image(data-URL) 与 localImage(读文件、5MiB 上限、mime 由扩展名推断、保留 sourcePath),仅当 text 与 image 皆无才拒绝;capabilities.input.image === true 的会话收到结构化 HostTurnInput[],否则降级为 os.tmpdir 临时文件 + [Image attached: <path>] 文本(staging 失败在任何状态变更前以 -32073 返回);
    3. Claude Code:能力声明 image=true;sdk-transport 以 content-block 数组发送(base64 image source);空文本守卫放宽为"无 text 且无 image"才非法;
    4. 投影:live 与历史 userMessage 以 {type:"inputImage", imageUrl:"data:…"} 回显图片(与工具输出图片同形态),重载后缩略图不消失;
    5. 级联修复:revert 对"未映射尾部边界"(幻影/失败消息、零映射僵尸线程)返回 no-op 成功(Desktop 可编辑/删除失败项、队列得以排空);numTurns 按边界索引计算而非硬编码 1。

    验证:host-runtime 355 通过(image-only turn/start 受理、localImage 解码、无能力适配器降级、revert no-op、numTurns 端到端);claude-code 225 通过(SDK 收到 image content block 断言);protocol-core 104 通过(live/历史 image 回显)。不支持图片的 harness(pi/omp/grok/opencode/antigravity/deepseek)走降级路径或明确 invalidRequest+诊断,不再出现静默丢弃。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions