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/attempts.mjs
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* Nothing here clears the ledger: releaseHeld, --requeue and --set-env leave it alone. A missing ledger always admits.
|
|
8
8
|
*/
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
|
-
import { amendmentKindProblems } from "./conformance.mjs";
|
|
11
10
|
import { parseContractComment } from "./render.mjs";
|
|
12
11
|
import { postUpsert, findLeading, engineCommentCount } from "./statuscomment.mjs";
|
|
13
12
|
|
|
@@ -31,18 +30,28 @@ export const emptyLedger = () => ({ attempts: 0, signatures: [], lastInputHash:
|
|
|
31
30
|
export function normalizeLedger(x) {
|
|
32
31
|
if (!x || typeof x !== "object") return emptyLedger();
|
|
33
32
|
return { attempts: Number.isInteger(x.attempts) && x.attempts > 0 ? x.attempts : 0, signatures: Array.isArray(x.signatures) ? x.signatures.map((s) => ({ ...s, sig: String(s?.sig ?? "") })) : [],
|
|
34
|
-
lastInputHash: typeof x.lastInputHash === "string" ? x.lastInputHash : null, spend: Number(x.spend) > 0 ? Number(x.spend) : 0, ...(Number.isInteger(x.comments) && x.comments >= 0 ? { comments: x.comments } : {}), ...(x.escalated ? { escalated: x.escalated } : {}) };
|
|
33
|
+
lastInputHash: typeof x.lastInputHash === "string" ? x.lastInputHash : null, spend: Number(x.spend) > 0 ? Number(x.spend) : 0, ...(Number.isInteger(x.comments) && x.comments >= 0 ? { comments: x.comments } : {}), ...(x.escalated ? { escalated: x.escalated } : {}), ...(x.hostPin ? { hostPin: true } : {}) };
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
/** `{maxAttempts, maxIdentical}` from the orchestration config (posint, else the defaults 4 and 2). */
|
|
38
37
|
export const budgets = (cfg) => ({ maxAttempts: Number(cfg?.maxAttempts) >= 1 ? Math.floor(cfg.maxAttempts) : DEFAULT_ISSUE_ATTEMPTS, maxIdentical: Number(cfg?.maxIdentical) >= 1 ? Math.floor(cfg.maxIdentical) : DEFAULT_MAX_IDENTICAL });
|
|
39
38
|
|
|
40
39
|
/** The ledger after one failed lane (a new object): attempts+1, the signature with its run link, the hash it ran under, spend added. */
|
|
41
|
-
|
|
40
|
+
const normDetail = (d) => String(d ?? "").replace(/https?:\/\/\S+/g, "").replace(/\b[0-9a-f]{7,40}\b/g, "").replace(/\d+/g, "#").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
41
|
+
/** #5931: what blocked a lane: code, normalized detail, contract hash, the engine version the lane ran, placement, and the env keys the detail names. */
|
|
42
|
+
export function blockerSignature({ code = null, detail = "", contractHash = null, engineVersion = null, placement = null, env = null } = {}) {
|
|
43
|
+
const envKeys = [...new Set(String(detail ?? "").match(/\b[A-Z][A-Z0-9]*_[A-Z0-9_]+\b/g) ?? [])].sort();
|
|
44
|
+
return { code: code ?? null, detail: normDetail(detail), contractHash: contractHash ?? null, engineVersion: engineVersion ? majorMinor(engineVersion) || String(engineVersion) : null, placement: placement ?? null, ...(envKeys.length ? { envKeys, env: Object.fromEntries(envKeys.map((k) => [k, env?.[k] == null ? null : sha(env[k])])) } : {}) };
|
|
45
|
+
}
|
|
46
|
+
/** A credentials block naming ops_credentials is pinned to the host on readmit. */
|
|
47
|
+
export const isCredentialsBlock = (detail) => /ops_credentials/i.test(String(detail ?? "")) && /credential/i.test(String(detail ?? ""));
|
|
48
|
+
|
|
49
|
+
export function recordFailure(ledger, { signature, hash = null, spend = 0, run = null, blocker = null }) {
|
|
42
50
|
const l = normalizeLedger(ledger);
|
|
43
51
|
const changed = hash && l.lastInputHash && hash !== l.lastInputHash; // a new input starts a new escalation window, the lifetime counters stay
|
|
44
|
-
const { escalated, ...rest } = l;
|
|
45
|
-
|
|
52
|
+
const { escalated, ...rest } = l;
|
|
53
|
+
const pin = l.hostPin || (blocker && isCredentialsBlock(blocker.detail)); // `comments` (the engine comment count seen at the last mirror) rides along
|
|
54
|
+
return { ...rest, ...(pin ? { hostPin: true } : {}), ...(escalated && !changed ? { escalated } : {}), attempts: l.attempts + 1, signatures: [...l.signatures, { sig: String(signature ?? ""), ...(hash ? { hash } : {}), ...(run ? { run } : {}), ...(blocker ? { blocker } : {}) }], lastInputHash: hash ?? l.lastInputHash, spend: Math.round((l.spend + (Number(spend) || 0)) * 1e6) / 1e6 };
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
/** The breach of the lifetime budget, or null: attempts reached the cap, or one signature exceeded `maxIdentical` failures. */
|
|
@@ -51,7 +60,7 @@ export function breach(ledger, cfg) {
|
|
|
51
60
|
const counts = new Map();
|
|
52
61
|
for (const s of l.signatures) counts.set(s.sig, (counts.get(s.sig) ?? 0) + 1);
|
|
53
62
|
const worst = [...counts].sort((a, b) => b[1] - a[1])[0];
|
|
54
|
-
if (worst && worst[1]
|
|
63
|
+
if (worst && worst[1] >= maxIdentical) return { kind: "identical", detail: `failure signature \`${worst[0]}\` repeated ${worst[1]} times (max_identical_signature ${maxIdentical})` };
|
|
55
64
|
if (l.attempts >= maxAttempts) return { kind: "attempts", detail: `${l.attempts} lanes ran (max_attempts_per_issue ${maxAttempts})` };
|
|
56
65
|
return null;
|
|
57
66
|
}
|
|
@@ -60,15 +69,28 @@ export function breach(ledger, cfg) {
|
|
|
60
69
|
* Admission of a re-run. `hash` null (unreadable input) fails open. Returns {ok:true} or {ok:false, code, reason}: `escalate` (a budget
|
|
61
70
|
* breach not yet escalated), or `loop.no_new_input` (the same input after a failure).
|
|
62
71
|
*/
|
|
63
|
-
export function admitInput(ledger, hash, cfg) {
|
|
72
|
+
export function admitInput(ledger, hash, cfg, cur = null) {
|
|
64
73
|
const l = normalizeLedger(ledger);
|
|
65
74
|
if (!hash || !l.attempts || !l.lastInputHash || hash !== l.lastInputHash) return { ok: true };
|
|
75
|
+
const why = changedSince(l.signatures[l.signatures.length - 1]?.blocker, cur); // #5931: the hash omits placement and env values
|
|
76
|
+
if (why) return { ok: true, reason: why };
|
|
66
77
|
const b = breach(l, cfg);
|
|
67
78
|
if (b && !l.escalated) return { ok: false, code: "escalate", reason: b.detail };
|
|
68
79
|
const last = l.signatures[l.signatures.length - 1]?.sig;
|
|
69
80
|
return { ok: false, code: NO_NEW_INPUT, reason: `input unchanged since the last failure${last ? ` (\`${last}\`)` : ""}${b ? `; ${b.detail}` : ""}` };
|
|
70
81
|
}
|
|
71
82
|
|
|
83
|
+
/** What relevant thing changed since the blocker (engine version, placement, contract hash, a referenced env key), or null. */
|
|
84
|
+
export function changedSince(b, cur) {
|
|
85
|
+
if (!b || !cur) return null;
|
|
86
|
+
const diff = (a, c) => a != null && c != null && String(a) !== String(c);
|
|
87
|
+
if (diff(b.engineVersion, cur.engineVersion ? majorMinor(cur.engineVersion) || cur.engineVersion : null)) return `engine version changed ${b.engineVersion} -> ${cur.engineVersion}`;
|
|
88
|
+
if (diff(b.placement, cur.placement)) return `placement changed ${b.placement} -> ${cur.placement}`;
|
|
89
|
+
if (diff(b.contractHash, cur.contractHash)) return "contract hash changed";
|
|
90
|
+
const keys = (b.envKeys ?? []).filter((k) => cur.env && cur.env[k] !== undefined && (b.env?.[k] ?? null) !== (cur.env[k] == null ? null : sha(cur.env[k])));
|
|
91
|
+
return keys.length ? `env key changed: ${keys.join(", ")}` : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
export const markEscalated = (ledger, at) => ({ ...normalizeLedger(ledger), escalated: at ?? true });
|
|
73
95
|
|
|
74
96
|
/** The one consolidated FORGE:ESCALATION body: signatures with run links, spend, what unblocks it. */
|
|
@@ -87,28 +109,6 @@ export function parseAttempts(body) {
|
|
|
87
109
|
try { return normalizeLedger(JSON.parse(m[1])); } catch { return null; }
|
|
88
110
|
}
|
|
89
111
|
|
|
90
|
-
const ID_RE = /^#?\d+$/;
|
|
91
|
-
/**
|
|
92
|
-
* The shared amendment schema (#5986, extends #5979 past guard ids): kind/path/requirement presence plus field types. Returns the
|
|
93
|
-
* rejection strings, [] when valid; the lane returns them to the builder once and never posts a rejected shape.
|
|
94
|
-
*/
|
|
95
|
-
export function validateAmendments(amendments) {
|
|
96
|
-
if (amendments !== undefined && amendments !== null && !Array.isArray(amendments)) return ["amendments must be an array"];
|
|
97
|
-
const out = [...amendmentKindProblems(amendments)];
|
|
98
|
-
for (const a of amendments ?? []) {
|
|
99
|
-
if (!a || typeof a !== "object") { out.push(`amendment must be an object: ${JSON.stringify(a ?? null).slice(0, 120)}`); continue; }
|
|
100
|
-
const tag = JSON.stringify(a).slice(0, 200);
|
|
101
|
-
if (a.why !== undefined && typeof a.why !== "string") out.push(`amendment 'why' must be a string: ${tag}`);
|
|
102
|
-
if (a.path !== undefined && typeof a.path !== "string") out.push(`amendment 'path' must be a string: ${tag}`);
|
|
103
|
-
if (a.kind === "supersedes" && a.guard !== undefined && !ID_RE.test(String(a.guard))) out.push(`supersedes 'guard' must be an issue id like #123: ${tag}`);
|
|
104
|
-
if (a.kind === "decision") {
|
|
105
|
-
const d = a.decision;
|
|
106
|
-
if (!d || typeof d !== "object" || typeof d.choice !== "string" || !d.choice.trim() || (d.anchors !== undefined && !Array.isArray(d.anchors))) out.push(`decision needs {choice: string, anchors: [paths]}: ${tag}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return [...new Set(out)];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
112
|
/** Hash of the last trusted, parseable FORGE:CONTRACT comment (the frozen contract), or null. */
|
|
113
113
|
export function frozenContractHash(comments, trusted) {
|
|
114
114
|
let h = null;
|
|
@@ -125,16 +125,19 @@ export function frozenContractHash(comments, trusted) {
|
|
|
125
125
|
* The orchestrate seam, bound to GitHub: `hash(n)` reads the issue and computes the input hash (null on any read failure: fail open),
|
|
126
126
|
* `load(n)` reads the FORGE:ATTEMPTS comment, `mirror(n, ledger)` upserts it, `notify(...)` posts the one escalation or the no-new-input note.
|
|
127
127
|
*/
|
|
128
|
-
export function makeAttemptsSeam({ gh, repo, engineVersion = null, sandboxVersion = null, cfg = {}, trusted = null, contractHash = null }) {
|
|
128
|
+
export function makeAttemptsSeam({ gh, repo, engineVersion = null, hostVersion = null, sandboxVersion = null, cfg = {}, trusted = null, contractHash = null }) {
|
|
129
129
|
const view = async (n) => JSON.parse(String(await gh(["issue", "view", String(n), "-R", repo, "--json", "title,body,labels,comments"])));
|
|
130
130
|
const isTrusted = async () => trusted ?? (await import("./prefilter.mjs")).isTrustedIssueComment;
|
|
131
|
+
let seenSandbox = sandboxVersion;
|
|
131
132
|
return {
|
|
133
|
+
noteSandboxVersion(v) { if (v) seenSandbox = v; },
|
|
132
134
|
cfg,
|
|
133
135
|
async hash(n) {
|
|
134
136
|
try {
|
|
135
137
|
const v = await view(n), t = await isTrusted();
|
|
136
138
|
const decisions = (v.comments ?? []).filter((c) => /^\s*<!--\s*FORGE:DECISION\b/.test(c?.body ?? "") && t(c)).map((c) => c.body);
|
|
137
|
-
return computeInputHash({ title: v.title, body: v.body, labels: v.labels, decisions, engineVersion, sandboxVersion,
|
|
139
|
+
return computeInputHash({ title: v.title, body: v.body, labels: v.labels, decisions, engineVersion, sandboxVersion: seenSandbox ?? hostVersion, // the version the lane ran; the host's only when none is known
|
|
140
|
+
contractHash: contractHash ? await contractHash(n) : frozenContractHash(v.comments, t) });
|
|
138
141
|
} catch { return null; }
|
|
139
142
|
},
|
|
140
143
|
async load(n) {
|
|
@@ -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 { computeInputHash, emptyLedger, normalizeLedger, recordFailure, breach, admitInput, markEscalated, frozenContractHash, renderEscalation, renderAttempts, parseAttempts,
|
|
5
|
+
import { computeInputHash, emptyLedger, normalizeLedger, recordFailure, breach, admitInput, markEscalated, blockerSignature, frozenContractHash, renderEscalation, renderAttempts, parseAttempts, budgets, makeAttemptsSeam } from "./attempts.mjs";
|
|
6
6
|
import { renderContract } from "./render.mjs";
|
|
7
7
|
import { postKeyed } from "./statuscomment.mjs";
|
|
8
8
|
|
|
@@ -31,19 +31,19 @@ describe("#5986 admission, budgets, escalation", () => {
|
|
|
31
31
|
const a = admitInput(fail(null, "ci.red:x", "H1"), "H1", cfg);
|
|
32
32
|
assert.equal(a.ok, false); assert.equal(a.code, "loop.no_new_input"); assert.match(a.reason, /ci\.red:x/);
|
|
33
33
|
});
|
|
34
|
-
it("the
|
|
35
|
-
let l = fail(null, "s", "H1");
|
|
34
|
+
it("the 2nd identical signature breaches; 4 lanes breach; different signatures stay under max_identical", () => {
|
|
35
|
+
let l = fail(null, "s", "H1");
|
|
36
36
|
assert.equal(breach(l, cfg), null);
|
|
37
|
-
assert.equal(breach(fail(l, "s", "
|
|
37
|
+
assert.equal(breach(fail(l, "s", "H2"), cfg).kind, "identical");
|
|
38
38
|
let m = null; for (const [i, s] of ["a", "b", "c", "d"].entries()) m = fail(m, s, `H${i}`);
|
|
39
39
|
assert.equal(breach(m, cfg).kind, "attempts");
|
|
40
40
|
assert.equal(breach(m, { maxAttempts: 5 }), null);
|
|
41
41
|
});
|
|
42
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 <=
|
|
44
|
-
assert.equal(admitInput(l, "
|
|
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
45
|
l = markEscalated(l);
|
|
46
|
-
assert.equal(admitInput(l, "
|
|
46
|
+
assert.equal(admitInput(l, "H2", cfg).code, "loop.no_new_input");
|
|
47
47
|
assert.deepEqual(admitInput(l, "H4", cfg), { ok: true });
|
|
48
48
|
assert.equal(fail(l, "s", "H4").escalated, undefined, "the next window escalates again");
|
|
49
49
|
});
|
|
@@ -73,18 +73,6 @@ describe("#5986 contract hash in the input hash", () => {
|
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
describe("#5986 shared amendment schema", () => {
|
|
77
|
-
it("accepts valid shapes and rejects wrong types with a message", () => {
|
|
78
|
-
assert.deepEqual(validateAmendments([{ kind: "add-deliverable", path: "a.mjs", why: "x" }, { kind: "decision", decision: { choice: "c", anchors: ["a.mjs"] }, why: "y" }]), []);
|
|
79
|
-
assert.deepEqual(validateAmendments(undefined), []);
|
|
80
|
-
assert.ok(validateAmendments([{ kind: "nope" }]).length);
|
|
81
|
-
assert.match(validateAmendments([{ kind: "add-deliverable", path: 5 }])[0], /path/);
|
|
82
|
-
assert.match(validateAmendments([{ kind: "supersedes", guard: "abc", why: "x" }]).join(), /guard/);
|
|
83
|
-
assert.match(validateAmendments([{ kind: "decision", decision: { anchors: "a" }, why: "x" }]).join(), /choice/);
|
|
84
|
-
assert.match(validateAmendments({ kind: "x" })[0], /array/);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
76
|
describe("#5986 synthetic replay of looping issue timelines", () => {
|
|
89
77
|
// shapes of the AlterLab timelines (#40762 repeated builder.blocked, #41419 repeated amendments, #41262 mixed signatures); the real logs are not in the repo
|
|
90
78
|
const timelines = [
|
|
@@ -125,3 +113,29 @@ describe("#5986 synthetic replay of looping issue timelines", () => {
|
|
|
125
113
|
assert.ok(lanes <= 4, `lanes ${lanes}`);
|
|
126
114
|
});
|
|
127
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}`;
|
|
@@ -213,3 +220,22 @@ export function bypassesGuard({ laneFiles = [], att = null } = {}) {
|
|
|
213
220
|
if (!surface.length || !lane.length) return false;
|
|
214
221
|
return !lane.some((f) => surface.some((s) => f === s || f.startsWith(`${s}/`)));
|
|
215
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
|
+
}
|
|
@@ -313,7 +313,7 @@ export const appendBatchLog = (dir, text) => { try { appendFileSync(join(dir, BA
|
|
|
313
313
|
/** #5806: minutes without progress (setup reads or dispatch) before a stall is acted on; `FORGEDOCK_SCHEDD_STALL_MIN` overrides (was 10). */
|
|
314
314
|
export const DEFAULT_STALL_MIN = 3;
|
|
315
315
|
/** #5806: auto-recoveries one batch gets in total (one per distinct ready set); past it every stall alerts. */
|
|
316
|
-
export const MAX_STALL_RECOVERIES =
|
|
316
|
+
export const MAX_STALL_RECOVERIES = 6;
|
|
317
317
|
/** #5745: `; admission held by <code>: <detail>` for each failing preflight gate, "" when none. Pure. */
|
|
318
318
|
export const holdGateDetail = (gates) => (Array.isArray(gates) ? gates : []).filter((g) => g?.code).map((g) => `; admission held by ${g.code}: ${g.detail ?? "failing"}`).join("");
|
|
319
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. */
|
|
@@ -331,7 +331,7 @@ export function runningSplit(state, parallel = null) {
|
|
|
331
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 } = {}) {
|
|
332
332
|
if (!state || cancelled || reported || lastProgressMs === null) return null;
|
|
333
333
|
if (paused) return null; // #5975: an operator pause is an intended wait, not a dispatch stall
|
|
334
|
-
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
|
|
335
335
|
const order = new Set((state.order ?? []).map(Number)), results = state.results ?? {}, heldSet = new Set(held.map(Number));
|
|
336
336
|
const running = Object.keys(state.running ?? {}).length;
|
|
337
337
|
const k = Number.isInteger(parallel) && parallel > 0 ? parallel : Number.isInteger(state.parallel) && state.parallel > 0 ? state.parallel : 1;
|
|
@@ -353,17 +353,22 @@ export function evaluateDispatchStall(state, { held = [], parallel = null, hoste
|
|
|
353
353
|
* daemon restarts so a restart never re-arms it; `probe` is the batch env probe (lanecheck `probeBatchEnv`), null when the
|
|
354
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
|
|
355
355
|
* is recovered once (`resume` an unhosted batch, `restart-daemon` when its runner is alive but wedged); the same ready set
|
|
356
|
-
* stalling again
|
|
357
|
-
*
|
|
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}}
|
|
358
359
|
*/
|
|
359
|
-
|
|
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 } = {}) {
|
|
360
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
|
|
361
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` };
|
|
362
367
|
const count = Number(recovery?.count) || 0;
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
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` };
|
|
367
372
|
return { action: hosted ? "restart-daemon" : "resume", sig, cause: null };
|
|
368
373
|
}
|
|
369
374
|
|
|
@@ -371,8 +376,8 @@ export function decideStallAction(stall, { recovery = null, probe = null, hosted
|
|
|
371
376
|
export function recordStallRecovery(batch, stall, { action, sig = stall.ready.join(","), now = Date.now() } = {}) {
|
|
372
377
|
const prev = readHealth(batch.dir) ?? {}, at = new Date(now).toISOString();
|
|
373
378
|
const what = action === "restart-daemon" ? "restart the hosting schedd (its runner is alive but not progressing)" : "resume the batch (no runner hosts it)";
|
|
374
|
-
const text = `FORGE:DECISION batch ${batch.id} stall-recovery: ${what}; why: ${stall.detail}; alternative: alert only (a repeat of this stall
|
|
375
|
-
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 */ }
|
|
376
381
|
appendBatchLog(batch.dir, `${at} ${text}`);
|
|
377
382
|
return text;
|
|
378
383
|
}
|
|
@@ -409,7 +414,7 @@ export function recordStallAlert(batch, stall, { now = Date.now(), cause = null
|
|
|
409
414
|
const sig = stall.ready.join(","), prev = readHealth(batch.dir) ?? {};
|
|
410
415
|
if (prev.stall?.sig === sig) return false;
|
|
411
416
|
const at = new Date(now).toISOString();
|
|
412
|
-
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}`;
|
|
413
418
|
try { writeHealth(batch.dir, { ...prev, stall: { at, sig, detail: stall.detail, ...(cause ? { cause } : {}) }, ...(prev.alertedAt ? {} : { alertedAt: at, alert: text }) }); } catch { return false; }
|
|
414
419
|
appendBatchLog(batch.dir, `${at} ${text.split("\n").slice(0, cause ? 3 : 2).join(" | ")}`);
|
|
415
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", () => {
|
|
@@ -407,6 +416,25 @@ describe("#5938 stall verdict is re-evaluated: full K, recovery lanes, pool capa
|
|
|
407
416
|
});
|
|
408
417
|
});
|
|
409
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
|
+
|
|
410
438
|
describe("#5987 efficiency status line", () => {
|
|
411
439
|
it("batch status shows the efficiency line with and without breaches; none without a ledger", async () => {
|
|
412
440
|
const { writeEfficiency } = await import("./efficiency.mjs");
|
package/bin/lean/batch.mjs
CHANGED
|
@@ -385,7 +385,7 @@ export function openBatch(root, id) {
|
|
|
385
385
|
/** #5975: the pause record, or null when missing or invalid. */
|
|
386
386
|
readPause: () => { const v = readJson(f("pause")); return v && typeof v === "object" && !Array.isArray(v) && typeof v.since === "string" ? v : null; },
|
|
387
387
|
/** #5975: lift the pause. @returns {boolean} whether one was set */
|
|
388
|
-
clearPause: () => { const had = !!self.readPause(); try { rmSync(f("pause"), { force: true }); } catch { /* already gone */ } return had; },
|
|
388
|
+
clearPause: () => { const had = !!self.readPause(); try { rmSync(f("pause"), { force: true }); } catch { /* already gone */ } if (had) try { put(f("pause-cleared"), new Date().toISOString() + "\n"); } catch { /* advisory: the stall clock marker */ } return had; },
|
|
389
389
|
/** #5975: lift the pause when its `expiresAt` has passed. @returns {object|null} the expired record (with `ownerGone`) */
|
|
390
390
|
expirePause: (now = Date.now()) => {
|
|
391
391
|
const p = self.readPause();
|
|
@@ -417,6 +417,16 @@ export function openBatch(root, id) {
|
|
|
417
417
|
for (const n of ["state.json", "log.jsonl"]) { try { const m = statSync(f(n)).mtimeMs; if (best === null || m > best) best = m; } catch { /* absent */ } }
|
|
418
418
|
return best;
|
|
419
419
|
},
|
|
420
|
+
/**
|
|
421
|
+
* The dispatch-stall clock: the newer of the last progress and the last operator input that can make an issue ready (a `--release`
|
|
422
|
+
* or hold expiry, `--requeue`, `--add`, a live K / placement change, an unpause, a cleared breaker). Without it a release after
|
|
423
|
+
* hours of holds reads as hours of idle and the runner is declared stalled the moment the issue turns ready.
|
|
424
|
+
*/
|
|
425
|
+
lastDispatchClockMs: () => {
|
|
426
|
+
let best = self.lastProgressMs();
|
|
427
|
+
for (const n of ["hold", "hold-info", "requeue", "add", "parallel", "execution", "gates", "pause-cleared", "clear-breaker"]) { try { const m = statSync(f(n)).mtimeMs; if (best === null || m > best) best = m; } catch { /* absent */ } }
|
|
428
|
+
return best;
|
|
429
|
+
},
|
|
420
430
|
/** The lane updates in `log.jsonl`, in order (unparsable lines skipped). */
|
|
421
431
|
readLog: () => {
|
|
422
432
|
let text = "";
|
package/bin/lean/batch.test.mjs
CHANGED
|
@@ -114,6 +114,39 @@ await orchestrateFromCli(["1", "2", "3", "--parallel", "2", "--repo", "o/r", "--
|
|
|
114
114
|
assert.equal(other.saves.map((s) => s.breaker).find(Boolean)?.transport, undefined);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
it("breaker trip with pending issues keeps the batch open and dispatches after the cooldown (#6042)", async () => {
|
|
118
|
+
const run = async (detail, clearAt = null) => {
|
|
119
|
+
let t = 0; const launched = []; let req = null;
|
|
120
|
+
const rows = await orchestrate({ issues: [1, 2, 3, 4], parallel: 1, readBody: async () => "", now: () => t, maxDeferrals: 3, breaker: { errors: 3, window_min: 30 }, pollMs: 1000,
|
|
121
|
+
sleep: async (ms) => { t += ms; if (clearAt !== null && t >= clearAt) req = t; },
|
|
122
|
+
getClearBreaker: clearAt === null ? null : () => req, consumeClearBreaker: () => { req = null; },
|
|
123
|
+
store: { load: () => null, save: () => {} },
|
|
124
|
+
runOne: async (n) => { launched.push(n); t += 1000; return n <= 3 && launched.filter((x) => x === n).length === 1 && launched.length <= 3 ? { terminalReason: "engine-error", detail } : { terminalReason: "merged", pr: 5 }; } });
|
|
125
|
+
return { rows, launched };
|
|
126
|
+
};
|
|
127
|
+
const env = await run("VM restart: sandbox.lost");
|
|
128
|
+
assert.ok(env.launched.length > 3, "the environmental trip auto-clears after the cooldown and dispatch resumes");
|
|
129
|
+
const hosted = await run("boom", 60000);
|
|
130
|
+
assert.ok(hosted.launched.length > 3, "a hosted clear request resumes dispatch without a --resume");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("a sandbox-gone burst from one pool agent (VM restart) does not trip the breaker (#6042, #5859)", async () => {
|
|
134
|
+
const updates = []; const seen = new Set();
|
|
135
|
+
const rows = await orchestrate({ issues: [1, 2, 3, 4, 5], parallel: 5, readBody: async () => "", maxDeferrals: 3, breaker: { errors: 3, window_min: 10 }, onUpdate: (r) => updates.push(r),
|
|
136
|
+
store: { load: () => null, save: () => {} },
|
|
137
|
+
runOne: async (n) => { if (!seen.has(n)) { seen.add(n); return { terminalReason: "engine-error", detail: `sandbox fake-${n} exited without a result`, lostWithoutResult: true, agent: "legion" }; } return { terminalReason: "merged", pr: 5 }; } });
|
|
138
|
+
assert.ok(!updates.some((u) => u.outcome === "breaker"), "the breaker never trips");
|
|
139
|
+
assert.ok(rows.filter((r) => r.outcome === "merged").length === 5);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("a non-environmental breaker with no clear channel still ends the run with issues pending (#6042 P1)", async () => {
|
|
143
|
+
let t = 0; const launched = [];
|
|
144
|
+
await orchestrate({ issues: [1, 2, 3, 4], parallel: 1, readBody: async () => "", now: () => t, sleep: async (ms) => { t += ms; }, maxDeferrals: 3, breaker: { errors: 3, window_min: 30 },
|
|
145
|
+
store: { load: () => null, save: () => {} },
|
|
146
|
+
runOne: async (n) => { launched.push(n); t += 1000; return { terminalReason: "engine-error", detail: "boom" }; } });
|
|
147
|
+
assert.ok(!launched.includes(4));
|
|
148
|
+
});
|
|
149
|
+
|
|
117
150
|
it("gh.unavailable deferrals (forge#4157) are requeued, never relaunched as engine-error, and never trip the breaker", async () => {
|
|
118
151
|
const { now, sleep } = fakeClock();
|
|
119
152
|
const updates = [];
|
|
@@ -1464,6 +1497,22 @@ describe("#4592: forgedock orchestrate --hold / --release", () => {
|
|
|
1464
1497
|
assert.ok(!lines.some((x) => /held \(none\)/.test(x)));
|
|
1465
1498
|
});
|
|
1466
1499
|
|
|
1500
|
+
it("#5988: --hold on more than 10 issues needs an explicit --ttl and prints the resume plan; --ttl is parsed like --for", async () => {
|
|
1501
|
+
const root = tmpDir("batch-hold-ttl-");
|
|
1502
|
+
const b = openBatch(root, "b1");
|
|
1503
|
+
const many = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
1504
|
+
b.writePlan({ argv: [], repo: "o/r" });
|
|
1505
|
+
b.store.save({ order: many });
|
|
1506
|
+
const io = { gh: async () => JSON.stringify({ state: "OPEN" }) };
|
|
1507
|
+
await assert.rejects(orchestrateFromCli(["--hold", "b1", ...many.map(String)], { batchRoot: root, io }), /requires an explicit --ttl/);
|
|
1508
|
+
assert.deepEqual(b.readHeld(), []);
|
|
1509
|
+
const lines = []; const l = console.log; console.log = (x) => lines.push(String(x));
|
|
1510
|
+
let res; try { res = await orchestrateFromCli(["--hold", "b1", ...many.map(String), "--ttl", "4h"], { batchRoot: root, io }); } finally { console.log = l; }
|
|
1511
|
+
assert.equal(res.changed.length, 12);
|
|
1512
|
+
assert.ok(lines.some((x) => /resume plan: 12 issues held for 4h; an alert posts 30 min before expiry/.test(x)), lines.join("\n"));
|
|
1513
|
+
assert.ok(Object.values(b.readHoldInfo()).every((h) => Number.isFinite(Date.parse(h.expiresAt))), "the ttl set an expiry");
|
|
1514
|
+
});
|
|
1515
|
+
|
|
1467
1516
|
it("through the CLI: --hold / --release write the hold file (usage and unknown batch reject); --resume <id> N releases N", async () => {
|
|
1468
1517
|
const root = tmpDir("batch-hold-cli-");
|
|
1469
1518
|
const b = openBatch(root, "b1");
|
|
@@ -1741,7 +1790,7 @@ describe("#5161 transient engine-error retries", () => {
|
|
|
1741
1790
|
const rows = await orchestrate({ issues: [1, 2], parallel: 1, readBody: async () => "", now, sleep, breaker: { errors: 2, window_min: 30 },
|
|
1742
1791
|
store: { load: () => null, save: (st) => saves.push(st) }, runOne: async () => { throw new Error(CURL_502); } });
|
|
1743
1792
|
assert.equal(saves.map((st) => st.breaker).find(Boolean)?.transport, true);
|
|
1744
|
-
assert.ok(rows.some((r) => r.outcome === "held"));
|
|
1793
|
+
assert.ok(!rows.some((r) => r.outcome === "held"), "#6042: a transport trip pauses admission and the batch stays open instead of ending held");
|
|
1745
1794
|
});
|
|
1746
1795
|
});
|
|
1747
1796
|
|
|
@@ -1918,7 +1967,7 @@ describe("#5168: --requeue accepts engine-error; a claude login failure is held,
|
|
|
1918
1967
|
} });
|
|
1919
1968
|
assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
|
|
1920
1969
|
assert.equal(starts[1].length, 4, "deferred past maxDeferrals: the hold is uncapped");
|
|
1921
|
-
assert.ok(starts[2][0] >= t0 +
|
|
1970
|
+
assert.ok(starts[2][0] >= t0 + 300_000, "the held account admits nothing until the next probe (#5988: held at most 5 min, not the 15 min retry hint)");
|
|
1922
1971
|
assert.ok(!updates.some((u) => u.outcome === "breaker" || u.outcome === "engine-error"));
|
|
1923
1972
|
assert.ok(updates.some((u) => u.outcome === "paused" && /paused \(backend\.auth\)/.test(u.detail ?? "")));
|
|
1924
1973
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Pool capacity sampler (#4540, #5048, #5985): `capacity()` is sync (admission is sync) and refreshes `provider.capacity()` in the
|
|
5
|
+
* background at most every `pollMs`. `null` = unknown, `{free, online, load_per_core?, mem_available_gb?, at}` = a sample (`at` counts
|
|
6
|
+
* samples, failures included). A failed probe makes every caller see a throw until the next SUCCESSFUL sample; the refresh runs
|
|
7
|
+
* before that throw, so a recovered pool clears it. (It used to run after, so one failed probe, e.g. a pool restart, kept the
|
|
8
|
+
* batch on "capacity probe failed" for good: no capacity gating, no K controller input, the pool marked down until a daemon restart.)
|
|
9
|
+
*/
|
|
10
|
+
export function makeCapacitySampler({ provider, now = Date.now, pollMs = 5000 } = {}) {
|
|
11
|
+
let free = null, online = null, at = 0, last = -Infinity, failed = false, live = {};
|
|
12
|
+
return () => {
|
|
13
|
+
const t = now();
|
|
14
|
+
if (typeof provider?.capacity === "function" && t - last >= pollMs) {
|
|
15
|
+
last = t;
|
|
16
|
+
Promise.resolve().then(() => provider.capacity()).then((c) => {
|
|
17
|
+
failed = false; free = c && Number.isInteger(c.free) ? c.free : null; online = c && Number.isInteger(c.online) ? c.online : null;
|
|
18
|
+
live = { ...(Number.isFinite(c?.load_per_core) ? { load_per_core: c.load_per_core } : {}), ...(Number.isFinite(c?.mem_available_gb) ? { mem_available_gb: c.mem_available_gb } : {}) };
|
|
19
|
+
at++;
|
|
20
|
+
}, () => { free = null; online = null; failed = true; at++; });
|
|
21
|
+
}
|
|
22
|
+
if (failed) throw new Error("capacity probe failed"); // #5048: until the next successful sample, so every caller sees it (release review CONC-1)
|
|
23
|
+
return free === null && online === null ? null : { free, online, ...live, at };
|
|
24
|
+
};
|
|
25
|
+
}
|