Skip to content

ci: give risk-gate a pull_request trigger that writes the risk:T* label - #3404

Merged
Birfy merged 3 commits into
mainfrom
dev/3393-risk-gate-wiring
Nov 27, 2026
Merged

Birfy merged 3 commits into
mainfrom
dev/3393-risk-gate-wiring

Conversation

@Birfy

@Birfy Birfy commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Related #3393.

Slice

Give the risk tier a producer. Until now risk:T* was a label a human typed, so done-when item 4 ("the label is written by a script") had no machine behind it. This adds the workflow that writes it, the script it calls, and the offline tests for that script. One slice, three new files, nothing else touched (tests.yml is untouched).

How the label is decided and written

  • Trigger: pull_request on opened, synchronize, reopened, one concurrency group per PR with cancel-in-progress, 5 minute timeout.
  • The checkout is ref: pull_request.base.sha. The script and the rules table that judge a PR are the ones on main; a PR cannot ship a rules table that grades its own diff.
  • risk-gate-label.mjs computes the tier with the existing risk-gate.mjs engine and then converges the label set: every other risk:T* is deleted, the target is added, and a run that already finds the target sends no write at all. So a re-run, a cancelled run and a re-push all end at exactly one risk:T* label. It posts no comment - the tier and its reasons stay in the run summary - so there is no second copy to keep in sync.
  • Dry run is the default: without --apply it prints the change and writes nothing, so only the workflow can change a PR.
  • permissions: contents: read + pull-requests: write, nothing else.

Two things a reader should know

  1. The first run on this PR is expected to be red: the workflow is defined by the PR's head but checks out the base commit, and main does not contain risk-gate-label.mjs yet, so the step fails with a missing module. The failure step says so and names the two causes it cannot fix itself. The first PR that gets its label from the script is the one opened after this merges.
  2. The labels risk:T0 to risk:T3 all already exist in this repository, so the workflow has something to attach.

