Skip to content

fix(worker): 未确认投递隔离在前序未结束时也能释放并重新驱动队列 (#2642) - #2648

Merged
deepcoldy merged 2 commits into
masterfrom
fix/traex-successive-queued-2642
Oct 31, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
fix/traex-successive-queued-2642

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

关联 #2642(修复后可关闭)。

根因:产品 bug,不是等待预算或夹具问题

TraeX 某条输入的 history 回执晚于 writeInput 的在线确认预算时(测试里 BOTMUX_TIME_SCALE=0.01,预算约 26ms;CI 高负载下回执经常更晚),worker 会进入「submit 未确认 → 投递隔离」(quarantineUnconfirmedSubmits,目前只有 TraeX 打开)。隔离的作用是把后续输入挡在 BotMux 里,只有两条路能释放它,而前序 turn 还没结束时两条都走不通:

  1. 精确终态:被隔离 attempt 的原生终态已经到了,但它在 CodexBridgeQueue 的 FIFO 里排在没结束的前序后面,drainEmittable() 不让它出队,releaseInputDeliveryQuarantineForStructuredTerminal 就一直没被调用。
  2. 20s 延迟复查: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.ts releaseInputDeliveryQuarantine redrive:直接调 flushPending(),和新消息到达走同一个入口,type-ahead、restart、围栏等各道投递闸照常判定;没到 ready 时再补一次 fireIdle()。

没有调大任何超时,也没有改原用例的等待条件。

影响面

  • settleDeferredSubmitConfirmation 由所有走 codexBridgeQueue 的 CLI 共用(Codex、CoCo、TraeX 等)。改动只影响「精确 attempt 已终态、未出队」这一种状态:旧行为是静默作废,新行为是按结构化成功结算、不发终态也不发卡。pending、已出队、被替换这几种状态的判定都不变。
  • 投递隔离只有 TraeX 会布,redrive 的改动只在隔离释放时生效。
  • 只涉及 worker 内存状态,不涉及持久化;PTY / tmux 后端走同一条路径(tmux 变体交给 CI)。

复现与验证

确定性复现(修复前红 → 修复后绿):夹具新增 delayedHistoryReceipt,让第 N 次提交的 history 回执晚 400ms 落盘,等价于高负载下回执错过在线预算。新增两条用例:被隔离的分别是原始提问(第 1 条)和改变 capacity 的那条纠正(第 2 条)。

  • master 上:第 2 条用例的日志指纹与 CI 逐字一致(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 压力):

  • master 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。

变异复验(摘掉守卫必须咬红):

  • M1: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。
  • M2:redrive 还原成 if (isPromptReady) flushPending(); else fireIdle() → 两条集成用例都红(timeout: correction submitted / timeout: held input after deferred recheck)。

相关单测:bunx vitest run bridge-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-redrive 27 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 加假时钟跑了探针。

级别 场景 探针证据 处理
P1 第一版修法(已终态 attempt 照常跑复查)下,复查 miss 又同时检测到 usage-limit:走 suppress-usage-limit 发 failed 终态,dropPendingTurn(…, allowStarted) 删掉已收齐的 final,回复丢失,影响所有 codexBridgeQueue CLI 探针 drained 只剩前序、terms=[capacity failed submit_usage_limit];旧语义对照组正常 drain 出 done 改成已终态 attempt 直接按结构化成功短路,不跑复查、不看 usage;单测覆盖「recheck=false + usageLimit=true」时 recheck 不被调用、attempt 仍在队列
P3 同一版下,没有 turnId 的输入复查 miss 会误发「未提交」卡 探针 notifies 出现 input_not_submitted 同一处短路一并修复

无条件 flushPending 的探针:非 type-ahead 且未 ready、microtask 前进入 restart、microtask 前又布了新隔离,这几种情况写入都是 0 次;type-ahead 非 durable 时写入 1 次,符合预期。

不发版,不部署。

🤖 Generated with Claude Code

…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]>
复审指出:新用例只覆盖 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
deepcoldy merged commit fefe1c6 into master Oct 31, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 f308264…46bd9c50e(4 个提交),同批合入的还有 #2649 #2645 #2586,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Gemini basic bot flow feishu-core-clis failed Replanned 20 times, exceeding the limit. Please configure a larger value for replanningCycleLimit (or use MIDSCENE_REPLANNING_CYCLE_LIMIT) to handle more complex tasks.
Codex prompt submission feishu-core-codex failed Node "feishu.waitForBotResponse" timed out after 300000ms.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

🚀 Released in v3.56.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant