@loucompanion/forge-bridge 0.1.4-dev.86fc5d1208e6 → 0.1.4-dev.894bcbd53d64
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 +144 -3
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -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 +101 -15
- package/dist/bridge/bridge.service.js +472 -345
- package/dist/bridge/bridge.types.d.ts +27 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- 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 +17 -0
- 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/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.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +21 -0
- package/dist/runtime/attempt-process-supervisor.js +62 -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-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +67 -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 +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -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 +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- 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 +81 -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 +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -0
- package/dist/runtime/host-runtime-contract.js +35 -2
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +343 -67
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- 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.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -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-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- 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 +27 -7
- package/dist/session/managed-attempt-tools.js +406 -123
- package/dist/session/managed-build-coordinator.d.ts +17 -1
- package/dist/session/managed-build-coordinator.js +14 -1
- 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 +100 -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 +111 -230
- 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 +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- 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 +228 -219
- 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 +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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 +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
- package/dist/session/provider-cli/provider-cli.process.js +286 -403
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +87 -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 +207 -192
- 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-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 +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -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 +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -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-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +189 -69
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- 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 +120 -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 +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -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 +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -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 +124 -155
- package/dist/worktree/worktree.types.d.ts +38 -0
- package/package.json +2 -2
|
@@ -7,28 +7,34 @@ import { assertHostAttemptRootIdentity, retainHostDiagnostics } from "./host-dia
|
|
|
7
7
|
import { assertHostExecutionRoot, compactHostAttemptId } from "./host-execution-root.js";
|
|
8
8
|
import { PreparedRuntimeReadiness } from "./prepared-runtime-readiness.js";
|
|
9
9
|
import { preparedRuntimeIdentity } from "./prepared-runtime-identity.js";
|
|
10
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
10
11
|
import { resolveExistingDirectoryPath } from "../shared/path/path.js";
|
|
11
12
|
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
12
|
-
import { redactText } from "../shared/redaction/redaction.js";
|
|
13
13
|
import { StreamingProviderProcessRunner, } from "../session/provider-cli/provider-cli.process.js";
|
|
14
14
|
import { createRuntimeIsolationLease, renewRuntimeIsolationLease, transitionRuntimeIsolationLease, validRuntimeIsolationLease, withRuntimeIsolationResources, } from "./runtime-isolation-lease.js";
|
|
15
|
-
import { hostPortEnvironment, loadHostRuntimeContract, } from "./host-runtime-contract.js";
|
|
15
|
+
import { hostPortEnvironment, loadHostRuntimeContract, newAttemptApiMasterKey, withAttemptApiMasterKey, } from "./host-runtime-contract.js";
|
|
16
16
|
import { HostPortBroker, } from "./host-port-broker.js";
|
|
17
17
|
import { NodeHostRuntimeAdapter, } from "./node-host-runtime-adapter.js";
|
|
18
18
|
import { AttemptProcessSupervisorRegistry } from "./attempt-process-supervisor-registry.js";
|
|
19
|
+
import { terminateAttemptManagedCommands } from "./managed-command-teardown.js";
|
|
19
20
|
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "./attempt-database-broker.js";
|
|
20
21
|
import { AttemptNodeRuntimeLauncher } from "./attempt-node-runtime-launcher.js";
|
|
21
22
|
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
22
23
|
import { RecoveryStabilizedMemory, buildMemoryAdmissionDiagnostics, resolveAdaptiveMemoryReserveBytes, } from "./memory-capacity.js";
|
|
23
24
|
import { PlaywrightHostRuntimeAdapter } from "./playwright-host-runtime-adapter.js";
|
|
24
|
-
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "./host-runtime-promotion.js";
|
|
25
|
+
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, readmitHostRuntimeContract, } from "./host-runtime-promotion.js";
|
|
25
26
|
import { ExactHostProcessRecovery, } from "../shared/process/host-process-recovery.js";
|
|
26
27
|
import { resetGeneratedOutputs } from "./generated-output-reset.js";
|
|
27
28
|
import { assertCanonicalDirectory, createCanonicalDirectory } from "./attempt-private-directory.js";
|
|
28
29
|
import { readCanonicalSourceFile } from "./canonical-source-file.js";
|
|
29
30
|
import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
|
|
30
31
|
import { architectMinimumWorkspaceEstimateBytes } from "./workspace-resource-estimator.js";
|
|
31
|
-
import { createAspNetRuntimePrebuildPlan, ensureAspNetRuntimePrebuilt, resolveWorktreeCommitSha, } from "./aspnet-runtime-prebuild.js";
|
|
32
|
+
import { createAspNetRuntimePrebuildPlan, ensureAspNetRuntimePrebuilt, executeAspNetRuntimeBuild, resolveWorktreeCommitSha, supervisedRuntimeLaunchArguments, } from "./aspnet-runtime-prebuild.js";
|
|
33
|
+
import { HostLoadGovernor } from "./host-load-governor.js";
|
|
34
|
+
import { hostLoadChildEnvironment } from "./host-load-child-environment.js";
|
|
35
|
+
import { aspNetPrebuildStepClass } from "./host-load-step-class.js";
|
|
36
|
+
import { attachSupervisedStepProcess, runHostGovernedStep } from "./host-load-step-run.js";
|
|
37
|
+
import { HostLoadSampler } from "./host-load-sampler.js";
|
|
32
38
|
const hostCapacityWaiterScanLimit = 64;
|
|
33
39
|
const maximumProcessRecoveryMetadataBytes = 1024 * 1024;
|
|
34
40
|
export class HostRuntimeLeaseManager {
|
|
@@ -60,10 +66,18 @@ export class HostRuntimeLeaseManager {
|
|
|
60
66
|
workspaceAvailableBytes = Number.MAX_SAFE_INTEGER;
|
|
61
67
|
portBroker;
|
|
62
68
|
nodeAdapter;
|
|
69
|
+
/** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
|
|
63
70
|
capacityConfiguration;
|
|
64
71
|
memoryAvailability;
|
|
65
72
|
executionRoot;
|
|
66
|
-
|
|
73
|
+
/** Host-wide admission for heavy steps (decisions 0013, 0018): the host test slot, and the budget when on. */
|
|
74
|
+
hostLoadGovernor;
|
|
75
|
+
requirementsCheck = null;
|
|
76
|
+
/** Installs the decision 0013 accept-time requirements recheck for host attempts. */
|
|
77
|
+
setRequirementsCheck(check) {
|
|
78
|
+
this.requirementsCheck = check;
|
|
79
|
+
}
|
|
80
|
+
constructor(stateRoot, portBroker = new HostPortBroker(), nodeAdapter, processSupervisors = new AttemptProcessSupervisorRegistry(), processRunner = new StreamingProviderProcessRunner(), listenerInspector = new HostListenerInspector(), promotionStore = new HostParallelPromotionStore(stateRoot), playwrightAdapter = new PlaywrightHostRuntimeAdapter(), processRecovery = new ExactHostProcessRecovery(), capacityResourceSample, executionRoot, databaseBroker = null, hostLoad = null) {
|
|
67
81
|
this.stateRoot = stateRoot;
|
|
68
82
|
this.processSupervisors = processSupervisors;
|
|
69
83
|
this.processRunner = processRunner;
|
|
@@ -73,6 +87,7 @@ export class HostRuntimeLeaseManager {
|
|
|
73
87
|
this.processRecovery = processRecovery;
|
|
74
88
|
this.capacityResourceSample = capacityResourceSample;
|
|
75
89
|
this.databaseBroker = databaseBroker;
|
|
90
|
+
this.hostLoadGovernor = new HostLoadGovernor({ stateRoot, load: hostLoad ?? new HostLoadSampler() });
|
|
76
91
|
this.executionRoot = path.resolve(executionRoot ?? stateRoot);
|
|
77
92
|
if (executionRoot !== undefined)
|
|
78
93
|
assertHostExecutionRoot(this.executionRoot);
|
|
@@ -82,7 +97,40 @@ export class HostRuntimeLeaseManager {
|
|
|
82
97
|
this.capacityConfiguration = loadHostCapacityConfiguration(capacityResourceSample);
|
|
83
98
|
this.memoryAvailability = new RecoveryStabilizedMemory(this.capacityConfiguration.memoryRecoverySamples, this.capacityConfiguration.memoryRecoverySampleIntervalMs);
|
|
84
99
|
}
|
|
100
|
+
/** Today's defaults for the limits the server can push, before any env bound (decision 0014). */
|
|
101
|
+
capacityLimitDefaults() {
|
|
102
|
+
return {
|
|
103
|
+
maxConcurrentAttempts: this.capacityConfiguration.defaultHardMaxAttempts,
|
|
104
|
+
memoryReserveBytes: this.capacityConfiguration.adaptiveHostReserveBytes,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Decision 0014: the bridge's effective max attempts and memory reserve. They
|
|
109
|
+
* apply from the next attempt admission; admitted attempts keep their
|
|
110
|
+
* reservations and are never preempted, even when the new limit is lower than
|
|
111
|
+
* what already runs. The idle reserve follows the reserve as at startup.
|
|
112
|
+
*/
|
|
113
|
+
applyCapacityLimits(limits) {
|
|
114
|
+
const current = this.capacityConfiguration;
|
|
115
|
+
const hardMaxAttempts = Math.max(1, Math.min(32, Math.floor(limits.maxConcurrentAttempts)));
|
|
116
|
+
const hostReserveBytes = Math.max(512 * 1024 ** 2, Math.floor(limits.memoryReserveBytes));
|
|
117
|
+
if (hardMaxAttempts === current.hardMaxAttempts && hostReserveBytes === current.hostReserveBytes)
|
|
118
|
+
return;
|
|
119
|
+
this.capacityConfiguration = {
|
|
120
|
+
...current,
|
|
121
|
+
hardMaxAttempts,
|
|
122
|
+
hostReserveBytes,
|
|
123
|
+
idleHostReserveBytes: idleHostReserveBytesFor(hostReserveBytes, current),
|
|
124
|
+
};
|
|
125
|
+
// A raised limit may admit queued attempts now rather than at their next recheck.
|
|
126
|
+
this.drainAdmissionWaiters();
|
|
127
|
+
}
|
|
128
|
+
hostLoadChildEnvironment() {
|
|
129
|
+
return this.hostLoadGovernor.enabled ? hostLoadChildEnvironment(this.stateRoot) : {};
|
|
130
|
+
}
|
|
85
131
|
async reap(options) {
|
|
132
|
+
// Heavy-step tokens whose owner died or whose lease lapsed are returned first.
|
|
133
|
+
await this.hostLoadGovernor.reclaim().catch(() => undefined);
|
|
86
134
|
await this.refreshKnownPromotions();
|
|
87
135
|
const recoveredAttempts = [];
|
|
88
136
|
const report = {
|
|
@@ -207,6 +255,11 @@ export class HostRuntimeLeaseManager {
|
|
|
207
255
|
// drop that met a lingering session) are removed once no live lease holds them.
|
|
208
256
|
// A degraded lease may still own running processes after a restart, so its database is kept.
|
|
209
257
|
await this.databaseBroker?.reapOrphans(id => this.active.has(id) || this.degraded.has(id)).catch(() => undefined);
|
|
258
|
+
// Heavy-step tokens of a dead owner with no recorded process tree (an attempt that
|
|
259
|
+
// ended with a crashed bridge or MCP server) are returned once no live lease holds
|
|
260
|
+
// their attempt; a degraded lease may still own the running step, so its tokens stay.
|
|
261
|
+
await this.hostLoadGovernor.releaseOrphaned(token => !token.dispatchAttemptId
|
|
262
|
+
|| (!this.active.has(token.dispatchAttemptId) && !this.degraded.has(token.dispatchAttemptId))).catch(() => undefined);
|
|
210
263
|
return report;
|
|
211
264
|
}
|
|
212
265
|
snapshot() {
|
|
@@ -924,6 +977,15 @@ export class HostRuntimeLeaseManager {
|
|
|
924
977
|
let attemptRootIdentity = null;
|
|
925
978
|
try {
|
|
926
979
|
const runtimeContract = await loadHostRuntimeContract(normalizedWorktreePath);
|
|
980
|
+
// Decision 0013 accept-time recheck. Readiness probes are exempt: they are how the
|
|
981
|
+
// API learns the requirements in the first place.
|
|
982
|
+
const unmetRequirements = dispatch.workItem.kind === "runtime_readiness"
|
|
983
|
+
? []
|
|
984
|
+
: this.requirementsCheck?.(runtimeContract.contract.requires) ?? [];
|
|
985
|
+
if (unmetRequirements.length > 0) {
|
|
986
|
+
// Typed, so the API receives the retryable code and re-places the work (not bridge.execution_failed).
|
|
987
|
+
throw new ForgeFailureError("placement_requirements_unmet", `placement_requirements_unmet: this host does not meet the project's requirements: ${unmetRequirements.join("; ")}.`);
|
|
988
|
+
}
|
|
927
989
|
if (runtimeContract.contract.runtime.hostConcurrency === "disabled") {
|
|
928
990
|
throw new Error("host_runtime_disabled: project runtime configuration requires Docker execution.");
|
|
929
991
|
}
|
|
@@ -1088,6 +1150,8 @@ export class HostRuntimeLeaseManager {
|
|
|
1088
1150
|
parallelPromotionEligible: hostRuntimeParallelEligible(runtimeContract) && dispatch.cycleRun.phase !== "prepared_readiness",
|
|
1089
1151
|
processSupervisor,
|
|
1090
1152
|
adapterCleanups: [],
|
|
1153
|
+
adapterCleanupsByPort: new Map(),
|
|
1154
|
+
restartingConfiguredProject: false,
|
|
1091
1155
|
pendingAdapterLaunches: new Map(),
|
|
1092
1156
|
runtimeResourcesReleased: false,
|
|
1093
1157
|
releasing: false,
|
|
@@ -1150,6 +1214,15 @@ export class HostRuntimeLeaseManager {
|
|
|
1150
1214
|
await this.writeLedger(renewed);
|
|
1151
1215
|
}
|
|
1152
1216
|
async startConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
|
|
1217
|
+
return await this.launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, true);
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Launches the configured project. Only the first launch, from the admitted commit's clean
|
|
1221
|
+
* source, may record parallel-safety proof: a restart serves the workspace after the provider
|
|
1222
|
+
* edited it, and a proof observed there would be stored under the admitted commit and could
|
|
1223
|
+
* move this or a later attempt at that commit into shared admission for source it never ran.
|
|
1224
|
+
*/
|
|
1225
|
+
async launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, promote) {
|
|
1153
1226
|
const active = this.active.get(dispatchAttemptId);
|
|
1154
1227
|
if (!active || active.lease.fencingToken !== fencingToken || active.lease.state !== "active" || active.releasing) {
|
|
1155
1228
|
throw new Error("host_runtime_project_unavailable: an active matching host runtime lease is required.");
|
|
@@ -1171,6 +1244,11 @@ export class HostRuntimeLeaseManager {
|
|
|
1171
1244
|
executionClass: active.executionClass,
|
|
1172
1245
|
};
|
|
1173
1246
|
}
|
|
1247
|
+
const playwrightConfig = active.runtimeContract.contract.runtime.playwright;
|
|
1248
|
+
// A host without the project's pinned browsers fails here, before any database,
|
|
1249
|
+
// build, launch, or promotion work that the attempt would otherwise waste.
|
|
1250
|
+
if (playwrightConfig)
|
|
1251
|
+
await this.playwrightAdapter.assertBrowserCacheReady(playwrightConfig, active.lease.worktreePath);
|
|
1174
1252
|
const owner = hostPortOwner(active.lease);
|
|
1175
1253
|
const logDirectory = active.lease.resources.paths.find(entry => entry.role === "logs")?.path;
|
|
1176
1254
|
if (!logDirectory)
|
|
@@ -1196,8 +1274,9 @@ export class HostRuntimeLeaseManager {
|
|
|
1196
1274
|
data: { database: active.databaseCapability.databaseName },
|
|
1197
1275
|
});
|
|
1198
1276
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1277
|
+
const apiMasterKey = attemptApiMasterKey(active);
|
|
1278
|
+
// Runtime output is persisted to attempt logs; the database login and master key it may print are redacted.
|
|
1279
|
+
const capabilitySecrets = [...attemptDatabaseCapabilitySecrets(active.databaseCapability?.connectionString), apiMasterKey];
|
|
1201
1280
|
const launcher = new AttemptNodeRuntimeLauncher(active.processSupervisor, owner, logDirectory, this.listenerInspector, capabilitySecrets);
|
|
1202
1281
|
for (const configuredPort of configuredPorts) {
|
|
1203
1282
|
const workingDirectory = await containedWorkingDirectory(active.lease.worktreePath, configuredPort.launch.workingDirectory);
|
|
@@ -1207,7 +1286,7 @@ export class HostRuntimeLeaseManager {
|
|
|
1207
1286
|
};
|
|
1208
1287
|
const prebuild = createAspNetRuntimePrebuildPlan({
|
|
1209
1288
|
command: configuredPort.launch.command,
|
|
1210
|
-
args: configuredPort
|
|
1289
|
+
args: supervisedRuntimeLaunchArguments(configuredPort),
|
|
1211
1290
|
cwd: workingDirectory,
|
|
1212
1291
|
worktreePath: active.lease.worktreePath,
|
|
1213
1292
|
environment: buildEnvironment,
|
|
@@ -1218,9 +1297,31 @@ export class HostRuntimeLeaseManager {
|
|
|
1218
1297
|
await onProjectCheckpoint?.({
|
|
1219
1298
|
code: "host_runtime_build_started",
|
|
1220
1299
|
message: `Preparing the ASP.NET runtime for commit ${active.inputCommitSha.slice(0, 12)} before binding its assigned port.`,
|
|
1221
|
-
data: { input_commit_sha: active.inputCommitSha, project_path: prebuild.projectPath },
|
|
1300
|
+
data: { input_commit_sha: active.inputCommitSha, project_path: prebuild.projectPath, output_directory: prebuild.outputDirectory },
|
|
1222
1301
|
});
|
|
1223
|
-
|
|
1302
|
+
let hostLoadWaitMs = null;
|
|
1303
|
+
const build = await ensureAspNetRuntimePrebuilt(prebuild,
|
|
1304
|
+
// Only a real build (not a verified cache hit) takes a host load token.
|
|
1305
|
+
async (plan, buildSignal) => await runHostGovernedStep(this.hostLoadGovernor, {
|
|
1306
|
+
classification: aspNetPrebuildStepClass,
|
|
1307
|
+
label: prebuild.projectPath,
|
|
1308
|
+
dispatchAttemptId,
|
|
1309
|
+
priority: this.admissions.get(dispatchAttemptId)?.priority ?? "foreground",
|
|
1310
|
+
signal: buildSignal,
|
|
1311
|
+
onWaiting: async (decision) => await onProjectCheckpoint?.({
|
|
1312
|
+
code: "host_runtime_build_waiting_for_host_capacity",
|
|
1313
|
+
message: `The ASP.NET runtime build is waiting for host capacity: ${decision.detail}`,
|
|
1314
|
+
data: { status: "waiting_for_host_capacity", step_class: aspNetPrebuildStepClass.stepClass, reason: decision.reason },
|
|
1315
|
+
}),
|
|
1316
|
+
}, async (waitMs, control) => {
|
|
1317
|
+
hostLoadWaitMs = waitMs;
|
|
1318
|
+
// A reclaimed token stops the build: its capacity is no longer reserved. So does a
|
|
1319
|
+
// build whose process tree cannot be recorded on its token (a reclaim could not stop it).
|
|
1320
|
+
const unrecorded = new AbortController();
|
|
1321
|
+
const stepSignal = anySignal(buildSignal, control.fenced, unrecorded.signal);
|
|
1322
|
+
return await executeAspNetRuntimeBuild(active.processSupervisor, logDirectory, plan, stepSignal, capabilitySecrets, async (metadataPath) => await attachSupervisedStepProcess(control, metadataPath)
|
|
1323
|
+
.catch((error) => { unrecorded.abort(error); }));
|
|
1324
|
+
}), signal);
|
|
1224
1325
|
await onProjectCheckpoint?.({
|
|
1225
1326
|
code: build.cacheHit ? "host_runtime_build_cached" : "host_runtime_build_completed",
|
|
1226
1327
|
message: build.cacheHit
|
|
@@ -1230,19 +1331,18 @@ export class HostRuntimeLeaseManager {
|
|
|
1230
1331
|
input_commit_sha: active.inputCommitSha,
|
|
1231
1332
|
build_fingerprint: build.fingerprint,
|
|
1232
1333
|
receipt_path: build.receiptPath,
|
|
1334
|
+
...(hostLoadWaitMs === null ? {} : { host_load_wait_ms: hostLoadWaitMs }),
|
|
1233
1335
|
},
|
|
1234
1336
|
});
|
|
1235
1337
|
}
|
|
1236
1338
|
await this.launchNodeRuntime(dispatchAttemptId, fencingToken, configuredPort.name, {
|
|
1237
1339
|
command: configuredPort.launch.command,
|
|
1238
|
-
args: configuredPort
|
|
1340
|
+
args: supervisedRuntimeLaunchArguments(configuredPort),
|
|
1239
1341
|
cwd: workingDirectory,
|
|
1240
|
-
environment:
|
|
1241
|
-
...buildEnvironment,
|
|
1242
|
-
},
|
|
1342
|
+
environment: withAttemptApiMasterKey(configuredPort, buildEnvironment, apiMasterKey),
|
|
1243
1343
|
}, launcher, signal);
|
|
1244
1344
|
}
|
|
1245
|
-
const promotedLease = await this.promoteVerifiedRuntime(active, active.lease);
|
|
1345
|
+
const promotedLease = promote ? await this.promoteVerifiedRuntime(active, active.lease) : active.lease;
|
|
1246
1346
|
const runtimeEnvironment = hostRuntimeEnvironment(active.sessionId, promotedLease, active.runtimeContract, active.executionClass, active.databaseCapability);
|
|
1247
1347
|
const playwright = active.runtimeContract.contract.runtime.playwright;
|
|
1248
1348
|
if (!playwright) {
|
|
@@ -1281,6 +1381,94 @@ export class HostRuntimeLeaseManager {
|
|
|
1281
1381
|
executionClass: active.executionClass,
|
|
1282
1382
|
};
|
|
1283
1383
|
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Relaunches the configured project so it serves the current workspace. Every
|
|
1386
|
+
* configured process stops (the API port changes, so the dev server's proxy target
|
|
1387
|
+
* must change with it), its port reservation is released and dropped from the
|
|
1388
|
+
* persisted lease, and the regular start path runs again, including the ASP.NET
|
|
1389
|
+
* prebuild, whose receipt rebuilds only when the sources changed.
|
|
1390
|
+
*/
|
|
1391
|
+
async restartConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
|
|
1392
|
+
const active = this.active.get(dispatchAttemptId);
|
|
1393
|
+
if (!active || active.lease.fencingToken !== fencingToken || active.lease.state !== "active" || active.releasing) {
|
|
1394
|
+
throw new Error("host_runtime_project_unavailable: an active matching host runtime lease is required.");
|
|
1395
|
+
}
|
|
1396
|
+
if (signal?.aborted)
|
|
1397
|
+
throw new Error(String(signal.reason ?? "Host runtime restart was cancelled."));
|
|
1398
|
+
if (active.restartingConfiguredProject) {
|
|
1399
|
+
throw new Error("host_runtime_project_conflict: a configured project restart is already in progress.");
|
|
1400
|
+
}
|
|
1401
|
+
active.restartingConfiguredProject = true;
|
|
1402
|
+
// Release cancels the whole restart through this controller and waits for it to settle.
|
|
1403
|
+
const controller = linkedAbortController(signal);
|
|
1404
|
+
const promise = this.runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, controller.signal, onProjectCheckpoint);
|
|
1405
|
+
const restart = { controller, promise };
|
|
1406
|
+
active.configuredProjectRestart = restart;
|
|
1407
|
+
try {
|
|
1408
|
+
return await promise;
|
|
1409
|
+
}
|
|
1410
|
+
finally {
|
|
1411
|
+
// The controller is not aborted on settle: adapters this restart launched keep it as their
|
|
1412
|
+
// parent signal for as long as they run, exactly as they would keep the caller's signal.
|
|
1413
|
+
if (active.configuredProjectRestart === restart)
|
|
1414
|
+
active.configuredProjectRestart = null;
|
|
1415
|
+
active.restartingConfiguredProject = false;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
async runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
|
|
1419
|
+
// The relaunch keeps the admission granted at start. A workspace contract that changed only its
|
|
1420
|
+
// launch environment is adopted; any other change throws host_runtime_contract_changed.
|
|
1421
|
+
const readmitted = readmitHostRuntimeContract(active, await loadHostRuntimeContract(active.lease.worktreePath));
|
|
1422
|
+
active.runtimeContract = readmitted.runtimeContract;
|
|
1423
|
+
active.runtimeContractFingerprint = readmitted.runtimeContractFingerprint;
|
|
1424
|
+
if (readmitted.changed) {
|
|
1425
|
+
await onProjectCheckpoint?.({ code: "host_runtime_contract_readmitted", message: "The workspace's runtime contract changed only its launch environment; the restart runs it under the admission granted at start." });
|
|
1426
|
+
}
|
|
1427
|
+
const portNames = active.executionClass === "analysis_only" ? [] : configuredLaunchPortNames(active.runtimeContract);
|
|
1428
|
+
const pendingPort = portNames.find(name => active.pendingAdapterLaunches.has(name));
|
|
1429
|
+
if (pendingPort) {
|
|
1430
|
+
throw new Error(`host_runtime_project_conflict: configured port '${pendingPort}' is still launching.`);
|
|
1431
|
+
}
|
|
1432
|
+
const temporaryDirectory = active.lease.resources.paths.find(entry => entry.role === "temporary")?.path;
|
|
1433
|
+
if (active.runtimeContract.contract.runtime.playwright && temporaryDirectory) {
|
|
1434
|
+
// The generated Playwright config targets the stack being stopped. If the restart fails, no
|
|
1435
|
+
// config may be left pointing at ports another attempt can now be assigned.
|
|
1436
|
+
await this.playwrightAdapter.discardOverlay(temporaryDirectory);
|
|
1437
|
+
}
|
|
1438
|
+
await this.stopConfiguredProject(active, portNames);
|
|
1439
|
+
// Keeps whatever admission the attempt holds; see launchConfiguredProject.
|
|
1440
|
+
const restarted = await this.launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, false);
|
|
1441
|
+
if (active.releasing) {
|
|
1442
|
+
throw new Error("host_runtime_project_unavailable: the host runtime lease was released during restart.");
|
|
1443
|
+
}
|
|
1444
|
+
return restarted;
|
|
1445
|
+
}
|
|
1446
|
+
/** Stops configured project processes in reverse launch order and releases their ports. */
|
|
1447
|
+
async stopConfiguredProject(active, portNames) {
|
|
1448
|
+
const launched = active.lease.resources.ports
|
|
1449
|
+
.map(port => port.name)
|
|
1450
|
+
.filter(name => portNames.includes(name))
|
|
1451
|
+
.reverse();
|
|
1452
|
+
for (const name of launched) {
|
|
1453
|
+
if (active.releasing) {
|
|
1454
|
+
throw new Error("host_runtime_project_unavailable: the host runtime lease was released during restart.");
|
|
1455
|
+
}
|
|
1456
|
+
const cleanup = active.adapterCleanupsByPort.get(name);
|
|
1457
|
+
if (!cleanup) {
|
|
1458
|
+
throw new Error(`host_runtime_project_restart_unavailable: configured port '${name}' has no supervised process to stop.`);
|
|
1459
|
+
}
|
|
1460
|
+
// A failed stop keeps the cleanup and the port record for the fenced release retry.
|
|
1461
|
+
await cleanup();
|
|
1462
|
+
removeCleanup(active.adapterCleanups, cleanup);
|
|
1463
|
+
active.adapterCleanupsByPort.delete(name);
|
|
1464
|
+
const runtimeLease = withRuntimeIsolationResources(active.lease, {
|
|
1465
|
+
...active.lease.resources,
|
|
1466
|
+
ports: active.lease.resources.ports.filter(port => port.name !== name),
|
|
1467
|
+
});
|
|
1468
|
+
await this.writeLedger(runtimeLease);
|
|
1469
|
+
active.lease = runtimeLease;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1284
1472
|
providerProcessRunner(dispatchAttemptId, fencingToken) {
|
|
1285
1473
|
const active = this.active.get(dispatchAttemptId);
|
|
1286
1474
|
if (!active || active.lease.fencingToken !== fencingToken || active.releasing)
|
|
@@ -1368,6 +1556,7 @@ export class HostRuntimeLeaseManager {
|
|
|
1368
1556
|
unlinkAbortController(controller, signal);
|
|
1369
1557
|
};
|
|
1370
1558
|
active.adapterCleanups.push(cleanup);
|
|
1559
|
+
active.adapterCleanupsByPort.set(portName, cleanup);
|
|
1371
1560
|
try {
|
|
1372
1561
|
if (active.releasing)
|
|
1373
1562
|
throw new Error("host_runtime_adapter_cancelled: host runtime release started during launch.");
|
|
@@ -1390,6 +1579,8 @@ export class HostRuntimeLeaseManager {
|
|
|
1390
1579
|
try {
|
|
1391
1580
|
await cleanup();
|
|
1392
1581
|
removeCleanup(active.adapterCleanups, cleanup);
|
|
1582
|
+
if (active.adapterCleanupsByPort.get(portName) === cleanup)
|
|
1583
|
+
active.adapterCleanupsByPort.delete(portName);
|
|
1393
1584
|
}
|
|
1394
1585
|
catch {
|
|
1395
1586
|
// Preserve the cleanup and broker claim for the fenced release retry.
|
|
@@ -1414,6 +1605,9 @@ export class HostRuntimeLeaseManager {
|
|
|
1414
1605
|
if (!preservePreparation)
|
|
1415
1606
|
this.pendingRenewals.delete(dispatchAttemptId);
|
|
1416
1607
|
if (!active) {
|
|
1608
|
+
// Queued steps are cancelled and running ones stopped; each returns its own
|
|
1609
|
+
// token once its processes are gone (never before, or capacity is reused early).
|
|
1610
|
+
this.hostLoadGovernor.stopAttempt(dispatchAttemptId);
|
|
1417
1611
|
this.cancelAdmissionWaiters(dispatchAttemptId, fencingToken, "Managed host admission was released before acquisition.");
|
|
1418
1612
|
this.releaseSingletonKeys(dispatchAttemptId, fencingToken);
|
|
1419
1613
|
this.releaseParallelProjects(dispatchAttemptId, fencingToken);
|
|
@@ -1423,10 +1617,20 @@ export class HostRuntimeLeaseManager {
|
|
|
1423
1617
|
if (active.lease.fencingToken !== fencingToken)
|
|
1424
1618
|
return null;
|
|
1425
1619
|
active.releasing = true;
|
|
1620
|
+
// Attempt teardown cancels the attempt's queued heavy steps and stops its running
|
|
1621
|
+
// ones. Each running step (an ASP.NET prebuild, an install, a validation step)
|
|
1622
|
+
// returns its own token only after its processes have exited, so the capacity is
|
|
1623
|
+
// not reused while, say, a build is still being terminated.
|
|
1624
|
+
this.hostLoadGovernor.stopAttempt(dispatchAttemptId);
|
|
1426
1625
|
for (const pending of active.pendingAdapterLaunches.values()) {
|
|
1427
1626
|
pending.controller.abort("Host runtime release cancelled the pending adapter launch.");
|
|
1428
1627
|
}
|
|
1429
1628
|
await Promise.allSettled([...active.pendingAdapterLaunches.values()].map(pending => pending.promise));
|
|
1629
|
+
const restart = active.configuredProjectRestart;
|
|
1630
|
+
if (restart) {
|
|
1631
|
+
restart.controller.abort("Host runtime release cancelled the configured project restart.");
|
|
1632
|
+
await restart.promise.catch(() => undefined);
|
|
1633
|
+
}
|
|
1430
1634
|
await active.databaseProvision?.catch(() => undefined);
|
|
1431
1635
|
let releasing = transitionRuntimeIsolationLease(active.lease, "releasing");
|
|
1432
1636
|
active.lease = releasing;
|
|
@@ -1434,7 +1638,17 @@ export class HostRuntimeLeaseManager {
|
|
|
1434
1638
|
try {
|
|
1435
1639
|
if (!active.runtimeResourcesReleased) {
|
|
1436
1640
|
await active.processSupervisor.stopAll(fencingToken, "Host runtime lease released.");
|
|
1641
|
+
// The attempt's MCP servers and process trees are stopped now; tokens they held
|
|
1642
|
+
// belong to dead owners and go back to the host budget at once, including any
|
|
1643
|
+
// without a recorded process tree (their steps were inside the stopped trees).
|
|
1644
|
+
await this.hostLoadGovernor.reclaim().catch(() => undefined);
|
|
1645
|
+
await this.hostLoadGovernor.releaseOrphaned(token => token.dispatchAttemptId === dispatchAttemptId)
|
|
1646
|
+
.catch(() => undefined);
|
|
1647
|
+
// This bridge's own steps whose trees only stopAll could prove gone (a supervised
|
|
1648
|
+
// validation step whose termination failed earlier) return their tokens now.
|
|
1649
|
+
await this.hostLoadGovernor.releaseRetainedAfterTeardown(dispatchAttemptId).catch(() => undefined);
|
|
1437
1650
|
await releaseAdapterResources(active.adapterCleanups);
|
|
1651
|
+
active.adapterCleanupsByPort.clear();
|
|
1438
1652
|
if (active.databaseCapability && this.databaseBroker) {
|
|
1439
1653
|
// A database the broker cannot drop now is reaped later; it must not hold host capacity.
|
|
1440
1654
|
await this.databaseBroker.release(dispatchAttemptId, fencingToken).catch(() => "retained");
|
|
@@ -1532,18 +1746,46 @@ export class HostRuntimeLeaseManager {
|
|
|
1532
1746
|
if (logsEntry.kind !== "directory") {
|
|
1533
1747
|
throw new Error("host_runtime_reaper_invalid: process ownership log path is not an ordinary directory.");
|
|
1534
1748
|
}
|
|
1535
|
-
const entries = await readPinnedSourceDirectory(logsRoot, logsEntry.identity);
|
|
1536
1749
|
const outcomes = [];
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
const
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1750
|
+
const failures = [];
|
|
1751
|
+
try {
|
|
1752
|
+
const entries = await readPinnedSourceDirectory(logsRoot, logsEntry.identity);
|
|
1753
|
+
for (const entry of entries) {
|
|
1754
|
+
if (entry.kind !== "file" || !/^process-supervisor\.[a-z][a-z0-9_-]{0,31}\.\d+\.json$/u.test(entry.name))
|
|
1755
|
+
continue;
|
|
1756
|
+
const metadataPath = path.join(logsRoot, entry.name);
|
|
1757
|
+
const value = JSON.parse((await readCanonicalSourceFile(metadataPath, maximumProcessRecoveryMetadataBytes, entry.identity)).toString("utf8"));
|
|
1758
|
+
if (!validHostProcessSupervisorMetadata(value, lease)) {
|
|
1759
|
+
throw new Error("host_runtime_reaper_invalid: process ownership metadata did not match the runtime lease.");
|
|
1760
|
+
}
|
|
1761
|
+
outcomes.push(await this.processRecovery.recover(value));
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
catch (error) {
|
|
1765
|
+
failures.push(error);
|
|
1766
|
+
}
|
|
1767
|
+
// Managed commands run in their own process groups and record their ownership apart
|
|
1768
|
+
// from the attempt's supervised children. They are recovered even when recovering a
|
|
1769
|
+
// supervised child failed, and both failures are reported together.
|
|
1770
|
+
try {
|
|
1771
|
+
const managed = await terminateAttemptManagedCommands({
|
|
1772
|
+
logDirectory: logsRoot,
|
|
1773
|
+
dispatchAttemptId: lease.dispatchAttemptId,
|
|
1774
|
+
runtimeLeaseId: lease.executionLeaseId,
|
|
1775
|
+
pinnedLogDirectory: logsEntry.identity,
|
|
1776
|
+
}, { reason: "attempt_teardown" });
|
|
1777
|
+
for (const command of managed) {
|
|
1778
|
+
if (command.outcome === "terminated" || command.outcome === "pid_reused")
|
|
1779
|
+
outcomes.push(command.outcome);
|
|
1544
1780
|
}
|
|
1545
|
-
outcomes.push(await this.processRecovery.recover(value));
|
|
1546
1781
|
}
|
|
1782
|
+
catch (error) {
|
|
1783
|
+
failures.push(error);
|
|
1784
|
+
}
|
|
1785
|
+
if (failures.length === 1)
|
|
1786
|
+
throw failures[0];
|
|
1787
|
+
if (failures.length > 1)
|
|
1788
|
+
throw new AggregateError(failures, "host_runtime_reaper_recovery_failed");
|
|
1547
1789
|
return outcomes;
|
|
1548
1790
|
}
|
|
1549
1791
|
async markLedgerDegraded(ledger) {
|
|
@@ -1919,6 +2161,18 @@ class AttemptSupervisedProviderProcessRunner {
|
|
|
1919
2161
|
: new Set();
|
|
1920
2162
|
const child = await this.supervisor.startChildReady("provider", request, handlers, signal, { maxStartAttempts: request.stdin === undefined ? 1 : 3, retryDelayMs: 100 });
|
|
1921
2163
|
this.onProcessTreeStarted();
|
|
2164
|
+
try {
|
|
2165
|
+
return await this.awaitProviderResult(child, baselineListeners, signal);
|
|
2166
|
+
}
|
|
2167
|
+
finally {
|
|
2168
|
+
// The provider tree, and the MCP server inside it, is gone. A managed command that
|
|
2169
|
+
// server started now has no supervisor and no receipt writer, so it must not keep
|
|
2170
|
+
// running into the next provider generation. This never rejects; a command it
|
|
2171
|
+
// cannot prove stopped is left to attempt teardown, which fails closed.
|
|
2172
|
+
await this.supervisor.stopOrphanedManagedCommands();
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
async awaitProviderResult(child, baselineListeners, signal) {
|
|
1922
2176
|
if (!this.enforceNoListeners)
|
|
1923
2177
|
return await child.result;
|
|
1924
2178
|
let settled = false;
|
|
@@ -2094,44 +2348,36 @@ function hostRuntimeEnvironment(sessionId, lease, runtimeContract, executionClas
|
|
|
2094
2348
|
environment.FORGE_BASE_URL = resolvedBaseUrls[0];
|
|
2095
2349
|
return environment;
|
|
2096
2350
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
const
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
},
|
|
2121
|
-
}, signal, { maxStartAttempts: 2, retryDelayMs: 250 });
|
|
2122
|
-
const result = await child.result;
|
|
2123
|
-
return {
|
|
2124
|
-
exitCode: result.exitCode,
|
|
2125
|
-
stdoutTail: appendRuntimeBuildTail(stdoutTail, redactText(result.stdout, exactSecrets)),
|
|
2126
|
-
stderrTail: appendRuntimeBuildTail(stderrTail, redactText(result.stderr, exactSecrets)),
|
|
2127
|
-
stdoutLogPath,
|
|
2128
|
-
stderrLogPath,
|
|
2129
|
-
};
|
|
2351
|
+
/**
|
|
2352
|
+
* Every environment key `hostRuntimeEnvironment` and the Playwright overlay derive from the
|
|
2353
|
+
* configured project's assigned ports. They name a live stack, so they are withheld while the
|
|
2354
|
+
* stack is down: after its ports are released another attempt may be assigned them.
|
|
2355
|
+
*/
|
|
2356
|
+
export function hostRuntimeStackEnvironmentKeys(runtimeContract) {
|
|
2357
|
+
const keys = new Set([
|
|
2358
|
+
"FORGE_E2E_API_URL",
|
|
2359
|
+
"FORGE_E2E_WEB_URL",
|
|
2360
|
+
"FORGE_BASE_URL",
|
|
2361
|
+
"FORGE_PLAYWRIGHT_BASE_URL",
|
|
2362
|
+
// The generated Playwright config embeds the base URL.
|
|
2363
|
+
"FORGE_PLAYWRIGHT_CONFIG",
|
|
2364
|
+
]);
|
|
2365
|
+
for (const port of runtimeContract.contract.runtime.ports) {
|
|
2366
|
+
const normalizedName = port.name.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
|
|
2367
|
+
keys.add(port.env);
|
|
2368
|
+
if (port.baseUrlEnv)
|
|
2369
|
+
keys.add(port.baseUrlEnv);
|
|
2370
|
+
keys.add(`FORGE_${normalizedName}_PORT`);
|
|
2371
|
+
keys.add(`FORGE_${normalizedName}_URL`);
|
|
2372
|
+
}
|
|
2373
|
+
return [...keys];
|
|
2130
2374
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2375
|
+
/** The attempt's API master key: issued on first use, then the same for every relaunch of the attempt. */
|
|
2376
|
+
function attemptApiMasterKey(active) {
|
|
2377
|
+
return active.apiMasterKey ??= newAttemptApiMasterKey();
|
|
2378
|
+
}
|
|
2379
|
+
function anySignal(...signals) {
|
|
2380
|
+
return AbortSignal.any(signals.filter((signal) => signal !== undefined));
|
|
2135
2381
|
}
|
|
2136
2382
|
function effectiveHostConcurrency(lease, runtimeContract, executionClass = "managed_runtime") {
|
|
2137
2383
|
if (executionClass === "analysis_only") {
|
|
@@ -2161,7 +2407,7 @@ function runtimeExecutionClass(dispatch) {
|
|
|
2161
2407
|
? "analysis_only"
|
|
2162
2408
|
: "managed_runtime";
|
|
2163
2409
|
}
|
|
2164
|
-
function runtimeAdmissionPriority(dispatch) {
|
|
2410
|
+
export function runtimeAdmissionPriority(dispatch) {
|
|
2165
2411
|
return dispatch.execution.lane.trim().toLowerCase() === "runtime_readiness"
|
|
2166
2412
|
|| dispatch.cycleRun.phase.trim().toLowerCase() === "readiness_probe"
|
|
2167
2413
|
? "background"
|
|
@@ -2233,6 +2479,18 @@ function configuredInteger(name, fallback, minimum, maximum) {
|
|
|
2233
2479
|
const parsed = Number.parseInt(process.env[name] ?? "", 10);
|
|
2234
2480
|
return Number.isFinite(parsed) ? Math.max(minimum, Math.min(maximum, parsed)) : fallback;
|
|
2235
2481
|
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Today's max attempts and adaptive memory reserve for this host, before
|
|
2484
|
+
* FORGE_HOST_MAX_CONCURRENT_ATTEMPTS and FORGE_HOST_MEMORY_RESERVE_BYTES
|
|
2485
|
+
* (decision 0014 treats those as bounds on the server's values).
|
|
2486
|
+
*/
|
|
2487
|
+
export function hostCapacityLimitDefaults(capacityResourceSample) {
|
|
2488
|
+
const configuration = loadHostCapacityConfiguration(capacityResourceSample);
|
|
2489
|
+
return {
|
|
2490
|
+
maxConcurrentAttempts: configuration.defaultHardMaxAttempts,
|
|
2491
|
+
memoryReserveBytes: configuration.adaptiveHostReserveBytes,
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2236
2494
|
function loadHostCapacityConfiguration(capacityResourceSample) {
|
|
2237
2495
|
const sampledCpuCount = capacityResourceSample
|
|
2238
2496
|
? Math.max(1, Math.floor(capacityResourceSample.totalCpuMillis / 1_000))
|
|
@@ -2240,23 +2498,41 @@ function loadHostCapacityConfiguration(capacityResourceSample) {
|
|
|
2240
2498
|
const totalMemoryBytes = capacityResourceSample?.totalMemoryBytes ?? os.totalmem();
|
|
2241
2499
|
const reserveFloorBytes = configuredInteger("FORGE_HOST_MEMORY_RESERVE_FLOOR_BYTES", 1024 ** 3, 512 * 1024 ** 2, 128 * 1024 ** 3);
|
|
2242
2500
|
const reserveCeilingBytes = configuredInteger("FORGE_HOST_MEMORY_RESERVE_CEILING_BYTES", 4 * 1024 ** 3, reserveFloorBytes, 128 * 1024 ** 3);
|
|
2243
|
-
const
|
|
2244
|
-
explicitBytes: configuredOptionalInteger("FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * 1024 ** 2, 128 * 1024 ** 3),
|
|
2501
|
+
const adaptiveOptions = {
|
|
2245
2502
|
floorBytes: reserveFloorBytes,
|
|
2246
2503
|
ceilingBytes: reserveCeilingBytes,
|
|
2247
2504
|
percent: configuredNumber("FORGE_HOST_MEMORY_RESERVE_PERCENT", 12.5, 1, 50),
|
|
2505
|
+
};
|
|
2506
|
+
const hostReserveBytes = resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, {
|
|
2507
|
+
...adaptiveOptions,
|
|
2508
|
+
explicitBytes: configuredOptionalInteger("FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * 1024 ** 2, 128 * 1024 ** 3),
|
|
2248
2509
|
});
|
|
2249
|
-
const
|
|
2510
|
+
const defaultHardMaxAttempts = Math.max(1, Math.min(8, Math.floor(sampledCpuCount / 2)));
|
|
2511
|
+
const idleReserveOverride = Number.parseInt(process.env.FORGE_HOST_IDLE_MEMORY_RESERVE_BYTES ?? "", 10);
|
|
2512
|
+
const idleReserveOverrideBytes = Number.isFinite(idleReserveOverride) ? idleReserveOverride : null;
|
|
2250
2513
|
return {
|
|
2251
|
-
hardMaxAttempts: configuredInteger("FORGE_HOST_MAX_CONCURRENT_ATTEMPTS",
|
|
2514
|
+
hardMaxAttempts: configuredInteger("FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", defaultHardMaxAttempts, 1, 32),
|
|
2252
2515
|
hostReserveBytes,
|
|
2253
|
-
idleHostReserveBytes:
|
|
2516
|
+
idleHostReserveBytes: idleHostReserveBytesFor(hostReserveBytes, { reserveFloorBytes, idleReserveOverrideBytes }),
|
|
2517
|
+
defaultHardMaxAttempts,
|
|
2518
|
+
adaptiveHostReserveBytes: resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, adaptiveOptions),
|
|
2519
|
+
reserveFloorBytes,
|
|
2520
|
+
idleReserveOverrideBytes,
|
|
2254
2521
|
cpuReserveMillis: configuredInteger("FORGE_HOST_CPU_RESERVE_MILLIS", 1000, 0, 32_000),
|
|
2255
2522
|
workspaceReserveBytes: configuredInteger("FORGE_HOST_WORKSPACE_RESERVE_BYTES", 10 * 1024 ** 3, 1024 ** 3, Number.MAX_SAFE_INTEGER),
|
|
2256
2523
|
memoryRecoverySamples: configuredInteger("FORGE_HOST_MEMORY_RECOVERY_SAMPLES", 2, 1, 10),
|
|
2257
2524
|
memoryRecoverySampleIntervalMs: configuredInteger("FORGE_HOST_MEMORY_RECOVERY_SAMPLE_INTERVAL_MS", 1_000, 100, 30_000),
|
|
2258
2525
|
};
|
|
2259
2526
|
}
|
|
2527
|
+
/**
|
|
2528
|
+
* The reserve kept while no attempt holds capacity: FORGE_HOST_IDLE_MEMORY_RESERVE_BYTES
|
|
2529
|
+
* clamped to [512 MiB, reserve], else min(reserve, reserve floor). Never above the reserve.
|
|
2530
|
+
*/
|
|
2531
|
+
function idleHostReserveBytesFor(hostReserveBytes, configuration) {
|
|
2532
|
+
const fallback = Math.min(hostReserveBytes, configuration.reserveFloorBytes);
|
|
2533
|
+
const override = configuration.idleReserveOverrideBytes;
|
|
2534
|
+
return override === null ? fallback : Math.max(512 * 1024 ** 2, Math.min(hostReserveBytes, override));
|
|
2535
|
+
}
|
|
2260
2536
|
function configuredOptionalInteger(name, minimum, maximum) {
|
|
2261
2537
|
const raw = process.env[name];
|
|
2262
2538
|
if (raw === undefined || raw.trim().length === 0)
|