forgedock 1.50.0 → 1.52.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/engine/outcome-codes.mjs +2 -0
- package/bin/engine-cli.mjs +98 -10
- package/bin/forgedock.mjs +40 -2
- package/bin/lean/batch-health.mjs +219 -0
- package/bin/lean/batch-health.test.mjs +156 -0
- package/bin/lean/batch.mjs +3 -3
- package/bin/lean/batch.test.mjs +236 -8
- package/bin/lean/conformance.mjs +66 -12
- package/bin/lean/conformance.test.mjs +55 -3
- package/bin/lean/context.mjs +35 -19
- package/bin/lean/context.test.mjs +26 -1
- package/bin/lean/credentials.mjs +18 -0
- package/bin/lean/effects.mjs +3 -3
- package/bin/lean/execution.mjs +11 -6
- package/bin/lean/execution.test.mjs +28 -0
- package/bin/lean/fixclosereasons.mjs +52 -0
- package/bin/lean/fixclosereasons.test.mjs +64 -0
- package/bin/lean/heavy.mjs +6 -3
- package/bin/lean/hostload.mjs +78 -0
- package/bin/lean/hostload.test.mjs +117 -0
- package/bin/lean/hotspots-remote.e2e.test.mjs +71 -0
- package/bin/lean/lean.mjs +34 -19
- package/bin/lean/lean.test.mjs +87 -14
- package/bin/lean/orchestrate-blocked.test.mjs +47 -0
- package/bin/lean/orchestrate.mjs +138 -12
- package/bin/lean/prefilter.mjs +4 -3
- package/bin/lean/prefilter.test.mjs +5 -4
- package/bin/lean/prompts.mjs +4 -2
- package/bin/lean/recovery.test.mjs +5 -5
- package/bin/lean/sandbox-provider.contract.test.mjs +15 -1
- package/bin/lean/schedd.mjs +8 -3
- package/bin/lean/schedd.test.mjs +21 -0
- package/bin/pool/agent.mjs +3 -1
- package/bin/pool/router.mjs +74 -8
- package/bin/review-staging.mjs +2 -0
- package/bin/runner.mjs +24 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +41 -2
- package/docs/OUTCOME-CODES.md +2 -1
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/pool/image/cs-cred +8 -1
- package/pool/install/install-agent.ps1 +6 -2
- package/scripts/file-deferred-followups.sh +23 -9
- package/scripts/file-deferred-followups.test.sh +34 -1
- package/scripts/hotspots.sh +12 -8
- package/scripts/hotspots.test.sh +22 -0
- package/scripts/prior-attempts.test.mjs +1 -1
- package/scripts/review-staging-post.sh +70 -25
- package/scripts/review-staging-post.test.sh +40 -8
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import { runFixCloseReasonsCli } from "./fixclosereasons.mjs";
|
|
6
|
+
|
|
7
|
+
const L = (...n) => n.map((name) => ({ name }));
|
|
8
|
+
function fake({ lists, failOn } = {}) {
|
|
9
|
+
const calls = [], out = [];
|
|
10
|
+
const gh = async (a) => {
|
|
11
|
+
calls.push(a);
|
|
12
|
+
if (a[0] === "issue" && a[1] === "list") return JSON.stringify(lists[a[a.indexOf("--label") + 1]] ?? []);
|
|
13
|
+
if (a[0] === "api" && failOn === a[3].split("/").pop()) throw new Error("boom");
|
|
14
|
+
return "";
|
|
15
|
+
};
|
|
16
|
+
return { gh, calls, out, print: (t) => out.push(t) };
|
|
17
|
+
}
|
|
18
|
+
const lists = {
|
|
19
|
+
"workflow:merged": [
|
|
20
|
+
{ number: 1, stateReason: "NOT_PLANNED", labels: L("workflow:merged") },
|
|
21
|
+
{ number: 2, stateReason: "COMPLETED", labels: L("workflow:merged") },
|
|
22
|
+
{ number: 3, stateReason: "NOT_PLANNED", labels: L("workflow:merged", "workflow:invalid") },
|
|
23
|
+
],
|
|
24
|
+
"workflow:decomposed": [
|
|
25
|
+
{ number: 4, stateReason: "NOT_PLANNED", labels: L("workflow:decomposed") },
|
|
26
|
+
{ number: 1, stateReason: "NOT_PLANNED", labels: L("workflow:merged", "workflow:decomposed") },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe("#5177 fix-close-reasons", () => {
|
|
31
|
+
it("re-closes NOT_PLANNED merged and decomposed issues as completed with a comment; leaves the rest", async () => {
|
|
32
|
+
const f = fake({ lists });
|
|
33
|
+
assert.equal(await runFixCloseReasonsCli(["o/r", "--apply"], f), 0);
|
|
34
|
+
const patches = f.calls.filter((a) => a[0] === "api");
|
|
35
|
+
assert.deepEqual(patches.map((a) => a[3]), ["repos/o/r/issues/1", "repos/o/r/issues/4"]);
|
|
36
|
+
for (const p of patches) assert.deepEqual(p.slice(0, 3).concat(p.slice(4)), ["api", "-X", "PATCH", "-f", "state=closed", "-f", "state_reason=completed"]);
|
|
37
|
+
const comments = f.calls.filter((a) => a[1] === "comment");
|
|
38
|
+
assert.deepEqual(comments.map((a) => a[2]), ["1", "4"]);
|
|
39
|
+
assert.match(comments[0][comments[0].indexOf("--body") + 1], /delivered and merged/);
|
|
40
|
+
assert.match(comments[1][comments[1].indexOf("--body") + 1], /decomposed/);
|
|
41
|
+
assert.match(f.out.at(-1), /2 found, 2 changed, 0 failed/);
|
|
42
|
+
});
|
|
43
|
+
it("is a dry run without --apply: no write", async () => {
|
|
44
|
+
const f = fake({ lists });
|
|
45
|
+
assert.equal(await runFixCloseReasonsCli(["o/r"], f), 0);
|
|
46
|
+
assert.equal(f.calls.filter((a) => a[0] !== "issue" || a[1] !== "list").length, 0);
|
|
47
|
+
assert.match(f.out.join("\n"), /would re-close #1/);
|
|
48
|
+
});
|
|
49
|
+
it("--milestone narrows the list query", async () => {
|
|
50
|
+
const f = fake({ lists: {} });
|
|
51
|
+
await runFixCloseReasonsCli(["o/r", "--milestone", "M1"], f);
|
|
52
|
+
for (const c of f.calls) assert.equal(c[c.indexOf("--milestone") + 1], "M1");
|
|
53
|
+
assert.equal(f.calls.length, 2);
|
|
54
|
+
});
|
|
55
|
+
it("counts a failed write and exits 1, continuing with the next issue", async () => {
|
|
56
|
+
const f = fake({ lists, failOn: "1" });
|
|
57
|
+
assert.equal(await runFixCloseReasonsCli(["o/r", "--apply"], f), 1);
|
|
58
|
+
assert.match(f.out.at(-1), /2 found, 1 changed, 1 failed/);
|
|
59
|
+
});
|
|
60
|
+
it("throws usage without a repo", async () => {
|
|
61
|
+
await assert.rejects(runFixCloseReasonsCli([], fake()), /usage: forgedock fix-close-reasons/);
|
|
62
|
+
await assert.rejects(runFixCloseReasonsCli(["--apply"], fake()), /usage/);
|
|
63
|
+
});
|
|
64
|
+
});
|
package/bin/lean/heavy.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import { writeAtomic } from "./batch.mjs";
|
|
|
26
26
|
import { schedDir, pidAlive, DEFAULT_PRIORITY } from "./sched.mjs";
|
|
27
27
|
import { which } from "./toolchain.mjs";
|
|
28
28
|
import { hostParallelism } from "./admission.mjs";
|
|
29
|
+
import { lowerPriority } from "./hostload.mjs";
|
|
29
30
|
|
|
30
31
|
export const HEAVY_DEFAULTS = Object.freeze({ enabled: true, max: null, step_mem_mb: 2048, reserve_mb: 1024, ramp_s: 60, max_wait_s: 1800 });
|
|
31
32
|
export const HEAVY_POLL_MS = 2000;
|
|
@@ -388,13 +389,15 @@ export async function runWrapped(argv, { env: env0 = process.env, open = openHea
|
|
|
388
389
|
let cores = 1; try { cores = hostP.cores() || 1; } catch { /* 1 */ }
|
|
389
390
|
const childEnv = { ...env, FORGE_HEAVY_HELD: "1",
|
|
390
391
|
...(env.FORGE_HEAVY_PARALLELISM_PINNED === "1" ? {} : { FORGE_HOST_PARALLELISM: String(hostParallelism({ cores, lanes: g.holders })) }) };
|
|
391
|
-
|
|
392
|
+
// #5174: a gated step runs at nice 10 / ionice idle so local test runners and installs do not starve the schedd event loop.
|
|
393
|
+
try { return await run(cmd, args, childEnv, (child) => lowerPriority(child?.pid)); } finally { g.release(); }
|
|
392
394
|
}
|
|
393
395
|
|
|
394
|
-
/** Spawn with inherited stdio; resolves {code, signal}; forwards termination signals to the child. */
|
|
395
|
-
export function spawnInherit(cmd, args, env) {
|
|
396
|
+
/** Spawn with inherited stdio; resolves {code, signal}; forwards termination signals to the child. `onSpawn(child)` runs once it has a pid. */
|
|
397
|
+
export function spawnInherit(cmd, args, env, onSpawn = null) {
|
|
396
398
|
return new Promise((done) => {
|
|
397
399
|
const child = spawn(cmd, args, { stdio: "inherit", env });
|
|
400
|
+
if (onSpawn && child.pid) { try { onSpawn(child); } catch { /* best effort */ } }
|
|
398
401
|
const fwd = (sig) => { try { child.kill(sig); } catch { /* gone */ } };
|
|
399
402
|
const sigs = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
400
403
|
for (const s of sigs) process.on(s, fwd);
|
|
@@ -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
|
+
});
|
package/bin/lean/lean.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { ciPollDelayMs, ENGINE_VERSION, DEFAULT_MAX_SESSION_LIMIT_PAUSES, DEFAUL
|
|
|
15
15
|
import { openDependency, laneMergedPrs, dependencyOnLane, isTrustedComment, decomposedSubissues, isDecomposedRecord, reopenRevokedDecomposition } from "../engine/phases.mjs";
|
|
16
16
|
import { createHash, randomBytes } from "node:crypto";
|
|
17
17
|
import { otherLaneOwner } from "./lanelock.mjs";
|
|
18
|
-
import { applyValidateRecipes, deferChecklessPostDeploy, reproEnvMiss, resolveForgedockPaths, describesUnrunnableCommand, removedPathsOf, TRACKED, normalizeKindModes, blockingFailures, unverifiedRequirements, mutationTargets, mutationFailures, runMutationCheck, MUTATION_SURVIVED, isBugIssue, scopeText, explainFailures, inIssue, validateContract, cliUsageError, normalizeRunnerCommand, applyAmendments, amendmentKindProblems, precheck, alreadyFixedOnBase, READONLY_PROD_RE, EXTERNAL_NEED_RE, repoTracks, dropScopeValidates, tagOutOfBand, parseReview, decide, mergeReviewRows,
|
|
18
|
+
import { applyValidateRecipes, deferChecklessPostDeploy, reproEnvMiss, resolveForgedockPaths, describesUnrunnableCommand, removedPathsOf, TRACKED, normalizeKindModes, blockingFailures, unverifiedRequirements, mutationTargets, mutationFailures, runMutationCheck, MUTATION_SURVIVED, isBugIssue, scopeText, explainFailures, inIssue, validateContract, cliUsageError, normalizeRunnerCommand, applyAmendments, amendmentKindProblems, precheck, alreadyFixedOnBase, READONLY_PROD_RE, EXTERNAL_NEED_RE, repoTracks, dropScopeValidates, tagOutOfBand, parseReview, decide, mergeReviewRows, reaskable, criterionLines, closePlan, followupItems, renderPendingFollowups, bucketTally, pendingTracking, unnamedEdges, structureNote, impliedDocDeliverables } from "./conformance.mjs";
|
|
19
19
|
import { checkAdmission, hostParallelism, ADMISSION_RETRY_SECONDS } from "./admission.mjs";
|
|
20
20
|
import { namedPaths, isTrustedIssueComment } from "./prefilter.mjs";
|
|
21
21
|
import { checksAt } from "./postdeploy-check.mjs";
|
|
@@ -91,6 +91,8 @@ export const RECOVER_HOW = Object.freeze({
|
|
|
91
91
|
[OUTCOME_CODES.CONFORMANCE_UNJUSTIFIED_DEFERRAL]: "an earlier run deferred a requirement without a sufficient why after one builder resume; the branch holds its work. For each named gap either deliver the requirement (adding any needed file as an `add-deliverable` amendment) or, when the clause is optional, unquantified or outside the issue's acceptance criteria, record a `defer` amendment with a concrete why so the engine files a tracked follow-up instead of stopping",
|
|
92
92
|
[OUTCOME_CODES.ENV_REPRO_UNRUNNABLE]: "the repro harness could not run the contract's repro_test on head (timeout, missing runner or dependencies); the change may already be correct. Do not edit the deliverables or stub dependencies for it and never install anything globally: run the repro command through the repo's own toolchain and installed dependencies, and when it cannot run in this checkout, fix the repro_test command (not the code) so it does",
|
|
93
93
|
});
|
|
94
|
+
/** #5168: retry-in for a `backend.auth` deferral; the batch holds the account for it (an operator `--set-env` fix runs under a new identity). */
|
|
95
|
+
const AUTH_RETRY_SECONDS = 900;
|
|
94
96
|
/** #4323/#4334: precheck failure codes that are environment errors (state "environment"), never a builder resume. */
|
|
95
97
|
const ENV_CODES = Object.freeze([OUTCOME_CODES.ENV_TOOL_MISSING, OUTCOME_CODES.ENV_REPRO_UNRUNNABLE, ENV_VALIDATE_TIMEOUT, OUTCOME_CODES.CONTRACT_INVALID_COMMAND]);
|
|
96
98
|
export const DEFAULT_REVIEWER_MODEL = "claude-sonnet-5-5";
|
|
@@ -488,7 +490,7 @@ export async function runCore(o) {
|
|
|
488
490
|
}
|
|
489
491
|
if (["merged", "invalid", "needs-human", "budget-exceeded"].includes(reason)) {
|
|
490
492
|
if (reason === "budget-exceeded") T.close = ["left open", "recoverable budget.exceeded"]; // #4505: not a human escalation
|
|
491
|
-
else if (reason === "merged") T.close = [extra.close === "partial" ? "issue closed (partial)" : "issue closed (completed)", "label workflow:merged"];
|
|
493
|
+
else if (reason === "merged") T.close = [extra.keptOpen ? "left open (follow-up pending)" : extra.close === "partial" ? "issue closed (partial)" : "issue closed (completed)", "label workflow:merged"]; // #5159
|
|
492
494
|
else if (reason === "invalid" && extra.close === "already-fixed") T.close = ["issue closed (completed)", "already fixed on the base"]; // #5080
|
|
493
495
|
else if (reason === "invalid") T.close = ["issue closed (not planned)", "label workflow:invalid"];
|
|
494
496
|
else { T.close = ["left open", "label needs-human"]; T.anomalies.push(`needs-human: ${String(detail).split("\n")[0].slice(0, 300)}`); }
|
|
@@ -636,6 +638,9 @@ export async function runCore(o) {
|
|
|
636
638
|
const par = verifyParallelism();
|
|
637
639
|
return { ...deps, ...(runTmp ? { TMPDIR: runTmp } : {}), ...(par ? { FORGE_HOST_PARALLELISM: par } : {}), ...(toolchain?.env ?? {}) };
|
|
638
640
|
}
|
|
641
|
+
/** #5168: a failed claude login ends the lane `deferred` `backend.auth`, held per account by the batch (never the relaunch or the breaker). */
|
|
642
|
+
const authDeferral = (e) => Object.assign(e, { deferCode: OUTCOME_CODES.BACKEND_AUTH, retryInSeconds: AUTH_RETRY_SECONDS, backendId: laneBackendId(process.env, rotator),
|
|
643
|
+
deferDetail: `claude CLI authentication failed (login expired or invalid); held until the login is fixed: ${String(e?.message ?? e).split("\n")[0].slice(0, 300)}` });
|
|
639
644
|
/** Runner call with the per-run TMPDIR and FORGE_HOST_PARALLELISM; a usage limit pauses and resumes the same step, or defers past the cap (#4101). */
|
|
640
645
|
async function callRunner(args) {
|
|
641
646
|
let pauses = 0, rotations = 0;
|
|
@@ -649,6 +654,7 @@ export async function runCore(o) {
|
|
|
649
654
|
try { return await io.runner({ ...args, system, env: { ...laneEnv(), FORGE_DOCKER_LABELS: labels, ...(runTmp ? { CLAUDE_CODE_TMPDIR: runTmp } : {}), ...(toolchain?.env ?? {}), ...heavy, ...profEnv } }); }
|
|
650
655
|
catch (e) {
|
|
651
656
|
const epoch = Number.isFinite(e?.resetAtEpochMs) ? e.resetAtEpochMs : null;
|
|
657
|
+
if (e?.authFailure === true && e.usageLimit !== true && epoch === null) throw authDeferral(e); // #5168: an account condition, never engine-error
|
|
652
658
|
if (!(e?.usageLimit === true || epoch !== null)) throw e;
|
|
653
659
|
if (rotatorRetry(rotator, rotations)) { rotations++; ev({ event: "PHASE_ACCOUNT_ROTATED", phase: args.role }); continue; } // #5094: same args (resume too), next account
|
|
654
660
|
const waitMs = epoch !== null && epoch > now() ? epoch - now() : DEFAULT_SESSION_LIMIT_WAIT_MS;
|
|
@@ -1002,9 +1008,10 @@ export async function runCore(o) {
|
|
|
1002
1008
|
// #4337: with decomposition.close_parent, the tracker closes only once its trail and label exist: dependents then wait on the sub-issues, not on it.
|
|
1003
1009
|
if (await label("decomposed") && marked && closeParent) {
|
|
1004
1010
|
try {
|
|
1005
|
-
|
|
1011
|
+
// #5152: the scope moved to the sub-issues, it was not dropped: `completed`, never `not planned`
|
|
1012
|
+
await ghw(["issue", "close", String(issue), "-R", repo, "--reason", "completed", "--comment",
|
|
1006
1013
|
`Decomposed into ${refs(filed)}; this tracker is closed and its dependents wait on the sub-issues. A trusted \`FORGE:DECOMPOSED:REVOKED\` reopens it.`]);
|
|
1007
|
-
T.decisions.push(`Closed the decomposed parent (
|
|
1014
|
+
T.decisions.push(`Closed the decomposed parent (completed; scope moved to sub-issues); tracked by ${refs(filed)}`);
|
|
1008
1015
|
} catch { /* best effort: the parent stays open, as before #4337 */ }
|
|
1009
1016
|
}
|
|
1010
1017
|
return await finish("decomposed", `split into ${refs(filed)}`, { code: OUTCOME_CODES.DECOMPOSED, subissues: filed, decomposition: b.rationale });
|
|
@@ -1086,7 +1093,7 @@ export async function runCore(o) {
|
|
|
1086
1093
|
try {
|
|
1087
1094
|
iss = JSON.parse(await ghc(["issue", "view", String(issue), "-R", repo, "--json", "number,title,body,state,comments,labels,updatedAt"]));
|
|
1088
1095
|
} catch (e) {
|
|
1089
|
-
if (e?.deferCode) return finish("deferred", e.deferDetail ?? String(e.message), { code: e.deferCode, ...(e.retryInSeconds ? { retryInSeconds: e.retryInSeconds } : {}) }, e.deferCode); // #4662
|
|
1096
|
+
if (e?.deferCode) return finish("deferred", e.deferDetail ?? String(e.message), { code: e.deferCode, ...(e.retryInSeconds ? { retryInSeconds: e.retryInSeconds } : {}), ...(e.backendId ? { backendId: e.backendId } : {}) }, e.deferCode); // #4662; #5168 backendId
|
|
1090
1097
|
return finish("engine-error", `cannot read issue: ${e.message}`);
|
|
1091
1098
|
}
|
|
1092
1099
|
const priorState = stateOf(iss.body); // #4400: the last run's end (the lease write keeps its terminal fields), read before this run ends
|
|
@@ -1302,10 +1309,14 @@ export async function runCore(o) {
|
|
|
1302
1309
|
try { return selfCheckState(JSON.parse(await io.fs.read(`${wt}/${SELF_CHECK_FILE}`)), await worktreeFingerprint({ git, base })); } catch { return "skipped"; }
|
|
1303
1310
|
};
|
|
1304
1311
|
/** forge#4195: scripts/hotspots.sh facts in the worktree, or null (no io.hotspots, script failure): never fails a run. */
|
|
1312
|
+
let hotCfgNoted = false;
|
|
1305
1313
|
const hotspotsOf = async (args) => {
|
|
1306
1314
|
if (!io.hotspots) return null;
|
|
1307
|
-
const
|
|
1308
|
-
|
|
1315
|
+
const config = existsSync(join(cwd, "forge.yaml")) ? join(cwd, "forge.yaml") : null; // #5163: forge.yaml is often gitignored, so the worktree has none
|
|
1316
|
+
const h = await io.hotspots({ cwd: wt, config, ...args }).catch(() => null);
|
|
1317
|
+
if (!(h && typeof h === "object" && Array.isArray(h.files))) return null;
|
|
1318
|
+
if (h.config_source === null && !hotCfgNoted) { hotCfgNoted = true; T.anomalies.push("hotspot_config_missing: no forge.yaml readable for the hotspot gate (exclude_globs and generated_paths not applied; defaults used)"); }
|
|
1319
|
+
return h;
|
|
1309
1320
|
};
|
|
1310
1321
|
/** #4271: a bug lane with lean.repro_test on; refactor:split lanes never set it (no plan call, no repro_test). */
|
|
1311
1322
|
const reproOn = () => reproTest !== "off" && isBugIssue(iss?.labels);
|
|
@@ -1721,9 +1732,10 @@ export async function runCore(o) {
|
|
|
1721
1732
|
if (closes) {
|
|
1722
1733
|
T.plan = "skipped"; T.implement = "skipped"; T.review = "skipped"; T.pr = "none"; T.merge = "n/a";
|
|
1723
1734
|
T.decisions.push(`Builder verdict: ${result.status}`);
|
|
1724
|
-
|
|
1735
|
+
// #5152: already-fixed is delivered behaviour (`completed`); only invalid is dropped scope (`not planned`)
|
|
1736
|
+
await ghw(["issue", "close", String(issue), "-R", repo, "--reason", result.status === "already-fixed" ? "completed" : "not planned"]);
|
|
1725
1737
|
await label("invalid");
|
|
1726
|
-
return await finish("invalid", result.summary ?? result.status);
|
|
1738
|
+
return await finish("invalid", result.summary ?? result.status, result.status === "already-fixed" ? { close: "already-fixed" } : {});
|
|
1727
1739
|
}
|
|
1728
1740
|
const blocked = await endIfBlocked();
|
|
1729
1741
|
if (blocked) return blocked;
|
|
@@ -2236,16 +2248,16 @@ export async function runCore(o) {
|
|
|
2236
2248
|
const ctx = { contract: effective, changedFiles: files, issueText, pathExists: (x) => listed.has(x), repoFiles: listed, ignore: IGNORE, e2e: { checks: vcfg.e2e?.checks ?? [], isSpec: (x) => e2eSpecs([x], vcfg.e2e).length > 0 } };
|
|
2237
2249
|
let d = null, first = null;
|
|
2238
2250
|
for (let t = 0; t < 3; t++) {
|
|
2239
|
-
// #4327: a third run only when the repaired reply is incomplete solely by evidence paths
|
|
2251
|
+
// #4327/#5164: a third run only when the repaired reply is incomplete solely by reviewer slips (unresolved evidence paths, coverage misquotes).
|
|
2240
2252
|
if (t === 2) {
|
|
2241
|
-
if (d.state !== "review.incomplete" || !
|
|
2242
|
-
T.decisions.push(`Review incomplete only by unresolved evidence paths (${(d.missing ?? []).join(", ")}); reviewer re-asked once more`);
|
|
2253
|
+
if (d.state !== "review.incomplete" || !reaskable(d.failures.map((f) => f.detail))) break;
|
|
2254
|
+
T.decisions.push(`Review incomplete only by unresolved evidence paths or coverage misquotes (${(d.missing ?? []).join(", ")}); reviewer re-asked once more`);
|
|
2243
2255
|
}
|
|
2244
2256
|
// #4160: a reply with rows missing is re-asked for those ids only; an unparseable one gets the full prompt again.
|
|
2245
2257
|
const repair = first && (d.state === "review.incomplete" || d.state === "review.inconsistent");
|
|
2246
2258
|
await renew();
|
|
2247
2259
|
const rr = await callRunner({ role: "reviewer", issue, cwd: wt, model: reviewerModel, resume: null, system: REVIEWER_SYSTEM, readOnly: true,
|
|
2248
|
-
prompt: repair ? reviewerRepairPrompt({ missing: d.missing ?? [], problems: d.failures.map((f) => f.detail), rows: first })
|
|
2260
|
+
prompt: repair ? reviewerRepairPrompt({ missing: d.missing ?? [], problems: d.failures.map((f) => f.detail), rows: first, criteria: (d.missing ?? []).includes("issue_coverage") ? criterionLines(issueText) : [] })
|
|
2249
2261
|
: reviewerPrompt({ issue: iss, comments: trustedComments, contract: effective, result, files, diff, stat, base, structure: structureLine, ignore: IGNORE, domains, investigationVerdict: investigationVerdict(await io.fs.read(`${wt}/.forge-lean/investigation.md`).catch(() => null)) }) });
|
|
2250
2262
|
await renew();
|
|
2251
2263
|
await attempt("review", ++reviewN, rr, null, "review");
|
|
@@ -2289,7 +2301,7 @@ export async function runCore(o) {
|
|
|
2289
2301
|
run.findings = parseVerifierFindings(rr?.text, { pathExists: (x) => listed.has(x) });
|
|
2290
2302
|
run.cost_usd = num(rr?.costUsd) ?? 0;
|
|
2291
2303
|
} catch (e) {
|
|
2292
|
-
if (e?.deferUsageLimit) throw e;
|
|
2304
|
+
if (e?.deferUsageLimit || e?.deferCode === OUTCOME_CODES.BACKEND_AUTH) throw e; // #5168: a login failure (backend.auth) is not swallowed as a verifier error
|
|
2293
2305
|
run.error = String(e?.code || e?.message || e).split("\n")[0].slice(0, 200);
|
|
2294
2306
|
T.anomalies.push(`Independent verifier failed at ${head.slice(0, 12)}: ${run.error}`);
|
|
2295
2307
|
}
|
|
@@ -3062,9 +3074,12 @@ export async function runCore(o) {
|
|
|
3062
3074
|
}
|
|
3063
3075
|
}
|
|
3064
3076
|
const partial = closing.reason === "partial";
|
|
3065
|
-
|
|
3066
|
-
if (
|
|
3067
|
-
|
|
3077
|
+
// #5152: a merged change is `completed` even when partial: the remainder is tracked (FORGE:TRACKED), not dropped
|
|
3078
|
+
if (!keepOpen) await ghw(["issue", "close", String(issue), "-R", repo, "--reason", "completed"]).catch(() => {});
|
|
3079
|
+
if (keepOpen) { // #5159: the issue is not closed while a follow-up is pending, so the note must not say it is
|
|
3080
|
+
if (partial || closing.tracked.length) try { await post("FORGE:TRACKED", `## Left open: follow-up pending\nMerged by PR #${pr}; the issue stays open until the pending follow-up is filed (FORGE:FOLLOWUP_PENDING).${partial ? " The investigation's stated question is not answered in this change." : ""}${closing.tracked.length ? ` Already tracked in ${closing.tracked.join(", ")}.` : ""}`); } catch { /* the PR body links them too */ }
|
|
3081
|
+
} else if (partial) {
|
|
3082
|
+
try { await post("FORGE:TRACKED", `## Closed as partial\nClosed as completed by PR #${pr}; the investigation's stated question is not answered in this change and is carried forward in ${closing.tracked.join(", ")}.`); } catch { /* the PR body links them too */ }
|
|
3068
3083
|
} else if (closing.tracked.length) {
|
|
3069
3084
|
try { await post("FORGE:TRACKED", `## Remaining work tracked\nClosed as completed by PR #${pr}. The contracted deferred and post-deploy requirements are tracked in ${closing.tracked.join(", ")}.`); } catch { /* the PR body links them too */ }
|
|
3070
3085
|
}
|
|
@@ -3089,13 +3104,13 @@ export async function runCore(o) {
|
|
|
3089
3104
|
await gatePassed("merge_ci", "ci_red"); // #4375: merged means the required checks are green after a CI fix round
|
|
3090
3105
|
let mergedTo = null; // #4711: FORGE:STATE records the lane and merge commit, so a dependent's check needs no PR search
|
|
3091
3106
|
if (lane) try { const sha = JSON.parse(String(await ghc(["pr", "view", String(pr), "-R", repo, "--json", "mergeCommit"])) || "{}").mergeCommit?.oid; if (typeof sha === "string" && sha) mergedTo = { lane, pr, sha }; } catch { /* the PR-ancestry rule still applies */ }
|
|
3092
|
-
return await finish("merged", `PR #${pr}`, { pr, ...(mergedTo ? { mergedTo } : {}), ...(partial ? { close: "partial" } : {}), structure: T.structure ?? null, ...(milestone ? { milestone } : {}), ...(lane ? { lane } : {}) });
|
|
3107
|
+
return await finish("merged", `PR #${pr}`, { pr, ...(mergedTo ? { mergedTo } : {}), ...(partial ? { close: "partial" } : {}), ...(keepOpen ? { keptOpen: true } : {}), structure: T.structure ?? null, ...(milestone ? { milestone } : {}), ...(lane ? { lane } : {}) });
|
|
3093
3108
|
} catch (e) {
|
|
3094
3109
|
if (e?.deferUsageLimit) {
|
|
3095
3110
|
const when = e.resetAt || (Number.isFinite(e.resetAtEpochMs) ? new Date(e.resetAtEpochMs).toISOString() : "unknown");
|
|
3096
3111
|
return finish("deferred", `usage limit hit; resets at ${when}`, { code: OUTCOME_CODES.RATE_LIMITED, resetAt: when, resetAtEpochMs: Number.isFinite(e.resetAtEpochMs) ? e.resetAtEpochMs : null, backendId: laneBackendId(process.env, rotator) }, OUTCOME_CODES.RATE_LIMITED);
|
|
3097
3112
|
}
|
|
3098
|
-
if (e?.deferCode) return finish("deferred", e.deferDetail ?? String(e.message), { code: e.deferCode, ...(e.retryInSeconds ? { retryInSeconds: e.retryInSeconds } : {}) }, e.deferCode);
|
|
3113
|
+
if (e?.deferCode) return finish("deferred", e.deferDetail ?? String(e.message), { code: e.deferCode, ...(e.retryInSeconds ? { retryInSeconds: e.retryInSeconds } : {}), ...(e.backendId ? { backendId: e.backendId } : {}) }, e.deferCode); // #5168: backendId keys the account hold
|
|
3099
3114
|
// #4505: a turn overrun is mechanical: a non-human end the batch recovers, needs-human only once a budget recovery failed too
|
|
3100
3115
|
if (e?.laneCode === OUTCOME_CODES.BUDGET_EXCEEDED && !(recover?.final && recover.code === OUTCOME_CODES.BUDGET_EXCEEDED)) {
|
|
3101
3116
|
return finish("budget-exceeded", e.message, { code: OUTCOME_CODES.BUDGET_EXCEEDED, branch, ...(recover ? { recovery: true } : {}) }, OUTCOME_CODES.BUDGET_EXCEEDED);
|