Skip to content

fix(worker): STOP 退休已被 hold 回队列的在途定时写入 - #3979

Merged
deepcoldy merged 10 commits into
deepcoldy:masterfrom
yintamaa:fix/stop-drops-retain-retry
Nov 28, 2026
Merged

deepcoldy merged 10 commits into
deepcoldy:masterfrom
yintamaa:fix/stop-drops-retain-retry

Conversation

@yintamaa

Copy link
Copy Markdown
Contributor

改动内容

STOP 现在能识别已被 hold 回队列的在途定时写入:没有活动定时 turn、也没有在途定时写入时,若该写入此前由当前 CLI 的 flushPending 发起并在写入前被 retain,STOP 会按既有语义退休同任务条目,只回执一次,并取消其重试计时器;重试触发后不再写入。

覆盖两个共用重试槽的入口:

原因

retain 结算后 flushPending 清空 cliSubmissionInFlight,只留下 scheduledAdmissionRetry 重试槽。discardScheduledBacklogForStop(src/worker.ts,master 第 14960 行)只从活动 turn 与 cliSubmissionInFlight 推导 STOP 目标,看不到这个窗口:STOP 不退休队首,turn_input_rejected=0,随后重试照常写入一次。STOP 若在 hold 结算前一刻到达,写入会被标记 scheduledWriteCancelled 并按 reject 回执一次,两者结果不一致。

实现

  • 新增单槽 heldScheduledWrite。settleScheduledCliInputHold 按 retain 结算,且该条目正是当前代际 flushPending 中仍处于 scheduledWritePending 的写入时,记录条目、backend、generation、当时的 currentBotmuxTurnId、Web 终端提交代数和 raw 写入代数。
  • 清除时机:任一输入登记写入(共用的 noteCliInputWritten,队列写入与 TraeX 原生回答都会经过),或该条目被退休回执(discardUnwrittenScheduledInput)。
  • discardScheduledBacklogForStop 的目标顺序:活动定时 turn → 在途定时写入 → 仍有效的 heldScheduledWrite。有效的条件:backend 与 generation 未变;条目仍在 pendingMessages;没有其他输入正在写入;此后没有其他 turn 成为当前 turn;Web 终端提交代数和 raw 写入代数都未变。之后沿用既有退休逻辑,并在退休条目时调用 cancelScheduledAdmissionRetry(item)。
  • 以下行为不变:首部门控 retain(条目从未成为在途写入,STOP 早一刻到达同样不会退休它)、adopt 队列、非定时输入。
  • 测试 harness 为 pendingMessages 补默认空队列,与 pendingAdoptMessages 一致。原因是部分用例自建的 scope 会经 handleTermAction 调到 STOP 逻辑。

测试

test/worker-scheduled-deferred-retain.test.ts 新增 14 个用例,使用真实的 flushPending、term_action、discardScheduledBacklogForStop、killCli、noteCliInputWritten:

  • 写入边沿 retain(deferred 与 non-deferred)→ STOP → 重试:队列清空,回执 1 次,重试槽清空,不写入;
  • 预检中断 retain → STOP → 重试:结果同上,且没有任何准备副作用;
  • 重试通过首部门控后被阻塞、或在写前检查被拒(absorbed final 未结算)而留在队首:STOP 仍退休它,回执 1 次;
  • CLI 被替换(hold 在替换前或替换后结算)、真人输入越队写入(有或没有 turnId)、其他 turn 成为当前 turn、Web 终端提交、raw 透传写入、其他输入正在写入:STOP 都保留该写入,回执 0 次;
  • 首部门控 retain → STOP:条目保留,没有回执,重试写入一次。

已运行:

  • npx vitest run test/worker-scheduled-deferred-retain.test.ts:35/35;同文件 bun test:35/35。
  • flushPending / workerSubmitHarness / term_action 相关的 69 个测试文件(含 test-hygiene):3583 passed,13 skipped,0 failed。
  • bun run typecheck && bun run build:通过。

变异复验:

  • 回退 src/worker.ts:5 个用例失败(STOP 后队首仍保留),与问题描述一致;
  • 只去掉 STOP 对 heldScheduledWrite 的识别:同样 5 个失败;
  • 依次去掉以下各项,每次都有对应用例失败:写入者代际校验、STOP 时 backend/generation 校验、其他写入者校验、当前 turn 校验、Web 提交代数、raw 代数、noteCliInputWritten 中的清除、退休时的重试取消;
  • 把清除点前移到 prepareNormalWrite 开头:「写前检查被拒」用例失败;
  • 队列成员校验是防御性条件,没有专门用例覆盖。

已知边界(未在本 PR 处理)

  • tmux attach 的可写 Web 终端走 countHuman=false,提交不会递增 webTerminalSubmitGeneration。若 hold 后经该通道提交新输入再按 STOP,定时写入仍会被退休。
  • 在途写入等待写入边沿 admission 期间发生的 Web 提交,会被当作 hold 时的基线。这与 master 上 STOP 在该等待期间到达时直接取消在途写入的语义一致。

Refs #3963 / follow-up of #3974

🤖 Generated with Claude Code

定时写入在写入边沿(admission retain)或 Codex 预检窗口(中断/Web 输入线变脏)
被 hold 为 retain 后,flushPending 结算时清空 cliSubmissionInFlight,只留下
scheduledAdmissionRetry 重试槽。discardScheduledBacklogForStop 仅从当前活动
turn 与 cliSubmissionInFlight 推导 STOP 目标:此时到达的 STOP 不退休队首条目、
不回执,随后重试照常写入一次,与 STOP 在 hold 结算前一刻到达(标记
scheduledWriteCancelled、按 reject 回执一次)的结果不一致。

修复:
- 新增单槽 heldScheduledWrite:settleScheduledCliInputHold 按 retain 结算、且该
  条目正是当前代际 flushPending 中仍处于 scheduledWritePending 的写入时,记录
  条目、backend、generation、当时的 currentBotmuxTurnId、Web 终端提交代数与
  raw 写入代数。任一输入登记写入(共用的 noteCliInputWritten)或该条目被退休
  回执时清除。
- STOP 在没有活动定时 turn、也没有在途定时写入时,若该槽仍有效(backend 与
  generation 未变、条目仍在 pendingMessages、没有其他输入正在写入、此后没有其他
  turn 成为当前 turn、没有 Web 终端提交或 raw 写入),以其任务为目标,按既有语义
  退休同任务条目并只回执一次;退休时同步取消其重试计时器。
- 标记独立于重试槽:重试已触发、通过首部门控后又被阻塞,或在写前检查被拒并留在
  队首的条目仍归 STOP。CLI 被替换后(含 hold 在替换后才结算的旧写入),或其他
  输入(队列越队、Web 终端、raw 透传)接管 CLI 后,STOP 不再接管该写入。
- 首部门控 retain(从未成为在途写入)、adopt 队列及非定时输入的 STOP 语义不变。

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:需修改,1 个新增阻断

P2 / 阻断:注入斜杠命令后,STOP 会误退休 held 定时写入

