@loucompanion/forge-bridge 0.1.4-dev.e83e5bc6ecce → 0.1.4-dev.f22f5e3d01fe
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 +55 -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.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +71 -2
- package/dist/bridge/bridge.service.js +282 -114
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +132 -14
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +12 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- 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 +59 -3
- package/dist/runtime/host-runtime-lease.js +199 -8
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +7 -1
- package/dist/sandbox/host-capacity-broker.js +23 -4
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- 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 +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- 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 +49 -9
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +74 -151
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- 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.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +7 -2
- package/dist/session/session.service.js +100 -2
- package/dist/session/session.types.js +3 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- 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
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
2
2
|
import type { HostLoadStepCost } from "./host-load-step-class.js";
|
|
3
|
+
import { type HostTestSlotTicket, type HostTestSlotTicketRequest } from "./host-load-test-slot.js";
|
|
3
4
|
import { type HostLoadStepProcess, type HostLoadStepTerminator } from "./host-load-step-reaper.js";
|
|
4
5
|
/**
|
|
5
6
|
* File-backed token ledger for the host load governor (decision 0013). Every
|
|
@@ -40,6 +41,12 @@ export interface HostLoadToken {
|
|
|
40
41
|
readonly degradedAt?: string | null;
|
|
41
42
|
/** Set when the lease lapsed while the owner was still live: cost kept, renewal refused. */
|
|
42
43
|
readonly fencedAt?: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Set when the step ended but part of its process tree could not be proven
|
|
46
|
+
* stopped: the token is kept until it is (or until attempt teardown), and the
|
|
47
|
+
* attempt's own later steps do not wait for it (decision 0018).
|
|
48
|
+
*/
|
|
49
|
+
readonly retainedAt?: string | null;
|
|
43
50
|
}
|
|
44
51
|
export interface HostLoadTokenRequest {
|
|
45
52
|
readonly stepClass: string;
|
|
@@ -56,11 +63,17 @@ export interface HostLoadLedgerTransaction {
|
|
|
56
63
|
* restoring the reservations it lost, so no new step may be admitted yet.
|
|
57
64
|
*/
|
|
58
65
|
readonly recoveringUntil: string | null;
|
|
66
|
+
/** Live host test slot tickets of every owner (decision 0018). */
|
|
67
|
+
readonly queue: readonly HostTestSlotTicket[];
|
|
59
68
|
issue(request: HostLoadTokenRequest): HostLoadToken;
|
|
69
|
+
/** Takes an admitted step's ticket out of the queue in the same commit as its token. */
|
|
70
|
+
removeTicket(ticketId: string): void;
|
|
60
71
|
renew(tokenId: string, fencingToken: number): HostLoadToken | null;
|
|
61
72
|
remove(tokenId: string, fencingToken: number): boolean;
|
|
62
73
|
/** Records the step's process tree on its token; null when the token is fenced. */
|
|
63
74
|
attach(tokenId: string, fencingToken: number, stepProcess: HostLoadStepProcess): HostLoadToken | null;
|
|
75
|
+
/** Marks the token kept after its step ended (`retainedAt`), fenced or not; null when it is gone. */
|
|
76
|
+
retain(tokenId: string, fencingToken: number): HostLoadToken | null;
|
|
64
77
|
}
|
|
65
78
|
export interface HostLoadTransactionOutcome<T> {
|
|
66
79
|
readonly result: T;
|
|
@@ -91,6 +104,11 @@ export interface HostLoadTokenLedgerOptions {
|
|
|
91
104
|
* cost: it is put back (fenced, unless a quarantine is still recovering).
|
|
92
105
|
*/
|
|
93
106
|
readonly heldTokens?: () => readonly HostLoadToken[];
|
|
107
|
+
/**
|
|
108
|
+
* The steps this owner still waits on for the host test slot (decision 0018). Each
|
|
109
|
+
* transaction renews their tickets and drops the owner's other tickets.
|
|
110
|
+
*/
|
|
111
|
+
readonly waitingTickets?: () => readonly HostTestSlotTicketRequest[];
|
|
94
112
|
/** Stops a reclaimed token's step; defaults to the exact process-tree reaper. */
|
|
95
113
|
readonly terminateStep?: HostLoadStepTerminator;
|
|
96
114
|
/** Host suspend counter (test seam); defaults to hostSuspendedMs. */
|
|
@@ -145,6 +163,14 @@ export declare class HostLoadTokenLedger {
|
|
|
145
163
|
*/
|
|
146
164
|
release(tokenId: string, fencingToken: number): Promise<void>;
|
|
147
165
|
private lockedTransaction;
|
|
166
|
+
/** The live token set and host test slot queue one locked transaction reads and changes. */
|
|
167
|
+
private transactionView;
|
|
168
|
+
/**
|
|
169
|
+
* The host test slot queue (decision 0018): other owners' tickets while their owner
|
|
170
|
+
* lives and renews them, and this owner's current waiters, renewed. A ticket this
|
|
171
|
+
* owner no longer waits on (admitted, cancelled, timed out) leaves the queue here.
|
|
172
|
+
*/
|
|
173
|
+
private liveQueue;
|
|
148
174
|
/**
|
|
149
175
|
* Decides every token another owner can no longer vouch for (decision 0013):
|
|
150
176
|
* - owner alive but its lease lapsed (it stalled): the token is fenced, never
|
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
6
6
|
import { captureHostProcessIdentity } from "../shared/process/host-process-supervisor.js";
|
|
7
7
|
import { HostCapacityLedgerUnavailableError, HostLoadLedgerLock } from "./host-load-ledger-lock.js";
|
|
8
|
+
import { validHostTestSlotTicket } from "./host-load-test-slot.js";
|
|
8
9
|
import { terminateHostLoadStepProcess, validHostLoadStepProcess, } from "./host-load-step-reaper.js";
|
|
9
10
|
const processInstanceId = randomUUID();
|
|
10
11
|
const maximumLedgerBytes = 1024 * 1024;
|
|
@@ -160,10 +161,9 @@ export class HostLoadTokenLedger {
|
|
|
160
161
|
const { ledger, quarantined } = await this.read();
|
|
161
162
|
const nowMs = this.now();
|
|
162
163
|
const nowIso = new Date(nowMs).toISOString();
|
|
163
|
-
const expiresAt = () => new Date(this.now() + this.options.leaseMs).toISOString();
|
|
164
164
|
const suspendedMs = this.suspendedMs();
|
|
165
165
|
// Each lease records the host's suspend counter, so time asleep never counts as a missed renewal.
|
|
166
|
-
const lease = () => ({ expiresAt:
|
|
166
|
+
const lease = () => ({ expiresAt: new Date(this.now() + this.options.leaseMs).toISOString(), suspendedMsAtRenewal: suspendedMs });
|
|
167
167
|
const recoveringUntil = ledger.recoveringUntil && Date.parse(ledger.recoveringUntil) > nowMs
|
|
168
168
|
? ledger.recoveringUntil
|
|
169
169
|
: null;
|
|
@@ -183,72 +183,31 @@ export class HostLoadTokenLedger {
|
|
|
183
183
|
...restored,
|
|
184
184
|
];
|
|
185
185
|
const { reclaimed, degraded, fencedNow } = await this.reapExpired(current, nowMs, suspendedMs, nowIso);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
issue: request => {
|
|
196
|
-
const token = {
|
|
197
|
-
tokenId: randomUUID(),
|
|
198
|
-
fencingToken: nextFencingToken,
|
|
199
|
-
stepClass: request.stepClass,
|
|
200
|
-
label: request.label,
|
|
201
|
-
cost: { cpuCores: request.cost.cpuCores, memoryBytes: request.cost.memoryBytes },
|
|
202
|
-
dispatchAttemptId: request.dispatchAttemptId,
|
|
203
|
-
priority: request.priority,
|
|
204
|
-
owner: this.owner,
|
|
205
|
-
admittedAt: new Date(this.now()).toISOString(),
|
|
206
|
-
...lease(),
|
|
207
|
-
};
|
|
208
|
-
nextFencingToken += 1;
|
|
209
|
-
tokens = [...tokens, token];
|
|
210
|
-
changed = true;
|
|
211
|
-
return token;
|
|
212
|
-
},
|
|
213
|
-
renew: (tokenId, fencingToken) => {
|
|
214
|
-
const index = tokens.findIndex(token => token.tokenId === tokenId && token.fencingToken === fencingToken);
|
|
215
|
-
if (index < 0 || tokens[index].fencedAt)
|
|
216
|
-
return null;
|
|
217
|
-
const renewed = { ...tokens[index], ...lease() };
|
|
218
|
-
tokens = tokens.map((token, position) => position === index ? renewed : token);
|
|
219
|
-
changed = true;
|
|
220
|
-
return renewed;
|
|
221
|
-
},
|
|
222
|
-
attach: (tokenId, fencingToken, stepProcess) => {
|
|
223
|
-
const index = tokens.findIndex(token => token.tokenId === tokenId && token.fencingToken === fencingToken);
|
|
224
|
-
if (index < 0 || tokens[index].fencedAt)
|
|
225
|
-
return null;
|
|
226
|
-
const attached = { ...tokens[index], stepProcess };
|
|
227
|
-
tokens = tokens.map((token, position) => position === index ? attached : token);
|
|
228
|
-
changed = true;
|
|
229
|
-
return attached;
|
|
230
|
-
},
|
|
231
|
-
remove: (tokenId, fencingToken) => {
|
|
232
|
-
const before = tokens.length;
|
|
233
|
-
tokens = tokens.filter(token => !(token.tokenId === tokenId && token.fencingToken === fencingToken));
|
|
234
|
-
changed ||= tokens.length !== before;
|
|
235
|
-
return tokens.length !== before;
|
|
236
|
-
},
|
|
186
|
+
const queue = this.liveQueue(ledger.slotQueue ?? [], nowMs, lease().expiresAt);
|
|
187
|
+
const state = {
|
|
188
|
+
tokens: current
|
|
189
|
+
.filter(token => !reclaimed.includes(token))
|
|
190
|
+
.map(token => degraded.get(token) ?? fencedNow.get(token) ?? token),
|
|
191
|
+
queue: queue.tickets,
|
|
192
|
+
nextFencingToken: Math.max(ledger.nextFencingToken, ...restored.map(token => token.fencingToken + 1)),
|
|
193
|
+
changed: quarantined || reclaimed.length > 0 || degraded.size > 0 || fencedNow.size > 0 || held.length > 0
|
|
194
|
+
|| queue.changed || (ledger.recoveringUntil !== undefined && recoveringUntil === null),
|
|
237
195
|
};
|
|
238
|
-
const result = await action(
|
|
239
|
-
if (changed) {
|
|
196
|
+
const result = await action(this.transactionView(state, recoveringUntil, lease));
|
|
197
|
+
if (state.changed) {
|
|
240
198
|
// A lock broken under us (a stalled holder taken for dead) must not commit.
|
|
241
199
|
if (!await this.lock.holds(lockToken)) {
|
|
242
200
|
throw new HostCapacityLedgerUnavailableError("the ledger lock was lost before the update could be written.");
|
|
243
201
|
}
|
|
244
202
|
await this.write({
|
|
245
203
|
schemaVersion: 1,
|
|
246
|
-
nextFencingToken,
|
|
247
|
-
tokens,
|
|
204
|
+
nextFencingToken: state.nextFencingToken,
|
|
205
|
+
tokens: state.tokens,
|
|
206
|
+
...state.queue.length > 0 ? { slotQueue: state.queue } : {},
|
|
248
207
|
...recoveringUntil ? { recoveringUntil } : {},
|
|
249
208
|
});
|
|
250
209
|
}
|
|
251
|
-
const heldNow = tokens.filter(token => heldIds.has(key(token)));
|
|
210
|
+
const heldNow = state.tokens.filter(token => heldIds.has(key(token)));
|
|
252
211
|
return {
|
|
253
212
|
result,
|
|
254
213
|
reclaimed,
|
|
@@ -260,6 +219,74 @@ export class HostLoadTokenLedger {
|
|
|
260
219
|
await this.lock.release(lockToken);
|
|
261
220
|
}
|
|
262
221
|
}
|
|
222
|
+
/** The live token set and host test slot queue one locked transaction reads and changes. */
|
|
223
|
+
transactionView(state, recoveringUntil, lease) {
|
|
224
|
+
const replace = (tokenId, fencingToken, change, evenFenced = false) => {
|
|
225
|
+
const index = state.tokens.findIndex(token => token.tokenId === tokenId && token.fencingToken === fencingToken);
|
|
226
|
+
if (index < 0 || (state.tokens[index].fencedAt && !evenFenced))
|
|
227
|
+
return null;
|
|
228
|
+
const changed = change(state.tokens[index]);
|
|
229
|
+
state.tokens = state.tokens.map((token, position) => position === index ? changed : token);
|
|
230
|
+
state.changed = true;
|
|
231
|
+
return changed;
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
get tokens() { return state.tokens; },
|
|
235
|
+
get queue() { return state.queue; },
|
|
236
|
+
recoveringUntil,
|
|
237
|
+
issue: request => {
|
|
238
|
+
const token = {
|
|
239
|
+
tokenId: randomUUID(),
|
|
240
|
+
fencingToken: state.nextFencingToken,
|
|
241
|
+
stepClass: request.stepClass,
|
|
242
|
+
label: request.label,
|
|
243
|
+
cost: { cpuCores: request.cost.cpuCores, memoryBytes: request.cost.memoryBytes },
|
|
244
|
+
dispatchAttemptId: request.dispatchAttemptId,
|
|
245
|
+
priority: request.priority,
|
|
246
|
+
owner: this.owner,
|
|
247
|
+
admittedAt: new Date(this.now()).toISOString(),
|
|
248
|
+
...lease(),
|
|
249
|
+
};
|
|
250
|
+
state.nextFencingToken += 1;
|
|
251
|
+
state.tokens = [...state.tokens, token];
|
|
252
|
+
state.changed = true;
|
|
253
|
+
return token;
|
|
254
|
+
},
|
|
255
|
+
renew: (tokenId, fencingToken) => replace(tokenId, fencingToken, token => ({ ...token, ...lease() })),
|
|
256
|
+
attach: (tokenId, fencingToken, stepProcess) => replace(tokenId, fencingToken, token => ({ ...token, stepProcess })),
|
|
257
|
+
// A fenced token's step can end unproven too: the marker is metadata, not a renewal.
|
|
258
|
+
retain: (tokenId, fencingToken) => replace(tokenId, fencingToken, token => ({ ...token, retainedAt: new Date(this.now()).toISOString() }), true),
|
|
259
|
+
remove: (tokenId, fencingToken) => {
|
|
260
|
+
const before = state.tokens.length;
|
|
261
|
+
state.tokens = state.tokens.filter(token => !(token.tokenId === tokenId && token.fencingToken === fencingToken));
|
|
262
|
+
state.changed ||= state.tokens.length !== before;
|
|
263
|
+
return state.tokens.length !== before;
|
|
264
|
+
},
|
|
265
|
+
removeTicket: ticketId => {
|
|
266
|
+
const before = state.queue.length;
|
|
267
|
+
state.queue = state.queue.filter(ticket => ticket.ticketId !== ticketId);
|
|
268
|
+
state.changed ||= state.queue.length !== before;
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The host test slot queue (decision 0018): other owners' tickets while their owner
|
|
274
|
+
* lives and renews them, and this owner's current waiters, renewed. A ticket this
|
|
275
|
+
* owner no longer waits on (admitted, cancelled, timed out) leaves the queue here.
|
|
276
|
+
*/
|
|
277
|
+
liveQueue(stored, nowMs, expiresAt) {
|
|
278
|
+
const owner = this.owner;
|
|
279
|
+
const mine = (ticket) => ticket.owner.pid === owner.pid
|
|
280
|
+
&& ticket.owner.processInstanceId === owner.processInstanceId;
|
|
281
|
+
const others = stored.filter(ticket => !mine(ticket)
|
|
282
|
+
&& Date.parse(ticket.expiresAt) > nowMs
|
|
283
|
+
&& this.liveness.isLive(ticket.owner));
|
|
284
|
+
const waiting = (this.options.waitingTickets?.() ?? []).map(ticket => ({ ...ticket, owner, expiresAt }));
|
|
285
|
+
return {
|
|
286
|
+
tickets: [...others, ...waiting],
|
|
287
|
+
changed: waiting.length > 0 || others.length + waiting.length !== stored.length,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
263
290
|
/**
|
|
264
291
|
* Decides every token another owner can no longer vouch for (decision 0013):
|
|
265
292
|
* - owner alive but its lease lapsed (it stalled): the token is fenced, never
|
|
@@ -342,6 +369,7 @@ export class HostLoadTokenLedger {
|
|
|
342
369
|
schemaVersion: 1,
|
|
343
370
|
nextFencingToken,
|
|
344
371
|
tokens: parsed.tokens,
|
|
372
|
+
slotQueue: Array.isArray(parsed.slotQueue) ? parsed.slotQueue.filter(validHostTestSlotTicket) : [],
|
|
345
373
|
...parsed.recoveringUntil !== undefined ? { recoveringUntil: parsed.recoveringUntil } : {},
|
|
346
374
|
},
|
|
347
375
|
quarantined: false,
|
|
@@ -414,8 +442,12 @@ function validToken(value) {
|
|
|
414
442
|
&& validOwner(token.owner)
|
|
415
443
|
&& typeof token.admittedAt === "string"
|
|
416
444
|
&& typeof token.expiresAt === "string"
|
|
417
|
-
&& (token
|
|
445
|
+
&& validOptionalTokenFields(token);
|
|
446
|
+
}
|
|
447
|
+
/** The fields a token gains as its step runs, ends or loses its owner. */
|
|
448
|
+
function validOptionalTokenFields(token) {
|
|
449
|
+
const optionalTime = (time) => time === undefined || time === null || typeof time === "string";
|
|
450
|
+
return (token.stepProcess === undefined || token.stepProcess === null || validHostLoadStepProcess(token.stepProcess))
|
|
418
451
|
&& (token.suspendedMsAtRenewal === undefined || Number.isFinite(token.suspendedMsAtRenewal))
|
|
419
|
-
&& (token.degradedAt
|
|
420
|
-
&& (token.fencedAt === undefined || token.fencedAt === null || typeof token.fencedAt === "string");
|
|
452
|
+
&& optionalTime(token.degradedAt) && optionalTime(token.fencedAt) && optionalTime(token.retainedAt);
|
|
421
453
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type os from "node:os";
|
|
2
|
+
import type { PressureStallResource } from "./host-pressure-stall.js";
|
|
3
|
+
/** Host CPU time summed over every logical CPU, in milliseconds, from os.cpus(). */
|
|
4
|
+
export interface CpuTimeTotals {
|
|
5
|
+
readonly busyMs: number;
|
|
6
|
+
readonly totalMs: number;
|
|
7
|
+
readonly cpuCount: number;
|
|
8
|
+
}
|
|
9
|
+
export type CpuTimesSource = readonly Partial<Pick<os.CpuInfo, "times">>[];
|
|
10
|
+
/**
|
|
11
|
+
* Host CPU use at which the estimate starts to report pressure. Waits for a CPU
|
|
12
|
+
* are rare below it on a many-core host. 0.6 puts the default backpressure
|
|
13
|
+
* threshold (50%) at 80% host CPU use, the default CPU budget.
|
|
14
|
+
*/
|
|
15
|
+
export declare const windowsCpuPressureKnee = 0.6;
|
|
16
|
+
/** Busy is user + nice + sys + irq; idle is not busy. Null when any CPU lacks its times. */
|
|
17
|
+
export declare function cpuTimeTotals(cpus: CpuTimesSource): CpuTimeTotals | null;
|
|
18
|
+
/** Busy share of all logical CPUs (0-1) between two readings; null across a CPU count change or a counter reset. */
|
|
19
|
+
export declare function cpuUtilisation(previous: CpuTimeTotals | null, current: CpuTimeTotals | null): number | null;
|
|
20
|
+
/** Estimated share of wall time (percent) some runnable thread waited for a CPU, for one window. */
|
|
21
|
+
export declare function estimatedCpuStallPercent(utilisation: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Keeps 10/60/300-second exponentially decaying averages of the estimate, the
|
|
24
|
+
* way the kernel keeps PSI averages, so the governor's threshold and pressure
|
|
25
|
+
* streak read it exactly like PSI. The first window seeds every average, so a
|
|
26
|
+
* host already busy when the bridge starts reports pressure at once.
|
|
27
|
+
*/
|
|
28
|
+
export declare class WindowsCpuPressureEstimator {
|
|
29
|
+
private averages;
|
|
30
|
+
/** Folds in one window of host CPU use lasting `elapsedMs`. */
|
|
31
|
+
update(utilisation: number, elapsedMs: number): PressureStallResource;
|
|
32
|
+
current(): PressureStallResource | null;
|
|
33
|
+
reset(): void;
|
|
34
|
+
}
|