Skip to content

Add silent-revert and audit-merges report-only gates - #3397

Open
Birfy wants to merge 8 commits into
mainfrom
dev/3393-audit-gate
Open

Birfy wants to merge 8 commits into
mainfrom
dev/3393-audit-gate

Conversation

@Birfy

@Birfy Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Related #3393

Two report-only gates beside the existing workflows, and the scripts they run. All 15 files are new; nothing existing is edited, and tests.yml is byte-identical to main (sha256 6f60af36d734e48933f585e05857c2878f6673430065742568603fdea57fe2a9). compare/34a80ca5a1...1a356fa21b reports 0 entries for .github/workflows/tests.yml.

What it adds

file lines what it does
.github/scripts/silent-revert.mjs 216 reports lines this pull request deletes that main added after the merge base
.github/scripts/audit-merges.mjs 190 reports commits on main that skipped the merge queue
.github/workflows/silent-revert.yml 59 runs the first on pull_request
.github/workflows/audit-merges.yml 60 runs the second daily and by hand
5 fixtures + 3 test files 2003 recorded real trees and the gate's own cases

Evidence level of this slice

Only local dry runs so far. No real run exists for either workflow, and none can exist before this merges into the default branch: audit-merges.yml runs on schedule (a schedule only fires from the default branch) and on workflow_dispatch; silent-revert.yml runs on pull_request, so it will first run on the pull requests that follow this one, not on this one. Do not read the local runs below as CI state.

What was actually run, on the head bytes pulled back from the API (not the working copy):

  • node --test '.github/scripts/*.test.mjs' → tests 55 / pass 55 / fail 0, skipped 0.
  • silent-revert.mjs against a real git replay of recorded sample #886 @ cf907be7 (base/main/head rebuilt from the fixture's A and D line sets): prints #886 @fac476e: plugins/social/src/social.js: 90 line(s) … and … /social.test.js: 270 line(s) …, 2 finding(s) on 2 file(s) — source 1, test 1, exit 0. The counts are the fixture's own A ∩ D.
  • audit-merges.mjs through its real CLI (gh doubled by a fixture-answering stub): a mixed walk prints bypassed queue: #680 … (merge_group: failure), bypassed queue: #622 … (merge_group: absent), direct commit: 0d1e2f3a…, exit 1; a queue-only walk prints 0 bypassed the queue, 0 direct, exit 0; --since <sha> and --baseline print earlier … lines and exit 0.

Gate identity is an env value, not a constant

.github/scripts/audit-merges.mjs keeps merge-gate.yml / Merge gate as its defaults so the recorded fixtures stay the real old-line merges they are. The workflow passes the current gate instead:

env:
  GATE_PATH: .github/workflows/tests.yml
  GATE_NAME: FlyBot required checks

That is the whole change to the old script: two lines reading process.env.GATE_PATH / process.env.GATE_NAME, used by isGateRun. Proof of both directions on the same data: with the env set, a merge carrying a green FlyBot required checks run on tests.yml is recognised as queued while #680 (gate run failure) is still reported; without the env, both merges read as (merge_group: absent).

Fixtures are real samples, referenced by their historical blob sha

No fixture text was re-uploaded: each is the blob that already exists in this repository's object store, referenced by sha, so the bytes are exactly the recorded ones.

fixtures/silent-revert/886-cf907be7.json      569740caac826b7c92fb842f6162ed668ee7c3a0   82425 B
fixtures/silent-revert/907-b8b582bd.json      0263f71d5b9279a47e4cc824ad6283216a4c8e62   45237 B
fixtures/silent-revert/910-07dee97d.json      3cf20a60620ac619c31b1876ee48ac985541510c    5844 B
fixtures/audit-merges/absent.json             31c9b0657536104b16e4ded55f279d898ee6aeda     517 B
fixtures/audit-merges/bypassed.json           b29e1cdf1bd03224eabde9244bbb686b1c8ef797     774 B
fixtures/audit-merges/direct.json             2076ba6b02c03dbc257c6240c302979e42071b4f     377 B
fixtures/audit-merges/queued.json             0fb059ee96230e467c57fbba7832ad2786cbe186     675 B
fixtures/audit-merges/since.json              536d3b600e188ddf08c9fcac1d9a466a8296ac08    1612 B

