Repository navigation
fix(tmux): reattach remain-on-exit 重设统一走会话边界版本解析并补门控回归 - #2430
Merged
Merged
Conversation
#2418 已合入 master,跟进双审遗留的 1 P2 + 2 P3: - 补 applySessionOptions 的 remain-on-exit failed reattach 重设门控 回归(3.1c 不重设 / 3.3a 重设一次,双向断言 + null 缓存边界重探 集成用例),此前该门控无任何测试守(去门控变异全绿)。 - ensure-tmux 新增 resolveTmuxVersionAtSessionBoundary():缓存命中 直接用,缓存为 null(失败探测的短 TTL 内)时强制重探一次,仍读 不到保持 null fail-closed。new-session、reattach 重设、worker 启动 自检三处共用同一判定;热路径 resize() 仍用缓存 getter。 - worker 自检改走边界解析:自检日志描述的就是随后建会话将采取的 同一判定,不再在一次瞬时 tmux -V 超时下打印与实际相反的降级警告; 成功解析同时预热建会话缓存。 Co-Authored-By: Claude Code <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 27, 2026 08:30
This was referenced Oct 27, 2026
接 #2430 复审两条 P3: - applySessionOptions 增加 version 入参:createDetachedSession 把自己 边界解析的结果传入,一次会话创建只解析一次。此前方法末尾的重设会 再走一次边界解析,而 resolver 对任何 null(含 null TTL 内)都强制 重探,-V 挂住时一次创建最坏多付一次 3s 超时;reattach 路径无前置 解析,保持无参默认解析一次。新增「-V 持续不可读时每次会话创建只 探测两次」回归(改前实测 3 次)。 - worker 启动自检的边界解析挪进一次性 guard 内:tmux 永久不可读时 不再每次 spawnCli 都付探测成本;成功解析仍预热建会话缓存。 - 措辞收窄:resolver 只保证单次调用内重探一次,不保证两个边界答案 一致;连续两次探测失败、第三次成功时自检日志仍可能与后续建会话 的实际状态相反,docstring/注释不再写「不可能相反」。 Co-Authored-By: Claude Code <[email protected]>
Owner
Author
|
复审提的两条 P3 已在新 head
验证: |
|
🚀 Released in v3.54.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.
背景
#2418(已随
4da16d0bb合入)修复了 v3.53.0 把set-option remain-on-exit failed无条件链入new-session导致 tmux < 3.2 新会话全部建不起来的回归。合入后的代码评审发现三处遗留,本 PR 收口,均不改变 tmux ≥ 3.2 主机上的任何行为:applySessionOptions()对 reattach 会话回填remain-on-exit failed的版本门控(if (tmuxSupportsRemainOnExitFailed(version)))没有任何测试:把该门控改成无条件执行后,test/tmux-pipe-backend.test.ts全部用例在 vitest 与bun test下仍全绿。当前它在生产上无行为差异(该execSync位于自带 try/catch 内、是 try 块最后一条,旧版 tmux 的bad value: failed会被吞掉,终态与主动跳过相同),但声明的门控无守门,后续调整语句顺序或错误处理会静默回归。createDetachedSession)在版本缓存为 null 时会强制重探一次tmux -V,而 reattach 回填(applySessionOptions)用的是普通缓存 getter,两者不对称:升级前创建的老会话在一次瞬时探测失败后的短 TTL 内 reattach,会整个会话都不回填该选项(方向 fail-closed,不阻断,但可避免)。改动
src/setup/ensure-tmux.ts:新增resolveTmuxVersionAtSessionBoundary()——缓存命中直接用;缓存为近期失败结果(null,短 TTL 内)时绕过 TTL 强制重探恰好一次;重探仍读不到则保持 null,各调用点照旧 fail-closed。never throws。该保证只覆盖单次调用:不保证两个不同边界拿到同一答案(连续两次探测失败、第三次成功时,后一个边界可以做出与前一个不同的判定)。src/adapters/backend/tmux-pipe-backend.ts:createDetachedSession与applySessionOptions统一改用该边界解析(后者同时让 reattach 的window-size largest与remain-on-exit failed两个门控共享同一次解析);applySessionOptions(version?)接收调用方已付过的边界解析结果:创建路径把createDetachedSession的结果传入,一次会话创建只解析一次。否则方法末尾的重设会再触发一次边界解析,而 resolver 对任何 null(含 TTL 内)都强制重探,-V挂住(3s 超时)时一次会话创建最坏多等 3s。reattach 路径无前置解析,保持无参、在方法内解析一次;createDetachedSession边界解析为 null(new-session argv 因此不带; set-option remain-on-exit failed链),末尾applySessionOptions自己再解析一次且重探成功,会在会话已建后仍把该选项set-option上去——形成「链没发、选项却设了」的半分裂状态(argv 判定与 options 判定不一致)。传入同一值后 new-session 链与会话选项要么都设、要么都不设;显式传null不触发默认参数重探(JS 默认参数仅对undefined求值);resize()刻意保留缓存 getter(null TTL 本就是为频繁调用设计,不增加tmux -V调用)。src/worker.ts:启动自检改走同一边界解析,且整个解析位于一次性 guard 内部:成功解析预热随后建会话的进程缓存,tmux 永久不可读时也不会在每次spawnCli重复付探测成本。自检日志反映的是当时的边界判定:若自检重探也失败、而后续某次建会话重探成功,该会话仍会带链启用、熔断照常工作——相反结论的窗口从「必然出现」收窄为「连续两次探测失败、第三次成功」,并未被完全消除,注释与 docstring 均按此准确表述。test/tmux-pipe-backend.test.ts:reattach 门控双向用例(tmux 3.1c 不重设、tmux 3.3a 恰好重设一次;只写 3.1c 单向的话门控改成「永不重设」也绿,故两个方向都断言;reattach 不产生 new-session argv,断言走字符串命令的execSyncmock);reattach 边界 null 重探集成用例;create 路径探测次数用例(-V持续不可读时每次会话创建恰好 2 次探测:prime + 一次边界重探,改前实测 3 次)。test/tmux-functional-probe.test.ts:resolveTmuxVersionAtSessionBoundary3 条单测(已知缓存不重探、null 缓存重探一次并采用新结果、重探仍失败保持 null)。影响面
tmux -V(约 2ms,一次性),可能把本会误判为降级的会话纠正回正常启用;-V持续挂住时的创建路径最坏延迟相比未收窄前减少一次 3s 超时。测试验证
bunx tsc --noEmit:0 错;bun run build:通过。tmux-functional-probe+tmux-pipe-backend129/129;相关消费方 10 文件(pipe-backend-exit / pipe-exit-code / old-version-marker / reattach-backend / instance-identity / startup-tmux-gate / probe / indeterminate-probe-chain / cold-start / startup-storm-recovery)148/148;test-hygiene 26/26。bun test:functional-probe 25、pipe-backend 104、reattach-backend、cold-start、indeterminate-probe-chain、startup-tmux-gate、old-version-marker 全绿。bun test双引擎均复验):resolveTmuxVersionAtSessionBoundary去掉重探 → resolver 单测 + new-session 重探 e2e + reattach 重探 e2e 共 3 条双引擎红;applySessionOptions()无参)→ 探测次数用例双引擎红(实测 3 次 vs 期望 2 次);🤖 Generated with Claude Code