WindsurfAPI icon indicating copy to clipboard operation
WindsurfAPI copied to clipboard

两处 wire 语义待现场校准:result 先于 call 的历史、同回合多帧的 reasoning 重复

Open dwgx opened this issue 2 months ago • 2 comments

两处都已被注释与守卫钉住「当前行为」,但「上游到底接不接受」没有实测过。两者都不得用「同源 run ≥ 3 被拒」的已测结论去外推。

1. tool_result 先于其 call 的历史

stripOrphanedToolResults()(src/handlers/tool-emulation.js)收集的是整段历史的 call id,不是「到当前位置之前」。因此 [tool(a), assistant(tool_calls=[a])] 这种逆序历史在 stripOrphans:true 下保留 [4,2];若上游状态机要求 call 先于 result,这会在 wire 上留下孤儿。

  • 已测:三入口行为一致(direct / normalize / strip),见 test/wire-h2-orphan-scope.test.js;注释已在 6b8762f 写准(此前写的是 earlier in the conversation,与实现相反)。
  • 未测:上游对逆序 pair 的响应。
  • 最小实验:单 call 对照 [user, call(a), result(a), user] vs [user, result(a), call(a), user],固定账号 / 模型 / flags,各用独立会话,记录完整终止帧。不要把它和 run ≥ 3 混进同一个实验。

2. replay 开启时同一逻辑回合拆出的多帧重复携带 reasoning

DEVIN_CONNECT_REPLAY_REASONING=1 时,raw builder 把同一段 reasoning 写到 preText 帧与每个 call 帧(k+1 份,无 preText 时 k 份);经过既有预处理(交错拆分)后,完整匹配的 batch 实际是 2 份 / 1 份。

  • 编码器注释引用 req022:"every role=2 assistant turn carries #11, 59B–1470B" —— 这只证明字段存在,不证明同回合各帧载荷相等,也不是「replay 默认应开」的依据。
  • 未测:真实客户端在同一回合的多帧上是否重复携带;reasoning / reasoning_content 两个别名同时出现时上游更期望哪个(当前实现取 first-truthy,两个分支的 trim 行为也不同)。
  • 最小实验:抓一份真实 Devin 客户端同回合多帧的 wire,逐帧比较 #11 的字节。若相等,现有政策与参考一致(改注释即可);若不等,按抓包改编码。

两处当前行为与别名优先级已由 test/wire-h3-reasoning-policy.test.js 与 test/mutations/wire-h3-reasoning-policy.json(11 条突变)钉住。

dwgx avatar Sep 16 '26 12:09 dwgx

Two of the three questions now have tests: split arguments assemble byte-exactly at 1/128/4096-byte boundaries on all four surfaces, and a post-terminal error cannot be masked by the earlier success terminal (terminal-then-error yields the protocol's failure shape, not message_stop/response.completed/finishReason). The remaining question is upstream acceptance of a tool_result before its call, which needs a live capture; the local whole-history orphan rule is deliberate (src/handlers/tool-emulation.js:1089-1096).

dwgx avatar Oct 21 '26 15:10 dwgx

Status after v3.10.0: none of the three questions in this issue changed behavior — src/handlers/tool-emulation.js and src/leak-trace.js are untouched by the wave. Re-ran the pinning suites on the tag: orphan-scope 4/4, reasoning-policy 4/4 + 11 mutations, split-arguments byte-exact on all four surfaces, terminal-then-error not masked.

The remaining question is still the live one: does the upstream accept a tool_result before its call. The whole-history orphan rule is deliberate (src/handlers/tool-emulation.js:1089-1096): a seen-so-far set would silently discard a result whose matching call appears later, so the filter keeps it and lets the wire decide. That decision needs one real capture — an independent session with the full terminal frame — and there is nothing to change locally before that arrives.

dwgx avatar Oct 23 '26 22:10 dwgx