#886 and #907 are the two pull requests that deleted merged work and stayed green; #910 is the negative control whose A was empty at its base and which must keep reporting nothing.

Why silent-revert has no schedule

The check is head-vs-base for one pull request. On main its A is empty by construction, so a scheduled run there could only print a clean line — a false signal. It runs on pull_request (opened, synchronize, reopened) and workflow_dispatch (with an optional pr input).

The script comes from the base commit (git show origin/main:.github/scripts/silent-revert.mjs > base.mjs), so a pull request cannot weaken the check that judges it. The one exception is this repository's own condition: the pull request that adds the script has no base copy, so that single run falls back to its own copy under the same read-only token. That exception is asserted in silent-revert-collect.test.mjs, together with fetch-depth: 0, the explicit git fetch origin main, the read-only permissions, if: github.event_name == 'pull_request', and continue-on-error — a report-only gate that can turn a pull request red is a required check nobody agreed to.

Check names

silent-revert and audit-merges. Neither is, nor replaces, FlyBot required checks; neither introduces tests-ok or enqueue-guard. Both workflows are contents: read (plus actions: read, pull-requests: read for the audit), and neither comments, labels, approves or merges.

Known limits

  • audit-merges reads main's last N commits (default 50) and needs the gate's identity from env; a repository that renames its gate again must update the workflow's env, or every merge starts reading as absent.
  • The audit's own watermark is the head sha of the last successful audit-merges run; a day with no successful run widens the next scan rather than skipping it.
  • silent-revert compares line text, not blame: a re-indented or re-worded line is not a hit, and a legitimate revert is reported too — a Reviewer reads it, nothing blocks on it.
  • This slice does not add either gate to branch protection, and does not change the required check set.

Related #3393

Two report-only workflows beside the existing ones, and the scripts they run:

- silent-revert.yml: on pull_request, runs the base commit's copy of
  .github/scripts/silent-revert.mjs against the pull request's own files
  (base..HEAD), and reports lines that revert lines main added. On the one
  pull request that adds the script there is no base copy, so that single run
  uses its copy under the same read-only token.
- audit-merges.yml: on a daily schedule and by hand, lists merged pull
  requests since the previous successful run and reports any whose merge
  commit did not carry the passing gate run the merge-gate rules require.
- Neither workflow writes to the repository, and neither is named, nor
  replaces, FlyBot required checks. tests.yml is untouched.
@Birfy

Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Correcting one line of the description, on head 1a356fa21b09aa6f0dd6d9dd3ff7bf863403fd05.

The description says no real run exists for either workflow. That is now false for one of them, because a pull_request workflow runs from the head of the pull request that adds it — the same mechanism that let risk-tier run on #3396.

Real run, silent-revert: run 45774459367, event pull_request, path .github/workflows/silent-revert.yml, head_sha 1a356fa21b09, created 07:19:31Z, completed success in 15 s. Check-run name is silent-revert — not FlyBot required checks, not tests-ok, not enqueue-guard. It is a separate run from FlyBot CI (45774459236); this head carries 16 check-runs in total, 15 of them from FlyBot CI plus this one.

What that run exercised is the documented exception, not the normal path: main has no .github/scripts/silent-revert.mjs, so git -C head show origin/main:… writes an empty file, [ -s "$script" ] fails, and the step falls back to the head copy. The base-copy path — the one that makes a pull request unable to weaken the check that judges it — has no real run yet, by construction: it first runs on the pull requests that come after this one.

Still no real run, audit-merges: it triggers on schedule and workflow_dispatch only. A schedule fires from the default branch alone, so nothing can run it before this merges. The evidence for it remains the local dry runs in the description (real CLI process, gh answered from the recorded fixtures), and that stays labelled local until it has a run of its own.

Related #3393