src/worker.ts:15025-15035 判断 heldScheduledWrite 仍有效时,只检查 backend/generation、currentBotmuxTurnId、Web submit 与 raw 写入代数;但非 keepalive 的 flushPendingInjections 在 src/worker.ts:26578-26614 成功写入 tuiSlashAllow 白名单命令(例如 /compact)时,不调用 noteCliInputWritten、不轮换 currentBotmuxTurnId,也不推进这两个代数。

因此下面的序列会误删定时输入:

  1. 定时写入 A 在 write-edge admission 返回 retain,A 回到 pendingMessages,重试已武装;
  2. 随后一条 allowlisted /compact 经真实 flushPendingInjections 写入成功;
  3. 用户按 STOP。

实际结果:A 被 splice,turn_input_rejected=1,重试被取消;预期应是 A 保留、回执 0,因为 /compact 已经在 hold 之后接管 CLI。master 在同一结算后状态下没有 held fallback,A 会保留,所以这是本 PR 新增的误退休,不属于 PR 已声明的“admission await 期间输入作为 hold 基线”边界。

探针证据:临时 Vitest 探针使用真实 workerSubmitHarness、flushPending、flushPendingInjections、term_action,仅替换物理命令写入与计时器。经 bun scripts/fenced-run.ts -- bunx vitest run --project unit <probe> 实跑,/compact 写入调用 1 次后,STOP 的断言同时得到 turn_input_rejected 实际 1 / 期望 0、pendingMessages 实际 [] / 期望 [A]。

建议在非 keepalive 注入的字面写入边沿(sendRawCommandLineWithRecoveryFence 的 before-write 回调)使 held 槽失效,而不是等 awaitPtyQuiescence 返回后才清;否则注入写入进行中到达的 STOP 仍会命中同一窗口。请补 /compact(或 /clear)→ STOP 的回归用例。

既有边界(不阻断,不要求本 PR 处理)

src/worker.ts:15019-15033 的 activeTask 只由 currentBotmuxTurnId 推导且优先于 writingTask / heldTask。若已结束的 scheduled 任务 A 留下 capture identity,另一任务 B 随后 hold,STOP 仍选择 A,B 保留且重试有效;探针实测 B 的回执为 0。旧代码已经是 activeTask ?? writingTask 的优先级,因此这不是本 PR 引入的回归。

本地验证

  • 作者 head ce8fd1c670 与本地 rebase 后 af103d7496 的 stable patch-id 完全一致:01137f087d9a...。
  • bunx vitest run --project unit test/worker-scheduled-deferred-retain.test.ts:35/35。
  • 同文件 bun test:35/35。
  • 邻接 5 套件(test-hygiene、cli-startup-circuit-stop、cross-principal-interruption-gate、codex-app-capacity-recovery、worker-bridge-final-idle-signal):107/107。
  • bun run typecheck、bun run build:通过。
  • 临时探针未提交,工作树已恢复干净。

heldScheduledWrite 的有效性条件只覆盖队列写入、Web 终端提交与 raw
透传三条通道,漏了两条字面命令行写入:
- flushPendingInjections 写非 keepalive 的 tuiSlashAllow 命令(如
  /compact、/clear);
- handleAntigravitySideQuestion 写 /btw 旁路问答。
二者在定时写入 retain 回队列之后落地时,不轮换 currentBotmuxTurnId,
也不推进 web/raw 写入代数,随后的 STOP 会误把仍在队列的 held 写入
退休并回执一次。改为在各自物理写入前的 before-write 回调清除 held
槽;keepalive 属 bot 自动保活、不构成新操作员输入,保持不清。补三个
回归用例(非 keepalive 注入、keepalive 对照、/btw),变异各自咬红。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修:复审 P2(注入斜杠命令未使 held 写入失效)

复审指出的阻断已用真实组件探针复现:定时写入 write-edge retain 回队列后,经真实 flushPendingInjections 写入一条 allowlisted /compact,再触发 STOP,实际 turn_input_rejected=1、pendingMessages=[],与预期(0 回执、条目保留)相反。根因是注入走 sendRawCommandLineWithRecoveryFence 字面命令行通道,不经过 noteCliInputWritten,也不推进 currentBotmuxTurnId 与 web/raw 两个写入代数,held 槽的七项有效性校验全部漏过。

修复(commit 2c2bbbd,追加在作者原提交之上,未改写历史)

  • flushPendingInjections:非 keepalive 注入在物理写入前的 before-write 回调清除 heldScheduledWrite。放在写入边沿而非 awaitPtyQuiescence 之后,使注入进行中到达的 STOP 也无法误退休;keepalive 是 bot 自动保活、不构成新的操作员输入,保持不清。
  • 同构缺口一并修复:handleAntigravitySideQuestion 的 /btw 旁路问答是用户发起的独立 native conversation(注释明确主 turn 保留 capture identity),同样不触碰三个失效信号,在其写入边沿清槽。其余 sendRawCommandLineWithRecoveryFence 调用方已逐一核对:raw passthrough 有 rawInputWriteGeneration 递增覆盖;startup commands / initial rename 仅在启动期、时序上不可能与 held 窗口交叠;session fork 期间 term_action 直接 return,STOP 不可达;session rename 不产生模型输入,不改变定时写入的所有权。

测试

test/worker-scheduled-deferred-retain.test.ts 新增 3 个用例(35 → 38):

  • 非 keepalive /compact 注入后 STOP:held 写入保留、0 回执;
  • keepalive 注入后 STOP:held 写入仍被退休、1 回执(钉住 kind 区分);
  • Antigravity /btw 后 STOP:held 写入保留、0 回执。

变异复验:分别摘掉两个清槽点,对应用例各 1 红、其余保持绿;还原后 38/38 双引擎(vitest + bun test)通过。邻接 5 个注入路径测试文件 422/422,typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(2c2bbbd2f8):成功路径已修复,但仍有 1 个 P2 阻断

/compact 成功写入、/btw 成功写入以及两者物理写入进行中到达的 STOP 都已验证符合预期;keepalive 的 kind 区分也保持不变。但 before-write 无条件清槽引入了另一条反向边界。

P2 / 阻断:framed 注入明确 untouched 后,STOP 后的定时重试仍会执行

src/worker.ts:26605 在物理写入前清掉 heldScheduledWrite。但 framed runner 在 src/worker.ts:6354-6371 可以返回 submissionDisposition='untouched',明确证明没有 frame 被缓冲,随后抛出 submissionStarted=false 的 SubmissionWriteError。flushPendingInjections 的 catch(src/worker.ts:26624-26630)只记录失败,没有恢复 held 的 STOP 所有权。

复现序列:

  1. 定时写入 A retain 回队列并武装重试;
  2. 非 keepalive /compact 到达 before-write,held 被清除;
  3. 真实 sendRawCommandLine 的 framed 分支返回 untouched,证明注入未写入;
  4. 执行 STOP,再触发原重试。

