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
package/bin/pool/cli.mjs
CHANGED
|
@@ -11,11 +11,12 @@ import { startRouter } from "./router.mjs";
|
|
|
11
11
|
import { dockerCli } from "./docker.mjs";
|
|
12
12
|
import { readSecret } from "./store.mjs";
|
|
13
13
|
import { call as httpCall } from "./http.mjs";
|
|
14
|
+
import { agentsLeftBehind, leftBehindLine } from "./version.mjs";
|
|
14
15
|
|
|
15
16
|
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
16
17
|
const loadJson = (p) => JSON.parse(readFileSync(p, "utf8"));
|
|
17
18
|
|
|
18
|
-
const USAGE = "usage: forgedock pool router [install] | enroll [--cpus N --mem GB --agent-url URL | --outbound | --one-liner] | status [--json] [--account A] | link <user_code> [--account A] | policy <agent> [--cpus N --mem GB --idle-only --pause --resume-policy] | limit <agent> --lanes N|none | pause | resume | uninstall [--yes] | upgrade [agent] | remove <agent> [--config path]";
|
|
19
|
+
const USAGE = "usage: forgedock pool router [install] | enroll [--cpus N --mem GB --agent-url URL | --outbound | --one-liner] | status [--json] [--account A] | link <user_code> [--account A] | policy <agent> [--cpus N --mem GB --idle-only --pause --resume-policy] | limit <agent> --lanes N|none | pause | resume | uninstall [--yes] | upgrade [agent] [--wait [--timeout S] | --now] | remove <agent> [--config path]";
|
|
19
20
|
const HELP_FLAGS = ["--help", "-h"];
|
|
20
21
|
// Flags each verb accepts: `value` flags consume the next token, `bool` flags stand alone. Anything else dash-prefixed is rejected (#5008).
|
|
21
22
|
const VERB_FLAGS = {
|
|
@@ -27,7 +28,7 @@ const VERB_FLAGS = {
|
|
|
27
28
|
pause: { value: ["--config"], bool: [] },
|
|
28
29
|
resume: { value: ["--config"], bool: [] },
|
|
29
30
|
uninstall: { value: [], bool: ["--yes"] },
|
|
30
|
-
upgrade: { value: ["--config"], bool: [] },
|
|
31
|
+
upgrade: { value: ["--config", "--timeout"], bool: ["--now", "--wait"] },
|
|
31
32
|
remove: { value: ["--config"], bool: [] },
|
|
32
33
|
limit: { value: ["--config", "--lanes"], bool: [] },
|
|
33
34
|
enroll: { value: ["--config", "--cpus", "--mem", "--agent-url"], bool: ["--outbound", "--one-liner"] },
|
|
@@ -46,23 +47,38 @@ function rejectUnknownFlags(cmd, rest) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
/** #6008: sandboxes kept for adopt across the batches under `root` (issue, batch, age, phase): lanes no live dispatcher awaits. */
|
|
51
|
+
export async function keptRows(root, { now = Date.now() } = {}) {
|
|
52
|
+
try {
|
|
53
|
+
const B = await import("../lean/batch.mjs"), out = [];
|
|
54
|
+
for (const id of B.listBatches(root)) {
|
|
55
|
+
const b = B.openBatch(root, id), last = b.lastProgressMs();
|
|
56
|
+
const live = !b.readReport() && last !== null && now - last <= 10 * 60000;
|
|
57
|
+
for (const k of b.keptSandboxes(live)) out.push({ batch: id, ...k });
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
} catch { return []; }
|
|
61
|
+
}
|
|
62
|
+
export const keptLines = (rows) => rows.length ? [`kept sandboxes (${rows.length}):`, ...rows.map((k) => ` #${k.issue} batch ${k.batch} age ${Math.round((k.ageMs ?? 0) / 60000)}m phase ${k.phase ?? "?"}`)] : [];
|
|
49
63
|
const num = (x) => (Number.isFinite(x) ? String(Math.round(x * 10) / 10) : "-");
|
|
50
64
|
/** #5885: one row per host: used/borrowable/total cpus and memory, lane counts, pause state and why lanes are throttled or drained. */
|
|
51
65
|
export function statusTable(agents) {
|
|
52
66
|
const withAccount = agents.some((a) => a.account); // #5886: the column appears only when an agent has an account
|
|
53
|
-
const
|
|
67
|
+
const withEngine = agents.some((a) => a.engine_version); // the ENGINE column appears only when an agent reports its lane engine
|
|
68
|
+
const head = ["HOST", ...(withAccount ? ["ACCOUNT"] : []), "CPUS used/borrow/total", "MEM GB used/borrow/total", "ACTIVE", "THROTTLED", "PAUSED", ...(withEngine ? ["ENGINE"] : []), "REASON"];
|
|
54
69
|
const rows = agents.map((a) => {
|
|
55
70
|
const name = a.name ?? a.host ?? "?";
|
|
56
71
|
const acct = withAccount ? [a.account ?? "-"] : [];
|
|
57
|
-
if (a.ok === false) return [name, ...acct, "-", "-", "-", "-", "-", `unreachable${a.error ? `: ${a.error}` : ""}`];
|
|
72
|
+
if (a.ok === false) return [name, ...acct, "-", "-", "-", "-", ...(withEngine ? ["-"] : []), "-", `unreachable${a.error ? `: ${a.error}` : ""}`];
|
|
58
73
|
const used = (tot, free) => (Number.isFinite(tot) && Number.isFinite(free) ? tot - Math.max(0, free) : null);
|
|
59
74
|
const borrow = (b, free) => num(b ?? free);
|
|
60
75
|
const paused = a.owner_paused ? "owner" : a.paused ? (a.pending_resize ? "resize" : "yes") : "no";
|
|
61
76
|
const why = [a.owner_paused ? "paused by owner" : null, a.paused && !a.owner_paused && a.pending_resize ? "draining for resize" : null,
|
|
77
|
+
Number.isInteger(a.lane_target) ? `lane target ${a.lane_target}/${a.lane_ceiling ?? "-"}` : null, a.draining && !a.owner_paused && !a.pending_resize ? `draining: ${a.draining_reason ?? "yes"}` : null,
|
|
62
78
|
a.idle_gate ? `owner busy: ${a.idle_gate}` : null, a.last_drain ? `last drain ${a.last_drain.sandbox} at ${a.last_drain.at}: ${a.last_drain.reason}` : null].filter(Boolean).join("; ");
|
|
63
79
|
return [name, ...acct, `${num(used(a.cpus_total, a.cpus_free))}/${borrow(a.cpus_borrowable, a.cpus_free)}/${num(a.cpus_total)}`,
|
|
64
80
|
`${num(used(a.mem_total_gb, a.mem_free_gb))}/${borrow(a.mem_borrowable_gb, a.mem_free_gb)}/${num(a.mem_total_gb)}`,
|
|
65
|
-
String(a.active ?? "-"), String(a.throttled ?? 0), paused, why || "-"];
|
|
81
|
+
String(a.active ?? "-"), String(a.throttled ?? 0), paused, ...(withEngine ? [a.engine_version ? `${a.engine_version}${a.engine_skew ? " SKEW" : ""}` : "-"] : []), why || "-"];
|
|
66
82
|
});
|
|
67
83
|
const w = head.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
68
84
|
return [head, ...rows].map((r) => r.map((c, i) => (i === r.length - 1 ? c : c.padEnd(w[i]))).join(" ")).join("\n");
|
|
@@ -124,10 +140,12 @@ export async function runPoolCli(argv, deps = {}) {
|
|
|
124
140
|
case "status": {
|
|
125
141
|
const cfg = routerConfig();
|
|
126
142
|
const r = await call(`http://${cfg.listen.host}:${cfg.listen.port}`, "GET", `/agents${flag("account") ? `?account=${encodeURIComponent(flag("account"))}` : ""}`, { token: cfg.forgedock_token });
|
|
127
|
-
|
|
143
|
+
const kept = await keptRows((await import("../lean/batch.mjs")).batchRoot());
|
|
144
|
+
if (rest.includes("--json")) console.log(JSON.stringify(r.data && typeof r.data === "object" && !Array.isArray(r.data) && kept.length ? { ...r.data, kept_sandboxes: kept } : r.data, null, 2));
|
|
128
145
|
else if (!r.ok) throw new Error(`router refused: HTTP ${r.status} ${JSON.stringify(r.data)}`);
|
|
129
146
|
else console.log(statusTable(r.data?.agents ?? []));
|
|
130
147
|
if (!rest.includes("--json") && r.ok) for (const l of depcacheLines(r.data?.agents)) console.log(l); // #5901
|
|
148
|
+
if (!rest.includes("--json")) for (const l of keptLines(kept)) console.log(l); // #6008
|
|
131
149
|
// #5735: lane sandboxes used/ceiling per agent, and the lane total across all batches
|
|
132
150
|
for (const a of Array.isArray(r.data?.agents) ? r.data.agents : []) if (a?.lanes) console.log(`${a.name}: lanes ${a.lanes.used}/${a.lanes.ceiling ?? "-"}`);
|
|
133
151
|
if (Number.isInteger(r.data?.remote_lanes)) console.log(`remote lanes across batches: ${r.data.remote_lanes}`);
|
|
@@ -252,12 +270,38 @@ export async function runPoolCli(argv, deps = {}) {
|
|
|
252
270
|
// Push the current code (and lane image, when its recipe changed) to one agent or all of them.
|
|
253
271
|
const cfg = routerConfig();
|
|
254
272
|
const base = `http://${cfg.listen.host}:${cfg.listen.port}`;
|
|
255
|
-
const only = rest.find((x) => !x.startsWith("--") && x !== flag("config"));
|
|
256
|
-
const
|
|
273
|
+
const only = rest.find((x) => !x.startsWith("--") && x !== flag("config") && x !== flag("timeout"));
|
|
274
|
+
const now = rest.includes("--now"), wait = rest.includes("--wait");
|
|
275
|
+
const timeoutS = flag("timeout") === undefined ? 1800 : Number(flag("timeout"));
|
|
276
|
+
if (!Number.isFinite(timeoutS) || timeoutS < 0) throw new Error("usage: --timeout takes a number of seconds");
|
|
277
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
278
|
+
const clock = deps.now ?? Date.now;
|
|
279
|
+
const agentsNow = async () => (await call(base, "GET", "/agents", { token: cfg.forgedock_token })).data?.agents ?? [];
|
|
280
|
+
const list = await agentsNow();
|
|
257
281
|
for (const a of list.filter((x) => !only || x.name === only)) {
|
|
258
|
-
|
|
282
|
+
// The pool host is shared: upgrading restarts the agent under live sandboxes, so refuse unless asked (--wait drains, --now forces).
|
|
283
|
+
let active = a.active;
|
|
284
|
+
if (Number(active) > 0 && wait && !now) {
|
|
285
|
+
const deadline = clock() + timeoutS * 1000;
|
|
286
|
+
while (Number(active) > 0) {
|
|
287
|
+
if (clock() >= deadline) throw new Error(`${a.name}: still ${active} active sandbox(es) after ${timeoutS}s; not upgraded`);
|
|
288
|
+
await sleep(deps.pollMs ?? 10000);
|
|
289
|
+
active = (await agentsNow()).find((x) => x.name === a.name)?.active;
|
|
290
|
+
}
|
|
291
|
+
} else if (Number(active) > 0 && !now) {
|
|
292
|
+
throw new Error(`${a.name}: ${active} active sandbox(es) on this shared host; not upgraded. Use --wait to wait for idle, or --now to force.`);
|
|
293
|
+
}
|
|
294
|
+
const r = await call(base, "POST", `/agents/${encodeURIComponent(a.name)}/upgrade`, { body: now ? { force: true } : undefined, token: cfg.forgedock_token, timeoutMs: 30000 });
|
|
295
|
+
if (r.status === 409) throw new Error(`${a.name}: ${r.data?.active ?? "some"} active sandbox(es); not upgraded (HTTP 409)`);
|
|
259
296
|
console.log(`${a.name}: HTTP ${r.status} ${JSON.stringify(r.data)}`);
|
|
260
297
|
}
|
|
298
|
+
// R5: name the agents still on an older engine once the pushes are done (an agent restarts asynchronously, so this can lag briefly).
|
|
299
|
+
const behind = deps.leftBehind ? await deps.leftBehind(base, cfg) : deps.call ? [] : await (async () => { // a custom `call` seam is a fixture without /status
|
|
300
|
+
const get = (p) => httpCall(base, "GET", p, { token: cfg.forgedock_token }).catch(() => null);
|
|
301
|
+
const target = (await get("/version"))?.data?.version;
|
|
302
|
+
return agentsLeftBehind((await get("/status"))?.data?.agents, target).map((r) => ({ ...r, target }));
|
|
303
|
+
})();
|
|
304
|
+
if (behind.length) console.log(leftBehindLine(behind, behind[0].target));
|
|
261
305
|
break;
|
|
262
306
|
}
|
|
263
307
|
case "remove": {
|
package/bin/pool/docker.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import { execFile } from "node:child_process";
|
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { PACKAGE_STORES } from "./cache-sweep.mjs";
|
|
6
6
|
|
|
7
|
+
/** #6047: the lane's CPU quota as env, for lanes whose cgroup files are hidden (read by quotaCores in lean/admission.mjs). */
|
|
8
|
+
export const cpuQuotaEnv = (cpus) => (Number.isFinite(cpus) && cpus > 0 ? { CS_CPU_QUOTA: String(cpus) } : {});
|
|
9
|
+
|
|
7
10
|
/** #5757: work-dir and cache sweeps walk big trees (node_modules): 10 min, not the 120 s of a small rm. */
|
|
8
11
|
export const SWEEP_TIMEOUT_MS = 10 * 60000;
|
|
9
12
|
const SWEEP_SRC = new URL("./cache-sweep.mjs", import.meta.url);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #6091: engine-version aware placement (prefer the orchestrator's engine, execution.min_lane_engine gate), status skew, left-behind report.
|
|
4
|
+
import { test } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { createRouter } from "./router.mjs";
|
|
7
|
+
import { statusTable } from "./cli.mjs";
|
|
8
|
+
import { cmpVersion, agentsLeftBehind, upgradeAgentsAfterUpdate } from "./version.mjs";
|
|
9
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
10
|
+
|
|
11
|
+
const quiet = { info() {}, warn() {}, error() {} };
|
|
12
|
+
const json = (o, status = 200) => new Response(JSON.stringify(o), { status, headers: { "content-type": "application/json" } });
|
|
13
|
+
const spec = (id, extra = {}) => ({ id, issue: 1, batch: "b", repo: { slug: "o/x", url: "https://github.com/o/x.git" }, command: ["x"], ...extra });
|
|
14
|
+
const TARGET = "1.67.0"; // the router's own target: this repo's package.json version (asserted below)
|
|
15
|
+
|
|
16
|
+
// `old` has more free cpus, so capacity order alone would pick it.
|
|
17
|
+
function fixture({ oldFree = true, newFree = true } = {}) {
|
|
18
|
+
const posts = [];
|
|
19
|
+
const caps = { old: { version: "1.66.0", cpus_free: 8, mem_free_gb: 16 }, new: { version: TARGET, cpus_free: newFree ? 2 : 0, mem_free_gb: newFree ? 16 : 0 } };
|
|
20
|
+
if (!oldFree) caps.old = { version: "1.66.0", cpus_free: 0, mem_free_gb: 0 };
|
|
21
|
+
const fetchFn = async (url, init) => {
|
|
22
|
+
const u = new URL(url), h = u.hostname;
|
|
23
|
+
if (u.pathname === "/capacity") return json(caps[h]);
|
|
24
|
+
posts.push(`${h}${u.pathname}`);
|
|
25
|
+
return json({ id: JSON.parse(init.body).spec.id, state: "running" }, u.pathname === "/warm/claim" ? 200 : 201);
|
|
26
|
+
};
|
|
27
|
+
const router = createRouter({ state_dir: tmpDir("cs-eng-"), lane: { cpus: 2, mem_gb: 3 }, enroll_token: "e", forgedock_token: "fd", repo_root: process.cwd() }, { fetchFn, now: () => 5_000_000, log: quiet });
|
|
28
|
+
router.store.data.agents.old = { url: "http://old:7711", token: "t" };
|
|
29
|
+
router.store.data.agents.new = { url: "http://new:7711", token: "t" };
|
|
30
|
+
return { router, posts };
|
|
31
|
+
}
|
|
32
|
+
const target = async () => (await import("./version.mjs")).versionOf(process.cwd()).version;
|
|
33
|
+
test("fixture target is the router's target", async () => assert.equal(await target(), TARGET));
|
|
34
|
+
|
|
35
|
+
test("launch prefers the agent on the orchestrator engine over one with more free cpus", async () => {
|
|
36
|
+
const { router } = fixture();
|
|
37
|
+
const r = await router.launch(spec("l1"));
|
|
38
|
+
assert.equal(r.status, 201);
|
|
39
|
+
assert.equal(r.body.agent, "new");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("only the old agent free and min_lane_engine unset: the lane runs there and says its engine", async () => {
|
|
43
|
+
const { router } = fixture({ newFree: false });
|
|
44
|
+
const r = await router.launch(spec("l2"));
|
|
45
|
+
assert.equal(r.status, 201);
|
|
46
|
+
assert.equal(r.body.agent, "old");
|
|
47
|
+
assert.equal(r.body.engine_version, "1.66.0");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("min_lane_engine above the only free agent defers with pool.engine_old", async () => {
|
|
51
|
+
const { router, posts } = fixture({ newFree: false });
|
|
52
|
+
const r = await router.launch(spec("l3", { min_lane_engine: "1.67" }));
|
|
53
|
+
assert.equal(r.status, 503);
|
|
54
|
+
assert.equal(r.body.code, "pool.engine_old");
|
|
55
|
+
assert.ok(r.retryAfter > 0);
|
|
56
|
+
assert.deepEqual(posts, []);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("claim follows the same order and gate", async () => {
|
|
60
|
+
const { router, posts } = fixture();
|
|
61
|
+
const c = await router.claim(spec("c1", { min_lane_engine: "1.67" }));
|
|
62
|
+
assert.equal(c.body.agent, "new");
|
|
63
|
+
assert.deepEqual(posts, ["new/warm/claim"]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("status carries each agent's engine and flags skew; statusTable shows it", async () => {
|
|
67
|
+
const { router } = fixture();
|
|
68
|
+
const s = await router.status();
|
|
69
|
+
const t = await target();
|
|
70
|
+
const old = s.agents.find((a) => a.name === "old");
|
|
71
|
+
assert.equal(old.engine_version, "1.66.0");
|
|
72
|
+
assert.equal(old.engine_skew, cmpVersion("1.66.0", t) < 0);
|
|
73
|
+
const table = statusTable([{ name: "a", ok: true, engine_version: "1.66.0", engine_skew: true }, { name: "b", ok: true, engine_version: TARGET, engine_skew: false }]);
|
|
74
|
+
assert.match(table, /ENGINE/);
|
|
75
|
+
assert.match(table, /1\.66\.0 SKEW/);
|
|
76
|
+
assert.doesNotMatch(table.split("\n")[2], /SKEW/);
|
|
77
|
+
assert.doesNotMatch(statusTable([{ name: "a", ok: true }]), /ENGINE/, "no version info: table as before");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("cmpVersion is numeric, agents without a version never lag", () => {
|
|
81
|
+
assert.ok(cmpVersion("1.10.0", "1.9.9") > 0);
|
|
82
|
+
assert.equal(cmpVersion("1.67", "1.67.0"), 0);
|
|
83
|
+
assert.equal(cmpVersion(undefined, "1.67.0"), null);
|
|
84
|
+
assert.deepEqual(agentsLeftBehind([{ name: "a", ok: true, engine_version: "1.66.0" }, { name: "b", ok: true }, { name: "c", ok: true, engine_version: "1.67.0" }], "1.67.0"), [{ name: "a", version: "1.66.0" }]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("upgradeAgentsAfterUpdate names agents left behind and keeps its string result", async () => {
|
|
88
|
+
const warned = [], dir = tmpDir("cs-eng-cfg-"), cfgPath = `${dir}/router.json`;
|
|
89
|
+
(await import("node:fs")).writeFileSync(cfgPath, "{}");
|
|
90
|
+
const r = await upgradeAgentsAfterUpdate({ configPath: cfgPath, runPoolCli: async () => {}, warn: (m) => warned.push(m),
|
|
91
|
+
leftBehind: async () => ({ target: "1.67.0", rows: [{ name: "old", version: "1.66.0" }] }) });
|
|
92
|
+
assert.equal(r, "upgraded");
|
|
93
|
+
assert.match(warned[0], /left behind.*old 1\.66\.0/);
|
|
94
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #6061: the per-worker lane target. Same AIMD thresholds as the orchestrator controller (bin/lean/concurrency.mjs, imported):
|
|
5
|
+
* +1 while free memory is above floor + headroom and load per core is green for a hold window, halve (min 1) on load above
|
|
6
|
+
* 1.5/core or low memory, never above the configured ceiling. `drainState` says when the worker accepts no new lane (running
|
|
7
|
+
* lanes always finish). Pure: the caller keeps `greenSince` / busy timers and feeds the clock.
|
|
8
|
+
*/
|
|
9
|
+
import { LOAD_GREEN, LOAD_HALVE, MEM_FLOOR_GB, MEM_HEADROOM_GB } from "../lean/concurrency.mjs";
|
|
10
|
+
|
|
11
|
+
export const GREEN_HOLD_MS = 60_000;
|
|
12
|
+
export const DRAIN_AFTER_MS = 5 * 60_000;
|
|
13
|
+
const fin = (v) => typeof v === "number" && Number.isFinite(v);
|
|
14
|
+
|
|
15
|
+
/** Is the host over its pressure line (load above 1.5/core or free memory under the floor)? Unknown figures are not pressure. */
|
|
16
|
+
export const pressured = (live, { memFloorGb = MEM_FLOOR_GB } = {}) =>
|
|
17
|
+
(fin(live?.load_per_core) && live.load_per_core > LOAD_HALVE) || (fin(live?.mem_available_gb) && live.mem_available_gb < memFloorGb);
|
|
18
|
+
|
|
19
|
+
/** Next `{ target, greenSince, change }` (change: "grow" | "halve" | null). `refused` (a pool.* refusal) also halves. */
|
|
20
|
+
export function step({ target, ceiling, live, refused = false, now = Date.now(), greenSince = null, holdMs = GREEN_HOLD_MS, memFloorGb = MEM_FLOOR_GB, memHeadroomGb = MEM_HEADROOM_GB } = {}) {
|
|
21
|
+
const top = Math.max(1, Number.isInteger(ceiling) ? ceiling : 1);
|
|
22
|
+
const t = Math.min(top, Math.max(1, Number.isInteger(target) ? target : 1));
|
|
23
|
+
if (refused || pressured(live, { memFloorGb })) {
|
|
24
|
+
const next = Math.max(1, Math.floor(t / 2));
|
|
25
|
+
return { target: next, greenSince: null, change: next < t ? "halve" : null };
|
|
26
|
+
}
|
|
27
|
+
const green = fin(live?.load_per_core) && live.load_per_core < LOAD_GREEN && fin(live?.mem_available_gb) && live.mem_available_gb > memFloorGb + memHeadroomGb;
|
|
28
|
+
if (!green) return { target: t, greenSince: null, change: null };
|
|
29
|
+
const since = greenSince ?? now;
|
|
30
|
+
if (t < top && now - since >= holdMs) return { target: t + 1, greenSince: now, change: "grow" }; // each step needs a fresh hold window
|
|
31
|
+
return { target: t, greenSince: since, change: null };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** `{ draining, reason }`: paused (owner, policy or config), or the host busy for `drainAfterMs`. */
|
|
35
|
+
export function drainState({ paused = false, ownerPaused = false, policyPaused = false, busyForMs = 0, drainAfterMs = DRAIN_AFTER_MS } = {}) {
|
|
36
|
+
if (ownerPaused) return { draining: true, reason: "paused by owner" };
|
|
37
|
+
if (policyPaused) return { draining: true, reason: "paused by policy" };
|
|
38
|
+
if (paused) return { draining: true, reason: "paused" };
|
|
39
|
+
if (busyForMs >= drainAfterMs) return { draining: true, reason: `host busy for ${Math.round(busyForMs / 60000)}m` };
|
|
40
|
+
return { draining: false, reason: null };
|
|
41
|
+
}
|
package/bin/pool/lane-tools.mjs
CHANGED
|
@@ -17,6 +17,7 @@ export const RECIPES = {
|
|
|
17
17
|
python: { versioned: true, steps: (v) => [apt(v ? `python${v} python${v}-venv` : "python3 python3-venv")] },
|
|
18
18
|
xvfb: { versioned: false, steps: () => [apt("xvfb xauth")] }, // headless X for browser/GUI tests that call xvfb-run
|
|
19
19
|
shellcheck: { versioned: false, steps: () => [apt("shellcheck")] }, // shell-script linter for validate commands
|
|
20
|
+
yaml: { versioned: false, steps: () => [apt("python3-yaml")] }, // PyYAML for validate commands that `import yaml` (#5749)
|
|
20
21
|
playwright: { versioned: true, steps: (v) => [`RUN npx --yes playwright${v ? `@${v}` : ""} install --with-deps chromium`] },
|
|
21
22
|
// Example of a release-tarball tool; the version is required.
|
|
22
23
|
promtool: { versioned: true, steps: (v) => [`RUN curl -fsSL https://github.com/prometheus/prometheus/releases/download/v${v ?? "2.54.1"}/prometheus-${v ?? "2.54.1"}.linux-amd64.tar.gz | tar -xz --strip-components=1 -C /usr/local/bin --wildcards '*/promtool'`] },
|
|
@@ -70,6 +71,31 @@ export function installCommands(entry, { root = true } = {}) {
|
|
|
70
71
|
return RECIPES[recipe].steps(recipe === name ? version : null).map((s) => (root ? sh(s) : `sudo sh -c ${JSON.stringify(sh(s))}`));
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Generic install for a tool no recipe covers (2026-11-26 unclog): a missing Python module is pip-installed, a missing
|
|
76
|
+
* Node package npm-installed into the worktree, a missing command apt-installed. Replaces adding one recipe per tool
|
|
77
|
+
* (77 of 215 needs-human parks on open issues were "Remote sandbox lacks X"). `miss`: {kind, tool} from the validate
|
|
78
|
+
* preflight. Returns [] for an unsafe name or a kind nothing can install (environment, forgedock-path).
|
|
79
|
+
*/
|
|
80
|
+
const PYPI = { yaml: "PyYAML", PIL: "Pillow", cv2: "opencv-python-headless", bs4: "beautifulsoup4", sklearn: "scikit-learn", dateutil: "python-dateutil", jwt: "PyJWT", dotenv: "python-dotenv", google: "protobuf", attr: "attrs", magic: "python-magic", Crypto: "pycryptodome", OpenSSL: "pyOpenSSL", serial: "pyserial", usb: "pyusb", zmq: "pyzmq", git: "GitPython", jose: "python-jose", multipart: "python-multipart" };
|
|
81
|
+
const SAFE = /^@?[A-Za-z0-9][A-Za-z0-9._/+-]*$/;
|
|
82
|
+
/** Debian/Ubuntu package stems where the import name differs (python3-<stem>). */
|
|
83
|
+
const APT_PY = { PIL: "pil", cv2: "opencv", bs4: "bs4", sklearn: "sklearn", dateutil: "dateutil", jwt: "jwt", dotenv: "dotenv", serial: "serial", git: "git", magic: "magic" };
|
|
84
|
+
export function genericInstallCommands(miss, { root = true } = {}) {
|
|
85
|
+
const tool = String(miss?.tool ?? "").trim();
|
|
86
|
+
if (!tool || !SAFE.test(tool) || tool.includes("..")) return [];
|
|
87
|
+
const su = (c) => (root ? c : `sudo sh -c ${JSON.stringify(c)}`);
|
|
88
|
+
if (miss.kind === "python-module") {
|
|
89
|
+
const mod = tool.split(".")[0], pkg = PYPI[mod] ?? mod;
|
|
90
|
+
// 2026-11-26: lane images may ship python3 without pip; the distro package (python3-<module>) is the fallback
|
|
91
|
+
const deb = `python3-${(APT_PY[mod] ?? mod).toLowerCase().replace(/_/g, "-")}`;
|
|
92
|
+
return [`python3 -m pip install --user --quiet ${pkg} || python3 -m pip install --user --quiet --break-system-packages ${pkg} || (${su(`apt-get update -qq && apt-get install -y --no-install-recommends ${deb} && rm -rf /var/lib/apt/lists/*`)})`];
|
|
93
|
+
}
|
|
94
|
+
if (miss.kind === "node-module") return [`npm install --no-save --no-audit --no-fund ${tool}`];
|
|
95
|
+
if (miss.kind === "command" && !tool.includes("/")) return [su(`apt-get update -qq && apt-get install -y --no-install-recommends ${tool} && rm -rf /var/lib/apt/lists/*`)];
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
|
|
73
99
|
/**
|
|
74
100
|
* Installs `tools` in the running sandbox through the injected `run({command, timeoutMs})` -> {rc, stdout, stderr}.
|
|
75
101
|
* Never throws: {ok:true} or {ok:false, tool, stderrTail}.
|
|
@@ -35,3 +35,12 @@ describe("#5652 in-sandbox lane tool install", () => {
|
|
|
35
35
|
assert.match(installCommands("python@3.12")[0], /python3\.12 python3\.12-venv/);
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
describe("#5749 yaml recipe", () => {
|
|
40
|
+
it("#5749 yaml has a lane_tools recipe", () => {
|
|
41
|
+
assert.ok(hasRecipe("yaml"));
|
|
42
|
+
assert.match(installCommands("yaml")[0], /apt-get install .*python3-yaml/);
|
|
43
|
+
assert.ok(hasRecipe("shellcheck"));
|
|
44
|
+
assert.ok(!hasRecipe("vite") && !hasRecipe("forgedock"), "#5749: manifest/owned deps get no recipe");
|
|
45
|
+
});
|
|
46
|
+
});
|
package/bin/pool/mirror-seed.mjs
CHANGED
|
@@ -66,8 +66,12 @@ export function localRunner({ root, seedDir }) {
|
|
|
66
66
|
/** `runnerFor({slug, cache_key})` -> runner. Returns the agent's mirror seed handlers. */
|
|
67
67
|
export function makeMirrorSeed({ seedDir, runnerFor, partTtlMs = SEED_PART_TTL_MS, uploadMax = SEED_UPLOAD_MAX, totalMax = SEED_TOTAL_MAX }) {
|
|
68
68
|
mkdirSync(seedDir, { recursive: true });
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// Concurrent lanes seeding the same repo build byte-identical bundles (same sha256). One shared `<sha>.part` let them
|
|
70
|
+
// append into each other's upload: 409 offset mismatch, then 422 when one finish deleted the file under the others
|
|
71
|
+
// (2026-11-26 lane-lifecycle audit: bursts of 5–12 lanes within seconds). Each uploader now has its own part file.
|
|
72
|
+
const who = (u) => (typeof u === "string" && /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(u) ? `.${u}` : "");
|
|
73
|
+
const part = (up, uploader) => join(seedDir, `${up}${who(uploader)}.part`);
|
|
74
|
+
const size = (up, uploader) => { try { return statSync(part(up, uploader)).size; } catch { return 0; } };
|
|
71
75
|
/** Removes `.part` files idle past the TTL; returns the bytes the remaining ones hold. */
|
|
72
76
|
const sweep = () => {
|
|
73
77
|
let total = 0;
|
|
@@ -87,11 +91,11 @@ export function makeMirrorSeed({ seedDir, runnerFor, partTtlMs = SEED_PART_TTL_M
|
|
|
87
91
|
};
|
|
88
92
|
return {
|
|
89
93
|
/** `GET /mirrors`: {mirrors: {slug: {ref: sha} | "absent"}, upload_offset?}. */
|
|
90
|
-
async tips({ slug, cache_key = null, upload = null }) {
|
|
94
|
+
async tips({ slug, cache_key = null, upload = null, uploader = null }) {
|
|
91
95
|
if (typeof slug !== "string" || !SLUG_RE.test(slug)) throw fail(400, "slug required");
|
|
92
96
|
const out = String(await runnerFor({ slug, cache_key })(TIPS_SCRIPT, { NAME: mirrorName(slug) })).trim();
|
|
93
97
|
const mirror = out === "ABSENT" ? "absent" : Object.fromEntries(out.split("\n").filter(Boolean).map((l) => { const i = l.indexOf(" "); return [l.slice(i + 1), l.slice(0, i)]; }));
|
|
94
|
-
return { mirrors: { [slug]: mirror }, ...(upload && SHA_RE.test(upload) ? { upload_offset: size(upload) } : {}) };
|
|
98
|
+
return { mirrors: { [slug]: mirror }, ...(upload && SHA_RE.test(upload) ? { upload_offset: size(upload, uploader) } : {}) };
|
|
95
99
|
},
|
|
96
100
|
/** One chunk: {slug, cache_key, upload, offset, data_b64, sha256}. A wrong offset is a 409 carrying the offset to resume from. */
|
|
97
101
|
chunk(b) {
|
|
@@ -99,23 +103,23 @@ export function makeMirrorSeed({ seedDir, runnerFor, partTtlMs = SEED_PART_TTL_M
|
|
|
99
103
|
const buf = Buffer.from(String(b.data_b64 ?? ""), "base64");
|
|
100
104
|
if (!buf.length || buf.length > SEED_CHUNK_MAX) throw fail(413, `chunk must be 1..${SEED_CHUNK_MAX} bytes`);
|
|
101
105
|
if (sha256(buf) !== b.sha256) throw fail(422, "chunk checksum mismatch");
|
|
102
|
-
const have = size(b.upload);
|
|
106
|
+
const have = size(b.upload, b.uploader);
|
|
103
107
|
if (b.offset !== have) throw fail(409, "offset mismatch", { offset: have });
|
|
104
108
|
if (have + buf.length > uploadMax) throw fail(413, `upload exceeds ${uploadMax} bytes`);
|
|
105
109
|
if (sweep() + buf.length > totalMax) throw fail(413, `seed dir exceeds ${totalMax} bytes`);
|
|
106
|
-
appendFileSync(part(b.upload), buf);
|
|
110
|
+
appendFileSync(part(b.upload, b.uploader), buf);
|
|
107
111
|
return { offset: have + buf.length };
|
|
108
112
|
},
|
|
109
113
|
/** Verifies the whole bundle against {size, sha256 = upload} and applies it. A corrupt upload is dropped; the mirror is never touched on failure. */
|
|
110
114
|
async finish(b) {
|
|
111
115
|
check(b);
|
|
112
116
|
const f = b.finish ?? {};
|
|
113
|
-
const have = size(b.upload);
|
|
117
|
+
const p = part(b.upload, b.uploader), have = size(b.upload, b.uploader);
|
|
114
118
|
if (!Number.isInteger(f.size) || have !== f.size) throw fail(409, "incomplete upload", { offset: have });
|
|
115
|
-
if (!existsSync(
|
|
116
|
-
try { await runnerFor(b)(APPLY_SCRIPT, { NAME: mirrorName(b.slug), BUNDLE: `${b.upload}.part` }); }
|
|
117
|
-
catch (e) { rmSync(
|
|
118
|
-
rmSync(
|
|
119
|
+
if (!existsSync(p) || sha256(readFileSync(p)) !== b.upload) { rmSync(p, { force: true }); throw fail(422, "bundle checksum mismatch"); }
|
|
120
|
+
try { await runnerFor(b)(APPLY_SCRIPT, { NAME: mirrorName(b.slug), BUNDLE: `${b.upload}${who(b.uploader)}.part` }); }
|
|
121
|
+
catch (e) { rmSync(p, { force: true }); throw fail(422, `bundle apply failed: ${String(e.stderr || e.message).slice(-300)}`); }
|
|
122
|
+
rmSync(p, { force: true });
|
|
119
123
|
return { ok: true, ...(await this.tips({ slug: b.slug, cache_key: b.cache_key })) };
|
|
120
124
|
},
|
|
121
125
|
};
|