Skip to content

[PR] fix(launcher): cap the BUSY takeover budget, stop reporting reaped pids (#5955) - #5980

Closed
TOSKA1226 wants to merge 1 commit into
ranxianglei:2026-11-08_wedged-same-lane-takeoverfrom
TOSKA1226:opt-busy-budget
Closed

TOSKA1226 wants to merge 1 commit into
ranxianglei:2026-11-08_wedged-same-lane-takeoverfrom
TOSKA1226:opt-busy-budget

Conversation

@TOSKA1226

Copy link
Copy Markdown
Contributor

Stacked on #5972(base = 该 PR 的分支),只为把 11-09 本机验收量出来的两个点收拾掉,不改动 #5972 已有逻辑。

1) BUSY 候选的接管预算:最坏 ~13.8s → ~5.5s

接管候选是由定义 BUSY 的(TCP 通、health 在 ≥3 个 bring-up 周期里始终不应答),它的 event loop 已经被自己的 fold 打满,所以"优雅"那几级对它基本是空转。实测 13.8s 里有 12.4s 全花在这里:

  • requestShutdown POST 等满 3s(holder 永远不会读到这个请求)
  • waitForListenerClose 5s
  • SIGTERM 后再等 2s(WEDGED_TERM_GRACE_MS)
  • 然后才是它本来就必然要走的硬杀

改法:不删任何一级,只给 BUSY 路径换短预算 —— requestInstanceShutdown(origin, timeoutMs?) 新增可选预算,wedged 路径传 WEDGED_BUSY_REQUEST_TIMEOUT_MS = 750;两个观察阶段各 WEDGED_BUSY_GRACE_MS = 500;硬杀后的 waitForListenerClose 仍保留 5s(那一级是真可能需要的)。

实测(与 #5972 验收同一 harness,端口 18790,真实 holder 只 accept 不回应):

指标 改前 改后
端到端 16727 ms 7530 ms
force 日志 → listener 释放 12547 ms 4175 ms
force 日志 → health 200 13788 ms 5545 ms

4175ms 构成:750(POST 预算)+ 500 + 500(两段观察)+ ~200(taskkill)+ 2000(WEDGED_POST_KILL_SETTLE_MS,本 PR 没动)。settle 保持 2s 的依据:本机 4 次实测 taskkill /F /T → 首次 bind 成功为 162 / 191 / 226 / 252 ms,2s ≈ 8× 余量;抢跑一次要赔一整轮 bring-up。

2) win32 硬杀后的 ESRCH 噪音