`continue-on-error: true` on the audit step turned a run that reported a finding
green. The watermark is the last *green* run of this workflow, so the next run
took that run's head_sha as `--since` and signed yesterday's bypasses off as
`earlier`: each bypassed merge showed up once, in a green run nobody opens. The
comment above the watermark and the script's `exit 1` both promise the opposite.

Report-only means it blocks no pull request and writes nothing, not that it can
never be red. The first run is `--baseline` (every finding is earlier, exit 0),
so removing the line does not start red. tests.yml is untouched.
@Birfy

Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

New head: 7add160048376c2b0d00f2638e201996cf32388d (choice A, one line)

Previous head 1a356fa2 is superseded. The whole diff of the change, against 1a356fa2:

       - name: Audit the last merges on main
-        continue-on-error: true
         env:

That is the only line removed. audit-merges.mjs and audit-merges.test.mjs are byte-identical to 1a356fa2; silent-revert.yml and tests.yml are untouched. compare/34a80ca5a1...7add1600 → 15 files, +2642 −0 (one line fewer than before), .github/workflows/tests.yml 0 entries.

Why A, in the file's own terms: the watermark is the last green run of this workflow (runs?status=success). With the step swallowing exit 1, a run that reported a finding was green, the next run took its head_sha as --since, and every bypass before it became earlier — reported once, in a green run nobody opens. Report-only means it blocks no pull request and writes nothing; it does not mean it can never be red. The first run is --baseline (every finding is earlier, exit 0), so removing the line does not start red.

Wiring table, corrected

workflow job / check name triggers required can it turn red?
audit-merges.yml audit-merges schedule (41 3 * * *) + workflow_dispatch no yes — a finding after the watermark makes the run red; --baseline is green
silent-revert.yml silent-revert pull_request (opened/synchronize/reopened) + workflow_dispatch no no, by design — the script reports and exits 0, and the step keeps continue-on-error on pull_request. It is a warning-level check; do not use it as a required gate as-is (that would need dropping the exit-0 design or reading the step summary)

Both are non-required, neither is named nor replaces FlyBot required checks.

Still open, not changed here (you narrowed the scope to one thing)

silent-revert.yml:14 has workflow_dispatch.inputs.pr: required: false, while the checkout ref is refs/pull/${{ … || inputs.pr }}/head: dispatching by hand with the input empty checks out refs/pull//head and fails before the step's friendly ::error::workflow_dispatch needs the pr input can run. One-word fix (required: true), say the word and it goes in with the next slice rather than this one.

Evidence, on the new head's own bytes (codeload tarball of 7add1600)

$ sha256sum .github/workflows/{audit-merges,silent-revert,tests}.yml
db1903a9a8d888b0a0955cfa8be48dfe37e306a7b9e0e5a05e9c1ca53be140a4  audit-merges.yml
7812c3f9eece3ef60de9f51cfa5bd17ec353838a7d8e73407d1056b7baa6b74b  silent-revert.yml
6f60af36d734e48933f585e05857c2878f6673430065742568603fdea57fe2a9  tests.yml   ← same as main

$ grep -n continue-on-error .github/workflows/audit-merges.yml
(none)

$ node --test '.github/scripts/*.test.mjs'
ℹ tests 31 / pass 31 / fail 0 / skipped 0
逐文件: silent-revert.test.mjs 10, silent-revert-collect.test.mjs 3, audit-merges.test.mjs 18

