diff --git a/.github/actions/report-check-run/README.md b/.github/actions/report-check-run/README.md index 143e04daf8a..95261d396f0 100644 --- a/.github/actions/report-check-run/README.md +++ b/.github/actions/report-check-run/README.md @@ -58,6 +58,12 @@ and `head-sha` are cross-checks only. Any disagreement with the inputs is a fail - Every neutral reason must be in `$defs/skip-reason` of `/docs/conventions/pr-pipeline/pr-pipeline.schema.json`. A reason outside it, or an unreadable schema, turns the neutral into a failure. - `details_url` is this workflow run's page, built from the runner's own environment. +- When the run job's `lane-class`, `lane-resets`, `lane-turns` and `lane-max-turns` outputs make a + lane record ([lane-record.mjs](lane-record.mjs)), it opens `output.summary` as one line of + `key=value` tokens (`lane activity class resets turns max-turns`, absent ones omitted), goes into + `output.text` as one JSON block, sets `external_id` to `:::` + when both are positive integers, and is posted as one annotation for readers of older check + runs. It never changes the conclusion or title. - Exit 0 after posting; exit 1 on a refusal, a malformed repository, head SHA, fallback SHA or non-empty PR head SHA, or a failed POST. diff --git a/.github/actions/report-check-run/action.yml b/.github/actions/report-check-run/action.yml index 8a7600c4bfd..43beedaaa4f 100644 --- a/.github/actions/report-check-run/action.yml +++ b/.github/actions/report-check-run/action.yml @@ -54,8 +54,9 @@ inputs: lane-class: description: > The run job's lane-class output: report-lane-outcome's failure class, - empty on a success. With the three below it becomes one annotation on - the posted check run (lane-record.mjs). + empty on a success. With the three below it becomes the first line of + the posted check run's output.summary, its output.text and external_id, + and one annotation (lane-record.mjs). required: false default: "" lane-resets: diff --git a/.github/actions/report-check-run/lane-record.mjs b/.github/actions/report-check-run/lane-record.mjs index 94f9a435da2..55c85afa426 100644 --- a/.github/actions/report-check-run/lane-record.mjs +++ b/.github/actions/report-check-run/lane-record.mjs @@ -1,9 +1,12 @@ -// The lane record annotation for a posted check run: the run's failure class, -// limit reset and turn headroom, which ci-workflows' report-lane-outcome -// computed in the run job from the execution file. Every field is a run job -// output and is checked against a fixed shape here; nothing the model wrote -// reaches the message. A rate-limit message keeps the exact shape -// .github/scripts/pr-unblock/limit-stop.mjs parses. +// The lane record for a posted check run: the run's failure class, limit reset +// and turn headroom, which ci-workflows' report-lane-outcome computed in the +// run job from the execution file. Every field is a run job output or the +// runner's own environment and is checked against a fixed shape here; nothing +// the model wrote reaches the record. It is posted twice: as the first line of +// output.summary (with the JSON form in output.text), which +// .github/scripts/pr-unblock/limit-stop.mjs reads first, and as one annotation +// in the shape limit-stop.mjs reads on check runs posted before the summary +// line existed. const CLASSES = new Set([ "auth", @@ -15,33 +18,69 @@ const CLASSES = new Set([ "skipped-validation", "incomplete", ]); +const NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/; const RESETS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?Z$/; const COUNT = /^(0|[1-9][0-9]{0,5})$/; +const RUN_NUMBER = /^[1-9][0-9]*$/; const PATH = ".github/workflows/pr-run-activity-write.yml"; -// One check-run annotation, or null when the run job left no record: the -// skill did not run, or the class is not one report-lane-outcome emits. -export function laneRecordAnnotation({ - lane, - failureClass = "", - resets = "", - turns = "", - maxTurns = "", -}) { +// The record's fields that passed their shape, or null when the run job left +// no record: the skill did not run, or the class is not one +// report-lane-outcome emits. +function laneRecord({ failureClass = "", resets = "", turns = "", maxTurns = "" }) { if (failureClass !== "" && !CLASSES.has(failureClass)) { return null; } - const tokens = [ - failureClass === "rate-limit" && RESETS.test(resets) && `resets=${resets}`, - COUNT.test(turns) && `turns=${turns}`, - COUNT.test(maxTurns) && `max-turns=${maxTurns}`, - ].filter(Boolean); - if (failureClass === "" && tokens.length === 0) { + const fields = { + resets: failureClass === "rate-limit" && RESETS.test(resets) ? resets : null, + turns: COUNT.test(turns) ? turns : null, + "max-turns": COUNT.test(maxTurns) ? maxTurns : null, + }; + if (failureClass === "" && fields.turns === null && fields["max-turns"] === null) { + return null; + } + return { class: failureClass || null, ...fields }; +} + +const tokensOf = (fields) => + Object.entries(fields) + .filter(([, value]) => value !== null) + .map(([key, value]) => `${key}=${value}`); + +// The record as the check run's output fields and external_id, or null when +// there is none. The summary line is `lane= activity=` then +// class, resets, turns and max-turns in that order, each omitted when absent. +export function laneRecordOutput({ lane, activity, runId = "", runAttempt = "", ...inputs }) { + const record = laneRecord(inputs); + if (!record || !NAME.test(lane ?? "") || !NAME.test(activity ?? "")) { + return null; + } + const fields = { lane, activity, ...record }; + const json = Object.fromEntries( + Object.entries(fields) + .filter(([, value]) => value !== null) + .map(([key, value]) => [key, key.endsWith("turns") ? Number(value) : value]), + ); + return { + line: tokensOf(fields).join(" "), + text: `\`\`\`json\n${JSON.stringify(json)}\n\`\`\``, + externalId: + RUN_NUMBER.test(runId) && RUN_NUMBER.test(runAttempt) ? `${lane}:${activity}:${runId}:${runAttempt}` : null, + }; +} + +// One check-run annotation, or null when there is no record. +export function laneRecordAnnotation({ lane, ...inputs }) { + const fields = laneRecord(inputs); + if (!fields) { return null; } - const record = tokens.map((token) => ` ${token}`).join(""); + const { class: failureClass, ...rest } = fields; + const record = tokensOf(rest) + .map((token) => ` ${token}`) + .join(""); const at = { path: PATH, start_line: 1, end_line: 1 }; - if (failureClass === "") { + if (failureClass === null) { return { ...at, annotation_level: "notice", message: `${lane} completed:${record}.` }; } if (failureClass === "skipped-validation") { diff --git a/.github/actions/report-check-run/lane-record.test.mjs b/.github/actions/report-check-run/lane-record.test.mjs index 762f96187c1..96c77148311 100644 --- a/.github/actions/report-check-run/lane-record.test.mjs +++ b/.github/actions/report-check-run/lane-record.test.mjs @@ -2,11 +2,11 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { limitResetsAt } from "../../scripts/pr-unblock/limit-stop.mjs"; -import { laneRecordAnnotation } from "./lane-record.mjs"; +import { laneRecordAnnotation, laneRecordOutput } from "./lane-record.mjs"; const ENDED = "2026-10-17T12:00:00Z"; const RESETS = "2026-10-17T15:30:00Z"; -const run = { completed_at: ENDED }; +const run = { conclusion: "failure", completed_at: ENDED }; test("a rate-limit record is the limit stop limit-stop.mjs reads, with its reset", () => { const annotation = laneRecordAnnotation({ @@ -70,3 +70,54 @@ test("no record, an unknown class, or non-numeric turns add nothing", () => { assert.equal(laneRecordAnnotation({ lane: "pr-unblock", failureClass: "forged class" }), null); assert.equal(laneRecordAnnotation({ lane: "pr-unblock", turns: "4 x=1", maxTurns: "" }), null); }); + +test("the output record is one line of key=value tokens in a fixed order, its JSON form, and a run-scoped external id", () => { + const record = laneRecordOutput({ + lane: "pr-unblock", + activity: "resolve-conflicts", + failureClass: "rate-limit", + resets: RESETS, + turns: "12", + maxTurns: "30", + runId: "4242", + runAttempt: "2", + }); + assert.equal( + record.line, + `lane=pr-unblock activity=resolve-conflicts class=rate-limit resets=${RESETS} turns=12 max-turns=30`, + ); + assert.equal( + record.text, + "```json\n" + + `{"lane":"pr-unblock","activity":"resolve-conflicts","class":"rate-limit","resets":"${RESETS}","turns":12,"max-turns":30}` + + "\n```", + ); + assert.equal(record.externalId, "pr-unblock:resolve-conflicts:4242:2"); +}); + +test("absent fields are omitted from the output record, and a success carries no class", () => { + const record = laneRecordOutput({ lane: "pr-refine", activity: "simplify", turns: "4" }); + assert.equal(record.line, "lane=pr-refine activity=simplify turns=4"); + assert.equal(record.text, '```json\n{"lane":"pr-refine","activity":"simplify","turns":4}\n```'); + assert.equal(record.externalId, null); +}); + +test("the output record drops what fails its shape: a reset off rate-limit, a forged reset, a malformed run id", () => { + assert.equal( + laneRecordOutput({ lane: "pr-unblock", activity: "x", failureClass: "other", resets: RESETS }).line, + "lane=pr-unblock activity=x class=other", + ); + assert.equal( + laneRecordOutput({ lane: "pr-unblock", activity: "x", failureClass: "rate-limit", resets: `${RESETS} turns=1` }).line, + "lane=pr-unblock activity=x class=rate-limit", + ); + const forgedRun = { lane: "pr-unblock", activity: "x", failureClass: "other", runAttempt: "1" }; + assert.equal(laneRecordOutput({ ...forgedRun, runId: "1:2" }).externalId, null); + assert.equal(laneRecordOutput({ ...forgedRun, runId: "7", runAttempt: "0" }).externalId, null); +}); + +test("no record, an unknown class, or a malformed name add no output record", () => { + assert.equal(laneRecordOutput({ lane: "pr-unblock", activity: "x" }), null); + assert.equal(laneRecordOutput({ lane: "pr-unblock", activity: "x", failureClass: "forged class" }), null); + assert.equal(laneRecordOutput({ lane: "pr-unblock", activity: "x y=1", failureClass: "other" }), null); +}); diff --git a/.github/actions/report-check-run/report-check-run.mjs b/.github/actions/report-check-run/report-check-run.mjs index 359140c3f14..36c3bdb02d6 100644 --- a/.github/actions/report-check-run/report-check-run.mjs +++ b/.github/actions/report-check-run/report-check-run.mjs @@ -8,7 +8,7 @@ import { fileURLToPath, pathToFileURL } from "node:url"; import { createGitHub } from "../check-trusted-trigger/check-trusted-trigger.mjs"; import { decide } from "./decide.mjs"; -import { laneRecordAnnotation } from "./lane-record.mjs"; +import { laneRecordAnnotation, laneRecordOutput } from "./lane-record.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const SCHEMA = "docs/conventions/pr-pipeline/pr-pipeline.schema.json"; @@ -90,15 +90,29 @@ export async function main({ return 1; } const body = { ...decision.report }; - const annotation = laneRecordAnnotation({ + const inputs = { lane: env.LANE, failureClass: env.LANE_CLASS ?? "", resets: env.LANE_RESETS ?? "", turns: env.LANE_TURNS ?? "", maxTurns: env.LANE_MAX_TURNS ?? "", + }; + const record = laneRecordOutput({ + ...inputs, + activity: env.ACTIVITY, + runId: env.GITHUB_RUN_ID ?? "", + runAttempt: env.GITHUB_RUN_ATTEMPT ?? "", }); - if (annotation) { - body.output = { ...body.output, annotations: [annotation] }; + if (record) { + body.output = { + ...body.output, + summary: `${record.line}\n\n${body.output.summary}`, + text: record.text, + annotations: [laneRecordAnnotation(inputs)], + }; + if (record.externalId) { + body.external_id = record.externalId; + } } if (RUN_ID.test(env.GITHUB_RUN_ID ?? "")) { body.details_url = `${env.GITHUB_SERVER_URL ?? "https://github.com"}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}`; diff --git a/.github/actions/report-check-run/report-check-run.test.mjs b/.github/actions/report-check-run/report-check-run.test.mjs index 175254feac4..b1efb1a9a2d 100644 --- a/.github/actions/report-check-run/report-check-run.test.mjs +++ b/.github/actions/report-check-run/report-check-run.test.mjs @@ -12,6 +12,7 @@ import path from "node:path"; import { afterEach, beforeEach, test } from "node:test"; import { fileURLToPath } from "node:url"; +import { anyHandles, limitResetsAt } from "../../scripts/pr-unblock/limit-stop.mjs"; import { main } from "./report-check-run.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); @@ -70,6 +71,7 @@ async function run(env = {}, status) { GITHUB_API_URL: "https://api.example.test", GITHUB_SERVER_URL: "https://github.com", GITHUB_RUN_ID: "123", + GITHUB_RUN_ATTEMPT: "1", ...env, }, fetchImpl, @@ -109,22 +111,73 @@ test("a valid verdict POSTs one completed check run with the contract body", asy ); }); -test("a lane record from env POSTs as the check run's one annotation", async () => { - const { calls } = await run({ - ACT_OUTCOME: "failure", - LANE_CLASS: "rate-limit", - LANE_RESETS: "2026-10-17T15:30:00Z", - LANE_TURNS: "3", - LANE_MAX_TURNS: "30", +const LIMIT = { + ACT_OUTCOME: "failure", + LANE_CLASS: "rate-limit", + LANE_RESETS: "2026-10-17T15:30:00Z", + LANE_TURNS: "3", + LANE_MAX_TURNS: "30", +}; + +test("a lane record from env opens the summary, fills output.text and external_id, and keeps the annotation", async () => { + const { calls } = await run({ ...LIMIT, GITHUB_RUN_ATTEMPT: "2" }); + const { body } = calls[0]; + assert.equal(body.conclusion, "failure"); + const [line, blank, ...rest] = body.output.summary.split("\n"); + assert.equal(line, "lane=pr-refine activity=simplify class=rate-limit resets=2026-10-17T15:30:00Z turns=3 max-turns=30"); + assert.equal(blank, ""); + assert.equal(rest.join("\n"), "The activity step failed."); + const json = /^```json\n(.*)\n```$/.exec(body.output.text); + assert.deepEqual(JSON.parse(json[1]), { + lane: "pr-refine", + activity: "simplify", + class: "rate-limit", + resets: "2026-10-17T15:30:00Z", + turns: 3, + "max-turns": 30, }); - assert.equal(calls[0].body.conclusion, "failure"); - const [annotation] = calls[0].body.output.annotations; + assert.equal(body.external_id, "pr-refine:simplify:123:2"); + const [annotation] = body.output.annotations; assert.match(annotation.message, /class=rate-limit resets=2026-10-17T15:30:00Z turns=3 max-turns=30\)/); }); -test("no lane record POSTs no annotations", async () => { +test("the posted limit stop is the one limit-stop.mjs reads from the summary, with no annotations call", async () => { + const { calls } = await run(LIMIT); + const posted = { ...calls[0].body, id: 1, completed_at: "2026-10-17T12:00:00Z" }; + assert.equal(limitResetsAt(posted), Date.parse("2026-10-17T15:30:00Z")); + const listAnnotations = async () => { + throw new Error("annotations read for a run whose summary carries the record"); + }; + const ids = [1, 2, 3].map((id) => ({ ...posted, id })); + const now = Date.parse("2026-10-17T16:00:00Z"); + assert.equal(await anyHandles(ids.slice(0, 2), { listAnnotations, now }), false); + assert.equal(await anyHandles(ids, { listAnnotations, now }), true); + assert.equal(await anyHandles(ids.slice(0, 1), { listAnnotations, now: Date.parse("2026-10-17T15:00:00Z") }), true); +}); + +test("another posted failure class is a record limit-stop.mjs reads as no limit stop", async () => { + const { calls } = await run({ ACT_OUTCOME: "failure", LANE_CLASS: "max-turns", LANE_TURNS: "31", LANE_MAX_TURNS: "30" }); + const posted = { ...calls[0].body, id: 1, completed_at: "2026-10-17T12:00:00Z" }; + assert.equal(limitResetsAt(posted), null); + const listAnnotations = async () => { + throw new Error("annotations read for a run whose summary carries the record"); + }; + assert.equal(await anyHandles([posted], { listAnnotations, now: Date.parse("2026-10-20T00:00:00Z") }), true); +}); + +test("a malformed run attempt posts the record without an external_id", async () => { + const { calls } = await run({ ...LIMIT, GITHUB_RUN_ATTEMPT: "1:x" }); + assert.equal("external_id" in calls[0].body, false); + assert.match(calls[0].body.output.summary, /^lane=pr-refine activity=simplify class=rate-limit /); +}); + +test("no lane record POSTs no annotations, text, external_id or record line", async () => { const { calls } = await run(); - assert.equal(calls[0].body.output.annotations, undefined); + const { output } = calls[0].body; + assert.equal(output.annotations, undefined); + assert.equal(output.text, undefined); + assert.equal("external_id" in calls[0].body, false); + assert.doesNotMatch(output.summary, /lane=/); }); test("an absent verdict file POSTs failure on the env head", async () => { diff --git a/.github/scripts/pr-unblock/limit-stop.mjs b/.github/scripts/pr-unblock/limit-stop.mjs index 9708d2be359..fc0b25a5d00 100644 --- a/.github/scripts/pr-unblock/limit-stop.mjs +++ b/.github/scripts/pr-unblock/limit-stop.mjs @@ -4,12 +4,17 @@ // the usage limit stopped whose limit has reset: the lane's next trigger then // dispatches it again, at most MAX_LIMIT_STOPS times on one head. // -// A limit stop is read only from the lane record annotation that ci-workflows' -// report-lane-outcome writes with core.error: failure level, no title, and a -// message that opens " skipped: usage limit reached; re-run -// after it resets ( exited with: class=rate-limit ). Last SDK result: ", matched from its start, so text a step or the -// model prints elsewhere in the job cannot pass for one. +// A limit stop is read only from a failed run's lane record, which +// report-check-run writes from runner-computed outputs. The record is the first +// line of the run's output.summary, matched whole: `lane= +// activity=` naming the run itself, then class, resets, turns and +// max-turns in that order, each optional. A run with no such line was posted +// before report-check-run wrote it; its record is the annotation in the shape +// ci-workflows' report-lane-outcome writes with core.error: failure level, no +// title, and a message that opens " skipped: usage limit +// reached; re-run after it resets ( exited with: +// class=rate-limit ). Last SDK result: ", matched from its +// start, so text a step or the model prints elsewhere cannot pass for one. // When a limit stop names no `resets=` time, it is taken to reset this long // after the run ended: the shortest plan limit is a five-hour session window @@ -23,16 +28,25 @@ const HOUR_MS = 3_600_000; export const MAX_LIMIT_STOPS = 3; const RECORD = /^([^\n()]+) skipped: usage limit reached; re-run after it resets \(([^\n()]+) exited with: [a-z_]+ class=rate-limit((?: [a-z-]+=[^\s()]+)*)\)\. Last SDK result: /; -const RESETS = /^resets=(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?Z)$/; +const ISO = String.raw`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?Z`; +const RESETS = new RegExp(`^resets=(${ISO})$`); +const NAME = "[a-z][a-z0-9]*(?:-[a-z0-9]+)*"; +const SUMMARY_RECORD = new RegExp( + `^lane=(${NAME}) activity=(${NAME})(?: class=([a-z-]+))?(?: resets=(${ISO}))?` + + "(?: turns=(?:0|[1-9][0-9]{0,5}))?(?: max-turns=(?:0|[1-9][0-9]{0,5}))?$", +); -// When the limit that stopped `run` resets (epoch ms), or null when no lane -// record marks it a limit stop. The stated reset is held between one hour and -// seven days after the run ended. -export function limitResetsAt(run, annotations) { - const ended = Date.parse(run.completed_at ?? ""); - if (!Number.isFinite(ended)) { +// The lane record on the first line of `run`'s output.summary, or null when +// that line is not one or names another check run. +export function summaryRecord(run) { + const match = SUMMARY_RECORD.exec(String(run.output?.summary ?? "").split("\n")[0]); + if (!match || run.name !== `${match[1]} / ${match[2]}`) { return null; } + return { failureClass: match[3] ?? "", resets: match[4] ?? "" }; +} + +function annotationResets(annotations) { const record = annotations .filter((annotation) => annotation?.annotation_level === "failure" && !annotation.title) .map((annotation) => RECORD.exec(String(annotation.message ?? ""))) @@ -40,10 +54,29 @@ export function limitResetsAt(run, annotations) { if (!record) { return null; } - const stated = record[3] + return record[3] .split(" ") .map((token) => RESETS.exec(token)?.[1]) - .find(Boolean); + .find(Boolean) ?? ""; +} + +// When the limit that stopped the failed `run` resets (epoch ms), or null when +// its lane record does not mark it a limit stop. `annotations` are read only +// when the summary carries no record. The stated reset is held between one +// hour and seven days after the run ended. +export function limitResetsAt(run, annotations = []) { + const ended = Date.parse(run.completed_at ?? ""); + if (!Number.isFinite(ended) || run.conclusion !== "failure") { + return null; + } + const summary = summaryRecord(run); + if (summary && summary.failureClass !== "rate-limit") { + return null; + } + const stated = summary ? summary.resets : annotationResets(annotations); + if (stated === null) { + return null; + } const resets = stated ? Date.parse(stated) : ended + FALLBACK_RESET_MS; return Math.min(Math.max(resets, ended + HOUR_MS), ended + 7 * 24 * HOUR_MS); } @@ -55,7 +88,7 @@ const untrustedSkip = (run) => // Whether `runs` handle the head: any run that is not an untrusted skip or a // reset limit stop does, and so do MAX_LIMIT_STOPS limit stops. Annotations -// are read only for a failed run. +// are read only for a failed run whose summary carries no lane record. export async function anyHandles(runs, { listAnnotations, now }) { let stops = 0; for (const run of runs) { @@ -65,7 +98,7 @@ export async function anyHandles(runs, { listAnnotations, now }) { if (run.status !== "completed" || run.conclusion !== "failure") { return true; } - const resets = limitResetsAt(run, await listAnnotations(run.id)); + const resets = limitResetsAt(run, summaryRecord(run) ? [] : await listAnnotations(run.id)); if (resets === null || now < resets) { return true; } diff --git a/.github/scripts/pr-unblock/limit-stop.test.mjs b/.github/scripts/pr-unblock/limit-stop.test.mjs index daf2237f32a..7b4bb4aa810 100644 --- a/.github/scripts/pr-unblock/limit-stop.test.mjs +++ b/.github/scripts/pr-unblock/limit-stop.test.mjs @@ -51,3 +51,53 @@ test("reset limit stops stop handling a head until three of them stand on it", a assert.equal(await anyHandles([run(1), run(2)], { listAnnotations, now }), false); assert.equal(await anyHandles([run(1), run(2), run(3)], { listAnnotations, now }), true); }); + +// The summary record report-check-run writes on the first line of a posted +// check run named ` / `. +const posted = (line, extra = {}) => ({ + ...run(), + name: "pr-unblock / resolve-conflicts", + output: { title: "Failed", summary: `${line}\n\nThe activity step failed.` }, + ...extra, +}); +const LIMIT_LINE = "lane=pr-unblock activity=resolve-conflicts class=rate-limit resets=2026-10-17T13:00:00Z turns=4 max-turns=30"; + +test("the summary record is read first: its reset, and its class over any annotation", () => { + assert.equal(limitResetsAt(posted(LIMIT_LINE), []), Date.parse("2026-10-17T13:00:00Z")); + assert.equal(limitResetsAt(posted("lane=pr-unblock activity=resolve-conflicts class=rate-limit")), ended + 5 * HOUR); + const other = posted("lane=pr-unblock activity=resolve-conflicts class=other turns=3"); + assert.equal(limitResetsAt(other, [record(" resets=2026-10-17T13:00:00Z")]), null); +}); + +test("a summary record skips the annotations read; a run without one falls back to it", async () => { + const now = ended + 6 * HOUR; + const read = []; + const listAnnotations = async (id) => { + read.push(id); + return [record()]; + }; + const runs = [posted(LIMIT_LINE, { id: 1 }), run(2), posted(LIMIT_LINE, { id: 3 })]; + assert.equal(await anyHandles(runs, { listAnnotations, now }), true); + assert.deepEqual(read, [2]); +}); + +test("a summary line that is not the record is not read as one", () => { + const notRecords = [ + // the record below the first line + posted(`Failed.\n${LIMIT_LINE}`), + // embedded in other text, or with a token out of order or unknown + posted(`Model said: ${LIMIT_LINE}`), + posted("lane=pr-unblock activity=resolve-conflicts resets=2026-10-17T13:00:00Z class=rate-limit"), + posted(`${LIMIT_LINE} note=x`), + // a record naming another check run + posted(LIMIT_LINE.replace("resolve-conflicts", "address-feedback")), + ]; + for (const forged of notRecords) { + assert.equal(limitResetsAt(forged, []), null, forged.output.summary); + } +}); + +test("a run that did not fail is no limit stop, whatever its summary or annotations say", () => { + assert.equal(limitResetsAt(posted(LIMIT_LINE, { conclusion: "success" })), null); + assert.equal(limitResetsAt({ ...run(), conclusion: "neutral" }, [record()]), null); +}); diff --git a/docs/conventions/pr-pipeline/pr-run-activity.md b/docs/conventions/pr-pipeline/pr-run-activity.md index fbb623a37fa..eff0904a52a 100644 --- a/docs/conventions/pr-pipeline/pr-run-activity.md +++ b/docs/conventions/pr-pipeline/pr-run-activity.md @@ -255,8 +255,13 @@ The write file also outputs the lane record of a skill run: `lane-class` and `la failure class and usage-limit reset that ci-workflows' `report-lane-outcome` reads from the execution file's structured fields, and `lane-turns` and `lane-max-turns`, the turns taken and the cap. They come from steps after the skill. The report job passes them to `report-check-run`, which -checks each against a fixed shape and posts them as one annotation on the check run; a -`class=rate-limit` annotation is the limit stop the pr-unblock dispatchers read. In issue mode the +checks each against a fixed shape and writes them into the posted check run: as the first line of +`output.summary`, `lane= activity=` then `class`, `resets`, `turns` and `max-turns` +in that order, each omitted when absent; as one JSON block in `output.text`; and as +`external_id` `:::`. A failed run whose record says `class=rate-limit` +is the limit stop the pr-unblock dispatchers read from the check-run list they already fetch. The +record also stays, for one release, as an annotation in report-lane-outcome's shape, which the +dispatchers read only for a check run whose summary has no record line. In issue mode the same `class` and `resets` go into `lane.json` beside the kept branch, for report-outcome's `limited` exit. Any code the activity runs, not only the model, can forge this record, for example by planting the execution file. A forged limit stop can only restart the lane, at least an