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
|
@@ -13,3 +13,17 @@ export function decideClear({ tripped, requestAt }) {
|
|
|
13
13
|
if (tripped && Number.isFinite(tripped.at) && tripped.at > requestAt) return { clear: false, stale: true };
|
|
14
14
|
return { clear: true, stale: false };
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* #5978: the runner's own reset of a tripped breaker. It closes after `cooldownMs` when the failures were environmental
|
|
19
|
+
* (VM restart, mirror, network: `environmental`) and the pool is healthy again (#5947 classes); anything else needs `--clear-breaker`.
|
|
20
|
+
* @param {{tripped: ({at?: number}|null|undefined), now: number, cooldownMs: number, environmental: boolean, poolHealthy: boolean}} p
|
|
21
|
+
* @returns {{reset: boolean, why: string}}
|
|
22
|
+
*/
|
|
23
|
+
export function decideAutoReset({ tripped, now, cooldownMs, environmental, poolHealthy }) {
|
|
24
|
+
if (!tripped || !Number.isFinite(tripped.at)) return { reset: false, why: "not tripped" };
|
|
25
|
+
if (!environmental) return { reset: false, why: "failure signature is not environmental" };
|
|
26
|
+
if (now - tripped.at < cooldownMs) return { reset: false, why: "cooldown not elapsed" };
|
|
27
|
+
if (!poolHealthy) return { reset: false, why: "pool not healthy" };
|
|
28
|
+
return { reset: true, why: "environmental signature, cooldown elapsed, pool healthy" };
|
|
29
|
+
}
|
|
@@ -17,13 +17,14 @@ const MERGED = { terminalReason: "merged", pr: 9 };
|
|
|
17
17
|
|
|
18
18
|
/** A runner whose every pass costs 12 s of injected time; `req` is the pending request `at` (or null), made `reqAfterMs` after the trip. */
|
|
19
19
|
const slowRun = async ({ reqAfterMs }) => {
|
|
20
|
-
let t = 1_000_000, tripAt = null, req = null, consumed = 0; const acks = [], calls = [];
|
|
20
|
+
let t = 1_000_000, tripAt = null, req = null, consumed = 0; const acks = [], calls = [], ac = new AbortController();
|
|
21
21
|
const script = { 1: [EE("boom A")], 2: [EE("boom B")], 3: [MERGED] };
|
|
22
|
-
const rows = await orchestrate({ issues: [1, 2, 3], parallel: 1, readBody: async () => "", now: () => t, store: memStore(), pollMs: 12000, breaker: { errors: 2, window_min: 10 },
|
|
22
|
+
const rows = await orchestrate({ issues: [1, 2, 3], parallel: 1, readBody: async () => "", now: () => t, store: memStore(), pollMs: 12000, breaker: { errors: 2, window_min: 10 }, signal: ac.signal,
|
|
23
23
|
sleep: async (ms) => { t += Math.max(12000, Number(ms) || 0); },
|
|
24
24
|
runOne: async (n) => { calls.push(n); t += 12000; return script[n][0]; },
|
|
25
25
|
onUpdate: (u) => { if (u.outcome === "breaker" && tripAt === null) { tripAt = t; req = tripAt + reqAfterMs; } },
|
|
26
|
-
getClearBreaker: () => req, consumeClearBreaker: () => { req = null; consumed++;
|
|
26
|
+
getClearBreaker: () => req, consumeClearBreaker: () => { req = null; consumed++; if (reqAfterMs < 0) ac.abort(); }, // #6042: a trip kept closed by a stale request waits for an operator; the test ends it
|
|
27
|
+
ackClearBreaker: (i) => acks.push(i) });
|
|
27
28
|
return { rows, acks, calls, consumed };
|
|
28
29
|
};
|
|
29
30
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5979: post a machine comment only on a state change. A scheduler pass that re-derives the same DEPENDENCY, FACTS, or
|
|
5
|
+
* NEEDS_HUMAN text posts nothing; a changed FACTS or DEPENDENCY is edited in place; a changed NEEDS_HUMAN is a new comment
|
|
6
|
+
* (statuscomment.mjs header: a new comment notifies a person, an edit does not, and issuewatch keys on the newest one). Pure.
|
|
7
|
+
*/
|
|
8
|
+
import { IN_PLACE_MARKERS, contractKeyOf } from "./statuscomment.mjs";
|
|
9
|
+
|
|
10
|
+
/** Markers whose changed state is PATCHed rather than posted again. */
|
|
11
|
+
export const PATCH_MARKERS = Object.freeze(IN_PLACE_MARKERS.filter((m) => m !== "FORGE:NEEDS_HUMAN"));
|
|
12
|
+
|
|
13
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
|
+
|
|
15
|
+
/** The body without what changes between identical states: the cost/usage line, comment urls and ids, shas, whitespace. */
|
|
16
|
+
export function normalizeState(body) {
|
|
17
|
+
return String(body ?? "")
|
|
18
|
+
.split("\n")
|
|
19
|
+
.filter((l) => !/^\s*_?\s*cost \$[\d.]+/i.test(l))
|
|
20
|
+
.join("\n")
|
|
21
|
+
.replace(/https?:\/\/\S*#issuecomment-\d+/g, "")
|
|
22
|
+
.replace(/\b[0-9a-f]{7,40}\b/g, "")
|
|
23
|
+
.replace(/\s+/g, " ")
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The newest trusted comment carrying `marker` (a `<!-- marker` line anywhere in the body), or null. */
|
|
28
|
+
export function findLast(comments, marker, trusted = () => true) {
|
|
29
|
+
const re = new RegExp(`<!--\\s*${esc(marker)}(?![A-Za-z0-9_])`);
|
|
30
|
+
const list = Array.isArray(comments) ? comments : [];
|
|
31
|
+
for (let i = list.length - 1; i >= 0; i--) if (re.test(String(list[i]?.body ?? "")) && trusted(list[i])) return list[i];
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `{action: "skip"|"patch"|"create", prior}` for posting `body` under `marker` given the issue's comments. #5931: with a `contractHash`
|
|
37
|
+
* the prior is the newest comment keyed to that hash and every in-place marker (NEEDS_HUMAN too) is edited in place; a changed hash is a new comment.
|
|
38
|
+
*/
|
|
39
|
+
export function decidePost({ marker, body, comments, trusted, contractHash = null }) {
|
|
40
|
+
const keyed = !!contractHash && IN_PLACE_MARKERS.includes(marker);
|
|
41
|
+
const list = Array.isArray(comments) ? comments : [];
|
|
42
|
+
const prior = keyed ? findLast(list.filter((c) => contractKeyOf(c?.body) === String(contractHash).replace(/[^\w]/g, "")), marker, trusted) : findLast(comments, marker, trusted);
|
|
43
|
+
if (!prior) return { action: "create", prior: null };
|
|
44
|
+
if (normalizeState(prior.body) === normalizeState(body)) return { action: "skip", prior };
|
|
45
|
+
return { action: keyed || PATCH_MARKERS.includes(marker) ? "patch" : "create", prior };
|
|
46
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { normalizeState, findLast, decidePost } from "./commentstate.mjs";
|
|
6
|
+
import { IN_PLACE_MARKERS, contractKey } from "./statuscomment.mjs";
|
|
7
|
+
|
|
8
|
+
const body = (m, text, cost = "0.10") => `<!-- ${m} -->\n${text}\n\n_cost $${cost}, tokens 1 in / 2 out_`;
|
|
9
|
+
const url = "https://github.com/o/r/issues/1#issuecomment-5";
|
|
10
|
+
|
|
11
|
+
describe("post only on a state change (#5979)", () => {
|
|
12
|
+
for (const m of IN_PLACE_MARKERS) {
|
|
13
|
+
it(`a second identical ${m} post is skipped, even when only the usage line differs`, () => {
|
|
14
|
+
const comments = [{ body: body(m, "same state"), url }];
|
|
15
|
+
assert.equal(decidePost({ marker: m, body: body(m, "same state", "9.99"), comments }).action, "skip");
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
it("a changed DEPENDENCY or FACTS is patched in place; a changed NEEDS_HUMAN is a new comment", () => {
|
|
19
|
+
const comments = (m) => [{ body: body(m, "old"), url }];
|
|
20
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: body("FORGE:DEPENDENCY", "new"), comments: comments("FORGE:DEPENDENCY") }).action, "patch");
|
|
21
|
+
assert.equal(decidePost({ marker: "FORGE:FACTS", body: body("FORGE:FACTS", "new"), comments: comments("FORGE:FACTS") }).action, "patch");
|
|
22
|
+
assert.equal(decidePost({ marker: "FORGE:NEEDS_HUMAN", body: body("FORGE:NEEDS_HUMAN", "new"), comments: comments("FORGE:NEEDS_HUMAN") }).action, "create");
|
|
23
|
+
});
|
|
24
|
+
it("no earlier comment creates; an untrusted one is ignored", () => {
|
|
25
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: "x", comments: [] }).action, "create");
|
|
26
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: "x", comments: [{ body: body("FORGE:DEPENDENCY", "x") }], trusted: () => false }).action, "create");
|
|
27
|
+
});
|
|
28
|
+
it("findLast returns the newest; normalizeState drops usage, ids and shas", () => {
|
|
29
|
+
assert.equal(findLast([{ body: "<!-- FORGE:FACTS -->\na" }, { body: "<!-- FORGE:FACTS -->\nb" }], "FORGE:FACTS").body.endsWith("b"), true);
|
|
30
|
+
assert.equal(normalizeState(body("M", "a b 1e0c3e45")), normalizeState(body("M", "a b", "5")));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("#5931 in-place per contract hash", () => {
|
|
35
|
+
for (const m of ["FORGE:NEEDS_HUMAN", "FORGE:FACTS", "FORGE:AMENDMENT-STATE"]) {
|
|
36
|
+
it(`${m}: edited in place at the same contract hash, a new comment when the hash changes`, () => {
|
|
37
|
+
assert.ok(IN_PLACE_MARKERS.includes(m));
|
|
38
|
+
const comments = [{ body: `${body(m, "old")}\n${contractKey("c1")}`, url }];
|
|
39
|
+
assert.equal(decidePost({ marker: m, body: body(m, "new"), comments, contractHash: "c1" }).action, "patch");
|
|
40
|
+
assert.equal(decidePost({ marker: m, body: body(m, "new"), comments, contractHash: "c2" }).action, "create");
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Closed-loop lane concurrency (#5985). K (`getParallel`/`--parallel`) is the ceiling; the operating point moves under it:
|
|
5
|
+
* additive increase while the pool reports headroom and has refused nothing lately, multiplicative decrease (halve) on a
|
|
6
|
+
* `pool.*` refusal or load above 1.5/core. A lane the pool refused is held for REFUSAL_HOLD_MS unless the named condition
|
|
7
|
+
* (load below 1.0, free memory above the floor) clears first. Pure: no I/O, the caller feeds samples and persists events.
|
|
8
|
+
*/
|
|
9
|
+
export const REFUSAL_HOLD_MS = 5 * 60_000;
|
|
10
|
+
export const HEAVY_CPU_AVG = 1.5;
|
|
11
|
+
export const LOAD_HALVE = 1.5;
|
|
12
|
+
export const LOAD_GREEN = 1.0;
|
|
13
|
+
export const MEM_FLOOR_GB = 4;
|
|
14
|
+
export const MEM_HEADROOM_GB = 2;
|
|
15
|
+
|
|
16
|
+
const fin = (v) => typeof v === "number" && Number.isFinite(v);
|
|
17
|
+
/** `host_load` from a refusal reason/code (`pool.host_load` or `host_load`); "" when it is not a pool reason. */
|
|
18
|
+
export const poolReason = (v) => { const m = /^(?:pool\.)?(host_load|host_mem|projected_peak|disk(?:_low|_cap)?)$/.exec(String(v ?? "")); return m ? m[1].replace(/^disk_.*/, "disk") : ""; };
|
|
19
|
+
|
|
20
|
+
/** The named condition a refusal waits on: true = cleared, false = still holding, null = unknown (no figures, or no named condition). */
|
|
21
|
+
export function conditionCleared(reason, cap, { memFloorGb = MEM_FLOOR_GB } = {}) {
|
|
22
|
+
const r = poolReason(reason);
|
|
23
|
+
if (r === "host_load") return fin(cap?.load_per_core) ? cap.load_per_core < LOAD_GREEN : null;
|
|
24
|
+
if (r === "host_mem") return fin(cap?.mem_available_gb) ? cap.mem_available_gb > memFloorGb : null;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A repo is heavy when its recent finished lanes average more than 1.5 cpus (`usage-history.jsonl` rows `{repo, cpu_avg}`). */
|
|
29
|
+
export function classifyRepo(rows, repo, { window = 20 } = {}) {
|
|
30
|
+
const v = (rows ?? []).filter((x) => x && x.repo === repo && fin(x.cpu_avg)).slice(-window).map((x) => x.cpu_avg);
|
|
31
|
+
return v.length > 0 && v.reduce((a, b) => a + b, 0) / v.length > HEAVY_CPU_AVG ? "heavy" : "light";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function makeController({ ceiling, heavyCap = null, now = Date.now, memFloorGb = MEM_FLOOR_GB, holdMs = REFUSAL_HOLD_MS, start = null } = {}) {
|
|
35
|
+
let top = Math.max(1, Number.isInteger(ceiling) ? ceiling : 1);
|
|
36
|
+
let k = Math.min(top, Math.max(1, Number.isInteger(start) ? start : top)); // no signal yet: run at the ceiling, as before
|
|
37
|
+
let factor = "ceiling";
|
|
38
|
+
let lastRefusal = -Infinity;
|
|
39
|
+
const held = new Map(); // issue -> { at, reason }
|
|
40
|
+
const hcap = () => Math.max(1, Math.min(top, Number.isInteger(heavyCap) ? heavyCap : Math.ceil(top / 3)));
|
|
41
|
+
const ev = (change, inputs) => ({ event: "concurrency", change, k, ceiling: top, factor, inputs });
|
|
42
|
+
return {
|
|
43
|
+
setCeiling(c) { if (Number.isInteger(c) && c >= 1) { const was = top; top = c; k = k >= was ? top : Math.min(k, top); } },
|
|
44
|
+
/** The operating point under the ceiling; a heavy lane class has its own, lower cap. */
|
|
45
|
+
operating(klass = "light") { return Math.min(top, k, klass === "heavy" ? hcap() : Infinity); },
|
|
46
|
+
ceiling: () => top,
|
|
47
|
+
/** Concurrent heavy lanes allowed, separate from light lanes. */
|
|
48
|
+
heavyLimit: () => hcap(),
|
|
49
|
+
limiting(klass = "light") { return klass === "heavy" && hcap() < Math.min(top, k) ? "heavy cap" : k < top ? factor : "ceiling"; },
|
|
50
|
+
/** A launch was refused. Halves on a `pool.*` reason or load above 1.5/core. Returns the event, or null when nothing moved. */
|
|
51
|
+
refused({ issue = null, code = "", reason = "", live = null } = {}) {
|
|
52
|
+
const r = poolReason(reason) || poolReason(code);
|
|
53
|
+
const hot = fin(live?.load_per_core) && live.load_per_core > LOAD_HALVE;
|
|
54
|
+
if (issue !== null && r) held.set(issue, { at: now(), reason: r });
|
|
55
|
+
if (!r && !hot) return null;
|
|
56
|
+
const t = now();
|
|
57
|
+
if (t - lastRefusal < 1000) return null; // one storm of simultaneous refusals is one halving
|
|
58
|
+
lastRefusal = t;
|
|
59
|
+
const before = k;
|
|
60
|
+
k = Math.max(1, Math.floor(k / 2));
|
|
61
|
+
factor = r || "host_load";
|
|
62
|
+
return k === before ? null : ev("decrease", { from: before, reason: r || "load", live });
|
|
63
|
+
},
|
|
64
|
+
/** One pool sample: +1 while memory is above floor+headroom, load below 1 and nothing was refused for `holdMs`. */
|
|
65
|
+
observe(cap) {
|
|
66
|
+
if (!cap || !fin(cap.load_per_core) || !fin(cap.mem_available_gb)) return null; // unknown pool: K applies unchanged
|
|
67
|
+
if (k >= top) { factor = "ceiling"; return null; }
|
|
68
|
+
if (cap.mem_available_gb > memFloorGb + MEM_HEADROOM_GB && cap.load_per_core < LOAD_GREEN && now() - lastRefusal >= holdMs) {
|
|
69
|
+
const before = k; k += 1;
|
|
70
|
+
if (k >= top) factor = "ceiling";
|
|
71
|
+
return ev("increase", { from: before, load_per_core: cap.load_per_core, mem_available_gb: cap.mem_available_gb });
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
},
|
|
75
|
+
/** True while `issue` must not be launched: refused within holdMs and its named condition has not cleared. */
|
|
76
|
+
holding(issue, cap) {
|
|
77
|
+
const h = held.get(issue);
|
|
78
|
+
if (!h) return false;
|
|
79
|
+
if (conditionCleared(h.reason, cap, { memFloorGb }) === true || now() - h.at >= holdMs) { held.delete(issue); return false; }
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
release(issue) { held.delete(issue); },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `running/K/ceiling (limiting factor)`, with the configured ceiling as the achieved-vs-configured reference. */
|
|
87
|
+
export function formatConcurrency({ running, k, ceiling, factor = "ceiling" } = {}) {
|
|
88
|
+
return `concurrency: ${running ?? 0}/${k ?? ceiling}/${ceiling} (${factor})`;
|
|
89
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/** #5985: closed-loop lane concurrency. */
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { makeController, classifyRepo, conditionCleared, formatConcurrency, poolReason, REFUSAL_HOLD_MS } from "./concurrency.mjs";
|
|
8
|
+
|
|
9
|
+
const green = { load_per_core: 0.4, mem_available_gb: 12 };
|
|
10
|
+
const mk = (o = {}) => { const c = { t: 1_000_000 }; return { c, ctl: makeController({ ceiling: 8, now: () => c.t, ...o }) }; };
|
|
11
|
+
|
|
12
|
+
describe("controller (#5985)", () => {
|
|
13
|
+
it("halves on pool.host_load, increases +1 under a green pool, never above the ceiling or below 1", () => {
|
|
14
|
+
const { c, ctl } = mk();
|
|
15
|
+
assert.equal(ctl.operating(), 8, "no signal: K is the ceiling");
|
|
16
|
+
const e = ctl.refused({ issue: 1, code: "pool.host_load", live: { load_per_core: 2.2 } });
|
|
17
|
+
assert.equal(e.change, "decrease");
|
|
18
|
+
assert.equal(ctl.operating(), 4);
|
|
19
|
+
assert.equal(ctl.observe(green), null, "refusal in the last N minutes: no increase");
|
|
20
|
+
c.t += REFUSAL_HOLD_MS;
|
|
21
|
+
assert.equal(ctl.observe(green).change, "increase");
|
|
22
|
+
assert.equal(ctl.operating(), 5);
|
|
23
|
+
for (let i = 0; i < 10; i++) ctl.observe(green);
|
|
24
|
+
assert.equal(ctl.operating(), 8);
|
|
25
|
+
assert.equal(ctl.limiting(), "ceiling");
|
|
26
|
+
for (let i = 0; i < 6; i++) { c.t += 2000; ctl.refused({ code: "pool.host_mem" }); }
|
|
27
|
+
assert.equal(ctl.operating(), 1);
|
|
28
|
+
});
|
|
29
|
+
it("a high load alone halves; an unknown pool and a non-pool refusal leave K unchanged", () => {
|
|
30
|
+
const { ctl } = mk();
|
|
31
|
+
assert.equal(ctl.refused({ code: "sandbox.capacity" }), null);
|
|
32
|
+
assert.equal(ctl.observe(null), null);
|
|
33
|
+
assert.equal(ctl.observe({ load_per_core: 0.2 }), null);
|
|
34
|
+
assert.ok(ctl.refused({ live: { load_per_core: 1.8 } }));
|
|
35
|
+
assert.equal(ctl.operating(), 4);
|
|
36
|
+
assert.equal(ctl.limiting(), "host_load");
|
|
37
|
+
});
|
|
38
|
+
it("a red pool (low memory or load >= 1) does not increase", () => {
|
|
39
|
+
const { c, ctl } = mk();
|
|
40
|
+
ctl.refused({ code: "pool.host_load" }); c.t += REFUSAL_HOLD_MS;
|
|
41
|
+
assert.equal(ctl.observe({ load_per_core: 1.2, mem_available_gb: 12 }), null);
|
|
42
|
+
assert.equal(ctl.observe({ load_per_core: 0.3, mem_available_gb: 5 }), null);
|
|
43
|
+
});
|
|
44
|
+
it("classifies heavy repos from usage-history cpu_avg > 1.5 and caps heavy lanes below light", () => {
|
|
45
|
+
const rows = [{ repo: "a/h", cpu_avg: 3 }, { repo: "a/h", cpu_avg: 2 }, { repo: "a/l", cpu_avg: 0.4 }];
|
|
46
|
+
assert.equal(classifyRepo(rows, "a/h"), "heavy");
|
|
47
|
+
assert.equal(classifyRepo(rows, "a/l"), "light");
|
|
48
|
+
assert.equal(classifyRepo(rows, "a/none"), "light", "no history: light");
|
|
49
|
+
const { ctl } = mk({ ceiling: 16 });
|
|
50
|
+
assert.equal(ctl.operating("light"), 16);
|
|
51
|
+
assert.equal(ctl.operating("heavy"), 6);
|
|
52
|
+
assert.equal(ctl.limiting("heavy"), "heavy cap");
|
|
53
|
+
});
|
|
54
|
+
it("names the cleared condition and formats running/K/ceiling (limiting factor)", () => {
|
|
55
|
+
assert.equal(conditionCleared("pool.host_load", { load_per_core: 1.2 }), false);
|
|
56
|
+
assert.equal(conditionCleared("host_load", { load_per_core: 0.9 }), true);
|
|
57
|
+
assert.equal(conditionCleared("pool.host_mem", { mem_available_gb: 9 }), true);
|
|
58
|
+
assert.equal(conditionCleared("pool.host_mem", {}), null);
|
|
59
|
+
assert.equal(conditionCleared("pool.projected_peak", green), null);
|
|
60
|
+
assert.equal(poolReason("pool.disk_cap"), "disk");
|
|
61
|
+
assert.equal(poolReason("sandbox.capacity"), "");
|
|
62
|
+
assert.equal(formatConcurrency({ running: 3, k: 4, ceiling: 8, factor: "host_load" }), "concurrency: 3/4/8 (host_load)");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("503-storm replay (#5985)", () => {
|
|
67
|
+
it("at most 1 refusal per lane per 5 min: refused lanes hold until the condition clears", () => {
|
|
68
|
+
const fx = JSON.parse(readFileSync(new URL("./fixtures/capacity-storm.json", import.meta.url), "utf8"));
|
|
69
|
+
const c = { t: 0 };
|
|
70
|
+
const ctl = makeController({ ceiling: fx.lanes, now: () => c.t });
|
|
71
|
+
const byLane = new Map();
|
|
72
|
+
for (const a of fx.attempts) (byLane.get(a.lane) ?? byLane.set(a.lane, []).get(a.lane)).push(a);
|
|
73
|
+
const refusals = new Map();
|
|
74
|
+
for (c.t = 0; c.t <= fx.endMs; c.t += fx.pollMs) {
|
|
75
|
+
const cap = c.t < fx.clearsAtMs ? { load_per_core: 2.1, mem_available_gb: 1.2 } : { load_per_core: 0.6, mem_available_gb: 9 };
|
|
76
|
+
ctl.observe(cap);
|
|
77
|
+
for (const [lane, rows] of byLane) {
|
|
78
|
+
if (ctl.holding(lane, cap)) continue;
|
|
79
|
+
const storm = c.t < fx.clearsAtMs;
|
|
80
|
+
if (!storm) { ctl.release(lane); continue; }
|
|
81
|
+
const rec = rows.reduce((b, r) => (Math.abs(r.at - c.t) < Math.abs(b.at - c.t) ? r : b)); // the recorded refusal code nearest this attempt
|
|
82
|
+
ctl.refused({ issue: lane, code: rec.code, live: cap });
|
|
83
|
+
(refusals.get(lane) ?? refusals.set(lane, []).get(lane)).push(c.t);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
assert.ok(refusals.size === fx.lanes);
|
|
87
|
+
for (const [lane, ts] of refusals) for (let i = 0; i < ts.length; i++) {
|
|
88
|
+
const inWin = ts.filter((x) => x >= ts[i] && x < ts[i] + 300_000).length;
|
|
89
|
+
assert.ok(inWin <= 1, `lane ${lane}: ${inWin} refusals within 5 min`);
|
|
90
|
+
}
|
|
91
|
+
const unreplayed = fx.attempts.length; // the unconstrained timer retry would have refused each lane every minute
|
|
92
|
+
assert.ok([...refusals.values()].flat().length < unreplayed / 3);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("heavy lanes in orchestrate (#5985)", () => {
|
|
97
|
+
it("a heavy repo's lanes run at most the heavy cap at once while light lanes keep the rest of K", async () => {
|
|
98
|
+
const { orchestrate } = await import("./orchestrate.mjs");
|
|
99
|
+
const usageRows = [{ repo: "o/heavy", cpu_avg: 3 }, { repo: "o/light", cpu_avg: 0.3 }];
|
|
100
|
+
const run = async (repo) => {
|
|
101
|
+
let cur = 0, max = 0;
|
|
102
|
+
const events = [];
|
|
103
|
+
await orchestrate({ issues: [1, 2, 3, 4, 5, 6], parallel: 6, usageRows: () => usageRows, repoSlug: "o/none", repoOf: () => repo, readBody: async () => "", onUpdate: (e) => events.push(e),
|
|
104
|
+
sleep: async () => { await new Promise((r) => setImmediate(r)); },
|
|
105
|
+
runOne: async () => { cur++; max = Math.max(max, cur); await new Promise((r) => setTimeout(r, 20)); cur--; return { terminalReason: "merged", pr: 1 }; } });
|
|
106
|
+
return { max, events };
|
|
107
|
+
};
|
|
108
|
+
const heavy = await run("o/heavy"), light = await run("o/light");
|
|
109
|
+
assert.equal(heavy.max, 2, "ceiling 6, heavy cap ceil(6/3)");
|
|
110
|
+
assert.equal(light.max, 6);
|
|
111
|
+
assert.ok(heavy.events.some((e) => e.event === "concurrency" && e.change === "heavy-cap"));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -166,6 +166,9 @@ function oracle(c, quotes = Q) {
|
|
|
166
166
|
const bad = rv.issue_coverage.some((x) => x.status !== "covered") || rows.some((r) => ["missing", "partial"].includes(r.status)) || rv.scope.some((s) => s.authorized_by === "none") || billing;
|
|
167
167
|
return "```json\n" + JSON.stringify({ ...rv, verdict: bad ? "NONCONFORMING" : "CONFORMS", summary: "oracle" }) + "\n```";
|
|
168
168
|
}
|
|
169
|
+
// #6083: these gates are advisory by default; the tests of their blocking path re-promote them with engine.conformance_kinds enforce
|
|
170
|
+
const ENFORCED = Object.fromEntries(["conformance.unimplemented", "conformance.untracked_deferral", "conformance.preserve_violated"].map((c) => [c, "enforce"]));
|
|
171
|
+
const runCaseEnf = (cs, conformance = "enforce", extra = {}) => runCase(cs, conformance, { ...extra, opts: { ...(extra.opts ?? {}), conformanceKinds: ENFORCED } });
|
|
169
172
|
const generic = () => "```json\n" + JSON.stringify({ verdict: "PASS", fixes_issue: true, regression: false, reason: "looks good" }) + "\n```";
|
|
170
173
|
|
|
171
174
|
async function runCase(cs, conformance = "enforce", extra = {}) {
|
|
@@ -204,17 +207,19 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
|
|
|
204
207
|
res.amendments = [{ kind: "add-requirement", requirement: req("R3"), why: "the issue's requirement 3 was missing" }, { kind: "add-deliverable", id: "D3", path: "src/routes/export.js", why: "implements R3" }]; } });
|
|
205
208
|
merged(o); assert.ok(o.staging.export); assert.ok(o.markers.includes("FORGE:AMENDMENT"));
|
|
206
209
|
});
|
|
207
|
-
it("3 scope creep: an unauthorized billing change is
|
|
208
|
-
const o = await
|
|
210
|
+
it("3 scope creep: an unauthorized billing change is caught by the review's preserve check and reverted before it can reach staging", async () => {
|
|
211
|
+
const o = await runCaseEnf({ contract: FULL, impl: (t) => { fix(t, ["scrape", "search", "export"]); t.write({ "src/billing.js": "export function price(units) { return Math.round(units) * 0.01; }\n" }); },
|
|
209
212
|
resume: (t) => t.restore("src/billing.js") });
|
|
210
|
-
|
|
213
|
+
// unclog: file scope alone is advisory (no precheck stop); the violated preserve row (P1) blocks and the resume reverts it
|
|
214
|
+
merged(o); assert.equal(o.staging.billingChanged, false); assert.deepEqual([o.counts.builder, o.counts.reviewer], [3, 2]);
|
|
215
|
+
assert.ok(o.log.some((e) => e.event === "ADVISORY" && e.rows.includes("scope_creep")), "scope creep is recorded as advisory");
|
|
211
216
|
});
|
|
212
217
|
it("4 a claimed follow-up without a tracking issue blocks merge before any review", async () => {
|
|
213
|
-
const o = await
|
|
218
|
+
const o = await runCaseEnf({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred", note: "follow-up" } : r)) });
|
|
214
219
|
blocked(o, "conformance.untracked_deferral"); assert.equal(o.counts.reviewer, 0); assert.equal(o.followups.length, 0);
|
|
215
220
|
});
|
|
216
221
|
it("4b the deferral made typed on the resume is tracked, linked, and the issue closes", async () => {
|
|
217
|
-
const o = await
|
|
222
|
+
const o = await runCaseEnf({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred" } : r)),
|
|
218
223
|
resume: (t, res) => { res.amendments = [{ kind: "defer", requirement: "R3", why: "export ships on its own release train" }]; } });
|
|
219
224
|
merged(o); assert.equal(o.followups.length, 1); assert.equal(o.followups[0].state, "OPEN");
|
|
220
225
|
assert.match(o.pr.body, new RegExp(`Remaining work tracked\\n- #${o.followups[0].number}`)); assert.ok(o.markers.includes("FORGE:TRACKED"));
|
|
@@ -264,14 +269,14 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
|
|
|
264
269
|
it("#5087 a declared topology.route_reachability that rejects the new route blocks before merge (#38241 fixture)", async () => {
|
|
265
270
|
const ingress = path.join(tmpDir("ingress-"), "check-ingress.sh");
|
|
266
271
|
fs.writeFileSync(ingress, "for p in \"$@\"; do case \"$p\" in /api/v1/batch*) ;; /api/v1/*) echo \"unreachable: $p -> api\" >&2; exit 1 ;; esac; done\n");
|
|
267
|
-
const o = await
|
|
272
|
+
const o = await runCaseEnf({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { routeReachability: `bash ${ingress.replace(/\\/g, "/")}`, verify: { maxRounds: 0 } } });
|
|
268
273
|
assert.equal(o.staging.search, false, "staging untouched");
|
|
269
274
|
assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR");
|
|
270
275
|
assert.ok(o.log.some((e) => e.event === "PRECHECK" && e.failures.includes("conformance.unimplemented")));
|
|
271
276
|
assert.match(o.ret.detail, /topology\.route_reachability[\s\S]*\/api\/v1\/agent\/signup\/pending[\s\S]*unreachable: \/api\/v1\/agent\/signup\/pending -> api/);
|
|
272
277
|
});
|
|
273
278
|
it("#5284 a declared topology.prod_parity surface touched without a check result or justification blocks before merge", async () => {
|
|
274
|
-
const o = await
|
|
279
|
+
const o = await runCaseEnf({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { prodParity: { "web/src/app/**": "note: exercise the page under the production runtime" }, verify: { maxRounds: 0 } } });
|
|
275
280
|
assert.equal(o.staging.search, false, "staging untouched");
|
|
276
281
|
assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR");
|
|
277
282
|
assert.ok(o.log.some((e) => e.event === "PRECHECK" && e.failures.includes("conformance.unimplemented")));
|
|
@@ -297,7 +302,7 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
|
|
|
297
302
|
assert.ok(review.includes("**Issue coverage:** 2/2 "), "the guidance row is not counted as an issue requirement");
|
|
298
303
|
});
|
|
299
304
|
it("#5750 a lane following the prescription but missing the outcome fails", async () => {
|
|
300
|
-
const o = await
|
|
305
|
+
const o = await runCaseEnf({ issue: GISSUE, quotes: GQ, contract: GUIDED, impl: (t) => t.write({ "src/routes/scrape.js": prescribed, "test/leak.test.js": leakTest([]) }) });
|
|
301
306
|
assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR"); assert.equal(o.issue.state, "OPEN");
|
|
302
307
|
assert.equal(o.ret.code, "conformance.unimplemented");
|
|
303
308
|
});
|