Repository navigation
fix: release held done-family events when the next item opens (#1061) - #1062
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1062Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1062.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 On it — pulling the PR branch ( |
[bot] 🏷 Review complete — verified, mergeable. Diff review (head Root-cause check (§Triage): the reported symptom is the root cause here. The hold-until-completion design (#732/#821) is still needed — the retry must be able to drop the degenerate turn's done-family wholesale — but holding across an Verification (all performed by me, not taken on trust):
No small fixes needed on my side — nothing found to patch on the branch. 中文摘要:修复了 Responses 插件管道在退化轮重试机制下把 done 事件扣留到 completion、导致多 reasoning 项时 |
pipePluginResponsesWithStrip held response.output_text.done / response.content_part.done / response.output_item.done until the completion event decided retry, but forwarded response.output_item.added immediately. With an upstream that emits more than one reasoning item per turn (gpt-5.x interleaved thinking), the client saw added(rs_2) before done(rs_1) — opencode v2 hard-errors on that ordering (InvalidProviderOutput: started reasoning before the previous item ended). Fix: an opening output_item.added now flushes pending tag/arg tails and all held done-family events first, restoring exact upstream relative order for every item type. At the terminal event only the last item's family can still be held, so the degenerate-turn retry (#732/#821) keeps dropping exactly what it needs. Secondary path in the same pipe: the retry stream's own reasoning_summary_* frames were raw-forwarded with fresh ids whose items were never announced (their added is dropped by retryFraming), leaking ids the client cannot resolve. They are now suppressed with the other retry framing events.
c122791 to
3aee7e8
Compare
ranxianglei
left a comment
There was a problem hiding this comment.
独立审查(第二双眼睛)——结论:可合并 ✅
Diff 核对(src/plugin.ts +28/-3 + 回归套件 218 行):
- 主修:
output_item.added新分支先flushArgTails()+flushTail("")再放行全部 heldEvents,恢复上游原始顺序;覆盖所有 item 类型而非仅 reasoning——正确,恢复上游序对任何严格客户端都安全。 - 顺序链我逐行核过:
retryFraming(type)在新分支之前消费重试流的 added(不会误触发 flush);added 不在扣留集必达新分支;heldItemId/heldOutputIndex在 retryFraming 丢弃前已捕获。 - 尾帧顺序正确:pending summary/text 尾属于前一 item 的正文,先于其 done 放行,与上游序一致。
heldVisibleChars不清零——已放行文本仍计入空回合判定,防止误触发重试 ✓。- 次要路径:
retryFraming吞掉response.reasoning_summary_*,堵住重试流未 announce 的 reasoning id 泄漏;未做「补发 done」是正确取舍(释放后 rewrite 的 message delta 会打到已关闭 item 上,更糟)。 - 重试语义保留验证:到终局时 heldEvents 只剩最后一个 item 的族,整批丢弃语义不变。
- 与 #1056(刚合入)同函数区域,rebase 无冲突;#1039 的参数透传不变量未被触碰。
验证(本机):rebase 到 master 9caa685 → typecheck 0 错 / 2084 pass / 0 fail / build 成功;E2E codex 四阶段全过(warmup→load→compress→purity, 210s,本地 sglang)。分支已 force-push(c122791 → 3aee7e8)。
动 wire 事件序,按 §7.4 须人工合并。
Problem (#1061)
pipePluginResponsesWithStripheldresponse.output_text.done/response.content_part.done/response.output_item.doneuntil the completion event decided retry, but forwardedresponse.output_item.addedimmediately. With an upstream that emits more than one reasoning item per turn (gpt-5.x interleaved thinking), the client receivedadded(rs_2)beforedone(rs_1). opencode v2 hard-errors on that ordering (packages/ai/src/protocols/open-responses.ts:1501:started reasoning before the previous item ended) — reproduced against the published 0.1.129 pipe with a fully legal stream.Fix
response.output_item.addednow flushes pending tag/arg tails plus all held done-family events before forwarding itself, restoring exact upstream relative order for every item type. At the terminal event only the last item's family can still be held, so the degenerate-turn retry ([BUG] In some cases, with Codex's auto model + DeepSeek, it will suddenly terminate automatically. #732/workbuddy报错Empty stream: upstream gateway sent only placeholder chunks without any model output (chunks=0, bytes=0) #821) still drops exactly what it needs.reasoning_summary_*frames were raw-forwarded with fresh ids whose items were never announced (theiraddedis dropped byretryFraming), leaking ids the client cannot resolve. They are now suppressed with the other retry framing events.Both compression modes considered (§6): this pipe serves the plugin lane and proxy-mode Responses SSE that skips injection (#460); both are restored to upstream order. The non-plugin adapter path (
src/loop/adapter-responses.ts) emits dones immediately and is untouched.Pre-flight
tests/fix-1061-held-done-ordering.test.ts(3 tests): multi-reasoning ordering, healthy-turn order preservation + retry-gate retention, retry reasoning-id leak suppression. Verified RED on master first (all 3 fail with the exact symptom), GREEN after the fix.npm run typecheck— cleannpm test— 2085 pass / 0 fail / 2 skipped (e2e gates)npm run build— successCloses #1061