Skip to content

Commit 42323f3

Browse files
committed
pm: the arm leg clears a landing the maintainer approved or enqueued, ties a record to the landed commit, and drops rows edited after it
The sweep now reads the guard's own leg order on an arm landing: an authorized approval, then an authorized enqueue, then the record. A cleared landing stays on the maintainer's list. Reviews and timeline events count only strictly before merged_at (the queue's removal shares the merge's instant), comments only when created and last edited by then. A record counts only on a pull GitHub says landed as this commit. The verifier's sub-agent refusal now asks for the reviewing agent's transcript. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kXwEA8abP4hMhtodW
1 parent f31ef38 commit 42323f3

2 files changed

Lines changed: 89 additions & 21 deletions

File tree

‎scripts/pm/check-governed-merges.mjs‎

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,10 @@
526526
* readers on the landed commit (`readArmLanding`): an arm landing is listed APART
527527
* from the maintainer's merges, a `pass` on a same-head at-tier PASS record that
528528
* existed when it landed, a ⛔ `breach` without one; the arm's Tier H stays on
529-
* the maintainer's list with its reasons; a read that fails is NOT MEASURED and
529+
* the maintainer's list with its reasons, and so does an arm landing an
530+
* authorized approval or enqueue cleared first (the guard's own leg order); a
531+
* record counts only on a pull GitHub says landed AS this commit
532+
* (`merge_commit_sha`); a read that fails is NOT MEASURED and
530533
* the sweep INCOMPLETE (exit 2). Its reads ride the channel that attributed the
531534
* row; the body and labels are the pull's NOW (the timeline keeps a removed
532535
* `security` label). ⛔ It cannot tell a record written by the run that served
@@ -1164,7 +1167,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
11641167
'the nested `ui/` workspace rows, on the register (#25712)': 16,
11651168
'⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75,
11661169
'⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 74,
1167-
'⚖️ #33603: the sweep lists a low-risk arm landing APART and judges it on a same-head at-tier PASS record': 27,
1170+
'⚖️ #33603: the sweep lists a low-risk arm landing APART and judges it on a same-head at-tier PASS record': 36,
11681171
});
11691172