临时探针使用真实 flushPendingInjections、sendRawCommandLineWithRecoveryFence、sendRawCommandLine、term_action,仅控制 adapter 返回值和计时器。实测:

  • STOP 的 turn_input_rejected:实际 0 / 期望 1;
  • STOP 后 pendingMessages:实际 [A] / 期望 [];
  • 随后重试再次调用 writeInput:总次数实际 2 / 期望 1(仅 untouched 注入那次)。

因此成功注入的误退休已修好,但“证明未写入”时却重新打开了原 PR 要关闭的 STOP 漏窗。建议保存失败前的 held 记录,并区分结果结算:成功或 ambiguous 时保持失效;明确 submissionStarted=false / untouched 时恢复 STOP 所有权。若 STOP 在失败写入进行中已经到达,也需要记录该停止意图并在 untouched 结算时退休 A,否则仅事后恢复仍会漏掉这一时序。请补这两种失败窗口的回归用例。

其余验证

  • 修复 commit 2c2bbbd2f8 与本地 rebase c273604afe 的 stable patch-id 一致:6d6d59d85cce...。
  • 目标文件 Vitest 38/38、Bun 38/38。
  • 成功写入中途 STOP 的 /compact、/btw 临时探针:2/2。
  • 注入/Antigravity/raw/fork/deployment 邻接 9 文件:187/187;核心 worker 邻接 5 文件:107/107。
  • bun run typecheck、bun run build:通过。
  • 补充 Bun 邻接测试中的 5 个超时在 origin/master 以相同用例复现,属于基线既有结果,未计为本 PR 回归。
  • 新 head 的 build、network-boundary CI 已通过;其余 CI 在复审时仍 pending,未计为绿。
  • 临时探针和基线 worktree 均已清理,当前工作树干净。

flushPending 在逐项 postTerminalPromptFence(TraeX、ZCode)等待
postTerminalInputIsBlocked 返回后,直接以 pendingMessages[0]! 调用
activeTurnBlocks。等待期间若生命周期路径清空了队列,就会抛出 TypeError;
由重试计时器 void flushPending() 发起时成为 unhandledRejection,worker 退出。
本 PR 让 STOP 能在重试窗口内退休被 hold 的队首,为该窗口增加了一个触发源;
coalesce、cancel_queued_turn 等既有路径同样可能触发。

修复:该等待返回后若队列已空,直接结束本轮循环。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yintamaa

Copy link
Copy Markdown
Contributor Author

感谢代修,2c2bbbd2f 已核对:非 keepalive 注入与 /btw 都在写前边沿清槽,覆盖了我这边同时在做的修复(我本地的重复改动已丢弃,未推送)。

在你的提交之上追加了两项(merge,未改写历史):

  • 6324d2b55:合入最新 master。
  • cf47dd627 fix(worker): 逐项提示符围栏等待后队列清空时结束本轮 flush:自审发现,flushPending 的逐项 postTerminalPromptFence(TraeX、ZCode)在 await postTerminalInputIsBlocked(...) 之后直接读 pendingMessages[0]!。若等待期间队列被清空,会抛出 TypeError;由重试计时器触发时成为未捕获异常。本 PR 让 STOP 能在重试窗口内退休队首,新增了一个触发源(coalesce、cancel_queued_turn 等既有路径同样可能清空队列)。修复为等待返回后队列为空即结束本轮。

新增用例 STOP emptying the queue while a retry awaits the post-terminal prompt fence ends that flush cleanly:不抛异常,A 回执 1 次,未写入,isFlushing 复位。去掉守卫后该用例以 TypeError 失败。

验证:test/worker-scheduled-deferred-retain.test.ts vitest 39/39、bun test 39/39;bun run typecheck、bun run build 通过。

你提到的既有边界(已结束定时任务的 capture identity 优先于 held 写入)未改动。

framed runner(minimax/atomcode/antigravity-acp)的注入若在缓冲任何
字节前被拒,sendRawCommandLine 返回 submissionDisposition=untouched
(submissionStarted=false),证明没有输入到达 CLI。上一轮在写入边沿
无条件清除 heldScheduledWrite,导致这类失败后 STOP 看不到该定时写入、
重试到点仍会再写一次。改为把写入边沿的清除降级为挂起
(suspendedHeldWrite):注入成功或 ambiguous(可能已缓冲字节)时保持
失效;明确未写入时恢复 held,若 STOP 在写入进行中已到达则 latch
stopRequested,结算时复用 discardScheduledBacklogForStop 的完整有效
性校验立即退休。/btw 入口在 runnerFramedInput 时直接 return,触达不
了 framed 分支,无需同改。补三个回归用例(untouched 恢复、dirty_unknown
保持失效、写入进行中 STOP 的竞态),三轮变异各自精确咬红。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第二轮:framed 注入明确未写入时恢复 held 的 STOP 所有权

复审指出的第二个阻断已用真实组件独立复现:framed runner(minimax/atomcode/antigravity-acp)的注入经真实 sendRawCommandLine 走 framed 分支返回 submitted:false, submissionDisposition:'untouched' 后,上一轮在 before-write 无条件清槽导致 STOP 看不到该 held 写入(回执 0、条目留存),重试到点仍会再写一次。

修复(commit 856b98e,追加在作者最新 head cf47dd6 之上)

把写入边沿的"直接清槽"降级为"挂起",新增模块级单槽 suspendedHeldWrite(含 stopRequested 标记)与 restoreSuspendedHeldWrite(),按写入结果三向结算:

  • 注入成功(await 正常返回):挂起槽丢弃,held 保持失效——新输入确实接管了 CLI;
  • 明确未写入(SubmissionWriteError.submissionStarted === false,含 framed untouched/flushed_invalid 与各类写前拒绝):恢复 held 的 STOP 所有权;若 STOP 在写入进行中已到达(discardScheduledBacklogForStop 对挂起槽 latch 了 stopRequested),恢复时复用 discardScheduledBacklogForStop 的完整七项有效性校验立即退休,回执一次并取消重试;
  • ambiguous(dirty_unknown,frame 可能已缓冲)或普通失败:CLI 状态不确定,挂起槽丢弃、held 保持失效,遵守不向不确定状态重放的既有原则。
  • wire 脏回退分支(注入条目 unshift 重试)同步恢复挂起槽,因为该注入确定未落地。

/btw 不需要同改:其入口在 cliAdapter.runnerFramedInput === true 时直接以 unavailable return,触达不到 framed 写入分支。

测试(38 → 42,含作者 cf47dd6 的 1 个围栏用例)

新增 3 个用例:framed untouched 后 STOP 仍退休(0 写入、1 回执、重试槽空);framed dirty_unknown 后 STOP 保留条目;STOP 在 framed 写入 await 期间到达、untouched 结算时退休且只回执一次。三轮变异(摘恢复、摘 stopRequested latch、挂起退回直接清槽)分别精确咬红 2/1/2 个对应用例,dirty 对照始终保持绿。

验证

vitest 42/42、bun test 42/42;harness 与注入/中断邻接 10 文件共 248 用例全绿;typecheck、build 通过。本 commit 在作者 merge 最新 master 的 head 上 cherry-pick,与 rebase 树上的原始提交 stable patch-id 一致(26efb8e7…)。新 head CI 已触发。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(856b98e6d3):3 个阻断问题

