diff --git a/scripts/pm/check-half-states.mjs b/scripts/pm/check-half-states.mjs index 4b0a9a678d7..b415c207764 100644 --- a/scripts/pm/check-half-states.mjs +++ b/scripts/pm/check-half-states.mjs @@ -266,6 +266,18 @@ * handler. `unknown`/null readings are SKIPPED and never vouched for — * GitHub computes mergeability asynchronously, so that reading is the * platform saying "ask again later", not a state to name. + * H82 a CLAIMED card's PR that CI cannot see, silent past the threshold: + * a DRAFT in merge conflict, or a head — draft or not — carrying zero + * GitHub Actions check suites. A card PR stays draft until its seat + * lands it, so H12 and H16 (non-draft only) were blind where the + * in-flight work is, and nothing read whether CI started at all: a + * conflicting PR starts no `pull_request` workflow, so no green or red + * event ever wakes the thread waiting for one. "Claimed" is a bound + * card (closing keyword or `Part of`) the sweep holds under + * `pm:dispatched`. Two per-PR reads for candidates only — the PR row + * (shared with H16's) and the head's check suites filtered to the + * Actions app; an unread suite is UNJUDGED, counted in the summary, + * never a zero. A non-draft dirty PR stays H16's row alone. * * ## H17 — an item here that is NOT an invariant * @@ -4598,6 +4610,130 @@ export function h16StuckMergeConflict(pr, nowMs = Date.now()) { ); } +// --------------------------------------------------------------------------- +// H82 — a claimed card's PR that CI cannot see: a DRAFT in merge conflict, or +// a head that carries no GitHub Actions check suite at all. +// +// H12 and H16 read only non-draft PRs, and in this fleet a card PR stays draft +// until its seat lands it — so the conflict detector was blind exactly where +// the in-flight work is. And neither row reads whether CI started at all: a +// conflicting PR starts no `pull_request` workflow, so its head carries ZERO +// Actions check suites, no green and no red event ever arrives, and a card +// thread waiting "until CI is green" waits on nothing while its seat waits on +// the thread. `dispatch-runbook.md` 〈卡线程〉 states the wake rule this row +// reads mechanically: zero Actions 30 minutes after the push, or `dirty`. +// --------------------------------------------------------------------------- + +/** + * H82 threshold, in MINUTES — the wait the card-thread rule allows before the + * seat wakes the thread (`推后 30 分钟零 Actions`; the self-test pins the number). + * + * Aged by the PR's `updated_at`, H16's proxy and for H16's reason: neither a + * conflict nor a missing suite carries a timestamp of its own, a push bumps + * the PR row, and `main` advancing under it does not. The error direction is + * H16's too — a quiet PR whose base just moved flags at once (over-report), + * while a comment on the PR defers the row by one threshold (a bounded + * under-report, never a silence). + */ +export const CLAIMED_PR_BLIND_STALE_MINUTES = 30; + +/** + * The GitHub Actions app id, the `app_id` filter on the check-suites read. + * Unfiltered, the other apps' suites hide the gap: measured on the head this + * row is written for, `/commits/SHA/check-suites` answered 5 suites (deploy + * previews, the fleet app) and 0 of them Actions', while a head CI ran on + * answered 10 Actions suites of 15. + */ +export const GITHUB_ACTIONS_APP_ID = 15368; + +/** + * The claimed cards a PR delivers: the cards its body binds — H16's + * extractor, a closing keyword or `Part of`, quoted spellings naming nothing — + * that the sweep holds OPEN under `pm:dispatched`. + * + * `pm:dispatched` is the claim's machine-readable bit: the state model defines + * the label as claimed and assigned, and a label without its claim is H1/H2's + * row, never a reason for this one to stay silent. Reading the label costs no + * request; reading every bound card's thread again would. + * + * @param {object} pr — a PR row (list or single). + * @param {Iterable} dispatched — open `pm:dispatched` card numbers. + * @returns {number[]} ascending. + */ +export function h82ClaimedCards(pr, dispatched) { + const held = new Set([...(dispatched ?? [])].map(Number)); + return h16HeldCards(pr?.body).filter((n) => held.has(n)); +} + +/** + * Whether this PR buys the H82 reads — the gathering policy, exported so the + * self-test pins that it is never NARROWER than the predicate. + * + * Open (draft or not: the no-Actions leg reads both), not merged, not the + * release bot's `changeset-release/*` head, bound to at least one claimed card, + * and either silent past the threshold or carrying an unreadable `updated_at` + * — which the predicate flags rather than reads as fresh, so skipping it here + * would drop the row the predicate promises. + */ +export function h82NeedsDetail(pr, claimed, nowMs = Date.now()) { + if (!pr || typeof pr.draft !== 'boolean' || pr.merged_at) return false; + if ((pr.head?.ref ?? '').startsWith('changeset-release/')) return false; + if ((claimed ?? []).length === 0) return false; + const updated = Date.parse(pr.updated_at ?? ''); + if (!Number.isFinite(updated)) return true; + return (nowMs - updated) / 60_000 > CLAIMED_PR_BLIND_STALE_MINUTES; +} + +/** + * H82 — null when clean or unjudged, else the finding sentence. Takes the + * SINGLE-PR payload (the listing carries no `mergeable_state`) and the + * check-suites reading for its head. + * + * Two legs, one row per PR: + * + * dirty a DRAFT whose `mergeable_state` is literally `dirty`. A + * non-draft dirty PR is H16's row, so it is ⛔ not reported + * twice; `unknown` is the platform saying "ask again later" and + * is skipped, as in H16. + * no Actions any claimed PR, draft or not, not dirty, whose head answered + * `total_count: 0` for the Actions app. A reading of `null` — + * the read failed, or was not made — is UNJUDGED and says + * nothing: the summary clause counts it, the row never invents + * a zero. + * + * @param {object} pr — the single-PR payload. + * @param {number[]} claimed — `h82ClaimedCards` for it. + * @param {{ actionsSuites: number|null }} reading + */ +export function h82ClaimedPrBlind(pr, claimed, reading, nowMs = Date.now()) { + if (!h82NeedsDetail(pr, claimed, nowMs)) return null; + const dirty = pr.mergeable_state === 'dirty'; + if (dirty && pr.draft !== true) return null; + const suites = reading?.actionsSuites; + if (!dirty && suites !== 0) return null; + const updated = Date.parse(pr.updated_at ?? ''); + const age = Number.isFinite(updated) + ? `untouched for ~${Math.round((nowMs - updated) / 60_000)} min (threshold ${CLAIMED_PR_BLIND_STALE_MINUTES} min)` + : 'with an unreadable `updated_at` (which must not read as fresh)'; + const cards = `${claimed.length === 1 ? 'card' : 'cards'} ${claimed.map((n) => `#${n}`).join(', ')}`; + const head = String(pr.head?.sha ?? '').slice(0, 10) || 'unread'; + if (dirty) { + return ( + `a claimed ${cards} (\`pm:dispatched\`) delivered by this DRAFT, which is in MERGE CONFLICT ` + + `(\`mergeable_state: dirty\`), ${age} — a conflicting PR starts no \`pull_request\` workflow, so no ` + + 'green or red event ever arrives and a thread waiting for CI waits on nothing. H16 reads only ' + + 'non-draft PRs, and a card PR stays draft until its seat lands it. The seat wakes the card thread ' + + 'this round; the thread merges `origin/main`, resolves, pushes, and confirms Actions started.' + ); + } + return ( + `a claimed ${cards} (\`pm:dispatched\`) delivered by this ${pr.draft ? 'DRAFT' : 'ready'} PR, whose head ` + + `\`${head}\` carries ZERO GitHub Actions check suites, ${age} — no CI ever ran on this head, so no ` + + 'green or red event will arrive. The seat wakes the card thread this round; the thread re-reads ' + + '`mergeable_state`, merges `origin/main` and pushes again, and confirms Actions started on the new head.' + ); +} + // --------------------------------------------------------------------------- // H17 — the on-hold TRIGGER-FILE INDEX. Not a predicate: an inventory. // @@ -19101,6 +19237,13 @@ export const SWEEP_COUNT_KEYS = [ 'conflictProbed', 'sharedFileCandidates', 'sharedFileProbed', + // H82's coverage quadruple: claimed card PRs past the threshold, how many PR + // rows answered, and of the heads not dirty, how many check-suite reads were + // owed and how many answered (an unread one is UNJUDGED, never a zero). + 'claimedPrCandidates', + 'claimedPrProbed', + 'claimedPrSuitesOwed', + 'claimedPrSuitesRead', // H43's coverage triple and its fourth state (#14967) — the register that // did not load. `governedRegisterReason` is a STRING, not a counter, and it // rides the same contract for the same reason: without it the clause would @@ -19714,6 +19857,10 @@ export function summaryLine(counts, findingCount) { `Shared-file holds (H36): changed-file page read on ${counts.sharedFileProbed ?? 0} of ` + `${counts.sharedFileCandidates ?? 0} open PR(s) — a pair needs both sides read, so a shortfall ` + 'can only MISS a hold, never invent one. ' + + `Claimed card PRs (H82): PR row read on ${counts.claimedPrProbed ?? 0} of ${counts.claimedPrCandidates ?? 0} ` + + `open PR(s) bound to a \`pm:dispatched\` card and silent past ${CLAIMED_PR_BLIND_STALE_MINUTES} min, and the Actions ` + + `check suites read on ${counts.claimedPrSuitesRead ?? 0} of ${counts.claimedPrSuitesOwed ?? 0} head(s) not in conflict` + + `${(counts.claimedPrSuitesRead ?? 0) < (counts.claimedPrSuitesOwed ?? 0) ? ' — an unread head is UNJUDGED on the no-Actions leg, never clean' : ''}. ` + // H43's coverage clause (#14967). It is UNCONDITIONAL, like every other // window's: this row can be quiet for three different reasons — no governed // PR is short of coverage, no file page was read, or the register itself @@ -20110,6 +20257,7 @@ export const SUMMARY_CLAUSE_ANCHORS = [ ['h20Dispatch', 'Dispatch liveness (H20 + H27): '], ['h32Seats', 'Seat liveness (H32): '], ['h36SharedFiles', 'Shared-file holds (H36): '], + ['h82ClaimedPrs', 'Claimed card PRs (H82): '], ['h43GovernedReviews', 'Governed review requests (H43): '], ['h37Folds', 'Family folds (H37): '], ['h40References', 'Dangling references (H40): '], @@ -20601,6 +20749,8 @@ export const HALF_STATE_FAMILY_BAND = Object.freeze({ H4: 'stall', H12: 'stall', H16: 'stall', + // H82 is a `stall` for H16's reason: a claimed PR CI cannot see never lands. + H82: 'stall', H19: 'stall', H20: 'stall', H26: 'stall', @@ -22358,6 +22508,12 @@ async function sweep(options = {}) { // mode as H16's detail pass, so it owes the same `read X of Y`. sharedFileCandidates: 0, sharedFileProbed: 0, + // H82's coverage quadruple — the PR-row half shares H16's per-row failure + // mode; the check-suite half is disclosed rather than rethrown (sweep pass). + claimedPrCandidates: 0, + claimedPrProbed: 0, + claimedPrSuitesOwed: 0, + claimedPrSuitesRead: 0, // H43's coverage triple (#14967) — the governed slice of the PRs whose // file page H36 already read, how many of those the cheap union left // short, and how many review pages answered. `governedRegisterReason` is @@ -24831,6 +24987,8 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen // a bounded gap the report states, while "no row readable" is a sweep whose // H16 pass silently examined nothing and would otherwise print as quiet. let lastDetailError = null; + // The PR rows this pass read, kept for H82 below so a PR both rows want costs ONE GET. + const prDetails = new Map(); for (const pr of seenPrs.values()) { if (!h16NeedsDetail(pr)) continue; stats.conflictCandidates = (stats.conflictCandidates ?? 0) + 1; @@ -24842,6 +25000,7 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen continue; } stats.conflictProbed = (stats.conflictProbed ?? 0) + 1; + prDetails.set(pr.number, detail); const stuck = h16StuckMergeConflict(detail); if (stuck) findings.push([pr, 'H16', stuck]); } @@ -24849,6 +25008,57 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen throw lastDetailError; } + // H82 — a claimed card's PR that CI cannot see. Candidates only + // (`h82NeedsDetail`: bound to an open `pm:dispatched` card the label pages + // above already hold, and silent past the threshold), so the cost is bounded + // by the in-flight card PRs. Two reads each: the PR row (reused when H16 + // read it) and, for a head not in conflict, its check suites filtered to the + // Actions app. + // + // The PR-row half takes H16's posture: one failed read drops that PR, an + // all-failed pass is the transport and is rethrown. The check-suite half is + // DISCLOSED instead of rethrown — it needs a scope the PR row does not + // (`checks`), so a token without it must cost the no-Actions leg, stated on + // the summary line, never the whole sweep. + const dispatchedCards = [...seen.values()].filter((i) => labelNames(i).includes('pm:dispatched')).map((i) => i.number); + let lastClaimedError = null; + for (const pr of seenPrs.values()) { + const claimed = h82ClaimedCards(pr, dispatchedCards); + if (!h82NeedsDetail(pr, claimed)) continue; + stats.claimedPrCandidates = (stats.claimedPrCandidates ?? 0) + 1; + let detail = prDetails.get(pr.number); + if (!detail) { + try { + detail = await rest(`/repos/${OWNER_REPO}/pulls/${pr.number}`); + } catch (err) { + lastClaimedError = err; + continue; + } + } + stats.claimedPrProbed = (stats.claimedPrProbed ?? 0) + 1; + let actionsSuites = null; + const sha = detail?.head?.sha ?? pr.head?.sha ?? null; + if (detail?.mergeable_state !== 'dirty') { + stats.claimedPrSuitesOwed = (stats.claimedPrSuitesOwed ?? 0) + 1; + if (sha) { + try { + const page = await rest(`/repos/${OWNER_REPO}/commits/${sha}/check-suites?app_id=${GITHUB_ACTIONS_APP_ID}&per_page=1`); + if (Number.isInteger(page?.total_count)) { + actionsSuites = page.total_count; + stats.claimedPrSuitesRead = (stats.claimedPrSuitesRead ?? 0) + 1; + } + } catch { + actionsSuites = null; + } + } + } + const blind = h82ClaimedPrBlind(detail, claimed, { actionsSuites }); + if (blind) findings.push([pr, 'H82', blind]); + } + if (h16DetailPassUnreadable(stats.claimedPrCandidates, stats.claimedPrProbed)) { + throw lastClaimedError; + } + // H36 (#12286) — the shared-file pass, H16's transport posture over one // changed-file page per open PR (the population this sweep already listed; // gathering policy at `h36NeedsFiles`). A failed page drops that PR out of @@ -26451,6 +26661,10 @@ export const SELF_TEST_BATTERIES = Object.freeze({ // Registered with the unowned-PR row, pin just under the count: the firing, the assignee/mailbox/closed // exemptions, the unread-label UNJUDGED leg, the text, the band and the wiring. 'H76 unowned open PR': 11, + // Registered with the claimed-card-PR row, pin AT the count: each leg's firing case beside the control that + // silences it, H16's blind spot read both ways, the unread suite that must stay silent, the gate, the band, + // the summary pair and the wiring. + 'H82 claimed card PR CI cannot see': 24, // Registered with the ruled-card-in-the-box row (#29386), pin just under the // count: the firing case, the label / fence / anchoring / id controls each // beside its positive twin, the threshold boundary, the governing stamp, the @@ -29690,6 +29904,43 @@ async function selfTest() { b(BATTERY76, 'H76 wiring: every listed open PR is judged with the label taken LAZILY from mailbox-open.mjs, never spelled in the sweep', (() => { const src = readFileSync(fileURLToPath(import.meta.url), 'utf8'); return src.includes("({ MAILBOX_LABEL: mailboxLabel } = await import('./mailbox-open.mjs'));") && src.includes('const unowned = h76OpenPrWithoutAssignee(pr, mailboxLabel);'); })(), true); b(BATTERY76, 'floor: this battery is DECLARED on the frozen roster with a positive pin', Object.hasOwn(SELF_TEST_BATTERIES, BATTERY76) && SELF_TEST_BATTERIES[BATTERY76] > 0 && Object.isFrozen(SELF_TEST_BATTERIES), true); + // -- H82: a claimed card's PR that CI cannot see. Offline fixtures in the single-PR payload's shape, the head + // the measured incident had (zero Actions suites, five from other apps), never a live read. + const BATTERY82 = 'H82 claimed card PR CI cannot see'; + const NOW82 = Date.parse('2026-11-22T12:00:00Z'); + const minsAgo82 = (m) => new Date(NOW82 - m * 60_000).toISOString(); + const SHA82 = '473c7ff4aa0000000000000000000000000000aa'; + const pr82 = (extra = {}) => ({ number: 35923, draft: true, merged_at: null, mergeable_state: 'clean', updated_at: minsAgo82(120), head: { ref: 'claude/project-thread-x', sha: SHA82 }, body: 'Fixes #35897\nFixes #35899', ...extra }); + const claimed82 = h82ClaimedCards(pr82(), [35897, 35899, 1]); + const row82 = (extra = {}, suites = 5, claimed = claimed82, now = NOW82) => String(h82ClaimedPrBlind(pr82(extra), claimed, { actionsSuites: suites }, now) ?? ''); + b(BATTERY82, 'H82 claimed: the bound cards the sweep holds under `pm:dispatched`, ascending', claimed82.join(), '35897,35899'); + b(BATTERY82, '⛔ H82 claimed: a bound card NOT under `pm:dispatched` is not claimed, and its dispatched twin is', [h82ClaimedCards(pr82({ body: 'Fixes #7' }), [35897]).length, h82ClaimedCards(pr82({ body: 'Fixes #35897' }), [35897]).length].join(), '0,1'); + b(BATTERY82, 'H82 claimed: `Part of #N` binds as H16 reads it; a backticked `Fixes #N` binds nothing', [h82ClaimedCards(pr82({ body: 'Part of #35897' }), [35897]).join(), h82ClaimedCards(pr82({ body: 'quoting `Fixes #35897`' }), [35897]).length].join('/'), '35897/0'); + b(BATTERY82, 'H82 claimed: an absent body or an absent dispatched list claims nothing, never a crash', [h82ClaimedCards({}, [1]).length, h82ClaimedCards(pr82(), undefined).length].join(), '0,0'); + const dirty82 = row82({ mergeable_state: 'dirty' }); + b(BATTERY82, '⭐ H82 fires: a claimed DRAFT in merge conflict past the threshold, naming the state, both cards and the wake', ['MERGE CONFLICT', '`mergeable_state: dirty`', 'cards #35897, #35899', 'wakes the card thread', 'confirms Actions started'].every((x) => dirty82.includes(x)), true); + b(BATTERY82, '⛔ H82 control: the same draft CLEAN with Actions suites on its head is silent', row82(), ''); + b(BATTERY82, '⭐ H82: H16 is silent on the dirty draft H82 fires on — the blind spot this row closes', `${h16StuckMergeConflict(pr82({ mergeable_state: 'dirty', updated_at: minsAgo82(600) }), NOW82)}/${row82({ mergeable_state: 'dirty', updated_at: minsAgo82(600) }).length > 0}`, 'null/true'); + const none82 = row82({}, 0); + b(BATTERY82, '⭐ H82 fires: a claimed draft, not in conflict, whose head carries ZERO Actions suites — naming the head', ['ZERO GitHub Actions check suites', '`473c7ff4aa`', 'DRAFT PR', 'no CI ever ran on this head'].every((x) => none82.includes(x)), true); + b(BATTERY82, '⭐ H82: a claimed READY PR with zero Actions suites fires too — the no-Actions leg reads draft or not', row82({ draft: false }, 0).includes('ready PR'), true); + b(BATTERY82, '⛔ H82: a claimed non-draft DIRTY PR is H16\'s row alone, never reported twice — and H16 does fire on it', `${row82({ draft: false, mergeable_state: 'dirty', updated_at: minsAgo82(300) }, 0) === ''}/${typeof h16StuckMergeConflict(pr82({ draft: false, mergeable_state: 'dirty', updated_at: minsAgo82(300) }), NOW82)}`, 'true/string'); + b(BATTERY82, '⛔ H82: an UNREAD suite reading (null) is silent — never a zero — while its read zero twin fires', `${row82({}, null) === ''}/${row82({}, 0).length > 0}`, 'true/true'); + b(BATTERY82, 'H82: `unknown` mergeable state is not a conflict — silent with suites, still firing on zero suites', `${row82({ mergeable_state: 'unknown' }, 3) === ''}/${row82({ mergeable_state: 'unknown' }, 0).length > 0}`, 'true/true'); + b(BATTERY82, 'H82: exactly at the threshold is silent, a minute past it fires', `${row82({ updated_at: minsAgo82(CLAIMED_PR_BLIND_STALE_MINUTES) }, 0) === ''}/${row82({ updated_at: minsAgo82(CLAIMED_PR_BLIND_STALE_MINUTES + 1) }, 0).length > 0}`, 'true/true'); + b(BATTERY82, 'H82: an unreadable `updated_at` FIRES and says so, never reads as fresh', row82({ updated_at: 'not-a-date' }, 0).includes('unreadable `updated_at`'), true); + b(BATTERY82, '⛔ H82: an UNCLAIMED dirty draft is silent (no bound dispatched card), its claimed twin fires', `${row82({ mergeable_state: 'dirty' }, 5, []) === ''}/${dirty82.length > 0}`, 'true/true'); + b(BATTERY82, '⛔ H82: the release bot\'s head, a merged row and a row without a `draft` field are out of scope', [row82({ head: { ref: 'changeset-release/main', sha: SHA82 } }, 0), row82({ merged_at: '2026-11-22T10:00:00Z' }, 0), String(h82ClaimedPrBlind({ mergeable_state: 'dirty', updated_at: minsAgo82(600), body: 'Fixes #35897' }, [35897], { actionsSuites: 0 }, NOW82) ?? '')].join('|'), '||'); + const fixtures82 = [{}, { mergeable_state: 'dirty' }, { draft: false }, { updated_at: 'not-a-date' }, { updated_at: minsAgo82(31) }, { updated_at: minsAgo82(5) }, { mergeable_state: 'unknown' }, { merged_at: '2026-11-22T10:00:00Z' }]; + b(BATTERY82, 'H82 gate: never NARROWER than the predicate — every fixture that fires was a candidate', fixtures82.every((x) => [0, 5, null].every((s) => row82(x, s) === '' || h82NeedsDetail(pr82(x), claimed82, NOW82))), true); + b(BATTERY82, 'H82 gate: a fresh PR buys no read, an unreadable timestamp does, an unclaimed PR does not', [h82NeedsDetail(pr82({ updated_at: minsAgo82(5) }), claimed82, NOW82), h82NeedsDetail(pr82({ updated_at: 'x' }), claimed82, NOW82), h82NeedsDetail(pr82(), [], NOW82)].join(), 'false,true,false'); + b(BATTERY82, 'H82 constants: the card-thread wake rule\'s 30 minutes, and the GitHub Actions app id the suite read filters on', `${CLAIMED_PR_BLIND_STALE_MINUTES}/${GITHUB_ACTIONS_APP_ID}`, '30/15368'); + b(BATTERY82, 'H82 band: a `stall`, registered, and the sweep really pushes it; not a loud finding', `${familyBand('H82')}/${familyRegistryCoverage().emitted.includes('H82')}/${isLoudFinding(none82)}`, 'stall/true/false'); + b(BATTERY82, 'H82 summary: a partial suite read says how much and that an unread head is UNJUDGED; a full one does not', (() => { const part = saidBy('h82ClaimedPrs', summaryLine({ claimedPrCandidates: 3, claimedPrProbed: 3, claimedPrSuitesOwed: 2, claimedPrSuitesRead: 1 }, 0)); const full = saidBy('h82ClaimedPrs', summaryLine({ claimedPrCandidates: 3, claimedPrProbed: 3, claimedPrSuitesOwed: 2, claimedPrSuitesRead: 2 }, 0)); return part.includes('PR row read on 3 of 3') && part.includes('read on 1 of 2 head(s)') && part.includes('UNJUDGED') && !full.includes('UNJUDGED'); })(), true); + b(BATTERY82, 'H82 summary: the four count keys ride the enumerated contract', ['claimedPrCandidates', 'claimedPrProbed', 'claimedPrSuitesOwed', 'claimedPrSuitesRead'].every((k) => SWEEP_COUNT_KEYS.includes(k)), true); + b(BATTERY82, 'H82 wiring: after H16\'s rethrow, the PR row reused from H16, the suites read filtered to the Actions app, a failed suite read left UNJUDGED and not rethrown', (() => { const src = readFileSync(fileURLToPath(import.meta.url), 'utf8'); const at = src.indexOf('const blind = h82ClaimedPrBlind(detail, claimed, { actionsSuites });'); return at > src.indexOf('throw lastDetailError;') && src.includes('let detail = prDetails.get(pr.number);') && src.includes('/check-suites?app_id=${GITHUB_ACTIONS_APP_ID}&per_page=1') && /\} catch \{\n\s+actionsSuites = null;\n/u.test(src) && src.includes('throw lastClaimedError;'); })(), true); + b(BATTERY82, 'floor: this battery is DECLARED on the frozen roster with a positive pin', Object.hasOwn(SELF_TEST_BATTERIES, BATTERY82) && SELF_TEST_BATTERIES[BATTERY82] > 0, true); + // -- H73 (#29386): a RULED decision card still sitting in the decision box. // Positive controls beside every negative one: the label, the fence, the // anchoring, the id, the threshold, the governing stamp, the re-entry line. diff --git a/scripts/pm/post-stamped.mjs b/scripts/pm/post-stamped.mjs index dbd2e8d9f4b..9c87db7b926 100644 --- a/scripts/pm/post-stamped.mjs +++ b/scripts/pm/post-stamped.mjs @@ -483,6 +483,15 @@ * analysis that check could never find is not written. `decisionFacetRefusals`' banner carries the predicate, the * measurement it was chosen on, and what it cannot see. `--comment` only. * + * ## A claim goes out with its labels, never alone + * + * A comment whose first keyed line (after the signature) is `Claim:` is `EXIT_REFUSED` with zero writes, and the + * refusal prints the `label-write.mjs --comment-file … --add pm:dispatched --remove pm:queue --assign LOGIN` stroke + * that folds the same comment — judged by `judgeBody`, unchanged — with the labels and assignee. Measured: claims + * posted here as lone comments left their cards `pm:queue` and unassigned until triage knocked. Judged after the route + * is resolved, on one arm: on a route resolved `direct` the fold does not exist (it is relay-only) and the claim stays + * this tool's write, said on stderr. `claimStrokeRefusal` carries why it is not in `judgeBody`. `--comment` only. + * * ## ⚖️ Why this ACTS by default, where `sweep-closed-cards.mjs` dry-runs * * Its sibling next door defaults to a dry run and needs `--write`, because it @@ -2058,6 +2067,61 @@ export function keyedLineRefusalText(rows) { ); } +// --------------------------------------------------------------------------- +// A claim is ONE stroke with its labels and assignee — a lone `Claim:` comment is refused before the write +// --------------------------------------------------------------------------- + +/** + * The claim this comment OPENS with — its first keyed line, read after one leading signature line + * (`stripSignatureLine`) through the patrol's own marker (`CLAIM_COMMENT_MARKER` by `markerMatches`, so a decorated + * `> Claim:` is a claim here exactly as it is to H2) — or null. Only the opening line: a round report or a seat post + * that quotes a `Claim:` further down is not a claim being made, and stays this tool's write. Pure. + */ +export function openingClaimLine(body) { + const first = stripSignatureLine(body) + .split(/\r?\n/) + .find((line) => line.trim() !== ''); + return first !== undefined && markerMatches(CLAIM_COMMENT_MARKER, first) ? first.trim() : null; +} + +/** + * Why this comment must not go out alone, or null. A claim sent here lands while the card's labels and assignee do + * not move: the card stays `pm:queue`, unassigned, readable as free, until a sweep or a triage knock notices — the + * half-state the one-stroke rule exists to prevent. `label-write.mjs --comment-file` folds the same comment, judged by + * this file's own `judgeBody`, into the stroke that moves the labels, comment first. + * + * ⛔ Deliberately NOT in `judgeBody`: that is the path `label-write` folds through, and the fold is the remedy. And + * route-aware, on one arm only: the fold is RELAY-ONLY (`label-write.mjs` header), so on a route resolved `direct` + * — the one place it does not exist — the claim stays this tool's write and `main` says so. Any other route, an + * undecidable one included (it cannot prove the fold absent), is refused. `--comment` only. Pure. + * + * @param {string} body — the rendered bytes this act would send. + * @param {{ mode: string, route: { transport?: string|null, error?: string|null } | null }} ctx + * @returns {{ line: string, transport: string|null } | null} + */ +export function claimStrokeRefusal(body, { mode, route } = {}) { + if (mode !== 'comment') return null; + const line = openingClaimLine(body); + if (line === null) return null; + if (route && !route.error && route.transport === 'direct') return null; + return { line, transport: route && !route.error ? route.transport ?? null : null }; +} + +/** The refusal a caller reads, naming the stroke that carries the same comment. */ +export function claimStrokeRefusalText(refusal, { number = 'N', file = null } = {}) { + const transport = refusal.transport ? `the route resolved \`${refusal.transport}\`` : 'the route could not be decided, so the fold cannot be ruled out'; + return ( + 'post-stamped: REFUSED — this comment opens with a `Claim:` line, and a claim is ONE stroke with its labels and ' + + 'assignee. Nothing was written.\n' + + ` line: ${offendingSpan(refusal.line, 160)}\n` + + ' Sent alone, the claim lands and the card stays `pm:queue` with no assignee — readable as free — until someone\n' + + ' notices. Fold it into the label write, comment first, in one relay stroke:\n' + + ` node scripts/pm/label-write.mjs --issue ${number} --comment-file ${file ?? 'PATH'} --add pm:dispatched --remove pm:queue --assign LOGIN\n` + + ' The comment is judged there by this file\'s own `judgeBody`, so nothing about the body changes.\n' + + ` (${transport}; \`--comment-file\` is relay-only, and only on a route resolved \`direct\` does this tool post a claim.)` + ); +} + // --------------------------------------------------------------------------- // The record's keyed line — a `## Contract review` comment, refused before the write // --------------------------------------------------------------------------- @@ -3976,6 +4040,10 @@ const USAGE = [ ' A mailbox comment whose `To:` is a triage seat and whose key is `Request: contract-review` is REFUSED, whether', ' or not the key line spells its template: a lane without the review tier knocks an L2 seat, then a sibling', ' seat with the tier — never triage.', + ' A comment whose first line after the signature opens `Claim:` is REFUSED: a claim is ONE stroke with its', + ' labels and assignee — `label-write.mjs --issue N --comment-file PATH --add pm:dispatched --remove pm:queue', + ' --assign LOGIN` folds the same comment. Only on a route resolved `direct`, where that fold does not exist, is', + ' the claim written here, with a note on stderr.', ' The attribution footer is the caller\'s: its form differs by channel and act, so this tool adds none.', '', ` Exit: 0 written and stored · ${EXIT_USAGE} usage · ${EXIT_REFUSED} refused, nothing written ·`, @@ -4036,6 +4104,17 @@ async function main(argv) { } console.error(route.error ? `post-stamped: transport undecidable on a live run — ${route.error}` : `post-stamped: transport ${route.transport} — ${route.reason}`); + // A claim is one stroke with its labels (`claimStrokeRefusal`): judged HERE, after the route, ⛔ never in `judgeBody`, + // which is the path the remedy — `label-write.mjs --comment-file` — folds the same comment through. + const loneClaim = claimStrokeRefusal(rendered.body, { mode: options.mode, route }); + if (loneClaim !== null) { + console.error(claimStrokeRefusalText(loneClaim, { number: options.number, file: options.file })); + return EXIT_REFUSED; + } + if (options.mode === 'comment' && openingClaimLine(rendered.body) !== null) { + console.error('post-stamped: a `Claim:` comment on a route resolved `direct` — `label-write.mjs --comment-file` is relay-only, so this write is the claim alone; move the labels and assignee with `label-write.mjs` right after it.'); + } + if (options.dryRun) { console.error( `post-stamped: DRY RUN — nothing was written. Substituted with \`${rendered.stamp}\` — ` + @@ -4219,8 +4298,9 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the one judge: every body refusal on ONE path — `main` and `label-write.mjs --comment-file` call `judgeBody`, never a copy': 8, 'the review route: a `Request: contract-review` knock addressed to triage is refused; to a review or sibling seat, and every other key to triage, it passes': 10, 'the record tier: a record naming `CONTRACT_REVIEW_TIER` is written only on a transcript `verify-review-tier.mjs` passes; another tier and a non-record comment are untouched': 16, + 'the claim stroke: a comment opening `Claim:` is refused on every route but `direct`, pointing at the `label-write` fold; the same body through that fold passes': 15, }); -const SELF_TEST_BATTERY_FLOOR = 29; +const SELF_TEST_BATTERY_FLOOR = 30; const UNATTRIBUTED_BATTERY = '(unattributed)'; let selfTestReachedVerdict = false; @@ -5758,6 +5838,48 @@ export function selfTest() { t('↔ structural: label-write imports judgeBody and judges its folded comment with it, ⛔ no reader of its own', /\bjudgeBody\b[^;]*from '\.\/post-stamped\.mjs'/u.test(lw) && /judgeBody\(text, \{ mode: 'comment', tierEvidence: options\.tierEvidence \}/u.test(lw) && !/function\s+(signatureRefusal|claimKeyedLineRefusals|decisionFacetRefusals)\b/u.test(lw)); } + // ── the claim stroke: a claim goes out with its labels, never alone ────────── + battery('the claim stroke: a comment opening `Claim:` is refused on every route but `direct`, pointing at the `label-write` fold; the same body through that fold passes'); + { + const SIG = 'domain:skills#2 · os-justin · session_01QSeKYmhU5KEj1nukYhp1Tg'; + const CLAIM = `${SIG}\nClaim: PM loop round 1 · {{NOW}}\nSession: \`session_x\`\nBranch: \`claude/issue-7-fold\`\nSeat: \`domain:skills#2\`\n`; + const RELAY = { transport: 'dispatch', error: null }; + const DIRECT = { transport: 'direct', error: null }; + const UNDECIDED = { transport: null, error: 'no session' }; + t('the opening claim is read under one signature line, and without one', openingClaimLine(CLAIM)?.startsWith('Claim: PM loop round 1') === true && openingClaimLine('Claim: x') === 'Claim: x'); + t('…a decorated `> Claim:` is a claim here exactly as the patrol reads it', openingClaimLine(`${SIG}\n> Claim: x`) === '> Claim: x'); + t('⛔ control: a `Claim:` QUOTED further down a round report is not a claim being made', openingClaimLine(`${SIG}\nRound report\n\nClaim: x. Seat: domain:skills#2 taken.`) === null && openingClaimLine(`${SIG}\nRelease: x`) === null); + t('⭐ a claim on the relay route is refused, naming its line and the route', claimStrokeRefusal(CLAIM, { mode: 'comment', route: RELAY })?.transport === 'dispatch' && claimStrokeRefusal(CLAIM, { mode: 'comment', route: RELAY }).line.startsWith('Claim:')); + t('…and on an UNDECIDABLE route too — it cannot prove the fold absent', claimStrokeRefusal(CLAIM, { mode: 'comment', route: UNDECIDED })?.transport === null && claimStrokeRefusal(CLAIM, { mode: 'comment', route: null }) !== null); + t('⛔ control: on a route resolved `direct` — where the relay-only fold does not exist — the claim stays this tool\'s write', claimStrokeRefusal(CLAIM, { mode: 'comment', route: DIRECT }) === null); + t('⛔ control: a card BODY opening `Claim:` and a comment that is no claim pass on the relay route', claimStrokeRefusal(CLAIM, { mode: 'body', route: RELAY }) === null && claimStrokeRefusal(`${SIG}\nRound report {{NOW}}`, { mode: 'comment', route: RELAY }) === null); + const text = claimStrokeRefusalText(claimStrokeRefusal(CLAIM, { mode: 'comment', route: RELAY }), { number: 36203, file: 'claim.md' }); + t('⭐ the refusal prints the ONE stroke that folds it — the card, the file, the labels and the assignee — and says nothing was written', ['label-write.mjs --issue 36203 --comment-file claim.md --add pm:dispatched --remove pm:queue --assign LOGIN', 'Nothing was written', 'ONE stroke with its labels'].every((x) => text.includes(x))); + t('…and placeholders where the caller gave none', claimStrokeRefusalText({ line: 'Claim: x', transport: null }).includes('--issue N --comment-file PATH')); + const folded = judgeBody(CLAIM, { mode: 'comment' }, NOW_MS, 'label-write'); + t('⭐ control: the SAME claim through `judgeBody` — the path `label-write --comment-file` folds it through — passes, rendered', folded.ok && folded.rendered.body.includes('Claim: PM loop round 1 · 2026-09-10T06:37Z')); + const dir = mkdtempSync(join(tmpdir(), 'post-stamped-claim-')); + try { + const run = (transport, body) => { + writeFileSync(join(dir, 'b.md'), body, 'utf8'); + return spawnSync(process.execPath, [SELF_PATH, '--dry-run', '--comment=7', '--repo=o/r', `--file=${join(dir, 'b.md')}`], { encoding: 'utf8', env: { ...process.env, HTTPS_PROXY: '', https_proxy: '', GITHUB_TOKEN: '', GH_TOKEN: '', OS_FLEET_TRANSPORT: transport, OS_FLEET_SESSION: '', CLAUDE_CODE_REMOTE_SESSION_ID: '' } }); + }; + const refused = run('dispatch', CLAIM); + t('⭐ the CLI refuses the claim on a dry run off the direct route: exit 2, the stroke on stderr, nothing on stdout', refused.status === EXIT_REFUSED && refused.stderr.includes('--comment-file') && refused.stderr.includes('--issue 7') && refused.stdout === ''); + const direct = run('direct', CLAIM); + t('⛔ control: the same claim on the direct route renders (exit 0) and says the labels follow as a second write', direct.status === EXIT_OK && direct.stdout.includes('Claim: PM loop round 1') && direct.stderr.includes('relay-only')); + const other = run('dispatch', `${SIG}\nRound report {{NOW}}\n`); + t('⛔ control: a signed comment that is no claim, on the same undecidable route, renders (exit 0) — the refusal keys on the claim', other.status === EXIT_OK && !other.stderr.includes('--comment-file')); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + const own = readFileSync(SELF_PATH, 'utf8'); + const mainOnly = own.slice(own.indexOf('async function main(argv)'), own.indexOf('// --self-test — offline')); + const judgeOnly = own.slice(own.indexOf('export function judgeBody('), own.indexOf('const USAGE = [')); + t('structural: main judges the claim after the route is resolved and before the dry-run exit; `judgeBody` never does', mainOnly.indexOf('claimStrokeRefusal(rendered.body') > mainOnly.indexOf('await resolveRoute(') && mainOnly.indexOf('claimStrokeRefusal(rendered.body') < mainOnly.indexOf('if (options.dryRun)') && !judgeOnly.includes('claimStrokeRefusal')); + t('the usage says it, with the stroke', USAGE.includes('opens `Claim:` is REFUSED') && USAGE.includes('--comment-file PATH --add pm:dispatched --remove pm:queue')); + } + battery('the review route: a `Request: contract-review` knock addressed to triage is refused; to a review or sibling seat, and every other key to triage, it passes'); { const SIG = 'domain:server#3 · os-bill · session_01QSeKYmhU5KEj1nukYhp1Tg';