Skip to content

fix: AI 分支命名只提供已配置的 CLI;执行器失败时 Agent 循环文案准确 - #1470

Open
Robert0622 wants to merge 4 commits into
Tencent:mainfrom
Robert0622:fix/sweep-0200-branch-naming-cli
Open

Robert0622 wants to merge 4 commits into
Tencent:mainfrom
Robert0622:fix/sweep-0200-branch-naming-cli

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

本次全量走查基于最新 main(be6918d7,v0.4.3)。我在本地起了真实环境:MySQL、agentflow 服务、Web 和 Chatbot。然后在私有测试仓库上用真实模型跑了完整 LOOP:OpenCode / Pi / dsh 用 DeepSeek flash,Cursor 用 grok,CodeBuddy 用 deepseek flash。过程包括派发需求、AI 分支命名、审批、返工、重试和合并请求,并用 Playwright 点遍各页面的按钮。共确认并修复 2 个产品问题,另外修了 1 处过期的测试桩。

问题 A:仓库抽屉的「AI 生成工作分支」CLI 下拉列出了未配置的 CLI,保存后每次派发都失败

现象

  • 「项目配置 → 仓库 → 工作分支命名 → AI 生成」的 CLI 下拉列出了全部执行器类型,包括当前用户没有配置的 Codex、Claude Code、Antigravity、Kimi、ZCode。
  • 选 Codex 保存,界面提示「仓库已保存」。
  • 之后派发需求一律 400:仓库…的工作分支生成失败:请配置 LOOP 负责人的模型凭据或执行机器登录。
  • 用户在保存时没有任何提示,要等到派发失败才会发现,而且项目里所有需求都派不出去。

根因

  • AI 分支命名用派发人自己的凭据执行,和角色节点一样。
  • 角色编辑器自 fix: only offer configured executors in model pickers #1291 起只提供 executorConfigured() 为真的 CLI,但 web/app/repo_drawer.js 的分支命名下拉漏了这一步:它直接列出 state.data.executors 里所有带 kind 的执行器,保存时也不校验。

复现

  1. 只配置 CodeBuddy、OpenCode、Cursor、Pi、dsh 的凭据。
  2. 打开仓库抽屉,命名方式选「AI 生成」,展开 CLI 下拉。
  3. 选 Codex,保存成功。
  4. 在需求列表点「派发」,返回 400。
下拉列出未配置 CLI Codex 可直接保存 派发失败

修复(web/app/repo_drawer.js)

  • 新增 fillRepoBranchExecutors(),复用角色编辑器的 executorConfigured(),下拉只列已配置的 CLI。
  • 执行器配置还在加载时,显示「检查配置中…」,加载完成后重新渲染。
  • 已保存但当前用户未配置的 CLI 保留为禁用项,显示「xxx(未配置)」。这样修改仓库的其他字段时,不会悄悄改掉已存的设置,也不会因为下拉里没有这一项而丢值。
  • 保存时,如果 CLI 被改成了未配置的执行器,拦截并提示「请选用已配置的 CLI」,不发 PUT 请求。

影响和风险

  • 只改了仓库抽屉的前端选项和校验,后端接口和已存数据都不变。
  • 已经存了未配置 CLI 的仓库仍能正常编辑其他字段。

修复后

  • 下拉只剩已配置的 5 个 CLI。
  • 已存的 Codex 显示为禁用的「Codex(未配置)」,修改默认分支后保存,该值保留。
  • 切到 CodeBuddy 保存后,真实派发生成了 AI 分支 tl/1795718493368256911-readme-json,后续 LOOP 跑通并提交了 PR。
只列已配置 CLI 已存未配置项禁用保留 切换到已配置 CLI 后派发成功

问题 B:开启自修正的角色执行器失败时,轨迹文案错误

现象

  • 角色开启了 Agent 循环(maxIterations=3,耗尽后转人工),执行器本身失败(比如模型名无效,exit status 1)。
  • 第 1 轮后,轨迹显示:
    • 门禁失败策略为 ,跳过自修正(策略为空)
    • Agent 自修正次数已耗尽,转人工判断
  • 实际只跑了 1 轮,并没有进入自修正,排查时会误以为门禁配置有问题或 3 次都失败了。

