@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.15efe2d7309f
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 +146 -3
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +92 -14
- package/dist/bridge/bridge.service.js +446 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +31 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -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 +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -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 +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- 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 +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +61 -0
- package/dist/runtime/host-load-governor-config.js +86 -0
- package/dist/runtime/host-load-governor.d.ts +193 -0
- package/dist/runtime/host-load-governor.js +662 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +75 -2
- package/dist/runtime/host-load-sampler.js +142 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- 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 +88 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- 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-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +39 -6
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- 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/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- 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 +207 -121
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- 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 +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +91 -215
- 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.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- 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 +31 -19
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +221 -182
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +277 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -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.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +109 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +106 -181
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -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-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -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/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -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 +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +15 -2
- package/dist/session/session.service.js +246 -138
- package/dist/session/session.types.d.ts +4 -0
- package/dist/session/session.types.js +7 -7
- 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/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- 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 +14 -7
- 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/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +127 -155
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { GitClient } from "../shared/git/git.js";
|
|
3
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
3
4
|
import { loadHostRuntimeContract } from "./host-runtime-contract.js";
|
|
4
5
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible } from "./host-runtime-promotion.js";
|
|
5
6
|
import { preparedRuntimeIdentity } from "./prepared-runtime-identity.js";
|
|
7
|
+
import { unresolvedReapplyConflicts, WipGit } from "../worktree/wip-git.js";
|
|
6
8
|
/** Foreground barrier: prepare a wave, verify its exact runtimes, then release agents. */
|
|
7
9
|
export class PreparedRuntimeReadiness {
|
|
8
10
|
runtime;
|
|
@@ -43,6 +45,15 @@ export class PreparedRuntimeReadiness {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
has(id) { return this.preparations.has(id); }
|
|
48
|
+
/**
|
|
49
|
+
* Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
|
|
50
|
+
* check() found the prepared contract parallel-eligible, so the lease manager may admit it
|
|
51
|
+
* beside other shared-admission runs of the same repository instead of exclusively.
|
|
52
|
+
*/
|
|
53
|
+
isParallelEligibleProbe(id, fence) {
|
|
54
|
+
return [...this.preparations.values()].some(entry => entry.probe?.sandbox.dispatchAttemptId === id
|
|
55
|
+
&& entry.probe.lease.fencingToken === fence);
|
|
56
|
+
}
|
|
46
57
|
hasPending() { return this.preparations.size > 0; }
|
|
47
58
|
pendingSnapshots() {
|
|
48
59
|
return [...this.preparations.values()].map(entry => ({
|
|
@@ -160,8 +171,9 @@ export class PreparedRuntimeReadiness {
|
|
|
160
171
|
if (hostRuntimeContractFingerprint(contract) !== identity.runtimeContractFingerprint) {
|
|
161
172
|
throw new Error("host_runtime_prepared_source_changed: runtime contract changed while capturing its source identity.");
|
|
162
173
|
}
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
const settled = await this.settledWithoutProbe(entry, identity, worktree, checkpoint);
|
|
175
|
+
if (settled)
|
|
176
|
+
return settled;
|
|
165
177
|
await checkpoint?.({ code: "host_runtime_prepared_probe_started", expiresAt: entry.expiresAt,
|
|
166
178
|
message: `Verifying prepared runtime ${identity.inputCommitSha.slice(0, 12)} before agent admission; project-default readiness is not a substitute.` });
|
|
167
179
|
const probeId = randomUUID();
|
|
@@ -172,11 +184,14 @@ export class PreparedRuntimeReadiness {
|
|
|
172
184
|
inputCommitSha: identity.inputCommitSha },
|
|
173
185
|
};
|
|
174
186
|
entry.probe = probe;
|
|
187
|
+
// Any revocation from here on (this probe's own violation or a sibling's) voids its proof.
|
|
188
|
+
const revocationGeneration = await this.store.revocationGeneration(dispatch.repo.id);
|
|
175
189
|
const stopPreparedHeadMonitor = new AbortController();
|
|
176
190
|
const preparedHeadMonitor = monitorPreparedHead(worktree, identity.inputCommitSha, controller, stopPreparedHeadMonitor.signal);
|
|
177
191
|
let cleanupConfirmed;
|
|
178
192
|
let verifiedRuntimeContractFingerprint;
|
|
179
|
-
let verifiedPorts;
|
|
193
|
+
let verifiedPorts = [];
|
|
194
|
+
let isolationViolated = false;
|
|
180
195
|
try {
|
|
181
196
|
controller.signal.throwIfAborted();
|
|
182
197
|
await this.runtime.acquire(probe, controller.signal);
|
|
@@ -189,6 +204,12 @@ export class PreparedRuntimeReadiness {
|
|
|
189
204
|
verifiedRuntimeContractFingerprint = hostRuntimeContractFingerprint(started.runtimeContract);
|
|
190
205
|
verifiedPorts = started.lease.resources.ports.map(port => port.name).sort();
|
|
191
206
|
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
// A shared probe's stray listener: the lease stopped it and revoked the repository (see unproven).
|
|
209
|
+
if (!(error instanceof ForgeFailureError && error.failureCode === "host_runtime_isolation_violation"))
|
|
210
|
+
throw error;
|
|
211
|
+
isolationViolated = true;
|
|
212
|
+
}
|
|
192
213
|
finally {
|
|
193
214
|
stopPreparedHeadMonitor.abort();
|
|
194
215
|
await preparedHeadMonitor;
|
|
@@ -199,25 +220,15 @@ export class PreparedRuntimeReadiness {
|
|
|
199
220
|
if (!cleanupConfirmed) {
|
|
200
221
|
throw new Error("host_runtime_prepared_probe_cleanup_unconfirmed: matching probe teardown was not confirmed.");
|
|
201
222
|
}
|
|
223
|
+
if (isolationViolated)
|
|
224
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
202
225
|
// Probe-owned processes may create transient, untracked files while they
|
|
203
226
|
// are alive. Verify the prepared source only after matching teardown is
|
|
204
227
|
// confirmed: persistent source edits still fail closed, while files that
|
|
205
228
|
// belong to the probe lifecycle cannot create a false source-change loop.
|
|
206
229
|
const currentDiagnostics = { entries: new Map() };
|
|
207
230
|
const currentIdentity = await preparedRuntimeIdentity(worktree, controller.signal, currentDiagnostics);
|
|
208
|
-
const changed =
|
|
209
|
-
if (verifiedRuntimeContractFingerprint !== identity.runtimeContractFingerprint
|
|
210
|
-
|| currentIdentity.runtimeContractFingerprint !== identity.runtimeContractFingerprint) {
|
|
211
|
-
changed.push("runtime contract");
|
|
212
|
-
}
|
|
213
|
-
if (currentIdentity.inputCommitSha !== identity.inputCommitSha)
|
|
214
|
-
changed.push("HEAD");
|
|
215
|
-
if (currentIdentity.sourceFingerprint !== identity.sourceFingerprint) {
|
|
216
|
-
const paths = changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries);
|
|
217
|
-
changed.push(paths.length > 0
|
|
218
|
-
? `source fingerprint (${paths.join(", ")})`
|
|
219
|
-
: "source fingerprint");
|
|
220
|
-
}
|
|
231
|
+
const changed = identityChanges(identity, currentIdentity, verifiedRuntimeContractFingerprint, changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries));
|
|
221
232
|
if (changed.length > 0) {
|
|
222
233
|
throw new Error(`host_runtime_prepared_source_changed: ${changed.join(", ")} changed during isolation verification.`);
|
|
223
234
|
}
|
|
@@ -225,12 +236,54 @@ export class PreparedRuntimeReadiness {
|
|
|
225
236
|
throw new Error("host_runtime_prepared_probe_incomplete: assigned-port verification did not confirm every configured launch port.");
|
|
226
237
|
}
|
|
227
238
|
controller.signal.throwIfAborted();
|
|
228
|
-
await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint)
|
|
239
|
+
const recorded = await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint, identity.isolationFingerprint, revocationGeneration)
|
|
240
|
+
.then(() => true, (error) => errorMessage(error).startsWith("host_parallel_promotion_revoked:")
|
|
241
|
+
? false : Promise.reject(error));
|
|
242
|
+
if (!recorded)
|
|
243
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
229
244
|
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
230
|
-
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its
|
|
245
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its proof is retained for every head with the same isolation inputs.` });
|
|
246
|
+
return identity;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The identity when the worktree needs no probe, or null to probe it. Recorded proof for the same
|
|
250
|
+
* isolation inputs already covers it: a re-apply conflict changes source, not those inputs, and the
|
|
251
|
+
* stack it defers starts at validation from the agent's resolved source, as any edited source does.
|
|
252
|
+
* Without proof, nothing is probed (no exclusive admission, no stack launch) when no proof could be
|
|
253
|
+
* recorded: a quarantined contract, or restored work with unresolved re-apply conflicts, which
|
|
254
|
+
* cannot build and which the agent resolves first (deferredProjectStartEvent in
|
|
255
|
+
* worktree-wip-events.ts). Those runs take exclusive admission.
|
|
256
|
+
*/
|
|
257
|
+
async settledWithoutProbe(entry, identity, worktree, checkpoint) {
|
|
258
|
+
const repoId = entry.dispatch.repo.id;
|
|
259
|
+
if (await this.store.load(repoId, identity))
|
|
260
|
+
return identity;
|
|
261
|
+
if (await this.store.quarantined(repoId, identity.runtimeContractFingerprint)) {
|
|
262
|
+
return await this.unproven(entry, identity, checkpoint, "quarantined");
|
|
263
|
+
}
|
|
264
|
+
// An unreadable conflict state is not probed either: the stack may not build.
|
|
265
|
+
const conflicted = await unresolvedReapplyConflicts(new WipGit(), worktree)
|
|
266
|
+
.then(conflicts => conflicts.length > 0 ? "reapply_conflicts" : null, () => "reapply_conflicts_unreadable");
|
|
267
|
+
return conflicted ? await this.unproven(entry, identity, checkpoint, conflicted) : null;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
|
|
271
|
+
* contract is quarantined, or whose worktree still has unresolved WIP re-apply conflicts, records
|
|
272
|
+
* no proof. The agent's admission then finds none and runs under exclusive admission.
|
|
273
|
+
*/
|
|
274
|
+
async unproven(entry, identity, checkpoint, cause = "revoked") {
|
|
275
|
+
const reason = unprovenReasons[cause];
|
|
276
|
+
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
277
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} did not prove isolation (${reason}); its runs are serialized.` });
|
|
231
278
|
return identity;
|
|
232
279
|
}
|
|
233
280
|
}
|
|
281
|
+
const unprovenReasons = {
|
|
282
|
+
revoked: "the repository's promotion was revoked during the probe",
|
|
283
|
+
quarantined: "its runtime contract is quarantined after a recent isolation violation, so it was not probed",
|
|
284
|
+
reapply_conflicts: "its worktree has unresolved conflicts from re-applied saved work, which the agent resolves first, so it was not probed",
|
|
285
|
+
reapply_conflicts_unreadable: "its worktree's record of conflicts from re-applied saved work could not be read, so it was not probed",
|
|
286
|
+
};
|
|
234
287
|
const preparedHeadPollIntervalMs = 1_000;
|
|
235
288
|
async function monitorPreparedHead(worktree, expectedCommitSha, preparationController, stopSignal) {
|
|
236
289
|
const git = new GitClient();
|
|
@@ -274,6 +327,24 @@ async function waitForPreparedHeadPoll(signal) {
|
|
|
274
327
|
function errorMessage(error) {
|
|
275
328
|
return error instanceof Error ? error.message : String(error);
|
|
276
329
|
}
|
|
330
|
+
/** What changed between the identity a probe started from and the one after its teardown. */
|
|
331
|
+
function identityChanges(prepared, current, verifiedRuntimeContractFingerprint, changedPaths) {
|
|
332
|
+
const changed = [];
|
|
333
|
+
if (verifiedRuntimeContractFingerprint !== prepared.runtimeContractFingerprint
|
|
334
|
+
|| current.runtimeContractFingerprint !== prepared.runtimeContractFingerprint) {
|
|
335
|
+
changed.push("runtime contract");
|
|
336
|
+
}
|
|
337
|
+
if (current.inputCommitSha !== prepared.inputCommitSha)
|
|
338
|
+
changed.push("HEAD");
|
|
339
|
+
// Ignored launch inputs change only the isolation fingerprint; either change voids the proof.
|
|
340
|
+
if (current.sourceFingerprint !== prepared.sourceFingerprint
|
|
341
|
+
|| current.isolationFingerprint !== prepared.isolationFingerprint) {
|
|
342
|
+
changed.push(changedPaths.length > 0
|
|
343
|
+
? `source or isolation inputs (${changedPaths.join(", ")})`
|
|
344
|
+
: "source or isolation inputs");
|
|
345
|
+
}
|
|
346
|
+
return changed;
|
|
347
|
+
}
|
|
277
348
|
function changedIdentityPaths(before, after) {
|
|
278
349
|
const paths = new Set([...before.keys(), ...after.keys()]);
|
|
279
350
|
const changed = [...paths]
|
|
@@ -0,0 +1,104 @@
|
|
|
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;
|
|
101
|
+
/** The offer refusal message while the runner yields to foreground work. */
|
|
102
|
+
export declare function runnerYieldingMessage(report: RunnerSettingsReport): string;
|
|
103
|
+
/** One line describing the effective settings, for the bridge log. */
|
|
104
|
+
export declare function describeRunnerSettings(report: RunnerSettingsReport): string;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
2
|
+
import { parseHostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
3
|
+
// Decision 0014 §3 "Precedence" and §6 "Bridge hub": the server pushes a runner
|
|
4
|
+
// settings document (`ApplySettings`) and is the source of truth. Host env vars
|
|
5
|
+
// are one-sided safety bounds only: a ceiling on capacity, a floor on reserves.
|
|
6
|
+
// The bridge reports the effective values, their sources and every env bound it
|
|
7
|
+
// saw back to the server (`SettingsApplied`), so a host bound is never silent.
|
|
8
|
+
// Nothing here is persisted to bridge.json (0014 agent constraint).
|
|
9
|
+
export const runnerSettingKeys = [
|
|
10
|
+
"maxConcurrentAttempts",
|
|
11
|
+
"cpuBudgetPercent",
|
|
12
|
+
"yieldCpuBudgetPercent",
|
|
13
|
+
"memoryReserveBytes",
|
|
14
|
+
"maxHeavySteps",
|
|
15
|
+
"yieldToForeground",
|
|
16
|
+
];
|
|
17
|
+
export const defaultCpuBudgetPercent = 80;
|
|
18
|
+
export const defaultYieldCpuBudgetPercent = 50;
|
|
19
|
+
const MiB = 1024 ** 2;
|
|
20
|
+
const GiB = 1024 ** 3;
|
|
21
|
+
/** The server's ranges (contract); a value outside them is rejected, not clamped, so it is never silent. */
|
|
22
|
+
const serverRanges = {
|
|
23
|
+
maxConcurrentAttempts: { min: 1, max: 32 },
|
|
24
|
+
cpuBudgetPercent: { min: 10, max: 100 },
|
|
25
|
+
yieldCpuBudgetPercent: { min: 10, max: 100 },
|
|
26
|
+
memoryReserveBytes: { min: 512 * MiB, max: 128 * GiB },
|
|
27
|
+
maxHeavySteps: { min: 1, max: 64 },
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Computes every effective value (decision 0014 precedence):
|
|
31
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
32
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
33
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
34
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
35
|
+
*/
|
|
36
|
+
export function computeEffectiveRunnerSettings(document, environment, hostDefaults, localYield) {
|
|
37
|
+
const rejected = [];
|
|
38
|
+
const server = (key) => {
|
|
39
|
+
const value = document?.[key] ?? null;
|
|
40
|
+
if (value === null)
|
|
41
|
+
return null;
|
|
42
|
+
const range = serverRanges[key];
|
|
43
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
44
|
+
rejected.push({ key, reason: `${String(value)} is not a whole number; the host default applies.`, kind: "invalid" });
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (value < range.min || value > range.max) {
|
|
48
|
+
rejected.push({ key, reason: `${value} is outside ${range.min}-${range.max}; the host default applies.`, kind: "invalid" });
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
const attemptsCeiling = integerEnv(environment, "FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", 1, 32);
|
|
54
|
+
const cpuCeilings = cpuBudgetCeilings(environment);
|
|
55
|
+
const reserveFloor = integerEnv(environment, "FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * MiB, 128 * GiB);
|
|
56
|
+
const heavyStepsCeiling = integerEnv(environment, "FORGE_HOST_MAX_HEAVY_STEPS", 1, 64);
|
|
57
|
+
const attempts = ceilingValue(server("maxConcurrentAttempts"), lowest(attemptsCeiling), hostDefaults.maxConcurrentAttempts);
|
|
58
|
+
const cpu = ceilingValue(server("cpuBudgetPercent"), lowest(...cpuCeilings), defaultCpuBudgetPercent);
|
|
59
|
+
// The yield budget's ceilings are the CPU budget's. Without a server value they
|
|
60
|
+
// cap its default rather than replace it: a host allowing 90% CPU must not raise
|
|
61
|
+
// the 50% yield default, which no env var sets today.
|
|
62
|
+
const serverYieldCpu = server("yieldCpuBudgetPercent");
|
|
63
|
+
const yieldCpu = ceilingValue(serverYieldCpu ?? defaultYieldCpuBudgetPercent, lowest(...cpuCeilings), defaultYieldCpuBudgetPercent);
|
|
64
|
+
const yieldCpuSource = serverYieldCpu === null && yieldCpu.source === "server" ? "default" : yieldCpu.source;
|
|
65
|
+
const reserve = floorValue(server("memoryReserveBytes"), reserveFloor?.value ?? null, hostDefaults.memoryReserveBytes);
|
|
66
|
+
const heavySteps = ceilingValue(server("maxHeavySteps"), lowest(heavyStepsCeiling), null);
|
|
67
|
+
const serverYield = document?.yieldToForeground === true;
|
|
68
|
+
const yielding = serverYield || localYield;
|
|
69
|
+
// The host's own switch wins the label: turning the server toggle off would not stop it.
|
|
70
|
+
const yieldSource = localYield ? "host_local" : serverYield ? "server" : "default";
|
|
71
|
+
const bounds = [];
|
|
72
|
+
const addCeilings = (key, set) => {
|
|
73
|
+
for (const bound of set)
|
|
74
|
+
if (bound)
|
|
75
|
+
bounds.push({ key, envVar: bound.envVar, value: bound.value, kind: "ceiling" });
|
|
76
|
+
};
|
|
77
|
+
addCeilings("maxConcurrentAttempts", [attemptsCeiling]);
|
|
78
|
+
addCeilings("cpuBudgetPercent", cpuCeilings);
|
|
79
|
+
addCeilings("yieldCpuBudgetPercent", cpuCeilings);
|
|
80
|
+
if (reserveFloor)
|
|
81
|
+
bounds.push({ key: "memoryReserveBytes", envVar: reserveFloor.envVar, value: reserveFloor.value, kind: "floor" });
|
|
82
|
+
addCeilings("maxHeavySteps", [heavyStepsCeiling]);
|
|
83
|
+
const values = {
|
|
84
|
+
maxConcurrentAttempts: attempts.value,
|
|
85
|
+
cpuBudgetPercent: cpu.value,
|
|
86
|
+
yieldCpuBudgetPercent: yieldCpu.value,
|
|
87
|
+
memoryReserveBytes: reserve.value,
|
|
88
|
+
maxHeavySteps: heavySteps.value,
|
|
89
|
+
yieldToForeground: yielding,
|
|
90
|
+
};
|
|
91
|
+
const budgetPercent = yielding ? Math.min(values.yieldCpuBudgetPercent, values.cpuBudgetPercent) : values.cpuBudgetPercent;
|
|
92
|
+
return {
|
|
93
|
+
report: {
|
|
94
|
+
version: null,
|
|
95
|
+
governor: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
|
|
96
|
+
values,
|
|
97
|
+
sources: {
|
|
98
|
+
maxConcurrentAttempts: attempts.source,
|
|
99
|
+
cpuBudgetPercent: cpu.source,
|
|
100
|
+
yieldCpuBudgetPercent: yieldCpuSource,
|
|
101
|
+
memoryReserveBytes: reserve.source,
|
|
102
|
+
maxHeavySteps: heavySteps.source,
|
|
103
|
+
yieldToForeground: yieldSource,
|
|
104
|
+
},
|
|
105
|
+
bounds,
|
|
106
|
+
rejected,
|
|
107
|
+
},
|
|
108
|
+
yielding,
|
|
109
|
+
governorCpuBudgetFraction: budgetPercent / 100,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
114
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
115
|
+
*/
|
|
116
|
+
export function parseRunnerSettingsDocument(raw) {
|
|
117
|
+
if (!raw || typeof raw !== "object")
|
|
118
|
+
return null;
|
|
119
|
+
const record = raw;
|
|
120
|
+
const version = record.version;
|
|
121
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0)
|
|
122
|
+
return null;
|
|
123
|
+
const numeric = (key) => {
|
|
124
|
+
const value = record[key];
|
|
125
|
+
// Kept as-is (even out of range) so computeEffectiveRunnerSettings can report it as rejected.
|
|
126
|
+
return typeof value === "number" ? value : null;
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
runnerId: typeof record.runnerId === "string" ? record.runnerId : null,
|
|
130
|
+
version,
|
|
131
|
+
maxConcurrentAttempts: numeric("maxConcurrentAttempts"),
|
|
132
|
+
cpuBudgetPercent: numeric("cpuBudgetPercent"),
|
|
133
|
+
yieldCpuBudgetPercent: numeric("yieldCpuBudgetPercent"),
|
|
134
|
+
memoryReserveBytes: numeric("memoryReserveBytes"),
|
|
135
|
+
maxHeavySteps: numeric("maxHeavySteps"),
|
|
136
|
+
yieldToForeground: record.yieldToForeground === true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The report for what is actually in force after an apply in which the host
|
|
141
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
142
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
143
|
+
* rejection, so the server never reads a desired value as applied.
|
|
144
|
+
*/
|
|
145
|
+
export function runnerSettingsInForce(report, previous, failures) {
|
|
146
|
+
if (failures.length === 0)
|
|
147
|
+
return report;
|
|
148
|
+
const values = { ...report.values };
|
|
149
|
+
const sources = { ...report.sources };
|
|
150
|
+
for (const failure of failures) {
|
|
151
|
+
keepPrevious(values, previous.values, failure.key);
|
|
152
|
+
sources[failure.key] = previous.sources[failure.key];
|
|
153
|
+
}
|
|
154
|
+
return { ...report, values, sources, rejected: [...report.rejected, ...failures] };
|
|
155
|
+
}
|
|
156
|
+
function keepPrevious(target, previous, key) {
|
|
157
|
+
target[key] = previous[key];
|
|
158
|
+
}
|
|
159
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
160
|
+
export function sameRunnerSettingsReport(left, right) {
|
|
161
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
162
|
+
}
|
|
163
|
+
function ceilingValue(server, ceiling, fallback) {
|
|
164
|
+
if (server !== null) {
|
|
165
|
+
return ceiling && ceiling.value < server
|
|
166
|
+
? { value: ceiling.value, source: "host_env" }
|
|
167
|
+
: { value: server, source: "server" };
|
|
168
|
+
}
|
|
169
|
+
return ceiling ? { value: ceiling.value, source: "host_env" } : { value: fallback, source: "default" };
|
|
170
|
+
}
|
|
171
|
+
function floorValue(server, floor, fallback) {
|
|
172
|
+
if (server !== null) {
|
|
173
|
+
return floor !== null && floor > server
|
|
174
|
+
? { value: floor, source: "host_env" }
|
|
175
|
+
: { value: server, source: "server" };
|
|
176
|
+
}
|
|
177
|
+
return floor !== null ? { value: floor, source: "host_env" } : { value: fallback, source: "default" };
|
|
178
|
+
}
|
|
179
|
+
function lowest(...bounds) {
|
|
180
|
+
let result = null;
|
|
181
|
+
for (const bound of bounds) {
|
|
182
|
+
if (bound && (result === null || bound.value < result.value))
|
|
183
|
+
result = bound;
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Both CPU ceilings: the new FORGE_HOST_CPU_BUDGET_PERCENT (10–100) and the
|
|
189
|
+
* existing FORGE_HOST_LOAD_CPU_BUDGET_FRACTION (0.05–1, the governor's own
|
|
190
|
+
* parse), reported as a percent.
|
|
191
|
+
*/
|
|
192
|
+
function cpuBudgetCeilings(environment) {
|
|
193
|
+
const percent = numberEnv(environment, "FORGE_HOST_CPU_BUDGET_PERCENT", 10, 100);
|
|
194
|
+
const fraction = numberEnv(environment, "FORGE_HOST_LOAD_CPU_BUDGET_FRACTION", 0.05, 1);
|
|
195
|
+
return [
|
|
196
|
+
percent,
|
|
197
|
+
fraction ? { envVar: fraction.envVar, value: Math.round(fraction.value * 10_000) / 100 } : null,
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
/** Matches the lease manager's parse (parseInt, clamped); an unparsable value counts as unset. */
|
|
201
|
+
function integerEnv(environment, envVar, minimum, maximum) {
|
|
202
|
+
const raw = environment[envVar];
|
|
203
|
+
if (raw === undefined || raw.trim() === "")
|
|
204
|
+
return null;
|
|
205
|
+
const parsed = Number.parseInt(raw, 10);
|
|
206
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.max(minimum, Math.min(maximum, parsed)) } : null;
|
|
207
|
+
}
|
|
208
|
+
/** Matches the governor config's parse (Number, clamped); an unparsable value counts as unset. */
|
|
209
|
+
function numberEnv(environment, envVar, minimum, maximum) {
|
|
210
|
+
const raw = environment[envVar];
|
|
211
|
+
if (raw === undefined || raw.trim() === "")
|
|
212
|
+
return null;
|
|
213
|
+
const parsed = Number(raw);
|
|
214
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.min(maximum, Math.max(minimum, parsed)) } : null;
|
|
215
|
+
}
|
|
216
|
+
/** The offer refusal message while the runner yields to foreground work. */
|
|
217
|
+
export function runnerYieldingMessage(report) {
|
|
218
|
+
const where = report.sources.yieldToForeground === "host_local" ? "on this host (forge-bridge yield on)" : "in Forge";
|
|
219
|
+
return `runner_yielding: this runner is yielding to foreground work (turned on ${where}); it takes no new attempts until yield is off. Running attempts continue.`;
|
|
220
|
+
}
|
|
221
|
+
/** One line describing the effective settings, for the bridge log. */
|
|
222
|
+
export function describeRunnerSettings(report) {
|
|
223
|
+
const { values } = report;
|
|
224
|
+
const parts = [
|
|
225
|
+
`max attempts ${values.maxConcurrentAttempts}`,
|
|
226
|
+
`CPU budget ${values.cpuBudgetPercent}%`,
|
|
227
|
+
`yield budget ${values.yieldCpuBudgetPercent}%`,
|
|
228
|
+
`memory reserve ${formatBytes(values.memoryReserveBytes)}`,
|
|
229
|
+
`heavy steps ${values.maxHeavySteps ?? "budget only"}`,
|
|
230
|
+
`yield ${values.yieldToForeground ? "on" : "off"}`,
|
|
231
|
+
];
|
|
232
|
+
const capped = report.bounds
|
|
233
|
+
.filter(bound => report.sources[bound.key] === "host_env")
|
|
234
|
+
.map(bound => `${bound.envVar}=${bound.value}`);
|
|
235
|
+
return `${parts.join(", ")}${capped.length > 0 ? `; host bounds in force: ${[...new Set(capped)].join(", ")}` : ""}`;
|
|
236
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type DotnetPathPlatform, type DotnetProjectFiles } from "./dotnet-build-outputs.js";
|
|
2
|
+
/** What a supervised project runtime runs, recorded in the attempt log directory at launch. */
|
|
3
|
+
export interface SupervisedRuntimeDescriptor {
|
|
4
|
+
readonly schemaVersion: 1;
|
|
5
|
+
/** The runtime contract's port name, for example `api`. */
|
|
6
|
+
readonly role: string;
|
|
7
|
+
/** The attempt supervisor child, for example `project-api`. */
|
|
8
|
+
readonly childName: string;
|
|
9
|
+
readonly command: string;
|
|
10
|
+
readonly args: readonly string[];
|
|
11
|
+
readonly cwd: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SupervisedRuntimeCollision {
|
|
14
|
+
readonly childName: string;
|
|
15
|
+
readonly role: string;
|
|
16
|
+
/** The runtime's supervised process (the `dotnet run` the supervisor started), when recorded. */
|
|
17
|
+
readonly pid: number | null;
|
|
18
|
+
readonly project: string;
|
|
19
|
+
readonly outputDirectory: string;
|
|
20
|
+
/** The running file the build would have to replace. */
|
|
21
|
+
readonly lockedPath: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SupervisedRuntimeBuildCheck {
|
|
24
|
+
readonly command: string;
|
|
25
|
+
readonly args: readonly string[];
|
|
26
|
+
readonly cwd: string;
|
|
27
|
+
readonly worktreePath: string;
|
|
28
|
+
/** The attempt's FORGE_LOG_DIR, which holds the supervisor ledger and runtime descriptors. */
|
|
29
|
+
readonly logDirectory: string;
|
|
30
|
+
/** A runner-authored script that builds the worktree's solution (a managed verification tier). */
|
|
31
|
+
readonly buildsWorktreeSolution?: boolean;
|
|
32
|
+
readonly platform?: DotnetPathPlatform;
|
|
33
|
+
readonly files?: DotnetProjectFiles;
|
|
34
|
+
}
|
|
35
|
+
export declare function supervisedRuntimeDescriptorPath(logDirectory: string, childName: string): string;
|
|
36
|
+
export declare function writeSupervisedRuntimeDescriptor(logDirectory: string, descriptor: Omit<SupervisedRuntimeDescriptor, "schemaVersion">): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Finds the first running supervised runtime of this attempt whose build output the command
|
|
39
|
+
* would write. Only the project graph and output directory decide a collision: a build of an
|
|
40
|
+
* unrelated project, into another output, or a test run without a build never matches.
|
|
41
|
+
*/
|
|
42
|
+
export declare function findSupervisedRuntimeCollision(check: SupervisedRuntimeBuildCheck): Promise<SupervisedRuntimeCollision | null>;
|
|
43
|
+
export declare function supervisedRuntimeCollisionMessage(collision: SupervisedRuntimeCollision): string;
|
|
44
|
+
/** Fails fast, naming the runtime, instead of letting the build hit the runtime's locked files. */
|
|
45
|
+
export declare function assertBuildSparesSupervisedRuntimes(check: SupervisedRuntimeBuildCheck): Promise<void>;
|