Issue Description
前台 Bash 命令如果恰好在 timeout 边界退出,Qoder 会把它判定为超时并调用 taskkill。当 taskkill 因进程已经退出而返回 128/255 时,shell 结果 Promise 被 reject,但 ShellExecService 只在成功分支结算工具结果和停止 TaskOutput 轮询。结果是:
- shell 命令实际已经完成,输出文件也有内容;
- 但 agent 永远收不到 tool result;
- [TaskOutput] 轮询永久继续;
- 整个 turn 卡死,用户消息可能排队,只有重启 Qoder 才能恢复。
这不是模型、网络或机器休眠问题。
最小复现(3 秒即可,不需要等 120 秒)
在一个新会话中只执行一次 Bash:
command: sleep 3; echo REPRO_OK
timeout: 3000
run_in_background: false
预期:返回 timeout 错误(或带 timedOut=true 的输出),并停止轮询。
实际:Bash 工具没有任何返回,会话一直处于 running;输出文件里已经有 REPRO_OK。
Steps to Reproduce
必须同时满足:
- 前台 Bash,run_in_background=false;
- 设置了有限 timeout(默认 120000ms),且 autoBackground=false;
- 命令的进程完成点落在 timeout 边界附近(例如 sleep 的秒数等于 timeout 的秒数;任何在超时瞬间退出的前台命令都可能触发);
- Windows 上 taskkill /pid /f /t 失败,返回 128/255,常见原因是进程已经先退出;
- 失败后 c.result 被 reject,但没有进入 completeWithResult / stopPolling 的结算路径。
需要注意:
- 不是 120 秒专属;3 秒也能复现。
- 不是 sleep 专属;sleep 只是最容易把完成点压在 timeout 边界。
- 不是每次必现,是竞态。历史上很多 sleep 120 正常返回;但一旦 taskkill 失败,就会稳定卡死。
代码级根因
实现位于当前版本的:
app.asar.unpacked/node_modules/@qoder-ai/qoder-agent-sdk/dist/_worker/qoder-worker-runtime.obf.mjs
关键路径:
- sOn 的超时处理 #w() 在 autoBackground=false 时调用 #C(false) → #p()。
- #p() 在 Windows 上通过 c5e() 执行 taskkill /pid /f /t,超时 2 秒。
- 子进程在 taskkill 运行期间已经退出;taskkill 返回 128/255,#p() 判断 isLeaderExited 后仍然抛出 termination failed。
- sOn.#v() 在 exit 时等待 #E(杀进程 Promise);#E reject 后,c.result 被 reject。
- ShellExecService.executeImpl 里的结算链是:
c.result.then(async e => {
// …
if (o) {
// …
Xge.stopPolling(c.taskOutput.taskId);
// …
}
Er.completeWithResult(o, h);
return h;
});
这条链没有 rejection handler。返回给 agent 的 t.result(由 Er.attachExecution 创建)只能由成功分支里的 Er.completeWithResult 结算。因此 c.result 一旦 reject:
- t.result 永远 pending;
- Xge.stopPolling 永远不会执行;
- agent turn 永远等待;
- TaskOutput 的全局 setInterval 继续轮询。
日志里的 unhandledRejection 就是这条 rejection 没有被处理的直接证据。
Expected Behavior
返回 timeout 错误(或带 timedOut=true 的输出),并停止轮询。
Actual Behavior
Bash 工具没有任何返回,会话一直处于 running;输出文件里已经有 REPRO_OK。
Screenshots / Screen Recordings
对应日志:
2026-10-29T16:00:16.528+08:00 WARN [ShellCommand] pid=16176 timed out after 3s, autoBackground=false
2026-10-29T16:00:16.529+08:00 DEBUG [ShellCommand] pid=16176 kill requested, status=running
2026-10-29T16:00:16.529+08:00 DEBUG [ProcessUtils] killProcessGroup: pid=16176, escalate=true, isWindows=true
2026-10-29T16:00:16.645+08:00 DEBUG [ShellCommand] pid=16176 exited: code=0, signal=none, timedOut=true, status=completed
2026-10-29T16:00:16.749+08:00 WARN [ProcessUtils] taskkill failed: pid=16176, timeoutMs=2000, error=Error: Command failed with exit code 128
2026-10-29T16:00:16.749+08:00 WARN [ShellCommand] pid=16176 termination failed: Error: Failed to terminate process tree pid=16176
2026-10-29T16:00:16.750+08:00 ERROR [unhandledRejection] Failed to terminate process tree pid=16176
2026-10-29T16:00:16.751+08:00 ERROR [unhandledRejection] Failed to terminate process tree pid=16176
停止该会话后,它的轮询条目仍未清除:
2026-10-29T16:01:52.616+08:00 DEBUG [TaskOutput] tick #1840, activePolling=2, tasks=[b46jk815a,b1cl6u0qo]
两次真实事故
时间:2026-10-29 01:45:36
taskId:b8pxia512
命令:sleep 120; cat …
timeout 触发:01:47:36.577
taskkill:exit 128
后续:轮询 4232 次,直到 13:36:42;无 tool result;13:36:54 重启后恢复
时间:2026-10-29 13:43:56
taskId:b8mxzb17k
命令:sleep 120; cat …
timeout 触发:13:45:56.550
taskkill:exit 255
后续:轮询 530 次,直到 15:12:59;无 tool result;15:14:43 重启后恢复
关键日志(第二次):
2026-10-29T13:45:56.550+08:00 WARN [ShellCommand] pid=28732 timed out after 120s, autoBackground=false
2026-10-29T13:45:56.550+08:00 DEBUG [ShellCommand] pid=28732 kill requested, status=running
2026-10-29T13:45:56.551+08:00 DEBUG [ProcessUtils] killProcessGroup: pid=28732, escalate=true, isWindows=true
2026-10-29T13:45:56.725+08:00 WARN [Shell] execution failed: taskId=b8mxzb17k, pid=28732, code=1
2026-10-29T13:45:56.725+08:00 DEBUG [ShellCommand] pid=28732 exited: code=1, signal=none, timedOut=true, status=completed
2026-10-29T13:45:56.726+08:00 WARN [ProcessUtils] taskkill failed: pid=28732, timeoutMs=2000, error=Error: Command failed with exit code 255
2026-10-29T13:45:56.727+08:00 WARN [ShellCommand] pid=28732 termination attempt failed, attempt=1/2
2026-10-29T13:45:56.727+08:00 WARN [ShellCommand] pid=28732 termination retry skipped: original child exited
2026-10-29T13:45:56.727+08:00 WARN [ShellCommand] pid=28732 termination failed
2026-10-29T13:45:56.727+08:00 ERROR [unhandledRejection] Failed to terminate process tree pid=28732
2026-10-29T13:45:56.728+08:00 ERROR [unhandledRejection] Failed to terminate process tree pid=28732
2026-10-29T15:12:59.820+08:00 DEBUG [TaskOutput] tick #5660, activePolling=1, tasks=[b8mxzb17k]
第一次事故同样有 termination failed 和两次 unhandledRejection,轮询一直持续到 13:36:42;全量日志中没有出现这两个 task 的 stopPolling 记录。
Operating System
-Windows 10.0.26300 x64;Git Bash:C:\Program Files\Git\bin\bash.exe;时区 +08:00
Current Qoder Version (Menu → About Qoder → Copy)
- Qoder Desktop 0.4.11 stable,build 82443378,构建时间 2026-10-23,commit d9996760e3d4f61dedf1589a76f87d7001618ebf
- Agent/runtime:1.1.75-hotfix.1
- Bash 工具:前台执行,timeout=120000ms(默认),stdoutToFile=true,autoBackground=false