forgedock 1.65.0 → 1.67.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 +2 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +143 -19
- package/bin/forgedock.mjs +7 -0
- package/bin/help-text.mjs +3 -3
- package/bin/introspect-schedule.mjs +98 -0
- package/bin/introspect-schedule.test.mjs +67 -0
- package/bin/lean/advisory.test.mjs +49 -0
- package/bin/lean/amendment-schema.mjs +31 -0
- package/bin/lean/attempts.mjs +159 -0
- package/bin/lean/attempts.test.mjs +127 -0
- package/bin/lean/basered.mjs +55 -0
- package/bin/lean/basered.test.mjs +68 -1
- package/bin/lean/batch-health.mjs +13 -5
- package/bin/lean/batch-health.test.mjs +16 -0
- package/bin/lean/batch.mjs +62 -0
- package/bin/lean/batch.test.mjs +119 -3
- package/bin/lean/capwait.mjs +14 -3
- package/bin/lean/capwait.test.mjs +20 -0
- package/bin/lean/clear-breaker.mjs +14 -0
- package/bin/lean/commentstate.mjs +41 -0
- package/bin/lean/commentstate.test.mjs +32 -0
- package/bin/lean/concurrency.mjs +89 -0
- package/bin/lean/concurrency.test.mjs +113 -0
- package/bin/lean/conformance.e2e.test.mjs +4 -2
- package/bin/lean/conformance.mjs +35 -3
- package/bin/lean/conformance.test.mjs +52 -0
- package/bin/lean/depcache.mjs +9 -0
- package/bin/lean/efficiency.mjs +162 -0
- package/bin/lean/efficiency.test.mjs +79 -0
- package/bin/lean/execution.mjs +31 -13
- package/bin/lean/execution.test.mjs +46 -0
- package/bin/lean/failure-stop.mjs +46 -0
- package/bin/lean/failure-stop.test.mjs +45 -0
- package/bin/lean/fixtures/capacity-storm.json +609 -0
- package/bin/lean/lean.mjs +130 -30
- package/bin/lean/lean.test.mjs +138 -47
- package/bin/lean/liveness.mjs +37 -0
- package/bin/lean/liveness.test.mjs +33 -0
- package/bin/lean/orchestrate-attempts.test.mjs +74 -0
- package/bin/lean/orchestrate-envhold.test.mjs +17 -0
- package/bin/lean/orchestrate-pause.test.mjs +84 -0
- package/bin/lean/orchestrate-reconcile.test.mjs +147 -0
- package/bin/lean/orchestrate.mjs +202 -28
- package/bin/lean/phaseledger.mjs +6 -0
- package/bin/lean/phaseledger.test.mjs +13 -1
- package/bin/lean/prompts.mjs +6 -10
- package/bin/lean/reconcile.mjs +90 -0
- package/bin/lean/recurrence.mjs +38 -2
- package/bin/lean/recurrence.test.mjs +56 -1
- package/bin/lean/sandbox-remote.mjs +33 -2
- package/bin/lean/sched.mjs +19 -0
- package/bin/lean/sched.test.mjs +11 -1
- package/bin/lean/schedd-health.mjs +8 -1
- package/bin/lean/schedd-health.test.mjs +19 -0
- package/bin/lean/schedd.mjs +97 -10
- package/bin/lean/schedd.test.mjs +138 -1
- package/bin/lean/slo.mjs +126 -0
- package/bin/lean/slo.test.mjs +112 -0
- package/bin/lean/statuscomment.mjs +37 -0
- package/bin/lean/statuscomment.test.mjs +48 -1
- package/bin/lean/verify.mjs +2 -1
- package/bin/pool/agent.mjs +46 -8
- package/bin/pool/cache-sweep.mjs +41 -4
- package/bin/pool/cli.mjs +28 -1
- package/bin/pool/health.mjs +18 -0
- package/bin/pool/lane-tools.mjs +21 -0
- package/bin/pool/mirror-seed.mjs +21 -2
- package/bin/pool/router.mjs +6 -2
- package/bin/stats/attempts.mjs +54 -0
- package/bin/stats/attempts.test.mjs +30 -0
- package/bin/stats/churn.mjs +49 -0
- package/bin/stats/churn.test.mjs +31 -0
- package/bin/stats/index.mjs +11 -3
- package/commands/orchestrate.md +21 -18
- package/docs/CONFIG.md +1 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/package.json +1 -1
- package/pool/image/entrypoint.sh +2 -1
- package/scripts/check-devdocs-freshness.sh +1 -1
package/bin/lean/orchestrate.mjs
CHANGED
|
@@ -124,7 +124,8 @@
|
|
|
124
124
|
* then queue order. A sub-issue's estimate is the parent's ÷ N, floored at the M default. Without `estimate` the order is
|
|
125
125
|
* the queue order except that decomposed sub-issues go first. A settled row carries `est_minutes` (estimated vs. actual).
|
|
126
126
|
*/
|
|
127
|
-
import { decideClear } from "./clear-breaker.mjs";
|
|
127
|
+
import { decideClear, decideAutoReset } from "./clear-breaker.mjs";
|
|
128
|
+
import { RECONCILE_MS, BREAKER_COOLDOWN_MS, diffSelection, readmitDue, needsDecisionDigest, environmentalDetail, closesManually } from "./reconcile.mjs";
|
|
128
129
|
import { parseDependsOn } from "../engine/phases.mjs";
|
|
129
130
|
import { classifyNeedsHuman, recoveryCodeOf, recoveryClassOf, OUTCOME_CODES, ENV_VALIDATE_PLACEMENT, ENV_VALIDATE_TIMEOUT, MECHANICAL_CODES } from "../engine/outcome-codes.mjs";
|
|
130
131
|
import { detectGateDeadlock, formatGateDeadlock } from "./gatewatch.mjs";
|
|
@@ -141,6 +142,8 @@ import { formatOverload } from "./hostload.mjs";
|
|
|
141
142
|
import { normalizeStacking, planAdmissible, stackAdmissible } from "./stacking.mjs";
|
|
142
143
|
import { lackedTools } from "./toolplace.mjs";
|
|
143
144
|
import { openPrerequisites } from "./prereq.mjs";
|
|
145
|
+
import { makeController, classifyRepo, formatConcurrency } from "./concurrency.mjs";
|
|
146
|
+
import { admitInput, breach, recordFailure, markEscalated, NO_NEW_INPUT } from "./attempts.mjs";
|
|
144
147
|
|
|
145
148
|
// A dependency that finished like this no longer blocks its dependents.
|
|
146
149
|
const SATISFIED = new Set(["merged", "invalid"]);
|
|
@@ -148,6 +151,7 @@ const DEFAULT_TRAIN_EVERY_MS = 30000; // #5836: merge-train poll period
|
|
|
148
151
|
// #5836: a lane that ended pr-ready is waiting on the merge train, not failed: its dependents wait
|
|
149
152
|
const WAITING_ON_TRAIN = (row) => row?.outcome === "pr-ready";
|
|
150
153
|
// #5162: a dependent of a root that ended like this is held (resumable), not skipped. #5805: also behind a root held on an engine/env change.
|
|
154
|
+
const ATTEMPT_FAILED = ["needs-human", "engine-error", "budget-exceeded", "failed"]; // #5986: final lane outcomes that count as a failed attempt
|
|
151
155
|
const HOLD_ROOT = new Set(["needs-human", "engine-error", "deferred", "budget-exceeded", "held"]);
|
|
152
156
|
/** #5162: members of a real dependency cycle (a nontrivial SCC or a self-loop) among `nodes`; `edgesOf(n)` lists n's dependencies. */
|
|
153
157
|
export function cyclicNodes(nodes, edgesOf) {
|
|
@@ -183,7 +187,7 @@ export const HOST_BUSY_RETRY_S = 60;
|
|
|
183
187
|
// #4528: a busy host or a full sandbox pool is a wait, not a failure: requeued after its retry-in, never capped.
|
|
184
188
|
// A lane that could not be resolved because gh/git failed (network blip) is the same kind of wait (#4791).
|
|
185
189
|
// #4788: an unreachable pool is a wait too (the lane already retried for unreachable_window_min); a stall is reported by poolStall.
|
|
186
|
-
const UNCAPPED_DEFERRALS = new Set(["host.busy", "sandbox.capacity", "sandbox.unreachable", "sandbox.repo_missing", "lane.unresolved"]);
|
|
190
|
+
const UNCAPPED_DEFERRALS = new Set(["host.busy", "sandbox.capacity", "sandbox.unreachable", "sandbox.repo_missing", "lane.unresolved", "base.red"]); // #5992: a red base is the base's wait, never the issue's
|
|
187
191
|
export const POOL_OFFLINE_ALERT_MIN = 10;
|
|
188
192
|
// #5112: `sandbox.capacity` deferrals of one issue after which `execution.fallback_local` runs it on the host (headroom permitting).
|
|
189
193
|
export const CAPACITY_FALLBACK_AFTER = 3;
|
|
@@ -336,12 +340,12 @@ const toMap = (o) => new Map(Object.entries(o ?? {}).map(([k, v]) => [Number(k),
|
|
|
336
340
|
* @returns {Promise<Array<{issue:number, outcome:string, pr:?number, cost_usd:number, minutes:number, detail?:string}>>}
|
|
337
341
|
*/
|
|
338
342
|
export async function orchestrate({ issues, parallel = 3, runOne, readBody, prefilter = null, resolveLane = null, now = () => Date.now(), blockedRefreshMs = 60000, onUpdate = () => {}, onCrossLane = () => {},
|
|
339
|
-
store = null, adopt = null, getParallel = null, getAdded = null, getRequeued = null, breaker = null, maxDeferrals = DEFAULT_MAX_DEFERRALS, sleep = cancellableSleep, pollMs = 5000, getClearBreaker = null, consumeClearBreaker = null, ackClearBreaker = null,
|
|
340
|
-
classify = null, maintenance = null, limits = null, identity = () => "default", batchId = null, drift = null, integration = null, sched = null, priorityOf = null, remote = null, beforeAdmit = null, preflight = null,
|
|
341
|
-
recovery = null, decide = () => {}, conflicting = null, relabelNeedsHuman = null, markRecovering = null, onExit = null, issueLabels = null, issueState = null, getCancelled = null, getHeld = null, expireHolds = null, getHoldInfo = null, getBlocked = null, trusted = null, getGates = null, stopLane = null, releaseLease = null, stopRetryMs = STOP_RETRY_MS, stopTimeoutMs = STOP_TIMEOUT_MS,
|
|
343
|
+
store = null, adopt = null, getParallel = null, usageRows = null, repoSlug = null, repoOf = null, getAdded = null, getRequeued = null, reconcile = null, select = null, breaker = null, maxDeferrals = DEFAULT_MAX_DEFERRALS, sleep = cancellableSleep, pollMs = 5000, getClearBreaker = null, consumeClearBreaker = null, ackClearBreaker = null,
|
|
344
|
+
classify = null, maintenance = null, limits = null, identity = () => "default", batchId = null, drift = null, integration = null, sched = null, priorityOf = null, remote = null, beforeAdmit = null, preflight = null, baseProbe = null,
|
|
345
|
+
recovery = null, decide = () => {}, conflicting = null, relabelNeedsHuman = null, markRecovering = null, onExit = null, issueLabels = null, issueState = null, getCancelled = null, getHeld = null, expireHolds = null, getPause = null, expirePause = null, getHoldInfo = null, getBlocked = null, trusted = null, getGates = null, stopLane = null, releaseLease = null, suspendLane = null, stopRetryMs = STOP_RETRY_MS, stopTimeoutMs = STOP_TIMEOUT_MS,
|
|
342
346
|
estimate = null, starveMs = DEFAULT_STARVE_MS, setupConcurrency = DEFAULT_SETUP_CONCURRENCY, signal = null, dispatchCheck = null, syncParked = null, syncEveryMs = DEFAULT_SYNC_EVERY_MS, lifecycle = null,
|
|
343
347
|
getChildren = null, autoChildren = null, baseWait = null, rotator = null, stacking = "off", readPrReady = null, transientRetries = DEFAULT_TRANSIENT_RETRIES, overload = null, version = null, onInterrupted = null, envHold = null, envIssue = null, logicalDeps = null,
|
|
344
|
-
train = null, trainEveryMs = DEFAULT_TRAIN_EVERY_MS }) {
|
|
348
|
+
train = null, trainEveryMs = DEFAULT_TRAIN_EVERY_MS, attempts = null }) {
|
|
345
349
|
const saved = store?.load?.() ?? null;
|
|
346
350
|
if (train && saved?.train) train.restore(saved.train); // #5836: the merge train resumes with the batch
|
|
347
351
|
const order = saved ? [...saved.order] : [];
|
|
@@ -351,6 +355,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
351
355
|
const crossSeen = new Set(saved?.crossSeen ?? []);
|
|
352
356
|
const results = toMap(saved?.results); // issue -> final row
|
|
353
357
|
const running = new Map(); // issue -> promise
|
|
358
|
+
const keptBoxes = toMap(saved?.kept); // #6008: issue -> {issue, since, phase}: sandboxes kept for adopt (no dispatcher lease)
|
|
354
359
|
const runRecs = toMap(saved?.running); // issue -> {startedAt, lane, pid?}: persisted so a restart can adopt the lane
|
|
355
360
|
const pending = [...(saved?.pending ?? [])];
|
|
356
361
|
const notBefore = toMap(saved?.notBefore);
|
|
@@ -370,6 +375,8 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
370
375
|
// filed or updated); affected product issues are held on it (never needs-human) and 2+ issues on a signature stop admitting lanes that need it.
|
|
371
376
|
const envSigs = toMap(saved?.envSigs);
|
|
372
377
|
const engineSigs = toMap(saved?.engineSigs);
|
|
378
|
+
const readmit = toMap(saved?.readmit); // #5978: re-admission policy state (backoff step, version and base seen) per ended issue
|
|
379
|
+
const ledgers = toMap(saved?.attempts); // #5986: issue -> attempts ledger; never cleared by releaseHeld, --requeue or --set-env (see attempts.mjs)
|
|
373
380
|
const deterministic = new Set(saved?.deterministicSigs ?? []);
|
|
374
381
|
const toolReadmits = new Set(saved?.toolReadmits ?? []);
|
|
375
382
|
const ehMaxMs = Number(envHold?.maxMs) > 0 ? Number(envHold.maxMs) : ENV_HOLD_MAX_MS;
|
|
@@ -405,8 +412,10 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
405
412
|
const quota = toMap(saved?.quota); // issue -> {cost_usd, minutes, resumeAt (epoch ms), rotations}
|
|
406
413
|
let tripped = saved?.breaker ?? null;
|
|
407
414
|
let pfAll = false, pfRemote = false, pfNoted = new Set(); // #4866: lane preflight holds
|
|
415
|
+
let baseRedHold = null; // #5992: {sha, issue, detail}: the base is red; only the attributed fixer is admitted until the sha moves or the guard passes
|
|
408
416
|
let opHeld = new Set(); // #4592: operator-held issues this pass (the batch `hold` file is the authority)
|
|
409
417
|
const opHeldHit = new Set(); // held issues that were pending this pass
|
|
418
|
+
let opPause = null, pauseHit = false; // #5975: the batch-level pause (the `pause` file is the authority); pauseHit: an issue was pending behind it this pass
|
|
410
419
|
// #4376: operator cancel (the batch `cancel` file through `getCancelled`); persisted, but the file stays the authority.
|
|
411
420
|
let cancelled = getCancelled ? (saved?.cancelled ?? null) : null;
|
|
412
421
|
const budget = maintenance && Number(maintenance.share) > 0 ? { share: Number(maintenance.share), whenIdle: !!maintenance.whenIdle } : null;
|
|
@@ -492,6 +501,10 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
492
501
|
const everRelabelled = new Set(saved?.relabelled ?? []); // #4656: issues the runner already relabelled; never parked on top
|
|
493
502
|
const relabelled = new Set(saved?.relabelled ?? []); // #4315: queued recoveries relabelled needs-human when a batch stopped
|
|
494
503
|
// #4267: decisions are recorded, never awaited: a failing or slow recorder cannot block the batch.
|
|
504
|
+
// #5985: the controller moves are persisted to log.jsonl with their inputs (the post-deploy check reads them)
|
|
505
|
+
const conc = makeController({ ceiling: parallel, now });
|
|
506
|
+
let heavyHeldHit = false;
|
|
507
|
+
const concEmit = (e) => { if (!e) return; const ev = { ...e, batch: batchId ?? null, running: running.size, line: formatConcurrency({ running: running.size, k: e.k, ceiling: e.ceiling, factor: e.factor }) }; try { store?.log?.(ev); } catch { /* advisory */ } onUpdate(ev); };
|
|
495
508
|
const decided = (d) => { try { Promise.resolve(decide?.(d)).catch(() => {}); } catch { /* best effort */ } };
|
|
496
509
|
const firstLine = (x) => String(x ?? "").split("\n")[0].slice(0, 300);
|
|
497
510
|
|
|
@@ -499,7 +512,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
499
512
|
let halted = false; // #4454: stopped by `signal`; the batch's state is no longer this process's to write
|
|
500
513
|
const save = () => {
|
|
501
514
|
if (!store || halted) return;
|
|
502
|
-
store.save({ v: 1, ...(setup ? { phase: "setup", setup: { ...setup } } : {}), engineVersion: version, order, deps: toObj(deps), lanes: toObj(lanes), crossSeen: [...crossSeen], results: toObj(results), running: toObj(runRecs),
|
|
515
|
+
store.save({ v: 1, ...(setup ? { phase: "setup", setup: { ...setup } } : {}), engineVersion: version, order, deps: toObj(deps), lanes: toObj(lanes), crossSeen: [...crossSeen], results: toObj(results), running: toObj(runRecs), ...(keptBoxes.size ? { kept: toObj(keptBoxes) } : {}),
|
|
503
516
|
pending, notBefore: toObj(notBefore), requeues: toObj(requeues), deferrals: toObj(deferrals), engineErrors: toObj(engineErrors), ...(transients.size ? { transientRetries: toObj(transients) } : {}), ...(quota.size ? { quota: toObj(quota) } : {}), ...(limitedAccounts.size ? { limitedAccounts: toObj(limitedAccounts) } : {}), ...(capDefers.size ? { capDeferrals: toObj(capDefers) } : {}), ...(capReasons.size ? { capReasons: toObj(capReasons) } : {}),
|
|
504
517
|
prefilter: toObj(checked), errorTimes, breaker: tripped, ...(agentRestarts.length ? { agentRestarts, lostRequeued: [...lostOnce] } : {}), ...(budget ? { classes: toObj(classes), dispatch: { ...dispatch } } : {}),
|
|
505
518
|
...(reg ? { priorities: toObj(priorities) } : {}), ...(sandboxUse.size ? { sandbox: toObj(sandboxUse) } : {}),
|
|
@@ -509,9 +522,14 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
509
522
|
...(requeueApplied.size ? { requeueApplied: [...requeueApplied], requeued: toObj(requeuedInfo) } : {}),
|
|
510
523
|
...(relabelled.size ? { relabelled: [...relabelled] } : {}), ...(cancelled ? { cancelled } : {}), ...(train ? { train: train.snapshot() } : {}),
|
|
511
524
|
...(estimate ? { estimates: toObj(estimates), enqueued: toObj(enqueued) } : {}), ...(heads.size ? { heads: [...heads] } : {}),
|
|
512
|
-
...(engineSigs.size ? { engineSigs: toObj(engineSigs) } : {}), ...(deterministic.size ? { deterministicSigs: [...deterministic] } : {}), ...(toolReadmits.size ? { toolReadmits: [...toolReadmits] } : {}), ...(envSigs.size ? { envSigs: toObj(envSigs) } : {}) });
|
|
525
|
+
...(engineSigs.size ? { engineSigs: toObj(engineSigs) } : {}), ...(deterministic.size ? { deterministicSigs: [...deterministic] } : {}), ...(toolReadmits.size ? { toolReadmits: [...toolReadmits] } : {}), ...(select ? { select } : {}), ...(readmit.size ? { readmit: toObj(readmit) } : {}), ...(envSigs.size ? { envSigs: toObj(envSigs) } : {}), ...(ledgers.size ? { attempts: toObj(ledgers) } : {}) });
|
|
513
526
|
};
|
|
514
527
|
const update = (row) => { store?.log?.(row); onUpdate(row); };
|
|
528
|
+
// #5978 R11: a merge into a staging lane branch does not fire `Closes`: the seam closes the issue and folds its post-deploy checks into the release rollup.
|
|
529
|
+
const closeOnLane = async (n, lane, row) => {
|
|
530
|
+
if (!reconcile?.closeIssue || !closesManually(lane)) return;
|
|
531
|
+
try { await reconcile.closeIssue(n, { lane, row }); update({ issue: n, outcome: "closed", detail: `closed on merge into ${lane}` }); } catch (err) { update({ issue: n, outcome: "close-failed", detail: String(err?.message ?? err).slice(0, 200) }); }
|
|
532
|
+
};
|
|
515
533
|
/** #5755: records `issue` on its signature and files or updates the one env issue (seam `envIssue.ensure`); the issue number, or null when none could be filed. */
|
|
516
534
|
const fileEnvIssue = async ({ sig, code, issue, tools, evidence }) => {
|
|
517
535
|
const e = envSigs.get(sig) ?? { issues: [], number: null };
|
|
@@ -779,7 +797,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
779
797
|
let cap = null, probeFailed = false;
|
|
780
798
|
try { cap = remote.capacity?.() ?? null; } catch { probeFailed = true; }
|
|
781
799
|
// #5048: only a failed probe (a throw) marks the pool down; null is unknown (first pass, no capacity()) and leaves the state; a sample clears it.
|
|
782
|
-
if (probeFailed) notePool(true, "capacity probe failed"); else if (cap !== null) notePool(false);
|
|
800
|
+
if (probeFailed) notePool(true, "capacity probe failed"); else if (cap !== null) { notePool(false); concEmit(conc.observe(cap)); } // #5985: the live sample moves the operating point
|
|
783
801
|
// #4788: zero live agents for longer than `remote.poolOfflineMin` (default 10): one loud batch event, none while online > 0.
|
|
784
802
|
if (cap && cap.online === 0) {
|
|
785
803
|
poolOfflineSince ??= now();
|
|
@@ -799,10 +817,11 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
799
817
|
decided({ issue: n, what: `run #${n} on the host: the pool refused it ${capDefers.get(n)} times for capacity (execution.fallback_local)`, why: "sustained sandbox.capacity and the host has headroom",
|
|
800
818
|
alternative: "keep deferring until a pool slot frees" });
|
|
801
819
|
}
|
|
802
|
-
} else if (cap && Number.isInteger(cap.free)) {
|
|
820
|
+
} else if (cap && (Number.isInteger(cap.free) || capWait.conditional(n, cap))) {
|
|
803
821
|
if (cap.at !== capAt) { capAt = cap.at; capAdmits = 0; }
|
|
804
|
-
|
|
805
|
-
if (
|
|
822
|
+
// #5985: a refusal's named condition (load < 1.0, free mem > floor) and the per-lane refusal hold gate the relaunch, not the timer
|
|
823
|
+
if (capWait.blocked(n, cap) || conc.holding(n, cap)) { notBefore.set(n, now() + Math.max(pollMs, 1)); return false; }
|
|
824
|
+
if (Number.isInteger(cap.free) && capAdmits >= cap.free && remoteRun.size < remoteMax()) { notBefore.set(n, now() + Math.max(pollMs, 1)); return false; }
|
|
806
825
|
}
|
|
807
826
|
if (p.where === "remote" && remoteRun.size < remoteMax()) { remoteCapped.delete(n); capWait.admitted(n); remoteRun.add(n); capAdmits++; placed.set(n, p); return true; }
|
|
808
827
|
if (p.where === "remote" && !remote.fallbackLocal) { remoteCapped.add(n); return false; }
|
|
@@ -848,14 +867,16 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
848
867
|
const requeue = (n, delayMs) => { pending.push(n); enqueued.set(n, now()); if (delayMs > 0) notBefore.set(n, now() + delayMs); else notBefore.delete(n); };
|
|
849
868
|
const TRANSPORT_COOLDOWN_MS = 5 * 60000;
|
|
850
869
|
const netTransients = new Map(); // #5947: issue -> net.transient deferrals (backoff step)
|
|
870
|
+
const envDetails = []; // #5978: the details of the recent engine-errors, for the breaker auto-reset
|
|
851
871
|
let transportErrors = 0; // #4685: engine-errors in the current window that were link failures
|
|
852
872
|
const noteEngineError = (detail = "") => {
|
|
853
873
|
if (!breaker) return;
|
|
854
874
|
const t = now(), windowMs = breaker.window_min * 60000;
|
|
855
875
|
errorTimes = [...errorTimes.filter((x) => t - x < windowMs), t];
|
|
876
|
+
envDetails.push(detail); if (envDetails.length > breaker.errors) envDetails.shift();
|
|
856
877
|
transportErrors = isTransientEngineError(detail) ? Math.min(transportErrors + 1, errorTimes.length) : 0;
|
|
857
878
|
if (!tripped && errorTimes.length >= breaker.errors) {
|
|
858
|
-
tripped = { at: t, ...(transportErrors >= errorTimes.length ? { transport: true } : {}), detail: `circuit breaker: ${errorTimes.length} engine-errors within ${breaker.window_min} min; admissions stopped` };
|
|
879
|
+
tripped = { at: t, ...(envDetails.length && envDetails.every(environmentalDetail) ? { environmental: true } : {}), ...(transportErrors >= errorTimes.length ? { transport: true } : {}), detail: `circuit breaker: ${errorTimes.length} engine-errors within ${breaker.window_min} min; admissions stopped` };
|
|
859
880
|
update({ issue: null, outcome: "breaker", detail: tripped.detail });
|
|
860
881
|
}
|
|
861
882
|
return t;
|
|
@@ -900,6 +921,24 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
900
921
|
if (changed) save();
|
|
901
922
|
};
|
|
902
923
|
|
|
924
|
+
// #5986: a failed lane lands in the issue's ledger; a lifetime-budget breach escalates once (FORGE:ESCALATION, needs-human) and parks the row.
|
|
925
|
+
const recordAttempt = async (n, row, r) => {
|
|
926
|
+
try {
|
|
927
|
+
const hash = (await attempts.hash?.(n)) ?? null;
|
|
928
|
+
let l = ledgers.get(n) ?? (await attempts.load?.(n)) ?? null;
|
|
929
|
+
l = recordFailure(l, { signature: failureSignature(row.code ?? r?.code, row.detail), hash, spend: Number(row.cost_usd) || 0, run: r?.runUrl ?? null });
|
|
930
|
+
const b = breach(l, attempts.cfg);
|
|
931
|
+
if (b && !l.escalated) {
|
|
932
|
+
l = markEscalated(l);
|
|
933
|
+
await attempts.notify?.({ issue: n, code: "escalate", ledger: l, reason: b.detail });
|
|
934
|
+
if (row.outcome !== "needs-human") { row.detail = `attempts.exhausted: ${b.detail}\n${String(row.detail ?? "")}`; row.outcome = "needs-human"; }
|
|
935
|
+
decided({ issue: n, what: `escalated #${n} to a person: ${b.detail}`, why: "lifetime attempt budget (#5986)", alternative: "run another lane on the same input" });
|
|
936
|
+
}
|
|
937
|
+
ledgers.set(n, l);
|
|
938
|
+
const comments = await attempts.mirror?.(n, l);
|
|
939
|
+
if (Number.isInteger(comments)) ledgers.set(n, { ...l, comments });
|
|
940
|
+
} catch { /* the ledger is best effort: a failed write never changes the lane's outcome */ }
|
|
941
|
+
};
|
|
903
942
|
// Apply one lane's result: requeue it (deferred, dependency-open, engine-error) or record its final row.
|
|
904
943
|
const settleLane = async (n, r, rec, pf) => {
|
|
905
944
|
if (halted) return; // #4454: a resume adopts the lane and settles it
|
|
@@ -1042,11 +1081,15 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1042
1081
|
const pol = deferPolicy(r, { now: now(), deferrals: deferrals.get(n) ?? 0, maxDeferrals });
|
|
1043
1082
|
let capGated = false; // #4909: the pool reports free slots, so the slot (not the retry-in timer) gates the relaunch
|
|
1044
1083
|
if (r?.code === "sandbox.unreachable") notePool(true, r.detail ?? "sandbox unreachable");
|
|
1084
|
+
if (r?.code === "base.red" && baseProbe && !baseRedHold) { // #5992: a lane's base.red result raises the one batch hold at once (its guardRed verdict is cached, so this runs no second probe)
|
|
1085
|
+
try { const v = await baseProbe(); if (v?.red) { const issue = Number.isInteger(v.att?.issue) ? v.att.issue : null, detail = `base.red: base ${String(v.sha).slice(0, 12)} is red on ${(v.commands ?? []).join(", ") || "a guard command"}${v.att ? `; last change ${String(v.att.sha).slice(0, 12)}${issue ? ` (#${issue})` : ""}` : ""}; admissions paused until the base moves`; update({ issue: null, outcome: "preflight", code: "base.red", detail }); baseRedHold = { sha: v.sha, issue, detail }; } } catch { /* the next pass probes */ }
|
|
1086
|
+
}
|
|
1045
1087
|
if (r?.code === "sandbox.capacity") {
|
|
1046
|
-
capWait.refused(n);
|
|
1088
|
+
capWait.refused(n, r.reason ?? null);
|
|
1089
|
+
concEmit(conc.refused({ issue: n, code: r.code, reason: r.reason, live: r.live ?? null })); // #5985
|
|
1047
1090
|
if (r.detail) capReasons.set(n, String(r.detail).slice(0, 300));
|
|
1048
1091
|
capDefers.set(n, (capDefers.get(n) ?? 0) + 1); // #5112: counted for the fallback_local capacity fallback
|
|
1049
|
-
try {
|
|
1092
|
+
try { const c = remote?.capacity?.(); capGated = Number.isInteger(c?.free) || capWait.conditional(n, c); } catch { capGated = false; }
|
|
1050
1093
|
}
|
|
1051
1094
|
if (!pol.capped) {
|
|
1052
1095
|
if (!pol.host && !pol.hold) deferrals.set(n, (deferrals.get(n) ?? 0) + 1);
|
|
@@ -1220,7 +1263,8 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1220
1263
|
// #5652: a remote lane's tool/capability end is not recovered on the host when host fallback is off; the lane message names the fix
|
|
1221
1264
|
const noHostRecovery = !hostFallbackOn() && row.placement?.where === "remote" && [OUTCOME_CODES.ENV_CAPABILITY_REMOTE, OUTCOME_CODES.ENV_TOOL_MISSING].includes(row.code);
|
|
1222
1265
|
if (noHostRecovery) decided({ issue: n, what: `no host re-placement for ${row.code}: host fallback is off (execution.host_fallback / host.role: orchestrator)`, why: firstLine(row.detail), alternative: "re-place the lane on the host" });
|
|
1223
|
-
|
|
1266
|
+
// #5979: failure.repeated is a typed park (not in RECOVERABLE_CODES): never relaunched, reported parked below
|
|
1267
|
+
if (!repeatEnv && !noHostRecovery && !sameHostReplay && row.code !== OUTCOME_CODES.FAILURE_REPEATED && classifyNeedsHuman(facts) === "recoverable" && used < max) {
|
|
1224
1268
|
// #5727: the first remote end on a tool no recipe can install, before any build work, is re-placed on the host without spending an attempt
|
|
1225
1269
|
const free = !prior && r?.toolNoRecipe === true && row.code === OUTCOME_CODES.ENV_TOOL_MISSING && row.placement?.where === "remote" && !freeRecovered.has(n);
|
|
1226
1270
|
const code = recoveryCodeOf(facts), attempt = used + 1;
|
|
@@ -1249,8 +1293,10 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1249
1293
|
if (row.outcome === "needs-human" && !row.parkedQueued && !row.securityEscalated && !everRelabelled.has(n) && typeof relabelNeedsHuman === "function" && (cls => cls === "parked" || (cls === "recoverable" && prior))(classifyNeedsHuman({ ...row, issueEdited: r?.issueEdited === true }, { parked: true }))) { // a recoverable row with a finished recovery has used its attempts
|
|
1250
1294
|
try { const res = await relabelNeedsHuman({ issue: n, parked: { code: row.code, pr: Number.isInteger(row.pr) ? row.pr : null }, evidence: `Mechanical park \`${row.code}\`${Number.isInteger(row.pr) ? ` (PR #${row.pr})` : ""}:\n${String(row.detail ?? "")}` }); if (res !== false && res !== "failed" && res !== "skipped") row.parkedQueued = true; else if (res === false || res === "failed") { const ev = { event: "relabel.failed", issue: n, batch: batchId ?? null, detail: `parked relabel failed (${row.code}): needs-human kept` }; try { store?.log?.(ev); } catch { /* best effort */ } onUpdate(ev); } } catch { /* best effort */ }
|
|
1251
1295
|
}
|
|
1296
|
+
if (attempts && ATTEMPT_FAILED.includes(row.outcome)) await recordAttempt(n, row, r); // #5986
|
|
1252
1297
|
results.set(n, row);
|
|
1253
1298
|
if (row.outcome === "merged" && lifecycle && r?.milestone) lifecycleTitles.add(String(r.milestone)); // #4657
|
|
1299
|
+
if (row.outcome === "merged") await closeOnLane(n, rec?.lane ?? r?.lane, row);
|
|
1254
1300
|
if (row.outcome === "merged" && integration?.onMerged && String(rec?.lane ?? r?.lane ?? "").startsWith("milestone/")) {
|
|
1255
1301
|
// #4667: counts the merge toward the milestone's integration run; an error is a row, never the outcome.
|
|
1256
1302
|
try { await integration.onMerged(n, { ...row, lane: rec?.lane ?? r?.lane }, r); } catch (e) { update({ issue: n, outcome: "integration", detail: `integration check failed: ${String(e?.message ?? e).slice(0, 300)}` }); }
|
|
@@ -1268,6 +1314,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1268
1314
|
// #5437: a lane's post-run bookkeeping (r.postRun) starts once its slot is free; the batch waits for it before it ends.
|
|
1269
1315
|
const postRuns = new Set();
|
|
1270
1316
|
const settle = async (n, r, rec, pf) => {
|
|
1317
|
+
if (r?.kept) keptBoxes.set(n, r.kept); // #6008
|
|
1271
1318
|
await settleLane(n, r, rec, pf);
|
|
1272
1319
|
if (typeof r?.postRun !== "function") return;
|
|
1273
1320
|
const p = Promise.resolve().then(() => r.postRun()).catch(() => {}).finally(() => postRuns.delete(p));
|
|
@@ -1299,7 +1346,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1299
1346
|
heads.delete(n); enqueued.delete(n); busyNoted.delete(n);
|
|
1300
1347
|
const rec = { startedAt: now(), ...(plan ? { plan: true } : {}), ...(stackedOn ? { stackedOn } : {}), ...(queueMs != null ? { queueMs } : {}), ...(lane ? { lane } : {}), ...(remoteRun.has(n) ? { remote: true } : {}), ...(pl ? { placement: pl } : {}) };
|
|
1301
1348
|
if (!firstAdmit.has(n)) firstAdmit.set(n, rec.startedAt); // #5834: chain wall time starts at the first admission, plan lane included
|
|
1302
|
-
runRecs.set(n, rec); notBefore.delete(n); capReasons.delete(n); save();
|
|
1349
|
+
runRecs.set(n, rec); keptBoxes.delete(n); notBefore.delete(n); capReasons.delete(n); save();
|
|
1303
1350
|
track(n, (async () => {
|
|
1304
1351
|
// Pre-filter once per issue (a requeued issue is not re-checked); fail-open: an error means a normal lane.
|
|
1305
1352
|
if (prefilter && !checked.has(n)) { let pf = null; try { pf = await prefilter(n, lane); } catch { pf = null; } checked.set(n, pf); save(); }
|
|
@@ -1311,7 +1358,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1311
1358
|
if (!["merged", "invalid", "deferred"].includes(gone?.outcome)) gone = null; // #4920: deferred = another lane owns the issue (lease or open PR on GitHub)
|
|
1312
1359
|
}
|
|
1313
1360
|
// #5526: a hold placed since the pass read is honoured at launch: the issue goes back to pending, no lane
|
|
1314
|
-
if (!cancelled && !halted) { refreshHeld(); if (opHeld.has(n)) { running.delete(n); runRecs.delete(n); releaseSlot(n); endRemote(n); requeue(n, 0); save(); return; } }
|
|
1361
|
+
if (!cancelled && !halted) { refreshHeld(); refreshPause(); if (opHeld.has(n) || opPause) { running.delete(n); runRecs.delete(n); releaseSlot(n); endRemote(n); requeue(n, 0); save(); return; } }
|
|
1315
1362
|
if (halted) return; // #4454: stopped before launch; no pid, so a resume queues it again
|
|
1316
1363
|
let r;
|
|
1317
1364
|
if (cancelled) r = { terminalReason: "deferred", code: "run.interrupted", cost_usd: 0, detail: "cancelled before launch" }; // #4376
|
|
@@ -1396,7 +1443,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1396
1443
|
|
|
1397
1444
|
// #5469: a final held row names the owner and since when the hold recorded them (`forgedock orchestrate --hold ... --for`)
|
|
1398
1445
|
const heldByOperator = (n) => { let e = null; try { e = getHoldInfo?.()?.[n] ?? null; } catch { e = null; } return e ? `held by operator (${e.owner}, since ${e.since})` : "held by operator"; };
|
|
1399
|
-
const heldDetail = (n) => cancelled ? "cancelled by operator" : opHeld.has(n) ? heldByOperator(n) : baseHeld.has(n) ? baseHeld.get(n) : tripped?.detail ?? (integHeld.has(n) ? `integration: ${integHeld.get(n)}` : (driftHeld.has(n) ? `drift: ${driftHeld.get(n)} flagged` : budgetStop ? `execution budget: ${budgetStop}` : budgetHeld ? "maintenance share" : "not run"));
|
|
1446
|
+
const heldDetail = (n) => cancelled ? "cancelled by operator" : opHeld.has(n) ? heldByOperator(n) : opPause ? pauseText() : baseHeld.has(n) ? baseHeld.get(n) : tripped?.detail ?? (integHeld.has(n) ? `integration: ${integHeld.get(n)}` : (driftHeld.has(n) ? `drift: ${driftHeld.get(n)} flagged` : budgetStop ? `execution budget: ${budgetStop}` : budgetHeld ? "maintenance share" : "not run"));
|
|
1400
1447
|
// #4315: a recovery queued but never launched (the batch stopped: breaker, budget, hold; or a resume that did not relaunch a
|
|
1401
1448
|
// lost run) left the issue without needs-human, since a non-final attempt does not relabel. Relabel it once, with the full reason.
|
|
1402
1449
|
// #4318: also on a throw out of the loop and on a signal (`onExit`); `cause` overrides the held reason. Runs once per process.
|
|
@@ -1416,11 +1463,47 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1416
1463
|
if (typeof onExit === "function") { try { onExit(relabelQueued); } catch { /* best effort */ } }
|
|
1417
1464
|
|
|
1418
1465
|
// #4408: issues added to the running batch; returns how many joined. Re-reading the cumulative list is a no-op.
|
|
1466
|
+
// #5978: standing order (`--select`): one reconcile per interval. Matching open issues and engine-filed env.* issues join through
|
|
1467
|
+
// the `getAdded` path below; closed or moved pending issues leave; ended deferred/held/engine-error/conformance rows are requeued
|
|
1468
|
+
// through `drainRequeues` by policy (reconcile.mjs). Same DAG, priority and lane rules as an operator `--add`/`--requeue`.
|
|
1469
|
+
let nextReconcile = 0, parkedDigest = "";
|
|
1470
|
+
const selFresh = [], autoRequeues = [], selMatched = new Set(); // #6022: issues the selector has matched in this run
|
|
1471
|
+
const reconcileTick = async () => {
|
|
1472
|
+
if (!reconcile) return;
|
|
1473
|
+
const t = now();
|
|
1474
|
+
if (t < nextReconcile) return;
|
|
1475
|
+
nextReconcile = t + (reconcile.everyMs ?? RECONCILE_MS);
|
|
1476
|
+
let open = null;
|
|
1477
|
+
try { open = await reconcile.list(); } catch { open = null; } // a failed read never makes anything leave
|
|
1478
|
+
const labels = new Map((open ?? []).map((o) => [o.number, o.labels ?? []]));
|
|
1479
|
+
if (open) {
|
|
1480
|
+
const { join, leave } = diffSelection({ open, members: [...set], pending, running, results, matched: selMatched });
|
|
1481
|
+
for (const o of open) selMatched.add(o.number);
|
|
1482
|
+
selFresh.push(...join);
|
|
1483
|
+
for (const n of leave) {
|
|
1484
|
+
pending.splice(pending.indexOf(n), 1);
|
|
1485
|
+
skip(n, "left the selector: closed or moved");
|
|
1486
|
+
}
|
|
1487
|
+
if (leave.length) save();
|
|
1488
|
+
}
|
|
1489
|
+
for (const e of envSigs.values()) if (Number.isInteger(e.number) && !set.has(e.number)) selFresh.push(e.number); // R7: the engine-filed env.* issue joins the order
|
|
1490
|
+
let base = null;
|
|
1491
|
+
try { base = (await reconcile.base?.()) ?? null; } catch { base = null; }
|
|
1492
|
+
const { requeue, parked } = readmitDue({ results, state: readmit, now: t, version: reconcile.version?.() ?? null, base, labels: (n) => labels.get(n) ?? [] });
|
|
1493
|
+
for (const q of requeue) autoRequeues.push({ issue: q.issue, at: `reconcile-${t}`, reason: q.reason, by: "reconcile" });
|
|
1494
|
+
const digest = needsDecisionDigest(parked);
|
|
1495
|
+
if (digest !== parkedDigest) {
|
|
1496
|
+
parkedDigest = digest;
|
|
1497
|
+
if (digest) decided({ issue: null, what: digest, why: "one recovery attempt used; parked for an operator instead of lost", alternative: "forgedock orchestrate --requeue after deciding" });
|
|
1498
|
+
}
|
|
1499
|
+
if (requeue.length || parked.length) save();
|
|
1500
|
+
};
|
|
1419
1501
|
const drainAdds = async () => {
|
|
1420
1502
|
const kids = await drainChildren();
|
|
1421
|
-
|
|
1503
|
+
await reconcileTick();
|
|
1504
|
+
if (!getAdded && !selFresh.length) return kids;
|
|
1422
1505
|
let got = [];
|
|
1423
|
-
try { got = getAdded() ?? []; } catch { got = []; }
|
|
1506
|
+
try { got = [...(getAdded?.() ?? []), ...selFresh.splice(0)]; } catch { got = []; }
|
|
1424
1507
|
const fresh = [...new Set((Array.isArray(got) ? got : []).filter((n) => Number.isSafeInteger(n) && n > 0 && !set.has(n)))];
|
|
1425
1508
|
if (!fresh.length) return kids;
|
|
1426
1509
|
// An edge an operator wrote into a pending issue after the batch started (it waits on an added issue) holds too.
|
|
@@ -1474,9 +1557,9 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1474
1557
|
// #4550: `--requeue` entries (batch `requeue` file) not applied yet: a terminal issue and the dependents skipped behind it
|
|
1475
1558
|
// return to pending, the prior rows kept in history; their `Depends on` edges are re-read from the body and replaced (#5112).
|
|
1476
1559
|
const drainRequeues = async () => {
|
|
1477
|
-
if (!getRequeued) return 0;
|
|
1560
|
+
if (!getRequeued && !autoRequeues.length) return 0;
|
|
1478
1561
|
let got = [];
|
|
1479
|
-
try { got = getRequeued() ?? []; } catch { got = []; }
|
|
1562
|
+
try { got = [...(getRequeued?.() ?? []), ...autoRequeues.splice(0)]; } catch { got = []; }
|
|
1480
1563
|
const fresh = (Array.isArray(got) ? got : []).filter((e) => Number.isSafeInteger(e?.issue) && !requeueApplied.has(requeueKey(e)));
|
|
1481
1564
|
let n = 0;
|
|
1482
1565
|
for (const e of fresh) {
|
|
@@ -1549,6 +1632,33 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1549
1632
|
s.at = t;
|
|
1550
1633
|
try { Promise.resolve(stopLane(n, rec)).then((ok) => { if (ok !== false) s.accepted = true; }, () => {}); } catch { /* best effort */ }
|
|
1551
1634
|
}
|
|
1635
|
+
// #6008: hold and pause reach a kept sandbox through the durable marker on its issue (the sandbox cannot read batch files); cleared on release/unpause.
|
|
1636
|
+
const markKept = (ns, on, reason) => { if (!suspendLane) return; for (const n of ns) { try { Promise.resolve(suspendLane(n, on, reason)).catch(() => {}); } catch { /* best effort */ } } };
|
|
1637
|
+
// #5975: the batch pause. `paused (reason, until …)`, the one text every surface shows.
|
|
1638
|
+
function pauseText(p = opPause) { return `paused (${p?.reason ?? "no reason given"}, until ${p?.expiresAt ?? "unpause"})`; }
|
|
1639
|
+
function refreshPause() {
|
|
1640
|
+
if (!getPause) return;
|
|
1641
|
+
if (expirePause) { // like #5469 holds: a pause past its expiry is lifted here, with a row and a decision
|
|
1642
|
+
let e = null; try { e = expirePause() ?? null; } catch { e = null; }
|
|
1643
|
+
if (e) {
|
|
1644
|
+
decided({ issue: null, what: `pause expired (paused by ${e.owner} since ${e.since}${e.reason ? `: ${e.reason}` : ""}); admission resumed`, why: "pause expiry (--pause --for)", alternative: "pause it again" });
|
|
1645
|
+
update({ issue: null, outcome: "pause-expired", detail: `${e.owner}, since ${e.since}` });
|
|
1646
|
+
if (e.ownerGone) update({ issue: null, outcome: "hold-alert", detail: `the pause owner session (${e.owner}) is gone; the pause expired and admission resumed` });
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
let got = null; try { got = getPause() ?? null; } catch { got = opPause; }
|
|
1650
|
+
const next = got && typeof got === "object" ? got : null;
|
|
1651
|
+
if (next && !opPause) {
|
|
1652
|
+
decided({ issue: null, what: `batch ${pauseText(next)} (forgedock orchestrate --pause); running lanes continue`, why: "operator request", alternative: "cancel the batch" });
|
|
1653
|
+
update({ issue: null, outcome: "pause", detail: pauseText(next) });
|
|
1654
|
+
} else if (!next && opPause) {
|
|
1655
|
+
decided({ issue: null, what: "batch unpaused (forgedock orchestrate --unpause); admission resumed", why: "operator request", alternative: "resume the batch" });
|
|
1656
|
+
update({ issue: null, outcome: "unpause", detail: "admission resumed" });
|
|
1657
|
+
}
|
|
1658
|
+
if (next && !opPause) markKept([...keptBoxes.keys()], true, "paused");
|
|
1659
|
+
else if (!next && opPause) markKept([...keptBoxes.keys()].filter((n) => !opHeld.has(n)), false, "paused");
|
|
1660
|
+
opPause = next;
|
|
1661
|
+
}
|
|
1552
1662
|
// #4592: re-read the hold set; one decision and one row when it changes.
|
|
1553
1663
|
const holdExpiring = (list) => { let info = null; try { info = getHoldInfo?.() ?? null; } catch { info = null; } return !!expireHolds && list.some((n) => Number.isFinite(Date.parse(info?.[n]?.expiresAt))); }; // #5469
|
|
1554
1664
|
// #5632: a function declaration (hoisted): finish/recovery callbacks of a resumed batch can call it before this line runs
|
|
@@ -1568,6 +1678,8 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1568
1678
|
const fmt = (ns) => ns.map((n) => `#${n}`).join(", ");
|
|
1569
1679
|
const held = [...next].filter((n) => !opHeld.has(n)), freed = [...opHeld].filter((n) => !next.has(n));
|
|
1570
1680
|
opHeld = next;
|
|
1681
|
+
markKept(held.filter((n) => keptBoxes.has(n)), true, "held");
|
|
1682
|
+
markKept(freed.filter((n) => keptBoxes.has(n) && !opPause), false, "held");
|
|
1571
1683
|
for (const n of held) if (running.has(n)) update({ issue: n, outcome: "hold", detail: `#${n} held after launch: lane still running` }); // #5526
|
|
1572
1684
|
if (held.length) {
|
|
1573
1685
|
decided({ issue: null, what: `held ${fmt(held)} (forgedock orchestrate --hold)`, why: "operator request", alternative: "cancel the batch" });
|
|
@@ -1667,6 +1779,26 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1667
1779
|
const readmitted = new Set(); // "n:b": re-admit n on blocker b once; a lane that re-skips on b stays skipped
|
|
1668
1780
|
const blockerOf = (n) => { const r = results.get(n); const m = r?.outcome === "skipped" ? /^dependency #(\d+) /.exec(r.detail ?? "") : null; return m ? Number(m[1]) : null; };
|
|
1669
1781
|
const watchable = () => !!dispatchCheck && [...results.keys()].some((n) => blockerOf(n) !== null);
|
|
1782
|
+
// #5986: readmission needs a new input hash. false = refused (loop.no_new_input: the label stays, one note per hash); a missing ledger or unreadable input admits.
|
|
1783
|
+
const refusedNoted = new Set();
|
|
1784
|
+
const gateAdmit = async (n, { relabel = false } = {}) => {
|
|
1785
|
+
if (!attempts) return true;
|
|
1786
|
+
try {
|
|
1787
|
+
let l = ledgers.get(n) ?? null;
|
|
1788
|
+
if (!l) { l = (await attempts.load?.(n)) ?? null; if (l) ledgers.set(n, l); }
|
|
1789
|
+
if (!l) return true;
|
|
1790
|
+
const hash = (await attempts.hash?.(n)) ?? null, a = admitInput(l, hash, attempts.cfg);
|
|
1791
|
+
if (a.ok) return true;
|
|
1792
|
+
const key = `${n}|${hash}|${a.code}`;
|
|
1793
|
+
if (!refusedNoted.has(key)) {
|
|
1794
|
+
refusedNoted.add(key);
|
|
1795
|
+
if (a.code === "escalate") { l = markEscalated(l); ledgers.set(n, l); save(); await attempts.mirror?.(n, l); }
|
|
1796
|
+
await attempts.notify?.({ issue: n, code: a.code, ledger: l, reason: a.reason, relabel });
|
|
1797
|
+
update({ issue: n, event: NO_NEW_INPUT, code: NO_NEW_INPUT, detail: `${NO_NEW_INPUT}: ${a.reason}`, batch: batchId ?? null });
|
|
1798
|
+
}
|
|
1799
|
+
return false;
|
|
1800
|
+
} catch { return true; }
|
|
1801
|
+
};
|
|
1670
1802
|
// #5162: held rows behind `root` return to pending (and the root too when `withRoot`: requeued, counters reset), parents first via the edges.
|
|
1671
1803
|
const releaseHeld = (root, withRoot, why) => {
|
|
1672
1804
|
const moved = withRoot && results.has(root) ? [root] : [];
|
|
@@ -1712,7 +1844,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1712
1844
|
if (!why && v && h.version && v !== h.version) why = `engine version changed v${h.version} → v${v}`;
|
|
1713
1845
|
if (why) { /* env issue closed */ } else if (fp && h.env && fp !== h.env) why = "batch env changed (--set-env)";
|
|
1714
1846
|
else if (h.tools?.length && !toolReadmits.has(`${n}|${h.sig}`) && (await missingTools(h.tools))?.length === 0) { why = `${h.tools.join(", ")} now found on the host`; toolReadmits.add(`${n}|${h.sig}`); }
|
|
1715
|
-
if (why) { engineSigs.delete(n); releaseHeld(n, true, `re-admitted: ${why}`); continue; }
|
|
1847
|
+
if (why) { if (!(await gateAdmit(n))) continue; engineSigs.delete(n); releaseHeld(n, true, `re-admitted: ${why}`); continue; }
|
|
1716
1848
|
if (now() - (Number(h.since) || 0) >= ehMaxMs && !/no engine\/env change within/.test(r.detail ?? "")) { // the wait is over: the row stays held (resumable, --requeue), the batch may end
|
|
1717
1849
|
const { waiting, ...rest } = r;
|
|
1718
1850
|
const [head, ...tail] = String(rest.detail ?? "").split("\n");
|
|
@@ -1729,7 +1861,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1729
1861
|
if (restoredHeld.has(root) && ["needs-human", "budget-exceeded"].includes(ro) && typeof issueLabels === "function") { // label removed: requeue the root, its subtree follows
|
|
1730
1862
|
let names = null;
|
|
1731
1863
|
try { names = await issueLabels(root); } catch { names = null; }
|
|
1732
|
-
if (Array.isArray(names) && !names.includes("needs-human")) { releaseHeld(root, true, "needs-human label removed"); continue; }
|
|
1864
|
+
if (Array.isArray(names) && !names.includes("needs-human")) { if (await gateAdmit(root, { relabel: true })) releaseHeld(root, true, "needs-human label removed"); continue; }
|
|
1733
1865
|
}
|
|
1734
1866
|
if (!dispatchCheck) continue;
|
|
1735
1867
|
let g = null;
|
|
@@ -1788,7 +1920,12 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1788
1920
|
}
|
|
1789
1921
|
if (back.size) save();
|
|
1790
1922
|
};
|
|
1791
|
-
const
|
|
1923
|
+
const ceilingK = () => { let k = null; try { k = getParallel?.(); } catch { k = null; } return Number.isInteger(k) && k >= 1 ? k : parallel; };
|
|
1924
|
+
// #5985: K is the ceiling; the controller's operating point (and a lower heavy-lane cap) sits under it. A pool with no load/memory data leaves K unchanged.
|
|
1925
|
+
// #5985: light/heavy per lane (its repo's recent cpu_avg from usage-history rows, array or getter); heavy lanes have their own concurrent cap
|
|
1926
|
+
const laneClassOf = (n) => { let rows = null; try { rows = typeof usageRows === "function" ? usageRows() : usageRows; } catch { rows = null; } let repo = repoSlug; try { repo = repoOf?.(n) ?? repoSlug; } catch { repo = repoSlug; } return rows && repo ? classifyRepo(rows, repo) : "light"; };
|
|
1927
|
+
const heavyFull = (n) => { if (laneClassOf(n) !== "heavy") return false; let h = 0; for (const m of running.keys()) if (m !== n && laneClassOf(m) === "heavy") h++; if (h < conc.heavyLimit()) return false; if (!heavyHeldHit) { heavyHeldHit = true; concEmit({ event: "concurrency", change: "heavy-cap", k: conc.operating("light"), ceiling: ceilingK(), factor: "heavy cap", inputs: { heavy_limit: conc.heavyLimit() } }); } return true; };
|
|
1928
|
+
const K = () => { conc.setCeiling(ceilingK()); return conc.operating("light"); };
|
|
1792
1929
|
// #5836: one train poll (throttled): a merged PR becomes a merged row; a red, conflicting or moved-head PR is handed back as a
|
|
1793
1930
|
// needs-human row through the normal settle path, so in-batch recovery requeues a fix lane.
|
|
1794
1931
|
let lastTrainTick = -Infinity;
|
|
@@ -1804,6 +1941,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1804
1941
|
const row = { ...rest, outcome: "merged", detail: e.detail };
|
|
1805
1942
|
results.set(n, row);
|
|
1806
1943
|
if (lifecycle && e.entry.milestone) lifecycleTitles.add(String(e.entry.milestone));
|
|
1944
|
+
await closeOnLane(n, e.entry.lane, row);
|
|
1807
1945
|
if (integration?.onMerged && String(e.entry.lane ?? "").startsWith("milestone/")) {
|
|
1808
1946
|
try { await integration.onMerged(n, { ...row, lane: e.entry.lane }, { milestone: e.entry.milestone }); } catch (err) { update({ issue: n, outcome: "integration", detail: `integration check failed: ${String(err?.message ?? err).slice(0, 300)}` }); }
|
|
1809
1947
|
}
|
|
@@ -1834,6 +1972,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1834
1972
|
firstPass = false;
|
|
1835
1973
|
if (!pending.length && !running.size && !train?.size()) {
|
|
1836
1974
|
if (envWaiting() && !signal?.aborted) { await nap(ehWatchMs); continue; } // #5805: only engine/env holds remain: keep re-checking them
|
|
1975
|
+
if (reconcile && !signal?.aborted && !cancelled && !tripped) { await nap(reconcile.everyMs ?? RECONCILE_MS); continue; } // #5978: a standing order stays open: the next reconcile may bring issues
|
|
1837
1976
|
break;
|
|
1838
1977
|
}
|
|
1839
1978
|
// Resolve skips first: a dependency that finished unsatisfied (or never can) skips its dependents.
|
|
@@ -1858,9 +1997,11 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1858
1997
|
driftHeld.clear();
|
|
1859
1998
|
integHeld.clear();
|
|
1860
1999
|
opHeldHit.clear();
|
|
2000
|
+
pauseHit = false;
|
|
1861
2001
|
blockedHit.clear();
|
|
1862
2002
|
baseHit.clear();
|
|
1863
2003
|
refreshHeld();
|
|
2004
|
+
refreshPause();
|
|
1864
2005
|
await refreshBlocked();
|
|
1865
2006
|
await refreshBaseWaits();
|
|
1866
2007
|
checkGates();
|
|
@@ -1876,14 +2017,28 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1876
2017
|
if (pfNoted.size && !keys.size) update({ issue: null, outcome: "preflight", detail: "preflight cleared; admissions resumed" });
|
|
1877
2018
|
pfNoted = keys;
|
|
1878
2019
|
}
|
|
2020
|
+
// #5992: one dispatcher probe per (repo, base sha) while lanes wait; red holds every admission but the attributed fixer's.
|
|
2021
|
+
if (baseProbe && !tripped && !cancelled && !holdUntil && pending.length) {
|
|
2022
|
+
let v = null;
|
|
2023
|
+
try { v = await baseProbe(); } catch { v = null; }
|
|
2024
|
+
if (v?.red) {
|
|
2025
|
+
const issue = Number.isInteger(v.att?.issue) ? v.att.issue : null;
|
|
2026
|
+
const detail = `base.red: base ${String(v.sha).slice(0, 12)} is red on ${(v.commands ?? []).join(", ") || "a guard command"}${v.att ? `; last change ${String(v.att.sha).slice(0, 12)}${issue ? ` (#${issue})` : ""}` : ""}; admissions paused until the base moves`;
|
|
2027
|
+
if (baseRedHold?.sha !== v.sha) update({ issue: null, outcome: "preflight", code: "base.red", detail });
|
|
2028
|
+
baseRedHold = { sha: v.sha, issue, detail };
|
|
2029
|
+
} else if (baseRedHold) { update({ issue: null, outcome: "preflight", detail: "base.red cleared; admissions resumed" }); baseRedHold = null; }
|
|
2030
|
+
}
|
|
1879
2031
|
let planPass = false; // #5831: the plan pass evaluates every other gate but the in-batch dependencies
|
|
1880
2032
|
await gateEnvSigs(); // #5755
|
|
1881
2033
|
const isReady = (n) => {
|
|
1882
2034
|
if (pfAll || (pfRemote && isRemote(n))) return false;
|
|
2035
|
+
if (baseRedHold && n !== baseRedHold.issue) return false; // #5992
|
|
2036
|
+
if (opPause) { pauseHit = true; return false; } // #5975: every admission path (dependency merge, env/engine re-admit, requeue, add, recovery) ends here
|
|
1883
2037
|
if (opHeld.has(n)) { opHeldHit.add(n); return false; }
|
|
1884
2038
|
if (blocked.has(n)) { blockedHit.add(n); return false; } // #4773
|
|
1885
2039
|
if (baseHeld.has(n)) { baseHit.add(n); return false; } // #5031
|
|
1886
2040
|
if (!((notBefore.get(n) ?? 0) <= t && (planPass || edges(n).every((d) => results.has(d) && SATISFIED.has(results.get(d).outcome))))) return false;
|
|
2041
|
+
if (heavyFull(n)) return false; // #5985: a wave of heavy (test-suite) lanes never takes the whole ceiling
|
|
1887
2042
|
if (integration?.holds) {
|
|
1888
2043
|
let why = null;
|
|
1889
2044
|
try { why = integration.holds(n, { lane: lanes.get(n)?.lane ?? null }); } catch { why = null; }
|
|
@@ -1923,6 +2078,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1923
2078
|
for (const n of want) wanted.add(n);
|
|
1924
2079
|
for (const n of ready) {
|
|
1925
2080
|
if (running.size >= K()) break;
|
|
2081
|
+
if (heavyFull(n)) continue; // #5985
|
|
1926
2082
|
const g = grant(n, wanted);
|
|
1927
2083
|
if (g === "busy") continue; // #4481
|
|
1928
2084
|
if (!g && (notBefore.get(n) ?? 0) > t) continue; // #5592: per-issue wait, not a full host queue
|
|
@@ -1932,6 +2088,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1932
2088
|
} else if (!tripped && !cancelled && !holdUntil) {
|
|
1933
2089
|
for (const n of rank(pending.filter(isReady))) {
|
|
1934
2090
|
if (running.size >= K()) break;
|
|
2091
|
+
if (heavyFull(n)) continue; // #5985
|
|
1935
2092
|
if (grant(n, new Set()) === true) { pending.splice(pending.indexOf(n), 1); start(n); started++; }
|
|
1936
2093
|
}
|
|
1937
2094
|
}
|
|
@@ -1950,6 +2107,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1950
2107
|
try { sc = rank(pending.filter((n) => stackAdmissible({ n, edges: edges(n), results, pending, running, prReady, stackedTried, satisfied: SATISFIED }) && isReady(n))); } finally { planPass = false; }
|
|
1951
2108
|
for (const n of sc) {
|
|
1952
2109
|
if (running.size >= K()) break;
|
|
2110
|
+
if (heavyFull(n)) continue; // #5985
|
|
1953
2111
|
if (lanes.get(n)?.ok === false || (notBefore.get(n) ?? 0) > t) continue;
|
|
1954
2112
|
const so = stackAdmissible({ n, edges: edges(n), results, pending, running, prReady, stackedTried, satisfied: SATISFIED });
|
|
1955
2113
|
if (!so || grant(n, new Set()) !== true) continue;
|
|
@@ -1969,6 +2127,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1969
2127
|
try { cands = rank(pending.filter((n) => planAdmissible({ n, edges: edges(n), results, pending, running, planTried, satisfied: SATISFIED }) && isReady(n))); } finally { planPass = false; }
|
|
1970
2128
|
for (const n of cands) {
|
|
1971
2129
|
if (running.size >= K()) break;
|
|
2130
|
+
if (heavyFull(n)) continue; // #5985
|
|
1972
2131
|
if (lanes.get(n)?.ok === false || (notBefore.get(n) ?? 0) > t) continue;
|
|
1973
2132
|
if (grant(n, new Set()) !== true) continue;
|
|
1974
2133
|
pending.splice(pending.indexOf(n), 1);
|
|
@@ -1983,6 +2142,17 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
1983
2142
|
if (reg) withdrawExcept(wanted);
|
|
1984
2143
|
// #4685: a breaker tripped only by link failures (a router restart) closes itself after a cooldown
|
|
1985
2144
|
if (tripped?.transport && now() - tripped.at >= TRANSPORT_COOLDOWN_MS) { tripped = null; errorTimes = []; transportErrors = 0; save(); }
|
|
2145
|
+
// #5978: a standing order's breaker closes itself after a cooldown when the failures were environmental and the pool is healthy
|
|
2146
|
+
if (tripped && reconcile && !tripped.transport) {
|
|
2147
|
+
let healthy = true; try { healthy = reconcile.poolHealthy ? reconcile.poolHealthy() !== false : true; } catch { healthy = true; }
|
|
2148
|
+
const d = decideAutoReset({ tripped, now: now(), cooldownMs: BREAKER_COOLDOWN_MS, environmental: tripped.environmental === true, poolHealthy: healthy });
|
|
2149
|
+
if (d.reset) {
|
|
2150
|
+
tripped = null; errorTimes = []; transportErrors = 0; save();
|
|
2151
|
+
decided({ issue: null, what: `circuit breaker reset automatically: ${d.why}`, why: "FORGE:DECISION: the engine-errors were environmental (VM restart, mirror, network) and the pool is healthy again", alternative: "forgedock orchestrate --clear-breaker" });
|
|
2152
|
+
update({ issue: null, outcome: "breaker", detail: `circuit breaker cleared automatically: ${d.why}` });
|
|
2153
|
+
continue;
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
1986
2156
|
// #5947: --clear-breaker on a schedd-hosted batch reaches this runner through the batch's request file
|
|
1987
2157
|
if (getClearBreaker) { // #5964: time-scoped; the request is consumed only after the decision, so a long pass never loses it
|
|
1988
2158
|
let req = null; try { req = getClearBreaker(); } catch { req = null; }
|
|
@@ -2017,12 +2187,13 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
2017
2187
|
if (holdUntil) waits.push(holdUntil);
|
|
2018
2188
|
let wake = waits.length ? Math.max(0, Math.min(...waits) - t) : null;
|
|
2019
2189
|
if (holdUntil && pending.length) wake = Math.min(wake ?? pollMs, pollMs); // #4446: a cleared hold (forgedock limits clear) admits on the next poll
|
|
2190
|
+
if (getPause && pending.length && (opPause || running.size)) wake = Math.min(wake ?? pollMs, pollMs); // #5975: an --unpause or expiry
|
|
2020
2191
|
if ((getParallel || getHeld) && pending.length) wake = Math.min(wake ?? pollMs, pollMs);
|
|
2021
2192
|
if (offered.size && pending.length) wake = Math.min(wake ?? pollMs, pollMs); // a slot another batch frees
|
|
2022
2193
|
if (pending.some((n) => remoteCapped.has(n))) wake = Math.min(wake ?? pollMs, pollMs); // #5138: a live --set-max-remote raise
|
|
2023
2194
|
if ((getAdded || getRequeued || (getChildren && addsEpicChildren(autoChildren?.mode))) && running.size) wake = Math.min(wake ?? pollMs, pollMs); // #4408/#4550: an add or requeue while only lanes run
|
|
2024
2195
|
if (getRequeued && pending.some((n) => quota.has(n) || notBefore.has(n))) wake = Math.min(wake ?? pollMs, pollMs); // #5203: a --requeue releasing a quota pause
|
|
2025
|
-
if ((pfAll || pfRemote) && pending.length) wake = Math.min(wake ?? pollMs, pollMs); // #4866
|
|
2196
|
+
if ((pfAll || pfRemote || baseRedHold) && pending.length) wake = Math.min(wake ?? pollMs, pollMs); // #4866
|
|
2026
2197
|
if (baseWait && pending.length && baseHeld.size) wake = Math.min(wake ?? pollMs, pollMs); // #5031: a landed commit releases on the next tick
|
|
2027
2198
|
if (getBlocked && pending.length && blockedHit.size) wake = Math.min(wake ?? pollMs, pollMs); // #4773: a removed label releases on the next tick
|
|
2028
2199
|
if (getHeld && running.size) wake = Math.min(wake ?? pollMs, pollMs); // #4592: a release while only lanes run
|
|
@@ -2030,6 +2201,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
2030
2201
|
if (running.size && watchable()) wake = Math.min(wake ?? WATCH_EVERY_MS, WATCH_EVERY_MS); // #4595: re-check the blockers of skipped rows
|
|
2031
2202
|
if (running.size && envWaiting()) wake = Math.min(wake ?? ehWatchMs, ehWatchMs); // #5805: re-check engine/env holds while lanes run
|
|
2032
2203
|
if (train?.size()) wake = Math.min(wake ?? trainEveryMs, Math.max(0, trainEveryMs - (now() - lastTrainTick))); // #5836
|
|
2204
|
+
if (reconcile && running.size) wake = Math.min(wake ?? reconcile.everyMs ?? RECONCILE_MS, reconcile.everyMs ?? RECONCILE_MS); // #5978
|
|
2033
2205
|
if (tripped) wake = getClearBreaker ? Math.min(wake ?? pollMs, pollMs) : null;
|
|
2034
2206
|
if (getCancelled && running.size && (!cancelled || [...running.keys()].some((n) => { const x = stopSent.get(n); return x && !(x.accepted && x.reported); }))) wake = Math.min(wake ?? pollMs, pollMs); // #5241: a cancel keeps polling a lane whose stop is unconfirmed // #4376: notice a cancel while lanes run
|
|
2035
2207
|
if (running.size) {
|
|
@@ -2038,11 +2210,13 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
2038
2210
|
} else if (started) continue; // only lane-refused rows settled (synchronously): re-resolve skips first
|
|
2039
2211
|
else if (train?.size()) await nap(wake ?? trainEveryMs); // #5836: only train-held PRs are left: poll the train
|
|
2040
2212
|
else if (pending.length && offered.size) await nap(wake); // waiting for a host slot
|
|
2041
|
-
else if (pending.length && (pfAll || pfRemote)) await nap(Math.min(wake ?? pollMs, pollMs)); // #4866: a failing lane preflight is re-checked on the next poll
|
|
2213
|
+
else if (pending.length && (pfAll || pfRemote || baseRedHold)) await nap(Math.min(wake ?? pollMs, pollMs)); // #4866: a failing lane preflight is re-checked on the next poll
|
|
2042
2214
|
else if (pending.length && blockedHit.size) await nap(wake ?? pollMs); // #4773: only blocked issues wait: poll for the label's removal
|
|
2043
2215
|
else if (pending.length && baseHit.size) await nap(wake ?? pollMs); // #5031: only issues waiting for a base commit: poll for it
|
|
2044
2216
|
else if (pending.length && waits.length) await nap(Math.min(wake, getCancelled ? pollMs : Infinity)); // wake is poll-capped by a hold or a live K; #4454: nap wakes on a stop
|
|
2045
2217
|
else if (pending.length && budgetHeld) { if (await drainAdds()) continue; break; } // maintenance the budget does not admit now: held for a later batch
|
|
2218
|
+
else if (pending.length && opPause && pauseHit && Number.isFinite(Date.parse(opPause.expiresAt)) && !cancelled) await nap(wake ?? pollMs); // #5975: a timed pause keeps the batch open until it expires, not finalised silently
|
|
2219
|
+
else if (pending.length && opPause && pauseHit) { if (await drainAdds()) continue; break; } // #5975: paused with no expiry: pending for a --resume after --unpause
|
|
2046
2220
|
else if (pending.length && opHeldHit.size && !pending.some((n) => !opHeldHit.has(n) && isReady(n)) && holdExpiring([...opHeldHit]) && !cancelled) await nap(wake ?? pollMs); // #5469: a hold with an expiry keeps the batch open until it expires (re-admit or alert), not finalised silently
|
|
2047
2221
|
else if (pending.length && opHeldHit.size && !pending.some((n) => !opHeldHit.has(n) && isReady(n))) { if (await drainAdds()) continue; break; } // #4592: held by the operator: pending for a --resume
|
|
2048
2222
|
else if (pending.length && (driftHeld.size || integHeld.size)) { if (await drainAdds()) continue; break; } // held by a drift flag (block_dispatch) or a red integration streak (#4667): pending for a later batch
|
package/bin/lean/phaseledger.mjs
CHANGED
|
@@ -93,6 +93,12 @@ export const laneSum = (phases) => Object.entries(phases ?? {}).reduce((s, [id,
|
|
|
93
93
|
/** True when the lane phases sum to within `tol` of `wallMs`. */
|
|
94
94
|
export const withinWall = (phases, wallMs, tol = 0.05) => isNum(wallMs) && wallMs >= 0 && Math.abs(laneSum(phases) - wallMs) <= Math.max(1, wallMs * tol);
|
|
95
95
|
|
|
96
|
+
/** Fixed overhead = lane wall time not spent in a model call (never negative); model_share = model time / wall (0 when wall <= 0). */
|
|
97
|
+
export function overheadStats(_phases, wallMs, modelMs) {
|
|
98
|
+
const wall = isNum(wallMs) ? wallMs : 0, model = isNum(modelMs) ? modelMs : 0;
|
|
99
|
+
return { fixed_overhead_ms: Math.max(0, wall - model), model_share: wall > 0 ? Math.round((model / wall) * 1000) / 1000 : 0 };
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
export function flattenPhases(phases) {
|
|
97
103
|
const out = {};
|
|
98
104
|
for (const [id, v] of Object.entries(phases ?? {})) {
|
|
@@ -7,7 +7,7 @@ import { tmpDir } from "../tests/_tmp.mjs";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { phasesOf } from "./orchestrate.mjs";
|
|
9
9
|
import { aggregate } from "../stats/aggregate.mjs";
|
|
10
|
-
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, summarizePhases, formatLedgerSummary, WAIT_CAUSES, summarizeWaits, comparePhases, formatPhaseComparison, readBaselineRows } from "./phaseledger.mjs";
|
|
10
|
+
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, overheadStats, summarizePhases, formatLedgerSummary, WAIT_CAUSES, summarizeWaits, comparePhases, formatPhaseComparison, readBaselineRows } from "./phaseledger.mjs";
|
|
11
11
|
|
|
12
12
|
const clock = () => { let t = 1000; const f = () => t; f.tick = (ms) => { t += ms; }; return f; };
|
|
13
13
|
|
|
@@ -167,3 +167,15 @@ describe("phase comparison vs previous 7 days (#5649)", () => {
|
|
|
167
167
|
assert.equal(readBaselineRows({ root: join(root, "missing"), now }), null);
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
|
+
|
|
171
|
+
describe("overheadStats", () => {
|
|
172
|
+
it("splits wall into model share and fixed overhead", () => {
|
|
173
|
+
assert.deepEqual(overheadStats({}, 1000, 320), { fixed_overhead_ms: 680, model_share: 0.32 });
|
|
174
|
+
});
|
|
175
|
+
it("zero wall gives zero share", () => {
|
|
176
|
+
assert.deepEqual(overheadStats({}, 0, 50), { fixed_overhead_ms: 0, model_share: 0 });
|
|
177
|
+
});
|
|
178
|
+
it("model > wall clamps overhead to 0", () => {
|
|
179
|
+
assert.equal(overheadStats({}, 100, 150).fixed_overhead_ms, 0);
|
|
180
|
+
});
|
|
181
|
+
});
|