Repository navigation
fix(sandbox): 无 worker 关闭时 kill 后探测遇到 tmux server 退出中的 unknown,先短退避重探再决定是否保留沙盒树 - #2148
Merged
Merged
Conversation
…再决定是否保留沙盒树 kill 掉 tmux server 上最后一个会话会让 server 自行退出;紧跟着的 has-session 如果在 server 退出过程中连上,会读到 "server exited unexpectedly",按 server 级错误判成 unknown。retireOrphanedSandboxTree 只探测一次,于是把本可回收的 沙盒树保留下来(sandbox-relay-lifecycle:553 偶发)。 - persistent-backend 新增 probePersistentBackendTargetAfterKill:只对 unknown 做有界短退避重探(与 probeSessionWithRetry 同参数,默认 3 次、最多约 0.75s), exists / missing 立即返回;仍是 unknown 时照旧保守保留 - retireOrphanedSandboxTree 改用它 - 集成测试在 lab 的 tmux shim 上确定性注入「kill 后第一次 has-session 读到 server exited unexpectedly」,三种沙盒形态各一条;helper 补单测 Closes #2146 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 22, 2026 06:43
…次探测自身的 deadline Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
已合并 →
follow-up(不阻断):
未做:发版、部署。 |
This was referenced Oct 22, 2026
|
🚀 Released in v3.50.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.
改了什么
src/core/persistent-backend.ts:新增probePersistentBackendTargetAfterKill(target),用于 kill 之后的验证。unknown时才重探,带短退避,次数有界。参数与现有TmuxBackend.probeSessionWithRetry相同:默认 3 次,退避 150ms / 300ms 加抖动,最多约 0.75s。exists或missing时立即返回。unknown,就原样返回给调用方,由调用方保守处理。src/core/worker-pool.ts:无 worker 关闭里的retireOrphanedSandboxTree改用这个函数。原来是 kill 之后只探测一次。为什么
issue #2146:
test/sandbox-relay-lifecycle.integration.test.ts:553(worker-less close tears the tree down)在 bun-test 上偶发红,日志是killWorker: keeping the sandbox tree — backing session not proven gone (probe: unknown)。has-session如果正好在 server 退出过程中连上,会读到server exited unexpectedly。isTmuxServerLevelErrorText把它判成 server 级错误,结果是unknown。missing就保留沙盒树,等周期 sweep 在会话不活跃后回收。kill-session后立刻has-session。16 路并发共 1600 次,其中 2 次读到server exited unexpectedly;串行跑 200 次一次都没出现。no server running,即missing)。所以修法是重探,不改报错分类:真卡死、或一直不确定的 server 仍然是unknown,删除仍只在拿到权威的missing之后才做。对老用户的影响 / 影响面
missing之后,没有新的删除路径。unknown会多重探最多 2 次。herdr 的共享 / 自定义 target 本来就固定返回unknown,现在会多 2 次探测、多等最多约 0.75s,结果不变,仍然保留。execFileSync最多可阻塞 3s。新增的等待只在结果为unknown时发生,最多约 0.75s。probePersistentBackendTarget,fix(tmux): 托管会话改用独立 tmux socket,测试连不到宿主 tmux server #2107 给它加的 socket 分支会自动生效。我用git merge-tree试合了 fix(tmux): 托管会话改用独立 tmux socket,测试连不到宿主 tmux server #2107 当前 head 和本分支,无冲突。测试
test/sandbox-relay-lifecycle.integration.test.ts:给 lab 的 tmux shim 加一个开关,打开后 kill 之后的第一次has-session会确定性地报server exited unexpectedly,开关只生效一次。原用例改成两个变体:原样一个,打开注入一个。注入变体还会断言注入确实被这次探测消费掉了,防止注入落空导致假绿。三种沙盒形态(oncall / scratch / credential-only)各跑一遍。test/persistent-backend-type.test.ts:给新函数补单测,覆盖三种情况:unknown之后得到权威答案、权威答案立即返回且不等待、次数用完仍是unknown(并检查每次重探之间有递增的等待)。验证
本地(
TMPDIR=/var/tmp/bmxt,bun 1.4.2,只跑改到的和相关的文件;全量交给 CI):tsc --noEmit -p tsconfig.json:0 错vitest run test/sandbox-relay-lifecycle.integration.test.ts:44 passed / 2 skipped;bun test同一文件:44 pass / 2 skip / 0 failvitest run test/test-hygiene.test.ts test/persistent-backend-type.test.ts test/restart-worker-null-reattach.test.ts test/restart-recovery-card-status.test.ts test/terminal-cold-wake.test.ts test/command-retry.test.ts:111 passed。后四个文件 mock 了persistent-backend,都确认过不受影响。persistent-backend-type.test.ts用了vi.hoisted,按scripts/run-bun-tests.mjs的规则不进 bun 腿,在 master 上也是如此。变异证据(临时改动,跑完已还原):
retireOrphanedSandboxTree换回只探测一次keeping the sandbox tree — backing session not proven gone (probe: unknown),与 CI 失败同形;原样变体 3/3 绿missing时都重探(exists也重探)第二轮(
b7e2d4875):评审 P3 顺手修probePersistentBackendTarget里是按构造返回unknown的(根本不会去问 herdr),等多久结果都一样。现在遇到这种 target 直接返回unknown,不探测也不等待,之前每次无 worker 关闭都会白阻塞约 0.45s。attempts为 1 和 0 时都只探测一次、不等待;结构性 unknown 的 herdr target 不探测、不等待。变异验证:去掉 herdr 提前返回、把 attempts 下限改成 2,对应用例都会红。tsc --noEmit0 错;vitest run test/persistent-backend-type.test.ts test/test-hygiene.test.ts69 passed。在合入了最新 master(已含 fix(tmux): 托管会话改用独立 tmux socket,测试连不到宿主 tmux server #2107)的树上,注入用例用 vitest 和 bun 分别跑,都是 6/6 通过。worker.ts中 read-isolation 冷启动前的confirmPaneGone要求严格missing,同样可能碰上这个 server 退出窗口(后果是拒绝启动)。这段代码刚被 fix(tmux): 托管会话改用独立 tmux socket,测试连不到宿主 tmux server #2107 改过,另开 follow-up 处理。Closes #2146
🤖 Generated with Claude Code