diff --git a/.changes/pr-pipeline/fix-9362-dependency-redispatch-7d4b2e19.md b/.changes/pr-pipeline/fix-9362-dependency-redispatch-7d4b2e19.md new file mode 100644 index 00000000000..10506de2018 --- /dev/null +++ b/.changes/pr-pipeline/fix-9362-dependency-redispatch-7d4b2e19.md @@ -0,0 +1,8 @@ +--- +bump: patch +--- + +### Fixed + +- `pr-unblock-dispatch.yml` dispatches `review-dependency` again at a head whose newest `pr-unblock / apply-dependency-verdict` check skipped `no-model-turn`. The `pr-unblock / review-dependency` check runs that started before that verdict no longer hold the head, a limit stop aside. Each such round still posts its round marker, so the round cap bounds the retries. The dispatcher records a head as reviewed only once a verdict check started after its newest `review-dependency` check, or once that check is a select job skip (`awaiting-human`, `not-applicable`, `superseded-sha`) that no verdict follows ([#9362](https://github.com/melodic-software/claude-code-plugins/issues/9362)). +- The dispatch record's version is now 2, so `pr-unblock-dispatch.yml` and `pr-feedback-dispatch.yml` read a record cached under the old rule as empty. Such a record could still hold a `no-model-turn` head as handled and skip the release ([#9362](https://github.com/melodic-software/claude-code-plugins/issues/9362), [#9360](https://github.com/melodic-software/claude-code-plugins/pull/9360)). diff --git a/.github/scripts/pr-unblock/dependency-dispatch.mjs b/.github/scripts/pr-unblock/dependency-dispatch.mjs index 4de9f49bdca..abbec0d1005 100644 --- a/.github/scripts/pr-unblock/dependency-dispatch.mjs +++ b/.github/scripts/pr-unblock/dependency-dispatch.mjs @@ -3,22 +3,33 @@ // same dispatcher run as dispatch.mjs (pr-unblock-dispatch.yml), so the // trigger gate and the broker check it as they check a resolve-conflicts // dispatch. A head that already carries a pr-unblock / review-dependency check -// run was reviewed; the model job's own selection decides the round cap. -// Logs carry PR numbers, SHAs and run ids only. +// run was reviewed, unless the head's newest pr-unblock / +// apply-dependency-verdict check run skipped no-model-turn: the +// review-dependency check runs that started before it handled nothing, so the +// head is dispatched again. The model job's own selection decides the round +// cap, and every such round posts its round marker. Logs carry PR numbers, +// SHAs and run ids only. // // Reads are spent only where they can change the decision: none once // maxDispatch is reached, none for a head the record holds as reviewed, and // no commits or files for a red ci-status, which is review tier on its own -// (dependency-classify.mjs classify). +// (dependency-classify.mjs classify). A head is recorded only once a verdict +// check started after its newest review-dependency check, or that check is a +// select job skip no verdict follows, so a no-model-turn verdict still to come +// can release it. import { DEPENDABOT_ID, DEPENDABOT_LOGIN, RED } from "./dependency-classify.mjs"; import { emptyRecord, isHandled, markHandled } from "./dispatch-record.mjs"; +import { limitResetsAt } from "./limit-stop.mjs"; import { ciStatusOf, classifyPull, commitFilesReader } from "./review-dependency.mjs"; export const DEFAULTS = Object.freeze({ base: "main", workflow: "pr-unblock.yml", checkName: "pr-unblock / review-dependency", + // The verdict job's check: its no-model-turn skip releases the round's + // review-dependency check runs. + verdictCheckName: "pr-unblock / apply-dependency-verdict", // The GitHub Actions app, as in dispatch.mjs. appId: 15368, // Judgment: one model run per PR, a few Dependabot PRs open at a time. @@ -30,6 +41,14 @@ const RUN_ID = /^[1-9][0-9]{0,14}$/; const handles = (run) => !(run.status === "completed" && run.conclusion === "neutral" && String(run.output?.title ?? "").startsWith("Skipped: untrusted-trigger")); +// The neutral titles review-dependency-not-run posts from the select job's +// skip reasons (review-dependency.mjs select): no verdict job follows them, +// so no no-model-turn verdict can release the head. +const TERMINAL_SKIPS = new Set(["Skipped: awaiting-human", "Skipped: not-applicable", "Skipped: superseded-sha"]); + +// NaN for a run with no readable start: it compares false either way. +const startOf = (run) => Date.parse(run.started_at ?? ""); + async function listAll(api, base) { const nodes = []; let after; @@ -50,6 +69,7 @@ export async function dispatchDependencyReviews({ base = DEFAULTS.base, workflow = DEFAULTS.workflow, checkName = DEFAULTS.checkName, + verdictCheckName = DEFAULTS.verdictCheckName, appId = DEFAULTS.appId, maxDispatch = DEFAULTS.maxDispatch, config = null, @@ -106,7 +126,27 @@ export async function dispatchDependencyReviews({ continue; } existing = await api.listCheckRuns({ sha: node.headRefOid, checkName, appId }); - if (existing.some((run) => run.status === "completed" && handles(run))) { + // A round whose verdict job skipped no-model-turn handled nothing: the + // review-dependency check runs that started before that verdict job + // stop counting, so this run dispatches the head again. A limit stop is + // never released, though its round's verdict also finds no model turn. + let verdicts = []; + if (existing.some(handles)) { + verdicts = await api.listCheckRuns({ sha: node.headRefOid, checkName: verdictCheckName, appId }); + const newest = verdicts.reduce((a, b) => (startOf(b) > startOf(a) ? b : a), verdicts[0]); + if (newest?.status === "completed" && newest.conclusion === "neutral" && newest.output?.title === "Skipped: no-model-turn") { + const cut = startOf(newest); + existing = existing.filter((run) => limitResetsAt(run) !== null || !(startOf(run) < cut)); + } + } + // Until a verdict check started after the newest review-dependency + // check, a no-model-turn verdict may still release the head, so it is + // not recorded yet; a newest check that is a select job skip no verdict + // job follows records at once. An unreadable start records nothing. + const newestCheck = Math.max(...existing.map(startOf)); + const last = existing.find((run) => startOf(run) === newestCheck); + const terminal = last?.status === "completed" && last.conclusion === "neutral" && TERMINAL_SKIPS.has(last.output?.title); + if (existing.some((run) => run.status === "completed" && handles(run)) && (terminal || verdicts.some((run) => startOf(run) > newestCheck))) { markHandled(record, checkName, node.headRefOid); } } catch (error) { diff --git a/.github/scripts/pr-unblock/dependency-dispatch.test.mjs b/.github/scripts/pr-unblock/dependency-dispatch.test.mjs index 474c0f7198b..fcaee1ff0c0 100644 --- a/.github/scripts/pr-unblock/dependency-dispatch.test.mjs +++ b/.github/scripts/pr-unblock/dependency-dispatch.test.mjs @@ -2,7 +2,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { dispatchDependencyReviews } from "./dependency-dispatch.mjs"; -import { emptyRecord, markHandled } from "./dispatch-record.mjs"; +import { emptyRecord, markHandled, parseRecord } from "./dispatch-record.mjs"; const CHECK = "pr-unblock / review-dependency"; @@ -52,7 +52,8 @@ function fakeApi({ nodes = [], checks = new Map(), ci = new Map(), files = new M if (checkName === "ci-status") { return ci.get(sha) ?? []; } - return checks.get(sha) ?? []; + // A run that names no check is the review-dependency one. + return (checks.get(sha) ?? []).filter((run) => (run.name ?? CHECK) === checkName); }, async dispatchWorkflow({ workflow, ref, inputs }) { calls.dispatch.push({ workflow, ref, inputs }); @@ -186,6 +187,118 @@ test("dispatches at most the cap, lowest number first", async () => { assert.deepEqual(dispatched.map((d) => d.number), [21, 22]); }); +// A round whose verdict job found no model turn (#9362): its +// apply-dependency-verdict check skipped no-model-turn, so the +// review-dependency check runs before it handled nothing, and the next run +// dispatches the head again. Every such round posts its round marker, so the +// select job's round cap still ends it. +const roundRun = (name, conclusion, title, started) => ({ + name: `pr-unblock / ${name}`, + status: "completed", + conclusion, + started_at: started, + completed_at: started, + output: { title, summary: "" }, +}); +const noModelTurn = (started = "2026-10-17T10:05:00Z") => roundRun("apply-dependency-verdict", "neutral", "Skipped: no-model-turn", started); +const headOf = (node, runs) => new Map([[node.headRefOid, runs]]); + +test("a head whose last round had no model turn dispatches again, and is not recorded as handled", async () => { + for (const [label, check] of [ + ["the model call failed", roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z")], + ["the broker refused the run", roundRun("review-dependency", "neutral", "Skipped: not-assessed", "2026-10-17T10:00:00Z")], + ]) { + const node = pr(60); + const record = emptyRecord(); + const { dispatched } = await run(fakeApi({ nodes: [node], checks: headOf(node, [check, noModelTurn()]) }), { record }); + assert.deepEqual(dispatched, [{ number: 60, workflowRunId: "7060" }], label); + assert.equal(record.handled.get(CHECK), undefined, label); + } +}); + +// A rate-limited model call leaves no verdict, so its verdict job also skips +// no-model-turn; that never releases the limit stop. +test("a no-model-turn verdict after a limit stop still holds the head", async () => { + const node = pr(61); + const stop = { + ...roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"), + output: { title: "Failed", summary: "lane=pr-unblock activity=review-dependency class=rate-limit resets=2026-10-17T11:00:00Z" }, + }; + const { dispatched } = await run(fakeApi({ nodes: [node], checks: headOf(node, [stop, noModelTurn()]) })); + assert.deepEqual(dispatched, []); +}); + +test("a round that answered, or a newer review-dependency check, still holds the head", async () => { + for (const [label, runs] of [ + ["the last round escalated", [roundRun("review-dependency", "success", "Passed", "2026-10-17T10:00:00Z"), roundRun("apply-dependency-verdict", "neutral", "Skipped: awaiting-human", "2026-10-17T10:05:00Z")]], + ["a no-model-turn round before a round that answered", [ + roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"), + noModelTurn(), + roundRun("review-dependency", "success", "Passed", "2026-10-17T11:00:00Z"), + roundRun("apply-dependency-verdict", "success", "Passed", "2026-10-17T11:05:00Z"), + ]], + // review-dependency-not-run posts the round cap's skip after the round. + ["the round cap was reached after it", [ + roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"), + noModelTurn(), + roundRun("review-dependency", "neutral", "Skipped: awaiting-human", "2026-10-17T11:00:00Z"), + ]], + ["no verdict job ran", [roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z")]], + ]) { + const node = pr(62); + const lines = []; + const api = fakeApi({ nodes: [node], checks: headOf(node, runs) }); + assert.deepEqual((await run(api, { log: (line) => lines.push(line) })).dispatched, [], label); + assert.deepEqual(api.calls.dispatch, [], label); + assert.match(lines.at(-1), /already has a pr-unblock \/ review-dependency check run/, label); + } +}); + +// Between the round's review-dependency check and its verdict job's check, a +// dispatcher run must not record the head, or the verdict's no-model-turn skip +// could never release it. +test("a head whose newest review-dependency check has no later verdict check is not recorded, and is released once the verdict skips no-model-turn", async () => { + const node = pr(63); + const record = emptyRecord(); + const check = roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"); + assert.deepEqual((await run(fakeApi({ nodes: [node], checks: headOf(node, [check]) }), { record })).dispatched, [], "the head is handled for now"); + assert.equal(record.handled.get(CHECK), undefined, "but not recorded"); + // An older verdict check, from an earlier round, does not count. + await run(fakeApi({ nodes: [node], checks: headOf(node, [noModelTurn("2026-10-17T09:05:00Z"), check]) }), { record }); + assert.equal(record.handled.get(CHECK), undefined); + const later = await run(fakeApi({ nodes: [node], checks: headOf(node, [check, noModelTurn()]) }), { record }); + assert.deepEqual(later.dispatched, [{ number: 63, workflowRunId: "7063" }]); +}); + +// The round cap's skip, posted by review-dependency-not-run, has no verdict +// job after it, so it records the head at once; a read runner skip waits for +// its verdict. +test("a head whose newest review-dependency check is a select skip is recorded, and a read runner skip is not", async () => { + for (const [label, runs] of [ + ["the round cap after a no-model-turn round", [roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"), noModelTurn(), roundRun("review-dependency", "neutral", "Skipped: awaiting-human", "2026-10-17T11:00:00Z")]], + ["the round cap alone", [roundRun("review-dependency", "neutral", "Skipped: awaiting-human", "2026-10-17T11:00:00Z")]], + ["a sort that no longer applies", [roundRun("review-dependency", "neutral", "Skipped: not-applicable", "2026-10-17T11:00:00Z")]], + ]) { + const node = pr(64); + const record = emptyRecord(); + assert.deepEqual((await run(fakeApi({ nodes: [node], checks: headOf(node, runs) }), { record })).dispatched, [], label); + assert.ok(record.handled.get(CHECK)?.has(node.headRefOid), label); + } + const node = pr(65); + const record = emptyRecord(); + await run(fakeApi({ nodes: [node], checks: headOf(node, [roundRun("review-dependency", "neutral", "Skipped: not-assessed", "2026-10-17T10:00:00Z")]) }), { record }); + assert.equal(record.handled.get(CHECK), undefined); +}); + +// A record the dispatcher wrote before a no-model-turn verdict released the +// head holds it as handled; that record's version is read as empty. +test("a version 1 record that holds a no-model-turn head is ignored, and the head dispatches again", async () => { + const node = pr(66); + const record = parseRecord(JSON.stringify({ version: 1, handled: { [CHECK]: [node.headRefOid] }, dispatched: {} })); + const checks = headOf(node, [roundRun("review-dependency", "failure", "Failed", "2026-10-17T10:00:00Z"), noModelTurn()]); + assert.deepEqual((await run(fakeApi({ nodes: [node], checks }), { record })).dispatched, [{ number: 66, workflowRunId: "7066" }]); +}); + // Reads spent only where they change the decision. Each count beside the // assertion is what the dispatcher read before it skipped them. const RED_CI = [{ id: 1, app: { slug: "github-actions" }, status: "completed", conclusion: "failure" }]; @@ -212,11 +325,14 @@ test("once the cap is reached the rest are left unread", async () => { test("a reviewed head is recorded, and the next run reads nothing for it", async () => { const node = pr(10); - const checks = new Map([[node.headRefOid, [{ status: "completed", conclusion: "success", output: { title: "Reviewed" } }]]]); + // The round's verdict job posted after it, so no no-model-turn skip can still release the head. + const reviewed = { status: "completed", conclusion: "success", started_at: "2026-10-17T10:00:00Z", output: { title: "Reviewed" } }; + const checks = new Map([[node.headRefOid, [reviewed, roundRun("apply-dependency-verdict", "success", "Passed", "2026-10-17T10:05:00Z")]]]); const record = emptyRecord(); const first = fakeApi({ nodes: [node], checks }); assert.deepEqual((await run(first, { record })).dispatched, []); - assert.equal(first.calls.checks.length, 2); + // ci-status, then both checks' runs. + assert.equal(first.calls.checks.length, 3); assert.ok(record.handled.get(CHECK).has(node.headRefOid)); const second = fakeApi({ nodes: [node], checks }); assert.deepEqual((await run(second, { record })).dispatched, []); diff --git a/.github/scripts/pr-unblock/dispatch-record.mjs b/.github/scripts/pr-unblock/dispatch-record.mjs index 56215ab555d..4a004e059cc 100644 --- a/.github/scripts/pr-unblock/dispatch-record.mjs +++ b/.github/scripts/pr-unblock/dispatch-record.mjs @@ -9,6 +9,10 @@ import { readFileSync, writeFileSync } from "node:fs"; const SHA = /^[0-9a-f]{40}$/; const RUN_ID = /^[1-9][0-9]{0,14}$/; +// Raised whenever a dispatcher changes which check runs handle a head for +// good, so a record written under the old rule is read as empty: version 2 +// leaves unrecorded a head a later no-model-turn reply or verdict can release. +export const RECORD_VERSION = 2; export function emptyRecord() { return { handled: new Map(), dispatched: new Map() }; @@ -22,7 +26,7 @@ export function parseRecord(text) { } catch { return record; } - if (doc?.version !== 1) { + if (doc?.version !== RECORD_VERSION) { return record; } for (const [check, heads] of Object.entries(doc.handled ?? {})) { @@ -43,7 +47,7 @@ export function serializeRecord(record) { [...record.handled].filter(([, heads]) => heads.size > 0).sort(([a], [b]) => a.localeCompare(b)).map(([check, heads]) => [check, [...heads].sort()]), ); const dispatched = Object.fromEntries([...record.dispatched].sort(([a], [b]) => a.localeCompare(b))); - return `${JSON.stringify({ version: 1, handled, dispatched })}\n`; + return `${JSON.stringify({ version: RECORD_VERSION, handled, dispatched })}\n`; } export const isHandled = (record, check, head) => record.handled.get(check)?.has(head) === true; diff --git a/.github/scripts/pr-unblock/dispatch.test.mjs b/.github/scripts/pr-unblock/dispatch.test.mjs index 9f901849316..cc6fa59ef7b 100644 --- a/.github/scripts/pr-unblock/dispatch.test.mjs +++ b/.github/scripts/pr-unblock/dispatch.test.mjs @@ -864,13 +864,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: 1, handled: { [CHECK_NAME]: ["f".repeat(40)] }, dispatched: {} })); + writeFileSync(path, JSON.stringify({ version: 2, handled: { [CHECK_NAME]: ["f".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 () => ({}) }); try { writeFileSync(output, ""); assert.equal(await main(env, options()), 0); assert.equal(readFileSync(output, "utf8"), "record-changed=true\n"); - assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { version: 1, handled: { [CHECK_NAME]: [pr(1).headRefOid] }, dispatched: {} }); + assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { version: 2, handled: { [CHECK_NAME]: [pr(1).headRefOid] }, dispatched: {} }); writeFileSync(output, ""); assert.equal(await main(env, options()), 0); assert.equal(readFileSync(output, "utf8"), ""); diff --git a/.github/scripts/pr-unblock/feedback-dispatch.test.mjs b/.github/scripts/pr-unblock/feedback-dispatch.test.mjs index dbdb3a7e40c..aa23d12ce8a 100644 --- a/.github/scripts/pr-unblock/feedback-dispatch.test.mjs +++ b/.github/scripts/pr-unblock/feedback-dispatch.test.mjs @@ -566,7 +566,7 @@ test("a pr-verify run dispatches past a check run and a handled record from befo t.after(() => rmSync(dir, { recursive: true, force: true })); const before = { name: "pr-unblock / address-feedback", status: "completed", conclusion: "neutral", started_at: "2026-10-17T11:00:00Z", output: { title: "Skipped: no-model-turn" } }; const record = join(dir, "record.json"); - writeFileSync(record, JSON.stringify({ version: 1, handled: { "pr-unblock / address-feedback": [HEAD] }, dispatched: {} })); + writeFileSync(record, JSON.stringify({ version: 2, handled: { "pr-unblock / address-feedback": [HEAD] }, dispatched: {} })); const api = verifyApi({ checkRuns: [before] }); const { output } = await verifyMain(dir, api, HEAD, record); assert.equal(api.calls.dispatch.length, 1); @@ -936,6 +936,15 @@ test("a head whose newest address-feedback check has no later reply check is not assert.deepEqual(later.result, { number: 42, workflowRunId: "38779200001" }); }); +// A record the dispatcher wrote before a no-model-turn reply released the +// head holds it as handled; that record's version is read as empty. +test("a version 1 record that holds a no-model-turn head is ignored, and the head dispatches again", async () => { + const old = parseRecord(JSON.stringify({ version: 1, handled: { "pr-unblock / address-feedback": [HEAD] }, dispatched: {} })); + const check = roundRun("address-feedback", "failure", "Failed", "2026-10-17T10:00:00Z"); + const { result } = await decideWith(fakeApi({ checkRuns: [check, noModelTurn()] }), old); + assert.deepEqual(result, { number: 42, workflowRunId: "38779200001" }); +}); + test("a limit-stopped run is not recorded", async () => { const record = emptyRecord(); const stopped = failedRun("lane=pr-unblock activity=address-feedback class=rate-limit resets=2026-10-17T12:00:00Z"); diff --git a/docs/conventions/pr-pipeline/README.md b/docs/conventions/pr-pipeline/README.md index 8bf75169559..629a808e958 100644 --- a/docs/conventions/pr-pipeline/README.md +++ b/docs/conventions/pr-pipeline/README.md @@ -223,9 +223,11 @@ so the gate and the broker check them as they check a conflict dispatch. After t dispatches it lists open, non-draft, same-repository Dependabot PRs into `main`, sorts each with `dependency-classify.mjs`, and dispatches `pr-unblock.yml` with `activity: review-dependency` for at most 2 `review`-tier PRs per run whose head has no `pr-unblock / review-dependency` check run -from the GitHub Actions app (the untrusted-trigger skip aside). Their run ids join the same -dispatched-runs record. It has no schedule: the broker accepts a dispatcher run started only by a -push or a listed human, so a push to `main` or a hand run wakes it. In `pr-unblock.yml`, no +from the GitHub Actions app (the untrusted-trigger skip aside; one that started before the head's +newest `pr-unblock / apply-dependency-verdict` check run stops counting when that run skipped +`no-model-turn`, unless it is a limit stop, and the round cap still bounds the retries). Their run +ids join the same dispatched-runs record. It has no schedule: the broker accepts a dispatcher run +started only by a push or a listed human, so a push to `main` or a hand run wakes it. In `pr-unblock.yml`, no model holds a write token: `review-dependency-select` (base code only, read-only token) selects the pull request or posts its check neutral; `review-dependency` (a `read` skill in [patch output mode](pr-run-activity.md#patch-output-mode), on run-claude-cli with the diff --git a/docs/conventions/pr-pipeline/pr-run-activity.md b/docs/conventions/pr-pipeline/pr-run-activity.md index efa49f9a250..0bf666310e4 100644 --- a/docs/conventions/pr-pipeline/pr-run-activity.md +++ b/docs/conventions/pr-pipeline/pr-run-activity.md @@ -1077,7 +1077,9 @@ warns of a [classifier gap](README.md#classifier-gaps). `dependency-invalid`. With no verdict, the round still counts: it skips `no-model-turn` only when the same call's scan handed on no patch, refused nothing, and the PR head is still the select job's; a scan that refused an oversize patch escalates `dependency-fix-not-landed`, - and any other case `dependency-invalid`; + and any other case `dependency-invalid`. The dispatcher dispatches a head whose newest + verdict job skipped `no-model-turn` again on its next run, a limit stop aside; the round cap + bounds those retries; - re-reads the pull request: a closed one gets nothing, unless it is a `close` this job started at the reviewed head (its issue or marker is there), which resumes. `merge`, `close` and `escalate` need the reviewed head; a moved head skips `superseded-sha` and the