LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Feature]: 脚本/门禁节点失败时,UI 只显示 Run: exit status 1,真实失败原因没有进入节点错误

Open mmswukong opened this issue 1 week ago • 3 comments

Problem

背景 LoopForge 的 SOP 中大量使用 script 节点做门禁校验,例如「IP 需求分析 SOP」的:

requirement-gate draft-evidence-gate delivery-evidence-gate technical-evidence-gate evidence-gate

这些脚本失败时通常会把具体校验错误写到 stderr,并生成结构化 JSON 产物,例如:

{ "passed": false, "errors": [ "INVALID_CHALLENGE_EVIDENCE: DEL-05 / 缺有效路径或观察事实", "INVALID_CHALLENGE_EVIDENCE: DEL-11 / 缺有效路径或观察事实" ] } 但 Run 详情页的失败卡片只显示: Run: exit status 1

用户必须打开 Worker 日志,才能知道到底是哪条校验失败、应该怎么改。本次实际运行中,Agent 连续重写产物、门禁连续失败,最后 maxReworks 耗尽,Run 失败;页面上的“重试节点”又只是重复同一个确定性门禁,用户很难自行处理。

复现 环境:v0.4.0,Linux amd64,Go 1.26.11。

Run:run-1795259992989513731 SOP:ip-requirement-analysis(IP 需求分析 SOP) 节点:delivery-evidence-gate,attempt 4,执行 74 ms,exit status 1

实际页面显示:

节点已失败 步骤:交付质询证据门禁 失败信息 Run: exit status 1 但 Worker 日志中有:

INVALID_CHALLENGE_EVIDENCE: DEL-05 / 缺有效路径或观察事实 INVALID_CHALLENGE_EVIDENCE: DEL-11 / 缺有效路径或观察事实 节点产物 artifacts/delivery-evidence-gate.json 中也有完整的 errors 数组。

同一个问题在 requirement-gate 上也出现过:当时页面同样只显示 Run: exit status 1,而脚本实际输出是入口脚本退出 1。

image

Proposed behavior

根因

  1. 脚本输出和节点错误是两条独立的数据流 internal/engine/node_execute.go:641-657 中,脚本执行返回 (rawOutput, runErr): rawOutput, runErr := executeForTargets(current, node.ExecutionScope, func(target executionTarget) (string, error) { ... return sb.Exec(ctx, scriptSpec, targetSink) }) rawOutput 保存了脚本输出,runErr 只是进程退出错误。

但后续失败时:

internal/engine/node_execute.go:355-367 的 failNode 只接收 err internal/engine/node_outcome.go:58 执行: nr.Error = err.Error() rawOutput 没有合并进 nr.Error。

  1. Run 级脚本错误被统一包装成 Run: ... internal/engine/execution_scope.go:68-82:

func (t executionTarget) label() string { if t.Repository == nil { return "Run" } ... } internal/engine/execution_scope.go:143:

return result, fmt.Errorf("%s: %w", targets[0].label(), runErr) 所以 Run 级门禁的最终错误就是 Run: exit status 1;仓库级脚本则会显示成 ui_bear: exit status 1 这类前缀。

  1. loop-retro 也不能补救 internal/engine/observability.go:133-139 只使用 lastErr.Error():

if lastErr != nil { fmt.Fprintf(&b, "- 最终结果:未通过\n- 最后错误:%s\n\n", strings.ReplaceAll(lastErr.Error(), "\n", " ")) } 因此 loop-retro 里同样只有 Run: exit status 1,不会带上门禁的两条真实错误。

  1. UI 直接渲染 node.Error chatbot/src/RunAlerts.jsx:240-241:

<div className="run-alert-body"> <RunAlertReason text={item.reason} /> item.reason 来自节点错误,因此 UI 只能显示 Run: exit status 1。

这为什么是问题

  1. 失败信息缺失:用户看不到“哪条校验失败、哪个字段非法、应该改什么”,必须去翻 Worker 日志。
  2. 重试语义误导:脚本门禁失败时,如果输入产物没有变化,重试只会重复同一个确定性失败;页面却只给出“重试节点”,没有“修改上游产物后重跑”的提示。
  3. 返工预算耗尽时更严重:本次 challenge-delivery 已 rework 1 次,delivery-evidence-gate 的 maxReworks: 1 用尽,Run 直接失败;页面仍只显示一个无法解释的 exit status 1。
  4. 已有数据被浪费:引擎其实已经拿到了脚本输出(script.completed 遥测里记录了 输出 136 bytes),只是没有把它带到用户面前。

Scope

Platform — workflows / collaboration

Alternatives considered

修复建议 P0:脚本失败时把输出尾部合并进节点错误(最小改动) 在 internal/engine/node_execute.go 的脚本分支,rawOutput, runErr 之后加一层包装:

if runErr != nil { runErr = withScriptFailureDetail(runErr, rawOutput) } 建议 helper:

