Repository navigation
fix(pi): 会话换了工作目录后仍能采集到最终回复,采集不到时在群里告警 - #2081
Merged
Merged
Conversation
Pi 的 --session-id 只在当前 cwd 对应的会话目录里查找,找不到就在那里新建同 id 的会话文件。botmux 拼目录名的规则与 Pi 不一致(/root 拼成 --root 而不是 --root--),按 cwd 查找从未命中,总是退回全目录遍历,于是会话换目录冷恢复后 (例如 worktree 被删、退回 home),bridge 锁在旧目录里那份 Pi 再也不会写的 transcript 上,此后每一轮的回复都采集不到。 - 目录名按 Pi 的 getDefaultSessionDirPath 规则生成,兼顾软链接解析后的路径; 当前 cwd 目录里还没有文件时如实返回「没有」,由 late-attach 轮询在 Pi 建好 新文件后从头读取;全目录遍历只作兜底,且只接受会话头 cwd 与当前 cwd 一致的文件。 - 普通 IM 回合的 transcript 起点一直没出现、预启动租约到期被丢弃时,不再只打 一行 INFO:通过 user_notify 在话题里明确告知本轮回复采集不到。 - 回归测试覆盖 Pi 1.3.0 的 transcript 形态(v3 会话头、role:system 记录、 context_edit、回合边界标记)以及换目录冷恢复的端到端链路。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 20, 2026 23:42
- 普通写入路径抛错的回合(提交失败、ZMX 恢复持有、写入结果不明)已有各自的提示, 且字节可能根本没进 CLI;有提交失败复查在跑的回合也由复查负责通知。这两类回合的 预启动租约到期时不再追加「已经发给 X」的告警,避免两条互相矛盾的提示。 - 「哪些被剪掉的回合需要告警」抽成 uncollectedTurnsNeedingNotice,durable / 本地 / 已有提示三类排除各有测试;worker 的真实 prune 与通知函数经 harness 直接执行。 - 会话头按块读到第一个换行,上限对齐 Pi 的 1 MiB 扫描上限,超长首行不再让兜底 遍历把外来 cwd 的文件当成「未知」放行。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
已合并 → c3de2ac(squash)。合码时记录了两条不阻断的后续项,留作 follow-up:
未做:发版、部署。 |
deepcoldy
added a commit
to yangkaiyu-web/botmux
that referenced
this pull request
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.
现象
0 注入模式(
promptInjection: none)的 Pi 会话里,Pi 在终端写完了最终回复,卡片停在「等待输入」,群里只有状态卡、没有回复;日志里只有一行 INFOstructured ingest: expired 1 structured head(s) without transcript start,此外没有任何告警。根因(日志 + transcript 证据)
不是 Pi 1.3.0 改了 transcript 格式,而是 bridge 读错了文件:
--session-id只在当前 cwd 对应的会话目录里查找(main.js findLocalSessionByExactId → SessionManager.findById(cwd, …)),找不到就打印No project session found with id …; creating a new session with that id并在当前 cwd 目录新建同 id 的文件。/root,于是 Pi 在~/.pi/agent/sessions/--root--/下新建了<ts>_<sid>.jsonl,结论都写在这里。piSessionsDirForCwd拼目录名与 Pi 不一致(/root拼成--root,Pi 是--root--;/root/a/b拼成--root--a--b,Pi 是--root-a-b--),按 cwd 查找从未命中过,总是退回全目录遍历;而 spawn 时 Pi 的新文件还没建出来,遍历只找到旧 worktree 目录里那份旧文件 →baseline-existing到它的 EOF。Pi 之后再也不写那个文件,每一轮的 user 记录都看不到,20s 后 head 过期丢弃,最终回复无处可挂。证据:
Init … cwd=/root,Codex bridge baselined:指向--root-iserver-…-cd--/下的旧文件(offset = 旧文件大小,自 10-12 起未变),而--root--/下同 id 的新文件里,用户消息在提交后 0–1s 就已写入、最终回复与botmux-turn-settled(lastStopReason: stop)标记齐全。--root--),最早一例是 10-15,早于 10-20 升级 Pi 1.3.0 → 与 1.3.0 无关;daemon日志里历史上 39 次 head 过期也是这个形态。role:"system"带sections、context_edit)drain 时本就被忽略,不影响采集(已加测试钉住)。另一个会话属于另一条链:中途
stopReason:error(terminated)被 300s 兜底误判为失败、提前关掉了仍在运行的回合,真正的结论到达时已无回合可挂。这条由 #2075(「后续 assistant 记录清掉 held error」)修复,本 PR 不重复改;卡片停在「等待输入」是因为 Pi 1.3.0 的忙碌行⠴ Working未被识别,由 #2074 修复。改动
src/services/pi-transcript.tspiSessionDirName,逐字对齐 PigetDefaultSessionDirPath的编码;cwd 同时取resolve与realpath(Pi 用process.cwd(),软链接已解析)。findPiTranscriptBySessionId(sid, cwd):先只看 cwd 目录(与 Pi 自己的查找一致);cwd 目录里还没有时如实返回 undefined,worker 现有的 late-attach 轮询会在 Pi 建好新文件后以fresh-empty从 offset 0 读取,argv 里的首条提示也能正常归属;全目录遍历仅作兜底,且有 cwd 时只接受会话头cwd与当前 cwd 一致的文件(本机 1012 个会话头全部带cwd)。src/worker.ts+src/services/structured-uncollected-notice.ts:普通 IM 回合的 transcript 起点一直没出现、预启动租约到期被丢弃时,通过现有的user_notify在话题里告警(daemon 侧同时打 WARN、触发session.requires_attention钩子)。以下回合不告警,因为已有别的提示:structured_start_timeout/rpc_delivery_ambiguous_timeout终态;告警文案:
⚠️ 这条消息已经发给 Pi,但它的会话记录(transcript)里一直没出现这一轮,botmux 采集不到本轮回复,结论不会自动转发到群里。Pi 若已在终端里作答,请打开 Web 终端查看;确认没被处理再重发。影响面
CodexBridgeQueue的公共过期出口,作用于所有结构化 bridge CLI(codex / coco / grok / traex / cursor / omp / pi 等);按全舰队日志统计,过期事件 2 个多月内 Pi 以外的 CLI 合计十余次,且每次都意味着回复丢失,告警不会成为噪音。Claude 系走BridgeTurnQueue,不受影响。baseline-existing,行为不变);全新会话行为不变;adopt 走split-live不变。i18n1296 行附近)改的是不同区域,三者可独立合入、无冲突。fix(pi): 修复 Pi 1.3.0 忙碌误判空闲、工作目录被删后回退 home、升级后旧进程报错 #2074 让工作目录被删时不再退回 home,但用户通过恢复卡「换目录」或/cd后同样会换 cwd,本 PR 的定位修复仍然需要。测试
test/pi-transcript-locate.test.ts(新):目录编码与 Pi 一致;换 cwd 后在新文件出现前不返回旧文件、出现后返回新文件;同目录 resume 不变;软链接工作目录;兜底遍历只认 header cwd 一致的文件;Pi 1.3.0 完整回合形态(v3 会话头、system 记录、context_edit、被重试的 error、settle 标记)只产出一个 user + 一个 final;在文件出现前打的 Lark 回合能归属到 final。test/worker-pi-transcript-cwd-move.integration.test.ts(新):真 worker + 按 Pi 规则落盘的假 pi,复现「旧 cwd 有同 id 旧文件、新 cwd 冷恢复」→ 最终回复以final_output发出且旧文件未被改动;transcript 一直不出现这一轮 → 发出user_notify告警且没有final_output。test/structured-uncollected-notice.test.ts、test/worker-structured-uncollected-notice.test.ts(新):告警的排除规则;后者经 worker-function-harness 直接执行 worker 里真实的pruneExpiredStructuredHeadsAndEmit与通知函数,同时喂入普通 / durable / 本地 / 写入抛错 / 复查中五种回合,断言只有普通回合收到告警、durable 回合收到structured_start_timeout终态。不发版、不部署。
🤖 Generated with Claude Code