3535 # the addition and it is the point: flipping a governed draft to ready is
3636 # the first move of the exact sequence this guard exists to interrupt, and
3737 # it is not in the default set — without it the warning would not re-fire
38- # at the one moment a seat most needs to read it.
38+ # at the one moment a seat most needs to read it. That same flip is the
39+ # moment an approver taps merge, and the re-fired run holds this REQUIRED
40+ # context `in_progress` for its whole wall (a direct merge is refused
41+ # meanwhile) — which is why this leg is kept cheap rather than dropped: it
42+ # checks out commits and trees only and installs nothing unless the diff
43+ # needs the generator toolchain (the two checkout steps below).
3944 types : [opened, synchronize, reopened, ready_for_review]
4045 merge_group :
4146
8792 # (n = 288): max 1.1 minutes; 2× is 2.2, and never below 10. 20 + 10 = 30.
8893 timeout-minutes : 30
8994 steps :
95+ # The QUEUE leg's checkout, unchanged: the refusing leg reads the queue
96+ # head with the whole tree on disk.
9097 - name : Checkout repository
98+ if : github.event_name != 'pull_request'
9199 uses : actions/checkout@v7
92100 # CHECKOUT BUDGET: lint.yml's `typecheck-source-gates` sizes it.
93101 timeout-minutes : 20
@@ -100,6 +108,27 @@ jobs:
100108 # than diffing what it happens to have.
101109 fetch-depth : 0
102110
111+ # The EARLY-WARNING leg's checkout: the same full history, without file
112+ # contents. The judgment reads commits and trees only (`merge-base`,
113+ # `log`, `diff-tree --name-only`), and the only files it and the
114+ # self-test open live under `scripts/` and `.github/` — so a blobless
115+ # fetch plus a sparse tree of those two answers byte-identically.
116+ # Measured 2026-10-26 on this repository: a blobless full-history clone
117+ # took 7 s for 105 MiB against 58 s for 956 MiB with contents, and the
118+ # judgment on PR #25965 printed the same bytes on both checkouts. ⛔ Still
119+ # `fetch-depth: 0` — the #9902 reason above holds on this leg too. A diff
120+ # that needs the generator toolchain gets the full tree back below.
121+ - name : Checkout repository (commits and trees only)
122+ if : github.event_name == 'pull_request'
123+ uses : actions/checkout@v7
124+ timeout-minutes : 20
125+ with :
126+ fetch-depth : 0
127+ filter : blob:none
128+ sparse-checkout : |
129+ scripts
130+ .github
131+
103132 # Pinned to the same major and spelling as every other setup-node in this
104133 # repo, and it keeps its literal `node-version` (rather than
105134 # `node-version-file`) for the measured reason the Part-of Closing-Keyword
@@ -167,16 +196,37 @@ jobs:
167196 # verdict stays inside the script — where the exit contract lives — instead
168197 # of becoming an opaque red step nobody can read a governance answer out of.
169198 #
170- # Both legs install. The `pull_request` leg is a FORECAST of the queue
171- # verdict ("the merge-queue run of this same check will REFUSE it"), so a
172- # leg that cannot recompute forecasts a refusal that will not happen — the
173- # false-alarm direction, which trains seats to hold PRs that need no
174- # holding. Same diff, same answer, on both legs and at the seat.
199+ # Both legs install WHEREVER THE RECOMPUTE CAN CHANGE THE ANSWER. The
200+ # `pull_request` leg is a FORECAST of the queue verdict ("the merge-queue
201+ # run of this same check will REFUSE it"), so a leg that cannot recompute
202+ # forecasts a refusal that will not happen — the false-alarm direction,
203+ # which trains seats to hold PRs that need no holding. Same diff, same
204+ # answer, on both legs and at the seat. But a diff that touches no
205+ # register path never runs a generator at all, so on that leg the script
206+ # is asked first (`--toolchain-needed`, the same predicate the lift
207+ # consults) and the toolchain is acquired only on `true`. The queue leg
208+ # never asks, so its output stays empty and it always installs; a
209+ # question that fails leaves it empty too, which also installs.
210+ - name : Does this diff need the generator toolchain?
211+ id : toolchain
212+ if : github.event_name == 'pull_request'
213+ continue-on-error : true
214+ run : node scripts/pm/check-governed-queue-guard.mjs --toolchain-needed >> "$GITHUB_OUTPUT"
215+
216+ # The generators read the whole tree, which the sparse checkout above
217+ # left out; the blobs arrive on demand from the partial clone's remote.
218+ - name : Restore the full tree for the generator recompute
219+ if : github.event_name == 'pull_request' && steps.toolchain.outputs.needed != 'false'
220+ continue-on-error : true
221+ run : git sparse-checkout disable
222+
175223 - name : Setup pnpm
224+ if : steps.toolchain.outputs.needed != 'false'
176225 uses : ./.github/actions/setup-pnpm
177226 continue-on-error : true
178227
179228 - name : Get pnpm store directory
229+ if : steps.toolchain.outputs.needed != 'false'
180230 shell : bash
181231 continue-on-error : true
182232 run : |
@@ -185,6 +235,7 @@ jobs:
185235 # Deliberately the same key as lint.yml's: one store, one entry, and this
186236 # job is a cache READER in the steady state rather than a second writer.
187237 - name : Setup pnpm cache
238+ if : steps.toolchain.outputs.needed != 'false'
188239 uses : actions/cache@v6
189240 continue-on-error : true
190241 with :
@@ -194,6 +245,7 @@ jobs:
194245 ${{ runner.os }}-pnpm-store-v3-
195246
196247 - name : Install dependencies
248+ if : steps.toolchain.outputs.needed != 'false'
197249 continue-on-error : true
198250 run : pnpm install --frozen-lockfile
199251
0 commit comments