@loucompanion/forge-bridge 0.1.4-dev.4677bbd22f17 → 0.1.4-dev.60e18c3cfec6
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 +33 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +72 -1
- package/dist/bridge/bridge.service.js +308 -9
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-load-admission.d.ts +60 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +67 -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 +43 -0
- package/dist/runtime/host-load-governor-config.js +76 -0
- package/dist/runtime/host-load-governor.d.ts +174 -0
- package/dist/runtime/host-load-governor.js +541 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +43 -0
- package/dist/runtime/host-load-sampler.js +74 -6
- package/dist/runtime/host-load-step-class.d.ts +68 -0
- package/dist/runtime/host-load-step-class.js +106 -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-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -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 +3 -0
- package/dist/runtime/host-runtime-contract.js +4 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +279 -10
- package/dist/runtime/host-runtime-promotion.js +12 -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/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -0
- package/dist/session/managed-attempt-tools.js +156 -37
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -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 +94 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +49 -19
- 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 +184 -209
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- 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-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +9 -9
- package/dist/session/pre-publication-validation.js +21 -55
- package/dist/session/provider-cli/provider-cli.process.js +2 -2
- package/dist/session/provider-cli/provider-cli.prompts.js +5 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.service.js +132 -14
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +229 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +3 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -3,11 +3,13 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
5
5
|
import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
|
|
6
|
-
import {
|
|
6
|
+
import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
|
|
7
|
+
import { managedAttemptInvocation, supportsNativeTestPostgresFallback, validationExecutionForStep, } from "./pre-publication-step-execution.js";
|
|
7
8
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
8
9
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
9
10
|
import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
|
|
10
11
|
import { ProcessPrePublicationCommandRunner, pnpmDirectoryLaunch } from "./pre-publication-process.js";
|
|
12
|
+
import { ProcessTreeTerminationError } from "../shared/process/process.js";
|
|
11
13
|
import { findUnreferencedNewExports } from "./unreferenced-exports.js";
|
|
12
14
|
import { ForgeFailureError, sanitizeFailureError, } from "./session.types.js";
|
|
13
15
|
const contractRelativePath = ".forge/validation/ci-parity.v1.json";
|
|
@@ -84,10 +86,12 @@ export class PrePublicationValidator {
|
|
|
84
86
|
commands;
|
|
85
87
|
dockerEngineProbe;
|
|
86
88
|
nativeTestPostgresFallback;
|
|
87
|
-
|
|
89
|
+
hostLoad;
|
|
90
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad) {
|
|
88
91
|
this.commands = commands;
|
|
89
92
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
90
93
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
94
|
+
this.hostLoad = hostLoad;
|
|
91
95
|
}
|
|
92
96
|
async validate(worktreePath, profile, capabilities, emit, signal, execution) {
|
|
93
97
|
const checksExports = profile === "implementation" || profile === "comment_repair";
|
|
@@ -130,11 +134,11 @@ export class PrePublicationValidator {
|
|
|
130
134
|
let skipped = { count: 0, reasons: [] };
|
|
131
135
|
for (const step of check.steps) {
|
|
132
136
|
const stepStartedMs = Date.now() - 1000;
|
|
133
|
-
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
137
|
+
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
134
138
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
135
139
|
if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
|
|
136
140
|
await emit?.(validationEvent("prepublication_validation_timeout_confirmation_started", check.id, "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment."));
|
|
137
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
141
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
138
142
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
139
143
|
await emit?.(validationEvent(result.exitCode === 0
|
|
140
144
|
? "prepublication_validation_timeout_confirmation_passed"
|
|
@@ -144,7 +148,7 @@ export class PrePublicationValidator {
|
|
|
144
148
|
}
|
|
145
149
|
if (isTransientBridgeCleanupFailure(check.id, step, result)) {
|
|
146
150
|
await emit?.(validationEvent("prepublication_validation_cleanup_confirmation_started", check.id, "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment."));
|
|
147
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
151
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
148
152
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
149
153
|
await emit?.(validationEvent(result.exitCode === 0
|
|
150
154
|
? "prepublication_validation_cleanup_confirmation_passed"
|
|
@@ -154,7 +158,7 @@ export class PrePublicationValidator {
|
|
|
154
158
|
}
|
|
155
159
|
if (isTransientShellInfrastructureFailure(result)) {
|
|
156
160
|
await emit?.(validationEvent("prepublication_infrastructure_confirmation_started", check.id, "The validation shell reported a known host-runtime failure; confirming once with the same command and attempt environment."));
|
|
157
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
161
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
158
162
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
159
163
|
const infrastructureFailed = isTransientShellInfrastructureFailure(result);
|
|
160
164
|
await emit?.(validationEvent(infrastructureFailed
|
|
@@ -213,7 +217,7 @@ export class PrePublicationValidator {
|
|
|
213
217
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
214
218
|
if (!snapshot.available) {
|
|
215
219
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
216
|
-
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check)
|
|
220
|
+
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check.id)
|
|
217
221
|
? this.nativeTestPostgresFallback()
|
|
218
222
|
: null;
|
|
219
223
|
if (fallback) {
|
|
@@ -299,8 +303,14 @@ export class PrePublicationValidator {
|
|
|
299
303
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
|
|
300
304
|
}
|
|
301
305
|
}
|
|
302
|
-
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection) {
|
|
306
|
+
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
|
|
303
307
|
const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
|
|
308
|
+
// Every launch, including confirmation reruns, is admitted by the host load governor first.
|
|
309
|
+
return await runHostGovernedValidationStep(this.hostLoad, {
|
|
310
|
+
checkId, command: invocation.command, args: invocation.args, owner: execution?.hostLoadOwner, signal, emit,
|
|
311
|
+
}, async (stepSignal) => await this.launchStep(checkId, step, invocation, cwd, stepSignal, execution, postgresAdminConnection));
|
|
312
|
+
}
|
|
313
|
+
async launchStep(checkId, step, invocation, cwd, signal, execution, postgresAdminConnection) {
|
|
304
314
|
const stepExecution = validationExecutionForStep(checkId, step, execution, postgresAdminConnection);
|
|
305
315
|
const before = await readValidationFiles(cwd, step.assertUnchangedPaths ?? []);
|
|
306
316
|
const result = await this.runCommand(invocation.command, invocation.args, cwd, signal, stepExecution);
|
|
@@ -345,57 +355,13 @@ export class PrePublicationValidator {
|
|
|
345
355
|
};
|
|
346
356
|
}
|
|
347
357
|
catch (error) {
|
|
358
|
+
// Carries the check its host capacity token waits on; it names only the executable.
|
|
359
|
+
if (error instanceof ProcessTreeTerminationError)
|
|
360
|
+
throw error;
|
|
348
361
|
throw sanitizeFailureError(error, exactSecrets);
|
|
349
362
|
}
|
|
350
363
|
}
|
|
351
364
|
}
|
|
352
|
-
function managedAttemptInvocation(checkId, step, environment) {
|
|
353
|
-
const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
|
|
354
|
-
const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
|
|
355
|
-
|| Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
|
|
356
|
-
if (checkId !== "playwright-e2e" || !attemptOwned) {
|
|
357
|
-
return step;
|
|
358
|
-
}
|
|
359
|
-
if (!playwrightConfig) {
|
|
360
|
-
throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
|
|
361
|
-
}
|
|
362
|
-
return {
|
|
363
|
-
command: "pnpm",
|
|
364
|
-
args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const nativeFallbackCheckIds = new Set([
|
|
368
|
-
"owned-suite-registration",
|
|
369
|
-
"dotnet-build-and-unit",
|
|
370
|
-
"comment-repair-dotnet-regression",
|
|
371
|
-
]);
|
|
372
|
-
const nativeFallbackDotnetTierScripts = [
|
|
373
|
-
"scripts/run-dotnet-test-tier.ps1",
|
|
374
|
-
"scripts/run-dotnet-test-tier-set.ps1",
|
|
375
|
-
"scripts/run-affected-dotnet-tests.mjs",
|
|
376
|
-
];
|
|
377
|
-
function supportsNativeTestPostgresFallback(check) {
|
|
378
|
-
return nativeFallbackCheckIds.has(check.id);
|
|
379
|
-
}
|
|
380
|
-
function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
381
|
-
// The connection only exists when Docker is unavailable and the operator
|
|
382
|
-
// provisioned a dedicated native test cluster. Only the runner-authored
|
|
383
|
-
// .NET test tiers and the suite-identity check receive it; build, client,
|
|
384
|
-
// Bridge, and E2E steps never do.
|
|
385
|
-
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
386
|
-
return execution;
|
|
387
|
-
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
388
|
-
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
389
|
-
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
390
|
-
return execution;
|
|
391
|
-
return {
|
|
392
|
-
...execution,
|
|
393
|
-
environment: {
|
|
394
|
-
...execution?.environment,
|
|
395
|
-
...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
|
|
396
|
-
},
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
365
|
function environmentValue(environment, name) {
|
|
400
366
|
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
401
367
|
? environment?.[name]?.trim() ?? ""
|
|
@@ -379,7 +379,7 @@ export class StreamingProviderProcessRunner {
|
|
|
379
379
|
const childStderr = child.stderr;
|
|
380
380
|
if (!childStdout || !childStderr) {
|
|
381
381
|
const pipeError = new Error("Provider process stdout/stderr streams were not piped.");
|
|
382
|
-
void terminate().then(() => reject(pipeError), terminationError => reject(new AggregateError([pipeError, terminationError], "Provider launch failed and its process tree could not be proven stopped.")));
|
|
382
|
+
void terminate().then(() => reject(pipeError), terminationError => reject(new AggregateError([pipeError, terminationError], "host_process_supervisor_termination_failed: Provider launch failed and its process tree could not be proven stopped.")));
|
|
383
383
|
return;
|
|
384
384
|
}
|
|
385
385
|
const stdout = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
@@ -415,7 +415,7 @@ export class StreamingProviderProcessRunner {
|
|
|
415
415
|
cleanup();
|
|
416
416
|
// Do not release the caller's reservation/worktree/port ownership until
|
|
417
417
|
// descendant termination has completed (or failed with explicit proof).
|
|
418
|
-
void terminate().then(() => reject(error), terminationError => reject(new AggregateError([error, terminationError], "Provider process failed and its process tree could not be proven stopped.")));
|
|
418
|
+
void terminate().then(() => reject(error), terminationError => reject(new AggregateError([error, terminationError], "host_process_supervisor_termination_failed: Provider process failed and its process tree could not be proven stopped.")));
|
|
419
419
|
};
|
|
420
420
|
const abort = () => {
|
|
421
421
|
if (!closed)
|
|
@@ -278,7 +278,10 @@ function buildRuntimeContextPrompt(dispatch, prompt, runtimeEnvironment) {
|
|
|
278
278
|
? "- `FORGE_HOST_CONCURRENCY=host_parallel_safe` means Forge verified this contract's assigned-port probe and gave this attempt independent ports, paths, and process supervisors. Do not share or discover another attempt's runtime resources."
|
|
279
279
|
: "- `FORGE_HOST_CONCURRENCY=host_serial_only` means Forge holds the runner-local project singleton named by `FORGE_SINGLETON_KEYS`; do not bypass or release it yourself.";
|
|
280
280
|
const playwright = runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
281
|
-
? "\n- For Playwright, use the generated `FORGE_PLAYWRIGHT_CONFIG`; it targets this attempt's verified `FORGE_PLAYWRIGHT_BASE_URL`, disables project `webServer` startup/reuse, and writes under `FORGE_TEST_OUTPUT_DIR`. Do not invoke the project Playwright config directly."
|
|
281
|
+
? "\n- For Playwright, use the generated `FORGE_PLAYWRIGHT_CONFIG`; it targets this attempt's verified `FORGE_PLAYWRIGHT_BASE_URL`, disables project `webServer` startup/reuse, and writes under `FORGE_TEST_OUTPUT_DIR`. Do not invoke the project Playwright config directly. Run `playwright test --config <absolute value of FORGE_PLAYWRIGHT_CONFIG>` from the Playwright project directory through `forge.start_managed_command` (in Forge: command `pnpm`, args `[\"--dir\", \"tests/e2e\", \"exec\", \"playwright\", \"test\", \"--config\", \"<path>\"]`), and append spec file paths such as `specs/<name>.spec.ts` to run only the specs you are working on. Repository wrappers that start their own disposable stack, such as Forge's `pnpm --dir tests/e2e test`, refuse to run inside a managed attempt; Forge-owned pre-publication still runs the full suite."
|
|
282
|
+
: "";
|
|
283
|
+
const stackUnavailable = runtimeEnvironment?.FORGE_RUNTIME_STACK === "unavailable"
|
|
284
|
+
? "\n- `FORGE_RUNTIME_STACK=unavailable` means Forge's restart of this attempt's application stack failed, so no attempt-owned API, web, or Playwright URLs are supplied for this turn. Do not reuse URLs or ports from an earlier turn or start the stack yourself; fix the source so the restart succeeds. Forge restarts the stack and reruns validation after this turn."
|
|
282
285
|
: "";
|
|
283
286
|
return `${prompt.trimEnd()}
|
|
284
287
|
|
|
@@ -292,7 +295,7 @@ ${concurrency}
|
|
|
292
295
|
- If a tool creates \`TestResults\`, \`test-results\`, or \`playwright-report\` beneath source, use \`forge.reset_generated_outputs\` to quarantine only those untracked generated directories. Do not issue a recursive delete.
|
|
293
296
|
- Use the attempt-scoped \`FORGE_TMPDIR\`, \`FORGE_LOG_DIR\`, \`FORGE_CACHE_DIR\`, \`FORGE_BROWSER_PROFILE_DIR\`, and \`FORGE_TEST_OUTPUT_DIR\` paths instead of shared host paths.
|
|
294
297
|
- Use supplied \`FORGE_*\` URLs, ports, and paths. Do not search for a free port, kill a process occupying one, or reuse an existing dev server, browser profile, database, container, network, or volume.
|
|
295
|
-
- Never run broad process or Docker cleanup. Stop only resources you created for this resource lease.${playwright}`;
|
|
298
|
+
- Never run broad process or Docker cleanup. Stop only resources you created for this resource lease.${playwright}${stackUnavailable}`;
|
|
296
299
|
}
|
|
297
300
|
return `${prompt.trimEnd()}
|
|
298
301
|
|
|
@@ -67,4 +67,10 @@ export declare class ProcessBackedProviderCliService implements ProviderCliServi
|
|
|
67
67
|
private recoverMissingQaCompletion;
|
|
68
68
|
private recoverMissingCommentRepairCompletion;
|
|
69
69
|
private validatePrePublicationWithRecovery;
|
|
70
|
+
/**
|
|
71
|
+
* Restarts the attempt's runtime stack when the workspace changed since it was
|
|
72
|
+
* launched, before a validation pass runs against it. A build of the changed
|
|
73
|
+
* source that fails is a validation failure the bounded repair turn can fix.
|
|
74
|
+
*/
|
|
75
|
+
private refreshPrePublicationRuntime;
|
|
70
76
|
}
|
|
@@ -2,6 +2,9 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { RepositoryCoordinatorLock } from "../../sandbox/repository-lock.js";
|
|
4
4
|
import { GitClient } from "../../shared/git/git.js";
|
|
5
|
+
import { HostPortCollisionError } from "../../runtime/host-port-broker.js";
|
|
6
|
+
import { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
|
|
7
|
+
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
5
8
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
6
9
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
7
10
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
@@ -213,16 +216,20 @@ function providerOwnsBranchPublication(context) {
|
|
|
213
216
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
214
217
|
}
|
|
215
218
|
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
219
|
+
const hostLoadOwner = {
|
|
220
|
+
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
221
|
+
priority: runtimeAdmissionPriority(context.dispatch),
|
|
222
|
+
};
|
|
216
223
|
if (context.processRunner)
|
|
217
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
224
|
+
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
218
225
|
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
219
|
-
return { baselineRevision, environment };
|
|
226
|
+
return { baselineRevision, environment, hostLoadOwner };
|
|
220
227
|
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
221
228
|
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
222
229
|
if (observedSandboxId !== expectedSandboxId) {
|
|
223
230
|
throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
|
|
224
231
|
}
|
|
225
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
232
|
+
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
226
233
|
}
|
|
227
234
|
function remoteTrackingRefspec(branchName) {
|
|
228
235
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
@@ -432,7 +439,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
432
439
|
}
|
|
433
440
|
}
|
|
434
441
|
function isManagedVerificationNonterminal(status) {
|
|
435
|
-
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
442
|
+
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
443
|
+
|| status === "waiting_for_host_capacity";
|
|
436
444
|
}
|
|
437
445
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
438
446
|
try {
|
|
@@ -564,7 +572,12 @@ export class ProcessBackedProviderCliService {
|
|
|
564
572
|
providerToolHeartbeatIntervalMs;
|
|
565
573
|
publicationCoordinator;
|
|
566
574
|
prePublicationValidator;
|
|
567
|
-
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
575
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
576
|
+
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
577
|
+
// this default. A container cannot reach the host ledger, so when the host
|
|
578
|
+
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
579
|
+
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
580
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment())) {
|
|
568
581
|
this.processRunner = processRunner;
|
|
569
582
|
this.git = git;
|
|
570
583
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
@@ -583,7 +596,7 @@ export class ProcessBackedProviderCliService {
|
|
|
583
596
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
584
597
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
585
598
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
586
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment });
|
|
599
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
587
600
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
588
601
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
589
602
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -766,7 +779,7 @@ export class ProcessBackedProviderCliService {
|
|
|
766
779
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
767
780
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
768
781
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
769
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment });
|
|
782
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
770
783
|
const implementationPrompt = debugCycle
|
|
771
784
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
772
785
|
: developCycle
|
|
@@ -914,7 +927,7 @@ export class ProcessBackedProviderCliService {
|
|
|
914
927
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
915
928
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
916
929
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "pending_approval", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
917
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment });
|
|
930
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
918
931
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
919
932
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
920
933
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -1019,7 +1032,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1019
1032
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1020
1033
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1021
1034
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
1022
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment });
|
|
1035
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
1023
1036
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
1024
1037
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
1025
1038
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -1139,6 +1152,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1139
1152
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1140
1153
|
let repairSpec = null;
|
|
1141
1154
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1155
|
+
let ciRepairSpecPath = null;
|
|
1142
1156
|
let completionTools = null;
|
|
1143
1157
|
if (repairChecks) {
|
|
1144
1158
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1149,6 +1163,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1149
1163
|
}
|
|
1150
1164
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1151
1165
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1166
|
+
ciRepairSpecPath = specPath;
|
|
1152
1167
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1153
1168
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1154
1169
|
repairSpec = {
|
|
@@ -1160,7 +1175,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1160
1175
|
};
|
|
1161
1176
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1162
1177
|
repairEnvironment = readiness.environment;
|
|
1163
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1178
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1179
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1180
|
+
});
|
|
1164
1181
|
await context.emit({
|
|
1165
1182
|
role: "runner",
|
|
1166
1183
|
kind: "checkpoint",
|
|
@@ -1175,7 +1192,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1175
1192
|
});
|
|
1176
1193
|
}
|
|
1177
1194
|
if (addressComments) {
|
|
1178
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1195
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1196
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1197
|
+
});
|
|
1179
1198
|
await context.emit({
|
|
1180
1199
|
role: "runner",
|
|
1181
1200
|
kind: "checkpoint",
|
|
@@ -1299,6 +1318,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1299
1318
|
: addressComments
|
|
1300
1319
|
? "comment_repair"
|
|
1301
1320
|
: "conflict_repair";
|
|
1321
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1302
1322
|
await this.validatePrePublicationWithRecovery({
|
|
1303
1323
|
context,
|
|
1304
1324
|
validationProfile,
|
|
@@ -1306,6 +1326,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1306
1326
|
outputState,
|
|
1307
1327
|
preparedHeadSha,
|
|
1308
1328
|
repairScope: "pull_request",
|
|
1329
|
+
...(readinessSpecPath ? {
|
|
1330
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1331
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1332
|
+
} : {}),
|
|
1309
1333
|
});
|
|
1310
1334
|
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1311
1335
|
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
@@ -1384,6 +1408,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1384
1408
|
worktree,
|
|
1385
1409
|
phase: "qa",
|
|
1386
1410
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1411
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1387
1412
|
});
|
|
1388
1413
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1389
1414
|
worktreePath: worktree.worktreePath,
|
|
@@ -1493,6 +1518,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1493
1518
|
worktree,
|
|
1494
1519
|
phase: "comment_repair",
|
|
1495
1520
|
runtimeEnvironment: repairEnvironment,
|
|
1521
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1496
1522
|
});
|
|
1497
1523
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1498
1524
|
worktreePath: worktree.worktreePath,
|
|
@@ -1572,13 +1598,23 @@ export class ProcessBackedProviderCliService {
|
|
|
1572
1598
|
return artifact;
|
|
1573
1599
|
}
|
|
1574
1600
|
async validatePrePublicationWithRecovery(options) {
|
|
1575
|
-
const { context, validationProfile,
|
|
1601
|
+
const { context, validationProfile, outputState, preparedHeadSha, repairScope } = options;
|
|
1576
1602
|
const { dispatch, worktree } = context;
|
|
1577
1603
|
const processRunner = recoveringProviderProcessRunner(context.processRunner ?? this.processRunner);
|
|
1578
|
-
|
|
1579
|
-
|
|
1604
|
+
// A runtime restart assigns new ports, so every environment derived from it is refreshed with it.
|
|
1605
|
+
let repairEnvironment = options.repairEnvironment;
|
|
1606
|
+
let environment = providerProcessEnv(dispatch, repairEnvironment);
|
|
1607
|
+
let validationEnvironment = prePublicationValidationEnv(dispatch, repairEnvironment);
|
|
1580
1608
|
for (let repairTurn = 0;; repairTurn += 1) {
|
|
1581
1609
|
try {
|
|
1610
|
+
const refreshed = await this.refreshPrePublicationRuntime(context, validationProfile, repairTurn);
|
|
1611
|
+
if (refreshed) {
|
|
1612
|
+
repairEnvironment = options.onRuntimeEnvironmentRefreshed
|
|
1613
|
+
? await options.onRuntimeEnvironmentRefreshed(refreshed)
|
|
1614
|
+
: refreshed;
|
|
1615
|
+
environment = providerProcessEnv(dispatch, repairEnvironment);
|
|
1616
|
+
validationEnvironment = prePublicationValidationEnv(dispatch, repairEnvironment);
|
|
1617
|
+
}
|
|
1582
1618
|
await this.prePublicationValidator.validate(worktree.worktreePath, validationProfile, publicationCapabilities(context, repairEnvironment), context.emit, context.signal, prePublicationExecution(context, validationEnvironment, this.processRunner, preparedHeadSha));
|
|
1583
1619
|
if (repairTurn > 0) {
|
|
1584
1620
|
await context.emit({
|
|
@@ -1594,6 +1630,17 @@ export class ProcessBackedProviderCliService {
|
|
|
1594
1630
|
catch (error) {
|
|
1595
1631
|
if (!(error instanceof PrePublicationValidationError))
|
|
1596
1632
|
throw error;
|
|
1633
|
+
if (error.checkId === runtimeRestartCheckId) {
|
|
1634
|
+
// The restart stopped the stack and released its ports before it failed, so the URLs the
|
|
1635
|
+
// repair turn would inherit name ports another attempt may now hold. The turn runs without
|
|
1636
|
+
// them; the next pass restarts the stack and supplies fresh ones.
|
|
1637
|
+
const unavailable = withoutRuntimeStack(repairEnvironment, context.runtimeStackEnvironmentKeys ?? []);
|
|
1638
|
+
repairEnvironment = options.onRuntimeEnvironmentRefreshed
|
|
1639
|
+
? await options.onRuntimeEnvironmentRefreshed(unavailable)
|
|
1640
|
+
: unavailable;
|
|
1641
|
+
environment = providerProcessEnv(dispatch, repairEnvironment);
|
|
1642
|
+
validationEnvironment = prePublicationValidationEnv(dispatch, repairEnvironment);
|
|
1643
|
+
}
|
|
1597
1644
|
if (repairTurn >= maxPrePublicationRepairTurns) {
|
|
1598
1645
|
await context.emit({
|
|
1599
1646
|
role: "runner",
|
|
@@ -1677,6 +1724,77 @@ export class ProcessBackedProviderCliService {
|
|
|
1677
1724
|
}
|
|
1678
1725
|
}
|
|
1679
1726
|
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Restarts the attempt's runtime stack when the workspace changed since it was
|
|
1729
|
+
* launched, before a validation pass runs against it. A build of the changed
|
|
1730
|
+
* source that fails is a validation failure the bounded repair turn can fix.
|
|
1731
|
+
*/
|
|
1732
|
+
async refreshPrePublicationRuntime(context, validationProfile, repairTurn) {
|
|
1733
|
+
if (!context.refreshRuntimeEnvironment)
|
|
1734
|
+
return null;
|
|
1735
|
+
let refreshed;
|
|
1736
|
+
try {
|
|
1737
|
+
refreshed = await context.refreshRuntimeEnvironment(context.signal);
|
|
1738
|
+
}
|
|
1739
|
+
catch (error) {
|
|
1740
|
+
// A restart that fails to build, start or become ready reflects the changed source, which a
|
|
1741
|
+
// bounded repair turn can fix; the next pass restarts again. Cancellation, a released lease
|
|
1742
|
+
// and a changed runtime contract still end the attempt.
|
|
1743
|
+
if (restartFailureForRepair(error)) {
|
|
1744
|
+
throw new PrePublicationValidationError(runtimeRestartCheckId, 1, "forge-host-runtime-restart", [],
|
|
1745
|
+
// The session's host_runtime_restart_started event records why it restarted.
|
|
1746
|
+
`Forge restarted the attempt runtime stack before validation, and the restart failed: ${error.message}`);
|
|
1747
|
+
}
|
|
1748
|
+
throw error;
|
|
1749
|
+
}
|
|
1750
|
+
if (!refreshed)
|
|
1751
|
+
return null;
|
|
1752
|
+
const { environment: restarted, reason, changes } = refreshed;
|
|
1753
|
+
const apiUrl = restarted.FORGE_E2E_API_URL ?? restarted.FORGE_API_URL ?? null;
|
|
1754
|
+
const webUrl = restarted.FORGE_E2E_WEB_URL ?? restarted.FORGE_WEB_URL ?? restarted.FORGE_PLAYWRIGHT_BASE_URL ?? null;
|
|
1755
|
+
await context.emit({
|
|
1756
|
+
role: "runner",
|
|
1757
|
+
kind: "checkpoint",
|
|
1758
|
+
content: `Restarted the attempt runtime stack before pre-publication validation because ${restartReasonText[reason]}; validation${repairTurn > 0 ? " and repair turns" : ""} now use${apiUrl ? ` API ${apiUrl}` : " the refreshed runtime URLs"}${webUrl ? ` and web ${webUrl}` : ""}.`,
|
|
1759
|
+
eventType: "prepublication_runtime_restarted",
|
|
1760
|
+
data: JSON.stringify({
|
|
1761
|
+
reason,
|
|
1762
|
+
changes,
|
|
1763
|
+
validationProfile,
|
|
1764
|
+
repairTurn,
|
|
1765
|
+
apiUrl,
|
|
1766
|
+
webUrl,
|
|
1767
|
+
}),
|
|
1768
|
+
});
|
|
1769
|
+
return restarted;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
const restartReasonText = {
|
|
1773
|
+
previous_restart_incomplete: "the previous restart did not complete",
|
|
1774
|
+
fingerprint_unavailable: "the workspace state could not be compared with the stack's",
|
|
1775
|
+
workspace_changed: "the workspace changed since it was launched",
|
|
1776
|
+
};
|
|
1777
|
+
const runtimeRestartCheckId = "host-runtime-restart";
|
|
1778
|
+
/** The environment with the runtime stack's URLs and ports withheld and the stack marked unavailable. */
|
|
1779
|
+
function withoutRuntimeStack(environment, stackKeys) {
|
|
1780
|
+
const remaining = { ...(environment ?? {}) };
|
|
1781
|
+
for (const key of stackKeys)
|
|
1782
|
+
delete remaining[key];
|
|
1783
|
+
remaining.FORGE_RUNTIME_STACK = "unavailable";
|
|
1784
|
+
return remaining;
|
|
1785
|
+
}
|
|
1786
|
+
const restartFailuresForRepair = new Set([
|
|
1787
|
+
"host_runtime_project_start_failed",
|
|
1788
|
+
"host_runtime_process_exited",
|
|
1789
|
+
"host_runtime_listener_timeout",
|
|
1790
|
+
"host_runtime_http_readiness_timeout",
|
|
1791
|
+
"host_port_collision",
|
|
1792
|
+
]);
|
|
1793
|
+
function restartFailureForRepair(error) {
|
|
1794
|
+
if (error instanceof ForgeFailureError)
|
|
1795
|
+
return restartFailuresForRepair.has(error.failureCode);
|
|
1796
|
+
// The port broker throws an untyped collision once its launch retries are exhausted.
|
|
1797
|
+
return error instanceof HostPortCollisionError;
|
|
1680
1798
|
}
|
|
1681
1799
|
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1682
1800
|
const invocation = [error.command, ...error.args].join(" ");
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec } from "../session.types.js";
|
|
2
2
|
import type { WorktreeHandle } from "../../worktree/worktree.types.js";
|
|
3
3
|
import type { ProviderProcessRunner } from "./provider-cli.process.js";
|
|
4
|
+
/**
|
|
5
|
+
* Why the attempt's runtime stack restarted before a validation pass. The first cause that applies:
|
|
6
|
+
* a previous restart did not complete; the workspace state could not be compared with the stack's
|
|
7
|
+
* (either reading was unavailable); or the workspace changed since the stack was launched.
|
|
8
|
+
*/
|
|
9
|
+
export type RuntimeRestartReason = "previous_restart_incomplete" | "fingerprint_unavailable" | "workspace_changed";
|
|
10
|
+
export interface RuntimeEnvironmentRefresh {
|
|
11
|
+
/** The restarted stack's runtime environment. */
|
|
12
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
13
|
+
readonly reason: RuntimeRestartReason;
|
|
14
|
+
/** What changed in the workspace since the stack was launched, when both states could be read. */
|
|
15
|
+
readonly changes: readonly string[];
|
|
16
|
+
}
|
|
4
17
|
export interface ProviderCliRunContext {
|
|
5
18
|
readonly dispatch: RunOnceDispatchPacket;
|
|
6
19
|
readonly worktree: WorktreeHandle;
|
|
7
20
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
21
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
22
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
8
23
|
readonly processRunner?: ProviderProcessRunner;
|
|
9
24
|
readonly signal?: AbortSignal;
|
|
25
|
+
/**
|
|
26
|
+
* Restarts the attempt's host runtime stack when the workspace changed since it was
|
|
27
|
+
* launched (an uncommitted edit, an in-progress merge), so validation and repair
|
|
28
|
+
* turns run against the current source. Resolves to the refreshed runtime
|
|
29
|
+
* environment and why the stack restarted, or null when the stack is current or
|
|
30
|
+
* there is no configured project.
|
|
31
|
+
*/
|
|
32
|
+
refreshRuntimeEnvironment?(signal?: AbortSignal): Promise<RuntimeEnvironmentRefresh | null>;
|
|
33
|
+
/**
|
|
34
|
+
* The runtime environment keys that name the configured project's live stack (its URLs and
|
|
35
|
+
* ports). A failed restart withholds them from the repair turn, since the stack is down.
|
|
36
|
+
*/
|
|
37
|
+
readonly runtimeStackEnvironmentKeys?: readonly string[];
|
|
10
38
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
11
39
|
}
|
|
12
40
|
export interface ProviderCliDraftContext {
|
|
13
41
|
readonly dispatch: RunOnceDispatchPacket;
|
|
14
42
|
readonly worktree: WorktreeHandle;
|
|
15
43
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
44
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
45
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
16
46
|
readonly processRunner?: ProviderProcessRunner;
|
|
17
47
|
readonly signal?: AbortSignal;
|
|
18
48
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type HostLoadAcquireOptions, type HostLoadAdmission, type HostLoadStepGate, type HostLoadStepRequest } from "../runtime/host-load-governor.js";
|
|
2
|
+
export interface SandboxHostCapacityGateOptions {
|
|
3
|
+
readonly write?: (line: string) => void;
|
|
4
|
+
readonly responseRoot?: string;
|
|
5
|
+
readonly pollMs?: number;
|
|
6
|
+
/** Fails closed if the bridge never answers (the host enforces its own maximum wait first). */
|
|
7
|
+
readonly maxWaitMs?: number;
|
|
8
|
+
/** Owner of authentic replies (root in the container; tests use their own uid). */
|
|
9
|
+
readonly trustedOwnerUid?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class SandboxBrokeredHostLoadGate implements HostLoadStepGate {
|
|
12
|
+
readonly enabled = true;
|
|
13
|
+
private readonly write;
|
|
14
|
+
private readonly responseRoot;
|
|
15
|
+
private readonly pollMs;
|
|
16
|
+
private readonly trustedOwnerUid;
|
|
17
|
+
readonly maxWaitMs: number;
|
|
18
|
+
constructor(options?: SandboxHostCapacityGateOptions);
|
|
19
|
+
acquire(request: HostLoadStepRequest, options?: HostLoadAcquireOptions): Promise<HostLoadAdmission>;
|
|
20
|
+
private admission;
|
|
21
|
+
private send;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The brokered gate when the host bridge enabled it for this sandbox. The
|
|
25
|
+
* variable is removed once read, so commands the sandbox runs never inherit it
|
|
26
|
+
* (a nested Forge process must not queue behind its parent's token).
|
|
27
|
+
*/
|
|
28
|
+
export declare function sandboxHostLoadGateFromEnvironment(environment?: NodeJS.ProcessEnv): HostLoadStepGate | undefined;
|
|
29
|
+
/** Test support: forgets the cached gate. */
|
|
30
|
+
export declare function resetSandboxHostLoadGateForTesting(): void;
|