Skip to content

[Bug] pi-subagents: Incorrectly reports "completed" when watchdog times out with only partial output (empty-reply termin | [Bug] pi-subagents:watchdog 超时且仅有部分输出时误报 completed(附空回复终态对照) #4359

Open

Description

@monater

问题与影响

本次在 Pi 中使用 acp_delegate 做小范围代码修改时,遇到多次无交付或超时。回看 .out、.activity、.session.jsonl 后,发现需要区分两个问题:

  1. 可由源码表达式复现的状态误判:异步子进程被 watchdog 终止、code === null,且只留下部分进度文字或 stderr 时,仍可能被标为 completed。这样主代理收到成功通知,却没有可验收的交付。
  2. 现有空回复提示无法区分不同上游终态:incomplete/error 与 completed/stop + content=[] 都被归入同一条“likely a thinking-only stop (thinking budget exhausted)”提示。本次保存的终态并不能证明 reasoning 预算耗尽。这里反馈的是诊断信息不足,不声称空回复一定由 billion-context 造成。

环境与验证范围

  • 实际故障环境:Windows 10 build 19045;Node.js v24.19.0;@earendil-works/pi-coding-agent 1.3.0;已安装 billion-context 0.1.202,使用 bundled Pi-native acp_delegate。
  • 子代理角色:worker;模型 ID:auto/gpt-6.1-sol,经自定义 OpenAI Responses 兼容网关;thinking level 涉及 high、medium、low。
  • 已检查本地 0.1.202 的 dist/agent/pi-native.js,存在下文相同的 effectiveExitCode 和状态赋值逻辑。
  • 另读取了发布标签 v0.1.204 的 pi-subagents/src/delegate-tool.ts,并在 Node 中提取其纯函数返回表达式及状态赋值表达式执行验证。没有在 v0.1.204 重跑完整委派,也没有为了复现发起新的付费模型请求。

会话中保存的终态对照

下表只记录终态与必要计数,不包含任务正文、业务配置、凭据或完整对话。不同记录不可直接推断为同一个根因。

记录 thinking session 中的关键事实 外层结果/现象
A:首轮失败 high content=[];stopReason="error";rawStopReason="incomplete";errorMessage="Response incomplete without a provider reason";该 assistant 的 output usage 为 1 子进程 exit 0,但没有最终回复;外层给通用 NO_FINAL_OUTPUT 提示
B:另一次首轮失败 high content=[];stopReason="stop";rawStopReason="completed";input usage 18928、output usage 0;无 errorMessage 同样 exit 0、同样通用 NO_FINAL_OUTPUT 提示
C:恢复运行 medium 新增轮次先读取文件,最后仍为 content=[]、stopReason="stop"、rawStopReason="completed";最后一轮 input usage 42798、output usage 0 exit 0,无最终交付,再次得到通用 NO_FINAL_OUTPUT 提示
D:外层任务超时 medium 外层 15 分钟;完成初步读取后嵌套调用 acp_delegate(async:false, timeoutMinutes:30, thinkingLevel:"high");.out 仅有准备开始工作的进度文字 watchdog 后为 SIGTERM;出现 completed 与 timed-out 信息并存的结果,不能据此验收任务
E:缩窄后的独立任务 low 有实际 edit、验证命令和最终 text;没有继续嵌套委派 正常交付,主代理随后独立复核通过

A 与 B/C 的上游终态不同;D 还有明确的内外层时间预算冲突;E 说明同一模型/环境也能成功。不能据这些样本断定统一根因,更不能断定调低 thinking 就能修复。

状态误判的代码路径

发布标签源码位置:

当前逻辑:

export function genuineNoOutput(code: number | null, timedOut: boolean, output: string): boolean {
  return !timedOut && code === 0 && output.trim().length === 0;
}

export function effectiveExitCode(code: number | null, output: string, stderr: string): number | null {
  return code ?? (output || stderr ? 0 : null);
}

const noOutput = genuineNoOutput(code, Boolean(run.timedOut), output);
const effectiveCode = effectiveExitCode(code, output, stderrText);
run.status = effectiveCode === 0 && !noOutput ? "completed" : "failed";

当 code=null、run.timedOut 已有值时,noOutput=false;只要 output 或 stderr 非空,effectiveCode=0,最后状态便是 completed。这里没有把“真正超时且未完成”与“agent 已完成、只是进程清理卡住”的情况分开。

无网络、无模型调用的最小复现

下面只复现上述纯分类逻辑;不是完整进程/watchdog 集成复现。代码体与源码一致(仅去掉 TypeScript 类型,可直接用 Node 执行):

const assert = require('node:assert/strict');

function genuineNoOutput(code, timedOut, output) {
  return !timedOut && code === 0 && output.trim().length === 0;
}
function effectiveExitCode(code, output, stderr) {
  return code ?? (output || stderr ? 0 : null);
}
function classify(code, timedOut, output, stderr) {
  const noOutput = genuineNoOutput(code, timedOut, output);
  const effectiveCode = effectiveExitCode(code, output, stderr);
  return effectiveCode === 0 && !noOutput ? 'completed' : 'failed';
}

const actual = [
  classify(null, true, 'I will inspect the files', ''),
  classify(null, true, '', 'warning'),
  classify(null, true, '', ''),
  classify(0, false, '', ''),
  classify(0, false, 'done', ''),
];
console.log(actual);
assert.deepEqual(actual, ['completed', 'completed', 'failed', 'failed', 'completed']);

实际输出:

[ 'completed', 'completed', 'failed', 'failed', 'completed' ]

前两项分别模拟真正超时后的部分进度文字、仅 stderr;在尚未成功完成 agent 的前提下,预期都应为失败/超时,而非成功完成。

空回复诊断问题

A/B/C 的外层提示均为:

child exited 0 but produced NO final reply text — likely a thinking-only stop (thinking budget exhausted) or a no-op termination. Treat the task as NOT delivered: inspect the activity log and session file, then re-dispatch if needed.

但是 A 的持久化 session 已给出 stopReason=error、rawStopReason=incomplete 和具体 errorMessage;B/C 则是 completed 空内容。空内容本身也无法证明 thinking-only:本次记录没有可见 thinking 块。建议在可获得的情况下直接携带最后一个 assistant 的 stopReason/rawStopReason/errorMessage、正文/思考块计数和 usage,并在缺失信息时明确标为 unknown。

这不是要求把所有错误归因于插件;网关、模型和 Pi 本身都可能需要继续排查。希望工具保留足够的原始诊断,避免主代理在预算耗尽、上游 incomplete、完成但空内容之间盲目重试。

官方使用说明与本次工作流因素

已阅读 pi-subagents/README.md:worker 拥有完整默认工具及已加载扩展;print/JSON 模式中的 async 会降为同步;delegate.maxDepth 默认 2、设为 1 可禁止嵌套。

因此 D 中 worker 继续委派并非工具违反现有文档。我们自己的任务拆分/提示也有改进空间:外层预算 15 分钟、内层 30 分钟不合理。希望文档或诊断能提示这种预算冲突;若实现允许,也可考虑将剩余 deadline 传递给子代。它应与上面的状态误报分开处理。

期望行为与回归验证建议

  1. 真正 watchdog timeout 且 agent 未成功完成时,不因部分进度文字或 stderr 非空而标成 completed;仍保留已有产物供人工检查。
  2. 保留已经完整交付、仅 teardown/EOF 卡住时的成功特例;不要简单地把所有 code=null/SIGTERM 都改为失败。可以结合 agentSettled、timedOut 和明确的成功/错误终态判断。
  3. 对 exit-0 空回复保留当前 loud failure 行为,同时将上游 error/incomplete 与 completed-empty 的诊断分开。
  4. 回归覆盖:正常成功、exit-0 空输出、error/incomplete 空输出、超时仅部分 text、超时仅 stderr、完全无输出超时、成功 agent_settled 后清理卡住;并检查 async 通知与 sync 返回的语义一致。

已查到 #2832 也涉及空内容的诊断,但那是 preflight 摘要路径;本报告针对 pi-subagents delegate 生命周期和主代理可见状态。若维护者希望拆分“状态误报”与“空回复诊断”两部分,可以分别跟进。

Activity

  1. changed the title [-][Bug] pi-subagents:watchdog 超时且仅有部分输出时误报 completed(附空回复终态对照)[/-] [+][Bug] pi-subagents: Incorrectly reports "completed" when watchdog times out with only partial output (empty-reply termin | [Bug] pi-subagents:watchdog 超时且仅有部分输出时误报 completed(附空回复终态对照)[/+] on Oct 23, 2026
  2. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    查重:不重复——按失败签名检索 open+closed issue/PR(watchdog timeout completed、acp_delegate timeout status、NO_FINAL_OUTPUT empty reply、genuineNoOutput/effectiveExitCode 等),无命中;最接近的 #2832(已关闭,preflight summary probe 路径,不同子系统)与 PR #3745(acp_delegate_wait 等待超时展示层,非执行状态判定)均不覆盖本问题。

    标签:bug pi scope/wiring p2 —— pi 车道委托生命周期缺陷,影响明确但有绕行(人工查结果文件/重新派发),未达核心停摆级别。

    修复已完成,PR:#4411

    结构化八问:

    1. 是什么问题:异步委托生命周期两处缺陷——① watchdog 超时杀掉未 settle 的子进程时,只要还有任何部分进度文本或 stderr,run 就被标成 completed,父 agent 收到成功通知却没有交付物;② exit-0 空回复只有一条泛化的「可能是 thinking-only stop」文案,无法区分上游 error/incomplete 与 completed-empty。
    2. 什么原因导致的:状态判定只有「有效退出码 + 输出非空」一个维度——effectiveExitCode 见到任何输出就把 null 强制成 0,于是「有部分输出」被当成了「完成证据」;诊断侧则完全没有捕获 message_end 的终态信息,只能靠固定文案猜可能原因。
    3. 影响范围与严重程度:凡命中 watchdog 超时/外部 kill/spawn 失败且恰好有进度文本或 stderr 的异步 acp_delegate run 都会误报成功(长任务 + 大窗口 + high thinking 下概率高);后果是父 agent 基于不存在的交付物继续决策(你主会话里「继续推进却没发现没拿到东西」即此)。有绕行:人工检查结果文件/活动日志后重新派发。
    4. 怎么修复的:新增纯函数 classifyDelegateOutcome——completed 要求有效退出码成功且有正向完成证据(真实非 null 退出码且无超时,或观察到 agent_settled);timeout + 未 settle 一律 FAILED,artifact 保留供检查。settled 例外保留(已交付但 teardown/EOF 挂起仍算 completed);agentSettled=false 时该规则与同步路径三元式逐行投影一致,async/sync 语义对齐。诊断侧捕获最后一条 assistant message_end 的 stopReason/rawStopReason/errorMessage + text/thinking 块计数 + 该轮 usage,失败正文、结果文件回填、warn 日志各追加一行 upstream terminal state: …;未观测字段渲染 unknown,print 模式渲染 unavailable。
    5. 是否有回归问题:逐项清点既有行为——正常成功(exit 0 + 输出)不变;exit-0 空输出仍是响亮失败(基础文案中性化 + 追加诊断行);settled 例外不变;同步路径不变;usage 聚合语义不变(terminal-only 事件不触发假零值)。唯一有意变更见下方披露,其余路径由矩阵测试 + 同步投影断言逐行钉住。
    6. 是否破坏缓存:不涉及(无缓存/重试/游标面)。
    7. 是否改了设计方向:没有——仍是同一生命周期结构,只是状态判定从「输出非空」升级为「需要完成证据」;诊断信息走既有事件 applier 通道。
    8. 是否引入新配置:无。

    行为变更披露(旧→新):agent 未 settle 时,watchdog kill / 外部 null-code 关闭 / spawn 错误且带有部分进度文本或 stderr 的情形,报告值由 completed 变为 failed ⚠️。原因:部分输出不等于交付,误报成功正是本 issue 修的缺陷;结果文件与活动日志不受影响,仍可人工检查。这是唯一语义变化。

    测试:11 行终态矩阵(含你给的两行误判 case)+ async/sync 一致性投影断言 + issue 中 A/B/C 三种 message_end 形状提取 + applier last-wins 捕获 + formatter 渲染;本地定向运行全部通过,src typecheck 干净,改动的三个测试文件 strict tsc 干净;全量判定以 CI 为准。pi-subagents 0.2.2 → 0.2.3。

    顺手小修(PR 内第二个独立标注 commit):发现 tests/delegate-tool.test.ts 存在 6 处既有 strict-tsc 错误(测试文件从不被 CI typecheck,所以一直不可见)——已直接在 PR 内修掉(一处参数类型放宽、4 个本地字面量补 usageReported、一处 execute 调用补齐参数),无需另立 issue。

    范围外(另行处理):内外预算冲突(case D)——README 已加提示:嵌套 sync delegate 自带 timeoutMinutes 超过外层剩余预算会被外层先杀;向子进程传递剩余 deadline 属独立变更,不在本 PR。

    判定:CI 绿即可合(合并请你操作)。

  3. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    状态更新:修复内容本身没有变化(分析与八问见楼上第 2 楼),这轮处理的是上一轮 CI 的两个红灯。

    红灯原因——分支基线过期,不是本 PR 的改动
    CI 的 pull_request 检查跑在「合并引用」上(本分支 + 触发时刻的 master)。我们分支切出之后,master 又合入了 kernel acp-kernel 0.0.15x→0.0.160 的一系列 lockfile 同步,导致 lock-sync 门对我们旧基线的 lockfile 重新生成后出现 diff;同时触发时刻的 master 自身带有几个子模块专用的未使用导出,这个在触发之后才由 master 提交 91eeecddb("un-export 4 child-only symbols")修掉——所以 unused-exports 也红了。两处红都是 master 侧当时树的问题,与本 PR diff 无关;同一提交的 11 个 e2e workflow 全部是绿的。

    本轮做了什么

    1. 把分支 rebase 到当前 master(50e250685),无冲突;
    2. lockfile 重新生成校验幂等、无 diff;unused-exports 门干净;
    3. 定向测试 162/162 通过(delegate-tool / delegate-no-output / delegate-event-applier / events 四个文件)+ typecheck 干净;
    4. 已推送,PR [PR] fix(pi-subagents): watchdog timeout no longer falsely reports completed; empty reply diagnostics include upstream termin | fix(pi-subagents): watchdog 超时不再误报 completed;空回复诊断带上游终态 #4411 新头 ce244912b + 057247302,与 master 可合并。

    当前状态:新一轮 CI 已触发,等结果。全绿后即可合(合并请你操作)。行为变更披露维持第 2 楼不变。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions