@loucompanion/forge-bridge 0.1.4-dev.60e18c3cfec6 → 0.1.4-dev.6b2148ecc60c
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/README.md +22 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +125 -0
- package/dist/bridge/bridge.service.d.ts +1 -1
- package/dist/bridge/bridge.service.js +4 -110
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +9 -2
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +19 -10
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +7 -0
- package/dist/runtime/host-load-governor.d.ts +10 -0
- package/dist/runtime/host-load-governor.js +125 -34
- package/dist/runtime/host-load-sampler.d.ts +26 -3
- package/dist/runtime/host-load-sampler.js +61 -2
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-lease.d.ts +2 -2
- package/dist/runtime/host-runtime-lease.js +9 -8
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/sandbox/host-capacity-broker.d.ts +7 -1
- package/dist/sandbox/host-capacity-broker.js +23 -4
- package/dist/session/managed-attempt-tools.js +8 -9
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.schemas.js +22 -12
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-validation.d.ts +23 -11
- package/dist/session/pre-publication-validation.js +178 -107
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +13 -22
- package/dist/session/provider-cli/provider-cli.process.js +36 -337
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +45 -8
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -7
- package/dist/session/provider-cli/provider-cli.service.js +66 -243
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/sandbox-host-capacity-gate.js +12 -3
- package/dist/session/session.types.js +2 -2
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import os from "node:os";
|
|
2
3
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
3
4
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
4
5
|
import { decideHostLoadAdmission, } from "./host-load-admission.js";
|
|
5
|
-
import { loadHostLoadGovernorConfig } from "./host-load-governor-config.js";
|
|
6
|
+
import { hostLoadGovernorEnabled, loadHostLoadGovernorConfig } from "./host-load-governor-config.js";
|
|
6
7
|
import { HostCapacityLedgerUnavailableError } from "./host-load-ledger-lock.js";
|
|
7
8
|
import { HostLoadRuntimeSettingsReader } from "./host-load-runtime-settings.js";
|
|
9
|
+
import { decideHostTestSlot, takesHostTestSlot } from "./host-load-test-slot.js";
|
|
8
10
|
import { terminateHostLoadStepProcess } from "./host-load-step-reaper.js";
|
|
9
11
|
import { HostCapacityTokenFencedError, HostLoadTokenLedger, } from "./host-load-token-ledger.js";
|
|
10
12
|
export class HostCapacityTimeoutError extends ForgeFailureError {
|
|
@@ -26,6 +28,8 @@ export class HostCapacityTimeoutError extends ForgeFailureError {
|
|
|
26
28
|
* overtake an unfit head until the head has waited past the anti-starvation
|
|
27
29
|
* window. Running steps are never preempted. Reserved cost comes from the
|
|
28
30
|
* shared token ledger, so other processes' steps count against the same budget.
|
|
31
|
+
* The host test slot (decision 0018) comes first: a heavy step waits for it in
|
|
32
|
+
* the host-wide queue the ledger keeps, then for the budget when that is on.
|
|
29
33
|
*/
|
|
30
34
|
export class HostLoadGovernor {
|
|
31
35
|
options;
|
|
@@ -45,7 +49,7 @@ export class HostLoadGovernor {
|
|
|
45
49
|
constructor(options) {
|
|
46
50
|
this.options = options;
|
|
47
51
|
this.config = options.config ?? loadHostLoadGovernorConfig();
|
|
48
|
-
this.enabled = this.config
|
|
52
|
+
this.enabled = hostLoadGovernorEnabled(this.config);
|
|
49
53
|
this.runtimeSettings = new HostLoadRuntimeSettingsReader(options.stateRoot);
|
|
50
54
|
this.ledger = new HostLoadTokenLedger({
|
|
51
55
|
stateRoot: options.stateRoot,
|
|
@@ -57,18 +61,27 @@ export class HostLoadGovernor {
|
|
|
57
61
|
suspendedMs: options.suspendedMs,
|
|
58
62
|
// Every ledger transaction renews the steps this governor is running.
|
|
59
63
|
heldTokens: () => [...this.held.values()].map(entry => entry.token),
|
|
64
|
+
// ...and keeps its waiters' places in the host test slot queue.
|
|
65
|
+
waitingTickets: () => this.waiters.flatMap(waiter => waiter.ticket && !waiter.settled ? [waiter.ticket] : []),
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
get maxWaitMs() {
|
|
63
69
|
return this.config.maxWaitMs;
|
|
64
70
|
}
|
|
65
71
|
async acquire(request, options = {}) {
|
|
66
|
-
if (!this.enabled)
|
|
67
|
-
throw new Error("host_load_governor_disabled: acquire() requires FORGE_HOST_LOAD_GOVERNOR=on.");
|
|
72
|
+
if (!this.enabled) {
|
|
73
|
+
throw new Error("host_load_governor_disabled: acquire() requires a host test slot or FORGE_HOST_LOAD_GOVERNOR=on.");
|
|
74
|
+
}
|
|
68
75
|
const { signal } = options;
|
|
69
76
|
if (signal?.aborted)
|
|
70
77
|
throw abortError(signal);
|
|
71
|
-
|
|
78
|
+
// With the budget off, a step that takes no slot needs nothing from the ledger:
|
|
79
|
+
// a ledger fault cannot fail a `git status` or a dependency install.
|
|
80
|
+
if (this.config.mode !== "on" && !takesHostTestSlot(request.stepClass))
|
|
81
|
+
return slotFreeAdmission(request);
|
|
82
|
+
// Only the budget reads load samples.
|
|
83
|
+
if (this.config.mode === "on")
|
|
84
|
+
await this.options.load.start().catch(() => undefined);
|
|
72
85
|
if (signal?.aborted)
|
|
73
86
|
throw abortError(signal);
|
|
74
87
|
return await new Promise((resolve, reject) => {
|
|
@@ -83,6 +96,16 @@ export class HostLoadGovernor {
|
|
|
83
96
|
deadline: null,
|
|
84
97
|
lastDecision: null,
|
|
85
98
|
settled: false,
|
|
99
|
+
ticket: this.config.testSlots > 0 && takesHostTestSlot(request.stepClass)
|
|
100
|
+
? {
|
|
101
|
+
ticketId: randomUUID(),
|
|
102
|
+
stepClass: request.stepClass,
|
|
103
|
+
label: request.label,
|
|
104
|
+
dispatchAttemptId: request.dispatchAttemptId,
|
|
105
|
+
priority: request.priority,
|
|
106
|
+
enqueuedAt: new Date(this.options.now?.() ?? Date.now()).toISOString(),
|
|
107
|
+
}
|
|
108
|
+
: null,
|
|
86
109
|
};
|
|
87
110
|
waiter.deadline = setTimeout(() => this.settle(waiter, () => reject(new HostCapacityTimeoutError(request.stepClass, request.label, monotonicNowMs() - waiter.enqueuedAtMs, waiter.lastDecision?.detail ?? "the host stayed at capacity."))), this.config.maxWaitMs);
|
|
88
111
|
waiter.deadline.unref?.();
|
|
@@ -177,46 +200,29 @@ export class HostLoadGovernor {
|
|
|
177
200
|
async drainOnce() {
|
|
178
201
|
if (this.waiters.length === 0)
|
|
179
202
|
return;
|
|
180
|
-
|
|
181
|
-
// bridge has in force apply from the next admission; running steps keep theirs.
|
|
182
|
-
// The operator's env ceilings hold with or without the file, and over whatever it says.
|
|
183
|
-
const overrides = await this.runtimeSettings.read();
|
|
184
|
-
const cpuBudgetFraction = Math.min(overrides?.cpuBudgetFraction ?? this.config.cpuBudgetFraction, this.config.cpuBudgetCeilingFraction ?? 1);
|
|
185
|
-
const config = cpuBudgetFraction === this.config.cpuBudgetFraction ? this.config : { ...this.config, cpuBudgetFraction };
|
|
186
|
-
const maxHeavySteps = lowestLimit(overrides?.maxHeavySteps ?? null, this.config.maxHeavyStepsCeiling ?? null);
|
|
203
|
+
const budget = this.config.mode === "on" ? await this.budgetPass() : null;
|
|
187
204
|
if (this.waiters.length === 0)
|
|
188
205
|
return;
|
|
189
|
-
const signals = this.readSignals();
|
|
190
|
-
const logicalCpus = this.logicalCpus();
|
|
191
206
|
const nowMs = monotonicNowMs();
|
|
192
207
|
const outcomes = [];
|
|
193
208
|
const outcome = await this.ledger.transaction(transaction => {
|
|
194
|
-
const runningMemoryBytes = this.runningStepsMemoryBytes(transaction.tokens);
|
|
209
|
+
const runningMemoryBytes = budget ? this.runningStepsMemoryBytes(transaction.tokens) : 0;
|
|
195
210
|
const head = this.waiters[0];
|
|
196
211
|
const headStarving = head !== undefined && nowMs - head.enqueuedAtMs >= this.config.antiStarvationMs;
|
|
197
212
|
for (const waiter of this.waiters) {
|
|
198
213
|
if (waiter.settled)
|
|
199
214
|
continue;
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
config,
|
|
207
|
-
maxHeavySteps,
|
|
208
|
-
});
|
|
209
|
-
const decision = transaction.recoveringUntil
|
|
210
|
-
? {
|
|
211
|
-
...computed,
|
|
212
|
-
admitted: false,
|
|
213
|
-
reason: "ledger_recovering",
|
|
214
|
-
detail: `The host load ledger was corrupt and was quarantined; admissions resume at ${transaction.recoveringUntil}, once running steps have restored their reservations.`,
|
|
215
|
-
}
|
|
216
|
-
: computed;
|
|
215
|
+
const decision = this.decide(waiter, transaction, budget, runningMemoryBytes);
|
|
216
|
+
if (decision.admitted && waiter.ticket) {
|
|
217
|
+
// The ticket leaves the host queue in the same commit that issues the token.
|
|
218
|
+
transaction.removeTicket(waiter.ticket.ticketId);
|
|
219
|
+
waiter.ticket = null;
|
|
220
|
+
}
|
|
217
221
|
outcomes.push({ waiter, decision, token: decision.admitted ? transaction.issue(waiter.request) : null });
|
|
218
|
-
// A starving head blocks the
|
|
219
|
-
|
|
222
|
+
// A starving head blocks the budget so running steps drain and it can start. A
|
|
223
|
+
// slot wait does not: the host queue already orders slot waiters, and steps
|
|
224
|
+
// behind this one locally may be ahead of it there, or take no slot.
|
|
225
|
+
if (waiter === head && headStarving && !decision.admitted && decision.reason !== "host_test_slot")
|
|
220
226
|
break;
|
|
221
227
|
}
|
|
222
228
|
});
|
|
@@ -261,6 +267,53 @@ export class HostLoadGovernor {
|
|
|
261
267
|
}));
|
|
262
268
|
}
|
|
263
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Decision 0014: the CPU budget (or yield budget) and the heavy-step limit the
|
|
272
|
+
* bridge has in force apply from the next admission; running steps keep theirs.
|
|
273
|
+
* The operator's env ceilings hold with or without the file, and over whatever it says.
|
|
274
|
+
*/
|
|
275
|
+
async budgetPass() {
|
|
276
|
+
const overrides = await this.runtimeSettings.read();
|
|
277
|
+
const cpuBudgetFraction = Math.min(overrides?.cpuBudgetFraction ?? this.config.cpuBudgetFraction, this.config.cpuBudgetCeilingFraction ?? 1);
|
|
278
|
+
return {
|
|
279
|
+
config: cpuBudgetFraction === this.config.cpuBudgetFraction ? this.config : { ...this.config, cpuBudgetFraction },
|
|
280
|
+
maxHeavySteps: lowestLimit(overrides?.maxHeavySteps ?? null, this.config.maxHeavyStepsCeiling ?? null),
|
|
281
|
+
signals: this.readSignals(),
|
|
282
|
+
logicalCpus: this.logicalCpus(),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/** The host test slot first (decision 0018), then the budget when it is on. */
|
|
286
|
+
decide(waiter, transaction, budget, runningMemoryBytes) {
|
|
287
|
+
const slot = waiter.ticket
|
|
288
|
+
? decideHostTestSlot({
|
|
289
|
+
ticket: waiter.ticket,
|
|
290
|
+
queue: transaction.queue,
|
|
291
|
+
tokens: transaction.tokens,
|
|
292
|
+
testSlots: this.config.testSlots,
|
|
293
|
+
nowMs: this.options.now?.() ?? Date.now(),
|
|
294
|
+
antiStarvationMs: this.config.antiStarvationMs,
|
|
295
|
+
})
|
|
296
|
+
: null;
|
|
297
|
+
const decision = slot && !slot.admitted ? slot : budget
|
|
298
|
+
? decideHostLoadAdmission({
|
|
299
|
+
request: waiter.request.cost,
|
|
300
|
+
running: transaction.tokens.map(token => token.cost),
|
|
301
|
+
runningMemoryBytes,
|
|
302
|
+
logicalCpus: budget.logicalCpus,
|
|
303
|
+
signals: budget.signals,
|
|
304
|
+
config: budget.config,
|
|
305
|
+
maxHeavySteps: budget.maxHeavySteps,
|
|
306
|
+
})
|
|
307
|
+
: slot ?? slotFreeDecision;
|
|
308
|
+
if (!transaction.recoveringUntil)
|
|
309
|
+
return decision;
|
|
310
|
+
return {
|
|
311
|
+
...decision,
|
|
312
|
+
admitted: false,
|
|
313
|
+
reason: "ledger_recovering",
|
|
314
|
+
detail: `The host load ledger was corrupt and was quarantined; admissions resume at ${transaction.recoveringUntil}, once running steps have restored their reservations.`,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
264
317
|
readSignals() {
|
|
265
318
|
const snapshot = this.options.load.current();
|
|
266
319
|
const cpu = snapshot?.systemPressure?.cpu?.some;
|
|
@@ -346,6 +399,10 @@ export class HostLoadGovernor {
|
|
|
346
399
|
this.waiters.splice(index, 1);
|
|
347
400
|
if (this.waiters.length === 0)
|
|
348
401
|
this.disarmRecheck();
|
|
402
|
+
// A waiter that left without admission gives up its place now, not when its ticket lapses.
|
|
403
|
+
if (waiter.ticket)
|
|
404
|
+
void this.ledger.transaction(() => undefined).then(outcome => this.applyHeldOutcome(outcome), () => undefined);
|
|
405
|
+
waiter.ticket = null;
|
|
349
406
|
complete();
|
|
350
407
|
}
|
|
351
408
|
/** Renewed tokens reset their lease clock; fenced ones stop their steps (they keep their cost until released). */
|
|
@@ -461,6 +518,17 @@ export class HostLoadGovernor {
|
|
|
461
518
|
// The tree recorded on the token (supervised builds, installs) is stopped and checked.
|
|
462
519
|
?? (entry.token.stepProcess ? async () => await terminate(entry.token.stepProcess) : "attempt_teardown");
|
|
463
520
|
this.armRenewal();
|
|
521
|
+
// Recorded in the ledger so the attempt's own next steps, in any process, do not
|
|
522
|
+
// wait for the slot this token keeps until the step's remains are gone.
|
|
523
|
+
void this.ledger.transaction(transaction => transaction.retain(entry.token.tokenId, entry.token.fencingToken))
|
|
524
|
+
.then(outcome => {
|
|
525
|
+
// Kept on the held entry too: a ledger rebuilt from held tokens must not lose the marker.
|
|
526
|
+
if (outcome.result)
|
|
527
|
+
entry.token = outcome.result;
|
|
528
|
+
this.applyHeldOutcome(outcome);
|
|
529
|
+
void this.drain();
|
|
530
|
+
})
|
|
531
|
+
.catch(() => undefined);
|
|
464
532
|
}
|
|
465
533
|
/**
|
|
466
534
|
* Attempt teardown stopped the attempt's processes (its process supervisor
|
|
@@ -539,3 +607,26 @@ function lowestLimit(a, b) {
|
|
|
539
607
|
return a;
|
|
540
608
|
return Math.min(a, b);
|
|
541
609
|
}
|
|
610
|
+
const slotFreeDecision = {
|
|
611
|
+
admitted: true,
|
|
612
|
+
reason: "admitted",
|
|
613
|
+
cpuBudgetCores: null,
|
|
614
|
+
memoryBudgetBytes: null,
|
|
615
|
+
reservedCpuCores: 0,
|
|
616
|
+
reservedMemoryBytes: 0,
|
|
617
|
+
detail: "The step takes no host test slot and the host budget is off.",
|
|
618
|
+
};
|
|
619
|
+
/** Admits a slot-free step at once, without a ledger token: nothing would count it. */
|
|
620
|
+
function slotFreeAdmission(request) {
|
|
621
|
+
return {
|
|
622
|
+
tokenId: `slot-free-${randomUUID()}`,
|
|
623
|
+
fencingToken: 0,
|
|
624
|
+
stepClass: request.stepClass,
|
|
625
|
+
waitMs: 0,
|
|
626
|
+
decision: slotFreeDecision,
|
|
627
|
+
fenced: new AbortController().signal,
|
|
628
|
+
attachProcess: async () => undefined,
|
|
629
|
+
release: async () => undefined,
|
|
630
|
+
retainUntilStopped: () => undefined,
|
|
631
|
+
};
|
|
632
|
+
}
|
|
@@ -18,10 +18,22 @@ export interface HostOwnCgroupLoad {
|
|
|
18
18
|
/** All memory charged to the unit (`memory.current`), including page cache. */
|
|
19
19
|
readonly memoryChargedBytes: number | null;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Where `systemPressure` comes from: Linux PSI, or (decision 0021) an estimate
|
|
23
|
+
* of CPU `some` pressure from whole-host CPU use on Windows, which has no PSI.
|
|
24
|
+
*/
|
|
25
|
+
export type HostLoadPressureSource = "psi" | "windows_estimate";
|
|
21
26
|
/** Live host load. Reported in every heartbeat but never a material capability signal. */
|
|
22
27
|
export interface HostLoadSnapshot {
|
|
23
28
|
readonly sampledAt: string;
|
|
29
|
+
/**
|
|
30
|
+
* True when `systemPressure` carries a CPU pressure signal the governor gates on.
|
|
31
|
+
* The wire name predates decision 0021: on Windows the signal is an estimate
|
|
32
|
+
* (see `pressureSource`), and the static host fact `psiAvailable` stays false.
|
|
33
|
+
*/
|
|
24
34
|
readonly psiAvailable: boolean;
|
|
35
|
+
/** Null exactly when `psiAvailable` is false. */
|
|
36
|
+
readonly pressureSource: HostLoadPressureSource | null;
|
|
25
37
|
readonly systemPressure: HostSystemPressure | null;
|
|
26
38
|
/** True only when the bridge runs in a cgroup of its own (see isDedicatedBridgeUnit). */
|
|
27
39
|
readonly ownCgroupDedicated: boolean;
|
|
@@ -48,7 +60,7 @@ export interface HostLoadSource {
|
|
|
48
60
|
*/
|
|
49
61
|
export interface HostCpuAttribution {
|
|
50
62
|
readonly sampledAt: string;
|
|
51
|
-
/** Busy cores on the whole host, from /proc/stat deltas. */
|
|
63
|
+
/** Busy cores on the whole host, from /proc/stat deltas (os.cpus() deltas on Windows). */
|
|
52
64
|
readonly hostCoresInUse: number;
|
|
53
65
|
/** Cores used by the bridge's dedicated cgroup; null when the cgroup is not dedicated. */
|
|
54
66
|
readonly ownCoresInUse: number | null;
|
|
@@ -80,8 +92,9 @@ export interface HostLoadSamplerOptions {
|
|
|
80
92
|
export declare const defaultHostLoadSampleIntervalMs = 5000;
|
|
81
93
|
/**
|
|
82
94
|
* Samples Linux PSI and the bridge's own cgroup on an interval and caches the
|
|
83
|
-
* latest snapshot. Every read is async and failure-tolerant: a host without
|
|
84
|
-
* (
|
|
95
|
+
* latest snapshot. Every read is async and failure-tolerant: a Linux host without
|
|
96
|
+
* PSI (old kernel, `psi=0`) or another non-Windows host reports `psiAvailable: false`
|
|
97
|
+
* and no pressure. Windows reports a CPU pressure estimate instead (decision 0021).
|
|
85
98
|
*/
|
|
86
99
|
export declare class HostLoadSampler implements HostLoadSource {
|
|
87
100
|
private readonly environment;
|
|
@@ -100,6 +113,8 @@ export declare class HostLoadSampler implements HostLoadSource {
|
|
|
100
113
|
private hostCpuMark;
|
|
101
114
|
private latestCpuAttribution;
|
|
102
115
|
private latestMemoryHeadroom;
|
|
116
|
+
private windowsCpuMark;
|
|
117
|
+
private readonly windowsCpuPressure;
|
|
103
118
|
private readonly forgeCgroups;
|
|
104
119
|
private readonly sandboxCpu;
|
|
105
120
|
constructor(options?: HostLoadSamplerOptions);
|
|
@@ -115,6 +130,14 @@ export declare class HostLoadSampler implements HostLoadSource {
|
|
|
115
130
|
sample(): Promise<HostLoadSnapshot>;
|
|
116
131
|
private startOnce;
|
|
117
132
|
private readSnapshot;
|
|
133
|
+
/**
|
|
134
|
+
* Decision 0021: Windows has no PSI or cgroups. CPU pressure is estimated from
|
|
135
|
+
* whole-host CPU use between samples, and memory is available physical memory.
|
|
136
|
+
* The bridge's own share is not attributed, so external load stays unknown and
|
|
137
|
+
* Forge's work counts through reserved cost and the pressure gate (as on a Linux
|
|
138
|
+
* host whose bridge has no dedicated cgroup).
|
|
139
|
+
*/
|
|
140
|
+
private readWindowsSnapshot;
|
|
118
141
|
private readCgroupMemoryHeadroom;
|
|
119
142
|
private readSystemPressure;
|
|
120
143
|
private readOwnCgroup;
|
|
@@ -2,13 +2,15 @@ import path from "node:path";
|
|
|
2
2
|
import { defaultHostEnvironment, detectHostFacts, readOptional, } from "./host-facts.js";
|
|
3
3
|
import { cgroupLeafName, isDedicatedBridgeUnit, parseCgroupCpuUsageUsec, parseCgroupMemoryAnonBytes, parseMemAvailableBytes, parseNonNegativeInteger, parsePressureStall, parseProcStatCpuTotals, parseUnifiedCgroupMembership, parseUnifiedCgroupPath, } from "./host-pressure-stall.js";
|
|
4
4
|
import { ForgeCgroupCpuMeter, readCgroupMemoryHeadroomBytes, } from "./host-load-forge-cgroups.js";
|
|
5
|
+
import { cpuTimeTotals, cpuUtilisation, WindowsCpuPressureEstimator, } from "./host-load-windows-cpu.js";
|
|
5
6
|
export const defaultHostLoadSampleIntervalMs = 5_000;
|
|
6
7
|
/** Samples kept for the governor's pressure streak (FORGE_HOST_LOAD_BACKPRESSURE_SAMPLES is at most 60). */
|
|
7
8
|
const retainedSampleCount = 64;
|
|
8
9
|
/**
|
|
9
10
|
* Samples Linux PSI and the bridge's own cgroup on an interval and caches the
|
|
10
|
-
* latest snapshot. Every read is async and failure-tolerant: a host without
|
|
11
|
-
* (
|
|
11
|
+
* latest snapshot. Every read is async and failure-tolerant: a Linux host without
|
|
12
|
+
* PSI (old kernel, `psi=0`) or another non-Windows host reports `psiAvailable: false`
|
|
13
|
+
* and no pressure. Windows reports a CPU pressure estimate instead (decision 0021).
|
|
12
14
|
*/
|
|
13
15
|
export class HostLoadSampler {
|
|
14
16
|
environment;
|
|
@@ -27,6 +29,8 @@ export class HostLoadSampler {
|
|
|
27
29
|
hostCpuMark = null;
|
|
28
30
|
latestCpuAttribution = null;
|
|
29
31
|
latestMemoryHeadroom = null;
|
|
32
|
+
windowsCpuMark = null;
|
|
33
|
+
windowsCpuPressure = new WindowsCpuPressureEstimator();
|
|
30
34
|
forgeCgroups;
|
|
31
35
|
sandboxCpu;
|
|
32
36
|
constructor(options = {}) {
|
|
@@ -77,6 +81,9 @@ export class HostLoadSampler {
|
|
|
77
81
|
sample() {
|
|
78
82
|
this.inFlight ??= this.readSnapshot()
|
|
79
83
|
.then(snapshot => {
|
|
84
|
+
// A Windows reading that did not advance the CPU window returns the last snapshot.
|
|
85
|
+
if (snapshot === this.latest)
|
|
86
|
+
return snapshot;
|
|
80
87
|
this.latest = snapshot;
|
|
81
88
|
this.history.push(snapshot);
|
|
82
89
|
if (this.history.length > retainedSampleCount)
|
|
@@ -104,6 +111,8 @@ export class HostLoadSampler {
|
|
|
104
111
|
async readSnapshot() {
|
|
105
112
|
const sampledAtMs = this.now();
|
|
106
113
|
const monotonicMs = this.monotonicNow();
|
|
114
|
+
if (this.environment.platform === "win32")
|
|
115
|
+
return this.readWindowsSnapshot(sampledAtMs, monotonicMs);
|
|
107
116
|
const linux = this.environment.platform === "linux";
|
|
108
117
|
const [systemPressure, ownCgroup, memoryAvailableBytes, hostCoresInUse, cgroupMemoryHeadroomBytes, sandboxCores] = linux
|
|
109
118
|
? await Promise.all([
|
|
@@ -124,12 +133,49 @@ export class HostLoadSampler {
|
|
|
124
133
|
return {
|
|
125
134
|
sampledAt,
|
|
126
135
|
psiAvailable: systemPressure !== null,
|
|
136
|
+
pressureSource: systemPressure !== null ? "psi" : null,
|
|
127
137
|
systemPressure,
|
|
128
138
|
ownCgroupDedicated: ownCgroup !== null,
|
|
129
139
|
ownCgroup,
|
|
130
140
|
memoryAvailableBytes,
|
|
131
141
|
};
|
|
132
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Decision 0021: Windows has no PSI or cgroups. CPU pressure is estimated from
|
|
145
|
+
* whole-host CPU use between samples, and memory is available physical memory.
|
|
146
|
+
* The bridge's own share is not attributed, so external load stays unknown and
|
|
147
|
+
* Forge's work counts through reserved cost and the pressure gate (as on a Linux
|
|
148
|
+
* host whose bridge has no dedicated cgroup).
|
|
149
|
+
*/
|
|
150
|
+
readWindowsSnapshot(sampledAtMs, monotonicMs) {
|
|
151
|
+
let totals;
|
|
152
|
+
try {
|
|
153
|
+
totals = cpuTimeTotals(this.environment.cpus());
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
totals = null;
|
|
157
|
+
}
|
|
158
|
+
const previous = this.windowsCpuMark;
|
|
159
|
+
const sampledAt = new Date(sampledAtMs).toISOString();
|
|
160
|
+
if (this.latest && totals && previous && previous.totals.cpuCount === totals.cpuCount
|
|
161
|
+
&& monotonicMs - previous.atMs < minimumWindowsCpuWindowMs) {
|
|
162
|
+
// Too soon after the last reading (start() right after a sample) for a stable delta:
|
|
163
|
+
// the window stays open and the last snapshot is returned as is. sample() does not
|
|
164
|
+
// record it again, so it never counts as another sample in the pressure streak.
|
|
165
|
+
return this.latest;
|
|
166
|
+
}
|
|
167
|
+
this.windowsCpuMark = totals ? { totals, atMs: monotonicMs } : null;
|
|
168
|
+
const elapsedMs = previous ? monotonicMs - previous.atMs : 0;
|
|
169
|
+
const utilisation = previous && elapsedMs > 0 ? cpuUtilisation(previous.totals, totals) : null;
|
|
170
|
+
// The first sample, or a break in readings (no times, a CPU count change, a counter
|
|
171
|
+
// reset), reports no pressure and restarts the averages from the next window.
|
|
172
|
+
if (utilisation === null)
|
|
173
|
+
this.windowsCpuPressure.reset();
|
|
174
|
+
const cpu = utilisation === null ? null : this.windowsCpuPressure.update(utilisation, elapsedMs);
|
|
175
|
+
this.latestMemoryHeadroom = null;
|
|
176
|
+
this.latestCpuAttribution = hostCpuAttribution(sampledAt, utilisation !== null && totals ? roundCores(utilisation * totals.cpuCount) : null, null);
|
|
177
|
+
return windowsSnapshot(sampledAt, cpu, this.fallbackFreeMemory());
|
|
178
|
+
}
|
|
133
179
|
async readCgroupMemoryHeadroom() {
|
|
134
180
|
const membership = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "self", "cgroup"));
|
|
135
181
|
const cgroupPath = membership ? parseUnifiedCgroupMembership(membership) : null;
|
|
@@ -216,6 +262,19 @@ export class HostLoadSampler {
|
|
|
216
262
|
return content ? parsePressureStall(content) : null;
|
|
217
263
|
}
|
|
218
264
|
}
|
|
265
|
+
/** Windows CPU deltas shorter than this are too noisy to fold into the pressure estimate. */
|
|
266
|
+
const minimumWindowsCpuWindowMs = 250;
|
|
267
|
+
function windowsSnapshot(sampledAt, cpu, memoryAvailableBytes) {
|
|
268
|
+
return {
|
|
269
|
+
sampledAt,
|
|
270
|
+
psiAvailable: cpu !== null,
|
|
271
|
+
pressureSource: cpu !== null ? "windows_estimate" : null,
|
|
272
|
+
systemPressure: cpu ? { cpu, memory: null, io: null } : null,
|
|
273
|
+
ownCgroupDedicated: false,
|
|
274
|
+
ownCgroup: null,
|
|
275
|
+
memoryAvailableBytes,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
219
278
|
function roundCores(value) {
|
|
220
279
|
return Math.round(value * 100) / 100;
|
|
221
280
|
}
|
|
@@ -58,7 +58,9 @@ export interface ManagedCommandStepInput {
|
|
|
58
58
|
/**
|
|
59
59
|
* Maps a managed command to its class: `managed.<profile>` for verification
|
|
60
60
|
* profiles (a .NET tier's cost per parallel shard), `managed.playwright`,
|
|
61
|
-
* `managed.build` for build-producing commands,
|
|
61
|
+
* `managed.build` for build-producing commands, `managed.test` for a test run
|
|
62
|
+
* that reuses an earlier build, and `managed.command` otherwise. Only
|
|
63
|
+
* `managed.command` skips the host test slot (decision 0018).
|
|
62
64
|
*/
|
|
63
65
|
export declare function classifyManagedCommand(input: ManagedCommandStepInput): HostLoadStepClassification;
|
|
64
66
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// (decision 0013). Step 4 replaces the defaults with P75 estimates from history.
|
|
1
|
+
import path from "node:path";
|
|
3
2
|
const gib = 1024 ** 3;
|
|
4
3
|
export const defaultHostLoadStepCosts = {
|
|
5
4
|
dotnetTier: { cpuCores: 2, memoryBytes: 3 * gib },
|
|
@@ -60,7 +59,9 @@ function stepClassSegment(value) {
|
|
|
60
59
|
/**
|
|
61
60
|
* Maps a managed command to its class: `managed.<profile>` for verification
|
|
62
61
|
* profiles (a .NET tier's cost per parallel shard), `managed.playwright`,
|
|
63
|
-
* `managed.build` for build-producing commands,
|
|
62
|
+
* `managed.build` for build-producing commands, `managed.test` for a test run
|
|
63
|
+
* that reuses an earlier build, and `managed.command` otherwise. Only
|
|
64
|
+
* `managed.command` skips the host test slot (decision 0018).
|
|
64
65
|
*/
|
|
65
66
|
export function classifyManagedCommand(input) {
|
|
66
67
|
if (input.verificationProfile) {
|
|
@@ -74,14 +75,68 @@ export function classifyManagedCommand(input) {
|
|
|
74
75
|
},
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
|
-
const invocation = [input.command, ...input.args].map(argument => argument.toLowerCase());
|
|
78
|
-
|
|
78
|
+
const invocation = [input.command, ...input.args].map(argument => argument.toLowerCase().replaceAll("\\", "/"));
|
|
79
|
+
const programs = programsRun(invocation);
|
|
80
|
+
if (programs.some(program => path.posix.basename(program).includes("playwright"))) {
|
|
79
81
|
return { stepClass: "managed.playwright", cost: defaultHostLoadStepCosts.playwright };
|
|
80
82
|
}
|
|
81
83
|
if (input.buildProducing)
|
|
82
84
|
return { stepClass: "managed.build", cost: defaultHostLoadStepCosts.managedBuild };
|
|
85
|
+
if (isTestRun(invocation, programs))
|
|
86
|
+
return { stepClass: "managed.test", cost: defaultHostLoadStepCosts.dotnetTier };
|
|
83
87
|
return { stepClass: "managed.command", cost: defaultHostLoadStepCosts.generic };
|
|
84
88
|
}
|
|
89
|
+
const testRunScripts = [...dotnetTierScripts, affectedDotnetScript].map(script => script.toLowerCase());
|
|
90
|
+
const packageManagers = new Set(["npm", "pnpm", "yarn", "npx"]);
|
|
91
|
+
const scriptHosts = new Set(["node", "pwsh", "powershell", "bash", "sh", "tsx"]);
|
|
92
|
+
const programName = (argument) => path.posix.basename(argument).replace(/\.(exe|cmd)$/u, "");
|
|
93
|
+
// Package-manager options that take a value (`pnpm --dir tests/e2e`, `npm --prefix x`), in
|
|
94
|
+
// lower case like the invocation, so `-c` and `-f` are pnpm's `-C` and `-F`.
|
|
95
|
+
const packageManagerValueOptions = new Set(["--dir", "-c", "--prefix", "--filter", "-f", "--workspace", "--cwd", "--config"]);
|
|
96
|
+
/** The operands of an invocation, without options and, for a package manager, the values its options take. */
|
|
97
|
+
function operandsOf(command, args) {
|
|
98
|
+
const operands = [];
|
|
99
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
100
|
+
const argument = args[index];
|
|
101
|
+
if (!argument.startsWith("-"))
|
|
102
|
+
operands.push(argument);
|
|
103
|
+
else if (packageManagers.has(command) && packageManagerValueOptions.has(argument))
|
|
104
|
+
index += 1;
|
|
105
|
+
}
|
|
106
|
+
return operands;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The programs an invocation runs: the executable and, for a script host or a
|
|
110
|
+
* package manager's exec, the script or tool it starts. Arguments after that
|
|
111
|
+
* (a search pattern, a file to read) never classify the command, so
|
|
112
|
+
* `rg vitest src` or `cat playwright.config.ts` stays a plain command.
|
|
113
|
+
*/
|
|
114
|
+
function programsRun(invocation) {
|
|
115
|
+
const command = programName(invocation[0] ?? "");
|
|
116
|
+
const operands = operandsOf(command, invocation.slice(1));
|
|
117
|
+
if (scriptHosts.has(command))
|
|
118
|
+
return [command, ...operands.slice(0, 1)];
|
|
119
|
+
if (command === "npx")
|
|
120
|
+
return [command, ...operands.slice(0, 1)];
|
|
121
|
+
if (packageManagers.has(command) && ["exec", "dlx"].includes(operands[0] ?? ""))
|
|
122
|
+
return [command, ...operands.slice(1, 2)];
|
|
123
|
+
// `pnpm vitest`, `yarn playwright test`: these run a package's binary by name.
|
|
124
|
+
if (command === "pnpm" || command === "yarn")
|
|
125
|
+
return [command, ...operands.slice(0, 1)];
|
|
126
|
+
return [command];
|
|
127
|
+
}
|
|
128
|
+
/** `dotnet test`, the tier and affected scripts, Vitest, or a package manager's test script. */
|
|
129
|
+
function isTestRun(invocation, programs) {
|
|
130
|
+
const command = programs[0] ?? "";
|
|
131
|
+
const operands = operandsOf(command, invocation.slice(1));
|
|
132
|
+
if (command === "dotnet" && operands[0] === "test")
|
|
133
|
+
return true;
|
|
134
|
+
if (programs.some(program => testRunScripts.some(script => program.endsWith(script))))
|
|
135
|
+
return true;
|
|
136
|
+
if (programs.some(program => programName(program) === "vitest"))
|
|
137
|
+
return true;
|
|
138
|
+
return packageManagers.has(command) && (operands[0] === "test" || (operands[0] === "run" && operands[1] === "test"));
|
|
139
|
+
}
|
|
85
140
|
/**
|
|
86
141
|
* The default cost of a step class, for a step whose cost the requester does
|
|
87
142
|
* not get to choose (a Docker sandbox asking the host bridge for admission).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HostLoadAdmissionDecision } from "./host-load-admission.js";
|
|
2
|
+
import type { HostLoadToken, HostLoadTokenOwner, HostLoadTokenPriority } from "./host-load-token-ledger.js";
|
|
3
|
+
/** Every governed step class takes the slot unless it is known to be light. */
|
|
4
|
+
export declare function takesHostTestSlot(stepClass: string): boolean;
|
|
5
|
+
/** A step waiting for the slot, as its owner records it in the ledger. */
|
|
6
|
+
export interface HostTestSlotTicketRequest {
|
|
7
|
+
readonly ticketId: string;
|
|
8
|
+
readonly stepClass: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly dispatchAttemptId: string | null;
|
|
11
|
+
readonly priority: HostLoadTokenPriority;
|
|
12
|
+
/** Wall clock (ISO): every process on the host orders by the same clock. */
|
|
13
|
+
readonly enqueuedAt: string;
|
|
14
|
+
}
|
|
15
|
+
/** A ticket in the ledger: its owner renews `expiresAt` on every transaction while it waits. */
|
|
16
|
+
export interface HostTestSlotTicket extends HostTestSlotTicketRequest {
|
|
17
|
+
readonly owner: HostLoadTokenOwner;
|
|
18
|
+
readonly expiresAt: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The host queue in admission order: foreground first, except background that has
|
|
22
|
+
* waited past the anti-starvation window, then oldest first.
|
|
23
|
+
*/
|
|
24
|
+
export declare function orderHostTestSlotQueue(tickets: readonly HostTestSlotTicketRequest[], nowMs: number, antiStarvationMs: number): HostTestSlotTicketRequest[];
|
|
25
|
+
export interface HostTestSlotInput {
|
|
26
|
+
readonly ticket: HostTestSlotTicketRequest;
|
|
27
|
+
/** Every live ticket on the host, this one included or not. */
|
|
28
|
+
readonly queue: readonly HostTestSlotTicketRequest[];
|
|
29
|
+
/** Every live token on the host; fenced and degraded ones still hold their slot. */
|
|
30
|
+
readonly tokens: readonly HostLoadToken[];
|
|
31
|
+
readonly testSlots: number;
|
|
32
|
+
readonly nowMs: number;
|
|
33
|
+
readonly antiStarvationMs: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Admitted once the slots the holders leave free reach this ticket's place in the
|
|
37
|
+
* host queue. A token kept until its attempt's teardown (`retainedAt`) holds the slot
|
|
38
|
+
* against every other attempt, but not against its own: that attempt's next step
|
|
39
|
+
* would otherwise wait for its own teardown.
|
|
40
|
+
*/
|
|
41
|
+
export declare function decideHostTestSlot(input: HostTestSlotInput): HostLoadAdmissionDecision;
|
|
42
|
+
/** A ticket read back from the ledger; a malformed one is dropped, never trusted. */
|
|
43
|
+
export declare function validHostTestSlotTicket(value: unknown): value is HostTestSlotTicket;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The host test slot (decision 0018): two Forge sessions on one host share it, so
|
|
2
|
+
// their builds, test runs, Playwright runs and runtime builds take turns instead of
|
|
3
|
+
// competing for the CPU and memory. Waiters queue host-wide in the shared ledger,
|
|
4
|
+
// foreground before background and first come, first served within a class, so a
|
|
5
|
+
// step in another process (the completion MCP server) is never overtaken by the
|
|
6
|
+
// bridge's own steps. A slot holder that crashed keeps its slot only until the
|
|
7
|
+
// ledger reclaims its token (dead owner, process tree stopped, or lease fenced).
|
|
8
|
+
/** Steps that never take the slot: plain managed commands (git, ls, cat) and dependency installs. */
|
|
9
|
+
const slotFreeStepClasses = new Set(["managed.command", "deps.install"]);
|
|
10
|
+
/** Every governed step class takes the slot unless it is known to be light. */
|
|
11
|
+
export function takesHostTestSlot(stepClass) {
|
|
12
|
+
return !slotFreeStepClasses.has(stepClass);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The host queue in admission order: foreground first, except background that has
|
|
16
|
+
* waited past the anti-starvation window, then oldest first.
|
|
17
|
+
*/
|
|
18
|
+
export function orderHostTestSlotQueue(tickets, nowMs, antiStarvationMs) {
|
|
19
|
+
const rank = (ticket) => ticket.priority === "foreground" || nowMs - Date.parse(ticket.enqueuedAt) >= antiStarvationMs ? 0 : 1;
|
|
20
|
+
return [...tickets].sort((a, b) => rank(a) - rank(b)
|
|
21
|
+
|| Date.parse(a.enqueuedAt) - Date.parse(b.enqueuedAt)
|
|
22
|
+
|| a.ticketId.localeCompare(b.ticketId));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Admitted once the slots the holders leave free reach this ticket's place in the
|
|
26
|
+
* host queue. A token kept until its attempt's teardown (`retainedAt`) holds the slot
|
|
27
|
+
* against every other attempt, but not against its own: that attempt's next step
|
|
28
|
+
* would otherwise wait for its own teardown.
|
|
29
|
+
*/
|
|
30
|
+
export function decideHostTestSlot(input) {
|
|
31
|
+
const ownRetained = (token) => Boolean(token.retainedAt)
|
|
32
|
+
&& token.dispatchAttemptId !== null && token.dispatchAttemptId === input.ticket.dispatchAttemptId;
|
|
33
|
+
const holders = input.tokens.filter(token => takesHostTestSlot(token.stepClass) && !ownRetained(token));
|
|
34
|
+
const queue = input.queue.some(entry => entry.ticketId === input.ticket.ticketId)
|
|
35
|
+
? input.queue
|
|
36
|
+
: [...input.queue, input.ticket];
|
|
37
|
+
const ahead = orderHostTestSlotQueue(queue, input.nowMs, input.antiStarvationMs)
|
|
38
|
+
.findIndex(entry => entry.ticketId === input.ticket.ticketId);
|
|
39
|
+
const free = Math.max(0, input.testSlots - holders.length);
|
|
40
|
+
const admitted = ahead < free;
|
|
41
|
+
const reserved = {
|
|
42
|
+
reservedCpuCores: input.tokens.reduce((sum, token) => sum + token.cost.cpuCores, 0),
|
|
43
|
+
reservedMemoryBytes: input.tokens.reduce((sum, token) => sum + token.cost.memoryBytes, 0),
|
|
44
|
+
cpuBudgetCores: null,
|
|
45
|
+
memoryBudgetBytes: null,
|
|
46
|
+
};
|
|
47
|
+
if (admitted) {
|
|
48
|
+
return { ...reserved, admitted, reason: "admitted_test_slot", detail: "The host test slot is free." };
|
|
49
|
+
}
|
|
50
|
+
const heldBy = holders.length > 0
|
|
51
|
+
? `held by ${holders.map(describeHolder).join("; ")}`
|
|
52
|
+
: "the steps ahead of this one take it first";
|
|
53
|
+
return {
|
|
54
|
+
...reserved,
|
|
55
|
+
admitted,
|
|
56
|
+
reason: "host_test_slot",
|
|
57
|
+
detail: `Waiting for the host test slot (${input.testSlots} at once): ${heldBy}; ${ahead} step(s) ahead in the host queue.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function describeHolder(token) {
|
|
61
|
+
const attempt = token.dispatchAttemptId ? `, attempt ${token.dispatchAttemptId}` : "";
|
|
62
|
+
const state = token.degradedAt
|
|
63
|
+
? ", whose owner is gone; it is returned once its processes are stopped"
|
|
64
|
+
: token.fencedAt ? ", which is past its lease"
|
|
65
|
+
: token.retainedAt ? ", whose processes could not be proven stopped; it is returned at attempt teardown" : "";
|
|
66
|
+
return `${token.label} (${token.stepClass}${attempt}${state})`;
|
|
67
|
+
}
|
|
68
|
+
/** A ticket read back from the ledger; a malformed one is dropped, never trusted. */
|
|
69
|
+
export function validHostTestSlotTicket(value) {
|
|
70
|
+
const ticket = value;
|
|
71
|
+
return Boolean(ticket)
|
|
72
|
+
&& typeof ticket.ticketId === "string"
|
|
73
|
+
&& typeof ticket.stepClass === "string"
|
|
74
|
+
&& typeof ticket.label === "string"
|
|
75
|
+
&& (ticket.dispatchAttemptId === null || typeof ticket.dispatchAttemptId === "string")
|
|
76
|
+
&& (ticket.priority === "foreground" || ticket.priority === "background")
|
|
77
|
+
&& Number.isFinite(Date.parse(String(ticket.enqueuedAt)))
|
|
78
|
+
&& Number.isFinite(Date.parse(String(ticket.expiresAt)))
|
|
79
|
+
&& Number.isSafeInteger(ticket.owner?.pid)
|
|
80
|
+
&& typeof ticket.owner?.processInstanceId === "string";
|
|
81
|
+
}
|