11701173
// DELETING an entry silences that battery's floor exactly as effectively as
@@ -4105,6 +4108,9 @@ async function fetchPullAttribution({ apiUrl }, slug, pull, channels) {
41054108
attribution: {
41064109
mergedBy: body?.merged_by?.login ?? null,
41074110
mergedAt: body?.merged_at ?? null,
4111+
// The commit GitHub says this pull landed as (#33711 S2): the arm leg ties a record's head to the landed
4112+
// commit through it, so a commit that only NAMES the pull in its subject is never excused by its record.
4113+
mergeCommitSha: body?.merge_commit_sha ?? null,
41084114
title: body?.title ?? null,
41094115
// GitHub's own `additions` / `deletions` (#19036), off the read this row
41104116
// already pays for — printed beside the LANDED number when they differ,
@@ -4414,7 +4420,7 @@ export function pullSizeFrom(head) {
44144420
export const ARM_READER_SOURCE = './check-governed-queue-guard.mjs';
44154421

44164422
/** The guard exports the arm leg reads with. A missing one is NOT MEASURED, never a second parser here. */
4417-
export const ARM_READER_EXPORTS = Object.freeze(['decomposeGovernedWork', 'readLowRiskTier', 'landsOnLowRiskArm', 'loadRecordRecognisers', 'recordVerdict', 'lowRiskRecordVerdict', 'makePullReader', 'makeCommentReader', 'makeTimelineReader']);
4423+
export const ARM_READER_EXPORTS = Object.freeze(['decomposeGovernedWork', 'readLowRiskTier', 'landsOnLowRiskArm', 'authorizedApprovalVerdict', 'enqueuerFromTimeline', 'authorizedEnqueueVerdict', 'loadRecordRecognisers', 'recordVerdict', 'lowRiskRecordVerdict', 'makePullReader', 'makeReviewReader', 'makeCommentReader', 'makeTimelineReader']);
44184424

44194425
/** Load the guard's readers and the record recognisers once per run. Never throws: a failed load is the reason. */
44204426
export async function loadArmReaders(load = (specifier) => import(specifier)) {
@@ -4430,13 +4436,20 @@ export async function loadArmReaders(load = (specifier) => import(specifier)) {
44304436

44314437
/**
44324438
* One governed entry's arm reading, or null when no catalog row was hit or no PR names it. `paths` is every path
4433-
* of the landed commit; `fetchers` are `{ fetchPull, fetchTimeline, fetchComments }` (the guard's readers);
4434-
* `mergedAt` keeps only the comments that existed when it landed, the rows the queue could have read.
4435-
* States: `pass` (an arm landing on a same-head at-tier PASS record), `breach` (an arm landing without one),
4436-
* `tier-h` (the arm read H: the maintainer's merge, listed with the others), `not-measured` (a read failed: listed
4437-
* with the maintainer's merges, and the sweep is INCOMPLETE). Never throws.
4439+
* of the landed commit; `fetchers` are `{ fetchPull, fetchReviews, fetchTimeline, fetchComments }` (the guard's
4440+
* readers); `attribution` is the row's pull read (`mergedAt`, `mergeCommitSha`), or null when it failed.
4441+
* ⭐ The legs run in the guard's own order (`entrySatisfied`): an authorized approval, then an authorized enqueue,
4442+
* then the record — so an entry the maintainer cleared is the maintainer's merge, never a seat's BREACH (#33711 S1).
4443+
* Each leg reads only what existed before the landing: reviews and timeline events strictly before `merged_at`
4444+
* (the queue's `removed_from_merge_queue` shares the merge's instant, measured on #33555, #33632 and #33616), and
4445+
* comments created AND last edited at or before it (#33711 N4). The record's head is the landed commit's only
4446+
* when GitHub's `merge_commit_sha` is that commit (#33711 S2).
4447+
* States: `pass` (an arm landing on a same-head at-tier PASS record), `breach` (an arm landing without one, or
4448+
* whose pull did not land as this commit), `cleared` (the arm read S, but an authorized approval or enqueue
4449+
* cleared it first: the maintainer's merge), `tier-h` (the arm read H: the maintainer's merge), `not-measured`
4450+
* (a read failed: listed with the maintainer's merges, and the sweep is INCOMPLETE). Never throws.
44384451
*/
4439-
export async function readArmLanding(entry, { paths, repo, readers, fetchers, runGit, mergedAt = null }) {
4452+
export async function readArmLanding(entry, { paths, repo, readers, fetchers, runGit, attribution = null }) {
44404453
if (!entry || entry.pr == null || !(entry.surfaces ?? []).some((s) => s?.lowRiskVerdict)) return null;
44414454
const why = (error) => String(error?.message ?? error).split('\n')[0];
44424455
let headSha = null;
@@ -4460,19 +4473,42 @@ export async function readArmLanding(entry, { paths, repo, readers, fetchers, ru
44604473
return { state: 'tier-h', headSha, reasons: work.surfaces.find((s) => s?.lowRiskVerdict)?.lowRiskVerdict?.reasons ?? [] };
44614474
}
44624475
if (sizeLimbFires(entry.size)) return { state: 'tier-h', headSha, reasons: [`the landed diff crosses the ${HUMAN_MERGE_LINE_THRESHOLD}-line human-merge line`] };
4476+
// S2: the record's head is tied to THIS commit only through the pull's own merge. A pull GitHub says is not
4477+
// merged, or merged as another commit, cannot excuse this one: never `pass`.
4478+
if (!attribution) return unmeasured('its merge could not be read, so no record can be tied to this commit');
4479+
const landed = Date.parse(attribution.mergedAt ?? '');
4480+
if (attribution.mergedAt == null || Number.isNaN(landed)) {
4481+
return { state: 'breach', headSha, reason: `#${entry.pr} is not merged (no \`merged_at\`), so no record on it covers this commit` };
4482+
}
4483+
const merged = String(attribution.mergeCommitSha ?? '').toLowerCase();
4484+
if (merged !== String(entry.sha ?? '').toLowerCase()) {
4485+
return { state: 'breach', headSha, reason: `#${entry.pr} landed as ${merged ? merged.slice(0, 12) : '(no merge_commit_sha)'}, not as this commit, so its record does not cover it` };
4486+
}
4487+
const before = (at) => Date.parse(at ?? '') < landed;
4488+
// S1, the approval leg then the enqueue leg, each as the queue read them before the merge.
4489+
let reviews;
4490+
try {
4491+
reviews = await fetchers.fetchReviews(entry.pr);
4492+
} catch (error) {
4493+
return unmeasured(`its reviews could not be read (${why(error)})`);
4494+
}
4495+
const approval = guard.authorizedApprovalVerdict(reviews.filter((r) => before(r?.submitted_at)), headSha);
4496+
if (approval.state === 'approved') return { state: 'cleared', by: 'review', who: approval.approvers, headSha };
4497+
const enqueue = guard.authorizedEnqueueVerdict(guard.enqueuerFromTimeline(events.filter((e) => before(e?.created_at))));
4498+
if (enqueue.state === 'authorized') return { state: 'cleared', by: 'enqueue', who: [enqueue.login], headSha };
44634499
if (recognisers?.available !== true) return unmeasured(recognisers?.reason ?? 'the record recognisers were not loaded');
44644500
const card = recognisers.deliveredCard(head);
44654501
let baseRef = null;
44664502
try {
44674503
baseRef = String(runGit(['rev-parse', '--verify', `${entry.sha}^1`])).trim() || null;
44684504
} catch { /* a carried record then reads unreadable, never stands */ }
44694505
const pair = { pr: entry.pr, card: card.card, headSha, runGit, baseRef, paths: work.paths, repo };
4470-
const landed = Date.parse(mergedAt ?? '');
44714506
for (const thread of recognisers.threads) {
44724507
const number = pair[thread.number];
44734508
try {
44744509
const rows = number === null || number === undefined ? [] : await fetchers.fetchComments(number);
4475-
pair[thread.rows] = Number.isNaN(landed) ? rows : rows.filter((r) => !(Date.parse(r?.created_at ?? '') > landed));
4510+
// A row counts only when it existed, unedited since, when the commit landed; a missing time never counts.
4511+
pair[thread.rows] = rows.filter((r) => [r?.created_at, r?.updated_at ?? r?.created_at].every((at) => Date.parse(at ?? '') <= landed));
44764512
} catch (error) {
44774513
return unmeasured(`${thread.where} #${number}'s comment thread could not be read (${why(error)})`);
44784514
}
@@ -4496,6 +4532,7 @@ export function armCell(entry) {
44964532
const head = a.headSha ? ` on head ${String(a.headSha).slice(0, 12)}` : '';
44974533
if (a.state === 'pass') return `\n ✅ low-risk arm landing${head}: same-head at-tier PASS record ${a.record?.where ?? ''} comment ${a.record?.id ?? '(no id)'}`;
44984534
if (a.state === 'breach') return `\n ⛔ BREACH — low-risk arm landing${head} WITHOUT a same-head at-tier PASS record: ${a.reason}`;
4535+
if (a.state === 'cleared') return `\n low-risk arm: Tier S${head}, cleared by an authorized ${a.by === 'review' ? 'approval' : 'enqueue'} (${(a.who ?? []).join(', ')}) before the record leg — the maintainer's merge`;
44994536
if (a.state === 'not-measured') return `\n ⚠️ low-risk arm NOT MEASURED${head} — ${a.reason}; listed here, unjudged`;
45004537
return `\n low-risk arm: Tier H${head} — ${(a.reasons ?? []).slice(0, 2).join('; ') || 'no reason recorded'}`;
45014538
}
@@ -5564,10 +5601,10 @@ async function main() {
55645601
return read(n);
55655602
};
55665603
const fetchers = armReaders.available
5567-
? { fetchPull: counted(armReaders.guard.makePullReader(api)), fetchTimeline: counted(armReaders.guard.makeTimelineReader(api)), fetchComments: counted(armReaders.guard.makeCommentReader(api)) }
5604+
? { fetchPull: counted(armReaders.guard.makePullReader(api)), fetchReviews: counted(armReaders.guard.makeReviewReader(api)), fetchTimeline: counted(armReaders.guard.makeTimelineReader(api)), fetchComments: counted(armReaders.guard.makeCommentReader(api)) }
55685605
: null;
55695606
const root = repoById.get(entry.repoId)?.path;
5570-
entry.arm = await readArmLanding(entry, { paths: pathsBySha.get(entry.sha) ?? [], repo: entry.repoId, readers: armReaders, fetchers, runGit: (argv) => git(root, argv), mergedAt: entry.attribution?.mergedAt ?? null });
5607+
entry.arm = await readArmLanding(entry, { paths: pathsBySha.get(entry.sha) ?? [], repo: entry.repoId, readers: armReaders, fetchers, runGit: (argv) => git(root, argv), attribution: entry.attribution ?? null });
55715608
if (entry.arm?.state === 'not-measured') armUnmeasured += 1;
55725609
}
55735610

@@ -8865,11 +8902,13 @@ async function selfTest() {
88658902
body: ['## Contract review', '', `Served-tier: \`${tier}\``, `Head-sha: \`${head}\``, ...(signed ? ['Reviewed-by: `session_01SEAT`'] : []), '', verdict].join('\n'),
88668903
});
88678904
const entryOf = (paths = [SK, CS], size = null) => classifyCommit({ sha: LANDED, date: '2026-11-15T04:30:00Z', subject: 'docs(skills): wording (#70)' }, paths, OS, size);
8868-
const run = async ({ prRows = [record()], cardRows = [], pull = {}, throws = null, paths = [SK, CS], size = null, rd = readers, mergedAt = MERGED_AT } = {}) => readArmLanding(entryOf(paths, size), {
8869-
paths, repo: 'objectstack', readers: rd, runGit, mergedAt,
8905+
const LANDING = { mergedAt: MERGED_AT, mergeCommitSha: LANDED };
8906+
const run = async ({ prRows = [record()], cardRows = [], pull = {}, throws = null, paths = [SK, CS], size = null, rd = readers, attribution = LANDING, reviews = [], events = [] } = {}) => readArmLanding(entryOf(paths, size), {
8907+
paths, repo: 'objectstack', readers: rd, runGit, attribution,
88708908
fetchers: {
88718909
fetchPull: async () => { if (throws === 'pull') throw new Error('HTTP 502'); return { sha: HEAD, body: BODY, labels: [], fork: { measured: true, isFork: false, headRepo: 'o/r', baseRepo: 'o/r' }, headRef: 'claude/project-thread-x', ...pull }; },
8872-
fetchTimeline: async () => { if (throws === 'timeline') throw new Error('HTTP 502'); return []; },
8910+
fetchReviews: async () => { if (throws === 'reviews') throw new Error('HTTP 502'); return reviews; },
8911+
fetchTimeline: async () => { if (throws === 'timeline') throw new Error('HTTP 502'); return events; },
88738912
fetchComments: async (n) => { if (throws === 'comments') throw new Error('HTTP 502'); return n === 70 ? prRows : n === 69 ? cardRows : []; },
88748913
},
88758914
});
@@ -8891,7 +8930,26 @@ async function selfTest() {
88918930
assert('⛔ a-PASS-record-below-the-tier-is-a-BREACH', await breach({ prRows: [record({ tier: 'TIER_DEFAULT' })] }, /does not stand at the tier/) === true);
88928931
assert('⛔ an-unsigned-PASS-record-is-a-BREACH', await breach({ prRows: [record({ signed: false })] }, /names no reviewer/) === true);
88938932
assert('⛔ a-PASS-record-posted-AFTER-the-landing-is-a-BREACH-the-queue-could-not-read-it', await breach({ prRows: [record({ at: '2026-11-15T06:00:00Z' })] }, /no `## Contract review` record on its head/) === true);
8894-
assert('and-with-no-merge-time-read-every-row-counts', (await run({ prRows: [record({ at: '2026-11-15T06:00:00Z' })], mergedAt: null }))?.state === 'pass');
8933+
assert('⛔ a-PASS-record-EDITED-after-the-landing-does-not-count', await breach({ prRows: [{ ...record(), updated_at: '2026-11-15T06:00:00Z' }] }, /no `## Contract review` record on its head/) === true);
8934+
// #33711 S2: the record's head is tied to the landed commit only through the pull's own merge.
8935+
assert('⛔ a-pull-that-landed-as-ANOTHER-commit-is-never-PASS', await breach({ attribution: { ...LANDING, mergeCommitSha: 'f'.repeat(40) } }, /landed as ffffffffffff, not as this commit/) === true);
8936+
assert('⛔ a-pull-closed-UNMERGED-is-never-PASS', await breach({ attribution: { ...LANDING, mergedAt: null } }, /is not merged/) === true);
8937+
// #33711 S1: the guard's order — an authorized approval, then an authorized enqueue, then the record.
8938+
const APPROVED = (login, at = '2026-11-15T04:10:00Z') => ({ id: 1, state: 'APPROVED', user: { login }, commit_id: HEAD, submitted_at: at });
8939+
const cleared = async (over, by) => { const v = await run(over); return v?.state === 'cleared' && v.by === by ? true : JSON.stringify(v); };
8940+
assert('⭐ an-authorized-APPROVAL-before-the-landing-clears-it-the-maintainers-merge-not-a-BREACH', await cleared({ prRows: [], reviews: [APPROVED('os-zhuang')] }, 'review') === true);
8941+
// The timeline a queue merge leaves, measured on #33555, #33632 and #33616: the removal shares the merge's instant.
8942+
const QUEUED = (login) => [
8943+
{ event: 'added_to_merge_queue', actor: { login }, created_at: '2026-11-15T04:40:00Z' },
8944+
{ event: 'merged', actor: { login }, created_at: MERGED_AT },
8945+
{ event: 'removed_from_merge_queue', actor: { login: 'github-merge-queue[bot]' }, created_at: MERGED_AT },
8946+
];
8947+
assert('⭐ an-authorized-ENQUEUE-clears-it-read-on-the-timeline-as-the-queue-saw-it-before-the-merge', await cleared({ prRows: [], events: QUEUED('os-zhuang') }, 'enqueue') === true);
8948+
assert('control-a-seat-account-enqueue-clears-nothing-the-record-decides', (await run({ events: QUEUED('objectstack-fleet[bot]') }))?.state === 'pass' &&
8949+
await breach({ prRows: [], events: QUEUED('objectstack-fleet[bot]') }, /no `## Contract review` record/) === true);
8950+
assert('⛔ an-approval-AFTER-the-landing-or-by-an-unauthorized-account-clears-nothing',
8951+
await breach({ prRows: [], reviews: [APPROVED('os-zhuang', '2026-11-15T06:00:00Z')] }, /no `## Contract review` record/) === true &&
8952+
await breach({ prRows: [], reviews: [APPROVED('os-someone')] }, /no `## Contract review` record/) === true);
88958953
const tierH = async (over, re) => { const v = await run(over); return v?.state === 'tier-h' && v.reasons.some((r) => re.test(r)) ? true : JSON.stringify(v); };
88968954
assert('⭐ the-arm-reading-H-a-security-label-stays-on-the-maintainers-list', await tierH({ pull: { labels: ['security'] } }, /`security` label/) === true);
88978955
assert('⭐ the-arm-reading-H-a-Clause-2-yes-body-stays-on-the-maintainers-list', await tierH({ pull: { body: 'Fixes #69\n\nClause-②: yes\nMetadata-protocol: none\n' } }, /Clause-②/) === true);
@@ -8900,6 +8958,8 @@ async function selfTest() {
89008958
const unmeasured = async (over, re) => { const v = await run(over); return v?.state === 'not-measured' && re.test(v.reason) ? true : JSON.stringify(v); };
89018959
assert('⛔ an-unread-pull-is-NOT-MEASURED', await unmeasured({ throws: 'pull' }, /its pull request could not be read/) === true);
89028960
assert('⛔ an-unread-timeline-is-NOT-MEASURED', await unmeasured({ throws: 'timeline' }, /its timeline could not be read/) === true);
8961+
assert('⛔ unread-reviews-are-NOT-MEASURED', await unmeasured({ throws: 'reviews' }, /its reviews could not be read/) === true);
8962+
assert('⛔ an-unread-merge-is-NOT-MEASURED-never-a-record-on-an-untied-head', await unmeasured({ attribution: null }, /its merge could not be read/) === true);
89038963
assert('⛔ an-unread-comment-thread-is-NOT-MEASURED', await unmeasured({ throws: 'comments' }, /comment thread could not be read/) === true);
89048964
assert('⛔ readers-that-did-not-load-are-NOT-MEASURED', await unmeasured({ rd: { available: false, reason: 'no guard' } }, /no guard/) === true);
89058965
assert('no-catalog-row-or-no-PR-number-is-no-arm-reading', (await run({ paths: ['AGENTS.md'] })) === null &&
@@ -8908,10 +8968,12 @@ async function selfTest() {
89088968
const at = (e, arm) => ({ ...e, attribution: { mergedBy: 'os-zhuang', mergedAt: MERGED_AT, title: 't', size: null }, attributionChannel: 'env-token', arm });
89098969
const human = at(classifyCommit({ sha: 'e'.repeat(40), date: MERGED_AT, subject: 'docs(adr): x (#71)' }, ['docs/adr/0001-x.md'], OS), undefined);
89108970
const report = renderReport({ window: dateWindowFor('2026-11-14T00:00:00Z'), repos: allAudited, scanned: 3, lookups: 3,
8911-
entries: [at(entryOf(), pass), at({ ...entryOf(), pr: 72, subject: 'docs(skills): y (#72)' }, { state: 'breach', headSha: HEAD, reason: 'no record', record: {} }), human] });
8971+
entries: [at(entryOf(), pass), at({ ...entryOf(), pr: 72, subject: 'docs(skills): y (#72)' }, { state: 'breach', headSha: HEAD, reason: 'no record', record: {} }), human,
8972+
at({ ...entryOf(), pr: 73, subject: 'docs(skills): z (#73)' }, { state: 'cleared', by: 'enqueue', who: ['os-zhuang'], headSha: HEAD })] });
89128973
const apart = report.indexOf('Low-risk skills arm landings');
89138974
assert('⭐ the-report-head-counts-the-arm-landings-and-their-breaches', report.includes('of which 2 landed through the low-risk skills arm, 1 of them ⛔ BREACH'), report);
89148975
assert('⭐ arm-landings-are-listed-AFTER-the-maintainers-list-never-in-it', apart > report.indexOf('PR #71') && report.indexOf('PR #70') > apart && report.indexOf('PR #72') > apart, report);
8976+
assert('⭐ a-CLEARED-arm-landing-stays-on-the-maintainers-list-and-says-who-cleared-it', report.indexOf('PR #73') < apart && report.includes('cleared by an authorized enqueue (os-zhuang)'), report);
89158977
assert('the-PASS-row-names-its-record-and-the-BREACH-row-says-BREACH', report.includes('same-head at-tier PASS record PR comment 900') && report.includes('⛔ BREACH — low-risk arm landing'), report);
89168978
assert('tier-h-and-not-measured-rows-stay-on-the-maintainers-list-with-their-reason', armCell({ arm: { state: 'tier-h', reasons: ['the PR carries the `security` label'] } }).includes('Tier H') &&
89178979
armCell({ arm: { state: 'not-measured', reason: 'x' } }).includes('NOT MEASURED') && armCell({}) === '');

0 commit comments

Comments
 (0)