@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0fedbc5c9ef7
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 +89 -1
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +19 -12
- package/dist/bridge/bridge.service.js +155 -282
- package/dist/bridge/bridge.types.d.ts +5 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +56 -12
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +10 -171
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +7 -1
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +4 -1
- package/dist/runtime/host-load-governor.d.ts +10 -1
- package/dist/runtime/host-load-governor.js +33 -3
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +8 -1
- package/dist/runtime/host-load-sampler.js +14 -7
- package/dist/runtime/host-load-test-slot.js +7 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
- package/dist/runtime/prepared-runtime-readiness.js +63 -16
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +3 -7
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +50 -82
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +7 -3
- package/dist/session/pre-publication-validation.js +32 -30
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +33 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +27 -43
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +35 -16
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.service.d.ts +6 -0
- package/dist/session/session.service.js +131 -88
- package/dist/session/session.types.d.ts +1 -0
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.js +9 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +42 -0
- package/dist/worktree/wip-git.js +139 -0
- package/dist/worktree/wip-refs.d.ts +77 -0
- package/dist/worktree/wip-refs.js +146 -0
- package/dist/worktree/wip-restore.d.ts +46 -0
- package/dist/worktree/wip-restore.js +280 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +115 -0
- package/dist/worktree/worktree-wip.d.ts +51 -0
- package/dist/worktree/worktree-wip.js +190 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +112 -181
- package/dist/worktree/worktree.types.d.ts +35 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -66,7 +66,7 @@ export class HostLoadGovernor {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
get maxWaitMs() {
|
|
69
|
-
return this.config.
|
|
69
|
+
return this.config.maxTotalWaitMs;
|
|
70
70
|
}
|
|
71
71
|
async acquire(request, options = {}) {
|
|
72
72
|
if (!this.enabled) {
|
|
@@ -85,15 +85,17 @@ export class HostLoadGovernor {
|
|
|
85
85
|
if (signal?.aborted)
|
|
86
86
|
throw abortError(signal);
|
|
87
87
|
return await new Promise((resolve, reject) => {
|
|
88
|
+
const enqueuedAtMs = monotonicNowMs();
|
|
88
89
|
const waiter = {
|
|
89
90
|
request,
|
|
90
|
-
enqueuedAtMs
|
|
91
|
+
enqueuedAtMs,
|
|
91
92
|
signal,
|
|
92
93
|
onWaiting: options.onWaiting,
|
|
93
94
|
resolve,
|
|
94
95
|
reject,
|
|
95
96
|
abort: () => this.settle(waiter, () => reject(abortError(signal))),
|
|
96
97
|
deadline: null,
|
|
98
|
+
progressAtMs: enqueuedAtMs,
|
|
97
99
|
lastDecision: null,
|
|
98
100
|
settled: false,
|
|
99
101
|
ticket: this.config.testSlots > 0 && takesHostTestSlot(request.stepClass)
|
|
@@ -107,7 +109,8 @@ export class HostLoadGovernor {
|
|
|
107
109
|
}
|
|
108
110
|
: null,
|
|
109
111
|
};
|
|
110
|
-
|
|
112
|
+
// The backstop: even behind healthy holders, a step queues no longer than maxTotalWaitMs.
|
|
113
|
+
waiter.deadline = setTimeout(() => this.timeOut(waiter, `${waiter.lastDecision?.detail ?? "The host stayed at capacity."} It reached the longest a step may queue (${minutes(this.config.maxTotalWaitMs)}).`), this.config.maxTotalWaitMs);
|
|
111
114
|
waiter.deadline.unref?.();
|
|
112
115
|
signal?.addEventListener("abort", waiter.abort, { once: true });
|
|
113
116
|
// Foreground goes ahead of background, except background that has already
|
|
@@ -233,6 +236,7 @@ export class HostLoadGovernor {
|
|
|
233
236
|
waiter.lastDecision = decision;
|
|
234
237
|
if (first && !waiter.settled)
|
|
235
238
|
void Promise.resolve(waiter.onWaiting?.(decision)).catch(() => undefined);
|
|
239
|
+
this.checkStalled(waiter, decision);
|
|
236
240
|
continue;
|
|
237
241
|
}
|
|
238
242
|
const entry = {
|
|
@@ -310,6 +314,7 @@ export class HostLoadGovernor {
|
|
|
310
314
|
return {
|
|
311
315
|
...decision,
|
|
312
316
|
admitted: false,
|
|
317
|
+
progressing: false,
|
|
313
318
|
reason: "ledger_recovering",
|
|
314
319
|
detail: `The host load ledger was corrupt and was quarantined; admissions resume at ${transaction.recoveringUntil}, once running steps have restored their reservations.`,
|
|
315
320
|
};
|
|
@@ -387,6 +392,26 @@ export class HostLoadGovernor {
|
|
|
387
392
|
return reported;
|
|
388
393
|
return Math.max(1, typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length);
|
|
389
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Waiting behind healthy holders of the host test slot is progress: their steps run, and the slot passes
|
|
397
|
+
* down the queue as they finish. Any other wait (a holder past its lease or whose owner is gone, the
|
|
398
|
+
* budget, a recovering ledger) counts toward maxWaitMs from the last time the queue made progress.
|
|
399
|
+
*/
|
|
400
|
+
checkStalled(waiter, decision) {
|
|
401
|
+
if (waiter.settled)
|
|
402
|
+
return;
|
|
403
|
+
const nowMs = monotonicNowMs();
|
|
404
|
+
if (decision.reason === "host_test_slot" && decision.progressing === true) {
|
|
405
|
+
waiter.progressAtMs = nowMs;
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (nowMs - waiter.progressAtMs < this.config.maxWaitMs)
|
|
409
|
+
return;
|
|
410
|
+
this.timeOut(waiter, `${decision.detail} The queue made no progress for ${minutes(nowMs - waiter.progressAtMs)}.`);
|
|
411
|
+
}
|
|
412
|
+
timeOut(waiter, detail) {
|
|
413
|
+
this.settle(waiter, () => waiter.reject(new HostCapacityTimeoutError(waiter.request.stepClass, waiter.request.label, monotonicNowMs() - waiter.enqueuedAtMs, detail)));
|
|
414
|
+
}
|
|
390
415
|
settle(waiter, complete) {
|
|
391
416
|
if (waiter.settled)
|
|
392
417
|
return;
|
|
@@ -592,6 +617,11 @@ function tighterMemory(hostAvailable, cgroupHeadroom) {
|
|
|
592
617
|
return hostAvailable;
|
|
593
618
|
return hostAvailable === null ? cgroupHeadroom : Math.min(hostAvailable, cgroupHeadroom);
|
|
594
619
|
}
|
|
620
|
+
/** Whole minutes for messages (at least 1); sub-minute limits only occur in tests and tuning. */
|
|
621
|
+
function minutes(ms) {
|
|
622
|
+
const whole = Math.max(1, Math.round(ms / 60_000));
|
|
623
|
+
return whole === 1 ? "1 minute" : `${whole} minutes`;
|
|
624
|
+
}
|
|
595
625
|
function abortError(signal) {
|
|
596
626
|
if (signal.reason instanceof Error)
|
|
597
627
|
return signal.reason;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
4
|
+
import { fileIdentityKey } from "../shared/fs/file-identity.js";
|
|
4
5
|
export class HostCapacityLedgerUnavailableError extends ForgeFailureError {
|
|
5
6
|
code = "host_capacity_ledger_unavailable";
|
|
6
7
|
constructor(detail, options) {
|
|
@@ -120,10 +121,11 @@ export class HostLoadLedgerLock {
|
|
|
120
121
|
* there is none, or null if it is live or too young to judge.
|
|
121
122
|
*/
|
|
122
123
|
async judgeStale(lockPath) {
|
|
123
|
-
|
|
124
|
+
// Exact (bigint) stats: a rounded Windows file id could name a different lock file.
|
|
125
|
+
const stat = await fs.lstat(lockPath, { bigint: true }).catch(() => null);
|
|
124
126
|
if (!stat)
|
|
125
127
|
return "absent";
|
|
126
|
-
const observed = stat.isFile() && stat.size <=
|
|
128
|
+
const observed = stat.isFile() && stat.size <= 16n * 1024n ? await readLock(lockPath) : null;
|
|
127
129
|
if (observed?.holder && validHolder(observed.holder) && typeof observed.token === "string") {
|
|
128
130
|
// A live holder keeps its lock however old it is.
|
|
129
131
|
if (this.options.isLive(observed.holder))
|
|
@@ -131,9 +133,9 @@ export class HostLoadLedgerLock {
|
|
|
131
133
|
return { identity: `t-${observed.token}` };
|
|
132
134
|
}
|
|
133
135
|
// Unreadable (claims are atomic, so this is corruption): give it until the stale age.
|
|
134
|
-
if (Date.now() - stat.mtimeMs < (this.options.unreadableStaleAfterMs ?? 30_000))
|
|
136
|
+
if (Date.now() - Number(stat.mtimeMs) < (this.options.unreadableStaleAfterMs ?? 30_000))
|
|
135
137
|
return null;
|
|
136
|
-
return { identity: `i-${stat.
|
|
138
|
+
return { identity: `i-${fileIdentityKey(stat).replace(":", "-")}-${stat.mtimeNs}-${stat.size}` };
|
|
137
139
|
}
|
|
138
140
|
/**
|
|
139
141
|
* Claims the next free link of the stale lock's break chain, held only for the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { fileIdentityKey } from "../shared/fs/file-identity.js";
|
|
4
5
|
export function hostLoadRuntimeSettingsPath(stateRoot) {
|
|
5
6
|
return path.join(stateRoot, "host-load-governor", "runner-settings.v1.json");
|
|
6
7
|
}
|
|
@@ -45,8 +46,9 @@ export class HostLoadRuntimeSettingsReader {
|
|
|
45
46
|
async read() {
|
|
46
47
|
let key;
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
// Exact (bigint) stats: a replaced file whose rounded Windows id matched would read as unchanged.
|
|
50
|
+
const stat = await fs.stat(this.filePath, { bigint: true });
|
|
51
|
+
key = `${stat.mtimeNs}:${stat.ctimeNs}:${stat.size}:${fileIdentityKey(stat)}`;
|
|
50
52
|
}
|
|
51
53
|
catch {
|
|
52
54
|
this.cachedKey = null;
|
|
@@ -40,6 +40,12 @@ export interface HostLoadSnapshot {
|
|
|
40
40
|
/** Reported only for a dedicated unit; never a shared terminal/session/app scope. */
|
|
41
41
|
readonly ownCgroup: HostOwnCgroupLoad | null;
|
|
42
42
|
readonly memoryAvailableBytes: number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Busy share (0-100) of all logical CPUs over the last sampling window: /proc/stat deltas
|
|
45
|
+
* on Linux, os.cpus() deltas on Windows. Null on the first sample, after a break in
|
|
46
|
+
* readings, and on other platforms. For display only; the governor gates on pressure.
|
|
47
|
+
*/
|
|
48
|
+
readonly hostCpuPercent: number | null;
|
|
43
49
|
}
|
|
44
50
|
/** What the bridge service needs: static facts plus the latest cached load sample. */
|
|
45
51
|
export interface HostLoadSource {
|
|
@@ -142,7 +148,8 @@ export declare class HostLoadSampler implements HostLoadSource {
|
|
|
142
148
|
private readSystemPressure;
|
|
143
149
|
private readOwnCgroup;
|
|
144
150
|
private coresInUse;
|
|
145
|
-
|
|
151
|
+
/** Busy share (0-1) of all logical CPUs since the last /proc/stat reading. */
|
|
152
|
+
private readHostCpuUse;
|
|
146
153
|
private readMemoryAvailable;
|
|
147
154
|
private fallbackFreeMemory;
|
|
148
155
|
private readPressure;
|
|
@@ -114,12 +114,12 @@ export class HostLoadSampler {
|
|
|
114
114
|
if (this.environment.platform === "win32")
|
|
115
115
|
return this.readWindowsSnapshot(sampledAtMs, monotonicMs);
|
|
116
116
|
const linux = this.environment.platform === "linux";
|
|
117
|
-
const [systemPressure, ownCgroup, memoryAvailableBytes,
|
|
117
|
+
const [systemPressure, ownCgroup, memoryAvailableBytes, hostCpu, cgroupMemoryHeadroomBytes, sandboxCores] = linux
|
|
118
118
|
? await Promise.all([
|
|
119
119
|
this.readSystemPressure(),
|
|
120
120
|
this.readOwnCgroup(monotonicMs),
|
|
121
121
|
this.readMemoryAvailable(),
|
|
122
|
-
this.
|
|
122
|
+
this.readHostCpuUse(),
|
|
123
123
|
this.readCgroupMemoryHeadroom(),
|
|
124
124
|
Promise.resolve(this.forgeCgroups?.paths() ?? [])
|
|
125
125
|
.then(paths => this.sandboxCpu.coresInUse(paths, monotonicMs)).catch(() => 0),
|
|
@@ -129,7 +129,7 @@ export class HostLoadSampler {
|
|
|
129
129
|
// Docker sandbox CPU is Forge's own work, already counted through reserved cost.
|
|
130
130
|
const ownCores = ownCgroup?.cpuCoresInUse ?? null;
|
|
131
131
|
this.latestMemoryHeadroom = cgroupMemoryHeadroomBytes;
|
|
132
|
-
this.latestCpuAttribution = hostCpuAttribution(sampledAt,
|
|
132
|
+
this.latestCpuAttribution = hostCpuAttribution(sampledAt, hostCpu === null ? null : roundCores(hostCpu.utilisation * hostCpu.cpuCount), ownCores === null ? null : ownCores + sandboxCores);
|
|
133
133
|
return {
|
|
134
134
|
sampledAt,
|
|
135
135
|
psiAvailable: systemPressure !== null,
|
|
@@ -138,6 +138,7 @@ export class HostLoadSampler {
|
|
|
138
138
|
ownCgroupDedicated: ownCgroup !== null,
|
|
139
139
|
ownCgroup,
|
|
140
140
|
memoryAvailableBytes,
|
|
141
|
+
hostCpuPercent: hostCpu === null ? null : hostCpuPercent(hostCpu.utilisation),
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
@@ -174,7 +175,7 @@ export class HostLoadSampler {
|
|
|
174
175
|
const cpu = utilisation === null ? null : this.windowsCpuPressure.update(utilisation, elapsedMs);
|
|
175
176
|
this.latestMemoryHeadroom = null;
|
|
176
177
|
this.latestCpuAttribution = hostCpuAttribution(sampledAt, utilisation !== null && totals ? roundCores(utilisation * totals.cpuCount) : null, null);
|
|
177
|
-
return windowsSnapshot(sampledAt, cpu, this.fallbackFreeMemory());
|
|
178
|
+
return windowsSnapshot(sampledAt, cpu, this.fallbackFreeMemory(), utilisation === null ? null : hostCpuPercent(utilisation));
|
|
178
179
|
}
|
|
179
180
|
async readCgroupMemoryHeadroom() {
|
|
180
181
|
const membership = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "self", "cgroup"));
|
|
@@ -231,7 +232,8 @@ export class HostLoadSampler {
|
|
|
231
232
|
return null;
|
|
232
233
|
return roundCores(usedUsec / elapsedUsec);
|
|
233
234
|
}
|
|
234
|
-
|
|
235
|
+
/** Busy share (0-1) of all logical CPUs since the last /proc/stat reading. */
|
|
236
|
+
async readHostCpuUse() {
|
|
235
237
|
const content = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "stat"));
|
|
236
238
|
const totals = content ? parseProcStatCpuTotals(content) : null;
|
|
237
239
|
const previous = this.hostCpuMark;
|
|
@@ -242,7 +244,7 @@ export class HostLoadSampler {
|
|
|
242
244
|
const busyDelta = totals.busyTicks - previous.busyTicks;
|
|
243
245
|
if (totalDelta <= 0 || busyDelta < 0)
|
|
244
246
|
return null;
|
|
245
|
-
return
|
|
247
|
+
return { utilisation: Math.min(1, busyDelta / totalDelta), cpuCount: totals.cpuCount };
|
|
246
248
|
}
|
|
247
249
|
async readMemoryAvailable() {
|
|
248
250
|
const meminfo = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "meminfo"));
|
|
@@ -264,7 +266,7 @@ export class HostLoadSampler {
|
|
|
264
266
|
}
|
|
265
267
|
/** Windows CPU deltas shorter than this are too noisy to fold into the pressure estimate. */
|
|
266
268
|
const minimumWindowsCpuWindowMs = 250;
|
|
267
|
-
function windowsSnapshot(sampledAt, cpu, memoryAvailableBytes) {
|
|
269
|
+
function windowsSnapshot(sampledAt, cpu, memoryAvailableBytes, cpuPercent) {
|
|
268
270
|
return {
|
|
269
271
|
sampledAt,
|
|
270
272
|
psiAvailable: cpu !== null,
|
|
@@ -273,11 +275,16 @@ function windowsSnapshot(sampledAt, cpu, memoryAvailableBytes) {
|
|
|
273
275
|
ownCgroupDedicated: false,
|
|
274
276
|
ownCgroup: null,
|
|
275
277
|
memoryAvailableBytes,
|
|
278
|
+
hostCpuPercent: cpuPercent,
|
|
276
279
|
};
|
|
277
280
|
}
|
|
278
281
|
function roundCores(value) {
|
|
279
282
|
return Math.round(value * 100) / 100;
|
|
280
283
|
}
|
|
284
|
+
/** A 0-1 busy share as a percentage with two decimals. */
|
|
285
|
+
function hostCpuPercent(utilisation) {
|
|
286
|
+
return Math.round(Math.min(1, Math.max(0, utilisation)) * 10_000) / 100;
|
|
287
|
+
}
|
|
281
288
|
function hostCpuAttribution(sampledAt, hostCoresInUse, ownCoresInUse) {
|
|
282
289
|
if (hostCoresInUse === null)
|
|
283
290
|
return null;
|
|
@@ -55,8 +55,15 @@ export function decideHostTestSlot(input) {
|
|
|
55
55
|
admitted,
|
|
56
56
|
reason: "host_test_slot",
|
|
57
57
|
detail: `Waiting for the host test slot (${input.testSlots} at once): ${heldBy}; ${ahead} step(s) ahead in the host queue.`,
|
|
58
|
+
// Only a running, healthy holder is progress. With no holder the steps ahead are waiting too (for
|
|
59
|
+
// the budget, say), and that wait must count as stalled, not reset the clock.
|
|
60
|
+
progressing: holders.length > 0 && holders.every(healthyHolder),
|
|
58
61
|
};
|
|
59
62
|
}
|
|
63
|
+
/** A holder whose step is still running under a live, renewed lease; the ledger reclaims the rest. */
|
|
64
|
+
function healthyHolder(token) {
|
|
65
|
+
return !token.degradedAt && !token.fencedAt && !token.retainedAt;
|
|
66
|
+
}
|
|
60
67
|
function describeHolder(token) {
|
|
61
68
|
const attempt = token.dispatchAttemptId ? `, attempt ${token.dispatchAttemptId}` : "";
|
|
62
69
|
const state = token.degradedAt
|
|
@@ -57,6 +57,18 @@ export interface HostRuntimeDirectoryEntry {
|
|
|
57
57
|
/** Returns one identity-bound directory inventory for runtime discovery. */
|
|
58
58
|
export type HostRuntimeDirectorySnapshot = (target: string) => Promise<readonly HostRuntimeDirectoryEntry[]>;
|
|
59
59
|
export declare function loadHostRuntimeContract(worktreePath: string, snapshot?: HostRuntimeSourceSnapshot, directorySnapshot?: HostRuntimeDirectorySnapshot): Promise<LoadedHostRuntimeContract>;
|
|
60
|
+
/** A managed attempt's own API master key: 32 random bytes, base64-encoded, as Security:MasterKey expects. */
|
|
61
|
+
export declare function newAttemptApiMasterKey(): string;
|
|
62
|
+
/**
|
|
63
|
+
* The environment a managed attempt's ASP.NET API launches with. When neither the launch profile
|
|
64
|
+
* nor the runtime contract configures Security__MasterKey or Security__MasterKeyFile, the API gets
|
|
65
|
+
* the attempt's own key. Otherwise ASP.NET Development falls back to the host user's dotnet
|
|
66
|
+
* user-secrets: the host's own key where they exist, and a failed secret write wherever they do not.
|
|
67
|
+
* The caller keeps one key for the attempt's whole life, so a restart against the same attempt
|
|
68
|
+
* database can still decrypt what was stored before it. The key is a secret: it is for the API
|
|
69
|
+
* process only, never for the environment handed to checks or providers.
|
|
70
|
+
*/
|
|
71
|
+
export declare function withAttemptApiMasterKey(port: HostRuntimePortConfig, environment: Readonly<Record<string, string>>, attemptMasterKey: string): Readonly<Record<string, string>>;
|
|
60
72
|
export declare function defaultHostRuntimeContract(): HostRuntimeContract;
|
|
61
73
|
export declare function validateHostRuntimeContract(source: string): HostRuntimeContract;
|
|
62
74
|
export declare function hostPortEnvironment(config: HostRuntimePortConfig, hostIp: "127.0.0.1", hostPort: number): Readonly<Record<string, string>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isAlias, parseDocument, visit } from "yaml";
|
|
@@ -425,6 +425,34 @@ function safeAspNetLaunchEnvironment(name, value) {
|
|
|
425
425
|
"TMPDIR",
|
|
426
426
|
]).has(normalized);
|
|
427
427
|
}
|
|
428
|
+
// The settings an ASP.NET API reads its secret-store master key from (Security:MasterKey wins).
|
|
429
|
+
const aspNetMasterKeySettings = ["security__masterkey", "security__masterkeyfile"];
|
|
430
|
+
/** A managed attempt's own API master key: 32 random bytes, base64-encoded, as Security:MasterKey expects. */
|
|
431
|
+
export function newAttemptApiMasterKey() {
|
|
432
|
+
return randomBytes(32).toString("base64");
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* The environment a managed attempt's ASP.NET API launches with. When neither the launch profile
|
|
436
|
+
* nor the runtime contract configures Security__MasterKey or Security__MasterKeyFile, the API gets
|
|
437
|
+
* the attempt's own key. Otherwise ASP.NET Development falls back to the host user's dotnet
|
|
438
|
+
* user-secrets: the host's own key where they exist, and a failed secret write wherever they do not.
|
|
439
|
+
* The caller keeps one key for the attempt's whole life, so a restart against the same attempt
|
|
440
|
+
* database can still decrypt what was stored before it. The key is a secret: it is for the API
|
|
441
|
+
* process only, never for the environment handed to checks or providers.
|
|
442
|
+
*/
|
|
443
|
+
export function withAttemptApiMasterKey(port, environment, attemptMasterKey) {
|
|
444
|
+
if (port.adapter !== "aspnetcore")
|
|
445
|
+
return environment;
|
|
446
|
+
const masterKeySetting = (name) => aspNetMasterKeySettings.includes(name.toLowerCase());
|
|
447
|
+
if (Object.entries(environment).some(([name, value]) => masterKeySetting(name) && value.trim().length > 0)) {
|
|
448
|
+
return environment;
|
|
449
|
+
}
|
|
450
|
+
// A blank setting configures nothing; drop it so the attempt's key is the only one.
|
|
451
|
+
return {
|
|
452
|
+
...Object.fromEntries(Object.entries(environment).filter(([name]) => !masterKeySetting(name))),
|
|
453
|
+
Security__MasterKey: attemptMasterKey,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
428
456
|
async function findFiles(root, accepts, maximumDepth, maximumEntries, snapshot) {
|
|
429
457
|
const results = [];
|
|
430
458
|
let examined = 0;
|
|
@@ -29,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
|
|
|
29
29
|
}
|
|
30
30
|
export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
|
|
31
31
|
export interface HostRuntimeProjectCheckpoint {
|
|
32
|
-
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned" | "host_runtime_contract_readmitted";
|
|
32
|
+
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned" | "host_runtime_contract_readmitted" | "host_runtime_isolation_serialized";
|
|
33
33
|
readonly message: string;
|
|
34
34
|
readonly data?: Readonly<Record<string, unknown>>;
|
|
35
35
|
}
|
|
@@ -73,6 +73,8 @@ export interface HostRuntimeReapOptions {
|
|
|
73
73
|
readonly runnerId: string;
|
|
74
74
|
readonly runnerInstanceId: string;
|
|
75
75
|
readonly nowMs?: number;
|
|
76
|
+
/** Where maintenance reports a degraded lease it released or kept; the bridge log by default. */
|
|
77
|
+
readonly log?: (message: string) => void;
|
|
76
78
|
}
|
|
77
79
|
export interface HostRuntimeReapReport {
|
|
78
80
|
readonly examined: number;
|
|
@@ -116,6 +118,9 @@ export interface HostRuntimeLeaseRuntime {
|
|
|
116
118
|
providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
|
|
117
119
|
release(dispatchAttemptId: string, fencingToken: string): Promise<RuntimeIsolationLease | null>;
|
|
118
120
|
invalidatePromotion?(repoId: string, scope?: "all" | "discovery"): Promise<void>;
|
|
121
|
+
promotionQuarantined?(repoId: string, runtimeContractFingerprint: string): Promise<boolean>;
|
|
122
|
+
/** The isolation violation the shared-run listener monitor found after launch, if any; the attempt must fail with it. */
|
|
123
|
+
isolationViolation?(dispatchAttemptId: string, fencingToken: string): Error | null;
|
|
119
124
|
hasForegroundDemand?(): boolean;
|
|
120
125
|
reap?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
|
|
121
126
|
snapshot?(): HostRuntimeCapacitySnapshot;
|
|
@@ -183,6 +188,16 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
183
188
|
hasForegroundDemand(): boolean;
|
|
184
189
|
acquirePreparation(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
185
190
|
acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
191
|
+
/**
|
|
192
|
+
* Whether acquire asks for shared project admission. A parallel-eligible probe in a promoted repository
|
|
193
|
+
* runs beside its shared runs (the listener audit fails it closed); otherwise it probes exclusively.
|
|
194
|
+
*/
|
|
195
|
+
private sharedAdmissionRequested;
|
|
196
|
+
/**
|
|
197
|
+
* Whether a shared admission may launch without downgrading to exclusive: a stored proof matches the
|
|
198
|
+
* contract by isolation inputs or exact commit, or it is a still-eligible probe of an unrevoked repository.
|
|
199
|
+
*/
|
|
200
|
+
private sharedAdmissionStillValid;
|
|
186
201
|
private reserveHostCapacity;
|
|
187
202
|
private reserveBackgroundAdmission;
|
|
188
203
|
private hostCapacityAvailable;
|
|
@@ -218,13 +233,22 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
218
233
|
/** Stops configured project processes in reverse launch order and releases their ports. */
|
|
219
234
|
private stopConfiguredProject;
|
|
220
235
|
providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
|
|
236
|
+
isolationViolation(dispatchAttemptId: string, fencingToken: string): Error | null;
|
|
221
237
|
private markCapacityReservationRunning;
|
|
222
238
|
providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
|
|
239
|
+
/** Isolation enforcement for parallel-eligible contracts after each launch (restarts included); see monitorListeners. */
|
|
240
|
+
private auditRuntimeListeners;
|
|
241
|
+
/**
|
|
242
|
+
* Quarantines the contract and drops every promotion for the repository. An exclusive run collides with nobody, so it
|
|
243
|
+
* keeps running unpromoted and reports why; a shared one stops its project (a failed stop is left to release) and fails.
|
|
244
|
+
*/
|
|
245
|
+
private handleIsolationViolation;
|
|
246
|
+
private monitorSharedRuntimeListeners;
|
|
223
247
|
private promoteVerifiedRuntime;
|
|
224
248
|
launchNodeRuntime<T>(dispatchAttemptId: string, fencingToken: string, portName: string, command: NodeRuntimeCommand, launcher: NodeRuntimeCommandLauncher<T>, signal?: AbortSignal): Promise<HostNodeRuntimeLaunch<T>>;
|
|
225
249
|
release(dispatchAttemptId: string, fencingToken: string, preservePreparation?: boolean): Promise<RuntimeIsolationLease | null>;
|
|
226
250
|
private readLedgers;
|
|
227
|
-
|
|
251
|
+
/** Degrades and counts a ledger whose runtime may still be live. A retained released ledger owns no slot, so it is neither changed nor counted. */
|
|
228
252
|
private markLedgerDegraded;
|
|
229
253
|
private rememberDegraded;
|
|
230
254
|
private forgetDegraded;
|
|
@@ -249,7 +273,8 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
249
273
|
private drainParallelProjectWaiters;
|
|
250
274
|
private drainBackgroundAdmissionWaiters;
|
|
251
275
|
private refreshKnownPromotions;
|
|
252
|
-
invalidatePromotion(repoId: string, scope?: "all" | "discovery"): Promise<void>;
|
|
276
|
+
invalidatePromotion(repoId: string, scope?: "all" | "discovery", quarantineFingerprints?: readonly string[]): Promise<void>;
|
|
277
|
+
promotionQuarantined(repoId: string, fingerprint: string): Promise<boolean>;
|
|
253
278
|
private drainAdmissionWaiters;
|
|
254
279
|
private reconcileReservationOwners;
|
|
255
280
|
private reservationOwnerIsLive;
|