@loucompanion/forge-bridge 0.1.4-dev.e1b4f55fb18d → 0.1.4-dev.e3697e9f5c98
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 +42 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +70 -1
- package/dist/bridge/bridge.service.js +278 -4
- 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/cleanup/cleanup.service.js +15 -9
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -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-load-admission.d.ts +9 -1
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.js +3 -1
- package/dist/runtime/host-load-governor-config.d.ts +9 -0
- package/dist/runtime/host-load-governor-config.js +30 -0
- package/dist/runtime/host-load-governor.d.ts +2 -0
- package/dist/runtime/host-load-governor.js +23 -1
- 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-runtime-lease.d.ts +58 -2
- package/dist/runtime/host-runtime-lease.js +198 -7
- 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/session/pre-publication-pass.d.ts +60 -0
- package/dist/session/pre-publication-pass.js +145 -0
- package/dist/session/pre-publication-validation.d.ts +21 -11
- package/dist/session/pre-publication-validation.js +149 -104
- 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.prompts.js +4 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +72 -143
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- 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 +2 -2
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -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
|
@@ -3,7 +3,8 @@ const epsilon = 1e-9;
|
|
|
3
3
|
* Decision 0013 admission rule. A step is admitted when the reserved cost of
|
|
4
4
|
* running steps plus its own cost fits the budget and host pressure is under
|
|
5
5
|
* the backpressure threshold. Memory `full` pressure is a hard stop. A step
|
|
6
|
-
* too large for the budget on its own runs only when nothing else does.
|
|
6
|
+
* too large for the budget on its own runs only when nothing else does. An
|
|
7
|
+
* optional count limit (decision 0014) caps how many heavy steps run at once.
|
|
7
8
|
* Without PSI, a simple per-host semaphore applies instead.
|
|
8
9
|
*/
|
|
9
10
|
export function decideHostLoadAdmission(input) {
|
|
@@ -11,17 +12,23 @@ export function decideHostLoadAdmission(input) {
|
|
|
11
12
|
const reservedCpuCores = running.reduce((sum, cost) => sum + cost.cpuCores, 0);
|
|
12
13
|
const reservedMemoryBytes = running.reduce((sum, cost) => sum + cost.memoryBytes, 0);
|
|
13
14
|
const base = { reservedCpuCores, reservedMemoryBytes };
|
|
15
|
+
const maxHeavySteps = input.maxHeavySteps ?? null;
|
|
14
16
|
if (!signals) {
|
|
15
|
-
|
|
17
|
+
// The count limit narrows the semaphore: min(fallback slots, max heavy steps).
|
|
18
|
+
const limited = maxHeavySteps !== null && maxHeavySteps < config.fallbackSlots;
|
|
19
|
+
const slots = limited ? maxHeavySteps : config.fallbackSlots;
|
|
20
|
+
const admitted = running.length < slots;
|
|
16
21
|
return {
|
|
17
22
|
...base,
|
|
18
23
|
admitted,
|
|
19
|
-
reason: admitted ? "admitted_fallback" : "fallback_slots",
|
|
24
|
+
reason: admitted ? "admitted_fallback" : limited ? "heavy_step_limit" : "fallback_slots",
|
|
20
25
|
cpuBudgetCores: null,
|
|
21
26
|
memoryBudgetBytes: null,
|
|
22
27
|
detail: admitted
|
|
23
28
|
? "Host pressure data is unavailable; admitted under the per-host step semaphore."
|
|
24
|
-
:
|
|
29
|
+
: limited
|
|
30
|
+
? `Host pressure data is unavailable; ${running.length} of ${slots} heavy step(s) allowed at once are running (max heavy steps).`
|
|
31
|
+
: `Host pressure data is unavailable; ${running.length} of ${config.fallbackSlots} heavy step slot(s) are in use.`,
|
|
25
32
|
};
|
|
26
33
|
}
|
|
27
34
|
const cpuBudgetCores = Math.max(0, input.logicalCpus * config.cpuBudgetFraction - (signals.externalCpuCores ?? 0));
|
|
@@ -46,6 +53,14 @@ export function decideHostLoadAdmission(input) {
|
|
|
46
53
|
detail: `Host CPU pressure (some avg10 ${signals.cpuSomeAvg10}%) has been at or above ${config.cpuPressureThreshold}% for ${signals.cpuPressuredSamples} sample(s).`,
|
|
47
54
|
};
|
|
48
55
|
}
|
|
56
|
+
if (maxHeavySteps !== null && running.length >= maxHeavySteps) {
|
|
57
|
+
return {
|
|
58
|
+
...budget,
|
|
59
|
+
admitted: false,
|
|
60
|
+
reason: "heavy_step_limit",
|
|
61
|
+
detail: `${running.length} heavy step(s) are running and the host allows at most ${maxHeavySteps} at once.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
49
64
|
if (running.length === 0) {
|
|
50
65
|
const oversize = request.cpuCores > cpuBudgetCores + epsilon
|
|
51
66
|
|| (memoryBudgetBytes !== null && request.memoryBytes > memoryBudgetBytes + epsilon);
|
|
@@ -24,8 +24,10 @@ export function withoutHostLoadGovernorVariables(environment) {
|
|
|
24
24
|
}
|
|
25
25
|
return kept;
|
|
26
26
|
}
|
|
27
|
+
// Decision 0014 operator ceilings the child's governor applies itself (host-load-governor-config.ts).
|
|
28
|
+
const hostCeilingEnvironmentNames = new Set(["FORGE_HOST_CPU_BUDGET_PERCENT", "FORGE_HOST_MAX_HEAVY_STEPS"]);
|
|
27
29
|
export function isHostLoadChildEnvironmentName(name) {
|
|
28
|
-
return name.startsWith("FORGE_HOST_LOAD_") || name === cgroupUnitEnvironment;
|
|
30
|
+
return name.startsWith("FORGE_HOST_LOAD_") || name === cgroupUnitEnvironment || hostCeilingEnvironmentNames.has(name);
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
31
33
|
* The variables a child needs to share this bridge's ledger: the flag, the
|
|
@@ -28,6 +28,15 @@ export interface HostLoadGovernorConfig {
|
|
|
28
28
|
readonly sampleIntervalMs: number;
|
|
29
29
|
/** Without a dedicated cgroup, a step this old is assumed to use its reserved memory. */
|
|
30
30
|
readonly memoryRampMs: number;
|
|
31
|
+
/**
|
|
32
|
+
* Decision 0014 operator ceilings, applied by every governor itself so they hold even
|
|
33
|
+
* without the bridge's runtime settings file (before its first write, after a failed
|
|
34
|
+
* write, or a file that can't be read): the lower of FORGE_HOST_CPU_BUDGET_PERCENT (as a
|
|
35
|
+
* fraction) and an explicitly set FORGE_HOST_LOAD_CPU_BUDGET_FRACTION, and
|
|
36
|
+
* FORGE_HOST_MAX_HEAVY_STEPS. Null when unset.
|
|
37
|
+
*/
|
|
38
|
+
readonly cpuBudgetCeilingFraction?: number | null;
|
|
39
|
+
readonly maxHeavyStepsCeiling?: number | null;
|
|
31
40
|
}
|
|
32
41
|
export declare const defaultHostLoadGovernorConfig: HostLoadGovernorConfig;
|
|
33
42
|
export declare function parseHostLoadGovernorMode(value: string | undefined): HostLoadGovernorMode;
|
|
@@ -36,8 +36,38 @@ export function loadHostLoadGovernorConfig(environment = process.env) {
|
|
|
36
36
|
sampleStaleMs: defaults.sampleStaleMs,
|
|
37
37
|
sampleIntervalMs: defaults.sampleIntervalMs,
|
|
38
38
|
memoryRampMs: defaults.memoryRampMs,
|
|
39
|
+
cpuBudgetCeilingFraction: lowestFraction(optionalCpuPercentFraction(environment.FORGE_HOST_CPU_BUDGET_PERCENT), optionalFraction(environment.FORGE_HOST_LOAD_CPU_BUDGET_FRACTION)),
|
|
40
|
+
maxHeavyStepsCeiling: optionalHeavySteps(environment.FORGE_HOST_MAX_HEAVY_STEPS),
|
|
39
41
|
};
|
|
40
42
|
}
|
|
43
|
+
/** Matches runner-settings' parse of FORGE_HOST_CPU_BUDGET_PERCENT (Number, 10-100); unparsable is unset. */
|
|
44
|
+
function optionalCpuPercentFraction(raw) {
|
|
45
|
+
if (raw === undefined || raw.trim() === "")
|
|
46
|
+
return null;
|
|
47
|
+
const value = Number(raw);
|
|
48
|
+
return Number.isFinite(value) ? Math.min(100, Math.max(10, value)) / 100 : null;
|
|
49
|
+
}
|
|
50
|
+
/** An explicitly set FORGE_HOST_LOAD_CPU_BUDGET_FRACTION is a ceiling too (runner-settings' cpuBudgetCeilings). */
|
|
51
|
+
function optionalFraction(raw) {
|
|
52
|
+
if (raw === undefined || raw.trim() === "")
|
|
53
|
+
return null;
|
|
54
|
+
const value = Number(raw);
|
|
55
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0.05, value)) : null;
|
|
56
|
+
}
|
|
57
|
+
function lowestFraction(a, b) {
|
|
58
|
+
if (a === null)
|
|
59
|
+
return b;
|
|
60
|
+
if (b === null)
|
|
61
|
+
return a;
|
|
62
|
+
return Math.min(a, b);
|
|
63
|
+
}
|
|
64
|
+
/** Matches runner-settings' parse of FORGE_HOST_MAX_HEAVY_STEPS (parseInt, 1-64); unparsable is unset. */
|
|
65
|
+
function optionalHeavySteps(raw) {
|
|
66
|
+
if (raw === undefined || raw.trim() === "")
|
|
67
|
+
return null;
|
|
68
|
+
const value = Number.parseInt(raw, 10);
|
|
69
|
+
return Number.isFinite(value) ? Math.min(64, Math.max(1, value)) : null;
|
|
70
|
+
}
|
|
41
71
|
function bounded(raw, fallback, minimum, maximum) {
|
|
42
72
|
if (raw === undefined || raw.trim() === "")
|
|
43
73
|
return fallback;
|
|
@@ -93,6 +93,8 @@ export declare class HostLoadGovernor implements HostLoadStepGate {
|
|
|
93
93
|
private drainAgain;
|
|
94
94
|
/** Own cgroup anonymous memory with no heavy step running: the bridge's baseline. */
|
|
95
95
|
private idleOwnMemoryBytes;
|
|
96
|
+
/** The bridge's pushed settings (decision 0014), shared with every governor on this state root. */
|
|
97
|
+
private readonly runtimeSettings;
|
|
96
98
|
constructor(options: HostLoadGovernorOptions);
|
|
97
99
|
get maxWaitMs(): number;
|
|
98
100
|
acquire(request: HostLoadStepRequest, options?: HostLoadAcquireOptions): Promise<HostLoadAdmission>;
|
|
@@ -4,6 +4,7 @@ import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
|
4
4
|
import { decideHostLoadAdmission, } from "./host-load-admission.js";
|
|
5
5
|
import { loadHostLoadGovernorConfig } from "./host-load-governor-config.js";
|
|
6
6
|
import { HostCapacityLedgerUnavailableError } from "./host-load-ledger-lock.js";
|
|
7
|
+
import { HostLoadRuntimeSettingsReader } from "./host-load-runtime-settings.js";
|
|
7
8
|
import { terminateHostLoadStepProcess } from "./host-load-step-reaper.js";
|
|
8
9
|
import { HostCapacityTokenFencedError, HostLoadTokenLedger, } from "./host-load-token-ledger.js";
|
|
9
10
|
export class HostCapacityTimeoutError extends ForgeFailureError {
|
|
@@ -39,10 +40,13 @@ export class HostLoadGovernor {
|
|
|
39
40
|
drainAgain = false;
|
|
40
41
|
/** Own cgroup anonymous memory with no heavy step running: the bridge's baseline. */
|
|
41
42
|
idleOwnMemoryBytes = null;
|
|
43
|
+
/** The bridge's pushed settings (decision 0014), shared with every governor on this state root. */
|
|
44
|
+
runtimeSettings;
|
|
42
45
|
constructor(options) {
|
|
43
46
|
this.options = options;
|
|
44
47
|
this.config = options.config ?? loadHostLoadGovernorConfig();
|
|
45
48
|
this.enabled = this.config.mode === "on";
|
|
49
|
+
this.runtimeSettings = new HostLoadRuntimeSettingsReader(options.stateRoot);
|
|
46
50
|
this.ledger = new HostLoadTokenLedger({
|
|
47
51
|
stateRoot: options.stateRoot,
|
|
48
52
|
leaseMs: this.config.leaseMs,
|
|
@@ -171,6 +175,15 @@ export class HostLoadGovernor {
|
|
|
171
175
|
return await this.draining;
|
|
172
176
|
}
|
|
173
177
|
async drainOnce() {
|
|
178
|
+
if (this.waiters.length === 0)
|
|
179
|
+
return;
|
|
180
|
+
// Decision 0014: the CPU budget (or yield budget) and the heavy-step limit the
|
|
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);
|
|
174
187
|
if (this.waiters.length === 0)
|
|
175
188
|
return;
|
|
176
189
|
const signals = this.readSignals();
|
|
@@ -190,7 +203,8 @@ export class HostLoadGovernor {
|
|
|
190
203
|
runningMemoryBytes,
|
|
191
204
|
logicalCpus,
|
|
192
205
|
signals,
|
|
193
|
-
config
|
|
206
|
+
config,
|
|
207
|
+
maxHeavySteps,
|
|
194
208
|
});
|
|
195
209
|
const decision = transaction.recoveringUntil
|
|
196
210
|
? {
|
|
@@ -517,3 +531,11 @@ function abortError(signal) {
|
|
|
517
531
|
error.name = "AbortError";
|
|
518
532
|
return error;
|
|
519
533
|
}
|
|
534
|
+
/** The lower of two optional limits; null when neither is set. */
|
|
535
|
+
function lowestLimit(a, b) {
|
|
536
|
+
if (a === null)
|
|
537
|
+
return b;
|
|
538
|
+
if (b === null)
|
|
539
|
+
return a;
|
|
540
|
+
return Math.min(a, b);
|
|
541
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface HostLoadRuntimeOverrides {
|
|
2
|
+
/** Share of logical CPUs heavy steps may reserve: the CPU budget, or the yield budget while yielding. */
|
|
3
|
+
readonly cpuBudgetFraction: number;
|
|
4
|
+
/** Host-wide count of heavy steps at once; null means the budget alone limits them. */
|
|
5
|
+
readonly maxHeavySteps: number | null;
|
|
6
|
+
/** For diagnostics: whether the budget above is the yield budget. */
|
|
7
|
+
readonly yielding: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function hostLoadRuntimeSettingsPath(stateRoot: string): string;
|
|
10
|
+
/** Atomically replaces the overrides every governor on this state root reads. */
|
|
11
|
+
export declare function writeHostLoadRuntimeSettings(stateRoot: string, overrides: HostLoadRuntimeOverrides): Promise<void>;
|
|
12
|
+
/** Bridge startup: drops overrides an earlier bridge process left behind. */
|
|
13
|
+
export declare function resetHostLoadRuntimeSettings(stateRoot: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Reads the overrides at admission time. The parsed file is cached by mtime and
|
|
16
|
+
* size, so a governor re-checking its queue every second costs one stat. A
|
|
17
|
+
* missing or unreadable file means no overrides.
|
|
18
|
+
*/
|
|
19
|
+
export declare class HostLoadRuntimeSettingsReader {
|
|
20
|
+
private readonly filePath;
|
|
21
|
+
private cachedKey;
|
|
22
|
+
private cached;
|
|
23
|
+
constructor(stateRoot: string);
|
|
24
|
+
read(): Promise<HostLoadRuntimeOverrides | null>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
export function hostLoadRuntimeSettingsPath(stateRoot) {
|
|
5
|
+
return path.join(stateRoot, "host-load-governor", "runner-settings.v1.json");
|
|
6
|
+
}
|
|
7
|
+
/** Atomically replaces the overrides every governor on this state root reads. */
|
|
8
|
+
export async function writeHostLoadRuntimeSettings(stateRoot, overrides) {
|
|
9
|
+
const filePath = hostLoadRuntimeSettingsPath(stateRoot);
|
|
10
|
+
const content = {
|
|
11
|
+
schemaVersion: 1,
|
|
12
|
+
cpuBudgetFraction: overrides.cpuBudgetFraction,
|
|
13
|
+
maxHeavySteps: overrides.maxHeavySteps,
|
|
14
|
+
yielding: overrides.yielding,
|
|
15
|
+
writtenAt: new Date().toISOString(),
|
|
16
|
+
writerPid: process.pid,
|
|
17
|
+
};
|
|
18
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
19
|
+
const temporary = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
20
|
+
try {
|
|
21
|
+
await fs.writeFile(temporary, `${JSON.stringify(content)}\n`, { mode: 0o600 });
|
|
22
|
+
await fs.rename(temporary, filePath);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
await fs.rm(temporary, { force: true }).catch(() => undefined);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Bridge startup: drops overrides an earlier bridge process left behind. */
|
|
30
|
+
export async function resetHostLoadRuntimeSettings(stateRoot) {
|
|
31
|
+
await fs.rm(hostLoadRuntimeSettingsPath(stateRoot), { force: true });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reads the overrides at admission time. The parsed file is cached by mtime and
|
|
35
|
+
* size, so a governor re-checking its queue every second costs one stat. A
|
|
36
|
+
* missing or unreadable file means no overrides.
|
|
37
|
+
*/
|
|
38
|
+
export class HostLoadRuntimeSettingsReader {
|
|
39
|
+
filePath;
|
|
40
|
+
cachedKey = null;
|
|
41
|
+
cached = null;
|
|
42
|
+
constructor(stateRoot) {
|
|
43
|
+
this.filePath = hostLoadRuntimeSettingsPath(stateRoot);
|
|
44
|
+
}
|
|
45
|
+
async read() {
|
|
46
|
+
let key;
|
|
47
|
+
try {
|
|
48
|
+
const stat = await fs.stat(this.filePath);
|
|
49
|
+
key = `${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}:${stat.ino}`;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
this.cachedKey = null;
|
|
53
|
+
this.cached = null;
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (key === this.cachedKey)
|
|
57
|
+
return this.cached;
|
|
58
|
+
const parsed = await fs.readFile(this.filePath, "utf8").then(parseOverrides).catch(() => null);
|
|
59
|
+
this.cachedKey = key;
|
|
60
|
+
this.cached = parsed;
|
|
61
|
+
return parsed;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function parseOverrides(content) {
|
|
65
|
+
const raw = JSON.parse(content);
|
|
66
|
+
if (!raw || raw.schemaVersion !== 1)
|
|
67
|
+
return null;
|
|
68
|
+
const fraction = raw.cpuBudgetFraction;
|
|
69
|
+
if (typeof fraction !== "number" || !Number.isFinite(fraction))
|
|
70
|
+
return null;
|
|
71
|
+
const steps = raw.maxHeavySteps;
|
|
72
|
+
return {
|
|
73
|
+
// The governor config's own bounds for the budget fraction.
|
|
74
|
+
cpuBudgetFraction: Math.min(1, Math.max(0.05, fraction)),
|
|
75
|
+
maxHeavySteps: typeof steps === "number" && Number.isInteger(steps) && steps >= 1 ? Math.min(64, steps) : null,
|
|
76
|
+
yielding: raw.yielding === true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -15,6 +15,7 @@ import { HostParallelPromotionStore } from "./host-runtime-promotion.js";
|
|
|
15
15
|
import { type HostProcessRecovery } from "../shared/process/host-process-recovery.js";
|
|
16
16
|
import { HostLoadGovernor } from "./host-load-governor.js";
|
|
17
17
|
import { type HostLoadGovernorSource } from "./host-load-sampler.js";
|
|
18
|
+
import type { RunnerHostDefaults } from "./runner-settings.js";
|
|
18
19
|
export interface HostRuntimeLeaseStart {
|
|
19
20
|
readonly lease: RuntimeIsolationLease;
|
|
20
21
|
readonly environment: Readonly<Record<string, string>>;
|
|
@@ -28,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
|
|
|
28
29
|
}
|
|
29
30
|
export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
|
|
30
31
|
export interface HostRuntimeProjectCheckpoint {
|
|
31
|
-
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned";
|
|
32
|
+
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned" | "host_runtime_contract_readmitted";
|
|
32
33
|
readonly message: string;
|
|
33
34
|
readonly data?: Readonly<Record<string, unknown>>;
|
|
34
35
|
}
|
|
@@ -96,10 +97,20 @@ export interface HostNodeRuntimeLaunch<T> extends NodeRuntimeAdapterLaunch<T> {
|
|
|
96
97
|
}
|
|
97
98
|
export interface HostRuntimeLeaseRuntime {
|
|
98
99
|
setRequirementsCheck?(check: HostRequirementsCheck | null): void;
|
|
100
|
+
/** Decision 0014: today's max attempts and memory reserve defaults, before env bounds. */
|
|
101
|
+
capacityLimitDefaults?(): RunnerHostDefaults;
|
|
102
|
+
/** Decision 0014: the effective max attempts and memory reserve, from the next attempt admission. */
|
|
103
|
+
applyCapacityLimits?(limits: HostCapacityLimits): void;
|
|
99
104
|
acquirePreparation?(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
100
105
|
acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
101
106
|
start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
102
107
|
startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
108
|
+
/**
|
|
109
|
+
* Stops the attempt's configured project processes, releases their ports, and
|
|
110
|
+
* starts them again (rebuilding when sources changed) so the stack serves the
|
|
111
|
+
* current workspace. Returns the environment with the newly assigned URLs.
|
|
112
|
+
*/
|
|
113
|
+
restartConfiguredProject?(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
103
114
|
updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
|
|
104
115
|
providerProcessRunner?(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
|
|
105
116
|
providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
|
|
@@ -147,7 +158,8 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
147
158
|
private workspaceAvailableBytes;
|
|
148
159
|
private readonly portBroker;
|
|
149
160
|
private readonly nodeAdapter;
|
|
150
|
-
|
|
161
|
+
/** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
|
|
162
|
+
private capacityConfiguration;
|
|
151
163
|
private readonly memoryAvailability;
|
|
152
164
|
private readonly executionRoot;
|
|
153
165
|
/** Host-wide admission for heavy steps (decision 0013); inert unless FORGE_HOST_LOAD_GOVERNOR=on. */
|
|
@@ -156,6 +168,15 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
156
168
|
/** Installs the decision 0013 accept-time requirements recheck for host attempts. */
|
|
157
169
|
setRequirementsCheck(check: HostRequirementsCheck | null): void;
|
|
158
170
|
constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery, capacityResourceSample?: HostCapacityResourceSample | undefined, executionRoot?: string, databaseBroker?: AttemptDatabaseBroker | null, hostLoad?: HostLoadGovernorSource | null);
|
|
171
|
+
/** Today's defaults for the limits the server can push, before any env bound (decision 0014). */
|
|
172
|
+
capacityLimitDefaults(): RunnerHostDefaults;
|
|
173
|
+
/**
|
|
174
|
+
* Decision 0014: the bridge's effective max attempts and memory reserve. They
|
|
175
|
+
* apply from the next attempt admission; admitted attempts keep their
|
|
176
|
+
* reservations and are never preempted, even when the new limit is lower than
|
|
177
|
+
* what already runs. The idle reserve follows the reserve as at startup.
|
|
178
|
+
*/
|
|
179
|
+
applyCapacityLimits(limits: HostCapacityLimits): void;
|
|
159
180
|
hostLoadChildEnvironment(): Readonly<Record<string, string>>;
|
|
160
181
|
reap(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
|
|
161
182
|
snapshot(): HostRuntimeCapacitySnapshot;
|
|
@@ -178,6 +199,24 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
178
199
|
start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
179
200
|
updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
|
|
180
201
|
startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
202
|
+
/**
|
|
203
|
+
* Launches the configured project. Only the first launch, from the admitted commit's clean
|
|
204
|
+
* source, may record parallel-safety proof: a restart serves the workspace after the provider
|
|
205
|
+
* edited it, and a proof observed there would be stored under the admitted commit and could
|
|
206
|
+
* move this or a later attempt at that commit into shared admission for source it never ran.
|
|
207
|
+
*/
|
|
208
|
+
private launchConfiguredProject;
|
|
209
|
+
/**
|
|
210
|
+
* Relaunches the configured project so it serves the current workspace. Every
|
|
211
|
+
* configured process stops (the API port changes, so the dev server's proxy target
|
|
212
|
+
* must change with it), its port reservation is released and dropped from the
|
|
213
|
+
* persisted lease, and the regular start path runs again, including the ASP.NET
|
|
214
|
+
* prebuild, whose receipt rebuilds only when the sources changed.
|
|
215
|
+
*/
|
|
216
|
+
restartConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
|
|
217
|
+
private runConfiguredProjectRestart;
|
|
218
|
+
/** Stops configured project processes in reverse launch order and releases their ports. */
|
|
219
|
+
private stopConfiguredProject;
|
|
181
220
|
providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
|
|
182
221
|
private markCapacityReservationRunning;
|
|
183
222
|
providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
|
|
@@ -228,4 +267,21 @@ export declare class HostRuntimeCapacityRequestImpossibleError extends Error {
|
|
|
228
267
|
}
|
|
229
268
|
export declare function hostRuntimeEventResources(lease: RuntimeIsolationLease, runtimeContract?: LoadedHostRuntimeContract, executionClass?: HostRuntimeExecutionClass): Record<string, unknown>;
|
|
230
269
|
export declare function hostRuntimeSingletonKeys(dispatch: RunOnceDispatchPacket): readonly string[];
|
|
270
|
+
/**
|
|
271
|
+
* Every environment key `hostRuntimeEnvironment` and the Playwright overlay derive from the
|
|
272
|
+
* configured project's assigned ports. They name a live stack, so they are withheld while the
|
|
273
|
+
* stack is down: after its ports are released another attempt may be assigned them.
|
|
274
|
+
*/
|
|
275
|
+
export declare function hostRuntimeStackEnvironmentKeys(runtimeContract: LoadedHostRuntimeContract): readonly string[];
|
|
231
276
|
export declare function runtimeAdmissionPriority(dispatch: RunOnceDispatchPacket): HostRuntimeAdmissionPriority;
|
|
277
|
+
/** The pushed attempt limits (decision 0014), already resolved against host env bounds. */
|
|
278
|
+
export interface HostCapacityLimits {
|
|
279
|
+
readonly maxConcurrentAttempts: number;
|
|
280
|
+
readonly memoryReserveBytes: number;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Today's max attempts and adaptive memory reserve for this host, before
|
|
284
|
+
* FORGE_HOST_MAX_CONCURRENT_ATTEMPTS and FORGE_HOST_MEMORY_RESERVE_BYTES
|
|
285
|
+
* (decision 0014 treats those as bounds on the server's values).
|
|
286
|
+
*/
|
|
287
|
+
export declare function hostCapacityLimitDefaults(capacityResourceSample?: HostCapacityResourceSample): RunnerHostDefaults;
|