Skip to content

Commit 10d0801

Browse files
committed
fix(repair): single status-check rollup; stale failures no longer block finalization
1 parent e137917 commit 10d0801

8 files changed

Lines changed: 295 additions & 114 deletions

‎src/repair/comment-router-utils.ts‎

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "node:fs";
33
import path from "node:path";
44

55
import type { JsonValue, LooseRecord } from "./json-types.js";
6+
import { rollUpStatusChecks } from "./status-check-rollup.js";
67

78
const PASSING_CHECK_CONCLUSIONS = new Set(["SUCCESS", "SKIPPED", "NEUTRAL"]);
89
const DEFAULT_IGNORED_CHECKS = [
@@ -82,24 +83,24 @@ export function hasSuccessfulDispatchExecutionJob(jobs: LooseRecord[], requiredJ
8283
}
8384

8485
export function summarizeChecks(checks: LooseRecord[]) {
85-
const ignored = ignoredCheckNames();
86-
const latestChecks = latestCheckRuns(checks);
86+
const rolledUpChecks = rollUpStatusChecks(
87+
checks,
88+
process.env.CLAWSWEEPER_COMMENT_ROUTER_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
89+
);
8790
const counts: Record<string, number> = {};
8891
const blockers: LooseRecord[] = [];
8992
const pending: LooseRecord[] = [];
9093
const terminalBlockers: LooseRecord[] = [];
9194
const externalBlockers: LooseRecord[] = [];
9295
let gatingTotal = 0;
93-
for (const check of latestChecks) {
96+
for (const { check, ignored } of rolledUpChecks) {
9497
const name = String(check.name ?? check.context ?? "unknown check");
95-
const workflow = String(check.workflowName ?? "");
96-
const ignoredCheck = ignored.has(name.toLowerCase()) || ignored.has(workflow.toLowerCase());
9798
const status = String(check.status ?? check.state ?? "").toUpperCase();
9899
const conclusion = String(check.conclusion ?? "").toUpperCase();
99100
const externalActionRequired = isExternalActionRequiredCheck(check);
100101
const key = externalActionRequired ? "ACTION_REQUIRED" : conclusion || status || "UNKNOWN";
101102
counts[key] = (counts[key] ?? 0) + 1;
102-
if (ignoredCheck) continue;
103+
if (ignored) continue;
103104
gatingTotal += 1;
104105
if (externalActionRequired) {
105106
const blocker = `${name}:ACTION_REQUIRED`;
@@ -126,7 +127,7 @@ export function summarizeChecks(checks: LooseRecord[]) {
126127
}
127128
}
128129
return {
129-
total: latestChecks.length,
130+
total: rolledUpChecks.length,
130131
gatingTotal,
131132
counts,
132133
blockers,
@@ -144,32 +145,6 @@ function isExternalActionRequiredCheck(check: LooseRecord) {
144145
return false;
145146
}
146147

147-
function latestCheckRuns(checks: LooseRecord[]) {
148-
const byKey = new Map<string, LooseRecord>();
149-
for (const check of checks) {
150-
const key = checkIdentity(check);
151-
const previous = byKey.get(key);
152-
if (!previous || checkTimestamp(check) >= checkTimestamp(previous)) {
153-
byKey.set(key, check);
154-
}
155-
}
156-
return [...byKey.values()];
157-
}
158-
159-
function checkIdentity(check: LooseRecord) {
160-
const name = String(check.name ?? check.context ?? "unknown check").toLowerCase();
161-
const workflow = String(check.workflowName ?? "").toLowerCase();
162-
return `${workflow}\n${name}`;
163-
}
164-
165-
function checkTimestamp(check: LooseRecord) {
166-
for (const field of ["completedAt", "completed_at", "startedAt", "started_at"]) {
167-
const parsed = Date.parse(String(check[field] ?? ""));
168-
if (Number.isFinite(parsed)) return parsed;
169-
}
170-
return 0;
171-
}
172-
173148
export function shouldSuppressProcessedCommentVersion(entry: LooseRecord) {
174149
const status = String(entry.status ?? "").toLowerCase();
175150
if (!["executed", "skipped"].includes(status)) return false;
@@ -504,12 +479,6 @@ function commandRoutingTime(command: LooseRecord) {
504479
return Number.isFinite(created) ? created : 0;
505480
}
506481

507-
function ignoredCheckNames() {
508-
return commaSet(
509-
process.env.CLAWSWEEPER_COMMENT_ROUTER_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
510-
);
511-
}
512-
513482
export function readLedger(file: JsonValue) {
514483
let contents: string;
515484
try {

‎src/repair/finalize-open-prs.ts‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { sleepMs } from "./timing.js";
1818
import { DEFAULT_TARGET_REPO, REPAIR_CLUSTER_WORKFLOW, REVIEW_BOTS } from "./constants.js";
1919
import { numberEnv } from "./env-utils.js";
2020
import { compactText, escapeRegExp } from "./text-utils.js";
21+
import { rollUpStatusChecks } from "./status-check-rollup.js";
2122

2223
const DEFAULT_HEAD_PREFIX = "clawsweeper/";
2324
const PASSING_CHECK_CONCLUSIONS = new Set(["SUCCESS", "SKIPPED", "NEUTRAL"]);
@@ -294,18 +295,18 @@ function summarize(prs: JsonValue) {
294295
}
295296

296297
function summarizeChecks(checks: LooseRecord[]) {
297-
const ignored = ignoredCheckNames();
298+
const rolledUpChecks = rollUpStatusChecks(
299+
checks,
300+
process.env.CLAWSWEEPER_FINALIZER_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
301+
);
298302
const counts: Record<string, number> = {};
299303
const blockers: LooseRecord[] = [];
300-
for (const check of checks) {
301-
const name = String(check.name ?? check.context ?? "unknown check");
302-
const workflow = String(check.workflowName ?? "");
303-
const ignoredCheck = ignored.has(name) || ignored.has(workflow);
304+
for (const { check, ignored } of rolledUpChecks) {
304305
const status = String(check.status ?? check.state ?? "").toUpperCase();
305306
const conclusion = String(check.conclusion ?? "").toUpperCase();
306307
const key = conclusion || status || "UNKNOWN";
307308
counts[key] = (counts[key] ?? 0) + 1;
308-
if (ignoredCheck) continue;
309+
if (ignored) continue;
309310
if (status && !["COMPLETED", "SUCCESS"].includes(status)) {
310311
blockers.push(`${displayCheckName(check)}:${status}`);
311312
continue;
@@ -315,7 +316,7 @@ function summarizeChecks(checks: LooseRecord[]) {
315316
}
316317
}
317318
return {
318-
total: checks.length,
319+
total: rolledUpChecks.length,
319320
counts,
320321
blockers,
321322
};
@@ -713,18 +714,6 @@ function isSecurityRoutedAction(action: LooseRecord) {
713714
);
714715
}
715716

716-
function ignoredCheckNames() {
717-
const configured = String(
718-
process.env.CLAWSWEEPER_FINALIZER_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
719-
);
720-
return new Set(
721-
configured
722-
.split(",")
723-
.map((item: JsonValue) => item.trim())
724-
.filter(Boolean),
725-
);
726-
}
727-
728717
function writeReports(report: LooseRecord) {
729718
const resultsDir = path.join(repoRoot(), "results");
730719
fs.mkdirSync(resultsDir, { recursive: true });

‎src/repair/post-flight.ts‎

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
writeRepairSquashMergeBody,
3232
} from "./repair-merge-message.js";
3333
import { compactText as compactPlainText } from "./text-utils.js";
34+
import { rollUpStatusChecks } from "./status-check-rollup.js";
3435

3536
const PASSING_CHECK_CONCLUSIONS = new Set(["SUCCESS", "SKIPPED", "NEUTRAL"]);
3637
const FIX_PR_MERGE_STATES = new Set(["CLEAN", "HAS_HOOKS", "UNSTABLE"]);
@@ -512,12 +513,11 @@ function validateMergePreflight(preflight: LooseRecord) {
512513

513514
function validateStatusChecks(checks: LooseRecord[]) {
514515
if (!Array.isArray(checks) || checks.length === 0) return "no PR checks found";
515-
const ignored = ignoredCheckNames();
516516
const blockers: LooseRecord[] = [];
517517
let considered = 0;
518-
for (const check of latestCheckRuns(checks)) {
518+
for (const { check, ignored } of postFlightStatusCheckRollup(checks)) {
519519
const name = String(check.name ?? check.context ?? "unknown check");
520-
if (isIgnoredStatusCheck(check, ignored)) continue;
520+
if (ignored) continue;
521521
considered += 1;
522522
const status = String(check.status ?? check.state ?? "").toUpperCase();
523523
const conclusion = String(check.conclusion ?? "").toUpperCase();
@@ -552,49 +552,17 @@ function shouldWaitForIssueImplementationChecks(checkBlock: string, view: LooseR
552552
}
553553

554554
function hasPendingChecks(checks: LooseRecord[]) {
555-
const ignored = ignoredCheckNames();
556-
return latestCheckRuns(checks ?? []).some((check: JsonValue) => {
557-
if (isIgnoredStatusCheck(check, ignored)) return false;
555+
return postFlightStatusCheckRollup(checks ?? []).some(({ check, ignored }) => {
556+
if (ignored) return false;
558557
return isPendingStatusCheck(check);
559558
});
560559
}
561560

562-
function isIgnoredStatusCheck(check: LooseRecord, ignored: Set<string>) {
563-
const name = String(check.name ?? check.context ?? "unknown check").toLowerCase();
564-
const workflow = String(check.workflowName ?? "").toLowerCase();
565-
return ignored.has(name) || Boolean(workflow && ignored.has(workflow));
566-
}
567-
568-
function latestCheckRuns(checks: LooseRecord[]) {
569-
const byKey = new Map<string, LooseRecord>();
570-
for (const check of checks) {
571-
const key = checkIdentity(check);
572-
const previous = byKey.get(key);
573-
if (!previous || checkTimestamp(check) >= checkTimestamp(previous)) byKey.set(key, check);
574-
}
575-
return [...byKey.values()];
576-
}
577-
578-
function checkIdentity(check: LooseRecord) {
579-
const name = String(check.name ?? check.context ?? "unknown check").toLowerCase();
580-
const workflow = String(check.workflowName ?? "").toLowerCase();
581-
return `${workflow}\n${name}`;
582-
}
583-
584-
function checkTimestamp(check: LooseRecord) {
585-
for (const field of [
586-
"startedAt",
587-
"started_at",
588-
"createdAt",
589-
"created_at",
590-
"completedAt",
591-
"completed_at",
592-
]) {
593-
const parsed = Date.parse(String(check[field] ?? ""));
594-
if (Number.isFinite(parsed)) return parsed;
595-
}
596-
if (isPendingStatusCheck(check)) return Number.MAX_SAFE_INTEGER;
597-
return 0;
561+
function postFlightStatusCheckRollup(checks: LooseRecord[]) {
562+
return rollUpStatusChecks(
563+
checks,
564+
process.env.CLAWSWEEPER_POST_FLIGHT_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
565+
);
598566
}
599567

600568
function isPendingStatusCheck(check: LooseRecord) {
@@ -603,19 +571,6 @@ function isPendingStatusCheck(check: LooseRecord) {
603571
return !conclusion && Boolean(status) && !["COMPLETED", "SUCCESS"].includes(status);
604572
}
605573

606-
function ignoredCheckNames() {
607-
const configured = String(
608-
process.env.CLAWSWEEPER_POST_FLIGHT_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS.join(","),
609-
);
610-
return new Set(
611-
configured
612-
.split(",")
613-
.map((item: JsonValue) => item.trim())
614-
.map((item: string) => item.toLowerCase())
615-
.filter(Boolean),
616-
);
617-
}
618-
619574
function shouldRequirePrChecks() {
620575
return process.env.CLAWSWEEPER_POST_FLIGHT_REQUIRE_PR_CHECKS === "1";
621576
}

‎src/repair/status-check-rollup.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import type { JsonValue, LooseRecord } from "./json-types.js";
2+
3+
export interface RolledUpStatusCheck {
4+
check: LooseRecord;
5+
ignored: boolean;
6+
}
7+
8+
export function rollUpStatusChecks(
9+
checks: LooseRecord[],
10+
ignoredNames: JsonValue,
11+
): RolledUpStatusCheck[] {
12+
const ignored = parseIgnoredStatusCheckNames(ignoredNames);
13+
const latestByIdentity = new Map<string, LooseRecord>();
14+
for (const check of checks) {
15+
const identity = statusCheckIdentity(check);
16+
const previous = latestByIdentity.get(identity);
17+
if (!previous || statusCheckTimestamp(check) >= statusCheckTimestamp(previous)) {
18+
latestByIdentity.set(identity, check);
19+
}
20+
}
21+
return [...latestByIdentity.values()].map((check) => ({
22+
check,
23+
ignored: ignored.has(statusCheckName(check)) || ignored.has(statusCheckWorkflow(check)),
24+
}));
25+
}
26+
27+
function parseIgnoredStatusCheckNames(value: JsonValue) {
28+
return new Set(
29+
String(value ?? "")
30+
.split(",")
31+
.map((item: string) => item.trim().toLowerCase())
32+
.filter(Boolean),
33+
);
34+
}
35+
36+
function statusCheckIdentity(check: LooseRecord) {
37+
return `${statusCheckWorkflow(check)}\n${statusCheckName(check)}`;
38+
}
39+
40+
function statusCheckName(check: LooseRecord) {
41+
return String(check.name ?? check.context ?? "unknown check").toLowerCase();
42+
}
43+
44+
function statusCheckWorkflow(check: LooseRecord) {
45+
return String(check.workflowName ?? "").toLowerCase();
46+
}
47+
48+
function statusCheckTimestamp(check: LooseRecord) {
49+
for (const field of [
50+
"startedAt",
51+
"started_at",
52+
"createdAt",
53+
"created_at",
54+
"completedAt",
55+
"completed_at",
56+
]) {
57+
const parsed = Date.parse(String(check[field] ?? ""));
58+
if (Number.isFinite(parsed)) return parsed;
59+
}
60+
return isPendingStatusCheck(check) ? Number.MAX_SAFE_INTEGER : 0;
61+
}
62+
63+
function isPendingStatusCheck(check: LooseRecord) {
64+
const status = String(check.status ?? check.state ?? "").toUpperCase();
65+
const conclusion = String(check.conclusion ?? "").toUpperCase();
66+
return !conclusion && Boolean(status) && !["COMPLETED", "SUCCESS"].includes(status);
67+
}

‎test/repair/comment-router-utils.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,45 @@ test("summarizeChecks uses the latest run for duplicate check names", () => {
15501550
assert.equal(checks.counts.SUCCESS, 2);
15511551
});
15521552

1553+
test("router status policy keeps representative decisions across the shared rollup", () => {
1554+
const checks = summarizeChecks([
1555+
{
1556+
name: "auto-response",
1557+
workflowName: "Auto Response",
1558+
status: "COMPLETED",
1559+
conclusion: "CANCELLED",
1560+
},
1561+
{
1562+
name: "queued",
1563+
workflowName: "CI",
1564+
status: "IN_PROGRESS",
1565+
conclusion: null,
1566+
},
1567+
{
1568+
name: "failed",
1569+
workflowName: "CI",
1570+
status: "COMPLETED",
1571+
conclusion: "FAILURE",
1572+
},
1573+
{
1574+
name: "passed",
1575+
workflowName: "CI",
1576+
status: "COMPLETED",
1577+
conclusion: "SUCCESS",
1578+
},
1579+
]);
1580+
1581+
assert.deepEqual(checks, {
1582+
total: 4,
1583+
gatingTotal: 3,
1584+
counts: { CANCELLED: 1, IN_PROGRESS: 1, FAILURE: 1, SUCCESS: 1 },
1585+
blockers: ["queued:IN_PROGRESS", "failed:FAILURE"],
1586+
pending: ["queued:IN_PROGRESS"],
1587+
terminalBlockers: ["failed:FAILURE"],
1588+
externalBlockers: [],
1589+
});
1590+
});
1591+
15531592
test("skipped automerge ledger entries stay retryable", () => {
15541593
assert.equal(
15551594
shouldSuppressProcessedCommentVersion({

0 commit comments

Comments
 (0)