diff --git a/.changes/pr-pipeline/fix-pr-verify-cap-head-fail-d4570a1c.md b/.changes/pr-pipeline/fix-pr-verify-cap-head-fail-d4570a1c.md new file mode 100644 index 00000000000..2bc28641b0b --- /dev/null +++ b/.changes/pr-pipeline/fix-pr-verify-cap-head-fail-d4570a1c.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Fixed + +- pr-verify's repeated-fail cap (`merge.max-verify-fails`, `verify:repeated-fail`) closes a pull request only when its current head itself has a FAIL that is not superseded (owner decision Q245, [#17646](https://github.com/melodic-software/claude-code-plugins/issues/17646)). FAILs at superseded heads no longer close it: a pass at the head goes on to the normal pass decision. pr-merge's `capped_close` and pr-unblock's `verify-cap.mjs` read the same reader, so both follow it; the README's Verifier verdict section, the schema and `pr-pipeline.yaml` say so. pr-unblock's address-feedback and fix-ci dispatchers no longer record a capped head as handled, so a head whose FAIL a later pass supersedes is dispatched again; the dispatch record's version is 7, so heads an earlier version recorded at the cap are read again. diff --git a/.changes/source-control/fix-pr-verify-cap-head-fail-d4570a1c.md b/.changes/source-control/fix-pr-verify-cap-head-fail-d4570a1c.md new file mode 100644 index 00000000000..341512ba7ea --- /dev/null +++ b/.changes/source-control/fix-pr-verify-cap-head-fail-d4570a1c.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Fixed + +- `babysit_verify_evidence.py` refuses `verify:repeated-fail` only when a counted FAIL that is not superseded stands at the vetted head and FAILs sit at `merge.max-verify-fails` or more heads, that one included (owner decision Q245, [#17646](https://github.com/melodic-software/claude-code-plugins/issues/17646)). A head whose newest verdicts pass, or whose own FAIL is superseded, goes on to the `verify:earlier-fail` or pass decision, whatever FAILs sit at earlier heads or on other pull requests for its issues. Before, FAILs at superseded heads kept counting, so the pr-merge lane closed a pull request whose current head had passed. Counting across other pull requests, the capped-close floor, draft-judged exclusions and `verify:fail` at the head are unchanged. diff --git a/.github/scripts/pr-merge/enable-auto-merge.mjs b/.github/scripts/pr-merge/enable-auto-merge.mjs index 5242d9bc980..c638f5fa979 100755 --- a/.github/scripts/pr-merge/enable-auto-merge.mjs +++ b/.github/scripts/pr-merge/enable-auto-merge.mjs @@ -47,8 +47,8 @@ // untrusted work in any spelling and none ever removed by a non-human, so // one added after admission refuses for a person // (`untrusted-provenance`). Then a pr-verify PASS or PASS-NOTES stands at that head, no FAIL is -// at it, no earlier FAIL is uncleared, FAILs sit at fewer than -// merge.max-verify-fails heads, and the spec is unchanged and trusted. A +// at it, no earlier FAIL is uncleared, and the spec is unchanged and +// trusted. A // read that fails, or a line without the link's answer, refuses. Only the // scheduled run and // a hand-started one read them (READER_EVENTS), last, for a pull request diff --git a/.github/scripts/pr-unblock/dispatch-record.mjs b/.github/scripts/pr-unblock/dispatch-record.mjs index 7d6282e9aa6..abbc1e52fc0 100644 --- a/.github/scripts/pr-unblock/dispatch-record.mjs +++ b/.github/scripts/pr-unblock/dispatch-record.mjs @@ -48,10 +48,12 @@ export async function sendDispatch(api, log, { workflow, base, node, inputs, lab // version 5 a resolve-conflicts head a select job's stop left under an older // base, and version 6 a resolve-conflicts, sync-shared-copies or // review-dependency head a head-lag stop left (limit-stop.mjs -// lagStopsRelease). A fix-ci +// lagStopsRelease), and version 7 an address-feedback or fix-ci head +// pr-verify's FAIL cap held, which a superseded FAIL now clears +// (https://github.com/melodic-software/claude-code-plugins/issues/17646). A fix-ci // head recorded at its per-head cap needs no new version: a record with no // fix-ci entry reads the same either way; nor do fix-docs runs, read as none. -export const RECORD_VERSION = 6; +export const RECORD_VERSION = 7; // The fix-docs runs kept per head, newest last: the reader drops the settled // runs that do not count, so more than this many is a tampered entry. const MAX_DOCS_RUNS = 20; diff --git a/.github/scripts/pr-unblock/dispatch.test.mjs b/.github/scripts/pr-unblock/dispatch.test.mjs index 688b9967f6c..10e76645f38 100644 --- a/.github/scripts/pr-unblock/dispatch.test.mjs +++ b/.github/scripts/pr-unblock/dispatch.test.mjs @@ -1480,13 +1480,13 @@ test("main carries the record in DISPATCH_RECORD and writes it only when it chan DISPATCH_RECORD: path, }; // A recorded head no open PR carries any more is dropped. - writeFileSync(path, JSON.stringify({ version: 6, handled: { [CHECK_NAME]: ["f".repeat(40)] }, bases: { ["f".repeat(40)]: "b".repeat(40) }, dispatched: {} })); + writeFileSync(path, JSON.stringify({ version: 7, handled: { [CHECK_NAME]: ["f".repeat(40)] }, bases: { ["f".repeat(40)]: "b".repeat(40) }, dispatched: {} })); const options = () => ({ api: fakeApi({ pages: [[pr(1)]], checked: new Set([pr(1).headRefOid]) }), sleep: async () => {}, log: () => {}, loadLimits: async () => LIMIT_DEFAULTS, loadAdoption: async () => ({}), loadOwnedBranches: async () => [] }); try { writeFileSync(output, ""); assert.equal(await main(env, options()), 0); assert.equal(readFileSync(output, "utf8"), "listed=true\nrecord-changed=true\n"); - assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { version: 6, handled: { [CHECK_NAME]: [pr(1).headRefOid] }, bases: {}, dispatched: {}, docsRuns: {} }); + assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { version: 7, handled: { [CHECK_NAME]: [pr(1).headRefOid] }, bases: {}, dispatched: {}, docsRuns: {} }); writeFileSync(output, ""); assert.equal(await main(env, options()), 0); assert.equal(readFileSync(output, "utf8"), "listed=true\n"); diff --git a/.github/scripts/pr-unblock/feedback-dispatch.mjs b/.github/scripts/pr-unblock/feedback-dispatch.mjs index 72f84cfd41c..e5ea13a6d8c 100644 --- a/.github/scripts/pr-unblock/feedback-dispatch.mjs +++ b/.github/scripts/pr-unblock/feedback-dispatch.mjs @@ -747,8 +747,10 @@ export async function dispatchFeedback({ } } // Last, as it costs a full verifier read, and on a pass-only dispatch too: a - // later pass clears no cap, and a push past it could never merge, so - // pr-merge closes the pull request for a fresh attempt. It closes only the + // pass clears the cap only by superseding the head's FAIL + // (https://github.com/melodic-software/claude-code-plugins/issues/17646), + // and a push past it could never merge, so pr-merge closes the pull request + // for a fresh attempt. It closes only the // lanes App's: an adopted owner's is never skipped. A pass-only round skips // only on a cap the reader found: it only resolves notes a pass superseded, // and nothing sends it again, so a cap that could not be read (#11354) @@ -777,11 +779,6 @@ export async function dispatchFeedback({ return skip(`#${number} has no unresolved review thread, and the verifier read for an earlier FAIL ${readFailed ? "failed" : `could not count every FAIL (${capped})`}; a later pass inside the retry window reads it again`); } if (capped) { - // The cap never clears for the head: later runs skip it before any - // read. A sibling read that failed is read again next run. - if (capFinal(capped)) { - markHandled(record, settings.checkName, head); - } const warning = deadlineWarning(number, capped); if (warning) { log(warning); diff --git a/.github/scripts/pr-unblock/feedback-dispatch.test.mjs b/.github/scripts/pr-unblock/feedback-dispatch.test.mjs index 8be3e738ac3..afa213379c9 100644 --- a/.github/scripts/pr-unblock/feedback-dispatch.test.mjs +++ b/.github/scripts/pr-unblock/feedback-dispatch.test.mjs @@ -1,3 +1,4 @@ +// test-scope: .github/actions/resolve-config/package.json import assert from "node:assert/strict"; import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { join } from "node:path"; @@ -218,10 +219,6 @@ const pull = (overrides) => [ }, ]; -// Owner decision 2026-10-29: pr-verify's FAILs at the cap never clear for the -// pull request, so a fix round's push could never merge: the gate's reader -// (verify-cap.mjs) says so, the dispatcher starts no round and posts nothing, -// and pr-merge closes it for a fresh attempt. test("a PR whose pr-verify FAILs are at the cap gets no address-feedback round", async () => { const api = fakeApi(); const asked = []; @@ -234,13 +231,20 @@ test("a PR whose pr-verify FAILs are at the cap gets no address-feedback round", assert.deepEqual(api.calls.dispatch, []); assert.deepEqual(asked, [{ number: 42, head: HEAD, base: "b".repeat(40), expected: [] }]); assert.match(lines.join("\n"), /^skip: #42: .*verify:repeated-fail/m); - // The cap never clears for the head: a later run at it reads nothing. +}); + +test("a capped head whose FAIL a later pass superseded is read again and dispatched", async () => { const record = emptyRecord(); - await decide(api, resolvedLane(), { verifyCapped, record }); - const again = await decide(fakeApi(), resolvedLane(), { verifyCapped, record }); - assert.equal(again.result, null); - assert.equal(asked.length, 2); - assert.match(again.lines.join("\n"), /\(recorded\)/); + const answers = [{ cap: "verify:repeated-fail: fails at 3 heads, the cap is 3", supersededAtHead: false }, { cap: null, supersededAtHead: true }]; + const verifyCapped = () => answers.shift(); + const capped = await decide(fakeApi(), resolvedLane(), { verifyCapped, record }); + assert.equal(capped.result, null, "capped: no round"); + assert.equal(record.handled.size, 0, "the cap is not recorded as handling the head"); + const api = fakeApi(); + const cleared = await decide(api, resolvedLane(), { verifyCapped, record }); + assert.deepEqual(cleared.result, { number: 42, workflowRunId: "38779200001" }); + assert.deepEqual(api.calls.dispatch.map((call) => call.inputs["pr-number"]), ["42"]); + assert.equal(answers.length, 0, "a superseded head FAIL is a clean head (#17646): the second run reads the verifier again"); }); // A sibling pull request's FAIL run the reader cannot read may hide the cap: @@ -276,8 +280,6 @@ test("a PR skipped because the listing did not fit warns with the reader's detai assert.ok(!sibling.lines.some((line) => line.includes("verify-deadline-skip")), sibling.lines.join("\n")); }); -// A verifier PASS at a new head clears no cap, so the pass-only dispatch -// starts no round either. test("a pass-only dispatch of a PR whose pr-verify FAILs are at the cap gets no round", async () => { const api = fakeApi(); const { result, lines } = await decide(api, resolvedLane(), { passOnly: true, verifyCapped: () => "verify:repeated-fail: fails at 3 heads, the cap is 3" }); @@ -319,7 +321,6 @@ test("a pass-only dispatch names the head superseded only when the gate's reader assert.deepEqual(await inputs({ passOnly: true, verifyCapped: () => ({ cap: null, supersededAtHead: false }) }), [undefined]); assert.deepEqual(await inputs({ passOnly: true, verifyCapped: () => null }), [undefined]); assert.deepEqual(await inputs({ verifyCapped: () => ({ cap: null, supersededAtHead: true }) }), [undefined]); - // A cap the reader found still skips the round, superseded or not. assert.deepEqual(await inputs({ passOnly: true, verifyCapped: () => ({ cap: "verify:repeated-fail: fails at 3 heads, the cap is 3", supersededAtHead: true }) }), []); }); diff --git a/.github/scripts/pr-unblock/fix-ci-dispatch.mjs b/.github/scripts/pr-unblock/fix-ci-dispatch.mjs index 3e36ca91e6b..954f98cad18 100644 --- a/.github/scripts/pr-unblock/fix-ci-dispatch.mjs +++ b/.github/scripts/pr-unblock/fix-ci-dispatch.mjs @@ -63,7 +63,7 @@ import { failingChecks } from "./fix-ci-context.mjs"; import { prHold, reviewReader } from "./gate-source.mjs"; import { HEAD_LAG_STOP, KILL_SWITCH_STOP, killSwitchStop, laneStop, releasesHead } from "./limit-stop.mjs"; import { serverFailure } from "./request-budget.mjs"; -import { final as capFinal, deadlineWarning } from "./verify-cap.mjs"; +import { deadlineWarning } from "./verify-cap.mjs"; export const DEFAULTS = Object.freeze({ base: "main", @@ -683,11 +683,6 @@ export async function dispatchCiFixes({ log(warning); } log(`skip fix-ci #${node.number}: pr-verify's FAILs are at the cap or cannot all be read (${verifyCap}); pr-merge closes it for a fresh attempt, so no fix-ci round`); - // The cap never clears for the head: later runs skip it before any - // read. A sibling read that failed is read again next run. - if (capFinal(verifyCap)) { - markHandled(record, checkName, node.headRefOid); - } continue; } if (fixCiRuns.some((run) => run.conclusion === "NEUTRAL" && run.title === HEAD_LAG_STOP)) { diff --git a/.github/scripts/pr-unblock/fix-ci-dispatch.test.mjs b/.github/scripts/pr-unblock/fix-ci-dispatch.test.mjs index 7ff06a26fe6..4268b96d226 100644 --- a/.github/scripts/pr-unblock/fix-ci-dispatch.test.mjs +++ b/.github/scripts/pr-unblock/fix-ci-dispatch.test.mjs @@ -241,17 +241,16 @@ test("a PR whose pr-verify FAILs are at the cap gets no fix-ci round", async () assert.match(lines.join("\n"), /^skip fix-ci #5: .*verify:repeated-fail/m); }); -test("a capped head is recorded, so the next run skips it without reading the verifier again", async () => { +test("a capped head whose FAIL a later pass superseded is read again and dispatched", async () => { const record = emptyRecord(); - let reads = 0; - const verifyCapped = () => { - reads += 1; - return "verify:repeated-fail"; - }; - await run({ pages: [[pr(5)]] }, { verifyCapped, record }); - const { api } = await run({ pages: [[pr(5)]] }, { verifyCapped, record }); - assert.equal(reads, 1); - assert.deepEqual(api.calls.dispatch, []); + const answers = ["verify:repeated-fail: fails at 3 heads, the cap is 3", null]; + const verifyCapped = () => answers.shift(); + const capped = await run({ pages: [[pr(5)]] }, { verifyCapped, record }); + assert.deepEqual(capped.api.calls.dispatch, [], "capped: no round"); + assert.equal(record.handled.size, 0, "the cap is not recorded as handling the head"); + const cleared = await run({ pages: [[pr(5)]] }, { verifyCapped, record }); + assert.deepEqual(cleared.api.calls.dispatch.map((call) => call.inputs["pr-number"]), ["5"]); + assert.equal(answers.length, 0, "a superseded head FAIL is a clean head (#17646): the second run reads the verifier again"); }); test("a head whose sibling FAIL run cannot be read is skipped but not recorded", async () => { diff --git a/.github/scripts/pr-unblock/verify-cap.mjs b/.github/scripts/pr-unblock/verify-cap.mjs index 4c47ed04ac3..e99ac44252c 100644 --- a/.github/scripts/pr-unblock/verify-cap.mjs +++ b/.github/scripts/pr-unblock/verify-cap.mjs @@ -1,10 +1,15 @@ // verify-cap.mjs: whether pr-verify's FAILs on a pull request are at the // merge gate's cap (`verify:repeated-fail`), read by the gate's own reader, // babysit_verify_evidence.py `evidence`, so the cap is counted in one place. -// The cap never clears for the pull request: a fix round's push could never -// merge, so feedback-dispatch.mjs and fix-ci-dispatch.mjs start no -// address-feedback or fix-ci round on it and post nothing; the pr-merge lane -// closes it for a fresh attempt at its issue (owner decision 2026-10-29). A +// The cap applies only when a FAIL that is not superseded stands at the head +// (owner decision Q245, +// https://github.com/melodic-software/claude-code-plugins/issues/17646); FAILs +// at earlier heads alone never reach it, and a later supersession of the +// head's FAIL clears it. While it applies, the pr-merge lane closes the pull +// request for a fresh attempt at its issue (owner decision 2026-10-29), so +// feedback-dispatch.mjs and fix-ci-dispatch.mjs start no address-feedback or +// fix-ci round on it and post nothing, and record nothing, so a head whose +// cap cleared is read again. A // FAIL run of another pull request for the same issue that cannot be read // (`verify:unreadable` with the reader's SIBLING_UNREADABLE detail), or an // artifact listing that does not fit in this caller's limit (a detail that @@ -155,9 +160,6 @@ async function fetchCarry(env) { } } -// Whether a verifyCapReader answer never clears for the head, so a -// dispatcher records the head as handled: the cap does, a sibling read that -// failed may clear next run. export const final = (answer) => typeof answer === "string" && answer.startsWith(CAPPED); // The workflow annotation for a skip because the listing did not fit in the @@ -193,7 +195,6 @@ function stderrSummary(stderr) { // A function of { number, head, base, expected } that returns the reader's cap refusal, // `verify:repeated-fail` with its detail (the FAILed heads), the sibling // read's or the caller limit's `verify:unreadable` with its detail, or null. -// Only the first never clears for the head (`final`). // `base`: the pull request's base commit, so the reader takes the gate's // merge.max-verify-fails (the lower of that commit's and main's). // `expected`: refusals the round is sent for, which warn nothing. diff --git a/docs/conventions/pr-pipeline.yaml b/docs/conventions/pr-pipeline.yaml index 9022a66fa49..8bae55247c0 100644 --- a/docs/conventions/pr-pipeline.yaml +++ b/docs/conventions/pr-pipeline.yaml @@ -1635,8 +1635,10 @@ merge: max-minutes: 60 max-skips: 3 # pr-verify FAILs at this many distinct heads of one PR hold it, never to - # merge unattended, whatever a later pass says, so pushing until the - # verifier passes once does not merge it (owner decision 2026-10-21). The + # merge unattended (owner decision 2026-10-21), when one that is not + # superseded stands at its head; FAILs at earlier heads alone leave a pass + # at the head to decide (owner decision Q245, + # https://github.com/melodic-software/claude-code-plugins/issues/17646). The # pr-merge lane closes a lanes App one for a fresh attempt at its issue, # and address-feedback and fix-ci start no more rounds on it (owner # decision 2026-10-29). diff --git a/docs/conventions/pr-pipeline/README.md b/docs/conventions/pr-pipeline/README.md index 4bdc23550b3..45d0d907aaa 100644 --- a/docs/conventions/pr-pipeline/README.md +++ b/docs/conventions/pr-pipeline/README.md @@ -2113,8 +2113,7 @@ work in any spelling, and none ever removed by a non-human or through an App, so after admission refuses as `untrusted-provenance`, `untrusted-provenance-removed-by-non-human` or `issue-labels-unreadable`, each a refusal a person clears, the removal one only through a new issue: see the trust hold below), a PASS or PASS-NOTES of [pr-verify](#verifier-verdict) stands at the head, -no FAIL is at it, no earlier FAIL is uncleared, FAILs sit at fewer than `merge.max-verify-fails` -heads, and the spec is unchanged and trusted; and `evidence --lane-reviews` finds no hold on the +no FAIL is at it, no earlier FAIL is uncleared, and the spec is unchanged and trusted; and `evidence --lane-reviews` finds no hold on the gate's risk score (`babysit_risk.score` over the inputs the gate builds, at the lane room's rung): an open CRITICAL security finding or a review not bound to the head, whether or not the lane applied its hold label, a symlink, submodule or other non-regular mode, a high path, the manifest @@ -2963,12 +2962,14 @@ other artifact with such a name is ignored. The resolver and the gate each hold dependency-manager list, and one test runs both to keep them equal. At the pull request's vetted head: -- counted `fail` verdicts at `merge.max-verify-fails` (default 3) or more distinct heads of the pull - request, tied as in the item after next, refuse (`verify:repeated-fail`) whatever a later pass - says, a `fail` at the head included. A value that is not a count of 1 or more, an empty or - non-scalar one included, is 1, so any earlier `fail` holds. Before a `fail` at the head or a - pass decides, counted `fail` verdicts of other pull requests in this repository, for its linked - issues, count too, at their own heads, unless that pull request merged or is a closed lanes App +- a counted `fail` at the head that is not superseded (the next item), with counted `fail` + verdicts at `merge.max-verify-fails` (default 3) or more distinct heads of the pull request, tied + as in the item after next, that head included, refuses (`verify:repeated-fail`). `fail` verdicts + at other heads alone never cap: a head whose newest verdicts pass, or whose `fail` is superseded, + goes on to the items below (owner decision Q245, 2026-11-20). A value that is not a count of 1 or + more, an empty or non-scalar one included, is 1, so any `fail` standing at the head caps. Before a + `fail` at the head decides, counted `fail` verdicts of other pull requests in this repository, + for its linked issues, count too, at their own heads, unless that pull request merged or is a closed lanes App attempt, so a second pull request for the same issue, closing or `Refs:`, does not reset the count. Every `fail` of such a pull request that closes one of the issues counts. Every counted `fail` of one whose name carries the issue counts too, from the listing the gate already reads: @@ -3009,8 +3010,9 @@ head: relink), else at least one body edit from the last `fail`'s run's creation (a body fix). The lanes App, any other Bot, an actor GitHub cannot name, a read that fails or is cut short, a time that cannot be read, or the same linked issues with no body edit keep the refusal. Both the - resolver and the gate read these acts in one GraphQL query, only on this path. A superseded `fail` still counts toward `merge.max-verify-fails`, and the - passes then decide as below. A judgment on an older listing (pr-merge's provisional one) can + resolver and the gate read these acts in one GraphQL query, only on this path. Supersession is judged before the cap: a superseded `fail` caps + nothing at its own head, and the passes then decide as below; it still counts toward + `merge.max-verify-fails` when a later head fails. A judgment on an older listing (pr-merge's provisional one) can still refuse `verify:fail` until a listing that holds the superseding pass is read; - a counted `fail` at another head of the pull request (its number, one of its commits, or a verdict recording its head branch, read from the name's digest, or for a name without one from @@ -3113,7 +3115,7 @@ round (`pr-dispatch-feedback.yml`, above), whose push the verifier judges again. ([when work stops for the owner](../../contracts/loop-lane/README.md#when-work-stops-for-the-owner)): it still refuses the merge, with no label. Only `verify:untrusted-spec` needs a human, since the spec's provenance is a trust boundary. `verify:too-old` waits for the fresh pass above, with no label. `verify:repeated-fail` never -clears for the pull request, so it never merges unattended, and no person's label goes on for it +clears at its failed head, so the pull request never merges unattended there, and no person's label goes on for it (owner decision 2026-10-29). Instead, while `merge.report-only` is false, the pr-merge lane closes a lanes App pull request at it for a fresh attempt at its issue (`babysit_verify_evidence.py` `capped_close`, run by `enable-auto-merge.mjs` through the reader's `capped-close` command, or by the gate under diff --git a/docs/conventions/pr-pipeline/pr-pipeline.schema.json b/docs/conventions/pr-pipeline/pr-pipeline.schema.json index db63b88e69c..092bf9ed925 100644 --- a/docs/conventions/pr-pipeline/pr-pipeline.schema.json +++ b/docs/conventions/pr-pipeline/pr-pipeline.schema.json @@ -1431,7 +1431,7 @@ "type": "integer", "minimum": 1, "default": 3, - "description": "Counted pr-verify fail verdicts at this many distinct heads of one pull request refuse it `verify:repeated-fail` whatever a later pass says: the pr-merge lane closes a lanes App pull request for a fresh attempt at its issue, and address-feedback and fix-ci start no more rounds on it (README.md, Verifier verdict). Any other value is 1, so any earlier fail holds." + "description": "Counted pr-verify fail verdicts at this many distinct heads of one pull request refuse it `verify:repeated-fail` when one that is not superseded stands at its head; fail verdicts at other heads alone never do (owner decision Q245): the pr-merge lane closes a lanes App pull request for a fresh attempt at its issue, and address-feedback and fix-ci start no more rounds on it (README.md, Verifier verdict). Any other value is 1, so any fail standing at the head caps." }, "verify-cap-attempts": { "type": "integer", diff --git a/plugins/source-control/skills/babysit-prs/scripts/babysit_merge_policy.py b/plugins/source-control/skills/babysit-prs/scripts/babysit_merge_policy.py index 0683be840d6..4119a2a178a 100755 --- a/plugins/source-control/skills/babysit-prs/scripts/babysit_merge_policy.py +++ b/plugins/source-control/skills/babysit-prs/scripts/babysit_merge_policy.py @@ -915,9 +915,11 @@ def floor(self) -> Floor: # `RISK_ESCALATION_MINUTES`. risk_escalation_minutes: int = RISK_ESCALATION_MINUTES # `merge.max-verify-fails`: counted pr-verify FAILs at distinct heads of - # one pull request at which it holds, never to merge unattended, whatever - # a later pass says (`babysit_verify_evidence`). Absent is `MAX_VERIFY_FAILS`; anything - # but a whole number of at least 1 is 1, so any earlier FAIL holds. + # one pull request at which it holds, never to merge unattended, when one + # that is not superseded stands at its head (`babysit_verify_evidence`, + # https://github.com/melodic-software/claude-code-plugins/issues/17646). + # Absent is `MAX_VERIFY_FAILS`; anything but a whole number of at least 1 + # is 1, so any FAIL standing at the head caps. max_verify_fails: int = MAX_VERIFY_FAILS # `merge.verify-cap-attempts`: fresh attempts one issue gets after the # pr-merge lane closes its pull request at the FAIL cap or as too old diff --git a/plugins/source-control/skills/babysit-prs/scripts/babysit_verify_evidence.py b/plugins/source-control/skills/babysit-prs/scripts/babysit_verify_evidence.py index dfec20c6af1..535b12f7f9c 100755 --- a/plugins/source-control/skills/babysit-prs/scripts/babysit_verify_evidence.py +++ b/plugins/source-control/skills/babysit-prs/scripts/babysit_verify_evidence.py @@ -21,11 +21,14 @@ `Reader.evidence` decides one pull request at its vetted head, in this order: -- counted FAILs at `max_fails` or more distinct heads of this pull request - (tied as in the item after next): `verify:repeated-fail`, whatever a pass - says, a FAIL at the head included. Before a FAIL at the head or a pass - decides, FAILs of other pull requests in this repository that are not - merged, nor a closed lanes App attempt (`_counts`), and close one of its +- a counted FAIL at the head, under any pull request number, that is not + superseded (the next item), with counted FAILs at `max_fails` or more + distinct heads of this pull request (tied as in the item after next), that + head included: `verify:repeated-fail`. FAILs at other heads alone never + cap: a head whose newest verdicts pass, or whose FAIL is superseded, goes + on to the items below (owner decision Q245, 2026-11-20). Before a FAIL at + the head decides, FAILs of other pull requests in this repository that are + not merged, nor a closed lanes App attempt (`_counts`), and close one of its issues (its closing issues, or its `Refs:` issue) count too, at their own heads, and so does every FAIL of such a pull request whose name carries one of those issues, a `Refs:` pull request's FAILs among them (a FAIL among @@ -43,10 +46,11 @@ at least one from the first FAIL's creation for a pass that records other linked issues than each FAIL does (a relink), else at least one body edit from the last FAIL's creation (a body fix judged at the same head). - A superseded FAIL still counts toward `max_fails`, and the passes then - decide as below; the report's `supersededAtHead` names it, for pr-unblock - to resolve that FAIL's fail-note threads. Any record, time or read that - fails keeps `verify:fail`; + Supersession is judged before the cap. A superseded FAIL caps nothing at + its own head, and the passes then decide as below; it still counts toward + `max_fails` when a later head FAILs. The report's `supersededAtHead` names + it, for pr-unblock to resolve that FAIL's fail-note threads. Any record, + time or read that fails keeps `verify:fail`; - a counted FAIL at another head of this pull request: its number, one of its commits (`pulls//commits`), or a verdict recording its head branch (read from the name's digest, else from its verdict.json) for a pull request that @@ -140,9 +144,11 @@ and enable-auto-merge.mjs shows one that stands as a failing `pr-merge/unarmed` status. `verify:spec-changed` and `verify:too-old` wait for the lanes to judge the head again. -`verify:repeated-fail` never clears (`VERIFY_FINAL`), so the gate never merges -such a pull request unattended: the pr-merge lane closes a lanes App one for a -fresh attempt (`capped_close`), and address-feedback and fix-ci start no +`verify:repeated-fail` clears at its FAILed head only when that FAIL is +later superseded there; otherwise it stands (`VERIFY_FINAL`), so +the gate never merges such a pull request unattended: the pr-merge lane +closes a lanes App one for a fresh attempt (`capped_close`), and +address-feedback and fix-ci start no round on a pull request at `verify:repeated-fail` (pr-unblock verify-cap.mjs). A `verify:fail` or `verify:earlier-fail` only waits: @@ -1826,7 +1832,6 @@ class Reader: head_refs_path: str | None = field( default_factory=lambda: os.environ.get(HEAD_REFS_ENV) or None ) - # `merge.max-verify-fails`: FAILed heads at which a pass no longer clears. max_fails: int = merge_policy.MAX_VERIFY_FAILS # `merge.agent-identity`, the lanes App's login: its trusted-list id is # the author a size split's sub-issue needs (`_split_child`); unset, no @@ -4361,10 +4366,14 @@ def capped(heads: set[str]) -> str: refusal: str | None detail = unreadable head_superseded = False - if len(failed) >= self.max_fails: + if ( + head in failed + and not (head_superseded := superseded(head)) + and len(failed) >= self.max_fails + ): refusal = REPEATED_FAIL detail = f"fails at {len(failed)} heads ({_heads(failed)}), the cap is {self.max_fails}" - elif head in failed and not (head_superseded := superseded(head)): + elif head in failed and not head_superseded: # A FAIL here gets a fix round, so the cap counts the other pull # requests for its issues first: a round past it cannot merge. heads = failed | elsewhere()[1] @@ -4393,19 +4402,15 @@ def capped(heads: set[str]) -> str: # Every pass of the run that started last must allow # (`_newest`), so listing order decides nothing; any unreadable # one refuses (`_Unreadable`). - live, others = elsewhere() - heads = failed | others - if len(heads) >= self.max_fails: - refusal, detail = REPEATED_FAIL, capped(heads) - else: - refusals = { - self._pass_refusal(run_id, name, number, head, live, pr, artifact) - for run_id, name, artifact in self._newest(passes) - } - refusal = next( - (r for r in (SPEC_CHANGED, UNTRUSTED_SPEC) if r in refusals), - None, - ) + live = elsewhere()[0] + refusals = { + self._pass_refusal(run_id, name, number, head, live, pr, artifact) + for run_id, name, artifact in self._newest(passes) + } + refusal = next( + (r for r in (SPEC_CHANGED, UNTRUSTED_SPEC) if r in refusals), + None, + ) elif unread_pass: refusal, detail = UNREADABLE, unread_pass elif too_old: @@ -4854,7 +4859,8 @@ def _superseded( A relink at a merge-only head needs its body edit from the last FAIL's creation, as a body fix does: a FAIL created after an edit already judged that edit. - A superseded FAIL still counts toward `max_fails`. A record, time or + A superseded FAIL still counts toward a later FAILed head's + `max_fails`. A record, time or read that fails is False.""" judged_at = judged_at or sha fails = fail_artifacts.get(sha, []) diff --git a/plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_verify_evidence.py b/plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_verify_evidence.py index 47f820a1991..dae4563efc4 100644 --- a/plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_verify_evidence.py +++ b/plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_verify_evidence.py @@ -1261,7 +1261,9 @@ class ARelinkByPeopleSupersedesAFailAtItsHead(unittest.TestCase): changed there and it passed again, when every body edit and issue connect or disconnect from the FAIL's creation to the pass's start was a trusted person's; any other actor, a read that fails or the same linked issues - keep it. It still counts toward the FAIL cap, and a merge-only head + keep it. At its own head it counts as a clean head, so the FAIL cap + does not refuse there (#17646); it still counts toward the cap when a + later head FAILs, and a merge-only head carries it forward unless it was superseded at its own head or by the merge-only head's own pass under the same rule, which there also needs a trusted body edit.""" @@ -1373,16 +1375,52 @@ def test_another_prs_fail_at_the_head_keeps_it(self) -> None: fake.records[name] = record(99, verdict="fail", linked_issues=[]) self.assertEqual(read(fake).refusal, "verify:fail") - def test_a_superseded_fail_still_counts_toward_the_cap(self) -> None: - fake = self.relinked() - with ( - mock.patch.object(postmerge, "gh_capture", side_effect=fake), - mock.patch.object(ve.merge_policy, "gh_capture", side_effect=fake), - mock.patch.object(ve, "gh_api_with_headers", side_effect=_page_with_date), - ): - reader = ve.Reader(REPO, "main", now=NOW, max_fails=1) - refusal = reader.evidence(PR, HEAD, pull()).refusal - self.assertEqual(refusal, "verify:repeated-fail") + def test_a_superseded_fail_at_the_head_at_the_cap_lets_the_pass_decide( + self, + ) -> None: + """#17646: supersession is judged before the cap, so a superseded + FAIL at the head counts as a clean head; the same FAIL not superseded + stays capped.""" + + def evidence_at_cap_one(fake: FakeGitHub) -> ve.Evidence: + with ( + mock.patch.object(postmerge, "gh_capture", side_effect=fake), + mock.patch.object(ve.merge_policy, "gh_capture", side_effect=fake), + mock.patch.object( + ve, "gh_api_with_headers", side_effect=_page_with_date + ), + ): + reader = ve.Reader(REPO, "main", now=NOW, max_fails=1) + return reader.evidence(PR, HEAD, pull()) + + evidence = evidence_at_cap_one(self.relinked()) + self.assertIsNone(evidence.refusal) + self.assertIs(evidence.report()["supersededAtHead"], True) + unanswered = self.relinked() + unanswered.relink = relink_answer() + evidence = evidence_at_cap_one(unanswered) + self.assertEqual(evidence.refusal, "verify:repeated-fail") + self.assertIs(evidence.report()["supersededAtHead"], False) + + def test_fails_at_three_earlier_heads_cap_only_a_head_fail_not_superseded( + self, + ) -> None: + """#17646's reader test: the same history where the head's FAIL is + superseded does not yield `verify:repeated-fail`.""" + + def history() -> FakeGitHub: + fake = self.relinked() + for i, sha in enumerate((EARLIER, IN_PR, UNRELATED), start=3): + fake.artifacts.append(artifact(named(sha, "fail"), i)) + fake.runs[i] = judged(i, OLDER_START) + return fake + + evidence = read(history()) + self.assertIsNone(evidence.refusal, "a superseded head FAIL is a clean head") + self.assertIs(evidence.report()["supersededAtHead"], True) + unanswered = history() + unanswered.relink = relink_answer() + self.assertEqual(read(unanswered).refusal, "verify:repeated-fail") def merge_only(self, *, superseded: bool) -> FakeGitHub: """The relinked FAIL and pass at EARLIER, and a head that only merged @@ -1543,21 +1581,34 @@ def test_the_report_names_a_fail_superseded_at_the_head(self) -> None: self.assertEqual(evidence.refusal, "verify:fail") self.assertIs(evidence.report()["supersededAtHead"], False) - def test_the_report_names_no_fail_superseded_elsewhere_or_capped(self) -> None: + def test_the_report_names_no_fail_superseded_elsewhere(self) -> None: # Superseded at an earlier head only: nothing at this head gave way. merge_only = ARelinkByPeopleSupersedesAFailAtItsHead().merge_only( superseded=True ) self.assertIs(read(merge_only).report()["supersededAtHead"], False) - # At the cap the FAIL at the head is never judged superseded. - fake = self.edited() - with ( - mock.patch.object(postmerge, "gh_capture", side_effect=fake), - mock.patch.object(ve.merge_policy, "gh_capture", side_effect=fake), - mock.patch.object(ve, "gh_api_with_headers", side_effect=_page_with_date), - ): - reader = ve.Reader(REPO, "main", now=NOW, max_fails=1) - evidence = reader.evidence(PR, HEAD, pull()) + + def test_a_superseded_fail_at_the_head_is_judged_before_the_cap(self) -> None: + """#17646: a body-fixed FAIL at the head counts as a clean head, so + the cap does not refuse it; an App edit keeps the FAIL capped.""" + + def evidence_at_cap_one(fake: FakeGitHub) -> ve.Evidence: + with ( + mock.patch.object(postmerge, "gh_capture", side_effect=fake), + mock.patch.object(ve.merge_policy, "gh_capture", side_effect=fake), + mock.patch.object( + ve, "gh_api_with_headers", side_effect=_page_with_date + ), + ): + reader = ve.Reader(REPO, "main", now=NOW, max_fails=1) + return reader.evidence(PR, HEAD, pull()) + + evidence = evidence_at_cap_one(self.edited()) + self.assertIsNone(evidence.refusal) + self.assertIs(evidence.report()["supersededAtHead"], True) + evidence = evidence_at_cap_one( + self.edited(relink_answer([(RELINK_AT, LANES_ACTOR)])) + ) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertIs(evidence.report()["supersededAtHead"], False) @@ -1891,6 +1942,14 @@ def also_closes_issue_8(fake: FakeGitHub, *closers: int) -> FakeGitHub: return fake +def failing_at_head(fake: FakeGitHub) -> FakeGitHub: + """`fake` with a FAIL of this pull request at the head (run 9): the cap + closes only on a head whose own FAIL stands (owner decision Q245).""" + fake.artifacts.append(artifact(named(HEAD, "fail"), 9)) + fake.runs[9] = judged(9, OLDER_START) + return fake + + class FailsOnAnotherPullRequestForTheSameIssueCount(unittest.TestCase): """A second open pull request for the same issue does not reset the cap: counted FAILs of any open pull request in this repository that closes one @@ -1915,21 +1974,22 @@ def sibling_fails(*shas: str, number: int = SIBLING) -> FakeGitHub: return fake def test_three_fails_on_an_open_pull_request_refuse(self) -> None: - evidence = read(self.sibling_fails(*SIBLING_HEADS)) + evidence = read(failing_at_head(self.sibling_fails(*SIBLING_HEADS))) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertFalse(evidence.needs_human) - def test_two_there_and_one_here_refuse(self) -> None: - fake = self.sibling_fails(*SIBLING_HEADS[:2]) - fake.artifacts.append(artifact(named(EARLIER, "fail"), 9)) - fake.runs[9] = judged(9, OLDER_START) + def test_three_fails_there_leave_a_pass_at_the_head_to_decide(self) -> None: + self.assertIsNone(read(self.sibling_fails(*SIBLING_HEADS)).refusal) + + def test_two_there_one_here_and_a_fail_at_the_head_refuse(self) -> None: + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS[:2])) + fake.artifacts.append(artifact(named(EARLIER, "fail"), 8)) + fake.runs[8] = judged(8, OLDER_START) self.assertEqual(read(fake).refusal, "verify:repeated-fail") def test_two_there_and_a_fail_at_the_head_reach_the_cap(self) -> None: # Not verify:fail: a fix round whose push could never merge. - fake = self.sibling_fails(*SIBLING_HEADS[:2]) - fake.artifacts.append(artifact(named(HEAD, "fail"), 9)) - fake.runs[9] = judged(9, OLDER_START) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS[:2])) evidence = read(fake) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertFalse(evidence.needs_human) @@ -1965,7 +2025,7 @@ def test_a_closed_pull_request_of_anyone_else_still_counts(self) -> None: None, ): with self.subTest(author): - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.closer_states[SIBLING] = "CLOSED" if author is not None: fake.closer_authors[SIBLING] = author @@ -1989,7 +2049,7 @@ def test_a_capped_close_record_starts_the_count_again(self) -> None: self.assertIsNone(read_as_lane(fake).refusal) def test_fails_after_the_newest_record_still_count(self) -> None: - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.closing_comments[7] = [ capped_record( SIBLING + 2, LANES_APP_ACTOR, createdAt="2026-09-01T00:00:00Z" @@ -2008,7 +2068,7 @@ def test_only_the_caps_own_close_resets_the_count(self) -> None: None, ): with self.subTest(author): - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.closers[7] = [(SIBLING, REPO), (SIBLING + 2, REPO), (PR, REPO)] if author is not None: fake.closer_authors[SIBLING + 2] = author @@ -2016,14 +2076,20 @@ def test_only_the_caps_own_close_resets_the_count(self) -> None: def test_a_record_resets_only_its_own_issue(self) -> None: # A close on one issue ends no attempt at another, whose FAILs stay. - fake = also_closes_issue_8(self.sibling_fails(*SIBLING_HEADS)) + fake = also_closes_issue_8(failing_at_head(self.sibling_fails(*SIBLING_HEADS))) self.assertEqual(read_as_lane(fake).refusal, "verify:repeated-fail") # Records on both of them end the attempts at both. fake.closing_comments[7] = [capped_record(SIBLING + 2, LANES_APP_ACTOR)] - self.assertIsNone(read_as_lane(fake).refusal) + self.assertEqual( + read_as_lane(fake).refusal, + "verify:fail", + "the FAIL at the head alone is under the cap and waits for a fix round", + ) def test_a_pull_request_for_two_issues_counts_for_the_one_not_reset(self) -> None: - fake = also_closes_issue_8(self.sibling_fails(*SIBLING_HEADS), SIBLING) + fake = also_closes_issue_8( + failing_at_head(self.sibling_fails(*SIBLING_HEADS)), SIBLING + ) self.assertEqual(read_as_lane(fake).refusal, "verify:repeated-fail") def test_a_capped_close_record_anyone_else_wrote_or_edited_resets_nothing( @@ -2058,12 +2124,12 @@ def test_a_capped_close_record_anyone_else_wrote_or_edited_resets_nothing( ), ): with self.subTest(name): - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.closing_comments[7] = [node] self.assertEqual(read_as_lane(fake).refusal, "verify:repeated-fail") def test_without_the_lane_identity_no_record_resets(self) -> None: - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.closing_comments[7] = [capped_record(SIBLING, LANES_APP_ACTOR)] self.assertEqual(read(fake).refusal, "verify:repeated-fail") @@ -2175,7 +2241,7 @@ def test_after_a_capped_close_record_the_next_attempt_is_uncapped(self) -> None: def test_the_attempts_own_three_fails_still_cap(self) -> None: fake = self.attempt() - for i, sha in enumerate((EARLIER, IN_PR, UNRELATED), start=9): + for i, sha in enumerate((EARLIER, IN_PR, HEAD), start=9): fake.artifacts.append(artifact(named(sha, "fail"), i)) fake.runs[i] = judged(i, OLDER_START) self.assertEqual(read(fake).refusal, "verify:repeated-fail") @@ -2216,7 +2282,8 @@ def test_a_merged_pull_requests_three_fails_leave_the_attempt_uncapped( self.assertIsNone(read(self.attempt("MERGED")).refusal) def test_the_same_fails_cap_while_that_pull_request_is_open(self) -> None: - self.assertEqual(read(self.attempt("OPEN")).refusal, "verify:repeated-fail") + fake = failing_at_head(self.attempt("OPEN")) + self.assertEqual(read(fake).refusal, "verify:repeated-fail") class FailsOnARefsPullRequestForTheSameIssueCount(unittest.TestCase): @@ -2249,11 +2316,15 @@ def sibling_fails(*shas: str, suffix: str = "-i7") -> FakeGitHub: return fake def test_three_fails_on_another_refs_pull_request_refuse(self) -> None: - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) evidence = read(fake) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertFalse(evidence.needs_human) - self.assertEqual(downloads(fake), 0) + self.assertEqual( + downloads(fake), + 1, + "only the head FAIL's own record, read to judge whether it is superseded", + ) def test_two_there_and_a_fail_at_the_head_reach_the_cap(self) -> None: fake = self.sibling_fails(*SIBLING_HEADS[:2]) @@ -2271,11 +2342,13 @@ def test_only_names_that_carry_the_issue_count(self) -> None: # writer named issues) counts only for its own pull request. for suffix, refusal in ( ("-i7.8", "verify:repeated-fail"), - ("-i8", None), - ("", None), + ("-i8", "verify:fail"), + ("", "verify:fail"), ): with self.subTest(suffix): - fake = self.sibling_fails(*SIBLING_HEADS, suffix=suffix) + fake = failing_at_head( + self.sibling_fails(*SIBLING_HEADS, suffix=suffix) + ) self.assertEqual(read(fake).refusal, refusal) def test_a_long_cross_reference_timeline_holds_nothing(self) -> None: @@ -2290,7 +2363,7 @@ def test_a_long_cross_reference_timeline_holds_nothing(self) -> None: fake = self.sibling_fails(*SIBLING_HEADS[:2]) fake.mentions[7], fake.mentions_total[7] = mentions, 101 self.assertIsNone(read(fake).refusal) - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) fake.mentions[7], fake.mentions_total[7] = mentions, 101 self.assertEqual(read(fake).refusal, "verify:repeated-fail") @@ -2298,8 +2371,8 @@ def test_a_refs_pull_requests_own_state_decides(self) -> None: # A `Refs:` pull request is in no closing list, so its state is read # on its own; a failed read is unreadable, never an excuse. for answer, refusal in ( - ({"state": "closed", "merged_at": "2026-10-02T00:00:00Z"}, None), - ({"state": "closed", "user": LANES_APP_USER}, None), + ({"state": "closed", "merged_at": "2026-10-02T00:00:00Z"}, "verify:fail"), + ({"state": "closed", "user": LANES_APP_USER}, "verify:fail"), ({"state": "closed"}, "verify:repeated-fail"), ( {"state": "closed", "user": {"login": "someone", "type": "User"}}, @@ -2309,7 +2382,7 @@ def test_a_refs_pull_requests_own_state_decides(self) -> None: ("error", "verify:unreadable"), ): with self.subTest(refusal=refusal, answer=answer): - fake = self.sibling_fails(*SIBLING_HEADS) + fake = failing_at_head(self.sibling_fails(*SIBLING_HEADS)) if answer == "error": fake.fail.add(f"pulls/{SIBLING}") else: @@ -2342,10 +2415,15 @@ def named_fails(*shas: str, suffix: str = "-i7") -> FakeGitHub: return fake def test_three_named_fails_refuse(self) -> None: - evidence = read(self.named_fails(*SIBLING_HEADS)) + fake = failing_at_head(self.named_fails(*SIBLING_HEADS)) + evidence = read(fake) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertFalse(evidence.needs_human) - self.assertEqual(downloads(self.named_fails(*SIBLING_HEADS)), 0) + self.assertEqual( + downloads(fake), + 1, + "only the head FAIL's own record, read to judge whether it is superseded", + ) def test_two_named_and_a_fail_at_the_head_reach_the_cap(self) -> None: fake = self.named_fails(*SIBLING_HEADS[:2]) @@ -2362,7 +2440,7 @@ def test_any_listed_issue_counts(self) -> None: ten = "-i" + ".".join(str(n) for n in range(1, 11)) for suffix in ("-i7.12", "-i3.7", ten): with self.subTest(suffix): - fake = self.named_fails(*SIBLING_HEADS, suffix=suffix) + fake = failing_at_head(self.named_fails(*SIBLING_HEADS, suffix=suffix)) self.assertEqual(read(fake).refusal, "verify:repeated-fail") def test_a_name_without_the_issue_does_not_count(self) -> None: @@ -2463,7 +2541,7 @@ def test_an_unreadable_run_of_a_named_fail_refuses(self) -> None: self.assertIsNone(read(fake).refusal) def test_a_record_on_another_issue_leaves_a_named_fail_counted(self) -> None: - fake = also_closes_issue_8(self.named_fails(*SIBLING_HEADS)) + fake = also_closes_issue_8(failing_at_head(self.named_fails(*SIBLING_HEADS))) self.assertEqual(read_as_lane(fake).refusal, "verify:repeated-fail") def test_an_unreadable_named_fail_before_the_record_reads_no_state(self) -> None: @@ -2493,9 +2571,10 @@ def test_a_foreign_run_never_counts(self) -> None: class RepeatedFailsHoldForTheLanes(unittest.TestCase): """FAILs at `merge.max-verify-fails` (default 3) distinct heads of one - pull request hold it, never to merge unattended, whatever a later pass - says (owner decision 2026-10-21), for the lanes with no label (owner rule - 2026-10-27); fewer leave the pass to decide.""" + pull request hold it, never to merge unattended (owner decision + 2026-10-21), for the lanes with no label (owner rule 2026-10-27), only + when one of them stands at the head (owner decision Q245, 2026-11-20); a + pass at the head, or fewer heads, leave the pass to decide.""" @staticmethod def failed_at(*shas: str) -> FakeGitHub: @@ -2507,13 +2586,28 @@ def failed_at(*shas: str) -> FakeGitHub: runs=runs, ) - def test_fails_at_three_heads_refuse_despite_a_later_pass(self) -> None: - evidence = read(self.failed_at(EARLIER, IN_PR, UNRELATED)) + def test_fails_at_three_earlier_heads_leave_a_later_pass_to_decide(self) -> None: + self.assertIsNone(read(self.failed_at(EARLIER, IN_PR, UNRELATED)).refusal) + + def test_a_pass_after_fails_at_four_earlier_heads_decides(self) -> None: + oldest = "1" * 40 + fake = self.failed_at(EARLIER, IN_PR, UNRELATED, oldest) + fake.diffs[oldest] = change("1111") + evidence = read(fake) + self.assertIsNone(evidence.refusal) + self.assertEqual(len([v for v in evidence.verdicts if v.verdict == "fail"]), 4) + + def test_a_fail_at_the_head_after_fails_at_four_earlier_heads_caps(self) -> None: + oldest = "1" * 40 + fake = self.failed_at(EARLIER, IN_PR, UNRELATED, oldest, HEAD) + fake.diffs[oldest] = change("1111") + evidence = read(fake) self.assertEqual(evidence.refusal, "verify:repeated-fail") self.assertFalse(evidence.needs_human) self.assertEqual( evidence.detail, - f"fails at 3 heads ({EARLIER}, {IN_PR}, {UNRELATED}), the cap is 3", + f"fails at 5 heads ({oldest}, {HEAD}, {EARLIER}, {IN_PR}, {UNRELATED})," + " the cap is 3", ) def test_the_cap_fails_closed_when_its_fails_cannot_be_read(self) -> None: @@ -2604,11 +2698,11 @@ def test_a_fail_at_the_head_under_the_cap_stays_verify_fail(self) -> None: self.assertFalse(evidence.needs_human) def test_the_reader_takes_its_cap_from_the_setting(self) -> None: - fake = self.failed_at(EARLIER, IN_PR) + fake = self.failed_at(EARLIER, HEAD) for cap, expected in ( (2, "verify:repeated-fail"), (1, "verify:repeated-fail"), - (3, None), + (3, "verify:fail"), ): with self.subTest(cap=cap): with mock.patch.object(postmerge, "gh_capture", side_effect=fake): @@ -7098,9 +7192,9 @@ def test_a_tied_fail_after_the_pass_holds(self) -> None: # Only the untied FAILs' records: the pass decides nothing. self.assertEqual(download_requests(fake), 2) - def test_a_third_failed_head_reaches_the_cap(self) -> None: + def test_a_third_failed_head_at_the_head_reaches_the_cap(self) -> None: fake = self.heads() - fake.artifacts.append(artifact(named(IN_PR, "fail", 96), 5)) + fake.artifacts.append(artifact(named(HEAD, "fail", 96), 5)) fake.runs[5] = run(5) evidence = read(fake) self.assertEqual(evidence.refusal, "verify:repeated-fail") @@ -7157,8 +7251,10 @@ class TheByIdFetchDecidesAsGhRunDownloadDid(unittest.TestCase): report in each of the six cases and spend half the download requests. Two fields were changed since by design, not by the fetch: `needsHuman` is false for the repeated-FAIL cap (owner rule 2026-10-27), and the - report no longer carries `headFail`. Break `_record` on purpose and these - fail.""" + report no longer carries `headFail`. The cap needs a FAIL standing at the + head (owner decision Q245), so the third failed head is now at the head, + and a capped case also reads the head FAIL's record to judge whether it + is superseded. Break `_record` on purpose and these fail.""" @staticmethod def report( @@ -7181,7 +7277,7 @@ def cases(self) -> dict[str, tuple[FakeGitHub, dict[str, Any], int, int]]: before (`gh run download`, two each) and after (one each).""" heads = EachVerdictIsOneRequest.heads third = heads() - third.artifacts.append(artifact(named(IN_PR, "fail", 96), 5)) + third.artifacts.append(artifact(named(HEAD, "fail", 96), 5)) third.runs[5] = run(5) unreadable = heads() del unreadable.records[named(UNRELATED, "fail", 98)] @@ -7207,12 +7303,12 @@ def capped(*shas: str) -> str: third, self.report( "verify:repeated-fail", - ["pass"], - [*both, IN_PR], - detail=capped(EARLIER, TIE, IN_PR), + ["fail", "pass"], + both, + detail=capped(EARLIER, TIE, HEAD), ), - 4, - 2, + 6, + 3, ), "unreadable untied record": ( unreadable, @@ -7234,8 +7330,8 @@ def capped(*shas: str) -> str: both, detail=capped(EARLIER, TIE, HEAD), ), - 4, - 2, + 6, + 3, ), } @@ -8504,7 +8600,7 @@ def test_at_an_earlier_head(self) -> None: self.assertEqual(read(self.fail_at(EARLIER)).refusal, "verify:earlier-fail") def test_toward_the_cap(self) -> None: - heads = (EARLIER, IN_PR, UNRELATED) + heads = (EARLIER, IN_PR, HEAD) fake = self.fail_at(*heads) self.assertEqual(read(fake).refusal, "verify:repeated-fail") for sha in heads: @@ -8512,15 +8608,15 @@ def test_toward_the_cap(self) -> None: self.assertIsNone(read(fake).refusal) def test_toward_another_pull_requests_cap(self) -> None: - fake = FailsOnAnotherPullRequestForTheSameIssueCount.sibling_fails( - *SIBLING_HEADS + fake = failing_at_head( + FailsOnAnotherPullRequestForTheSameIssueCount.sibling_fails(*SIBLING_HEADS) ) for run_id in set(fake.runs) - {1}: fake.runs[run_id] = judged(run_id, FAIL_JUDGED) self.assertEqual(read(fake).refusal, "verify:repeated-fail") for sha in SIBLING_HEADS: draft_race(fake, sha) - self.assertIsNone(read(fake).refusal) + self.assertEqual(read(fake).refusal, "verify:fail") def test_only_a_listed_draft_step_conclusion_reads_the_state(self) -> None: def draft_run(jobs: dict[str, Any]) -> bool: