forgedock 1.51.0 → 1.53.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.
Files changed (103) hide show
  1. package/bin/engine/outcome-codes.mjs +3 -0
  2. package/bin/engine/telemetry-seam.mjs +4 -2
  3. package/bin/engine-cli.mjs +61 -17
  4. package/bin/experiment.mjs +58 -6
  5. package/bin/forge-utils.mjs +6 -2
  6. package/bin/forgedock.mjs +25 -1
  7. package/bin/lean/account-watch.mjs +28 -0
  8. package/bin/lean/account-watch.test.mjs +30 -0
  9. package/bin/lean/activation.mjs +20 -0
  10. package/bin/lean/activation.test.mjs +14 -1
  11. package/bin/lean/basered.mjs +115 -0
  12. package/bin/lean/basered.test.mjs +66 -0
  13. package/bin/lean/batch-health.mjs +40 -6
  14. package/bin/lean/batch-health.test.mjs +34 -1
  15. package/bin/lean/batch.mjs +41 -2
  16. package/bin/lean/batch.test.mjs +104 -2
  17. package/bin/lean/checkpoint-reconcile.mjs +43 -0
  18. package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
  19. package/bin/lean/conformance.e2e.test.mjs +1 -1
  20. package/bin/lean/conformance.mjs +205 -23
  21. package/bin/lean/conformance.test.mjs +164 -3
  22. package/bin/lean/context.mjs +27 -17
  23. package/bin/lean/context.test.mjs +15 -0
  24. package/bin/lean/effects.mjs +11 -7
  25. package/bin/lean/execution.mjs +19 -3
  26. package/bin/lean/execution.test.mjs +39 -0
  27. package/bin/lean/findinglabel.mjs +16 -0
  28. package/bin/lean/findinglabel.test.mjs +39 -0
  29. package/bin/lean/heavy.mjs +6 -3
  30. package/bin/lean/hostload.mjs +78 -0
  31. package/bin/lean/hostload.test.mjs +117 -0
  32. package/bin/lean/hotspots-remote.e2e.test.mjs +71 -0
  33. package/bin/lean/issuewatch-release.mjs +6 -2
  34. package/bin/lean/issuewatch-release.test.mjs +16 -0
  35. package/bin/lean/issuewatch.mjs +11 -1
  36. package/bin/lean/lanelock.mjs +14 -0
  37. package/bin/lean/lean.mjs +171 -36
  38. package/bin/lean/lean.test.mjs +302 -10
  39. package/bin/lean/light.mjs +48 -7
  40. package/bin/lean/light.test.mjs +37 -3
  41. package/bin/lean/limits.test.mjs +142 -9
  42. package/bin/lean/orchestrate-cancel.test.mjs +143 -0
  43. package/bin/lean/orchestrate.mjs +110 -26
  44. package/bin/lean/postdeploy-check.test.mjs +39 -0
  45. package/bin/lean/prompts.mjs +8 -7
  46. package/bin/lean/quota.mjs +39 -0
  47. package/bin/lean/recovery.test.mjs +10 -0
  48. package/bin/lean/relaxation.mjs +73 -0
  49. package/bin/lean/relaxation.test.mjs +54 -0
  50. package/bin/lean/release-postmerge.mjs +119 -0
  51. package/bin/lean/release-rehearsal.mjs +63 -0
  52. package/bin/lean/release-rehearsal.test.mjs +93 -0
  53. package/bin/lean/release-review.e2e.test.mjs +77 -0
  54. package/bin/lean/release-review.mjs +198 -0
  55. package/bin/lean/release-review.test.mjs +180 -0
  56. package/bin/lean/release.mjs +228 -0
  57. package/bin/lean/release.test.mjs +292 -0
  58. package/bin/lean/rotator.mjs +150 -31
  59. package/bin/lean/rotator.test.mjs +105 -2
  60. package/bin/lean/sandbox-remote.mjs +9 -2
  61. package/bin/lean/schedd.mjs +56 -6
  62. package/bin/lean/schedd.test.mjs +108 -6
  63. package/bin/lean/verifier.mjs +3 -2
  64. package/bin/lean/verify.mjs +2 -1
  65. package/bin/lean/verify.test.mjs +6 -0
  66. package/bin/pool/agent.mjs +18 -4
  67. package/bin/pool/router.mjs +68 -25
  68. package/bin/review-staging.mjs +23 -0
  69. package/bin/stats/conformance-outcomes.mjs +208 -0
  70. package/bin/stats/conformance-outcomes.test.mjs +188 -0
  71. package/bin/stats/depth.mjs +218 -0
  72. package/bin/stats/depth.test.mjs +133 -0
  73. package/bin/stats/experiment.mjs +7 -5
  74. package/bin/stats/github-source.mjs +2 -2
  75. package/bin/stats/index.mjs +64 -2
  76. package/bin/stats/local-source.mjs +11 -0
  77. package/bin/stats/query.mjs +69 -0
  78. package/bin/stats/selffiled.mjs +52 -0
  79. package/bin/stats/selffiled.test.mjs +71 -0
  80. package/commands/orchestrate.md +1 -1
  81. package/commands/review-pr-agents/security.md +4 -0
  82. package/commands/review-pr-staging.md +2 -0
  83. package/commands/work-on/build.md +4 -6
  84. package/docs/CONFIG.md +66 -8
  85. package/docs/ISSUE-WATCH.md +2 -0
  86. package/docs/OUTCOME-CODES.md +3 -0
  87. package/docs/STATS.md +44 -0
  88. package/docs/TELEMETRY.md +1 -1
  89. package/package.json +1 -1
  90. package/pool/README.md +1 -1
  91. package/pool/image/cs-cred +14 -1
  92. package/pool/install/install-agent.ps1 +6 -2
  93. package/scripts/backfill-finding-labels.mjs +50 -0
  94. package/scripts/backfill-finding-labels.test.mjs +36 -0
  95. package/scripts/doctor-pipeline-state.sh +21 -6
  96. package/scripts/file-deferred-followups.sh +60 -238
  97. package/scripts/file-deferred-followups.test.sh +99 -187
  98. package/scripts/followup-route.mjs +12 -0
  99. package/scripts/hotspots.sh +12 -8
  100. package/scripts/hotspots.test.sh +22 -0
  101. package/scripts/owner-route-parity.test.sh +17 -1
  102. package/scripts/prior-attempts.test.mjs +1 -1
  103. package/scripts/review-pr-side-effects.test.sh +40 -0
@@ -0,0 +1,78 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * Host overload signal (#5174). Remote lanes already run every heavy step inside their sandbox (sandbox-remote.mjs runs
5
+ * `forgedock run-issue` there). What loads a small dispatcher are the lanes that run on it: local placements and fallbacks.
6
+ * - `hostOverload` is the snapshot: overloaded when the 1-min load average divided by cores is above
7
+ * `engine.overload_load_per_core` (default 2; 0 disables; env FORGEDOCK_OVERLOAD_LOAD_PER_CORE overrides). An unreadable probe never counts as overloaded.
8
+ * - orchestrate `grant()` holds new local admissions while it is overloaded (remote placements are never held).
9
+ * - `forgedock status` and `forgedock schedd status` print `formatOverload`.
10
+ * - `lowerPriority` runs a local heavy step at nice 10 (plus `ionice -c3` on Linux when available), so test runners and
11
+ * installs do not starve the schedd event loop. Best effort, never throws.
12
+ */
13
+ import { spawn } from "node:child_process";
14
+ import { cpus, loadavg, setPriority as osSetPriority } from "node:os";
15
+ import { which } from "./toolchain.mjs";
16
+
17
+ export const OVERLOAD_DEFAULTS = Object.freeze({ load_per_core: 2 });
18
+ export const HEAVY_NICE = 10;
19
+
20
+ /** Threshold (load per core) from cfg.overload_load_per_core: > 0 sets it, 0 disables (null), unset or invalid is the default. */
21
+ export function overloadThreshold(cfg = {}) {
22
+ const v = cfg?.overload_load_per_core;
23
+ if (v === undefined || v === null || String(v).trim() === "") return OVERLOAD_DEFAULTS.load_per_core;
24
+ const n = Number(v);
25
+ if (!Number.isFinite(n) || n < 0) return OVERLOAD_DEFAULTS.load_per_core;
26
+ return n === 0 ? null : n;
27
+ }
28
+
29
+ /** Snapshot {overloaded, load1, cores, perCore, threshold}; threshold null (disabled) or an unreadable probe is never overloaded. */
30
+ export function hostOverload({ threshold = OVERLOAD_DEFAULTS.load_per_core, host = { loadAvg1: () => loadavg()[0], cores: () => cpus().length || 1 } } = {}) {
31
+ const probe = (f) => { try { const v = f?.(); return Number.isFinite(v) ? v : null; } catch { return null; } };
32
+ const load1 = probe(host?.loadAvg1), cores = probe(host?.cores);
33
+ const perCore = load1 !== null && cores ? load1 / cores : null;
34
+ const t = Number.isFinite(threshold) && threshold > 0 ? threshold : null;
35
+ return { overloaded: perCore !== null && t !== null && perCore > t, load1, cores, perCore, threshold: t };
36
+ }
37
+
38
+ /**
39
+ * A `() => snapshot` probe with the threshold read from an admission cfg (engine-cli `readAdmission`). The env
40
+ * `FORGEDOCK_OVERLOAD_LOAD_PER_CORE` (same values; 0 disables) overrides forge.yaml host-wide; the test helper sets it to 0.
41
+ */
42
+ export function liveOverload(cfg = {}, { host, env = process.env } = {}) {
43
+ const e = env?.FORGEDOCK_OVERLOAD_LOAD_PER_CORE;
44
+ const threshold = overloadThreshold(e !== undefined && String(e).trim() !== "" ? { overload_load_per_core: e } : cfg);
45
+ return () => hostOverload({ threshold, ...(host ? { host } : {}) });
46
+ }
47
+
48
+ /** `host_overloaded (load X.X/core > T): new local admissions held`, or null when not overloaded. */
49
+ export function formatOverload(snap) {
50
+ if (!snap?.overloaded) return null;
51
+ return `host_overloaded (load ${Number(snap.perCore).toFixed(1)}/core > ${snap.threshold}): new local admissions held`;
52
+ }
53
+
54
+ /** One-line host summary: the overload line, else `load X.X/core (threshold T)`, else null when load is unknown. */
55
+ export function formatHostLoad(snap) {
56
+ const o = formatOverload(snap);
57
+ if (o) return o;
58
+ if (!Number.isFinite(snap?.perCore)) return null;
59
+ return `load ${snap.perCore.toFixed(1)}/core${snap.threshold ? ` (threshold ${snap.threshold})` : " (overload hold off)"}`;
60
+ }
61
+
62
+ /** Default `spawnIonice`: `ionice -c3 -p <pid>` detached and unref'd when ionice is on PATH; returns whether it was started. */
63
+ export function spawnIoniceIdle(pid, { find = (n) => which(n, process.env.PATH ?? ""), run = spawn } = {}) {
64
+ const ionice = find("ionice");
65
+ if (!ionice) return false;
66
+ const c = run(ionice, ["-c3", "-p", String(pid)], { stdio: "ignore", detached: true, windowsHide: true });
67
+ c?.on?.("error", () => {}); c?.unref?.();
68
+ return true;
69
+ }
70
+
71
+ /** Lower a heavy step's CPU (nice 10) and, on Linux, IO (ionice idle class) priority; returns whether nice was applied. Never throws. */
72
+ export function lowerPriority(pid, { setPriority = osSetPriority, spawnIonice = spawnIoniceIdle, platform = process.platform, level = HEAVY_NICE } = {}) {
73
+ if (!Number.isInteger(pid) || pid <= 0) return false;
74
+ let ok = false;
75
+ try { setPriority(pid, level); ok = true; } catch { ok = false; }
76
+ if (platform === "linux") { try { spawnIonice(pid); } catch { /* best effort */ } }
77
+ return ok;
78
+ }
@@ -0,0 +1,117 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5174: host overload hold (orchestrate grant), status host line, heavy-step niceness.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { getPriority } from "node:os";
7
+ import { OVERLOAD_DEFAULTS, HEAVY_NICE, overloadThreshold, hostOverload, liveOverload, formatOverload, formatHostLoad, lowerPriority, spawnIoniceIdle } from "./hostload.mjs";
8
+ import { orchestrate } from "./orchestrate.mjs";
9
+ import { spawnInherit, runWrapped } from "./heavy.mjs";
10
+
11
+ const host = (load1, cores) => ({ loadAvg1: () => load1, cores: () => cores });
12
+ const sleep = (ms) => new Promise((r) => setTimeout(r, Math.min(ms ?? 1, 5)));
13
+
14
+ describe("#5174 hostload", () => {
15
+ it("overloadThreshold: default 2, > 0 sets, 0 disables, invalid is the default", () => {
16
+ assert.equal(OVERLOAD_DEFAULTS.load_per_core, 2);
17
+ assert.equal(overloadThreshold({}), 2);
18
+ assert.equal(overloadThreshold(), 2);
19
+ assert.equal(overloadThreshold({ overload_load_per_core: 3.5 }), 3.5);
20
+ assert.equal(overloadThreshold({ overload_load_per_core: 0 }), null);
21
+ assert.equal(overloadThreshold({ overload_load_per_core: -1 }), 2);
22
+ assert.equal(overloadThreshold({ overload_load_per_core: "x" }), 2);
23
+ });
24
+
25
+ it("hostOverload: overloaded only when load1/cores > threshold; unreadable probes and a disabled threshold never are", () => {
26
+ assert.deepEqual(hostOverload({ threshold: 2, host: host(18, 4) }), { overloaded: true, load1: 18, cores: 4, perCore: 4.5, threshold: 2 });
27
+ assert.equal(hostOverload({ threshold: 2, host: host(8, 4) }).overloaded, false, "exactly at the threshold is not over it");
28
+ assert.equal(hostOverload({ threshold: 2, host: host(4, 4) }).overloaded, false);
29
+ assert.equal(hostOverload({ threshold: null, host: host(18, 4) }).overloaded, false);
30
+ assert.equal(hostOverload({ threshold: 2, host: { loadAvg1: () => { throw new Error("no /proc"); }, cores: () => 4 } }).overloaded, false);
31
+ assert.equal(hostOverload({ threshold: 2, host: host(NaN, 4) }).overloaded, false);
32
+ assert.equal(hostOverload({ threshold: 2, host: host(18, 0) }).overloaded, false);
33
+ assert.equal(liveOverload({ overload_load_per_core: 1 }, { host: host(18, 4), env: {} })().overloaded, true);
34
+ assert.equal(liveOverload({ overload_load_per_core: 0 }, { host: host(18, 4), env: {} })().overloaded, false);
35
+ assert.equal(liveOverload({ overload_load_per_core: 1 }, { host: host(18, 4), env: { FORGEDOCK_OVERLOAD_LOAD_PER_CORE: "0" } })().overloaded, false, "env 0 disables");
36
+ assert.equal(liveOverload({}, { host: host(6, 4), env: { FORGEDOCK_OVERLOAD_LOAD_PER_CORE: "1" } })().threshold, 1, "env overrides forge.yaml");
37
+ assert.equal(liveOverload({}, { host: host(6, 4), env: {} })().threshold, 2);
38
+ const live = liveOverload({})();
39
+ assert.equal(typeof live.overloaded, "boolean");
40
+ });
41
+
42
+ it("formatOverload / formatHostLoad render the status lines", () => {
43
+ const over = hostOverload({ threshold: 2, host: host(18, 4) });
44
+ assert.equal(formatOverload(over), "host_overloaded (load 4.5/core > 2): new local admissions held");
45
+ assert.equal(formatHostLoad(over), "host_overloaded (load 4.5/core > 2): new local admissions held");
46
+ const ok = hostOverload({ threshold: 2, host: host(2, 4) });
47
+ assert.equal(formatOverload(ok), null);
48
+ assert.equal(formatHostLoad(ok), "load 0.5/core (threshold 2)");
49
+ assert.equal(formatHostLoad(hostOverload({ threshold: null, host: host(2, 4) })), "load 0.5/core (overload hold off)");
50
+ assert.equal(formatHostLoad(null), null);
51
+ assert.equal(formatOverload(undefined), null);
52
+ });
53
+
54
+ it("lowerPriority: nice 10, ionice idle on Linux only, never throws", () => {
55
+ const calls = [];
56
+ assert.equal(lowerPriority(123, { setPriority: (p, l) => calls.push(["nice", p, l]), spawnIonice: (p) => calls.push(["ionice", p]), platform: "linux" }), true);
57
+ assert.deepEqual(calls, [["nice", 123, HEAVY_NICE], ["ionice", 123]]);
58
+ calls.length = 0;
59
+ assert.equal(lowerPriority(123, { setPriority: (p, l) => calls.push(["nice", p, l]), spawnIonice: (p) => calls.push(["ionice", p]), platform: "darwin" }), true);
60
+ assert.deepEqual(calls, [["nice", 123, 10]]);
61
+ assert.equal(lowerPriority(123, { setPriority: () => { throw new Error("EPERM"); }, spawnIonice: () => { throw new Error("x"); }, platform: "linux" }), false);
62
+ assert.equal(lowerPriority(0), false);
63
+ assert.equal(lowerPriority(undefined), false);
64
+ const spawned = [];
65
+ assert.equal(spawnIoniceIdle(42, { find: () => "/usr/bin/ionice", run: (c, a, o) => { spawned.push([c, a, o.detached, o.windowsHide]); return { on() {}, unref() {} }; } }), true);
66
+ assert.deepEqual(spawned, [["/usr/bin/ionice", ["-c3", "-p", "42"], true, true]]);
67
+ assert.equal(spawnIoniceIdle(42, { find: () => null, run: () => assert.fail("no ionice") }), false);
68
+ });
69
+
70
+ it("spawnInherit runs onSpawn with the child; a real heavy child ends up at nice 10 and its exit code propagates", async () => {
71
+ let pid = null, nice = null;
72
+ const r = await spawnInherit(process.execPath, ["-e", "setTimeout(() => process.exit(4), 300)"], process.env, (c) => {
73
+ pid = c.pid; lowerPriority(c.pid); try { nice = getPriority(c.pid); } catch { nice = null; }
74
+ });
75
+ assert.deepEqual(r, { code: 4, signal: null });
76
+ assert.ok(Number.isInteger(pid));
77
+ assert.equal(nice, Math.max(HEAVY_NICE, getPriority()), "the heavy child runs at nice 10 (or the parent's, if already lower)");
78
+ });
79
+
80
+ it("runWrapped passes the priority hook on the gated path only (llm and nested steps pass through)", async () => {
81
+ const seen = [];
82
+ const run = async (cmd, args, env, onSpawn) => { seen.push(typeof onSpawn); return { code: 0, signal: null }; };
83
+ const open = () => ({ stats: () => ({ holders: 0 }) });
84
+ const host2 = { memAvailableMb: () => 64000, cores: () => 8 };
85
+ await runWrapped(["run", "--name", "x", "--", "/r/x"], { env: { FORGE_HEAVY_HELD: "1" }, run, host: host2, open });
86
+ await runWrapped(["run", "--name", "claude", "--", "/r/claude"], { env: { FORGE_HEAVY_DISABLED: "1" }, run, host: host2, open });
87
+ assert.deepEqual(seen, ["undefined", "undefined"]);
88
+ });
89
+
90
+ it("orchestrate holds new local admissions while overloaded, one host-overloaded row per episode, then admits", async () => {
91
+ let over = true, probes = 0;
92
+ const snap = () => { probes++; return hostOverload({ threshold: 2, host: host(over ? 18 : 2, 4) }); };
93
+ const rows = [], started = [];
94
+ const runOne = async (n) => { started.push(n); return { terminalReason: "merged", pr: n }; };
95
+ const done = orchestrate({ issues: [1, 2], parallel: 2, runOne, readBody: async () => "", overload: snap, onUpdate: (r) => rows.push(r), pollMs: 1, sleep });
96
+ for (let i = 0; i < 200 && probes < 5; i++) await new Promise((r) => setTimeout(r, 5));
97
+ assert.deepEqual(started, [], "nothing admitted while overloaded");
98
+ over = false;
99
+ const out = await done;
100
+ assert.deepEqual(out.map((r) => r.outcome).sort(), ["merged", "merged"]);
101
+ const held = rows.filter((r) => r.outcome === "host-overloaded");
102
+ assert.equal(held.length, 1, "one row per episode");
103
+ assert.equal(held[0].detail, "host_overloaded (load 4.5/core > 2): new local admissions held");
104
+ });
105
+
106
+ it("a throwing probe is not overloaded; remote placements are never held", async () => {
107
+ const started = [];
108
+ const runOne = async (n) => { started.push(n); return { terminalReason: "merged", pr: n }; };
109
+ await orchestrate({ issues: [1], parallel: 1, runOne, readBody: async () => "", overload: () => { throw new Error("x"); }, pollMs: 1, sleep });
110
+ assert.deepEqual(started, [1]);
111
+ let probes = 0;
112
+ const out = await orchestrate({ issues: [2], parallel: 1, runOne, readBody: async () => "", pollMs: 1, sleep,
113
+ overload: () => { probes++; return { overloaded: true }; }, remote: { max: 1, isRemote: () => true } });
114
+ assert.deepEqual(out.map((r) => r.outcome), ["merged"]);
115
+ assert.equal(probes, 0, "the remote placement never consults the overload gate");
116
+ });
117
+ });
@@ -0,0 +1,71 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // Remote lanes use the batch-pinned config for hotspot facts (#5193, deferred from #5163). No mocks: the pinned forge.yaml is
4
+ // materialised by the real pool/image/entrypoint.sh snippet, then the real io.hotspots runs the real scripts/hotspots.sh in a
5
+ // real git repo. Skipped when yq (which hotspots.sh needs to read forge.yaml) or jq is missing.
6
+ import { describe, it } from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { execFileSync } from "node:child_process";
9
+ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { tmpDir } from "../tests/_tmp.mjs";
13
+ import { makeLeanIo } from "./effects.mjs";
14
+
15
+ const has = (bin) => { try { execFileSync(bin, ["--version"], { stdio: "ignore", timeout: 10000 }); return true; } catch { return false; } };
16
+ const skip = !has("yq") ? "yq unavailable" : !has("jq") ? "jq unavailable" : false;
17
+ const ENTRYPOINT = fileURLToPath(new URL("../../pool/image/entrypoint.sh", import.meta.url));
18
+ const PINNED = "maintenance:\n hotspot:\n exclude_globs:\n - \"web/public/openapi.json\"\n generated_paths:\n - \"gen/*.json\"\n";
19
+
20
+ const git = (cwd, ...a) => execFileSync("git", ["-c", "user.email=t@example.com", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { cwd, stdio: "pipe" }).toString();
21
+ const lines = (n) => Array.from({ length: n }, (_, i) => `l${i}`).join("\n") + "\n";
22
+
23
+ /** the real entrypoint block that writes the batch-pinned config into the lane checkout (pool/image/entrypoint.sh) */
24
+ function pinnedBlock() {
25
+ const m = readFileSync(ENTRYPOINT, "utf8").match(/if \[ -n "\$\{CS_FORGE_YAML_B64:-\}" \]; then\n[\s\S]*?\nfi\n/);
26
+ assert.ok(m, "entrypoint.sh no longer writes CS_FORGE_YAML_B64 to forge.yaml");
27
+ return m[0];
28
+ }
29
+
30
+ function lane(root) {
31
+ mkdirSync(join(root, "web/public"), { recursive: true });
32
+ mkdirSync(join(root, "gen"), { recursive: true });
33
+ git(root, "init", "-q", "-b", "main");
34
+ writeFileSync(join(root, "web/public/openapi.json"), lines(2100));
35
+ writeFileSync(join(root, "gen/api.json"), lines(2100));
36
+ writeFileSync(join(root, ".gitignore"), "forge.yaml\n"); // the supported layout: forge.yaml is untracked
37
+ git(root, "add", "-A"); git(root, "commit", "-qm", "base");
38
+ git(root, "checkout", "-qb", "lane");
39
+ writeFileSync(join(root, "web/public/openapi.json"), lines(2446));
40
+ writeFileSync(join(root, "gen/api.json"), lines(2446));
41
+ git(root, "add", "-A"); git(root, "commit", "-qm", "grow");
42
+ }
43
+
44
+ describe("remote lane hotspot facts use the pinned config (#5193)", { skip }, () => {
45
+ const io = makeLeanIo({ repo: "o/r" });
46
+ const paths = ["web/public/openapi.json", "gen/api.json"];
47
+
48
+ it("honours exclude_globs and generated_paths from the pinned forge.yaml the entrypoint writes", async () => {
49
+ const root = tmpDir("hotspots-remote-");
50
+ lane(root);
51
+ execFileSync("bash", ["-c", pinnedBlock()], { cwd: root, env: { ...process.env, CS_FORGE_YAML_B64: Buffer.from(PINNED).toString("base64") } });
52
+ assert.equal(readFileSync(join(root, "forge.yaml"), "utf8"), PINNED);
53
+ const h = await io.hotspots({ cwd: root, base: "main", paths });
54
+ assert.ok(h, "io.hotspots returned null");
55
+ assert.deepEqual(h.generated_paths, ["gen/*.json"]);
56
+ const by = Object.fromEntries(h.files.map((f) => [f.path, f]));
57
+ assert.equal(by["web/public/openapi.json"].growth, 346);
58
+ assert.equal(by["web/public/openapi.json"].excluded, true);
59
+ assert.equal(by["gen/api.json"].generated, true);
60
+ assert.equal(by["gen/api.json"].excluded, true);
61
+ });
62
+
63
+ it("control: without the pinned config the same files are not excluded (the defect this guards)", async () => {
64
+ const root = tmpDir("hotspots-remote-ctl-");
65
+ lane(root);
66
+ const h = await io.hotspots({ cwd: root, base: "main", paths });
67
+ const by = Object.fromEntries(h.files.map((f) => [f.path, f]));
68
+ assert.equal(by["web/public/openapi.json"].excluded, false);
69
+ assert.equal(by["gen/api.json"].excluded, false);
70
+ });
71
+ });
@@ -176,7 +176,7 @@ export function releasePlanComment({ theme, tag, decision, policy, now }) {
176
176
  `**Included:** ${r.set.map((i) => `#${i.number}`).join(" ")}`,
177
177
  ...(r.pulled.length ? [`**Pulled prerequisites:** ${r.pulled.map((p) => `#${p.number} (${p.theme}, for #${p.for})`).join(", ")}`] : []),
178
178
  `**Excluded (stay pooled):** ${r.excluded.map((e) => `#${e.number} (${e.reason})`).join(", ") || "none"}`,
179
- "Promotion to the default branch stays human-only; the watch opens the deploy PR and never merges it."].join("\n");
179
+ "Promotion to the default branch stays opt-in (`release.auto_merge`); the watch opens the deploy PR, starts `forgedock release` for it and never merges it itself."].join("\n");
180
180
  }
181
181
 
182
182
  // ── the tick ─────────────────────────────────────────────────────────────────────────────────────────────────
@@ -200,7 +200,11 @@ export async function releaseTick({ watch, repo, io, state, defaults = [], listO
200
200
  if (!base) throw new Error("no default branch known; cannot open the deploy PR");
201
201
  const open = JSON.parse(await gh(["pr", "list", "-R", repo, "--head", rel.lane, "--base", base, "--state", "open", "--json", "number"]));
202
202
  rel.deployPr = open[0]?.number ?? (+(/(\d+)\s*$/.exec(await gh(["pr", "create", "-R", repo, "--base", base, "--head", rel.lane, "--title", `release(${rel.theme}): ${rel.tag}`,
203
- "--body", `Themed release **${rel.theme}** (${rel.tag}).\n\nIssues: ${rel.issues.map((n) => `#${n}`).join(" ")}\nMerged: ${state.merged.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\nFailed: ${state.failed.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\n\nPromotion is human-only: the issue watch opened this PR and never merges it.`]))?.[1]) || true);
203
+ "--body", `Themed release **${rel.theme}** (${rel.tag}).\n\nIssues: ${rel.issues.map((n) => `#${n}`).join(" ")}\nMerged: ${state.merged.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\nFailed: ${state.failed.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\n\nThe issue watch opened this PR and starts forgedock release for it; it never merges (promotion is opt-in via release.auto_merge).`]))?.[1]) || true);
204
+ }
205
+ // Hand the deploy PR to the release job (#5214); a failed start is recorded, never thrown (claims must not strand). Promotion stays opt-in.
206
+ if (io.release?.start && !rel.job) {
207
+ try { rel.job = (await io.release.start({ repo, pr: rel.deployPr, tag: rel.tag })) || "started"; } catch (e) { rel.jobError = String(e?.message ?? e); }
204
208
  }
205
209
  (state.releases ??= []).push(rel); state.release = null;
206
210
  }
@@ -244,3 +244,19 @@ test("CLI: --dry-run prints the cut without writing; refuses a non-release watch
244
244
  const w = loadWatches(`issue_watch:\n watches:\n sr:\n mode: release\n threshold: { min_issues: 2 }\n`).sr;
245
245
  assert.match(formatStatus({ name: "sr", repo: "o/r", phase: "running", claimed: [1], inflight: [1], merged: [], verified: [], failed: [], pool: [2, 3], llm: 2, releases: [], release: { theme: "billing", issues: [1], batch: "b1" } }, w), /pool: 2.*active: billing.*llm-classified: 2/);
246
246
  });
247
+
248
+ test("#5214: the deploy PR is handed to the release job once, without merge; a failed start is recorded", async () => {
249
+ for (const [prs, fail] of [[[], false], [[{ number: 9 }], false], [[], true]]) {
250
+ const issues = [1, 2, 3].map((n) => iss(n, { labels: lbl("billing") }));
251
+ const io = world(issues, { prs }), started = [];
252
+ io.release = { start: async (a) => { started.push(a); if (fail) throw new Error("spawn failed"); return "r1"; } };
253
+ const w = W(), st = fresh();
254
+ await step(io, w, st);
255
+ io.reported.add("b1"); io.closed.add(1);
256
+ await step(io, w, st);
257
+ assert.deepEqual(started, [{ repo: "o/r", pr: prs[0]?.number ?? 77, tag: "billing-2026-10-30" }]);
258
+ assert.equal(st.releases[0].job, fail ? undefined : "r1"); assert.equal(st.releases[0].jobError, fail ? "spawn failed" : undefined);
259
+ assert.equal(io.calls.some((a) => a[0] === "pr" && a[1] === "merge"), false);
260
+ await step(io, w, st); assert.equal(started.length, 1);
261
+ }
262
+ });
@@ -9,7 +9,7 @@
9
9
  * batch (batch.mjs `addIssues`, so K, the `Depends on` DAG and the report apply) and starts a new one after it reports.
10
10
  * No LLM calls.
11
11
  */
12
- import { existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs";
12
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmdirSync } from "node:fs";
13
13
  import { execFileSync, spawn, spawnSync } from "node:child_process";
14
14
  import { homedir, hostname } from "node:os";
15
15
  import { dirname, join } from "node:path";
@@ -18,6 +18,7 @@ import { writeAtomic, batchRoot, openBatch, listBatches } from "./batch.mjs";
18
18
  import { milestoneSlug, readBranches, isDefaultLane, defaultBranches, DEFAULT_STAGING_BRANCH, DEFAULT_FEATURE_PATTERN } from "./lane.mjs";
19
19
  import { postDeployOnly } from "./prefilter.mjs";
20
20
  import { releaseTick, formatDryRun } from "./issuewatch-release.mjs";
21
+ import { releaseRoot } from "./release.mjs";
21
22
  import { loadPolicy } from "./decision-engine.mjs";
22
23
  import { decisionContext, decisionsActive, decisionStep, decisionCounts, formatDecisionDryRun, claimsUsed } from "./issuewatch-decisions.mjs";
23
24
  import { APP_SLUG } from "../init-repo.mjs";
@@ -483,6 +484,15 @@ function realIo(repo, env = process.env) {
483
484
  p.on("close", (code) => { res = { code: code ?? 1 }; }); p.on("error", () => { res = { code: 1 }; });
484
485
  return { poll: () => res };
485
486
  },
487
+ release: {
488
+ // #5214: start the resumable `forgedock release` job for the deploy PR; no --merge (promotion is release.auto_merge only)
489
+ start: async ({ repo: r }) => {
490
+ const dir = releaseRoot(env), ls = () => { try { return readdirSync(dir); } catch { return []; } }, before = new Set(ls());
491
+ spawn(process.execPath, [CLI, "release", "--repo", r], { detached: true, windowsHide: true, stdio: "ignore", cwd: process.cwd(), env }).unref();
492
+ for (let i = 0; i < 10; i++) { const id = ls().find((x) => !before.has(x)); if (id) return id; await new Promise((res) => setTimeout(res, 500)); }
493
+ return "started";
494
+ },
495
+ },
486
496
  batch: {
487
497
  add: (id, issues) => openBatch(root, id).addIssues(issues),
488
498
  // release #5068 MAT-1: the CLI path checks the label, reopens a finished batch and hosts it on the schedd
@@ -29,3 +29,17 @@ export async function otherLaneOwner({ gh, repo, issue, branch = `feat/issue-${i
29
29
  const other = Array.isArray(prs) ? prs.find((p) => Number.isInteger(p?.number) && p.number !== ownPr) : null;
30
30
  return other ? { kind: "pr", detail: `PR #${other.number} is open on ${branch} from another lane` } : null;
31
31
  }
32
+
33
+ /**
34
+ * #5241: clear the lease on `issue`'s FORGE:STATE when `shouldClear(lease)` agrees (a cancelled lane's, once it ended).
35
+ * @param {{projector: {readState: Function, writeState: Function}, issue: number, shouldClear?: (lease: object) => boolean}} a
36
+ * @returns {Promise<boolean>} true when a lease was cleared; false when none, kept by the guard, or GitHub is unreadable (fail-safe)
37
+ */
38
+ export async function clearLease({ projector, issue, shouldClear = () => true }) {
39
+ try {
40
+ const st = await projector.readState(issue);
41
+ if (!st?.lease || !shouldClear(st.lease)) return false;
42
+ await projector.writeState(issue, { ...st, lease: null });
43
+ return true;
44
+ } catch { return false; }
45
+ }