Skip to content

policy-sign exits 0 on a queue ref it cannot parse, while merge-gate parses the same ref #2671

Not planned

Description

@Birfy

Written-by: Chief

A queue entry can be judged by merge-gate and skipped by policy-sign when both read the same merge_group.head_ref. Two parsers disagree about the ref, and the one that disagrees fails open: policy-sign returns exit 0 with "this run carries no pull request, so there is nothing to sign".

两处解析器(同一 payload,不同答案)

.github/scripts/merge-gate.mjs:61-64 — 认得分支名里带斜杠,且校验结尾是 7–40 位 hex:

export function prFromHeadRef(ref) {
  const branch = String(ref ?? '').trim().replace(/^refs\/heads\//i, '')
  const m = /^gh-readonly-queue\/(.+)\/pr-(\d+)-([0-9a-f]{7,40})$/i.exec(branch)
  return m ? { pr: Number(m[2]), base: m[3].toLowerCase() } : null
}

.github/scripts/policy-sign.mjs:122 — base 只允许单段,结尾不校验:

const match = /^gh-readonly-queue\/[^/]+\/pr-(\d+)-/.exec(ref)
return match === null ? undefined : Number(match[1])

而 .github/scripts/policy-sign.mjs:159-163 把 undefined 当成「这次 run 没有 PR,没什么可签」并 返回 0:

if (number === undefined) {
  process.stdout.write('policy-sign: this run carries no pull request, so there is nothing to sign\n')
  return 0
}

复现(同一 ref 喂两个导出函数)

在 main 656fadab71170275eeeb924fdfddc33f8072ba81:

ref = gh-readonly-queue/release/1.0/pr-12-abc1234
policy-sign pullRequestNumber -> undefined      (它随后 exit 0 = 绿)
merge-gate prFromHeadRef      -> {"pr":12,"base":"abc1234"}

第二种不一致方向相反但不更安全:gh-readonly-queue/main/pr-12-nothex 的 policy-sign 取到 12 继续判,merge-gate 拒绝。

后果

  • 以带斜杠的分支(release/1.0)为 base 的队列条目,merge-gate 正常判定,policy-sign 却什么都不判照样绿——一个门禁在自己读不懂的输入上给通过,而不是拒绝。
  • 两个脚本对同一事件的读法必须一致:不一致时哪个是错的没有依据,而这一处错的方向恰好是「放行」。

修法(口径已定,实现照此做)

  1. 只留一个解析器:把 merge-gate.mjs 的 prFromHeadRef 提成共享模块(或 policy-sign.mjs 直接 import 它),两边调用同一个函数,policy-sign 删掉本地正则。导出名与签名不变,prFromHeadRef 的行为按 merge-gate.mjs 现有测试为准。
  2. policy-sign 的「没有 PR」分支要区分事件:event.merge_group 存在时,队列必然指向一个 PR,解析不出来必须 exit 1(fail-closed,输出 ::error::policy-sign cannot read a pull request from this queue ref: <ref>);push 与手动 run 仍 exit 0。
  3. 不碰 ruleset、不碰 review-policy.json、不改 merge-gate 的判定方向。

红先

  • 新增用例:merge_group.head_ref = 'gh-readonly-queue/release/1.0/pr-12-abc1234' 时 pullRequestNumber 返回 12(改前 undefined)。
  • 新增用例:merge_group.head_ref = 'gh-readonly-queue/main/pr-12-nothex' 时 pullRequestNumber 返回 undefined(与 merge-gate 一致),且 main() 在这个输入上 exit 1(改前 exit 0)。
  • 保留:push 事件、无 GITHUB_EVENT_PATH、--pr 123 三条仍 exit 0 / 取到号。

验收

cd core || true
node --test .github/scripts/policy-sign.test.mjs .github/scripts/merge-gate.test.mjs

(在仓库根:node --test .github/scripts/policy-sign.test.mjs .github/scripts/merge-gate.test.mjs;两套现有用例必须全绿。)

范围外

  • 3000 文件 API 上限导致的不可见文件不在本单内。
  • policy-sign 是否应成为必过 context 不在本单内(那是 ruleset 决定)。

Docs-not-needed: the change keeps an existing script's decision direction; no architecture or subsystem doc describes policy-sign's ref parsing.

Activity

  1. added
    bug
    agent-ready
    area:automation
    on Nov 8, 2026
  2. HugoXK commented on Nov 8, 2026

    @HugoXK
    Contributor

    Claim

    Written-by: FlyBot Lead
    Claimed-by: FlyBot Lead
    Claim-Id: 54e7ff17fdff4384bedcc7d1a065bc28
    Branch: dev/2671-policy-sign-exits-0-on-a-queue-ref-it-ca
    Base: 656fada
    At: 2026-11-08T05:51:54Z

  3. added
    agent-pr
    and removed
    agent-ready
    on Nov 8, 2026
  4. self-assigned this
    on Nov 8, 2026
  5. Birfy commented on Nov 8, 2026

    @Birfy
    CollaboratorAuthor

    Written-by: Chief

    修复已出:PR #2672,tip d5dd4a5677667bb6753406f6662fe9de6d0a70c3(05:58Z)。改动是:新增 .github/scripts/pr-ref.mjs 把 prFromHeadRef 提出来,merge-gate.mjs 改为 import 并 re-export(外部 import 与既有用例不变),policy-sign.mjs 的 pullRequestNumber() 改用同一个函数,并且 merge_group 事件下解析失败改为 exit 1。红先 2 条,验收 node --test .github/scripts/policy-sign.test.mjs .github/scripts/merge-gate.test.mjs 76/76。

    它现在卡在一个只有人能做的地方,与代码无关。 这两个脚本都在 policy/gates.json 的 gateFiles 里,所以 PR 正文必须带 Policy-sign: <comment id>,指向一条不是本 PR 作者(作者是 Birfy)、User 类型、并且正文点到了 tip d5dd4a567766 的评论。团队所有 Bot 都写 Birfy,owner 本人也是 Birfy,所以 Bot 侧补不出这条签名。

    现状:tests-ok 因 policy-sign 红,PR 保持 open、不入队、也不改任何判定方向。等有权限的人评论后,把 Policy-sign: <comment id> 写进正文,再 workflow_dispatch 一次 Test。

    在签名到位前这个 issue 不再派活,标 needs-human。缺陷本身仍然成立:同一个 merge_group.head_ref,merge-gate 读得出 PR 号、policy-sign 读不出,而读不出的那一边 exit 0(绿)而不是拒绝。

  6. added
    needs-human
    and removed
    agent-pr
    on Nov 8, 2026
  7. Birfy commented on Nov 25, 2026

    @Birfy
    CollaboratorAuthor

    基于已退役布局关闭(关闭原因,非验收结论)

    • main 锚点:d8898cad(2026-11-25T12:20:16Z,2156 blobs)
    • 正文引用的定位路径在 main d8898cad 上不存在
    • Release FlyBot 0.3.0 with the OpenTeamily workspace #3377(FlyBot 0.3.0,2026-11-25T01:29Z)移除了 core/ plugins/ policy/ patches/ .github/agent/ .github/scripts/ workflows/test.yml
    • 结论:重构前血缘的条目,无法在当前 main 上复现或评审;如仍需该项能力,请在现行线上重开一条并写明当前路径
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:automationbugneeds-human

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions