Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- The monitoring lane and the lane sweep reopen the closed issue they hold for a key or fingerprint, with a comment carrying the new evidence, instead of filing a new one; a close as not planned or duplicate mutes it, and the lane sweep no longer limits this to a 14-day window ([README.md, The monitoring lane](https://github.com/melodic-software/claude-code-plugins/blob/main/docs/conventions/pr-pipeline/README.md#the-monitoring-lane)).
45 changes: 35 additions & 10 deletions .github/scripts/maintenance-audit-lane-runs/file-findings.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The lane sweep's file job: checks every claim against main, fingerprints
// each finding, reads the issues earlier sweeps filed, and files, comments or
// skips per planFiling. No model. Writes with the job's own token, one call at
// each finding, reads the issues earlier sweeps filed, and files, comments,
// reopens or skips per planFiling. No model. Writes with the job's own token, one call at
// a time, 1 s apart, within its call budget.
import { appendFileSync, readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
Expand All @@ -16,6 +16,7 @@ import {
planFiling,
readFingerprint,
renderBody,
renderReopenComment,
validateFinding,
} from "./findings.mjs";

Expand Down Expand Up @@ -71,13 +72,14 @@ export const droppedLine = (d) => `- dropped (${d.unit}) ${inertLine(d.title)}:
export async function writeAll({ plan, call, repo, labels, runUrl, wait = () => delay(1000) }) {
const filed = [];
const commented = [];
const reopened = [];
const failed = [];
for (const { fingerprint: fp, finding, regressionOf } of plan.file) {
for (const { fingerprint: fp, finding } of plan.file) {
await wait();
try {
const issue = await call("POST", `/repos/${repo}/issues`, {
title: inertTitle(finding.title),
body: renderBody(finding, fp, runUrl, regressionOf),
body: renderBody(finding, fp, runUrl),
labels,
});
filed.push(issue.number);
Expand All @@ -96,7 +98,31 @@ export async function writeAll({ plan, call, repo, labels, runUrl, wait = () =>
failed.push({ target: `#${number}`, error: error.message });
}
}
return { filed, commented, failed };
// The marker is the fingerprint, which a reopen leaves unchanged, so the
// PATCH sets the state only and keeps any rewrite a person made. Before it,
// the issue goes back to triage: the filing labels that exist return, and
// agent-ready comes off (a 404 means it was not on the issue). The PATCH
// runs last, so a failed label call leaves the issue closed and retried.
for (const { number, finding } of plan.reopen) {
try {
await wait();
await call("POST", `/repos/${repo}/issues/${number}/comments`, { body: renderReopenComment(finding, runUrl) });
if (labels.length > 0) {
await wait();
await call("POST", `/repos/${repo}/issues/${number}/labels`, { labels });
}
await wait();
await call("DELETE", `/repos/${repo}/issues/${number}/labels/agent-ready`).catch((error) => {
if (error.status !== 404) throw error;
});
await wait();
await call("PATCH", `/repos/${repo}/issues/${number}`, { state: "open", state_reason: "reopened" });
reopened.push(number);
} catch (error) {
failed.push({ target: `#${number}`, error: error.message });
}
}
return { filed, commented, reopened, failed };
}

async function main() {
Expand All @@ -116,7 +142,7 @@ async function main() {
body: body ? JSON.stringify(body) : undefined,
});
if (response.status === 404 && method === "GET") return null;
if (!response.ok) throw new Error(`${method} ${path}: HTTP ${response.status}`);
if (!response.ok) throw Object.assign(new Error(`${method} ${path}: HTTP ${response.status}`), { status: response.status });
return response.json();
};

Expand All @@ -138,26 +164,25 @@ async function main() {
items,
existing,
openNumbers: new Set(openItems.map((i) => i.number)),
now: new Date(),
});
const labels = [];
for (const name of LABELS) {
if (await call("GET", `/repos/${repo}/labels/${encodeURIComponent(name)}`)) labels.push(name);
}
const runUrl = `${env.GITHUB_SERVER_URL}/${repo}/actions/runs/${env.GITHUB_RUN_ID}`;
const { filed, commented, failed } = await writeAll({ plan, call, repo, labels, runUrl });
const { filed, commented, reopened, failed } = await writeAll({ plan, call, repo, labels, runUrl });
const lines = [
"### Lane sweep filing",
"",
`Filed: ${filed.map((n) => `#${n}`).join(", ") || "none"}. Commented: ${commented.map((n) => `#${n}`).join(", ") || "none"}. Labels applied: ${labels.join(", ") || "none"}. Calls: ${budget.used}.`,
`Filed: ${filed.map((n) => `#${n}`).join(", ") || "none"}. Commented: ${commented.map((n) => `#${n}`).join(", ") || "none"}. Reopened: ${reopened.map((n) => `#${n}`).join(", ") || "none"}. Labels applied: ${labels.join(", ") || "none"}. Calls: ${budget.used}.`,
"",
...failed.map((f) => `- failed ${f.target}: ${f.error}`),
...plan.skip.map((s) => `- skipped ${s.fingerprint}: ${s.reason}`),
...dropped.map(droppedLine),
];
appendFileSync(env.GITHUB_STEP_SUMMARY, `${lines.join("\n")}\n`);
console.log(
`file-findings: filed ${filed.length}, commented ${commented.length}, failed ${failed.length}, skipped ${plan.skip.length}, dropped ${dropped.length}`,
`file-findings: filed ${filed.length}, commented ${commented.length}, reopened ${reopened.length}, failed ${failed.length}, skipped ${plan.skip.length}, dropped ${dropped.length}`,
);
if (failed.length > 0) {
console.log(`::error::${failed.length} lane sweep write(s) failed; see the step summary`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { join } from "node:path";
import { test } from "node:test";

import { droppedLine, prepareItems, writeAll } from "./file-findings.mjs";
import { planFiling } from "./findings.mjs";
import { parseJudgeOutput } from "./write-findings.mjs";

const finding = (over = {}) => ({
Expand Down Expand Up @@ -92,16 +93,99 @@ test("one failed write is recorded and the rest still file", async () => {
};
const plan = {
file: [
{ fingerprint: "aaaa", finding: finding({ title: "fix: rejected" }), regressionOf: null },
{ fingerprint: "bbbb", finding: finding(), regressionOf: null },
{ fingerprint: "aaaa", finding: finding({ title: "fix: rejected" }) },
{ fingerprint: "bbbb", finding: finding() },
],
comment: [{ number: 7 }],
reopen: [],
};
const result = await writeAll({ plan, call, repo: "o/r", labels: [], runUrl: "u", wait: async () => {} });
assert.equal(calls.length, 3);
assert.deepEqual(result, {
filed: [102],
commented: [7],
reopened: [],
failed: [{ target: "aaaa", error: "POST /repos/o/r/issues: HTTP 422" }],
});
});

test("a reopen comments with the checked claims, re-triages, then sets the state open as reopened", async () => {
const calls = [];
const call = async (method, path, body) => {
calls.push([method, path, body]);
return {};
};
const plan = { file: [], comment: [], reopen: [{ number: 12, fingerprint: "cccc", finding: finding() }] };
const labels = ["needs-triage", "source: lane-sweep"];
let waits = 0;
const result = await writeAll({ plan, call, repo: "o/r", labels, runUrl: "https://run/1", wait: async () => waits++ });
assert.deepEqual(result, { filed: [], commented: [], reopened: [12], failed: [] });
assert.deepEqual(
calls.map(([method, path]) => `${method} ${path}`),
[
"POST /repos/o/r/issues/12/comments",
"POST /repos/o/r/issues/12/labels",
"DELETE /repos/o/r/issues/12/labels/agent-ready",
"PATCH /repos/o/r/issues/12",
],
);
assert.equal(waits, 4);
assert.match(calls[0][2].body, /https:\/\/run\/1/);
assert.match(calls[0][2].body, /```text\na\.yml:1: if: true\n```/);
assert.deepEqual(calls[1][2], { labels });
assert.deepEqual(calls[3][2], { state: "open", state_reason: "reopened" });
});

test("a reopen with no filing labels skips the label POST, and a 404 on agent-ready is not a failure", async () => {
const calls = [];
const call = async (method, path) => {
calls.push(`${method} ${path}`);
if (method === "DELETE") throw Object.assign(new Error(`${method} ${path}: HTTP 404`), { status: 404 });
return {};
};
const plan = { file: [], comment: [], reopen: [{ number: 12, fingerprint: "cccc", finding: finding() }] };
const result = await writeAll({ plan, call, repo: "o/r", labels: [], runUrl: "u", wait: async () => {} });
assert.deepEqual(result, { filed: [], commented: [], reopened: [12], failed: [] });
assert.deepEqual(calls, [
"POST /repos/o/r/issues/12/comments",
"DELETE /repos/o/r/issues/12/labels/agent-ready",
"PATCH /repos/o/r/issues/12",
]);
});

test("a failed label removal other than 404 is recorded and leaves the issue closed for the next run", async () => {
const fp = "0123456789abcdef";
const issue = { number: 12, state: "closed", state_reason: "completed", body: `x\n<!-- lane-sweep:fp=${fp} -->` };
const calls = [];
const call = async (method, path, body) => {
calls.push(`${method} ${path}`);
if (method === "DELETE") throw Object.assign(new Error(`${method} ${path}: HTTP 500`), { status: 500 });
if (method === "PATCH") Object.assign(issue, body);
return {};
};
const items = [{ fingerprint: fp, finding: finding() }];
const plan = planFiling({ items, existing: [issue], openNumbers: new Set() });
const result = await writeAll({ plan, call, repo: "o/r", labels: [], runUrl: "u", wait: async () => {} });
assert.deepEqual(result.reopened, []);
assert.deepEqual(result.failed, [{ target: "#12", error: "DELETE /repos/o/r/issues/12/labels/agent-ready: HTTP 500" }]);
assert.ok(!calls.includes("PATCH /repos/o/r/issues/12"));
assert.equal(issue.state, "closed");
assert.equal(issue.body, `x\n<!-- lane-sweep:fp=${fp} -->`);
assert.deepEqual(
planFiling({ items, existing: [issue], openNumbers: new Set() }).reopen.map((r) => r.number),
[12],
);
});

test("a failed reopen comment skips its PATCH and is recorded", async () => {
const calls = [];
const call = async (method, path) => {
calls.push(`${method} ${path}`);
if (method === "POST") throw new Error(`${method} ${path}: HTTP 500`);
return {};
};
const plan = { file: [], comment: [], reopen: [{ number: 12, fingerprint: "cccc", finding: finding() }] };
const result = await writeAll({ plan, call, repo: "o/r", labels: [], runUrl: "u", wait: async () => {} });
assert.deepEqual(calls, ["POST /repos/o/r/issues/12/comments"]);
assert.deepEqual(result.failed, [{ target: "#12", error: "POST /repos/o/r/issues/12/comments: HTTP 500" }]);
});
42 changes: 25 additions & 17 deletions .github/scripts/maintenance-audit-lane-runs/findings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { join, normalize } from "node:path";

export const SLICES = new Set(["A", "C", "D"]);
export const MAX_NEW_ISSUES = 5;
const REGRESSION_DAYS = 14;
const MARKER = /^<!-- lane-sweep:fp=([0-9a-f]{16}) -->$/;
const TEXT_FIELDS = ["title", "problem", "root_cause", "proposed_fix", "workflow", "job", "signature"];

Expand Down Expand Up @@ -90,13 +89,11 @@ export const inertTitle = (text) =>
.replace(/@(?=[A-Za-z0-9])/g, "@\u200b")
.replace(/#(?=\d)/g, "#\u200b");

export function renderBody(finding, fp, runUrl, regressionOf = null) {
const claims = finding.evidence.map((c) => `${c.path}:${c.line}: ${c.quote}`).join("\n");
const claimsOf = (finding) => finding.evidence.map((c) => `${c.path}:${c.line}: ${c.quote}`).join("\n");

export function renderBody(finding, fp, runUrl) {
return [
`Filed by the lane sweep ([run](${runUrl})) from slice ${finding.slice}. A model wrote the fenced text below from CI data, which can carry text written to steer it; every cited line was checked against main when filed. Rewrite the issue in your own words before marking it agent-ready.`,
...(regressionOf
? ["", `A finding with the same fingerprint was fixed in #${regressionOf}; this may be a regression.`]
: []),
"",
"## Problem",
"",
Expand All @@ -106,7 +103,7 @@ export function renderBody(finding, fp, runUrl, regressionOf = null) {
"",
fenced(finding.root_cause),
"",
fenced(claims),
fenced(claimsOf(finding)),
"",
"## Proposed fix",
"",
Expand All @@ -120,6 +117,14 @@ export function renderBody(finding, fp, runUrl, regressionOf = null) {
].join("\n");
}

// The comment that reopens a closed issue: the run and the recheck claims.
export const renderReopenComment = (finding, runUrl) =>
[
`Seen again by the lane sweep in [this run](${runUrl}) after this issue was closed, so it is reopened. Every cited line below was checked against main in that run.`,
"",
fenced(claimsOf(finding)),
].join("\n");

// The fingerprint from the body's last line only.
export function readFingerprint(body) {
const last = String(body ?? "")
Expand All @@ -129,16 +134,16 @@ export function readFingerprint(body) {
return MARKER.exec(last ?? "")?.[1] ?? null;
}

// items: [{fingerprint, finding}]; existing: sweep issues (open, and closed in
// the lookback) with body; openNumbers: open issue and PR numbers.
export function planFiling({ items, existing, openNumbers, now, maxNew = MAX_NEW_ISSUES }) {
// items: [{fingerprint, finding}]; existing: sweep issues of any state, with
// no time window, with body; openNumbers: open issue and PR numbers.
export function planFiling({ items, existing, openNumbers, maxNew = MAX_NEW_ISSUES }) {
const byFp = new Map();
for (const issue of existing) {
const fp = readFingerprint(issue.body);
if (fp && !byFp.has(fp)) byFp.set(fp, issue);
if (fp && issue.state === "open") byFp.set(fp, issue);
}
const plan = { file: [], comment: [], skip: [] };
const plan = { file: [], comment: [], reopen: [], skip: [] };
const seen = new Set();
for (const { fingerprint: fp, finding } of items) {
const skip = (reason) => plan.skip.push({ fingerprint: fp, reason });
Expand All @@ -156,20 +161,23 @@ export function planFiling({ items, existing, openNumbers, now, maxNew = MAX_NEW
skip("not-planned");
continue;
}
if (match?.state_reason === "duplicate") {
skip("closed-duplicate");
continue;
}
if (finding.covered_by !== null && openNumbers.has(finding.covered_by)) {
skip("covered");
continue;
}
if (match) {
plan.reopen.push({ number: match.number, fingerprint: fp, finding });
continue;
}
if (plan.file.length >= maxNew) {
skip("cap");
continue;
}
const recent = match && now - new Date(match.closed_at) <= REGRESSION_DAYS * 86_400_000;
plan.file.push({
fingerprint: fp,
finding,
regressionOf: recent ? match.number : null,
});
plan.file.push({ fingerprint: fp, finding });
}
return plan;
}
Loading
Loading