forgedock 1.71.0 → 1.72.1
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 -1
- package/bin/engine/outcome-codes.mjs +5 -4
- package/bin/init-detect.mjs +35 -2
- package/bin/lean/admit.mjs +152 -0
- package/bin/lean/admit.test.mjs +120 -0
- package/bin/lean/attempts.mjs +1 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +17 -0
- package/bin/lean/concurrency.mjs +7 -2
- package/bin/lean/concurrency.test.mjs +16 -3
- package/bin/lean/conformance.mjs +2 -0
- package/bin/lean/conformance.test.mjs +9 -0
- package/bin/lean/effects.mjs +22 -0
- package/bin/lean/failure-census.mjs +1 -1
- package/bin/lean/heavy.mjs +20 -6
- package/bin/lean/heavy.test.mjs +24 -3
- package/bin/lean/lean.mjs +97 -5
- package/bin/lean/lean.test.mjs +38 -0
- package/bin/lean/orchestrate-envhold.test.mjs +14 -0
- package/bin/lean/orchestrate-heldroot.test.mjs +32 -0
- package/bin/lean/orchestrate.mjs +33 -11
- package/bin/lean/queuecause.mjs +42 -0
- package/bin/lean/release-cigreen.mjs +18 -4
- package/bin/lean/release-cigreen.test.mjs +23 -0
- package/bin/lean/release-review.mjs +24 -10
- package/bin/lean/release-review.test.mjs +65 -0
- package/bin/lean/release.mjs +1 -1
- package/bin/lean/release.test.mjs +19 -0
- package/bin/lean/schedd.mjs +24 -1
- package/bin/lean/schedd.test.mjs +38 -0
- package/bin/pool/agent.mjs +61 -18
- package/bin/pool/docker-dns.mjs +39 -0
- package/bin/pool/docker.mjs +7 -3
- package/bin/pool/engine-placement.test.mjs +2 -2
- package/bin/pool/image-manifest.test.mjs +13 -0
- package/bin/pool/lane-image.mjs +56 -15
- package/bin/pool/lane-tools.mjs +26 -12
- package/bin/pool/lane-tools.test.mjs +63 -1
- package/bin/pool/project-layer.mjs +2 -2
- package/bin/pool/router.mjs +2 -1
- package/bin/review-staging.mjs +14 -11
- package/bin/review-staging.test.mjs +20 -1
- package/bin/stats/escapes.mjs +124 -0
- package/bin/stats/index.mjs +5 -1
- package/bin/stats/quality-ledger.mjs +49 -0
- package/bin/stats/quality-ledger.test.mjs +84 -0
- package/bin/stats/weekly.mjs +230 -0
- package/docs/OUTCOME-CODES.md +2 -1
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/pool/image/Dockerfile +4 -1
- package/pool/image/lane-tools-sets.json +6 -0
- package/scripts/lane-variants.mjs +51 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* queue_wait by cause (#6203). One clock per batch: an issue's wait starts when it is first seen pending ("ready") and
|
|
5
|
+
* accrues per cause while it is pending; it does NOT reset on a requeue (the old `enqueued` stamp did), and it stops while the
|
|
6
|
+
* issue runs. The runner calls `tick` once per scheduling pass with a pure `causeOf(issue)`; `take` closes the issue's
|
|
7
|
+
* accrual when its lane starts and returns the totals so far. State is plain JSON so a resumed batch keeps it.
|
|
8
|
+
*/
|
|
9
|
+
export const QUEUE_CAUSES = Object.freeze(["hold", "pause", "capacity", "breaker", "dependency", "host_offline", "other"]);
|
|
10
|
+
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
11
|
+
|
|
12
|
+
export function createQueueClock(saved = null) {
|
|
13
|
+
const acc = new Map(Object.entries(saved?.acc ?? {}).map(([n, c]) => [n, { ...c }]));
|
|
14
|
+
const readyAt = new Map(Object.entries(saved?.readyAt ?? {}));
|
|
15
|
+
const last = new Map(); // issue -> {at, cause}; not persisted: a restart opens a fresh segment
|
|
16
|
+
const add = (n, cause, ms) => { if (ms > 0) { const a = acc.get(n) ?? {}; a[cause] = (a[cause] ?? 0) + ms; acc.set(n, a); } };
|
|
17
|
+
const close = (n, t) => { const l = last.get(n); if (l) add(String(n), l.cause, Math.max(0, t - l.at)); last.delete(n); };
|
|
18
|
+
return {
|
|
19
|
+
/** Attribute the time since the previous tick to the issue's previous cause, then open a segment with its current cause. */
|
|
20
|
+
tick(pending, causeOf, t) {
|
|
21
|
+
const keep = new Set();
|
|
22
|
+
for (const n of pending) {
|
|
23
|
+
const k = String(n); keep.add(k);
|
|
24
|
+
if (!readyAt.has(k)) readyAt.set(k, t);
|
|
25
|
+
close(k, t);
|
|
26
|
+
let c = "other"; try { c = causeOf(n); } catch { /* fail-open */ }
|
|
27
|
+
last.set(k, { at: t, cause: QUEUE_CAUSES.includes(c) ? c : "other" });
|
|
28
|
+
}
|
|
29
|
+
for (const k of [...last.keys()]) if (!keep.has(k)) close(k, t); // left the queue without take(): stop accruing
|
|
30
|
+
},
|
|
31
|
+
/** The issue starts: close its segment and return {total_ms, causes, ready_at}; null when it was never queued. */
|
|
32
|
+
take(n, t) {
|
|
33
|
+
const k = String(n); close(k, t);
|
|
34
|
+
const causes = acc.get(k);
|
|
35
|
+
if (!causes) return null;
|
|
36
|
+
return { total_ms: Math.round(Object.values(causes).reduce((a, b) => a + b, 0)), causes: Object.fromEntries(Object.entries(causes).map(([c, v]) => [c, Math.round(v)])), ready_at: isNum(Number(readyAt.get(k))) ? Number(readyAt.get(k)) : null };
|
|
37
|
+
},
|
|
38
|
+
/** The issue ended for good: forget it. */
|
|
39
|
+
drop(n) { const k = String(n); acc.delete(k); readyAt.delete(k); last.delete(k); },
|
|
40
|
+
toJSON: () => ({ acc: Object.fromEntries(acc), readyAt: Object.fromEntries(readyAt) }),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -20,6 +20,10 @@ export const CI_GREEN_POLL_MS = 30_000;
|
|
|
20
20
|
export const CI_GREEN_MAX_WAIT_MIN = 40;
|
|
21
21
|
const SEVERITY_ORDER = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
|
|
22
22
|
const json = (s) => JSON.parse(String(s || "null"));
|
|
23
|
+
/** `gh api --paginate --jq '.x[] | {..}'` prints one JSON object per line, across all pages. */
|
|
24
|
+
const ndjson = (s) => String(s || "").split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
25
|
+
/** Polls (CI_GREEN_POLL_MS apart) to wait for a rerun's attempt number to advance before the checks are read again. */
|
|
26
|
+
const RERUN_SETTLE_POLLS = 10;
|
|
23
27
|
|
|
24
28
|
/** forge.yaml `release.ci_green.max_wait_min` and `release.block_severity` (lowest blocking severity; default high) -> `{ciGreen, blockSeverity}`; only set keys are returned. */
|
|
25
29
|
export function ciGreenKeys(r) {
|
|
@@ -76,9 +80,9 @@ export function realCiSeam(ctx) {
|
|
|
76
80
|
isDraft: async (pr) => Boolean(json(await gh(["pr", "view", String(pr), "--repo", repo, "--json", "isDraft"]))?.isDraft),
|
|
77
81
|
headOf: async (pr) => String(await gh(["pr", "view", String(pr), "--repo", repo, "--json", "headRefOid", "--jq", ".headRefOid"])).trim(),
|
|
78
82
|
checks: async ({ head }) => {
|
|
79
|
-
const runs =
|
|
83
|
+
const runs = ndjson(await gh(["api", "--paginate", `repos/${repo}/commits/${head}/check-runs?per_page=100`, "--jq", ".check_runs[] | {name, status, conclusion, link: .details_url}"]));
|
|
80
84
|
let statuses = [];
|
|
81
|
-
try { statuses =
|
|
85
|
+
try { statuses = ndjson(await gh(["api", "--paginate", `repos/${repo}/commits/${head}/status?per_page=100`, "--jq", ".statuses[] | {name: .context, state, link: .target_url}"])); } catch { /* check runs alone */ }
|
|
82
86
|
return [
|
|
83
87
|
...runs.map((k) => ({ name: k.name, bucket: bucketOf(k.status, k.conclusion), link: k.link })),
|
|
84
88
|
...statuses.map((k) => ({ name: k.name, bucket: k.state === "success" ? "pass" : k.state === "pending" ? "pending" : "fail", link: k.link })),
|
|
@@ -158,14 +162,24 @@ async function waitGreen(ctx, pr, seam) {
|
|
|
158
162
|
}
|
|
159
163
|
ctx.save?.();
|
|
160
164
|
let reran = 0;
|
|
165
|
+
const before = new Map();
|
|
161
166
|
for (const id of ids.keys()) {
|
|
162
|
-
|
|
167
|
+
const attempt = await seam.runAttempt(id);
|
|
168
|
+
if (!attemptGuard({ attempt }).allow) continue;
|
|
163
169
|
await seam.rerunFailed(id);
|
|
170
|
+
before.set(id, attempt);
|
|
164
171
|
reran++;
|
|
165
172
|
}
|
|
166
173
|
if (!reran) return { red: true, head, failing: st.failing };
|
|
167
174
|
ctx.io.print?.(`release: ci-green: rerunning ${[...ids.values()].join(", ")} once`);
|
|
168
|
-
|
|
175
|
+
// The old failure stays visible until GitHub registers the new attempt: wait for the attempt number to advance (bounded), not a fixed sleep.
|
|
176
|
+
for (let n = 0; n < RERUN_SETTLE_POLLS; n++) {
|
|
177
|
+
await seam.sleep(CI_GREEN_POLL_MS);
|
|
178
|
+
if (seam.now() >= deadline) break;
|
|
179
|
+
let settled = true;
|
|
180
|
+
for (const [id, was] of before) { const now = await seam.runAttempt(id); if (was == null || now == null || now <= was) settled = false; }
|
|
181
|
+
if (settled) break;
|
|
182
|
+
}
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
185
|
|
|
@@ -27,6 +27,29 @@ function seam(snaps, o = {}) {
|
|
|
27
27
|
const ctx = (s, extra = {}) => ({ io: { ciGreen: s, print() {} }, repo: "o/r", def: "main", config: {}, state: { steps: { "release-pr": { done: true, result: { pr: 7 } } } }, save() {}, ...extra });
|
|
28
28
|
const row = (bucket, id = 1) => ({ name: "build", bucket, link: link(id) });
|
|
29
29
|
|
|
30
|
+
describe("ci-green rerun lag and pagination (#6177)", () => {
|
|
31
|
+
it("waits for the rerun attempt to register instead of reading the stale failure as red", async () => {
|
|
32
|
+
const s = seam([]); let att = 1, polls = 0;
|
|
33
|
+
s.runAttempt = async () => { if (s.log.includes("rerun:5") && ++polls > 3) att = 2; return att; };
|
|
34
|
+
s.checks = async () => [row(att >= 2 ? "pass" : "fail", 5)];
|
|
35
|
+
const r = await ciGreenStep(ctx(s));
|
|
36
|
+
assert.equal(r.green, true); assert.equal(s.log.filter((x) => x === "rerun:5").length, 1);
|
|
37
|
+
});
|
|
38
|
+
it("stays bounded when the attempt never advances", async () => {
|
|
39
|
+
const s = seam([[row("fail", 5)]]);
|
|
40
|
+
const c = ctx(s, { io: { ciGreen: s, print() {}, review: {} } });
|
|
41
|
+
const r = await ciGreenWait(c, 7, { noFix: true });
|
|
42
|
+
assert.equal(r.red, true); assert.ok(s.log.filter((x) => x === "sleep").length <= 12);
|
|
43
|
+
});
|
|
44
|
+
it("reads every page of check runs", async () => {
|
|
45
|
+
const { realCiSeam } = await import("./release-cigreen.mjs");
|
|
46
|
+
const calls = [];
|
|
47
|
+
const gh = async (a) => { calls.push(a); const all = a.includes("--paginate"); return a.join(" ").includes("/status") ? "" : Array.from({ length: all ? 150 : 100 }, (_, i) => JSON.stringify({ name: `c${i}`, status: "completed", conclusion: "success" })).join("\n"); };
|
|
48
|
+
const out = await realCiSeam({ io: { gh }, repo: "o/r" }).checks({ head: H });
|
|
49
|
+
assert.equal(out.length, 150); assert.ok(calls.every((a) => a[0] !== "api" || a.includes("--paginate")));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
30
53
|
describe("ci-green step (#6164)", () => {
|
|
31
54
|
it("is a default release step between release-pr and review", () => {
|
|
32
55
|
const i = RELEASE_STEPS.indexOf("ci-green");
|
|
@@ -337,7 +337,7 @@ export async function fixStep(ctx) {
|
|
|
337
337
|
if (s.err) return blocked(s.err);
|
|
338
338
|
res = s.r;
|
|
339
339
|
}
|
|
340
|
-
if (res.marker === "FORGE:GATE_PASS") return { verdict: res.verdict, head: res.head };
|
|
340
|
+
if (res.marker === "FORGE:GATE_PASS" && !res.blocking?.length && !res.guards?.length) return { verdict: res.verdict, head: res.head };
|
|
341
341
|
if (res.blocking?.length || res.guards?.length) {
|
|
342
342
|
const names = res.blocking?.length ? res.blocking.map((n) => `#${n}`).join(" ") : (res.guards ?? []).map((g) => g.name).join(", ");
|
|
343
343
|
const queued = res.blocking?.length ? await seam.queueBlockers?.({ pr: res.pr, blockers: res.blocking }) : null;
|
|
@@ -347,8 +347,16 @@ export async function fixStep(ctx) {
|
|
|
347
347
|
ctx.save();
|
|
348
348
|
return { blocked: true, held: true, reason };
|
|
349
349
|
}
|
|
350
|
-
if (res.ciFailing > 0) return
|
|
351
|
-
return
|
|
350
|
+
if (res.ciFailing > 0) return blockedForRerun(ctx, `required checks of #${res.pr} are not green at ${String(res.head).slice(0, 7)} (${res.ciPendingOnly ? "pending" : "red"}); re-run the release: ci-green waits and fixes CI once, then one review pass`);
|
|
351
|
+
return blockedForRerun(ctx, `${res.verdict} (${res.marker}) on #${res.pr} at ${String(res.head).slice(0, 7)} with no blocking finding and no red CI: the gate summary names the blocker; read it and re-run the release`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** #6175: a block that tells the operator to re-run must leave ci-green and review undone, else the resume re-reads the same stale review result. */
|
|
355
|
+
function blockedForRerun(ctx, reason) {
|
|
356
|
+
delete ctx.state.steps["ci-green"];
|
|
357
|
+
delete ctx.state.steps.review;
|
|
358
|
+
ctx.save();
|
|
359
|
+
return blocked(reason);
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
/**
|
|
@@ -375,11 +383,11 @@ async function legacyFixStep(ctx) {
|
|
|
375
383
|
if (s.err) return blocked(s.err);
|
|
376
384
|
r = s.r;
|
|
377
385
|
if (r.marker === "FORGE:GATE_PASS") break;
|
|
378
|
-
if (r.ciCancelOnly) return
|
|
386
|
+
if (r.ciCancelOnly) return blockedForRerun(ctx, `required checks of #${r.pr} still cancelled after a rerun, with no failure to fix`);
|
|
379
387
|
continue;
|
|
380
388
|
}
|
|
381
389
|
// Required checks that are only still pending (#5519) have not failed: no CI issue or lane, the release re-runs once CI finishes.
|
|
382
|
-
if (!r.blocking?.length && r.ciFailing > 0 && r.ciPendingOnly) return
|
|
390
|
+
if (!r.blocking?.length && r.ciFailing > 0 && r.ciPendingOnly) return blockedForRerun(ctx, `required checks of #${r.pr} still pending, with no failure to fix; re-run the release once CI finishes`);
|
|
383
391
|
if (roundsAt(ctx.state, r.head) >= cfg.maxRounds) {
|
|
384
392
|
const s = await secondRound(ctx, seam, r, cfg);
|
|
385
393
|
if (s.blocked) return s;
|
|
@@ -477,15 +485,21 @@ export function realSeam({ repo, def, env = process.env, laneStrip = [], cwd = p
|
|
|
477
485
|
queueBlockers: async ({ blockers }) => {
|
|
478
486
|
try {
|
|
479
487
|
const batches = (await io?.batches?.(repo)) ?? [];
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
488
|
+
const open = batches.find((b) => !b.paused && !b.cancelled); // #6178: a paused or cancelled batch admits nothing
|
|
489
|
+
if (!open) return { batch: null, ...(batches.length ? { error: "every batch is paused or cancelled" } : {}) };
|
|
490
|
+
const add = io?.addToBatch ?? (async (id, nums) => { const { orchestrateFromCli } = await import("../engine-cli.mjs"); return orchestrateFromCli(["--add", id, ...nums.map(String)]); });
|
|
491
|
+
const res = await add(open.id, blockers);
|
|
492
|
+
// #6178: queued only when the add scheduled something; skipped ones (owned elsewhere, closed, unreadable) are not queued
|
|
493
|
+
if (res && !(res.added?.length || res.requeued?.length)) return { batch: null, error: `batch ${open.id} took none of ${blockers.map((n) => `#${n}`).join(" ")}: ${(res.skipped ?? []).map((x) => `#${x.issue} ${x.reason}`).join(", ") || "nothing added"}` };
|
|
494
|
+
return { batch: open.id };
|
|
484
495
|
} catch (e) { return { batch: null, error: String(e?.message ?? e).split("\n")[0] }; }
|
|
485
496
|
},
|
|
486
497
|
holdReleasePr: async ({ pr, blockers, guards, queued, verdict }) => {
|
|
487
498
|
const what = blockers.length ? `confirmed CRITICAL/HIGH finding(s) ${blockers.map((n) => `#${n}`).join(" ")}` : `failed guard(s) ${guards.map((g) => g.name).join(", ")}`;
|
|
488
|
-
|
|
499
|
+
// #6178: with nothing queued the PR stays open with a status; closing it would drop the blockers
|
|
500
|
+
const queuedLine = queued?.batch ? `They are queued in orchestrate batch ${queued.batch}.` : `No open orchestrate batch took them${queued?.error ? ` (${queued.error})` : ""}: start one with \`forgedock orchestrate ${blockers.join(" ")}\`. This release PR stays open.`;
|
|
501
|
+
const body = `Release stopped: ${verdict ?? "BLOCK DEPLOY"}. ${what} block this release. ${queuedLine} Nothing found by the review is fixed inside the release PR; the next release starts fresh after they merge (the open-finding gate enforces it).`;
|
|
502
|
+
if (!queued?.batch && blockers.length) { try { gh(["pr", "comment", String(pr), "-R", repo, "--body", body]); } catch { /* the blocked result still stops the job */ } return { closed: false }; }
|
|
489
503
|
try { gh(["pr", "close", String(pr), "-R", repo, "--comment", body]); return { closed: true }; } catch { try { gh(["pr", "comment", String(pr), "-R", repo, "--body", body]); } catch { /* the blocked result still stops the job */ } return { closed: false }; }
|
|
490
504
|
},
|
|
491
505
|
async fileDeferred({ pr, items }) {
|
|
@@ -663,6 +663,12 @@ describe("default flow (v1.0 contract, dcfb86bf): one review pass, nothing found
|
|
|
663
663
|
assert.equal((await fixStep(c)).verdict, "APPROVE FOR DEPLOY");
|
|
664
664
|
assert.equal(s.log.filter((e) => e[0] === "lane" || e[0] === "fix-issue").length, 0);
|
|
665
665
|
});
|
|
666
|
+
it("a blocker is never passed on GATE_PASS (#6174: block_severity medium)", async () => {
|
|
667
|
+
const s = fakeSeam();
|
|
668
|
+
const c = def(s, { review: { done: true, result: { pr: 7, head: H1, verdict: "APPROVE FOR DEPLOY", marker: "FORGE:GATE_PASS", blocking: [101], filed: [101], ciFailing: 0 } } });
|
|
669
|
+
const r = await fixStep(c);
|
|
670
|
+
assert.equal(r.blocked, true); assert.equal(r.held, true);
|
|
671
|
+
});
|
|
666
672
|
it("a confirmed blocker stops the release: no fix lane, blockers queued into the open batch, release PR closed, status names the blockers", async () => {
|
|
667
673
|
const s = fakeSeam({ fins: [blockFin], summary: bad });
|
|
668
674
|
const calls = [];
|
|
@@ -682,11 +688,70 @@ describe("default flow (v1.0 contract, dcfb86bf): one review pass, nothing found
|
|
|
682
688
|
const c = def(s); c.state.steps.review = { done: true, result: await reviewStep(c) };
|
|
683
689
|
assert.match((await fixStep(c)).reason, /^review blockers #100; release PR #7 held/);
|
|
684
690
|
});
|
|
691
|
+
describe("#6178 queueBlockers picks an open batch and checks the add", () => {
|
|
692
|
+
const mk = (batches, add, calls = []) => realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp", gh: (a) => { calls.push(a); return ""; }, io: { batches: async () => batches, addToBatch: add } });
|
|
693
|
+
it("skips paused and cancelled batches", async () => {
|
|
694
|
+
const added = [];
|
|
695
|
+
const r = await mk([{ id: "p", paused: true }, { id: "c", cancelled: true }, { id: "ok" }], async (id) => { added.push(id); return { added: [100], skipped: [] }; }).queueBlockers({ blockers: [100] });
|
|
696
|
+
assert.deepEqual(added, ["ok"]); assert.equal(r.batch, "ok");
|
|
697
|
+
});
|
|
698
|
+
it("no open batch: nothing is added", async () => {
|
|
699
|
+
let called = false;
|
|
700
|
+
const r = await mk([{ id: "p", paused: true }], async () => { called = true; return {}; }).queueBlockers({ blockers: [100] });
|
|
701
|
+
assert.equal(r.batch, null); assert.equal(called, false);
|
|
702
|
+
});
|
|
703
|
+
it("a skipped-only add is not reported as queued", async () => {
|
|
704
|
+
const r = await mk([{ id: "b" }], async () => ({ added: [], requeued: [], skipped: [{ issue: 100, reason: "owned by x" }] })).queueBlockers({ blockers: [100] });
|
|
705
|
+
assert.equal(r.batch, null); assert.match(r.error, /#100 owned by x/);
|
|
706
|
+
});
|
|
707
|
+
it("holdReleasePr leaves the PR open with a status when nothing was queued", async () => {
|
|
708
|
+
const calls = [];
|
|
709
|
+
const r = await mk([], async () => ({}), calls).holdReleasePr({ pr: 7, blockers: [100], guards: [], queued: { batch: null } });
|
|
710
|
+
assert.equal(r.closed, false); assert.equal(calls[0][1], "comment"); assert.match(calls[0].join(" "), /stays open/);
|
|
711
|
+
});
|
|
712
|
+
it("a guard-only hold (no blockers) still closes the PR", async () => {
|
|
713
|
+
const calls = [];
|
|
714
|
+
const r = await mk([], async () => ({}), calls).holdReleasePr({ pr: 7, blockers: [], guards: [{ name: "g" }], queued: { batch: null } });
|
|
715
|
+
assert.equal(r.closed, true); assert.equal(calls[0][1], "close");
|
|
716
|
+
});
|
|
717
|
+
});
|
|
685
718
|
it("MEDIUM, LOW and unconfirmed findings never block: GATE_PASS stays a pass", async () => {
|
|
686
719
|
const s = fakeSeam({ fins: [fin({ toFile: [{ id: "u", title: "maybe", severity: "HIGH" }, { id: "m", title: "med", severity: "MEDIUM" }], confirmedIds: ["m"] })] });
|
|
687
720
|
const r = await reviewStep(def(s));
|
|
688
721
|
assert.deepEqual(r.blocking, []);
|
|
689
722
|
});
|
|
723
|
+
it("#6175: a red or pending CI block clears ci-green and review, so a resume re-runs both instead of re-reading the stale result", async () => {
|
|
724
|
+
for (const pend of [false, true]) {
|
|
725
|
+
const s = fakeSeam({ heads: [H1] });
|
|
726
|
+
s.summary = async () => ({ code: 0, data: { verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", ciFailing: 2, ciPendingOnly: pend }, lines: [] });
|
|
727
|
+
const c = def(s, { "ci-green": { done: true }, review: { done: true, result: { pr: 7, head: H1, verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", blocking: [], guards: [], ciFailing: 2, ciPendingOnly: pend } } });
|
|
728
|
+
let saved = 0; c.save = () => { saved++; };
|
|
729
|
+
const r = await fixStep(c);
|
|
730
|
+
assert.equal(r.blocked, true);
|
|
731
|
+
assert.equal(c.state.steps["ci-green"], undefined, "ci-green is re-run on resume");
|
|
732
|
+
assert.equal(c.state.steps.review, undefined, "review is re-run on resume");
|
|
733
|
+
assert.ok(saved > 0, "the cleared ledger is saved");
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
it("#6175: a review blocker keeps ci-green and review done (the stop is sticky)", async () => {
|
|
737
|
+
const s = fakeSeam({ fins: [blockFin], summary: bad });
|
|
738
|
+
s.queueBlockers = async () => ({ batch: "b-1" }); s.holdReleasePr = async () => ({ closed: true });
|
|
739
|
+
const c = def(s, { "ci-green": { done: true } }); c.state.steps.review = { done: true, result: await reviewStep(c) };
|
|
740
|
+
await fixStep(c);
|
|
741
|
+
assert.ok(c.state.steps["ci-green"].done && c.state.steps.review.done);
|
|
742
|
+
});
|
|
743
|
+
it("#6175: the legacy pending-only block clears ci-green and review so a resume re-runs them", async () => {
|
|
744
|
+
const s = fakeSeam({ heads: [H1] });
|
|
745
|
+
const res = { pr: 7, head: H1, verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", blocking: [], guards: [], ciFailing: 1, ciPendingOnly: true };
|
|
746
|
+
const c = ctx(s, { "ci-green": { done: true }, review: { done: true, result: res } });
|
|
747
|
+
s.summary = async () => ({ code: 0, data: res, lines: [] });
|
|
748
|
+
let saved = 0; c.save = () => { saved++; };
|
|
749
|
+
const r = await fixStep(c);
|
|
750
|
+
assert.equal(r.blocked, true);
|
|
751
|
+
assert.equal(c.state.steps["ci-green"], undefined);
|
|
752
|
+
assert.equal(c.state.steps.review, undefined);
|
|
753
|
+
assert.ok(saved > 0);
|
|
754
|
+
});
|
|
690
755
|
it("coStartCi is not run in the default flow", async () => {
|
|
691
756
|
const s = fakeSeam(); const c = def(s); c.config.fix = { coStart: true };
|
|
692
757
|
const gh = []; c.io.gh = async (a) => { gh.push(a); return "{}"; };
|
package/bin/lean/release.mjs
CHANGED
|
@@ -501,7 +501,7 @@ export function realReleaseIo({ env = process.env, exec = execFileSync, print =
|
|
|
501
501
|
runningLanes: (repo) => unfinished(repo).flatMap((b) => Object.entries(b.store.load()?.lanes ?? {})
|
|
502
502
|
.filter(([n, rec]) => rec?.pid && isLaneAlive(rec.pid, b.resultFile(n)) && !existsSync(b.resultFile(n)))
|
|
503
503
|
.map(([n]) => ({ batch: b.id, issue: n }))),
|
|
504
|
-
batches: (repo) => unfinished(repo).map((b) => ({ id: b.id, k: b.readParallel() ?? 1 })),
|
|
504
|
+
batches: (repo) => unfinished(repo).map((b) => ({ id: b.id, k: b.readParallel() ?? 1, paused: !!b.readPause(), cancelled: !!b.readCancel() })),
|
|
505
505
|
setParallel: async (id, k) => {
|
|
506
506
|
const { orchestrateFromCli } = await import("../engine-cli.mjs");
|
|
507
507
|
await orchestrateFromCli(["--set-parallel", id, String(k)]);
|
|
@@ -647,3 +647,22 @@ describe("default ci-green flow in the conductor (#6164)", () => {
|
|
|
647
647
|
assert.equal(readReleaseConfig("release:\n review_fixes: true\n").reviewFixes, true);
|
|
648
648
|
});
|
|
649
649
|
});
|
|
650
|
+
|
|
651
|
+
describe("realReleaseIo.batches reports paused/cancelled (#6178)", () => {
|
|
652
|
+
it("flags a paused and a cancelled batch, leaves an open one unflagged", async () => {
|
|
653
|
+
const { mkdirSync, writeFileSync } = await import("node:fs");
|
|
654
|
+
const { realReleaseIo } = await import("./release.mjs");
|
|
655
|
+
const root = tmpDir("release-6178");
|
|
656
|
+
const seed = (id, files = {}) => {
|
|
657
|
+
const d = join(root, id); mkdirSync(join(d, "lanes"), { recursive: true });
|
|
658
|
+
writeFileSync(join(d, "plan.json"), JSON.stringify({ repo: REPO })); writeFileSync(join(d, "state.json"), JSON.stringify({ lanes: {} }));
|
|
659
|
+
for (const [n, v] of Object.entries(files)) writeFileSync(join(d, n), JSON.stringify(v));
|
|
660
|
+
};
|
|
661
|
+
seed("b20261110-000000-1"); seed("b20261110-000000-2", { pause: { since: "2026-11-10T00:00:00Z" } }); seed("b20261110-000000-3", { cancel: { at: "2026-11-10T00:00:00Z" } });
|
|
662
|
+
const io = realReleaseIo({ env: { ...process.env, FORGEDOCK_BATCH_DIR: root }, print: () => {} });
|
|
663
|
+
const by = Object.fromEntries((await io.batches(REPO)).map((b) => [b.id.slice(-1), b]));
|
|
664
|
+
assert.deepEqual([by[1].paused, by[1].cancelled], [false, false]);
|
|
665
|
+
assert.deepEqual([by[2].paused, by[2].cancelled], [true, false]);
|
|
666
|
+
assert.deepEqual([by[3].paused, by[3].cancelled], [false, true]);
|
|
667
|
+
});
|
|
668
|
+
});
|
package/bin/lean/schedd.mjs
CHANGED
|
@@ -65,6 +65,8 @@ import { applySetExecution } from "./live-execution.mjs";
|
|
|
65
65
|
import { liveOverload } from "./hostload.mjs";
|
|
66
66
|
|
|
67
67
|
/** #5938: epoch ms of the newest lane log of a running issue (a lane heartbeat), or null. */
|
|
68
|
+
/** #6197: an add/requeue unconsumed this long (ms) re-hosts or flags its batch. */
|
|
69
|
+
export const UNRUN_STALE_MS = 60_000;
|
|
68
70
|
export function lanesAlive(b, state) {
|
|
69
71
|
let best = null;
|
|
70
72
|
for (const n of Object.keys(state?.running ?? {})) { try { const m = statSync(b.logFile(n)).mtimeMs; if (best === null || m > best) best = m; } catch { /* no lane log yet */ } }
|
|
@@ -224,7 +226,7 @@ function takeLock(lock, pid, alive) {
|
|
|
224
226
|
*/
|
|
225
227
|
export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(process.env.FORGEDOCK_SCHEDD_IDLE_MS) || IDLE_MS,
|
|
226
228
|
root = batchRoot(), log = (m) => console.log(m), pid = process.pid, alive = pidAlive, resumeOnStart = true, stopMs = STOP_MS,
|
|
227
|
-
lockCheckMs = LOCK_CHECK_MS, admitMs = Number(process.env.FORGEDOCK_SCHEDD_ADMIT_MS) || ADMIT_MS, lagMs = LAG_MS, stallCheckMs = Number(process.env.FORGEDOCK_SCHEDD_STALL_CHECK_MS) || 60_000, stallMin = Number(process.env.FORGEDOCK_SCHEDD_STALL_MIN) || DEFAULT_STALL_MIN, due = null, dueMs = Number(process.env.FORGEDOCK_SCHEDD_DUE_MS) || DUE_MS, preflight = null,
|
|
229
|
+
lockCheckMs = LOCK_CHECK_MS, admitMs = Number(process.env.FORGEDOCK_SCHEDD_ADMIT_MS) || ADMIT_MS, lagMs = LAG_MS, stallCheckMs = Number(process.env.FORGEDOCK_SCHEDD_STALL_CHECK_MS) || 60_000, stallMin = Number(process.env.FORGEDOCK_SCHEDD_STALL_MIN) || DEFAULT_STALL_MIN, unrunStaleMs = UNRUN_STALE_MS, due = null, dueMs = Number(process.env.FORGEDOCK_SCHEDD_DUE_MS) || DUE_MS, preflight = null,
|
|
228
230
|
abandonMs = (Number(process.env.FORGEDOCK_SCHEDD_ABANDON_DAYS) > 0 ? Number(process.env.FORGEDOCK_SCHEDD_ABANDON_DAYS) * 24 * 3600 * 1000 : ABANDON_AGE_MS), killChildren = killTrackedChildren,
|
|
229
231
|
hostLoad = liveOverload(), installedVersion = readInstalledVersion, respawn = undefined, probeEnv = (env) => probeBatchEnv(env), restartForStall = undefined,
|
|
230
232
|
exit = null, hardExitMs = HARD_EXIT_MS, unit = unitState, probe = undefined, successorMs = SUCCESSOR_MS, successorPollMs = 200, rehost = undefined, sloGh = undefined, introspect = undefined } = {}) {
|
|
@@ -308,6 +310,7 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
308
310
|
// dispatched by re-hosting the batch once the run has ended. Once per distinct set of unrun entries, so an add that cannot
|
|
309
311
|
// drain (a cancel, a tripped breaker) never loops.
|
|
310
312
|
const rehostedUnrun = new Map();
|
|
313
|
+
const unrunRehostAt = new Map(); // #6197: last stale-input re-host per batch (rate limit)
|
|
311
314
|
function rehostUnrun(id) {
|
|
312
315
|
if (closing || hosted.has(id) || starting.has(id)) return;
|
|
313
316
|
let sig;
|
|
@@ -657,6 +660,26 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
657
660
|
if (b.isTerminal() && (!Number.isFinite(created) || now - created >= 24 * 3600_000)) continue; // nothing left to report or re-host
|
|
658
661
|
const reported = !!b.readReport(), cancelled = !!b.readCancel(), state = b.store.peek(), isHosted = hosted.has(id) || starting.has(id);
|
|
659
662
|
await efficiencyTick(b, plan, state, { now, reported, cancelled }); // #5987: advisory; never throws, never changes dispatch
|
|
663
|
+
// #6197: an add/requeue left unconsumed past UNRUN_STALE_MS is a stall of its own: re-host an unhosted batch (reported ones too,
|
|
664
|
+
// even when rehostUnrun's one-shot signature already fired; at most once per window), alert on a hosted one that is not draining.
|
|
665
|
+
const unrunAge = !cancelled ? b.unrunInputAgeMs(now) : null;
|
|
666
|
+
if (unrunAge !== null && unrunAge > unrunStaleMs) {
|
|
667
|
+
const st = b.store.load();
|
|
668
|
+
if (!(st?.breaker && !st.breaker.transport && !st.breaker.environmental)) {
|
|
669
|
+
const adds = b.unrunAdds(), reqs = b.unrunRequeues().map((e) => e.issue ?? e), what = [...adds, ...reqs].map((n) => `#${n}`).join(", ");
|
|
670
|
+
if (!isHosted) {
|
|
671
|
+
if (now - (unrunRehostAt.get(id) ?? 0) >= unrunStaleMs) {
|
|
672
|
+
unrunRehostAt.set(id, now);
|
|
673
|
+
log(`schedd: re-hosting batch ${id} (unconsumed add/requeue ${what} for ${Math.round(unrunAge / 1000)}s)`);
|
|
674
|
+
const started = host({ argv: ["--resume", id], cwd: process.cwd(), env: {}, keepBreaker: true });
|
|
675
|
+
starting.set(id, started);
|
|
676
|
+
started.catch((e) => log(`schedd: re-host ${id} failed: ${e?.message ?? e}`)).finally(() => starting.delete(id));
|
|
677
|
+
}
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (recordStallAlert(b, { ready: [...adds, ...reqs], code: "unconsumed-input", detail: `add/requeue ${what} unconsumed for ${Math.round(unrunAge / 1000)}s` })) log(`schedd: batch ${id} needs you: unconsumed add/requeue ${what}`);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
660
683
|
const stallOpts = { held: b.readHeld(), paused: b.readPause?.() ?? null, parallel: b.readParallel(), hosted: isHosted, lastProgressMs: b.lastDispatchClockMs(), now, windowMin: stallMin, cancelled, reported, lanesAliveMs: lanesAlive(b, state) };
|
|
661
684
|
let stall = evaluateDispatchStall(state, stallOpts);
|
|
662
685
|
if (stall && preflight) { // #5745: name the preflight gate holding admission (advisory; dispatch decisions are unchanged)
|
package/bin/lean/schedd.test.mjs
CHANGED
|
@@ -640,6 +640,44 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
|
|
|
640
640
|
} finally { await d.close(); }
|
|
641
641
|
});
|
|
642
642
|
|
|
643
|
+
// #6197: an add that no resume consumed is retried by the watchdog once it is older than unrunStaleMs.
|
|
644
|
+
const staleAddRun = async ({ tag, staleMs, ageMs, cancel = false, waitMs }) => {
|
|
645
|
+
const dir = tmpDir(`schedd-stale-${tag}-`), root = join(dir, "batches"), id = `b20261031-000000-619${tag}`;
|
|
646
|
+
const calls = [];
|
|
647
|
+
const runBatch = async ({ argv, sink }) => {
|
|
648
|
+
calls.push(argv);
|
|
649
|
+
const b = openBatch(root, id);
|
|
650
|
+
if (argv[0] !== "--resume") {
|
|
651
|
+
b.writePlan({ daemon: true, repo: "o/r", created: new Date().toISOString() });
|
|
652
|
+
b.store.save({ v: 1, order: [1], results: { 1: { terminalReason: "merged" } }, running: {}, pending: [] });
|
|
653
|
+
b.writeReport({ done: true });
|
|
654
|
+
writeFileSync(join(b.dir, "add"), "[2]\n");
|
|
655
|
+
const old = new Date(Date.now() - ageMs);
|
|
656
|
+
utimesSync(join(b.dir, "add"), old, old);
|
|
657
|
+
if (cancel) b.requestCancel({ reason: "operator" });
|
|
658
|
+
}
|
|
659
|
+
sink.batch({ id, dir: b.dir });
|
|
660
|
+
return {};
|
|
661
|
+
};
|
|
662
|
+
const d = await startDaemon({ dir, root, runBatch, log: () => {}, resumeOnStart: false, stallCheckMs: 50, unrunStaleMs: staleMs });
|
|
663
|
+
try {
|
|
664
|
+
await request(await connectDaemon({ dir, spawnDaemon: null }), { op: "submit", argv: ["1"], cwd: dir, env: {} });
|
|
665
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
666
|
+
return calls.length;
|
|
667
|
+
} finally { await d.close(); }
|
|
668
|
+
};
|
|
669
|
+
it("#6197: a reported batch whose add stayed unconsumed past the stale window is re-hosted again after the one-shot re-host", async () => {
|
|
670
|
+
const n = await staleAddRun({ tag: "1", staleMs: 300, ageMs: 10_000, waitMs: 1500 });
|
|
671
|
+
assert.ok(n >= 3, `initial + one-shot re-host + stale re-host; got ${n}`);
|
|
672
|
+
assert.ok(n <= 10, `rate limited, not a loop; got ${n}`);
|
|
673
|
+
});
|
|
674
|
+
it("#6197: an add younger than the stale window gets only the one-shot re-host", async () => {
|
|
675
|
+
assert.equal(await staleAddRun({ tag: "2", staleMs: 60_000, ageMs: 0, waitMs: 1000 }), 2);
|
|
676
|
+
});
|
|
677
|
+
it("#6197: a cancelled batch is never re-hosted for a stale add", async () => {
|
|
678
|
+
assert.equal(await staleAddRun({ tag: "3", staleMs: 300, ageMs: 10_000, cancel: true, waitMs: 1000 }), 1);
|
|
679
|
+
});
|
|
680
|
+
|
|
643
681
|
it("#4917: a batch whose breaker tripped (not transport) is not re-hosted by the timer", async () => {
|
|
644
682
|
const dir = tmpDir("schedd-rehost-brk-"), root = join(dir, "batches"), id = "b20261031-000000-4919";
|
|
645
683
|
const calls = [];
|