Repository navigation
fix(worker): 未确认投递隔离在前序未结束时也能释放并重新驱动队列 (#2642) - #2648
Merged
Merged
Conversation
…d」偶发 (#2642) TraeX 某条输入的 history 回执晚于 writeInput 的在线确认预算时,worker 进入 「submit 未确认 → 投递隔离」。隔离在前序 turn 仍未结束时释放不了: - 精确终态排在未结束的前序后面,FIFO 不出队,走不到释放; - 20s 延迟复查把「已收到原生终态、尚未出队」的同一 attempt 当成被替换,直接作废; - 复查释放后的 redrive 在未 prompt-ready 时只 fireIdle,而前序未结束时 idle 边被 post-terminal 围栏挡住,type-ahead 队列没人再驱动。 修法: - settleDeferredSubmitConfirmation:只有精确 attempt 已不在队列才算过期;已终态 未出队的 attempt 直接按结构化证据确认(不跑适配器复查、不看 usage-limit),只 释放隔离,final/terminal 仍由 FIFO drain 发。 - 隔离释放时直接 flushPending(与新消息到达同一入口,各投递闸照常判定),未 ready 时再补 fireIdle。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 31, 2026 17:54
复审指出:新用例只覆盖 assistant_final,若将来 hasTerminalTurn 被改成 只认非空 finalText,turn_aborted(空 final + ambiguous)会静默回退到 stale:attempt 丢弃(TraeX 隔离永久卡死且不发终态)。补用例:FIFO 堵在 未结束前序后的 abort 终态,断言 hasTerminalTurn 为 true、复查零调用、 按 suppress-active/structured-transcript 结算,且空 final/ambiguous 终态 保留在队列中供 FIFO drain 发出。 变异:hasTerminalTurn 加 finalText !== '' 条件 → 本用例红、 assistant_final 用例仍绿(钉的是 abort 特有语义)。 Co-Authored-By: Claude Code <[email protected]>
|
@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 f308264…46bd9c50e(4 个提交),同批合入的还有 #2649 #2645 #2586,失败不一定由本 PR 引起。
|
This was referenced Oct 31, 2026
|
🚀 Released in v3.56.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 #2642(修复后可关闭)。
根因:产品 bug,不是等待预算或夹具问题
TraeX 某条输入的 history 回执晚于
writeInput的在线确认预算时(测试里BOTMUX_TIME_SCALE=0.01,预算约 26ms;CI 高负载下回执经常更晚),worker 会进入「submit 未确认 → 投递隔离」(quarantineUnconfirmedSubmits,目前只有 TraeX 打开)。隔离的作用是把后续输入挡在 BotMux 里,只有两条路能释放它,而前序 turn 还没结束时两条都走不通:CodexBridgeQueue的 FIFO 里排在没结束的前序后面,drainEmittable()不让它出队,releaseInputDeliveryQuarantineForStructuredTerminal就一直没被调用。settleDeferredSubmitConfirmation用hasPendingTurn判断 attempt 还在不在。这个函数要求finalText === undefined,于是「已收到终态、还没出队」的同一个 attempt 被当成「已被替换」,复查直接作废(日志:Discarded stale deferred submit recheck (attempt))。隔离永远不会释放,之后的输入全部卡住。把 2 修好以后还有第二道闸:复查释放隔离后会做 redrive,但在没到 prompt-ready 时它只调
fireIdle()。前序没结束,idle 边会被 post-terminal 围栏(postTerminalPromptFenceHolds)挡回去,type-ahead 队列就没人再驱动了。这条路径同样会让「第一条输入被隔离」这种变体卡死(高负载复现里就碰到过)。CI 失败日志(run 41209945586)与上述完全吻合:
Quarantined … turn=om_capacity→deferred 20000ms recheck queued→ 20s 后Discarded stale deferred submit recheck (attempt)→ 第三条输入再也没写进去,41.7s 超时。修法
src/services/submit-confirmation.ts:只有精确 attempt 已经不在队列里(被 prune,或被 N+1 替换)才算过期。已收到终态、还没出队的 attempt 直接按结构化证据结算(suppress-active / structured-transcript):不跑适配器复查,也不看 usage-limit,worker 侧只调onConfirmed释放隔离;final 和 terminal 仍由 FIFO drain 发出。src/worker.tsreleaseInputDeliveryQuarantineredrive:直接调flushPending(),和新消息到达走同一个入口,type-ahead、restart、围栏等各道投递闸照常判定;没到 ready 时再补一次fireIdle()。没有调大任何超时,也没有改原用例的等待条件。
影响面
settleDeferredSubmitConfirmation由所有走codexBridgeQueue的 CLI 共用(Codex、CoCo、TraeX 等)。改动只影响「精确 attempt 已终态、未出队」这一种状态:旧行为是静默作废,新行为是按结构化成功结算、不发终态也不发卡。pending、已出队、被替换这几种状态的判定都不变。复现与验证
确定性复现(修复前红 → 修复后绿):夹具新增
delayedHistoryReceipt,让第 N 次提交的 history 回执晚 400ms 落盘,等价于高负载下回执错过在线预算。新增两条用例:被隔离的分别是原始提问(第 1 条)和改变 capacity 的那条纠正(第 2 条)。Quarantined … om_capacity→Discarded stale deferred submit recheck (attempt)→timeout: held input after composer)。bun test test/traex-auto-model.integration.test.ts -t "late receipt quarantines|successive input queued"→3 pass 0 fail。高负载复现(isolate-run,假 CLI 关掉 systemd scope,和 worker 一起吃 CPU/IO 压力):
ebf9695be,--cpus 1、3 路并行 × 8 轮、4 个yes加 2 路dd oflag=dsync:原用例23 pass / 1 fail。失败那次是第一条输入回执迟到被隔离,20s 后复查释放了隔离,但 type-ahead 队列再也没被驱动,45s 超时,属于上面的「第二道闸」。(第 2 条输入变体要在更重的负载下才出现;更重的配置会先在启动阶段超时,所以 CI 指纹那个变体用上面的确定性复现覆盖。)24 pass / 0 fail(两轮都是)。isolate-run --cpus 4 -- bun test test/traex-auto-model.integration.test.ts→22 pass 0 fail。vitest 腿只跑新增和原用例:3 passed。变异复验(摘掉守卫必须咬红):
submit-confirmation.ts还原到 master → 单测「still settles an exact attempt whose native terminal is FIFO-held…」红;集成用例「…quarantines the capacity-changing correction」红,timeout: held input after deferred recheck。if (isPromptReady) flushPending(); else fireIdle()→ 两条集成用例都红(timeout: correction submitted/timeout: held input after deferred recheck)。相关单测:
bunx vitest runbridge-fallback-gate、dispatch-user-route、submit-confirmation、traex-auto-model-worker、worker-codex-session-upgrade、worker-input-delivery-redrive、worker-structured-turn-attribution、codex-bridge-queue → 490 个全部通过(worker-input-delivery-redrive原来断言「未 ready 时不 flush」,这条钉的正是第二道闸,已改成新契约);bun 腿submit-confirmation+worker-input-delivery-redrive27 pass。tsc/bun run build:本机共享node_modules缺@base-ui/react(master 新加的依赖),报searchable-group-picker.tsx两个错误。master 基线报的是同样两个,和本 PR 无关,交给 CI 的全新安装验证。独立对抗复核
攻击面:复查窗口内人工干预(restart / 换代)、终态到达但未出队、复查 await 期间换代、prune 过期、attempt N 被 N+1 替换、隔离释放后无条件 flush 与 restart / 新隔离 / 非 type-ahead 的交叠。复核时用真实
CodexBridgeQueue、真实scheduleSubmitFailureNotify加假时钟跑了探针。suppress-usage-limit发failed终态,dropPendingTurn(…, allowStarted)删掉已收齐的 final,回复丢失,影响所有 codexBridgeQueue CLIterms=[capacity failed submit_usage_limit];旧语义对照组正常 drain 出doneinput_not_submitted无条件
flushPending的探针:非 type-ahead 且未 ready、microtask 前进入 restart、microtask 前又布了新隔离,这几种情况写入都是 0 次;type-ahead 非 durable 时写入 1 次,符合预期。不发版,不部署。
🤖 Generated with Claude Code