本轮所有验证均在 detached 的远端原样 856b98e6d3 上执行(包含 cf47dd627f)。挂起槽的 untouched / dirty_unknown 三向结算本身,以及额外攻击的旧 CLI 换代、挂起中 coalesce 两个探针均通过;但下面三条独立路径仍可复现。

1. P1 / 阻断:settleInputBox await 期间 STOP 清队,重试仍抛 TypeError

cf47dd627f 只在 postTerminalInputIsBlocked 后补了空队列 guard(src/worker.ts:33288-33296)。但 src/worker.ts:33363 的 await cliAdapter.settleInputBox(...) 返回后没有同类复核,继续到 src/worker.ts:33412-33413 读取 scheduledHead.turnId;此时 scheduledHead === undefined。

探针使用真实 flushPending、重试计时器和 STOP:A 首次 retain 后,重试停在 settleInputBox,STOP 退休 A,再以 refused=false 放行。实际结果为:

TypeError: Cannot read properties of undefined (reading 'turnId')

这与已修复的 post-terminal 窗口具有相同的 worker void flushPending() unhandled-rejection 风险。请至少在该 await 后重新校验队列/队首,并逐项审计后续带 await 的 input gates 在解引用 pendingMessages[0] 前是否都有等价保护。

2. P2 / 阻断:stopRequested 未绑定原 STOP 目标, untouched 恢复时可能改杀另一任务

src/worker.ts:15041 在计算 activeTask / writingTask 之前就无条件 latch;restoreSuspendedHeldWrite 随后又调用全局 discardScheduledBacklogForStop 重新选目标。

探针序列:当前 scheduled capture identity 属于任务 B,任务 A 已 held 并被注入挂起;STOP 到达时按既有优先级选择 B,A 回执为 0;随后清除 B 的 identity,再让注入以 untouched 结算。恢复逻辑此时重新选择 A,实测 A 的 turn_input_rejected=1、队列被清空,而不是保留 A。也就是 STOP 的目标在恢复期间发生了漂移。

请只在 suspended held write 本身就是本次 STOP 的有效目标时 latch,并在恢复时结算那个精确 item/task;不要在 STOP 已选择其他 scheduled turn 后,再经全局目标选择追加退休 A。

3. P2 / 阻断:直接 tui_text_input 成功提交仍不会使 held 失效

handleTuiTextInput(src/worker.ts:26690,IPC 入口 src/worker.ts:52830)是另一条操作员原生输入通道。其成功路径不调用 noteCliInputWritten,也不推进 Web/raw 代数或改变 capture identity,因此既有 held 七项校验仍全部通过。

探针以真实 handleTuiTextInput 执行成功提交(仅替换物理 submit helper),随后 STOP:实测 A 的回执为 1、队列被删除;按“其他操作员输入已接管 CLI”的语义应为回执 0、保留 A。请把该通道纳入同一挂起/结算模型,并保留明确 pre-write refusal 时的恢复语义,避免简单新增一个无条件清槽点后重现 untouched 漏窗。

验证记录

  • 远端原样 head:目标文件 Vitest 42/42、Bun 42/42。
  • 注入/Antigravity/raw/fork/deployment/startup 邻接 10 文件:239/239。
  • 挂起期间 CLI 换代、coalesce 两个额外交叠探针:2/2。
  • 上述三个问题的临时探针均实际跑出对应 TypeError / 错误回执。
  • bun run typecheck、bun run build:通过。
  • CI 在复审时仍有分片 pending,未计为绿。
  • 临时探针与 detached worktree均已清理。

第三轮复审的三个阻断,均用真实组件探针复现后修复:

P1 崩溃:flushPending 重试在 settleInputBox 与 traex 自动模型准入两个
await 期间被 STOP 清空队列后,仍以非空断言读取 pendingMessages[0],
抛出 TypeError(与 cf47dd6 已修的 post-terminal 围栏同构)。两处
await 后补空队列 break,并逐项审计该 drain 循环其余 await 均已有队首
保护。

P2 目标漂移:suspendedHeldWrite 的 stopRequested 此前在 STOP 入口无条件
latch,untouched 恢复时又重跑全局目标选择,当 STOP 实际针对另一调度
任务 B 时会漂移退休被挂起的 A。改为仅在无活动 turn/在途写入且挂起项
本身通过七项有效性校验时才 latch;恢复时用抽出的
heldScheduledWriteIsCurrent 复核并只退休精确 item(retireScheduledTaskItem),
不再全局重选。

P3 通道遗漏:handleTuiTextInput 的操作员原生提交绕过 noteCliInputWritten
与两个写入代数,成功提交后 held 七项校验仍全过、STOP 误退休。纳入与
注入相同的挂起/结算模型(抽出 suspendHeldForLiteralWrite 共用):写入
边沿挂起,成功或 ambiguous 保持失效,明确 pre-write refusal
(submissionStarted=false / 非 dirty_unknown)恢复 STOP 所有权。

测试 42→48,新增 settleInputBox/auto-model 空队列、STOP 目标漂移、
精确结算防轮换、TUI 成功与 untouched 共 6 个用例;每个修复点变异均精确
咬红。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第三轮:P1 崩溃 + P2 目标漂移 + P3 tui_text_input 通道

三个阻断均用真实组件探针在远端原样 head 上独立复现,逐项修复(commit b43ba15,ff 追加在 856b98e 之上)。

P1:重试 await 期间 STOP 清队导致空队首 TypeError

cf47dd627f 只补了 post-terminal fence 一处。审计 drain 循环全部 5 个 await 点后,定位另外两处解引用 pendingMessages[0]! 前无空队列保护:settleInputBox(33363)与 admitTraexAutoModelPendingInput(33321)。探针在 settleInputBox await 内 STOP,复现 TypeError: Cannot read properties of undefined (reading 'turnId')。两处各补 if (pendingMessages.length === 0) break;;其余三个 await(post-terminal、question、admission)确认已有队首移动保护。

P2:stopRequested 目标漂移

根因有二,分别修复:

  1. discardScheduledBacklogForStop 在计算 STOP 目标前无条件 latch 挂起槽。改为仅当无活动调度 turn / 在途写入、且挂起项本身通过七项有效性校验时才 latch——STOP 属于另一任务 B 时不再标记 A。
  2. restoreSuspendedHeldWrite 原先重跑全局 discardScheduledBacklogForStop 重新选目标。改为恢复后用新抽出的 heldScheduledWriteIsCurrent 在结算时刻复核,并经 retireScheduledTaskItem 只退休挂起的精确 item,绝不全局重选。两个新辅助(谓词 + 精确退休)同时被正常 STOP 路径复用,消除两份校验漂移。

P3:handleTuiTextInput 通道遗漏

该操作员原生提交(IPC tui_text_input)绕过 noteCliInputWritten 与 web/raw 代数,成功后 held 七项校验全过。抽出共享辅助 suspendHeldForLiteralWrite(注入路径一并改用),在 writeInput 物理写入边沿挂起 held,并按结果三向结算:成功 → 保持失效;adapter 明确 submitted:false 且非 dirty_unknown、或 catch 到 submissionStarted=false → 恢复 STOP 所有权;ambiguous/不确定 → 保持失效。早期导航失败在挂起之前返回,不影响该槽。

