forgedock 1.67.0 → 1.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/bin/config-schema.mjs +1 -0
  2. package/bin/engine/outcome-codes.mjs +1 -0
  3. package/bin/engine-cli.mjs +103 -21
  4. package/bin/engine.mjs +10 -0
  5. package/bin/forgedock.mjs +17 -1
  6. package/bin/help-text.mjs +1 -0
  7. package/bin/lean/admission.mjs +21 -0
  8. package/bin/lean/admission.test.mjs +30 -0
  9. package/bin/lean/advisory.test.mjs +39 -15
  10. package/bin/lean/amendment-schema.mjs +3 -4
  11. package/bin/lean/attempts.mjs +34 -31
  12. package/bin/lean/attempts.test.mjs +33 -19
  13. package/bin/lean/basered.mjs +26 -0
  14. package/bin/lean/batch-health.mjs +17 -12
  15. package/bin/lean/batch-health.test.mjs +39 -11
  16. package/bin/lean/batch.mjs +11 -1
  17. package/bin/lean/batch.test.mjs +51 -2
  18. package/bin/lean/capsample.mjs +25 -0
  19. package/bin/lean/ci-gate.mjs +2 -90
  20. package/bin/lean/ci-gate.test.mjs +1 -127
  21. package/bin/lean/ci-precheck.mjs +25 -8
  22. package/bin/lean/ci-precheck.test.mjs +24 -0
  23. package/bin/lean/clear-breaker.test.mjs +4 -3
  24. package/bin/lean/commentstate.mjs +10 -5
  25. package/bin/lean/commentstate.test.mjs +12 -1
  26. package/bin/lean/conformance.e2e.test.mjs +9 -6
  27. package/bin/lean/conformance.mjs +62 -197
  28. package/bin/lean/conformance.test.mjs +46 -376
  29. package/bin/lean/depcache.mjs +102 -10
  30. package/bin/lean/depcache.test.mjs +105 -0
  31. package/bin/lean/docsgate.mjs +0 -32
  32. package/bin/lean/docsgate.test.mjs +2 -23
  33. package/bin/lean/effects-cap.test.mjs +9 -1
  34. package/bin/lean/effects-killtree.test.mjs +35 -0
  35. package/bin/lean/effects.mjs +57 -25
  36. package/bin/lean/engine-readmit.test.mjs +35 -0
  37. package/bin/lean/envgap.mjs +111 -0
  38. package/bin/lean/envgap.test.mjs +64 -0
  39. package/bin/lean/execution.mjs +13 -4
  40. package/bin/lean/execution.test.mjs +33 -0
  41. package/bin/lean/failure-census.mjs +170 -0
  42. package/bin/lean/failure-census.test.mjs +59 -0
  43. package/bin/lean/failure-stop.mjs +12 -1
  44. package/bin/lean/failure-stop.test.mjs +14 -1
  45. package/bin/lean/guardgate.test.mjs +2 -3
  46. package/bin/lean/heavy.mjs +33 -4
  47. package/bin/lean/heavy.test.mjs +38 -6
  48. package/bin/lean/hostconfig.mjs +54 -0
  49. package/bin/lean/hostconfig.test.mjs +67 -0
  50. package/bin/lean/hotarea.mjs +0 -36
  51. package/bin/lean/hotarea.test.mjs +1 -22
  52. package/bin/lean/issuewatch-verify.mjs +19 -4
  53. package/bin/lean/issuewatch.mjs +21 -4
  54. package/bin/lean/issuewatch.test.mjs +48 -1
  55. package/bin/lean/lane-audit-gap.mjs +66 -0
  56. package/bin/lean/lane-audit-gap.test.mjs +59 -0
  57. package/bin/lean/lane-audit-llm.mjs +52 -0
  58. package/bin/lean/lane-audit-llm.test.mjs +57 -0
  59. package/bin/lean/lane-audit-query.mjs +47 -0
  60. package/bin/lean/lane-audit-query.test.mjs +44 -0
  61. package/bin/lean/lane-audit-signatures.mjs +33 -0
  62. package/bin/lean/lane-audit.mjs +110 -0
  63. package/bin/lean/lane-audit.test.mjs +97 -0
  64. package/bin/lean/lane-recovery.test.mjs +33 -0
  65. package/bin/lean/lanecheck.mjs +5 -3
  66. package/bin/lean/lanecheck.test.mjs +6 -0
  67. package/bin/lean/lean.mjs +247 -152
  68. package/bin/lean/lean.test.mjs +502 -206
  69. package/bin/lean/limits.mjs +17 -0
  70. package/bin/lean/limits.test.mjs +15 -1
  71. package/bin/lean/live-execution.mjs +24 -2
  72. package/bin/lean/live-execution.test.mjs +62 -0
  73. package/bin/lean/orchestrate-attempts.test.mjs +17 -9
  74. package/bin/lean/orchestrate-dispatch-placement.test.mjs +81 -0
  75. package/bin/lean/orchestrate-envhold.test.mjs +62 -1
  76. package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
  77. package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
  78. package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
  79. package/bin/lean/orchestrate-pause.test.mjs +53 -1
  80. package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
  81. package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
  82. package/bin/lean/orchestrate-stacking.test.mjs +10 -0
  83. package/bin/lean/orchestrate.mjs +215 -42
  84. package/bin/lean/postdeploy-check.test.mjs +1 -3
  85. package/bin/lean/precheck.mjs +20 -0
  86. package/bin/lean/preflight.mjs +110 -14
  87. package/bin/lean/preflight.test.mjs +64 -4
  88. package/bin/lean/prompts.mjs +11 -21
  89. package/bin/lean/recurrence.mjs +6 -148
  90. package/bin/lean/recurrence.test.mjs +11 -147
  91. package/bin/lean/release-deploy.mjs +35 -5
  92. package/bin/lean/release-deploy.test.mjs +50 -3
  93. package/bin/lean/release-flakes.mjs +48 -2
  94. package/bin/lean/release-flakes.test.mjs +45 -1
  95. package/bin/lean/release-ledger.mjs +19 -1
  96. package/bin/lean/release-ledger.test.mjs +23 -0
  97. package/bin/lean/release-preflight.mjs +28 -0
  98. package/bin/lean/release-preflight.test.mjs +42 -1
  99. package/bin/lean/release-review.mjs +40 -5
  100. package/bin/lean/release-review.test.mjs +43 -2
  101. package/bin/lean/release.mjs +45 -15
  102. package/bin/lean/release.test.mjs +32 -0
  103. package/bin/lean/retry.mjs +1 -1
  104. package/bin/lean/retry.test.mjs +6 -1
  105. package/bin/lean/rotator.mjs +9 -0
  106. package/bin/lean/rotator.test.mjs +11 -1
  107. package/bin/lean/sandbox-remote.mjs +51 -13
  108. package/bin/lean/schedd.mjs +13 -8
  109. package/bin/lean/schedd.test.mjs +65 -5
  110. package/bin/lean/selfreview.mjs +1 -1
  111. package/bin/lean/statuscomment.mjs +4 -1
  112. package/bin/lean/validate-catalog.mjs +108 -0
  113. package/bin/lean/validate-catalog.test.mjs +46 -1
  114. package/bin/lean/verify.mjs +1 -1
  115. package/bin/pool/affinity.test.mjs +91 -0
  116. package/bin/pool/agent.mjs +247 -23
  117. package/bin/pool/cache-sweep.mjs +31 -10
  118. package/bin/pool/ci-autoscale.mjs +160 -0
  119. package/bin/pool/cli.mjs +56 -9
  120. package/bin/pool/docker.mjs +5 -0
  121. package/bin/pool/engine-placement.test.mjs +94 -0
  122. package/bin/pool/image-manifest.mjs +24 -0
  123. package/bin/pool/image-manifest.test.mjs +20 -0
  124. package/bin/pool/lane-target.mjs +41 -0
  125. package/bin/pool/lane-tools.mjs +29 -5
  126. package/bin/pool/lane-tools.test.mjs +36 -7
  127. package/bin/pool/mirror-seed.mjs +15 -11
  128. package/bin/pool/project-layer.mjs +142 -0
  129. package/bin/pool/project-layer.test.mjs +73 -0
  130. package/bin/pool/router.mjs +106 -36
  131. package/bin/pool/version.mjs +72 -2
  132. package/bin/review-staging.mjs +11 -3
  133. package/bin/runner.mjs +59 -11
  134. package/bin/stats/release.mjs +7 -0
  135. package/bin/stats/release.test.mjs +20 -0
  136. package/bin/stats/scorecard.mjs +187 -0
  137. package/bin/stats/scorecard.test.mjs +89 -0
  138. package/bin/stats/tool-parks.mjs +29 -0
  139. package/bin/stats/tool-parks.test.mjs +21 -0
  140. package/docs/CONFIG.md +41 -0
  141. package/docs/OUTCOME-CODES.md +1 -0
  142. package/docs/STATS.md +17 -0
  143. package/package.json +1 -1
  144. package/pool/image/Dockerfile +15 -3
  145. package/pool/image/manifest.json +25 -0
  146. package/pool/image/mirror.sh +11 -2
  147. package/pool/install/install-agent.ps1 +11 -4
  148. package/scripts/ci-local/adapters/github-actions.mjs +8 -0
  149. package/scripts/ci-local/cli.mjs +1 -1
  150. package/scripts/ci-local/plan.mjs +3 -2
  151. package/scripts/ci-local.test.sh +14 -2
  152. package/scripts/failure-census.mjs +67 -0
  153. package/scripts/review-finalize.sh +5 -5
  154. package/scripts/review-finalize.test.sh +8 -1
  155. package/scripts/verify-phase-trail.sh +11 -0
  156. package/scripts/verify-phase-trail.test.sh +9 -0
@@ -60,3 +60,20 @@ export function openLimits(file = limitsFile(), { now = () => Date.now() } = {})
60
60
  list: () => Object.entries(read()).map(([id, h]) => ({ id, until: h.until, source: h.source ?? null, setAt: h.setAt ?? null })),
61
61
  };
62
62
  }
63
+
64
+ /** #5988: a hold expiry alert is posted this long before `expiresAt` (T-30 min). */
65
+ export const HOLD_EXPIRY_WARN_MS = 30 * 60000;
66
+
67
+ /**
68
+ * #5988: hold-info entries (`{issue: {expiresAt, ...}}`) whose expiry is within `leadMs` and not yet warned. `warned` is the
69
+ * caller's marker set (an issue is warned once per expiresAt). Pure; an entry without a valid future expiry is never listed.
70
+ * @returns {Array<{issue:number, expiresAt:string, inMs:number, key:string}>}
71
+ */
72
+ export function holdExpiryWarnings(info, { now = Date.now(), leadMs = HOLD_EXPIRY_WARN_MS, warned = new Set() } = {}) {
73
+ const out = [];
74
+ for (const [n, e] of Object.entries(info ?? {})) {
75
+ const at = Date.parse(e?.expiresAt), key = `${n}@${e?.expiresAt}`;
76
+ if (Number.isFinite(at) && at > now && at - now <= leadMs && !warned.has(key)) out.push({ issue: Number(n), expiresAt: e.expiresAt, inMs: at - now, key });
77
+ }
78
+ return out;
79
+ }
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
5
5
  import { readFileSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
  import { tmpDir } from "../tests/_tmp.mjs";
8
- import { openLimits, laneBackendId, limitsFile } from "./limits.mjs";
8
+ import { openLimits, laneBackendId, limitsFile, holdExpiryWarnings, HOLD_EXPIRY_WARN_MS } from "./limits.mjs";
9
9
  import { orchestrate } from "./orchestrate.mjs";
10
10
  import { limitsFromCli } from "../engine-cli.mjs";
11
11
 
@@ -402,3 +402,17 @@ describe("tokenbaton rotation holds (#5205)", () => {
402
402
  onUpdate: (u) => { if (u.outcome === "paused") assert.equal(limits.holdUntil("A"), until); } });
403
403
  });
404
404
  });
405
+
406
+ describe("#5988: hold expiry warning", () => {
407
+ const at = (ms) => new Date(ms).toISOString();
408
+ it("lists a hold within 30 min of expiry once; never an open-ended, expired or distant hold", () => {
409
+ const now = 1_000_000, warned = new Set();
410
+ const info = { 1: { expiresAt: at(now + 20 * 60000) }, 2: { expiresAt: at(now + 3 * 3600000) }, 3: { expiresAt: null }, 4: { expiresAt: at(now - 1) } };
411
+ const w = holdExpiryWarnings(info, { now, warned });
412
+ assert.deepEqual(w.map((x) => x.issue), [1]);
413
+ assert.equal(HOLD_EXPIRY_WARN_MS, 30 * 60000);
414
+ warned.add(w[0].key);
415
+ assert.deepEqual(holdExpiryWarnings(info, { now, warned }), []);
416
+ assert.deepEqual(holdExpiryWarnings(null, { now }), []);
417
+ });
418
+ });
@@ -135,12 +135,25 @@ export function lazyWeight({ initial = null, compute = null } = {}) {
135
135
  * `placeLane` with the remote or hybrid facts); mode `local` places every new lane on the host. `onChange(exec)` is
