Repository navigation
fix(tmux): 避免 uutils cat 缓冲导致会话输入排队 - #2718
Merged
deepcoldy merged 3 commits intoNov 3, 2026
Merged
Conversation
lijason1121
requested review from
47seek,
LucasIcarus,
deepcoldy,
xiaoxueSunn and
xiongz-c
as code owners
November 3, 2026 04:42
dd 方案在 uutils 0.2–0.5 上同样会压住第二块之后的短写,换个 coreutils 工具只是把问题挪到另一批版本。实测(socketpair stdin → FIFO,与 tmux 一致): - cat:GNU、uutils 0.2–0.7 立即转发;uutils 0.8.0 全部压到 EOF(-u 无效) - dd bs=65536:GNU、uutils 0.6–0.8 立即转发;uutils 0.2–0.5 第 2 块起压住 改为 pipe-pane 命令内先看 `cat --version`:非 uutils 照旧 exec cat,行为与 内存占用不变;uutils 则用 botmux 自身运行时(node / bun / 编译版经 BUN_BE_BUN / Electron 经 ELECTRON_RUN_AS_NODE)执行 stdin→stdout 中继。 中继在沙箱外运行,按 program-status-relay 的做法 cd / 并清除 NODE_OPTIONS/BUN_OPTIONS,bun 加 --no-env-file --config=/dev/null。 另外转义 pipe-pane 参数里的 # 与 %:tmux 会按 format/strftime 展开该参数, 路径中含这两个字符时原先会被改写。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
busybox 的 cat 在 socket stdin + FIFO 输出下同样把短写攒到 EOF (实测 BusyBox v1.35.0:pipe-pane 子进程 stdin 为 socket,写入 0/400ms 的短块都在 stdin 关闭后才到达,真 tmux 8 次里约 7 次退订后才收到 OSC),但它的 --version 是 exit 1 且 banner 打在 stderr,原来的 case "$(cat --version </dev/null)" 在外层 2>/dev/null 下捕获空串、 落进 *) exec cat,Alpine/musl 主机上 ready/final 丢失、输入排队的 原 bug 原样保留。 改为在命令替换里加 2>&1,并把 *BusyBox* 与 *uutils* 一起纳入中继 分支;GNU/BSD cat 的 --version 串不含这两个关键字,行为与内存占用 不变。测试夹具增加 busybox 一腿(--version 拒绝 + banner 走 stderr + 攒包),真机矩阵 2x3 扩到 3x3;摘掉 2>&1 或 *BusyBox* 任一处, busybox 6 个用例咬红,双腿验证。 Co-Authored-By: Claude Code <[email protected]>
Owner
|
#2718 代修说明(maintainer side) 感谢这个修复——第一版 dd 在 uutils 0.2–0.5 也攒短写的发现很关键。双审确认新方案(运行时检测 + 自带中继)成立,同时发现并代补了一个覆盖缺口,已作为追加 commit 0ef9f83 以 fast-forward 方式推到本分支(未改动你的两个提交):
验证(新 head 0ef9f83)
这是自动评审的初步结论与代修,最终以维护者复审为准。 |
Owner
|
已合并,感谢 @lijason1121! 最终落地包含 3 个提交(你的两个提交 + 维护者代补的 busybox 覆盖):squash 为 0b5eaac,PR head 首跑 CI 全部通过(含 bun-test 与 linux/darwin/musl 三种编译二进制)。 特别有价值的一点:第一版 后续(不阻塞,无需你处理):
欢迎继续贡献。 |
|
🚀 Released in v3.57.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.
背景
tmux pipe-pane 后端用
cat > <fifo>把 pane 输出复制给 worker。在系统cat会缓冲短写的主机上,这个cat会把短写一直压到 EOF 才输出(uutils 加-u也无效)。CLI 明明已经输出完、回到了输入提示符,worker 却收不到 ready/final 字节,后续输入就一直排队。已确认两批这样的cat:cat把短写压到 EOF;而 uutils 0.2–0.5 的dd bs=65536也会压短写(第 2 块起),换一个 coreutils 工具只是把问题挪到另一批版本上,所以最终改用自带中继。fd0 -> socket:[…]),真机上就是坏的那一种。真 tmux 端到端 8 次里约 7 次要等取消订阅(EOF)才收到 OSC。实测矩阵
测法:socketpair 作 stdin、FIFO 作 stdout(与 tmux 的接法一致),依次写入 4 个短块,看每块是否在 0.6s 内送达。
cat-u无效)dd bs=65536改了什么
src/adapters/backend/tmux-pipe-relay.ts,生成 pipe-pane 的 shell 命令:cat --version 2>&1。uutils 或 BusyBox 之外(GNU、BSD/macOS、toybox 等)照旧exec cat,行为和内存占用都与改动前一致process.stdin.pipe(process.stdout)中继,不受 coreutils 版本影响。四种运行形态:node、bun、编译版二进制(BUN_BE_BUN=1)、Electron(ELECTRON_RUN_AS_NODE=1)--versionexit 1 且 banner 走 stderr,所以探测必须2>&1,否则 Alpine/musl 上会误判成普通 cat;其 banner 文本不随 locale 变化program-status-relay的做法加固:先cd /,unset NODE_OPTIONS BUN_OPTIONS,bun 加--no-env-file --config=/dev/null,tmux 环境和 pane 工作目录都没法往里注入代码cat一致:EOF(tmux 关闭 pipe)时退出;FIFO 读端消失后,写入触发 EPIPE 退出%Y被改成2026),路径里只要有#或%就会被改写。现在对#、%做了转义pipePaneCommand影响面
TmuxPipeBackend的 pipe-pane 复制命令,覆盖新建、恢复、adopt 会话以及所有 CLI;队列、适配器、持久状态与协议都没动cat --version 2>&1(毫秒级 fork+exec),之后照旧exec cat,字节流与内存占用不变cat约 1 MB)验证
test/tmux-pipe-streaming.test.ts的覆盖:NODE_OPTIONS/BUN_OPTIONS/工作目录bunfig.toml里的 preload 都不会执行TmuxPipeBackend(含旧版 tmux 的 if-shell dead-pane guard 形态):短 ready/OSC final、Unicode/控制序列、跨 64 KiB 读边界的大块及其短尾都能完整送达空格 # % $ " '时,直接pipe-pane和if-shell嵌套两种形式都能送达真实组件真值验证:真 tmux + 私有 socket 下,把 PATH 首位的 cat 换成真实 uutils 0.8.0 / 真实 BusyBox 1.35,修复形态均在几十毫秒内把不带换行的短写送达、第二块独立到达不合并、EOF 正常退出;standalone 编译二进制以
BUN_BE_BUN=1形态实测中继可用;HOME 级.bunfig.tomlpreload 也被--config=/dev/null挡住。变异复验(vitest 与 bun test 双腿):
exec cat)→ uutils 8 条失败2>&1→ busybox 6 条失败;去掉*BusyBox*→ busybox 6 条失败#/%转义 → 2 条失败unset NODE_OPTIONS BUN_OPTIONS→ 注入用例失败未覆盖:macOS 实机(BSD cat 立即转发,不受影响;darwin 编译二进制 CI 构建通过)、真实模型调用的端到端测试、完整单测套件(交由 CI)。另外,在 TMPDIR 很长的环境里,
tmux-old-version-marker/tmux-startup-storm-recovery会因 socket 路径超长失败;master 上也一样,与本改动无关,TMPDIR=/tmp下通过。🤖 Generated with Claude Code