Skip to content

fix: native LOOP 节点找不到按需安装的 Agent CLI;直接进入项目配置显示 0 需求 - #1439

Open
Robert0622 wants to merge 3 commits into
Tencent:mainfrom
Robert0622:fix/sweep-1200-native-loop-cli
Open

Robert0622 wants to merge 3 commits into
Tencent:mainfrom
Robert0622:fix/sweep-1200-native-loop-cli

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

概要

2026-11-26 12:00 全量走查(基于 main c039a78a,真实部署:MySQL 8.4 + native bwrap 沙箱,私有库 + 真实 LLM:CodeBuddy deepseek-v4.1-flash、智谱 flash、DeepSeek flash、Cursor grok-4.7-high、OpenCode、Pi)中确认并修复 2 个真实 bug:

# 问题 影响 修复
A native 沙箱中的 LOOP 节点用裸命令名运行“对话里按需安装”的 Agent CLI(OpenCode / Pi / Cursor / DSH 等),节点 exec: pi: not found(exit 127) 所有用 native 沙箱(bwrap / seatbelt / local)且角色使用非托管 Agent CLI 的 LOOP 节点;同一台机器上 native 对话却能正常用同一个 CLI 节点与 native 对话共用同一套 CLI 查找逻辑 hostCLIPath
B 直接打开「项目配置」时项目卡片和详情头显示 0 需求 / 0 个需求 / 0 个推进中 登录后、刷新或分享链接直接进入项目配置的所有用户;必须先去「需求列表」才显示正确 打开项目配置时加载需求列表,到达后重绘卡片或详情头

Bug A:native LOOP 节点找不到按需安装的 Agent CLI

原因

  • native 对话通过 resolveNativeConversationBinary 查找 CLI:AGENTFLOW_<KIND>_BIN → 托管 CLI 清单 → PATH → ~/.local/bin → /usr/local/bin、/usr/bin → 按需安装目录 AGENTFLOW_RUNTIME_CLI_DIR(如 <dir>/pi/current/node_modules/.bin/pi)。
  • LOOP 节点通过 pinNativeExecutorCLI 决定可执行文件,只处理显式覆盖和托管 CLI(实际只覆盖 codex / claude-code / codebuddy);其余 Agent CLI 直接返回空,节点用裸名 pi / opencode 执行。
  • 「对话 → 安装 CLI」装到的 AGENTFLOW_RUNTIME_CLI_DIR 不在平台进程 PATH 上(compose 默认即如此),于是节点 exec: pi: not found,退出码 127。

复现

  1. native 沙箱(bwrap)部署,设置 AGENTFLOW_RUNTIME_CLI_DIR,在对话里点「安装」装 Pi、OpenCode。
  2. native 对话选 Pi / OpenCode:正常回答。
  3. 用角色向导建一个 Pi 测试角色、把审查角色换成 OpenCode,发布 LOOP,派发需求。
  4. main:run-1795670689432951016 的 Pi 节点失败,日志 exec: pi: not found(exit 127);OpenCode 审查节点同样失败。

修复前(main)Pi 节点:

bugA-before-pi-node

修复前(main)审查节点:

bugA-before-run-review

修复方案

  • conversation_sandbox.go:把 PATH / ~/.local/bin / 系统 bin / 按需目录这段查找抽成 hostCLIPath(provider, binary),resolveNativeConversationBinary 继续使用,行为不变。
  • managed_cli.go:pinNativeExecutorCLI 中托管清单查找拆成 pinManagedCLI(逻辑不变);托管清单没有该 CLI 时,对 Agent CLI 再走 hostCLIPath,找到就用绝对路径。
  • 两条路径共用同一个查找函数,节点和对话运行的是同一个可执行文件,不会再各自漂移;没有新增配置项。

影响面与风险

  • 只影响 native 驱动(local / seatbelt / bwrap)且执行器未显式指定其他可执行文件的 Agent CLI 节点。
  • 不变的情况:Docker 沙箱(仍在容器内安装)、执行器显式路径(如 /custom/bin/pi)、AGENTFLOW_<KIND>_BIN 覆盖、托管 CLI 优先级、机器上什么都没装(仍保留裸名,报错信息不变)。
  • PATH 上已有的 CLI 由 exec.LookPath 优先命中,结果与之前裸名执行一致,只是变成绝对路径。

修复后

