forgedock 1.67.0 → 1.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +1 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +103 -21
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +39 -15
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.mjs +11 -1
- package/bin/lean/batch.test.mjs +51 -2
- package/bin/lean/capsample.mjs +25 -0
- package/bin/lean/ci-gate.mjs +2 -90
- package/bin/lean/ci-gate.test.mjs +1 -127
- package/bin/lean/ci-precheck.mjs +25 -8
- package/bin/lean/ci-precheck.test.mjs +24 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +62 -197
- package/bin/lean/conformance.test.mjs +46 -376
- package/bin/lean/depcache.mjs +102 -10
- package/bin/lean/depcache.test.mjs +105 -0
- package/bin/lean/docsgate.mjs +0 -32
- package/bin/lean/docsgate.test.mjs +2 -23
- package/bin/lean/effects-cap.test.mjs +9 -1
- package/bin/lean/effects-killtree.test.mjs +35 -0
- package/bin/lean/effects.mjs +57 -25
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +111 -0
- package/bin/lean/envgap.test.mjs +64 -0
- package/bin/lean/execution.mjs +13 -4
- package/bin/lean/execution.test.mjs +33 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/failure-stop.mjs +12 -1
- package/bin/lean/failure-stop.test.mjs +14 -1
- package/bin/lean/guardgate.test.mjs +2 -3
- package/bin/lean/heavy.mjs +33 -4
- package/bin/lean/heavy.test.mjs +38 -6
- package/bin/lean/hostconfig.mjs +54 -0
- package/bin/lean/hostconfig.test.mjs +67 -0
- package/bin/lean/hotarea.mjs +0 -36
- package/bin/lean/hotarea.test.mjs +1 -22
- package/bin/lean/issuewatch-verify.mjs +19 -4
- package/bin/lean/issuewatch.mjs +21 -4
- package/bin/lean/issuewatch.test.mjs +48 -1
- package/bin/lean/lane-audit-gap.mjs +66 -0
- package/bin/lean/lane-audit-gap.test.mjs +59 -0
- package/bin/lean/lane-audit-llm.mjs +52 -0
- package/bin/lean/lane-audit-llm.test.mjs +57 -0
- package/bin/lean/lane-audit-query.mjs +47 -0
- package/bin/lean/lane-audit-query.test.mjs +44 -0
- package/bin/lean/lane-audit-signatures.mjs +33 -0
- package/bin/lean/lane-audit.mjs +110 -0
- package/bin/lean/lane-audit.test.mjs +97 -0
- package/bin/lean/lane-recovery.test.mjs +33 -0
- package/bin/lean/lanecheck.mjs +5 -3
- package/bin/lean/lanecheck.test.mjs +6 -0
- package/bin/lean/lean.mjs +247 -152
- package/bin/lean/lean.test.mjs +502 -206
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +24 -2
- package/bin/lean/live-execution.test.mjs +62 -0
- package/bin/lean/orchestrate-attempts.test.mjs +17 -9
- package/bin/lean/orchestrate-dispatch-placement.test.mjs +81 -0
- package/bin/lean/orchestrate-envhold.test.mjs +62 -1
- package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
- package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
- package/bin/lean/orchestrate-pause.test.mjs +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
- package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
- package/bin/lean/orchestrate-stacking.test.mjs +10 -0
- package/bin/lean/orchestrate.mjs +215 -42
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +110 -14
- package/bin/lean/preflight.test.mjs +64 -4
- package/bin/lean/prompts.mjs +11 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- package/bin/lean/release-deploy.mjs +35 -5
- package/bin/lean/release-deploy.test.mjs +50 -3
- package/bin/lean/release-flakes.mjs +48 -2
- package/bin/lean/release-flakes.test.mjs +45 -1
- package/bin/lean/release-ledger.mjs +19 -1
- package/bin/lean/release-ledger.test.mjs +23 -0
- package/bin/lean/release-preflight.mjs +28 -0
- package/bin/lean/release-preflight.test.mjs +42 -1
- package/bin/lean/release-review.mjs +40 -5
- package/bin/lean/release-review.test.mjs +43 -2
- package/bin/lean/release.mjs +45 -15
- package/bin/lean/release.test.mjs +32 -0
- package/bin/lean/retry.mjs +1 -1
- package/bin/lean/retry.test.mjs +6 -1
- package/bin/lean/rotator.mjs +9 -0
- package/bin/lean/rotator.test.mjs +11 -1
- package/bin/lean/sandbox-remote.mjs +51 -13
- package/bin/lean/schedd.mjs +13 -8
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +247 -23
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +56 -9
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/image-manifest.mjs +24 -0
- package/bin/pool/image-manifest.test.mjs +20 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +29 -5
- package/bin/pool/lane-tools.test.mjs +36 -7
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/project-layer.mjs +142 -0
- package/bin/pool/project-layer.test.mjs +73 -0
- package/bin/pool/router.mjs +106 -36
- package/bin/pool/version.mjs +72 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/release.mjs +7 -0
- package/bin/stats/release.test.mjs +20 -0
- package/bin/stats/scorecard.mjs +187 -0
- package/bin/stats/scorecard.test.mjs +89 -0
- package/bin/stats/tool-parks.mjs +29 -0
- package/bin/stats/tool-parks.test.mjs +21 -0
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +15 -3
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +14 -2
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
package/bin/lean/recurrence.mjs
CHANGED
|
@@ -1,51 +1,23 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Deterministic: zero LLM calls. The engine's inputs are subjectHistory rows (context.mjs) and the merged PRs' file lists.
|
|
4
|
+
* forge.yaml `recurrence.hot_areas` (#5751): areas where one lane at a time may work (branch lock), and `pathsOverlap`.
|
|
5
|
+
* The recurrence design routing (symptom/area detection, design lane, design block requirement) was cut in #6083: it had no
|
|
6
|
+
* measured catch and 15 parks on 11 issues in 25 days.
|
|
8
7
|
*/
|
|
9
|
-
import { OUTCOME_CODES as C } from "../engine/outcome-codes.mjs";
|
|
10
|
-
import { subjectHistory } from "./context.mjs";
|
|
11
|
-
|
|
12
|
-
export const RECURRENCE_DEFAULTS = Object.freeze({ mode: "on", threshold: 2 });
|
|
13
|
-
/** At most this many merged rows have their file lists read (one GitHub call each). */
|
|
14
|
-
export const MAX_RECURRENCE_ROWS = 6;
|
|
15
|
-
|
|
16
8
|
const clean = (p) => String(p ?? "").trim().replace(/^\.?\/+/, "").replace(/\/+$/, "");
|
|
17
9
|
const list = (v) => (Array.isArray(v) ? v : typeof v === "string" ? v.split(",") : []).map((x) => String(x).trim()).filter(Boolean);
|
|
18
|
-
const COUNTER_SEP = " -- "; // `pattern -- glob, glob`: the git grep pathspec separator
|
|
19
10
|
|
|
20
11
|
/**
|
|
21
|
-
* forge.yaml `recurrence
|
|
22
|
-
* {
|
|
23
|
-
* @returns {{mode:"on"|"off", threshold:number, hotAreas:{name:string, paths:string[]}[], counters:{name:string, pattern:string, paths:string[]}[]}}
|
|
12
|
+
* forge.yaml `recurrence:`: `hot_areas` is a list of {name, paths} or a block map {name: "glob, glob"}.
|
|
13
|
+
* @returns {{hotAreas:{name:string, paths:string[]}[]}}
|
|
24
14
|
*/
|
|
25
15
|
export function parseRecurrenceConfig(raw) {
|
|
26
16
|
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
27
|
-
const m = String(r.mode ?? "").trim().toLowerCase();
|
|
28
|
-
const mode = r.mode === false || m === "off" || m === "false" ? "off" : RECURRENCE_DEFAULTS.mode;
|
|
29
|
-
const t = Number(r.threshold);
|
|
30
|
-
const threshold = Number.isInteger(t) && t >= 1 ? t : RECURRENCE_DEFAULTS.threshold;
|
|
31
17
|
const rows = (v) => (Array.isArray(v) ? v : v && typeof v === "object" ? Object.entries(v).map(([name, val]) => ({ name, val })) : []);
|
|
32
18
|
const hotAreas = rows(r.hot_areas).map((x) => ({ name: String(x?.name ?? "").trim(), paths: list(x?.paths ?? x?.val).map(clean) }))
|
|
33
19
|
.filter((a) => a.name && a.paths.length);
|
|
34
|
-
|
|
35
|
-
if (x?.val !== undefined) {
|
|
36
|
-
const s = String(x.val), i = s.lastIndexOf(COUNTER_SEP);
|
|
37
|
-
return { name: String(x.name).trim(), pattern: (i >= 0 ? s.slice(0, i) : s).trim(), paths: i >= 0 ? list(s.slice(i + COUNTER_SEP.length)).map(clean) : [] };
|
|
38
|
-
}
|
|
39
|
-
return { name: String(x?.name ?? "").trim(), pattern: String(x?.pattern ?? "").trim(), paths: list(x?.paths).map(clean) };
|
|
40
|
-
}).filter((c) => c.name && c.pattern);
|
|
41
|
-
return { mode, threshold, hotAreas, counters };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Issue numbers named by `Recurs #n` (also `Recurs: #n`, `Recurs of #n`, `Recurs #n, #m`). */
|
|
45
|
-
export function recursLinks(body = "") {
|
|
46
|
-
const out = new Set();
|
|
47
|
-
for (const m of String(body ?? "").matchAll(/\brecurs(?:\s+of)?\s*:?\s*((?:#\d+[\s,]*(?:and\s+)?)+)/gi)) for (const n of m[1].matchAll(/#(\d+)/g)) out.add(Number(n[1]));
|
|
48
|
-
return [...out].filter((n) => Number.isSafeInteger(n) && n > 0);
|
|
20
|
+
return { hotAreas };
|
|
49
21
|
}
|
|
50
22
|
|
|
51
23
|
/** Two paths overlap when they are equal or one is a directory prefix of the other. */
|
|
@@ -53,117 +25,3 @@ export function pathsOverlap(a, b) {
|
|
|
53
25
|
const x = clean(a), y = clean(b);
|
|
54
26
|
return Boolean(x && y) && (x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`));
|
|
55
27
|
}
|
|
56
|
-
|
|
57
|
-
/** #5979: backticked error/outcome-code/test signatures of the issue body (identifier-shaped, not a path). */
|
|
58
|
-
function symptomTerms(body) {
|
|
59
|
-
return [...new Set([...String(body ?? "").matchAll(/`([A-Za-z][\w.:-]{3,79})`/g)].map((m) => m[1].toLowerCase()).filter((t) => !/\.(?:m?[jt]sx?|md|json|ya?ml|py|sh)$/.test(t)))];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** #5979: a subjectHistory row shares the issue's symptom: it matched on a code-shaped term (outcome code, error name, symbol), on two or more terms, or its title carries a backticked signature of the issue. */
|
|
63
|
-
function symptomMatch(row, terms) {
|
|
64
|
-
const m = (row?.matched ?? []).map(String);
|
|
65
|
-
return m.some((t) => /[._:-]|\d|[a-z][A-Z]|^[A-Z0-9_]{3,}$/.test(t)) || m.length >= 2 || terms.some((t) => String(row?.title ?? "").toLowerCase().includes(t));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Count earlier merged fixes on the same symptom and the same area. A subjectHistory row counts when it is a merged PR
|
|
70
|
-
* whose files (`mergedPrFiles[number]`) overlap a path the issue names AND that shares the symptom (#5979: path-only overlap never counts). A `Recurs #n` link is an explicit symptom match:
|
|
71
|
-
* it counts when its files overlap or are unknown (the author declared the same area). Rows without overlap never count.
|
|
72
|
-
* @returns {{recurs:boolean, count:number, threshold:number, evidence:{number:number, title:string, via:string, paths:string[]}[], reason:string}}
|
|
73
|
-
*/
|
|
74
|
-
export function detectRecurrence({ rows = [], mergedPrFiles = {}, body = "", namedPaths = [], threshold = RECURRENCE_DEFAULTS.threshold } = {}) {
|
|
75
|
-
const named = [...new Set((namedPaths ?? []).map(clean).filter(Boolean))];
|
|
76
|
-
const filesOf = (n) => (mergedPrFiles instanceof Map ? mergedPrFiles.get(n) : mergedPrFiles?.[n]);
|
|
77
|
-
const evidence = [], seen = new Set();
|
|
78
|
-
const sym = symptomTerms(body);
|
|
79
|
-
for (const r of rows ?? []) {
|
|
80
|
-
const n = Number(r?.number);
|
|
81
|
-
if (!Number.isSafeInteger(n) || seen.has(n) || r?.kind !== "PR" || r?.status !== "merged") continue;
|
|
82
|
-
if (!symptomMatch(r, sym)) continue; // #5979: path overlap alone is the same area, not the same symptom
|
|
83
|
-
const paths = (filesOf(n) ?? []).map(clean).filter((f) => named.some((p) => pathsOverlap(f, p)));
|
|
84
|
-
if (!paths.length) continue;
|
|
85
|
-
seen.add(n);
|
|
86
|
-
evidence.push({ number: n, title: String(r.title ?? ""), via: `subject (${(r.matched ?? []).join(", ")})`, paths: [...new Set(paths)] });
|
|
87
|
-
}
|
|
88
|
-
for (const n of recursLinks(body)) {
|
|
89
|
-
if (seen.has(n)) continue;
|
|
90
|
-
const files = filesOf(n);
|
|
91
|
-
const paths = Array.isArray(files) ? files.map(clean).filter((f) => named.some((p) => pathsOverlap(f, p))) : null;
|
|
92
|
-
if (paths && !paths.length) continue;
|
|
93
|
-
seen.add(n);
|
|
94
|
-
evidence.push({ number: n, title: "", via: "Recurs link", paths: paths ?? [] });
|
|
95
|
-
}
|
|
96
|
-
const t = Number.isInteger(threshold) && threshold >= 1 ? threshold : RECURRENCE_DEFAULTS.threshold;
|
|
97
|
-
const count = evidence.length, recurs = count >= t;
|
|
98
|
-
const reason = recurs
|
|
99
|
-
? `recurrence: ${count} earlier merged fix(es) on the same symptom and area (threshold ${t}): ${evidence.map((e) => `#${e.number}${e.paths.length ? ` (${e.paths.slice(0, 3).join(", ")})` : ""}`).join(", ")}`
|
|
100
|
-
: "";
|
|
101
|
-
return { recurs, count, threshold: t, evidence, reason };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** #6016: a staging->default release PR head (`release/...`). */
|
|
105
|
-
export const isReleaseHead = (ref) => /^release\//.test(String(ref ?? ""));
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The engine-side gather: subjectHistory rows plus one file-list read per merged row (capped). `io`: {gh, git}. Never
|
|
109
|
-
* throws: a failed source contributes nothing and lands in `errors`.
|
|
110
|
-
*/
|
|
111
|
-
export async function recurrenceFacts({ io, repo, issue, title = "", body = "", base = null, namedPaths = [], threshold, exclude = [], createdAt = null }) {
|
|
112
|
-
const errors = [];
|
|
113
|
-
let rows = [];
|
|
114
|
-
try { const h = await subjectHistory({ io, repo, issue, title, body, base, exclude }); rows = h.rows ?? []; errors.push(...(h.errors ?? [])); } catch (e) { errors.push(`recurrence: ${String(e?.message ?? e).slice(0, 80)}`); }
|
|
115
|
-
// #6016: a release PR (head release/*) touches every shipped file, and a PR merged after the issue was filed cannot be an
|
|
116
|
-
// earlier fix that did not hold: neither is evidence. A row whose metadata cannot be read stays (explicit Recurs links too).
|
|
117
|
-
const created = Date.parse(createdAt ?? "");
|
|
118
|
-
const notEvidence = new Set();
|
|
119
|
-
for (const r of rows.filter((x) => x?.kind === "PR" && x?.status === "merged").slice(0, MAX_RECURRENCE_ROWS)) {
|
|
120
|
-
try {
|
|
121
|
-
const m = JSON.parse(String(await io.gh(["api", `repos/${repo}/pulls/${Number(r.number)}`, "--jq", "{head: .head.ref, merged: .merged_at}"])));
|
|
122
|
-
if (isReleaseHead(m?.head) || (Number.isFinite(created) && Date.parse(m?.merged ?? "") > created)) notEvidence.add(Number(r.number));
|
|
123
|
-
} catch { /* unreadable: keep the row */ }
|
|
124
|
-
}
|
|
125
|
-
rows = rows.filter((r) => !notEvidence.has(Number(r?.number)));
|
|
126
|
-
const wanted = [...new Set([...rows.filter((r) => r?.kind === "PR" && r?.status === "merged").map((r) => Number(r.number)), ...recursLinks(body)])].slice(0, MAX_RECURRENCE_ROWS);
|
|
127
|
-
const mergedPrFiles = {};
|
|
128
|
-
if (namedPaths.length) {
|
|
129
|
-
for (const n of wanted) {
|
|
130
|
-
try {
|
|
131
|
-
const out = String(await io.gh(["api", `repos/${repo}/pulls/${n}/files`, "--paginate", "--jq", ".[].filename"]));
|
|
132
|
-
mergedPrFiles[n] = out.split("\n").map((x) => x.trim()).filter(Boolean);
|
|
133
|
-
} catch { /* not a PR (an issue link) or unreadable: unknown files */ }
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return { ...detectRecurrence({ rows, mergedPrFiles, body, namedPaths, threshold }), errors };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** The design lane's plan instruction (#5751): why the earlier fixes failed, delete or replace, a measurable outcome. */
|
|
140
|
-
export function designLaneNote(detection) {
|
|
141
|
-
if (!detection?.recurs) return "";
|
|
142
|
-
const ev = detection.evidence.map((e) => `- #${e.number}${e.title ? ` ${e.title}` : ""} [${e.via}]${e.paths.length ? `: ${e.paths.join(", ")}` : ""}`).join("\n");
|
|
143
|
-
return `\n\nDESIGN LANE (#5751): this issue recurs. ${detection.count} earlier merged fix(es) hit the same symptom in the same area:\n${ev}\nDo not add another patch on top of them. Read each earlier fix (gh pr view N, git show) as an active input, then put a "design" object in .forge-lean/contract.json:
|
|
144
|
-
{"design":{"why_failed":"<why the earlier fixes did not hold, naming them>","disposition":"delete|replace|extend","outcome":{"metric":"<what is measured>","target":"<the value that shows it held>"}}}
|
|
145
|
-
Prefer "delete" or "replace" of the earlier fixes; "extend" needs its reason in why_failed. The outcome needs a validate (test, counter or check) that measures it. When the redesign is too big for one lane, decompose it into ordinary lanes with the split-required block.`;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** #5751: a design lane's contract must carry design {why_failed, disposition delete|replace|extend, outcome {metric, target}}. */
|
|
149
|
-
export function designContractFailures(contract, detection) {
|
|
150
|
-
if (!detection?.recurs) return [];
|
|
151
|
-
// #5918/#5979: a design block is demanded once. Asked for on an earlier run and still absent, it is not demanded again: the repeat parks (failure.repeated) for a decision.
|
|
152
|
-
if (detection.demanded) {
|
|
153
|
-
const d0 = contract?.design;
|
|
154
|
-
if (d0 && typeof d0 === "object" && !Array.isArray(d0)) return designContractFailures(contract, { ...detection, demanded: false });
|
|
155
|
-
return [{ code: C.FAILURE_REPEATED, kind: "design_missing_repeated", detail: `recurring issue (${detection.count} earlier fixes): the design block was already demanded on an earlier run and is still missing; parked for a decision instead of demanding it again` }];
|
|
156
|
-
}
|
|
157
|
-
const d = contract?.design, problems = [];
|
|
158
|
-
const s = (v) => typeof v === "string" && v.trim();
|
|
159
|
-
if (!d || typeof d !== "object" || Array.isArray(d)) problems.push("no design block");
|
|
160
|
-
else {
|
|
161
|
-
if (!s(d.why_failed)) problems.push("design.why_failed is empty");
|
|
162
|
-
if (!["delete", "replace", "extend"].includes(String(d.disposition ?? "").trim())) problems.push("design.disposition is not delete, replace or extend");
|
|
163
|
-
if (!s(d.outcome?.metric) || !(s(d.outcome?.target) || Number.isFinite(d.outcome?.target))) problems.push("design.outcome needs a metric and a target");
|
|
164
|
-
}
|
|
165
|
-
return problems.length ? [{ code: C.RECURRENCE_DESIGN_MISSING, kind: "design_missing", detail: `recurring issue (${detection.count} earlier fixes) routed to a design lane: ${problems.join("; ")}` }] : [];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** #5979: true when an earlier NEEDS_HUMAN/PARKED comment of the issue already reported the missing design block. */
|
|
169
|
-
export const designDemanded = (comments) => (Array.isArray(comments) ? comments : []).some((c) => /<!--\s*FORGE:(?:NEEDS_HUMAN|PARKED)/.test(String(c?.body ?? "")) && /routed to a design lane:/.test(String(c?.body ?? "")));
|
|
@@ -2,153 +2,17 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { parseRecurrenceConfig,
|
|
5
|
+
import { parseRecurrenceConfig, pathsOverlap } from "./recurrence.mjs";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
assert.deepEqual(parseRecurrenceConfig(
|
|
13
|
-
});
|
|
14
|
-
it("
|
|
15
|
-
|
|
16
|
-
assert.
|
|
17
|
-
assert.equal(c.threshold, 3);
|
|
18
|
-
assert.deepEqual(c.hotAreas, [{ name: "billing", paths: ["src/billing/**", "src/pay.js"] }]);
|
|
19
|
-
assert.deepEqual(c.counters, [{ name: "flags", pattern: "FLAG_[A-Z]+", paths: ["src/**"] }]);
|
|
20
|
-
assert.deepEqual(parseRecurrenceConfig({ counters: { exports: "^export (a|b) -- bin/*.mjs" } }).counters, [{ name: "exports", pattern: "^export (a|b)", paths: ["bin/*.mjs"] }]);
|
|
21
|
-
assert.equal(parseRecurrenceConfig({ mode: false, threshold: 0 }).mode, "off");
|
|
22
|
-
assert.equal(parseRecurrenceConfig({ threshold: 0 }).threshold, 2, "an invalid threshold keeps the default");
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("recurrence detection (#5751)", () => {
|
|
27
|
-
it("two merged fixes on the same symptom touching a named path route to a design lane and record the reason", () => {
|
|
28
|
-
const d = detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: ["src/billing/reserve.js"], 11: ["src/billing/reserve.js", "README.md"] }, namedPaths: NAMED });
|
|
29
|
-
assert.equal(d.recurs, true);
|
|
30
|
-
assert.equal(d.count, 2);
|
|
31
|
-
assert.deepEqual(d.evidence.map((e) => e.number), [10, 11]);
|
|
32
|
-
assert.match(d.reason, /^recurrence: 2 earlier merged fix\(es\) on the same symptom and area \(threshold 2\): #10 \(src\/billing\/reserve\.js\), #11/);
|
|
33
|
-
});
|
|
34
|
-
it("one matching fix does not route", () => {
|
|
35
|
-
const d = detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, namedPaths: NAMED });
|
|
36
|
-
assert.equal(d.recurs, false);
|
|
37
|
-
assert.equal(d.count, 1);
|
|
38
|
-
assert.equal(d.reason, "");
|
|
39
|
-
});
|
|
40
|
-
it("symptom matches without path overlap, unmerged rows and issues do not count", () => {
|
|
41
|
-
const d = detectRecurrence({ rows: [row(10), row(11), row(12, { status: "closed unmerged" }), row(13, { kind: "issue", status: "completed" })],
|
|
42
|
-
mergedPrFiles: { 10: ["src/other.js"], 11: ["docs/x.md"], 12: NAMED, 13: NAMED }, namedPaths: NAMED });
|
|
43
|
-
assert.equal(d.recurs, false);
|
|
44
|
-
assert.equal(d.count, 0);
|
|
45
|
-
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: [] }).recurs, false, "an issue naming no path has no area");
|
|
46
|
-
});
|
|
47
|
-
it("a directory named by the issue overlaps the files under it", () => {
|
|
48
|
-
assert.equal(pathsOverlap("src/billing/reserve.js", "src/billing"), true);
|
|
49
|
-
assert.equal(pathsOverlap("src/billingx.js", "src/billing"), false);
|
|
50
|
-
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: ["src/billing/a.js"], 11: ["src/billing/b.js"] }, namedPaths: ["src/billing/"] }).recurs, true);
|
|
51
|
-
});
|
|
52
|
-
it("Recurs #n links count: unknown files are the author's declaration, files elsewhere are not", () => {
|
|
53
|
-
assert.deepEqual(recursLinks("Recurs #10, #11\nalso recurs of #12 and Recurs: #13"), [10, 11, 12, 13]);
|
|
54
|
-
const d = detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, body: "Recurs #10, #20", namedPaths: NAMED });
|
|
55
|
-
assert.equal(d.count, 2, "#10 counts once; #20 (files unknown) counts");
|
|
56
|
-
assert.deepEqual(d.evidence.map((e) => [e.number, e.via]), [[10, "subject (reservation, leak)"], [20, "Recurs link"]]);
|
|
57
|
-
assert.equal(detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED, 21: ["elsewhere.js"] }, body: "Recurs #21", namedPaths: NAMED }).recurs, false);
|
|
58
|
-
});
|
|
59
|
-
it("the threshold is configurable", () => {
|
|
60
|
-
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: NAMED, threshold: 3 }).recurs, false);
|
|
61
|
-
assert.equal(detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, namedPaths: NAMED, threshold: 1 }).recurs, true);
|
|
62
|
-
});
|
|
63
|
-
it("recurrenceFacts reads subject history and each merged PR's files, with no LLM call", async () => {
|
|
64
|
-
const calls = [];
|
|
65
|
-
const gh = async (a) => {
|
|
66
|
-
calls.push(a.join(" "));
|
|
67
|
-
if (a.includes("search/issues")) return [10, 11].map((n) => JSON.stringify({ number: n, title: `fix ${n}`, pr: true, merged: true })).join("\n");
|
|
68
|
-
const m = /pulls\/(\d+)\/files/.exec(a.join(" "));
|
|
69
|
-
if (m) return m[1] === "10" ? "src/billing/reserve.js\n" : "src/billing/reserve.js\nx.md\n";
|
|
70
|
-
throw new Error("unexpected");
|
|
71
|
-
};
|
|
72
|
-
const d = await recurrenceFacts({ io: { gh }, repo: "o/r", issue: 7, title: "reservation leak on 429", body: "See src/billing/reserve.js", namedPaths: NAMED, threshold: 2 });
|
|
73
|
-
assert.equal(d.recurs, true);
|
|
74
|
-
assert.deepEqual(d.evidence.map((e) => e.number), [11, 10]);
|
|
75
|
-
assert.ok(calls.some((c) => c.includes("pulls/10/files")) && calls.some((c) => c.includes("pulls/11/files")));
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("recurrence evidence excludes release PRs and later merges (#6016)", () => {
|
|
80
|
-
const gh = (meta) => async (a) => {
|
|
81
|
-
const j = a.join(" ");
|
|
82
|
-
if (j.includes("search/issues")) return [10, 11, 12].map((n) => JSON.stringify({ number: n, title: `pr ${n}`, pr: true, merged: true })).join("\n");
|
|
83
|
-
const f = /pulls\/(\d+)\/files/.exec(j); if (f) return "src/billing/reserve.js\n";
|
|
84
|
-
const m = /pulls\/(\d+)$/.exec(a[1] ?? ""); if (m) return JSON.stringify(meta[m[1]]);
|
|
85
|
-
throw new Error("unexpected " + j);
|
|
86
|
-
};
|
|
87
|
-
it("a release PR and a PR merged after the issue was filed are not earlier fixes", async () => {
|
|
88
|
-
const meta = { 10: { head: "release/20261123-1", merged: "2026-11-01T00:00:00Z" }, 11: { head: "feat/x", merged: "2026-11-20T00:00:00Z" }, 12: { head: "feat/y", merged: "2026-11-02T00:00:00Z" } };
|
|
89
|
-
const d = await recurrenceFacts({ io: { gh: gh(meta) }, repo: "o/r", issue: 7, title: "reservation leak", body: "See src/billing/reserve.js", namedPaths: NAMED, threshold: 2, createdAt: "2026-11-10T00:00:00Z" });
|
|
90
|
-
assert.deepEqual(d.evidence.map((e) => e.number), [12]);
|
|
91
|
-
assert.equal(d.recurs, false);
|
|
92
|
-
});
|
|
93
|
-
it("isReleaseHead matches only release/ heads", () => {
|
|
94
|
-
assert.equal(isReleaseHead("release/1"), true);
|
|
95
|
-
assert.equal(isReleaseHead("feat/release/1"), false);
|
|
96
|
-
assert.equal(isReleaseHead(null), false);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("design lane (#5751)", () => {
|
|
101
|
-
const det = detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: NAMED });
|
|
102
|
-
it("the plan note names the earlier fixes and asks why they failed, delete or replace, a measurable outcome and allows a split", () => {
|
|
103
|
-
const n = designLaneNote(det);
|
|
104
|
-
assert.match(n, /DESIGN LANE/);
|
|
105
|
-
assert.match(n, /#10 fix leak 10/);
|
|
106
|
-
assert.match(n, /why_failed/);
|
|
107
|
-
assert.match(n, /delete\|replace\|extend/);
|
|
108
|
-
assert.match(n, /"metric"/);
|
|
109
|
-
assert.match(n, /split-required/);
|
|
110
|
-
assert.equal(designLaneNote({ recurs: false }), "");
|
|
111
|
-
assert.equal(designLaneNote(null), "");
|
|
112
|
-
});
|
|
113
|
-
it("a design lane's contract must carry why_failed, a disposition and a measurable outcome", () => {
|
|
114
|
-
assert.equal(designContractFailures({}, det)[0].kind, "design_missing");
|
|
115
|
-
assert.match(designContractFailures({}, det)[0].detail, /no design block/);
|
|
116
|
-
assert.match(designContractFailures({ design: { why_failed: "", disposition: "replace", outcome: { metric: "m", target: 0 } } }, det)[0].detail, /why_failed is empty/);
|
|
117
|
-
assert.deepEqual(designContractFailures({ design: { why_failed: "w", disposition: "delete", outcome: { metric: "m", target: 0 } } }, det), []);
|
|
118
|
-
assert.deepEqual(designContractFailures({}, { recurs: false }), [], "an ordinary lane needs no design block");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
import { designDemanded } from "./recurrence.mjs";
|
|
123
|
-
describe("symptom match and one-time design demand (#5979)", () => {
|
|
124
|
-
const files = { 10: NAMED, 11: NAMED };
|
|
125
|
-
it("path-only overlap without a symptom match does not recur", () => {
|
|
126
|
-
const rows = [row(10, { matched: ["billing"], title: "tidy billing" }), row(11, { matched: ["reserve"], title: "rename" })];
|
|
127
|
-
const d = detectRecurrence({ rows, mergedPrFiles: files, namedPaths: NAMED, body: "the page is slow" });
|
|
128
|
-
assert.equal(d.recurs, false);
|
|
129
|
-
assert.equal(d.count, 0);
|
|
130
|
-
});
|
|
131
|
-
it("a code-shaped symptom plus path still recurs", () => {
|
|
132
|
-
const rows = [row(10, { matched: ["reservation.leak"] }), row(11, { matched: ["reservation.leak"] })];
|
|
133
|
-
assert.equal(detectRecurrence({ rows, mergedPrFiles: files, namedPaths: NAMED }).recurs, true);
|
|
134
|
-
});
|
|
135
|
-
it("a backticked signature of the issue in the row title is a symptom match", () => {
|
|
136
|
-
const rows = [row(10, { matched: ["billing"], title: "fix `ERR_RESERVE` crash" }), row(11, { matched: ["billing"], title: "again ERR_RESERVE" })];
|
|
137
|
-
assert.equal(detectRecurrence({ rows, mergedPrFiles: files, namedPaths: NAMED, body: "throws `ERR_RESERVE`" }).recurs, true);
|
|
138
|
-
});
|
|
139
|
-
it("a Recurs link is unchanged", () => {
|
|
140
|
-
assert.equal(detectRecurrence({ rows: [], mergedPrFiles: { 5: NAMED, 6: NAMED }, body: "Recurs #5, #6", namedPaths: NAMED }).recurs, true);
|
|
141
|
-
});
|
|
142
|
-
it("a design block already demanded on an earlier run is not demanded again", () => {
|
|
143
|
-
const det = { recurs: true, count: 2, demanded: true };
|
|
144
|
-
const f = designContractFailures({}, det);
|
|
145
|
-
assert.equal(f.length, 1);
|
|
146
|
-
assert.equal(f[0].kind, "design_missing_repeated");
|
|
147
|
-
assert.equal(designContractFailures({}, { ...det, demanded: false })[0].kind, "design_missing");
|
|
148
|
-
assert.deepEqual(designContractFailures({ design: { why_failed: "w", disposition: "replace", outcome: { metric: "m", target: "t" } } }, det), []);
|
|
149
|
-
});
|
|
150
|
-
it("designDemanded reads an earlier NEEDS_HUMAN naming the design lane", () => {
|
|
151
|
-
assert.equal(designDemanded([{ body: "<!-- FORGE:NEEDS_HUMAN -->\nrecurring issue (2 earlier fixes) routed to a design lane: no design block" }]), true);
|
|
152
|
-
assert.equal(designDemanded([{ body: "<!-- FORGE:NEEDS_HUMAN -->\nother" }]), false);
|
|
7
|
+
describe("recurrence config (#5751; design routing cut in #6083)", () => {
|
|
8
|
+
it("reads list and block-map hot areas, and nothing else", () => {
|
|
9
|
+
assert.deepEqual(parseRecurrenceConfig(undefined), { hotAreas: [] });
|
|
10
|
+
const r = parseRecurrenceConfig({ hot_areas: { api: "src/api/**, src/routes/**" } });
|
|
11
|
+
assert.deepEqual(r.hotAreas, [{ name: "api", paths: ["src/api/**", "src/routes/**"] }]);
|
|
12
|
+
assert.deepEqual(parseRecurrenceConfig({ hot_areas: [{ name: "db", paths: ["db/"] }] }).hotAreas, [{ name: "db", paths: ["db"] }]);
|
|
13
|
+
});
|
|
14
|
+
it("a directory overlaps the files under it", () => {
|
|
15
|
+
assert.ok(pathsOverlap("src/a", "src/a/b.mjs"));
|
|
16
|
+
assert.ok(!pathsOverlap("src/a", "src/ab/b.mjs"));
|
|
153
17
|
});
|
|
154
18
|
});
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { fenced } from "./release-fence.mjs";
|
|
15
15
|
import { buildDispatchArgs } from "./release-control.mjs";
|
|
16
|
-
import { INFRA_SIGNATURES } from "./release-flakes.mjs";
|
|
16
|
+
import { INFRA_SIGNATURES, classifyFailedStep } from "./release-flakes.mjs";
|
|
17
|
+
import { BLOCKER_LABEL } from "./release-rehearsal.mjs";
|
|
17
18
|
import { verifyStep, verifyConfigured } from "./release-verify.mjs";
|
|
18
19
|
import { engineOn, runStages } from "./deploy-stages.mjs";
|
|
19
20
|
|
|
20
|
-
export const BOUNDS = { pollMs: 10_000, runPollMs: 20_000, defaultStageS: 3600, rerunMax: 2, maxAttempts: 3 };
|
|
21
|
+
export const BOUNDS = { pollMs: 10_000, runPollMs: 20_000, defaultStageS: 3600, rerunMax: 2, maxAttempts: 3, failureMax: 2 };
|
|
21
22
|
const json = (s) => JSON.parse(String(s || "null"));
|
|
22
23
|
const blocked = (reason) => ({ blocked: true, reason });
|
|
23
24
|
const tail = (s, n = 400) => String(s ?? "").trim().slice(-n);
|
|
@@ -103,6 +104,25 @@ export function classifyDeploy(log, sigs) {
|
|
|
103
104
|
return /migrat/i.test(log) ? "migration" : "deterministic";
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/** #6015: one open tracking issue per release+sha (marker lookup, then create or comment), filed before any rerun. @returns the issue url or number. */
|
|
108
|
+
async function recordDeployIssue(ctx, fails, latest) {
|
|
109
|
+
const { io, repo, state } = ctx, st = state.deploy;
|
|
110
|
+
const mark = `<!-- FORGE:DEPLOY_FAILURE release=${ctx.fence?.lease?.release ?? state.id ?? "-"} sha=${st.merge ?? "-"} -->`;
|
|
111
|
+
const line = (f, i) => `${i + 1}. run ${f.runId}: class \`${f.class}\`, step \`${f.step ?? "unknown"}\`\n\n\`\`\`\n${f.excerpt}\n\`\`\``;
|
|
112
|
+
if (!st.issue) {
|
|
113
|
+
const open = json(await io.gh(["issue", "list", "--repo", repo, "--label", BLOCKER_LABEL, "--state", "open", "--limit", "100", "--json", "number,body"])) ?? [];
|
|
114
|
+
const found = open.find((i) => String(i.body ?? "").includes(mark));
|
|
115
|
+
if (found) st.issue = String(found.number);
|
|
116
|
+
}
|
|
117
|
+
if (st.issue) {
|
|
118
|
+
if (st.issueCommented !== latest.runId + ":" + latest.rerunsAt) await io.gh(["issue", "comment", st.issue, "--repo", repo, "--body", `Deploy failure ${fails.length}:\n${line(latest, fails.length - 1)}`]);
|
|
119
|
+
} else {
|
|
120
|
+
st.issue = String(await io.gh(["issue", "create", "--repo", repo, "--label", BLOCKER_LABEL, "--title", `release-blocker: deploy failed at ${String(st.merge ?? "").slice(0, 12)}`, "--body", `${mark}\nProduction deploy failed; the engine reruns only a transient class once and stops after 2 failures.\n\n${fails.map(line).join("\n\n")}\n`])).trim();
|
|
121
|
+
}
|
|
122
|
+
st.issueCommented = latest.runId + ":" + latest.rerunsAt; ctx.save();
|
|
123
|
+
return st.issue;
|
|
124
|
+
}
|
|
125
|
+
|
|
106
126
|
const hold = (reason, kind) => ({ blocked: `${reason} (owner ask: decide rollback or fix; label needs-agent when no host is attached)`, hold: { kind, label: "needs-agent" } });
|
|
107
127
|
|
|
108
128
|
/**
|
|
@@ -116,10 +136,20 @@ async function recover(ctx, d, run, why, freezeNow, b, workflow) {
|
|
|
116
136
|
if (freezeNow) return { blocked: `${why}; ${d.freeze_variable} is set, so the engine never reruns or redispatches the deploy (I26): roll back, or a human runs the workflow with override_freeze` };
|
|
117
137
|
if (!run || !["failure", "timed_out", "cancelled"].includes(run.conclusion)) return { blocked: `${why}; nothing to rerun (a run that finished without changing live is not retried)` };
|
|
118
138
|
if (run.conclusion === "cancelled" && await superseded({ io, repo, workflow }, run)) return { blocked: `${why}; run ${run.databaseId} was cancelled by a newer run of the concurrency group: expected, not rerun` };
|
|
119
|
-
if (st.reruns >= rerunMax || st.attempts >= maxAttempts) return { blocked: `${why}; recovery spent (${st.reruns}/${rerunMax} reruns, ${st.attempts}/${maxAttempts} actions): hand off to the rollback ladder (#5563)` };
|
|
120
139
|
let log = ""; try { log = String(await io.gh(["run", "view", String(run.databaseId), "--repo", repo, "--log-failed"])); } catch { /* unreadable log: not transient */ }
|
|
121
|
-
const
|
|
122
|
-
|
|
140
|
+
const c = classifyFailedStep({ log, sigs: rec.signatures });
|
|
141
|
+
const cls = c.class === "infra" ? "transient" : c.class === "migration" ? "migration" : "deterministic";
|
|
142
|
+
const fails = (st.failures ??= []);
|
|
143
|
+
if (!fails.length || fails[fails.length - 1].rerunsAt !== st.reruns) fails.push({ class: c.class, step: c.step, runId: run.databaseId, excerpt: c.excerpt, rerunsAt: st.reruns }); // a resume with no rerun in between is the same failure
|
|
144
|
+
ctx.save();
|
|
145
|
+
let issue; try { issue = await recordDeployIssue(ctx, fails, fails[fails.length - 1]); } catch (e) { return { blocked: `${why}; could not file the deploy tracking issue (${tail(e?.message, 120)}), so nothing is rerun` }; }
|
|
146
|
+
const at = issue ? ` (tracking issue ${issue})` : "";
|
|
147
|
+
const cap = Math.min(b.failureMax ?? BOUNDS.failureMax, BOUNDS.failureMax); // never raised by deploy.recovery
|
|
148
|
+
if (fails.length >= cap) return hold(`${why}; the deploy failed ${fails.length} times, stopping${at}: recovery spent, hand off to the rollback ladder (#5563); ${fails.map((f) => `${f.class}/${f.step ?? "?"}`).join(", ")}`, "deploy-failed");
|
|
149
|
+
if (st.reruns >= Math.min(rerunMax, BOUNDS.rerunMax) || st.attempts >= maxAttempts) return { blocked: `${why}; recovery spent (${st.reruns}/${rerunMax} reruns, ${st.attempts}/${maxAttempts} actions)${at}: hand off to the rollback ladder (#5563)` };
|
|
150
|
+
if (cls !== "transient") return hold(`${why}; ${c.class} failure at step ${c.step ?? "?"}, never retried blindly${at}: ${tail(log, 200)}`, c.class === "migration" ? "migration" : c.class === "deterministic" ? "deterministic" : c.class);
|
|
151
|
+
if ((st.rerunClasses ??= []).includes(c.class)) return hold(`${why}; ${c.class} already rerun once${at}`, "deploy-failed");
|
|
152
|
+
st.rerunClasses.push(c.class);
|
|
123
153
|
st.reruns += 1; st.attempts += 1; ctx.save(); // counted before the act: a crash can only spend budget, never exceed it
|
|
124
154
|
const f = await fenced(ctx.fence, { action: "rerun", key: idemKey(ctx, `rerun:${run.databaseId}:${st.reruns}`) }, () => io.gh(["run", "rerun", String(run.databaseId), "--repo", repo, "--failed"]));
|
|
125
155
|
if (f.refused) return { blocked: `rerun ${f.refused}` };
|
|
@@ -20,6 +20,7 @@ function world(o = {}) {
|
|
|
20
20
|
if (a[0] === "run" && a[1] === "list") { const r = w.runs[Math.min(w.reran ?? 0, w.runs.length - 1)]; return JSON.stringify(r ? [r] : []); }
|
|
21
21
|
if (a[0] === "run" && a[1] === "view") return w.log;
|
|
22
22
|
if (a[0] === "run" && a[1] === "rerun") { w.reran = (w.reran ?? 0) + 1; return ""; }
|
|
23
|
+
if (a[0] === "issue") { w.issues = w.issues ?? []; w.issues.push({ a, at: w.reran ?? 0 }); return a[1] === "list" ? "[]" : a[1] === "create" ? "https://github.com/o/r/issues/77" : ""; }
|
|
23
24
|
if (a[0] === "workflow" || a[0] === "pr") return "";
|
|
24
25
|
throw new Error(`unexpected gh ${a.join(" ")}`);
|
|
25
26
|
},
|
|
@@ -67,7 +68,7 @@ describe("release deploy stages (#5560)", () => {
|
|
|
67
68
|
it("rerun_max bounds the reruns, then escalates", async () => {
|
|
68
69
|
const { w, io } = world({ live: [OLD], log: "429 Too Many Requests", runs: [{ databaseId: 9, status: "completed", conclusion: "failure" }] });
|
|
69
70
|
const out = await deployStep(mk(io));
|
|
70
|
-
assert.match(out.reason, /recovery spent/); assert.equal(w.reran,
|
|
71
|
+
assert.match(out.reason, /recovery spent/); assert.equal(w.reran, 1);
|
|
71
72
|
});
|
|
72
73
|
it("max_attempts bounds the actions", async () => {
|
|
73
74
|
const { w, io } = world({ live: [OLD], log: "429 Too Many Requests", runs: [{ databaseId: 9, status: "completed", conclusion: "failure" }] });
|
|
@@ -111,7 +112,8 @@ describe("release deploy stages (#5560)", () => {
|
|
|
111
112
|
const c = mk(io);
|
|
112
113
|
try { await deployStep(c); } catch { /* killed */ }
|
|
113
114
|
const out = await deployStep(c);
|
|
114
|
-
assert.
|
|
115
|
+
if (dieOn === "run rerun") assert.ok(out.blocked, dieOn); // #6015: a crash after the counted rerun leaves a second recorded failure: stop, never a third attempt
|
|
116
|
+
else assert.equal(out.live, true, dieOn);
|
|
115
117
|
assert.ok((w.reran ?? 0) <= 1, `${dieOn}: one rerun`);
|
|
116
118
|
assert.equal(w.gh.filter((g) => g.startsWith("workflow run")).length, 0, dieOn);
|
|
117
119
|
}
|
|
@@ -152,7 +154,7 @@ describe("deploy observation and recovery (#5560)", () => {
|
|
|
152
154
|
assert.equal((await deployStep(mk(ok.io))).live, true); assert.equal(ok.w.reran, undefined);
|
|
153
155
|
const bad = world({ live: [OLD], runs: [{ databaseId: 9, status: "completed", conclusion: "cancelled" }], log: "the runner received a shutdown signal" });
|
|
154
156
|
const out = await deployStep(mk(bad.io));
|
|
155
|
-
assert.equal(bad.w.reran,
|
|
157
|
+
assert.equal(bad.w.reran, 1); assert.match(out.reason, /recovery spent/);
|
|
156
158
|
});
|
|
157
159
|
it("shared INFRA_SIGNATURES count as transient without any configured signature", async () => {
|
|
158
160
|
const { w, io } = world({ live: [OLD, SHA], log: "fatal: ECONNRESET", runs: [{ databaseId: 9, status: "completed", conclusion: "failure" }, { databaseId: 9, status: "completed", conclusion: "success" }] });
|
|
@@ -223,3 +225,48 @@ describe("deploy helpers", () => {
|
|
|
223
225
|
assert.ok(validatePolicy({ ...base, deploy: { ...POLICY, recovery: { rerun_max: "2" } } }).some((f) => /rerun_max/.test(f)));
|
|
224
226
|
});
|
|
225
227
|
});
|
|
228
|
+
|
|
229
|
+
describe("deploy failure classification and one issue (#6015)", () => {
|
|
230
|
+
const FAIL = [{ databaseId: 9, status: "completed", conclusion: "failure" }];
|
|
231
|
+
const creates = (w) => (w.issues ?? []).filter((i) => i.a[1] === "create");
|
|
232
|
+
it("two failed attempts yield exactly one issue and no third rerun", async () => {
|
|
233
|
+
const { w, io } = world({ live: [OLD], log: "build\tCompile\t2026 429 Too Many Requests", runs: FAIL });
|
|
234
|
+
const out = await deployStep(mk(io));
|
|
235
|
+
assert.equal(creates(w).length, 1); assert.equal(w.reran, 1); assert.equal(out.hold?.kind, "deploy-failed"); assert.match(out.reason, /issues\/77/);
|
|
236
|
+
assert.equal((w.issues ?? []).filter((i) => i.a[1] === "comment").length, 1);
|
|
237
|
+
const again = await deployStep(mk(io, { state: { steps: { "post-merge": { result: { merge: SHA } } }, deploy: undefined } })); // a fresh state still finds the marker, never a third rerun beyond the cap
|
|
238
|
+
assert.ok((w.reran ?? 0) <= 2); assert.ok(again.blocked || again.live === undefined);
|
|
239
|
+
});
|
|
240
|
+
it("the cap cannot be raised above 2 by deploy.recovery", async () => {
|
|
241
|
+
const { w, io } = world({ live: [OLD], log: "429 Too Many Requests", runs: FAIL });
|
|
242
|
+
await deployStep(mk(io, {}, { ...POLICY, recovery: { rerun_max: 9, max_attempts: 9, signatures: ["429"] } }));
|
|
243
|
+
assert.equal(w.reran, 1);
|
|
244
|
+
});
|
|
245
|
+
it("a secrets decrypt or SSH failure is never rerun, but the issue is filed", async () => {
|
|
246
|
+
for (const [log, cls] of [["deploy\tDecrypt secrets\t2026 sops: failed to decrypt ETIMEDOUT", "secrets"], ["deploy\tDeploy via SSH\t2026 ssh: connect to host x port 22: ETIMEDOUT", "ssh"]]) {
|
|
247
|
+
const { w, io } = world({ live: [OLD], log, runs: FAIL });
|
|
248
|
+
const c = mk(io); const out = await deployStep(c);
|
|
249
|
+
assert.equal(w.reran, undefined, cls); assert.equal(out.hold?.kind, cls); assert.equal(creates(w).length, 1);
|
|
250
|
+
assert.equal(c.state.deploy.failures[0].class, cls); assert.equal(c.state.deploy.failures[0].runId, 9);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
it("the issue is filed before the rerun", async () => {
|
|
254
|
+
const { w, io } = world({ live: [OLD, SHA], log: "ECONNRESET", runs: [...FAIL, { databaseId: 9, status: "completed", conclusion: "success" }] });
|
|
255
|
+
const order = []; const g = io.gh;
|
|
256
|
+
io.gh = async (a) => { if (a[0] === "issue" && a[1] === "create") order.push("issue"); if (a[1] === "rerun") order.push("rerun"); return g(a); };
|
|
257
|
+
const out = await deployStep(mk(io));
|
|
258
|
+
assert.deepEqual(order, ["issue", "rerun"]); assert.equal(out.live, true);
|
|
259
|
+
});
|
|
260
|
+
it("a class is rerun once only", async () => {
|
|
261
|
+
const { w, io } = world({ live: [OLD], log: "ECONNRESET", runs: FAIL });
|
|
262
|
+
const c = mk(io, {}, { ...POLICY, recovery: { rerun_max: 2, max_attempts: 3 } });
|
|
263
|
+
c.state.deploy = { phase: "DEPLOYING", attempts: 1, reruns: 1, rerunClasses: ["infra"], failures: [{ class: "infra", step: null, runId: 9, excerpt: "x", rerunsAt: 0 }] };
|
|
264
|
+
await deployStep(c); assert.equal(w.reran, undefined);
|
|
265
|
+
});
|
|
266
|
+
it("a failing issue filing blocks the rerun", async () => {
|
|
267
|
+
const { w, io } = world({ live: [OLD], log: "ECONNRESET", runs: FAIL }); const g = io.gh;
|
|
268
|
+
io.gh = async (a) => { if (a[0] === "issue") throw new Error("HTTP 500"); return g(a); };
|
|
269
|
+
const out = await deployStep(mk(io));
|
|
270
|
+
assert.match(out.reason, /tracking issue/); assert.equal(w.reran, undefined);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
@@ -40,6 +40,40 @@ export function classifyFailure(text) {
|
|
|
40
40
|
const hit = INFRA_SIGNATURES.find(([, re]) => re.test(String(text ?? "")));
|
|
41
41
|
return hit ? { class: "infra", signature: hit[0] } : { class: "unknown", signature: null };
|
|
42
42
|
}
|
|
43
|
+
/** #6015: a deploy or rehearsal workflow is never a CI flake: its failures go through release-deploy recover (classify, file, bounded rerun). */
|
|
44
|
+
export const isDeployWorkflow = (name) => /deploy|rehears|migrat/i.test(String(name ?? ""));
|
|
45
|
+
|
|
46
|
+
const STEP_SECRETS = /decrypt|sops|secrets?\b|age[- ]key|gpg/i, STEP_SSH = /\bssh\b|scp\b|rsync/i;
|
|
47
|
+
const LOG_SECRETS = /failed to decrypt|decryption failed|sops.*(error|failed)|no matching keys|cannot decrypt|age: error/i;
|
|
48
|
+
const LOG_SSH = /permission denied \(publickey|ssh: connect to host|ssh_exchange_identification|kex_exchange_identification|host key verification failed|ssh: .*(timed out|refused)/i;
|
|
49
|
+
|
|
50
|
+
/** The step named by the first `--log-failed` line (`job<TAB>step<TAB>time line`) or the first failed step of `steps` [{name, conclusion}]. */
|
|
51
|
+
function failedStepName(steps, log) {
|
|
52
|
+
const s = (steps ?? []).find((x) => x?.conclusion === "failure" || x?.conclusion === "timed_out");
|
|
53
|
+
if (s?.name) return String(s.name);
|
|
54
|
+
const m = /^[^\t\n]*\t([^\t\n]+)\t/m.exec(String(log ?? ""));
|
|
55
|
+
return m ? m[1].trim() : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* #6015: name the failed deploy step (DEPLOY_FREEZE / LIVE_CHECK semantics of #5560 via `reason`). Pure.
|
|
60
|
+
* Secrets decrypt, SSH, rehearsal, migration, freeze and live-check failures are never transient; only a network/infra signature
|
|
61
|
+
* (shared INFRA_SIGNATURES or `sigs`) in some other step is. @returns {{class, transient: boolean, step: string|null, excerpt: string}}
|
|
62
|
+
*/
|
|
63
|
+
export function classifyFailedStep({ steps, log, reason, sigs } = {}) {
|
|
64
|
+
const text = String(log ?? ""), step = failedStepName(steps, text), name = step ?? "";
|
|
65
|
+
const excerpt = text.trim().slice(-400), out = (cls, transient = false) => ({ class: cls, transient, step, excerpt });
|
|
66
|
+
if (/DEPLOY_FREEZE|\bfreeze\b/i.test(String(reason ?? ""))) return out("freeze");
|
|
67
|
+
if (/LIVE_CHECK/.test(String(reason ?? ""))) return out("live-check");
|
|
68
|
+
if (STEP_SECRETS.test(name) || LOG_SECRETS.test(text)) return out("secrets");
|
|
69
|
+
if (STEP_SSH.test(name) || (!step && LOG_SSH.test(text))) return out("ssh");
|
|
70
|
+
if (/rehears/i.test(name)) return out("rehearsal");
|
|
71
|
+
if (/migrat/i.test(name) || (!step && /migrat/i.test(text))) return out("migration");
|
|
72
|
+
const configured = (sigs ?? []).some((x) => { try { return new RegExp(x, "i").test(text); } catch { return text.includes(x); } });
|
|
73
|
+
if (INFRA_SIGNATURES.some(([, re]) => re.test(text)) || configured) return out("infra", true);
|
|
74
|
+
return /migrat/i.test(text) ? out("migration") : out("deterministic");
|
|
75
|
+
}
|
|
76
|
+
|
|
43
77
|
export const signatureHash = (check, test, signature) => createHash("sha256").update([check, test ?? "", signature ?? ""].join("\0")).digest("hex").slice(0, 16);
|
|
44
78
|
|
|
45
79
|
/** Same-SHA flips in `runs` [{sha, check, test?, conclusion, id, at}]: a check that failed and then passed on one sha. */
|
|
@@ -54,8 +88,8 @@ export function detectSameShaFlip(runs) {
|
|
|
54
88
|
}
|
|
55
89
|
|
|
56
90
|
/** One `flakes.json` entry. */
|
|
57
|
-
export const flakeEntry = ({ check, test = null, signature = null, kind, sha = null, runIds = [], at, rerun = false }) =>
|
|
58
|
-
({ check, test, signature, signature_hash: signatureHash(check, test, signature), kind, sha, run_ids: runIds, at, ...(rerun ? { rerun: true } : {}) });
|
|
91
|
+
export const flakeEntry = ({ check, test = null, signature = null, kind, sha = null, runIds = [], at, rerun = false, attempt = null, reuseForfeited = false }) =>
|
|
92
|
+
({ check, test, signature, signature_hash: signatureHash(check, test, signature), kind, sha, run_ids: runIds, at, ...(rerun ? { rerun: true } : {}), ...(attempt != null ? { attempt } : {}), ...(reuseForfeited ? { reuse_forfeited: "deploy test reuse forfeited" } : {}) });
|
|
59
93
|
|
|
60
94
|
/** Append entries to `flakes.json` and the `_active` `flakes` key in one commit. */
|
|
61
95
|
export async function recordFlakes(lctx, entries, now = Date.now()) {
|
|
@@ -67,6 +101,17 @@ export async function recordFlakes(lctx, entries, now = Date.now()) {
|
|
|
67
101
|
return r.ok ? { ok: true, recorded: entries.length } : { ok: false, error: r.refused ?? "lost the race recording flakes" };
|
|
68
102
|
}
|
|
69
103
|
|
|
104
|
+
/** #6014: a release-PR CI run is rerun at most this many times (Actions run_attempt 1 is the first run, so attempt 3 is the last allowed). */
|
|
105
|
+
export const RERUN_ATTEMPT_CAP = 2;
|
|
106
|
+
|
|
107
|
+
/** @param {{attempt?: number|null, cap?: number}} p @returns {{allow: boolean, why: string}} refuse once `attempt - 1` reruns have already happened. */
|
|
108
|
+
export function attemptGuard({ attempt, cap = RERUN_ATTEMPT_CAP }) {
|
|
109
|
+
const n = Number(attempt);
|
|
110
|
+
if (!Number.isFinite(n) || n < 1) return { allow: true, why: "attempt unknown" };
|
|
111
|
+
if (n - 1 >= cap) return { allow: false, why: `run is on attempt ${n}: already rerun ${n - 1} times (cap ${cap}); needs a recorded classification and a filed issue for the failing job` };
|
|
112
|
+
return { allow: true, why: `attempt ${n}, ${n - 1} of ${cap} reruns used` };
|
|
113
|
+
}
|
|
114
|
+
|
|
70
115
|
/**
|
|
71
116
|
* Which failed jobs to `rerun --failed`: infra class only, once per job (`done` = keys of jobs already rerun), and only while the
|
|
72
117
|
* minutes already spent stay inside `ci.rerun_budget_min`. Every job gets a decision, so a skipped rerun is never silent.
|
|
@@ -76,6 +121,7 @@ export function planRerun({ jobs, done = [], spentMin = 0, budgetMin }) {
|
|
|
76
121
|
const seen = new Set(done);
|
|
77
122
|
let spent = spentMin;
|
|
78
123
|
return jobs.map((j) => {
|
|
124
|
+
if (j.attempt != null) { const g = attemptGuard({ attempt: j.attempt }); if (!g.allow) return { ...j, rerun: false, capped: true, why: g.why }; }
|
|
79
125
|
if (j.class !== "infra") return { ...j, rerun: false, why: "not an infra flake" };
|
|
80
126
|
if (seen.has(j.key)) return { ...j, rerun: false, why: "already rerun once" };
|
|
81
127
|
const cost = j.minutes ?? 0;
|