Repository navigation
fix(pi): 执行失败如实反映到卡片和群里,不再误报也不再停留 - #2075
Merged
Merged
Conversation
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 20, 2026 19:36
- pi-transcript:挂起的 error 记录在本轮出现任何后续 assistant 记录(含 toolUse)时即撤销。 原先只有 stop/length 或 turn-settled 标记才撤销,Pi 重试后继续干活超过 5 分钟,兜底计时器就把 这次已恢复的错误当成本轮失败:卡片切「执行失败」、群里发失败提示,还提前关掉了仍在运行的轮次, 之后 steer 进来的飞书消息 20 秒后被当成「未启动」丢弃,真正的失败反而无处归属、群里静默。 - 识别 Pi 取模型凭据失败(API key auth failed / Failed to resolve API key),给出专用错误码 pi_credential_unavailable 和「请求未发到模型、属暂态错误、直接重发即可」的提示。 - 「执行失败」之后有其它轮次正常完成(如在 Web 终端里直接输入「继续」),清掉失败标签并重刷卡片。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
错误恢复后 Pi 若在没写 turn-settled 标记的情况下被杀,这个读取器不会为该轮报失败, 与「还没出现任何 error 就被杀」的轮次相同:挂起的 error 只是单次请求失败的证据, 不承担进程存活探测。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
force-pushed
the
fix/pi-turn-failure-status
branch
from
October 20, 2026 23:10
cce3bee to
b502de2
Compare
This was referenced Oct 20, 2026
|
🚀 Released in v3.48.0 |
Owner
Author
|
已合并(squash → 4679296)。 合码前核对:评审结论 0 P1 / 0 P2;必需检查 build、test 与其余 CI 共 14 项全绿;与最新 master 合并无冲突,合并结果编译和相关测试通过;落地 diff 与审过的 diff patch-id 一致。 对老用户无 breakchange:配置项、默认值、命令、prompt 和持久化格式都没改,只修正了错误行为:
消息数只会减少,不会增加。 评审中提到的非阻断项留作后续跟进,均不影响当前行为:
|
This was referenced Oct 21, 2026
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.
背景
PR 评审群里 Pi 复审时,「执行失败」状态和群里的提示与实际情况对不上,两个方向都有:
API key auth failed for provider …: Failed to resolve API key … from shell command: …后本轮停下,卡片却显示「等待输入」,群里没有失败提示,发起方一直以为 Pi 还在审。对照现场 transcript 和 daemon 日志,查到三个原因:
stopReason:"error"只代表一次请求失败,Pi 会在同一轮里重试。读取器会先挂起这条 error,等 turn-settled 标记或 300 秒兜底再定论;但只有stop/length终态会撤销挂起,toolUse不会。于是 Pi 重试成功、继续跑工具超过 5 分钟后,兜底计时器把那次早已恢复的错误当成本轮失败:卡片切「执行失败」、群里发失败提示。expired 1 structured head(s) without transcript start)。之后真正的凭据失败无处归属:没有提示,卡片停在「等待输入」。凭据失败本身的成因:Pi(1.3.0)对 models.json 里
"apiKey": "!<command>"形式的 key,每次请求前都不缓存地重新执行该命令,超时硬编码为 10 秒(resolve-config-value.js)。机器负载高时命令超时,请求没有发出;Pi 把它当作 auth 错误,不重试。现场记录里durationMs是 10009,与此吻合。改了什么
services/pi-transcript.ts:本轮出现任何后续 assistant 记录(包括 toolUse)时,撤销挂起的 error。这说明 Pi 已经越过这次错误。300 秒兜底只覆盖「error 之后再无任何记录」的情形(Pi 重试中被杀、扩展没加载),与该常量原本的取值依据一致:错误到下一条记录的间隔,p95 为 90s,最大 166s。errorMessage命中API key auth failed或Failed to resolve API key时,错误码记为pi_credential_unavailable。这是 Pi 专用码,与codexRolloutFailureCode同理,不改共享分类。群里的失败提示改成专用文案(示意见下)。core/worker-pool.ts的turn_terminal:失败之后,若有另一轮以completed结束,就清掉失败标签,卡片空闲时立即重刷。终态按 transcript 顺序到达,失败之后完成的轮次一定更新,可以证明会话已经走出那次失败。判断全部基于 Pi 的 session JSONL(error 记录、turn-settled 标记、errorMessage),没有新增读屏逻辑。
失败提示文案(中文 locale,
{reason}是脱敏后的 errorMessage):卡片没有新增任何样式或标签,只是从「执行失败」恢复为已有的「等待输入」。
关于「凭据失败时自动重试一次」
评估后这次不做,只把提示做准确:
影响面
pi-transcript.ts只有 Pi 适配器使用(pi.ts的 bridgeSpec)。新错误码只影响 Pi 失败提示的文案选择。turn_terminal是所有 CLI 共用的路径,但改动只在「会话带着失败标签,且另一轮以 completed 结束」时生效。飞书消息入轮本来就会清这个标签,所以实际变化只在不经过入轮的轮次上:终端本地轮次、HTTP/异步触发、续跑。这些轮次完成后,卡片不再停在失败。验证
bun run build:通过(tsc 和构建审计)。bunx vitest run test/pi-transcript.test.ts test/pi-cot.test.ts test/structured-bridge-clis.test.ts test/turn-failure-card.test.ts test/failed-idle-card-recovery.test.ts test/async-terminal-settle.test.ts test/daemon-ordinary-ingress-failure-notice.test.ts test/bridge-final-output-retry.test.ts test/codex-bridge-queue.test.ts test/cli-adapters.test.ts:10 个文件,1025 passed,1 skipped。session-lifecycle-start、ordinary-turn-recovery、silent-turn-receipt、card-integration、restore-zombie-close、failed-turn-retry、card-handler-retry-turn等 9 个文件:609 passed。worker-pi-cot.integration、worker-argv-reaction-status.integration和新增的worker-pi-turn-failure.integration:全部通过。pi-transcript.test.ts新增 3 条:①错误后继续跑工具,兜底时限过三倍也不报失败(二次 drain 跨读);②恢复一次之后再真失败,只报后一次;③凭据失败的分类。failed-idle-card-recovery.test.ts:驱动真实 daemon IPC handler,覆盖本地轮次完成后清标签并重刷、仍在 working 时只清标签、失败或中断不清、同一失败轮次的终态不清。worker-pi-turn-failure.integration.test.ts:真 worker + 假 pi + 手写 transcript,验证凭据失败会发出turnFailed提示(专用文案),并在提示之后发failed终态。turn_terminal里的清除:2 条用例变红。pi_credential_unavailable。未覆盖 / 后续
⠴ Working,worker 会误判空闲(卡片显示「等待输入」)。这是现场「等待输入」的另一半原因,由 fix(pi): 修复 Pi 1.3.0 忙碌误判空闲、工作目录被删后回退 home、升级后旧进程报错 #2074 修复,本 PR 不重复。两者独立,合入顺序不限。🤖 Generated with Claude Code