diff --git a/scripts/pm/bounce-reading.mjs b/scripts/pm/bounce-reading.mjs new file mode 100644 index 00000000000..e3d1e079b89 --- /dev/null +++ b/scripts/pm/bounce-reading.mjs @@ -0,0 +1,160 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * bounce-reading — the ONE reading of "was this pull sent back for changes, and has a re-review on its current head + * cleared that since?" (`landing-operations.md`: a 退回 takes `pm:awaiting-merge` off in the same stroke, and + * 「复审过再挂、入队,其间不补四件」). + * + * ## Why it is its own file + * + * Two readers prescribe the hand-off's pieces: H48 in `check-half-states.mjs` (`h48GovernedVerdictWithoutBrief`, + * whose remedy is「add `pm:awaiting-merge`」) and `label-write.mjs --handoff` (whose `--dry-run` answers exit 7, a + * piece owed, and whose real stroke adds the label). On a bounced pull whose ACCEPT and same-head PASS are still on + * the thread both used to prescribe the label back. They read the bounce HERE, through one wrapper + * (`h48BounceReading` in `check-half-states.mjs`, which hands this file the contract-review readers), so the patrol + * row and the hand-off door cannot disagree. ⛔ Never re-spell a trigger in either reader. + * + * ⛔ No imports, no network, no I/O: rows in, a reading out. The contract-review readers are HANDED in (`readers`), + * because they live in `check-half-states.mjs` and a static import back would close a module cycle with that file's + * top-level await (its H62 banner measures both import directions for a sibling that does this). A sibling of its readers, ⛔ not under a `lib/` + * subdirectory (`seat-record.mjs` says why). + * + * ## The three triggers (card #39516), each with the moment it happened + * + * queue-red a red merge-queue build of this pull: the merge-queue-triage workflow's comment on the pull + * thread (`MERGE_QUEUE_TRIAGE_MARKER`, author `MERGE_QUEUE_TRIAGE_AUTHOR`). That workflow runs on + * every merge_group CI run that concluded failure, and the failure is what ejects the entry. + * ⚠️ Source measured on #39400 (2026-12-04): the REST timeline's `removed_from_merge_queue` event + * carries no head sha, no reason and no run (`commit_id` null; GraphQL is not reachable from a + * session), and also fires when the pull merges or a person dequeues it; the queue's check-runs + * sit on the merge-group commit, never on the pull's head. The triage comment names the red run + * and is on the thread both readers already hold. A comment carrying the triage workflow's + * `infra:no-runner` marker is NOT a bounce: the red was runners nobody got, the flake class the + * ruling keeps the label through (「flake/缺批准被踢不摘」). + * review-record the NEWEST `## Contract review` record on the thread (trusted author, names a head) reads FAIL, + * or carries an open must-fix or should-fix. + * changes-requested a trusted reviewer's newest deciding review is CHANGES_REQUESTED — trusted by the same + * record-author binding the records are read through (the relay identity and + * `GOVERNED_APPROVERS`: the maintainer asking for changes, 「维护者要改」), never a second login + * list. ⚠️ Not `author_association`: measured on #39400, the maintainer's own review there reads + * `CONTRIBUTOR`. A later APPROVED or a dismissal by the same reviewer supersedes it, and a + * COMMENTED review decides nothing (GitHub's own review-decision rule). + * + * ## Since when, and the one exit + * + * The bounce dates from the NEWEST trigger. It clears only on a trusted `## Contract review` record that names the + * pull's CURRENT head, reads one PASS line with no FAIL spelling and no open or unreadable grade (the queue guard's + * standard), and is NEWER than that trigger. An undated trigger can never be cleared (fail closed). + * + * ⚠️ The queue-red trigger is not narrowed to the current head. A fix pushed after the red moves the head and leaves + * no PASS on it, so the pull stays bounced until its re-review — the ruling's 「复审过再挂」. Narrowing it to the same + * head would read the pull as clear between the fix push and the re-review, and H48 would ask for the label back. + * + * ## Three input states, never two (#4690) + * + * A thread or a review page that was not read (`undefined`) or could not be read (`null`), or a record-author + * binding that did not load, is `unread`: no trigger can be ruled out and no PASS trusted. + */ + +/** The trigger names, in the order the header gives them. */ +export const BOUNCE_TRIGGERS = Object.freeze(['queue-red', 'review-record', 'changes-requested']); + +/** The identity the merge-queue-triage workflow comments as (`github.rest.issues.createComment` under GITHUB_TOKEN). */ +export const MERGE_QUEUE_TRIAGE_AUTHOR = 'github-actions[bot]'; + +/** The workflow's per-run marker line, `merge-queue-triage:RUN` inside an HTML comment, on a line of its own. */ +export const MERGE_QUEUE_TRIAGE_MARKER = /^$/m; + +/** The workflow's `infra:no-runner` marker: every red job was a runner nobody got — the flake class, no bounce. */ +export const MERGE_QUEUE_NO_RUNNER_MARKER = /^$/m; + +/** The review states that decide a reviewer's standing; COMMENTED and PENDING decide nothing. */ +const DECIDING_REVIEW_STATES = Object.freeze(['APPROVED', 'CHANGES_REQUESTED', 'DISMISSED']); + +const stampOf = (iso) => { + const parsed = Date.parse(iso ?? ''); + return Number.isFinite(parsed) ? parsed : null; +}; + +/** An undated moment sorts after every dated one, so it can never be cleared (fail closed). */ +const laterOrEqual = (a, b) => (a.stamp === null ? true : b.stamp === null ? false : a.stamp >= b.stamp); + +/** + * Every red merge-queue build the triage workflow recorded on this thread, oldest first in thread order: + * `{ id, at, stamp, run }`. A comment by any other author, or one carrying the no-runner marker, is not one. Pure. + */ +export function queueRedRemovals(rows) { + return (Array.isArray(rows) ? rows : []) + .filter((row) => String(row?.user?.login ?? '') === MERGE_QUEUE_TRIAGE_AUTHOR) + .map((row) => ({ row, triage: MERGE_QUEUE_TRIAGE_MARKER.exec(String(row?.body ?? '')) })) + .filter(({ row, triage }) => triage !== null && !MERGE_QUEUE_NO_RUNNER_MARKER.test(String(row?.body ?? ''))) + .map(({ row, triage }) => ({ id: row?.id ?? null, at: row?.created_at ?? null, stamp: stampOf(row?.created_at), run: triage[1] })); +} + +/** + * The CHANGES_REQUESTED reviews still standing: per reviewer `admits` trusts (the record-author binding), the NEWEST + * deciding review, kept when it is CHANGES_REQUESTED. `{ id, login, at, stamp }`. Pure. + */ +export function changesRequestedReviews(reviews, admits = () => false) { + const newest = new Map(); + (Array.isArray(reviews) ? reviews : []).forEach((review, index) => { + const login = String(review?.user?.login ?? ''); + if (!login || !DECIDING_REVIEW_STATES.includes(String(review?.state ?? ''))) return; + if (!admits(review)) return; + const candidate = { review, index, stamp: stampOf(review?.submitted_at) }; + const best = newest.get(login); + const newer = best === undefined || (candidate.stamp === null || best.stamp === null ? index > best.index : candidate.stamp >= best.stamp); + if (newer) newest.set(login, candidate); + }); + return [...newest.entries()] + .filter(([, { review }]) => review?.state === 'CHANGES_REQUESTED') + .map(([login, { review, stamp }]) => ({ id: review?.id ?? null, login, at: review?.submitted_at ?? null, stamp })); +} + +/** + * The reading. `rows` is the pull's issue-comment thread, `reviews` its submitted-review page, `headSha` its CURRENT + * head, `authors` the queue guard's record-author binding (`{ available, admits(row) }`). `readers` carries the + * contract-review readers: `recordOf(body, headSha)` → `null` (no record that names a head) or + * `{ fails, open, pass, onHead }`, and `newestOf(rows)` → the newest record row's `{ index, createdAt, stamp }`. + * + * @returns {{ state: 'unread', reason: string } + * | { state: 'clear', since: null, clearedBy: null } + * | { state: 'clear', since: object, clearedBy: { id: number|null, at: string|null } } + * | { state: 'bounced', since: { trigger: string, id: number|null, at: string|null, stamp: number|null, ref: string } }} + */ +export function bouncedSince({ rows, reviews, headSha, authors } = {}, readers = {}) { + if (rows === undefined || rows === null) return { state: 'unread', reason: 'the pull thread was not read' }; + if (reviews === undefined || reviews === null) return { state: 'unread', reason: 'the submitted-review page was not read' }; + if (authors?.available !== true) return { state: 'unread', reason: `the record-author binding did not load (${authors?.reason ?? 'no reason given'})` }; + if (typeof readers.recordOf !== 'function' || typeof readers.newestOf !== 'function') { + return { state: 'unread', reason: 'no contract-review reader was handed in' }; + } + const thread = Array.isArray(rows) ? rows : []; + const records = thread + .filter((row) => authors.admits(row)) + .map((row) => ({ row, standing: readers.recordOf(row?.body, headSha) })) + .filter(({ standing }) => standing !== null); + + const triggers = []; + for (const red of queueRedRemovals(thread)) { + triggers.push({ trigger: 'queue-red', id: red.id, at: red.at, stamp: red.stamp, ref: `merge-queue-triage comment ${red.id ?? '(no id)'} on queue run ${red.run}` }); + } + const newest = readers.newestOf(records.map(({ row }) => row)); + const newestRecord = newest === null ? null : records[newest.index]; + if (newestRecord && (newestRecord.standing.fails || newestRecord.standing.open)) { + const why = newestRecord.standing.fails ? 'reads FAIL' : 'carries an open must-fix or should-fix'; + triggers.push({ trigger: 'review-record', id: newestRecord.row?.id ?? null, at: newestRecord.row?.created_at ?? null, stamp: stampOf(newestRecord.row?.created_at), ref: `the newest \`## Contract review\` (comment ${newestRecord.row?.id ?? '(no id)'}) ${why}` }); + } + for (const cr of changesRequestedReviews(reviews, (review) => authors.admits(review))) { + triggers.push({ trigger: 'changes-requested', id: cr.id, at: cr.at, stamp: cr.stamp, ref: `review ${cr.id ?? '(no id)'} by \`${cr.login}\` requests changes` }); + } + if (triggers.length === 0) return { state: 'clear', since: null, clearedBy: null }; + const since = triggers.reduce((best, t) => (laterOrEqual(t, best) ? t : best)); + + const clearing = since.stamp === null + ? [] + : records.filter(({ row, standing }) => standing.onHead && standing.pass && (stampOf(row?.created_at) ?? -Infinity) > since.stamp); + if (clearing.length === 0) return { state: 'bounced', since }; + const by = clearing[clearing.length - 1].row; + return { state: 'clear', since, clearedBy: { id: by?.id ?? null, at: by?.created_at ?? null } }; +} diff --git a/scripts/pm/check-half-states.mjs b/scripts/pm/check-half-states.mjs index 1b993eb3594..3f6304aa957 100644 --- a/scripts/pm/check-half-states.mjs +++ b/scripts/pm/check-half-states.mjs @@ -1006,6 +1006,8 @@ import { isEntrypoint } from '../invoked-as.mjs'; import { SEAT_RECORD_MARKER, seatRecordAccepts, seatRecordOf } from './seat-record.mjs'; // The retired seat numbers and the account seat each became — the leaf table `seatMarkOf` reads, below. import { SEAT_NUMBER_ACCOUNTS } from './seat-numbers.mjs'; +// The ONE "sent back for changes since" reading H48 and `label-write.mjs --handoff` share (`h48BounceReading`, below). +import { bouncedSince } from './bounce-reading.mjs'; /** * The repo this file sweeps when nothing says otherwise. It is a FALLBACK for a @@ -12383,6 +12385,52 @@ export function h48SpeaksAbout(pr, governed) { return String(pr?.state ?? 'open') !== 'closed'; } +/** + * A contract-review record as the bounce reading weighs it (`bounce-reading.mjs`, `readers.recordOf`): `null` when + * the body carries no `## Contract review` heading or names no head on its `Head-sha:` line (a quoted heading opens + * nothing there, so a comment quoting a record is no record), else `{ fails, open, pass, onHead }` off this file's + * ONE record reading (`contractReviewRecordReading`): `fails` a FAIL verdict line or a FAIL spelled anywhere else, + * `open` an open must-fix or should-fix, `pass` the queue guard's standard (one PASS line, no FAIL spelling, no open + * or unreadable grade), `onHead` the record names `headSha`. Pure. + */ +export function contractReviewBounceStanding(body, headSha) { + const text = String(body ?? ''); + if (contractReviewHeadSha(text) === null) return null; + const reading = contractReviewRecordReading(text); + if (reading === null) return null; + const fails = reading.verdicts.includes('FAIL') || reading.failSpellings.length > 0; + const open = reading.findings.open.length > 0; + const pass = !fails && !open && reading.findings.unreadable.length === 0 && reading.verdicts.length === 1 && reading.verdicts[0] === 'PASS'; + return { fails, open, pass, onHead: contractReviewHeadMatch(text, headSha) !== null }; +} + +/** + * The bounce reading H48 and `label-write.mjs --handoff` both ask — `bounce-reading.mjs`'s `bouncedSince`, handed + * this file's contract-review readers. ⛔ The ONE wiring: a second caller asks this, never `bouncedSince` with its + * own readers, so the patrol row and the hand-off door cannot read one pull two ways. + * + * @param {{ rows: any[]|null|undefined, reviews: any[]|null|undefined, headSha: string, authors: { available: boolean, admits?: Function } }} inputs + */ +export function h48BounceReading(inputs) { + return bouncedSince(inputs, { + recordOf: contractReviewBounceStanding, + newestOf: (rows) => latestMarkedComment(rows, CONTRACT_REVIEW_HEADING_MARKER), + }); +} + +/** + * The gathering policy for the bounce leg: does this PR need its submitted-review page (and the record authors) to + * be judged? Only when H48 would fire WITHOUT the leg — governed, thread read, an ACCEPT on it, a half missing. A + * whole hand-off, a PR with no verdict and an unread thread buy nothing. Pure. + */ +export function h48NeedsBounceRead(pr, governed, commentRows) { + if (!Array.isArray(commentRows) || !h48SpeaksAbout(pr, governed)) return false; + if (!latestMarkedComment(commentRows, ACCEPT_VERDICT_MARKER)) return false; + const hasBrief = latestMarkedComment(commentRows, MAINTAINER_BRIEF_MARKER) !== null; + const hasLabel = labelNames(pr ?? {}).includes(GOVERNED_PR_AWAITING_MERGE_LABEL); + return !(hasLabel && hasBrief); +} + /** * H48 — null when clean OR unjudged, else the finding sentence. * @@ -12393,12 +12441,23 @@ export function h48SpeaksAbout(pr, governed) { * request, or a walk that hit the page ceiling. UNJUDGED. * rows judged. * + * ## A pull sent back for changes is NOT a half hand-off (card #39516) + * + * A 退回 takes `pm:awaiting-merge` off on purpose, and the label goes back only after the fix passes re-review + * (`landing-operations.md`: 「复审过再挂、入队,其间不补四件」). So once a half is missing the row asks `bounce` + * — `h48BounceReading`'s answer, the reading `label-write.mjs --handoff` refuses on — and stays QUIET while it + * reads `bounced`: a red merge-queue build, a newest review record reading FAIL or carrying an open must-fix or + * should-fix, or a trusted reviewer's CHANGES_REQUESTED, with no PASS on the current head newer than it. `undefined` (the + * leg never consulted) and `unread` are UNJUDGED; only `clear` lets the finding through. The leg is asked only + * after a half is found missing, so a whole hand-off needs none of it (`h48NeedsBounceRead`). + * * @param {{ number?: number, state?: string, merged_at?: string|null, labels?: any[] }} pr * @param {{ glob: string, files?: string[] }[]} governed — the matched slice. * @param {{ body?: string, created_at?: string }[]|null|undefined} commentRows — * REST rows rather than bodies, so the sentence can date the verdict it found. + * @param {{ state: 'unread'|'clear'|'bounced' }|undefined} bounce — `h48BounceReading`'s answer. */ -export function h48GovernedVerdictWithoutBrief(pr, governed, commentRows) { +export function h48GovernedVerdictWithoutBrief(pr, governed, commentRows, bounce = undefined) { if (commentRows === undefined || commentRows === null) return null; if (!h48SpeaksAbout(pr, governed)) return null; const rows = Array.isArray(commentRows) ? commentRows : []; @@ -12411,6 +12470,9 @@ export function h48GovernedVerdictWithoutBrief(pr, governed, commentRows) { const hasBrief = latestMarkedComment(rows, MAINTAINER_BRIEF_MARKER) !== null; const hasLabel = labelNames(pr ?? {}).includes(GOVERNED_PR_AWAITING_MERGE_LABEL); if (hasLabel && hasBrief) return null; + // The bounce (header): quiet while the pull is sent back, UNJUDGED when the leg was not read — ⛔ never a remedy + // that puts the label back on a pull the maintainer cannot merge yet. + if (bounce?.state !== 'clear') return null; const surfaces = governed ?? []; const hits = surfaces.reduce((n, s) => n + (s.files?.length ?? 0), 0); @@ -19592,6 +19654,8 @@ export const SWEEP_COUNT_KEYS = [ // unbought one, and either way an unjudged PR must not read as a clean one. 'briefCandidates', 'briefJudged', + // …and how many of the judged ones read as sent back for changes (#39516), quiet until a re-review clears them. + 'briefBounced', // H69's coverage pair. `seatRecordCandidates` is how many governed Tier H // open PRs carried a pending approver request and `seatRecordJudged` how // many of those had a readable thread AND, where a record existed, a @@ -20251,7 +20315,10 @@ export function summaryLine(counts, findingCount) { 'already in hand: `commentCache` holds CARD threads only. A thread that failed or reached that ' + 'ceiling is UNJUDGED rather than short, a PR whose changed-file page went unread is not in this ' + 'population at all — nor is a Tier S PR, whose landing has no maintainer inbox — and a governed ' + - 'PR with NO `**ACCEPT**` verdict is CLEAN rather than quiet' + 'PR with NO `**ACCEPT**` verdict is CLEAN rather than quiet. A PR missing a half is asked whether it ' + + 'was sent back for changes, on ONE submitted-review page bought for it: ' + + `${counts.briefBounced ?? 0} read bounced and stay quiet until a PASS on their current head newer than ` + + 'the bounce, and one whose page or record authors could not be read is UNJUDGED' }. ` + // H69's coverage pair. UNCONDITIONAL like every other window's, the // register's availability leading it for H43's reason, and the one fetch @@ -25464,13 +25531,41 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen // and it buys one per GOVERNED OPEN PR — 11 of 31 on the board it landed // against. The candidate/judged pair below is what keeps a run whose walks // all failed separable from a board where every handoff was complete. + // + // The bounce leg (#39516): a PR the row would fire on is asked whether it was sent back for changes, through + // `h48BounceReading` — the reading `label-write.mjs --handoff` refuses on. It buys ONE submitted-review page per + // such PR (never per governed PR: `h48NeedsBounceRead`) and the queue guard's record authors, loaded once; a + // page or a binding that did not answer leaves the PR UNJUDGED, never a finding asking for the label back. + const prReviewCache = new Map(); + const prReviewRowsFor = async (number) => { + if (prReviewCache.has(number)) return prReviewCache.get(number); + let value = null; + try { + const page = await rest(`/repos/${OWNER_REPO}/pulls/${number}/reviews?per_page=${H43_REVIEWS_PAGE_SIZE}`); + // A full page may hide the newest review: UNREAD, never a short list. + value = Array.isArray(page) && page.length < H43_REVIEWS_PAGE_SIZE ? page : null; + } catch { + value = null; + } + prReviewCache.set(number, value); + return value; + }; for (const pr of seenPrs.values()) { const governed = governedByPr.get(pr.number); if (!h48SpeaksAbout(pr, governed)) continue; stats.briefCandidates = (stats.briefCandidates ?? 0) + 1; const rows = await prCommentRowsFor(pr.number); - if (rows !== null) stats.briefJudged = (stats.briefJudged ?? 0) + 1; - const handoff = h48GovernedVerdictWithoutBrief(pr, governed, rows); + let bounce; + if (h48NeedsBounceRead(pr, governed, rows)) { + if (recordAuthors === null) { + recordAuthors = await h43RecordAuthors(); + if (!recordAuthors.available) stats.governedRecordAuthorsReason = recordAuthors.reason; + } + bounce = h48BounceReading({ rows, reviews: await prReviewRowsFor(pr.number), headSha: String(pr.head?.sha ?? ''), authors: recordAuthors }); + if (bounce.state === 'bounced') stats.briefBounced = (stats.briefBounced ?? 0) + 1; + } + if (rows !== null && bounce?.state !== 'unread') stats.briefJudged = (stats.briefJudged ?? 0) + 1; + const handoff = h48GovernedVerdictWithoutBrief(pr, governed, rows, bounce); if (handoff) findings.push([pr, 'H48', handoff]); } @@ -26880,6 +26975,10 @@ export const SELF_TEST_BATTERIES = Object.freeze({ // the non-approver and assign-only requests that must not read as a // summons, and the Tier S slice the row stands down on. 'H69 seat record before governed review': 40, + // Registered with the bounced-pull reading (#39516), pin AT the count: a NARROWING of when H48 fires, so the + // controls that keep it a narrowing and not a silencer live inside it — the unbounced pull that must still fire, + // each trigger's exit cell, the flake, foreign-author and untrusted-reviewer controls, and the unread leg that stays UNJUDGED. + 'H48 bounced pull': 29, // Registered with the hand-off timing: 89 cases (57 legacy coverage cases now // driven with the hand-off DUE, 32 timing cases), the pin just under. What this // battery floors is a NARROWING of when the row fires — only once the seat's @@ -35439,17 +35538,21 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading. body: '## 维护者速读\n用户能看到什么变化:dev 的四行草稿,不是评审后的最终速读。', ...extra, }); - const h48row = (...args) => String(h48GovernedVerdictWithoutBrief(...args) ?? ''); + // Every case below reads a pull NOT sent back for changes: the bounce leg answers `clear` (`bounce-reading.mjs`), + // the one state that lets the finding through. The bounce cases and the unconsulted leg follow the adjacency block. + const CLEAR48 = Object.freeze({ state: 'clear', since: null, clearedBy: null }); + const h48at = (pr, governed, rows, bounce = CLEAR48) => h48GovernedVerdictWithoutBrief(pr, governed, rows, bounce); + const h48row = (...args) => String(h48at(...args) ?? ''); // The complete handoff, and each way it comes apart. - t('H48: verdict + label + brief -> clean', h48GovernedVerdictWithoutBrief(pr48([LABEL48]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), null); - t('H48: verdict + label, NO brief -> finding', typeof h48GovernedVerdictWithoutBrief(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]), 'string'); + t('H48: verdict + label + brief -> clean', h48at(pr48([LABEL48]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), null); + t('H48: verdict + label, NO brief -> finding', typeof h48at(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]), 'string'); t('H48: …and the row names the brief half that is missing', h48row(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]).includes('no comment whose line begins `## 维护者速读`'), true); t('H48: …and the remedy is posting it as a COMMENT', h48row(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]).includes('post the final 维护者速读 brief as a COMMENT'), true); t('H48: …and never asks for the label, which is already there', h48row(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]).includes('add `pm:awaiting-merge`'), false); - t('H48: verdict + brief, NO label -> finding', typeof h48GovernedVerdictWithoutBrief(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), 'string'); + t('H48: verdict + brief, NO label -> finding', typeof h48at(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), 'string'); t('H48: …and the row names the label half that is missing', h48row(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]).includes('no `pm:awaiting-merge` label'), true); - t('⛔ H48: the OLD shape — `needs-user-decision` on the PR — no longer satisfies the label half (the maintainer split the inboxes)', typeof h48GovernedVerdictWithoutBrief(pr48([DECISION_INBOX_LABEL]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), 'string'); + t('⛔ H48: the OLD shape — `needs-user-decision` on the PR — no longer satisfies the label half (the maintainer split the inboxes)', typeof h48at(pr48([DECISION_INBOX_LABEL]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]), 'string'); t('H48: the PR-side constant is `pm:awaiting-merge`, PRs only, and NOT one of the six card states', [GOVERNED_PR_AWAITING_MERGE_LABEL, PM_EXCLUSIVE_STATE_LABELS.includes(GOVERNED_PR_AWAITING_MERGE_LABEL)].join('|'), 'pm:awaiting-merge|false'); t('H48: …and the remedy is the label write', h48row(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]).includes('Remedy: add `pm:awaiting-merge`.'), true); t('H48: …and never asks for a brief that is already posted', h48row(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]).includes('as a COMMENT'), false); @@ -35459,17 +35562,17 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading. // The BODY draft is not the brief — the half this row exists to find must not // be allowed to satisfy itself out of the text the dev wrote before review. - t('H48: a `## 维护者速读` section in the BODY — the dev\'s draft, same heading — does NOT satisfy the brief half', typeof h48GovernedVerdictWithoutBrief(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]), 'string'); + t('H48: a `## 维护者速读` section in the BODY — the dev\'s draft, same heading — does NOT satisfy the brief half', typeof h48at(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]), 'string'); t('H48: …and the fixture body really does carry the comment marker\'s heading, so the case is not vacuous', MAINTAINER_BRIEF_MARKER.test(pr48([LABEL48]).body), true); t('H48: …and the row SAYS so, where a reader would otherwise assume a bug', h48row(pr48([LABEL48]), GOV48, [cm48(VERDICT48)]).includes('PR BODY does NOT satisfy this half'), true); t('H48: …and that clause is absent once the brief really is posted', h48row(pr48([]), GOV48, [cm48(VERDICT48), cm48(BRIEF48)]).includes('PR BODY does NOT satisfy'), false); - t('H48: a brief comment ANYWHERE on the thread counts, not only the newest', h48GovernedVerdictWithoutBrief(pr48([LABEL48]), GOV48, [cm48(BRIEF48, '2026-09-05T10:00:00Z'), cm48(VERDICT48), cm48('lgtm')]), null); + t('H48: a brief comment ANYWHERE on the thread counts, not only the newest', h48at(pr48([LABEL48]), GOV48, [cm48(BRIEF48, '2026-09-05T10:00:00Z'), cm48(VERDICT48), cm48('lgtm')]), null); // ⛔ No verdict is CLEAN — the boundary of this card, pinned so a later reader // does not "fix" it into the 代读 row it was ruled not to be. - t('H48: no verdict at all -> CLEAN, not quiet', h48GovernedVerdictWithoutBrief(pr48([]), GOV48, [cm48('rebased onto main')]), null); - t('H48: …the live 代读 shape (label + brief, no verdict) is CLEAN and deliberately not this card', h48GovernedVerdictWithoutBrief(pr48([LABEL48]), GOV48, [cm48(BRIEF48)]), null); - t('H48: …and an empty thread on a governed PR is clean', h48GovernedVerdictWithoutBrief(pr48([]), GOV48, []), null); + t('H48: no verdict at all -> CLEAN, not quiet', h48at(pr48([]), GOV48, [cm48('rebased onto main')]), null); + t('H48: …the live 代读 shape (label + brief, no verdict) is CLEAN and deliberately not this card', h48at(pr48([LABEL48]), GOV48, [cm48(BRIEF48)]), null); + t('H48: …and an empty thread on a governed PR is clean', h48at(pr48([]), GOV48, []), null); t('H48: …and the row states that boundary in its own sentence', h48row(pr48([]), GOV48, [cm48(VERDICT48)]).includes('No verdict at all is CLEAN on this row'), true); t('H48 row: states its report-only posture', h48row(pr48([]), GOV48, [cm48(VERDICT48)]).includes('Report-only patrol INPUT'), true); t('H48 row: …and refuses the one substitution a seat must never make', h48row(pr48([]), GOV48, [cm48(VERDICT48)]).includes('no seat may substitute an approving review'), true); @@ -35479,11 +35582,11 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading. t('H48 row: …and dates the verdict it found, so the reader can go to it', h48row(pr48([]), GOV48, [cm48(VERDICT48)]).includes('(newest one 2026-09-05T14:30:00Z)'), true); // Population: governed-only, open-only, drafts IN. - t('H48: a NON-governed PR with a verdict and nothing else is out of population', h48GovernedVerdictWithoutBrief(pr48([]), [], [cm48(VERDICT48)]), null); + t('H48: a NON-governed PR with a verdict and nothing else is out of population', h48at(pr48([]), [], [cm48(VERDICT48)]), null); t('H48 population: …and the counting policy says so directly', h48SpeaksAbout(pr48([]), []), false); t('H48 population: an undefined governed slice is out too, never a crash', h48SpeaksAbout(pr48([]), undefined), false); - t('H48: a CLOSED PR is out — the handoff is over and nothing here is fixable', h48GovernedVerdictWithoutBrief(pr48([], { state: 'closed' }), GOV48, [cm48(VERDICT48)]), null); - t('H48: a MERGED PR is out for the same reason', h48GovernedVerdictWithoutBrief(pr48([], { merged_at: '2026-09-05T14:29:00Z' }), GOV48, [cm48(VERDICT48)]), null); + t('H48: a CLOSED PR is out — the handoff is over and nothing here is fixable', h48at(pr48([], { state: 'closed' }), GOV48, [cm48(VERDICT48)]), null); + t('H48: a MERGED PR is out for the same reason', h48at(pr48([], { merged_at: '2026-09-05T14:29:00Z' }), GOV48, [cm48(VERDICT48)]), null); t('H48 population: ⛔ a DRAFT is IN — the correct terminal state is still half a handoff', h48SpeaksAbout(pr48([], { draft: true }), GOV48), true); t('H48 population: …and so is a non-draft governed PR', h48SpeaksAbout(pr48([], { draft: false }), GOV48), true); t('H48 population: a closed PR is out', h48SpeaksAbout(pr48([], { state: 'closed' }), GOV48), false); @@ -35497,16 +35600,16 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading. const TIER_S_48 = GOVERNED_REGISTER.available ? GOVERNED_REGISTER.matcher(['.claude/agents/os-dev.md']) : []; const MIXED_48 = GOVERNED_REGISTER.available ? GOVERNED_REGISTER.matcher(['.claude/agents/os-dev.md', 'AGENTS.md']) : []; t('H48 population: a Tier S PR (all governed paths on the record row) is OUT — no inbox on that tier', h48SpeaksAbout(pr48([]), TIER_S_48), false); - t('H48 tier: …so a verdict with NEITHER half on a Tier S PR is no finding', h48GovernedVerdictWithoutBrief(pr48([]), TIER_S_48, [cm48(VERDICT48)]), null); - t('H48 tier: …and the same verdict on a MIXED slice (one Tier H row) still is one', typeof h48GovernedVerdictWithoutBrief(pr48([]), MIXED_48, [cm48(VERDICT48)]), 'string'); + t('H48 tier: …so a verdict with NEITHER half on a Tier S PR is no finding', h48at(pr48([]), TIER_S_48, [cm48(VERDICT48)]), null); + t('H48 tier: …and the same verdict on a MIXED slice (one Tier H row) still is one', typeof h48at(pr48([]), MIXED_48, [cm48(VERDICT48)]), 'string'); t('H48 tier: …naming the tier it speaks about', h48row(pr48([]), MIXED_48, [cm48(VERDICT48)]).includes('GOVERNED on Tier H'), true); t('H48 summary: a Tier S PR is stated as out of the population', saidBy('h48Brief', summaryLine({}, 0)).includes('nor is a Tier S PR'), true); // Three input states, never two (#4690) — and here the unreadable one is a // thread this row BOUGHT and did not get, which is why it must not read clean. - t('H48: an unconsulted thread is UNJUDGED, never clean', h48GovernedVerdictWithoutBrief(pr48([]), GOV48, undefined), null); - t('H48: an UNREADABLE (failed or ceiling-bound) thread is UNJUDGED too', h48GovernedVerdictWithoutBrief(pr48([]), GOV48, null), null); - t('H48: a missing PR is judged on the slice it was handed, never a crash', typeof h48GovernedVerdictWithoutBrief(undefined, GOV48, [cm48(VERDICT48)]), 'string'); + t('H48: an unconsulted thread is UNJUDGED, never clean', h48at(pr48([]), GOV48, undefined), null); + t('H48: an UNREADABLE (failed or ceiling-bound) thread is UNJUDGED too', h48at(pr48([]), GOV48, null), null); + t('H48: a missing PR is judged on the slice it was handed, never a crash', typeof h48at(undefined, GOV48, [cm48(VERDICT48)]), 'string'); // The verdict marker — `CLAIM_COMMENT_MARKER`'s strictness minus the one // property that was an accommodation for a shipped dialect. @@ -35536,7 +35639,73 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading. // the live register's contents. const ASKED48 = { ...pr48([LABEL48]), requested_reviewers: [{ login: 'the-maintainer' }] }; t('H48 adjacency: H43 is silent once the maintainer is asked', h43GovernedReviewRequestGap(ASKED48, GOV48, ['the-maintainer'], []), null); - t('H48 adjacency: …while H48 still fires on that PR, because the brief is missing', typeof h48GovernedVerdictWithoutBrief(ASKED48, GOV48, [cm48(VERDICT48)]), 'string'); + t('H48 adjacency: …while H48 still fires on that PR, because the brief is missing', typeof h48at(ASKED48, GOV48, [cm48(VERDICT48)]), 'string'); + + // -- H48 — a pull SENT BACK for changes is not a half hand-off (#39516) ---- + // + // The #39400 shape: ACCEPT, a same-head PASS and the brief on the thread, the label taken off by the bounce. On + // `main` the row asked for the label back on every trigger below. One cell per trigger, one exit cell per trigger + // (a NEWER PASS on the current head restores the finding), the unbounced control, and the controls that keep the + // bounce a narrowing rather than a silencer. Driven through `h48BounceReading`, the ONE wiring + // `label-write.mjs --handoff` asks too, with the record authors injected as H43's cases inject them. + const BATTERY48B = 'H48 bounced pull'; + const HEAD48 = 'c0ffee00'.repeat(5); + const OLD48 = 'deadbeef'.repeat(5); + const FLEET48 = 'objectstack-fleet[bot]'; + // The record-author binding as the guard assembles it: the relay identity and the approver (`recordTrustedAuthors`). + const AUTH48 = { available: true, admits: (row) => [FLEET48, 'os-zhuang'].includes(row?.user?.login) }; + const fleet48 = (id, body, at) => ({ id, user: { login: FLEET48 }, body, created_at: at }); + const REC48 = (sha, verdict = 'PASS', findings = 'No must-fix, no should-fix.') => + `## Contract review\n\nServed-tier: \`CONTRACT_REVIEW_TIER\`\nHead-sha: \`${sha}\`\nReviewed-by: an isolated reviewer session\n\n${findings}\n\n**VERDICT: ${verdict}**\n`; + const TRIAGE48 = (id, at, extra = '') => ({ id, user: { login: 'github-actions[bot]' }, created_at: at, body: `### ⛔ merge queue 构建失败 — 先分诊,再决定要不要重排\n\n**分类:\`failure\`** —— 按下面的日志分诊。\n\n\n${extra}---\n` }); + // Handed off once, then bounced: the label is off, the ACCEPT, the brief and the same-head PASS are still there. + const BASE48 = [fleet48(1, `${BRIEF48}\n\n## 席位核对\n\n${VERDICT48}`, '2026-12-04T05:00:00Z'), fleet48(2, REC48(HEAD48), '2026-12-04T05:10:00Z')]; + const RE48 = fleet48(9, REC48(HEAD48), '2026-12-04T07:00:00Z'); + // `CONTRIBUTOR` is what the maintainer's own review reads on #39400: the association decides nothing here. + const CR48 = { id: 77, state: 'CHANGES_REQUESTED', user: { login: 'os-zhuang' }, submitted_at: '2026-12-04T06:00:00Z', author_association: 'CONTRIBUTOR' }; + const pr48b = () => ({ ...pr48([]), head: { sha: HEAD48 } }); + const reading48 = (rows, reviews = []) => h48BounceReading({ rows, reviews, headSha: HEAD48, authors: AUTH48 }); + const fire48 = (rows, reviews = []) => typeof h48GovernedVerdictWithoutBrief(pr48b(), GOV48, rows, reading48(rows, reviews)); + const RED48 = [...BASE48, TRIAGE48(3, '2026-12-04T06:00:00Z')]; + const FAIL48 = [...BASE48, fleet48(3, REC48(HEAD48, 'FAIL', 'M1 (must-fix) — the read-back skips the label.'), '2026-12-04T06:00:00Z')]; + const OPEN48 = [...BASE48, fleet48(3, REC48(HEAD48, 'PASS', 'S1 (should-fix) — the read-back skips the label.'), '2026-12-04T06:00:00Z')]; + b(BATTERY48B, '⭐ H48 bounce control: an UNBOUNCED pull with ACCEPT and no label still gets today\'s finding', fire48(BASE48), 'string'); + b(BATTERY48B, '⭐ …and the control asks for the label, as it did before the bounce reading', String(h48GovernedVerdictWithoutBrief(pr48b(), GOV48, BASE48, reading48(BASE48))).includes(`Remedy: add \`${LABEL48}\``), true); + b(BATTERY48B, '⭐ H48 bounce ① a red merge-queue build on the same head (the triage comment): no finding', fire48(RED48), 'object'); + b(BATTERY48B, '⭐ H48 bounce ① exit: a NEWER PASS on the current head restores the finding', fire48([...RED48, RE48]), 'string'); + b(BATTERY48B, '⭐ H48 bounce ② the newest review record reads FAIL: no finding', fire48(FAIL48), 'object'); + b(BATTERY48B, '⭐ H48 bounce ② exit: a NEWER PASS on the current head restores the finding', fire48([...FAIL48, RE48]), 'string'); + b(BATTERY48B, 'H48 bounce ② an open should-fix in the newest record (beside its PASS line) is a bounce too', fire48(OPEN48), 'object'); + b(BATTERY48B, 'H48 bounce ② …and its delta review closing the finding on the current head clears it', fire48([...OPEN48, fleet48(9, REC48(HEAD48, 'PASS', '- **S1 (should-fix): closed.**'), '2026-12-04T07:00:00Z')]), 'string'); + b(BATTERY48B, '⭐ H48 bounce ③ the maintainer\'s CHANGES_REQUESTED review: no finding', fire48(BASE48, [CR48]), 'object'); + b(BATTERY48B, '⭐ H48 bounce ③ exit: a NEWER PASS on the current head restores the finding', fire48([...BASE48, RE48], [CR48]), 'string'); + b(BATTERY48B, 'H48 bounce ③ control: a later APPROVED by the same reviewer supersedes it — the finding stands', fire48(BASE48, [CR48, { ...CR48, id: 78, state: 'APPROVED', submitted_at: '2026-12-04T06:30:00Z' }]), 'string'); + b(BATTERY48B, 'H48 bounce ③ control: a CHANGES_REQUESTED by a reviewer the record-author binding does not trust decides nothing — the finding stands', fire48(BASE48, [{ ...CR48, user: { login: 'someone' }, author_association: 'MEMBER' }]), 'string'); + b(BATTERY48B, 'H48 bounce ③ control: COMMENTED decides nothing, so a request for changes under it still bounces', fire48(BASE48, [CR48, { ...CR48, id: 79, state: 'COMMENTED', submitted_at: '2026-12-04T06:30:00Z' }]), 'object'); + b(BATTERY48B, 'H48 bounce ① control: an `infra:no-runner` red is the flake class the label stays through — the finding stands', fire48([...BASE48, TRIAGE48(3, '2026-12-04T06:00:00Z', `\n`)]), 'string'); + b(BATTERY48B, 'H48 bounce ① control: the triage comment from any other author is no bounce — the finding stands', fire48([...BASE48, { ...TRIAGE48(3, '2026-12-04T06:00:00Z'), user: { login: 'someone' } }]), 'string'); + b(BATTERY48B, '⛔ H48 bounce exit: a newer PASS on an OLDER head clears nothing — still quiet', fire48([...RED48, fleet48(9, REC48(OLD48), '2026-12-04T07:00:00Z')]), 'object'); + b(BATTERY48B, '⛔ H48 bounce exit: a newer PASS by an author the queue guard does not trust clears nothing — still quiet', fire48([...RED48, { ...RE48, user: { login: 'someone' } }]), 'object'); + b(BATTERY48B, '⛔ H48 bounce exit: a PASS OLDER than the bounce clears nothing — the base PASS is that PASS', reading48(RED48).state, 'bounced'); + b(BATTERY48B, '⛔ H48 bounce: a red before a fix push (head moved, no re-review yet) still reads bounced — 复审过再挂', reading48([...BASE48, TRIAGE48(3, '2026-12-04T06:00:00Z')].map((r) => (r.id === 2 ? fleet48(2, REC48(OLD48), r.created_at) : r))).state, 'bounced'); + b(BATTERY48B, 'H48 bounce: the reading dates the bounce from the NEWEST trigger and names it', [reading48([...RED48], [{ ...CR48, submitted_at: '2026-12-04T05:30:00Z' }]).since?.trigger, reading48([...RED48], [{ ...CR48, submitted_at: '2026-12-04T06:30:00Z' }]).since?.trigger].join(), 'queue-red,changes-requested'); + b(BATTERY48B, 'H48 bounce: a comment QUOTING a record names no head and is no record', contractReviewBounceStanding(`> ${REC48(HEAD48, 'FAIL').split('\n').join('\n> ')}`, HEAD48), null); + b(BATTERY48B, 'H48 bounce: the record standing reads FAIL, open, PASS and the head off the ONE record reading', [contractReviewBounceStanding(REC48(HEAD48, 'FAIL'), HEAD48), contractReviewBounceStanding(REC48(OLD48, 'PASS', 'S1 (should-fix) — x.'), HEAD48), contractReviewBounceStanding(REC48(HEAD48), HEAD48)].map((r) => [r.fails, r.open, r.pass, r.onHead].join('/')).join(), 'true/false/false/true,false/true/false/false,false/false/true/true'); + // Three input states, never two (#4690): an unread leg is UNJUDGED, never a finding asking for the label back. + b(BATTERY48B, '⛔ H48 bounce: an UNCONSULTED leg (no fourth argument) is UNJUDGED — no finding', h48GovernedVerdictWithoutBrief(pr48b(), GOV48, BASE48), null); + b(BATTERY48B, '⛔ H48 bounce: an unread review page, or record authors that did not load, read `unread` and the row is UNJUDGED', [h48BounceReading({ rows: BASE48, reviews: null, headSha: HEAD48, authors: AUTH48 }).state, h48BounceReading({ rows: BASE48, reviews: [], headSha: HEAD48, authors: { available: false, reason: 'x' } }).state, typeof h48GovernedVerdictWithoutBrief(pr48b(), GOV48, BASE48, h48BounceReading({ rows: BASE48, reviews: null, headSha: HEAD48, authors: AUTH48 }))].join(), 'unread,unread,object'); + b(BATTERY48B, 'H48 bounce gathering: the leg is bought only where the row would fire without it', [h48NeedsBounceRead(pr48b(), GOV48, BASE48), h48NeedsBounceRead({ ...pr48b(), labels: [{ name: LABEL48 }] }, GOV48, BASE48), h48NeedsBounceRead(pr48b(), GOV48, [cm48(BRIEF48)]), h48NeedsBounceRead(pr48b(), GOV48, null), h48NeedsBounceRead(pr48b(), [], BASE48)].join(), 'true,false,false,false,false'); + // The source the queue-red trigger reads is the triage workflow's own marker: a rename there reds HERE. + { + const triage = readFileSync(new URL('../../.github/workflows/merge-queue-triage.yml', import.meta.url), 'utf8'); + b(BATTERY48B, 'H48 bounce source: the triage workflow still prints the per-run marker and the no-runner marker this reading greps', [triage.includes('const marker = ``;'), triage.includes('``'), triage.includes('issues.createComment({ owner, repo, issue_number: prNumber, body })')].join(), 'true,true,true'); + } + { + const src = readFileSync(fileURLToPath(import.meta.url), 'utf8'); + b(BATTERY48B, 'H48 bounce wiring: the sweep asks the ONE reading on the review page it buys and hands it to the row', [src.includes('bounce = h48BounceReading({ rows, reviews: await prReviewRowsFor(pr.number), headSha: String(pr.head?.sha ?? \'\'), authors: recordAuthors });'), src.includes('const handoff = h48GovernedVerdictWithoutBrief(pr, governed, rows, bounce);')].join(), 'true,true'); + } + b(BATTERY48B, 'H48 bounce summary: the bounced count rides the forwarding contract and the clause says what it costs', [SWEEP_COUNT_KEYS.includes('briefBounced'), saidBy('h48Brief', summaryLine({ briefJudged: 3, briefCandidates: 3, briefBounced: 2 }, 0)).includes('2 read bounced and stay quiet until a PASS on their current head')].join(), 'true,true'); + b(BATTERY48B, 'H48 bounce floor: this battery is DECLARED on the frozen roster with a positive pin', Object.hasOwn(SELF_TEST_BATTERIES, BATTERY48B) && SELF_TEST_BATTERIES[BATTERY48B] > 0 && Object.isFrozen(SELF_TEST_BATTERIES), true); // Registry, counters and the clause. t('H48 band: registered as a state row', familyBand('H48'), 'state'); diff --git a/scripts/pm/label-write.mjs b/scripts/pm/label-write.mjs index 2e078806d47..09891583180 100644 --- a/scripts/pm/label-write.mjs +++ b/scripts/pm/label-write.mjs @@ -267,6 +267,12 @@ * slice — plus one Tier H entry for the size limb or the declared narrowing when that is what admitted * the pull (`handoffSlice`: otherwise both rows stand down and read ✓ with nobody asked) — and told the hand-off * is DUE on the gate's own PASS. Any ✗ is exit 4, never repaired. + * bounce a pull sent back for changes is REFUSED (exit 2, zero writes, under `--dry-run` too, so never exit 7): + * `h48BounceReading` (`bounce-reading.mjs`, wired in check-half-states) reads a red merge-queue build (the + * triage workflow's comment), a newest `## Contract review` reading FAIL or carrying an open must-fix or + * should-fix, or a trusted reviewer's CHANGES_REQUESTED, with no PASS on the current head newer than it. H48 asks + * the same reading and stays quiet on such a pull, so the per-round reader and the patrol never ask for + * `pm:awaiting-merge` back before the re-review (「复审过再挂、入队,其间不补四件」). * once a pull already whole — the label on, every approver covered, a `## 维护者速读` brief on the thread — * sends nothing and exits 0: ⛔ no second request comment. Short of the brief, the request is owed. A request whose signature names an uncovered approver is refused: a seat never * requests its own account (「⛔ 永不请席位自身账号」). @@ -460,6 +466,8 @@ import { h43GovernedReviewRequestGap, readSignatureLine, h48GovernedVerdictWithoutBrief, + // …and the ONE bounce reading H48 asks (`bounce-reading.mjs`, wired there): a pull sent back is no hand-off. + h48BounceReading, } from './check-half-states.mjs'; import { GOVERNED_TIER_H, GOVERNED_TIER_S, LOW_RISK_CHANGESET_PATH, sizeLimbFires, slugFromRemote } from './check-governed-merges.mjs'; // The `--land` dogfood gate's readers (header: `--land` on a breaking or narrowing pull), each CALLED from its owner: @@ -1942,10 +1950,13 @@ function handoffPullView(pull, labels, assignees) { return { ...pull, labels: labels.map((name) => ({ name })), assignees: assignees.map((login) => ({ login })) }; } -/** The `now H43` / `④ H43` and `H48` lines: each row's own finding sentence, or ✓ when it has none. Pure. */ -export function handoffRowLines({ pull, matched, approvers, reviewed, handoff, rows }) { +/** + * The `now H43` / `④ H43` and `H48` lines: each row's own finding sentence, or ✓ when it has none. `bounce` is + * `h48BounceReading`'s answer, handed to H48 exactly as the patrol hands it (header: `--handoff`, bounce). Pure. + */ +export function handoffRowLines({ pull, matched, approvers, reviewed, handoff, rows, bounce }) { const h43 = h43GovernedReviewRequestGap(pull, matched, approvers, reviewed, handoff); - const h48 = h48GovernedVerdictWithoutBrief(pull, matched, rows); + const h48 = h48GovernedVerdictWithoutBrief(pull, matched, rows, bounce); return { h43, h48, clean: h43 === null && h48 === null }; } @@ -2026,13 +2037,15 @@ async function handoffGate(c) { const authors = { available: true, admits: (row) => recordAuthorTrusted(row, recognisers.trustedAuthors), reason: null }; const handoffPr = h43HandoffReading(rows, headSha, authors); + // The bounce (header: `--handoff`, bounce): the ONE reading H48 asks, on the thread and review page read above. + const bounce = h48BounceReading({ rows, reviews: reviews.json, headSha, authors }); const labels = labelNamesOf(c.card?.labels); const assigned = loginsOf(c.card?.assignees); const slice = handoffSlice(tier, paths); // `now H43` / `now H48` (header): the rows as the pull stands, printed on every exit past the reads. let nowClean = false; const printNow = (handoff) => { - const now = handoffRowLines({ pull: handoffPullView(pull.json, labels, assigned), matched: slice, approvers, reviewed, handoff, rows }); + const now = handoffRowLines({ pull: handoffPullView(pull.json, labels, assigned), matched: slice, approvers, reviewed, handoff, rows, bounce }); nowClean = now.clean; record(`[${stamp()}] ② now H43 ${now.h43 === null ? '✓' : '✗'} · now H48 ${now.h48 === null ? '✓' : '✗'} — ${repo}#${issue} as it stands, head \`${headSha.slice(0, 12)}\`${now.h43 ? `\n H43: ${now.h43}` : ''}${now.h48 ? `\n H48: ${now.h48}` : ''}`); }; @@ -2077,6 +2090,12 @@ async function handoffGate(c) { return stop(refuse(`the same-head \`## Contract review\` (comment ${pass.id} on the ${pass.where}) does not stand at its tier: the \`${pass.face}\` face owes \`Served-tier: ${pass.tierName}\` and its \`Served-tier:\` line reads ${pass.servedIsIdentifier ? 'a model-identifier token (not quoted)' : pass.served?.state === 'read' ? `\`${pass.served.value}\`` : pass.served?.state ?? 'nothing'}`)); } if (pass.state !== 'stands' || pass.verdict !== 'PASS') return stop(refuse(`the same-head \`## Contract review\` (comment ${pass.id} on the ${pass.where}) is not PASS: ${pass.verdictReason ?? pass.state}`)); + // A pull sent back for changes gets no piece of the hand-off back until its re-review passes (header: bounce). + if (bounce.state === 'unread') return stop(unread(`whether the pull was sent back for changes is unknown: ${bounce.reason}`)); + if (bounce.state === 'bounced') { + const s = bounce.since; + return stop(refuse(`the pull was sent back for changes — ${s.ref} (${s.trigger}, ${s.at ?? 'undated'}) — and no \`## Contract review\` PASS on the head \`${sha12}\` is newer than that: a bounced pull gets no piece of the hand-off back, \`${GOVERNED_PR_AWAITING_MERGE_LABEL}\` included, until its re-review passes (「复审过再挂、入队,其间不补四件」)`)); + } record(`[${stamp()}] ② hand-off records ✓ — ACCEPT ${handoffPr.record.createdAt} newer than head \`${sha12}\` · PASS comment ${pass.id} on the ${pass.where}, the \`${pass.face}\` face at \`Served-tier: ${pass.tierName}\``); // The gate's own verdict is what the rows are told: the hand-off is DUE, on the PASS the guard's reading chose. @@ -2085,7 +2104,7 @@ async function handoffGate(c) { const plan = handoffReviewPlan({ approvers, author: pull.json.user?.login ?? null, requested: (pull.json.requested_reviewers ?? []).map((u) => u?.login).filter(Boolean), assigned, reviewed }); const named = (l) => (l.length ? l.map((x) => `\`${x}\``).join(', ') : 'none'); record(`[${stamp()}] ② hand-off plan — covered ${named(plan.covered)} · request ${named(plan.toRequest)} · assign the author ${named(plan.toAssign)} · \`${GOVERNED_PR_AWAITING_MERGE_LABEL}\` ${labels.includes(GOVERNED_PR_AWAITING_MERGE_LABEL) ? 'already on' : 'to add'}`); - return { ok: true, plan, tier, slice, pull: pull.json, reviewed, rows, handoff, headSha, approvers, nowClean, hasBrief: latestMarkedComment(rows, MAINTAINER_BRIEF_MARKER) !== null }; + return { ok: true, plan, tier, slice, pull: pull.json, reviewed, rows, handoff, headSha, approvers, nowClean, bounce, hasBrief: latestMarkedComment(rows, MAINTAINER_BRIEF_MARKER) !== null }; } /** A dry run's exit: 0, or under `--handoff` `EXIT_HANDOFF_OWED` when a `now` row reads ✗ (header: exit codes). */ @@ -2268,7 +2287,7 @@ async function foldStroke(c) { const pending = (pullRead.json?.requested_reviewers ?? []).map((u) => String(u?.login ?? '').toLowerCase()); const unasked = gate.plan.toRequest.filter((a) => !pending.includes(a.toLowerCase())); record(`[${stamp()}] ④ reviewers ${mark(unasked.length === 0)} — pending ${render((pullRead.json?.requested_reviewers ?? []).map((u) => u?.login))} · requested by this stroke ${render(gate.plan.toRequest)}${unasked.length ? ` · NOT pending: ${render(unasked)}` : ''}`); - const rows = handoffRowLines({ pull: handoffPullView(pullRead.json ?? {}, backLabels, backAssignees), matched: gate.slice, approvers: gate.approvers, reviewed: gate.reviewed, handoff: gate.handoff, rows: hit ? [...gate.rows, hit] : gate.rows }); + const rows = handoffRowLines({ pull: handoffPullView(pullRead.json ?? {}, backLabels, backAssignees), matched: gate.slice, approvers: gate.approvers, reviewed: gate.reviewed, handoff: gate.handoff, rows: hit ? [...gate.rows, hit] : gate.rows, bounce: gate.bounce }); record(`[${stamp()}] ④ H43 ${mark(rows.h43 === null)} — ${rows.h43 ?? 'every GOVERNED_APPROVERS account is requested, assigned or has reviewed'}`); record(`[${stamp()}] ④ H48 ${mark(rows.h48 === null)} — ${rows.h48 ?? `\`${GOVERNED_PR_AWAITING_MERGE_LABEL}\` and a \`## 维护者速读\` brief both on the pull`}`); handoffClean = unasked.length === 0 && rows.clean; @@ -3038,7 +3057,9 @@ const SELF_TEST_BATTERIES = Object.freeze({ [LAND_DOGFOOD_BATTERY]: 64, [HAND_SET_BATTERY]: 42, // Raised 59 → 68 with the carried PASS: the git reader and base ref handed to the guard's `regenCarry`, both directions. - [HANDOFF_BATTERY]: 68, + // Raised 68 → 81 with the bounce: each trigger refused, each trigger's exit, the unbounced control and the flake, + // foreign-author and untrusted-reviewer controls that keep it a narrowing rather than a silencer. + [HANDOFF_BATTERY]: 81, }); const SELF_TEST_BATTERY_FLOOR = 19; const UNATTRIBUTED_BATTERY = '(unattributed)'; @@ -3963,10 +3984,13 @@ export async function selfTest() { const argv = ['--repo', 'objectstack-ai/objectstack', '--issue', '7', '--comment-file', REQ_FILE, '--handoff']; const hand = (b, extra = {}) => driveOffline(extra.argv ?? argv, b, { route, relay: extra.relay ?? 'success', files: { [REQ_FILE]: extra.request ?? REQUEST }, now: NOW, tierReading: extra.tier ?? TIER_H, recognisers, approvers: PAIR, ...(extra.send ? { send: extra.send } : {}), ...(extra.gitReader ? { gitReader: extra.gitReader } : {}) }); const writesOf = (run) => run.fake.calls.filter((c) => c.method !== 'GET').map((c) => `${c.method} ${c.path}`); - const handoffOf = (b) => h43HandoffReading(b.comments, b.head.sha, { available: true, admits: (r) => r?.user?.login === RELAY_COMMENT_AUTHOR }); + const RELAY_AUTHORS = { available: true, admits: (r) => r?.user?.login === RELAY_COMMENT_AUTHOR }; + const handoffOf = (b) => h43HandoffReading(b.comments, b.head.sha, RELAY_AUTHORS); + // H48 asks the bounce exactly as the patrol does: `h48BounceReading` over the thread and the review page. + const bounceOf = (b) => h48BounceReading({ rows: b.comments, reviews: b.reviews ?? [], headSha: b.head.sha, authors: RELAY_AUTHORS }); const rowsOn = (b, slice = H_SLICE, handoff = handoffOf(b)) => { const pull = { number: b.number, state: b.state, user: { login: b.author }, requested_reviewers: b.requested.map((login) => ({ login })), assignees: b.assignees.map((login) => ({ login })), labels: b.labels.map((name) => ({ name })), head: b.head }; - return { h43: h43GovernedReviewRequestGap(pull, slice, PAIR, [], handoff), h48: h48GovernedVerdictWithoutBrief(pull, slice, b.comments) }; + return { h43: h43GovernedReviewRequestGap(pull, slice, PAIR, [], handoff), h48: h48GovernedVerdictWithoutBrief(pull, slice, b.comments, bounceOf(b)) }; }; // The CLI owns the plan. @@ -4191,6 +4215,36 @@ export async function selfTest() { const owedDry = await hand(board(coveredNoBrief), { argv: ['--repo', 'objectstack-ai/objectstack', '--issue', '7', '--handoff', '--dry-run'], send: neverSend }); t('…and the per-round dry run on that pull never says it is whole: `now H48 ✗`, exit 7', [owedDry.exit, owedDry.text.includes('already handed off'), owedDry.text.includes('now H48 ✗')], [EXIT_HANDOFF_OWED, false, true]); + // ⭐ The bounce (header: `--handoff`, bounce): a pull sent back for changes — its ACCEPT and same-head PASS still on + // the thread, the label taken off — is REFUSED, under --dry-run too, so the per-round reader never answers exit 7 + // and the real stroke never puts the label back; a NEWER PASS on the current head restores today's reading. One + // cell per trigger and one exit cell per trigger, each red on `main` (exit 7, and the real stroke adds the label). + const DRY = ['--repo', 'objectstack-ai/objectstack', '--issue', '7', '--handoff', '--dry-run']; + const TRIAGE = (id, created, extra = '') => ({ id, user: { login: 'github-actions[bot]' }, created_at: created, updated_at: created, body: `### ⛔ merge queue 构建失败 — 先分诊,再决定要不要重排\n\n**分类:\`failure\`** —— 按下面的日志分诊。\n\n\n${extra}---\n_Generated by [Claude Code](https://claude.ai/code) · merge-queue-triage workflow_\n` }); + const RE_PASS = row(504, '2026-11-08T15:00:00Z', PASS()); + const CR = [{ id: 901, state: 'CHANGES_REQUESTED', user: { login: 'os-zhuang' }, submitted_at: '2026-11-08T14:30:00Z', author_association: 'CONTRIBUTOR' }]; + const bounced = (run) => [run.exit, run.sent.length, writesOf(run).length, run.text.includes('sent back for changes'), run.text.includes('now H48 ✓')]; + const BOUNCED = [EXIT_USAGE, 0, 0, true, true]; + const owedAgain = (run) => [run.exit, run.text.includes('sent back for changes'), run.text.includes('now H48 ✗')]; + const OWED_AGAIN = [EXIT_HANDOFF_OWED, false, true]; + const unbounced = await hand(board(), { argv: DRY, send: neverSend }); + t('⭐ bounce control: an UNBOUNCED pull with ACCEPT, a same-head PASS and no label still reads `now H48 ✗`, exit 7', owedAgain(unbounced), OWED_AGAIN); + const red = () => board({ comments: [...board().comments, TRIAGE(503, '2026-11-08T14:30:00Z')] }); + t('⭐ bounce ① a red merge-queue build on the same head (the triage comment): the dry run is REFUSED, `now H48 ✓`, exit 2, zero sends — never exit 7', bounced(await hand(red(), { argv: DRY, send: neverSend })), BOUNCED); + t('⭐ …and the real stroke is refused too: the label is NOT put back, zero sends', bounced(await hand(red())), BOUNCED); + t('⭐ bounce ① exit: a NEWER PASS on the current head clears it — exit 7 again, `now H48 ✗`', owedAgain(await hand(board({ comments: [...red().comments, RE_PASS] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + t('bounce ① control: a red whose triage comment carries the `infra:no-runner` marker is the flake class, no bounce — exit 7', owedAgain(await hand(board({ comments: [...board().comments, TRIAGE(503, '2026-11-08T14:30:00Z', `\n`)] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + t('bounce ① control: the same comment from any author but the triage workflow is no bounce — exit 7', owedAgain(await hand(board({ comments: [...board().comments, { ...TRIAGE(503, '2026-11-08T14:30:00Z'), user: { login: 'someone' } }] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + const failNewest = () => board({ comments: [...board().comments, row(503, '2026-11-08T14:30:00Z', PASS(OLD_HEAD, '`CONTRACT_REVIEW_TIER`', 'FAIL'))] }); + t('⭐ bounce ② the NEWEST review record reads FAIL (here on another head, so the same-head PASS still stands): REFUSED, exit 2, zero sends', bounced(await hand(failNewest(), { argv: DRY, send: neverSend })), BOUNCED); + t('⭐ bounce ② exit: a NEWER PASS on the current head clears it — exit 7 again', owedAgain(await hand(board({ comments: [...failNewest().comments, RE_PASS] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + const openNewest = () => board({ comments: [...board().comments, row(503, '2026-11-08T14:30:00Z', PASS(OLD_HEAD).replace('No must-fix, no should-fix.', 'S1 (should-fix) — the read-back skips the label.'))] }); + t('bounce ② an open should-fix in the newest record is a bounce too: REFUSED, exit 2', bounced(await hand(openNewest(), { argv: DRY, send: neverSend })), BOUNCED); + t('⭐ bounce ③ the approver\'s CHANGES_REQUESTED review: REFUSED, exit 2, zero sends', bounced(await hand(board({ reviews: CR }), { argv: DRY, send: neverSend })), BOUNCED); + t('⭐ bounce ③ exit: a NEWER PASS on the current head clears it — exit 7 again', owedAgain(await hand(board({ reviews: CR, comments: [...board().comments, RE_PASS] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + t('bounce ③ control: a later APPROVED by the same reviewer supersedes the request — exit 7', owedAgain(await hand(board({ reviews: [...CR, { ...CR[0], id: 902, state: 'APPROVED', submitted_at: '2026-11-08T14:40:00Z' }] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + t('bounce ③ control: a CHANGES_REQUESTED by a reviewer the queue guard does not trust is no bounce — exit 7', owedAgain(await hand(board({ reviews: [{ ...CR[0], user: { login: 'someone' }, author_association: 'MEMBER' }] }), { argv: DRY, send: neverSend })), OWED_AGAIN); + // The rule this mode writes is the skill's, pinned as substrings so a reworded rule reds here. const skill = readFileSync(new URL(HANDOFF_RULE_PATH, REPO_ROOT), 'utf8'); const perRound = readFileSync(new URL('.claude/skills/pm-dispatch/references/execution-duties.md', REPO_ROOT), 'utf8');