FORGE-472: auto-merge gates on every check at the exact head and on a real approval #1289

Open
gmackie wants to merge 1 commit from FORGE-472-merge-gate into main
Owner

Fixes FORGE-472. Related: FORGE-458 (the feature), FORGE-443 (where it was seen).

Why both PRs got through

Both were merged by the FORGE-458 cron green sweep (packages/api/src/automerge/green-sweep.ts); production changeset_events show "ForgeGraph merged PR #N at : CI green", required: [].

  • controlsFoundry #99, changeset:nix red: the sweep read only Forgejo commit statuses. changeset:nix is a ForgeGraph builds row (provider native), not a Forgejo status, so it was never evaluated. At head 2cdf669: forgejo:CI passed 13:08Z, changeset:nix failed 12:41Z, merged 13:16Z.
  • bob #338, no review: the sweep recorded an approval itself, as the workspace owner (idempotency key auto-merge-green:<sha>), then merged 7 s later. Nobody approved head 3777c5f.

The gate now (decideMergeGate, pure, at the exact head)

  • Forgejo Actions: the base branch's required contexts present and passed, or every CI status when unprotected. On a protected branch an advisory check may have failed, but one still running blocks.
  • ForgeGraph pipelines (changeset:nix|manifest|mise) are always required. The newest run of each at the head must have passed, and none the changeset ran on earlier heads may be missing (a first head expects the repo's last pipeline from the past 7 days). Runs for other heads are stale and never count.
  • At least one check; settling and AUTO_MERGE_GREEN_SINCE as before.
  • An approval at the head from a person or agent (fg pr approve), and no reviewer's latest verdict "changes requested". The sweep never approves on its own, and its old auto-merge-green: approvals never count.
  • Pending, failed, cancelled, missing and stale checks all block. The merge stays pinned to the head, so each push is evaluated from scratch.

Record

Every decision is logged as fg.merge_gate (checks evaluated with source and status, approvers, reason, actor). A merge also stores the checks, approvers and actor on the changeset's merged event (issue: FORGE-472).

Behaviour change

Green PRs now wait for an fg pr approve at their head instead of being approved by the cron. CLAUDE.md is updated.

Tests

  • green-sweep.test.ts: a table of 37 gate cases (the acceptance cases, plus pending/failed/cancelled/missing/stale pipelines and Forgejo checks, protected branches, settling, and approvals: stale, automatic, changes requested, superseded verdicts), plus the decision record.
  • green-sweep.database.test.ts: the three acceptance cases through the real sweep (red nix: not merged; no approval: not merged; green and approved: merged, with the log line and merged event checked), plus stale approval/pipeline and automatic approval. Against the old code, 6 of the 11 fail, including the red-nix and no-approval cases.
  • Locally: vitest unit (52) and database (11, PGlite), tsc for @forgegraph/api, oxlint clean (warnings only on lines that were already there).

🤖 Generated with Claude Code

Fixes FORGE-472. Related: FORGE-458 (the feature), FORGE-443 (where it was seen). ## Why both PRs got through Both were merged by the FORGE-458 cron green sweep (`packages/api/src/automerge/green-sweep.ts`); production `changeset_events` show "ForgeGraph merged PR #N at <sha>: CI green", `required: []`. - **controlsFoundry #99, `changeset:nix` red:** the sweep read only Forgejo commit statuses. `changeset:nix` is a ForgeGraph `builds` row (provider `native`), not a Forgejo status, so it was never evaluated. At head 2cdf669: `forgejo:CI` passed 13:08Z, `changeset:nix` failed 12:41Z, merged 13:16Z. - **bob #338, no review:** the sweep recorded an approval itself, as the workspace owner (idempotency key `auto-merge-green:<sha>`), then merged 7 s later. Nobody approved head 3777c5f. ## The gate now (`decideMergeGate`, pure, at the exact head) - Forgejo Actions: the base branch's required contexts present and passed, or every CI status when unprotected. On a protected branch an advisory check may have failed, but one still running blocks. - ForgeGraph pipelines (`changeset:nix|manifest|mise`) are always required. The newest run of each at the head must have passed, and none the changeset ran on earlier heads may be missing (a first head expects the repo's last pipeline from the past 7 days). Runs for other heads are stale and never count. - At least one check; settling and `AUTO_MERGE_GREEN_SINCE` as before. - An approval at the head from a person or agent (`fg pr approve`), and no reviewer's latest verdict "changes requested". The sweep **never approves on its own**, and its old `auto-merge-green:` approvals never count. - Pending, failed, cancelled, missing and stale checks all block. The merge stays pinned to the head, so each push is evaluated from scratch. ## Record Every decision is logged as `fg.merge_gate` (checks evaluated with source and status, approvers, reason, `actor`). A merge also stores the checks, approvers and actor on the changeset's `merged` event (`issue: FORGE-472`). ## Behaviour change Green PRs now wait for an `fg pr approve` at their head instead of being approved by the cron. CLAUDE.md is updated. ## Tests - `green-sweep.test.ts`: a table of 37 gate cases (the acceptance cases, plus pending/failed/cancelled/missing/stale pipelines and Forgejo checks, protected branches, settling, and approvals: stale, automatic, changes requested, superseded verdicts), plus the decision record. - `green-sweep.database.test.ts`: the three acceptance cases through the real sweep (red nix: not merged; no approval: not merged; green and approved: merged, with the log line and `merged` event checked), plus stale approval/pipeline and automatic approval. Against the old code, 6 of the 11 fail, including the red-nix and no-approval cases. - Locally: `vitest` unit (52) and database (11, PGlite), `tsc` for `@forgegraph/api`, `oxlint` clean (warnings only on lines that were already there). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FORGE-472: auto-merge gates on every check at the exact head and on a real approval
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Has been cancelled
CI / gitleaks (pull_request) Has been skipped
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / web-build (pull_request) Has been skipped
CI / checks (pull_request) Has been skipped
CI / unit-api (pull_request) Has been skipped
CI / unit-web (pull_request) Has been skipped
CI / database (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / ci (pull_request) Failing after 4m57s
Preview / e2e (pull_request) Has been cancelled
Preview / release (pull_request) Has been cancelled
f6b94db04c
The FORGE-458 green sweep merged controlsFoundry #99 with changeset:nix red
and bob #338 with nobody's review:

- it read only Forgejo commit statuses, and ForgeGraph's own changeset:*
  pipelines are build rows, so changeset:nix was never evaluated;
- it recorded an approval itself, as the workspace owner, and merged on it.

The sweep's gate (decideMergeGate) now requires, at the exact head:
Forgejo checks as before (required contexts, or every check unprotected;
an advisory check still running blocks), every ForgeGraph pipeline's newest
run passed with none the changeset ran before missing, at least one check,
settling, and an approval from a person or agent with no changes requested.
It never approves on its own, and its old automatic approvals never count.
Pending, failed, cancelled, missing and stale checks all block. Every
decision is logged as fg.merge_gate with the checks evaluated and the
approvers, and a merge stores the same on its merged event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmackie force-pushed FORGE-472-merge-gate from f6b94db04c
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Has been cancelled
CI / gitleaks (pull_request) Has been skipped
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / web-build (pull_request) Has been skipped
CI / checks (pull_request) Has been skipped
CI / unit-api (pull_request) Has been skipped
CI / unit-web (pull_request) Has been skipped
CI / database (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / ci (pull_request) Failing after 4m57s
Preview / e2e (pull_request) Has been cancelled
Preview / release (pull_request) Has been cancelled
to 7838eda32f
All checks were successful
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 29s
CI / gitleaks (pull_request) Successful in 4m14s
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / unit-api (pull_request) Successful in 54s
CI / unit-web (pull_request) Successful in 44s
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / checks (pull_request) Successful in 8m7s
CI / web-build (pull_request) Successful in 8m20s
CI / database (pull_request) Successful in 18m36s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 1m24s
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
2026-11-23 22:56:05 +00:00
Compare
gmackie force-pushed FORGE-472-merge-gate from 7838eda32f
All checks were successful
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 29s
CI / gitleaks (pull_request) Successful in 4m14s
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / unit-api (pull_request) Successful in 54s
CI / unit-web (pull_request) Successful in 44s
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / checks (pull_request) Successful in 8m7s
CI / web-build (pull_request) Successful in 8m20s
CI / database (pull_request) Successful in 18m36s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 1m24s
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
to 87759ca50f
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 12s
CI / gitleaks (pull_request) Successful in 37s
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / checks (pull_request) Successful in 3m51s
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / unit-web (pull_request) Successful in 10m31s
CI / unit-api (pull_request) Successful in 14m10s
CI / web-build (pull_request) Failing after 16m56s
CI / database (pull_request) Successful in 15m56s
CI / ci (pull_request) Failing after 10m57s
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
forgegraph/ci CI passed
2026-11-24 00:34:22 +00:00
Compare
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 12s
CI / gitleaks (pull_request) Successful in 37s
Required
Details
Preview / deploy (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / checks (pull_request) Successful in 3m51s
CI / database-d1 (pull_request) Has been skipped
CI / go (pull_request) Has been skipped
CI / unit-web (pull_request) Successful in 10m31s
CI / unit-api (pull_request) Successful in 14m10s
CI / web-build (pull_request) Failing after 16m56s
CI / database (pull_request) Successful in 15m56s
CI / ci (pull_request) Failing after 10m57s
Required
Details
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
forgegraph/ci CI passed
Some required checks were not successful.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin FORGE-472-merge-gate:FORGE-472-merge-gate
git switch FORGE-472-merge-gate
Sign in to join this conversation.
No description provided.