Repository navigation
fix(dsh): 看门狗先于 prompt 确认触发时不再因未处理拒绝崩溃 - #3523
Merged
Merged
Conversation
dsh runner 在发出 session/prompt 之前就给本轮装好了空闲看门狗与 hard limit 计时器, 但要等 runtime 确认(ACK)之后才 await 这轮的 promise。宿主负载高、ACK 晚于看门狗时 (或 runtime 在 ACK 前退出),这一轮被拒绝时还没有任何监听者,成为未处理的 Promise 拒绝:runner 直接以退出码 1 崩溃,不发 final,用户收不到任何回复。CI 上 dsh-runner.test.ts「still terminates a turn that emits progress forever」偶发 「exit 1、0 个 final」正是这个形状(780ms 内退出,早于 1200ms 的 hard limit)。 - runTurn 改为让 ACK 请求与本轮 promise 赛跑:看门狗或 runtime 退出先到时立即结束本轮, 照常发 final 并回收 runner,不再等一个可能永远不来的 ACK。本轮在 ACK 前不可能成功 结束(通知要等 ACK 给的 messageId 认领回执后才处理),所以赛跑只会被拒绝提前结束。 - fake dsh server 增加 FAKE_DSH_PROMPT_ACK_DELAY_MS,回归用例让 ACK 晚于看门狗, 断言 runner 发出一条 final 并以 1 回收、stderr 无未处理拒绝。 - 原偶发用例的空闲窗口由 300ms 放宽到 1000ms(hard limit 4s),并改等 close 再读 stdout,避免负载下空闲看门狗先于 hard limit 触发。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 17, 2026 02:52
|
🚀 Released in v3.59.18 |
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.
改了什么
dsh runner 的
runTurn改成让session/prompt的确认(ACK)请求与本轮的 turn promise 赛跑(Promise.race)。原来的写法:发 prompt 之前就给本轮装好空闲看门狗(
--turn-timeout-ms)和 hard limit 计时器,但要等 ACK 返回后才await turnPromise。如果 ACK 比看门狗晚到(宿主负载高),或者 runtime 在 ACK 之前退出,这一轮被拒绝时还没有任何监听者,就成了未处理的 Promise 拒绝:runner 直接以退出码 1 崩溃,不发 final,用户收不到任何回复。现在看门狗或 runtime 退出先到时,本轮立即结束:照常发出 final(
dsh runner error: dsh turn timed out …),然后按致命错误回收 runner,也不再去等一个可能永远不来的 ACK。本轮在 ACK 之前不可能成功结束——通知要等 ACK 给出的 messageId 认领回执后才会处理,turn.resolve()只在那之后调用——所以这场赛跑只会因为拒绝而提前结束,ACK 正常到达时行为不变。为什么
CI 偶发:
test/dsh-runner.test.ts › still terminates a turn that emits progress forever断言expected [] to have a length of 1 but got +0,进程退出码 1 的断言已经通过,只是 final 一个都没有。这条用例在 CI 上 780ms 就结束了,早于 300ms×4=1200ms 的 hard limit,说明 runner 不是走 hard limit 路径退出的。确定性复现:给 fake dsh server 加了
FAKE_DSH_PROMPT_ACK_DELAY_MS,让 ACK 晚于 300ms 看门狗到达。修复前稳定复现与 CI 一字不差的失败,runner 的 stderr 是dsh-runner.ts:641 … Error: dsh turn timed out after 300ms,栈来自看门狗计时器,进程因未处理拒绝退出。排查过程中排除的两种解释(探针证据):
process.exit时丢掉还在队列里的数据,但这条用例总输出只有约 5KB,远小于管道缓冲,final 在退出前就已经写进内核了。这个机制与本次偶发无关,本 PR 不改。影响面
src/dsh-runner.ts一处(dsh CLI 会话的 runner),不碰共用的 runner-common、JSON-RPC 核心或其它 runner。逐个看过 mira/mir/codex-app/antigravity/minimax runner,都没有「先装看门狗、ACK 之后才 await」的同构写法。--turn-timeout-ms通常是分钟级,ACK 超时是 30s,所以这个崩溃主要出现在 runtime 在 ACK 前退出、或者 turn timeout 配得比 ACK 慢的时候。修复后这两种情况都会正常回复错误并回收 runner。close之后再读 stdout,避免负载下空闲看门狗先于 hard limit 触发。验证
bunx vitest run --project unit test/dsh*.test.ts test/test-hygiene.test.ts:10 个文件 246 例全绿。HOME=$(mktemp -d) bun test --timeout=180000 test/dsh-runner.test.ts:63 pass / 0 fail。bunx tsc --noEmit:0;bun run build:通过。timed out after 300ms)、以 1 退出、stderr 无未处理拒绝。🤖 Generated with Claude Code