taskkill /F /T 已收割整棵树,随后防御性的 process.kill(pid,'SIGKILL') 必然 ESRCH,而这条被写成 its listener may survive the cleanup (#4125) —— 每次接管都刷一行"可能没杀掉",等于训练运维忽略唯一重要的那行。现在 ESRCH 静默(与 POSIX 分支对齐),其它 errno 照旧上报。hardKillProxyTree 仅为回归测试而导出。

验证

  • 测试 16 → 18 全绿:新增短预算断言(shutdown 收到 timeoutMs === 750、单轮 escalate 假时钟耗时 ≥2s 且 ≤4.5s)与 ESRCH 静默断言(对已退出 pid 硬杀不产生 direct SIGKILL 行,taskkill 自身的失败仍上报)
  • npx tsc --noEmit 干净;npx tsup 构建成功(dist/index.js 5.75MB)
  • 反向用例未受影响:能被唤醒的 holder 仍走优雅关闭、SAME-build BUSY holder 仍 attach 且绝不杀、user-zone / 外车道 / 异端口全不动

commit: 055a51f(父 e7d7179,即 #5972 分支当前 tip)。强杀活进程是否随 prerelease 发、以及 merge 顺序仍留给 owner。

@ranxianglei ranxianglei changed the title fix(launcher): cap the BUSY takeover budget, stop reporting reaped pids (#5955) [PR] fix(launcher): cap the BUSY takeover budget, stop reporting reaped pids (#5955) Nov 8, 2026
@TOSKA1226

Copy link
Copy Markdown
Contributor Author

基线已包含这次修复:055a51f 的父提交就是 e7d7179,所以本 PR 不复述、不重复改 wedgedLedgerFilePath,直接叠在绿的门禁之上。

顺带核对了一下本 PR head 的门禁:055a51f 上 7 个 gate 全 success/completed(含 unused-exports),mergeable_state: clean,无冲突、无需 rebase。

@TOSKA1226

Copy link
Copy Markdown
Contributor Author

一个小请求(不影响评审结论):如果最终采用 squash,麻烦在 commit body 里保留一行 Co-authored-by: TOSKA1226 <toska1226@users.noreply.github.com>;用 merge commit 或 rebase-merge 则无需额外处理(055a51f 的 author 已经是这个身份)。只是为了让改动在历史里可追溯到提交者,评审口径不变。

@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/wiring labels Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复。 本主题在途只有 #5972(本 PR 的 base)+ 本 PR,无并列修复 PR;同族条目(#4811 已关闭、#5451、#5014)机制不同,不冲突。

标签: bug + dsh + scope/wiring + p2 —— 缺陷修复(接管延迟 + 日志噪音),复现与验收环境均为 dsh/win32,改动面是 launcher 进程生命周期接线,特定条件下的性能降级定 p2。

Review 结论:代码质量达到外部提交标准,无需返工;合并前置条件见末尾

独立审了 diff(src/launcher.ts +45/-12、测试 +57/-2)、周边既有行为、CI 实际覆盖,并在 head sha 055a51f 上做了定向本地验证。

先纠正一处门禁误读(不影响代码结论,但影响"已验证"的判断)

PR 侧评论称 "055a51f 上 7 个 gate 全 success(含 unused-exports)"——不成立。我拉了该 head 的全部 check-runs(共 15 个):7 个绿色 gate job 全部来自 e2e 车道工作流(如 workflow e2e-fake-codex),含义是"无 ci:full 标签 → 车道跳过",不是 ci.yml 的静态门禁。原因是 ci.yml 的 pull_request 触发器限定 base ∈ {master, agent-relay, bugfix*},本 PR base 是 #5972 分支,所以 core 矩阵(test shards / static-gates / unused-exports / typecheck)在本 head 上一个都没跑过。对比:#5972 head e7d7179 上全套 core 矩阵是绿的。

我已在 055a51f worktree 上补齐定向验证(全部通过):

  • node scripts/check-unused-exports.mjs → clean(hardKillProxyTree 导出未被标记)
  • node scripts/check-test-import-graph.mjs → ok
  • npx tsc --noEmit → exit 0
  • node --import tsx --test tests/issue5955-wedged-same-lane-takeover.test.ts → 18/18 pass(含新增 2 条),与作者声明一致

回归审查清单(逐项过完的既有行为)

既有行为 结论
requestInstanceShutdown 其它调用方(src/agent/dsh-native.ts:905、rotateStalePredecessor @ src/launcher.ts:4958) 默认参数保持 3s,行为不变 ✓
wedged 升级梯级结构(POST→观察→SIGTERM→观察→硬杀) 一级未删,仅 BUSY 路径预算缩短=有意变更,PR 正文已带实测披露 ✓
硬杀后 waitForListenerClose 5s + WEDGED_POST_KILL_SETTLE_MS 2s 原样保留(已读代码确认)✓
WEDGED_TERM_GRACE_MS 移除 全仓零残留引用,无死常量 ✓
win32 ESRCH 静默 与 POSIX 分支对齐;非 ESRCH errno 与 taskkill 自身失败仍上报 ✓
快速退出路径 holder 在预算内释放 listener 时后续阶段照旧跳过 ✓
边界情形:holder 恰在接管前恢复响应 旧逻辑给最多 ~10s 优雅机会,新逻辑 ~1.95s 内走到硬杀。评估:该路径只在 ≥3 轮 bring-up 连续 health 不应答 + 10min 窗口后才触发;会话状态在磁盘统一存储而非进程内存;终态(硬杀)与旧逻辑相同,只是更快到达——无新数据丢失机制,可接受

测试有效性

两条新测试断言有牙且双向:升级测试同时钉死 timeoutMs === 750、耗时 ≥2s(settle 没被删)且 ≤4.5s(若退回 3s/5s 梯级必超界);ESRCH 测试钉死"已收割 pid 不产生 survivor 行"且"真失败仍上报",并按平台自适应(win32 期望 1 行 taskkill 失败、POSIX 期望 0 行)。#5972 的反向用例(可唤醒 holder 走优雅关闭、SAME-build attach、kill 失败回退 spawn)全部保留并通过。

结构化八问

  1. 是什么问题:[PR] fix(launcher): force-takeover the wedged same-lane proxy holding the canonical port (#5955) #5972 本机验收量出的两点——BUSY 卡死实例的强制接管最坏 ~13.8s(其中 ~12.4s 耗在对它必然空转的优雅阶段);win32 硬杀后防御性 SIGKILL 撞 ESRCH 被报成 "listener may survive",每次接管刷一行误导噪音。
  2. 什么原因导致的:接管候选由定义就是 BUSY(事件循环饱和、health 不应答),完整优雅预算(3s POST + 5s 等待 + 2s SIGTERM drain)对它不可能成功却全额支付;win32 上 taskkill /F /T 已收割整棵树,随后的 process.kill 必然 ESRCH 却被写成"可能没杀掉"。
  3. 影响范围与严重程度:仅影响"同车道 wedged 实例占 canonical 端口"这一罕见场景;改前每轮接管多付 ~8s 延迟 + 一行误导日志。属特定条件下性能降级 + 日志噪音,定 p2,非可用性缺陷。
  4. 怎么修复的:保留全部梯级,只给 BUSY 路径换短预算(POST 750ms、两段观察各 500ms,硬杀后 5s 监听等待 + 2s settle 不动);win32 ESRCH 静默对齐 POSIX 分支,其它 errno 照旧上报。
  5. 是否有回归问题:见上方逐项清单——除有意缩短的接管时长外全部保持;高危模式(语义漂移/fail-fast 变吞错/阈值漂移)逐项过完,唯一语义变化即本 PR 目的本身且已披露。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及——[PR] fix(launcher): force-takeover the wedged same-lane proxy holding the canonical port (#5955) #5972 架构内的纯预算参数优化。
  8. 是否引入了新的配置:无——全部为模块内命名常量,无 env/config surface 变化。

合并前置条件与留给 owner 的事项

判定:可合(满足上述前置条件后)。 代码整洁度按外部提交从严标准全项通过,无需对齐重构。

@TOSKA1226

Copy link
Copy Markdown
Contributor Author

接受纠正,我这条记录作废:055a51f 上那 7 个绿色 gate 全部是 e2e 车道的"无 ci:full → 跳过",不是 ci.yml 的静态门禁;ci.yml 的 pull_request 触发器限定 base ∈ {master, agent-relay, bugfix*},stacked base 下 core 矩阵对本 diff 是零覆盖。我引用的 check-run 结论是绿的没错,但把它读成"core 门禁已过"是错的,是我表述失误。你在 worktree 上补的四项定向验证(unused-exports / test-import-graph / tsc --noEmit / 18 测试)才是这个 head 上真正有效的验证,谢谢补齐。

前置条件我认,并且已经安排好了执行方式:

  1. [PR] fix(launcher): force-takeover the wedged same-lane proxy holding the canonical port (#5955) #5972 合并后我立刻自己做 rebase:opt-busy-budget 已在 fork(TOSKA1226:opt-busy-budget),fetch master → rebase → force-push 到同一分支,base 自动变为 master、core 矩阵随之触发;不需要你们代为操作。
  2. rebase 后我会在这里贴一次矩阵结果,绿了再请你们合 [PR] fix(launcher): cap the BUSY takeover budget, stop reporting reaped pids (#5955) #5980。
  3. Co-authored-by 的请求按你说的交给 owner 定,我不再重复提。

关于 #5972 mergeable_state=blocked:那是 required-checks/branch-protection 侧的配置问题,与 head 上的实际结论无关;这条属于 owner 侧的动作,我在本 PR 不做假设。

@TOSKA1226

Copy link
Copy Markdown
Contributor Author

Retargeting this PR: the src half is now superseded by 2826c51 (field-tuned ladder + win32 ESRCH silence, authored on the feature branch), so I'm not going to fight it — 055a51f's launcher changes duplicate what already landed and the branch is dirty against the new head.

What 2826c51 did not bring is coverage: it is a +33/−14 change to src/launcher.ts with zero test files, which means the new escalation budget (1s POST + 2s post-shutdown wait + 1s SIGTERM drain + 2s post-kill wait + 2s settle) and the ESRCH silence are unguarded against the next re-tune.

So I moved the surviving value onto a tests-only branch on top of 2826c51:

  • branch tests-wedged-budget @ 016d933 (fork, based on the feature-branch head 2826c51)
  • tests/issue5955-wedged-same-lane-takeover.test.ts — 18 cases, +61/−2
  • src/launcher.ts — one token: export function hardKillProxyTree so the win32 silence assertion can call it (gate-safe: the test import keeps unused-exports green)

Local verification on 2826c51:

  • node --import tsx --test tests/issue5955-wedged-same-lane-takeover.test.ts → 18/18 pass, 2.8s
  • tsc --noEmit → exit 0
  • node scripts/check-unused-exports.mjs → clean (8 waived)
  • node scripts/check-test-import-graph.mjs → ok

The budget assertion no longer hardcodes our old 750ms constant; it asserts shutdownTimeouts[0] is a number in (0, 3000) (i.e. never the 3s graceful default a BUSY holder can't answer) and that total escalation staging stays within ~6s of virtual time, so a future re-tune inside that envelope stays green and a regression back to the 3s+5s+2s ladder fails.

I'll leave this PR open but inert; once #5972 lands I'll rebase the tests-only branch onto master and open it as a proper PR against master (base = master, so the core matrix really runs instead of being skipped by the ci:full guard). Say the word if you'd rather have the tests folded into #5972 itself before merge — cherry-picking 016d933 works too.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner

Retarget 完成,本 PR 关闭,由 #5989 取代。

原因:依赖 #5972 已并入 master(merge 6d750ef),而本 PR 的 src 改动已被 2826c51(field-tuned ladder 1s/2s/1s/2s + win32 ESRCH silence)取代 —— 该 commit 已在 master 上。原 head 055a51f 相对 master 处于冲突状态且内容重复。

#5989 只保留本 PR 真正未进 master 的增量:测试覆盖(commit 016d933,tests +61/−2 + launcher.ts 一个 export token),base = master,ci.yml 的 core 矩阵会真正运行。

已在 master 6d750ef + 016d933 上验证:wedged-takeover 测试 18/18 绿、launcher 全量 351 pass / 1 skip、tsc --noEmit / unused-exports / test-import-graph 全绿、3-way merge 无冲突。署名(Co-authored-by 请求)已在 #5989 body 中注明。

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

Labels

bug Something isn't working dsh p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants