From 2094171235543e246099cae689bbb252b6d1704b Mon Sep 17 00:00:00 2001 From: TangZ-L <345187680+TangZ-L@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:38:13 +0800 Subject: [PATCH] =?UTF-8?q?docs(flow):=20=E6=96=B0=E5=A2=9E=20merge=20queu?= =?UTF-8?q?e=20=E6=B2=BB=E7=90=86=20issue=20(#609)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bugfix-merge-queue-stale-base.en.md | 104 ++++++++++++++++++ .../bugfix-merge-queue-stale-base.i18n.yaml | 5 + .../issues/bugfix-merge-queue-stale-base.md | 104 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 .agents/flow/issues/bugfix-merge-queue-stale-base.en.md create mode 100644 .agents/flow/issues/bugfix-merge-queue-stale-base.i18n.yaml create mode 100644 .agents/flow/issues/bugfix-merge-queue-stale-base.md diff --git a/.agents/flow/issues/bugfix-merge-queue-stale-base.en.md b/.agents/flow/issues/bugfix-merge-queue-stale-base.en.md new file mode 100644 index 00000000..f7f1802a --- /dev/null +++ b/.agents/flow/issues/bugfix-merge-queue-stale-base.en.md @@ -0,0 +1,104 @@ +# Enable a merge queue so stale green checks cannot merge into a moved base + +English | [中文](bugfix-merge-queue-stale-base.md) + +```yaml flow +kind: issue +id: bugfix-61 +milestone: bugfix +depends: [] +priority: P2 +status: ready +scope: + - .agents/** + - .github/workflows/ci.yml + - docs/** + - plans/** +adr: [] +github: + number: 609 + url: https://github.com/Shadow-Azure/harness-evolution/issues/609 +``` + +## Background + +### Scenario + +The #589 / #562 incident on 2026-11-25 is the canonical sample: + +- PR #589 was green at 02:03Z–02:16Z on head `6adde1d4`, when its base did not yet contain CaseTools. +- PR #562 merged `f9ad7434` at 03:09Z, adding `CaseTools` that calls the old writer CLI. +- PR #589 merged `744f4f57` at 06:21Z (changing the writer to the explicit-conclusion contract), and the merged result was never verified by any CI: each PR was green against its own base, and the combination was red. + +One direct cause was that the `Protect main` ruleset had no required status checks; that gap was closed on 2026-11-25 (`required_status_checks: ci-ok`, `strict_required_status_checks_policy: true`). But `strict` only means "update the branch and re-run once the base moves"; it does not change what is verified — it never tests "does this PR still hold after another PR merges first". It only shortens the window by forcing a manual rebase and a full re-run. + +### Analysis + +- Cost of `strict`: the unit lane takes ~14 minutes; every time the base moves (common with parallel agent PRs) every in-flight PR must be updated and re-run, which is high manual friction, and there is still a window where the base moves again after the update and before the merge. +- Merge queue semantics: once a PR enters the queue, GitHub builds the merge result against the **latest main in the queue** and runs the required checks on that result; only then does it merge, and the next PR is rebuilt on the new main automatically. It verifies the merged result, not the PR head against an old base. +- Current state: the repository is public and supports merge queues; `.github/workflows/ci.yml` only triggers on `pull_request` and `push`, with no `merge_group`; the `Protect main` ruleset has required status checks but no `merge_queue` rule. Adding only the ruleset rule without a `merge_group` trigger would mean the queued required check never appears and the queue would stall. + +## Goals + +- Add a `merge_queue` rule to the `Protect main` ruleset (squash merge; `max_entries_to_build` / `max_entries_to_merge` / `min_entries_to_merge_wait_minutes` sized for a single maintainer's throughput). +- Add a `merge_group` trigger to `.github/workflows/ci.yml` so the `ci-ok` aggregate runs in queue builds. +- Keep `docs-flow` / `flow-online` PR-only (`if: github.event_name == 'pull_request'`; the diff gate already ran on the PR), and rely on `ci-ok` treating skipped lanes as passing. +- Keep `strict_required_status_checks_policy: true` as the fallback for direct merges that bypass the queue. +- Document the merge flow (PR → enqueue → queue build → merge) and the rollback path. + +## Design authority + +- [`.agents/flow/README.en.md`](../README.en.md): the GitHub-sync and gate contract; the `(#N)` PR/commit rule and diff-scope rule are unchanged. +- [`.github/workflows/ci.yml`](../../../.github/workflows/ci.yml): the `ci-ok` aggregate lane and its "skipped counts as passing" semantics. +- [docs/development.en.md](../../../docs/development.en.md): the contributor loop and gate summary, which need the merge-queue instructions. + +## Implementation + +- Ruleset: add `merge_queue` to `Protect main` (`merge_method: squash`; grouping and concurrency caps sized for CI duration; initial suggestion `max_entries_to_build: 1`, `max_entries_to_merge: 1`, `min_entries_to_merge: 1`), keeping the existing `required_status_checks` (`ci-ok`, strict). +- `ci.yml`: + - add `merge_group` to `on`; + - confirm `ci-ok` still appears for `merge_group` events (the aggregate lane must not depend on PR-only event fields); + - keep `docs-flow` / `flow-online` guarded to PR-only so the queue does not repeat the diff and online-consistency checks. +- Docs: add a "Merge flow: merge queue" section to `docs/development.md` / `.en.md` covering enqueue, queue build, failure re-queue, and rollback (disabling the ruleset's `merge_queue` rule restores plain merges). +- Agent Note: record why merge queue was chosen over strict-only and its cost. + +## Implementation steps + +1. Validate locally/on a test branch that `ci-ok` aggregates correctly under `merge_group` and that skipped lanes do not fail it. +2. Add `merge_group` to `ci.yml`; run `pnpm test:gates` and workflow syntax validation. +3. Add the `merge_queue` rule to the repository ruleset (requires repository admin). +4. Verify with two test PRs: enqueue both; confirm the second rebuilds on the first's merged main and passes; confirm a deliberately semantic-conflicting sample is blocked. +5. Update docs and the Agent Note; after merging, observe for a week before deciding whether to keep `strict`. + +## Dependencies and boundary + +- Dependencies: the `Protect main` required status checks (added 2026-11-25). +- Boundary: only the `ci.yml` trigger, the ruleset configuration, docs, and an Agent Note; no application code, tests, or check-content changes; no approval or bypass changes. + +## Verification + +```sh +pnpm test:gates +pnpm verify:flow +gh api repos/Shadow-Azure/harness-evolution/rulesets/25782062 --jq '.rules[].type' +``` + +- Expected: the ruleset rule list contains `merge_queue` and `required_status_checks`; `ci.yml` produces `ci-ok` for `merge_group`; two test PRs enqueue in order and the second queue build runs against the first's merged main; a semantic-conflict sample is blocked by the queue build. + +## Acceptance + +- `merge_group` triggers CI and `ci-ok` becomes the required check for queue builds; `docs-flow`/`flow-online` skip in the queue while `ci-ok` still passes. +- The second queued PR rebuilds on the new main automatically and passes; manual rebases are no longer required. +- A semantic-conflict sample cannot pass the queue build or be merged directly. +- `docs/development.md` / `.en.md` and the Agent Note are updated and `verify:docs` passes; disabling the `merge_queue` rule rolls back to plain merges. + +## Gates and CI + +- Hit: `pnpm test:gates`, `pnpm verify:flow`, `pnpm verify:docs` (docs changes), and CI's own lint/syntax. +- No new dependencies; queue builds reuse the existing lanes, costing one full CI run per enqueue (unit lane ~14 minutes). + +## Non-goals + +- No application code, test fixture, or `verify-flow --diff` semantic changes; `strict` is kept as a direct-merge fallback. +- No auto-merge enablement (evaluated separately); no approval-count, code-owner, or bypass changes. +- No self-hosted merge bot or third-party CI orchestration. diff --git a/.agents/flow/issues/bugfix-merge-queue-stale-base.i18n.yaml b/.agents/flow/issues/bugfix-merge-queue-stale-base.i18n.yaml new file mode 100644 index 00000000..d458744a --- /dev/null +++ b/.agents/flow/issues/bugfix-merge-queue-stale-base.i18n.yaml @@ -0,0 +1,5 @@ +# 双语配对一致性记录(docs/i18n/README.md):两侧在最后一次确认一致状态下的 +# git blob hash。两种语言同等权威;编辑任一侧后带上另一侧,然后重录: +# pnpm run record:i18n -- .agents/flow/issues/bugfix-merge-queue-stale-base.md +bugfix-merge-queue-stale-base.md: 4341ebbab1c6f8007180fe66d544f670ab863da5 +bugfix-merge-queue-stale-base.en.md: f7f1802a47a431a95117ab6214968e594d44263b diff --git a/.agents/flow/issues/bugfix-merge-queue-stale-base.md b/.agents/flow/issues/bugfix-merge-queue-stale-base.md new file mode 100644 index 00000000..4341ebba --- /dev/null +++ b/.agents/flow/issues/bugfix-merge-queue-stale-base.md @@ -0,0 +1,104 @@ +# 启用 merge queue,避免旧 base 上的绿色检查直接合入 + +[English](bugfix-merge-queue-stale-base.en.md) | 中文 + +```yaml flow +kind: issue +id: bugfix-61 +milestone: bugfix +depends: [] +priority: P2 +status: ready +scope: + - .agents/** + - .github/workflows/ci.yml + - docs/** + - plans/** +adr: [] +github: + number: 609 + url: https://github.com/Shadow-Azure/harness-evolution/issues/609 +``` + +## 背景 + +### 问题场景 + +2026-11-25 的 #589 / #562 事故是典型样本: + +- PR #589 的 CI 于 02:03Z–02:16Z 在 head `6adde1d4` 上全绿,当时的 base 还没有 CaseTools。 +- PR #562 于 03:09Z 合入 `f9ad7434`,新增 `CaseTools`,按旧 writer CLI 调用。 +- PR #589 于 06:21Z 合入 `744f4f57`(改 writer 为显式结论契约),合并结果从未被任何 CI 验证过:两个 PR 各自在各自 base 上都是绿的,拼在一起才红。 + +当时的直接原因之一是 `Protect main` ruleset 没有 required status checks;该缺口已于 2026-11-25 补齐(`required_status_checks: ci-ok`,`strict_required_status_checks_policy: true`)。但 `strict` 只解决“base 前进后必须更新分支并重跑”,并不改变检查对象——它仍然不验证“另一个 PR 先合入后,本 PR 的合并结果是否还成立”,只是用“手动 rebase + 全量重跑”把时间窗压短。 + +### 分析 + +- `strict` 的成本:单测 lane 约 14 分钟;每次 base 前进(并行 agent PR 场景下很常见),所有在途 PR 都要重新 update + 重跑,人工摩擦高,且仍然存在“更新后、合并前 base 再次前进”的窗口。 +- merge queue 的语义:PR 进入队列后,GitHub 基于**队列中最新的 main** 构造合并结果,并对该结果跑 required checks;通过才合入,后一个 PR 会自动基于前一个合入后的 main 重建。它验证的正是“合并结果”,而不是“旧 base 上的 PR head”。 +- 现状:仓库是 public,支持 merge queue;`.github/workflows/ci.yml` 只有 `pull_request` 与 `push` 触发,没有 `merge_group`;`Protect main` ruleset 只有 required_status_checks,没有 `merge_queue` 规则。若只加 ruleset 规则不加 `merge_group` 触发器,队列里的 required check 永远不会产生,队列会卡死。 + +## 目标 + +- 在 `Protect main` ruleset 增加 `merge_queue` 规则(squash 合并;`max_entries_to_build` / `max_entries_to_merge` / `min_entries_to_merge_wait_minutes` 按单维护者吞吐设置)。 +- `.github/workflows/ci.yml` 增加 `merge_group` 触发器,保证 `ci-ok` 聚合在队列构建中运行。 +- `docs-flow` / `flow-online` 保持 `if: github.event_name == 'pull_request'`(diff 门禁已在 PR 上执行);`ci-ok` 已把 skipped 视为通过,因此队列构建不会因这两条 lane 跳过而失败。 +- 保留 `strict_required_status_checks_policy: true` 作为“绕过队列直接合并”时的兜底。 +- 文档记录合并流程(PR → 入队 → 队列构建 → 合入)与回滚方式。 + +## 设计依据 + +- [`.agents/flow/README.md`](../README.md):GitHub 同步与门禁契约;PR 标题/提交 `(#N)` 与 diff scope 规则不变。 +- [`.github/workflows/ci.yml`](../../../.github/workflows/ci.yml):`ci-ok` 聚合 lane 的定义与“skipped 视为通过”的语义。 +- [docs/development.md](../../../docs/development.md):贡献者的日常循环与门禁摘要,需要补 merge queue 操作说明。 + +## 实现内容 + +- ruleset:`Protect main` 增加 `merge_queue`(`merge_method: squash`,`grouping_strategy` 与并发上限按 CI 时长设置;初始建议 `max_entries_to_build: 1`、`max_entries_to_merge: 1`、`min_entries_to_merge: 1`),保留现有 `required_status_checks`(`ci-ok`,strict)。 +- `ci.yml`: + - `on` 增加 `merge_group`; + - 确认 `ci-ok` 在 `merge_group` 事件下正常产生(聚合 lane 不依赖 PR-only 事件字段); + - `docs-flow` / `flow-online` 的 `if` 条件保持 PR-only,避免队列中重复跑 diff 门禁与在线一致性检查。 +- 文档:`docs/development.md` / `.en.md` 增加一节「合并流程:merge queue」,说明入队、队列构建、失败重排、回滚(关闭 ruleset 的 merge_queue 规则即恢复普通合并)。 +- Agent Note:记录选择 merge queue 而非“只靠 strict”的理由与成本。 + +## 实施步骤 + +1. 本地/测试分支验证 `merge_group` 触发下 `ci-ok` 正常聚合且 skipped lane 不判红。 +2. 改 `ci.yml` 增加 `merge_group`,跑 `pnpm test:gates` 与 workflow 语法校验。 +3. 在仓库 setings/ruleset 增加 `merge_queue` 规则(需仓库管理员权限)。 +4. 用两个测试 PR 验证:同时入队,第二个在第一个合入后自动重建并通过;构造一个语义冲突验证被拦。 +5. 更新 docs 与 Agent Note,PR 合入后观察一周再决定是否保留 strict。 + +## 依赖与交付边界 + +- 依赖:`Protect main` 的 required_status_checks(已于 2026-11-25 补齐)。 +- 交付边界:只改 `ci.yml` 触发器、ruleset 配置、docs 与 Agent Note;不改任何应用代码、测试或验证 lane 的检查内容;不改审批规则与 bypass 策略。 + +## 独立验证 + +```sh +pnpm test:gates +pnpm verify:flow +gh api repos/Shadow-Azure/harness-evolution/rulesets/25782062 --jq '.rules[].type' +``` + +- 预期:ruleset 规则列表出现 `merge_queue` 与 `required_status_checks`;`ci.yml` 在 `merge_group` 事件下产生 `ci-ok`;两个测试 PR 依次入队,第二个的队列构建基于第一个合入后的 main;语义冲突样本在队列构建中被拦。 + +## 验收标准 + +- `merge_group` 事件触发 CI,`ci-ok` 成为队列构建的 required check;`docs-flow`/`flow-online` 在队列中跳过但 `ci-ok` 仍通过。 +- 队列中的第二个 PR 在第一个合入后自动基于新 main 重建并通过;不再需要手动 rebase。 +- 语义冲突样本无法通过队列构建,也无法直接合并。 +- `docs/development.md` / `.en.md` 与 Agent Note 更新,`verify:docs` 通过;关闭 merge_queue 规则可回滚为普通合并。 + +## 门禁与 CI + +- 命中:`pnpm test:gates`、`pnpm verify:flow`、`pnpm verify:docs`(文档改动)、CI 自身的 lint/syntax。 +- 不新增依赖;merge queue 构建复用现有 lane,成本为每次入队一次全量 CI(单测 lane 约 14 分钟)。 + +## 非目标 + +- 不改应用代码、测试夹具或 `verify-flow --diff` 语义;不移除 `strict`(保留为直接合并兜底)。 +- 不启用 auto-merge(可另行评估);不改审批人数、code owner 或 bypass 策略。 +- 不引入自建合并机器人或第三方 CI 编排。