forgedock 1.71.0 → 1.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +5 -4
- package/bin/init-detect.mjs +35 -2
- package/bin/lean/admit.mjs +152 -0
- package/bin/lean/admit.test.mjs +120 -0
- package/bin/lean/attempts.mjs +1 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +17 -0
- package/bin/lean/concurrency.mjs +7 -2
- package/bin/lean/concurrency.test.mjs +16 -3
- package/bin/lean/conformance.mjs +2 -0
- package/bin/lean/conformance.test.mjs +9 -0
- package/bin/lean/effects.mjs +22 -0
- package/bin/lean/failure-census.mjs +1 -1
- package/bin/lean/heavy.mjs +20 -6
- package/bin/lean/heavy.test.mjs +24 -3
- package/bin/lean/lean.mjs +97 -5
- package/bin/lean/lean.test.mjs +38 -0
- package/bin/lean/orchestrate-envhold.test.mjs +14 -0
- package/bin/lean/orchestrate-heldroot.test.mjs +32 -0
- package/bin/lean/orchestrate.mjs +33 -11
- package/bin/lean/queuecause.mjs +42 -0
- package/bin/lean/release-cigreen.mjs +18 -4
- package/bin/lean/release-cigreen.test.mjs +23 -0
- package/bin/lean/release-review.mjs +24 -10
- package/bin/lean/release-review.test.mjs +65 -0
- package/bin/lean/release.mjs +1 -1
- package/bin/lean/release.test.mjs +19 -0
- package/bin/lean/schedd.mjs +24 -1
- package/bin/lean/schedd.test.mjs +38 -0
- package/bin/pool/agent.mjs +61 -18
- package/bin/pool/docker-dns.mjs +39 -0
- package/bin/pool/docker.mjs +7 -3
- package/bin/pool/engine-placement.test.mjs +2 -2
- package/bin/pool/image-manifest.test.mjs +13 -0
- package/bin/pool/lane-image.mjs +56 -15
- package/bin/pool/lane-tools.mjs +26 -12
- package/bin/pool/lane-tools.test.mjs +63 -1
- package/bin/pool/project-layer.mjs +2 -2
- package/bin/pool/router.mjs +2 -1
- package/bin/review-staging.mjs +14 -11
- package/bin/review-staging.test.mjs +20 -1
- package/bin/stats/escapes.mjs +124 -0
- package/bin/stats/index.mjs +5 -1
- package/bin/stats/quality-ledger.mjs +49 -0
- package/bin/stats/quality-ledger.test.mjs +84 -0
- package/bin/stats/weekly.mjs +230 -0
- package/docs/OUTCOME-CODES.md +2 -1
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/pool/image/Dockerfile +4 -1
- package/pool/image/lane-tools-sets.json +6 -0
- package/scripts/lane-variants.mjs +51 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* `forgedock stats scorecard --weekly [--repo R] [--json]` (#6203): merges, all-in $/merge, issue->merge median/p90, first-pass %,
|
|
5
|
+
* escape %, human touches/merge, queue_wait by cause and non-merged spend %, by ISO week (UTC) and engine version.
|
|
6
|
+
* Reads ~/.forge/batches/<id>/log.jsonl (+ plan.json, state.json), the MERGE_LEDGER records in ~/.forge/runs and the escape cache.
|
|
7
|
+
* Deterministic, no network. A field a source lacks degrades to n/a; it is never invented.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { percentile } from "./aggregate.mjs";
|
|
13
|
+
|
|
14
|
+
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
15
|
+
const MIN = 60000;
|
|
16
|
+
export const QUEUE_CAUSES = ["hold", "pause", "capacity", "breaker", "dependency", "host_offline", "other"];
|
|
17
|
+
const parseJsonl = (file) => { try { return readFileSync(file, "utf8").split("\n").flatMap((l) => { try { return l.trim() ? [JSON.parse(l)] : []; } catch { return []; } }); } catch { return []; } };
|
|
18
|
+
const readJson = (f) => { try { return JSON.parse(readFileSync(f, "utf8")); } catch { return null; } };
|
|
19
|
+
export const forgeHome = (env = process.env) => env.FORGE_HOME_DIR || join(homedir(), ".forge");
|
|
20
|
+
|
|
21
|
+
/** ISO week start (Monday, UTC) as YYYY-MM-DD. */
|
|
22
|
+
export function weekOf(ms) {
|
|
23
|
+
const d = new Date(ms); const day = (d.getUTCDay() + 6) % 7;
|
|
24
|
+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() - day)).toISOString().slice(0, 10);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Batches read from disk: [{id, repo, created, engineVersion, rows}] (rows with a parsed `t`). */
|
|
28
|
+
export function readBatches({ home = forgeHome(), repo = null } = {}) {
|
|
29
|
+
const root = join(home, "batches");
|
|
30
|
+
if (!existsSync(root)) return [];
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const id of readdirSync(root)) {
|
|
33
|
+
if (!/^b\d{8}-/.test(id)) continue;
|
|
34
|
+
const dir = join(root, id), plan = readJson(join(dir, "plan.json")), state = readJson(join(dir, "state.json"));
|
|
35
|
+
if (repo && String(plan?.repo ?? "").toLowerCase() !== repo.toLowerCase()) continue;
|
|
36
|
+
const m = /^b(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/.exec(id);
|
|
37
|
+
const created = Date.parse(plan?.created ?? "") || (m ? Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]) : NaN);
|
|
38
|
+
const rows = parseJsonl(join(dir, "log.jsonl")).map((r) => ({ ...r, t: Date.parse(r.at ?? "") })).filter((r) => isNum(r.t));
|
|
39
|
+
out.push({ id, repo: plan?.repo ?? null, created, engineVersion: state?.engineVersion ?? null, rows });
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** MERGE_LEDGER records from the run logs: Map "repo-ish#issue" -> last record. */
|
|
45
|
+
export function readMergeLedgers({ home = forgeHome(), env = process.env } = {}) {
|
|
46
|
+
const dir = env.FORGE_RUNS_DIR || join(home, "runs"), out = new Map();
|
|
47
|
+
if (!existsSync(dir)) return out;
|
|
48
|
+
for (const f of readdirSync(dir)) {
|
|
49
|
+
if (!f.endsWith(".jsonl")) continue;
|
|
50
|
+
let text; try { text = readFileSync(join(dir, f), "utf8"); } catch { continue; }
|
|
51
|
+
if (!text.includes("MERGE_LEDGER")) continue;
|
|
52
|
+
const issue = Number(/(\d+)\.jsonl$/.exec(f)?.[1]);
|
|
53
|
+
for (const l of text.split("\n")) { if (!l.includes("MERGE_LEDGER")) continue; try { const e = JSON.parse(l); if (e.event === "MERGE_LEDGER") out.set(issue, { ...e, ts: Date.parse(e.ts ?? "") }); } catch { /* skip */ } }
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deduped spend of one issue's rows, in order. Rows of a recovery chain carry the cost so far, so a row that is >= the previous
|
|
60
|
+
* row's cost adds only the difference; a lower one starts a new run and counts in full. Returns [{t, usd}] increments.
|
|
61
|
+
*/
|
|
62
|
+
export function spendIncrements(rows) {
|
|
63
|
+
let prev = 0; const out = [];
|
|
64
|
+
for (const r of rows) {
|
|
65
|
+
if (!isNum(r.cost_usd) || r.cost_usd <= 0) continue;
|
|
66
|
+
const inc = r.cost_usd >= prev ? r.cost_usd - prev : r.cost_usd;
|
|
67
|
+
prev = r.cost_usd; if (inc > 0) out.push({ t: r.t, usd: inc });
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const issueListed = (detail, n) => new RegExp(`#?\\b${n}\\b`).test(String(detail ?? "")) && /^[#\d,\s]+$/.test(String(detail ?? "").trim());
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The engine version a batch ran at time t. A batch outlives upgrades, so its state.json (the latest version) is wrong for older
|
|
76
|
+
* rows: the "vA -> vB" rows (re-admission and upgrade interrupts) give the transitions; before the first one the version was A.
|
|
77
|
+
*/
|
|
78
|
+
export function versionAt(rows, finalVersion, t) {
|
|
79
|
+
const tr = [];
|
|
80
|
+
for (const r of rows) { const m = /v?(\d+\.\d+\.\d+)\s*(?:→|->)\s*v?(\d+\.\d+\.\d+)/.exec(r.detail ?? ""); if (m) tr.push({ t: r.t, from: m[1], to: m[2] }); }
|
|
81
|
+
tr.sort((a, b) => a.t - b.t);
|
|
82
|
+
// No transition recorded: state.json's version holds for a short batch; a batch that ran over a day may have straddled an unrecorded upgrade.
|
|
83
|
+
if (!tr.length) return rows.length && rows[rows.length - 1].t - rows[0].t <= 24 * 3600000 ? finalVersion ?? null : null;
|
|
84
|
+
let v = tr[0].from;
|
|
85
|
+
for (const x of tr) if (x.t <= t) v = x.to;
|
|
86
|
+
return v;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Global intervals from a batch's rows: pause and breaker. */
|
|
90
|
+
function globalSpans(rows) {
|
|
91
|
+
const pause = [], breaker = []; let ps = null, bs = null;
|
|
92
|
+
for (const r of rows) {
|
|
93
|
+
if (r.outcome === "pause") { ps = ps ?? r.t; const u = Date.parse(/until (\d{4}-[\dT:.\-]+Z)/.exec(r.detail ?? "")?.[1] ?? ""); if (isNum(u)) { pause.push([r.t, u]); ps = null; } }
|
|
94
|
+
else if (r.outcome === "unpause" || r.outcome === "pause-expired") { if (ps != null) pause.push([ps, r.t]); ps = null; pause.push([r.t, r.t]); }
|
|
95
|
+
else if (r.outcome === "breaker") { if (/cleared/.test(r.detail ?? "")) { if (bs != null) breaker.push([bs, r.t]); bs = null; } else bs = bs ?? r.t; }
|
|
96
|
+
}
|
|
97
|
+
return { pause, breaker };
|
|
98
|
+
}
|
|
99
|
+
const overlap = (a0, a1, spans) => spans.reduce((s, [b0, b1]) => s + Math.max(0, Math.min(a1, b1) - Math.max(a0, b0)), 0);
|
|
100
|
+
const gapCause = (prev) => {
|
|
101
|
+
if (!prev) return "other";
|
|
102
|
+
const o = prev.outcome, c = prev.code ?? "";
|
|
103
|
+
if (c === "sandbox.capacity" || c === "host.busy" || c === "sandbox.disk_pressure" || o === "host-overloaded") return "capacity";
|
|
104
|
+
if (c === "sandbox.unreachable" || c === "sandbox.transient") return "host_offline";
|
|
105
|
+
if (o === "held" || /^dependency-/.test(o) || c === "dependency.open") return "dependency";
|
|
106
|
+
if (o === "needs-human" || o === "requeued" || o === "hold" || o === "hold-expired" || o === "readmitted") return "hold";
|
|
107
|
+
return "other";
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Queue wait of one merged issue by cause, from ready to merged, minus the lane's active time; never reset by a requeue.
|
|
112
|
+
* ready = the first row naming the issue in a batch's `added` rows, else the batch's creation. Gaps between a lane's end and the
|
|
113
|
+
* next lane's start take the cause of the row that ended the previous attempt; pause and breaker spans override within a gap.
|
|
114
|
+
*/
|
|
115
|
+
export function queueByCause(issueRows, mergedRow, ready, spans) {
|
|
116
|
+
const causes = Object.fromEntries(QUEUE_CAUSES.map((c) => [c, 0]));
|
|
117
|
+
let cursor = ready, prev = null;
|
|
118
|
+
for (const r of issueRows) {
|
|
119
|
+
if (r.t > mergedRow.t) break;
|
|
120
|
+
if (["hold", "hold-expired", "readmitted", "requeued", "held"].includes(r.outcome) && !isNum(r.wall_ms) && !r.minutes) { if (r.outcome === "hold" || r.outcome === "held") prev = r; continue; }
|
|
121
|
+
const active = isNum(r.wall_ms) ? r.wall_ms : isNum(r.minutes) ? r.minutes * MIN : 0;
|
|
122
|
+
const start = Math.max(cursor, r.t - active);
|
|
123
|
+
if (start > cursor) {
|
|
124
|
+
const p = overlap(cursor, start, spans.pause), b = overlap(cursor, start, spans.breaker);
|
|
125
|
+
const h = Math.min(overlap(cursor, start, spans.hold ?? []), start - cursor - p - b);
|
|
126
|
+
causes.pause += p; causes.breaker += b; causes.hold += Math.max(0, h);
|
|
127
|
+
causes[gapCause(prev)] += Math.max(0, start - cursor - p - b - Math.max(0, h));
|
|
128
|
+
}
|
|
129
|
+
cursor = Math.max(cursor, r.t); prev = r;
|
|
130
|
+
}
|
|
131
|
+
const total = Object.values(causes).reduce((a, b) => a + b, 0);
|
|
132
|
+
return { total, causes };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** One record per merged issue: the data every weekly metric reads. */
|
|
136
|
+
export function mergeRecords(batches, ledgers = new Map()) {
|
|
137
|
+
const recs = [], byIssue = new Map();
|
|
138
|
+
for (const b of batches) {
|
|
139
|
+
const spans = globalSpans(b.rows);
|
|
140
|
+
const added = new Map();
|
|
141
|
+
for (const r of b.rows) if (r.outcome === "added" && r.issue == null) for (const m of String(r.detail ?? "").matchAll(/#(\d+)/g)) if (!added.has(+m[1])) added.set(+m[1], r.t);
|
|
142
|
+
const per = new Map();
|
|
143
|
+
for (const r of b.rows) if (Number.isInteger(r.issue)) { if (!per.has(r.issue)) per.set(r.issue, []); per.get(r.issue).push(r); }
|
|
144
|
+
const holdSpan = new Map(); // issue -> [[placed, expired|Infinity]]: an operator hold row lists the issues; a hold-expired row ends it
|
|
145
|
+
for (const r of b.rows) {
|
|
146
|
+
if (r.outcome === "hold" && r.issue == null) for (const m of String(r.detail ?? "").matchAll(/\d+/g)) if (issueListed(r.detail, m[0])) { const a = holdSpan.get(+m[0]) ?? []; a.push([r.t, Infinity]); holdSpan.set(+m[0], a); }
|
|
147
|
+
if (r.outcome === "hold-expired" && Number.isInteger(r.issue)) { const open = (holdSpan.get(r.issue) ?? []).filter((x) => x[1] === Infinity && x[0] <= r.t).pop(); if (open) open[1] = r.t; }
|
|
148
|
+
}
|
|
149
|
+
const holds = new Map(); // operator hold rows list the issues in detail
|
|
150
|
+
for (const r of b.rows) if (r.outcome === "hold" && r.issue == null) for (const m of String(r.detail ?? "").matchAll(/\d+/g)) if (issueListed(r.detail, m[0])) holds.set(+m[0], (holds.get(+m[0]) ?? 0) + 1);
|
|
151
|
+
for (const [issue, rows] of per) {
|
|
152
|
+
const key = `${b.id}#${issue}`;
|
|
153
|
+
const spend = spendIncrements(rows);
|
|
154
|
+
const touches = rows.filter((r) => (r.outcome === "requeued" && r.trigger == null && !/^dependency \d+ requeued/.test(r.detail ?? "")) || (r.outcome === "readmitted" && /^needs-human label removed/.test(r.detail ?? ""))).length + (holds.get(issue) ?? 0);
|
|
155
|
+
const merged = rows.find((r) => r.outcome === "merged");
|
|
156
|
+
const ready = Math.min(added.get(issue) ?? Infinity, b.created ?? Infinity, ...rows.map((r) => r.t - (isNum(r.wall_ms) ? r.wall_ms : 0)));
|
|
157
|
+
const q = merged ? queueByCause(rows, merged, ready, { ...spans, hold: holdSpan.get(issue) ?? [] }) : null;
|
|
158
|
+
const mq = merged?.phases?.queue_wait?.causes;
|
|
159
|
+
const led = merged ? ledgers.get(issue) : null;
|
|
160
|
+
const rec = { key, batch: b.id, issue, repo: b.repo, version: led?.engine_version ?? merged?.engineVersion ?? versionAt(b.rows, b.engineVersion, (merged ?? rows[rows.length - 1]).t) ?? "unknown", spend, spendUsd: spend.reduce((s, x) => s + x.usd, 0), humanTouches: touches + (isNum(led?.human_touch) ? led.human_touch : 0), merged: Boolean(merged) };
|
|
161
|
+
if (merged) {
|
|
162
|
+
const firstPass = typeof led?.first_pass === "boolean" ? led.first_pass : typeof merged.first_pass === "boolean" ? merged.first_pass : null;
|
|
163
|
+
Object.assign(rec, { mergedAt: merged.t, firstPass, ready, issueToMergeMs: Number.isFinite(ready) ? merged.t - ready : null, queue: mq ? { total: Object.values(mq).reduce((a, b2) => a + (isNum(b2) ? b2 : 0), 0), causes: { ...Object.fromEntries(QUEUE_CAUSES.map((c) => [c, 0])), ...mq }, measured: true } : { ...q, measured: false }, pr: merged.pr ?? null });
|
|
164
|
+
}
|
|
165
|
+
if (!byIssue.has(issue) && !merged) { /* kept: spend on a never-merged issue still counts */ }
|
|
166
|
+
recs.push(rec); byIssue.set(key, rec);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// An issue merged in one batch and spent in another: the other batch's spend is non-merged only when no batch merged it.
|
|
170
|
+
const mergedAnywhere = new Set(recs.filter((r) => r.merged).map((r) => `${r.repo}#${r.issue}`));
|
|
171
|
+
for (const r of recs) r.mergedElsewhere = !r.merged && mergedAnywhere.has(`${r.repo}#${r.issue}`);
|
|
172
|
+
return recs;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const pct = (a, b) => (b > 0 ? a / b : null);
|
|
176
|
+
/** Aggregate merge records by (week, version). `escapes`: Map "issue-or-pr" -> boolean escaped (from `stats escapes`). */
|
|
177
|
+
export function weeklyScorecard(recs, { escapes = null } = {}) {
|
|
178
|
+
const groups = new Map();
|
|
179
|
+
const g = (week, version) => { const k = `${week}\u0000${version}`; if (!groups.has(k)) groups.set(k, { week, version, merges: 0, spend: 0, nonMergedSpend: 0, firstPass: [0, 0], touches: 0, i2m: [], queue: Object.fromEntries(QUEUE_CAUSES.map((c) => [c, 0])), queueN: 0, queueMeasured: 0, esc: [0, 0] }); return groups.get(k); };
|
|
180
|
+
for (const r of recs) {
|
|
181
|
+
for (const s of r.spend) { const x = g(weekOf(s.t), r.version); x.spend += s.usd; if (!r.merged && !r.mergedElsewhere) x.nonMergedSpend += s.usd; }
|
|
182
|
+
if (!r.merged) continue;
|
|
183
|
+
const x = g(weekOf(r.mergedAt), r.version);
|
|
184
|
+
x.merges++; x.touches += r.humanTouches;
|
|
185
|
+
if (r.firstPass != null) { x.firstPass[1]++; if (r.firstPass) x.firstPass[0]++; }
|
|
186
|
+
if (isNum(r.issueToMergeMs)) x.i2m.push(r.issueToMergeMs);
|
|
187
|
+
if (r.queue) { x.queueN++; if (r.queue.measured) x.queueMeasured++; for (const c of QUEUE_CAUSES) x.queue[c] += r.queue.causes[c] ?? 0; }
|
|
188
|
+
const esc = escapes?.get?.(r.pr) ?? escapes?.get?.(`pr:${r.pr}`);
|
|
189
|
+
if (typeof esc === "boolean") { x.esc[1]++; if (esc) x.esc[0]++; }
|
|
190
|
+
}
|
|
191
|
+
return [...groups.values()].sort((a, b) => (a.week < b.week ? -1 : a.week > b.week ? 1 : a.version.localeCompare(b.version, undefined, { numeric: true }))).map((x) => ({
|
|
192
|
+
week: x.week, version: x.version, merges: x.merges, spend_usd: x.spend,
|
|
193
|
+
usd_per_merge: x.merges ? x.spend / x.merges : null,
|
|
194
|
+
issue_to_merge_median_min: x.i2m.length ? percentile(x.i2m, 50) / MIN : null, issue_to_merge_p90_min: x.i2m.length ? percentile(x.i2m, 90) / MIN : null,
|
|
195
|
+
first_pass_pct: pct(x.firstPass[0], x.firstPass[1]), first_pass_n: x.firstPass[1],
|
|
196
|
+
escape_pct: pct(x.esc[0], x.esc[1]), escape_n: x.esc[1],
|
|
197
|
+
human_touches_per_merge: x.merges ? x.touches / x.merges : null,
|
|
198
|
+
queue_wait_min_per_merge: x.queueN ? Object.fromEntries(QUEUE_CAUSES.map((c) => [c, x.queue[c] / x.queueN / MIN])) : null,
|
|
199
|
+
non_merged_spend_pct: pct(x.nonMergedSpend, x.spend),
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const f = (v, d = 1, suf = "") => (v == null ? "n/a" : `${v.toFixed(d)}${suf}`);
|
|
204
|
+
export function renderWeekly(rows, { repo = null } = {}) {
|
|
205
|
+
if (!rows.length) return "No batch data found.\n";
|
|
206
|
+
const lines = [`Weekly scorecard${repo ? ` (${repo})` : ""}: by ISO week (Monday, UTC) and engine version. n/a = the source has no such field.`, ""];
|
|
207
|
+
const head = ["week", "engine", "merges", "$/merge", "i2m med", "i2m p90", "1st-pass", "escape", "touch/m", "nonmerged$"];
|
|
208
|
+
const body = rows.map((r) => [r.week, r.version, String(r.merges), f(r.usd_per_merge, 2, ""), f(r.issue_to_merge_median_min, 0, "m"), f(r.issue_to_merge_p90_min, 0, "m"),
|
|
209
|
+
r.first_pass_pct == null ? "n/a" : `${Math.round(r.first_pass_pct * 100)}% (${r.first_pass_n})`, r.escape_pct == null ? "n/a" : `${(r.escape_pct * 100).toFixed(1)}% (${r.escape_n})`, f(r.human_touches_per_merge, 2), f(r.non_merged_spend_pct == null ? null : r.non_merged_spend_pct * 100, 0, "%")]);
|
|
210
|
+
const w = head.map((h, i) => Math.max(h.length, ...body.map((b) => b[i].length)));
|
|
211
|
+
const line = (c) => c.map((x, i) => x.padEnd(w[i])).join(" ").trimEnd();
|
|
212
|
+
lines.push(line(head), line(w.map((n) => "-".repeat(n))), ...body.map(line), "", "queue_wait per merged issue, minutes by cause (ready to start, not reset by requeue):");
|
|
213
|
+
const qh = ["week", "engine", ...QUEUE_CAUSES], qb = rows.filter((r) => r.queue_wait_min_per_merge).map((r) => [r.week, r.version, ...QUEUE_CAUSES.map((c) => f(r.queue_wait_min_per_merge[c], 0))]);
|
|
214
|
+
const qw = qh.map((h, i) => Math.max(h.length, ...qb.map((b) => b[i].length)));
|
|
215
|
+
const ql = (c) => c.map((x, i) => x.padEnd(qw[i])).join(" ").trimEnd();
|
|
216
|
+
lines.push(ql(qh), ql(qw.map((n) => "-".repeat(n))), ...qb.map(ql));
|
|
217
|
+
return `${lines.join("\n")}\n`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Entry used by `forgedock stats scorecard --weekly`. */
|
|
221
|
+
export async function runWeekly(argv, deps = {}) {
|
|
222
|
+
const repoAt = argv.indexOf("--repo"), repo = repoAt >= 0 ? argv[repoAt + 1] : null, json = argv.includes("--json");
|
|
223
|
+
const home = deps.home ?? forgeHome();
|
|
224
|
+
const batches = deps.batches ?? readBatches({ home, repo });
|
|
225
|
+
const recs = mergeRecords(batches, deps.ledgers ?? readMergeLedgers({ home }));
|
|
226
|
+
const { readEscapeCache } = await import("./escapes.mjs");
|
|
227
|
+
const rows = weeklyScorecard(recs, { escapes: deps.escapes ?? readEscapeCache({ home, repo }) });
|
|
228
|
+
(deps.out ?? ((s) => process.stdout.write(s)))(json ? `${JSON.stringify(rows, null, 2)}\n` : renderWeekly(rows, { repo }));
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
package/docs/OUTCOME-CODES.md
CHANGED
|
@@ -59,6 +59,7 @@ An absent or unknown code is recorded as `unclassified`, with the raw reason kep
|
|
|
59
59
|
| `env.lane_limit` | Core work-on (forge#4690): the lane's systemd scope hit its own `TasksMax` (forks refused, `pids.events max`) or `MemoryMax` (`memory.events oom_kill`) and the engine stopped the lane after checkpointing its work. The message names the limit. An environment error, not an engine-error: it ends `needs-human`, is not relaunched and is not counted by the circuit breaker, so other lanes keep being admitted. Raise `engine.lane_limits.tasks_max` / `memory_max` if the work is legitimate | lean | scope `pids.events` / `memory.events` sampled by `bin/runner.mjs` `readScopeLimitEvents` |
|
|
60
60
|
| `env.tool_missing` | Core work-on (forge#4323): a validate command the builder recorded as failed was rerun by the engine and could not run because the host lacks a tool or module (`command not found` / exit 127, Python `No module named x`, Node `Cannot find module|package 'x'` for a bare name the repo does not track). An environment error, not a conformance failure: no builder resume, no reviewer. Also ends this way when a remote-sandbox builder reports a missing tool as a `credentials` block (forge#4685, `missingToolBlock`). Ends `needs-human` naming the tool; recoverable by `forgedock orchestrate` (the recovery lane runs the check through the repo's own toolchain). Skipped on a CI-verified head | lean | `gate()` rerun via `io.runCommand`, `{rc, output}` classified by `conformance.mjs` `missingTool` |
|
|
61
61
|
| `env.repro_unrunnable` | Core work-on (forge#4334): on a bug lane the frozen `repro_test` could not be run on head by `scripts/acceptance-red-green.sh` (`HEAD=UNRUNNABLE`: timeout, exit 126/127, unclassifiable output) or the harness returned no result. An environment error, not a conformance failure: no builder resume, no reviewer. Ends `needs-human`; recoverable by `forgedock orchestrate` (the recovery lane reruns the repro command through the repo's own toolchain and installed dependencies). Other non-proofs (passes on base, fails on head, base unrunnable) stay `conformance.unimplemented` | lean | `gate()` `io.redGreen` words, classified by `conformance.mjs` `reproFailures` |
|
|
62
|
+
| `env.capability_docker` | Core work-on (forge#6196): a validate command needed a Docker daemon or image the sandbox lacks (no daemon, image not present, `docker` not found). Environment, never conformance: recovered on a placement with Docker (the pool `docker: true` sidecar) or the validate is deferred to CI with a FORGE:DECISION. Recoverable. |
|
|
62
63
|
| `env.capability_remote` | Core work-on (forge#4542): a lane placed in a remote sandbox ended `builder.blocked (credentials)` and its summary names only host capabilities declared in `execution.host_capabilities` (SOPS/age key, ops credentials, prod monitor SSH), which the sandbox does not relay but the dispatching host has. Recoverable by `forgedock orchestrate`: the recovery lane is placed local, once, under the same lease. A credential need the host lacks too stays `builder.blocked` | lean | `endBlocked` via `execution.mjs` `hostCapabilityBlock` |
|
|
63
64
|
| `env.engine_skew` | Core work-on (forge#5931): a remote sandbox lane ran an engine version (major.minor) other than the dispatching host's, so gates fixed in the host version still fire. Held as an environment outcome (re-admitted on an engine upgrade or --set-env), never reported as conformance. |
|
|
64
65
|
| `sandbox.start_failed` | A `forgedock orchestrate` lane sandbox (forge.yaml `execution`, provider `container` or `remote`) could not start: bad image, missing endpoint, a refused launch (HTTP 4xx other than 401/403/429) or a non-HTTP start failure. The lane never ran. Final `needs-human` row: not relaunched and not counted by the engine-error circuit breaker | orchestrate | `bin/lean/execution.mjs` `providerLanes`: `provider.start` threw without `retryable`, `transient` or a 5xx/401/403 `status` |
|
|
@@ -124,7 +125,7 @@ An absent or unknown code is recorded as `unclassified`, with the raw reason kep
|
|
|
124
125
|
`forgedock orchestrate` recovers mechanical outcomes inside the batch:
|
|
125
126
|
|
|
126
127
|
- **recoverable**:
|
|
127
|
-
- needs-human with `ci.red`, `base.conflict`, `builder.block_untyped`, `env.tool_missing`, `env.repro_unrunnable`, `env.validate_timeout`, `env.capability_remote`, `contract.invalid_command`, `budget.exceeded`, `conformance.unimplemented`, `conformance.omission` or `conformance.unjustified_deferral` (#5035: the recovery lane resumes the lane branch, delivers the named gap or records a defer-with-why amendment that files a tracked follow-up);
|
|
128
|
+
- needs-human with `ci.red`, `base.conflict`, `builder.block_untyped`, `env.tool_missing`, `env.repro_unrunnable`, `env.validate_timeout`, `env.capability_docker`, `env.capability_remote`, `contract.invalid_command`, `budget.exceeded`, `conformance.unimplemented`, `conformance.omission` or `conformance.unjustified_deferral` (#5035: the recovery lane resumes the lane branch, delivers the named gap or records a defer-with-why amendment that files a tracked follow-up);
|
|
128
129
|
- `contract.invalid` when the issue was edited mid-run (`issueEdited`);
|
|
129
130
|
- `ci-pending` on a conflicting PR, recovered as `base.conflict`.
|
|
130
131
|
|
package/package.json
CHANGED
package/pool/README.md
CHANGED
|
@@ -31,6 +31,8 @@ The `forgedock pool` CLI wiring is tracked separately (#4544).
|
|
|
31
31
|
|
|
32
32
|
Per-repo lane tools (#5650): forge.yaml `execution.lane_tools` (`name` or `name@version`) rides in the launch spec as `lane_tools`. The agent resolves the image in `launch` (`bin/pool/lane-tools.mjs`): no tools keeps the base `forgedock-lane:<version>`; otherwise it uses `<base>-t<sha256 of the sorted list, 12 hex>`, building it once `FROM` the base with one recipe per tool (warm sandboxes keep `lane_tools` in their stored spec, so they use the same image). A tool with no recipe fails before any build (`lane_tools.unknown_recipe`, naming the tool and the known recipes); a failed or timed-out build is `lane_tools.build_failed` and the launch records the error. To add a recipe, add an entry to `RECIPES` in `bin/pool/lane-tools.mjs`: `{versioned, steps(version) -> Dockerfile instructions}` for the Debian/Ubuntu lane image; tool names appear nowhere else.
|
|
33
33
|
|
|
34
|
+
Pulled variants (#6187): `pool/image/lane-tools-sets.json` lists the `lane_tools` sets worth prebuilding. After the base image push, `publish.yml` (and `lane-image.yml` for a manual rebuild) runs `scripts/lane-variants.mjs` to build and push each as `ghcr.io/rapiercraftstudios/forgedock-lane:<version>-t<hash>` (same hash as `laneToolsTag`). A host pulls the variant like the base (IPv4 pins on an IPv6 dial error), retags it to the local tag and builds on the host only when the pull fails (a set that is not in the list is always built). The fallback build runs under the same IPv4 fallback. A failed build is never cached as a permanent 422: it is reported (`lane_tools.build_failed`, carrying the last 1500 characters of the build output) for 1, 2, 5, then 10 minutes after consecutive failures of the tag, then retried.
|
|
35
|
+
|
|
34
36
|
Priority and reservations (#5856): a host's leftover compute can run lanes while its own workload keeps priority. Agent config `agent.json`: `reservations: [{"name":"marcode","cpus":10,"mem_gb":20}]`, `idle_only: true` (for a box with no reservations: borrow lanes run only while owner load and free memory are above the floor). Sandboxes carry `spec.priority` (`reserved` with `spec.reservation`, `normal`, `borrow`; lanes are `borrow`). Admission: reserved is always admitted up to its reservation (borrowed lanes are throttled via `--cpu-shares`, then SIGTERMed with `drain_grace_s`, and rescheduled by the dispatcher); borrow may use reserved-but-idle capacity; normal stays outside reservations. `/capacity` adds `cpus_free_unreserved`, `cpus_borrowable` and `reservations[]` so the router prefers hosts with free non-reserved capacity. Run one agent per docker daemon (a second agent would reap the first one's sandboxes).
|
|
35
37
|
|
|
36
38
|
Tunnel-only hosts (no Tailscale): `forgedock pool enroll --agent-url http://127.0.0.1:<port> [--cpus N --mem GB]` prints `AGENT_URL=... pool/install/install-agent-linux.sh --router ... --token CODE`; the router then reaches the agent at that URL (for example a reverse SSH tunnel).
|
package/pool/image/Dockerfile
CHANGED
|
@@ -21,8 +21,11 @@ ARG FORGEDOCK_RECIPE=
|
|
|
21
21
|
LABEL org.opencontainers.image.version=$FORGEDOCK_VERSION forgedock.recipe=$FORGEDOCK_RECIPE
|
|
22
22
|
RUN test -n "$FORGEDOCK_VERSION" || { echo "FORGEDOCK_VERSION build arg is required" >&2; exit 1; }
|
|
23
23
|
|
|
24
|
-
ENV IS_SANDBOX=1 DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 PLAYWRIGHT_BROWSERS_PATH=/opt/playwright UV_PYTHON_INSTALL_DIR=/opt/uv-python PATH=/opt/cs/bin:/opt/node/bin:/root/.local/bin:$PATH
|
|
24
|
+
ENV NODE_OPTIONS=--dns-result-order=ipv4first IS_SANDBOX=1 DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 PLAYWRIGHT_BROWSERS_PATH=/opt/playwright UV_PYTHON_INSTALL_DIR=/opt/uv-python PATH=/opt/cs/bin:/opt/node/bin:/root/.local/bin:$PATH
|
|
25
25
|
|
|
26
|
+
# IPv4 for apt: hosts whose Docker networking dials IPv6 first with no IPv6 route (WSL mirrored) fail apt fetches in
|
|
27
|
+
# lane_tools variant builds FROM this image (#6187).
|
|
28
|
+
RUN echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv4
|
|
26
29
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
27
30
|
ca-certificates curl git jq xz-utils build-essential python3 python3-venv python3-dev python3-yaml gnupg pkg-config libpq-dev \
|
|
28
31
|
shellcheck xvfb xauth postgresql-client redis-tools \
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
// #6187: enumerate the pool-served lane_tools sets (pool/image/lane-tools-sets.json) as published variant tags.
|
|
5
|
+
// node scripts/lane-variants.mjs <version> print `<remote tag> <local tag>` per set
|
|
6
|
+
// node scripts/lane-variants.mjs <version> --build build each (FROM the pushed base) and push it; a failed set is reported, the rest continue
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join, dirname } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { laneToolsTag, laneToolsDockerfile, validateLaneTools, checkRecipes } from "../bin/pool/lane-tools.mjs";
|
|
14
|
+
import { remoteLaneImage, remoteVariantImage } from "../bin/pool/lane-image.mjs";
|
|
15
|
+
|
|
16
|
+
const SETS_FILE = join(dirname(fileURLToPath(import.meta.url)), "..", "pool", "image", "lane-tools-sets.json");
|
|
17
|
+
|
|
18
|
+
/** The validated sets: each an array of canonical tool entries; throws naming a bad entry or an unknown recipe. */
|
|
19
|
+
export function loadSets(file = SETS_FILE) {
|
|
20
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
21
|
+
if (!Array.isArray(raw)) throw new Error(`${file}: expected an array of tool lists`);
|
|
22
|
+
return raw.map((set, i) => {
|
|
23
|
+
const { tools, errors } = validateLaneTools(set);
|
|
24
|
+
if (errors.length || !tools.length) throw new Error(`${file} set ${i}: ${errors.join("; ") || "empty"}`);
|
|
25
|
+
checkRecipes(tools);
|
|
26
|
+
return tools;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** [{tools, local, remote, dockerfile}] for `version`; local is `<base>-t<hash>` on the published base ref, remote the variant tag. */
|
|
31
|
+
export function variants(version, sets = loadSets()) {
|
|
32
|
+
const base = remoteLaneImage(version);
|
|
33
|
+
return sets.map((tools) => { const local = laneToolsTag(base, tools); return { tools, tag: local, remote: remoteVariantImage(version, local), dockerfile: laneToolsDockerfile(base, tools) }; });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
37
|
+
const [version, flag] = process.argv.slice(2);
|
|
38
|
+
if (!/^\d+\.\d+\.\d+$/.test(version ?? "")) { console.error("usage: lane-variants.mjs <X.Y.Z> [--build]"); process.exit(2); }
|
|
39
|
+
let failed = 0;
|
|
40
|
+
for (const v of variants(version)) {
|
|
41
|
+
console.log(`${v.remote} ${v.tools.join(",")}`);
|
|
42
|
+
if (flag !== "--build") continue;
|
|
43
|
+
const dir = mkdtempSync(join(tmpdir(), "lane-variant-"));
|
|
44
|
+
try {
|
|
45
|
+
writeFileSync(join(dir, "Dockerfile"), v.dockerfile);
|
|
46
|
+
const r = spawnSync("docker", ["buildx", "build", "--platform", "linux/amd64", "--push", "--label", `org.opencontainers.image.source=${process.env.GITHUB_SERVER_URL ?? "https://github.com"}/${process.env.GITHUB_REPOSITORY ?? ""}`, "-t", v.remote, dir], { stdio: "inherit" });
|
|
47
|
+
if (r.status !== 0) { failed++; console.error(`::warning::variant ${v.remote} was not published; hosts build it locally`); }
|
|
48
|
+
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
49
|
+
}
|
|
50
|
+
process.exit(failed ? 1 : 0);
|
|
51
|
+
}
|