func withScriptFailureDetail(err error, output string) error { detail := strings.TrimSpace(output) if detail == "" { return err } const limit = 4 << 10 // 4KB if len(detail) > limit { detail = "…\n" + detail[len(detail)-limit:] } return fmt.Errorf("%w\n%s", err, detail) } 效果:

Run: exit status 1 INVALID_CHALLENGE_EVIDENCE: DEL-05 / 缺有效路径或观察事实 INVALID_CHALLENGE_EVIDENCE: DEL-11 / 缺有效路径或观察事实 要求:

输出必须脱敏(复用现有 redaction 能力) 限制长度(建议 4KB 或最后 20 行) 不要改变 node.Error 的字符串契约,避免破坏现有 API 客户端 增加测试:脚本 stderr 两行 + exit 1,断言 node.Error 包含两行且长度受限 P1:门禁结构化 errors 直接上浮 如果节点有类似 artifacts/.json / -gate.json 的产物,且内容为:

{"passed": false, "errors": ["..."]} 建议在失败时解析并写入新的可选字段,例如:

type NodeRun struct { ... FailureDetail string json:"failureDetail,omitempty" } FailureDetail 存结构化 errors 或脚本输出尾部 UI 优先展示 FailureDetail,再回退到 Error 该字段为可选,旧客户端不受影响 P2:修正证据门禁只校验第一段的问题 当前 delivery-evidence-gate 的 evidence_ok 只校验「证据」字段的第一段 目录/路径 — 观察;用 ; 连接的其余证据完全不校验。这导致:

Agent 写了完整证据,但第一段是目录(如 ui_bear/project/app/(auth))就失败 第一段是 .agentflow/inputs/...(不在绑定仓库目录)就失败 建议:

按 ; 拆分多条证据,逐条校验格式和路径 允许仓库内已跟踪目录:只要 git ls-files 中存在以 path/ 开头的文件即可 明确允许 .agentflow/inputs/** 作为上游证据,或在文档中明确“首段必须是仓库文件,上游证据放后面” 失败信息中回显当前非法值,方便 Agent 自修正 P3:UI 失败卡片和重试语义 失败卡片展示: 短原因(Run: exit status 1) 详细原因(FailureDetail 或脚本输出尾部) “Worker 日志”“loop-retro”“门禁 JSON”入口 对确定性门禁: 如果当前节点输入产物未变化,提示“输入未变化,重试会重复失败” 主按钮改为“修改上游产物后重跑”,或至少同时提供“重跑上游节点” chatbot/src/RunAlerts.jsx:305-315 的重试按钮可增加 reason / detail 区域,并区分 script、gate、agent 节点类型

Checks

  • [x] This proposal does not require organization-specific infrastructure or credentials.
  • [x] I searched existing issues and discussions for similar proposals.

mmswukong avatar Nov 21 '26 15:11 mmswukong

感谢反馈。我理解的诉求是:脚本或门禁节点失败时,页面上的失败信息只有「Run: exit status 1」,脚本输出和产物里的具体校验错误没有进入节点错误,排查时只能去看 Worker 日志。

已经看到这条 Issue,我们会按现有 Issue 的排期查看。

cocofhu00 avatar Nov 21 '26 15:11 cocofhu00

Implemented the script/command + gate path in #1203: a failed script node now stores its captured output (last 4 KiB, ANSI-stripped) in node.Error alongside the wrapped process error, so the run page, retry feedback, loop-retro and the UI failure card show the actual gate message instead of only Run: exit status 1. Tests cover a failing gate script whose stderr must appear in the node error and a 6 KiB noisy script whose error stays capped while keeping the tail.

One related gap worth tracking separately: agent-node CLI failures still surface as bare exit status 1 through a different path. Our real run-1795287172373072924 (SOP secops-delivery, node implement) failed exactly that way — the node error is just exit status 1, with no stderr, which matches the symptom here but not the script path. If a follow-up issue is welcome, I can file/reproduce it with that run.

linus-liu-web avatar Nov 22 '26 05:11 linus-liu-web

Same failure class on the Agent node path, with fresh evidence and a fix in #1206.

Our real secops-delivery run (run-1795287172373072924, node implement) failed with only exit status 1 in the UI. The Worker telemetry actually contained:

dsh: QUOTA: Insufficient Balance (request_id: 23ec223c-7096-4aab-ae54-ff5a2303de44)

So the operator could not tell "model account out of balance" from a crash without opening the Worker log.

#1206 fixes the Agent/CLI path: runCommand now keeps the last 4 KiB of stderr on the process error (ProcessError), and the Agent runner appends it to the node error, so the run page, retry feedback and loop retrospective show --- 执行器 stderr --- plus the real cause. It is complementary to #1203 (script/command nodes); script/gate handling is unchanged.

Validation: new runtime tests for stderr capture/bounding and Agent error decoration; full go test ./internal/engine passes; full go test ./internal/runtime passes except a pre-existing tempdir failure that also fails on unmodified main.

linus-liu-web avatar Nov 22 '26 06:11 linus-liu-web