LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Bug]: 脚本节点 shell 选项标注 "bash/sh" 却只用 sh(dash) 执行,报错被吞且返工循环无熔断,我自己用AI生成的 workflow 系统性失败

Open gpqd123 opened this issue 3 days ago • 1 comments

Component / host

Platform — runner / sandbox

Edition

Platform

LoopForge version

v0.4.3

What happened?

一个 workflow 的 verify 节点(Type=script,ScriptLanguage=shell),脚本里含set -euo pipefail,每次执行都确定性失败,并被另外两个缺陷放大成无法收敛的返工死循环。 1. 解释器不匹配(根因)。 runner 用 sh -lc 执行 shell 脚本节点 (internal/runner/daemon.go:801);无执行机时的本地路径同样是 sh -lc (internal/engine/node_execute.go:758)。默认隔离沙箱基础镜像是 node:22-bookworm(internal/runtime/sandbox_docker.go:1164),Debian 的 /bin/sh 是 dash。dash 不支持 set -o pipefail,脚本在 set 这一行就以退出码 2 终止,一个检查都没跑。每次失败完全一致:约 250–400 ms、39 字节输出(就是报错本身)。

2. UI 明确承诺了 bash。 脚本编辑器的语言选择器把 shell 选项标注为 "Shell (bash/sh)"(web/index.html:1330)。而且这个选择器不是单纯的高亮切换—— 保存时会把所选语言写回节点的 scriptLanguage 字段(web/app.js:1488-1490 → web/app/flows.js:1169-1171),该字段直接决定真实解释器(python → python3 -c, shell → 原样交给 sh)。也就是说,平台在"决定执行语言"的控件上承诺了 bash, 运行时却只给 sh(dash)——UI 契约与实现直接矛盾。

3. 脚本是 AI 生成的,不是手写。 set -euo pipefail 是 LLM 写 shell 脚本的 默认开场白。因此这不是"用户写了冷门 bash 语法"的边缘用例:任何 AI 生成的、带 shell verify 节点的 workflow 都会系统性踩中。平台用 dash 执行,而用户和 AI 自然生成 bash。

4. 失败反馈吞掉了真实报错。 脚本失败时 runner 只设 errMsg = err.Error() (internal/runner/exec.go:115 与 :418),对 ExitError 就只剩 exit status 2。 捕获到的 stderr(sh: 9: set: Illegal option -o pipefail)被流式写进 worker 日志, 却从不传给返工的 agent。agent 因此无法区分"环境失败"和"代码失败"。

5. 相同失败反复发生却没有熔断。 verify 失败不断路由回上游 agent 节点 (loop-retro/返工),即使已连续 3 次字节级相同的亚秒失败,即使 agent 已在产物里 明确上报:"若 verify 仍以同样的无命令退出码失败,则属 verify 节点自身的验证命令/ 执行器配置问题,需要人工查看该节点配置。" 平台在 2 秒后又让它返工了一轮。

影响: 一次 bug 修复 run,约 13 分钟就产出了正确且完整验证的修复,随后却烧掉 34+ 分钟(3 轮返工,手动停止时仍在循环)去对抗一个永远不可能通过的验证器。agent 在追查幻影失败的过程中还做了范围外的仓库改动。

期望行为:

  • shell 节点优先用 bash 执行(兑现 UI 的 "bash/sh" 承诺),无 bash 的镜像回退 sh; 或支持 shebang;而不是静默用 dash 处决 bash 脚本。
  • 脚本失败反馈带上捕获输出/stderr 的尾部。
  • 连续 N 次相同的脚本失败(尤其是亚秒、近乎零输出、显然没跑任何检查的失败) 应作为"验证器/基础设施错误"终止 run,而不是触发更多返工。

Reproduction

  1. 创建一个脚本节点(ScriptLanguage=shell),脚本内容为:
    set -euo pipefail
    echo ok
    
  2. 在默认 Docker 沙箱(node:22-bookworm 基础镜像)上运行。
  3. 观察:节点在 <1 秒内失败,报 sh: 1: set: Illegal option -o pipefail, 退出码 2;脚本里没有任何命令真正执行。
  4. 若该节点接成 verify 门禁并配置了返工/reject 到上游 agent 节点,agent 会无限返工, 且收到的反馈只有 exit status 2,没有命令、没有输出。

Sanitized diagnostics

worker 日志摘录(已移除凭证/端点),同一 run 连续三次 verify 尝试:


07:23:40  verify  stderr    sh: 9: set: Illegal option -o pipefail
07:23:40  verify  worker    执行器失败:exit status 2
07:23:40  verify  platform  Shell 脚本执行失败 · 262 ms · 输出 39 bytes
07:23:40  verify  platform  loop-retro

07:35:31  verify  stderr    sh: 9: set: Illegal option -o pipefail
07:35:31  verify  worker    执行器失败:exit status 2
07:35:31  verify  platform  Shell 脚本执行失败 · 241 ms · 输出 39 bytes
07:35:31  verify  platform  loop-retro

07:57:22  verify  stderr    sh: 9: set: Illegal option -o pipefail
07:57:22  verify  worker    执行器失败:exit status 2
07:57:22  verify  platform  Shell 脚本执行失败 · 384 ms · 输出 39 bytes
07:57:22  verify  platform  loop-retro


三次尝试之间,fix agent 重跑了 lint、逐文件全量测试套件(全部通过)、以及新鲜
clone 复核(全部通过),并在第 3 轮报告里写道:"若 verify 仍以同样的无命令退出码
失败,则属 verify 节点自身的验证命令/执行器配置问题,需要人工查看该节点配置。"
2 秒后下一次 verify 以完全相同的方式失败,又触发了一轮返工。

代码引用(main @ be6918d7):
- `web/index.html:1330` — 脚本编辑器语言选项标注 "Shell (bash/sh)"
- `web/app.js:1488-1490`、`web/app/flows.js:1169-1171` — 编辑器语言选择写回
  节点 `scriptLanguage`,决定真实解释器(非仅高亮)
- `internal/runner/daemon.go:801` — `Argv: []string{"sh", "-lc", task.Command}`
- `internal/engine/node_execute.go:758` — 本地路径同样 `sh -lc`
- `internal/runner/exec.go:115`、`:418` — `result.errMsg = err.Error()`;
  同文件已有输出尾部捕获(eventBatcher),但未拼进错误消息
- `internal/runtime/sandbox_docker.go:1164` — 默认基础镜像 `node:22-bookworm`(dash)

对照:平台自己的 CLI 安装器显式检查 bash 并用 `bash -o pipefail` 执行
(`internal/runtime/cli_ondemand.go:204`、`:231`),说明作者清楚 pipefail 需要 bash,
只是脚本节点从未得到同样处理。

Safety checks

  • [x] I removed credentials, private endpoints, internal identifiers, and personal data.
  • [x] I searched existing issues for duplicates.

gpqd123 avatar Nov 30 '26 08:11 gpqd123

Hi — I'm reproducing this now and preparing a fix; I'll open a PR shortly.

four1er avatar Nov 30 '26 08:11 four1er