测试(42 → 48)与变异

新增 6 用例:settleInputBox / auto-model 空队列崩溃、STOP 目标漂移(不同 task 的 B)、latch 后当前 turn 轮换为 C 的精确结算、TUI 成功提交、TUI untouched 恢复。变异矩阵:两处空队列 guard、无条件 latch、全局重选恢复、TUI 挂起、TUI 失败总清槽——每个修复点摘除后均有对应用例精确咬红,还原后 48/48 双引擎(vitest + bun test)通过;harness/注入/STOP/tui/auto-model 邻接 13 文件 564 用例全绿;typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(b43ba15266):前三项修复有效,仍有 2 个 P2 阻断

两处空队列 guard、STOP 精确目标绑定,以及 TUI 成功 / untouched 路径均已有有效修复;目标文件双引擎 48/48。继续攻击 TUI 的真实 adapter 结果形状和共享挂起槽的并发边界后,发现下面两类独立问题。

1. P2 / 阻断:无 disposition 的 Antigravity ambiguous 被误判为 untouched

src/worker.ts:26809-26814 目前以 submitted === false && submissionDisposition !== 'dirty_unknown' 作为“证明未写入”的恢复条件。但 Antigravity 的真实 unconfirmed 返回(src/adapters/cli/antigravity.ts:1059)是:

{ submitted: false, recheck, proveConsumed, settleConsumed }

它没有 submissionDisposition,且原有注释明确说明此时仍可能已产生 USER_INPUT,需要保留 transcript proof。当前条件会把这种 ambiguous 结果当成 untouched,恢复 held 的 STOP 所有权。

探针使用真实 handleTuiTextInput 与上述真实结果形状,提交返回 false 后执行 STOP:实测定时项 A 的 turn_input_rejected=1、队列被删除;按 ambiguous 不重放的语义应为回执 0、保留 A。请只在显式证明 untouched(或等价的安全 disposition)时恢复;缺失 disposition / 带 proveConsumed 的 unconfirmed 结果必须走 ambiguous 分支。请补这个真实结果形状的回归用例。

2. P2 / 阻断:注入与 TUI 并发时共享单槽,成功写入与 untouched 恢复会互相覆盖

flushPendingInjections 与 handleTuiTextInput 现在共用单个 suspendedHeldWrite,但普通 PTY 下两条入口没有覆盖整个 suspend→settle 窗口的互斥。TUI 在注入已挂起后调用 suspendHeldForLiteralWrite 会变成 no-op,随后双方却都能 restore / clear 同一个槽。

实跑时序:

  1. A held,非 keepalive 注入将 A 挂起并停在物理写入中;
  2. TUI text input 以 untouched 先结算,restoreSuspendedHeldWrite 恢复 A;
  3. 注入随后成功,但成功路径只清 suspendedHeldWrite,已恢复的 heldScheduledWrite 仍然残留;
  4. STOP 实测 A 回执 1、队列被删除;成功注入已经接管 CLI,正确结果应是回执 0、保留 A。

请让这两类 literal writer 在整个挂起/结算生命周期内互斥,或为每次挂起引入独立归属与结果仲裁,不能让一个 writer 的 untouched 恢复覆盖另一个 writer 已成功的事实。建议至少补“注入成功 × TUI untouched”与反向完成顺序的交叠用例。

验证记录

  • 远端原样 b43ba15266 detached 树:目标文件 Vitest 48/48、Bun 48/48。
  • 注入/raw/fork/deployment/TUI 等邻接 14 文件:315/315。
  • bun run typecheck、bun run build:通过。
  • 上述两个临时探针均实际得到错误回执 1;工作树与临时探针已清理。
  • CI 未纳入本次通过结论。

第四轮复审的两个 P2,均用真实组件探针复现后修复:

P2-1 Antigravity ambiguous 误判为 untouched:handleTuiTextInput 的
未确认结果分支此前用「非 dirty_unknown 即恢复」的黑名单判据,但真实
Antigravity unconfirmed 返回 {submitted:false, recheck, proveConsumed}
不带 submissionDisposition,却可能已产生 USER_INPUT,被错误恢复 held。
改为显式零字节白名单:仅 untouched/flushed_invalid 恢复 STOP 所有权,
缺失 disposition 或 dirty_unknown 一律保持失效。

P2-2 注入与 TUI 并发共用单槽相互覆盖:两个 literal writer 此前共享无主
suspendedHeldWrite,先结算者的恢复会被后结算者的成功忽略,导致注入成功
后 STOP 仍误退休。引入每次挂起的所有权 token(suspend 返回 id,
restore/clear 校验 id 否则 no-op):未挂起槽的 writer 拿到 undefined,
其任何结算都不触碰他人的槽;槽只由挂起它的 writer 仲裁。STOP 的 latch
仍标记当前槽,恢复时由持 token 者经七项有效性校验后退休。

测试 48→51(agy unconfirmed 保持失效、flushed_invalid 恢复、注入/TUI
并发槽归属),两点变异均精确咬红;双引擎 51/51,邻接 14 文件 611 绿,
typecheck/build 通过。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第四轮:ambiguous 误判 + 并发槽归属(commit 4d355a2)

两个 P2 均用真实组件探针在 b43ba15 上独立复现后修复。

P2-1:Antigravity unconfirmed 被误判为零字节 untouched

handleTuiTextInput 的未确认结果分支此前用「submissionDisposition !== 'dirty_unknown' 即恢复」的黑名单。但 antigravity.ts:1059 的真实 unconfirmed 返回 { submitted:false, recheck, proveConsumed, settleConsumed } 不带 disposition,且可能已产生 USER_INPUT——黑名单对 undefined 放行,错误恢复 held 致 STOP 误退休。

改为显式零字节白名单:仅 submissionDisposition === 'untouched' | 'flushed_invalid'(types.ts 注释明确这两个是同代可安全 cancel/retry 的零字节 disposition)才恢复;缺失 disposition、dirty_unknown 一律保持失效。注入路径不受影响——它经 sendRawCommandLine 的 framed 分支,靠 SubmissionWriteError.submissionStarted 区分,agy unconfirmed 是正常 resolve 不进该 catch。

P2-2:注入与 TUI 并发共用无主单槽相互覆盖

普通 PTY 下 handleTuiTextInput 走 adapter 直写,既不经过 commandLineWriteTail 也不检查 injectionFlushing,两个 literal writer 的 suspend→settle 周期可交错:注入挂起 A 后,TUI 先 untouched 结算会把 A 恢复,注入随后成功却只清自己的引用,held 残留被 STOP 误退休。

