Repository navigation
fix(sandbox): relay watcher 先消费请求再发布响应,根治 sandbox-relay-lifecycle 偶发失败 - #2130
Merged
Merged
Conversation
finish() 原来先原子写 <id>.res.json、再删 <id>.req.json。两步之间 已执行完的请求看上去仍在排队:集成测试一看到响应就断言请求已删, watcher 进程恰在两步之间被调度走时就红;接手同一 outbox 的 watcher (restore / transfer 后)扫到它也会再执行一遍。 对调为先删请求、再发布响应,「看到响应 ⇒ 请求已消费」由生产代码保证。 协议不变:沙盒侧客户端只写 req.json、只轮询 res.json。 新增回归用例:在请求已存在后挂 fs.watch,断言请求文件的删除事件 先于响应出现(served / rejected 两条完成路径,仅 Linux)。 Closes #2128 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 21, 2026 22:46
Owner
Author
|
已合并 →
|
This was referenced Oct 21, 2026
|
🚀 Released in v3.49.0 |
This was referenced Oct 22, 2026
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.
Closes #2128
改了什么
src/adapters/backend/sandbox.ts:startOutboxWatcher里的finish()对调了两步顺序。原来先写<id>.res.json、再删<id>.req.json,现在先删请求,再发布响应。这样任何人看到响应时,请求都已经被消费。test/sandbox-relay-watcher.test.ts:新增回归用例,覆盖两条完成路径:请求被正常执行(served)和被拒绝(rejected)。fs.watch,这样请求文件唯一的rename事件就是它被删除。断言这个事件先于响应文件出现。test/sandbox-relay-lifecycle.integration.test.ts:只在 352 行的断言上补了一句注释,说明它依赖的就是上面这个先后关系。断言本身没改。为什么
根因见 #2128。旧顺序下,写响应和删请求之间有一个窗口。集成测试的
expectPaneRelayServed一看到响应就断言请求已删除;watcher 进程恰好在两步之间被调度走时,测试就会红。masterebf12dfe4、dbefd6bf2和 #2122 都红过,三次落在不同的用例上,但都是同一处断言。修法选择改生产代码的顺序,而不是放宽测试,因为「看到响应 ⇒ 请求已被消费」本来就应该是 relay 的保证。旧顺序下,两步之间这条已经执行完的请求看上去仍在排队;接手同一 outbox 的 watcher(restore / transfer 之后)此时扫到它,会再执行一遍。
测试侧没有加等待,也没有加 sleep:原来的断言改由生产代码保证成立。
对老用户的影响
botmux send和 dispatch relay 客户端只写req.json、只轮询res.json,从不检查req.json在不在。升级后,pane 里还在跑的旧客户端配新 watcher,或反过来,都兼容。验证
本地只跑改到的文件,全量靠 CI。
1. 改到的测试文件
bunx vitest run test/sandbox-relay-watcher.test.ts→ 12 passed(原 10 条 + 新增 2 条);bun test→ 12 pass。test/sandbox-relay-lifecycle.integration.test.ts(真 worker + 私有 tmux socket + bwrap)本地各跑一次:vitest 41 passed / 2 skipped,bun 41 pass / 2 skip。2. 变异(区分力)
expected 3 to be less than 2)3. 新用例自身的稳定性
新用例依赖
fs.watch,所以专门压测,防止它本身变成新的偶发。用taskset把测试进程限制在少数几个核上:动手前还单独写了原型验证 inotify 的事件顺序:两种写入顺序各跑 300 次,Node 和 Bun 都 300/300 判定正确,没有丢事件。另外确认了 Node 和 Bun 的事件类型一致(删除和改名报
rename,属性变更报change),所以用例只取rename事件。4. 与在途 PR 的冲突检查
sandbox.ts和这两个测试文件。🤖 Generated with Claude Code