136
136
  * called once each time the effective `{mode, maxRemote}` differs from the last one seen (the pinned one first).
137
137
  */
138
- export function liveRemote(base, { exec, readOverride = () => null, place, onChange = null }) {
138
+ export const BELOW_PINNED_WARN_HOURS = 6;
139
+ export function liveRemote(base, { exec, readOverride = () => null, place, onChange = null, onBelowPinned = null, belowPinnedHours = BELOW_PINNED_WARN_HOURS, now = Date.now }) {
139
140
  const keyOf = (e) => `${e.mode}|${e.maxRemote}`;
140
141
  let last = keyOf(effectiveExecution(exec, null));
142
+ let live = null; // the override applied by the last current() call
143
+ let belowSince = null, belowWarned = false; // #5746: since when a live max_remote has been below the pinned value
144
+ const noteBelow = () => {
145
+ const pinned = exec?.maxRemote;
146
+ if (!(live?.maxRemote !== undefined && Number.isInteger(pinned) && live.maxRemote < pinned)) { belowSince = null; belowWarned = false; return; }
147
+ const t = now();
148
+ belowSince ??= t;
149
+ const hours = Number(belowPinnedHours) > 0 ? Number(belowPinnedHours) : BELOW_PINNED_WARN_HOURS;
150
+ if (!belowWarned && t - belowSince > hours * 3600000) { belowWarned = true; try { onBelowPinned?.({ maxRemote: live.maxRemote, pinned, hours }); } catch { /* advisory */ } }
151
+ };
141
152
  const current = () => {
142
153
  let o = null;
143
154
  try { o = readOverride() ?? null; } catch { o = null; }
155
+ live = sanitizeOverride(o);
156
+ noteBelow();
144
157
  const e = effectiveExecution(exec, o);
145
158
  const k = keyOf(e);
146
159
  if (k !== last) { last = k; try { onChange?.(e); } catch { /* advisory */ } }
@@ -148,12 +161,21 @@ export function liveRemote(base, { exec, readOverride = () => null, place, onCha
148
161
  };
149
162
  return Object.defineProperties(base, {
150
163
  max: { get: () => current().maxRemote, enumerable: true, configurable: true },
164
+ mode: { get: () => current().mode, enumerable: true, configurable: true }, // #5746: the effective mode (the live override included)
151
165
  fallbackLocal: { get: () => { const e = current(); return e.mode === "hybrid" && Number.isInteger(e.maxRemote) && e.maxRemote >= 1; }, enumerable: true, configurable: true },
152
166
  place: {
153
167
  value: (n) => {
154
168
  const e = current();
155
169
  if (e.mode === "local") return { where: "local", reason: "live placement: local" };
156
- return place(e, n);
170
+ const p = place(e, n);
171
+ // #5746: remote mode with no remote slots holds the lane when the host is not allowed; else names the real cause
172
+ if (e.mode === "remote" && p?.where === "local" && !(Number.isInteger(e.maxRemote) && e.maxRemote >= 1)) {
173
+ const reason = live?.maxRemote !== undefined ? "max_remote 0 (live override)" : "max_remote 0";
174
+ return base.hostFallback === false ? { where: "remote", reason, hold: true } : { ...p, reason };
175
+ }
176
+ // #5746: remote mode never places on the host unless host_fallback is true (a host-only `needs` capability, headroom, ...)
177
+ if (e.mode === "remote" && p?.where === "local" && base.hostFallback === false) return { where: "remote", reason: `host fallback off, not on the host: ${p.reason}` };
178
+ return p;
157
179
  },
158
180
  enumerable: true, configurable: true, writable: true,
159
181
  },
@@ -83,6 +83,45 @@ describe("#5138 live execution control", () => {
83
83
  });
84
84
  });
85
85
 
86
+ describe("#5746 live max_remote 0 in remote mode", () => {
87
+ const exec = { mode: "remote", maxRemote: 4 };
88
+ const place = (e) => ({ where: e.maxRemote >= 1 ? "remote" : "local", reason: e.maxRemote >= 1 ? "mode remote" : "max_remote 0" });
89
+ it("holds with the live-override reason when the host is not allowed", () => {
90
+ const r = liveRemote({ hostFallback: false }, { exec, readOverride: () => ({ maxRemote: 0 }), place });
91
+ assert.deepEqual(r.place(1), { where: "remote", reason: "max_remote 0 (live override)", hold: true });
92
+ });
93
+ it("names the live override but stays local when the host is allowed", () => {
94
+ const r = liveRemote({ hostFallback: true }, { exec, readOverride: () => ({ maxRemote: 0 }), place });
95
+ assert.deepEqual(r.place(1), { where: "local", reason: "max_remote 0 (live override)" });
96
+ });
97
+ });
98
+
99
+ describe("#5746 live max_remote below the pinned value warns once after N hours", () => {
100
+ it("warns once past the threshold, not before, and re-arms when restored", () => {
101
+ let t = 0, o = { maxRemote: 0 };
102
+ const warned = [];
103
+ const r = liveRemote({ onBudget: "stop" }, { exec: { mode: "remote", maxRemote: 3 }, readOverride: () => o, place: () => ({ where: "remote", reason: "r" }),
104
+ belowPinnedHours: 2, now: () => t, onBelowPinned: (w) => warned.push(w) });
105
+ void r.max;
106
+ t = 2 * 3600000; void r.max;
107
+ assert.equal(warned.length, 0);
108
+ t += 1; void r.max; void r.max;
109
+ assert.deepEqual(warned, [{ maxRemote: 0, pinned: 3, hours: 2 }]);
110
+ o = { maxRemote: 3 }; void r.max;
111
+ o = { maxRemote: 1 }; void r.max;
112
+ t += 3 * 3600000; void r.max;
113
+ assert.equal(warned.length, 2);
114
+ });
115
+ it("no warning without an override or with an override at or above the pinned value", () => {
116
+ let t = 0, o = null;
117
+ const warned = [];
118
+ const r = liveRemote({}, { exec: { mode: "remote", maxRemote: 2 }, readOverride: () => o, place: () => ({ where: "remote" }), belowPinnedHours: 1, now: () => t, onBelowPinned: (w) => warned.push(w) });
119
+ void r.max; t = 10 * 3600000; void r.max;
120
+ o = { maxRemote: 4 }; void r.max; t *= 2; void r.max;
121
+ assert.equal(warned.length, 0);
122
+ });
123
+ });
124
+
86
125
  describe("#5735 remoteLaneNote", () => {
87
126
  const lanes = (agents, total) => ({ agents, total });
88
127
  it("warns when max_remote exceeds the summed host lane ceiling and always prints the total", () => {
@@ -115,3 +154,26 @@ describe("#5933 drain semantics", () => {
115
154
  assert.equal(mk({ mode: "hybrid", maxRemote: 0 }).place(1).where, "local");
116
155
  });
117
156
  });
157
+
158
+ describe("#5746 remote mode never places on the host unless host_fallback is true", () => {
159
+ const exec = { mode: "remote", maxRemote: 4 };
160
+ const needsHost = () => ({ where: "local", reason: "host capability: prod-monitor" }); // placeLane: a `needs` entry the provider does not relay
161
+ it("a host-only capability stays remote when the host is not allowed", () => {
162
+ const r = liveRemote({ hostFallback: false }, { exec, readOverride: () => null, place: needsHost });
163
+ assert.deepEqual(r.place(1), { where: "remote", reason: "host fallback off, not on the host: host capability: prod-monitor" });
164
+ assert.equal(r.mode, "remote");
165
+ });
166
+ it("host_fallback true keeps the host placement", () => {
167
+ const r = liveRemote({ hostFallback: true }, { exec, readOverride: () => null, place: needsHost });
168
+ assert.equal(r.place(1).where, "local");
169
+ });
170
+ it("an operator's live --set-placement local is not a fallback", () => {
171
+ const r = liveRemote({ hostFallback: false }, { exec, readOverride: () => ({ mode: "local" }), place: needsHost });
172
+ assert.deepEqual(r.place(1), { where: "local", reason: "live placement: local" });
173
+ assert.equal(r.mode, "local");
174
+ });
175
+ it("hybrid placement is untouched by host_fallback false", () => {
176
+ const r = liveRemote({ hostFallback: false }, { exec: { mode: "hybrid", maxRemote: 2 }, readOverride: () => null, place: () => ({ where: "local", reason: "light lane, host has headroom" }) });
177
+ assert.equal(r.place(1).where, "local");
178
+ });
179
+ });
@@ -38,25 +38,33 @@ describe("#5986 attempts ledger in the batch runner", () => {
38
38
  assert.deepEqual(r.rows.map((x) => x.outcome), ["merged", "merged"], "root and its held dependent");
39
39
  });
40
40
 
41
- it("the 3rd identical-signature failure escalates once and stops; counters survive resumes (state.json)", async () => {
41
+ it("the 2nd identical-signature failure escalates once with one comment and stops; counters survive resumes (state.json)", async () => {
42
42
  const store = memStore(), h = { v: "H1" }, a = seam(h);
43
43
  await run(store, a, async () => FAIL);
44
- h.v = "H2"; await run(store, a, async () => FAIL);
45
44
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 0);
46
- h.v = "H3"; const third = await run(store, a, async () => FAIL);
47
- assert.equal(third.rows[0].outcome, "needs-human");
45
+ h.v = "H2"; const second = await run(store, a, async () => FAIL);
46
+ assert.equal(second.rows[0].outcome, "needs-human");
48
47
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 1, "one escalation");
49
- assert.equal(store.peek().attempts[1].attempts, 3);
50
- assert.equal(store.peek().attempts[1].signatures.length, 3);
48
+ assert.equal(store.peek().attempts[1].attempts, 2);
49
+ assert.equal(store.peek().attempts[1].signatures.length, 2);
51
50
  let ran = 0;
52
- const again = await run(store, a, async () => { ran++; return MERGED; }); // same hash H3, label removed
51
+ const again = await run(store, a, async () => { ran++; return MERGED; }); // same hash H2, label removed
53
52
  assert.equal(ran, 0);
54
53
  assert.equal(again.rows[0].outcome, "needs-human");
55
54
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 1, "still one escalation");
56
- h.v = "H4";
55
+ h.v = "H3";
57
56
  assert.equal((await run(store, a, async () => MERGED)).rows[0].outcome, "merged", "a new input hash readmits");
58
57
  });
59
-
58
+ it("#5931 a remote lane on another engine version ends env.engine_skew, never conformance", async () => {
59
+ const store = memStore();
60
+ const rows = await orchestrate({ issues: [1], parallel: 1, pollMs: 5, store, version: "1.63.0",
61
+ envHold: { version: () => "1.63.0", maxMs: 1, watchMs: 1 },
62
+ runOne: async () => ({ terminalReason: "needs-human", code: "recurrence.design_missing", detail: "gate fired", engineVersion: "1.61.2" }),
63
+ remote: { max: 2, isRemote: () => true, admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 } });
64
+ assert.equal(rows[0].code, "env.engine_skew");
65
+ assert.match(rows[0].detail, /env\.engine_skew/);
66
+ assert.equal(rows[0].outcome, "held");
67
+ });
60
68
  it("an engine-error that breaches the lifetime attempts cap ends needs-human (escalated)", async () => {
61
69
  const store = memStore(), h = { v: "H1" }, a = seam(h, { cfg: { maxAttempts: 1, maxIdentical: 5 } });
62
70
  const r = await run(store, a, async () => ({ terminalReason: "engine-error", detail: "boom" }));
@@ -0,0 +1,81 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import { describe, it } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { orchestrate } from "./orchestrate.mjs";
6
+ import { tmpDir } from "../tests/_tmp.mjs";
7
+ import { openBatch } from "./batch.mjs";
8
+ import { utimesSync } from "node:fs";
9
+ import { evaluateDispatchStall } from "./batch-health.mjs";
10
+ import { makeCapacitySampler } from "./capsample.mjs";
11
+
12
+ // #5746: remote mode with host_fallback false never places a lane on the orchestrator host, whichever branch picks "local"
13
+ const runRemote = async (place, extra = {}) => {
14
+ const seen = [], saves = [];
15
+ await orchestrate({ issues: [5], parallel: 2, readBody: async () => "", pollMs: 5,
16
+ store: { load: () => null, save: (s) => saves.push(JSON.parse(JSON.stringify(s))), log: () => {} },
17
+ remote: { mode: "remote", max: 2, isRemote: () => true, hostFallback: false, place, admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
18
+ runOne: async (_n, _l, ctx = {}) => { seen.push({ where: ctx.placement?.where, remote: ctx.remote }); return { terminalReason: "merged", pr: 1 }; }, ...extra });
19
+ return { seen, saves };
20
+ };
21
+
22
+ describe("#5746 remote mode keeps lanes off the host", () => {
23
+ it("a host-capability placement (placeLane `needs`) is placed remotely and recorded", async () => {
24
+ const { seen, saves } = await runRemote(() => ({ where: "local", reason: "host capability: prod-monitor" }));
25
+ assert.deepEqual(seen, [{ where: "remote", remote: true }]);
26
+ const running = saves.flatMap((s) => Object.values(s.running ?? {}));
27
+ assert.ok(running.length > 0 && running.every((r) => r.placement?.where === "remote" && r.remote === true), JSON.stringify(running));
28
+ });
29
+ it("a throwing placement never falls to the host", async () => {
30
+ const { seen } = await runRemote(() => { throw new Error("probe"); });
31
+ assert.deepEqual(seen.map((s) => s.where), ["remote"]);
32
+ });
33
+ it("host_fallback true keeps the host placement (hybrid-style config)", async () => {
34
+ const { seen } = await runRemote(() => ({ where: "local", reason: "host capability: x" }), { remote: { mode: "remote", max: 2, isRemote: () => true, hostFallback: true, place: () => ({ where: "local", reason: "host capability: x" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 } });
35
+ assert.deepEqual(seen.map((s) => s.where), ["local"]);
36
+ });
37
+ it("every running entry carries placement.where, also for a lane admitted without a recorded one", async () => {
38
+ const { saves } = await runRemote(() => ({ where: "remote", reason: "mode remote" }));
39
+ const running = saves.flatMap((s) => Object.values(s.running ?? {}));
40
+ assert.ok(running.length > 0 && running.every((r) => typeof r.placement?.where === "string"), JSON.stringify(running));
41
+ });
42
+ });
43
+
44
+ // dispatch stall: a release after a long hold is not hours of idle
45
+ describe("dispatch-stall clock after an operator release", () => {
46
+ const MIN = 60000;
47
+ it("--release / hold expiry / requeue / unpause restart the idle clock", () => {
48
+ const dir = tmpDir("stall-clock-");
49
+ const b = openBatch(dir, "b-test");
50
+ b.store.save({ v: 1, order: [1], pending: [1], running: {}, results: {} });
51
+ const old = new Date(Date.now() - 150 * MIN);
52
+ for (const f of ["state.json"]) utimesSync(`${b.dir}/${f}`, old, old);
53
+ assert.ok(Date.now() - b.lastDispatchClockMs() >= 149 * MIN, "no operator input: the clock is the last progress");
54
+ b.holdIssues([1]);
55
+ b.releaseIssues([1]);
56
+ assert.ok(Date.now() - b.lastDispatchClockMs() < MIN, "a release restarts the clock");
57
+ const state = { order: [1], pending: [1], running: {}, results: {}, parallel: 4 };
58
+ const idle = evaluateDispatchStall(state, { held: [], hosted: true, lastProgressMs: b.lastProgressMs(), now: Date.now(), windowMin: 3 });
59
+ const fresh = evaluateDispatchStall(state, { held: [], hosted: true, lastProgressMs: b.lastDispatchClockMs(), now: Date.now(), windowMin: 3 });
60
+ assert.equal(idle?.code, "dispatch-stalled"); // the old clock: declared stalled the moment the hold lifts
61
+ assert.equal(fresh, null);
62
+ b.setPause({}); b.clearPause();
63
+ assert.ok(Date.now() - b.lastDispatchClockMs() < MIN);
64
+ });
65
+ });
66
+
67
+ // a failed capacity probe clears at the next good sample (it used to stay failed forever)
68
+ describe("capacity sampler recovers from a failed probe", () => {
69
+ it("throws after a failed probe, then samples again once the pool answers", async () => {
70
+ let t = 0, ok = false, calls = 0;
71
+ const cap = makeCapacitySampler({ provider: { capacity: async () => { calls++; if (!ok) throw new Error("502"); return { free: 3, online: 2 }; } }, now: () => t, pollMs: 5000 });
72
+ assert.equal(cap(), null);
73
+ await new Promise((r) => setImmediate(r));
74
+ assert.throws(() => cap(), /capacity probe failed/);
75
+ ok = true; t += 6000;
76
+ assert.throws(() => cap(), /capacity probe failed/); // this call starts the refresh; the sample lands after it
77
+ await new Promise((r) => setImmediate(r));
78
+ assert.deepEqual(cap(), { free: 3, online: 2, at: 2 });
79
+ assert.equal(calls, 2);
80
+ });
81
+ });
@@ -20,7 +20,7 @@ const harness = ({ script, issues = Object.keys(script).map(Number), parallel =
20
20
  recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
21
21
  envHold: { maxMs: 120_000, watchMs: 30_000, ...envHold },
22
22
  runOne: async (n, _l, ctx = {}) => {
23
- calls.push({ n, recover: ctx.recover?.attempt ?? 0 });
23
+ calls.push({ n, recover: ctx.recover?.attempt ?? 0, at: t });
24
24
  t += 1000;
25
25
  const list = script[n] ?? [{ terminalReason: "merged", pr: 1 }];
26
26
  const k = calls.filter((c) => c.n === n).length - 1;
@@ -210,6 +210,20 @@ describe("#5755 one env issue per signature", () => {
210
210
  assert.equal(byIssue[1].outcome, "merged");
211
211
  });
212
212
 
213
+ it("#6123 an env issue that is closed but the gap persists re-admits with exponential backoff (15m, 1h, 4h), not every watch", async () => {
214
+ const e = seam(() => true); // closed from the start, the tool is still missing: every re-admit re-parks on the same signature
215
+ const { calls, byIssue } = await harness({ script: { 1: [miss("html2text"), miss("html2text"), miss("html2text"), miss("html2text"), miss("html2text"), MERGED] },
216
+ envHold: { maxMs: 5 * 3600_000, watchMs: 300_000 }, extra: { envIssue: e } });
217
+ const gaps = calls.slice(1).map((c, i) => c.at - calls[i].at);
218
+ assert.equal(calls.length, 6);
219
+ assert.equal(byIssue[1].outcome, "merged");
220
+ // gap 0 is the first re-admit (a fresh env issue closure); each later one waits 15m, 1h, 4h, 4h
221
+ assert.ok(gaps[0] < 15 * 60_000);
222
+ assert.ok(gaps[1] >= 15 * 60_000 && gaps[1] < 3600_000, String(gaps));
223
+ assert.ok(gaps[2] >= 3600_000 && gaps[2] < 4 * 3600_000, String(gaps));
224
+ assert.ok(gaps[3] >= 4 * 3600_000 && gaps[4] >= 4 * 3600_000, String(gaps));
225
+ });
226
+
213
227
  it("without the seam the env.validate_timeout flow is unchanged (needs-human)", async () => {
214
228
  const { byIssue } = await harness({ script: { 1: [timeout()] }, envHold: null });
215
229
  assert.notEqual(byIssue[1].outcome, "held");
@@ -292,6 +306,22 @@ describe("#5859 agent restart: correlated sandbox loss is sandbox.lost, not engi
292
306
  for (const n of issues) assert.equal(r.byIssue[n].outcome, "merged");
293
307
  });
294
308
 
309
+ // #5988: three sandboxes destroyed for max lifetime together are one batch-level event; the breaker stays closed and each lane is requeued.
310
+ it("3 sandboxes destroyed for max lifetime within 30 s: no breaker trip, lanes requeued, reported once (#5988)", async () => {
311
+ const MAXLIFE = (n) => ({ ...LOST(n), detail: `sandbox fake-${n} destroyed: max lifetime reached` });
312
+ const issues = [1, 2, 3], script = Object.fromEntries(issues.map((n) => [n, [MAXLIFE(n), MERGED]]));
313
+ const store = memStore(), logged = [];
314
+ store.log = (ev) => logged.push(ev);
315
+ const r = await harness({ script, issues, parallel: 3, store, envHold: undefined, extra: { envHold: null, breaker: BREAKER, remote: { agentHealthy: async () => true } } });
316
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"), "the breaker never trips");
317
+ for (const n of issues) assert.equal(r.byIssue[n].outcome, "merged", `#${n} requeued and relaunched`);
318
+ const st = store.load();
319
+ assert.deepEqual(st.errorTimes, []);
320
+ assert.equal(st.breaker, null);
321
+ assert.equal(logged.filter((e) => e.event === "agent.restarted").length, 1, "one batch-level event");
322
+ assert.equal(st.agentRestarts[0].requeued, 3);
323
+ });
324
+
295
325
  it("agent restart: failure after healthy is an ordinary engine-error", async () => {
296
326
  const store = memStore();
297
327
  const r = await harness({ script: { 1: [LOST(1), LOST(1), MERGED], 2: [LOST(2), MERGED], 3: [LOST(3), MERGED] }, issues: [1, 2, 3], parallel: 3, store,
@@ -322,3 +352,34 @@ describe("#5859 agent restart: correlated sandbox loss is sandbox.lost, not engi
322
352
  assert.ok(r.updates.some((u) => u.outcome === "breaker"));
323
353
  });
324
354
  });
355
+
356
+ describe("#5988: breaker scoped by signature and agent", () => {
357
+ it("12 sandbox.exited engine-errors on one agent quarantine only that agent; other agents keep admitting", async () => {
358
+ const issues = [...Array.from({ length: 12 }, (_, i) => i + 1), 50], quarantined = [], reseeds = [];
359
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited before a result (run ${n})`, agent: "vm-a" });
360
+ const script = Object.fromEntries(issues.slice(0, 12).map((n) => [n, [sick(n), MERGED]]));
361
+ const r = await harness({ script, issues, parallel: 1, envHold: undefined,
362
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 }, quarantineAgent: (q) => quarantined.push(q), reseedCache: (q) => reseeds.push(q) } });
363
+ assert.deepEqual(quarantined.map((q) => q.agent), ["vm-a"], "that agent only, once");
364
+ assert.equal(reseeds.length, 1, "the cache is reseeded once");
365
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"), "the batch breaker never trips");
366
+ assert.equal(r.byIssue[50].outcome, "merged", "unaffected work keeps admitting");
367
+ assert.ok(r.updates.some((u) => u.outcome === "agent-quarantine"));
368
+ });
369
+
370
+ it("without placement callbacks the agent is still quarantined in-batch: its lanes are requeued, the breaker stays closed", async () => {
371
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited (run ${n})`, agent: "vm-a" });
372
+ const r = await harness({ script: { 1: [sick(1), MERGED], 2: [sick(2), MERGED], 3: [sick(3), MERGED], 4: [sick(4), MERGED] }, issues: [1, 2, 3, 4, 50], parallel: 1, envHold: undefined,
373
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 } } });
374
+ assert.ok(r.updates.some((u) => u.outcome === "agent-quarantine"));
375
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"));
376
+ assert.equal(r.byIssue[50].outcome, "merged");
377
+ });
378
+
379
+ it("a persistently sick agent without placement callbacks cannot loop forever: the batch breaker counts it after bounded requeues", async () => {
380
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited (run ${n})`, agent: "vm-a" });
381
+ const r = await harness({ script: Object.fromEntries([1, 2, 3, 4, 5].map((n) => [n, [sick(n)]])), issues: [1, 2, 3, 4, 5], parallel: 1, envHold: undefined,
382
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 } } });
383
+ assert.ok(r.updates.some((u) => u.outcome === "breaker"), "bounded: the batch breaker trips");
384
+ });
385
+ });
@@ -0,0 +1,72 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5893: a needs-human root with held dependents is readmitted only when the label is really gone (fresh read) and its removal
4
+ // event post-dates the newest FORGE:NEEDS_HUMAN; an identical block (outcome code + ask key) needs a newer removal event.
5
+ import { describe, it } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { orchestrate } from "./orchestrate.mjs";
8
+
9
+ const memStore = () => { let st = null; return { load: () => (st ? JSON.parse(JSON.stringify(st)) : null), save: (s) => { st = JSON.parse(JSON.stringify(s)); }, log: () => {}, peek: () => st }; };
10
+ const FAIL = { terminalReason: "needs-human", code: "spend.cap", detail: "needs a spend decision" };
11
+ const MERGED = { terminalReason: "merged", pr: 1 };
12
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
13
+
14
+ // Run 1 blocks root 1 (2 is held behind it); run 2 resumes the batch and watches the held root.
15
+ const resume = async (store, { issueLabels, heldFacts, ran, watchMs = 60 }) => {
16
+ const updates = [];
17
+ const p = orchestrate({ issues: [1, 2], parallel: 1, pollMs: 5, store, readBody: async (n) => (n === 2 ? "**Depends on**: #1" : ""), issueLabels, ...(heldFacts ? { heldFacts } : {}),
18
+ runOne: async (n) => { ran.push(n); return MERGED; }, onUpdate: (r) => updates.push(r) });
19
+ await Promise.race([p, sleep(watchMs)]);
20
+ return { updates, p };
21
+ };
22
+ const block = async (store) => orchestrate({ issues: [1, 2], parallel: 1, pollMs: 5, store, readBody: async (n) => (n === 2 ? "**Depends on**: #1" : ""), issueLabels: async () => ["needs-human"], runOne: async (n) => (n === 1 ? FAIL : MERGED) });
23
+
24
+ describe("#5893 held needs-human root readmit", () => {
25
+ it("no readmit while needs-human label is still on (stale cache vs fresh read)", async () => {
26
+ const store = memStore(); await block(store);
27
+ const ran = []; const calls = [];
28
+ // the memoized read lacks the label; only a fresh read sees it
29
+ const issueLabels = async (n, o) => { calls.push(o?.fresh === true); return o?.fresh ? ["needs-human"] : []; };
30
+ const { updates } = await resume(store, { issueLabels, ran });
31
+ assert.deepEqual(ran, []);
32
+ assert.ok(!updates.some((u) => u.outcome === "readmitted"));
33
+ assert.ok(calls.every(Boolean), "every held-root label read is fresh");
34
+ });
35
+
36
+ it("removal event before the NEEDS_HUMAN comment: no readmit; unreadable events: no readmit", async () => {
37
+ for (const heldFacts of [async () => ({ removedAt: 10, blockedAt: 20, askKey: "k" }), async () => { throw new Error("gh down"); }, async () => null]) {
38
+ const store = memStore(); await block(store);
39
+ const ran = [];
40
+ const { updates } = await resume(store, { issueLabels: async () => [], heldFacts, ran });
41
+ assert.deepEqual(ran, []);
42
+ assert.ok(!updates.some((u) => u.outcome === "readmitted"));
43
+ }
44
+ });
45
+
46
+ it("removal event after the block readmits once and the subtree follows", async () => {
47
+ const store = memStore(); await block(store);
48
+ const ran = [];
49
+ const { updates, p } = await resume(store, { issueLabels: async () => [], heldFacts: async () => ({ removedAt: 30, blockedAt: 20, askKey: "k" }), ran, watchMs: 200 });
50
+ await Promise.race([p, sleep(500)]);
51
+ assert.equal(updates.filter((u) => u.outcome === "readmitted" && u.issue === 1).length, 1);
52
+ assert.ok(ran.includes(1));
53
+ });
54
+
55
+ it("identical block is not readmitted twice without a newer removal event; sig survives resume", async () => {
56
+ const store = memStore(); await block(store);
57
+ const ran = [];
58
+ const facts = { removedAt: 30, blockedAt: 20, askKey: "k" };
59
+ const first = await resume(store, { issueLabels: async () => [], heldFacts: async () => facts, ran, watchMs: 200 });
60
+ await Promise.race([first.p, sleep(500)]);
61
+ assert.deepEqual(store.peek().heldSigs?.[1], { sig: "needs-human:k", removedAt: 30 }.sig ? { sig: "needs-human:k", removedAt: 30 } : null);
62
+ // the lane blocks again with the same ask; the old removal event is the only one
63
+ const st = store.peek();
64
+ st.results = { ...st.results, 1: { issue: 1, outcome: "needs-human", code: "spend.cap" }, 2: { issue: 2, outcome: "held", root: 1, waiting: [1] } };
65
+ st.pending = []; st.running = {};
66
+ const store2 = memStore(); store2.save(st);
67
+ const ran2 = [];
68
+ const again = await resume(store2, { issueLabels: async () => [], heldFacts: async () => facts, ran: ran2 });
69
+ assert.deepEqual(ran2, []);
70
+ assert.ok(!again.updates.some((u) => u.outcome === "readmitted"));
71
+ });
72
+ });
@@ -6,7 +6,7 @@ import { orchestrate } from "./orchestrate.mjs";
6
6
  import { hostFallbackAllowed } from "./execution.mjs";
7
7
 
8
8
  // #5652: host re-placement of a remote lane's env.tool_missing / env.capability_remote end follows host.role / execution.host_fallback.
9
- const go = async (code, cfg) => {
9
+ const go = async (code, cfg, rec = {}) => {
10
10
  const calls = [];
11
11
  const rows = await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1 }, readBody: async () => "",
12
12
  remote: { max: 2, isRemote: () => true, hostFallback: hostFallbackAllowed(cfg), place: () => ({ where: "remote", reason: "mode remote" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
@@ -17,6 +17,18 @@ const go = async (code, cfg) => {
17
17
  return { rows, calls };
18
18
  };
19
19
 
20
+ // #5746: remote mode with host fallback off never re-places a mechanical recovery on the host
21
+ const goMech = async (hostFallback) => {
22
+ const calls = [];
23
+ await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, readBody: async () => "",
24
+ remote: { max: 2, isRemote: () => true, hostFallback, admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
25
+ runOne: async (n, _l, ctx = {}) => {
26
+ calls.push(ctx.placement?.where);
27
+ return ctx.recover ? { terminalReason: "merged", pr: 9 } : { terminalReason: "needs-human", code: "env.repro_unrunnable", detail: "x", placement: { where: "remote" } };
28
+ } });
29
+ return calls;
30
+ };
31
+
20
32
  describe("#5652 host fallback placement", () => {
21
33
  for (const code of ["env.capability_remote", "env.tool_missing"]) {
22
34
  it(`${code}: host.role unset keeps the host re-placement`, async () => {
@@ -38,6 +50,52 @@ describe("#5652 host fallback placement", () => {
38
50
  const r = await go("env.repro_unrunnable", { hostRole: "orchestrator" });
39
51
  assert.ok(r.calls.length >= 1);
40
52
  });
53
+ it("#5746: remote mode with nothing set disallows the host; hybrid keeps it; explicit true wins", () => {
54
+ assert.equal(hostFallbackAllowed({ mode: "remote" }), false);
55
+ assert.equal(hostFallbackAllowed({ mode: "hybrid" }), true);
56
+ assert.equal(hostFallbackAllowed({ mode: "remote", hostFallback: true }), true);
57
+ assert.equal(hostFallbackAllowed({ mode: "remote", fallbackLocal: true }), false);
58
+ });
59
+ it("#5746: a #5371 mechanical recovery with host_fallback false retries remotely, not on the host", async () => {
60
+ const calls = await goMech(false);
61
+ assert.ok(calls.length >= 2);
62
+ assert.ok(calls.every((w) => w !== "local"), JSON.stringify(calls));
63
+ });
64
+ it("#5746: with host fallback on the #5371 recovery still goes to the host", async () => {
65
+ const calls = await goMech(true);
66
+ assert.equal(calls[1], "local");
67
+ });
68
+ for (const [name, remoteCfg] of [
69
+ ["fallback_local with max_remote 0", { max: 0, fallbackLocal: true, offlineFallback: true, admit: () => ({ ok: true }), onBudget: "stop" }],
70
+ ["execution budget under on_budget local", { max: 2, admit: () => ({ ok: false, reason: "budget cap" }), onBudget: "local" }],
71
+ ]) {
72
+ it(`#5746: host_fallback false: ${name} never runs the lane on the host`, async () => {
73
+ const ac = new AbortController(), where = [];
74
+ const run = orchestrate({ issues: [5], parallel: 2, readBody: async () => "", pollMs: 5, signal: ac.signal,
75
+ remote: { isRemote: () => true, hostFallback: false, place: () => ({ where: "remote", reason: "mode remote" }), costPerMinute: 0, ...remoteCfg },
76
+ runOne: async (_n, _l, ctx = {}) => { where.push(ctx.placement?.where); return { terminalReason: "merged", pr: 1 }; } }).catch(() => {});
77
+ await new Promise((r) => setTimeout(r, 120));
78
+ ac.abort();
79
+ await Promise.race([run, new Promise((r) => setTimeout(r, 1000))]);
80
+ assert.ok(!where.includes("local"), JSON.stringify(where));
81
+ });
82
+ }
83
+ it("#5746: remote mode with nothing set ends a host-capability lane without a host re-placement", async () => {
84
+ const r = await go("env.capability_remote", { mode: "remote" });
85
+ assert.equal(r.calls.length, 1);
86
+ });
87
+ it("#5746: max_remote 0 holds the lane (no host run) and announces waiting", async () => {
88
+ const events = [], ac = new AbortController();
89
+ let ran = 0;
90
+ const run = orchestrate({ issues: [5], parallel: 2, readBody: async () => "", pollMs: 5, signal: ac.signal, decide: (d) => events.push(d.what),
91
+ remote: { max: 0, isRemote: () => true, hostFallback: false, place: () => ({ where: "remote", reason: "max_remote 0 (live override)", hold: true }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
92
+ runOne: async () => { ran++; return { terminalReason: "merged", pr: 1 }; } }).catch(() => {});
93
+ await new Promise((r) => setTimeout(r, 150));
94
+ ac.abort();
95
+ await Promise.race([run, new Promise((r) => setTimeout(r, 1000))]);
96
+ assert.equal(ran, 0);
97
+ assert.ok(events.some((w) => /waiting: max_remote 0/.test(w)), JSON.stringify(events));
98
+ });
41
99
  });
42
100
 
43
101
  // #5808: a lane's slow post-result work (teardown) is its postRun: the dependent starts at once, the batch still waits for it.
@@ -0,0 +1,37 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5749: an env.validate_timeout recovery lane waits while the host is overloaded; other recoveries are unchanged.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { orchestrate } from "./orchestrate.mjs";
7
+
8
+ const harness = ({ script, overloadedUntil }) => {
9
+ let t = 1_000_000; const calls = [], decisions = [];
10
+ return orchestrate({ issues: [7], parallel: 1, readBody: async () => "", now: () => t, pollMs: 1000,
11
+ sleep: async (ms) => { t += Math.max(1, Number(ms) || 0); },
12
+ recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
13
+ overload: () => ({ overloaded: overloadedUntil > 0 && t >= 1_000_500 && t < overloadedUntil }), // the first admission precedes the load spike
14
+ runOne: async (n, _l, ctx = {}) => { calls.push({ recover: ctx.recover?.attempt ?? 0, at: t }); t += 1000; const k = calls.length - 1; return script[Math.min(k, script.length - 1)]; },
15
+ decide: (d) => decisions.push(d), onUpdate: () => {} }).then((rows) => ({ rows, calls, decisions, start: 1_000_000 }));
16
+ };
17
+ const TIMEOUT = { terminalReason: "needs-human", code: "env.validate_timeout", detail: "timed out", cost_usd: 1 };
18
+ const UNIMPL = { terminalReason: "needs-human", code: "conformance.unimplemented", detail: "V1 missing", cost_usd: 1 };
19
+ const MERGED = { terminalReason: "merged", pr: 1 };
20
+
21
+ describe("#5749 overload defers env.validate_timeout recovery", () => {
22
+ it("#5749 env.validate_timeout recovery waits while overloaded", async () => {
23
+ const o = await harness({ script: [TIMEOUT, MERGED], overloadedUntil: 1_000_000 + 60_000 });
24
+ assert.equal(o.calls.length, 2);
25
+ assert.ok(o.calls[1].at >= 1_000_000 + 60_000, `recovery started at +${o.calls[1].at - o.start} ms, before the overload cleared`);
26
+ assert.ok(o.decisions.some((d) => /deferred: the host is overloaded/.test(d.what)));
27
+ const n = await harness({ script: [TIMEOUT, MERGED], overloadedUntil: 0 });
28
+ assert.ok(n.calls[1].at < 1_000_000 + 10_000, "no overload: the recovery starts at once");
29
+ assert.ok(!n.decisions.some((d) => /overloaded/.test(d.what)));
30
+ });
31
+ it("#5749 conformance.unimplemented keeps resume counts under overload", async () => {
32
+ const o = await harness({ script: [UNIMPL, MERGED], overloadedUntil: 1_000_000 + 60_000 });
33
+ assert.equal(o.calls.length, 2);
34
+ assert.equal(o.calls[1].recover, 1, "the same single recovery attempt as before");
35
+ assert.ok(!o.decisions.some((d) => /overloaded/.test(d.what)));
36
+ });
37
+ });