Skip to content

[Bug] Pi/OMP 工具生命周期校验器把迟到/孤儿帧当作致命协议错误,整会话失效(Omp RPC returned an invalid Tool update) #173

Closed as not planned

Description

@wosnxn123

症状

Oh My Pi harness 线程运行中突然弹出错误项:Omp RPC returned an invalid Tool update,随后 turn 失败终止("已处理 13秒"后无任何后续事件)。实际 omp 子进程仍在正常工作,但会话永久失聪,必须重开线程。

环境

codexhost 0.5.0(main @ 1d021a6),Windows;Oh My Pi(can1357/oh-my-pi,omp --mode rpc)。

复现

  1. 在 OMP 线程中运行会触发异步/后台工具的任务(task 后台作业、detached 子代理;旧版本的 bash 自动后台化同样会发后置 update);
  2. OMP 按自身契约在 tool_execution_end 之后继续发 tool_execution_update(后台作业进度/结算);
  3. codexhost 抛 fatal → turn failed,其后所有事件被丢弃。

根因

packages/adapters/omp/src/omp-rpc-session.ts:1404-1411:

#updateTool(active: ActiveTurn, value: Record<string, unknown>): void {
  const callId = value.toolCallId;
  const outputResult = jsonValueSchema.safeParse(value.partialResult);
  if (typeof callId !== "string" || !active.tools.has(callId) || !outputResult.success) {
    throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
  }
  ...
}

三个致命条件中真正触发的是第二个——生命周期状态不匹配,而非帧格式错误:

  1. tool_execution_start → #startTool(:1380)登记 active.tools.set(callId, …);
  2. 首个 tool_execution_end(后台作业的 async.state:"running" 结果)→ #completeTool(:1413)执行 active.tools.delete(callId)(:1427),UI 渲染"运行了命令"完成态;
  3. 其后到达的同 callId tool_execution_update → !active.tools.has(callId) → 抛错。

而 OMP 上游明确允许这种后置 update:oh-my-pi 的 EventController#handleToolExecutionEnd 对后台 task 故意把组件留在 pendingTools,等后续 tool_execution_update/_end 结算(其测试 event-controller-task-async-updates.test.ts 即按 start → end(async running) → update(async completed) 馈送)。codexhost 假设严格的 start → update* → end 单调用生命周期,与 OMP 契约冲突。

次级隐患:jsonValueSchema.safeParse(undefined) === false(shared-contracts/src/json-value.ts:71-72,测试 json-value.test.ts:48-61 固化)——任何省略 partialResult 键的生产者帧同样致命。对称地雷:OMP 用于结算停放调用的第二个 tool_execution_end 会在 :1418-1425 抛 "invalid Tool end"(id 已删除 → 名字不匹配)。

抛错后果是整会话级:#updateTool → #handle → #push 的 catch(:997-1006)→ #fail(:1661-1666)拒绝全部 pending RPC(含在途 prompt)并 reject active turn;适配器 omp-adapter.ts:999-1017 将 turn 置 failed;#handle 此后在 :1012 早退,后续所有事件丢弃,子进程未被 kill 但会话永久失聪。

同族问题(pi / deepseek)

  • Pi 适配器逐行同型:pi-rpc-session.ts:1261-1268;且该 fatal 行为被测试固化:pi-rpc-session.test.ts:1594-1607("faults a known malformed Tool lifecycle",orphan update 场景 :545-551)。本人在 HEAD 运行该测试:通过,即现状即 fatal。
  • Pi 的 isError 校验比 omp 更严:pi-rpc-session.ts:1270-1283 要求 typeof value.isError === "boolean"(缺失即 fatal),而 omp 容忍缺失(:1422,isError: value.isError === true)。两者 history 映射又把缺失 isError 读作失败(pi-history.ts:234-247、omp-history.ts:235)——同一字段三种读法。
  • deepseek-harness modern:未匹配的 tool/result → ModernHistoryError → #fault(modern/session.ts:1836-1840, 1340-1364)。
  • 对照:grok / opencode / claude-code 均容忍 orphan 帧(grok-adapter.ts:1022-1023 if (!tool) return;;opencode 未知 part delta 忽略;claude 累加器只对已知 tool 发 progress)。

修复建议

  1. #updateTool 区分"格式错误"与"迟到/孤儿":!active.tools.has(callId) 时忽略并计数(return),仅对 callId 非字符串 / partialResult 非法等真损坏保留 fault;
  2. 容忍缺失 partialResult:safeParse(value.partialResult ?? null) 或跳过事件;
  3. #completeTool 容忍迟到/重复 end(id 已删除时忽略而非抛错);
  4. 可选保真:end 携带 details.async.state === "running" 时把 callId 停放到 parkedTools,使后置 update 仍能投影到既有 UI item(对齐 OMP 自身 EventController 语义);
  5. 测试:调整 pi-rpc-session.test.ts:1594-1607(orphan update 改为忽略、turn 继续),为 omp 增加回放 OMP 异步契约的回归测试(start → end(async running) → update(completed) [→ 二次 end])。

一句话本质

codexhost 把 OMP 契约允许的 tool_execution_end 之后异步作业 update 当作致命协议违规;由于抛错路径会 fail 整个 session,一帧良性的迟到帧即杀死 turn 并使其后一切事件不可见。

Activity

  1. wosnxn123 commented on Sep 6, 2026

    @wosnxn123
    Author

    【状态:已修复,待合并】PR: #182 (commit fix(pi,omp): tolerate late and orphan tool frames instead of faulting the session)

    修复内容:

    1. omp/pi #updateTool:callId 不在 active.tools(迟到/孤儿 update,含 OMP 契约允许的 end 之后异步作业 update)→ 忽略而非抛错;仅 callId 非字符串/空、或 partialResult 形状非法保留 fault;缺失 partialResult 以 ?? null 容忍;
    2. omp/pi #completeTool:callId 已删除(重复/迟到 end)→ 忽略;live id 名字不匹配、result 形状非法仍 fault;
    3. isError 极性统一:live pi 与 omp 一致(缺失=成功、true=失败),pi-history/omp-history 同步改为 isError === true 才失败,live 与 history 读法一致;
    4. 顺带:pi/omp 暴露 refreshUsage()([Bug] usage/缓存指标跨适配器语义不一致:claude 不发 cache 字段且 inputTokens 中途翻转、grok input 含 cache、opencode "latest" 实为累积、antigravity 逐 turn 回退 #177 的一部分)。

    验证:改写 Pi 原先固化 fatal 行为的测试为 late-tool-frames(orphan update → start → end(running) → late update → duplicate end → settle:无 fault、turn 成功、仅一对 started/completed);新增 omp 异步契约回放回归(start → end(async running) → update(completed) → 二次 end)与 missing-partialResult/missing-isError 容忍用例、history 极性用例;pi+omp 176 测试通过。

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