Repository navigation
fix(worker): 启动命令确认执行后再写首条消息,CLI 未就绪时不写入 - #2073
Merged
Merged
Conversation
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 20, 2026 19:25
deepcoldy
force-pushed
the
fix/startup-command-first-prompt
branch
from
October 20, 2026 23:27
38afb5a to
72b5112
Compare
会话冷启动时,启动命令(如 /effort xhigh)和多行首条消息一起卡在 CLI 输入框里不提交, 期间状态卡一直显示「工作中」。根因是 CLI 还没开始读输入(负载高时 Claude 66s 无任何输出), worker 就按超时兜底写入:15s 忙碌探针把空白屏判为就绪,45s 就绪门的静置检查被零输出直接满足, 启动命令只等「PTY 安静 500ms」,257ms 后又写入首条消息。积压的字节被 Ink 一次读入当作粘贴, 回车变成换行,软换行的 `\` 原样保留,什么都没提交。 - 首写闸门:全新 spawn 的第一次写入要求 CLI 输入框已上屏(渲染器优先,节流读取后端权威视口); CLI 自己的直接 ready 信号放行,90s 首条提示硬上限照常放行;首条提示超时的忙碌探针也要求输入框可见 - 启动命令逐条确认执行:Claude 家族看 transcript 的 <command-name> 记录(新增 adapter 接口 commandExecutionProbe),其他 CLI 看回车后的 PTY 输出、安静与输入框;20s 未确认则暂存首条消息、 群里提示,确认到达后自动继续;期间直写的 passthrough 也排到后面 - Claude 的 SessionStart hook 未回报前不判「提交未确认」,避免首条记录晚写导致的误报 - 卡片:首条消息被启动闸门扣着时不推送状态(保持「启动中」);放弃确认时 user_notify 带 kind=input_not_submitted,daemon 按当前状态重画卡片,不依赖可能丢失的状态边沿 PATCH Co-Authored-By: Claude Opus 5.5 <[email protected]>
daemon 只要 worker 存在就会直发 raw_input,冷启动时 CLI 可能还没开始读输入, 透传命令(如 /model)同样会被积压成粘贴而不提交。全新 spawn 的首写尚未证明输入框 上屏、或启动命令仍在执行/待确认时,透传改为入队并由 flushPending 经首写闸门送达。 回归测试补充场景 C(冷启动 + 开场透传命令)。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
有 SessionStart 信号的 Claude 会话,提交未确认的告警只由 SessionStart 和 transcript 裁决: SessionStart 未回报前一律等待(最长 10 分钟),回报后留 10s 让首条记录落盘,再确认缺失才告警; PTY 活跃(pty-output / still_active)不再延后或压住告警,输入框里卡着的粘贴同样会重绘。 另设 40s 最短等待,不比原来更早告警。没有 SessionStart 信号的 CLI 行为不变。 误报样例:Claude 等 SessionStart hook 跑完才写首条记录,SessionStart 比 spawn 晚 3 分多钟, 5 次复查都因 PTY 活跃被压住,最后仍以 still_active 发出 submit_unconfirmed; 对照的真卡住会话也被 PTY 活跃压了 3 次警告。 回归测试补场景 D(记录被扣到 SessionStart 晚到,全程不告警)和 E(卡在输入框, SessionStart 前不告警、之后告警)。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
不再用依赖 TMUX_TMPDIR 的裸 tmux kill-server:TMUX_TMPDIR 指向的目录不存在时, tmux 会静默回落 /tmp,打到宿主的默认 server。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
force-pushed
the
fix/startup-command-first-prompt
branch
from
October 21, 2026 05:10
72b5112 to
dc4412e
Compare
Owner
Author
|
已合并(1f3e7927e)。合并后留两条 follow-up,均不阻断:
|
deepcoldy
added a commit
to yangkaiyu-web/botmux
that referenced
this pull request
Oct 21, 2026
This was referenced Oct 21, 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.
问题
会话冷启动时,bot 配置的启动命令和多行首条消息会一起卡在 CLI 输入框里,不提交。期间状态卡一直显示「工作中」,和实际状态对不上。
2026-10-20 的现场:Claude Code bot 配置了
startupCommands: ["/effort xhigh"]。worker 日志按时间顺序如下。/effort xhigh+ 回车。awaitPtyQuiescence(500ms)因为 PTY 一直没有输出而立即返回,日志记为「Startup command sent」\+ 回车软换行),后面还有 2 次补发回车Prompt detected),这才开始读输入根因:worker 在 CLI 还没开始读输入时就写入了。这些字节积在 tty 里,Ink 挂载后一次性读到,判为粘贴:所有回车变成换行,软换行用的
\原样保留,什么都没有提交。提交的 transcript 里能看到字面\+ 换行,可以佐证这一点。同一时段的另一个会话 CLI 已经在读输入,所以/effort照常执行,没有卡住。补全菜单吞回车的猜测与日志不符:同一条写入路径在另一个会话里执行正常。还有两个连带问题:
"role":"user","content":"会被启动命令自己的<command-name>记录命中。如果启动命令的记录在首条消息的基线之后才落盘,首条消息会被误判为「已提交」。改动
decideFirstWriteLiveness,所有带 readyPattern 的 CLI):每次全新 spawn 的第一次写入(启动命令或首条消息)之前,要求 CLI 的输入框已经上屏。判断先看渲染器;渲染器没有时,按 1s 节流读取 tmux 等后端的权威视口,覆盖「输入框在 pipe 接上之前就已画好」的情况。<command-name>/xxx</command-name>记录确认(新增 adapter 接口commandExecutionProbe,/clear换了 transcript 文件也能跟上)。这是确定信号,不再用屏幕兜底:回车被粘贴吞掉时,屏幕上也是「有回显、已安静、❯ 可见」,用屏幕判断会误放行。writeInput原有的回车重试会打在一个确实在读输入的 CLI 上。still_active)不再延后、也不再压住告警。卡在输入框里的粘贴同样会重绘:本次现场就被它压了 3 次警告。decideSessionStartGatedSubmitWarning。没有 SessionStart 信号的 CLI 行为不变。user_notify带上kind: 'input_not_submitted'。daemon 收到后用现有的scheduleActiveRuntimePatch按当前状态重画卡片,不依赖状态边沿,也不触发 ✅ 反应。原来唯一一次 working→idle 边沿的 PATCH 如果丢了,没有任何路径会再纠正。影响面
worker.ts的flushPending首写、runStartupCommands、首条提示超时探针、提交失败延迟复查、状态采样器;worker-pool.ts的user_notify处理;CliAdapter新增可选接口。其他 CLI 的启动命令
原实现是通用的:启动命令写完后只等 PTY 安静 500ms 就继续,CLI 没有输出时这个条件立即满足;随后的首条消息不再检查就绪状态。所以所有 PTY CLI 都有同样的问题,不只是 Claude。本 PR 的两道检查都放在通用层;没有确定信号的 CLI 用 PTY 证据兜底。本机 bots.json 里配置了启动命令的 7 个 bot 都是 Claude(
/effort),relay 的 transcript 同样会记录<command-name>。验证
bunx tsc --noEmit -p .:通过test/worker-claude-startup-command-first-prompt.integration.test.ts:真实 worker、tmux 后端、claude-code adapter,配合一个按 Ink 行为模拟的假 CLI(回车和其他字节同块到达时按粘贴处理)。/effort xhigh先提交、记录落盘之后才写首条消息,多行首条消息以真实换行提交,全程没有粘贴。input_not_submitted的提示;模拟用户在终端回车后,消息自动投递。/model opus开场(worker ready 后直接发 raw_input)。期望它等输入框出现后再以独立提交送达,不出现粘贴。-S <私有 socket> kill-server,不会回落到宿主的默认 server。session-lifecycle-hooks的新用例变红。decideFirstWriteLiveness、judgeStartupCommandAck、ClaudecommandExecutionProbe(只认基线之后、本命令的记录)、daemon 收到input_not_submitted后重画卡片(旧 turn 的提示不重画)、decideSessionStartGatedSubmitWarning(按两条现场时间线逐次复查)。tsc、bun run build通过;相关的 18 个测试文件(含 A–E 集成测试和后台任务卡片相关测试)共 419 个用例通过。bun run build:通过vitest run --project unit:本机 46 个文件失败。其中 26 个在未改动的 master 上同样失败,是本机环境问题,例如/tmp/package.json带"type":"module",导致放在/tmp下的假 CLI 被当作 ESM 加载。另外 20 个是全量并发下的 30s 超时,单独重跑全部通过(20 个文件、324 个用例)。以 CI 结果为准。🤖 Generated with Claude Code