Skip to content

Commit 43c83ca

Browse files
committed
fix(pm): the queue guard's early-warning leg reads the .claude/** declaration off the event payload's body
Claude-Session: https://claude.ai/code/session_01QsR2jTeURPvEm465RcoYEC Co-authored-by: Claude <noreply@anthropic.com>
1 parent f32ad37 commit 43c83ca

1 file changed

Lines changed: 60 additions & 6 deletions

File tree

‎scripts/pm/check-governed-queue-guard.mjs‎

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,13 @@
480480
* not have crossed a `.claude/**` hunk (`ruleChangeCarryRefusal`);
481481
* - the four guard instruments and this guard's own workflow file are plain
482482
* Tier H rows of the register, so nothing here names them;
483-
* - the `pull_request` early-warning leg reads no body, so it names such a
484-
* diff "Tier H UNTIL the PR body is read" (`declarationUnread`) and never
485-
* reddens; `CODEOWNERS` must carry a line for each always-Tier-H path.
483+
* - the `pull_request` early-warning leg reads the body its event payload
484+
* carries (the body as of the event: an edit after it is read by the next
485+
* push or by the queue leg) and no record, so a `yes` or missing line is
486+
* Tier H on the body, a declared seat value is "Tier H UNTIL its record is
487+
* read" (`ruleChangeRecordStagePending`), and a payload with no body names
488+
* the diff "Tier H UNTIL the PR body is read" (`declarationUnread`); it
489+
* never reddens. `CODEOWNERS` must carry a line for each always-Tier-H path.
486490
*
487491
* ## The FOURTH leg: the SIZE line (#19036, maintainer ruling 2026-09-18)
488492
*
@@ -724,6 +728,7 @@ import {
724728
governedSurfacesFor,
725729
governedTierFor,
726730
groupHitsByException,
731+
landingTierOf,
727732
landsByHumanMerge,
728733
lowRiskArmVerdict,
729734
mergeWorkflowReadings,
@@ -732,6 +737,7 @@ import {
732737
recomputeProvenanceFor,
733738
readRuleChangeVerified,
734739
readWorkflowDiff,
740+
ruleChangeRecordStagePending,
735741
renderLiftApprovals,
736742
renderLowRiskLines,
737743
renderRuleChangeLines,
@@ -770,7 +776,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
770776
'the 2026-09-04 unpinned predicate (the queue leg\'s)': 12,
771777
'decomposition, and the multi-PR group trap': 13,
772778
'the verdict table, both events': 10,
773-
'the pull_request leg is an EARLY WARNING and never reddens': 6,
779+
// 6 → 9 (#35612): the leg reads the payload's body — a declared `none` waits on its record, `yes` is Tier H on the
780+
// body, no body still waits on the body; an entry with no split row is untouched.
781+
'the pull_request leg is an EARLY WARNING and never reddens': 9,
774782
'the replay fixtures: the three incidents this guard descends from': 11,
775783
'⭐ the ordering guarantee, measured with a spy that THROWS': 7,
776784
'the words a reader acts on (requirement (e))': 26,
@@ -1359,6 +1367,8 @@ export function resolveEventContext({ eventName, payload }) {
13591367
headSha: pull.head.sha,
13601368
namedPull: Number(pull.number),
13611369
draft: pull.draft === true,
1370+
// The body as of this event (#35612): the early-warning leg reads the `.claude/**` declaration off it.
1371+
body: typeof pull.body === 'string' ? pull.body : null,
13621372
label: `pull request #${pull.number}`,
13631373
};
13641374
}
@@ -1774,6 +1784,14 @@ export function renderGuardVerdict(verdict) {
17741784
` (GOVERNED_APPROVERS: ${GOVERNED_APPROVERS.join(', ')}). The queue leg reads the body and the record;`,
17751785
' `node scripts/pm/check-governed-merges.mjs --pr <n>` reads them now.',
17761786
]
1787+
: ruleChangeRecordStagePending(entry.surfaces)
1788+
? [
1789+
` ⚖️ landing tier: H(人合) UNTIL its record is read — the PR body declares \`Rule-change: ${entry.surfaces.find((s) => s?.ruleChangeVerdict?.declared)?.ruleChangeVerdict.declared ?? '(unread)'}\`, and every governed path`,
1790+
` above lies under ${tierSGlobs()}, which splits by declaration (2026-11-19): it lands Tier S(席内达档 L2 审核落地)`,
1791+
` once a \`## Contract review\` comment on ${REVIEW_OF_RECORD_LOCATION} naming the CURRENT head — \`Served-tier:`,
1792+
' CONTRACT_REVIEW_TIER`, `**VERDICT: PASS**` — reads the same value on its `Rule-change-verified:` line. This leg',
1793+
' reads no record; the queue leg does, and `node scripts/pm/check-governed-merges.mjs --pr <n>` reads it now.',
1794+
]
17771795
: entry.tier === TIER_S
17781796
? [
17791797
` ⚖️ landing tier: S(席内达档 L2 审核落地) — every governed path above lies under a Tier S surface (${tierSGlobs()}),`,
@@ -2249,6 +2267,18 @@ export function readLowRiskTier(entry, repo, pull, { timeline = null, runGit = n
22492267
return entry;
22502268
}
22512269

2270+
/**
2271+
* The early-warning leg's reading of the `.claude/**` declaration split off the event payload's body (#35612): the
2272+
* entry's split rows re-read with `{ body }` and no record, the tier re-read on the slice. Mutates and returns `entry`.
2273+
* Every other row passes through `applyRuleChangeSplit` as the same object. Pure but for the mutation.
2274+
*/
2275+
export function readPayloadDeclaration(entry, repo, body) {
2276+
if (!entry || !Array.isArray(entry.surfaces) || !entry.surfaces.some((s) => s?.ruleChangeVerdict)) return entry;
2277+
entry.surfaces = applyRuleChangeSplit(entry.surfaces, repo, { measured: true, reason: null, body: String(body ?? '') });
2278+
entry.tier = landingTierOf(entry.surfaces);
2279+
return entry;
2280+
}
2281+
22522282
/**
22532283
* A reader that answers each key from its first SUCCESSFUL read. A rejection is not cached: the next caller
22542284
* reads again, so one leg's transient failure is never another leg's verdict.
@@ -2689,8 +2719,13 @@ export function ruleChangeRecordVerdict(record, pair, recognisers, declared) {
26892719
* still governs everything the verdict is derived FROM; it never governed
26902720
* things the verdict merely mentions.
26912721
*/
2692-
export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fetchComments, fetchTimeline = null, fetchLabels = null, loadRecognisers = loadRecordRecognisers, lifted = [], runGit = null, baseRef = null }) {
2722+
export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fetchComments, fetchTimeline = null, fetchLabels = null, loadRecognisers = loadRecordRecognisers, lifted = [], runGit = null, baseRef = null, pullBody = null }) {
26932723
const { governed, unattributed } = decomposeGovernedWork(rows, assertGovernedRepo(repo, 'runGuard'));
2724+
// The early-warning leg reads the `.claude/**` declaration off the body its event payload carries (#35612); no record
2725+
// is read here, so a declared seat value stays Tier H with its record stage pending and the words say so.
2726+
if (event === EVENT_PULL_REQUEST && typeof pullBody === 'string') {
2727+
for (const entry of governed) readPayloadDeclaration(entry, repo, pullBody);
2728+
}
26942729
if (governed.length === 0 && unattributed.length === 0) {
26952730
return guardVerdict({ event, repo, governed, unattributed, apiCalls: 0, lifted });
26962731
}
@@ -4135,7 +4170,7 @@ async function main() {
41354170
const fetchLabels = makeLabelReader(reader);
41364171

41374172
const runGit = (args, input) => git(repoRoot, args, input);
4138-
const verdict = await runGuard({ event: context.event, repo, rows, fetchReviews, fetchPull, fetchComments, fetchTimeline, fetchLabels, lifted, runGit, baseRef: context.baseSha ?? null });
4173+
const verdict = await runGuard({ event: context.event, repo, rows, fetchReviews, fetchPull, fetchComments, fetchTimeline, fetchLabels, lifted, runGit, baseRef: context.baseSha ?? null, pullBody: context.body ?? null });
41394174
// The SIZE leg (#19036): every queued pull request, through the same pull
41404175
// reader the governed leg reads heads with. `merge_group` only, '' on the
41414176
// other leg, so the `pull_request` output is byte-identical to what it was.
@@ -4695,6 +4730,25 @@ export async function selfTest() {
46954730
/`Rule-change: none`/.test(warnedSText) && /`Rule-change-verified:`/.test(warnedSText) && /declaration split .*NOT MEASURED/.test(warnedSText) && !/No review of record\n? *substitutes here/.test(warnedSText),
46964731
warnedSText,
46974732
);
4733+
// #35612: the early-warning leg reads the body its event payload carries — `yes` is Tier H on the body, a declared
4734+
// `none` is Tier H UNTIL its record is read (this leg reads none), and the control: no body is still "UNTIL the PR
4735+
// body is read". End to end through `runGuard` with the payload body, and the context carries the body.
4736+
const payloadRun = async (body) => runGuard({ event: 'pull_request', repo: REPO, rows: [row(9529, ['.claude/agents/os-dev.md'])], fetchReviews: async () => [], fetchPull: async () => { throw new Error('the pull_request leg reads no pull'); }, fetchComments: async () => { throw new Error('the pull_request leg reads no thread'); }, pullBody: body });
4737+
const payloadNone = await payloadRun('Fixes #1\n\nRule-change: none\n');
4738+
const payloadYes = await payloadRun('Fixes #1\n\nRule-change: yes\n');
4739+
const payloadUnread = await payloadRun(null);
4740+
const [noneText, yesText, unreadText] = [payloadNone, payloadYes, payloadUnread].map(renderGuardVerdict);
4741+
assert('⭐ #35612 the-early-warning-reads-the-payload-body-a-declared-none-is-Tier-H-UNTIL-its-record-is-read-and-names-the-value',
4742+
payloadNone.exitCode === EXIT_CLEAR && payloadNone.entries[0].tier === TIER_H && !declarationUnread(payloadNone.entries[0]) && ruleChangeRecordStagePending(payloadNone.entries[0].surfaces) &&
4743+
/landing tier: H\(人合\) UNTIL its record is read — the PR body declares `Rule-change: none`/.test(noneText) && /`Rule-change-verified:`/.test(noneText) && !/UNTIL the PR body is read/.test(noneText),
4744+
noneText);
4745+
assert('⛔ #35612 a-payload-body-declaring-yes-is-Tier-H-on-the-body-with-the-maintainers-landing-and-the-control-no-body-still-reads-UNTIL-the-PR-body-is-read',
4746+
payloadYes.entries[0].tier === TIER_H && !ruleChangeRecordStagePending(payloadYes.entries[0].surfaces) && /declares `Rule-change: yes`/.test(yesText) && /authorized APPROVED review/.test(yesText) && !/UNTIL/.test(yesText) &&
4747+
declarationUnread(payloadUnread.entries[0]) && /UNTIL the PR body is read/.test(unreadText) &&
4748+
resolveEventContext({ eventName: 'pull_request', payload: { pull_request: { number: 1, body: 'Rule-change: none', base: { sha: 'b'.repeat(40) }, head: { sha: 'h'.repeat(40) } } } }).body === 'Rule-change: none' &&
4749+
resolveEventContext({ eventName: 'pull_request', payload: { pull_request: { number: 1, body: null, base: { sha: 'b'.repeat(40) }, head: { sha: 'h'.repeat(40) } } } }).body === null,
4750+
yesText);
4751+
assert('#35612 readPayloadDeclaration-leaves-an-entry-with-no-split-row-as-it-was', (() => { const e = decomposeGovernedWork([row(9530, ['AGENTS.md'])], REPO).governed[0]; const before = e.surfaces; return readPayloadDeclaration(e, REPO, 'Rule-change: none').surfaces === before && e.tier === TIER_H; })());
46984752
const warnedHText = renderGuardVerdict(warnedV);
46994753
assert('and-names-Tier-H-and-the-approval-it-waits-for-with-no-Tier-S-block', /landing tier: H/.test(warnedHText) && /authorized APPROVED review/.test(warnedHText) && !/Tier S \(/.test(warnedHText), warnedHText);
47004754
// The PR #25965 shape end to end on this leg: the warning names the PAYLOAD's

0 commit comments

Comments
 (0)