引入每次挂起的所有权 token:suspendHeldForLiteralWrite() 返回单调 id(无 held 或槽已被他人挂起时返回 undefined);新增 clearSuspendedHeldWrite(token),restoreSuspendedHeldWrite(token) 仅在 id 匹配时作用于该槽,foreign/undefined token 一律 no-op。注入与 TUI 各持各自 token 结算,槽只由挂起它的 writer 仲裁。STOP 的 latch 仍标记当前槽,恢复时由持 token 者经既有七项有效性校验后退休,目标漂移防护不变。

测试(48 → 51)与变异

新增:agy unconfirmed(无 disposition+proveConsumed)保持失效、flushed_invalid 恢复、注入挂起期间 TUI 先结算的并发槽归属。变异:白名单退回黑名单咬红 agy 用例;restore/clear 去掉 token 校验咬红并发用例,还原后 51/51 双引擎(vitest + bun test,365 断言);邻接 14 文件 611 用例全绿;typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(4d355a245c):白名单修复有效,仍有 1 个 P2 并发阻断

显式 untouched/flushed_invalid 白名单已修正 Antigravity 无 disposition 的 ambiguous 误判,上一轮“TUI untouched 先结算、注入后成功”的顺序也已修复。目标文件双引擎 51/51。反向完成顺序仍可复现:

P2 / 阻断:第二个 writer 成功但无 token,首个 writer 随后 untouched 又会恢复 A

clearSuspendedHeldWrite(undefined) 对未取得 token 的 writer 一律 no-op。这不仅适用于 untouched,也适用于真实提交成功的 TUI 路径;因此成功事实不会使当前 suspended slot 失效。

实跑序列:

  1. A held;注入取得 token 并挂起 A,物理写入保持 in-flight;
  2. TUI 因槽已占用取得 undefined,但真实 handleTuiTextInput 路径以 { submitted: true } 成功提交;
  3. TUI 成功路径调用 clearSuspendedHeldWrite(undefined),没有使 A 的挂起槽失效;
  4. 注入随后以 submissionStarted=false / untouched 结算,凭旧 token 把 A 恢复到 heldScheduledWrite;
  5. STOP 实测 A 的 turn_input_rejected=1、队列被删除;既然 TUI 已成功接管 CLI,正确结果应是回执 0、保留 A。

因此需要区分两种结算权限:

  • 恢复确实需要 token,防止 foreign untouched 恢复他人槽;
  • 任何已经到达物理写入边沿且成功或 ambiguous 的 writer,都必须使现有 held/suspended 所有权失效,即使它因为槽占用而没有 token。不能让这种成功路径变成 no-op。

可以按完整生命周期串行化 literal writers,或在结果仲裁中显式记录“后来者已经可能写入”;仅给 restore/clear 同时加 token 校验不足。请补“注入挂起 → TUI 成功 → 注入 untouched”及反向顺序的回归用例。

验证记录

  • 远端原样 4d355a245c detached 树:目标文件 Vitest 51/51、Bun 51/51。
  • 注入/raw/fork/deployment/TUI 等邻接 14 文件:315/315。
  • bun run typecheck、bun run build:通过。
  • 临时反向顺序探针实际得到错误回执 1;探针已清理。
  • CI 在复审时仍有分片 pending,未计为绿。

上一轮的槽所有权 token 把 restore 与 clear 一并收归 token 持有者,
导致一个真实成功的操作员输入若未取得 token(槽已被另一在途写入挂起),
其 clear(undefined) 被 no-op,挂起者随后凭旧 token 以 untouched 恢复
held,STOP 误退休已被新输入接管 CLI 的定时写入。

按结果区分两种结算,不再共用一个带 token 的 clear:
- restoreSuspendedHeldWrite(token):仅明确零字节(untouched/
  flushed_invalid、submissionStarted=false)恢复 STOP 所有权,严格校验
  token,foreign/undefined no-op,防止他人 untouched 恢复挂起槽;
- invalidateHeldForLiteralWrite():成功或 ambiguous/不确定的写入无条件
  清除 held 与 suspended 两个槽,不要 token——成功的操作员输入必须让
  held 写入丧失 STOP 所有权,与 noteCliInputWritten 语义对齐。
  注入路径仅在本次确实挂起过(heldToken 非 undefined,即非 keepalive)
  时调用,保活输入仍不触碰 held;TUI 路径始终调用(无 keepalive 概念)。

补两个并发完成顺序用例(注入挂起→无 token TUI 成功→注入 untouched;
注入先 untouched 恢复→无 token TUI 成功),变异:invalidate 漏清 held
咬红反向用例、整体 no-op 咬红两个、去掉 keepalive 条件咬红保活用例。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第五轮:成功的无 token 字面写入必须使 held 失效(commit 33f594e)

复审指出的并发阻断已用两个完成顺序的探针在 4d355a2 上复现:注入挂起 A 后,未取得 token 的 TUI 成功提交,其 clear(undefined) 被 no-op,注入随后凭旧 token 以 untouched 恢复 A,STOP 误退休(实测回执 1,应为 0)。

根因是上一轮把 restore 和 clear 都收归 token 持有者,混淆了两种相反的结算语义。现拆分为职责明确的两个函数:

  • restoreSuspendedHeldWrite(token)——仅用于明确零字节(untouched/flushed_invalid、submissionStarted=false)恢复 STOP 所有权,严格校验 token,foreign/undefined token 一律 no-op,防止他人的 untouched 恢复自己没挂起的槽;
  • invalidateHeldForLiteralWrite()——用于成功或 ambiguous/不确定的写入,无条件清除 heldScheduledWrite 与 suspendedHeldWrite 两个槽,不接收 token。成功的操作员输入必须让 held 写入丧失 STOP 所有权,与 noteCliInputWritten 的既有语义对齐,无论该 writer 当初是否挂起过槽。

调用方区别处理:

  • 注入路径仅在本次确实挂起过(heldToken !== undefined,即非 keepalive)时才 invalidate——keepalive 是 bot 保活、从不挂槽,仍不触碰 held;零字节仍走带 token 的 restore。
  • TUI 路径无 keepalive 概念,成功/ambiguous 三个出口一律无条件 invalidate;零字节走带 token 的 restore。

测试(51 → 53)与变异

新增两个并发完成顺序用例:①注入挂起→无 token TUI 成功→注入 untouched;②注入先 untouched 恢复 A→无 token TUI 成功。变异矩阵:invalidate 漏清 heldScheduledWrite 只咬红反向顺序用例、invalidate 整体 no-op 两个都红、去掉注入的 keepalive 条件咬红保活用例——三个变异点各自有独立护栏,还原后 53/53 双引擎(385 断言);邻接 10 文件 539 用例全绿;typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(33f594e07e):仍有 1 个对称的 P2 并发阻断

restore/invalidate 的职责拆分正确,新增用例也覆盖了“注入先持槽”的两个完成顺序。但注入调用方在 src/worker.ts:26718 与 src/worker.ts:26731 用 heldToken !== undefined 决定是否 invalidate,把“是否持有他人槽的 token”误当成了“本次非保活输入是否成功/可能写入”。

P2 / 阻断:TUI 先持槽时,无 token 的非保活注入成功仍不会使 A 失效

