Skip to content

fix(runs): bind the project default repository for manual runs of project LOOPs - #1468

Open
Robert0622 wants to merge 1 commit into
Tencent:mainfrom
Robert0622:fix/manual-run-project-default-repo
Open

Robert0622 wants to merge 1 commit into
Tencent:mainfrom
Robert0622:fix/manual-run-project-default-repo

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

Problem

POST /api/runs (the LOOP designer's Run dialog, web/app/runs.js:startRun) only binds the project's default repository when the workflow is a raw generic template (wf.Generic). A generic template has to be copied into a project before it can be edited (adoptGenericWorkflow sets Generic=false). That copy, like any other project LOOP, then starts without any repository checkout, even when the project has a default repository.

Requirement dispatch (POST /api/issues/:id/dispatch, dispatch.go) falls back to the project default repository for every LOOP, so the same LOOP behaves differently depending on which button starts it.

Reproduction (v0.4.3, be6918d, real deployment)

  1. Project sweep-1613 with default repository sweep-repo (a private GitHub repo).
  2. POST /api/workflows/issue-fix-production/clone → issue-fix-native (projectId sweep-1613), then publish.
  3. POST /api/runs {"workflowId":"issue-fix-native","projectId":"sweep-1613","input":"..."}
    → run repository is {"repositoryId":"","provider":"","name":"","baseBranch":""}, repositories: null. The agents run with no code.
  4. POST /api/issues/<id>/dispatch {"workflowId":"issue-fix-native"} on the same project
    → repository.repositoryId = "sweep-repo", the repo is cloned, and the LOOP runs clarify → design → implement → review on the code.

Fix

Bind the project default repository for any LOOP started within a project (req.ProjectID != ""). This matches requirement dispatch. Generic templates behave as before, including the existing repository_required 409 when the default repository is invalid.

Tests

  • New TestManualRunOfProjectLOOPBindsProjectDefaultRepository: fails before (must bind the project default repository: []), passes after.
  • go test ./internal/httpapi/ → ok (skipping two Chromium browser tests that fail on unmodified main in this container because Chromium can't start).
  • go vet ./internal/httpapi/ clean.

🤖 Generated with Claude Code

…ject LOOPs

POST /api/runs only attached the project's default repository when the
workflow was a raw generic template. A generic template must be copied into
the project before it can be edited, and that copy (like any project LOOP)
then started from the designer's Run dialog without any code checkout, while
requirement dispatch of the same LOOP did bind the repository.

Bind the project default repository for every LOOP started inside a project,
matching requirement dispatch.

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.

Code Review(自动化 CR · 初审):APPROVE

  • 审查版本:head 89468c40(base main be6918d7,merge-base 相同)
  • 审查范围:internal/httpapi/runs.go 中 POST /api/runs 绑定项目默认仓库的条件(从 wf.Generic 改成 req.ProjectID != ""),以及新增的 TestManualRunOfProjectLOOPBindsProjectDefaultRepository。对照了 dispatch.go 的需求派发回退逻辑、engine.StartWithRepositories 和 startWorkflowDefinitionSeeded、requireProjectWriter 权限检查、共享定时任务(scheduledWorkflow)以及 runs_start MCP 这个调用方。

实际验证(隔离环境,无 GitHub 凭据,合成数据)

  1. 真实部署对照:本地 MariaDB 加 head/base 两个服务实例,用本地 HTTP 上的合成 bare git 仓库作为项目 sweep 的默认仓库,项目内建一个普通(非 generic)LOOP,然后 POST /api/runs {"workflowId":…,"projectId":"sweep"}:
    • head:201,repositories=[<默认仓库>]、repository.repositoryId/provider/baseBranch 都已填好;native 沙箱的 script 节点 run 实际 clone 了仓库(git 服务端有 upload-pack 请求,工作区里有 run-…/app/README.md)。
    • base:201,repositories=[]、repository 为空,工作区里没有 checkout。PR 描述的问题能复现,修复也成立。
  2. 新测试在 head 上通过;把同一个测试文件放到 base 上失败(must bind the project default repository: [])。
  3. go vet ./internal/httpapi/ 通过。go test ./internal/httpapi/(跳过 Browser/Chromium)在 head 和 base 上的失败集合完全相同,都是 4 项,原因都是容器里 bwrap 无法创建用户命名空间(环境原因,和本 PR 无关)。
  4. CI 16/16 通过(含 core、platform-required、e2e-required)。

结论

没有发现由本 PR 引入的阻塞问题。另外记一个行为变化,不阻塞:项目的默认仓库无效(不存在或不属于该项目)时,非 generic LOOP 的手动运行现在会返回 409 repository_required(以前会在没有仓库的情况下启动)。这和需求派发拒绝无效绑定仓库的做法一致,PR 描述里也写明了。

未验证的部分:没有跑接真实模型的 Agent 节点(没有模型供应商凭据),节点执行只用 script 节点验证到 checkout 这一步。以上不代表代码一定没有缺陷。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Code Review + Unit Test: PASS ✅

审查版本: head 89468c40(base main be6918d7)

代码审查

变更范围: internal/httpapi/runs.go(1 行逻辑变更 + 注释)+ internal/httpapi/repository_clone_url_test.go(新增 1 个测试函数)

核心改动分析:

  • 原条件 wf.Generic && req.ProjectID != "" → 新条件 req.ProjectID != ""(wf 改为 _)
  • ok 保留:仍然确认 workflow 存在,保持 nil-safe
  • 与 dispatch.go POST /api/issues/:id/dispatch 的项目默认仓库回退逻辑完全对称
  • 行为变化:无效默认仓库现在对所有项目 LOOP 手动运行返回 409 repository_required(之前只对 generic 模板生效);PR 描述已说明此变化,与需求派发行为一致

无安全/逻辑问题。

单元测试(本地验证)

测试 PR head 89468c40 base main be6918d7
TestManualRunOfProjectLOOPBindsProjectDefaultRepository ✅ PASS ❌ FAIL (must bind the project default repository: [])
TestLegacyCloneURLCredentialsStayOutOfPromptAndRunViews ✅ PASS ✅ PASS
TestRepositoryBindingIsValidatedAndFrozenAtDispatch ✅ PASS ✅ PASS
TestRepositoryOneLinkSetup 等其余 repository 相关 ✅ 全 PASS ✅ 全 PASS
ok  agentflow/internal/httpapi  0.504s   (9 tests)

go vet ./internal/httpapi/:clean

before/after 均符合预期,修复有效。 部署级集成实测由另一会话并行进行,以该结果为准。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

02:00 轮 CR + 部署实测:89468c40 LGTM,可合入

代码审查

  • runs.go:POST /api/runs 绑默认仓库的条件从 wf.Generic 放宽为「带了 projectId 的任何 LOOP」,和 dispatch.go(需求派发)回退到项目默认仓库的逻辑对齐。ok 仍用于确认 workflow 存在;仓库不属于该项目时仍返回 409 repository_required,前端 app.js 已有对应 toast + 「绑定仓库」按钮。
  • 受影响的入口都走这一个 handler:设计器「运行」弹窗、AI 助手 / MCP 的 runs_start、共享定时任务。下面都测了。
  • 新测试 TestManualRunOfProjectLOOPBindsProjectDefaultRepository:PR 上通过;把它放到 main be6918d7 上跑会失败(must bind the project default repository: []),能抓到这个问题。
  • 没有阻塞问题。

部署实测(PR 89468c40 和 main be6918d7 同时部署,各用一个全新 MySQL 8.4.7 库,开登录,用 native 沙箱;代码仓库是私有测试库 Robert0622/loopforge-cr1468-1127,没有拿 Tencent/LoopForge 做测试对象;Agent 用 CodeBuddy iOA deepseek-v4.1-flash)

# 场景 main be6918d7 PR 89468c40
S1 项目副本 fix-copy(issue-fix-production 复制到项目)手动运行,真实跑「需求定型」节点 repositories: [],Agent 输出「未绑定代码仓库,工作区内无 calc 源码」,停在待确认 绑定 calc-repo,检出 loopforge-cr1468-1127 @ feature/fix-…,Agent 读了 calc/__init__.py 和基线提交 ca11da17,给出结论 ✅
S2 普通项目 LOOP probe-loop(单 Agent 节点)手动运行,让 Agent 在仓库里加 mul() 并验证 report.md = NO_REPO REPO_FOUND loopforge-cr1468-1127 CALC-REPO-1468 / OK,产出 repository-patch(2 个文件 +9/-1)✅
S3 原始 generic 模板 issue-fix-production 在项目里手动运行 绑定 calc-repo 绑定 calc-repo(行为不变)✅
S4 没有默认仓库的项目里手动运行 [],Agent 返回 NO_REPO [],Agent 返回 NO_REPO(不变)✅
S5 需求派发 POST /api/issues/:id/dispatch 绑定 calc-repo 绑定 calc-repo(不变)✅
S6 默认仓库失效(默认仓库被移到别的项目)后手动运行 201,不带仓库照常跑 409 repository_required「项目默认代码仓库无效,请重新绑定」,界面 toast 带「绑定仓库」按钮 ✅
S6b 同样状态下新建需求 400 repository must belong to issue project 400(不变;说明 S6 的 409 和需求链路是一致的)✅
S7 POST /api/runs 不带 projectId [] [](不变)✅
S8 AI 助手(CodeBuddy deepseek-v4.1-flash)调用 runs_start 启动 probe-loop 新运行 repositories: [] 新运行绑定 calc-repo ✅
UI 设计器打开 fix-copy → 运行 → 开始运行,进运行详情的任务 IDE POST /api/runs 201,repositories: [];IDE 里只有 requirement.md 201,repositories: ["calc-repo"];IDE 里有 loopforge-cr1468-1127/ 和 requirement.md ✅

S6 是一处行为变化:以前只有 generic 模板会在默认仓库失效时返回 409,现在所有项目 LOOP 都会。这和需求派发、新建需求的处理一致,PR 描述里也写了,所以不算阻塞。

截图

PR:任务 IDE 里检出了仓库
pr ide

main:同一个项目副本,没有检出仓库
main ide

PR:默认仓库失效时,界面提示「项目默认代码仓库无效,请重新绑定」并带「绑定仓库」按钮
pr 409

测试

  • go vet ./internal/httpapi/ 通过。
  • 新测试和相关用例 TestGenericTemplatesAndCopiesRunWithoutRepository、TestSSHRepositoryCheckoutAndDelivery、TestLegacyCloneURL…、TestRunStreamDeliversLiveSnapshots 在 PR 上都通过。
  • go test ./internal/httpapi/:PR 和 main 在同一台机器上对比跑,都只失败 TestMainBotBrowserStartsAndDrivesRunBrowser、TestBrowserStreamPushesFramesAndRunsCommands 这两个。原因是本机的 Chromium 起不来,两边结果一样,PR 没有多出失败。
  • CI 16/16 通过,没有冲突,crispinhu27 已 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