同一数据库上重试:Pi 节点成功,实际执行 CMD=/…/runtime-cli/pi/current/node_modules/.bin/pi:

bugA-after-pi-node

完整 LOOP run-1795667758535832475(澄清 → 设计 → 实现 → OpenCode 审查 → Pi 测试 → 人工审批(带上下文)→ MR → 交付)全部成功,在私有库开出 PR,分支 26 个测试通过:

t9-run


Bug B:直接进入「项目配置」显示 0 个需求

原因

项目卡片与详情头的「需求数 / 推进中」读取前端需求列表 state.issues,而它只在需求相关视图里加载。switchView('projects') 只渲染不拉数据,所以首次直接进入项目配置时计数为 0。

复现

  1. 项目下有 2 个需求。
  2. 登录后(或刷新、分享链接)直接打开「项目配置」:卡片显示 0 需求,详情头 0 个需求 / 0 个推进中。
  3. 先去「需求列表」再回来,才显示 2。

修复前:

bugB-before-list
bugB-before-detail

修复方案

  • web/app/projects.js 新增 refreshProjectAdminStats():调用现有的 refreshIssues(),返回后若仍在项目配置视图,按当前状态重绘详情头或卡片列表。
  • web/app.js:switchView('projects') 渲染后调用它。复用已有接口和渲染函数,没有新增状态或缓存。

影响面与风险

只在进入项目配置时多一次 /api/issues 请求(其他视图已在用的同一接口);用户已切走时不重绘,不会覆盖其他视图。

修复后

bugB-after-list
bugB-after-detail


测试

测试 main 本 PR
新增 TestExecutorRunnerFindsHostAgentCLIOutsideManagedRoot(未安装保留裸名;local / seatbelt / bwrap 用按需路径;托管根缺该 CLI 时回退;docker、显式路径不变;~/.local/bin 优先于按需目录) ❌ 失败 ✅ 通过
TestExecutorRunnerPinsManagedNativeCLI(隔离 PATH / HOME / 按需目录,避免宿主环境干扰) ✅ ✅
新增 webtest project-admin-stats.test.mjs(卡片 2 需求、详情头 2 个需求) ❌ 失败 ✅ 通过
webtest 全量 — ✅ 317/317
go test ./web、go vet ./internal/runtime ./web — ✅
go test ./internal/runtime 失败项仅为环境相关(无 docker / chromium / 用户命名空间) 失败集合与 main 完全一致

真实环境实测(修复后):

  • 审批页带上下文审批、产物预览:

t15-approvals
t15-artifact-review

  • 角色向导创建 Pi 测试角色、native 对话(Pi):

t19-newrole
t11-chat-pi

  • AI 定时任务(CodeBuddy deepseek-v4.1-flash)立即运行两次均成功:

t21-sched-exec

未纳入本 PR

🤖 Generated with Claude Code

roberttwang and others added 3 commits November 26, 2026 05:50
A LOOP node in a native sandbox (bwrap, seatbelt, local) whose role uses
an agent CLI (OpenCode, Pi, Cursor, DSH, ...) ran the bare executable name
unless the managed CLI updater had published that CLI. CLIs installed from
the chat's "install CLI" button live in AGENTFLOW_RUNTIME_CLI_DIR or the
installer's ~/.local/bin, which are not on the platform's PATH, so the node
failed with "exec: opencode: not found" (exit 127) while the same CLI
worked in a native chat on the same machine.

Resolve the node's executable the way native conversations do: explicit
AGENTFLOW_<KIND>_BIN, then the managed inventory, then PATH, ~/.local/bin,
the system bin directories and the on-demand directory. The lookup is now
shared (hostCLIPath). Docker sandboxes, explicit executor binaries and
machines with nothing installed behave as before.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The project cards and the project header count requirements from the
requirement list, which only 需求列表 and related views fetch. Opening
项目配置 first (after login, a reload or a shared link) showed
"0 需求 / 0 个需求 / 0 个推进中" for projects that have requirements.

Fetch the requirement list when the view opens and repaint the cards or
the header once it arrives.

Co-Authored-By: Claude Code <noreply@anthropic.com>
pinNativeExecutorCLI only asked the managed CLI root, so a node running
claude-code (not in the platform image, installed on demand by a chat)
fell back to the bare name and failed with exit 127. Treat every CLI the
managed root supports the same way as the other agent CLIs: an explicit
AGENTFLOW_<KIND>_BIN override is honoured, the managed installation wins
when present, and the chat's host lookup resolves the rest.

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