实跑序列:

  1. A held;TUI 先到达物理写入边沿,取得 token 并挂起 A,随后保持 in-flight;
  2. 非 keepalive /compact 注入到达自己的 before-write,因没有 active held 而得到 heldToken=undefined,但其物理命令真实成功;
  3. 注入成功路径因 heldToken === undefined 不调用 invalidateHeldForLiteralWrite();
  4. TUI 随后以 untouched 结算,凭自己的 token 恢复 A;
  5. STOP 实测 A 回执 1、队列被删除;既然非保活注入已经成功,正确结果应为回执 0、保留 A。

建议继续拆开三个独立事实:

  • 通道类型:用 item.kind !== 'keepalive' 判定,不能用 token 判定;
  • 是否到达写入边沿:对 catch 中的普通/ambiguous 失败,用独立的 literalWriteStarted 标记记录 before-write 已进入,防止早期 wire-dirty / pre-write refusal 误伤他人槽;
  • 谁可以恢复:仅 heldToken 负责 restore 的归属校验。

成功路径可按非 keepalive 直接 invalidate;失败路径则应是“非 keepalive 且已到达写入边沿、结果不是明确零字节”才 invalidate。请补“TUI 先挂起 → 无 token 非保活注入成功 → TUI untouched”以及 keepalive 对照用例。

验证记录

  • 远端原样 33f594e07e detached 树:目标文件 Vitest 53/53、Bun 53/53。
  • 邻接 14 文件:315/315。
  • bun run typecheck、bun run build:通过。
  • 上述对称临时探针实际得到错误回执 1;探针已清理。
  • CI 在复审时仍有分片 pending,未计为绿。

上一轮注入路径用 heldToken !== undefined 决定是否 invalidate,在反向
并发下失效:TUI 先挂起 A 持 token,随后的非保活注入在写入边沿发现槽
被占、拿到 undefined token,但物理命令确实成功,却因 token 为空跳过
invalidate;TUI 之后 untouched 凭自己的 token 恢复 A,STOP 误退休已被
注入接管 CLI 的定时写入。

把三个此前耦合的事实拆开(restore 仍只用 token):
- isOperatorInjection(item.kind !== 'keepalive'):通道类型,保活输入
  任何路径都不触碰 held;
- heldToken:仅零字节 restore 时校验归属,foreign/undefined no-op;
- literalWriteStarted:before-write 回调越过 suspend 点后置 true,使 catch
  中的 ambiguous/普通失败只在确实进入写入边沿时才 invalidate,wire-dirty
  等 suspend 前的早期拒绝不误伤他人槽。

成功路径:非保活即无条件 invalidate(含他人仍持有的 suspended 槽);
零字节:带 token restore;ambiguous:非保活且已进入写入边沿才 invalidate。
另给 harness 补 logError 惰性 no-op 默认,使 extracted 失败路径可解析。

补两个用例(TUI 先持槽时无 token 注入成功仍失效;注入在写入边沿前失败
不失效),变异:成功路径回退 token 判据、去掉 literalWriteStarted 条件,
各精确咬红;双引擎 55/55,邻接 14 文件 649 绿,typecheck/build 通过。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第六轮:注入按通道类型而非 token 决定 held 失效(commit 056b722)

复审指出的对称并发阻断已用反向顺序探针在 33f594e 复现:TUI 先挂起 A 持 token,非保活 /compact 随后在写入边沿发现槽被占、拿到 undefined token,但物理命令成功;上一轮注入路径用 heldToken !== undefined 决定 invalidate,token 为空就跳过,TUI 之后 untouched 凭自己的 token 恢复 A,STOP 误退休(实测应保留 A)。

按建议把三个此前耦合的事实拆开,restore 仍只认 token:

  • isOperatorInjection(通道类型):item.kind !== 'keepalive'。保活输入在成功、失败所有路径都不触碰 held。
  • heldToken(仅恢复归属):只在零字节 restoreSuspendedHeldWrite(token) 校验,foreign/undefined token 一律 no-op,防止他人 untouched 恢复自己没挂起的槽。
  • literalWriteStarted(写入边沿标记):before-write 回调越过 suspend 点后置 true。catch 里的 ambiguous/普通失败只有在非保活 且 已进入写入边沿时才 invalidate,使 wire-dirty 等 suspend 之前的早期拒绝(literalWriteStarted=false)不会误伤他人槽。

结算矩阵:

  • 成功:非保活即无条件 invalidate(包括另一 writer 仍持有的 suspended 槽);
  • 明确零字节(untouched/flushed_invalid、submissionStarted=false):带 token restore;
  • ambiguous/普通失败:非保活且到过写入边沿才 invalidate;
  • keepalive 或 suspend 前早期拒绝:不碰槽。

另给 test harness 补 logError 惰性 no-op 默认(extracted 失败路径此前解析为 undefined)。

测试(53 → 55)与变异

新增:TUI 先持槽时无 token 注入成功仍使槽失效(对称反向顺序)、注入在写入边沿前失败不失效。变异:成功路径回退 heldToken 判据咬红对称用例、去掉 literalWriteStarted 条件咬红早期失败用例,还原后 55/55 双引擎(404 断言);邻接 14 文件 649 用例全绿;typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(056b722b36):对称并发已修复,仍有 1 个 TUI 早期失败 P2

注入侧的通道类型、写入边沿、restore token 三事实拆分有效,目标文件双引擎 55/55。TUI 侧还缺同一个“是否到达写入边沿”判定。

P2 / 阻断:导航在 writeInput 前失败,仍无条件使 held 失效

真实 submitTuiTextInput 会在导航键被拒绝、或导航后 isCurrent() 失败时直接返回 false,根本不会调用 writeInput。但 handleTuiTextInput 在 src/worker.ts:26825 进入 !transaction.result 后,只要结果不是显式 untouched/flushed_invalid,就在 src/worker.ts:26860 无条件 invalidateHeldForLiteralWrite()。早期异常进入 catch 时,src/worker.ts:26905 也有同样的无条件失效分支。

探针使用真实 handleTuiTextInput + 真实 submitTuiTextInput,让首个导航键 sendSpecialKeys('Down') 返回 false:

  • cliAdapter.writeInput 调用次数为 0,操作员正文不可能到达 CLI;
  • 当前实现仍清掉 held;
  • 随后的 STOP 实际保留 A,队列仍为 [A];正确行为应是退休 A、回执一次。

建议 TUI 也维护自己的 literalWriteStarted,在 src/worker.ts:26803 的 writeInput 回调进入时设置,并应用到 return-false 与 catch 两条路径:

  • 未到达写入边沿:不碰 held/suspended;
  • 到达边沿后成功或 ambiguous:invalidate;
  • 到达边沿后明确零字节:仅按自己的 token restore。

不要仅用 submittedInputResult !== undefined 代替 started,因为 adapter 的 void 成功返回也是合法结果形状。请补导航键 false 与导航异常两种回归用例。

验证记录

  • 远端原样 056b722b36 detached 树:目标文件 Vitest 55/55、Bun 55/55。
  • 邻接 14 文件:315/315。
  • bun run typecheck、bun run build:通过。
  • 临时导航拒绝探针实际复现上述队列结果;探针已清理。
  • CI 在复审时仍有分片 pending,未计为绿。

