@loucompanion/forge-bridge 0.1.4-dev.bbb61d3d6127 → 0.1.4-dev.bd2cfb6b7438
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 +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +71 -2
- package/dist/bridge/bridge.service.js +292 -118
- 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/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +140 -16
- 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/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- 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 +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +41 -0
- package/dist/runtime/host-load-forge-cgroups.js +93 -4
- 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 +72 -11
- package/dist/runtime/host-load-governor.js +284 -67
- 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 +39 -4
- package/dist/runtime/host-load-sampler.js +83 -9
- package/dist/runtime/host-load-step-class.d.ts +37 -0
- package/dist/runtime/host-load-step-class.js +117 -2
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- 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 +82 -17
- package/dist/runtime/host-load-token-ledger.js +187 -79
- 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 +62 -3
- package/dist/runtime/host-runtime-lease.js +258 -13
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- 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 +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +200 -92
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +50 -20
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.js +31 -16
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +211 -134
- 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 +38 -339
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +50 -10
- 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 +93 -162
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -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/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +7 -2
- package/dist/session/session.service.js +115 -5
- package/dist/session/session.types.js +4 -4
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- 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/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { resolveLocalConfigPath } from "../cli/local-config.js";
|
|
4
|
+
import { DockerEngineProbe } from "./docker-engine-probe.js";
|
|
5
|
+
import { ephemeralTestPostgresClusterEnvironment } from "./ephemeral-test-postgres.js";
|
|
4
6
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "./host-runtime-contract.js";
|
|
5
7
|
export const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE_TEST_POSTGRES_CONFIG";
|
|
6
8
|
export const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
|
|
7
9
|
export const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
|
|
10
|
+
/**
|
|
11
|
+
* The cluster serves the shared test server while Docker is up, so tests that need a
|
|
12
|
+
* pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
|
|
13
|
+
* first, which keeps test databases out of the Docker VM and saves RAM.
|
|
14
|
+
*/
|
|
15
|
+
export const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
|
|
16
|
+
const nativeTestPostgresUses = ["preferred", "docker_unavailable", "ephemeral"];
|
|
8
17
|
const defaultPostgresPort = 5432;
|
|
9
18
|
const loopbackHosts = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
19
|
+
/**
|
|
20
|
+
* The provisioned cluster's grant for a check that can use it, or null to use Docker. A
|
|
21
|
+
* preferred cluster is granted whether or not Docker is up; the mode says which, because
|
|
22
|
+
* only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
|
|
23
|
+
* normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
|
|
24
|
+
* start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
|
|
25
|
+
*/
|
|
26
|
+
export function nativeTestPostgresGrant(fallback, dockerAvailable) {
|
|
27
|
+
if (!fallback || (dockerAvailable && fallback.use !== "preferred"))
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
connectionString: fallback.connectionString,
|
|
31
|
+
endpoint: fallback.endpoint,
|
|
32
|
+
mode: dockerAvailable ? nativeTestPostgresPreferredDatabaseMode : nativeTestPostgresFallbackDatabaseMode,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
10
35
|
export class NativeTestPostgresFallbackError extends Error {
|
|
11
36
|
code = "native_test_postgres_fallback_invalid";
|
|
12
37
|
constructor(detail) {
|
|
@@ -46,9 +71,17 @@ export function readNativeTestPostgresFallback(configPath = resolveNativeTestPos
|
|
|
46
71
|
if (document.schemaVersion !== 1 || typeof document.connectionString !== "string") {
|
|
47
72
|
throw new NativeTestPostgresFallbackError(`${configPath} must contain schemaVersion 1 and a connectionString.`);
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
if (document.use !== undefined && !nativeTestPostgresUses.includes(document.use)) {
|
|
75
|
+
throw new NativeTestPostgresFallbackError(`${configPath} 'use' must be 'preferred', 'docker_unavailable' or 'ephemeral'.`);
|
|
76
|
+
}
|
|
77
|
+
if (document.postgresBin !== undefined
|
|
78
|
+
&& (typeof document.postgresBin !== "string" || !path.isAbsolute(document.postgresBin))) {
|
|
79
|
+
throw new NativeTestPostgresFallbackError(`${configPath} 'postgresBin' must be an absolute path.`);
|
|
80
|
+
}
|
|
81
|
+
const fallback = parseNativeTestPostgresFallback(document.connectionString, document.use ?? "preferred");
|
|
82
|
+
return typeof document.postgresBin === "string" ? { ...fallback, postgresBin: document.postgresBin } : fallback;
|
|
50
83
|
}
|
|
51
|
-
export function parseNativeTestPostgresFallback(connectionString) {
|
|
84
|
+
export function parseNativeTestPostgresFallback(connectionString, use = "preferred") {
|
|
52
85
|
const fields = new Map();
|
|
53
86
|
for (const segment of connectionString.split(";")) {
|
|
54
87
|
const separator = segment.indexOf("=");
|
|
@@ -79,13 +112,32 @@ export function parseNativeTestPostgresFallback(connectionString) {
|
|
|
79
112
|
if (!(fields.get("username") ?? fields.get("userid") ?? fields.get("user"))) {
|
|
80
113
|
throw new NativeTestPostgresFallbackError("the fallback must name a dedicated test role.");
|
|
81
114
|
}
|
|
82
|
-
return { connectionString: connectionString.trim(), endpoint: `${host}:${port}
|
|
115
|
+
return { connectionString: connectionString.trim(), endpoint: `${host}:${port}`, use };
|
|
83
116
|
}
|
|
84
|
-
/** Environment for one runner-authored .NET test process using the
|
|
85
|
-
export function nativeTestPostgresFallbackEnvironment(
|
|
117
|
+
/** Environment for one runner-authored .NET test process using the cluster. */
|
|
118
|
+
export function nativeTestPostgresFallbackEnvironment(grant) {
|
|
86
119
|
return {
|
|
87
|
-
[hostRuntimeTestPostgresAdminEnvironment]:
|
|
88
|
-
[hostRuntimeLegacyTestPostgresEnvironment]:
|
|
89
|
-
FORGE_MANAGED_VERIFICATION_DATABASE_MODE:
|
|
120
|
+
[hostRuntimeTestPostgresAdminEnvironment]: grant.connectionString,
|
|
121
|
+
[hostRuntimeLegacyTestPostgresEnvironment]: grant.connectionString,
|
|
122
|
+
FORGE_MANAGED_VERIFICATION_DATABASE_MODE: grant.mode,
|
|
123
|
+
// The fixtures accept a superuser login only on the cluster that reports this id.
|
|
124
|
+
...(grant.ephemeralClusterId ? { [ephemeralTestPostgresClusterEnvironment]: grant.ephemeralClusterId } : {}),
|
|
90
125
|
};
|
|
91
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Runner-authored verification uses the operator-provisioned native test cluster,
|
|
129
|
+
* which holds no real data, whenever its file prefers it (the default); Docker then
|
|
130
|
+
* only starts pinned-engine containers. A `docker_unavailable` cluster is used only
|
|
131
|
+
* when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
|
|
132
|
+
* database serves.
|
|
133
|
+
*/
|
|
134
|
+
export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().probeWithoutRecovery()).available, readFallback = () => {
|
|
135
|
+
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
136
|
+
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
137
|
+
}) {
|
|
138
|
+
const fallback = readFallback();
|
|
139
|
+
if (!fallback)
|
|
140
|
+
return {};
|
|
141
|
+
const grant = nativeTestPostgresGrant(fallback, await dockerAvailable());
|
|
142
|
+
return grant ? nativeTestPostgresFallbackEnvironment(grant) : {};
|
|
143
|
+
}
|
|
@@ -28,5 +28,12 @@ export declare class PlaywrightHostRuntimeAdapter {
|
|
|
28
28
|
*/
|
|
29
29
|
assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
|
|
30
30
|
private readyBrowserCache;
|
|
31
|
+
/**
|
|
32
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
33
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
34
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
35
|
+
* The next `prepare` writes a fresh one.
|
|
36
|
+
*/
|
|
37
|
+
discardOverlay(temporaryDirectory: string): Promise<void>;
|
|
31
38
|
prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
|
|
32
39
|
}
|
|
@@ -35,6 +35,17 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
35
35
|
}
|
|
36
36
|
return { cache: resolution.cache, installCommand };
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the generated config, which names the base URL of the stack it was prepared for. A
|
|
40
|
+
* stopped stack's config must not survive: its port may be reassigned to another attempt, and a
|
|
41
|
+
* provider that remembers the config's path would otherwise run Playwright against that port.
|
|
42
|
+
* The next `prepare` writes a fresh one.
|
|
43
|
+
*/
|
|
44
|
+
async discardOverlay(temporaryDirectory) {
|
|
45
|
+
if (!await assertCanonicalDirectory(temporaryDirectory, true))
|
|
46
|
+
return;
|
|
47
|
+
await fs.rm(path.join(path.resolve(temporaryDirectory), playwrightOverlayFileName), { force: true });
|
|
48
|
+
}
|
|
38
49
|
async prepare(config, context) {
|
|
39
50
|
const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
|
|
40
51
|
const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
|
|
@@ -62,7 +73,7 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
62
73
|
if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
|
|
63
74
|
throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
|
|
64
75
|
}
|
|
65
|
-
const overlayPath = path.join(temporaryDirectory,
|
|
76
|
+
const overlayPath = path.join(temporaryDirectory, playwrightOverlayFileName);
|
|
66
77
|
const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
|
|
67
78
|
const browserCache = readyCache
|
|
68
79
|
? { path: readyCache, ready: true }
|
|
@@ -135,6 +146,7 @@ async function ensureAttemptWritableDirectories(targets, realWorktree) {
|
|
|
135
146
|
for (const target of resolvedTargets)
|
|
136
147
|
await createPrivateCanonicalDirectory(target);
|
|
137
148
|
}
|
|
149
|
+
const playwrightOverlayFileName = "forge.playwright.config.mjs";
|
|
138
150
|
async function writeAttemptOverlay(target, content) {
|
|
139
151
|
const parent = path.dirname(target);
|
|
140
152
|
const identity = await assertCanonicalDirectory(parent);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type HostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
2
|
+
export declare const runnerSettingKeys: readonly ["maxConcurrentAttempts", "cpuBudgetPercent", "yieldCpuBudgetPercent", "memoryReserveBytes", "maxHeavySteps", "yieldToForeground"];
|
|
3
|
+
export type RunnerSettingKey = typeof runnerSettingKeys[number];
|
|
4
|
+
/** The `ApplySettings` hub message. Null numeric fields mean "no server value": keep today's env/default behaviour. */
|
|
5
|
+
export interface RunnerSettingsDocument {
|
|
6
|
+
readonly runnerId: string | null;
|
|
7
|
+
readonly version: number;
|
|
8
|
+
readonly maxConcurrentAttempts: number | null;
|
|
9
|
+
readonly cpuBudgetPercent: number | null;
|
|
10
|
+
readonly yieldCpuBudgetPercent: number | null;
|
|
11
|
+
readonly memoryReserveBytes: number | null;
|
|
12
|
+
readonly maxHeavySteps: number | null;
|
|
13
|
+
readonly yieldToForeground: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RunnerSettingsValues {
|
|
16
|
+
readonly maxConcurrentAttempts: number;
|
|
17
|
+
readonly cpuBudgetPercent: number;
|
|
18
|
+
readonly yieldCpuBudgetPercent: number;
|
|
19
|
+
readonly memoryReserveBytes: number;
|
|
20
|
+
/** Null: the governor's budget alone limits heavy steps (no count limit). */
|
|
21
|
+
readonly maxHeavySteps: number | null;
|
|
22
|
+
readonly yieldToForeground: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where an effective value came from: the server's value as is, the bridge default,
|
|
26
|
+
* an env var that capped/floored the server value or supplied it, or the host's
|
|
27
|
+
* `forge-bridge yield on` flag.
|
|
28
|
+
*/
|
|
29
|
+
export type RunnerSettingSource = "server" | "default" | "host_env" | "host_local";
|
|
30
|
+
export interface RunnerSettingBound {
|
|
31
|
+
readonly key: RunnerSettingKey;
|
|
32
|
+
readonly envVar: string;
|
|
33
|
+
readonly value: number;
|
|
34
|
+
readonly kind: "ceiling" | "floor";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Why a key was rejected. `invalid`: the server value is outside the contract, so
|
|
38
|
+
* the host default applies (version skew; it never holds placement). `apply_failed`:
|
|
39
|
+
* the host could not put the value in force, so the previous value stays in force
|
|
40
|
+
* and the server holds placement until a later apply succeeds. Clamping by an env
|
|
41
|
+
* bound is neither: it is a `bound` and a `host_env` source.
|
|
42
|
+
*/
|
|
43
|
+
export type RunnerSettingRejectionKind = "invalid" | "apply_failed";
|
|
44
|
+
export interface RunnerSettingRejection {
|
|
45
|
+
readonly key: RunnerSettingKey;
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
readonly kind: RunnerSettingRejectionKind;
|
|
48
|
+
}
|
|
49
|
+
/** The `SettingsApplied` report; also carried in the capabilities `settings` block (schema 8). */
|
|
50
|
+
export interface RunnerSettingsReport {
|
|
51
|
+
/** The applied document version, or null before any ApplySettings was applied. */
|
|
52
|
+
readonly version: number | null;
|
|
53
|
+
/** FORGE_HOST_LOAD_GOVERNOR: CPU budget, yield budget and heavy steps only take effect when on. */
|
|
54
|
+
readonly governor: HostLoadGovernorMode;
|
|
55
|
+
readonly values: RunnerSettingsValues;
|
|
56
|
+
readonly sources: Readonly<Record<RunnerSettingKey, RunnerSettingSource>>;
|
|
57
|
+
readonly bounds: readonly RunnerSettingBound[];
|
|
58
|
+
readonly rejected: readonly RunnerSettingRejection[];
|
|
59
|
+
}
|
|
60
|
+
/** Today's bridge defaults for the keys whose default depends on the host. */
|
|
61
|
+
export interface RunnerHostDefaults {
|
|
62
|
+
/** floor(threads / 2) capped at 8 (at least 1). */
|
|
63
|
+
readonly maxConcurrentAttempts: number;
|
|
64
|
+
/** The adaptive reserve: 12.5% of RAM within 1–4 GiB, before FORGE_HOST_MEMORY_RESERVE_BYTES. */
|
|
65
|
+
readonly memoryReserveBytes: number;
|
|
66
|
+
}
|
|
67
|
+
export interface EffectiveRunnerSettings {
|
|
68
|
+
readonly report: RunnerSettingsReport;
|
|
69
|
+
/** Effective yield (server OR local flag). */
|
|
70
|
+
readonly yielding: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The governor CPU budget in force, as a fraction of logical CPUs: the CPU budget,
|
|
73
|
+
* or min(yield budget, CPU budget) while yielding.
|
|
74
|
+
*/
|
|
75
|
+
readonly governorCpuBudgetFraction: number;
|
|
76
|
+
}
|
|
77
|
+
export declare const defaultCpuBudgetPercent = 80;
|
|
78
|
+
export declare const defaultYieldCpuBudgetPercent = 50;
|
|
79
|
+
/**
|
|
80
|
+
* Computes every effective value (decision 0014 precedence):
|
|
81
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
82
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
83
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
84
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeEffectiveRunnerSettings(document: RunnerSettingsDocument | null, environment: Readonly<Record<string, string | undefined>>, hostDefaults: RunnerHostDefaults, localYield: boolean): EffectiveRunnerSettings;
|
|
87
|
+
/**
|
|
88
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
89
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseRunnerSettingsDocument(raw: unknown): RunnerSettingsDocument | null;
|
|
92
|
+
/**
|
|
93
|
+
* The report for what is actually in force after an apply in which the host
|
|
94
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
95
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
96
|
+
* rejection, so the server never reads a desired value as applied.
|
|
97
|
+
*/
|
|
98
|
+
export declare function runnerSettingsInForce(report: RunnerSettingsReport, previous: RunnerSettingsReport, failures: readonly RunnerSettingRejection[]): RunnerSettingsReport;
|
|
99
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
100
|
+
export declare function sameRunnerSettingsReport(left: RunnerSettingsReport, right: RunnerSettingsReport): boolean;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { parseHostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
2
|
+
// Decision 0014 §3 "Precedence" and §6 "Bridge hub": the server pushes a runner
|
|
3
|
+
// settings document (`ApplySettings`) and is the source of truth. Host env vars
|
|
4
|
+
// are one-sided safety bounds only: a ceiling on capacity, a floor on reserves.
|
|
5
|
+
// The bridge reports the effective values, their sources and every env bound it
|
|
6
|
+
// saw back to the server (`SettingsApplied`), so a host bound is never silent.
|
|
7
|
+
// Nothing here is persisted to bridge.json (0014 agent constraint).
|
|
8
|
+
export const runnerSettingKeys = [
|
|
9
|
+
"maxConcurrentAttempts",
|
|
10
|
+
"cpuBudgetPercent",
|
|
11
|
+
"yieldCpuBudgetPercent",
|
|
12
|
+
"memoryReserveBytes",
|
|
13
|
+
"maxHeavySteps",
|
|
14
|
+
"yieldToForeground",
|
|
15
|
+
];
|
|
16
|
+
export const defaultCpuBudgetPercent = 80;
|
|
17
|
+
export const defaultYieldCpuBudgetPercent = 50;
|
|
18
|
+
const MiB = 1024 ** 2;
|
|
19
|
+
const GiB = 1024 ** 3;
|
|
20
|
+
/** The server's ranges (contract); a value outside them is rejected, not clamped, so it is never silent. */
|
|
21
|
+
const serverRanges = {
|
|
22
|
+
maxConcurrentAttempts: { min: 1, max: 32 },
|
|
23
|
+
cpuBudgetPercent: { min: 10, max: 100 },
|
|
24
|
+
yieldCpuBudgetPercent: { min: 10, max: 100 },
|
|
25
|
+
memoryReserveBytes: { min: 512 * MiB, max: 128 * GiB },
|
|
26
|
+
maxHeavySteps: { min: 1, max: 64 },
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Computes every effective value (decision 0014 precedence):
|
|
30
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
31
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
32
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
33
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
34
|
+
*/
|
|
35
|
+
export function computeEffectiveRunnerSettings(document, environment, hostDefaults, localYield) {
|
|
36
|
+
const rejected = [];
|
|
37
|
+
const server = (key) => {
|
|
38
|
+
const value = document?.[key] ?? null;
|
|
39
|
+
if (value === null)
|
|
40
|
+
return null;
|
|
41
|
+
const range = serverRanges[key];
|
|
42
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
43
|
+
rejected.push({ key, reason: `${String(value)} is not a whole number; the host default applies.`, kind: "invalid" });
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (value < range.min || value > range.max) {
|
|
47
|
+
rejected.push({ key, reason: `${value} is outside ${range.min}-${range.max}; the host default applies.`, kind: "invalid" });
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
const attemptsCeiling = integerEnv(environment, "FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", 1, 32);
|
|
53
|
+
const cpuCeilings = cpuBudgetCeilings(environment);
|
|
54
|
+
const reserveFloor = integerEnv(environment, "FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * MiB, 128 * GiB);
|
|
55
|
+
const heavyStepsCeiling = integerEnv(environment, "FORGE_HOST_MAX_HEAVY_STEPS", 1, 64);
|
|
56
|
+
const attempts = ceilingValue(server("maxConcurrentAttempts"), lowest(attemptsCeiling), hostDefaults.maxConcurrentAttempts);
|
|
57
|
+
const cpu = ceilingValue(server("cpuBudgetPercent"), lowest(...cpuCeilings), defaultCpuBudgetPercent);
|
|
58
|
+
// The yield budget's ceilings are the CPU budget's. Without a server value they
|
|
59
|
+
// cap its default rather than replace it: a host allowing 90% CPU must not raise
|
|
60
|
+
// the 50% yield default, which no env var sets today.
|
|
61
|
+
const serverYieldCpu = server("yieldCpuBudgetPercent");
|
|
62
|
+
const yieldCpu = ceilingValue(serverYieldCpu ?? defaultYieldCpuBudgetPercent, lowest(...cpuCeilings), defaultYieldCpuBudgetPercent);
|
|
63
|
+
const yieldCpuSource = serverYieldCpu === null && yieldCpu.source === "server" ? "default" : yieldCpu.source;
|
|
64
|
+
const reserve = floorValue(server("memoryReserveBytes"), reserveFloor?.value ?? null, hostDefaults.memoryReserveBytes);
|
|
65
|
+
const heavySteps = ceilingValue(server("maxHeavySteps"), lowest(heavyStepsCeiling), null);
|
|
66
|
+
const serverYield = document?.yieldToForeground === true;
|
|
67
|
+
const yielding = serverYield || localYield;
|
|
68
|
+
// The host's own switch wins the label: turning the server toggle off would not stop it.
|
|
69
|
+
const yieldSource = localYield ? "host_local" : serverYield ? "server" : "default";
|
|
70
|
+
const bounds = [];
|
|
71
|
+
const addCeilings = (key, set) => {
|
|
72
|
+
for (const bound of set)
|
|
73
|
+
if (bound)
|
|
74
|
+
bounds.push({ key, envVar: bound.envVar, value: bound.value, kind: "ceiling" });
|
|
75
|
+
};
|
|
76
|
+
addCeilings("maxConcurrentAttempts", [attemptsCeiling]);
|
|
77
|
+
addCeilings("cpuBudgetPercent", cpuCeilings);
|
|
78
|
+
addCeilings("yieldCpuBudgetPercent", cpuCeilings);
|
|
79
|
+
if (reserveFloor)
|
|
80
|
+
bounds.push({ key: "memoryReserveBytes", envVar: reserveFloor.envVar, value: reserveFloor.value, kind: "floor" });
|
|
81
|
+
addCeilings("maxHeavySteps", [heavyStepsCeiling]);
|
|
82
|
+
const values = {
|
|
83
|
+
maxConcurrentAttempts: attempts.value,
|
|
84
|
+
cpuBudgetPercent: cpu.value,
|
|
85
|
+
yieldCpuBudgetPercent: yieldCpu.value,
|
|
86
|
+
memoryReserveBytes: reserve.value,
|
|
87
|
+
maxHeavySteps: heavySteps.value,
|
|
88
|
+
yieldToForeground: yielding,
|
|
89
|
+
};
|
|
90
|
+
const budgetPercent = yielding ? Math.min(values.yieldCpuBudgetPercent, values.cpuBudgetPercent) : values.cpuBudgetPercent;
|
|
91
|
+
return {
|
|
92
|
+
report: {
|
|
93
|
+
version: null,
|
|
94
|
+
governor: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
|
|
95
|
+
values,
|
|
96
|
+
sources: {
|
|
97
|
+
maxConcurrentAttempts: attempts.source,
|
|
98
|
+
cpuBudgetPercent: cpu.source,
|
|
99
|
+
yieldCpuBudgetPercent: yieldCpuSource,
|
|
100
|
+
memoryReserveBytes: reserve.source,
|
|
101
|
+
maxHeavySteps: heavySteps.source,
|
|
102
|
+
yieldToForeground: yieldSource,
|
|
103
|
+
},
|
|
104
|
+
bounds,
|
|
105
|
+
rejected,
|
|
106
|
+
},
|
|
107
|
+
yielding,
|
|
108
|
+
governorCpuBudgetFraction: budgetPercent / 100,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
113
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
114
|
+
*/
|
|
115
|
+
export function parseRunnerSettingsDocument(raw) {
|
|
116
|
+
if (!raw || typeof raw !== "object")
|
|
117
|
+
return null;
|
|
118
|
+
const record = raw;
|
|
119
|
+
const version = record.version;
|
|
120
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0)
|
|
121
|
+
return null;
|
|
122
|
+
const numeric = (key) => {
|
|
123
|
+
const value = record[key];
|
|
124
|
+
// Kept as-is (even out of range) so computeEffectiveRunnerSettings can report it as rejected.
|
|
125
|
+
return typeof value === "number" ? value : null;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
runnerId: typeof record.runnerId === "string" ? record.runnerId : null,
|
|
129
|
+
version,
|
|
130
|
+
maxConcurrentAttempts: numeric("maxConcurrentAttempts"),
|
|
131
|
+
cpuBudgetPercent: numeric("cpuBudgetPercent"),
|
|
132
|
+
yieldCpuBudgetPercent: numeric("yieldCpuBudgetPercent"),
|
|
133
|
+
memoryReserveBytes: numeric("memoryReserveBytes"),
|
|
134
|
+
maxHeavySteps: numeric("maxHeavySteps"),
|
|
135
|
+
yieldToForeground: record.yieldToForeground === true,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The report for what is actually in force after an apply in which the host
|
|
140
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
141
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
142
|
+
* rejection, so the server never reads a desired value as applied.
|
|
143
|
+
*/
|
|
144
|
+
export function runnerSettingsInForce(report, previous, failures) {
|
|
145
|
+
if (failures.length === 0)
|
|
146
|
+
return report;
|
|
147
|
+
const values = { ...report.values };
|
|
148
|
+
const sources = { ...report.sources };
|
|
149
|
+
for (const failure of failures) {
|
|
150
|
+
keepPrevious(values, previous.values, failure.key);
|
|
151
|
+
sources[failure.key] = previous.sources[failure.key];
|
|
152
|
+
}
|
|
153
|
+
return { ...report, values, sources, rejected: [...report.rejected, ...failures] };
|
|
154
|
+
}
|
|
155
|
+
function keepPrevious(target, previous, key) {
|
|
156
|
+
target[key] = previous[key];
|
|
157
|
+
}
|
|
158
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
159
|
+
export function sameRunnerSettingsReport(left, right) {
|
|
160
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
161
|
+
}
|
|
162
|
+
function ceilingValue(server, ceiling, fallback) {
|
|
163
|
+
if (server !== null) {
|
|
164
|
+
return ceiling && ceiling.value < server
|
|
165
|
+
? { value: ceiling.value, source: "host_env" }
|
|
166
|
+
: { value: server, source: "server" };
|
|
167
|
+
}
|
|
168
|
+
return ceiling ? { value: ceiling.value, source: "host_env" } : { value: fallback, source: "default" };
|
|
169
|
+
}
|
|
170
|
+
function floorValue(server, floor, fallback) {
|
|
171
|
+
if (server !== null) {
|
|
172
|
+
return floor !== null && floor > server
|
|
173
|
+
? { value: floor, source: "host_env" }
|
|
174
|
+
: { value: server, source: "server" };
|
|
175
|
+
}
|
|
176
|
+
return floor !== null ? { value: floor, source: "host_env" } : { value: fallback, source: "default" };
|
|
177
|
+
}
|
|
178
|
+
function lowest(...bounds) {
|
|
179
|
+
let result = null;
|
|
180
|
+
for (const bound of bounds) {
|
|
181
|
+
if (bound && (result === null || bound.value < result.value))
|
|
182
|
+
result = bound;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Both CPU ceilings: the new FORGE_HOST_CPU_BUDGET_PERCENT (10–100) and the
|
|
188
|
+
* existing FORGE_HOST_LOAD_CPU_BUDGET_FRACTION (0.05–1, the governor's own
|
|
189
|
+
* parse), reported as a percent.
|
|
190
|
+
*/
|
|
191
|
+
function cpuBudgetCeilings(environment) {
|
|
192
|
+
const percent = numberEnv(environment, "FORGE_HOST_CPU_BUDGET_PERCENT", 10, 100);
|
|
193
|
+
const fraction = numberEnv(environment, "FORGE_HOST_LOAD_CPU_BUDGET_FRACTION", 0.05, 1);
|
|
194
|
+
return [
|
|
195
|
+
percent,
|
|
196
|
+
fraction ? { envVar: fraction.envVar, value: Math.round(fraction.value * 10_000) / 100 } : null,
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
/** Matches the lease manager's parse (parseInt, clamped); an unparsable value counts as unset. */
|
|
200
|
+
function integerEnv(environment, envVar, minimum, maximum) {
|
|
201
|
+
const raw = environment[envVar];
|
|
202
|
+
if (raw === undefined || raw.trim() === "")
|
|
203
|
+
return null;
|
|
204
|
+
const parsed = Number.parseInt(raw, 10);
|
|
205
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.max(minimum, Math.min(maximum, parsed)) } : null;
|
|
206
|
+
}
|
|
207
|
+
/** Matches the governor config's parse (Number, clamped); an unparsable value counts as unset. */
|
|
208
|
+
function numberEnv(environment, envVar, minimum, maximum) {
|
|
209
|
+
const raw = environment[envVar];
|
|
210
|
+
if (raw === undefined || raw.trim() === "")
|
|
211
|
+
return null;
|
|
212
|
+
const parsed = Number(raw);
|
|
213
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.min(maximum, Math.max(minimum, parsed)) } : null;
|
|
214
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
2
|
+
import type { HostLoadStepProcess } from "../runtime/host-load-step-reaper.js";
|
|
3
|
+
import type { HostLoadTokenPriority } from "../runtime/host-load-token-ledger.js";
|
|
4
|
+
export declare const sandboxHostCapacityBrokerEnvironment = "FORGE_HOST_LOAD_BROKER";
|
|
5
|
+
export declare const sandboxHostCapacityBrokerProtocol = "stdout-v1";
|
|
6
|
+
export declare const sandboxHostCapacityLineType = "forge_host_capacity";
|
|
7
|
+
export declare const sandboxHostCapacityResponseRoot = "/run/forge/host-capacity";
|
|
8
|
+
/** Owner of authentic replies inside the container: root, via `docker exec --user 0`. */
|
|
9
|
+
export declare const sandboxHostCapacityResponseOwnerUid = 0;
|
|
10
|
+
export declare const sandboxHostCapacityMaxWaitEnvironment = "FORGE_HOST_LOAD_BROKER_MAX_WAIT_MS";
|
|
11
|
+
export interface SandboxHostCapacityRequest {
|
|
12
|
+
readonly action: "acquire" | "release" | "retain";
|
|
13
|
+
readonly requestId: string;
|
|
14
|
+
readonly stepClass: string;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SandboxHostCapacityResponse {
|
|
18
|
+
readonly requestId: string;
|
|
19
|
+
/** Rises with every reply the broker sends; the container keeps only the newest. */
|
|
20
|
+
readonly sequence: number;
|
|
21
|
+
readonly status: "waiting" | "admitted" | "failed" | "fenced";
|
|
22
|
+
readonly waitMs?: number;
|
|
23
|
+
readonly reason?: string;
|
|
24
|
+
readonly detail?: string;
|
|
25
|
+
readonly code?: string;
|
|
26
|
+
readonly message?: string;
|
|
27
|
+
}
|
|
28
|
+
export type SandboxHostCapacityDelivery = (response: SandboxHostCapacityResponse) => Promise<void>;
|
|
29
|
+
/** Parses one stdout line; null when it is not a well-formed broker request. */
|
|
30
|
+
export declare function parseSandboxHostCapacityRequest(line: string): SandboxHostCapacityRequest | null;
|
|
31
|
+
export interface SandboxHostCapacityBrokerOptions {
|
|
32
|
+
/** Requests (acquire or release) one sandbox may hold or start at once. */
|
|
33
|
+
readonly maximumOutstanding?: number;
|
|
34
|
+
/** Request lines allowed in a burst, and their sustained rate. */
|
|
35
|
+
readonly burst?: number;
|
|
36
|
+
readonly refillPerSecond?: number;
|
|
37
|
+
/** The sandbox's process tree (its container's init), recorded on each brokered token. */
|
|
38
|
+
readonly stepProcess?: () => Promise<HostLoadStepProcess | null>;
|
|
39
|
+
/** Delay before retrying a failed delivery; doubles up to a few seconds. */
|
|
40
|
+
readonly retryMs?: number;
|
|
41
|
+
readonly now?: () => number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One sandbox's brokered tokens. The sandbox never chooses the cost or the
|
|
45
|
+
* attempt. Replies for one request go out one at a time, newest state only,
|
|
46
|
+
* each with a rising sequence the container-side writer uses to refuse an
|
|
47
|
+
* older reply; a failed delivery is retried until a newer state replaces it
|
|
48
|
+
* or the broker closes. A sandbox that floods requests or exceeds its
|
|
49
|
+
* outstanding limit stops the broker and fails its attempt.
|
|
50
|
+
*/
|
|
51
|
+
export declare class SandboxHostCapacityBroker {
|
|
52
|
+
private readonly gate;
|
|
53
|
+
private readonly dispatchAttemptId;
|
|
54
|
+
private readonly priority;
|
|
55
|
+
private readonly deliver;
|
|
56
|
+
private readonly options;
|
|
57
|
+
private readonly tokens;
|
|
58
|
+
private readonly deliveries;
|
|
59
|
+
private readonly work;
|
|
60
|
+
private readonly maximumOutstanding;
|
|
61
|
+
private readonly burst;
|
|
62
|
+
private readonly refillPerSecond;
|
|
63
|
+
private readonly retryMs;
|
|
64
|
+
private readonly now;
|
|
65
|
+
private sequence;
|
|
66
|
+
private allowance;
|
|
67
|
+
private allowanceAtMs;
|
|
68
|
+
private closed;
|
|
69
|
+
private abuse;
|
|
70
|
+
constructor(gate: HostLoadStepGate, dispatchAttemptId: string, priority: HostLoadTokenPriority, deliver: SandboxHostCapacityDelivery, options?: SandboxHostCapacityBrokerOptions);
|
|
71
|
+
/**
|
|
72
|
+
* True when the line was a broker request; such a line is never a runner
|
|
73
|
+
* event. Throws sandbox_host_capacity_abuse once the sandbox breaks its
|
|
74
|
+
* limits: its tokens are returned and the attempt fails with that reason.
|
|
75
|
+
*/
|
|
76
|
+
handleLine(line: string): boolean;
|
|
77
|
+
/** The sandbox exited: cancel its waits and return every token it holds. */
|
|
78
|
+
close(): Promise<void>;
|
|
79
|
+
/** Requests waiting or admitted, for diagnostics and tests. */
|
|
80
|
+
outstanding(): number;
|
|
81
|
+
private stop;
|
|
82
|
+
private takeAllowance;
|
|
83
|
+
private track;
|
|
84
|
+
private acquire;
|
|
85
|
+
/**
|
|
86
|
+
* The sandbox's step ended but part of its tree may still run: the host token is
|
|
87
|
+
* kept, marked retained (so the attempt's own next step does not wait for it),
|
|
88
|
+
* until the sandbox releases the request or exits.
|
|
89
|
+
*/
|
|
90
|
+
private retain;
|
|
91
|
+
private release;
|
|
92
|
+
/** Queues the newest state for a request; at most one delivery per request is in flight. */
|
|
93
|
+
private respond;
|
|
94
|
+
private pump;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adds the broker variables to a worker `docker create` command, just before
|
|
98
|
+
* its image: the protocol, and the host's maximum queue wait so the
|
|
99
|
+
* container's own fail-safe never fires before the host answers.
|
|
100
|
+
*/
|
|
101
|
+
export declare function withSandboxHostCapacityBroker(createArgs: readonly string[], image: string, maxWaitMs: number): string[];
|
|
102
|
+
/** `docker exec` arguments that write one reply into the container as root. */
|
|
103
|
+
export declare function sandboxHostCapacityDeliveryExecArgs(container: string): string[];
|
|
104
|
+
/**
|
|
105
|
+
* The `node -e` script that writes one response file inside the container, run
|
|
106
|
+
* as root. It keeps the newest reply: one with a lower or equal sequence than
|
|
107
|
+
* the file already holds is dropped, so a late delivery can never replace a
|
|
108
|
+
* newer state. Replies are world-readable but owned by the writer (root, via
|
|
109
|
+
* `docker exec --user 0`). The directory must already be owned by that same uid
|
|
110
|
+
* and writable by no one else, i.e. the root-owned reply mount; it is never
|
|
111
|
+
* created here, where it could turn out to be the sandbox's own directory.
|
|
112
|
+
*/
|
|
113
|
+
export declare const sandboxHostCapacityResponseScript: string;
|