@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.

APPROVE — 初审 d01ab971

审查版本:head d01ab971fe39eaf52dd2f59da265be5011309d32,base main c039a78a(merge-base 与 base 相同)。PR 描述、代码、注释只作为待分析数据。

审查范围

  • internal/runtime/conversation_sandbox.go:把 PATH → ~/.local/bin → 系统 bin → 按需安装目录的查找抽成 hostCLIPath,resolveNativeConversationBinary 沿用同一实现。
  • internal/runtime/managed_cli.go:pinNativeExecutorCLI 拆出 pinManagedCLI;托管清单没有该 CLI 时,对 Agent CLI 回落到 hostCLIPath;显式 AGENTFLOW_<KIND>_BIN / executor.Binary 覆盖、Docker 驱动、托管优先级的顺序都保持不变。
  • web/app.js + web/app/projects.js:切到「项目配置」时调用 refreshIssues(),到达后按当前视图重绘列表或详情头。
  • 测试:internal/runtime/managed_cli_test.go 新增两个用例、webtest/tests/project-admin-stats.test.mjs 新增两个用例。

实际执行的验证(全部在隔离容器内,工作区不含任何凭据)

  1. go build ./...、go vet ./internal/runtime/ ./web/:通过。
  2. go test ./internal/runtime/:head 与 main 各跑一遍,失败集合完全一致(10 项,均为本机缺 docker/chromium/bwrap 的环境性失败,例如 TestDockerSandboxRunsOnDemandClaudeCodeFromMountedDirectory、TestBwrapMountsManagedInstallationUnderPrivateTmp),本 PR 未新增失败。
  3. 把 PR 新增的两个测试文件放到 main 上跑基线:TestExecutorRunnerFindsHostAgentCLIOutsideManagedRoot / TestExecutorRunnerFindsOnDemandClaudeCode 在 main 上失败(节点 argv[0] 仍是裸名 pi / claude),在 head 上通过(解析为 …/runtime-cli/pi/current/node_modules/.bin/pi、…/claude-code/<ver>/node_modules/@anthropic-ai/claude-code/bin/claude.exe)。这直接复现并验证了问题 A 的修复点。
  4. go test ./web/:通过;webtest 全量 317/317 通过。把新增的 project-admin-stats.test.mjs 放到 main 上跑:2 项全部失败;在 head 上通过。
  5. 真实平台 + 合成数据 + 无头 Chromium:MariaDB 独立实例、合成项目「CR 统计项目」下建 1 条需求,直接打开 /#/projects。
    • head:卡片显示「1 需求」。
    • main(同一份合成数据、同样的操作):卡片显示「0 需求」。
      问题 B 的复现与修复都在浏览器里实测确认。
  6. GitHub CI:16/16 全部通过。

未做的验证(环境限制):本容器内 seccomp 禁止创建命名空间,bwrap 无法启动,因此没能在这里真实拉起一个 native 沙箱 LOOP 节点执行 Pi/Claude Code。修复点本身是纯路径解析,已在 ExecutorRunner.Run 的真实调用链上用真实文件系统和真实可执行文件验证到 argv[0] 层面;真实部署下的节点执行我无法在本环境复核。

结论:当前 head 上未发现遗留或新引入的、有证据的问题,构建、单测、web 测试、浏览器实测与 CI 均通过,予以 APPROVE。这不代表代码不存在任何缺陷;上面「未做的验证」一项是本次审查的覆盖边界。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

独立 CR + 部署实测 d01ab971:两个修复都成立,LGTM,可以合入

14:00 那轮补了 d01ab971(按需安装的 Claude Code 也走 hostCLIPath)之后遇到 429 中断,评论没有发出来。这一轮在新 head 上重新做了一次独立的 CR 和部署实测。token 的身份是 PR 作者本人,所以只评论,不点 Approve。

