Repository navigation
test(lark): 终态回执用例改为等确定条件,根治 unified 卡投递泄漏导致的偶发失败 - #2122
Merged
Merged
Conversation
707 行的偶发失败来自前一个 unified 用例:它 sleep 20ms 就结束, 没等后台回复卡管线(文件锁 + durable 写盘后 sessionReply)。负载高时 这次 POST 落进下一个用例的 mockReset 之后,被 not.toHaveBeenCalled 数到。 固定的 /tmp dataDir 跨次运行残留 messageId,本机只 PATCH 不 POST, 所以本地复现不了。 - deliver() 同步调用真实 IPC handler 并保留其 promise,settle() 用 生产的 waitForFinalOutputDeliveryDrain 等围栏里的回执管线结束, 替换全部 8 处固定 sleep - unified 用例正向等自己的回复卡 POST 落地;afterEach 对每个会话 settle - dataDir 改为每次运行独立的 mkdtemp 目录 Closes #2121 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 19:09
unified 回复卡的发布不经 beginFinalOutputDelivery 围栏,靠所在用例 正向等 POST;以后新增不经围栏的后台写也要同样等待。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-terminal-receipt-tes
Owner
Author
|
已合并 →
|
This was referenced Oct 22, 2026
|
🚀 Released in v3.49.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.
Closes #2121
改了什么
只改了
test/turn-terminal-receipt.test.ts,生产代码没动。根因:失败的用例在 707 行,但这次红不是它自己的判定出错,而是前一个用例
does not duplicate the terminal UI of unified reply-card mode的后台投递漏了过来。turn_terminal会void起一条回复卡管线:先拿回复卡存储的文件锁,做 durable 写盘,然后调sessionReply发 unified 卡。sleep 20ms就结束了,没有等这次投递。负载高时 POST 晚于 20ms,落到下一个用例beforeEach里的mockReset()之后,707 行的not.toHaveBeenCalled()就数到了 1 次。/tmp/test-terminal-receipt,多次运行共用。本机跑过一次后,回复卡记录里已经有messageId,以后都只 PATCH、不 POST。CI runner 每次都是新机器,第一次跑就会 POST。修法:
deliver():按EventEmitter#emit的方式同步、依次调用真实 IPC handler,但保留每个 listener 的 promise。settle():handler 返回之后,再用生产代码的waitForFinalOutputDeliveryDrain等它围栏住的延迟回执管线结束(终态条重试、interim 的二次判定)。两步都完成,就是「终态已处理完」的确定条件:该发的终态条到这时一定已经发了。setTimeout(resolve, 20)全部换成deliver+settle。beforeWrite守卫匹配,不会把独立终态条误认成它。afterEach对本用例建过的每个会话都settle一次,围栏里的投递不会再漏进下一个用例。mkdtemp),afterAll删除。没有降低原有验证:
settle完断言恰好发了 1 次。原来是 sleep 后断言没发,再waitFor至少发过。生产代码不涉及时序问题:unified 卡的终态更新本来就设计成 fire-and-forget;独立终态条正确排除了 unified 模式,CI 上那 1 次调用也是 unified 卡自己的 POST(本地复现时抓到的参数是
turnId='om_turn_unified'、uuidbrc_…),不是误发的终态条。影响面
src/、配置或依赖;不涉及其它 CLI、后端或会话类型。waitForFinalOutputDeliveryDrain是现有的生产导出(graceful shutdown 用的就是它),没有为测试新增导出。验证
本地只跑相关测试文件。压测时用
taskset把测试进程限制在少数几个核上,模拟负载高的 CI runner。1. 整文件跑通
bunx vitest run test/turn-terminal-receipt.test.ts→ 34 passedbun test test/turn-terminal-receipt.test.ts→ 34 passbunx vitest run test/test-hygiene.test.ts→ 26 passedmock.calls元组下标,不在本次改动的行上),没有新增错误。2. 高负载连续 50 次
对照组是「旧用例,只把 dataDir 换成独立临时目录」,等价于 CI 新机器上的旧代码。
retries transport failure(expected 'tr_…' to be 'brc_…')retries transport failure3. 直接复现
给
withFileLock注入延迟,模拟负载下的锁和 fsync 耗时:Received number of calls: 1,抓到的泄漏调用是('interactive', 'om_turn_unified', uuid brc_…)。4. 变异(区分力)
逐个改坏
worker-pool.ts里对应的判定,每次跑完都还原:excludes silent schedules, VC receivers…这条照样通过,抓不到这个回归。整文件跑时旧版可能会红,但红在无关的retries transport failure上:被推迟的那条 VC 终态条(tr_uuid)在 retries 用例首次发送之后、1 秒重试之前插进来,被数成了第 2 次调用。这和 test(lark): turn-terminal-receipt 的 unified 回复卡投递泄漏到下一个用例,bun-test 间歇失败 #2121 是同一种跨用例泄漏,只是这次漏过去的是变异自己的终态条。excludes…这条对应用例上。settle()只覆盖经beginFinalOutputDelivery围栏登记的管线。unified 回复卡的发布不在围栏内,由它所在的用例自己正向等 POST;doc comment 已写明,以后新增不经围栏的后台写也要同样等待。🤖 Generated with Claude Code