Repository navigation
fix(worker): remote-runner 串行 FIFO 门不再绑定下放 slash 开关 - #4045
Merged
Merged
Conversation
#3484:flushPending 的 serialRemoteTurns 把「每 drain 只放一条、终态后 补踢队列」的 FIFO 串行门错误地合取了 delegatedSlashCommands.length>0。 remote-runner 后端本身用 activeTurnId 守卫拒绝在途第二 turn (返回 submitted:false / 'turn ... is still active'),因此未开启 下放命令的默认会话里,连发的第 2/3 条消息在首个 turn 在途时被直接 写入后端、被守卫拒绝,worker 发 submit_impossible 通知并丢弃出队项 ——消息丢失而非排队串行。开启 delegatedSlashCommands 的会话恰好 因为这个合取一直有 FIFO 保护。 修复:serialRemoteTurns 对所有 effectiveBackendType==='remote-runner' 的会话为真;串行语义本就由 remote-runner turn 通道保证,与下放开关 无关,不新增配置。 测试:新增 test/worker-remote-runner-serial-fifo.test.ts,用 spawnTsScript 驱动真实 worker + 可控假 provider(首 turn busy 延迟、 final 由释放文件门控),断言非下放会话三条消息按 m1→m2→m3 FIFO 排空、全程无 'is still active' 拒绝通知、三条均 turn_terminal completed;摘门变异(serialRemoteTurns=false)精确咬出 m2/m3 两条 submit_impossible 用户通知(与 issue 症状一致)。vitest 新用例 1/1、 bun 腿 1/1、typecheck 0;既有 worker-remote-runner.integration 12/12 全绿(含非下放的 takeover 排队场景)。 Refs #3484 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 30, 2026 07:56
deepcoldy
commented
Nov 30, 2026
deepcoldy
left a comment
Owner
Author
There was a problem hiding this comment.
结论:代码可合,无阻断项,无需作者修改(head 024e11101f)。
核验要点:
- 忙时到达:串行 break 在任何后续出队前生效,后继消息留在队列;各 final 后按 FIFO 逐条释放。
- 快速 final:将既有 same-chunk busy/final 用例临时改为非下放配置后通过,flush finally 的补踢没有丢唤醒。
- 恢复/reattach:
remoteRunnerRecoveredTurnInFlight在 FIFO 门前独立拦截,精确终态清栅栏并补踢;现有非下放 takeover 集成用例通过。 - 跨 principal:未经确认的他人输入仍按既有边界拒绝;以确认后的
queueAfterActiveTurn形态实测 A/B/C 三 principal 连发,顺序及 provider 收到的 caller 均正确。 - 与 #4050 当前 head
445b0561911a的三方合并无冲突;叠合树保留本 PR 谓词及其 activeTurnSteer 例外。
实际验证:相关 4 个测试文件 65/65 通过;新增用例 Bun 腿 1/1;两个临时真实 worker 探针通过;bun run build 成功。探针改动均已还原,工作树干净。
非阻断测试卫生建议:后续可让该 harness 同时回收 fake provider 孙进程(进程组 kill、stdin 关闭退出或定时器 unref),避免断言提前失败时本机残留;不要求本 PR 修改。
合码仍需按门禁等待当前 head 的全部必需 CI 检查通过。
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.
背景
Closes #3484
remote-runner 后端自身用
activeTurnId守卫保证同一时刻只有一个在途 turn:第二个 turn 在首个 turn 未终态时提交会返回{ submitted:false, disposition:'untouched', failureReason:'remote runner turn <id> is still active' }。worker 的 flush 循环里有一个 FIFO 串行门
serialRemoteTurns:为真时每个 flush 只写一条(if (serialRemoteTurns && result?.submitted !== false) break;),并在 turn 终态、prompt-ready 时通过 microtask 补踢队列(worker.ts约 35964/36014 行)。但这个门的条件被错误地合取了「本会话开启了delegatedSlashCommands」:delegatedSlashCommands是 #3481 为「按 Bot 显式下放 /adopt、/detach」引入的开关,默认关闭。于是默认的非下放 remote-runner 会话没有 FIFO 保护:连发的第 2、3 条消息在首个 turn 在途时被同一 flush 路径直接写入后端,被 activeTurnId 守卫拒绝;worker 走writeInput: submit impossible — notifying user immediately,向飞书发「刚才那条消息没有安全写入 Remote Runner,原因:remote runner turn … is still active」回执,并把已出队的消息丢弃——用户连发的消息丢失,而不是排队等首 turn 结束后按序送达。开启下放命令的会话恰好因为这个合取一直有串行保护。该缺陷已由独立探针在真实 worker + 可控 provider 上复现(非下放 phase:m1 到达 provider,m2/m3 各收到一条
is still active拒绝通知;下放 phase:g1→g2→g3 严格 FIFO 且零拒绝)。改动
src/worker.ts一处条件放宽:串行语义由 remote-runner turn 通道本身保证,与是否启用下放 slash 命令无关;不新增配置、不改后端守卫、不改路由。对已开启
delegatedSlashCommands的会话行为完全不变(条件原本即为真)。影响面
effectiveBackendType === 'remote-runner')。acceptSlashFromBots挡下但命中下放白名单的 bot slash 应入口拒收)是独立的入口门控加固,另单处理。测试验证
新增
test/worker-remote-runner-serial-fifo.test.ts(沿用worker-remote-runner.integration.test.ts的spawnTsScript真实 worker 子进程 + 假 provider harness):delegatedSlashCommands;is still active的user_notify,且 provider 只收到 m1(m2/m3 留在 worker 队列);[m1,m2,m3],三条均收到turn_terminal completed,全程零拒绝通知。实际结果(分支基于最新 master
44a1554a43,worktree/data00/botmux-wt-20261130/rr-serial-3484):bunx vitest run test/worker-remote-runner-serial-fifo.test.ts:1/1 passed(6.8s);bun test test/worker-remote-runner-serial-fifo.test.ts(bun 腿):1 pass / 0 fail;node scripts/tsc.mjs -p tsconfig.typecheck.json:exit 0;bunx vitest run test/worker-remote-runner.integration.test.ts:12/12 passed(含同样是非下放配置的 takeover 排队场景,门放宽后仍正确);const serialRemoteTurns = false;后,新测试精确咬红——m2/m3 产生两条与线上症状一致的submit_impossible用户通知(expected [user_notify, …(2)] to have length +0 but got 2);还原后全绿。🤖 Generated with Claude Code