Not doing

  • The timing coupling with merge-gate (gate 4 fails closed on a missing label, and a label written after that run has already started needs a re-run or a labeled trigger) is a separate slice.
  • Binding the label to the head sha (risk:T2@<sha>) touches the regex, gate 4 and this script together; separate slice.
  • tests.yml does not yet run .github/scripts/*.test.mjs; one separate line, separate PR.

Evidence (head 4b92184)

  • Pushed tree b107e677 equals the tree of the reviewed local commit 22b928e7; the three blobs are bafdee9f (script), 55551b07 (tests), 32f17ca2 (workflow).
  • Local green: node --test .github/scripts/*.test.mjs -> tests 39 / pass 39 / fail 0 (24 risk-gate + 8 merge-gate + 7 new).
  • Local green: node .github/scripts/merge-gate.mjs --self-test -> self-test: 5/5 cases as expected, including risk:T3 is advisory, not a blocker.
  • The tests use a stub API inside the test process: no network, no token, nothing leaves the machine.
  • Check name added: Risk tier label, which is neither FlyBot required checks nor contains tests-ok / enqueue-guard.
  • CI green: reported separately once checks run on this head.

Review

A review comment bound to this head follows separately; a new commit invalidates it.

Pure labelPlan(tier, labels) plus a CLI that converges instead of stacking:
labels of another tier are removed, the target is added, and a run that
already finds the target sends no write. It posts no comment; the tier and
its reasons stay in the run summary from risk-gate.mjs. Without --apply it
writes nothing. Related #3393.
The workflow is the only producer of the label. It checks out the base
commit, so the script and the rules table that judge a pull request are the
ones already on main and never the pull request's own copies. Minimal
permissions (contents: read, pull-requests: write); a failure says in the
run summary that no label was applied, and the gates in tests.yml are not
affected. Related #3393.
Four cases on the pure write rule and three on the command: --apply sends
exactly the two writes, a re-run sends none, a dry run sends none, no
comment is ever posted, and a 403 fails loudly instead of claiming success.
The API is a stub in the test process, so nothing leaves the machine and no
token is needed. Related #3393.
@Birfy

Birfy commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Review 4b92184 (PR #3404)

Related/Refs: present, Related #3393 only; no Fixes / Closes / Resolves as a link.
Slice: single slice - the label producer (workflow + script + its tests). tests.yml untouched, no other file in the diff.
Binding: conclusions bound to head 4b92184, tree b107e677, identical to the tree I reviewed at 22b928e7; blobs bafdee9f / 55551b07 / 32f17ca2.
Local green: node --test .github/scripts/*.test.mjs 39/39 pass, 0 fail; node .github/scripts/merge-gate.mjs --self-test 5/5 including the advisory-T3 case. I re-ran these myself in the worktree, not from the report.
CI green: not read. The connector's check-run listing returns a body this machine rejects, and the only small channel left is anonymous REST, which the user has asked us to stop using. What I can state is machine-verified: the merge queue will only merge this head if the required checks pass on it. No claim of per-run green.
Risk: script output T3 (.github/** hits the T3 paths) - matches the label the workflow will apply; the Tier is advisory, not a veto.
Check name: Risk tier label. Neither FlyBot required checks nor anything containing tests-ok / enqueue-guard. The 7 suite jobs and the aggregate gate in tests.yml are byte-identical to main.
Permissions: contents: read + pull-requests: write, no issues: write, so the job cannot create repository labels - which is why it fails loudly instead of pretending.
What I accept as a known, stated limit: the first run on this PR is expected red because the base commit has no risk-gate-label.mjs. The failure text says so. The label producer gets its first real exercise on the next PR after this merges.
Send back / release: release with two follow-ups in the next stage - (1) the merge-gate timing coupling (a label written after gate 4 ran needs a re-run or a labeled trigger), (2) binding the label to the head sha (risk:T2@<sha>) which must change the regex, gate 4 and this script in one slice.

@Birfy

Birfy commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Review 4b92184 (PR #3404)

Related/Refs: Related #3393 only; no Fixes / Closes / Resolves in the diff or the body.
Slice: one slice — three new files, nothing modified: .github/workflows/risk-gate.yml, .github/scripts/risk-gate-label.mjs, .github/scripts/risk-gate-label.test.mjs (269 lines added). tests.yml is untouched.
Binding: every conclusion below is bound to head 4b921842. A new commit voids it.

Local green (run at this head in a clean worktree, not in CI):

  • node --test .github/scripts/risk-gate-label.test.mjs → 7/7 pass
  • regression over the gates already on main, same head: risk-gate.test.mjs + risk-gate-judge.test.mjs + risk-gate-api.test.mjs + merge-gate.test.mjs → 32/32 pass
  • node .github/scripts/merge-gate.mjs --self-test → 5/5, including risk:T3 is advisory, not a blocker: exit 0

CI green: not claimed. I have no reading for this head: the connector's check-runs and pull-request endpoints both answer tool_output_too_large through this proxy, and anonymous api.github.com is off-limits since 2026-11-27.

The "Risk tier label" run on this PR itself is expected to be red, and I say so before it happens rather than after. The workflow checks out github.event.pull_request.base.sha and then runs .github/scripts/risk-gate-label.mjs; on this PR the base is main 97fd976b, which does not contain that file, so the step fails with a module-not-found error. It turns green for the next pull request after this one merges. That is the price of reading the script and the rules from the base — a pull request must not judge its own diff — not a defect in the wiring. Do not read that red as "the wiring is broken", and do not let anyone re-run it hoping for green: on this head it cannot go green.

Two consequences stated in the workflow itself and worth repeating here: a pull request from a fork gets a read-only GITHUB_TOKEN and cannot be labelled, and the four risk:T0..risk:T3 labels must already exist in the repository because the job has no issues: write.

Risk: T3 from risk-tier.judge over the git diff (3 files, 269 lines): every path under .github/** is T3, plus pattern hits in the label writer (token env read) and in its test (child_process). Advisory only — T3 does not block; this merges on the Lead's decision once FlyBot required checks are green.

Still open after this PR, not asked for here: .github/scripts/*.test.mjs still do not run in CI, so the seven new tests are local-only evidence until that slice lands.

Release — no defect found in this slice.

@Birfy
Birfy added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 4a3e7a0 Nov 27, 2026
16 of 17 checks passed
@Birfy
Birfy deleted the dev/3393-risk-gate-wiring branch November 27, 2026 04:07
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