Skip to content

feat(sop): add an MR node to the built-in code delivery SOPs - #967

Merged
Robert0622 merged 6 commits into
mainfrom
feat/generic-sop-mr-node
Nov 16, 2026
Merged

Robert0622 merged 6 commits into
mainfrom
feat/generic-sop-mr-node

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Refs #717. The built-in backend, frontend and defect-fix SOPs ended at 交付汇总, whose prompt opened a PR only when the user explicitly asked. A run could succeed (all gates pass, human acceptance approved) with every source change still uncommitted, and the workspace is reclaimed right after success — the code never reached the repository while the requirement showed 已交付.

These three templates now run 人工验收 → 发起 MR → 交付汇总:

  • 发起 MR commits the work branch, pushes it, and opens (or updates) the MR/PR against the repository's main branch — GitHub MCP when configured, otherwise the GitHub API with $AGENTFLOW_GIT_TOKEN; it never merges, pushes the main branch or force-pushes. The link, branches and commit SHA go to mr-body.md (the artifact name the platform already ranks highest when resolving a run's delivery MR). {{existingMR}} keeps the existing-branch/existing-MR rules.
  • A run-scoped command gate checks every writable repository of the run, listed by the engine in AGENTFLOW_WORK_BRANCHES (dir<TAB>work branch<TAB>target branch, taken from the run's frozen repository context, so a requirement's release branch and a scheduled SOP's integration branch count as targets). A repository with commits beyond origin/<target> fails while it has uncommitted changes (excluding .agentflow and node_modules), sits off the run's work branch, or git ls-remote origin refs/heads/<work branch> is not HEAD. A repository the run left unchanged is skipped. The role retries once with that output and then waits for a person (loop.onExhausted=human), so a prompt the agent ignores can no longer end in a succeeded run. Repository-scoped commands also get AGENTFLOW_WORK_BRANCH and AGENTFLOW_BASE_BRANCH.
  • A second gate of the new verification mode mr has the engine list the MRs from the work branch into the frozen target branch with their head commits (new tracker FindBranchMRsInto, GitHub and Gongfeng). Every writable repository whose work branch on origin carries commits beyond the target needs an MR that carries the pushed tip: an open one whose head is the tip (or whose host reports no head), or a merged one whose head is the tip. Missing, closed, mistargeted or stale MRs — including an earlier merged MR on a reused work branch — fail the gate (self-correct once, then a person). The lookup runs as the run: GitHub with the Git token the run pushed with (else the Owner of the run's own project), Gongfeng through the run project's MCP as the responsible user — not whichever project bound the repository first; a failed lookup names the identity it used. A host that cannot be queried — SSH repository, lookup error, no lookup configured — goes straight to a person. mr gates take no commands. The role editor shows them without a command box and keeps them on save; it used to coerce every gate to mode:'command' and drop gates without commands.
  • If push or MR creation fails (missing credentials, permissions), the role submits human with the action required instead of pass.
  • Runs without a bound repository still deliver from the task workspace: the node records that in mr-body.md and passes; a local repository without a remote does not block.
  • 交付汇总 no longer pushes or opens PRs; it lists the MR from mr-body.md.
  • The product SOP delivers documents only and is unchanged.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

  • Fresh installs get the new graph from migrations/seed/001_public_catalog.sql.
  • Existing installs: migrations/033_generic_sop_mr_node.sql is a manual data migration (AGENTS.md): the installer and ./start.sh pull do not run it, and docs/deployment.md describes applying it. New installs get the new templates from the seed. It is idempotent and only rewrites a template whose node graph is still the shipped original (7 nodes, accept → deliver, 交付汇总 at its shipped position, no mr node); the 交付汇总 prompt is replaced only while it is the unedited seed text. Operator-edited templates keep their graph; SOPs already adopted into a project are copies and are not touched (re-adopt or add the node by hand).
  • Runs on these templates now need a Git credential with push access when a repository is bound; without it the run stops at 发起 MR for a person instead of succeeding.

Validation

go test ./internal/repo/ ./internal/domain/ ./internal/engine/ -count=1   # pass
go vet ./internal/repo/                                                    # pass
python3 -m unittest scripts/test-install.py                                # 49 tests pass
python3 scripts/check-public.py                                            # pass
bash scripts/scan-secrets.sh                                               # no leaks

New tests in internal/repo/public_catalog_test.go:

  • TestPublicCodeSOPsOpenMRBeforeDeliver: the three code SOPs route accept → mr → deliver, the MR role has one run-scoped command gate, loops to a person and keeps {{existingMR}}; the product SOP has no MR node. Fails on the current seed.
  • TestPublicMRGateRequiresTheRunWorkBranchPushed: runs the gate command taken from the seed against a local bare remote — no repository, unchanged repository (ignoring .agentflow/node_modules), modified + untracked files, unpushed commit, HEAD pushed only to another branch, pushed work branch, a commit after the push, checkout moved off the work branch, target branch missing on origin, and a release-based work branch measured against its frozen target versus main.
  • TestVerifyRunMRsRequiresAnMRCarryingThePushedTip: only repositories with pushed commits are looked up, into their frozen target; missing, closed, stale-head and earlier-merged MRs fail; an open/reopened MR or a merged MR whose head is the tip passes; lookup errors, no lookup and SSH repositories escalate to a person; read-only repositories are skipped.
  • TestFindBranchMRsIntoReadsWithTheRunCredentials: a GitHub repository bound to two projects is read with the run's push token, else the run project's Owner (not the first project's); a rejected token names the identity; Gongfeng lookups bind as the run's responsible user.
  • TestMRGateRejectsAnEarlierMergedMROnAReusedWorkBranch: the review repro on a bare remote — a reused work branch whose previous delivery is merged, one new pushed commit, only the old merged MR on the host → fails; a new MR carrying the tip → passes.
  • TestMRPendingCommandReportsThePushedTip: against a bare remote — unpushed branch, branch at the target, local-only commits, pushed commits, and a remote tip the checkout has not fetched yet.
  • TestBranchMRsIntoKeepOnlyTheTargetAndCarryHeads: Gongfeng and GitHub listings keep only MRs into the requested target and carry their head SHA.
  • TestMRGateRunsInTheNodeLoop: an agent node with an mr gate runs through the engine and passes without repositories, without looking anything up.
  • TestValidateVerificationGateRequiresScopeForCommands: mr is a valid mode and rejects commands. TestAgentGatesKeepMRGatesOnSave (web): the role editor's save path keeps mr gates.
  • TestExecutionTargetsAndTelemetryHelpers: AGENTFLOW_WORK_BRANCHES lists writable repositories with their frozen target (read-only and branchless ones left out, a legacy root checkout as .); repository targets export AGENTFLOW_WORK_BRANCH/AGENTFLOW_BASE_BRANCH.
  • Every public role passes ValidateVerificationGates; every template passes ValidateWorkflowPreparation and ValidateWorkflowMetricStages.

Migration checked on MySQL 8.4:

  • old seed + 033 → payload JSON-equal to the new seed for all four templates;
  • re-running 033 changes nothing;
  • a template with an extra operator node is left alone; a template with an edited 交付汇总 prompt gains the MR node and keeps its prompt;
  • old seed + 016 + 033 differs from the new seed only by 016's legacy taskPrompt fields.

Not run: a live SOP run with a real agent pushing and opening a PR; go test ./..., local/scripts/*.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

The backend, frontend and defect-fix generic SOPs ended at 交付汇总, whose
prompt opened a PR only when the user explicitly asked. A run could succeed
with every source change still uncommitted in a workspace that is reclaimed
right after success (#717).

A 「发起 MR」 node now runs between 人工验收 and 交付汇总. It commits the work
branch, pushes it, opens or updates the MR/PR against the main branch and
records the link in mr-body.md. A run-scoped command gate fails while any
repository checkout with a remote has uncommitted or unpushed changes; the
role retries once with that feedback and then waits for a person. Runs
without a bound repository still deliver from the task workspace. 交付汇总
no longer pushes or opens PRs. The product SOP is unchanged.

migrations/033_generic_sop_mr_node.sql upgrades existing installations only
where the node graph is the shipped original and rewrites the 交付汇总 prompt
only while unedited; install-schema-extensions.sh runs it with 031.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread scripts/install-schema-extensions.sh Outdated
exit 1
fi
cat migrations/seed/*.sql migrations/031_generic_backend_openssh.sql | docker_access compose exec -T mysql sh -c 'MYSQL_PWD="$MYSQL_PASSWORD" mysql -u loopforge loopforge'
cat migrations/seed/*.sql migrations/031_generic_backend_openssh.sql migrations/033_generic_sop_mr_node.sql | docker_access compose exec -T mysql sh -c 'MYSQL_PWD="$MYSQL_PASSWORD" mysql -u loopforge loopforge'

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.

[P2] 将 033 保留为手动数据迁移

根目录 AGENTS.md 要求数据迁移由运维手动执行。把 033 接入这里会让 start.sh pull 自动改写已有 SOP 图,并在验收后增加 Git 写入。当前的匹配条件也会命中只调整过交付节点位置的模板,并覆盖该位置。请让新安装从 seed 取得新模板,把已有模板的改写留给运维手动执行,并核对待迁移的图是否仍是原版。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

已在 b581fe9 修改。

  • 033 已从 install-schema-extensions.sh 和两个安装测试脚本里移除,安装和 ./start.sh pull 不会再执行它。新安装从 seed 拿到新模板;已有安装由运维手动执行,docs/deployment.md 的「Updating existing public SOPs」一节补充了命令和影响(之后的运行会推送工作分支、创建 MR,需要负责人的 Git 凭据有推送权限)。
  • 匹配条件增加了 $.Workflow.nodes[6].position 必须等于原始位置。在 MySQL 8.4 上验证:交付节点被移动过的模板会被跳过、位置保持不变;原版模板执行 033 后与新 seed 完全一致;重复执行没有变化;交付提示词被改过的模板只加节点、不覆盖提示词。

Comment thread internal/repo/public_catalog_test.go Outdated
t.Fatal("an unpushed commit must block")
}
git(repo, "push", "-q", "-u", "origin", "work")
if !passes(workspace) {

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.

[P1] 校验本轮实际推送的工作分支和 MR

我用本地 bare remote 跑了这段门禁。当前 HEAD 只推到了另一个远端分支、本轮工作分支没有推送时,门禁仍返回 0,因为 rev-list --not --remotes 接受任一远端跟踪引用。即使工作分支确实已推送,mr-body.md 的 required 也只要求产物存在,无法证明托管平台上已创建 MR,创建失败仍可能被标成功。建议对每个绑定仓库检查远端工作分支及 MR 的 head 和 base。Base 应使用运行上下文中冻结的目标分支,包含需求指定的 release 分支和定时 SOP 的集成分支。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

复现成立,分支部分已在 b581fe9 修改。

  • 引擎从运行上下文中冻结的仓库信息导出分支:run 范围的命令拿到 AGENTFLOW_WORK_BRANCHES,每个可写仓库一行 目录<TAB>工作分支<TAB>目标分支;逐仓库的命令拿到 AGENTFLOW_WORK_BRANCH 和 AGENTFLOW_BASE_BRANCH。目标分支取 repositoryBaseBranch,所以需求指定的 release 分支和定时 SOP 的集成分支(dispatch.go 会把 BaseBranch 设为集成分支)都包含在内。只读仓库不列入。
  • 门禁逐个检查这些仓库。相对 origin/<目标分支> 有新提交的仓库,必须没有未提交的改动、当前就在本轮工作分支上,并且 git ls-remote origin refs/heads/<工作分支> 返回的提交等于 HEAD。不再依赖本地缓存的远端跟踪引用。相对目标分支没有新提交、也没有未提交改动的仓库直接跳过,多仓库项目里没改的仓库不会被拦。
  • 测试 TestPublicMRGateRequiresTheRunWorkBranchPushed 用本地 bare remote 覆盖了你说的场景:HEAD 只推到另一个分支时门禁失败。同时覆盖了推送后又追加提交、切离工作分支、目标分支在远端不存在,以及按冻结的 release 分支和按 main 计算结果不同这几种情况。

MR 存在性这一半暂时没有放进门禁。门禁命令只能操作 Git,按平台查 MR 需要引擎介入。FindBranchMR 已经支持按工作分支查 GitHub 和工蜂的 MR,但目前只在 run 结束后由 deliveryMRsFromRun 使用。准备另开一个 PR,在「发起 MR」节点通过前由引擎用它核对 MR 的 head 和 base,查不到就转人工。这样改动可以单独评审。在那之前,提示词要求创建失败时提交 human,不能提交 pass;推送这一步已经由门禁保证。

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.

[P1] 发起 MR 节点仍需验证实际 MR

本地门禁回归通过。HEAD 只推到其他分支会被拦,门禁也会使用运行上下文里的目标分支。033 已从安装流程移除。原 P1 的 MR 核验仍未完成:工作分支推送后,只要存在 mr-body.md 且 Agent 提交了 pass,即使托管平台没有匹配的 MR,运行也能进入「交付汇总」。建议在节点通过前用 FindBranchMR 核验与本轮工作分支和目标分支匹配的 MR,缺失时转人工。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

已在 0910478 补上。

  • 新增门禁模式 mr,由引擎用 FindBranchMR 到托管平台核验。这就是交付状态同步用的那套查询,支持 GitHub 和工蜂。每个可写仓库只要远端工作分支相对冻结的目标分支有新提交,就必须有一个未关闭的 MR,源分支是本轮工作分支,目标分支是冻结的目标分支。MR 缺失、已关闭或目标分支不对时,门禁按它的 onFailure 处理:先自修正一次,然后转人工。无法查询的情况直接转人工,包括 SSH 仓库、查询报错、平台没有配置查询这三种。
  • 判断"是否有新提交"是在检出目录里执行的:先 git ls-remote 取远端工作分支,必要时 fetch,再和 origin/<目标分支> 比较。没推送、也没有新提交的仓库不会被要求有 MR。
  • 三个代码 SOP 的「发起 MR」角色在推送门禁之后加了 mr-opened 门禁,seed 和 033 已同步。033 在 MySQL 8.4 上重新验证过:原版模板执行后与新 seed 一致,重复执行没有变化,交付节点被移动过的模板会被跳过。
  • 顺带修了一个会让这个门禁丢失的问题:角色编辑器保存时会把所有门禁强制写成 mode:'command',并丢掉没有命令的门禁。现在保存时会保留 mr 门禁,编辑器里也会把它显示成"由平台核验",不显示命令框。
  • 测试:TestVerifyRunMRsRequiresAnOpenMRIntoTheFrozenTarget、TestMRPendingCommandCountsPushedCommitsBeyondTarget(使用 bare remote,覆盖远端有新提交但本地还没 fetch 的情况)、TestMRGateRunsInTheNodeLoop,以及 web 端的 TestAgentGatesKeepMRGatesOnSave。

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.

[P1] 用本轮远端提交核验 MR

真实 MR 查询已接入,缺失和错目标的回归也通过了。复用已有工作分支时,如果上一次 MR 已合并、本轮又向同名分支推了新提交,FindBranchMR 仍能返回旧 MR。verifyRunMRs 允许 merged,也没有核对 MR 的源提交。用本地 bare remote 复现:目标分支已有上一次交付,本轮多推了一个新提交,托管查询只返回旧的已合并 MR,门禁仍通过。请按目标分支筛选 MR 并核对本轮远端工作分支的 tip。允许已合并 MR 的场景也需要证明它覆盖本轮提交。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

复现成立,已在 ae2f9f6 修改。

  • tracker 新增 FindBranchMRsInto(project, source, target),按冻结的目标分支筛选,返回从工作分支到这个目标分支的全部 MR,并带上托管平台报告的 head SHA(GitHub 取 head.sha,工蜂取 sha)。旧的 FindBranchMR 仍只用于交付状态同步。
  • 判断是否需要 MR 的命令现在同时输出远端工作分支的 tip(git ls-remote,必要时 fetch)。门禁只在两种情况下通过:有打开的 MR,且它的 head 等于这个 tip,或者平台没有报告 head(打开的 MR 本来就跟随源分支);或者有已合并的 MR,且它的 head 等于这个 tip。上一次交付已合并的 MR、已关闭的 MR、head 还停在旧提交的打开 MR,都会让门禁失败,并在报错里写明原因。
  • 用你的场景写了测试 TestMRGateRejectsAnEarlierMergedMROnAReusedWorkBranch:本地 bare remote,复用已有工作分支,上一次交付已经合并进 main,本轮又推了一个新提交,托管查询只返回旧的已合并 MR,这时门禁失败;再加一个 head 等于本轮 tip 的打开 MR,门禁通过。TestVerifyRunMRsRequiresAnMRCarryingThePushedTip 覆盖打开、重新打开、已合并、已关闭、head 落后这几种状态的组合,TestBranchMRsIntoKeepOnlyTheTargetAndCarryHeads 覆盖两个平台按目标分支筛选和带出 head。

工蜂如果某个版本的 search_merge_request 不返回 sha,已合并的 MR 就无法证明包含本轮提交,门禁会失败,自修正之后转人工;打开的 MR 不受影响。

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.

[P2] 用本轮执行凭据核验私有仓库的 MR

旧 MR 和当前远端 tip 的回归已通过。新门禁经 FindBranchMRsInto 调 githubClient,读取的是找到的第一个绑定项目的 Owner Git Token。Run 拉取、推送和创建 MR 使用本轮负责人的 Git 凭据。私有仓库仅授予执行人访问权限时,MR 能成功创建,门禁却无法读取它并转人工。请让门禁按本轮绑定的仓库和执行上下文选择查询凭据。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

成立,已在 5b5ff7e、418adf64 修改。

  • FindBranchMRsInto 改为接收 domain.BranchMRQuery,带上本轮的 ExecutionContext.ProjectID、ResponsibleUserID,以及节点推送所用的 gitTok(即 resolveGitToken(..., ResponsibleUserID) 的结果)。
  • GitHub:githubClientForRun 优先用本轮推送 Token;没有时用本轮项目(且该项目绑定了此仓库)的 Owner;不再取「第一个绑定项目」。
  • 工蜂:有本轮项目时走该项目的工蜂 MCP,并以本轮责任人身份绑定(bindProjectUserTrackerMCP(..., "责任人"));只有没有 run 项目时才回退到 gongfengClientForRemoteProject。说明一下:工蜂 MCP 的认证头是项目级配置,平台目前没有按用户的工蜂查询凭据,所以这里能做到的是「本轮项目的 MCP + 责任人身份」。
  • 查询失败时报错写明身份,例如「以本轮责任人的 Git Token 查询 GitHub 失败:…」「以 project-user: 查询工蜂 MR … 失败:…」,仍按无法核验转人工。
  • 测试:TestFindBranchMRsIntoReadsWithTheRunCredentials(同一远端仓库绑在两个项目上:有推送 Token 用它,无 Token 用本轮项目 Owner 而非第一个项目;401 报错带身份;工蜂按责任人绑定),TestVerifyRunMRsRequiresAnMRCarryingThePushedTip 断言查询带上项目、Token 和责任人。

roberttwang and others added 3 commits November 17, 2026 00:04
…branch

Address review on #967:
- 033 rewrites existing SOPs and adds Git pushes after acceptance, so it is
  no longer run by the installer or ./start.sh pull; docs/deployment.md
  describes running it by hand. It now also requires 交付汇总 to sit at its
  shipped position, so a moved node keeps its layout.
- Run-scoped commands get AGENTFLOW_WORK_BRANCHES and repository-scoped ones
  AGENTFLOW_WORK_BRANCH / AGENTFLOW_BASE_BRANCH from the run's frozen
  repository context. The MR gate uses them: a repository with commits beyond
  its target branch must be clean, on the run's work branch, and have that
  branch at HEAD on origin per git ls-remote. HEAD reachable from some other
  remote branch no longer passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Address review on #967: a pushed work branch plus mr-body.md and a pass
decision still let a run reach 交付汇总 without any MR on the host.

Add verification gate mode "mr". The engine checks it with FindBranchMR,
the lookup delivery tracking already uses for GitHub and Gongfeng: every
writable repository whose work branch on origin carries commits beyond the
run's frozen target branch needs a non-closed MR from that work branch into
that target. A missing, closed or mistargeted MR fails the gate with the
gate's onFailure; a host that cannot be queried (SSH repository, lookup
error, no lookup configured) goes to a person.

The three code SOPs' 发起 MR role gets an mr-opened gate after the push gate.
The role editor shows mr gates without a command box and keeps them on save;
it used to coerce every gate to a command gate and drop empty ones.

Co-authored-by: Cursor <cursoragent@cursor.com>
Address review on #967: on a reused work branch FindBranchMR could return
the previous, already merged MR after this run pushed new commits, and the
mr gate accepted it.

Add tracker FindBranchMRsInto, which lists every MR from the work branch
into the frozen target branch with the head commit the host reports
(GitHub head.sha, Gongfeng sha). The pending check now also reports the
work branch tip on origin. The gate passes only for an open MR whose head
is that tip (or whose host reports no head) or a merged MR whose head is
that tip; an earlier merged MR, a closed MR or an open MR still on an older
head fails the gate with what is wrong.

Co-authored-by: Cursor <cursoragent@cursor.com>

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

发起 MR 的图、手动迁移、按冻结目标分支检查推送,以及 MR 必须带上本轮远端 tip,这几处是对齐的。门禁查询用的凭据还不是本轮执行凭据。推送和创建 MR 用运行责任人的 Git Token;FindBranchMRsInto 走 githubClient / gongfengClientForRemoteProject,取第一个绑定了该远端仓库的本地项目,再用它的 Owner Token 或 Owner 的工蜂 MCP。私有仓库只给了执行人权限时,MR 能创建成功,门禁查不到并转人工。请按本轮绑定的仓库和执行上下文选查询凭据。

Comment thread internal/tracker/merge_mr.go Outdated
func (s *Service) FindBranchMRsInto(project, sourceBranch, targetBranch string) ([]domain.DeliveryMR, error) {
src, target := strings.TrimSpace(sourceBranch), strings.TrimSpace(targetBranch)
if strings.HasPrefix(project, "github:") {
g, err := s.githubClient(project)

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.

[P2] 用本轮执行凭据核验私有仓库的 MR

旧 MR 不覆盖本轮 tip 的回归已经过了。这里的查询凭据和本轮执行不是同一套。

  • 运行环境的 resolveRunCredentials 用 ExecutionContext.ResponsibleUserID 的 Git Token。推送、git ls-remote,以及节点里用 $AGENTFLOW_GIT_TOKEN 创建 PR,都是这把凭据。
  • githubClient 扫全部仓库绑定,命中的第一个 GongfengProjectID 就停,取那个本地项目 Owner 的 GitToken。同一个远端仓库绑在多个项目上时,用到的可能不是本轮项目的 Owner。
  • 工蜂这边 gongfengClientForRemoteProject 同样取第一个绑定项目,再以该项目 Owner 的工蜂 MCP 调用 search_merge_request。

私有仓库只授予执行人、不授予该 Owner 时:节点能把 MR 创建出来,这次查询返回 401/403,verifyRunMRs 把它当成无法核验,直接转人工。门禁没有证明 MR 不存在。

请让这次查询使用本轮 run 上绑定的仓库和责任人凭据(GitHub 用责任人的 Git Token,工蜂用责任人在该仓库上可用的查询身份),不要用「第一个绑定项目的 Owner」。查不到是凭据问题时,报错里写明是哪一个身份失败。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

成立,已在 5b5ff7e、418adf64 修改。

  • FindBranchMRsInto 改为接收 domain.BranchMRQuery,带上本轮的 ExecutionContext.ProjectID、ResponsibleUserID,以及节点推送所用的 gitTok(即 resolveGitToken(..., ResponsibleUserID) 的结果)。
  • GitHub:githubClientForRun 优先用本轮推送 Token;没有时用本轮项目(且该项目绑定了此仓库)的 Owner;不再取「第一个绑定项目」。
  • 工蜂:有本轮项目时走该项目的工蜂 MCP,并以本轮责任人身份绑定(bindProjectUserTrackerMCP(..., "责任人"));只有没有 run 项目时才回退到 gongfengClientForRemoteProject。说明一下:工蜂 MCP 的认证头是项目级配置,平台目前没有按用户的工蜂查询凭据,所以这里能做到的是「本轮项目的 MCP + 责任人身份」。
  • 查询失败时报错写明身份,例如「以本轮责任人的 Git Token 查询 GitHub 失败:…」「以 project-user: 查询工蜂 MR … 失败:…」,仍按无法核验转人工。
  • 测试:TestFindBranchMRsIntoReadsWithTheRunCredentials(同一远端仓库绑在两个项目上:有推送 Token 用它,无 Token 用本轮项目 Owner 而非第一个项目;401 报错带身份;工蜂按责任人绑定),TestVerifyRunMRsRequiresAnMRCarryingThePushedTip 断言查询带上项目、Token 和责任人。

roberttwang and others added 2 commits November 17, 2026 01:34
Co-authored-by: Cursor <cursoragent@cursor.com>
…e it on failure

Co-authored-by: Cursor <cursoragent@cursor.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.

已复测远端工作分支的 tip 和 MR 匹配、复用分支时排除旧 MR,以及按本轮执行上下文选择查询凭据。门禁、托管平台查询和 Web 编辑器回归通过。

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

MR 门禁已改用本轮执行上下文查询。GitHub 优先用本轮推送的责任人 Git Token,没有时用本轮项目(且该项目绑定了此仓库)的 Owner,不再拿第一个绑定项目的 Token;失败报错写明身份。工蜂走本轮项目的 MCP,并以责任人身份绑定;平台没有按用户的工蜂查询凭据,这一层用项目 MCP 是现有能力的上限。TestFindBranchMRsIntoReadsWithTheRunCredentials 确认同一远端仓库绑在两个项目上时,请求带的是推送 Token,其次才是本轮项目 Owner。

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.

3 participants