forgedock 1.67.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 +1 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +99 -12
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +25 -10
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.test.mjs +51 -2
- 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.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +56 -196
- package/bin/lean/conformance.test.mjs +40 -376
- 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/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 +10 -4
- package/bin/lean/execution.test.mjs +12 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -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 +206 -148
- package/bin/lean/lean.test.mjs +406 -190
- 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/orchestrate-attempts.test.mjs +17 -9
- 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 +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -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 +188 -33
- 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 +10 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- 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 +16 -9
- package/bin/lean/schedd.mjs +11 -6
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +143 -9
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +37 -8
- 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 +7 -2
- 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/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/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -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/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +11 -0
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
package/bin/lean/release.mjs
CHANGED
|
@@ -26,14 +26,14 @@ import { budgetReportLine, releaseRuns, detectBudget, readCiPolicy } from "./ci-
|
|
|
26
26
|
import { parseNightlyConfig, readNightly, blocksRelease, fileNightlyRed } from "./release-nightly.mjs";
|
|
27
27
|
import { parseBudgetConfig, applyOnExceed, waveReport, trailingMedian, historyFromRoot, gateHistoryFromRoot, releaseMinutes } from "./release-minutes.mjs";
|
|
28
28
|
import { cutSnapshot, writeRecord, checkChain, verifyRelease, defaultBehind, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
29
|
-
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat } from "./release-ledger.mjs";
|
|
29
|
+
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat, recordReleaseRound } from "./release-ledger.mjs";
|
|
30
30
|
import { fenced, epochTrailer } from "./release-fence.mjs";
|
|
31
31
|
import { holdCheck, exemptionsSection, runControl, VERBS as CONTROL_VERBS } from "./release-control.mjs";
|
|
32
32
|
import { parseFlakeConfig, classifyFailure, planRerun, flakeEntry, recordFlakes, readFlakes } from "./release-flakes.mjs";
|
|
33
33
|
import { readActive } from "./release-ledger.mjs";
|
|
34
34
|
import { statusFromCli, policyFromYaml } from "./release-status.mjs";
|
|
35
35
|
import { parseFixConfig } from "./release-fixloop.mjs";
|
|
36
|
-
import { hostPreflightStep, markReadyStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
36
|
+
import { hostPreflightStep, markReadyStep, stagingHealthStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
37
37
|
import { roleRefusal } from "./release-credentials.mjs";
|
|
38
38
|
import { mergeGuard } from "./release-gate.mjs";
|
|
39
39
|
|
|
@@ -130,7 +130,7 @@ const snapshotKeys = (r) => {
|
|
|
130
130
|
export const isSnapshot = (config) => config?.mode === "snapshot";
|
|
131
131
|
|
|
132
132
|
/** `{rehearsal}` / `{preflight}` only when configured, so the config of a repo without them keeps its shape. */
|
|
133
|
-
const optKeys = (r) => { const rehearsal = parseRehearsalConfig(r), preflight = parsePreflightConfig(r); return { ...(rehearsal ? { rehearsal } : {}), ...(preflight ? { preflight } : {}) }; };
|
|
133
|
+
const optKeys = (r) => { const rehearsal = parseRehearsalConfig(r), preflight = parsePreflightConfig(r); return { ...(r?.allow_red_staging === true || String(r?.allow_red_staging).toLowerCase() === "true" ? { allowRedStaging: true } : {}), ...(rehearsal ? { rehearsal } : {}), ...(preflight ? { preflight } : {}) }; };
|
|
134
134
|
|
|
135
135
|
const json = (s) => JSON.parse(String(s || "null"));
|
|
136
136
|
|
|
@@ -143,10 +143,26 @@ export async function bundleList({ io, repo, head, base }) {
|
|
|
143
143
|
|
|
144
144
|
const bundleBody = (list) => `## Release bundle\n\n${list.length ? list.map((p) => `- #${p.number} ${p.title}`).join("\n") : "_No merged PRs found since the last release._"}\n`;
|
|
145
145
|
|
|
146
|
+
/** #6013: one `state.rounds` entry per distinct head and outcome (a resume does not double-count). */
|
|
147
|
+
function noteRound(ctx, r) {
|
|
148
|
+
const { state, io } = ctx;
|
|
149
|
+
if ((state.rounds ?? []).some((x) => x.head === r.head && x.outcome === r.outcome)) return;
|
|
150
|
+
const at = new Date(io.now?.() ?? Date.now()).toISOString();
|
|
151
|
+
recordReleaseRound(state, { ...r, startedAt: at, endedAt: at });
|
|
152
|
+
ctx.save();
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
async function preflightStep(ctx) {
|
|
147
156
|
const { io, repo, state, staging } = ctx;
|
|
148
157
|
// Snapshot mode: lanes keep merging to staging; the release is cut from a fixed SHA, so nothing is refused or held (#5276).
|
|
149
|
-
|
|
158
|
+
const health = await stagingHealthStep(ctx);
|
|
159
|
+
if (health.refused) {
|
|
160
|
+
state.knownFailures = health.failed;
|
|
161
|
+
noteRound(ctx, { head: health.head, outcome: "red-staging", cause: health.failed.some((f) => f.cause === "regression") || !health.failed.length ? "regression" : "runner" });
|
|
162
|
+
ctx.save(); return { refused: health.refused, failed: health.failed }; }
|
|
163
|
+
state.knownFailures = health.failed ?? [];
|
|
164
|
+
const warn = health.warning ? { warning: health.warning } : {};
|
|
165
|
+
if (isSnapshot(ctx.config)) return { snapshot: true, held: 0, ...warn };
|
|
150
166
|
const lanes = await io.runningLanes(repo);
|
|
151
167
|
if (lanes.length) return { refused: `lanes of ${repo} are running (${lanes.map((l) => `${l.batch}#${l.issue}`).join(", ")}); wait or cancel them` };
|
|
152
168
|
const open = json(await io.gh(["pr", "list", "--repo", repo, "--base", staging, "--state", "open", "--json", "number"])) ?? [];
|
|
@@ -159,7 +175,7 @@ async function preflightStep(ctx) {
|
|
|
159
175
|
ctx.save();
|
|
160
176
|
await io.setParallel(b.id, 1);
|
|
161
177
|
}
|
|
162
|
-
return { held: state.held.length };
|
|
178
|
+
return { held: state.held.length, ...warn };
|
|
163
179
|
}
|
|
164
180
|
|
|
165
181
|
/** Restore every held batch to its recorded K; best effort, recorded as it goes. */
|
|
@@ -185,14 +201,15 @@ async function snapshotPrStep(ctx) {
|
|
|
185
201
|
}
|
|
186
202
|
const { branch } = state.release;
|
|
187
203
|
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", branch, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
188
|
-
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true, branch };
|
|
204
|
+
if (found) { noteRound(ctx, { pr: found.number, head: found.headRefOid, outcome: "cut" }); return { pr: found.number, head: found.headRefOid, url: found.url, reused: true, branch }; }
|
|
189
205
|
const list = state.releaseBundle ?? [];
|
|
190
|
-
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", branch, "--title", `Release: ${branch} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx)])).trim();
|
|
206
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", branch, "--title", `Release: ${branch} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx) + await scorecardBody(ctx)])).trim();
|
|
191
207
|
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
192
208
|
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
193
209
|
state.steps["release-pr"] = { done: false, result: { pr: n } }; // writeRecord reads the PR number from here
|
|
194
210
|
await writeRecord(ctx);
|
|
195
211
|
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
212
|
+
noteRound(ctx, { pr: n, head: v?.headRefOid, outcome: "cut" });
|
|
196
213
|
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length, branch };
|
|
197
214
|
}
|
|
198
215
|
|
|
@@ -202,13 +219,23 @@ async function releasePrStep(ctx) {
|
|
|
202
219
|
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", staging, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
203
220
|
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true };
|
|
204
221
|
const list = await bundleList({ io, repo, head: staging, base: def });
|
|
205
|
-
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", staging, "--title", `Release: ${staging} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx), ...(ctx.config.preflight ? ["--draft"] : [])])).trim();
|
|
222
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", staging, "--title", `Release: ${staging} -> ${def}`, "--body", bundleBody(list) + await exemptionBody(ctx) + await scorecardBody(ctx), ...(ctx.config.preflight ? ["--draft"] : [])])).trim();
|
|
206
223
|
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
207
224
|
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
208
225
|
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
209
226
|
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length };
|
|
210
227
|
}
|
|
211
228
|
|
|
229
|
+
/** The per-release scorecard (#6084) as a PR-body section with its regressions line; "" on any error (never blocks the PR). */
|
|
230
|
+
async function scorecardBody({ io, repo, state }) {
|
|
231
|
+
try {
|
|
232
|
+
const sc = io.scorecard ? await io.scorecard({ repo, release: state.release?.version ?? state.id }) : await (await import("../stats/scorecard.mjs")).gatherScorecard({ repo, release: state.release?.version ?? state.id }, { gh: io.gh, useCache: false });
|
|
233
|
+
if (!sc) return "";
|
|
234
|
+
const { renderScorecard } = await import("../stats/scorecard.mjs");
|
|
235
|
+
return `\n\n${renderScorecard(sc)}\n`;
|
|
236
|
+
} catch { return ""; }
|
|
237
|
+
}
|
|
238
|
+
|
|
212
239
|
/** The live operator exemptions as a PR-body section (#5568, I20); "" when unmanaged, none, or `_active` is unreadable. */
|
|
213
240
|
async function exemptionBody({ io, repo, config }) {
|
|
214
241
|
if (!config.managed || !io.api) return "";
|
|
@@ -255,21 +282,22 @@ export async function rerunInfraFlakes({ io, repo, head, fence, policy }) {
|
|
|
255
282
|
const cfg = parseFlakeConfig(policy);
|
|
256
283
|
if (!fence?.lctx || !(cfg.rerunBudgetMin > 0)) return out;
|
|
257
284
|
const prior = await readFlakes(fence.lctx), done = prior.filter((f) => f.rerun).map((f) => `${f.sha}:${f.check}`);
|
|
258
|
-
const runs = json(await io.gh(["run", "list", "--repo", repo, "--commit", head, "--status", "failure", "--json", "databaseId,name", "--limit", "20"])) ?? [];
|
|
285
|
+
const runs = json(await io.gh(["run", "list", "--repo", repo, "--commit", head, "--status", "failure", "--json", "databaseId,name,attempt", "--limit", "20"])) ?? [];
|
|
259
286
|
const at = new Date(io.now?.() ?? Date.now()).toISOString(), entries = [];
|
|
260
287
|
let spentMin = 0;
|
|
261
288
|
for (const r of runs) {
|
|
262
289
|
const log = String(await io.gh(["run", "view", String(r.databaseId), "--repo", repo, "--log-failed"]).catch(() => "")).slice(-20_000);
|
|
263
290
|
const c = classifyFailure(log);
|
|
264
|
-
const [d] = planRerun({ jobs: [{ key: `${head}:${r.name}`, name: r.name, class: c.class }], done, spentMin, budgetMin: cfg.rerunBudgetMin });
|
|
291
|
+
const [d] = planRerun({ jobs: [{ key: `${head}:${r.name}`, name: r.name, class: c.class, attempt: r.attempt }], done, spentMin, budgetMin: cfg.rerunBudgetMin });
|
|
265
292
|
if (d.rerun) {
|
|
266
293
|
const f = await fenced(fence, { action: "rerun", key: `rerun-failed:${r.databaseId}` }, () => io.gh(["run", "rerun", String(r.databaseId), "--repo", repo, "--failed"]));
|
|
267
294
|
if (f.refused) { out.skipped.push({ name: r.name, why: f.refused }); continue; }
|
|
268
295
|
out.reran.push(r.name);
|
|
269
|
-
} else out.skipped.push({ name: r.name, why: d.why });
|
|
270
|
-
entries.push(flakeEntry({ check: r.name, signature: c.signature, kind: c.class === "infra" ? "infra" : "decision", sha: head, runIds: [r.databaseId], at, rerun: d.rerun }));
|
|
296
|
+
} else out.skipped.push({ name: r.name, why: d.why, ...(d.capped ? { capped: true } : {}) });
|
|
297
|
+
entries.push(flakeEntry({ check: r.name, signature: c.signature, kind: c.class === "infra" ? "infra" : "decision", sha: head, runIds: [r.databaseId], at, rerun: d.rerun, attempt: r.attempt, reuseForfeited: d.rerun }));
|
|
271
298
|
}
|
|
272
|
-
|
|
299
|
+
// #6014: a rerun entry carries the attempt count and the forfeited reuse; a cap refusal is a visible decision entry, never an infra one
|
|
300
|
+
await recordFlakes(fence.lctx, entries.filter((e) => e.kind === "infra" || e.attempt != null && !e.rerun && out.skipped.some((s) => s.capped && s.name === e.check)));
|
|
273
301
|
} catch { /* best effort */ }
|
|
274
302
|
return out;
|
|
275
303
|
}
|
|
@@ -309,7 +337,8 @@ async function promotionStep(ctx) {
|
|
|
309
337
|
if (gate.deployGate === "failure" && ctx.config.managed && io.git) { // #5568: policy loaded lazily (release-config imports this module)
|
|
310
338
|
const { readPolicy } = await import("./release-config.mjs");
|
|
311
339
|
const policy = readPolicy({ io, defaultBranch: ctx.def }).policy;
|
|
312
|
-
await rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy });
|
|
340
|
+
const rr = await rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy });
|
|
341
|
+
if (rr.reran.length) noteRound(ctx, { pr, head, outcome: "rerun-flake", cause: "flake" }); // #6013: a rerun that clears an infra failure is a flake round
|
|
313
342
|
}
|
|
314
343
|
const cmd = `gh pr merge ${pr} --repo ${repo} --merge --match-head-commit ${head}`;
|
|
315
344
|
if (!opts.merge && !ctx.config.autoMerge) { io.print(`GATE_PASS on #${pr}. Merge when ready:\n ${cmd}`); return { stopped: true, why: "GATE_PASS; promotion is opt-in (--merge or release.auto_merge)", cmd, head, gate }; }
|
|
@@ -42,6 +42,7 @@ function fakeIo(world = {}) {
|
|
|
42
42
|
throw new Error(`unexpected gh ${j}`);
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
|
+
if (w.scorecard) io.scorecard = w.scorecard;
|
|
45
46
|
return io;
|
|
46
47
|
}
|
|
47
48
|
const ok = async () => ({ ok: true });
|
|
@@ -191,6 +192,19 @@ describe("release job (#5211)", () => {
|
|
|
191
192
|
assert.ok(create && create.includes("--head") && create.includes("staging") && create.includes("main"));
|
|
192
193
|
});
|
|
193
194
|
|
|
195
|
+
it("#6084: the release PR body carries the scorecard with regressions; a scorecard failure still creates the PR", async () => {
|
|
196
|
+
const body = (c) => c[c.indexOf("--body") + 1];
|
|
197
|
+
const sc = { release: "v2", against: "v1", minN: 10, values: { first_pass_rate: 0.5 }, previous: { first_pass_rate: 0.9 }, verdicts: { first_pass_rate: "regressed" }, regressions: ["first_pass_rate"] };
|
|
198
|
+
const a = await promote({ releasePr: [], scorecard: async () => sc });
|
|
199
|
+
const withCard = body(a.io.calls.find((c) => c[1] === "create"));
|
|
200
|
+
assert.match(withCard, /Release scorecard v2/);
|
|
201
|
+
assert.match(withCard, /Regressions vs v1: first-pass merge rate/);
|
|
202
|
+
const b = await promote({ releasePr: [], scorecard: async () => { throw new Error("boom"); } });
|
|
203
|
+
const create = b.io.calls.find((c) => c[1] === "create");
|
|
204
|
+
assert.ok(create);
|
|
205
|
+
assert.doesNotMatch(body(create), /scorecard/i);
|
|
206
|
+
});
|
|
207
|
+
|
|
194
208
|
it("R5: a killed job resumes from the last completed step", async () => {
|
|
195
209
|
const io = fakeIo(), root = tmp(), id = newReleaseId();
|
|
196
210
|
const mod = await import("./release.mjs");
|
|
@@ -594,3 +608,21 @@ describe("release start|go routing (#5571)", () => {
|
|
|
594
608
|
await assert.rejects(releaseFromCli(["start", "--wave", "x"], opts([], [])), /--wave/);
|
|
595
609
|
});
|
|
596
610
|
});
|
|
611
|
+
|
|
612
|
+
describe("preflight staging-health gate (#6013)", () => {
|
|
613
|
+
const snap = { mode: "snapshot" };
|
|
614
|
+
const world = (runs) => ({ pm: (a) => (a[0] === "api" && /check-runs/.test(a[1]) ? JSON.stringify(runs) : undefined) });
|
|
615
|
+
it("refuses a snapshot cut on a red staging head and proceeds when green", async () => {
|
|
616
|
+
const mod = await import("./release.mjs");
|
|
617
|
+
const root = tmp(), id = newReleaseId();
|
|
618
|
+
const base = (io) => ({ io, repo: REPO, root, mounts: DISK, id, opts: {}, config: snap, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ "release-pr": ok, review: ok, fixes: ok, promotion: ok, "post-merge": ok }) });
|
|
619
|
+
const reds = await mod.runRelease(base(fakeIo(world([{ name: "black", status: "completed", conclusion: "failure", text: "" }]))));
|
|
620
|
+
assert.equal(reds.status, "refused");
|
|
621
|
+
assert.match(JSON.stringify(reds), /black/);
|
|
622
|
+
const saved = JSON.parse(readFileSync(join(root, id, "state.json"), "utf8").toString());
|
|
623
|
+
assert.equal(saved.rounds[0].outcome, "red-staging");
|
|
624
|
+
assert.equal(saved.rounds[0].cause, "regression");
|
|
625
|
+
const green = await mod.runRelease({ ...base(fakeIo(world([{ name: "black", status: "completed", conclusion: "success", text: "" }]))), id: newReleaseId() });
|
|
626
|
+
assert.notEqual(green.status, "refused");
|
|
627
|
+
});
|
|
628
|
+
});
|
package/bin/lean/retry.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export const PUSH_TRANSIENT_RE = /remote unpack failed|index-pack failed|RPC failed|unexpected disconnect|early EOF|the remote end hung up|HTTP\/?\s?5\d\d|returned error: 5\d\d|\b50[0234]\b|internal server error|bad gateway|service unavailable|gateway time-?out|connection (?:reset|timed out|refused)|timed out|could not resolve host|broken pipe|ETIMEDOUT|ECONNRESET|temporarily unavailable|\[remote rejected\][^\n]*\(failed\)|unable to write file|unable to create temporary object|unpacker error|failed to write object/i;
|
|
6
6
|
export const PUSH_PERMANENT_RE = /protected branch|GH006|GH013|repository rule violations|permission (?:denied|to .* denied)|denied to|\b403\b|authentication failed|not allowed|hook declined|pre-receive hook declined|\[rejected\]|non-fast-forward|fetch first/i;
|
|
7
|
-
export const GH_TRANSIENT_RE = /HTTP 5\d\d|\b50[0234]\b|secondary rate limit|rate limit exceeded|abuse detection|something went wrong|internal server error|bad gateway|service unavailable|ETIMEDOUT|ECONNRESET|connection reset|timed out|\bEOF\b|temporarily unavailable/i;
|
|
7
|
+
export const GH_TRANSIENT_RE = /HTTP 5\d\d|\b50[0234]\b|secondary rate limit|rate limit exceeded|abuse detection|something went wrong|internal server error|bad gateway|service unavailable|ETIMEDOUT|ECONNRESET|connection reset|timed out|\bEOF\b|temporarily unavailable|stream error|received from peer|error connecting to|check your internet connection|no such host|TLS handshake timeout|i\/o timeout|network is unreachable|connection refused|EAI_AGAIN|ENETUNREACH|ECONNREFUSED/i; // 2026-11-26: gh's network-failure texts (a lossy link dropped a merge into engine-error)
|
|
8
8
|
/** #4507: gh failing to parse its own input: a torn HTTP cache entry (JSON) or a half-written config (YAML). */
|
|
9
9
|
export const GH_PARSE_RE = /invalid character .{0,40}looking for|unexpected end of JSON input|cannot unmarshal|yaml: line \d+|yaml: unmarshal/i;
|
|
10
10
|
export const MERGE_TRANSIENT_RE = new RegExp(`${GH_TRANSIENT_RE.source}|${GH_PARSE_RE.source}|base branch was modified|head branch was modified|mergeability.*unknown|try again`, "i");
|
package/bin/lean/retry.test.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import { pollUntil } from "./retry.mjs";
|
|
3
|
+
import { pollUntil, GH_TRANSIENT_RE as NET_RE } from "./retry.mjs";
|
|
4
4
|
|
|
5
5
|
test("pollUntil returns the first truthy probe value, sleeping between tries", async () => {
|
|
6
6
|
let n = 0, t = 0; const sleeps = [];
|
|
@@ -14,3 +14,8 @@ test("pollUntil returns null once the timeout passes, probing at least once", as
|
|
|
14
14
|
assert.equal(v, null); assert.ok(n >= 3);
|
|
15
15
|
assert.equal(await pollUntil(() => null, { timeoutMs: -1, pollMs: 1, sleep: async () => {}, now: () => 0 }), null);
|
|
16
16
|
});
|
|
17
|
+
|
|
18
|
+
test("gh network failures are transient, validation errors are not (2026-11-26: a dropped connection during gh pr merge became an engine-error)", () => {
|
|
19
|
+
for (const t of ["error connecting to api.github.com", "check your internet connection", "dial tcp: lookup api.github.com: no such host", "net/http: TLS handshake timeout", "read tcp: i/o timeout", "connect: connection refused"]) assert.ok(NET_RE.test(t), t);
|
|
20
|
+
for (const t of ["HTTP 422: Validation Failed", "GraphQL: Could not resolve to a PullRequest", "HTTP 404: Not Found"]) assert.ok(!NET_RE.test(t), t);
|
|
21
|
+
});
|
package/bin/lean/rotator.mjs
CHANGED
|
@@ -213,3 +213,12 @@ export function quotaRequeue({ rotator, r, prior = null, delayMs, exclude = null
|
|
|
213
213
|
return { delayMs, rotated: false };
|
|
214
214
|
} catch { return null; }
|
|
215
215
|
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* #5988: the account to try after `failed` (account numbers: the ones whose login just failed) hit a `backend.auth` failure,
|
|
219
|
+
* tried first on resume. Never `failed` itself; null when no rotator or no other account is usable.
|
|
220
|
+
*/
|
|
221
|
+
export function nextAccountAfterAuthFailure(rotator, failed = []) {
|
|
222
|
+
if (!rotator || typeof rotator.pick !== "function") return null;
|
|
223
|
+
try { const p = rotator.pick({ exclude: new Set([...failed].map(Number).filter((n) => Number.isInteger(n) && n > 0)) }); return Number.isInteger(p?.account) ? p.account : null; } catch { return null; }
|
|
224
|
+
}
|
|
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
|
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
-
import { parseLive, openRotator, rotatorRetry, quotaRequeue, rotatorKind, realClaude, accountOfPid, ROTATOR_KINDS, HEADROOM_PCT } from "./rotator.mjs";
|
|
8
|
+
import { parseLive, openRotator, rotatorRetry, quotaRequeue, rotatorKind, nextAccountAfterAuthFailure, realClaude, accountOfPid, ROTATOR_KINDS, HEADROOM_PCT } from "./rotator.mjs";
|
|
9
9
|
import { laneBackendId, openLimits } from "./limits.mjs";
|
|
10
10
|
import { orchestrate, formatTable } from "./orchestrate.mjs";
|
|
11
11
|
import { parseExecution } from "./execution.mjs";
|
|
@@ -244,3 +244,13 @@ describe("account rotator: detection, staleness, exclusion, pick (#5205)", () =>
|
|
|
244
244
|
assert.equal(accountOfPid(undefined, { procRoot: proc }), null);
|
|
245
245
|
});
|
|
246
246
|
});
|
|
247
|
+
|
|
248
|
+
describe("#5988: next account after an auth failure", () => {
|
|
249
|
+
const fake = (accounts) => ({ pick: ({ exclude }) => { const a = accounts.find((n) => !exclude.has(n)); return a ? { account: a } : { account: null }; } });
|
|
250
|
+
it("picks an account other than the failed one; null when none is left or there is no rotator", () => {
|
|
251
|
+
assert.equal(nextAccountAfterAuthFailure(fake([1, 2, 3]), [1]), 2);
|
|
252
|
+
assert.equal(nextAccountAfterAuthFailure(fake([1, 2]), [1, 2]), null);
|
|
253
|
+
assert.equal(nextAccountAfterAuthFailure(null, [1]), null);
|
|
254
|
+
assert.equal(nextAccountAfterAuthFailure({ pick: () => { throw new Error("x"); } }, [1]), null);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -57,7 +57,7 @@ export function isActionsEndpoint(endpoint) {
|
|
|
57
57
|
* `GET /agents -> {sandboxes}` is the router's live sandbox list (#5422, `inventory()`; malformed or any error throws).
|
|
58
58
|
* Optional relay (#4778): `GET /sandboxes/:id/relay -> {requests: [{rid, argv}]}` lists a sandbox's pending read-only capability
|
|
59
59
|
* requests (404/405 or malformed = none, an older router) and `POST /sandboxes/:id/relay/:rid` `{rc, stdout, stderr}` answers one.
|
|
60
|
-
* Optional `GET /status -> {free: N, online?, total?}` is the pool's free slots (#4540); without `online` the agents of `GET /agents` give it (#4788). Anything else (404, error, malformed) is unknown (null).
|
|
60
|
+
* Optional `GET /status[?repo=<slug>] -> {free: N, online?, total?}` is the pool's free slots (#4540); `?repo=` (#6041) limits `/status` and `/agents` to the agents the repo may use (router.json `repos.<slug>.agents` / `exclude_agents`); without `online` the agents of `GET /agents` give it (#4788). Anything else (404, error, malformed) is unknown (null).
|
|
61
61
|
*/
|
|
62
62
|
export function httpTransport({ endpoint, token = null, fetchFn = globalThis.fetch }) {
|
|
63
63
|
const root = String(endpoint ?? "").replace(/\/+$/, "");
|
|
@@ -75,7 +75,10 @@ export function httpTransport({ endpoint, token = null, fetchFn = globalThis.fet
|
|
|
75
75
|
const hop = r.status === 401 && ["router", "agent"].includes(r.data?.hop) ? r.data.hop : null;
|
|
76
76
|
const who = hop === "agent" && typeof r.data?.agent === "string" ? `agent ${r.data.agent.slice(0, 64)}` : hop;
|
|
77
77
|
const reason = hop && typeof r.data?.reason === "string" ? r.data.reason.replace(/^(router|agent) auth: /, "").replace(/[^\x20-\x7e]/g, "").slice(0, 80) : "";
|
|
78
|
-
|
|
78
|
+
// 2026-11-26: non-auth failures keep the pool's error text (printable, ≤160 chars, never a token), so a seed 409/422 says why
|
|
79
|
+
const live = typeof token === "function" ? (() => { try { return token(); } catch { return null; } })() : token;
|
|
80
|
+
const err = !hop && typeof r.data?.error === "string" ? redact(r.data.error, [live]).replace(/[^\x20-\x7e]/g, "").slice(0, 160) : "";
|
|
81
|
+
const e = new Error(`sandbox ${what}: HTTP ${r.status}${who ? ` (${who} auth${reason ? `: ${reason}` : ""})` : ""}${err ? `: ${err}` : ""}`);
|
|
79
82
|
e.status = r.status;
|
|
80
83
|
if (hop) e.hop = hop;
|
|
81
84
|
if (typeof r.data?.code === "string" && r.data.code.startsWith("pool.")) e.poolCode = r.data.code; // #5985: the pool's refusal code reaches the deferral row
|
|
@@ -88,8 +91,9 @@ export function httpTransport({ endpoint, token = null, fetchFn = globalThis.fet
|
|
|
88
91
|
return e;
|
|
89
92
|
};
|
|
90
93
|
const p = (id) => `/sandboxes/${encodeURIComponent(id)}`;
|
|
94
|
+
const placedEngine = new Map(); // sandbox id -> lane-engine version of the agent the router placed it on (R3: the ran version is recorded even when the lane reports none)
|
|
91
95
|
return {
|
|
92
|
-
async launch(spec) { const r = await call("POST", "/sandboxes", spec); if (!r.ok) throw fail("launch", r); return r.data ?? {}; },
|
|
96
|
+
async launch(spec) { const r = await call("POST", "/sandboxes", spec); if (!r.ok) throw fail("launch", r); if (typeof r.data?.engine_version === "string" && typeof spec?.id === "string") placedEngine.set(spec.id, r.data.engine_version); return r.data ?? {}; },
|
|
93
97
|
/** #4912: hand the lane to a ready warm sandbox. 200/201 = claimed; 204/404/405 (none ready, or a pool without warm sandboxes) = null. */
|
|
94
98
|
async claim(spec) { const r = await call("POST", "/sandboxes/claim", spec); if (r.status === 200 || r.status === 201) return r.data ?? {}; if (r.status === 204 || r.status === 404 || r.status === 405) return null; throw fail("claim", r); },
|
|
95
99
|
async status(id) {
|
|
@@ -100,7 +104,7 @@ export function httpTransport({ endpoint, token = null, fetchFn = globalThis.fet
|
|
|
100
104
|
return s === "running" || s === "pending" || s === "starting" || s === "paused" ? "running" : s === "gone" ? "gone" : "exited";
|
|
101
105
|
},
|
|
102
106
|
async logs(id, cursor = 0) { const r = await call("GET", `${p(id)}/logs?cursor=${encodeURIComponent(cursor)}`); return r.ok ? { text: String(r.data?.text ?? ""), cursor: r.data?.cursor ?? cursor } : { text: "", cursor }; },
|
|
103
|
-
async result(id) { const r = await call("GET", `${p(id)}/result`); if (r.status === 401) throw Object.assign(fail("result", r), { transient: true }); if (r.ok && r.data?.disk_pressure === true) return { terminalReason: "deferred", code: OUTCOME_CODES.SANDBOX_DISK_PRESSURE, retryInSeconds: 120, cost_usd: 0, detail: `sandbox ${id} was stopped to save the host drive (disk pressure); worktree and volume kept, requeued to resume` }; /* #5891 */ if (r.ok && r.data?.drained === true) return { terminalReason: "deferred", code: OUTCOME_CODES.SANDBOX_CAPACITY, retryInSeconds: 60, cost_usd: 0, detail: `sandbox ${id} was drained to free capacity for reserved work (${String(r.data.reason ?? "").slice(0, 120)}); rescheduled` }; /* #5856 */
|
|
107
|
+
async result(id) { const r = await call("GET", `${p(id)}/result`); if (r.status === 401) throw Object.assign(fail("result", r), { transient: true }); if (r.ok && r.data?.disk_pressure === true) return { terminalReason: "deferred", code: OUTCOME_CODES.SANDBOX_DISK_PRESSURE, retryInSeconds: 120, cost_usd: 0, detail: `sandbox ${id} was stopped to save the host drive (disk pressure); worktree and volume kept, requeued to resume` }; /* #5891 */ if (r.ok && r.data?.drained === true) return { terminalReason: "deferred", code: OUTCOME_CODES.SANDBOX_CAPACITY, retryInSeconds: 60, cost_usd: 0, detail: `sandbox ${id} was drained to free capacity for reserved work (${String(r.data.reason ?? "").slice(0, 120)}); rescheduled` }; /* #5856 */ if (r.ok && r.data && typeof r.data === "object") { const v = r.data.engineVersion ?? r.data.engine_version ?? r.data.forge_version ?? /ForgeDock\s*[·-]\s*v?(\d+\.\d+(?:\.\d+)?)/.exec(String(r.data.banner ?? r.data.log ?? ""))?.[1]; const pv = v ?? placedEngine.get(id); return pv && !r.data.engineVersion ? { ...r.data, engineVersion: String(pv) } : r.data; } return null; }, /* #5931 */
|
|
104
108
|
async usage(id) { const r = await call("GET", `${p(id)}/usage`); return r.ok && Number.isFinite(Number(r.data?.minutes)) ? { minutes: Number(r.data.minutes), ...(typeof r.data.agent === "string" && r.data.agent ? { agent: r.data.agent } : {}) } : null; }, // agent: #4549, optional
|
|
105
109
|
async stop(id) { const r = await call("POST", `${p(id)}/stop`); if (r.ok) return true; if (r.status === 404 || r.status === 405) return false; throw fail("stop", r); },
|
|
106
110
|
async destroy(id) { const r = await call("DELETE", p(id)); if (r.ok || r.status === 404) return true; throw fail("destroy", r); },
|
|
@@ -161,19 +165,21 @@ export function httpTransport({ endpoint, token = null, fetchFn = globalThis.fet
|
|
|
161
165
|
if (!list) throw fail("agents", r);
|
|
162
166
|
return list.some((a) => a?.ok === true && !a.paused && (!agent || a.name === agent));
|
|
163
167
|
},
|
|
164
|
-
async capacity() {
|
|
168
|
+
async capacity({ repo } = {}) {
|
|
169
|
+
const q = typeof repo === "string" && repo ? `?repo=${encodeURIComponent(repo)}` : ""; // #6041: only the repo's allowed agents count
|
|
165
170
|
// `free` (#4540) and agent liveness `online`/`total` (#4547) are each optional; none valid is unknown.
|
|
166
171
|
const ok = (v) => Number.isInteger(v) && v >= 0;
|
|
167
172
|
let out = {}, reached = false, lastErr = null;
|
|
168
173
|
try {
|
|
169
|
-
const r = await call("GET",
|
|
174
|
+
const r = await call("GET", `/status${q}`);
|
|
170
175
|
reached = true;
|
|
171
|
-
if (r.ok) { const { free, online, total } = r.data ?? {};
|
|
176
|
+
if (r.ok) { const { free, online, total } = r.data ?? {}; const agents = (Array.isArray(r.data?.agents) ? r.data.agents : []).filter((a) => typeof a?.engine_version === "string").map((a) => ({ name: a.name, ok: a.ok === true, paused: a.paused === true, engine_version: a.engine_version })); // R6: per-agent lane engines
|
|
177
|
+
out = { ...(ok(free) ? { free } : {}), ...(ok(online) ? { online } : {}), ...(ok(total) ? { total } : {}), ...(agents.length ? { agents } : {}) }; }
|
|
172
178
|
} catch (e) { out = {}; lastErr = e; }
|
|
173
179
|
if (out.online === undefined || out.load_per_core === undefined) {
|
|
174
180
|
// #4788: a router without /status liveness: online = agents answering and not paused, as bin/pool/router.mjs status() does.
|
|
175
181
|
try {
|
|
176
|
-
const r = await call("GET",
|
|
182
|
+
const r = await call("GET", `/agents${q}`);
|
|
177
183
|
reached = true;
|
|
178
184
|
const list = r.ok && Array.isArray(r.data?.agents) ? r.data.agents : null;
|
|
179
185
|
if (list && out.online === undefined) out = { ...out, online: list.filter((a) => a?.ok === true && !a.paused).length, total: list.length };
|
|
@@ -280,6 +286,7 @@ export function remoteProvider({ batch, repo, settings = {}, name = "remote", tr
|
|
|
280
286
|
const envSnap = settings.forgeYaml ? readEnvSnapshots(settings.forgeYaml) : null; // env.snapshots: off unless enabled
|
|
281
287
|
const spec = {
|
|
282
288
|
id, issue, batch: batch.id, image: settings.image ?? null,
|
|
289
|
+
...(typeof settings.minLaneEngine === "string" && settings.minLaneEngine ? { min_lane_engine: settings.minLaneEngine } : {}), // R2: the router drops lower-engine agents (pool.engine_old deferral)
|
|
283
290
|
priority: "borrow", // #5856: lanes run on leftover capacity; a pool with reservations throttles/drains them for reserved work
|
|
284
291
|
repo: { slug: repo, url: repo ? `https://github.com/${repo}.git` : null, ref: li >= 0 ? args[li + 1] ?? null : null },
|
|
285
292
|
...(settings.laneTools?.length ? { lane_tools: settings.laneTools } : {}), // #5650: per-repo lane image
|
|
@@ -334,7 +341,7 @@ export function remoteProvider({ batch, repo, settings = {}, name = "remote", tr
|
|
|
334
341
|
async capacity() {
|
|
335
342
|
// #5048: no capacity() is unknown (null); a transport error propagates, so the caller can report the pool down
|
|
336
343
|
if (typeof transport.capacity !== "function") return null;
|
|
337
|
-
return (await transport.capacity()) ?? null;
|
|
344
|
+
return (await transport.capacity({ repo })) ?? null;
|
|
338
345
|
},
|
|
339
346
|
/** #5985: the pool's usage-history rows; null when the transport has none. */
|
|
340
347
|
async usageHistory() { return typeof transport.usageHistory === "function" ? (await transport.usageHistory()) ?? null : null; },
|
package/bin/lean/schedd.mjs
CHANGED
|
@@ -79,7 +79,7 @@ export function batchVerdicts(root, { now = Date.now(), windowMin = DEFAULT_STAL
|
|
|
79
79
|
const b = openBatch(root, id);
|
|
80
80
|
if (!b.readPlan()?.daemon || b.isTerminal()) continue;
|
|
81
81
|
const state = b.store.peek(), stall = evaluateDispatchStall(state, { held: b.readHeld(), parallel: b.readParallel(), hosted: false, paused: b.readPause?.() ?? null, lastProgressMs: b.lastProgressMs(), now, windowMin, lanesAliveMs: lanesAlive(b, state) });
|
|
82
|
-
const decision = stall ? decideStallAction(stall, { recovery: readHealth(b.dir)?.stallRecovery ?? null, hosted: false }) : null;
|
|
82
|
+
const decision = stall ? decideStallAction(stall, { recovery: readHealth(b.dir)?.stallRecovery ?? null, hosted: false, now, windowMin }) : null;
|
|
83
83
|
out.push(batchVerdict(id, stall, decision));
|
|
84
84
|
} catch { /* one unreadable batch has no verdict */ }
|
|
85
85
|
}
|
|
@@ -288,7 +288,7 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
288
288
|
if (closing) return;
|
|
289
289
|
let b, st;
|
|
290
290
|
try { b = openBatch(root, id); if (b.readReport() || b.readCancel() || !b.pendingIssues().length) return; st = b.store.load(); } catch { return; }
|
|
291
|
-
if (st?.breaker && !st.breaker.transport) return; // a tripped breaker holds the batch for an operator --resume (a re-host would stop again at once)
|
|
291
|
+
if (st?.breaker && !st.breaker.transport && !st.breaker.environmental) return; // a tripped breaker holds the batch for an operator --resume (a re-host would stop again at once)
|
|
292
292
|
const at = Math.min(...b.pendingIssues().map((n) => Number(st?.notBefore?.[n]) || Infinity));
|
|
293
293
|
if (!Number.isFinite(at)) return; // nothing waits on the clock: a deliberate hold stays for --resume
|
|
294
294
|
if (at <= Date.now()) return; // the run that just ended already saw this retry-at pass and did not admit: re-hosting would loop every second
|
|
@@ -315,7 +315,7 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
315
315
|
const b = openBatch(root, id);
|
|
316
316
|
if (b.readCancel()) return;
|
|
317
317
|
const st = b.store.load();
|
|
318
|
-
if (st?.breaker && !st.breaker.transport) return;
|
|
318
|
+
if (st?.breaker && !st.breaker.transport && !st.breaker.environmental) return;
|
|
319
319
|
sig = JSON.stringify([b.unrunAdds(), b.unrunRequeues().map((e) => e.issue ?? e)]);
|
|
320
320
|
if (!b.unrunAdds().length && !b.unrunRequeues().length) { rehostedUnrun.delete(id); return; }
|
|
321
321
|
} catch { return; }
|
|
@@ -533,7 +533,7 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
533
533
|
return closing;
|
|
534
534
|
};
|
|
535
535
|
// #5966: a self-initiated stop (version handover, stall recovery). Under a systemd unit the process exits non-zero after a bounded
|
|
536
|
-
// drain so `Restart=` starts the successor (a hard
|
|
536
|
+
// drain so `Restart=` starts the successor (a hard bound fires even if close() hangs; path-scoped, see selfStop, #5983); without a unit it starts the successor and
|
|
537
537
|
// waits for it to listen, retrying once, then exits non-zero instead of lingering as an unreachable zombie.
|
|
538
538
|
const defaultProbe = () => new Promise((r) => {
|
|
539
539
|
if (process.platform === "win32") return r(true);
|
|
@@ -555,9 +555,13 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
555
555
|
stopCode = 1;
|
|
556
556
|
const underUnit = ["active", "activating"].includes(unit());
|
|
557
557
|
let hard;
|
|
558
|
-
|
|
558
|
+
// Path-scoped bound: under a unit it covers the whole stop (close only); unitless it covers close(), then a last-resort bound
|
|
559
|
+
// outlasts the two successor waits and the re-host (a flat hardExitMs equals the sum of those phases and would exit unhosted).
|
|
560
|
+
const arm = (ms, what) => { if (!exit) return undefined; const t = setTimeout(() => { log(`schedd: ${what} did not finish within ${ms} ms, exiting`); exit(1); }, ms); t.unref?.(); return t; };
|
|
561
|
+
hard = arm(hardExitMs, "stop");
|
|
559
562
|
try {
|
|
560
563
|
await close();
|
|
564
|
+
if (!underUnit && exit) { clearTimeout(hard); hard = arm(2 * successorMs + 2 * successorPollMs + hardExitMs, "successor handover"); }
|
|
561
565
|
const spawnOnce = () => { try { respawnFn?.(); } catch (e) { log(`schedd: respawn failed: ${e?.message ?? e}`); } };
|
|
562
566
|
spawnOnce();
|
|
563
567
|
if (probeFn && !underUnit) {
|
|
@@ -676,7 +680,8 @@ export async function startDaemon({ dir = schedDir(), runBatch, idleMs = Number(
|
|
|
676
680
|
// ready set is recovered once (health.json stallRecovery survives a daemon restart), a repeat alerts with the probed cause.
|
|
677
681
|
let probe = null;
|
|
678
682
|
try { probe = plan.env ? probeEnv(mergeEnv(process.env, plan.env)) : null; } catch { probe = null; }
|
|
679
|
-
const decision = decideStallAction(stall, { recovery: readHealth(b.dir)?.stallRecovery ?? null, probe, hosted: isHosted });
|
|
683
|
+
const decision = decideStallAction(stall, { recovery: readHealth(b.dir)?.stallRecovery ?? null, probe, hosted: isHosted, now, windowMin: stallMin });
|
|
684
|
+
if (decision.action === "wait") continue; // #6082: a capacity wait or a recovery still inside its backoff
|
|
680
685
|
if (decision.action === "alert") {
|
|
681
686
|
if (recordStallAlert(b, stall, { cause: decision.cause })) log(`schedd: batch ${id} needs you: ${stall.detail}${decision.cause ? `; probed: ${decision.cause}` : ""}`);
|
|
682
687
|
continue;
|
package/bin/lean/schedd.test.mjs
CHANGED
|
@@ -582,7 +582,7 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
|
|
|
582
582
|
} finally { await d.close(); }
|
|
583
583
|
});
|
|
584
584
|
|
|
585
|
-
it("#5806: a hosted runner wedged in setup restarts the daemon
|
|
585
|
+
it("#5806: a hosted runner wedged in setup restarts the daemon (decision logged); the same stall again is healed again after the backoff, no alert (#6082)", async () => {
|
|
586
586
|
const dir = tmpDir("schedd-stall-setup-"), root = join(dir, "batches"), id = "b20261121-000000-5806";
|
|
587
587
|
const b = openBatch(root, id);
|
|
588
588
|
b.writePlan({ daemon: true, repo: "o/r", created: new Date().toISOString() });
|
|
@@ -598,10 +598,9 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
|
|
|
598
598
|
assert.ok(lines.some((l) => /FORGE:DECISION batch .+ stall-recovery: restart the hosting schedd/.test(l)), lines.join("\n"));
|
|
599
599
|
assert.equal(JSON.parse(readFileSync(join(b.dir, "health.json"), "utf8")).stallRecovery.action, "restart-daemon");
|
|
600
600
|
utimesSync(join(b.dir, "state.json"), old, old);
|
|
601
|
-
await until(() =>
|
|
602
|
-
|
|
603
|
-
assert.
|
|
604
|
-
assert.match(readFileSync(join(b.dir, "batch.log"), "utf8"), /BATCH UNHEALTHY .*\(stuck in setup, 0\/2 issues read\).*probed: stalled again after auto-recovery/);
|
|
601
|
+
await until(() => restarts.length >= 2, 8000);
|
|
602
|
+
assert.equal(JSON.parse(readFileSync(join(b.dir, "health.json"), "utf8")).stallRecovery.count >= 2, true, "a second recovery is recorded");
|
|
603
|
+
assert.doesNotMatch(readFileSync(join(b.dir, "batch.log"), "utf8"), /BATCH UNHEALTHY/, "no operator alert while self-heal has attempts left");
|
|
605
604
|
} finally { await d.close(); }
|
|
606
605
|
});
|
|
607
606
|
|
|
@@ -660,6 +659,24 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
|
|
|
660
659
|
} finally { await d.close(); }
|
|
661
660
|
});
|
|
662
661
|
|
|
662
|
+
it("#6042: a batch whose breaker is environmental is re-hosted by the timer", async () => {
|
|
663
|
+
const dir = tmpDir("schedd-rehost-env-"), root = join(dir, "batches"), id = "b20261031-000000-6042";
|
|
664
|
+
const calls = [];
|
|
665
|
+
const runBatch = async ({ argv, sink }) => {
|
|
666
|
+
calls.push(argv);
|
|
667
|
+
const b = openBatch(root, id);
|
|
668
|
+
if (argv[0] !== "--resume") { b.writePlan({ daemon: true, repo: "o/r" }); b.store.save({ v: 1, order: [1], results: {}, running: {}, pending: [1], notBefore: { 1: Date.now() + 300 }, breaker: { at: Date.now(), errors: 3, environmental: true } }); }
|
|
669
|
+
sink.batch({ id, dir: b.dir });
|
|
670
|
+
return {};
|
|
671
|
+
};
|
|
672
|
+
const d = await startDaemon({ dir, root, runBatch, log: () => {}, resumeOnStart: false });
|
|
673
|
+
try {
|
|
674
|
+
await request(await connectDaemon({ dir, spawnDaemon: null }), { op: "submit", argv: ["1"], cwd: dir, env: {} });
|
|
675
|
+
await until(() => calls.length >= 2, 8000);
|
|
676
|
+
assert.equal(calls[1][0], "--resume");
|
|
677
|
+
} finally { await d.close(); }
|
|
678
|
+
});
|
|
679
|
+
|
|
663
680
|
it("#4454: close() stops every hosted batch loop before releasing the lock; no batch admits a lane after close()", async () => {
|
|
664
681
|
const dir = tmpDir("schedd-stop-"), root = join(dir, "batches"), lock = scheddPaths(dir).lock;
|
|
665
682
|
const started = { a: [], b: [] }, stoppedWithLock = {};
|
|
@@ -855,6 +872,49 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
|
|
|
855
872
|
assert.deepEqual(exits2, [1]);
|
|
856
873
|
});
|
|
857
874
|
|
|
875
|
+
it("#5983: unitless, the hard bound does not cut the successor waits short of the re-host; a hung close still exits", async () => {
|
|
876
|
+
const dir = tmpDir("schedd-bound-"), lines = [], exits = [];
|
|
877
|
+
let version = "1.51.0";
|
|
878
|
+
const d = await startDaemon({ dir, root: join(dir, "batches"), log: (m) => lines.push(m), resumeOnStart: false, lockCheckMs: 30, installedVersion: () => version, unit: () => null,
|
|
879
|
+
exit: (c) => exits.push(c), hardExitMs: 100, respawn: () => {}, probe: async () => false, successorMs: 150, successorPollMs: 10, runBatch: async () => ({}) });
|
|
880
|
+
version = "1.52.0";
|
|
881
|
+
await until(() => d.rehosted());
|
|
882
|
+
try {
|
|
883
|
+
assert.equal(d.rehosted().running, true, "re-hosted after waits longer than hardExitMs");
|
|
884
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
885
|
+
assert.deepEqual(exits, [], "the hard timer did not fire");
|
|
886
|
+
} finally { await d.rehosted().close(); }
|
|
887
|
+
const dir2 = tmpDir("schedd-bound2-"), exits2 = [];
|
|
888
|
+
let v2 = "1.51.0";
|
|
889
|
+
await startDaemon({ dir: dir2, root: join(dir2, "batches"), log: () => {}, resumeOnStart: false, lockCheckMs: 30, installedVersion: () => v2, unit: () => null,
|
|
890
|
+
exit: (c) => exits2.push(c), hardExitMs: 150, stopMs: 400, respawn: () => {}, probe: async () => false, successorMs: 50, successorPollMs: 10,
|
|
891
|
+
runBatch: ({ sink }) => { sink.batch({ id: "x", dir: dir2 }); return new Promise(() => {}); } }).then(async (d3) => {
|
|
892
|
+
request(await connectDaemon({ dir: dir2, spawnDaemon: null }), { op: "submit", argv: ["x"], cwd: dir2, env: {} }).catch(() => {});
|
|
893
|
+
await until(() => d3.running);
|
|
894
|
+
v2 = "1.52.0";
|
|
895
|
+
await until(() => exits2.length > 0);
|
|
896
|
+
assert.deepEqual(exits2, [1]);
|
|
897
|
+
await until(() => d3.rehosted()); // the stop carries on after the bound fired; release what it re-hosts
|
|
898
|
+
await d3.rehosted().close();
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it("#5983: unitless re-host that hangs still exits via the last-resort timer", async () => {
|
|
903
|
+
const dir = tmpDir("schedd-bound3-"), exits = [];
|
|
904
|
+
let version = "1.51.0";
|
|
905
|
+
const d = await startDaemon({ dir, root: join(dir, "batches"), log: () => {}, resumeOnStart: false, lockCheckMs: 30, installedVersion: () => version, unit: () => null,
|
|
906
|
+
exit: (c) => exits.push(c), hardExitMs: 100, respawn: () => {}, probe: async () => false, successorMs: 30, successorPollMs: 10,
|
|
907
|
+
rehost: () => new Promise(() => {}), runBatch: async () => ({}) });
|
|
908
|
+
try {
|
|
909
|
+
version = "1.52.0";
|
|
910
|
+
await until(() => exits.length > 0);
|
|
911
|
+
assert.deepEqual(exits, [1]);
|
|
912
|
+
} finally {
|
|
913
|
+
// the mocked exit leaves the daemon's timers and socket alive: close it (bounded, the re-host never settles) so the test file can exit
|
|
914
|
+
await Promise.race([d.close(), new Promise((r) => setTimeout(r, 1000).unref())]);
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
858
918
|
it("#5984 handover: settled() outlives closed until the successor is spawned and probed (CLI exits only after it)", async () => {
|
|
859
919
|
const dir = tmpDir("schedd-settled-"), order = [];
|
|
860
920
|
let version = "1.51.0";
|
package/bin/lean/selfreview.mjs
CHANGED
|
@@ -69,7 +69,7 @@ export const PLANNER_TIGHTENING = Object.freeze({
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
const PATH_RE = /[\w@.-]+(?:\/[\w@.*-]+)+\.\w+|[\w@.-]+\/[\w@.*-]+\/?/g;
|
|
72
|
-
const NEEDS_RESULT = new Set(["requirement_unimplemented", "untracked_deferral"]);
|
|
72
|
+
const NEEDS_RESULT = new Set(["requirement_unimplemented", "requirement_no_status", "untracked_deferral"]);
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* The deterministic conformance findings of the current tree: [{code, kind, detail, section}]. Validate commands are not
|
|
@@ -27,7 +27,10 @@ export const ENTRY_SEP = "\n\n---\n\n";
|
|
|
27
27
|
/** Markers posted once and edited in place (the marker leads the comment body, so anchored readers still match). */
|
|
28
28
|
export const UPSERT_MARKERS = Object.freeze(["FORGE:INVESTIGATION", "FORGE:IMPLEMENTATION", "FORGE:PARKED"]);
|
|
29
29
|
/** #5979: markers re-derived on every pass; a repeat of the same state posts nothing (FACTS and DEPENDENCY are edited in place, NEEDS_HUMAN stays a new comment when it changed). */
|
|
30
|
-
export const IN_PLACE_MARKERS = Object.freeze(["FORGE:FACTS", "FORGE:DEPENDENCY", "FORGE:NEEDS_HUMAN"]);
|
|
30
|
+
export const IN_PLACE_MARKERS = Object.freeze(["FORGE:FACTS", "FORGE:DEPENDENCY", "FORGE:NEEDS_HUMAN", "FORGE:AMENDMENT-STATE"]);
|
|
31
|
+
/** #5931: the hidden tag that keys an in-place comment to its issue's contract hash: one comment per (marker, hash), edited in place while the hash holds. */
|
|
32
|
+
export const contractKey = (hash) => (hash ? `<!-- forge-contract hash=${String(hash).replace(/[^\w]/g, "")} -->` : "");
|
|
33
|
+
export const contractKeyOf = (body) => /<!-- forge-contract hash=(\w+) -->/.exec(String(body ?? ""))?.[1] ?? null;
|
|
31
34
|
|
|
32
35
|
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
36
|
const markLine = (m) => `<!-- ${m} -->`;
|