diff --git a/.changes/pr-pipeline/work-resolve-issue-issue-11200-3d9f6b21.md b/.changes/pr-pipeline/work-resolve-issue-issue-11200-3d9f6b21.md new file mode 100644 index 00000000000..e17ee74249a --- /dev/null +++ b/.changes/pr-pipeline/work-resolve-issue-issue-11200-3d9f6b21.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Fixed + +- pr-merge's `clear-escalations` sweep now also removes `needs-session` after a push that mends the stop. That holds when the head is no longer any stop's head, the newest `pr-unblock/*` status for each stop's activity at the new head, if any, is a success, and its checks pass, not counting `ci-status`, which the label keeps red. Before, only a same-head retry lifted the label, and a session had to remove it by hand after a new head. A `dependency-workflow-unpinned` stop still comes off only on its own head. If the cause still holds, the lane stops again on the new head and labels it again ([#11200](https://github.com/melodic-software/claude-code-plugins/issues/11200)). diff --git a/.github/scripts/pr-merge/clear-escalations.mjs b/.github/scripts/pr-merge/clear-escalations.mjs index a4b0defd7a3..559e5ec7577 100755 --- a/.github/scripts/pr-merge/clear-escalations.mjs +++ b/.github/scripts/pr-merge/clear-escalations.mjs @@ -139,9 +139,11 @@ // // The session-builder queue label (needs-session, each `label` that // escalation-routes.json names) comes off with no comment when the lanes App -// added it last and each lane stop routed to it since then has its failing -// status cleared on that stop's head: a same-head retry landed and -// report-escalation.sh `clear` posted success after that stop (sessionVerdict). +// added it last and each lane stop routed to it since then is mended: a +// same-head retry landed and report-escalation.sh `clear` posted success after +// that stop, or the head moved off every such stop's head and the new head +// carries no failing status for their activities and passes its checks +// (sessionVerdict). // At most SESSION_CHECKS_PER_RUN pull requests are read a run, kept or cleared, // from the same rotating offset. // @@ -149,8 +151,8 @@ // GH_TOKEN the lane App token (pull-requests and issues write) // CHECKS_TOKEN the job's own token (checks: read, actions: read), for // the head's pr-require-checks runs and check runs, -// and a lane stop's head statuses, which the lane -// token cannot read +// and the statuses of a lane stop's head and the +// current head, which the lane token cannot read // GITHUB_REPOSITORY owner/repo // KILL_SWITCH `proceed` from the kill-switch step; anything else stops // TRACKER_CONFIG the base .work-item-tracker.json, for the human-gated @@ -445,20 +447,26 @@ const CHECKS = Object.freeze({ }); // A ci-fix stop: the lane could not fix CI at its resume key. Gone once a -// trusted push moved the head and, at the new head, no check fails, runs or -// was cancelled (fix-ci's failingChecks over every run, so a later skip hides -// no failure), each check's latest run ended in PASSING, and one passed. -// ci-status is left out: the label fails it. +// trusted push moved the head and checksHeld finds the new head's checks pass. async function ciPasses(context) { const moved = await context.moved(); if (moved === null) { return { held: "no trusted push alone moved the head off the resume key" }; } - const head = context.pull.head.sha; - const runs = await context.read(async (reader) => { + const held = await checksHeld(context.read, context.repo, context.pull.head.sha); + return held === null ? `${moved}, and no check other than ${AGGREGATE} fails, runs or was cancelled at it` : { held }; +} + +// Why `head`'s checks do not pass, or null when they do: no check fails, runs +// or was cancelled (fix-ci's failingChecks over every run, so a later skip +// hides no failure), each check's latest run ended in PASSING, and one passed. +// ci-status is left out: the label fails it. `read` runs a read with a token +// that holds checks: read and answers null when the read fails. +async function checksHeld(read, repo, head) { + const runs = await read(async (reader) => { const all = []; for (let page = 1; page <= CHECK_PAGES; page += 1) { - const batch = (await reader("GET", `/repos/${context.repo}/commits/${head}/check-runs?filter=all&per_page=100&page=${page}`))?.check_runs; + const batch = (await reader("GET", `/repos/${repo}/commits/${head}/check-runs?filter=all&per_page=100&page=${page}`))?.check_runs; if (!Array.isArray(batch)) { return null; } @@ -483,9 +491,9 @@ async function ciPasses(context) { [...latest.values()].some((run) => !PASSING.has(run.conclusion)) || !others.some((run) => run.conclusion === "success") ) { - return { held: `a check other than ${AGGREGATE} fails, runs, was cancelled or did not pass at ${head}, or its runs did not read` }; + return `a check other than ${AGGREGATE} fails, runs, was cancelled or did not pass at ${head}, or its runs did not read`; } - return `${moved}, and no check other than ${AGGREGATE} fails, runs or was cancelled at it`; + return null; } // The review lanes reviewLanesClean reads, as pr-require-checks.yml's @@ -1495,20 +1503,37 @@ const STOP_HEAD = /^- Head: `([0-9a-f]{40})`$/m; // report-escalation.sh's status context for an activity. const stopContext = (activity) => (activity === "resolve-conflicts" ? "pr-unblock/conflict" : `pr-unblock/${activity}`); +// A stop the new-head lift leaves on: the route marks a workflow or action +// change beyond a full-SHA pin swap, which green checks do not judge, so only +// its lane's own clear on the stop's head removes the label. +const SAME_HEAD_ONLY = Object.freeze(["dependency-workflow-unpinned"]); +// The newest status for `context` by github-actions[bot] in `statuses` +// (newest first), or undefined. +const laneStatus = (statuses, context) => statuses.find((status) => status?.context === context && status?.creator?.login === "github-actions[bot]"); + // Whether the session label `label` on `number` comes off, or { reason } // saying why it stays. It comes off only when the lanes App added it last, // and every lanes App lane-stopped comment (one per activity, edited in -// place) written or edited since then whose reason routes to `label` names a -// head whose newest status for that activity's context, by -// github-actions[bot], is `success` and newer than the stop: the stop that -// added it was cleared on that same head. report-stop-status posts a stop's -// failure in a job of its own, so a success older than the comment belongs to -// an earlier stop and proves nothing. A stop since the label whose reason or -// head does not parse, none at all, or a status read that fails keeps it. A -// later head carries no status, so a stop on an older head keeps it for a -// session. `checks` (the -// job token) reads the statuses; the lanes App token holds no statuses -// permission. +// place) written or edited since then whose reason routes to `label` is +// mended, on its own head or on a new one. +// - Same head: the newest status at the stop's head for that activity's +// context, by github-actions[bot], is `success` and newer than the stop +// (report-escalation.sh `clear`, after a same-head retry landed). +// report-stop-status posts a stop's failure in a job of its own, so a +// success older than the comment belongs to an earlier stop and proves +// nothing. +// - New head: when the PR's head is none of those stops' heads, a stop not +// so cleared is mended once its route is off SAME_HEAD_ONLY, the newest +// github-actions[bot] status for its context at the current head, if any, +// is `success`, and the current head's checks pass (checksHeld). The PR +// and the current head are read only when some stop is not cleared on its +// own head. +// A lane posts a status only on a head it gates, so nothing else marks a +// new head mended; a cause that still holds stops the lane again on the +// new head, and that stop puts the label back. +// A stop since the label whose reason or head does not parse, none at all, +// or a read that fails keeps it. `checks` (the job token) reads the statuses +// and check runs; the lanes App token holds no statuses permission. async function sessionVerdict({ github, checks, repo, number, label, bot }) { const timeline = await paginate(github, `/repos/${repo}/issues/${number}/timeline`); const { labeled, since } = labelHistory(timeline, label, new Set()); @@ -1522,7 +1547,7 @@ async function sessionVerdict({ github, checks, repo, number, label, bot }) { stops.set(activity, item); } } - const why = []; + const routed = []; for (const [activity, item] of stops) { const stoppedAt = Math.max(Date.parse(item.created_at), Date.parse(item.updated_at ?? item.created_at)); if (stoppedAt < since) { @@ -1534,27 +1559,69 @@ async function sessionVerdict({ github, checks, repo, number, label, bot }) { if (reason === undefined || head === undefined || escalationActivity(reason) !== activity) { return { reason: `the ${activity} stop since ${label} went on names no reason, head or activity this script can read` }; } - if (ROUTES[reason].label !== label) { - continue; + if (ROUTES[reason].label === label) { + routed.push({ activity, reason, head, stoppedAt }); } - const context = stopContext(activity); - let statuses; + } + if (routed.length === 0) { + return { reason: `no lane stop routed to ${label} since it went on` }; + } + // A read that fails keeps the label and leaves the run green. + const guarded = async (fn) => { try { - statuses = await readStatuses(checks, repo, head); + return await fn(); } catch (error) { console.log(`::warning title=clear-escalations::#${number}: ${escapeCommand(error?.message ?? error)}`); - return { reason: `the statuses of ${head} did not read` }; + return null; + } + }; + const why = []; + const open = []; + for (const stop of routed) { + const context = stopContext(stop.activity); + const statuses = await guarded(() => readStatuses(checks, repo, stop.head)); + if (statuses === null) { + return { reason: `the statuses of ${stop.head} did not read` }; } - const newest = statuses.find((status) => status?.context === context && status?.creator?.login === "github-actions[bot]"); - if (newest?.state !== "success") { - return { reason: `${reason} still fails ${context} at ${head} (${newest?.state ?? "no status"})` }; + const own = laneStatus(statuses, context); + if (own?.state === "success" && Date.parse(own.created_at) > stop.stoppedAt) { + why.push(`${stop.reason} no longer fails ${context} at ${stop.head}`); + } else { + open.push({ ...stop, context, own }); + } + } + if (open.length === 0) { + return { reason: null, why: why.join("; ") }; + } + const current = (await guarded(() => github("GET", `/repos/${repo}/pulls/${number}`)))?.head?.sha; + if (!SHA.test(String(current))) { + return { reason: "the pull request's head did not read" }; + } + if (routed.some(({ head }) => head === current)) { + const { reason, context, head, own } = open[0]; + const state = own?.state === "success" ? "no success since the stop" : (own?.state ?? "no status"); + return { reason: `${reason} still fails ${context} at ${head} (${state})` }; + } + const now = await guarded(() => readStatuses(checks, repo, current)); + if (now === null) { + return { reason: `the statuses of ${current} did not read` }; + } + for (const { reason, context, head } of open) { + if (SAME_HEAD_ONLY.includes(reason)) { + return { reason: `${reason} stopped at ${head}, and only its lane's clear on that head lifts ${label}: green checks do not judge its workflow change` }; } - if (!(Date.parse(newest.created_at) > stoppedAt)) { - return { reason: `${reason} still fails ${context} at ${head} (no success since the stop)` }; + const newest = laneStatus(now, context); + if (newest !== undefined && newest.state !== "success") { + return { reason: `${reason}'s ${context} reads ${newest.state} at the new head ${current}` }; } - why.push(`${reason} no longer fails ${context} at ${head}`); + why.push(`${reason} stopped at ${head}, and no ${context} status fails at the new head ${current}`); + } + const held = await checksHeld((fn) => guarded(() => fn(checks)), repo, current); + if (held !== null) { + return { reason: `${label} stays at the new head: ${held}` }; } - return why.length === 0 ? { reason: `no lane stop routed to ${label} since it went on` } : { reason: null, why: why.join("; ") }; + why.push(`no check other than ${AGGREGATE} fails, runs or was cancelled at ${current}`); + return { reason: null, why: why.join("; ") }; } // Takes each session label off where sessionVerdict finds its stop cleared, diff --git a/.github/scripts/pr-merge/clear-escalations.test.mjs b/.github/scripts/pr-merge/clear-escalations.test.mjs index 236c9e3ec25..72461748b01 100644 --- a/.github/scripts/pr-merge/clear-escalations.test.mjs +++ b/.github/scripts/pr-merge/clear-escalations.test.mjs @@ -42,17 +42,20 @@ const RED = [check("test-node", "failure")]; // `evidence` is what the gate's reader (enable-auto-merge pythonVerify) answers. // `reviewThreads` is the GraphQL reviewThreads page answered for a cursor. const threadPage = (nodes, hasNextPage = false) => ({ nodes, pageInfo: { hasNextPage, endCursor: hasNextPage ? "next" : null } }); -function world({ timeline, mainFiles = [{ filename: "README.md" }], mergeable = false, pullFiles = [], reviewComments = [], reviews = [], threadsFail = false, reviewThreads = () => threadPage([]), author, headChecks = [], evidence = () => null, numbers = [7], headRepo = REPO, reader, listed = ["needs-human"], labels = ["needs-human"], sessionNumbers = [], statuses = [] }) { +function world({ timeline, mainFiles = [{ filename: "README.md" }], mergeable = false, pullFiles = [], reviewComments = [], reviews = [], threadsFail = false, reviewThreads = () => threadPage([]), author, headChecks = [], evidence = () => null, numbers = [7], headRepo = REPO, reader, listed = ["needs-human"], labels = ["needs-human"], sessionNumbers = [], statuses = [], keyStatuses = [] }) { const calls = []; const known = (number) => numbers.includes(number) || sessionNumbers.includes(number); const checks = async (method, path) => { calls.push({ method, path, token: "checks" }); - // `statuses` is the HEAD's REST statuses, newest first, or an Error. - if (path.startsWith(`/repos/${REPO}/commits/${HEAD}/statuses?`)) { - if (statuses instanceof Error) { - throw statuses; + // `statuses` is the HEAD's REST statuses, newest first, or an Error; + // `keyStatuses` the KEY's, an older head a lane stopped on. + const statusHead = new RegExp(`^/repos/${REPO}/commits/([0-9a-f]{40})/statuses\\?`).exec(path)?.[1]; + if (statusHead === HEAD || statusHead === KEY) { + const rows = statusHead === HEAD ? statuses : keyStatuses; + if (rows instanceof Error) { + throw rows; } - return path.endsWith("page=1") ? statuses : []; + return path.endsWith("page=1") ? rows : []; } if (headChecks instanceof Error) { throw headChecks; @@ -84,7 +87,7 @@ function world({ timeline, mainFiles = [{ filename: "README.md" }], mergeable = if (method === "GET" && kind === "issues" && route.endsWith("/timeline") && known(Number(number))) { return path.endsWith("page=1") ? timeline : []; } - if (method === "GET" && kind === "pulls" && numbers.includes(Number(number))) { + if (method === "GET" && kind === "pulls" && known(Number(number))) { return { number: Number(number), state: "open", user: author, base: { ref: "main", sha: MAIN }, head: { sha: HEAD, ref: "feat/x", repo: { full_name: headRepo } }, labels: labels.map((name) => ({ name })), mergeable }; } if (method === "GET" && route === `/repos/${REPO}/compare/${HEAD}...${MAIN}`) { @@ -1697,10 +1700,10 @@ test("a person's comment written before the label and edited after it, or in the // whose escalation-routes.json entry names it, and its `clear` mode posts // success over the stop's failing status when a same-head retry lands. const sessionLabeled = (actor, at = "2026-10-18T10:00:00Z") => ({ event: "labeled", actor, label: { name: "needs-session" }, created_at: at }); -const stopBody = (reason, head = HEAD) => - `\nThe pr-unblock lane stopped \`fix-ci\` on this pull request: why. The lane labels it \`needs-session\` for a session builder, who makes the change this lane cannot, and the run ends in a failing \`pr-unblock/fix-ci\` status on the head the lane gated.\n\n- Reason: \`${reason}\`\n- Head: \`${head}\`\n- Run: https://github.com/${REPO}/actions/runs/1\n`; -const stopped = (reason = "ci-fix-escalated") => commented(BOT, stopBody(reason), "2026-10-18T10:00:02Z"); -const status = (state, creator = ACTIONS_BOT, at = "2026-10-18T11:00:00Z") => ({ context: "pr-unblock/fix-ci", state, creator, created_at: at }); +const stopBody = (reason, head = HEAD, activity = escalationActivity(reason)) => + `\nThe pr-unblock lane stopped \`${activity}\` on this pull request: why. The lane labels it \`needs-session\` for a session builder, who makes the change this lane cannot, and the run ends in a failing \`pr-unblock/${activity}\` status on the head the lane gated.\n\n- Reason: \`${reason}\`\n- Head: \`${head}\`\n- Run: https://github.com/${REPO}/actions/runs/1\n`; +const stopped = (reason = "ci-fix-escalated", head = HEAD) => commented(BOT, stopBody(reason, head), "2026-10-18T10:00:02Z"); +const status = (state, creator = ACTIONS_BOT, at = "2026-10-18T11:00:00Z", context = "pr-unblock/fix-ci") => ({ context, state, creator, created_at: at }); const sessionWorld = (options) => world({ numbers: [], sessionNumbers: [8], ...options }); test("a rung-0 ci-fix-escalated stop whose same-head retry landed leaves the PR without needs-session, with no comment", async () => { @@ -1755,6 +1758,57 @@ test("a needs-session a person added, or one with no lane stop since it went on, } }); +// The new-head lift (#11200): a stop's status sits on the stop's head, so a +// push leaves nothing that marks the new head mended. The label comes off +// when the head is none of the stops' heads, the new head carries no failing +// status for their activities, and its checks pass; ci-status, which the +// label keeps red, is not counted. +const NEW_HEAD_GREEN = [check("test-node", "success"), check("ci-status", "failure", { id: 2 })]; +const laneContext = (reason) => `pr-unblock/${escalationActivity(reason)}`; + +test("a needs-session stop on an older head comes off once the new head carries no failing status and its checks pass", async () => { + for (const reason of ["ci-fix-escalated", "dependency-round-cap"]) { + assert.equal(ROUTES[reason].label, "needs-session"); + const keyStatuses = [status("failure", ACTIONS_BOT, "2026-10-18T10:00:01Z", laneContext(reason))]; + const w = sessionWorld({ timeline: [sessionLabeled(BOT), stopped(reason, KEY)], keyStatuses, headChecks: NEW_HEAD_GREEN }); + const { code, logs } = await run(w); + assert.equal(code, 0); + assert.deepEqual(w.writes(), [{ method: "DELETE", path: `/repos/${REPO}/issues/8/labels/needs-session`, body: undefined }], reason); + const cleared = new RegExp(`#8 needs-session cleared: ${reason} stopped at ${KEY}, and no ${laneContext(reason)} status fails at the new head ${HEAD}; no check other than ci-status fails`); + assert.ok(logs.some((line) => cleared.test(line)), logs.join("\n")); + } +}); + +test("a new head keeps needs-session while the stop's status fails there or its checks do not pass", async () => { + for (const [options, kept] of [ + [{ statuses: [status("failure")], headChecks: NEW_HEAD_GREEN }, /pr-unblock\/fix-ci reads failure at the new head/], + [{ statuses: [status("pending"), status("success")], headChecks: NEW_HEAD_GREEN }, /pr-unblock\/fix-ci reads pending at the new head/], + [{ headChecks: RED }, /stays at the new head: a check other than ci-status fails/], + [{ headChecks: [check("ci-status", "failure")] }, /stays at the new head/], + [{ headChecks: [{ ...check("test-node", "success"), status: "in_progress", conclusion: null }] }, /stays at the new head/], + [{ headChecks: new Error("HTTP 403") }, /stays at the new head/], + ]) { + const w = sessionWorld({ timeline: [sessionLabeled(BOT), stopped("ci-fix-escalated", KEY)], keyStatuses: [status("failure")], ...options }); + const { code, logs } = await run(w); + assert.equal(code, 0); + assert.deepEqual(w.writes(), [], String(kept)); + assert.ok(logs.some((line) => /#8 needs-session kept: /.test(line) && kept.test(line)), logs.join("\n")); + } +}); + +test("a dependency-workflow-unpinned stop keeps needs-session on a new head; only its same-head clear removes it", async () => { + const reason = "dependency-workflow-unpinned"; + const context = laneContext(reason); + const failed = status("failure", ACTIONS_BOT, "2026-10-18T10:00:01Z", context); + const kept = sessionWorld({ timeline: [sessionLabeled(BOT), stopped(reason, KEY)], keyStatuses: [failed], headChecks: NEW_HEAD_GREEN }); + const { logs } = await run(kept); + assert.deepEqual(kept.writes(), []); + assert.ok(logs.some((line) => /#8 needs-session kept: dependency-workflow-unpinned stopped at .*only its lane's clear on that head/.test(line)), logs.join("\n")); + const lifted = sessionWorld({ timeline: [sessionLabeled(BOT), stopped(reason, KEY)], keyStatuses: [status("success", ACTIONS_BOT, undefined, context), failed] }); + await run(lifted); + assert.deepEqual(lifted.writes(), [{ method: "DELETE", path: `/repos/${REPO}/issues/8/labels/needs-session`, body: undefined }]); +}); + test("a needs-session stop whose head statuses do not read keeps the label without failing the run", async () => { const w = sessionWorld({ timeline: [sessionLabeled(BOT), stopped()], statuses: new Error("HTTP 403") }); const { code, logs } = await run(w); diff --git a/docs/conventions/pr-pipeline/README.md b/docs/conventions/pr-pipeline/README.md index 1c76b3374bb..1da1061e54e 100644 --- a/docs/conventions/pr-pipeline/README.md +++ b/docs/conventions/pr-pipeline/README.md @@ -716,8 +716,12 @@ the review could not finish (its cap, an unlanded fix, an unreadable config, a c an uncited control, a workflow change beyond a pin swap). `review-dependency` and `apply-dependency-patch` do not apply while `needs-session` is on (their `labels-absent` in `pr-pipeline.yaml`), so such a stop gets no same-head model re-run and no fresh round budget on a -rebased head until a session removes the label, or `clear-escalations.mjs` does once a same-head -retry cleared the stop's failing status. It also puts the PR in the +rebased head until a session removes the label, or `clear-escalations.mjs` does: once a same-head +retry cleared the stop's failing status, or once the head moved off every such stop's head and the +new head carries no failing status for their activities and passes its checks (`ci-status` aside, +which the label keeps red). A `dependency-workflow-unpinned` stop is lifted only on its own head, +since green checks do not judge a workflow change. If the cause holds, the lane stops again on the +new head and labels it again. It also puts the PR in the session-builder queue with that label, which no merge gate reads, so a session builder makes the change instead of a person; a person arms it only where the merge gate already asks for one. Every other reason is a defect the lane's bounded retries (the