The 31 is the correct number for this slice (my earlier 55/55 was the two branches' tests together; risk-gate* files are not in this PR).

Dry runs re-checked against the new bytes, unchanged behaviour: PR=886 … silent-revert.mjs --repo-dir replay-886 → 90 line(s) on plugins/social/src/social.js, 270 line(s) on plugins/social/test/social.test.js, silent-revert: 2 finding(s) on 2 file(s) — source 1, test 1, exit 0. audit-merges.mjs with the gh shadow + mixed fixture → 4 commits on main, 2 bypassed the queue, 1 direct, exit 1; with --baseline → same three as earlier …, exit 0.

CI on this head

/commits/7add1600/check-runs → 16 checks, silent-revert completed success in run 45776064097 (job 139759889852) — that is the pull_request path again, i.e. wiring only. audit-merges has no run and, being schedule + workflow_dispatch, cannot have one before this file is on the default branch. At the sample I took the rest of FlyBot CI (45776064126) was still in progress, so I am not claiming that run's result here.

Local green and CI green are separate: 31/31 is local, on the downloaded head bytes, and tests.yml does not run .github/scripts/*.test.mjs at all, so no CI run of this PR exercises these 31 tests.

…umber

Related #3393

Two changes in the gate's glue:

- drop `continue-on-error: ${{ github.event_name == 'pull_request' }}`: a finding
  already leaves the run green, because the script exits 0. The only thing that
  line bought was painting a run that could not do its job green as well — no
  `origin/main`, a shallow history, no git. Finding green: yes. Broken green: no.
  That is the same line, for the same reason, just removed from audit-merges.yml.
- `workflow_dispatch.inputs.pr: required: true`. With the input empty the
  checkout ref was `refs/pull//head`, so the run failed in checkout and the
  step's own `::error::workflow_dispatch needs the pr input` was unreachable.

A new small test file pins the wiring: no `continue-on-error` in either gate's
workflow, audit-merges keeps both its watermark run and its `--baseline` first
run, and a silent-revert run against a directory that is not there exits 1.
Related #3393

The test named "it cannot turn the run red" matched the `continue-on-error` line
that is now gone, so it pinned the wrong contract. It now asserts the opposite:
the step has no `continue-on-error`, so a run that cannot do its job (no
`origin/main`, shallow history, no git) is red, while a finding still leaves the
job green because the script exits 0. Name and comment say that.
Related #3393

The watermark is looked up by workflow file name, and a workflow of that name
exists in a deleted state (id 392609103, 36 runs, last success head bab1fe9 on
2026-11-24). If the lookup returns that one, the first run here is not a
baseline: its log opens with `audit-merges: watermark ... (from ...)` and it
judges what came after bab1fe9, not the whole history.

Comment only. The filter is left alone, because it is not known yet which
workflow id the name resolves to once this file is on the default branch; the
first scheduled run's first line settles it.
Related #3393

The previous commit rewrote the whole file instead of adding the four comment
lines, so the job id, the runner, the timeout and the checkout pin came out as
another version's values. This restores the file byte for byte from 19861a5 and
adds nothing but the comment.
Related #3393

The restore dropped the newline at the end of the file, so it was not yet byte
for byte the original. One byte, same content.
@Birfy

Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Final head: 0730d9a51ac68ba49b160979b97c54b790d2419c — 7 commits, 16 files, +2690/−0 against main 34a80ca5a1.

The three review items from the thread, plus one comment-only record fix and the wiring test:

  1. silent-revert.yml no longer swallows its exit code. continue-on-error: ${{ github.event_name == 'pull_request' }} (:46 at 1a356fa2) is gone. A finding still exits 0, so the report stays green; a run that cannot do its job (no origin/main, shallow history, no git) sets exit 1 and is red.
  2. The test that pinned the swallow now pins the opposite. .github/scripts/silent-revert-collect.test.mjs — renamed to workflow: report only, base copy of the script, full history, and only a real failure turns it red, and the assertion is now assert.doesNotMatch(step, /continue-on-error/).
  3. workflow_dispatch.inputs.pr is required: true (:15), so an empty input can no longer fail in checkout before the script's ::error:: line can fire.
  4. audit-merges.yml: four comment lines above the watermark lookup. The file name may still resolve to the deleted workflow of the same name (id 392609103, 36 runs, last success head bab1fe96 on 2026-11-24), in which case the first run's log opens with audit-merges: watermark … (from …) rather than audit-merges: baseline run. No change to the filtering. After merge, read the first line of the first scheduled run: if it is a watermark, the filter gets its own slice.
  5. New .github/scripts/audit-merges-wiring.test.mjs (4 tests) pins the glue: neither gate carries continue-on-error, audit-merges keeps both the watermark and the baseline path, pr stays required, and a run with an unreadable repository exits 1.

A bad commit in this history, named on purpose. 50113053 rewrote audit-merges.yml from memory instead of adding the comment, so the job id, runner, timeout and checkout pin came out as another version's values. 33a91097 restored the file byte for byte and 0730d9a5 gave back its final newline. The blob at head is d611632b, which is 19861a53's copy plus exactly those four comment lines — nothing from 50113053 or 33a91097 survives.

Local tests, on this head's own bytes (node --test '.github/scripts/*.test.mjs', extracted from the tarball of 0730d9a5):

tests 35 / pass 35 / fail 0
silent-revert.test.mjs 10, silent-revert-collect.test.mjs 3, audit-merges.test.mjs 18, audit-merges-wiring.test.mjs 4

tests.yml sha256 6f60af36d734e48933f585e05857c2878f6673430065742568603fdea57fe2a9 — unchanged, and compare lists 0 entries for it. grep -n continue-on-error over silent-revert.yml and audit-merges.yml → no output (the two left in ds-bot-upstream-track.yml:79/:97 are on main already and are not part of this slice).

CI on this head (/commits/0730d9a5/check-runs, 16 checks): completed success | silent-revert — run 45778126618. The rest of the matrix was in_progress when this comment was written, so this comment does not call it green.

What this does not prove. audit-merges has no run here and cannot have one before merge: schedule runs the default branch's copy and workflow_dispatch only exists there, so on a pull request it is absent, not pending. Its evidence is local — the PR=886 replay prints two findings (90 source lines, 270 test lines), the mixed fixture exits 1, --baseline exits 0. That replay rebuilds the three trees from the fixture's recorded lines, because refs/pull/886/head is no longer on the remote: the from commit the script prints is a synthesized commit, not cf907be7.

The workflow deleted that line; the file header still described it as part of
the design, so the same delivery said two different things. A finding exits 0
and stays green, a script that cannot run exits 1 — the header now says that.

Related #3393
@Birfy

Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Final head: c982f9a2d23f34538918c95f36a466ed56d2421e

Supersedes the 0730d9a5 evidence above for the file this commit touches. Parent 0730d9a5, tree 11b2bedd43ea205064a793706a2db92651236fdb.

The one change: .github/scripts/silent-revert.mjs header comment, 5 lines added / 4 deleted, one file. The workflow deleted its continue-on-error in an earlier head, but the file header still listed it as part of the design — the same delivery said two things. The header now says what the machine does:

// Report only. Read-only token, `$GITHUB_STEP_SUMMARY` and one `::warning` per file: never a
// comment, a label, a review or a merge, and nothing reads it to block. A finding exits 0, so the
// job stays green; a script that cannot run exits 1. A legitimate revert simply carries the report
// and a Reviewer decides. The script and this file are taken from the base commit by the workflow,
// so a pull request cannot weaken the check that judges it.

read-only token stays: both workflows still request contents/actions/pull-requests: read. No behaviour changed — a comment only.

Verified on the remote bytes of this head (codeload refs/pull/3397/head, not a working copy):

  • blob of silent-revert.mjs = 157b7f5ea2b45820d6e4aff22531925b78fd7dbd, 9802 B, 217 lines (was 25ee2d5c, 9743 B) — matched the blob computed locally before the commit, byte for byte;
  • tree built from the tarball with git add -A -f + git write-tree = 11b2bedd…, equal to the API's new_tree_sha;
  • diff -rq against the 0730d9a5 tree: one differing file, this .mjs;
  • tests.yml still blob 5bae353e, sha256 6f60af36d734e48933f585e05857c2878f6673430065742568603fdea57fe2a9 — byte-identical to main;
  • silent-revert.yml blob 2629d416 (unchanged), audit-merges.yml blob d611632b (unchanged), silent-revert.yml:15 still required: true;
  • node --test '.github/scripts/*.test.mjs' → tests 35 / pass 35 / fail 0 / skipped 0;
  • grep continue-on-error over both new workflows and this .mjs → no match.

CI on this head: 16 check-runs, 8 completed success (silent-revert among them, run 45780089222), 8 still in progress in run 45780089323. Not green yet — this comment will not claim it is.

Related #3393

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.

1 participant