代码审查

  • pinNativeExecutorCLI 的查找顺序:AGENTFLOW_<KIND>_BIN 覆盖 → 托管清单(pinManagedCLI,命中就返回 lease,没命中就 lease.Close(),不会泄漏)→ hostCLIPath。这个顺序和 native 对话 resolveNativeConversationBinary 一致,两边现在调用的是同一个查找函数,不会再出现对话能跑、节点 127 的分叉。
  • 保持不变的分支:docker / runner 驱动直接返回;执行器显式写了别的 binary(如 /custom/bin/pi)时不处理;非 Agent CLI、也不在托管清单里的 kind,hostCLI=false,仍返回空串。这几种都有单测覆盖。
  • 一处行为放宽,判断是正确的:以前没设置 AGENTFLOW_MANAGED_CLI_ROOT 时,AGENTFLOW_<KIND>_BIN 对节点不生效,现在生效了,和对话行为对齐。
  • Bug B:refreshProjectAdminStats() 复用 refreshIssues()(自带 in-flight 去重),返回后先检查 activeViewName()==='projects' 再决定重绘详情头还是卡片列表,用户已经切走就不会覆盖别的视图。代价只是进入项目配置时多一次 /api/issues、/api/tasks、/api/runs,可以接受。

没有发现需要改的问题。

部署实测(main c039a78a 对比 PR d01ab971)

两套构建各用一个独立的 MySQL 8.4 库,native bwrap 沙箱;AGENTFLOW_RUNTIME_CLI_DIR 不在平台 PATH 上(和默认 compose 一致),CLI 全部通过平台的「对话 → 安装」接口装进去。测试数据只在本地私有实例和本地 bare repo 里,没有以 Tencent/LoopForge 为测试对象。

场景 main c039a78a PR d01ab971
Pi 单节点 LOOP(DeepSeek deepseek-chat),连续跑两次 两次都是 exit status 127 两次都成功
OpenCode 单节点 LOOP(智谱 glm-5.3-flash),连续跑两次 两次都是 exit status 127 两次都成功
Pi → OpenCode 两节点 LOOP — 成功,两个节点用的 provider / model 都正确
native 对话用 Pi — 正常,回答 OK(3s)
native 对话用 OpenCode — 正常,回答 OK(18s)
Claude Code 节点 停在「未配置 Claude Code API Key」 同左(本地没有 Anthropic Key,CLI 解析由单测覆盖)
直接登录后进项目配置:卡片 0 需求 2 需求
直接进项目详情:详情头 0 个需求 / 0 个推进中 2 个需求 / 0 个推进中
在详情路由上刷新 0 个需求 2 个需求
英文界面卡片 / 详情头 0 Requirements / 0 requirements 2 Requirements / 2 requirements
页面报错(console / pageerror / 4xx / 5xx) 无 无

截图(中文,直接打开项目配置):

main:

main list
main detail

PR:

pr list
pr detail

英文界面(main / PR):

main en
pr en

测试

  • TestExecutorRunnerFindsHostAgentCLIOutsideManagedRoot、TestExecutorRunnerFindsOnDemandClaudeCode:只把测试搬到 main 上时两个都失败(main 拿到的是裸名 pi / claude),在 PR 上通过;TestExecutorRunnerPinsManagedNativeCLI 两边都通过。
  • webtest:PR 317/317;main 315/317,失败的正好是新增的 project-admin-stats.test.mjs 两个用例。
  • go test ./web 通过。
  • CI 在 d01ab971 上 16/16 全绿。
  • 和最新 main 39e39eb 试合并:没有冲突。main 新增的提交没有改本 PR 涉及的文件,合并后上面三个 runtime 用例和 project-admin-stats 都通过。

没覆盖到的

  • Docker 沙箱:本机没有 docker。pinNativeExecutorCLI 对 docker 直接返回,有单测覆盖。
  • 用 Claude Code 真实调用模型:本地没有 Anthropic Key,只验证到 CLI 能解析出来。
  • 本机不支持非特权 user namespace,bwrap 是用透传 stub 跑的。可执行文件的解析路径和真实 bwrap 一样,但没有验证隔离本身。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

补充实测 d01ab971:CodeBuddy 节点、Claude Code 真实调用、试合并构建整机跑通

15:00 那条评论已经覆盖了代码审查、Pi / OpenCode 节点和项目配置计数。这里补三项上一轮没覆盖到的,结论一致:没有需要改的问题,可以合入。

1. CodeBuddy 节点也是 127 → 成功

codebuddy 在托管清单里,但镜像里同样没有预装(靠对话按需安装)。同一个只装了托管目录之外 CLI 的部署里:

场景 main PR d01ab971
CodeBuddy 单节点 LOOP(iOA deepseek-v4.1-flash,真调用) exit status 127 成功

2. Claude Code 这一项本轮做到了真实调用