根因

  • internal/engine/node_execute.go 中,执行器失败时 failedAction 为空,跳过消息直接拼接空串。
  • 耗尽事件固定使用「次数已耗尽」文案,没有区分「执行失败直接转人工」和「迭代用尽」两种情况。

复现

  1. 建 LOOP tl-broken-loop:角色使用 dsh,模型设为 deepseek-no-such-model,loop maxIterations=3,onExhausted=human。
  2. 派发需求。
  3. 查看运行轨迹和活动。
修复前轨迹 修复前活动

修复

  • 新增 agentLoopSkipMessage(failedAction):
    • 策略为空(执行失败,不是门禁未通过)时,显示「本轮执行失败(不是门禁未通过),不进入自修正」。
    • 否则保留原文案。
  • 新增 agentLoopHumanMessage(iterations, max):
    • 未用尽迭代时,显示「Agent 第 N 轮执行失败,未进入自修正,转人工判断:…」。
    • 用尽时保留「Agent 自修正次数已耗尽,转人工判断:…」。
  • 事件类型和控制流都不变,只改了文案。

修复后:事件为 Agent 第 1 轮执行失败,未进入自修正,转人工判断:exit status 1 和 本轮执行失败(不是门禁未通过),不进入自修正。

修复后轨迹 修复后活动

C:e2e 单测桩过期

e2e/unit/flow-designer.test.mjs 的上下文桩缺少 workflowVersionLabel(sops.js 已有该函数),导致 renderSwitcher 抛出 TypeError,main 上 e2e unit 有 1 项失败。已按 sops.js 的实现补上这个桩。

测试

新增测试

  • webtest/tests/projects-repos.test.mjs:「AI branch naming offers only CLIs configured for the user」,覆盖以下几点:
    • 下拉只列已配置 CLI;
    • 强行选未配置 CLI 时被拦截,且不发 PUT;
    • 已存的未配置 CLI 显示为禁用,修改其他字段后保存时保留。
    • 修复前该测试失败,修复后通过。
  • internal/engine/core_cases_test.go:TestAgentLoopMessagesDescribeExecutorFailures。

回归结果(修复分支)

  • webtest:387/387 通过
  • chatbot(vitest):535/535 通过
  • e2e unit:24/24 通过(main 上为 23/24)
  • e2e API(真实服务和 MySQL):172 通过,15 跳过(均为环境不支持嵌套 Docker 的已标注用例)
    • runner-mode 4 项最初失败,原因是测试环境的 /tmp 为 noexec,加上残留了 runner 偏好;修正环境后 4/4 通过,与本 PR 无关。
  • go vet ./...:通过
  • go test ./...:main 与修复分支的失败集合完全相同,都是 15 个依赖 Docker、Chromium 或 systemd 的环境用例,本 PR 没有引入新的失败。
  • 真实场景:私有仓库上用 5 种执行器跑完需求,开出 4 个 PR,分支测试全部通过;UI 返工意见被执行器正确采纳。

🤖 Generated with Claude Code

roberttwang and others added 3 commits November 26, 2026 19:11
The repository drawer's AI branch-naming picker listed every built-in CLI,
including ones the user has no credentials or runner login for. Saving such a
CLI succeeded, and from then on every LOOP start in the project failed with
"工作分支生成失败:请配置 LOOP 负责人的模型凭据或执行机器登录", because the
branch name is generated with the dispatching user's credentials, exactly as
role nodes run.

Use the role editor's rule (executorConfigured, Tencent#1291): offer configured CLIs
only, keep a stored CLI that is not configured for the current editor visible
but disabled so editing other repository fields preserves it, and refuse to
save a newly chosen CLI that is not configured.

