forgedock 1.66.0 → 1.68.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 +3 -0
- package/bin/engine/outcome-codes.mjs +2 -0
- package/bin/engine-cli.mjs +193 -27
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +24 -1
- package/bin/help-text.mjs +4 -3
- package/bin/introspect-schedule.mjs +98 -0
- package/bin/introspect-schedule.test.mjs +67 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +64 -0
- package/bin/lean/amendment-schema.mjs +30 -0
- package/bin/lean/attempts.mjs +162 -0
- package/bin/lean/attempts.test.mjs +141 -0
- package/bin/lean/basered.mjs +81 -0
- package/bin/lean/basered.test.mjs +68 -1
- package/bin/lean/batch-health.mjs +20 -12
- package/bin/lean/batch-health.test.mjs +55 -11
- package/bin/lean/batch.mjs +45 -0
- package/bin/lean/batch.test.mjs +105 -5
- package/bin/lean/capwait.mjs +14 -3
- package/bin/lean/capwait.test.mjs +20 -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.mjs +14 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +46 -0
- package/bin/lean/commentstate.test.mjs +43 -0
- package/bin/lean/concurrency.mjs +89 -0
- package/bin/lean/concurrency.test.mjs +113 -0
- package/bin/lean/conformance.e2e.test.mjs +13 -8
- package/bin/lean/conformance.mjs +73 -181
- package/bin/lean/conformance.test.mjs +61 -345
- package/bin/lean/depcache.mjs +100 -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 +42 -24
- package/bin/lean/efficiency.mjs +162 -0
- package/bin/lean/efficiency.test.mjs +79 -0
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +93 -0
- package/bin/lean/envgap.test.mjs +53 -0
- package/bin/lean/execution.mjs +41 -17
- package/bin/lean/execution.test.mjs +58 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/failure-stop.mjs +46 -0
- package/bin/lean/failure-stop.test.mjs +45 -0
- package/bin/lean/fixtures/capacity-storm.json +609 -0
- 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/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 +5 -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 +311 -154
- package/bin/lean/lean.test.mjs +530 -223
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +21 -2
- package/bin/lean/live-execution.test.mjs +39 -0
- package/bin/lean/liveness.mjs +37 -0
- package/bin/lean/liveness.test.mjs +33 -0
- package/bin/lean/orchestrate-attempts.test.mjs +82 -0
- package/bin/lean/orchestrate-envhold.test.mjs +47 -0
- 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 +76 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +164 -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 +344 -45
- package/bin/lean/phaseledger.mjs +6 -0
- package/bin/lean/phaseledger.test.mjs +13 -1
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +100 -11
- package/bin/lean/preflight.test.mjs +44 -4
- package/bin/lean/prompts.mjs +13 -28
- package/bin/lean/reconcile.mjs +90 -0
- package/bin/lean/recurrence.mjs +6 -112
- package/bin/lean/recurrence.test.mjs +11 -92
- package/bin/lean/release-flakes.mjs +14 -2
- package/bin/lean/release-flakes.test.mjs +17 -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 +43 -14
- 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 +49 -11
- package/bin/lean/sched.mjs +19 -0
- package/bin/lean/sched.test.mjs +11 -1
- package/bin/lean/schedd-health.mjs +4 -4
- package/bin/lean/schedd-health.test.mjs +8 -4
- package/bin/lean/schedd.mjs +45 -8
- package/bin/lean/schedd.test.mjs +120 -7
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/slo.mjs +126 -0
- package/bin/lean/slo.test.mjs +112 -0
- package/bin/lean/statuscomment.mjs +40 -0
- package/bin/lean/statuscomment.test.mjs +48 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +3 -2
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +144 -10
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +53 -9
- package/bin/pool/docker.mjs +3 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +26 -0
- package/bin/pool/lane-tools.test.mjs +9 -0
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/router.mjs +88 -32
- package/bin/pool/version.mjs +29 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/attempts.mjs +54 -0
- package/bin/stats/attempts.test.mjs +30 -0
- package/bin/stats/churn.mjs +49 -0
- package/bin/stats/churn.test.mjs +31 -0
- package/bin/stats/index.mjs +11 -3
- 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/commands/orchestrate.md +21 -18
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +2 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +14 -2
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/check-devdocs-freshness.sh +1 -1
- 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 +11 -0
- 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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { computeInputHash, emptyLedger, normalizeLedger, recordFailure, breach, admitInput, markEscalated, blockerSignature, frozenContractHash, renderEscalation, renderAttempts, parseAttempts, budgets, makeAttemptsSeam } from "./attempts.mjs";
|
|
6
|
+
import { renderContract } from "./render.mjs";
|
|
7
|
+
import { postKeyed } from "./statuscomment.mjs";
|
|
8
|
+
|
|
9
|
+
const base = { title: "t", body: "b", labels: ["bug"], decisions: [], engineVersion: "1.2.3", sandboxVersion: "1.2.0", contractHash: "c1" };
|
|
10
|
+
const fail = (l, sig, hash) => recordFailure(l, { signature: sig, hash, spend: 1.5, run: `run-${(l?.attempts ?? 0) + 1}` });
|
|
11
|
+
|
|
12
|
+
describe("#5986 input hash", () => {
|
|
13
|
+
it("changes with body, title, labels, decisions, engine major.minor and contract; not with needs-human or a patch bump", () => {
|
|
14
|
+
const h = computeInputHash(base);
|
|
15
|
+
for (const k of [{ body: "b2" }, { title: "t2" }, { labels: ["bug", "x"] }, { decisions: ["FORGE:DECISION ok"] }, { engineVersion: "1.3.0" }, { sandboxVersion: "2.0.0" }, { contractHash: "c2" }]) assert.notEqual(computeInputHash({ ...base, ...k }), h, JSON.stringify(k));
|
|
16
|
+
assert.equal(computeInputHash({ ...base, labels: ["bug", { name: "needs-human" }] }), h);
|
|
17
|
+
assert.equal(computeInputHash({ ...base, engineVersion: "1.2.9" }), h);
|
|
18
|
+
assert.equal(computeInputHash({ ...base, labels: ["x", "bug"] }), computeInputHash({ ...base, labels: ["bug", "x"] }));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("#5986 admission, budgets, escalation", () => {
|
|
23
|
+
const cfg = {};
|
|
24
|
+
it("defaults are 4 and 2; a missing ledger admits; a changed hash admits", () => {
|
|
25
|
+
assert.deepEqual(budgets(undefined), { maxAttempts: 4, maxIdentical: 2 });
|
|
26
|
+
assert.deepEqual(admitInput(null, "H1", cfg), { ok: true });
|
|
27
|
+
assert.deepEqual(admitInput(fail(null, "s", "H1"), "H2", cfg), { ok: true });
|
|
28
|
+
assert.deepEqual(admitInput(fail(null, "s", "H1"), null, cfg), { ok: true }, "unreadable input fails open");
|
|
29
|
+
});
|
|
30
|
+
it("same hash after a failure is refused with loop.no_new_input", () => {
|
|
31
|
+
const a = admitInput(fail(null, "ci.red:x", "H1"), "H1", cfg);
|
|
32
|
+
assert.equal(a.ok, false); assert.equal(a.code, "loop.no_new_input"); assert.match(a.reason, /ci\.red:x/);
|
|
33
|
+
});
|
|
34
|
+
it("the 2nd identical signature breaches; 4 lanes breach; different signatures stay under max_identical", () => {
|
|
35
|
+
let l = fail(null, "s", "H1");
|
|
36
|
+
assert.equal(breach(l, cfg), null);
|
|
37
|
+
assert.equal(breach(fail(l, "s", "H2"), cfg).kind, "identical");
|
|
38
|
+
let m = null; for (const [i, s] of ["a", "b", "c", "d"].entries()) m = fail(m, s, `H${i}`);
|
|
39
|
+
assert.equal(breach(m, cfg).kind, "attempts");
|
|
40
|
+
assert.equal(breach(m, { maxAttempts: 5 }), null);
|
|
41
|
+
});
|
|
42
|
+
it("a breach escalates once at the same hash, then loop.no_new_input; a new hash admits and clears the escalated flag after the next failure", () => {
|
|
43
|
+
let l = null; for (let i = 1; i <= 2; i++) l = fail(l, "s", `H${i}`);
|
|
44
|
+
assert.equal(admitInput(l, "H2", cfg).code, "escalate");
|
|
45
|
+
l = markEscalated(l);
|
|
46
|
+
assert.equal(admitInput(l, "H2", cfg).code, "loop.no_new_input");
|
|
47
|
+
assert.deepEqual(admitInput(l, "H4", cfg), { ok: true });
|
|
48
|
+
assert.equal(fail(l, "s", "H4").escalated, undefined, "the next window escalates again");
|
|
49
|
+
});
|
|
50
|
+
it("the ledger round-trips through the FORGE:ATTEMPTS comment and the escalation names signatures, runs and spend", () => {
|
|
51
|
+
const l = fail(fail(null, "ci.red", "H1"), "base.conflict", "H1");
|
|
52
|
+
assert.deepEqual(parseAttempts(renderAttempts(l)), normalizeLedger(l));
|
|
53
|
+
assert.equal(parseAttempts("hello"), null);
|
|
54
|
+
assert.deepEqual(normalizeLedger(undefined), emptyLedger());
|
|
55
|
+
const body = renderEscalation(l, "2 lanes");
|
|
56
|
+
assert.match(body, /ci\.red[\s\S]*run-1[\s\S]*base\.conflict[\s\S]*Spend: \$3\.00/);
|
|
57
|
+
});
|
|
58
|
+
it("counters survive a releaseHeld-style round trip through JSON state", () => {
|
|
59
|
+
const l = fail(fail(null, "s", "H1"), "s", "H1");
|
|
60
|
+
assert.deepEqual(normalizeLedger(JSON.parse(JSON.stringify(l))), normalizeLedger(l));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("#5986 contract hash in the input hash", () => {
|
|
65
|
+
it("frozenContractHash takes the last trusted FORGE:CONTRACT comment; none gives null", () => {
|
|
66
|
+
assert.equal(frozenContractHash([{ body: "hi" }], () => true), null);
|
|
67
|
+
assert.equal(frozenContractHash([], () => true), null);
|
|
68
|
+
const mk = (c, h) => ({ body: `<!-- FORGE:CONTRACT -->\n${renderContract(c, h)}` });
|
|
69
|
+
assert.equal(frozenContractHash([mk({ requirements: [] }, "aaa111aaa111"), mk({ requirements: [] }, "bbb222bbb222")], () => true), "bbb222bbb222");
|
|
70
|
+
assert.equal(frozenContractHash([mk({ requirements: [] }, "aaa111aaa111")], () => false), null, "untrusted comments are ignored");
|
|
71
|
+
const h = (contractHash) => computeInputHash({ ...base, contractHash });
|
|
72
|
+
assert.notEqual(h("aaa111aaa111"), h("bbb222bbb222"));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("#5986 synthetic replay of looping issue timelines", () => {
|
|
77
|
+
// shapes of the AlterLab timelines (#40762 repeated builder.blocked, #41419 repeated amendments, #41262 mixed signatures); the real logs are not in the repo
|
|
78
|
+
const timelines = [
|
|
79
|
+
{ name: "#40762", sigs: () => "builder.blocked", amend: () => "same amendment", every: 1000 },
|
|
80
|
+
{ name: "#41419", sigs: () => "ci.red:same", amend: (i) => `amendment ${i % 3}`, every: 1000 },
|
|
81
|
+
{ name: "#41262", sigs: (i) => `sig${i % 3}`, amend: (i) => `amendment ${i}`, every: 1000 },
|
|
82
|
+
];
|
|
83
|
+
for (const t of timelines) it(`${t.name}: at most 4 lanes and 12 engine comments over a 30-readmit timeline with no new input`, async () => {
|
|
84
|
+
let issueBody = "b"; const comments = [], gh = async (a) => {
|
|
85
|
+
if (a[1] === "view") return JSON.stringify({ comments, title: "t", body: issueBody, labels: [] });
|
|
86
|
+
if (a[1] === "comment") { comments.push({ author: { login: "rapiercraft-forgedock" }, url: `https://x/issues/1#issuecomment-${comments.length + 1}`, body: a[a.indexOf("--body") + 1] }); return comments.at(-1).url; }
|
|
87
|
+
if (a[0] === "api") { const id = Number(/comments\/(\d+)/.exec(a[3])[1]); comments[id - 1].body = a[a.indexOf("-f") + 1].slice(5); }
|
|
88
|
+
return "";
|
|
89
|
+
};
|
|
90
|
+
const trusted = (c) => c.author?.login === "rapiercraft-forgedock";
|
|
91
|
+
const seam = makeAttemptsSeam({ gh, repo: "o/r", trusted, cfg: { maxAttempts: 4, maxIdentical: 2 } });
|
|
92
|
+
let ledger = null, lanes = 0;
|
|
93
|
+
for (let i = 0; i < 30; i++) { // readmitted every poll, the issue never edited
|
|
94
|
+
issueBody = `b${Math.floor(i / t.every)}`;
|
|
95
|
+
const hash = await seam.hash(1), a = admitInput(ledger, hash, seam.cfg);
|
|
96
|
+
if (!a.ok) { if (a.code === "escalate") ledger = markEscalated(ledger); await seam.notify({ issue: 1, code: a.code, ledger, reason: a.reason }); continue; }
|
|
97
|
+
lanes++;
|
|
98
|
+
await postKeyed({ gh, repo: "o/r", issue: 1, marker: "FORGE:AMENDMENT", body: t.amend(i), trusted });
|
|
99
|
+
ledger = recordFailure(ledger, { signature: t.sigs(i), hash });
|
|
100
|
+
await seam.mirror(1, ledger);
|
|
101
|
+
if (breach(ledger, seam.cfg) && !ledger.escalated) { ledger = markEscalated(ledger); await seam.notify({ issue: 1, code: "escalate", ledger, reason: "x" }); }
|
|
102
|
+
}
|
|
103
|
+
assert.ok(lanes <= 4, `lanes ${lanes}`);
|
|
104
|
+
assert.ok(comments.length <= 12, `comments ${comments.length}`);
|
|
105
|
+
});
|
|
106
|
+
it("a single unchanged-input timeline runs at most 4 lanes and posts one escalation", async () => {
|
|
107
|
+
let ledger = null, lanes = 0;
|
|
108
|
+
for (let i = 0; i < 20; i++) {
|
|
109
|
+
const a = admitInput(ledger, "H", { maxAttempts: 4, maxIdentical: 2 });
|
|
110
|
+
if (!a.ok) { if (a.code === "escalate") ledger = markEscalated(ledger); continue; }
|
|
111
|
+
lanes++; ledger = recordFailure(ledger, { signature: "s", hash: "H" });
|
|
112
|
+
}
|
|
113
|
+
assert.ok(lanes <= 4, `lanes ${lanes}`);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("#5931 blocker signature", () => {
|
|
118
|
+
const cfg = {};
|
|
119
|
+
const blk = (o = {}) => blockerSignature({ code: "ci.red", detail: "boom 12 abcdef1", contractHash: "c1", engineVersion: "1.63.0", placement: "remote", ...o });
|
|
120
|
+
const failB = (b) => recordFailure(null, { signature: "s", hash: "H1", blocker: b });
|
|
121
|
+
it("an unchanged signature is refused; a changed engine version, placement or contract hash is admitted with a reason", () => {
|
|
122
|
+
const l = failB(blk()), cur = { engineVersion: "1.63.1", placement: "remote", contractHash: "c1" };
|
|
123
|
+
assert.equal(admitInput(l, "H1", cfg, cur).code, "loop.no_new_input");
|
|
124
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, engineVersion: "1.64.0" }).reason, /engine version/);
|
|
125
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, placement: "local" }).reason, /placement/);
|
|
126
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, contractHash: "c2" }).reason, /contract hash/);
|
|
127
|
+
});
|
|
128
|
+
it("a referenced env key that changed admits", () => {
|
|
129
|
+
const l = failB(blk({ detail: "missing SOPS_KEY", env: { SOPS_KEY: "a" } }));
|
|
130
|
+
assert.equal(admitInput(l, "H1", cfg, { env: { SOPS_KEY: "a" } }).ok, false);
|
|
131
|
+
assert.match(admitInput(l, "H1", cfg, { env: { SOPS_KEY: "b" } }).reason, /SOPS_KEY/);
|
|
132
|
+
});
|
|
133
|
+
it("two identical signatures breach and a credentials block persists hostPin", () => {
|
|
134
|
+
let l = recordFailure(null, { signature: "x", hash: "H1", blocker: blk({ detail: "Builder is blocked (credentials): ops_credentials" }) });
|
|
135
|
+
assert.equal(l.hostPin, true);
|
|
136
|
+
assert.equal(normalizeLedger(JSON.parse(renderAttempts(l).replace(/^<!-- FORGE:ATTEMPTS /, "").replace(/ -->$/, ""))).hostPin, true);
|
|
137
|
+
l = recordFailure(l, { signature: "x", hash: "H2" });
|
|
138
|
+
assert.equal(breach(l, cfg).kind, "identical");
|
|
139
|
+
assert.equal(l.hostPin, true);
|
|
140
|
+
});
|
|
141
|
+
});
|
package/bin/lean/basered.mjs
CHANGED
|
@@ -43,6 +43,13 @@ export function baseRedPaths(rows = []) {
|
|
|
43
43
|
return { src: src.slice(0, 20), tests: tests.slice(0, 20) };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/** #5913: true when the lane's changed files include a file the failing guard names (guarded code first, else its tests): the lane is then the base fix, not a bystander. */
|
|
47
|
+
export function diffTouchesGuard({ changed = [], failed = [] } = {}) {
|
|
48
|
+
const { src, tests } = baseRedPaths(failed);
|
|
49
|
+
const have = new Set((changed ?? []).map((f) => String(f).trim().replace(/^\.\//, "")).filter(Boolean));
|
|
50
|
+
return [...src, ...tests].some((p) => have.has(p));
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
/** Issue number a commit stands for: a closing keyword, else an `issue-N` branch name (merge commit), else the last `(#N)` of the subject. */
|
|
47
54
|
export function issueOf(subject = "", body = "") {
|
|
48
55
|
const text = `${subject}\n${body}`;
|
|
@@ -158,3 +165,77 @@ async function fileBaseRed({ ghc, repo, att, body, title, key, commitDate }) {
|
|
|
158
165
|
return n ? Number(n[1]) : null;
|
|
159
166
|
} catch { return null; }
|
|
160
167
|
}
|
|
168
|
+
|
|
169
|
+
// #5992: one red-base verdict per (repo, base ref), valid for BASE_PROBE_TTL_MS and only while the base sha is unchanged.
|
|
170
|
+
export const BASE_PROBE_TTL_MS = 10 * 60 * 1000;
|
|
171
|
+
const probeCache = new Map();
|
|
172
|
+
const probeKey = (repo, base) => `${repo ?? ""}\u0000${base}`;
|
|
173
|
+
|
|
174
|
+
/** Cached verdict `{red, sha, att, commands, outputs}` for (repo, base) at `sha`; null on a miss, an expired entry or a moved sha. */
|
|
175
|
+
export function cachedBaseVerdict({ repo, base, sha, now = Date.now(), ttlMs = BASE_PROBE_TTL_MS } = {}) {
|
|
176
|
+
const e = probeCache.get(probeKey(repo, base));
|
|
177
|
+
if (!e || !sha || e.sha !== sha || now - e.at >= ttlMs) return null;
|
|
178
|
+
return e.verdict;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Record a verdict for (repo, base) at `sha` (a lane's guardRed shares its red result so later lanes and the dispatcher skip the probe). */
|
|
182
|
+
export function recordBaseVerdict({ repo, base, sha, red, att = null, commands = [], outputs = {}, now = Date.now() } = {}) {
|
|
183
|
+
if (!sha) return null;
|
|
184
|
+
const verdict = { red: !!red, sha, att, commands, outputs };
|
|
185
|
+
probeCache.set(probeKey(repo, base), { sha, at: now, verdict });
|
|
186
|
+
return verdict;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function clearBaseVerdicts() { probeCache.clear(); }
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* #5992: the dispatcher's one probe per (repo, base sha). `readSha()` gives the current base sha; a fresh cache entry for it is
|
|
193
|
+
* returned as is, otherwise `commands` run once on the base (runOnBase) and the verdict, with its attribution, is cached.
|
|
194
|
+
* Never throws; null when the sha or the base run gives no evidence (a timeout or env failure is not a red base).
|
|
195
|
+
*/
|
|
196
|
+
export async function probeBase({ repo, base, commands = [], readSha, git, runCommand, cwd, env, timeoutMs, now = Date.now(), ttlMs = BASE_PROBE_TTL_MS, fs = nodeFs } = {}) {
|
|
197
|
+
try {
|
|
198
|
+
if (!commands.length) return null;
|
|
199
|
+
const sha = String((await readSha()) ?? "").trim();
|
|
200
|
+
if (!sha) return null;
|
|
201
|
+
const hit = cachedBaseVerdict({ repo, base, sha, now, ttlMs });
|
|
202
|
+
if (hit) return hit;
|
|
203
|
+
const baseRuns = await runOnBase({ commands, git, runCommand, mergeBase: sha, cwd, env, timeoutMs, fs });
|
|
204
|
+
const { baseRed } = classifyBaseRed({ failed: commands.map((command) => ({ command })), baseRuns });
|
|
205
|
+
if (!baseRuns.length) return null;
|
|
206
|
+
const cmds = baseRed.map((f) => f.command);
|
|
207
|
+
const att = cmds.length ? await attribute({ failed: baseRuns.filter((b) => cmds.includes(b.command)), git, base: sha }) : null;
|
|
208
|
+
const outputs = Object.fromEntries(baseRuns.filter((b) => cmds.includes(b.command)).map((b) => [b.command, b.output]));
|
|
209
|
+
return recordBaseVerdict({ repo, base, sha, red: cmds.length > 0, att, commands: cmds, outputs, now });
|
|
210
|
+
} catch { return null; }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* #5992: a lane that touches none of the files the red guard names (the attributed `att.files`) may bypass the base.red hold;
|
|
215
|
+
* the guard is re-run on the merged tree at merge. False without both a known surface and a known lane diff (never guess a bypass).
|
|
216
|
+
*/
|
|
217
|
+
export function bypassesGuard({ laneFiles = [], att = null } = {}) {
|
|
218
|
+
const surface = (att?.files ?? []).map((f) => String(f).replace(/^\.\//, "").replace(/\/+$/, "")).filter(Boolean);
|
|
219
|
+
const lane = (laneFiles ?? []).map((f) => String(f).trim().replace(/^\.\//, "")).filter(Boolean);
|
|
220
|
+
if (!surface.length || !lane.length) return false;
|
|
221
|
+
return !lane.some((f) => surface.some((s) => f === s || f.startsWith(`${s}/`)));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* #6049: one issue per required release check the lane cannot run (lane-check parity gap), deduped by a hidden marker
|
|
226
|
+
* keyed on the context name: an open or recent issue gets no second copy. Never throws; returns the issue numbers filed.
|
|
227
|
+
*/
|
|
228
|
+
export async function reportParityGaps({ ghc, repo, release, gaps = [] }) {
|
|
229
|
+
const filed = [];
|
|
230
|
+
for (const g of gaps) {
|
|
231
|
+
const key = `<!-- FORGE:PARITY_GAP ${String(g.context).replace(/[^\w .:/()-]/g, "_")} -->`;
|
|
232
|
+
try {
|
|
233
|
+
if ((await findKeyed({ ghc, repo, key })).length) continue;
|
|
234
|
+
const body = `${key}\n## Lane-check parity gap\nThe required check \`${g.context}\` on \`${release}\` has no lane equivalent, so a lane cannot catch its failures before the release PR: ${g.reason}.`;
|
|
235
|
+
const url = String(await ghc(["issue", "create", "-R", repo, "--title", `ci: required release check ${g.context} has no lane pre-PR check`.slice(0, 120), "--body", body])).trim();
|
|
236
|
+
const n = url.match(/\/issues\/(\d+)/);
|
|
237
|
+
if (n) filed.push(Number(n[1]));
|
|
238
|
+
} catch { /* best effort */ }
|
|
239
|
+
}
|
|
240
|
+
return filed;
|
|
241
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
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 { classifyBaseRed, baseRedPaths, issueOf, attribute, runOnBase, reportBaseRed } from "./basered.mjs";
|
|
5
|
+
import { classifyBaseRed, baseRedPaths, issueOf, attribute, runOnBase, reportBaseRed, probeBase, bypassesGuard, cachedBaseVerdict, recordBaseVerdict, clearBaseVerdicts, BASE_PROBE_TTL_MS } from "./basered.mjs";
|
|
6
6
|
|
|
7
7
|
const SHA = "13834f1c51".padEnd(40, "0");
|
|
8
8
|
|
|
@@ -117,3 +117,70 @@ describe("reportTrainBaseRed (#5838)", () => {
|
|
|
117
117
|
assert.match(cr[cr.indexOf("--title") + 1], /staging is red on required check build/);
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
|
+
|
|
121
|
+
describe("base probe cache (#5992)", () => {
|
|
122
|
+
const SHA2 = "2".repeat(40);
|
|
123
|
+
const mk = (sha, rc = 1) => {
|
|
124
|
+
const calls = { run: 0 };
|
|
125
|
+
const git = async (a) => (a[0] === "rev-parse" ? sha : a[0] === "log" ? `${sha}\x1ffix: x (#7)\x1f` : "");
|
|
126
|
+
const runCommand = async () => { calls.run++; return { rc, output: "tests/guard.test.mjs failed" }; };
|
|
127
|
+
return { calls, git, runCommand, readSha: async () => sha };
|
|
128
|
+
};
|
|
129
|
+
const base = { repo: "o/r", base: "staging", commands: ["guard"], cwd: process.cwd(), timeoutMs: 1000 };
|
|
130
|
+
|
|
131
|
+
it("hit within the TTL: one probe run serves every later call and carries the attribution", async () => {
|
|
132
|
+
clearBaseVerdicts();
|
|
133
|
+
const m = mk(SHA);
|
|
134
|
+
const a = await probeBase({ ...base, ...m, now: 1000 });
|
|
135
|
+
const b = await probeBase({ ...base, ...m, now: 1000 + BASE_PROBE_TTL_MS - 1 });
|
|
136
|
+
assert.equal(m.calls.run, 1);
|
|
137
|
+
assert.equal(a.red, true);
|
|
138
|
+
assert.deepEqual(b, a);
|
|
139
|
+
assert.equal(b.att.issue, 7);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("miss after the TTL", async () => {
|
|
143
|
+
clearBaseVerdicts();
|
|
144
|
+
const m = mk(SHA);
|
|
145
|
+
await probeBase({ ...base, ...m, now: 1000 });
|
|
146
|
+
await probeBase({ ...base, ...m, now: 1000 + BASE_PROBE_TTL_MS });
|
|
147
|
+
assert.equal(m.calls.run, 2);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("miss when the base sha moves; a green base is cached as not red", async () => {
|
|
151
|
+
clearBaseVerdicts();
|
|
152
|
+
const m = mk(SHA);
|
|
153
|
+
await probeBase({ ...base, ...m, now: 1000 });
|
|
154
|
+
const m2 = mk(SHA2, 0);
|
|
155
|
+
const v = await probeBase({ ...base, ...m2, now: 1001 });
|
|
156
|
+
assert.equal(m2.calls.run, 1);
|
|
157
|
+
assert.equal(v.red, false);
|
|
158
|
+
assert.equal(cachedBaseVerdict({ repo: "o/r", base: "staging", sha: SHA, now: 1002 }), null);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("a lane's recorded red verdict is reused without a probe run; an env failure is no verdict of red", async () => {
|
|
162
|
+
clearBaseVerdicts();
|
|
163
|
+
recordBaseVerdict({ repo: "o/r", base: "staging", sha: SHA, red: true, commands: ["guard"], now: 5 });
|
|
164
|
+
const m = mk(SHA);
|
|
165
|
+
assert.equal((await probeBase({ ...base, ...m, now: 6 })).red, true);
|
|
166
|
+
assert.equal(m.calls.run, 0);
|
|
167
|
+
clearBaseVerdicts();
|
|
168
|
+
const env = mk(SHA);
|
|
169
|
+
env.runCommand = async () => ({ rc: 1, output: "ModuleNotFoundError: x" });
|
|
170
|
+
assert.equal((await probeBase({ ...base, ...env, now: 7 })).red, false);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("#5992: path-scoped guard bypass", () => {
|
|
175
|
+
const att = { sha: "a".repeat(40), files: ["src/guard.mjs", "tests/dir"] };
|
|
176
|
+
it("bypasses a lane clear of the guarded surface", () => assert.equal(bypassesGuard({ laneFiles: ["docs/a.md"], att }), true));
|
|
177
|
+
it("does not bypass when the lane touches a named file or a file under a named dir", () => {
|
|
178
|
+
assert.equal(bypassesGuard({ laneFiles: ["docs/a.md", "src/guard.mjs"], att }), false);
|
|
179
|
+
assert.equal(bypassesGuard({ laneFiles: ["tests/dir/x.mjs"], att }), false);
|
|
180
|
+
});
|
|
181
|
+
it("does not bypass without a known surface or lane diff, or on a sibling-prefix name", () => {
|
|
182
|
+
assert.equal(bypassesGuard({ laneFiles: ["a"], att: null }), false);
|
|
183
|
+
assert.equal(bypassesGuard({ laneFiles: [], att }), false);
|
|
184
|
+
assert.equal(bypassesGuard({ laneFiles: ["tests/directory.mjs"], att }), true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -13,6 +13,7 @@ import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
|
|
13
13
|
import { spawn as spawnProc } from "node:child_process";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { listBatches, openBatch, REQUEUABLE, writeAtomic } from "./batch.mjs";
|
|
16
|
+
import { efficiencyLine, readEfficiency } from "./efficiency.mjs";
|
|
16
17
|
|
|
17
18
|
export const DEFAULT_HEALTH = Object.freeze({ rootFailed: true, terminalShare: 0.5, stalled: true, checksMin: Object.freeze([15, 60]), issue: null, notifyCommand: null });
|
|
18
19
|
/** #5469: a hold older than this many hours is flagged (`config.holdHours` overrides). */
|
|
@@ -224,6 +225,8 @@ export function batchStatusLines(root, id, { now = Date.now() } = {}) {
|
|
|
224
225
|
const k = Array.isArray(g?.lanes) ? g.lanes.length : Number(g?.requeued) || 0;
|
|
225
226
|
if (g?.agent) out.push(` agent ${g.agent} restarted at ${g.at ?? "?"}; ${k} lane${k === 1 ? "" : "s"} requeued (sandbox.lost)${g.closed ? "" : ", waiting for the agent"}`);
|
|
226
227
|
}
|
|
228
|
+
const eff = efficiencyLine(readEfficiency(b.dir)); // #5987: the efficiency ledger, when the daemon wrote one
|
|
229
|
+
if (eff) out.push(` ${eff}`);
|
|
227
230
|
return out;
|
|
228
231
|
}
|
|
229
232
|
|
|
@@ -310,7 +313,7 @@ export const appendBatchLog = (dir, text) => { try { appendFileSync(join(dir, BA
|
|
|
310
313
|
/** #5806: minutes without progress (setup reads or dispatch) before a stall is acted on; `FORGEDOCK_SCHEDD_STALL_MIN` overrides (was 10). */
|
|
311
314
|
export const DEFAULT_STALL_MIN = 3;
|
|
312
315
|
/** #5806: auto-recoveries one batch gets in total (one per distinct ready set); past it every stall alerts. */
|
|
313
|
-
export const MAX_STALL_RECOVERIES =
|
|
316
|
+
export const MAX_STALL_RECOVERIES = 6;
|
|
314
317
|
/** #5745: `; admission held by <code>: <detail>` for each failing preflight gate, "" when none. Pure. */
|
|
315
318
|
export const holdGateDetail = (gates) => (Array.isArray(gates) ? gates : []).filter((g) => g?.code).map((g) => `; admission held by ${g.code}: ${g.detail ?? "failing"}`).join("");
|
|
316
319
|
/** #5938: `{running, k, local, remote, text}`: the live lanes of a saved state against K; a run record with `remote` is a pool lane. Pure. */
|
|
@@ -328,7 +331,7 @@ export function runningSplit(state, parallel = null) {
|
|
|
328
331
|
export function evaluateDispatchStall(state, { held = [], parallel = null, hosted = false, lastProgressMs = null, now = Date.now(), windowMin = DEFAULT_STALL_MIN, cancelled = false, reported = false, gates = [], lanesAliveMs = null, paused = null } = {}) {
|
|
329
332
|
if (!state || cancelled || reported || lastProgressMs === null) return null;
|
|
330
333
|
if (paused) return null; // #5975: an operator pause is an intended wait, not a dispatch stall
|
|
331
|
-
if (state.breaker && !state.breaker.transport) return null; // an operator --resume clears it; a re-host would stop again at once
|
|
334
|
+
if (state.breaker && !state.breaker.transport && !state.breaker.environmental) return null; // an operator --resume clears it; a re-host would stop again at once
|
|
332
335
|
const order = new Set((state.order ?? []).map(Number)), results = state.results ?? {}, heldSet = new Set(held.map(Number));
|
|
333
336
|
const running = Object.keys(state.running ?? {}).length;
|
|
334
337
|
const k = Number.isInteger(parallel) && parallel > 0 ? parallel : Number.isInteger(state.parallel) && state.parallel > 0 ? state.parallel : 1;
|
|
@@ -350,17 +353,22 @@ export function evaluateDispatchStall(state, { held = [], parallel = null, hoste
|
|
|
350
353
|
* daemon restarts so a restart never re-arms it; `probe` is the batch env probe (lanecheck `probeBatchEnv`), null when the
|
|
351
354
|
* batch pins no env. A broken env alerts at once (a resume would stall or fail the same way); the first stall of a ready set
|
|
352
355
|
* is recovered once (`resume` an unhosted batch, `restart-daemon` when its runner is alive but wedged); the same ready set
|
|
353
|
-
* stalling again
|
|
354
|
-
*
|
|
356
|
+
* stalling again is recovered again after a doubling backoff (#6082), a batch past `maxRecoveries` alerts with the probed cause,
|
|
357
|
+
* and a `pool-capacity` stall only waits. Pure.
|
|
358
|
+
* @returns {{action: "resume"|"restart-daemon"|"alert"|"wait", sig: string, cause: string|null}}
|
|
355
359
|
*/
|
|
356
|
-
|
|
360
|
+
/** #5988: the diagnosis a stall recovery acts on: the `dispatch-stalled` cause plus the gates in force. */
|
|
361
|
+
export const stallCause = (stall) => `${stall.code ?? "dispatch-stalled"}${stall.gates?.length ? `[${[...stall.gates].sort().join(",")}]` : ""}`;
|
|
362
|
+
|
|
363
|
+
export function decideStallAction(stall, { recovery = null, probe = null, hosted = false, maxRecoveries = MAX_STALL_RECOVERIES, now = Date.now(), windowMin = DEFAULT_STALL_MIN } = {}) {
|
|
357
364
|
const sig = stall.ready.join(",");
|
|
365
|
+
if (stall.code === "pool-capacity") return { action: "wait", sig, cause: `pool capacity: ${stall.reason}` }; // #6082: an intended wait, never recovered or alerted
|
|
358
366
|
if (probe && !probe.ok) return { action: "alert", sig, cause: `batch env: ${probe.detail}; fix it with --set-env <id> PATH=<dirs holding the tools>, then --resume` };
|
|
359
367
|
const count = Number(recovery?.count) || 0;
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
368
|
+
if (count >= maxRecoveries) return { action: "alert", sig, cause: `${count} auto-recoveries already spent${probe ? `; ${probe.detail}` : ""}` };
|
|
369
|
+
// #6082: a repeat stall is recovered again once the backoff (one window, doubling per recovery, capped at an hour) has passed
|
|
370
|
+
const at = Date.parse(recovery?.at ?? ""), cooldownMs = Math.min(60, windowMin * 2 ** Math.max(0, count - 1)) * 60000;
|
|
371
|
+
if (recovery && Number.isFinite(at) && now - at < cooldownMs) return { action: "wait", sig, cause: `recovered ${recovery.action} at ${recovery.at}; next attempt after the backoff` };
|
|
364
372
|
return { action: hosted ? "restart-daemon" : "resume", sig, cause: null };
|
|
365
373
|
}
|
|
366
374
|
|
|
@@ -368,8 +376,8 @@ export function decideStallAction(stall, { recovery = null, probe = null, hosted
|
|
|
368
376
|
export function recordStallRecovery(batch, stall, { action, sig = stall.ready.join(","), now = Date.now() } = {}) {
|
|
369
377
|
const prev = readHealth(batch.dir) ?? {}, at = new Date(now).toISOString();
|
|
370
378
|
const what = action === "restart-daemon" ? "restart the hosting schedd (its runner is alive but not progressing)" : "resume the batch (no runner hosts it)";
|
|
371
|
-
const text = `FORGE:DECISION batch ${batch.id} stall-recovery: ${what}; why: ${stall.detail}; alternative: alert only (a repeat of this stall
|
|
372
|
-
try { writeHealth(batch.dir, { ...prev, stallRecovery: { sig, at, action, count: (Number(prev.stallRecovery?.count) || 0) + 1, detail: stall.detail } }); } catch { /* advisory */ }
|
|
379
|
+
const text = `FORGE:DECISION batch ${batch.id} stall-recovery: ${what}; why: ${stall.detail}; alternative: alert only (a repeat of this stall is recovered again after a backoff, #6082)`;
|
|
380
|
+
try { writeHealth(batch.dir, { ...prev, stallRecovery: { sig, at, action, cause: stallCause(stall), gates: stall.gates ?? [], count: (Number(prev.stallRecovery?.count) || 0) + 1, detail: stall.detail } }); } catch { /* advisory */ }
|
|
373
381
|
appendBatchLog(batch.dir, `${at} ${text}`);
|
|
374
382
|
return text;
|
|
375
383
|
}
|
|
@@ -406,7 +414,7 @@ export function recordStallAlert(batch, stall, { now = Date.now(), cause = null
|
|
|
406
414
|
const sig = stall.ready.join(","), prev = readHealth(batch.dir) ?? {};
|
|
407
415
|
if (prev.stall?.sig === sig) return false;
|
|
408
416
|
const at = new Date(now).toISOString();
|
|
409
|
-
const text = `BATCH UNHEALTHY ${batch.id} (dispatch-stalled)\n cause: dispatch-stalled: ${stall.detail}${cause ? `\n probed: ${cause}` : ""}\n recovery:\n forgedock orchestrate --resume ${batch.id}\n forgedock orchestrate --cancel ${batch.id}`;
|
|
417
|
+
const text = `BATCH UNHEALTHY ${batch.id} (${stall.code ?? "dispatch-stalled"})\n cause: ${stall.code ?? "dispatch-stalled"}: ${stall.detail}${cause ? `\n probed: ${cause}` : ""}\n recovery:\n forgedock orchestrate --resume ${batch.id}\n forgedock orchestrate --cancel ${batch.id}`;
|
|
410
418
|
try { writeHealth(batch.dir, { ...prev, stall: { at, sig, detail: stall.detail, ...(cause ? { cause } : {}) }, ...(prev.alertedAt ? {} : { alertedAt: at, alert: text }) }); } catch { return false; }
|
|
411
419
|
appendBatchLog(batch.dir, `${at} ${text.split("\n").slice(0, cause ? 3 : 2).join(" | ")}`);
|
|
412
420
|
return true;
|
|
@@ -288,25 +288,34 @@ describe("#5806 setup/dispatch stall: 3-min threshold, one auto-recovery, then a
|
|
|
288
288
|
assert.match(d.cause, /batch env: gh, git not resolvable on the batch env PATH \(1 entry: \/bogus\)/);
|
|
289
289
|
});
|
|
290
290
|
|
|
291
|
-
it("a recovery is recorded
|
|
291
|
+
it("a recovery is recorded (health.json + FORGE:DECISION in batch.log); a repeat waits out the backoff, then is recovered again (#6082)", () => {
|
|
292
292
|
const root = tmpDir("stall-recover-"), b = openBatch(root, "b1");
|
|
293
293
|
b.writePlan({ daemon: true, repo: "o/r" });
|
|
294
|
-
const s = at(4);
|
|
294
|
+
const s = at(4), ok = { ok: true, detail: "batch env PATH resolves gh, git, node" };
|
|
295
295
|
const text = recordStallRecovery(b, s, { action: "resume", now: NOW });
|
|
296
296
|
assert.match(text, /^FORGE:DECISION batch b1 stall-recovery: resume the batch/);
|
|
297
297
|
assert.match(readFileSync(join(b.dir, "batch.log"), "utf8"), /FORGE:DECISION batch b1 stall-recovery/);
|
|
298
298
|
const rec = readHealth(b.dir).stallRecovery;
|
|
299
299
|
assert.deepEqual([rec.sig, rec.action, rec.count], ["1,2,3,4", "resume", 1]);
|
|
300
300
|
// the daemon restarted meanwhile: the decision reads health.json, not memory
|
|
301
|
-
const
|
|
302
|
-
assert.equal(
|
|
303
|
-
|
|
304
|
-
assert.equal(
|
|
305
|
-
assert.equal(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
301
|
+
const early = decideStallAction(s, { recovery: rec, hosted: true, probe: ok, now: NOW + 60_000 });
|
|
302
|
+
assert.equal(early.action, "wait", "inside the backoff nothing acts and nothing alerts");
|
|
303
|
+
const later = decideStallAction(s, { recovery: rec, hosted: true, probe: ok, now: NOW + 4 * 60_000 });
|
|
304
|
+
assert.equal(later.action, "restart-daemon", "the same stall persisting past the backoff is healed again, no operator");
|
|
305
|
+
assert.equal(decideStallAction(s, { recovery: { ...rec, count: 3 }, hosted: false, now: NOW + 3 * 3600_000 }).action, "resume");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("a pool-capacity stall only waits: no recovery, no alert (#6082)", () => {
|
|
309
|
+
const s = { code: "pool-capacity", reason: "pool full", ready: [1], detail: "waiting on pool capacity" };
|
|
310
|
+
assert.equal(decideStallAction(s, { hosted: true }).action, "wait");
|
|
311
|
+
assert.equal(decideStallAction(s, { hosted: false, recovery: { sig: "1", at: "x", action: "resume", count: MAX_STALL_RECOVERIES } }).action, "wait");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("an alert names the stall code, not always dispatch-stalled (#6082)", () => {
|
|
315
|
+
const root = tmpDir("stall-code-"), b = openBatch(root, "b1");
|
|
316
|
+
b.writePlan({ daemon: true, repo: "o/r" });
|
|
317
|
+
recordStallAlert(b, { ...at(4), code: "pool-capacity" }, { now: NOW });
|
|
318
|
+
assert.match(readHealth(b.dir).alert, /BATCH UNHEALTHY b1 \(pool-capacity\)/);
|
|
310
319
|
});
|
|
311
320
|
|
|
312
321
|
it("a batch that spent MAX_STALL_RECOVERIES alerts even on a new ready set", () => {
|
|
@@ -406,3 +415,38 @@ describe("#5938 stall verdict is re-evaluated: full K, recovery lanes, pool capa
|
|
|
406
415
|
assert.match(batchVerdict("b1", s, { action: "alert", cause: "no gh" }), /stalled -> no action, needs you \(no gh;/);
|
|
407
416
|
});
|
|
408
417
|
});
|
|
418
|
+
|
|
419
|
+
describe("#5988: a second restart for the same stall cause is refused", () => {
|
|
420
|
+
const stall = (ready, gates) => ({ code: "dispatch-stalled", ready, gates, detail: "stalled" });
|
|
421
|
+
it("a different ready set with the same cause waits out the backoff and the diagnosis is recorded", () => {
|
|
422
|
+
const root = tmpDir("stallcause");
|
|
423
|
+
mkdirSync(join(root, "b1"), { recursive: true });
|
|
424
|
+
const batch = { id: "b1", dir: join(root, "b1") };
|
|
425
|
+
const first = decideStallAction(stall([1, 2], ["base.red"]), { recovery: null, hosted: true });
|
|
426
|
+
assert.equal(first.action, "restart-daemon");
|
|
427
|
+
recordStallRecovery(batch, stall([1, 2], ["base.red"]), { action: first.action, sig: first.sig });
|
|
428
|
+
const rec = readHealth(batch.dir).stallRecovery;
|
|
429
|
+
assert.equal(rec.cause, "dispatch-stalled[base.red]");
|
|
430
|
+
assert.deepEqual(rec.gates, ["base.red"]);
|
|
431
|
+
const again = decideStallAction(stall([3], ["base.red"]), { recovery: rec, hosted: true });
|
|
432
|
+
assert.equal(again.action, "wait", "#6082: inside the backoff");
|
|
433
|
+
assert.equal(decideStallAction(stall([3], ["base.red"]), { recovery: rec, hosted: true, now: Date.now() + 3600_000 }).action, "restart-daemon", "#6082: after it, healed again");
|
|
434
|
+
assert.equal(decideStallAction(stall([3], []), { recovery: rec, hosted: true }).action, "wait", "backoff is per batch");
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe("#5987 efficiency status line", () => {
|
|
439
|
+
it("batch status shows the efficiency line with and without breaches; none without a ledger", async () => {
|
|
440
|
+
const { writeEfficiency } = await import("./efficiency.mjs");
|
|
441
|
+
const root = tmpDir("bh-eff-");
|
|
442
|
+
mkdirSync(join(root, "b1"));
|
|
443
|
+
const b = openBatch(root, "b1");
|
|
444
|
+
b.writePlan({ argv: ["1"], created: new Date().toISOString() });
|
|
445
|
+
assert.ok(!statusLines(root, { batch: "b1" }).some((l) => /efficiency:/.test(l)));
|
|
446
|
+
const eff = { v: 1, concurrency: { running: 3, ceiling: 12, achieved: 3 }, limiters: ["sandbox.capacity", "pool.host_load"], breaches: [] };
|
|
447
|
+
writeEfficiency(b.dir, eff);
|
|
448
|
+
assert.ok(statusLines(root, { batch: "b1" }).includes(" efficiency: 3/12 lanes (25%) - limiter sandbox.capacity pool.host_load"));
|
|
449
|
+
writeEfficiency(b.dir, { ...eff, breaches: [{ issue: 6001 }, { issue: 6001 }] });
|
|
450
|
+
assert.ok(statusLines(root, { batch: "b1" }).includes(" efficiency: 3/12 lanes (25%) - limiter sandbox.capacity pool.host_load; 2 SLO breaches -> FD#6001"));
|
|
451
|
+
});
|
|
452
|
+
});
|
package/bin/lean/batch.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { spawn } from "node:child_process";
|
|
|
20
20
|
import { createHash } from "node:crypto";
|
|
21
21
|
import { homedir, hostname } from "node:os";
|
|
22
22
|
import { dirname, join, resolve, sep } from "node:path";
|
|
23
|
+
import { humanCode } from "./reconcile.mjs";
|
|
23
24
|
import { sanitizeOverride, validateExecutionPatch } from "./live-execution.mjs";
|
|
24
25
|
|
|
25
26
|
export const RAM_FS = new Set(["tmpfs", "ramfs"]);
|
|
@@ -113,6 +114,23 @@ const readAdded = (file) => {
|
|
|
113
114
|
export const REQUEUABLE = (outcome) => ["needs-human", "engine-error", "held", "invalid", "skipped", "ci-pending", "pr-ready", "budget-exceeded", "lane-refused", "deferred"].includes(outcome) || /^dependency-/.test(String(outcome));
|
|
114
115
|
/** Key of one requeue entry; the runner records the applied keys in state.json `requeueApplied`. */
|
|
115
116
|
/** #5832: the `{dependency, branch, sha}` a stacked build of `issue` was admitted on (batch state `stacked`), or null. Rows carry `stacked`/`stackedOn`. */
|
|
117
|
+
/**
|
|
118
|
+
* #6008: sandboxes kept for adopt (issue, since, age, phase). `state.kept` records them as the lane returned them; a running
|
|
119
|
+
* remote record (handle) of a batch whose dispatcher is gone (`live` false) is a kept sandbox too. Newest listing order: by issue.
|
|
120
|
+
*/
|
|
121
|
+
export function keptSandboxes(state, { now = Date.now(), live = false } = {}) {
|
|
122
|
+
const out = new Map();
|
|
123
|
+
for (const [k, v] of Object.entries(state?.kept ?? {})) {
|
|
124
|
+
const issue = Number(k); if (!Number.isSafeInteger(issue) || !v) continue;
|
|
125
|
+
out.set(issue, { issue, since: v.since ?? null, phase: v.phase ?? null, ...(v.id ? { id: v.id } : {}) });
|
|
126
|
+
}
|
|
127
|
+
if (!live) for (const [k, rec] of Object.entries(state?.running ?? {})) {
|
|
128
|
+
const issue = Number(k);
|
|
129
|
+
if (!Number.isSafeInteger(issue) || out.has(issue) || !(rec?.handle || rec?.remote)) continue;
|
|
130
|
+
out.set(issue, { issue, since: rec.startedAt ?? null, phase: rec.phase ?? null, ...(rec.handle?.id ? { id: rec.handle.id } : {}) });
|
|
131
|
+
}
|
|
132
|
+
return [...out.values()].sort((a, b) => a.issue - b.issue).map((e) => ({ ...e, ageMs: (() => { const t = typeof e.since === "number" ? e.since : Date.parse(e.since); return Number.isFinite(t) ? Math.max(0, now - t) : null; })() }));
|
|
133
|
+
}
|
|
116
134
|
export const stackedOnOf = (state, issue) => state?.stacked?.[issue] ?? null;
|
|
117
135
|
|
|
118
136
|
export const requeueKey = (e) => `${e.issue}@${e.at}`;
|
|
@@ -185,6 +203,31 @@ export const dispatchOwner = (root, repo, issue, exceptId, opts = {}) => {
|
|
|
185
203
|
return (live.find((o) => o.running) ?? live.find((o) => o.id < exceptId))?.id ?? null;
|
|
186
204
|
};
|
|
187
205
|
|
|
206
|
+
/**
|
|
207
|
+
* #5978: coverage of a selector batch: every open issue the selector matches is exactly one of running, queued, backing-off (a
|
|
208
|
+
* deferral or re-admission wait), waiting on deps, human-blocked (the only reason to stay unscheduled), or `unscheduled`
|
|
209
|
+
* (the unhealthy state: matches but nothing will run it). Shared by `forgedock orchestrate --status`.
|
|
210
|
+
* @param {{state:object, open:Array<{number:number,labels?:string[]}>, now?:number}} p
|
|
211
|
+
*/
|
|
212
|
+
export function coverage({ state, open, now = Date.now() }) {
|
|
213
|
+
const st = state ?? {}, pending = new Set(st.pending ?? []), res = st.results ?? {}, readmit = st.readmit ?? {};
|
|
214
|
+
const out = { running: [], queued: [], backingOff: [], waitingDeps: [], humanBlocked: [], unscheduled: [] };
|
|
215
|
+
for (const { number: n, labels = [] } of open ?? []) {
|
|
216
|
+
const row = res[n], deps = (st.deps?.[n] ?? []).filter((d) => res[d]?.outcome !== "merged" && res[d]?.outcome !== "invalid");
|
|
217
|
+
if (st.running && Object.hasOwn(st.running, String(n))) out.running.push(n);
|
|
218
|
+
else if (row && humanCode(row, labels)) out.humanBlocked.push(n);
|
|
219
|
+
else if (!row && labels.some((l) => humanCode(null, [l]))) out.humanBlocked.push(n);
|
|
220
|
+
else if (pending.has(n) && (st.notBefore?.[n] ?? 0) > now) out.backingOff.push(n);
|
|
221
|
+
else if (pending.has(n) && deps.length) out.waitingDeps.push(n);
|
|
222
|
+
else if (pending.has(n)) out.queued.push(n);
|
|
223
|
+
else if (row && ["deferred", "held", "engine-error"].includes(row.outcome) && readmit[n]) out.backingOff.push(n);
|
|
224
|
+
else if (row && (row.outcome === "pr-ready" || row.outcome === "ci-pending")) out.queued.push(n); // a PR is on its way to merge
|
|
225
|
+
else if (row && /^(skipped|held)$/.test(row.outcome) && deps.length) out.waitingDeps.push(n);
|
|
226
|
+
else out.unscheduled.push(n);
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
|
|
188
231
|
/** Handle on one batch directory. */
|
|
189
232
|
export function openBatch(root, id) {
|
|
190
233
|
if (!ID_RE.test(String(id ?? ""))) throw new Error(`invalid batch id ${JSON.stringify(id)}`);
|
|
@@ -300,6 +343,8 @@ export function openBatch(root, id) {
|
|
|
300
343
|
readRequeued: () => readRequeueFile(f("requeue")),
|
|
301
344
|
/** Entries the runner has not applied yet (a finished or unhosted batch with a pending requeue). */
|
|
302
345
|
unrunRequeues: () => { const done = new Set(readJson(f("state.json"))?.requeueApplied ?? []); return readRequeueFile(f("requeue")).filter((e) => !done.has(requeueKey(e))); },
|
|
346
|
+
/** #6008: the kept-sandbox listing of this batch (issue, since, ageMs, phase); `live` = its dispatcher is running. */
|
|
347
|
+
keptSandboxes: (live = false) => keptSandboxes(readJson(f("state.json")), { live }),
|
|
303
348
|
/** Issues held by `--hold` (#4592): the `hold` file, sorted unique positive integers; [] when missing or invalid. */
|
|
304
349
|
readHeld: () => readAdded(f("hold")),
|
|
305
350
|
/** #4656: gates waiting on issues (`gates` file: [{ name, waitsOn: [n...], since? }], written by the ship/settle pre-flight); [] when missing or invalid. */
|