submitTuiTextInput 在导航键被拒绝或导航后 isCurrent() 失败时直接返回
false,不会调用 writeInput;但 handleTuiTextInput 的两个失败结算分支此前
无条件 invalidate,使这种"零字节且未到写入边沿"的早期失败也清掉 held,
STOP 因而漏过仍在队列的定时写入。

给 TUI 路径补与注入路径一致的 literalWriteStarted 标记,仅在 adapter 的
writeInput 回调(suspend 同一点)置 true:
- 未到写入边沿(导航/事务早期失败,writeInput 零调用):不碰 held 与
  suspended,held 的 STOP 所有权原样保留;
- 到达后明确零字节:仍按自己的 token restore;
- 到达后成功或 ambiguous/普通失败:invalidate。
标记独立于 submittedInputResult——adapter 合法的 void 成功返回不代表
未到写入边沿。成功返回点保持无条件 invalidate,因为能到达该处必然经过
writeInput。

补两个用例(导航键被拒、事务在 submit 前抛错,均 writeInput 零调用且
held 保留),两处 started 条件摘除后各自精确咬红;双引擎 57/57,邻接
14 文件 649 绿,typecheck/build 通过。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

代修第七轮:TUI 导航在 writeInput 前失败不触碰 held(commit 4690741)

复审指出的早期失败阻断已用真实 submitTuiTextInput 探针在 056b722 复现:首个导航键被拒时 submitTuiTextInput 直接返回 false、writeInput 零调用,但 handleTuiTextInput 的失败结算仍无条件 invalidate,清掉 held 致 STOP 漏过队列里的定时写入。

给 TUI 路径补与注入路径一致的 literalWriteStarted 标记,仅在 adapter 的 writeInput 回调(与 suspend 同一点)置 true,且独立于 submittedInputResult(adapter 合法的 void 成功返回不代表未到写入边沿):

  • 未到写入边沿(导航键被拒、isCurrent 失败、事务在 submit 前抛错,writeInput 零调用):不碰 held/suspended,STOP 所有权原样保留;
  • 到达后明确零字节(untouched/flushed_invalid、submissionStarted=false):仍按自己的 token restore;
  • 到达后成功或 ambiguous/普通失败:invalidate。

成功返回点保持无条件 invalidate——能到达该处必然经过 writeInput。restore 仍只认 token,未到 writeInput 时 heldToken 为 undefined 天然 no-op。

测试(55 → 57)与变异

新增导航键被拒、事务 submit 前抛错两个用例(均断言 writeInput 零调用且 held 保留、STOP 正常退休回执一次)。变异:!result 分支与 catch 分支分别摘除 started 条件,各精确咬红对应用例,还原后 57/57 双引擎(418 断言);邻接 14 文件 649 全绿;typecheck、build 通过。

这是自动评审的代修提交,最终以维护者审阅为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论(4690741484):零新增阻断,代码与本地验证通过

上一轮 TUI 早期失败问题已修复:

  • literalWriteStarted 只在真实 writeInput 回调置位,与 submittedInputResult 是否为空无关;
  • 导航拒绝、事务在 submit 前抛错这两条路径都不触碰 held/suspended,STOP 仍退休 A 且只回执一次;
  • 到达写入边沿后的 untouched/flushed_invalid 继续按 token restore;成功或 ambiguous 无条件 invalidate;成功返回点必然已经过 writeInput;
  • 注入先持槽、TUI 先持槽及两个完成顺序的既有用例均保留,没有发现新的状态语义偏差。

本地验证(远端原样 4690741484 detached 树)

  • 目标文件 Vitest 57/57、Bun 57/57(418 断言);
  • 注入/raw/fork/deployment/TUI 等邻接 14 文件 315/315;
  • bun run typecheck、bun run build 通过;
  • git diff --check 通过,临时 worktree 已清理。

CI 方面,build、三种 bun-binary 与 network-boundary 已通过;其余 Vitest/Bun 分片在复审时仍 pending,合并前应以这些分片最终全绿为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

合前 G7 复核:按列出的 #109 窄例外条件,可不同步 master,直接 squash

我独立重算并实跑了合并树,技术条件成立:

  • head 未变:远端仍为 4690741484,PR open、mergeable;该 head 的 15 项 CI 均通过。
  • 树三点一致:git merge-tree --write-tree origin/master HEAD 得到 48f3d2481aac303b70966fd7768fc91c6ed8a55d;在独立 worktree 实际 git merge --no-commit --no-ff origin/master 后,git write-tree 得到完全相同的 tree。
  • worker.ts 区段分离:合并后 master 侧增量只有 locale(3405)和 userWarnings(3415起)共 6 行;本 PR 最靠后 guard 在 33500。两处不相邻,且插件生成/告警与 STOP/held 状态机无共用代码路径。
  • 合并树验证:typecheck、build 通过;覆盖本 PR 及 master 本次前进涉及的 Claude/AtomCode/插件/Skill 区域的 17 个测试文件共 692/692;本 PR 目标文件另以 Bun 57/57 通过。构建和测试后再次 write-tree 仍为同一 48f3d2481a…。

两处说明性更正不影响例外判断:master 自 PR merge-base 起共前进 5 个 PR(只有 #3975 触及 worker.ts);按 3405 与 33500 计算行距为 95 行,不是 55 行。

合后若 head/base 均未再变化,应核验 squash 落地 tree 仍为 48f3d2481a…,并保留作者署名。验证用 worktree 已 abort 并清理,未改动 PR。

@deepcoldy
deepcoldy merged commit 0b67d1d into deepcoldy:master Nov 28, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并,感谢 @yintamaa 的贡献,也感谢你在评审期间主动同步主干并补齐 post-terminal 围栏的收尾修复。

这个改动让 /stop 对一类已被挂起重试机制接管的定时写入恢复了正确语义:被 hold 回队列的在途写入在 STOP 时能被精确退休、只回执一次,且不会被注入斜杠命令、TUI 原生输入等旁路通道干扰。

评审中确认的两个非本 PR 范围的既有边界(不阻断、无需在本 PR 处理):

  • tmux attach 的可写 Web 终端走 countHuman=false,其提交不递增 webTerminalSubmitGeneration,该边界在 master 已存在;
  • discardScheduledBacklogForStop 的 activeTask ?? writingTask ?? heldTask 优先级在 capture identity 残留时仍可能选到已结束任务,属 master 既有行为。

后续若需要可以另开 issue 跟进这两项。欢迎继续参与。

@github-actions

Copy link
Copy Markdown

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

这次运行覆盖 b3a1686…0b67d1d8e(2 个提交),同批合入的还有 #3975,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Kimi 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.
Antigravity 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 basic bot flow feishu-core-codex failed Reply "【MOCK-REPLY】已收到指令并完成操作:CODEX_E2E_MARKER_1795914487385" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 1×; re-opened 1×; repo card buttons 0 visible / 0 total, anchor matches 5,…

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.38

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.

2 participants