Repository navigation
fix(restart): 崩溃自动重启、dashboard 重启与 cwd-move 后恢复 workerReady,合并在飞重启的 attempt 可结算 - #2033
Merged
Merged
Conversation
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 19, 2026 13:24
…启成功后恢复 workerReady CLI 崩溃自动重启(cli_crash)、dashboard 重启按钮(operator)、角色切换 cwd-move 三条路径先把 ds.workerReady 置 false,再发不带 attemptId 的 restart。worker 对这种 restart 不回 restart_result,in-worker respawn 也不再发进程级 ready,于是 isSessionLifecycleInFlight 恒为真,fork / relay / dashboard 生命周期操作永久 worker_busy,直到手动 /restart(#1863)。 - requestSessionRestart 成为唯一的 restart IPC 发送方:新增 cwd-move 透传参数 updateWorkingDir;审计 reason 由来源推导(cli_crash → cli_crash,dashboard → operator,/restart 与卡片不带);同步发送失败通过 startFailure 回报调用方。 RestartSource 增加 cli_crash / dashboard / cwd_move。 - cli_crash:保留 1 分钟 3 次的崩溃计数与放弃逻辑;失败的 respawn 先回 restart_result(failed) 再报 claude_exit,每次崩溃各自铸新 attempt;在飞重启期间 的崩溃并入该轮(不发 IPC),不叠加第二次 respawn。 - dashboard 重启:保留 operator reason、重启通知与 IPC 断开时的 502。已有关联重启 在飞时返回 409 restart_in_progress(附可读提示,dashboard toast 直接展示)—— 并入会丢掉 operator 刚保存的配置,另起一次又会与在飞重启竞争。 - cwd-move:已有关联重启在飞时在落盘新目录之前返回 409 restart_in_progress,不改 会话 workingDir;否则仍先落盘再请求 respawn,IPC 断开时仍 killWorker 冷启动进新目录。 - 行为变化:master 上这两条入口在重启在飞时会再发一次裸 restart(并导致永久 worker_busy),现在改为 409,调用方稍后重试即可。/restart 与卡片并入保持 #1032 语义。 测试:新增 test/restart-paths-worker-ready.test.ts,三条路径各自经真实 IPC handler / IPC 路由驱动:成功回执后 workerReady 恢复且 fork / relay 不再 worker_busy;失败与超时 不放开;在飞崩溃并入不重复发 restart;dashboard / cwd-move 在飞时 409 且不发 IPC、 cwd-move 不落盘;IPC 断开的原有回退。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 后再结算 worker 收到 restart 时若已有一轮重启在飞(owned 重启、其续体、或 Codex 自动升级) 会直接合并、不叠加第二轮,但此前合并分支不碰 activeRestartAttemptId:在飞这一轮无 attempt 认领回执时(worker 自发的重启,或上一个 attempt 已因 replacement 退出被判 failed、daemon 随即为 claude_exit 铸了新 attempt),被合并的 attempt 永远等不到 restart_result,daemon 侧 workerReady 栅栏放不开(#1863)。这些窗口 daemon 看不到, dashboard / cwd-move 的 409 检查挡不住带配置变化的请求并入。 - foldRestartIntoWindow:合并时把请求的启动设置(cwd / env / model / larkToolBinding,按值比较、env 键无序)与该窗口 replacement 实际使用的快照比较 (restartCfg 捕获时记下;快照前到达的请求会被快照包含): - 相同 → 无人认领时接管回执(已有认领绝不替换); - 不同(或已有待收敛请求)→ 记为待收敛:旧 replacement 的就绪边沿与续体结束都 不结算它,窗口结束后从最新 lastInitConfig 收敛 respawn(decideRestartFollowup 新增 launch-config,cwd 差异仍走 cwd-move,预算规则相同),由收敛后的 replacement 就绪才结算;收敛失败则 failed。 - Codex 自动升级:窗口内 ready 边沿不结算(defer_upgrade);每个恢复 pass 验证通过后 按值判定(decideUpgradeLaunchConvergence),有差异时(含此前直接判失败的 cwd/env 变化)再跑一个恢复 pass,而不是报成功或报失败关闭输入。所有 pass 共享同一份显式的 升级上下文 upgradeContext:已验证的可执行文件(target.path,lastInitConfig 并不知道 它,普通重启会回退到 PATH 上的旧 codex)、精确线程(restoring 阶段禁止 fresh 回退)、 killCli 保留待发消息与已受理的斜杠注入、每个 pass 都做运行时版本与线程 fd 校验后才 结算;收敛 pass 只把启动设置换成并入请求要求的值(含 model)。最多 3 个 pass,超出 或任一 pass 失败时为接管 / 待收敛的 attempt 发 failed,输入保持关闭。 - 回执结算统一在 settleRestartAttemptOnReady:ready 边沿、续体收敛结束且 replacement 已在 prompt、升级验证通过。后两处先重发 prompt_ready 再发回执(daemon 请求该 attempt 时清了 cliReady,只有 prompt_ready 能重新置位)。 - 全新(非合并)restart 清掉残留的待收敛请求;fatal 退出时一并 failed 待收敛 attempt。 测试: - worker-restart-merge-attempt(真实 worker + 假 CLI / 假 codex,app-server 不应答使 续体卡在 7s 标题基线探测):无关联在飞重启时被合并的 attempt 拿到成功回执;已有认领 时后来者拿不到回执;ready 边沿后接管的同配置 attempt 在续体结束时补发 prompt_ready 与回执、无额外 respawn;worker 自发重启快照后到达的 role switch 只由新 cwd 的收敛 replacement 结算;上一个 attempt 已结算后带新 env/model 的重启收敛后才结算,且最终 replacement 使用新 env 与 --model。 - worker-codex-session-upgrade(执行真实 autoUpgradeCodex / fold / 结算函数,不 stub 收敛路径;killCli 桩按真实语义在未 preserveInjections 时清空注入):同配置并入验证后 结算、只跑一个 pass;快照后改 model / larkToolBinding 的并入跑第二个 pass——沿用 target.path、精确线程、preserveInjections(斜杠注入与待发消息存活)、请求的设置, 第二次校验通过后才结算;cwd / env 变化改为收敛而非失败;收敛 pass 校验失败、升级 pass 失败、设置反复变化超过 3 个 pass 时并入的 attempt 收到 failed 且输入保持关闭。 - restart-followup-policy:按值比较、classifyMergedRestart、launch-config 收敛、 decideUpgradeLaunchConvergence、decideRestartReceipt;worker-restart-race / null-reattach:源码钉住合并分类、快照捕获、收敛先于结算、升级收敛与失败路径。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
裸前缀 'function markPromptReady' 会先命中更早的 markPromptReadyFromPty,切片因此 吞进两者之间新增的 settleRestartAttemptOnReady(它自己也会重发 prompt_ready), 导致 prompt_ready 顺序断言误判。改为按 'function markPromptReady(): void' 定位。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
force-pushed
the
fix/restart-paths-worker-ready
branch
from
October 20, 2026 07:10
0b28a2a to
070dc64
Compare
This was referenced Oct 20, 2026
|
🚀 Released in v3.48.0 |
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.
Fixes #1863
问题
CLI 崩溃自动重启、dashboard 重启按钮、角色切换 cwd-move 这三条路径先把
ds.workerReady置 false,再发不带 attemptId 的 restart。worker 对这种 restart 不回restart_result,in-worker respawn 也不再发进程级ready,于是isSessionLifecycleInFlight恒为真:fork / relay / dashboard 生命周期操作永久worker_busy,只能手动/restart。另一处同源问题:worker 已有一轮重启在飞(owned 重启、其续体、Codex 自动升级)时收到新的 restart 会直接合并,但合并分支从不认领
activeRestartAttemptId,被合并的 attempt 永远等不到回执,栅栏同样放不开。改动
daemon 侧(
3d6a2c7c6)requestSessionRestart成为唯一的 restart IPC 发送方;RestartSource新增cli_crash/dashboard/cwd_move,审计 reason 由来源推导。restart_result(failed)再报claude_exit;在飞重启期间的崩溃并入该轮,不叠加 respawn。restart_in_progress(cwd-move 在落盘新目录之前拒绝),dashboard toast 直接展示提示。IPC 断开时的原有回退(502 / killWorker 冷启动)不变。worker 侧(
ab865e4ce)foldRestartIntoWindow:合并时把请求的启动设置(cwd / env / model / larkToolBinding,按值比较)与该窗口 replacement 实际使用的快照比较:upgradeContext(已验证的可执行文件、精确线程、保留待发消息与已受理的斜杠注入、每 pass 版本与线程 fd 校验);设置有差异时再跑一个恢复 pass,最多 3 个 pass,超出或失败则 failed 且输入保持关闭。settleRestartAttemptOnReady,结算前先重发prompt_ready。行为变化
/restart与卡片的并入保持 fix(core): 重启成功后恢复 worker 就绪状态 #1032 语义。已知边界(未在本 PR 处理)
cliReady变 true,但workerReady栅栏不放开,fork / relay 仍拒绝,直到收敛结算。/restart;正常情况下收敛期间 dashboard / cwd-move 会被 409,/restart、卡片、崩溃自动重启只并入,不会出现。影响面
core/worker-pool.ts、core/restart-coordinator.ts、core/restart-followup-policy.ts、core/dashboard-ipc-server.ts、worker.ts。测试
bun run build通过。bun test逐文件:worker-codex-session-upgrade 36/36、worker-restart-race 13/13、restart-followup-policy 29/29。test/restart-paths-worker-ready.test.ts(三条路径经真实 IPC handler 驱动)、test/worker-restart-merge-attempt.test.ts(真实 worker + 假 CLI / 假 codex)。target.path/ 丢注入保留 / 跳过校验 / 丢 model、去掉 3 pass 上限等),对应测试均变红。🤖 Generated with Claude Code