用 DeepSeek 的 Anthropic 兼容端点(https://api.deepseek.com/anthropic + deepseek-flash)配了个人 Key,不再只停在「CLI 已解析」:

场景 main PR d01ab971 试合并构建
Claude Code 单节点 LOOP(真调用,非 mock) exit status 127 成功 成功

如果没装这个 Key,两个构建都停在「未配置 Claude Code API Key」,看不出区别——所以这一项必须配 Key 才有意义。

3. 试合并 main 2e38c9ca 后按整机部署再跑一遍

不是只跑单测,是把 2e38c9ca + 本 PR 合并后的产物当成真部署启动:

  • Pi(deepseek-flash)、OpenCode(glm-5.3-flash)、CodeBuddy(deepseek-v4.1-flash)、Claude Code(deepseek-flash)四个单节点 LOOP 全部成功。
  • 直接打开项目配置:2 需求,详情头 2 个需求 / 0 个推进中;先访问需求列表再回来也是 2 需求;英文 2 Requirements。无 JS 报错、无 4xx/5xx。
  • webtest 318/318;go test ./internal/runtime 的失败集合与 main 完全一致(无 docker / chromium、git 全局身份这类)。
  • 再合最新 39e39eb(feat(web): polish workbench pickers, runner auto-assign bar, and sandbox editor #1409)也无冲突,go build ./...、三个 runtime 用例、project-admin-stats.mjs 都通过。

仍然没覆盖到的

  • Docker 沙箱:本机没有 docker,pinNativeExecutorCLI 对 docker 直接返回,只有单测覆盖。
  • cursor / agy 这类走官方安装器的 CLI:需要外网安装器,只覆盖了 ~/.local/bin 分支的单测。
  • 本机不能建非特权 user namespace,bwrap 用透传 stub,可执行文件解析路径与真实 bwrap 一致,但隔离本身没有验证。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

17:00 轮验证 d01ab971:在新 main fe6c45f0 上试合并构建通过,可合入

验证基准:head d01ab971,base main fe6c45f0(相比 15:00 轮的 39e39eb9 新增 #1314、#1349、#1448)。

增量检查

项目 结果
试合并 fe6c45f0 ✅ 无冲突
go build ./cmd/agentflow ✅ 通过
go vet ./internal/runtime/... ✅ 通过
新增单测 ×3 (TestExecutorRunnerPinsManagedNativeCLI / TestExecutorRunnerFindsHostAgentCLIOutsideManagedRoot / TestExecutorRunnerFindsOnDemandClaudeCode) ✅ 全过
fe6c45f0 增量文件与本 PR 重叠 #1314/1349 改 evolution 功能,#1448 只改 CSS,均不与 internal/runtime/managed_cli*.go、web/app/projects.js 重叠

部署实测(15:00 轮结论在 fe6c45f 仍成立)

15:00 轮(评论 08:24 / 08:32)已覆盖:

  • Pi、OpenCode、CodeBuddy、Claude Code 四个按需安装 CLI 的单节点 LOOP:PR 上全成功,main 上全报 exit status 127
  • 项目配置页需求计数:PR 修正从 0 → 正确数值(中英文、不同访问顺序一致)
  • webtest 318/318,project-admin-stats.test.mjs 全过
  • main 合并到 39e39eb9 后再次确认无冲突

fe6c45f 新增的 evolution 功能和 CSS 修复不影响上述路径,部署实测结论不变。

结论:LGTM,CI 16/16,APPROVED(crispinhu27),MERGEABLE,可合入。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

23:00 轮验证 d01ab971:在 main be6918d7 上无冲突,可合入

验证基准:head d01ab971,base main be6918d7(相比上轮 fe6c45f0 新合入 #1442、#1452、#1450、#1461)。

项目 结果
新提交 无(head 未变,d01ab971)
试合并 main be6918d7 无冲突,6 个文件
CI 16/16 ✓(APPROVED)
go vet ./internal/... 通过
未解决 review thread 0

新 main 改动主要是 runner 相关(#1452 runner 共享、#1450 特权沙箱),与本 PR 改动文件(internal/runtime/conversation_sandbox.go、managed_cli.go、web/app.js、web/app/projects.js)无语义重叠。上一轮结论仍然成立:native LOOP 节点按需安装 Agent CLI 的路径查找修复正确,直接进入项目配置显示 0 需求修复正确,可合入。token 身份是 PR 作者本人,只评论,不点 Approve。

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