@loucompanion/forge-bridge 0.1.4-dev.04a1e5b9e484 → 0.1.4-dev.19e5db286f12
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 +3 -3
- package/dist/bridge/bridge.service.d.ts +12 -1
- package/dist/bridge/bridge.service.js +55 -8
- package/dist/bridge/bridge.types.d.ts +6 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/cli/cli.help.js +2 -2
- package/dist/cli/cli.service.js +3 -1
- package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
- package/dist/runtime/attempt-process-supervisor.js +50 -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 +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +52 -0
- package/dist/runtime/host-load-admission.js +84 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +8 -0
- package/dist/runtime/host-load-forge-cgroups.js +51 -0
- package/dist/runtime/host-load-governor-config.d.ts +34 -0
- package/dist/runtime/host-load-governor-config.js +46 -0
- package/dist/runtime/host-load-governor.d.ts +123 -0
- package/dist/runtime/host-load-governor.js +415 -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-sampler.d.ts +121 -0
- package/dist/runtime/host-load-sampler.js +224 -0
- package/dist/runtime/host-load-step-class.d.ts +33 -0
- package/dist/runtime/host-load-step-class.js +46 -0
- package/dist/runtime/host-load-token-ledger.d.ts +135 -0
- package/dist/runtime/host-load-token-ledger.js +345 -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 +1 -0
- package/dist/runtime/host-runtime-contract.js +2 -0
- package/dist/runtime/host-runtime-lease.d.ts +7 -1
- package/dist/runtime/host-runtime-lease.js +67 -11
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- 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 +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/session/managed-attempt-tools.d.ts +25 -0
- package/dist/session/managed-attempt-tools.js +212 -15
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.runtime.js +22 -17
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +96 -0
- package/dist/session/pre-publication-process.d.ts +20 -0
- package/dist/session/pre-publication-process.js +97 -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 +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 +44 -112
- 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.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 +37 -1
- package/dist/session/provider-cli/provider-cli.process.js +297 -23
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +15 -0
- package/dist/session/provider-cli/provider-cli.service.js +126 -26
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/session.types.js +13 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.js +74 -0
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ import { hostPortEnvironment, loadHostRuntimeContract, } from "./host-runtime-co
|
|
|
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";
|
|
@@ -29,6 +30,8 @@ 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
32
|
import { createAspNetRuntimePrebuildPlan, ensureAspNetRuntimePrebuilt, resolveWorktreeCommitSha, } from "./aspnet-runtime-prebuild.js";
|
|
33
|
+
import { HostLoadGovernor } from "./host-load-governor.js";
|
|
34
|
+
import { HostLoadSampler } from "./host-load-sampler.js";
|
|
32
35
|
const hostCapacityWaiterScanLimit = 64;
|
|
33
36
|
const maximumProcessRecoveryMetadataBytes = 1024 * 1024;
|
|
34
37
|
export class HostRuntimeLeaseManager {
|
|
@@ -63,7 +66,9 @@ export class HostRuntimeLeaseManager {
|
|
|
63
66
|
capacityConfiguration;
|
|
64
67
|
memoryAvailability;
|
|
65
68
|
executionRoot;
|
|
66
|
-
|
|
69
|
+
/** Host-wide admission for heavy steps (decision 0013); inert unless FORGE_HOST_LOAD_GOVERNOR=on. */
|
|
70
|
+
hostLoadGovernor;
|
|
71
|
+
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
72
|
this.stateRoot = stateRoot;
|
|
68
73
|
this.processSupervisors = processSupervisors;
|
|
69
74
|
this.processRunner = processRunner;
|
|
@@ -73,6 +78,7 @@ export class HostRuntimeLeaseManager {
|
|
|
73
78
|
this.processRecovery = processRecovery;
|
|
74
79
|
this.capacityResourceSample = capacityResourceSample;
|
|
75
80
|
this.databaseBroker = databaseBroker;
|
|
81
|
+
this.hostLoadGovernor = new HostLoadGovernor({ stateRoot, load: hostLoad ?? new HostLoadSampler() });
|
|
76
82
|
this.executionRoot = path.resolve(executionRoot ?? stateRoot);
|
|
77
83
|
if (executionRoot !== undefined)
|
|
78
84
|
assertHostExecutionRoot(this.executionRoot);
|
|
@@ -83,6 +89,8 @@ export class HostRuntimeLeaseManager {
|
|
|
83
89
|
this.memoryAvailability = new RecoveryStabilizedMemory(this.capacityConfiguration.memoryRecoverySamples, this.capacityConfiguration.memoryRecoverySampleIntervalMs);
|
|
84
90
|
}
|
|
85
91
|
async reap(options) {
|
|
92
|
+
// Heavy-step tokens whose owner died or whose lease lapsed are returned first.
|
|
93
|
+
await this.hostLoadGovernor.reclaim().catch(() => undefined);
|
|
86
94
|
await this.refreshKnownPromotions();
|
|
87
95
|
const recoveredAttempts = [];
|
|
88
96
|
const report = {
|
|
@@ -1171,6 +1179,11 @@ export class HostRuntimeLeaseManager {
|
|
|
1171
1179
|
executionClass: active.executionClass,
|
|
1172
1180
|
};
|
|
1173
1181
|
}
|
|
1182
|
+
const playwrightConfig = active.runtimeContract.contract.runtime.playwright;
|
|
1183
|
+
// A host without the project's pinned browsers fails here, before any database,
|
|
1184
|
+
// build, launch, or promotion work that the attempt would otherwise waste.
|
|
1185
|
+
if (playwrightConfig)
|
|
1186
|
+
await this.playwrightAdapter.assertBrowserCacheReady(playwrightConfig, active.lease.worktreePath);
|
|
1174
1187
|
const owner = hostPortOwner(active.lease);
|
|
1175
1188
|
const logDirectory = active.lease.resources.paths.find(entry => entry.role === "logs")?.path;
|
|
1176
1189
|
if (!logDirectory)
|
|
@@ -1414,6 +1427,7 @@ export class HostRuntimeLeaseManager {
|
|
|
1414
1427
|
if (!preservePreparation)
|
|
1415
1428
|
this.pendingRenewals.delete(dispatchAttemptId);
|
|
1416
1429
|
if (!active) {
|
|
1430
|
+
await this.hostLoadGovernor.releaseAttempt(dispatchAttemptId).catch(() => undefined);
|
|
1417
1431
|
this.cancelAdmissionWaiters(dispatchAttemptId, fencingToken, "Managed host admission was released before acquisition.");
|
|
1418
1432
|
this.releaseSingletonKeys(dispatchAttemptId, fencingToken);
|
|
1419
1433
|
this.releaseParallelProjects(dispatchAttemptId, fencingToken);
|
|
@@ -1423,6 +1437,8 @@ export class HostRuntimeLeaseManager {
|
|
|
1423
1437
|
if (active.lease.fencingToken !== fencingToken)
|
|
1424
1438
|
return null;
|
|
1425
1439
|
active.releasing = true;
|
|
1440
|
+
// Attempt teardown returns the attempt's heavy-step tokens and cancels its queued steps.
|
|
1441
|
+
await this.hostLoadGovernor.releaseAttempt(dispatchAttemptId).catch(() => undefined);
|
|
1426
1442
|
for (const pending of active.pendingAdapterLaunches.values()) {
|
|
1427
1443
|
pending.controller.abort("Host runtime release cancelled the pending adapter launch.");
|
|
1428
1444
|
}
|
|
@@ -1532,18 +1548,46 @@ export class HostRuntimeLeaseManager {
|
|
|
1532
1548
|
if (logsEntry.kind !== "directory") {
|
|
1533
1549
|
throw new Error("host_runtime_reaper_invalid: process ownership log path is not an ordinary directory.");
|
|
1534
1550
|
}
|
|
1535
|
-
const entries = await readPinnedSourceDirectory(logsRoot, logsEntry.identity);
|
|
1536
1551
|
const outcomes = [];
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
const
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1552
|
+
const failures = [];
|
|
1553
|
+
try {
|
|
1554
|
+
const entries = await readPinnedSourceDirectory(logsRoot, logsEntry.identity);
|
|
1555
|
+
for (const entry of entries) {
|
|
1556
|
+
if (entry.kind !== "file" || !/^process-supervisor\.[a-z][a-z0-9_-]{0,31}\.\d+\.json$/u.test(entry.name))
|
|
1557
|
+
continue;
|
|
1558
|
+
const metadataPath = path.join(logsRoot, entry.name);
|
|
1559
|
+
const value = JSON.parse((await readCanonicalSourceFile(metadataPath, maximumProcessRecoveryMetadataBytes, entry.identity)).toString("utf8"));
|
|
1560
|
+
if (!validHostProcessSupervisorMetadata(value, lease)) {
|
|
1561
|
+
throw new Error("host_runtime_reaper_invalid: process ownership metadata did not match the runtime lease.");
|
|
1562
|
+
}
|
|
1563
|
+
outcomes.push(await this.processRecovery.recover(value));
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
catch (error) {
|
|
1567
|
+
failures.push(error);
|
|
1568
|
+
}
|
|
1569
|
+
// Managed commands run in their own process groups and record their ownership apart
|
|
1570
|
+
// from the attempt's supervised children. They are recovered even when recovering a
|
|
1571
|
+
// supervised child failed, and both failures are reported together.
|
|
1572
|
+
try {
|
|
1573
|
+
const managed = await terminateAttemptManagedCommands({
|
|
1574
|
+
logDirectory: logsRoot,
|
|
1575
|
+
dispatchAttemptId: lease.dispatchAttemptId,
|
|
1576
|
+
runtimeLeaseId: lease.executionLeaseId,
|
|
1577
|
+
pinnedLogDirectory: logsEntry.identity,
|
|
1578
|
+
}, { reason: "attempt_teardown" });
|
|
1579
|
+
for (const command of managed) {
|
|
1580
|
+
if (command.outcome === "terminated" || command.outcome === "pid_reused")
|
|
1581
|
+
outcomes.push(command.outcome);
|
|
1544
1582
|
}
|
|
1545
|
-
outcomes.push(await this.processRecovery.recover(value));
|
|
1546
1583
|
}
|
|
1584
|
+
catch (error) {
|
|
1585
|
+
failures.push(error);
|
|
1586
|
+
}
|
|
1587
|
+
if (failures.length === 1)
|
|
1588
|
+
throw failures[0];
|
|
1589
|
+
if (failures.length > 1)
|
|
1590
|
+
throw new AggregateError(failures, "host_runtime_reaper_recovery_failed");
|
|
1547
1591
|
return outcomes;
|
|
1548
1592
|
}
|
|
1549
1593
|
async markLedgerDegraded(ledger) {
|
|
@@ -1919,6 +1963,18 @@ class AttemptSupervisedProviderProcessRunner {
|
|
|
1919
1963
|
: new Set();
|
|
1920
1964
|
const child = await this.supervisor.startChildReady("provider", request, handlers, signal, { maxStartAttempts: request.stdin === undefined ? 1 : 3, retryDelayMs: 100 });
|
|
1921
1965
|
this.onProcessTreeStarted();
|
|
1966
|
+
try {
|
|
1967
|
+
return await this.awaitProviderResult(child, baselineListeners, signal);
|
|
1968
|
+
}
|
|
1969
|
+
finally {
|
|
1970
|
+
// The provider tree, and the MCP server inside it, is gone. A managed command that
|
|
1971
|
+
// server started now has no supervisor and no receipt writer, so it must not keep
|
|
1972
|
+
// running into the next provider generation. This never rejects; a command it
|
|
1973
|
+
// cannot prove stopped is left to attempt teardown, which fails closed.
|
|
1974
|
+
await this.supervisor.stopOrphanedManagedCommands();
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
async awaitProviderResult(child, baselineListeners, signal) {
|
|
1922
1978
|
if (!this.enforceNoListeners)
|
|
1923
1979
|
return await child.result;
|
|
1924
1980
|
let settled = false;
|
|
@@ -2161,7 +2217,7 @@ function runtimeExecutionClass(dispatch) {
|
|
|
2161
2217
|
? "analysis_only"
|
|
2162
2218
|
: "managed_runtime";
|
|
2163
2219
|
}
|
|
2164
|
-
function runtimeAdmissionPriority(dispatch) {
|
|
2220
|
+
export function runtimeAdmissionPriority(dispatch) {
|
|
2165
2221
|
return dispatch.execution.lane.trim().toLowerCase() === "runtime_readiness"
|
|
2166
2222
|
|| dispatch.cycleRun.phase.trim().toLowerCase() === "readiness_probe"
|
|
2167
2223
|
? "background"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PinnedDirectoryIdentity } from "./pinned-directory-process.js";
|
|
2
|
+
/**
|
|
3
|
+
* Why Forge stopped a managed command that had not finished:
|
|
4
|
+
* - `owner_exited`: the provider process whose MCP server started it has exited, so no
|
|
5
|
+
* process is left to supervise it or write its receipt.
|
|
6
|
+
* - `attempt_teardown`: the dispatch attempt is being torn down.
|
|
7
|
+
*/
|
|
8
|
+
export type ManagedCommandTeardownReason = "owner_exited" | "attempt_teardown";
|
|
9
|
+
export interface ManagedCommandTeardownScope {
|
|
10
|
+
/** The attempt's private FORGE_LOG_DIR; managed commands record ownership under it. */
|
|
11
|
+
readonly logDirectory: string;
|
|
12
|
+
readonly dispatchAttemptId: string;
|
|
13
|
+
readonly runtimeLeaseId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Reads the ownership records through pinned directory and file identities instead of
|
|
16
|
+
* pathnames. Restart recovery supplies the verified identity of the attempt's logs.
|
|
17
|
+
*/
|
|
18
|
+
readonly pinnedLogDirectory?: PinnedDirectoryIdentity;
|
|
19
|
+
}
|
|
20
|
+
export interface ManagedCommandTeardownOptions {
|
|
21
|
+
readonly reason: ManagedCommandTeardownReason;
|
|
22
|
+
/**
|
|
23
|
+
* Stop only commands whose owning MCP server process is gone. A command whose owner is
|
|
24
|
+
* alive is still supervised by it and must survive wait slices and MCP call boundaries.
|
|
25
|
+
*/
|
|
26
|
+
readonly onlyOrphaned?: boolean;
|
|
27
|
+
readonly graceMs?: number;
|
|
28
|
+
readonly platform?: NodeJS.Platform;
|
|
29
|
+
}
|
|
30
|
+
export type ManagedCommandTeardownOutcomeKind =
|
|
31
|
+
/** The recorded process tree had already exited. */
|
|
32
|
+
"absent"
|
|
33
|
+
/** Forge stopped the recorded process tree and proved it gone. */
|
|
34
|
+
| "terminated"
|
|
35
|
+
/** The recorded root PID now names another process, so the recorded tree is gone. */
|
|
36
|
+
| "pid_reused"
|
|
37
|
+
/** The command's owning MCP server is alive and still supervises it. */
|
|
38
|
+
| "owner_alive"
|
|
39
|
+
/** The command finished on its own; nothing was signalled or rewritten. */
|
|
40
|
+
| "already_terminal"
|
|
41
|
+
/** The command never recorded a process: it was queued, or its launch was interrupted. */
|
|
42
|
+
| "no_process_record";
|
|
43
|
+
export interface ManagedCommandTeardownOutcome {
|
|
44
|
+
readonly commandId: string;
|
|
45
|
+
readonly outcome: ManagedCommandTeardownOutcomeKind;
|
|
46
|
+
readonly receiptFinalized: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** Test support: points the Linux process inventory at another directory (null restores /proc). */
|
|
49
|
+
export declare function setManagedCommandProcRootForTesting(root: string | null): void;
|
|
50
|
+
/**
|
|
51
|
+
* Stops managed commands that an attempt's MCP servers started and proves their process
|
|
52
|
+
* trees are gone. Managed commands run in their own process group (Unix) or Job Object
|
|
53
|
+
* (Windows), outside the provider tree that the attempt supervisor stops, so stopping the
|
|
54
|
+
* provider alone leaves them running. Each command's durable receipt is given a terminal
|
|
55
|
+
* status when its owner can no longer write one.
|
|
56
|
+
*
|
|
57
|
+
* Every signal is fenced: the recorded root must still carry the recorded birth identity
|
|
58
|
+
* and, on Linux, this command's supervisor and attempt identity in its environment. A
|
|
59
|
+
* tree that cannot be proven to be the command's own fails the teardown instead of being
|
|
60
|
+
* reported stopped.
|
|
61
|
+
*/
|
|
62
|
+
export declare function terminateAttemptManagedCommands(scope: ManagedCommandTeardownScope, options: ManagedCommandTeardownOptions): Promise<readonly ManagedCommandTeardownOutcome[]>;
|