@loucompanion/forge-bridge 0.1.3-dev.8687c5099dce → 0.1.3-dev.88e93f53db5b
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 +18 -1
- package/dist/bridge/bridge.base.d.ts +2 -0
- package/dist/bridge/bridge.service.d.ts +25 -1
- package/dist/bridge/bridge.service.js +341 -74
- package/dist/bridge/bridge.types.d.ts +4 -0
- package/dist/cleanup/cleanup.service.d.ts +1 -0
- package/dist/cleanup/cleanup.service.js +70 -9
- package/dist/cli/cli.service.js +9 -4
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +340 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +5 -1
- package/dist/runtime/attempt-process-supervisor.d.ts +11 -0
- package/dist/runtime/attempt-process-supervisor.js +36 -2
- package/dist/runtime/host-listener-inspector.d.ts +2 -0
- package/dist/runtime/host-listener-inspector.js +25 -0
- package/dist/runtime/host-runtime-lease.d.ts +66 -5
- package/dist/runtime/host-runtime-lease.js +714 -38
- package/dist/runtime/memory-capacity.d.ts +68 -0
- package/dist/runtime/memory-capacity.js +121 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +24 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +1 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +5 -0
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/repository-lock.js +4 -2
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/session/managed-attempt-tools.d.ts +7 -1
- package/dist/session/managed-attempt-tools.js +257 -13
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +105 -0
- package/dist/session/managed-build-receipt.d.ts +21 -0
- package/dist/session/managed-build-receipt.js +335 -0
- package/dist/session/phase-completion.artifacts.d.ts +17 -0
- package/dist/session/phase-completion.artifacts.js +224 -22
- package/dist/session/phase-completion.prompts.js +2 -2
- package/dist/session/phase-completion.runtime.js +10 -3
- package/dist/session/phase-completion.schemas.js +1 -1
- package/dist/session/phase-completion.validation.js +7 -3
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +6 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +12 -2
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +37 -3
- package/dist/session/provider-cli/provider-cli.process.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.process.js +218 -17
- package/dist/session/provider-cli/provider-cli.prompts.js +17 -4
- package/dist/session/provider-cli/provider-cli.runtime.js +3 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +5 -2
- package/dist/session/provider-cli/provider-cli.service.js +83 -34
- package/dist/session/provider-cli/provider-output-state.js +61 -14
- package/dist/session/provider-cli/provider-usage.d.ts +7 -0
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/session-redaction.js +16 -1
- package/dist/session/session.service.js +81 -9
- package/dist/session/session.types.d.ts +15 -0
- package/dist/session/session.types.js +3 -1
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/host-process-supervisor.d.ts +2 -0
- package/dist/shared/process/host-process-supervisor.js +57 -9
- package/dist/shared/redaction/redaction.js +6 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +18 -0
- package/dist/worktree/dependency-warmer.js +218 -8
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/worktree.service.d.ts +2 -0
- package/dist/worktree/worktree.service.js +158 -17
- package/dist/worktree/worktree.types.d.ts +2 -0
- package/package.json +3 -2
- package/runtime/windows-job-supervisor.ps1 +89 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare const memoryAdmissionPolicyVersion = "memory-admission-v1";
|
|
2
|
+
export declare const memoryAdmissionEquation = "max(0, min(stabilized_available - reserve - pending_commitment, total - reserve - committed))";
|
|
3
|
+
export interface MemoryAdmissionDiagnostics {
|
|
4
|
+
readonly policyVersion: string;
|
|
5
|
+
readonly sampledAt: string;
|
|
6
|
+
readonly totalMemoryBytes: number;
|
|
7
|
+
readonly rawAvailableMemoryBytes: number;
|
|
8
|
+
readonly stabilizedAvailableMemoryBytes: number;
|
|
9
|
+
readonly reclaimableMemoryBytes: number | null;
|
|
10
|
+
readonly reclaimableMemorySource: "not_sampled_separately";
|
|
11
|
+
readonly controlPlaneMemoryBytes: number;
|
|
12
|
+
readonly reserveMemoryBytes: number;
|
|
13
|
+
readonly committedMemoryBytes: number;
|
|
14
|
+
readonly pendingCommitmentMemoryBytes: number;
|
|
15
|
+
readonly availableForAdmissionBytes: number;
|
|
16
|
+
readonly requestedMemoryBytes: number | null;
|
|
17
|
+
readonly shortfallMemoryBytes: number | null;
|
|
18
|
+
readonly decision: "snapshot" | "admitted" | "denied";
|
|
19
|
+
readonly equation: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MemoryAdmissionInputs {
|
|
22
|
+
readonly sampledAt: string;
|
|
23
|
+
readonly totalMemoryBytes: number;
|
|
24
|
+
readonly rawAvailableMemoryBytes: number;
|
|
25
|
+
readonly stabilizedAvailableMemoryBytes: number;
|
|
26
|
+
readonly controlPlaneMemoryBytes: number;
|
|
27
|
+
readonly reserveMemoryBytes: number;
|
|
28
|
+
/** Ambient host use plus every committed Forge request, including pending requests. */
|
|
29
|
+
readonly committedMemoryBytes: number;
|
|
30
|
+
/** Commitments not yet reflected in the OS available-memory sample. */
|
|
31
|
+
readonly pendingCommitmentMemoryBytes: number;
|
|
32
|
+
readonly requestedMemoryBytes?: number | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One memory admission equation for Docker and managed-host capacity. The raw
|
|
36
|
+
* OS/daemon sample already reflects resident active children, so only pending
|
|
37
|
+
* commitments are charged against sampled headroom. The total-memory ceiling
|
|
38
|
+
* independently charges every commitment and prevents reservation overcommit.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildMemoryAdmissionDiagnostics(inputs: MemoryAdmissionInputs): MemoryAdmissionDiagnostics;
|
|
41
|
+
export interface AdaptiveMemoryReserveOptions {
|
|
42
|
+
readonly explicitBytes?: number | null;
|
|
43
|
+
readonly floorBytes?: number | null;
|
|
44
|
+
readonly ceilingBytes?: number | null;
|
|
45
|
+
readonly percent?: number | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Derives a host safety reserve from the capacity domain it protects. An
|
|
49
|
+
* explicit operator value remains authoritative; otherwise the reserve scales
|
|
50
|
+
* with the sampled total inside conservative floors and ceilings.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveAdaptiveMemoryReserveBytes(totalMemoryBytes: number, options?: AdaptiveMemoryReserveOptions): number;
|
|
53
|
+
/**
|
|
54
|
+
* Applies pressure immediately while requiring durable recovery samples before
|
|
55
|
+
* increasing advertised capacity. This prevents one GC/cache sample from
|
|
56
|
+
* waking queued work and then immediately withdrawing the same capacity.
|
|
57
|
+
*/
|
|
58
|
+
export declare class RecoveryStabilizedMemory {
|
|
59
|
+
private readonly requiredRecoverySamples;
|
|
60
|
+
private readonly minimumRecoverySampleIntervalMs;
|
|
61
|
+
private stableBytes;
|
|
62
|
+
private recoveryFloorBytes;
|
|
63
|
+
private recoverySamples;
|
|
64
|
+
private lastRecoverySampleAt;
|
|
65
|
+
constructor(requiredRecoverySamples?: number, minimumRecoverySampleIntervalMs?: number);
|
|
66
|
+
observe(rawAvailableBytes: number, sampledAt?: number): number;
|
|
67
|
+
private resetRecovery;
|
|
68
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const GiB = 1024 ** 3;
|
|
2
|
+
export const memoryAdmissionPolicyVersion = "memory-admission-v1";
|
|
3
|
+
export const memoryAdmissionEquation = "max(0, min(stabilized_available - reserve - pending_commitment, total - reserve - committed))";
|
|
4
|
+
/**
|
|
5
|
+
* One memory admission equation for Docker and managed-host capacity. The raw
|
|
6
|
+
* OS/daemon sample already reflects resident active children, so only pending
|
|
7
|
+
* commitments are charged against sampled headroom. The total-memory ceiling
|
|
8
|
+
* independently charges every commitment and prevents reservation overcommit.
|
|
9
|
+
*/
|
|
10
|
+
export function buildMemoryAdmissionDiagnostics(inputs) {
|
|
11
|
+
const totalMemoryBytes = nonNegativeInteger(inputs.totalMemoryBytes);
|
|
12
|
+
const rawAvailableMemoryBytes = nonNegativeInteger(inputs.rawAvailableMemoryBytes);
|
|
13
|
+
const stabilizedAvailableMemoryBytes = nonNegativeInteger(inputs.stabilizedAvailableMemoryBytes);
|
|
14
|
+
const reserveMemoryBytes = nonNegativeInteger(inputs.reserveMemoryBytes);
|
|
15
|
+
const committedMemoryBytes = nonNegativeInteger(inputs.committedMemoryBytes);
|
|
16
|
+
const pendingCommitmentMemoryBytes = Math.min(committedMemoryBytes, nonNegativeInteger(inputs.pendingCommitmentMemoryBytes));
|
|
17
|
+
const requestedMemoryBytes = inputs.requestedMemoryBytes == null
|
|
18
|
+
? null
|
|
19
|
+
: nonNegativeInteger(inputs.requestedMemoryBytes);
|
|
20
|
+
const availableForAdmissionBytes = Math.max(0, Math.min(stabilizedAvailableMemoryBytes - reserveMemoryBytes - pendingCommitmentMemoryBytes, totalMemoryBytes - reserveMemoryBytes - committedMemoryBytes));
|
|
21
|
+
const shortfallMemoryBytes = requestedMemoryBytes === null
|
|
22
|
+
? null
|
|
23
|
+
: Math.max(0, requestedMemoryBytes - availableForAdmissionBytes);
|
|
24
|
+
return {
|
|
25
|
+
policyVersion: memoryAdmissionPolicyVersion,
|
|
26
|
+
sampledAt: inputs.sampledAt,
|
|
27
|
+
totalMemoryBytes,
|
|
28
|
+
rawAvailableMemoryBytes,
|
|
29
|
+
stabilizedAvailableMemoryBytes,
|
|
30
|
+
reclaimableMemoryBytes: null,
|
|
31
|
+
reclaimableMemorySource: "not_sampled_separately",
|
|
32
|
+
controlPlaneMemoryBytes: nonNegativeInteger(inputs.controlPlaneMemoryBytes),
|
|
33
|
+
reserveMemoryBytes,
|
|
34
|
+
committedMemoryBytes,
|
|
35
|
+
pendingCommitmentMemoryBytes,
|
|
36
|
+
availableForAdmissionBytes,
|
|
37
|
+
requestedMemoryBytes,
|
|
38
|
+
shortfallMemoryBytes,
|
|
39
|
+
decision: requestedMemoryBytes === null
|
|
40
|
+
? "snapshot"
|
|
41
|
+
: shortfallMemoryBytes === 0 ? "admitted" : "denied",
|
|
42
|
+
equation: memoryAdmissionEquation,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Derives a host safety reserve from the capacity domain it protects. An
|
|
47
|
+
* explicit operator value remains authoritative; otherwise the reserve scales
|
|
48
|
+
* with the sampled total inside conservative floors and ceilings.
|
|
49
|
+
*/
|
|
50
|
+
export function resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, options = {}) {
|
|
51
|
+
const explicit = positiveInteger(options.explicitBytes);
|
|
52
|
+
if (explicit !== null)
|
|
53
|
+
return explicit;
|
|
54
|
+
const total = Math.max(0, finiteInteger(totalMemoryBytes));
|
|
55
|
+
const floor = positiveInteger(options.floorBytes) ?? GiB;
|
|
56
|
+
const ceiling = Math.max(floor, positiveInteger(options.ceilingBytes) ?? 4 * GiB);
|
|
57
|
+
const percent = positiveNumber(options.percent) ?? 12.5;
|
|
58
|
+
const proportional = Math.floor(total * Math.min(50, percent) / 100);
|
|
59
|
+
return Math.max(floor, Math.min(ceiling, proportional));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Applies pressure immediately while requiring durable recovery samples before
|
|
63
|
+
* increasing advertised capacity. This prevents one GC/cache sample from
|
|
64
|
+
* waking queued work and then immediately withdrawing the same capacity.
|
|
65
|
+
*/
|
|
66
|
+
export class RecoveryStabilizedMemory {
|
|
67
|
+
requiredRecoverySamples;
|
|
68
|
+
minimumRecoverySampleIntervalMs;
|
|
69
|
+
stableBytes = null;
|
|
70
|
+
recoveryFloorBytes = null;
|
|
71
|
+
recoverySamples = 0;
|
|
72
|
+
lastRecoverySampleAt = null;
|
|
73
|
+
constructor(requiredRecoverySamples = 2, minimumRecoverySampleIntervalMs = 1_000) {
|
|
74
|
+
this.requiredRecoverySamples = requiredRecoverySamples;
|
|
75
|
+
this.minimumRecoverySampleIntervalMs = minimumRecoverySampleIntervalMs;
|
|
76
|
+
}
|
|
77
|
+
observe(rawAvailableBytes, sampledAt = Date.now()) {
|
|
78
|
+
const observed = Math.max(0, finiteInteger(rawAvailableBytes));
|
|
79
|
+
if (this.stableBytes === null) {
|
|
80
|
+
this.stableBytes = observed;
|
|
81
|
+
return observed;
|
|
82
|
+
}
|
|
83
|
+
if (observed <= this.stableBytes) {
|
|
84
|
+
this.stableBytes = observed;
|
|
85
|
+
this.resetRecovery();
|
|
86
|
+
return observed;
|
|
87
|
+
}
|
|
88
|
+
this.recoveryFloorBytes = this.recoveryFloorBytes === null
|
|
89
|
+
? observed
|
|
90
|
+
: Math.min(this.recoveryFloorBytes, observed);
|
|
91
|
+
if (this.lastRecoverySampleAt !== null
|
|
92
|
+
&& sampledAt - this.lastRecoverySampleAt < Math.max(0, this.minimumRecoverySampleIntervalMs)) {
|
|
93
|
+
return this.stableBytes;
|
|
94
|
+
}
|
|
95
|
+
this.recoverySamples += 1;
|
|
96
|
+
this.lastRecoverySampleAt = sampledAt;
|
|
97
|
+
if (this.recoverySamples < Math.max(1, this.requiredRecoverySamples)) {
|
|
98
|
+
return this.stableBytes;
|
|
99
|
+
}
|
|
100
|
+
this.stableBytes = this.recoveryFloorBytes ?? this.stableBytes;
|
|
101
|
+
this.resetRecovery();
|
|
102
|
+
return this.stableBytes;
|
|
103
|
+
}
|
|
104
|
+
resetRecovery() {
|
|
105
|
+
this.recoveryFloorBytes = null;
|
|
106
|
+
this.recoverySamples = 0;
|
|
107
|
+
this.lastRecoverySampleAt = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function finiteInteger(value) {
|
|
111
|
+
return Number.isFinite(value) ? Math.floor(value) : 0;
|
|
112
|
+
}
|
|
113
|
+
function positiveInteger(value) {
|
|
114
|
+
return Number.isFinite(value) && value > 0 ? Math.floor(value) : null;
|
|
115
|
+
}
|
|
116
|
+
function positiveNumber(value) {
|
|
117
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
118
|
+
}
|
|
119
|
+
function nonNegativeInteger(value) {
|
|
120
|
+
return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
|
|
121
|
+
}
|
|
@@ -23,9 +23,11 @@ export interface NodeRuntimeReadinessDiagnostics {
|
|
|
23
23
|
readonly exitCode?: number;
|
|
24
24
|
readonly stdoutTail?: string;
|
|
25
25
|
readonly stderrTail?: string;
|
|
26
|
+
readonly outputRevision?: number;
|
|
26
27
|
}
|
|
27
28
|
export interface NodeHostRuntimeAdapterOptions {
|
|
28
29
|
readonly readinessTimeoutMs?: number;
|
|
30
|
+
readonly hardReadinessTimeoutMs?: number;
|
|
29
31
|
readonly readinessPollIntervalMs?: number;
|
|
30
32
|
readonly httpProbeTimeoutMs?: number;
|
|
31
33
|
readonly probeHttp?: (url: string, timeoutMs: number, signal?: AbortSignal) => Promise<boolean>;
|
|
@@ -41,6 +43,7 @@ export interface NodeRuntimeAdapterLaunch<T> extends HostPortLaunch<T> {
|
|
|
41
43
|
export declare class NodeHostRuntimeAdapter {
|
|
42
44
|
private readonly broker;
|
|
43
45
|
private readonly readinessTimeoutMs;
|
|
46
|
+
private readonly hardReadinessTimeoutMs;
|
|
44
47
|
private readonly readinessPollIntervalMs;
|
|
45
48
|
private readonly httpProbeTimeoutMs;
|
|
46
49
|
private readonly probeHttp;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { withAspNetPrebuiltRunArguments } from "./aspnet-runtime-prebuild.js";
|
|
2
3
|
import { hostPortEnvironment, } from "./host-runtime-contract.js";
|
|
3
4
|
/**
|
|
4
5
|
* Launches an explicitly configured HTTP project command beneath the caller's
|
|
@@ -8,12 +9,14 @@ import { hostPortEnvironment, } from "./host-runtime-contract.js";
|
|
|
8
9
|
export class NodeHostRuntimeAdapter {
|
|
9
10
|
broker;
|
|
10
11
|
readinessTimeoutMs;
|
|
12
|
+
hardReadinessTimeoutMs;
|
|
11
13
|
readinessPollIntervalMs;
|
|
12
14
|
httpProbeTimeoutMs;
|
|
13
15
|
probeHttp;
|
|
14
16
|
constructor(broker, options = {}) {
|
|
15
17
|
this.broker = broker;
|
|
16
18
|
this.readinessTimeoutMs = boundedInteger(options.readinessTimeoutMs ?? 120_000, 100, 120_000, "readinessTimeoutMs");
|
|
19
|
+
this.hardReadinessTimeoutMs = boundedInteger(options.hardReadinessTimeoutMs ?? 600_000, this.readinessTimeoutMs, 900_000, "hardReadinessTimeoutMs");
|
|
17
20
|
this.readinessPollIntervalMs = boundedInteger(options.readinessPollIntervalMs ?? 100, 10, 5_000, "readinessPollIntervalMs");
|
|
18
21
|
this.httpProbeTimeoutMs = boundedInteger(options.httpProbeTimeoutMs ?? 1_000, 50, 10_000, "httpProbeTimeoutMs");
|
|
19
22
|
this.probeHttp = options.probeHttp ?? probeHttpReadiness;
|
|
@@ -49,15 +52,22 @@ export class NodeHostRuntimeAdapter {
|
|
|
49
52
|
return { ...launched, request: activeRequest };
|
|
50
53
|
}
|
|
51
54
|
async waitUntilReady(value, request, launcher, signal) {
|
|
52
|
-
const
|
|
55
|
+
const startedAt = Date.now();
|
|
56
|
+
const hardDeadline = startedAt + this.hardReadinessTimeoutMs;
|
|
57
|
+
let idleDeadline = startedAt + this.readinessTimeoutMs;
|
|
58
|
+
let outputRevision = -1;
|
|
53
59
|
let observedOwnership = "unbound";
|
|
54
|
-
while (Date.now() <=
|
|
60
|
+
while (Date.now() <= idleDeadline && Date.now() <= hardDeadline) {
|
|
55
61
|
if (signal?.aborted)
|
|
56
62
|
throw cancellationError(signal);
|
|
57
63
|
const diagnostics = await launcher.readinessDiagnostics?.(value);
|
|
58
64
|
if (diagnostics?.exited) {
|
|
59
65
|
throw new Error(readinessFailure("host_runtime_process_exited", `the supervised process exited with code ${diagnostics.exitCode ?? "unknown"} before its assigned runtime became ready`, request, diagnostics));
|
|
60
66
|
}
|
|
67
|
+
if (diagnostics?.outputRevision !== undefined && diagnostics.outputRevision > outputRevision) {
|
|
68
|
+
outputRevision = diagnostics.outputRevision;
|
|
69
|
+
idleDeadline = Math.min(hardDeadline, Date.now() + this.readinessTimeoutMs);
|
|
70
|
+
}
|
|
61
71
|
const ownership = await launcher.inspectListener(value, request, signal);
|
|
62
72
|
observedOwnership = ownership;
|
|
63
73
|
if (ownership === "foreign")
|
|
@@ -74,9 +84,14 @@ export class NodeHostRuntimeAdapter {
|
|
|
74
84
|
const code = observedOwnership === "owned"
|
|
75
85
|
? "host_runtime_http_readiness_timeout"
|
|
76
86
|
: "host_runtime_listener_timeout";
|
|
87
|
+
const reachedHardDeadline = Date.now() >= hardDeadline;
|
|
77
88
|
const detail = observedOwnership === "owned"
|
|
78
|
-
?
|
|
79
|
-
|
|
89
|
+
? reachedHardDeadline
|
|
90
|
+
? `the supervised process owned its assigned loopback port but HTTP readiness did not succeed within the ${this.hardReadinessTimeoutMs}ms hard limit`
|
|
91
|
+
: `the supervised process owned its assigned loopback port but made no readiness progress for ${this.readinessTimeoutMs}ms`
|
|
92
|
+
: reachedHardDeadline
|
|
93
|
+
? `the supervised process did not bind its assigned loopback port within the ${this.hardReadinessTimeoutMs}ms hard limit`
|
|
94
|
+
: `the supervised process did not bind its assigned loopback port and made no output progress for ${this.readinessTimeoutMs}ms`;
|
|
80
95
|
throw new Error(readinessFailure(code, detail, request, diagnostics));
|
|
81
96
|
}
|
|
82
97
|
}
|
|
@@ -195,15 +210,16 @@ function aspNetCoreArguments(command, args) {
|
|
|
195
210
|
if (args[0]?.toLowerCase() !== "run") {
|
|
196
211
|
throw new Error("node_runtime_adapter_invalid: aspnetcore adapter requires a dotnet run command.");
|
|
197
212
|
}
|
|
198
|
-
const
|
|
199
|
-
const
|
|
213
|
+
const prebuiltArgs = withAspNetPrebuiltRunArguments(command, args);
|
|
214
|
+
const applicationArguments = prebuiltArgs.indexOf("--");
|
|
215
|
+
const insertionIndex = applicationArguments < 0 ? prebuiltArgs.length : applicationArguments;
|
|
200
216
|
return [
|
|
201
|
-
...
|
|
217
|
+
...prebuiltArgs.slice(0, insertionIndex),
|
|
202
218
|
"--disable-build-servers",
|
|
203
219
|
"-p:UseSharedCompilation=false",
|
|
204
220
|
"-p:DefaultItemExcludesInProjectFolder=TestResults/**",
|
|
205
221
|
"--no-launch-profile",
|
|
206
|
-
...
|
|
222
|
+
...prebuiltArgs.slice(insertionIndex),
|
|
207
223
|
];
|
|
208
224
|
}
|
|
209
225
|
function validateCommand(command) {
|
|
@@ -5,6 +5,7 @@ export interface PlaywrightHostRuntimeContext {
|
|
|
5
5
|
readonly testOutputDirectory: string;
|
|
6
6
|
readonly browserProfileDirectory: string;
|
|
7
7
|
readonly baseUrl: string;
|
|
8
|
+
readonly ownershipToken: string;
|
|
8
9
|
}
|
|
9
10
|
export interface PreparedPlaywrightHostRuntime {
|
|
10
11
|
readonly configPath: string;
|
|
@@ -29,6 +29,9 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
29
29
|
throw new Error("playwright_runtime_adapter_invalid: writable directories must belong to the same attempt root.");
|
|
30
30
|
}
|
|
31
31
|
const baseUrl = loopbackHttpUrl(context.baseUrl);
|
|
32
|
+
if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
|
|
33
|
+
throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
|
|
34
|
+
}
|
|
32
35
|
const overlayPath = path.join(temporaryDirectory, "forge.playwright.config.mjs");
|
|
33
36
|
const browserCache = await resolvePlaywrightBrowserCache(attemptRoot);
|
|
34
37
|
const browserInstallCommand = await resolvePlaywrightBrowserInstallCommand(context.worktreePath, path.dirname(realSource));
|
|
@@ -45,6 +48,8 @@ export class PlaywrightHostRuntimeAdapter {
|
|
|
45
48
|
FORGE_PLAYWRIGHT_CONFIG: overlayPath,
|
|
46
49
|
FORGE_PLAYWRIGHT_BASE_URL: baseUrl,
|
|
47
50
|
FORGE_E2E_WEB_URL: baseUrl,
|
|
51
|
+
FORGE_E2E_OWNERSHIP_MODE: "attempt",
|
|
52
|
+
FORGE_E2E_OWNERSHIP_TOKEN: context.ownershipToken,
|
|
48
53
|
FORGE_PLAYWRIGHT_BROWSER_READY: browserCache.ready ? "true" : "false",
|
|
49
54
|
FORGE_PLAYWRIGHT_BROWSER_INSTALL_COMMAND: browserInstallCommand,
|
|
50
55
|
PLAYWRIGHT_BROWSERS_PATH: browserCache.path,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const minimumWorkspaceEstimateBytes: number;
|
|
2
|
+
export declare const architectMinimumWorkspaceEstimateBytes: number;
|
|
3
|
+
export interface RepositoryWorkspaceFootprint {
|
|
4
|
+
readonly sourceBytes: number;
|
|
5
|
+
readonly hasNode: boolean;
|
|
6
|
+
readonly hasDotNet: boolean;
|
|
7
|
+
readonly hasBrowser: boolean;
|
|
8
|
+
readonly serviceCount: number;
|
|
9
|
+
}
|
|
10
|
+
export interface WorkspaceEstimateHints {
|
|
11
|
+
readonly role?: string | null;
|
|
12
|
+
readonly serviceCount?: number;
|
|
13
|
+
readonly browser?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function estimateWorkspaceBytesFromRepo(repoPath: string, hints?: WorkspaceEstimateHints): Promise<number>;
|
|
16
|
+
export declare function calculateWorkspaceBytes(footprint: RepositoryWorkspaceFootprint, role?: string | null): number;
|
|
17
|
+
export declare function measureRepositoryWorkspace(repoPath: string): Promise<RepositoryWorkspaceFootprint>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
const GiB = 1024 ** 3;
|
|
6
|
+
const alignmentBytes = 512 * 1024 ** 2;
|
|
7
|
+
export const minimumWorkspaceEstimateBytes = 2 * GiB;
|
|
8
|
+
export const architectMinimumWorkspaceEstimateBytes = GiB;
|
|
9
|
+
const maximumBytes = 100 * GiB;
|
|
10
|
+
const footprintCacheLifetimeMs = 5 * 60_000;
|
|
11
|
+
const excludedDirectories = new Set([
|
|
12
|
+
".git",
|
|
13
|
+
".artifacts",
|
|
14
|
+
".forge-worktrees",
|
|
15
|
+
".local",
|
|
16
|
+
".next",
|
|
17
|
+
".nuget",
|
|
18
|
+
".pnpm-store",
|
|
19
|
+
".tmp",
|
|
20
|
+
".turbo",
|
|
21
|
+
"artifacts",
|
|
22
|
+
"bin",
|
|
23
|
+
"build",
|
|
24
|
+
"coverage",
|
|
25
|
+
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"obj",
|
|
28
|
+
"testresults",
|
|
29
|
+
]);
|
|
30
|
+
const footprintCache = new Map();
|
|
31
|
+
export async function estimateWorkspaceBytesFromRepo(repoPath, hints = {}) {
|
|
32
|
+
const cacheKey = path.resolve(repoPath);
|
|
33
|
+
const cached = footprintCache.get(cacheKey);
|
|
34
|
+
const footprint = cached && Date.now() - cached.measuredAt < footprintCacheLifetimeMs
|
|
35
|
+
? cached.footprint
|
|
36
|
+
: await measureRepositoryWorkspace(cacheKey);
|
|
37
|
+
if (!cached || cached.footprint !== footprint) {
|
|
38
|
+
footprintCache.set(cacheKey, { measuredAt: Date.now(), footprint });
|
|
39
|
+
}
|
|
40
|
+
return calculateWorkspaceBytes({
|
|
41
|
+
...footprint,
|
|
42
|
+
hasBrowser: footprint.hasBrowser || hints.browser === true,
|
|
43
|
+
serviceCount: Math.max(footprint.serviceCount, Math.max(0, hints.serviceCount ?? 0)),
|
|
44
|
+
}, hints.role);
|
|
45
|
+
}
|
|
46
|
+
export function calculateWorkspaceBytes(footprint, role) {
|
|
47
|
+
const normalizedRole = role?.trim().toLowerCase() ?? "";
|
|
48
|
+
if (normalizedRole === "architect") {
|
|
49
|
+
// Architect owns a checkout and planning artifacts, not dependencies,
|
|
50
|
+
// build outputs, browser state, services, or application runtime output.
|
|
51
|
+
const estimate = architectMinimumWorkspaceEstimateBytes
|
|
52
|
+
+ Math.max(0, footprint.sourceBytes) * 2;
|
|
53
|
+
return Math.min(maximumBytes, Math.max(architectMinimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
|
|
54
|
+
}
|
|
55
|
+
let estimate = 2 * GiB + Math.max(0, footprint.sourceBytes) * 3;
|
|
56
|
+
if (footprint.hasNode)
|
|
57
|
+
estimate += 3 * GiB;
|
|
58
|
+
if (footprint.hasDotNet)
|
|
59
|
+
estimate += 2 * GiB;
|
|
60
|
+
if (footprint.hasBrowser)
|
|
61
|
+
estimate += 1536 * 1024 ** 2;
|
|
62
|
+
estimate += Math.max(0, footprint.serviceCount) * GiB;
|
|
63
|
+
if (["qa", "ci_repair", "pr_fix"].includes(normalizedRole)) {
|
|
64
|
+
estimate += GiB;
|
|
65
|
+
}
|
|
66
|
+
return Math.min(maximumBytes, Math.max(minimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
|
|
67
|
+
}
|
|
68
|
+
export async function measureRepositoryWorkspace(repoPath) {
|
|
69
|
+
return await measureGitWorkspace(repoPath) ?? await measureFilesystemFallback(repoPath);
|
|
70
|
+
}
|
|
71
|
+
async function measureGitWorkspace(repoPath) {
|
|
72
|
+
let sourceBytes = 0;
|
|
73
|
+
let hasNode = false;
|
|
74
|
+
let hasDotNet = false;
|
|
75
|
+
let hasBrowser = false;
|
|
76
|
+
let serviceCount = 0;
|
|
77
|
+
const child = spawn("git", ["-c", "core.quotepath=false", "ls-files", "--cached", "--others", "--exclude-standard"], {
|
|
78
|
+
cwd: repoPath,
|
|
79
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
80
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
81
|
+
windowsHide: true,
|
|
82
|
+
});
|
|
83
|
+
const closed = new Promise((resolve) => {
|
|
84
|
+
child.once("close", resolve);
|
|
85
|
+
child.once("error", () => resolve(null));
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
const lines = readline.createInterface({ input: child.stdout, crlfDelay: Infinity });
|
|
89
|
+
for await (const relativePath of lines) {
|
|
90
|
+
if (!relativePath.trim())
|
|
91
|
+
continue;
|
|
92
|
+
const file = await inspectWorkspaceFile(path.join(repoPath, relativePath));
|
|
93
|
+
if (!file)
|
|
94
|
+
continue;
|
|
95
|
+
sourceBytes += file.bytes;
|
|
96
|
+
hasNode ||= file.hasNode;
|
|
97
|
+
hasDotNet ||= file.hasDotNet;
|
|
98
|
+
hasBrowser ||= file.hasBrowser;
|
|
99
|
+
serviceCount = Math.max(serviceCount, file.serviceCount);
|
|
100
|
+
}
|
|
101
|
+
return await closed === 0 ? { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount } : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
child.kill();
|
|
105
|
+
await closed;
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function measureFilesystemFallback(repoPath) {
|
|
110
|
+
let sourceBytes = 0;
|
|
111
|
+
let hasNode = false;
|
|
112
|
+
let hasDotNet = false;
|
|
113
|
+
let hasBrowser = false;
|
|
114
|
+
let serviceCount = 0;
|
|
115
|
+
const pending = [path.resolve(repoPath)];
|
|
116
|
+
while (pending.length > 0) {
|
|
117
|
+
const current = pending.pop();
|
|
118
|
+
const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
const entryPath = path.join(current, entry.name);
|
|
121
|
+
if (entry.isDirectory()) {
|
|
122
|
+
if (!excludedDirectories.has(entry.name.toLowerCase()))
|
|
123
|
+
pending.push(entryPath);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (!entry.isFile())
|
|
127
|
+
continue;
|
|
128
|
+
const file = await inspectWorkspaceFile(entryPath);
|
|
129
|
+
if (!file)
|
|
130
|
+
continue;
|
|
131
|
+
sourceBytes += file.bytes;
|
|
132
|
+
hasNode ||= file.hasNode;
|
|
133
|
+
hasDotNet ||= file.hasDotNet;
|
|
134
|
+
hasBrowser ||= file.hasBrowser;
|
|
135
|
+
serviceCount = Math.max(serviceCount, file.serviceCount);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount };
|
|
139
|
+
}
|
|
140
|
+
async function inspectWorkspaceFile(filePath) {
|
|
141
|
+
const stat = await fs.stat(filePath).catch(() => null);
|
|
142
|
+
if (!stat?.isFile())
|
|
143
|
+
return null;
|
|
144
|
+
const name = path.basename(filePath).toLowerCase();
|
|
145
|
+
const sandbox = name === "forge.sandbox.yml" || name === "forge.sandbox.yaml";
|
|
146
|
+
return {
|
|
147
|
+
bytes: stat.size,
|
|
148
|
+
hasNode: ["package.json", "pnpm-lock.yaml", "package-lock.json", "yarn.lock"].includes(name),
|
|
149
|
+
hasDotNet: name.endsWith(".sln") || name.endsWith(".csproj") || name.endsWith(".fsproj"),
|
|
150
|
+
hasBrowser: name.startsWith("playwright.config"),
|
|
151
|
+
serviceCount: sandbox
|
|
152
|
+
? countSandboxServices(await fs.readFile(filePath, "utf8").catch(() => ""))
|
|
153
|
+
: 0,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function countSandboxServices(yaml) {
|
|
157
|
+
let inServices = false;
|
|
158
|
+
let count = 0;
|
|
159
|
+
for (const rawLine of yaml.split(/\r?\n/gu)) {
|
|
160
|
+
const line = rawLine.trim();
|
|
161
|
+
if (!line || line.startsWith("#"))
|
|
162
|
+
continue;
|
|
163
|
+
if (!/^\s/u.test(rawLine)) {
|
|
164
|
+
inServices = line.toLowerCase() === "services:";
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (inServices && line.startsWith("-"))
|
|
168
|
+
count += 1;
|
|
169
|
+
}
|
|
170
|
+
return count;
|
|
171
|
+
}
|
|
172
|
+
function alignUp(value, alignment) {
|
|
173
|
+
return Math.ceil(value / alignment) * alignment;
|
|
174
|
+
}
|
|
@@ -19,23 +19,53 @@ export declare class DockerPreflight {
|
|
|
19
19
|
private readonly cacheMs;
|
|
20
20
|
private generation;
|
|
21
21
|
private cached;
|
|
22
|
-
private
|
|
22
|
+
private fullPreflightAt;
|
|
23
|
+
private staticPreflight;
|
|
24
|
+
private inspectionInFlight;
|
|
25
|
+
private lastCapacitySample;
|
|
23
26
|
private readonly options;
|
|
24
27
|
private readonly docker;
|
|
25
28
|
private readonly ownership;
|
|
26
29
|
private diskPressureLatched;
|
|
30
|
+
private readonly memoryAvailability;
|
|
27
31
|
constructor(options?: DockerPreflightOptions | string, commands?: CommandRunner, cacheMs?: number);
|
|
32
|
+
private unavailable;
|
|
33
|
+
private memoryReserveBytes;
|
|
34
|
+
private defaultAdmissionMemoryBytes;
|
|
28
35
|
current(): SandboxPreflightResult | null;
|
|
29
36
|
refresh(): Promise<SandboxPreflightResult>;
|
|
30
37
|
release(): Promise<void>;
|
|
31
38
|
run(force?: boolean): Promise<SandboxPreflightResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Refreshes only the admission inputs that change while the daemon's static
|
|
41
|
+
* capability snapshot remains valid. Heartbeats use this path so periodic
|
|
42
|
+
* liveness reporting does not wake Docker/WSL to rerun feature probes.
|
|
43
|
+
*/
|
|
44
|
+
refreshCapacity(): Promise<SandboxPreflightResult>;
|
|
45
|
+
/**
|
|
46
|
+
* When the cached static preflight remains usable, produces a capacity sample
|
|
47
|
+
* that began after this admission request. An older inspection is awaited,
|
|
48
|
+
* not preempted or reused. Later admission callers may share the next sample
|
|
49
|
+
* only when it began after they entered this method. Without a usable static
|
|
50
|
+
* snapshot, the existing fail-closed result is returned without probing.
|
|
51
|
+
*/
|
|
52
|
+
refreshCapacityForAdmission(): Promise<SandboxPreflightResult>;
|
|
53
|
+
private startInspection;
|
|
32
54
|
private inspect;
|
|
55
|
+
private inspectCapacity;
|
|
33
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Uses the same reviewed reserve vector as host-runtime admission. The input
|
|
59
|
+
* is always the physical host total; Docker Desktop's VM total is tracked as
|
|
60
|
+
* a separate daemon commitment domain.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveSandboxHostMemoryReserveBytes(totalMemoryBytes: number, explicitBytes?: number, environment?: NodeJS.ProcessEnv): number;
|
|
34
63
|
export declare function canRunDockerMaintenance(preflight: {
|
|
35
64
|
readonly healthy: boolean;
|
|
36
65
|
readonly unavailableCode?: string | null;
|
|
37
66
|
}): boolean;
|
|
38
67
|
export declare function evaluateDiskPressure(availableBytes: number, totalBytes: number, minimumAvailableBytes: number, highWatermarkPercent: number, lowWatermarkPercent: number, pressureLatched: boolean): boolean;
|
|
68
|
+
export declare function requiredAvailableBytesToClearDiskPressure(totalBytes: number, minimumAvailableBytes: number, lowWatermarkPercent: number): number;
|
|
39
69
|
export declare function storagePolicyAvailable(storageQuota: boolean, environment?: NodeJS.ProcessEnv): boolean;
|
|
40
70
|
export declare class DockerContextOwnershipLock {
|
|
41
71
|
private lockPath;
|