Repository navigation
fix(sandbox): 崩溃停机后重试不再拆掉刚准备好的沙箱树 - #3032
Merged
Merged
Conversation
崩溃循环停机后的重试直接进入 spawnCli(),不经过 killCli(), 上一代的 sandboxCleanup 仍在。沙箱分支先 prepare 本次视图再调用它, 而它清理的正是同一会话的树(scratch/direct)或 relay outbox, 导致新 CLI 绑定到已被删除的视图并立即退出。 四个分支统一在 prepare 之前停旧 watcher、调用并清空旧 cleanup。 Fixes #2500
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 11:16
This was referenced Nov 8, 2026
|
🚀 Released in v3.59.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.
症状
scratch 沙箱会话的 CLI 连续崩溃、daemon 停止自动重启(
park_diagnostic)之后,用户再发一条消息触发重试:新 CLI 一启动就以退出码 1 结束,沙箱视图不可用。根因
spawnCli()的沙箱分支先 prepare 本次视图,再调用sandboxCleanup释放上一代。正常的重启路径都先经过killCli(),它已经调用并清空了sandboxCleanup,所以这里平时是空操作。崩溃循环停机后的重试不经过
killCli():CLI 退出处理不碰sandboxCleanup,进入spawnCli()时它仍是上一代的 cleanup。对 scratch 而言它是teardownScratchSession(<同一 sid>),于是刚 prepare 好的同一会话树被立即卸载并删除,bwrap 随后绑定一个不存在的视图,CLI 启动即失败。direct 沙箱(oncall)、macOS scratch 与 credential-only relay 三个分支的写法相同,清理的也是同一会话的树或 relay outbox。修法
四个分支统一把「停上一代 outbox watcher、调用并清空上一代 cleanup」挪到 prepare 之前。这与
killCli()后再 spawn 的普通重启语义一致:先拆旧树,再建新树。warm reattach 分支不调用 cleanup,未改。验证
test/scratch-crash-stop-retry.test.ts:在私有挂载 + PID 命名空间里起真实 worker(scratch 沙箱、pty 后端),假 CLI 首次启动即崩溃,测试模拟 daemon 发park_diagnostic后再发一条消息。断言重试后的 CLI 在沙箱里启动并写出报告、工作目录可写,且 merged 根仍是挂载点。npx vitest run test/scratch-crash-stop-retry.test.ts test/scratch-submount-isolation.test.ts test/scratch-prepare-failure.test.ts:通过。npx vitest run test/sandbox-relay-lifecycle.integration.test.ts:除 3 个strict policy over an unstamped generation用例外全部通过;这 3 个在未改动的 origin/master 上同样失败,与本改动无关。npx tsc --noEmit -p .、bun run build:通过。Fixes #2500