Co-Authored-By: Claude Code <noreply@anthropic.com>
When an executor exits with an error on a role with a self-correction loop,
no gate decided the failure, so the trace read "门禁失败策略为 ,跳过自修正"
(an empty policy) and the hand-off event said "Agent 自修正次数已耗尽" although
only one iteration ran. Name the executor failure instead, and claim the loop
budget is spent only when every iteration ran. Behaviour is unchanged.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Since Tencent#1320 the LOOP switcher in flow-palette.js calls workflowVersionLabel
from sops.js, which the harness does not load, so `e2e/run.sh unit` failed on
main with a ReferenceError.

Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
crispinhu27 previously approved these changes Nov 26, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初审 d8f6bd4d:APPROVE

审查范围(5 个文件,+131/−11):internal/engine/node_execute.go、internal/engine/core_cases_test.go、web/app/repo_drawer.js、webtest/tests/projects-repos.test.mjs、e2e/unit/flow-designer.test.mjs,并结合角色编辑器 executorConfigured() 的既有约定(#1291)理解调用链。

逐项核验

  1. Agent 循环文案(问题 B):agentLoopSkipMessage("") 正确区分执行失败(非门禁)与门禁策略为空的场景;agentLoopHumanMessage(lastIteration, maxIterations) 在 iterations < maxIterations 时输出「第 N 轮执行失败,未进入自修正」,仅在真正用尽时保留「次数已耗尽」。调用点传参正确:lastIteration 初始化为 0、循环至少跑一轮后被赋值,exhausted 路径取 lastIteration。事件类型和控制流未变。TestAgentLoopMessagesDescribeExecutorFailures 四个断言覆盖全部分支。
  2. AI 分支命名 CLI 下拉(问题 A):fillRepoBranchExecutors 复用 executorConfigured(),只列已配置 CLI;已存未配置项显示为禁用 Option 保留;保存时通过 repoDrawerState.branchExecutorId 比对拦截未配置选择(不发 PUT);执行器配置加载中显示「检查配置中…」并在 executorModelCatalogRequest 完成后重渲染。新增 webtest 覆盖三个场景(过滤、拦截、保留),与角色编辑器行为一致。
  3. e2e 桩:workflowVersionLabel 与 sops.js 实现一致,修复 main 上 1 项 unit 失败。

验证依据

  • CI core 16 项检查全部通过(含 Non-browser Go tests、Real-browser Go tests、Coverage gate、Browser-free UI tests)。
  • 审查版本:head d8f6bd4d(base main be6918d7)。未发现本 PR 引入或加重的问题,不构成阻塞。

🤖 Generated with Claude Code

@Robert0622

Copy link
Copy Markdown
Collaborator Author

本轮 CR 结论:LGTM,可以合入

head: d8f6bd4d,CI 16/16 ✅,mergeable=CLEAN,crispinhu27 已 Approve。

代码审查

5 个文件(+131/−11),改动干净,分三块:

  1. web/app/repo_drawer.js — 新增 fillRepoBranchExecutors(),AI 分支命名下拉只列 executorConfigured() 返回 true 的 CLI;已存但当前用户未配置的 CLI 保留为禁用项(Codex(未配置));保存时拦截未配置的新选择。逻辑与角色编辑器完全对称,行为正确。

  2. internal/engine/node_execute.go — 把两处硬编码字符串拆成 agentLoopSkipMessage() 和 agentLoopHumanMessage(),消除了执行器失败时出现空门禁策略的问题。两个函数各自边界清晰,逻辑无误。

  3. e2e/unit/flow-designer.test.mjs — 补 workflowVersionLabel 桩,修复 main 上已有的 e2e unit 失败,属于顺手修复,无风险。

部署实测

在本机(MariaDB + d8f6bd4d 二进制):

  • 仓库抽屉 AI 分支命名 CLI 过滤:PUT /api/executor-models 返回结构、fillRepoBranchExecutors() 渲染路径经 webtest 覆盖(见下)。
  • Agent 循环文案:agentLoopSkipMessage() → 「本轮执行失败(不是门禁未通过),不进入自修正」;agentLoopSkipMessage("human") → 原有格式;agentLoopHumanMessage(1,3) → 「第 1 轮执行失败,未进入自修正」;agentLoopHumanMessage(3,3) → 「次数已耗尽」。四个边界均正确。
  • Go 测试:TestAgentLoopMessagesDescribeExecutorFailures、TestOpenSandboxBackendBinding 通过;go vet ./...(排除 web/embed.go 的 native-chat 目录缺失,属于 dev-only 资产不影响逻辑)通过。
  • webtest:tests/assets-agents.test.mjs、tests/projects-repos.test.mjs(含新增的「AI branch naming offers only CLIs configured for the user」)16/16 通过。

#1469 / #1470 交叉改动

两个 PR 都改了 internal/engine/node_execute.go,位置不重叠:#1470 改 1129/1183/1400 行(文案),#1469 改 441 行(WMA/A2A 分支入口)和其他文件。后合入的一方解这一处即可,合并本身无冲突。

没有发现问题,不需要改代码。

…ile the branch-naming CLI list loads

- agentLoopHumanMessage now distinguishes an executor failure from a gate
  (or submit_gate_result) failure whose policy is not "loop", matching
  agentLoopSkipMessage, instead of calling both "执行失败".
- The repository drawer repaints the AI branch-naming CLI picker as soon as
  the executor catalog request starts, so a saved configured CLI shows
  "(检查配置中)" rather than "(未配置)", and a prefix repo switched to AI
  shows "检查配置中…" rather than "无可用 CLI" until the catalog returns.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

04:00 轮 CR + 部署实测:原修复有效;补了 2 处小问题,新 head dc5a90a2

基准:PR 原 head d8f6bd4d、修复后 head dc5a90a2,对照 main be6918d7。部署环境:MySQL 8.4.9 + native 沙箱,私有测试库 Robert0622/loopforge-cr1470-1127,CodeBuddy deepseek-v4.1-flash(CLI 前加了模型白名单,只放行 flash)。评审 token 是 PR 作者本人,GitHub 不允许作者 Approve,所以只发评论。

新提交 dc5a90a2 改了什么

  1. 提前转人工时,门禁失败被说成「执行失败」(internal/engine/node_execute.go)
    • 复现:角色开 Agent 循环(maxIterations=3,onExhausted=human),门禁 onFailure=fail,或者 Agent 用 submit_gate_result 提交 fail。第 1 轮失败后,轨迹显示「门禁失败策略为 fail,跳过自修正」,但运行事件显示「Agent 第 1 轮执行失败,未进入自修正」,两条说法对不上。
    • 修复:agentLoopHumanMessage 增加 failedAction 参数。执行器本身失败时,仍显示「第 N 轮执行失败」;门禁失败或 Agent 提交 fail 时,显示「第 N 轮门禁未通过(失败策略为 X)」,与 agentLoopSkipMessage 的说法一致。迭代用尽时,仍显示「自修正次数已耗尽」。
  2. 执行器配置还没加载完,就把已配置的 CLI 标成「未配置」(web/app/repo_drawer.js)
    • 复现:刷新页面后第一次打开仓库抽屉。执行器配置要约 2 秒才返回,这段时间里,已存的 CodeBuddy 显示为禁用的「CodeBuddy(未配置)」。前缀模式的仓库切到「AI 生成」时,下拉显示「无可用 CLI,请先在个人配置中配置」。等请求返回才恢复正常。
    • 修复:syncRepoBranchNaming 一发起执行器配置请求就立即重画下拉,加载期间显示「(检查配置中)」和「检查配置中…」。这和 executorConfigured()(请求进行中视为未知)以及保存时的拦截文案保持一致。
    • 新增单测「AI branch naming says the CLI list is loading instead of not configured」。把 repo_drawer.js 换回 d8f6bd4d 的版本,这个用例失败(实际 CodeBuddy(未配置),预期 (检查配置中));用修复后的版本,用例通过。

部署实测(同一套场景,修复后版本 / main 对照)

# 场景 main be6918d7 PR dc5a90a2
A1 前缀仓库切「AI 生成」,看 CLI 下拉(只配了 CodeBuddy) 列出全部 10 个 CLI 只有「选择 CLI / CodeBuddy」 ✅
A1b 选未配置的 Codex 保存 「仓库已保存」,存成 codex 下拉里没有 Codex,选不到 ✅
A2 仓库已存 codex(未配置),只改提示词后保存 — 显示禁用的「Codex(未配置)」,值仍为 codex;保存后 executorId=codex 保留,prompt 已更新 ✅
A3 往下拉里注入未配置的 claude 再保存 保存成功(存成 claude) toast「请选用已配置的 CLI」,没有发出 PUT,已存的值不变 ✅
A4 改选 CodeBuddy + deepseek-v4.1-flash 保存 — 「仓库已保存」,存成 codebuddy / deepseek-v4.1-flash ✅
A5 executor-models 人为延迟 6 秒 — 加载中显示「CodeBuddy(检查配置中)」,返回后恢复成可选的 CodeBuddy,选中值不丢 ✅(d8f6bd4d 这里显示的是「(未配置)」)
A6 改回前缀模式 feature/ 保存 — 「仓库已保存」,不受 CLI 校验影响 ✅
A7 派发需求(仓库 AI 命名) 已存未配置的 claude:400「工作分支生成失败:请配置 LOOP 负责人的模型凭据…」 CodeBuddy flash 真实生成分支 readme-json-output-1,派发 201 ✅
B1 Agent 循环 3 轮/耗尽转人工,执行器失败(无效模型,exit 3) 「门禁失败策略为 ,跳过自修正」+「自修正次数已耗尽」 「本轮执行失败(不是门禁未通过),不进入自修正」+「Agent 第 1 轮执行失败,未进入自修正,转人工判断」 ✅
B2 同上,门禁/Agent 提交 fail 「自修正次数已耗尽」 修复后为「Agent 第 1 轮门禁未通过(失败策略为 fail),未进入自修正」 ✅(d8f6bd4d 显示的是「执行失败」)
B3 门禁 onFailure=loop,真实跑自修正 — 「第 1 轮未通过,进入自修正」,第 2 轮由 Agent 请求人工确认,进入 waiting_approval ✅,走的是原有路径

测试

  • webtest:388/388 通过(含新增用例);e2e/unit/flow-designer.test.mjs 13/13 通过;go test ./web/ ok。
  • go vet ./internal/engine/ clean;go test ./internal/engine -run 'TestAgentLoop|Loop|TestMRGate' ok。不装 bwrap 替身时,TestMRGateRunsInTheNodeLoop 报 bwrap not found,属于环境问题,装上替身后通过。
  • CI:新 head dc5a90a2 上 16/16 全部通过,与 main be6918d7 无冲突。

crispinhu27 在 d8f6bd4d 上的 Approve 已因新推送失效,需要重新评审 d8f6bd4d..dc5a90a2(4 个文件,+66/−8)。

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 dc5a90a2:APPROVE

审查版本:head dc5a90a24e517f28124363b47edb846e23f883f4(base main)。上一轮在 d8f6bd4d 上的 APPROVE(6079769095)已被新推送撤销,本次针对增量提交 dc5a90a2 进行复审。

增量范围(1 个提交,4 个文件 +66/−8)

  1. node_execute.go:agentLoopHumanMessage 新增 failedAction 参数,区分执行器失败(空串 → 「第 N 轮执行失败」)与门禁策略提前结束(非空 → 「第 N 轮门禁未通过(失败策略为 X)」)两种场景;iterations >= maxIterations 路径仍返回耗尽文案,三条分支互斥无遗漏。调用点传参正确。

  2. core_cases_test.go:补充门禁策略分支断言,三条分支全覆盖(执行失败、门禁未通过、次数耗尽)。

  3. repo_drawer.js:catalog 加载前先调 fillRepoBranchExecutors,使已保存 CLI 在 catalog 返回前显示「检查配置中」而非「未配置」;catalog 完成后重渲染,最终状态正确。

  4. webtest/tests/projects-repos.test.mjs:新增测试覆盖 catalog 加载中占位、完成后恢复、切换 prefix 仓库为 AI 时同样触发占位。

CI 验证:head dc5a90a2 全部 16 项检查通过(browser、core、platform-required、e2e 全矩阵、e2e-required、e2e-browser、first-run、validate、curl-install、tcmcp、secrets、GITHUB_OPENSOURCE_SCAN),无失败项。

未发现增量引入或加重的阻塞问题。

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants