diff --git a/.changes/pr-pipeline/feat-work-unblock-no-stops-oldest-first-ebf1f5bf.md b/.changes/pr-pipeline/feat-work-unblock-no-stops-oldest-first-ebf1f5bf.md new file mode 100644 index 00000000000..4fefda16365 --- /dev/null +++ b/.changes/pr-pipeline/feat-work-unblock-no-stops-oldest-first-ebf1f5bf.md @@ -0,0 +1,13 @@ +--- +bump: minor +--- + +### Changed + +- work-unblock and the hourly triage sweep no longer stop an item for a person outside an intent or security question (owner intent, 2026-10-24): + - A stranded issue already re-fired on its lane workflow files, or a lane token request that keeps failing, is re-fired again on a backoff (three hours, doubling, at most 24) with one comment edited in place, never `needs-human`. + - A lanes App PR merged with `Refs:` or closed unmerged takes `status: ready` and `agent-ready` off and adds no `needs-triage`, so the triage sweep sends the issue back to intake, whose fresh `status: ready` re-admits it. + - A blocker closed by a listed human or a merge in this repository counts whatever its close reason, and another repository's blocker counts once a listed human closed it there (a merge there, or another repository's pull request blocker, never counts). + - A listed human's open pull request for an issue counts as work running on it, so work-unblock does not re-fire or relabel it. + - The triage sweep re-dispatches intake for any issue with no `status:` label and no `agent-ready` or person's hold, whatever comments intake left (an issue the lanes App opened included), and for a born-triaged issue in `status: ready` that nothing admitted. After two dispatches in one triage cycle (a work-unblock hand-back starts a new one) it labels the issue `needs-triage` and says so in its own comment on the issue, instead of filing a new issue, and later passes skip that issue unread while it carries `needs-triage`. + - Admission on a blocker's close takes the issues it would label oldest opened first (owner Q95) (`.github/scripts/work-unblock/label-unblocked.mjs`, `.github/scripts/maintenance-audit-lane-runs/triage-sweep.mjs`). diff --git a/.github/scripts/maintenance-audit-lane-runs/triage-sweep.mjs b/.github/scripts/maintenance-audit-lane-runs/triage-sweep.mjs index b48c5c4d644..890aeaa2905 100644 --- a/.github/scripts/maintenance-audit-lane-runs/triage-sweep.mjs +++ b/.github/scripts/maintenance-audit-lane-runs/triage-sweep.mjs @@ -1,14 +1,31 @@ -// The hourly triage sweep: finds open issues intake triage never reached and +// The hourly triage sweep: finds open issues no intake verdict holds and // dispatches intake-triage.yml for them, with the job's own token only. An -// issue qualifies when it has no intake comment and no triage or status -// label, is no pull request, was not born triaged, is over an hour old, and -// its author is a listed human or the lanes App, as the intake lane admits on -// open. The needs-triage floor label is no triage label: it lands on open -// whether or not intake runs, so an issue whose intake run failed still -// qualifies. github-actions[bot] issues are left out: the lane sweep's can -// quote fork-controlled log lines. Per issue, one comment holds the runs -// dispatched; after 2 that left it untriaged the sweep files one needs-triage -// issue and labels the original needs-triage. No model. +// issue qualifies when it is no pull request, is over an hour old, its author +// is a listed human or the lanes App (as the intake lane admits on open), and +// either: +// +// - it has no `status:` label and no agent-ready, needs-human or needs-spec, +// whatever comments intake left: a triage that posted no comment or two, a +// verdict apply-verdict could not write (an issue the lanes App opened, +// whose --check refuses the App as actor while a github-actions[bot] +// dispatch passes), or an issue work-unblock handed back after its lane PR +// ended; or +// - /work-items:decompose published it born triaged in `status: ready`, with +// no agent-ready, admission-deferred or hold and no open blocker: nothing +// ran admission on it, and intake's dispatch runs it (a dispatch skips the +// born-triaged gate). +// +// The needs-triage floor label is no triage label: it lands on open whether +// or not intake runs. github-actions[bot] issues are left out: the lane +// sweep's can quote fork-controlled log lines. Per issue, one comment holds the runs +// dispatched; after 2 that left it untriaged the sweep labels it needs-triage +// and rewrites that comment to hand it to a maintainer, listing the runs. It +// files no issue. No model. The count is per triage cycle: a work-unblock +// hand-back comment the lanes App posted after the state comment's last edit +// starts a new cycle with no runs, in the same comment. An issue still +// carrying needs-triage whose own state comment hands it off is skipped +// without a REST read, found by one GraphQL search that returns the hits' +// comments, so hand-offs cannot use up the call budget. // // Accepted exposure: intake reads an issue's comments, and anyone can comment // in the hour before the sweep dispatches. Intake treats them as untrusted @@ -21,20 +38,38 @@ import { BORN_TRIAGED_MARKER, humanIds } from "../../actions/check-born-triaged/ import { createBudget } from "./collect.mjs"; export const MAX_DISPATCHES = 5; -const MAX_FILED = 5; +const MAX_HANDED = 5; const MAX_CHECKED = 20; const MAX_ISSUE_PAGES = 15; const COMMENT_PAGES = 3; const ATTEMPTS = 2; const MIN_AGE_MS = 3_600_000; const BOT = "github-actions[bot]"; -const INTAKE_MARKER = ""; -// `filed` holds the filed issue's number, or FILING while the filing is under way. +// `filed` is HANDED once the comment hands the issue to a maintainer. An older +// sweep's record holds the number of the issue it filed, or FILING while that +// filing was under way; both stop the sweep too. export const FILING = "?"; -const STATE = /^/; +export const HANDED = "handed"; +const STATE = /^/; +// work-unblock's comment when it hands an issue back to triage after its lane +// PR merged with Refs: or closed unmerged (label-unblocked.mjs handedMarker). +const HAND_BACK = /^/; +// The visible text of the hand-off comment, which the search matches. +const HANDED_TEXT = "so the sweep no longer dispatches it"; const FLOOR = "needs-triage"; -// Labels intake triage or a person applies once an issue is triaged. -const TRIAGED = /^(needs-human|needs-spec|agent-ready)$|^(status|priority|work-class): /; +// Labels a verdict or a person leaves: an issue with one is triaged. +const TRIAGED = /^(needs-human|needs-spec|agent-ready)$|^status: /; +// What keeps a born-triaged `status: ready` issue out of admission on purpose. +const ADMISSION_HOLDS = new Set(["agent-ready", "admission-deferred", "needs-human", "needs-owner-decision", "status: needs-decision", "status: needs-info", "work-class: untrusted-provenance"]); + +const names = (i) => (i.labels ?? []).map((l) => String(l.name ?? "").toLowerCase()); +const bornReady = (i) => + String(i.body ?? "") + .trimEnd() + .endsWith(BORN_TRIAGED_MARKER) && + names(i).includes("status: ready") && + !names(i).some((n) => ADMISSION_HOLDS.has(n)) && + !(i.issue_dependencies_summary?.blocked_by > 0); export function selectCandidates({ issues, now, authorIds }) { return issues @@ -42,36 +77,47 @@ export function selectCandidates({ issues, now, authorIds }) { (i) => !i.pull_request && authorIds.has(String(i.user?.id)) && - !(i.labels ?? []).some((l) => TRIAGED.test(l.name ?? "")) && - !String(i.body ?? "") - .trimEnd() - .endsWith(BORN_TRIAGED_MARKER) && + (!names(i).some((n) => TRIAGED.test(n)) || bornReady(i)) && now - new Date(i.created_at) >= MIN_AGE_MS, ) .sort((a, b) => new Date(a.created_at) - new Date(b.created_at) || a.number - b.number); } -// The intake lane's own lookup for its earlier comment. -export const hasIntakeComment = (comments) => - comments.some((c) => c.user?.login === BOT && String(c.body ?? "").startsWith(INTAKE_MARKER)); - -export function readState(comments) { +// `appId` is the lanes App's account id: only its hand-back starts a new +// cycle, so no one else can reset the dispatch count. +export function readState(comments, appId = null) { + const handBack = Math.max( + ...comments + .filter((c) => appId !== null && String(c.user?.id) === String(appId) && HAND_BACK.test(String(c.body ?? ""))) + .map((c) => Date.parse(c.created_at)) + .filter(Number.isFinite), + ); for (const c of comments) { const m = c.user?.login === BOT ? STATE.exec(String(c.body ?? "")) : null; if (m) { + if (handBack > Date.parse(c.updated_at ?? c.created_at)) { + return { commentId: c.id, runs: [], filed: null }; + } return { commentId: c.id, runs: m[1] ? m[1].split(",").map(Number) : [], - filed: m[2] === FILING ? FILING : m[2] ? Number(m[2]) : null, + filed: m[2] === FILING || m[2] === HANDED ? m[2] : m[2] ? Number(m[2]) : null, }; } } return { commentId: null, runs: [], filed: null }; } -export const renderState = ({ runs, filed, runUrl }) => +// `details` lists each run as {id, conclusion}, for the hand-off. +export const renderState = ({ runs, filed, runUrl, repoUrl, details = [] }) => `\n` + - (filed === FILING + (filed === HANDED + ? [ + `Intake triage did not triage this issue after ${runs.length} dispatches, ${HANDED_TEXT} and labeled it needs-triage for a maintainer. Triage it by hand, and read the runs for why intake did not:`, + "", + ...details.map((r) => `- ${repoUrl}/actions/runs/${r.id} (${r.conclusion ?? "unknown"})`), + ].join("\n") + : filed === FILING ? `Intake triage did not triage this issue after ${runs.length} dispatches; the sweep labeled it needs-triage for a maintainer.` : filed ? `Intake triage did not triage this issue after ${runs.length} dispatches; #${filed} hands it to a maintainer.` @@ -81,26 +127,24 @@ export function decide({ state, latest }) { if (state.filed) return "stop"; if (state.runs.length === 0) return "dispatch"; if (latest?.status !== "completed") return "wait"; - return state.runs.length >= ATTEMPTS ? "file" : "dispatch"; + return state.runs.length >= ATTEMPTS ? "hand" : "dispatch"; } const FILED_TITLE = /^Intake triage left #([1-9][0-9]*) untriaged after /; const SEARCH_PAGES = 10; -// The issues the sweep already filed a hand-off for, read from one search of -// its own hand-off issues, open or closed, so their originals cost no comment -// reads. Only a title the bot wrote counts. A failed or incomplete search -// excludes nothing: those issues are then read and skipped by their state. -async function handedOff(call, repo) { - const q = encodeURIComponent(`repo:${repo} is:issue author:app/github-actions in:title "Intake triage left"`); +// The numbers `pick` takes from one search's items. A failed or incomplete +// search excludes nothing: those issues are then read and skipped by their state. +async function search(call, query, pick) { + const q = encodeURIComponent(query); const numbers = new Set(); try { for (let page = 1; page <= SEARCH_PAGES; page += 1) { const found = await call("GET", `/search/issues?q=${q}&per_page=100&page=${page}`); if (found?.incomplete_results !== false) return new Set(); for (const item of found.items ?? []) { - const m = item.user?.login === BOT ? FILED_TITLE.exec(String(item.title ?? "")) : null; - if (m) numbers.add(Number(m[1])); + const number = pick(item); + if (number) numbers.add(number); } if ((found.items ?? []).length < 100) break; } @@ -111,20 +155,63 @@ async function handedOff(call, repo) { return numbers; } -export const renderFiledIssue = ({ number, runs, repoUrl }) => ({ - title: `Intake triage left #${number} untriaged after ${runs.length} dispatches`, - labels: ["needs-triage"], - body: [ - `The hourly triage sweep dispatched intake triage for #${number} ${runs.length} times, and the issue still has no intake comment. The sweep no longer dispatches it.`, - "", - ...runs.map((r) => `- ${repoUrl}/actions/runs/${r.id} (${r.conclusion ?? "unknown"})`), - "", - "Triage the issue by hand, and read the runs for why intake did not.", - ].join("\n"), -}); +// The issues this sweep handed off in a comment, from one GraphQL search per +// 50 issues that also returns each hit's first 100 comments, so a hit costs no +// REST read. The search only finds issues where github-actions commented and +// some comment, by anyone, holds the hand-off text, so a hit counts only when +// the bot's own state comment reads filed=handed and no Bot's work-unblock +// hand-back is newer than it; anything else is read and judged as usual. A +// failed search excludes nothing. +const HANDED_QUERY = `query($q: String!, $after: String) { + search(query: $q, type: ISSUE, first: 50, after: $after) { + pageInfo { hasNextPage endCursor } + nodes { ... on Issue { number comments(first: 100) { nodes { author { __typename login } body createdAt updatedAt } } } } + } +}`; +const isActionsBot = (author) => author?.__typename === "Bot" && author.login === "github-actions"; + +export function handedInComments(comments) { + const state = comments.find((c) => isActionsBot(c.author) && STATE.test(String(c.body ?? ""))); + if (STATE.exec(String(state?.body ?? ""))?.[2] !== HANDED) return false; + const at = Date.parse(state.updatedAt ?? state.createdAt); + return !comments.some((c) => c.author?.__typename === "Bot" && HAND_BACK.test(String(c.body ?? "")) && !(Date.parse(c.createdAt) <= at)); +} + +async function handedInSweepComments(call, repo) { + const numbers = new Set(); + const q = `repo:${repo} is:issue is:open commenter:app/github-actions in:comments "${HANDED_TEXT}"`; + let after = null; + try { + for (let page = 1; page <= SEARCH_PAGES; page += 1) { + const answer = await call("POST", "/graphql", { query: HANDED_QUERY, variables: { q, after } }); + const found = answer?.data?.search; + if (!found || answer.errors) return new Set(); + for (const node of found.nodes ?? []) { + if (Number.isInteger(node?.number) && handedInComments(node.comments?.nodes ?? [])) numbers.add(node.number); + } + if (!found.pageInfo?.hasNextPage) break; + after = found.pageInfo.endCursor; + } + } catch (error) { + if (/call budget/.test(error.message)) throw error; + return new Set(); + } + return numbers; +} + +// The issues handed to a maintainer, so their comments cost no reads: those an +// older sweep filed a hand-off issue for (only a title the bot wrote counts), +// and those whose own state comment hands them off (handedInSweepComments). +// The caller skips them only while they carry needs-triage. +async function handedOff(call, repo) { + const filed = await search(call, `repo:${repo} is:issue author:app/github-actions in:title "Intake triage left"`, (item) => + item.user?.login === BOT ? Number(FILED_TITLE.exec(String(item.title ?? ""))?.[1] ?? 0) : 0, + ); + return new Set([...filed, ...(await handedInSweepComments(call, repo))]); +} // One pass. `call` returns null for a GET that 404s. -export async function runSweep({ call, remaining = () => Infinity, repo, serverUrl, now, authorIds }) { +export async function runSweep({ call, remaining = () => Infinity, repo, serverUrl, now, authorIds, appId = null }) { const repoUrl = `${serverUrl}/${repo}`; const issues = []; for (let page = 1; page <= MAX_ISSUE_PAGES; page += 1) { @@ -132,19 +219,18 @@ export async function runSweep({ call, remaining = () => Infinity, repo, serverU issues.push(...batch); if (batch.length < 100) break; } - const result = { candidates: 0, dispatched: [], filed: [], handedOff: [], waiting: [], failed: [], truncated: null }; + const result = { candidates: 0, dispatched: [], handed: [], handedOff: [], waiting: [], failed: [], truncated: null }; const selected = selectCandidates({ issues, now, authorIds }); const filed = selected.length > 0 ? await handedOff(call, repo) : new Set(); - const candidates = selected.filter((i) => !filed.has(i.number)); + const candidates = selected.filter((i) => !(filed.has(i.number) && names(i).includes(FLOOR))); result.candidates = candidates.length; const handOff = (number) => call("POST", `/repos/${repo}/issues/${number}/labels`, { labels: [FLOOR] }); - // Issues intake already commented on, and ones the sweep already handed - // off, cost their reads and do not count toward MAX_CHECKED, so they cannot - // starve the issues behind them. + // Issues the sweep already handed off cost their reads and do not count + // toward MAX_CHECKED, so they cannot starve the issues behind them. let checked = 0; for (const { number, labels } of candidates) { if (checked >= MAX_CHECKED) break; - if (result.dispatched.length >= MAX_DISPATCHES && result.filed.length >= MAX_FILED) break; + if (result.dispatched.length >= MAX_DISPATCHES && result.handed.length >= MAX_HANDED) break; try { const comments = []; let full = false; @@ -154,7 +240,6 @@ export async function runSweep({ call, remaining = () => Infinity, repo, serverU full = batch.length === 100; if (!full) break; } - if (hasIntakeComment(comments)) continue; // Past the pages read, the state comment may be hidden: a person // decides, so the label goes on once. if (full) { @@ -164,8 +249,8 @@ export async function runSweep({ call, remaining = () => Infinity, repo, serverU result.handedOff.push(number); continue; } - const state = readState(comments); - // Filed, or a filing under way: the needs-triage label hands it to a person. + const state = readState(comments, appId); + // Handed to a maintainer already: the needs-triage label is on it. if (state.filed) continue; checked += 1; const latest = state.runs.length > 0 ? await call("GET", `/repos/${repo}/actions/runs/${state.runs.at(-1)}`) : null; @@ -173,9 +258,9 @@ export async function runSweep({ call, remaining = () => Infinity, repo, serverU let action = decide({ state, latest: state.runs.length > 0 && latest === null ? { status: "completed" } : latest }); if (action === "wait") result.waiting.push(number); if (action === "dispatch" && result.dispatched.length >= MAX_DISPATCHES) action = "stop"; - if (action === "file" && result.filed.length >= MAX_FILED) action = "stop"; - // Never start a run the budget left cannot record, or a filing it cannot finish. - if ((action === "dispatch" && remaining() < 2) || (action === "file" && remaining() < state.runs.length + 3)) { + if (action === "hand" && result.handed.length >= MAX_HANDED) action = "stop"; + // Never start a run the budget left cannot record, or a hand-off it cannot finish. + if ((action === "dispatch" && remaining() < 2) || (action === "hand" && remaining() < state.runs.length + 1)) { result.truncated = `stopped at #${number}: too little call budget left`; break; } @@ -197,20 +282,17 @@ export async function runSweep({ call, remaining = () => Infinity, repo, serverU runUrl: `${repoUrl}/actions/runs/${id}`, }); } - if (action === "file") { + if (action === "hand") { const runs = []; for (const id of state.runs) { const run = id === state.runs.at(-1) ? latest : await call("GET", `/repos/${repo}/actions/runs/${id}`); runs.push({ id, conclusion: run?.conclusion ?? null }); } - // The label and the in-progress record go first: the record stops - // later passes, so a write that fails after it can never file a second - // issue, and the label hands the original to a person either way. + // The label first, then the record that stops later passes: a failed + // record leaves the issue for the next pass, which labels it again. await handOff(number); - await writeState(call, repo, number, state, { runs: state.runs, filed: FILING }); - const filed = await call("POST", `/repos/${repo}/issues`, renderFiledIssue({ number, runs, repoUrl })); - result.filed.push(filed.number); - await writeState(call, repo, number, state, { runs: state.runs, filed: filed.number }); + await writeState(call, repo, number, state, { runs: state.runs, filed: HANDED, repoUrl, details: runs }); + result.handed.push(number); } } catch (error) { if (/call budget/.test(error.message)) { @@ -258,19 +340,20 @@ async function main() { serverUrl: env.GITHUB_SERVER_URL, now: new Date(), authorIds, + appId: /^[1-9][0-9]*$/.test(env.LANES_APP_ID ?? "") ? env.LANES_APP_ID : null, }); const numbers = (xs) => xs.map((n) => `#${n}`).join(", ") || "none"; const lines = [ "### Triage sweep", "", - `Candidates: ${result.candidates}. Dispatched: ${numbers(result.dispatched)}. Filed: ${numbers(result.filed)}. Handed off for too many comments: ${numbers(result.handedOff)}. Waiting on a run: ${numbers(result.waiting)}. Calls: ${budget.used}.`, + `Candidates: ${result.candidates}. Dispatched: ${numbers(result.dispatched)}. Handed to a maintainer after ${ATTEMPTS} dispatches: ${numbers(result.handed)}. Handed off for too many comments: ${numbers(result.handedOff)}. Waiting on a run: ${numbers(result.waiting)}. Calls: ${budget.used}.`, "", ...(result.truncated ? [`- ${result.truncated}`] : []), ...result.failed.map((f) => `- failed #${f.number}: ${f.error}`), ]; appendFileSync(env.GITHUB_STEP_SUMMARY, `${lines.join("\n")}\n`); console.log( - `triage-sweep: candidates ${result.candidates}, dispatched ${result.dispatched.length}, filed ${result.filed.length}, waiting ${result.waiting.length}, failed ${result.failed.length}, calls ${budget.used}`, + `triage-sweep: candidates ${result.candidates}, dispatched ${result.dispatched.length}, handed ${result.handed.length}, waiting ${result.waiting.length}, failed ${result.failed.length}, calls ${budget.used}`, ); if (result.failed.length > 0) { console.log(`::error::${result.failed.length} triage sweep issue(s) failed; see the step summary`); diff --git a/.github/scripts/maintenance-audit-lane-runs/triage-sweep.test.mjs b/.github/scripts/maintenance-audit-lane-runs/triage-sweep.test.mjs index 1d08e748478..b2b208e5829 100644 --- a/.github/scripts/maintenance-audit-lane-runs/triage-sweep.test.mjs +++ b/.github/scripts/maintenance-audit-lane-runs/triage-sweep.test.mjs @@ -1,20 +1,22 @@ // The hourly triage sweep's rules, from the owner-approved design: an open -// issue qualifies when it has no intake-triage comment and no triage or -// status label (the needs-triage floor label is not one), is not a pull -// request, was not born triaged, and is over an hour old; its author must be -// one the intake lane admits on open. Each pass dispatches at most 5, and -// after 2 dispatches that left the issue untriaged the sweep files one -// needs-triage issue and stops dispatching that issue. +// issue qualifies when it is not a pull request, is over an hour old, its +// author is one the intake lane admits on open, and it has no `status:` label +// and no agent-ready, needs-human or needs-spec (the needs-triage floor label +// is not one), whatever comments intake left (owner 2026-10-24, rows S2 and +// S3); or it was born triaged in `status: ready` with nothing admitting it +// and nothing holding it (row S1). Each pass dispatches at most 5, and +// after 2 dispatches that left the issue untriaged the sweep labels it +// needs-triage, says so in its comment on the issue, and stops dispatching it. +// Owner rule 2026-10-24: no new issues; comment on the original instead. import assert from "node:assert/strict"; import { test } from "node:test"; import { decide, FILING, - hasIntakeComment, + HANDED, MAX_DISPATCHES, readState, - renderFiledIssue, renderState, runSweep, selectCandidates, @@ -38,8 +40,9 @@ const APP = 337595936; const authors = new Set([String(HUMAN), String(APP)]); // The needs-triage floor label lands on open whether or not intake runs, so -// it does not mark an issue triaged: the missing intake comment decides. -test("a candidate has no triage or status label, is no PR, not born triaged, over an hour old, by an admitted author", () => { +// it does not mark an issue triaged. Priority and work-class labels are no +// verdict either: only a status label, agent-ready or a person's hold is. +test("a candidate has no status label, agent-ready or hold, is no PR, over an hour old, by an admitted author", () => { const issues = [ issue(1), issue(2, { labels: [{ name: "needs-triage" }] }), @@ -56,29 +59,41 @@ test("a candidate has no triage or status label, is no PR, not born triaged, ove issue(13, { labels: [{ name: "question" }, { name: "dependencies" }] }), issue(14, { user: { id: APP }, created_at: "2026-10-01T00:00:00Z" }), issue(15, { user: { id: BOT.id } }), + issue(16, { labels: [{ name: "status: ready" }] }), ]; assert.deepEqual( selectCandidates({ issues, now: NOW, authorIds: authors }).map((i) => i.number), - [14, 1, 2, 13], + [14, 1, 2, 6, 7, 10, 13], ); }); -test("a quoted born-triaged marker mid-body does not exempt the issue", () => { - const issues = [issue(1, { body: "\nmore text" })]; +// /work-items:decompose publishes an issue already triaged, so intake never +// ran admission on it: one in status: ready with nothing admitting or holding +// it, and no open blocker (work-unblock labels those when the blocker closes), +// is dispatched so intake's admission takes it. +test("a born-triaged issue in status: ready with no agent-ready, deferral, hold or open blocker is a candidate", () => { + const born = (number, labels = [], over = {}) => + issue(number, { body: "Fix it.\n\n", labels: [{ name: "status: ready" }, ...labels.map((name) => ({ name }))], ...over }); + const issues = [ + born(1), + born(2, ["agent-ready"]), + born(3, ["admission-deferred"]), + born(4, ["needs-human"]), + born(5, ["work-class: untrusted-provenance"]), + born(6, [], { issue_dependencies_summary: { blocked_by: 1, total_blocked_by: 1, blocking: 0, total_blocking: 0 } }), + born(7, [], { issue_dependencies_summary: { blocked_by: 0, total_blocked_by: 1, blocking: 0, total_blocking: 0 } }), + born(8, ["priority: high"]), + issue(9, { labels: [{ name: "status: ready" }] }), + born(10, [], { user: { id: OUTSIDER } }), + // A quoted marker mid-body is not the publisher's last line. + born(11, [], { body: "\nmore text" }), + ]; assert.deepEqual( selectCandidates({ issues, now: NOW, authorIds: authors }).map((i) => i.number), - [1], + [1, 7, 8], ); }); -test("only the bot's comment that starts with the intake marker counts as triaged", () => { - const marker = "\nThanks for the report."; - assert.equal(hasIntakeComment([{ user: BOT, body: marker }]), true); - assert.equal(hasIntakeComment([{ user: { login: "someone", id: 9 }, body: marker }]), false); - assert.equal(hasIntakeComment([{ user: BOT, body: `quoted: ${marker}` }]), false); - assert.equal(hasIntakeComment([]), false); -}); - test("the sweep state round-trips and is read only from the bot's comment", () => { const body = renderState({ runs: [11, 22], filed: null, runUrl: "https://github.com/o/r/actions/runs/22" }); const comments = [ @@ -93,9 +108,10 @@ test("the sweep state round-trips and is read only from the bot's comment", () = }); assert.deepEqual(readState([]), { commentId: null, runs: [], filed: null }); assert.equal(readState([{ id: 4, user: BOT, body: renderState({ runs: [11, 22], filed: FILING }) }]).filed, FILING); + assert.equal(readState([{ id: 6, user: BOT, body: renderState({ runs: [11, 22], filed: HANDED, repoUrl: "u" }) }]).filed, HANDED); }); -test("decide: dispatch first, wait on an unfinished run, dispatch again after one, file after two, stop once filed", () => { +test("decide: dispatch first, wait on an unfinished run, dispatch again after one, hand off after two, stop once handed off", () => { const done = { status: "completed", conclusion: "failure" }; assert.equal(decide({ state: { runs: [], filed: null }, latest: null }), "dispatch"); assert.equal(decide({ state: { runs: [1], filed: null }, latest: { status: "in_progress" } }), "wait"); @@ -106,29 +122,31 @@ test("decide: dispatch first, wait on an unfinished run, dispatch again after on "dispatch", ); assert.equal(decide({ state: { runs: [1, 2], filed: null }, latest: { status: "in_progress" } }), "wait"); - assert.equal(decide({ state: { runs: [1, 2], filed: null }, latest: done }), "file"); + assert.equal(decide({ state: { runs: [1, 2], filed: null }, latest: done }), "hand"); + assert.equal(decide({ state: { runs: [1, 2], filed: HANDED }, latest: done }), "stop"); assert.equal(decide({ state: { runs: [1, 2], filed: 9 }, latest: done }), "stop"); assert.equal(decide({ state: { runs: [1, 2], filed: FILING }, latest: done }), "stop"); }); -test("the filed issue names the issue and every failed run, and carries needs-triage", () => { - const filed = renderFiledIssue({ - number: 42, - runs: [ +test("the hand-off comment names every dispatched run and asks a maintainer to triage the issue", () => { + const body = renderState({ + runs: [11, 22], + filed: HANDED, + repoUrl: "https://github.com/o/r", + details: [ { id: 11, conclusion: "failure" }, { id: 22, conclusion: "success" }, ], - repoUrl: "https://github.com/o/r", }); - assert.equal(filed.title, "Intake triage left #42 untriaged after 2 dispatches"); - assert.deepEqual(filed.labels, ["needs-triage"]); - assert.match(filed.body, /#42/); - assert.ok(filed.body.includes("https://github.com/o/r/actions/runs/11")); - assert.ok(filed.body.includes("https://github.com/o/r/actions/runs/22")); + assert.ok(body.startsWith("\n")); + assert.ok(body.includes("after 2 dispatches")); + assert.ok(body.includes("- https://github.com/o/r/actions/runs/11 (failure)")); + assert.ok(body.includes("- https://github.com/o/r/actions/runs/22 (success)")); + assert.ok(body.includes("Triage it by hand")); }); // A fake GitHub holding issues, comments and runs, recording every write. -function fakeGitHub({ issues, comments = {}, runs = {}, failPatch = () => false, filedIssues = [] }) { +function fakeGitHub({ issues, comments = {}, runs = {}, failPatch = () => false, filedIssues = [], handedIssues = [], graphqlError = false }) { const writes = []; let nextRun = 900; let nextIssue = 5000; @@ -136,8 +154,30 @@ function fakeGitHub({ issues, comments = {}, runs = {}, failPatch = () => false, const call = async (method, path, body) => { let m; if (method === "GET" && (m = /^\/search\/issues\?q=([^&]+)&per_page=100&page=(\d+)$/.exec(path))) { - assert.equal(decodeURIComponent(m[1]), 'repo:o/r is:issue author:app/github-actions in:title "Intake triage left"'); - return { incomplete_results: false, items: filedIssues.slice((Number(m[2]) - 1) * 100, Number(m[2]) * 100) }; + const found = { + 'repo:o/r is:issue author:app/github-actions in:title "Intake triage left"': filedIssues, + 'repo:o/r is:issue is:open commenter:app/github-actions in:comments "so the sweep no longer dispatches it"': handedIssues, + }[decodeURIComponent(m[1])]; + assert.ok(found, decodeURIComponent(m[1])); + return { incomplete_results: false, items: found.slice((Number(m[2]) - 1) * 100, Number(m[2]) * 100) }; + } + // The hand-off search: GitHub matches the phrase in any comment, so each + // hit comes with its comments as GraphQL answers them. + if (method === "POST" && path === "/graphql") { + if (graphqlError) return { errors: [{ message: "Something went wrong" }] }; + assert.equal(body.variables.q, 'repo:o/r is:issue is:open commenter:app/github-actions in:comments "so the sweep no longer dispatches it"'); + const start = body.variables.after === null ? 0 : Number(body.variables.after); + // GraphQL names an App's account `Bot` and drops the `[bot]` suffix. + const author = (user) => + /\[bot\]$/.test(user?.login ?? "") ? { __typename: "Bot", login: user.login.replace(/\[bot\]$/, "") } : { __typename: "User", login: user?.login }; + const nodes = handedIssues.slice(start, start + 50).map(({ number }) => ({ + number, + comments: { + nodes: (comments[number] ?? []).slice(0, 100).map((c) => ({ author: author(c.user), body: c.body, createdAt: c.created_at, updatedAt: c.updated_at })), + }, + })); + const next = start + 50 < handedIssues.length; + return { data: { search: { pageInfo: { hasNextPage: next, endCursor: next ? String(start + 50) : null }, nodes } } }; } if (method === "GET" && (m = /^\/repos\/o\/r\/issues\?state=open&per_page=100&page=(\d+)$/.exec(path))) { return issues.slice((Number(m[1]) - 1) * 100, Number(m[1]) * 100); @@ -170,7 +210,7 @@ function fakeGitHub({ issues, comments = {}, runs = {}, failPatch = () => false, } const sweep = (gh) => - runSweep({ call: gh.call, repo: "o/r", serverUrl: "https://github.com", now: NOW, authorIds: authors }); + runSweep({ call: gh.call, repo: "o/r", serverUrl: "https://github.com", now: NOW, authorIds: authors, appId: String(APP) }); test("a pass dispatches at most 5 issues, oldest first, and records each run on the issue", async () => { // Listed newest first, as the issues API returns them. @@ -191,13 +231,26 @@ test("a pass dispatches at most 5 issues, oldest first, and records each run on assert.deepEqual(result.dispatched, [1, 2, 3, 4, 5]); }); -test("an issue with an intake comment is left alone", async () => { +// Row S3: an intake comment with no verdict label left the issue untriaged. +// Row S2: the lanes App opened the issue, so apply-verdict's --check refused +// the App as actor; a dispatch by this job's token passes it. +test("an issue with an intake comment but no status label is dispatched again, and so is one the lanes App opened", async () => { const gh = fakeGitHub({ - issues: [issue(1)], + issues: [issue(1), issue(2, { user: { id: APP } })], comments: { 1: [{ id: 5, user: BOT, body: "\nok" }] }, }); - await sweep(gh); + const result = await sweep(gh); + assert.deepEqual(result.dispatched, [1, 2]); +}); + +test("an issue with a status label is left alone, whatever its comments", async () => { + const gh = fakeGitHub({ + issues: [issue(1, { labels: [{ name: "status: needs-decision" }] })], + comments: { 1: [{ id: 5, user: BOT, body: "\nok" }] }, + }); + const result = await sweep(gh); assert.deepEqual(gh.writes, []); + assert.equal(result.candidates, 0); }); test("a second dispatch edits the same state comment", async () => { @@ -217,7 +270,7 @@ test("a second dispatch edits the same state comment", async () => { assert.deepEqual(readState([{ id: 5, user: BOT, body: gh.writes[1].body.body }]).runs, [11, 901]); }); -test("after 2 untriaged dispatches the sweep files once, then never dispatches or files again", async () => { +test("after 2 untriaged dispatches the sweep labels the issue and hands it off in its own comment, files no issue, and stops", async () => { const runs = { 11: { status: "completed", conclusion: "failure" }, 22: { status: "completed", conclusion: "success" }, @@ -233,17 +286,13 @@ test("after 2 untriaged dispatches the sweep files once, then never dispatches o [ ["POST", "/repos/o/r/issues/1/labels"], ["PATCH", "/repos/o/r/issues/comments/5"], - ["POST", "/repos/o/r/issues"], - ["PATCH", "/repos/o/r/issues/comments/5"], ], ); assert.deepEqual(first.writes[0].body, { labels: ["needs-triage"] }); - // The filing is recorded before the issue is filed, so a later pass stops. - assert.equal(readState([{ id: 5, user: BOT, body: first.writes[1].body.body }]).filed, FILING); - assert.deepEqual(first.writes[2].body.labels, ["needs-triage"]); - assert.deepEqual(result.filed, [5001]); - const marked = first.writes[3].body.body; - assert.equal(readState([{ id: 5, user: BOT, body: marked }]).filed, 5001); + const marked = first.writes[1].body.body; + assert.equal(readState([{ id: 5, user: BOT, body: marked }]).filed, HANDED); + assert.ok(marked.includes("- https://github.com/o/r/actions/runs/11 (failure)")); + assert.deepEqual(result.handed, [1]); const second = fakeGitHub({ issues: [issue(1)], @@ -280,14 +329,14 @@ test("an issue with more comments than the sweep reads goes to a maintainer, und test("a pass stops dispatching when the budget left cannot record the run", async () => { const gh = fakeGitHub({ issues: [issue(1), issue(2, { created_at: "2026-10-18T09:30:00Z" })] }); - let left = 7; + let left = 8; const call = async (...args) => { - if (left === 0) throw new Error("call budget of 7 reached"); + if (left === 0) throw new Error("call budget of 8 reached"); left -= 1; return gh.call(...args); }; - // issues page 1, the hand-off search, comments of #1, dispatch, state - // write: 5 calls; #2's comments leave 1, too few for a dispatch and its + // issues page 1, the two hand-off searches, comments of #1, dispatch, state + // write: 6 calls; #2's comments leave 1, too few for a dispatch and its // state write. const result = await runSweep({ call, @@ -302,26 +351,21 @@ test("a pass stops dispatching when the budget left cannot record the run", asyn assert.match(result.truncated, /budget/); }); -// The needs-triage label no longer takes the original out of later passes, so -// the in-progress record is what stops a second filing. -test("a filing whose state write fails is not filed again on the next pass", async () => { +test("a hand-off whose record write fails is retried on the next pass, and no pass files an issue", async () => { const comments = { 1: [{ id: 5, user: BOT, body: renderState({ runs: [11, 22], filed: null, runUrl: "u" }) }] }; - const gh = fakeGitHub({ - issues: [issue(1)], - comments, - runs: { - 11: { status: "completed", conclusion: "failure" }, - 22: { status: "completed", conclusion: "failure" }, - }, - failPatch: (body) => /filed=[0-9]/.test(body.body), - }); - const first = await sweep(gh); + const runs = { + 11: { status: "completed", conclusion: "failure" }, + 22: { status: "completed", conclusion: "failure" }, + }; + const failing = fakeGitHub({ issues: [issue(1)], comments, runs, failPatch: (body) => /filed=handed/.test(body.body) }); + const first = await sweep(failing); assert.equal(first.failed.length, 1); - // The pass persisted the in-progress record before it failed. - const recorded = gh.writes.find((w) => w.method === "PATCH").body.body; - comments[1] = [{ id: 5, user: BOT, body: recorded }]; - await sweep(gh); - assert.equal(gh.writes.filter((w) => w.method === "POST" && w.path === "/repos/o/r/issues").length, 1); + const retry = fakeGitHub({ issues: [issue(1)], comments, runs }); + const second = await sweep(retry); + assert.deepEqual(second.handed, [1]); + for (const gh of [failing, retry]) { + assert.ok(!gh.writes.some((w) => w.method === "POST" && w.path === "/repos/o/r/issues")); + } }); test("issues the sweep already filed do not use up the per-pass check limit", async () => { @@ -339,20 +383,20 @@ test("issues the sweep already filed do not use up the per-pass check limit", as }); // Codex P2 on #9303: with needs-triage no longer excluding them, the issues -// the sweep already handed off would spend the call budget on their comments -// every pass. One search for the sweep's own hand-off issues skips them unread. -test("issues the sweep filed a hand-off for are skipped without reading their comments", async () => { +// an older sweep filed a hand-off issue for would spend the call budget on +// their comments every pass. One search for those hand-off issues skips them unread. +test("issues an older sweep filed a hand-off for are skipped without reading their comments", async () => { const handed = Array.from({ length: 118 }, (_, i) => issue(i + 1, { labels: [{ name: "needs-triage" }], created_at: "2026-10-01T00:00:00Z" }), ); const filedIssues = [ ...handed.map((i) => ({ number: 6000 + i.number, - title: renderFiledIssue({ number: i.number, runs: [{}, {}], repoUrl: "u" }).title, + title: `Intake triage left #${i.number} untriaged after 2 dispatches`, user: BOT, })), // The same title from anyone else excludes nothing. - { number: 7000, title: renderFiledIssue({ number: 119, runs: [{}, {}], repoUrl: "u" }).title, user: { login: "someone" } }, + { number: 7000, title: "Intake triage left #119 untriaged after 2 dispatches", user: { login: "someone" } }, ]; const gh = fakeGitHub({ issues: [...handed, issue(119, { labels: [{ name: "needs-triage" }] })], @@ -374,22 +418,164 @@ test("issues the sweep filed a hand-off for are skipped without reading their co assert.equal(reads.filter((p) => p.includes("/comments")).length, 1); }); -test("an issue past the comment pages that already carries needs-triage is not handed off again", async () => { - const flood = Array.from({ length: 300 }, (_, i) => ({ id: i, user: { login: "someone", id: 9 }, body: "spam" })); - const gh = fakeGitHub({ issues: [issue(1, { labels: [{ name: "needs-triage" }] })], comments: { 1: flood } }); +// Review threads on #9814 (claude-review and Codex P2): work-unblock hands an +// issue back to intake after a Refs: merge or a closed lane PR, so a lifetime +// count of 2 dispatches would cut that flow off. The lanes App's hand-back +// comment, newer than the state comment's last edit, starts a new cycle. +const stateAt = (runs, filed, at) => ({ + id: 5, + user: BOT, + body: renderState({ runs, filed, runUrl: "u", repoUrl: "https://github.com/o/r" }), + created_at: "2026-10-17T00:00:00Z", + updated_at: at, +}); +const handBack = (user, at) => ({ id: 6, user, body: "\nThe lanes App's pull request #40 merged with `Refs:`.", created_at: at }); +const triaged = { 11: { status: "completed", conclusion: "success" }, 22: { status: "completed", conclusion: "success" } }; +const LANES = { login: "melodic-automation-lanes[bot]", id: APP }; + +test("a lanes App hand-back newer than the state comment starts a new cycle of dispatches in the same comment", async () => { + for (const filed of [null, HANDED]) { + const gh = fakeGitHub({ + issues: [issue(1)], + comments: { 1: [stateAt([11, 22], filed, "2026-10-17T06:00:00Z"), handBack(LANES, "2026-10-18T08:00:00Z")] }, + runs: triaged, + }); + const result = await sweep(gh); + assert.deepEqual(result.dispatched, [1], String(filed)); + assert.deepEqual( + gh.writes.map((w) => [w.method, w.path]), + [ + ["POST", "/repos/o/r/actions/workflows/intake-triage.yml/dispatches"], + ["PATCH", "/repos/o/r/issues/comments/5"], + ], + String(filed), + ); + assert.deepEqual(readState([{ id: 5, user: BOT, body: gh.writes[1].body.body }]), { commentId: 5, runs: [901], filed: null }); + } +}); + +test("a hand-back older than the state comment's last edit, or posted by anyone but the lanes App, keeps the count", async () => { + for (const [name, back] of [ + ["older", handBack(LANES, "2026-10-17T05:00:00Z")], + ["not the App", handBack({ login: "someone", id: OUTSIDER }, "2026-10-18T08:00:00Z")], + ["a listed human", handBack({ login: "owner", id: HUMAN }, "2026-10-18T08:00:00Z")], + ]) { + const gh = fakeGitHub({ issues: [issue(1)], comments: { 1: [stateAt([11, 22], null, "2026-10-17T06:00:00Z"), back] }, runs: triaged }); + const result = await sweep(gh); + assert.deepEqual(result.dispatched, [], name); + assert.deepEqual(result.handed, [1], name); + } +}); + +// Codex P2 on #9814: hand-offs now live only in a comment, so each handed +// issue would cost a comment read every pass and could use up the 120-call +// budget before a fresh issue behind them. One search for the hand-off text +// skips those still carrying needs-triage unread. +test("issues this sweep handed off in a comment are skipped without reading their comments", async () => { + const handed = Array.from({ length: 118 }, (_, i) => + issue(i + 1, { labels: [{ name: "needs-triage" }], created_at: "2026-10-01T00:00:00Z" }), + ); + const marked = renderState({ runs: [1, 2], filed: HANDED, repoUrl: "https://github.com/o/r" }); + const gh = fakeGitHub({ + issues: [...handed, issue(119, { labels: [{ name: "needs-triage" }] })], + comments: Object.fromEntries(handed.map((i) => [i.number, [{ id: i.number, user: BOT, body: marked }]])), + handedIssues: handed.map((i) => ({ number: i.number })), + }); + const reads = []; + let left = 120; + const call = async (method, path, body) => { + if (left === 0) throw new Error("call budget of 120 reached"); + left -= 1; + if (method === "GET") reads.push(path); + return gh.call(method, path, body); + }; + const result = await runSweep({ call, remaining: () => left, repo: "o/r", serverUrl: "https://github.com", now: NOW, authorIds: authors, appId: String(APP) }); + assert.deepEqual(result.dispatched, [119]); + assert.equal(reads.filter((p) => p.includes("/comments")).length, 1); +}); + +test("a search hit without needs-triage is read, so a hand-back after its label came off starts a new cycle", async () => { + const gh = fakeGitHub({ + issues: [issue(1)], + comments: { 1: [stateAt([11, 22], HANDED, "2026-10-17T06:00:00Z"), handBack(LANES, "2026-10-18T08:00:00Z")] }, + runs: triaged, + handedIssues: [{ number: 1 }], + }); const result = await sweep(gh); - assert.deepEqual(gh.writes, []); - assert.deepEqual(result.handedOff, []); + assert.deepEqual(result.dispatched, [1]); }); -test("issues intake already commented on do not use up the per-pass check limit", async () => { - const commented = Array.from({ length: 20 }, (_, i) => issue(i + 1, { created_at: "2026-10-01T00:00:00Z" })); +// Security review on #9814: the search matches the hand-off text in anyone's +// comment, so a hit is skipped only on the bot's own filed=handed state +// comment, with no newer hand-back. Each needs-triage hit below is read and +// dispatched; the control, the bot's own hand-off, is skipped unread. +test("a search hit whose hand-off text is not the bot's own hand-off is read and dispatched", async () => { + const text = "Intake triage did not triage this issue after 2 dispatches, so the sweep no longer dispatches it."; + const floor = [{ name: "needs-triage" }]; + for (const [name, notes] of [ + ["someone else's comment", [{ id: 7, user: { login: "someone", id: OUTSIDER }, body: text }]], + ["a forged state comment", [{ id: 7, user: { login: "someone", id: OUTSIDER }, body: renderState({ runs: [1, 2], filed: HANDED, repoUrl: "u" }) }]], + ["the bot's state still dispatching", [stateAt([11], null, "2026-10-17T06:00:00Z"), { id: 7, user: { login: "someone", id: OUTSIDER }, body: text }]], + ]) { + const gh = fakeGitHub({ issues: [issue(1, { labels: floor })], comments: { 1: notes }, runs: triaged, handedIssues: [{ number: 1 }] }); + const result = await sweep(gh); + assert.deepEqual(result.dispatched, [1], name); + } + const own = fakeGitHub({ + issues: [issue(1, { labels: floor })], + comments: { 1: [stateAt([11, 22], HANDED, "2026-10-17T06:00:00Z")] }, + runs: triaged, + handedIssues: [{ number: 1 }], + }); + const reads = []; + const call = (method, path, body) => { + if (method === "GET") reads.push(path); + return own.call(method, path, body); + }; + const result = await runSweep({ call, repo: "o/r", serverUrl: "https://github.com", now: NOW, authorIds: authors, appId: String(APP) }); + assert.equal(result.candidates, 0); + assert.equal(reads.filter((p) => p.includes("/comments")).length, 0); + assert.deepEqual(own.writes, []); +}); + +// Review on #9814: work-unblock adds no needs-triage, so one left from an +// earlier hand-off can still be on an issue it hands back. The bot's own +// filed=handed state with a newer lanes App hand-back is read, and its new +// cycle dispatches. +test("a needs-triage search hit with the bot's hand-off and a newer lanes App hand-back is read and dispatched", async () => { const gh = fakeGitHub({ - issues: [...commented, issue(21)], - comments: Object.fromEntries( - commented.map((i) => [i.number, [{ id: i.number, user: BOT, body: "\nok" }]]), - ), + issues: [issue(1, { labels: [{ name: "needs-triage" }] })], + comments: { 1: [stateAt([11, 22], HANDED, "2026-10-17T06:00:00Z"), handBack(LANES, "2026-10-18T08:00:00Z")] }, + runs: triaged, + handedIssues: [{ number: 1 }], }); const result = await sweep(gh); - assert.deepEqual(result.dispatched, [21]); + assert.deepEqual(result.dispatched, [1]); +}); + +test("a hand-off search that answers with GraphQL errors skips nothing: the hit is read", async () => { + const gh = fakeGitHub({ + issues: [issue(1, { labels: [{ name: "needs-triage" }] })], + comments: { 1: [stateAt([11, 22], HANDED, "2026-10-17T06:00:00Z")] }, + runs: triaged, + handedIssues: [{ number: 1 }], + graphqlError: true, + }); + const reads = []; + const call = (method, path, body) => { + if (method === "GET") reads.push(path); + return gh.call(method, path, body); + }; + const result = await runSweep({ call, repo: "o/r", serverUrl: "https://github.com", now: NOW, authorIds: authors, appId: String(APP) }); + assert.equal(result.candidates, 1); + assert.equal(reads.filter((p) => p.includes("/comments")).length, 1); + assert.deepEqual(gh.writes, []); +}); + +test("an issue past the comment pages that already carries needs-triage is not handed off again", async () => { + const flood = Array.from({ length: 300 }, (_, i) => ({ id: i, user: { login: "someone", id: 9 }, body: "spam" })); + const gh = fakeGitHub({ issues: [issue(1, { labels: [{ name: "needs-triage" }] })], comments: { 1: flood } }); + const result = await sweep(gh); + assert.deepEqual(gh.writes, []); + assert.deepEqual(result.handedOff, []); }); diff --git a/.github/scripts/work-unblock/label-unblocked.mjs b/.github/scripts/work-unblock/label-unblocked.mjs index 855f8c885c1..d060564aa95 100755 --- a/.github/scripts/work-unblock/label-unblocked.mjs +++ b/.github/scripts/work-unblock/label-unblocked.mjs @@ -1,9 +1,11 @@ #!/usr/bin/env node // label-unblocked.mjs: when an issue closes, labels `agent-ready` each issue // it blocked that is now ready for the resolve-issue lane, which the label -// starts: open, every blocker closed as completed by a listed human or a -// merge (a pull request blocker: merged), no hold label, and not already -// agent-ready. Every fact is read from the API now, never from the event +// starts: open, every blocker closed, for any reason, by a listed human or a +// merge in this repository (a pull request blocker: merged here; another +// repository's blocker: closed there by a listed human), no hold label, and +// not already agent-ready. Issues it would label are taken oldest +// opened first (owner Q95). Every fact is read from the API now, never from the event // payload. No model. // // Each new agent-ready is paced: at or over the issue lane's queued cap, or @@ -30,11 +32,13 @@ // admission-deferred with a comment saying why. // // An agent-ready issue left with nothing running is stranded: no hold, no open -// lane pull request, no outcome marker since its newest agent-ready, and no -// work-resolve-issue run for that label, or only one that ended with no -// report, over STRANDED_HOURS ago. It is re-fired once per version of the -// lane workflow files with the re-fire record below; one already re-fired on -// those files gets one comment saying why and needs-human instead. Both share +// lane pull request or open pull request of a listed human's for it, no +// outcome marker since its newest agent-ready, and no work-resolve-issue run +// for that label, or only one that ended with no report, over STRANDED_HOURS +// ago. It is re-fired with the re-fire record below once per version of the +// lane workflow files, and after that on a backoff (STRANDED_HOURS doubling +// with each re-fire, at most BACKOFF_CAP_HOURS), recorded in one comment +// edited in place; it never gets needs-human. All share // limits.restarts-per-run. // // On `schedule` it sweeps instead: every issue closed in the last @@ -68,17 +72,17 @@ // step (it waited in its slot past a lane workflow change, so no model ran). // A run a newer agent-ready run replaced while it waited is never re-fired: // admit never ran in it. A rerun keeps its first event's workflow files, so only a -// fresh label event runs on main's. Each issue is re-fired at most once per -// version of the two lane workflow files on main, recorded in a marker comment -// posted before the label moves, so a run that keeps failing stops until a -// workflow change lands. +// fresh label event runs on main's. Each issue is re-fired once per version +// of the two lane workflow files on main with a marker comment posted before +// the label moves, and after that on the stranded backoff, so a run that +// keeps failing is retried less often but never handed to a person. // // A run that minted no lane token did no work and ran no model: the WIP cap // skipped its resolve-issue job, or its `Request the lane token` step failed // (GitHub's rate limit past the retry budget among the reasons). Such a run is // re-fired with the same record: a failed mint up to limits.limit-stops-per-issue -// times per version of the lane workflow files, a WIP cap skip without a -// per-issue bound. It waits limits.reset-clamp-min hours after the run ended, past any reset +// times per version of the lane workflow files and then on the stranded +// backoff, a WIP cap skip without a per-issue bound. It waits limits.reset-clamp-min hours after the run ended, past any reset // the broker passes on (its Retry-After is at most an hour), and only while // the issue lane's WIP cap check (check-wip-cap.mjs) does not pause it. It is no // limit stop, so it never counts toward handing the issue to a person. @@ -86,9 +90,9 @@ // When that label's run opened a pull request instead, the newest one the // lanes App opened from the issue's lane branch in this repository decides. // Merged with `Refs:` (the issue stays open with nothing to run) or closed -// unmerged, the App adds needs-triage and removes -// agent-ready, so triage decides what is left; a person adding agent-ready -// again re-runs it. Open, it waits: report-outcome put needs-human on the +// unmerged, the App removes `status: ready` and agent-ready, so the triage +// sweep (maintenance-audit-lane-runs triage-sweep.mjs) dispatches intake, +// which decides what is left and whose fresh `status: ready` re-admits it. Open, it waits: report-outcome put needs-human on the // issue of a Refs PR, and this lifts that hold once that PR merges or closes // unmerged, only while its refs-hold marker and the App's needs-human label // are the newest. Each hand-off also counts against limits.restarts-per-run. @@ -140,7 +144,6 @@ import { admissionFacts, decide, loadRules, NEEDS_DECISION, openPullsFor, READY, const LABEL = "agent-ready"; const HUMAN_LABEL = "needs-human"; -const TRIAGE_LABEL = "needs-triage"; const DEFERRED_LABEL = "admission-deferred"; // The lane's caller and the write runner: the broker refuses a run whose copy // of either differs from main's. @@ -175,7 +178,13 @@ const IN_FLIGHT = ["queued", "in_progress", "waiting", "pending", "requested"]; export const LOOKBACK_HOURS = 3; // How long an agent-ready issue may sit with no run working on it. export const STRANDED_HOURS = 3; -const STRANDED = /^/; +// The one comment per issue that says it keeps being re-fired on a backoff, +// edited in place on each re-fire; it reads as a re-fire record timed by its +// last edit. +const INFRA = /^/; +// The longest wait between backoff re-fires. +export const BACKOFF_CAP_HOURS = 24; +const backoffDue = (since, refires) => since + Math.min(STRANDED_HOURS * 2 ** refires, BACKOFF_CAP_HOURS) * HOUR_MS; // The REST version that documents issue-field-values. const FIELD_API = { "X-GitHub-Api-Version": "2026-03-10" }; const DIMENSIONS = ["size", "complexity", "uncertainty"]; @@ -200,17 +209,21 @@ const isLabel = (event, kind) => event.event === kind && String(event.label?.nam // A re-fire marker reads as outcome `refired` with its workflow key. const parseMarker = (body) => { - const refire = REFIRED.exec(String(body ?? "")); + const refire = REFIRED.exec(String(body ?? "")) ?? INFRA.exec(String(body ?? "")); return refire ? { outcome: "refired", key: refire[1] } : parseOutcomeMarker(body); }; // The lanes App's outcome and re-fire markers on an issue, oldest first, each -// with when it was posted. +// with when it was posted (the backoff comment: last edited). const appMarkers = (comments, bot) => comments .filter((comment) => comment.user?.login === bot) - .map((comment) => ({ ...parseMarker(comment.body), at: Date.parse(comment.created_at) })) - .filter((marker) => marker.outcome !== undefined && Number.isFinite(marker.at)); + .map((comment) => ({ + ...parseMarker(comment.body), + at: Date.parse(INFRA.test(String(comment.body ?? "")) ? (comment.updated_at ?? comment.created_at) : comment.created_at), + })) + .filter((marker) => marker.outcome !== undefined && Number.isFinite(marker.at)) + .sort((a, b) => a.at - b.at); // The App's markers after which its removal of agent-ready is a restart. const RESTARTS = new Set(["limited", "refired", "turn-cap", "funding"]); @@ -253,35 +266,37 @@ async function readiness({ github, repo, humans, closes, bot = DEFAULT_BOT, base if (lower.includes(LABEL)) { return `already ${LABEL}`; } - // A blocker closed as not planned or duplicate never did the work, so only - // a completed close counts; a pull request counts only once merged. Any - // issue author can close their own issue as completed, so a blocking issue - // also needs a trusted close (trustedClose), read fresh from the issue - // itself. A blocker in another repository cannot be read with this - // repository's token, so it never counts. + // A blocker counts once closed, for any reason, by a listed human or a + // merge in this repository; a pull request counts only once merged here. + // Anyone can close their own issue, so a blocking issue needs a trusted + // close (trustedClose), read fresh from the issue in its own repository. + // Another repository's blocker counts only by a listed human's close there, + // and a read that fails there leaves it blocking: people the trusted list + // does not cover merge in other repositories. const blockers = await paginate(github, `${base}/dependencies/blocked_by`); - const closedHere = (blocker) => - blocker.state === "closed" && String(blocker.repository_url ?? "").toLowerCase().endsWith(`/repos/${repo}`.toLowerCase()); const issues = []; let pending = 0; for (const blocker of blockers) { - if (!closedHere(blocker)) { + const where = /\/repos\/([\w.-]+\/[\w.-]+)$/.exec(String(blocker.repository_url ?? ""))?.[1]; + const here = where?.toLowerCase() === repo.toLowerCase(); + if (blocker.state !== "closed" || !where) { pending += 1; } else if (blocker.pull_request) { - pending += blocker.pull_request.merged_at ? 0 : 1; - } else if (blocker.state_reason !== "completed" || !NUMBER.test(String(blocker.number))) { + pending += blocker.pull_request.merged_at && here ? 0 : 1; + } else if (!NUMBER.test(String(blocker.number))) { pending += 1; } else { - issues.push(Number(blocker.number)); + issues.push({ where, here, number: Number(blocker.number) }); } } for (const blocker of pending === 0 ? issues : []) { - if (!(await trustedClose({ github, repo, number: blocker, humans, closes }))) { + const read = trustedClose({ github, repo, where: blocker.where, number: blocker.number, humans, closes }); + if (!(await (blocker.here ? read : read.catch(() => false)))) { pending += 1; } } if (pending > 0) { - return `${pending} blocker(s) not closed as completed by a listed human or a merge`; + return `${pending} blocker(s) not closed by a listed human or a merge`; } // Removing the label by hand stops the lane until a person adds it back, // or the App or a listed human marks the issue `status: ready` again. @@ -306,12 +321,20 @@ async function closedSince(github, repo, since) { } // One answer per issue per run: a swept close is also its dependents' -// blocker, and a blocker can block several dependents. -function trustedClose({ github, repo, number, humans, closes }) { - if (!closes.has(number)) { - closes.set(number, (async () => isTrustedClose(github, repo, await github("GET", `/repos/${repo}/issues/${number}`), humans))()); +// blocker, and a blocker can block several dependents. `where` is the +// blocker's repository: outside `repo`, only a listed human's close counts. +function trustedClose({ github, repo, where = repo, number, humans, closes }) { + const key = `${where.toLowerCase()}#${number}`; + if (!closes.has(key)) { + closes.set( + key, + (async () => { + const closed = await github("GET", `/repos/${where}/issues/${number}`); + return where.toLowerCase() === repo.toLowerCase() ? isTrustedClose(github, repo, closed, humans) : humans.has(closed?.closed_by?.id); + })(), + ); } - return closes.get(number); + return closes.get(key); } @@ -496,9 +519,10 @@ async function admitMarked({ github, repo, number, issue, events, humans, bot, a } // Labels each issue `closed` blocked that is ready, each at most once per run, -// within the gate's room. Returns how many reads or writes failed. +// within the gate's room, oldest opened first (owner Q95). Returns how many +// reads or writes failed. async function labelUnblocked({ github, repo, closed, sweep, humans, bot, gate }) { - const seen = new Set(); + const seen = new Map(); const closes = new Map(); let failed = 0; for (const source of closed) { @@ -521,21 +545,24 @@ async function labelUnblocked({ github, repo, closed, sweep, humans, bot, gate } console.log(`label-unblocked: skipped a blocked item outside this repository's issues`); continue; } - if (seen.has(number)) { - continue; + if (!seen.has(number)) { + seen.set(number, Date.parse(item.created_at)); } - seen.add(number); - try { - const { reason, deferred } = await refusal({ github, repo, number, humans, closes, bot }); - if (reason !== null) { - console.log(`label-unblocked: #${number} not labeled: ${reason}`); - continue; - } - await admit({ github, repo, number, gate, deferred }); - } catch (error) { - failed += 1; - reportError(number, error); + } + } + // An unreadable open time sorts last. + const opened = (number) => (Number.isFinite(seen.get(number)) ? seen.get(number) : Number.POSITIVE_INFINITY); + for (const number of [...seen.keys()].sort((a, b) => opened(a) - opened(b) || a - b)) { + try { + const { reason, deferred } = await refusal({ github, repo, number, humans, closes, bot }); + if (reason !== null) { + console.log(`label-unblocked: #${number} not labeled: ${reason}`); + continue; } + await admit({ github, repo, number, gate, deferred }); + } catch (error) { + failed += 1; + reportError(number, error); } } return failed; @@ -551,7 +578,7 @@ export const escalationComment = (stops) => // version of the lane workflow files. const FAILED_CAUSE = `The work-resolve-issue run that \`${LABEL}\` started failed or was cancelled before it reported, or it stopped or the token broker refused it because its workflow files differ from main's.`; export const refireComment = (key, cause = FAILED_CAUSE) => - `\n${cause} work-unblock removed and added \`${LABEL}\` back to start a fresh run on main's workflow files. It does this once per version of those files, so if this run fails the same way, a person looks at it.`; + `\n${cause} work-unblock removed and added \`${LABEL}\` back to start a fresh run on main's workflow files. If this run ends the same way, it re-fires the issue again, waiting longer each time.`; // Why a stranded issue has nothing running, as the comments say it. const strandedCause = { @@ -560,10 +587,12 @@ const strandedCause = { "failed-again": `The work-resolve-issue run that \`${LABEL}\` started failed or was cancelled before it reported, over ${STRANDED_HOURS} hours ago.`, }; -// The hand-off of a stranded issue already re-fired on these workflow files: -// one per label add. -export const strandedComment = (key, cause) => - `\n${strandedCause[cause]} work-unblock already re-fired it once on these lane workflow files, so it no longer does, and the issue would hold a place in the issue lane's queue with nothing running. It added \`${HUMAN_LABEL}\`. To try again, remove \`${HUMAN_LABEL}\`, then remove \`${LABEL}\` and add it back.`; +const MINT_CAUSE = `The work-resolve-issue run that \`${LABEL}\` started could not get its lane token.`; + +// The backoff record of an issue whose re-fires on these workflow files keep +// ending the same way: one comment per issue, edited on each re-fire. +export const infraComment = (key, cause, refires) => + `\n${cause} work-unblock has re-fired it ${refires} time(s) on lane workflow files ${key} and keeps re-firing it, waiting longer each time, up to ${BACKOFF_CAP_HOURS} hours, until a run reports. This is a fault in the lanes, not in the issue; this comment is updated on each re-fire.`; // The relabel's record, posted before the label moves: one per recurrence // comment. @@ -573,9 +602,9 @@ export const recurrenceComment = (id) => // The hand-offs to triage once the lane PR ended, each posted once per pull // request before its labels move. export const refsMergedComment = (pr) => - `${handedMarker(pr)}\nThe lanes App's pull request #${pr} merged with \`Refs:\`, so this issue stays open and nothing starts the lane on it again. work-unblock added \`${TRIAGE_LABEL}\` and removed \`${LABEL}\`, so triage decides what work is left.`; + `${handedMarker(pr)}\nThe lanes App's pull request #${pr} merged with \`Refs:\`, so this issue stays open and nothing starts the lane on it again. work-unblock removed \`${READY}\` and \`${LABEL}\`, so the hourly triage sweep sends it back to intake triage, which decides what work is left and admits it again.`; export const refsClosedComment = (pr) => - `${handedMarker(pr)}\nThe lanes App's pull request #${pr} for this issue was closed without merging. work-unblock added \`${TRIAGE_LABEL}\` and removed \`${LABEL}\`, so triage decides what work is left; the lane does not run again on its own. To run it again, add \`${LABEL}\`.`; + `${handedMarker(pr)}\nThe lanes App's pull request #${pr} for this issue was closed without merging. work-unblock removed \`${READY}\` and \`${LABEL}\`, so the hourly triage sweep sends it back to intake triage, which decides what work is left and admits it again.`; // The work-resolve-issue runs for issue `number` created within RUN_WINDOW_MS // of the label event at `addedAt`, as `mine`. The run title ends with @@ -723,6 +752,19 @@ async function lanePulls({ github, repo, number, bot }) { return pulls; } +// A listed human's open pull request for issue `number` (openPullsFor: one +// GitHub says closes it, or one with its `Refs:` line), or null: work running +// on the issue, as an open lane PR is. +async function humanPull({ github, repo, number, humans }) { + for (const pr of await openPullsFor(github, repo, number)) { + const pull = await github("GET", `/repos/${repo}/pulls/${pr}`); + if (pull?.state === "open" && humans.has(pull.user?.id)) { + return pull; + } + } + return null; +} + // The newest of those opened at or after `addedAt`, or null. async function lastLanePull({ github, repo, number, addedAt, bot }) { let last = null; @@ -786,6 +828,10 @@ async function recurrenceRefusal({ github, repo, issue, bot, humans, inFlight, r if (open) { return { reason: `its lane PR #${open.number} is open` }; } + const person = await humanPull({ github, repo, number: issue.number, humans }); + if (person) { + return { reason: `a listed human's PR #${person.number} for it is open` }; + } const titles = await inFlight(); if (titles === null) { return { reason: "no Actions token to read its lane runs" }; @@ -851,9 +897,23 @@ async function refireRefusal({ github, actions, repo, number, lastAdd, addedAt, // whose label write failed is finished by the next sweep, not posted again. const relabeled = (marker) => events.some((event) => isLabel(event, "labeled") && event.actor?.login === bot && Date.parse(event.created_at) >= marker.at); + // A re-fire past the first on these workflow files waits longer each time + // (backoffDue from `since`), and its record is the one backoff comment, + // edited in place, never a new comment or a hold. + const backoff = (key, since, cause) => { + const first = Math.min(...markers.filter((marker) => marker.outcome === "refired" && marker.key === key).map((marker) => marker.at)); + const refires = events.filter((event) => isLabel(event, "labeled") && event.actor?.login === bot && Date.parse(event.created_at) >= first).length; + const due = backoffDue(since, refires); + if (now < due) { + return { reason: `re-fired ${refires} time(s) on workflow files ${key}; it is re-fired again after ${new Date(due).toISOString()}` }; + } + const own = comments.filter((comment) => comment.user?.login === bot && INFRA.test(String(comment.body ?? ""))).at(-1); + return { reason: null, resets: due, refire: key, recorded: true, infra: { id: own?.id, body: infraComment(key, cause, refires + 1) } }; + }; // An issue with nothing running since `since`: once STRANDED_HOURS have - // passed with no open lane PR, re-fired once per version of the lane - // workflow files, then handed to a person. + // passed with no open lane PR and no open pull request of a listed human's + // for it, re-fired, once per version of the lane workflow files and then on + // a backoff. const stranded = async (since, why, cause) => { if (now - since < STRANDED_HOURS * HOUR_MS) { return { reason: why }; @@ -862,13 +922,14 @@ async function refireRefusal({ github, actions, repo, number, lastAdd, addedAt, if (open) { return { reason: `${why}; its lane PR #${open.number} is open` }; } + const person = await humanPull({ github, repo, number, humans }); + if (person) { + return { reason: `${why}; a listed human's PR #${person.number} for it is open` }; + } const key = await workflowKey(); const fired = markers.filter((marker) => marker.outcome === "refired" && marker.key === key); if (fired.some(relabeled)) { - const explained = comments.some( - (comment) => comment.user?.login === bot && STRANDED.exec(String(comment.body ?? ""))?.[1] === key && Date.parse(comment.created_at) >= addedAt, - ); - return { reason: null, resets: since, stranded: cause, key, explained, why }; + return backoff(key, since, strandedCause[cause]); } return { reason: null, resets: since, refire: key, recorded: fired.length > 0, cause: strandedCause[cause] }; }; @@ -900,12 +961,12 @@ async function refireRefusal({ github, actions, repo, number, lastAdd, addedAt, // sweep finishes it without posting another. const recorded = markers.some((marker) => marker.outcome === "refired" && marker.at >= addedAt); // A mint that keeps failing (a broker misconfigured, an issue it refuses) - // stops after limits.limit-stops-per-issue re-fires on these workflow - // files, as a crash stops after one. A WIP cap skip made no mint attempt, - // and the cap and restarts-per-run bound it. + // goes on a backoff after limits.limit-stops-per-issue re-fires on these + // workflow files, as a crash does after one. A WIP cap skip made no mint + // attempt, and the cap and restarts-per-run bound it. const fired = markers.filter((marker) => marker.outcome === "refired" && marker.key === key).length; if (stalled === "mint-failed" && !recorded && fired >= limits["limit-stops-per-issue"]) { - return { reason: `its lane token request failed after ${fired} re-fires on workflow files ${key}` }; + return backoff(key, ended, MINT_CAUSE); } return { reason: null, resets: due, refire: key, recorded }; } @@ -1097,34 +1158,27 @@ async function restartLimited({ github, actions, repo, bot, humans, now, limits, for (const { number } of ready.slice(cap)) { console.log(`label-unblocked: #${number} restart deferred: ${cap} restarts this run`); } - for (const { number, refire, cause, recurrence, recorded, handOff, pr, explained, release, stranded, key: strandedKey, why } of ready.slice(0, cap)) { + for (const { number, refire, cause, recurrence, recorded, handOff, pr, explained, release, infra } of ready.slice(0, cap)) { const base = `/repos/${repo}/issues/${number}`; - if (stranded) { - // The comment first and the hold last, as the escalation does. - try { - if (!explained) { - await github("POST", `${base}/comments`, { body: strandedComment(strandedKey, stranded) }); - } - await github("POST", `${base}/labels`, { labels: [HUMAN_LABEL] }); - console.log(`label-unblocked: #${number} handed to a person: nothing running on it (${why})`); - } catch (error) { - failed += 1; - reportError(number, error); - } - continue; - } if (handOff) { // The comment first, then the labels; agent-ready comes off last, so a // failed write leaves the issue for the next sweep, which finds the - // comment and moves only the labels. + // comment and moves only the labels. With no `status:` label and no + // agent-ready, the hourly triage sweep dispatches intake on it, whose + // fresh `status: ready` re-admits it; needs-triage would keep that + // verdict from ready, so none is added. try { if (!explained) { await github("POST", `${base}/comments`, { body: handOff === "merged" ? refsMergedComment(pr) : refsClosedComment(pr) }); } - await github("POST", `${base}/labels`, { labels: [TRIAGE_LABEL] }); if (release) { await github("DELETE", `${base}/labels/${HUMAN_LABEL}`); } + await github("DELETE", `${base}/labels/${encodeURIComponent(READY)}`).catch((error) => { + if (error?.status !== 404) { + throw error; + } + }); await github("DELETE", `${base}/labels/${LABEL}`); console.log(`label-unblocked: #${number} handed to triage: lane PR #${pr} ${handOff === "merged" ? "merged with Refs:" : "closed unmerged"}`); } catch (error) { @@ -1138,6 +1192,11 @@ async function restartLimited({ github, actions, repo, bot, humans, now, limits, if (refire && !recorded) { await github("POST", `${base}/comments`, { body: refireComment(refire, cause) }); } + if (infra) { + await (infra.id === undefined + ? github("POST", `${base}/comments`, { body: infra.body }) + : github("PATCH", `/repos/${repo}/issues/comments/${infra.id}`, { body: infra.body })); + } // The labels, not the record, bound a relabel, so a failed record (the // alert locks every fix issue) is named and the relabel goes ahead. if (recurrence && !recorded) { @@ -1156,7 +1215,7 @@ async function restartLimited({ github, actions, repo, bot, humans, now, limits, const add = () => github("POST", `/repos/${repo}/issues/${number}/labels`, { labels: [LABEL] }); try { await add().catch(add); - const why = refire ? "re-fired after its failed run" : recurrence ? "relabeled after its reopen on a repeat failure" : "restarted after its limit stop"; + const why = infra ? "re-fired on a backoff" : refire ? "re-fired after its failed run" : recurrence ? "relabeled after its reopen on a repeat failure" : "restarted after its limit stop"; console.log(`label-unblocked: #${number} ${why}`); } catch (error) { failed += 1; diff --git a/.github/scripts/work-unblock/label-unblocked.test.mjs b/.github/scripts/work-unblock/label-unblocked.test.mjs index a9249c06809..3becc3d1aa6 100644 --- a/.github/scripts/work-unblock/label-unblocked.test.mjs +++ b/.github/scripts/work-unblock/label-unblocked.test.mjs @@ -22,8 +22,8 @@ import { refireComment, refsClosedComment, refsMergedComment, + infraComment, skipText, - strandedComment, } from "./label-unblocked.mjs"; const HERE = dirname(fileURLToPath(import.meta.url)); @@ -194,6 +194,9 @@ function world({ if ((match = route.match(/\/issues\/(\d+)\/events$/))) { return listed(events[match[1]] ?? []); } + if (method === "PATCH" && route.match(/\/issues\/comments\/(\d+)$/)) { + return {}; + } if (method === "POST" && (match = route.match(/\/issues\/(\d+)\/labels$/))) { return []; } @@ -213,9 +216,9 @@ function world({ } if (method === "POST" && route === "/graphql") { const { owner, name, number } = body.variables; - assert.equal(`${owner}/${name}`, REPO); // admit.mjs's text read: by default a listed human wrote the body. if (body.query.includes("comments(first: 100)")) { + assert.equal(`${owner}/${name}`, REPO); const spec = specs[String(number)] ?? { body: String(lookup(String(number))?.body ?? ""), author: { __typename: "User", databaseId: OWNER.id }, @@ -227,6 +230,9 @@ function world({ return { data: { repository: { issue: spec === "bad" ? null : { ...spec, comments } } } }; } const found = lookup(String(number)); + // The closer read answers for whichever repository it names, so a read + // of another repository's blocker sees that repository's closer. + assert.equal(`${API}/repos/${owner}/${name}`.toLowerCase(), String(found?.repository_url ?? `${API}/repos/${REPO}`).toLowerCase()); const nodes = found?.state === "closed" ? [{ closer: found.graphCloser }] : []; return { data: { repository: { issue: { timelineItems: { nodes } } } } }; } @@ -309,7 +315,9 @@ test("a hold or agent-ready label in another casing still counts", async () => { } }); -test("a blocker closed as not planned or duplicate still blocks", async () => { +// admit.mjs decide's rule: a blocker a listed human or a merge closed counts +// whatever its close reason; one an unlisted account closed still blocks. +test("a blocker a listed human closed as not planned or duplicate counts; one an unlisted account closed blocks", async () => { for (const reason of ["not_planned", "duplicate"]) { const { github, calls } = world({ blocking: [issue(20)], @@ -318,7 +326,15 @@ test("a blocker closed as not planned or duplicate still blocks", async () => { comments: { 20: [note()] }, }); assert.equal(await main({ env: envFor(), github }), 0); - assert.deepEqual(writes(calls), [], reason); + assert.deepEqual(writes(calls), [labeled(20)], reason); + const outsider = world({ + blocking: [issue(20)], + issues: { 20: issue(20) }, + blockedBy: { 20: [issue(10, { state: "closed" }), issue(11, { state: "closed", reason, closer: { id: 3003, login: "unlisted-maintainer", type: "User" } })] }, + comments: { 20: [note()] }, + }); + assert.equal(await main({ env: envFor(), github: outsider.github }), 0); + assert.deepEqual(writes(outsider.calls), [], `outsider ${reason}`); } }); @@ -790,15 +806,53 @@ test("the closer is read fresh: a blocked-by entry naming a listed closer does n assert.deepEqual(writes(calls), []); }); -test("a blocker in another repository, closed, does not count", async () => { - const { github, calls } = world({ +// Another repository's blocker is read there: a listed human's close counts, +// and an open one, an unlisted account's close or a failed read blocks. A +// merge there counts for nothing: people this repository's list does not +// cover merge in other repositories (the security review on #9814). +test("a blocker in another repository counts once a listed human closed it there", async () => { + const OTHER = "melodic-software/other"; + const closedThere = (closer, failOn, graphCloser = null) => + world({ + blocking: [issue(20)], + issues: { 20: issue(20), 5: issue(5, { state: "closed", repo: OTHER, closer, graphCloser }) }, + blockedBy: { 20: [issue(10, { state: "closed" }), issue(5, { state: "closed", repo: OTHER })] }, + comments: { 20: [note()] }, + failOn, + }); + const human = closedThere(OWNER); + assert.equal(await main({ env: envFor(), github: human.github }), 0); + assert.deepEqual(writes(human.calls), [labeled(20)]); + assert.ok(human.calls.includes(`GET /repos/${OTHER}/issues/5`)); + for (const [name, fake] of [ + ["unlisted closer", closedThere({ id: 3003, login: "unlisted-maintainer", type: "User" })], + ["failed read", closedThere(OWNER, `/repos/${OTHER}/issues/5`)], + ["commit there", closedThere({ id: 3003, login: "unlisted-maintainer", type: "User" }, undefined, commitClose({ repo: OTHER }))], + ["merged PR there", closedThere({ id: 3003, login: "unlisted-maintainer", type: "User" }, undefined, mergedPr({ repo: OTHER }))], + ]) { + assert.equal(await main({ env: envFor(), github: fake.github }), 0, name); + assert.deepEqual(writes(fake.calls), [], name); + } + const open = world({ blocking: [issue(20)], issues: { 20: issue(20) }, - blockedBy: { 20: [issue(10, { state: "closed" }), issue(5, { state: "closed", repo: "melodic-software/other" })] }, + blockedBy: { 20: [issue(10, { state: "closed" }), issue(5, { state: "open", repo: OTHER })] }, comments: { 20: [note()] }, }); - assert.equal(await main({ env: envFor(), github }), 0); - assert.deepEqual(writes(calls), []); + assert.equal(await main({ env: envFor(), github: open.github }), 0); + assert.deepEqual(writes(open.calls), []); + // Another repository's pull request blocker never counts, merged or not. + for (const [mergedAt, expected] of [["2026-10-16T11:00:00Z", []], [null, []]]) { + const pull = { ...issue(16, { state: "closed", reason: null, repo: OTHER }), pull_request: { url: `${API}/repos/${OTHER}/pulls/16`, merged_at: mergedAt } }; + const fake = world({ + blocking: [issue(20)], + issues: { 20: issue(20) }, + blockedBy: { 20: [issue(10, { state: "closed" }), pull] }, + comments: { 20: [note()] }, + }); + assert.equal(await main({ env: envFor(), github: fake.github }), 0, String(mergedAt)); + assert.deepEqual(writes(fake.calls), expected, String(mergedAt)); + } }); // Restarts after a limit stop (FINAL-DESIGN C4): the sweep restarts an open @@ -1463,13 +1517,26 @@ test("a failed mint is re-fired again on the same workflow files up to the bound assert.ok(!writes(calls).some((call) => call.includes("needs-human"))); }); -test("a failed mint stops after limit-stops-per-issue re-fires on the same workflow files, with no needs-human", async () => { +// Past the bound it keeps re-firing on the backoff (3 hours doubling per +// re-fire, at most 24, from when the run ended), recorded in one comment. +test("a failed mint past limit-stops-per-issue re-fires on the same workflow files goes on a backoff, with no needs-human", async () => { + const mintCause = "The work-resolve-issue run that `agent-ready` started could not get its lane token."; + // Three re-fires so far: 24 hours after the run ended at 10:05. const { github, actions, calls } = stalledRun(earlierPumps(3)); assert.equal(await sweep({ github, actions }), 0); assert.deepEqual(writes(calls), []); + const due = stalledRun(earlierPumps(3)); + assert.equal(await sweep({ github: due.github, actions: due.actions, now: Date.parse("2026-10-17T10:05:00Z") }), 0); + assert.deepEqual(writes(due.calls), [`POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body: infraComment(KEY, mintCause, 4) })}`, ...restarted(30)]); + assert.ok(!writes(due.calls).some((call) => call.includes("needs-human"))); + // A bound of 1: one re-fire so far, so 6 hours. const lower = stalledRun(earlierPumps(1)); assert.equal(await sweep({ github: lower.github, actions: lower.actions }, withLimits({ "limit-stops-per-issue": 1 })), 0); assert.deepEqual(writes(lower.calls), []); + const lowerDue = stalledRun(earlierPumps(1)); + const limits = withLimits({ "limit-stops-per-issue": 1 }); + assert.equal(await sweep({ github: lowerDue.github, actions: lowerDue.actions, now: Date.parse("2026-10-16T16:05:00Z") }, limits), 0); + assert.deepEqual(writes(lowerDue.calls), [`POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body: infraComment(KEY, mintCause, 2) })}`, ...restarted(30)]); }); test("a failed mint past the bound is re-fired again once the lane workflow files change", async () => { @@ -1761,15 +1828,19 @@ function lanePr({ pulls = [lanePull()], comments = [note()], events = [added(LAB } const triaged = (n, pr, body = refsMergedComment(pr)) => [ `POST /repos/${REPO}/issues/${n}/comments ${JSON.stringify({ body })}`, - `POST /repos/${REPO}/issues/${n}/labels {"labels":["needs-triage"]}`, + `DELETE /repos/${REPO}/issues/${n}/labels/status%3A%20ready`, `DELETE /repos/${REPO}/issues/${n}/labels/agent-ready`, ]; const CLOSED_PR = () => lanePull({ pr: 7493, merged: false, body: "Closes #30\n" }); -test("a lane PR merged with Refs: hands the issue to triage: the comment, needs-triage, then agent-ready off", async () => { +// Owner 2026-10-24: the hand-off is no dead end. needs-triage would keep +// re-triage from ready, so none is added; status: ready comes off so the +// triage sweep re-dispatches intake, whose fresh status: ready re-admits it. +test("a lane PR merged with Refs: hands the issue to triage: the comment, then status: ready and agent-ready off, no needs-triage", async () => { const { github, actions, calls } = lanePr(); assert.equal(await sweep({ github, actions }), 0); assert.deepEqual(writes(calls), triaged(30, 7805)); + assert.ok(!writes(calls).some((call) => call.includes("needs-triage"))); // The comment went out but a label write did not: only the labels move. const retry = lanePr({ comments: [note(), { id: 60, body: refsMergedComment(7805), user: LANES_BOT, created_at: "2026-10-16T11:47:00Z" }] }); assert.equal(await sweep({ github: retry.github, actions: retry.actions }), 0); @@ -1848,7 +1919,7 @@ test("hand-offs after ended lane PRs share the five-a-run cap with restarts, the }); assert.equal(await sweep({ github }), 0); const refiredIssues = writes(calls) - .filter((call) => call.startsWith("DELETE ")) + .filter((call) => call.startsWith("DELETE ") && call.endsWith("/labels/agent-ready")) .map((call) => Number(call.match(/issues\/(\d+)\//)[1])); assert.deepEqual(refiredIssues, [32, 33, 34, 35, 36]); }); @@ -1878,18 +1949,18 @@ const refsHeld = (extra = {}) => ...extra, }); -test("a Refs PR merging lifts the needs-human report-outcome set for it: needs-triage on, needs-human and agent-ready off", async () => { +test("a Refs PR merging lifts the needs-human report-outcome set for it: needs-human, status: ready and agent-ready off", async () => { const { github, calls } = refsHeld(); assert.equal(await sweep({ github }), 0); - const [comment, triage, agentReady] = triaged(30, 7805); - assert.deepEqual(writes(calls), [comment, triage, `DELETE /repos/${REPO}/issues/30/labels/needs-human`, agentReady]); + const [comment, status, agentReady] = triaged(30, 7805); + assert.deepEqual(writes(calls), [comment, `DELETE /repos/${REPO}/issues/30/labels/needs-human`, status, agentReady]); }); test("a Refs PR closed unmerged lifts the needs-human report-outcome set for it and hands the issue to triage", async () => { const { github, calls } = refsHeld({ pulls: [lanePull({ merged: false })] }); assert.equal(await sweep({ github }), 0); - const [comment, triage, agentReady] = triaged(30, 7805, refsClosedComment(7805)); - assert.deepEqual(writes(calls), [comment, triage, `DELETE /repos/${REPO}/issues/30/labels/needs-human`, agentReady]); + const [comment, status, agentReady] = triaged(30, 7805, refsClosedComment(7805)); + assert.deepEqual(writes(calls), [comment, `DELETE /repos/${REPO}/issues/30/labels/needs-human`, status, agentReady]); }); test("a needs-human that report-outcome did not set for the ended PR, or a PR still open, keeps the hold", async () => { @@ -1954,8 +2025,8 @@ test("a person removing agent-ready after the lane PR prevents both hand-offs to test("a hand-off whose label write failed is finished by the next sweep with the labels only, no second comment", async (t) => { const first = lanePr({ pulls: [CLOSED_PR()] }); const github = async (method, path, body) => { - if (method === "POST" && path.endsWith("/issues/30/labels")) { - first.calls.push(`${method} ${path} ${JSON.stringify(body)}`); + if (method === "DELETE" && path.endsWith("/issues/30/labels/status%3A%20ready")) { + first.calls.push(`${method} ${path}`); throw new Error("POST failed with status 502"); } return first.github(method, path, body); @@ -1965,6 +2036,20 @@ test("a hand-off whose label write failed is finished by the next sweep with the log.mock.restore(); // agent-ready stays on, so the next sweep comes back to the issue. assert.deepEqual(writes(first.calls), triaged(30, 7493, refsClosedComment(7493)).slice(0, 2)); + // A status: ready already gone (404) does not stop the hand-off. + const gone = lanePr({ + pulls: [CLOSED_PR()], + comments: [note(), { id: 63, body: refsClosedComment(7493), user: LANES_BOT, created_at: "2026-10-16T11:47:00Z" }], + }); + const missing = async (method, path, body) => { + if (method === "DELETE" && path.endsWith("/labels/status%3A%20ready")) { + gone.calls.push(`${method} ${path}`); + throw Object.assign(new Error("DELETE failed with status 404"), { status: 404 }); + } + return gone.github(method, path, body); + }; + assert.equal(await sweep({ github: missing }), 0); + assert.deepEqual(writes(gone.calls), triaged(30, 7493).slice(1)); const next = lanePr({ pulls: [CLOSED_PR()], comments: [note(), { id: 63, body: refsClosedComment(7493), user: LANES_BOT, created_at: "2026-10-16T11:47:00Z" }], @@ -2012,13 +2097,15 @@ const recurrenceNote = ({ id = 801, at = "2026-10-16T11:00:00Z", user = ALERT, b // The lane PR that closed the issue the first time: merged with Closes. const closingPull = () => lanePull({ body: "Closes #30\n", created: "2026-10-10T09:20:00Z", closed: "2026-10-10T10:00:00Z" }); -function reopened({ issues = [fixIssue(30)], comments = [note(), recurrenceNote()], events = [added("2026-10-10T09:00:00Z", OWNER)], pulls = [closingPull()], runs = [] } = {}) { +// `closing` lists pull requests GitHub says close the issue, outside its timeline. +function reopened({ issues = [fixIssue(30)], comments = [note(), recurrenceNote()], events = [added("2026-10-10T09:00:00Z", OWNER)], pulls = [closingPull()], runs = [], closing = [] } = {}) { const fake = world({ openReady: issues, comments: Object.fromEntries(issues.map((item) => [item.number, comments])), events: Object.fromEntries(issues.map((item) => [item.number, events])), timeline: Object.fromEntries(issues.map((item) => [item.number, pulls.map((pull) => crossRef(pull))])), - pulls: Object.fromEntries(pulls.map((pull) => [pull.number, pull])), + closing: Object.fromEntries(issues.map((item) => [item.number, closing.map((pull) => ({ number: pull.number, repository: { nameWithOwner: REPO } }))])), + pulls: Object.fromEntries([...pulls, ...closing].map((pull) => [pull.number, pull])), runs, }); return { ...fake, actions: fake.github }; @@ -2081,6 +2168,17 @@ test("a reopened fix issue with an open lane PR, a lane run in flight, a hold, o } }); +// A listed human's open PR for the fix issue is work running on it. +test("a reopened fix issue with a listed human's open closing PR is not relabeled; an unlisted author's PR does not hold it", async () => { + const humanPull = (user) => ({ number: 7960, state: "open", user }); + const listed = reopened({ closing: [humanPull(OWNER)] }); + assert.equal(await sweep({ github: listed.github, actions: listed.actions }), 0); + assert.deepEqual(writes(listed.calls), []); + const unlisted = reopened({ closing: [humanPull({ id: 3003, login: "unlisted-maintainer", type: "User" })] }); + assert.equal(await sweep({ github: unlisted.github, actions: unlisted.actions }), 0); + assert.deepEqual(writes(unlisted.calls), relabeled(30)); +}); + test("each recurrence comment relabels once; a newer one relabels again", async () => { const record = { id: 61, body: recurrenceComment(801), user: LANES_BOT, created_at: "2026-10-16T11:47:00Z" }; const after = [added("2026-10-10T09:00:00Z", OWNER), { event: "unlabeled", label: { name: "agent-ready" }, actor: LANES_BOT, created_at: "2026-10-16T11:47:01Z" }, added("2026-10-16T11:47:02Z")]; @@ -2241,6 +2339,24 @@ test("with room for one admission the first ready issue is labeled and the next assert.deepEqual(writes(calls), [labeled(20), deferredLabel(21)]); }); +// Owner Q95: admission takes the oldest issue first, by when it was opened, +// whatever order the closed listing and the blocking lists answer in. +test("with room for one admission the oldest issue a sweep unblocks is labeled first", async (t) => { + t.mock.method(console, "log", () => {}); + const opened = (n, at) => ({ ...issue(n), created_at: at }); + const { github, calls } = world({ + // Updated-desc order: 12 closed last, so the listing answers it first. + closedList: [closedAt(12, "2026-10-16T11:40:00Z"), closedAt(10, "2026-10-16T11:30:00Z")], + blockingOf: { 12: [opened(22, "2026-10-12T00:00:00Z"), opened(21, "2026-10-05T00:00:00Z")] }, + blocking: [opened(23, "2026-10-14T00:00:00Z"), opened(20, "2026-10-01T00:00:00Z")], + issues: { 20: issue(20), 21: issue(21), 22: issue(22), 23: issue(23) }, + blockedBy: { 20: [issue(10, { state: "closed" })], 21: [issue(12, { state: "closed" })], 22: [issue(12, { state: "closed" })], 23: [issue(10, { state: "closed" })] }, + queuedIssues: queuedN(22), + }); + assert.equal(await sweep({ github }, PAUSING), 0); + assert.deepEqual(writes(calls), [labeled(20), labeled(21), deferredLabel(22), deferredLabel(23)]); +}); + test("an issue already deferred is not labeled admission-deferred again", async (t) => { t.mock.method(console, "log", () => {}); const { github, calls } = world({ ...oneDependentWorld(["admission-deferred"]), queuedIssues: queuedN(24) }); @@ -2603,24 +2719,79 @@ test("a stranded agent-ready issue with no lane run is re-fired once with the re assert.ok(refireComment(KEY, NO_RUN_CAUSE).startsWith(`\n${NO_RUN_CAUSE}`)); }); -test("a stranded issue already re-fired on these workflow files gets one comment and needs-human", async () => { +// Owner 2026-10-24: nothing stops an item but intent or security, so a +// stranded issue already re-fired on these workflow files is re-fired again on +// a backoff (3 hours doubling per re-fire, at most 24), with one comment +// edited in place, and never gets needs-human. +const infraNote = (body, at) => ({ id: 52, body, user: LANES_BOT, created_at: "2026-10-16T14:00:02Z", updated_at: at }); +test("a stranded issue already re-fired on these workflow files is re-fired on a backoff, with one comment and no needs-human", async () => { const events = [ added("2026-10-16T06:00:00Z", OWNER), { event: "unlabeled", label: { name: "agent-ready" }, actor: LANES_BOT, created_at: "2026-10-16T08:00:00Z" }, added("2026-10-16T08:00:01Z"), ]; - const first = failedRun({ runs: [], comments: [note(), refireNote(KEY, "2026-10-16T07:59:59Z")], events }); - assert.equal(await sweep({ github: first.github, actions: first.actions }), 0); - assert.deepEqual(writes(first.calls), [ - `POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body: strandedComment(KEY, "no-run") })}`, - `POST /repos/${REPO}/issues/30/labels {"labels":["needs-human"]}`, + const comments = [note(), refireNote(KEY, "2026-10-16T07:59:59Z")]; + // One re-fire so far: 6 hours after the App's re-add, not before. + const early = failedRun({ runs: [], comments, events }); + assert.equal(await sweep({ github: early.github, actions: early.actions, now: Date.parse("2026-10-16T14:00:00Z") }), 0); + assert.deepEqual(writes(early.calls), []); + const first = failedRun({ runs: [], comments, events }); + assert.equal(await sweep({ github: first.github, actions: first.actions, now: Date.parse("2026-10-16T14:00:02Z") }), 0); + const body = infraComment(KEY, NO_RUN_CAUSE, 2); + assert.deepEqual(writes(first.calls), [`POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body })}`, ...restarted(30)]); + assert.ok(body.includes("re-fired it 2 time(s)")); + // The next one waits 12 hours and edits that comment. + const later = [ + ...events, + { event: "unlabeled", label: { name: "agent-ready" }, actor: LANES_BOT, created_at: "2026-10-16T14:00:03Z" }, + added("2026-10-16T14:00:04Z"), + ]; + const withNote = [...comments, infraNote(body, "2026-10-16T14:00:02Z")]; + const waiting = failedRun({ runs: [], comments: withNote, events: later }); + assert.equal(await sweep({ github: waiting.github, actions: waiting.actions, now: Date.parse("2026-10-17T02:00:00Z") }), 0); + assert.deepEqual(writes(waiting.calls), []); + const second = failedRun({ runs: [], comments: withNote, events: later }); + assert.equal(await sweep({ github: second.github, actions: second.actions, now: Date.parse("2026-10-17T02:00:05Z") }), 0); + assert.deepEqual(writes(second.calls), [ + `PATCH /repos/${REPO}/issues/comments/52 ${JSON.stringify({ body: infraComment(KEY, NO_RUN_CAUSE, 3) })}`, + ...restarted(30), ]); - assert.ok(strandedComment(KEY, "no-run").includes(NO_RUN_CAUSE)); - // A sweep after a failed label write adds only the label. - const posted = { id: 51, body: strandedComment(KEY, "no-run"), user: LANES_BOT, created_at: "2026-10-16T09:00:00Z" }; - const again = failedRun({ runs: [], comments: [note(), refireNote(KEY, "2026-10-16T07:59:59Z"), posted], events }); - assert.equal(await sweep({ github: again.github, actions: again.actions }), 0); - assert.deepEqual(writes(again.calls), [`POST /repos/${REPO}/issues/30/labels {"labels":["needs-human"]}`]); +}); + +test("the backoff between re-fires stops growing at 24 hours", async () => { + const events = [added("2026-10-10T06:00:00Z", OWNER)]; + for (let day = 10; day < 16; day += 1) { + events.push({ event: "unlabeled", label: { name: "agent-ready" }, actor: LANES_BOT, created_at: `2026-10-${day}T08:00:00Z` }); + events.push(added(`2026-10-${day}T08:00:01Z`)); + } + const comments = [note(), refireNote(KEY, "2026-10-10T07:59:59Z"), infraNote(infraComment(KEY, NO_RUN_CAUSE, 6), "2026-10-15T07:59:59Z")]; + const due = Date.parse("2026-10-16T08:00:01Z"); + const early = failedRun({ runs: [], comments, events }); + assert.equal(await sweep({ github: early.github, actions: early.actions, now: due - 1000 }), 0); + assert.deepEqual(writes(early.calls), []); + const { github, actions, calls } = failedRun({ runs: [], comments, events }); + assert.equal(await sweep({ github, actions, now: due }), 0); + assert.deepEqual(writes(calls), [`PATCH /repos/${REPO}/issues/comments/52 ${JSON.stringify({ body: infraComment(KEY, NO_RUN_CAUSE, 7) })}`, ...restarted(30)]); +}); + +// A listed human's open pull request for the issue is work running on it, as +// an open lane PR is: the issue is not stranded. +test("a stranded issue with a listed human's open closing PR is left alone; an unlisted author's PR is not running work", async () => { + const humanPr = (user) => + world({ + openReady: [ready(30)], + comments: { 30: [note()] }, + events: { 30: [added("2026-10-16T08:00:00Z", OWNER)] }, + blobs: BLOBS, + closing: { 30: [{ number: 7950, repository: { nameWithOwner: REPO } }] }, + pulls: { 7950: { number: 7950, state: "open", user } }, + }); + const listed = humanPr(OWNER); + assert.equal(await sweep({ github: listed.github, actions: listed.github }), 0); + assert.deepEqual(writes(listed.calls), []); + const unlisted = humanPr({ id: 3003, login: "unlisted-maintainer", type: "User" }); + assert.equal(await sweep({ github: unlisted.github, actions: unlisted.github }), 0); + assert.deepEqual(writes(unlisted.calls), refiredFor(30, NO_RUN_CAUSE)); }); test("an issue with a recent lane run or label is left alone; past 3 hours it counts as stranded", async () => { @@ -2666,7 +2837,7 @@ test("a stranded issue's no-report clock starts when its run ended, not when it assert.deepEqual(writes(ended.calls), refiredFor(30, NO_REPORT_CAUSE)); }); -test("a stranded issue whose re-fired run failed again over 3 hours ago gets one comment and needs-human", async () => { +test("a stranded issue whose re-fired run failed again is re-fired on a backoff from when it ended, with no needs-human", async () => { const { github, actions, calls } = failedRun({ comments: [note(), refireNote(KEY, "2026-10-16T07:59:59Z")], events: [ @@ -2676,10 +2847,9 @@ test("a stranded issue whose re-fired run failed again over 3 hours ago gets one ], runs: [{ ...laneRun({ at: "2026-10-16T08:00:04Z" }), updated_at: "2026-10-16T08:30:00Z" }], }); - assert.equal(await sweep({ github, actions }), 0); - assert.deepEqual(writes(calls), [ - `POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body: strandedComment(KEY, "failed-again") })}`, - `POST /repos/${REPO}/issues/30/labels {"labels":["needs-human"]}`, - ]); - assert.ok(strandedComment(KEY, "failed-again").includes("failed or was cancelled before it reported")); + // 6 hours after the run ended at 08:30. + assert.equal(await sweep({ github, actions, now: Date.parse("2026-10-16T14:30:00Z") }), 0); + const body = infraComment(KEY, "The work-resolve-issue run that `agent-ready` started failed or was cancelled before it reported, over 3 hours ago.", 2); + assert.deepEqual(writes(calls), [`POST /repos/${REPO}/issues/30/comments ${JSON.stringify({ body })}`, ...restarted(30)]); + assert.ok(!writes(calls).some((call) => call.includes("needs-human"))); }); diff --git a/.github/workflows/maintenance-audit-lane-runs.yml b/.github/workflows/maintenance-audit-lane-runs.yml index 01242575f1d..654b0f7d0ae 100644 --- a/.github/workflows/maintenance-audit-lane-runs.yml +++ b/.github/workflows/maintenance-audit-lane-runs.yml @@ -19,8 +19,9 @@ name: maintenance-audit-lane-runs # # A fourth job, triage-sweep, runs alone every hour (and with the daily run): # it dispatches intake-triage.yml for open issues intake never reached, at -# most 5 a pass, and files one needs-triage issue for an issue 2 dispatches -# left untriaged. It uses the job's own token, never the lanes App. +# most 5 a pass, and labels needs-triage, with a comment on the issue, an issue +# 2 dispatches in one triage cycle left untriaged. It uses the job's own +# token, never the lanes App. # # How to stop it: set the organization or repository lanes kill-switch # variable to anything but "false"; every job checks it first. diff --git a/.github/workflows/work-unblock.yml b/.github/workflows/work-unblock.yml index 716bd049f8b..2dd6bd2c210 100644 --- a/.github/workflows/work-unblock.yml +++ b/.github/workflows/work-unblock.yml @@ -3,9 +3,10 @@ name: work-unblock # What this does, in plain words: # # When an issue closes, each issue it was blocking may now be ready to work. -# This workflow labels `agent-ready` each blocked issue that is open, has every -# blocker closed as completed by a listed human or a merge (a pull request -# blocker: merged), carries no hold label (needs-owner-decision, +# This workflow labels `agent-ready`, oldest first, each blocked issue that is +# open, has every blocker closed, for any reason, by a listed human or a merge +# in this repository (a pull request blocker: merged here; another +# repository's blocker: closed there by a listed human), carries no hold label (needs-owner-decision, # status: needs-decision, status: needs-info, needs-human), and whose agent-ready label was never # removed, or was marked `status: ready` by the lanes App or a listed human # after its newest removal. That label starts work-resolve-issue.yml. The rules are in @@ -34,10 +35,13 @@ name: work-unblock # files`, or a run # cancelled after admit and before resolve-issue started (pick-slot's timeout); a # run a newer agent-ready run replaced is not. It does that once per issue -# per version of the lane's two workflow files on main, recorded in a comment. +# per version of the lane's two workflow files on main, recorded in a comment, +# and after that on a backoff (three hours, doubling each time, at most 24), +# recorded in one comment it edits; it never adds needs-human for it. An open +# pull request of a listed human's for the issue counts as work running on it. # When that run opened a lanes-App PR instead, and the PR merged with `Refs:` -# or was closed unmerged, the App adds needs-triage and takes agent-ready off, -# after a comment; a person adding agent-ready again re-runs it. A Refs PR +# or was closed unmerged, the App takes `status: ready` and agent-ready off, +# after a comment, so the hourly triage sweep sends it back to intake triage. A Refs PR # merging or closing unmerged also lifts a needs-human refs-hold already on # the issue for it. # report-outcome no longer sets that hold, so only an existing one is lifted. diff --git a/docs/conventions/pr-pipeline.yaml b/docs/conventions/pr-pipeline.yaml index 043e695b93a..3c7d8dd6a91 100644 --- a/docs/conventions/pr-pipeline.yaml +++ b/docs/conventions/pr-pipeline.yaml @@ -424,9 +424,10 @@ activities: label-unblocked: # When an issue closes (or, hourly, for each issue a listed human or a # merge closed in the last three hours), labels agent-ready each issue it - # blocked whose blockers are all closed as completed by a listed human or - # a merge, meaning a merged PR or a commit (a pull request blocker: - # merged; another repository's: never), that carries no + # blocked whose blockers are all closed, for any reason, by a listed human + # or a merge in this repository, meaning a merged PR or a commit (a pull + # request blocker: merged here; another repository's blocker: closed there + # by a listed human), oldest first, that carries no # hold label, and whose agent-ready label was never removed or was marked # `status: ready` by the lanes App or a listed human after its newest # removal. The label @@ -441,11 +442,13 @@ activities: # admission rules, and admits it only on their admit verdict; a refusal # moves it to `status: needs-decision` with a comment. Hourly it also # re-fires an agent-ready issue left stranded (no run, or one that ended - # with no report, for three hours) once per version of the lane workflow - # files, then hands it to a person with needs-human and a comment; and it - # hands an agent-ready issue whose - # lanes-App PR merged with `Refs:` or closed unmerged to triage - # (needs-triage on, agent-ready off), lifting only the needs-human + # with no report, for three hours, and no open PR of the lanes App's or a + # listed human's for it) once per version of the lane workflow files, then + # on a backoff (three hours doubling, at most 24) with one comment it + # edits, never needs-human; and it hands an agent-ready issue whose + # lanes-App PR merged with `Refs:` or closed unmerged back to intake + # triage (`status: ready` and agent-ready off, which the hourly triage + # sweep dispatches intake for), lifting only the needs-human # report-outcome set for a Refs PR that merged or closed unmerged. A # script, no model. # .github/workflows/work-unblock.yml runs it.