@loucompanion/forge-bridge 0.2.1-dev.17ad6c965e41 → 0.2.1-dev.4f11ffc822f9
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/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 +22 -1
- package/dist/bridge/bridge-chat-provider-command.js +102 -4
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +12 -0
- package/dist/bridge/bridge.service.d.ts +2 -0
- package/dist/bridge/bridge.service.js +11 -31
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +160 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-runtime-lease.d.ts +25 -2
- package/dist/runtime/host-runtime-lease.js +105 -137
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- 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/session/session.service.d.ts +4 -0
- package/dist/session/session.service.js +54 -20
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -10,7 +10,7 @@ import { generatedOutputRootForPath } from "./generated-output-reset.js";
|
|
|
10
10
|
import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
|
|
11
11
|
/** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
|
|
12
12
|
export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics) {
|
|
13
|
-
diagnostics
|
|
13
|
+
const inputs = new CapturedRuntimeInputs(diagnostics);
|
|
14
14
|
const root = await fs.realpath(worktreePath);
|
|
15
15
|
const rootIdentity = (await assertCanonicalDirectory(root));
|
|
16
16
|
const sourceKey = (target) => process.platform === "win32" ? target.toLowerCase() : target;
|
|
@@ -131,7 +131,7 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
131
131
|
bytes += sourceBytes.length;
|
|
132
132
|
const digest = createHash("sha256").update(sourceBytes).digest();
|
|
133
133
|
hash.update(digest);
|
|
134
|
-
|
|
134
|
+
inputs.set(name, digest.toString("hex"));
|
|
135
135
|
snapshot.set(sourceKey(target), Promise.resolve(sourceBytes));
|
|
136
136
|
}
|
|
137
137
|
catch (error) {
|
|
@@ -139,11 +139,12 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
139
139
|
throw error;
|
|
140
140
|
const disposition = deleted.has(name) ? "deleted" : "absent";
|
|
141
141
|
hash.update(disposition);
|
|
142
|
-
|
|
142
|
+
inputs.set(name, disposition);
|
|
143
143
|
snapshot.set(sourceKey(target), Promise.resolve(null));
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
const contract = await loadHostRuntimeContract(root, target => {
|
|
147
|
+
inputs.discovered(path.relative(root, path.resolve(target)));
|
|
147
148
|
const key = sourceKey(path.resolve(target));
|
|
148
149
|
const captured = snapshot.get(key);
|
|
149
150
|
if (captured)
|
|
@@ -192,7 +193,7 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
192
193
|
? null
|
|
193
194
|
: createHash("sha256").update(sourceBytes).digest();
|
|
194
195
|
hash.update(digest ?? "absent");
|
|
195
|
-
|
|
196
|
+
inputs.set(`runtime-discovery:${name}`, digest?.toString("hex") ?? "absent");
|
|
196
197
|
}
|
|
197
198
|
if (head !== (await git.run(root, ["rev-parse", "HEAD"])).trim()
|
|
198
199
|
|| JSON.stringify(source) !== JSON.stringify(await inventory())) {
|
|
@@ -204,11 +205,131 @@ export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics)
|
|
|
204
205
|
throw new Error("host_runtime_source_changed: runtime discovery inventory changed during verification.");
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
|
-
return {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
return await inputs.identity(root, git, signal, head, hostRuntimeContractFingerprint(contract), `sha256:${hash.digest("hex")}`);
|
|
209
|
+
}
|
|
210
|
+
/** Total bytes of git-ignored launch inputs one identity pass may read. */
|
|
211
|
+
export const ignoredLaunchInputByteBudget = 32 * 1024 * 1024;
|
|
212
|
+
/**
|
|
213
|
+
* Per-path digests captured while hashing the prepared source (forwarded to the diagnostics
|
|
214
|
+
* sink when one is supplied), plus every path runtime discovery asked for. The isolation
|
|
215
|
+
* fingerprint is computed from a subset of them.
|
|
216
|
+
*/
|
|
217
|
+
class CapturedRuntimeInputs {
|
|
218
|
+
diagnostics;
|
|
219
|
+
digests = new Map();
|
|
220
|
+
discoveryInputs = new Set();
|
|
221
|
+
constructor(diagnostics) {
|
|
222
|
+
this.diagnostics = diagnostics;
|
|
223
|
+
diagnostics?.entries.clear();
|
|
224
|
+
}
|
|
225
|
+
set(name, digest) {
|
|
226
|
+
this.digests.set(name, digest);
|
|
227
|
+
this.diagnostics?.entries.set(name, digest);
|
|
228
|
+
}
|
|
229
|
+
/** Records a worktree-relative path runtime discovery read (or probed for existence). */
|
|
230
|
+
discovered(relative) {
|
|
231
|
+
const portable = relative.replaceAll("\\", "/");
|
|
232
|
+
if (!portable.startsWith("..") && !path.isAbsolute(portable))
|
|
233
|
+
this.discoveryInputs.add(portable);
|
|
234
|
+
}
|
|
235
|
+
async identity(root, git, signal, inputCommitSha, runtimeContractFingerprint, sourceFingerprint) {
|
|
236
|
+
await this.captureIgnoredLaunchInputs(root, git, signal);
|
|
237
|
+
return {
|
|
238
|
+
inputCommitSha,
|
|
239
|
+
runtimeContractFingerprint,
|
|
240
|
+
sourceFingerprint,
|
|
241
|
+
isolationFingerprint: isolationFingerprint(runtimeContractFingerprint, this.digests, this.discoveryInputs),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Launch inputs Git ignores still shape the runtime: an ignored appsettings.Local.json can set
|
|
246
|
+
* Kestrel endpoints that override ASPNETCORE_URLS. The source inventory omits ignored files, so
|
|
247
|
+
* hash every individually ignored isolation input here. Ignored directories (node_modules, bin,
|
|
248
|
+
* obj and other build output) are collapsed by --directory and not walked. These digests feed
|
|
249
|
+
* only the isolation fingerprint, not the source fingerprint.
|
|
250
|
+
*/
|
|
251
|
+
async captureIgnoredLaunchInputs(root, git, signal) {
|
|
252
|
+
const names = (await git.run(root, ["ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"]))
|
|
253
|
+
.split("\0")
|
|
254
|
+
.filter(name => name && !name.endsWith("/") && !name.startsWith(".forge/") && isIsolationInputPath(name))
|
|
255
|
+
.sort();
|
|
256
|
+
if (names.length > 4096)
|
|
257
|
+
throw new Error("host_runtime_source_invalid: too many ignored launch inputs to verify.");
|
|
258
|
+
// One aggregate budget for every ignored input in the pass. Each read is bounded by what is
|
|
259
|
+
// left, and the size is checked before any bytes are read, so the pass fails closed instead
|
|
260
|
+
// of reading up to 4096 large files.
|
|
261
|
+
let remaining = ignoredLaunchInputByteBudget;
|
|
262
|
+
for (const name of names) {
|
|
263
|
+
signal?.throwIfAborted();
|
|
264
|
+
let digest;
|
|
265
|
+
try {
|
|
266
|
+
const bytes = await readCanonicalSourceFile(path.join(root, name), remaining);
|
|
267
|
+
remaining -= bytes.length;
|
|
268
|
+
digest = createHash("sha256").update(bytes).digest("hex");
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (error.code !== "ENOENT")
|
|
272
|
+
throw error;
|
|
273
|
+
digest = "absent";
|
|
274
|
+
}
|
|
275
|
+
this.set(`ignored-launch-input:${name}`, digest);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Basenames whose content can change how a launched runtime binds ports, resolves
|
|
281
|
+
* dependencies or picks its launch profile beyond what the runtime contract states. A
|
|
282
|
+
* derived contract already fingerprints the manifest and project file it chose; these
|
|
283
|
+
* cover the rest: lockfiles and package-manager config, .NET SDK and package props,
|
|
284
|
+
* launch profiles, Kestrel endpoint config (appsettings) and dev-server/Playwright config.
|
|
285
|
+
*/
|
|
286
|
+
const isolationInputBasenames = new Set([
|
|
287
|
+
"package.json",
|
|
288
|
+
"package-lock.json",
|
|
289
|
+
"npm-shrinkwrap.json",
|
|
290
|
+
"pnpm-lock.yaml",
|
|
291
|
+
"pnpm-workspace.yaml",
|
|
292
|
+
"yarn.lock",
|
|
293
|
+
".npmrc",
|
|
294
|
+
".yarnrc",
|
|
295
|
+
".yarnrc.yml",
|
|
296
|
+
"packages.lock.json",
|
|
297
|
+
"global.json",
|
|
298
|
+
"nuget.config",
|
|
299
|
+
"directory.build.props",
|
|
300
|
+
"directory.build.targets",
|
|
301
|
+
"directory.packages.props",
|
|
302
|
+
"launchsettings.json",
|
|
303
|
+
]);
|
|
304
|
+
/** Whether a worktree-relative path is an isolation input (see isolationInputBasenames). */
|
|
305
|
+
export function isIsolationInputPath(name) {
|
|
306
|
+
if (name === ".forge/forge.runtime.yml")
|
|
307
|
+
return true;
|
|
308
|
+
const basename = name.slice(name.lastIndexOf("/") + 1).toLowerCase();
|
|
309
|
+
return isolationInputBasenames.has(basename)
|
|
310
|
+
|| /\.(?:cs|fs|vb)proj$/u.test(basename)
|
|
311
|
+
|| /^appsettings(?:\.[^/]+)?\.json$/u.test(basename)
|
|
312
|
+
|| /^(?:vite|vitest|next|playwright)\.config\.(?:ts|mts|cts|js|mjs|cjs)$/u.test(basename);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Identity of the inputs that control runtime isolation: the runtime contract plus every
|
|
316
|
+
* launch-relevant source file and every file runtime discovery read. Ordinary source edits
|
|
317
|
+
* leave it unchanged, so a proof observed for one branch head can admit another head whose
|
|
318
|
+
* isolation inputs are byte-identical; any change to them requires a fresh probe.
|
|
319
|
+
*/
|
|
320
|
+
function isolationFingerprint(runtimeContractFingerprint, digests, discoveryInputs) {
|
|
321
|
+
const hash = createHash("sha256");
|
|
322
|
+
hash.update(JSON.stringify(["isolation-v1", runtimeContractFingerprint]));
|
|
323
|
+
const selected = [...digests]
|
|
324
|
+
.filter(([name]) => {
|
|
325
|
+
if (name.startsWith("runtime-discovery:") || name.startsWith("ignored-launch-input:"))
|
|
326
|
+
return true;
|
|
327
|
+
return discoveryInputs.has(name) || isIsolationInputPath(name);
|
|
328
|
+
})
|
|
329
|
+
.sort(([left], [right]) => left.localeCompare(right));
|
|
330
|
+
for (const [name, digest] of selected)
|
|
331
|
+
hash.update(JSON.stringify([name, digest]));
|
|
332
|
+
return `sha256:${hash.digest("hex")}`;
|
|
212
333
|
}
|
|
213
334
|
function directoryInventory(entries) {
|
|
214
335
|
return JSON.stringify(entries.map(entry => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RunOnceDispatchPacket } from "../session/session.types.js";
|
|
2
2
|
import type { HostRuntimeAdmissionCheckpointHandler, HostRuntimeLeaseRuntime } from "./host-runtime-lease.js";
|
|
3
3
|
import { HostParallelPromotionStore, type HostParallelProofIdentity } from "./host-runtime-promotion.js";
|
|
4
4
|
export interface PreparedRuntimePendingSnapshot {
|
|
@@ -19,6 +19,12 @@ export declare class PreparedRuntimeReadiness {
|
|
|
19
19
|
constructor(runtime: HostRuntimeLeaseRuntime, store: HostParallelPromotionStore, releasePreparation: (id: string, fence: string) => Promise<unknown>, admissionExpired: () => Error);
|
|
20
20
|
acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
21
21
|
has(id: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
|
|
24
|
+
* check() found the prepared contract parallel-eligible, so the lease manager may admit it
|
|
25
|
+
* beside other shared-admission runs of the same repository instead of exclusively.
|
|
26
|
+
*/
|
|
27
|
+
isParallelEligibleProbe(id: string, fence: string): boolean;
|
|
22
28
|
hasPending(): boolean;
|
|
23
29
|
pendingSnapshots(): readonly PreparedRuntimePendingSnapshot[];
|
|
24
30
|
verify(dispatch: RunOnceDispatchPacket, worktree: string, checkpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostParallelProofIdentity | undefined>;
|
|
@@ -27,4 +33,10 @@ export declare class PreparedRuntimeReadiness {
|
|
|
27
33
|
private drain;
|
|
28
34
|
private scheduleDeadline;
|
|
29
35
|
private check;
|
|
36
|
+
/**
|
|
37
|
+
* A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
|
|
38
|
+
* contract is quarantined, records no proof. The agent's admission then finds none and runs under
|
|
39
|
+
* exclusive admission.
|
|
40
|
+
*/
|
|
41
|
+
private unproven;
|
|
30
42
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { GitClient } from "../shared/git/git.js";
|
|
3
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
3
4
|
import { loadHostRuntimeContract } from "./host-runtime-contract.js";
|
|
4
5
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible } from "./host-runtime-promotion.js";
|
|
5
6
|
import { preparedRuntimeIdentity } from "./prepared-runtime-identity.js";
|
|
@@ -43,6 +44,15 @@ export class PreparedRuntimeReadiness {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
has(id) { return this.preparations.has(id); }
|
|
47
|
+
/**
|
|
48
|
+
* Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
|
|
49
|
+
* check() found the prepared contract parallel-eligible, so the lease manager may admit it
|
|
50
|
+
* beside other shared-admission runs of the same repository instead of exclusively.
|
|
51
|
+
*/
|
|
52
|
+
isParallelEligibleProbe(id, fence) {
|
|
53
|
+
return [...this.preparations.values()].some(entry => entry.probe?.sandbox.dispatchAttemptId === id
|
|
54
|
+
&& entry.probe.lease.fencingToken === fence);
|
|
55
|
+
}
|
|
46
56
|
hasPending() { return this.preparations.size > 0; }
|
|
47
57
|
pendingSnapshots() {
|
|
48
58
|
return [...this.preparations.values()].map(entry => ({
|
|
@@ -162,6 +172,9 @@ export class PreparedRuntimeReadiness {
|
|
|
162
172
|
}
|
|
163
173
|
if (await this.store.load(dispatch.repo.id, identity))
|
|
164
174
|
return identity;
|
|
175
|
+
// A quarantined contract cannot record proof: skip the exclusive admission and the stack launch.
|
|
176
|
+
if (await this.store.quarantined(dispatch.repo.id, identity.runtimeContractFingerprint))
|
|
177
|
+
return await this.unproven(entry, identity, checkpoint, true);
|
|
165
178
|
await checkpoint?.({ code: "host_runtime_prepared_probe_started", expiresAt: entry.expiresAt,
|
|
166
179
|
message: `Verifying prepared runtime ${identity.inputCommitSha.slice(0, 12)} before agent admission; project-default readiness is not a substitute.` });
|
|
167
180
|
const probeId = randomUUID();
|
|
@@ -172,11 +185,14 @@ export class PreparedRuntimeReadiness {
|
|
|
172
185
|
inputCommitSha: identity.inputCommitSha },
|
|
173
186
|
};
|
|
174
187
|
entry.probe = probe;
|
|
188
|
+
// Any revocation from here on (this probe's own violation or a sibling's) voids its proof.
|
|
189
|
+
const revocationGeneration = await this.store.revocationGeneration(dispatch.repo.id);
|
|
175
190
|
const stopPreparedHeadMonitor = new AbortController();
|
|
176
191
|
const preparedHeadMonitor = monitorPreparedHead(worktree, identity.inputCommitSha, controller, stopPreparedHeadMonitor.signal);
|
|
177
192
|
let cleanupConfirmed;
|
|
178
193
|
let verifiedRuntimeContractFingerprint;
|
|
179
|
-
let verifiedPorts;
|
|
194
|
+
let verifiedPorts = [];
|
|
195
|
+
let isolationViolated = false;
|
|
180
196
|
try {
|
|
181
197
|
controller.signal.throwIfAborted();
|
|
182
198
|
await this.runtime.acquire(probe, controller.signal);
|
|
@@ -189,6 +205,12 @@ export class PreparedRuntimeReadiness {
|
|
|
189
205
|
verifiedRuntimeContractFingerprint = hostRuntimeContractFingerprint(started.runtimeContract);
|
|
190
206
|
verifiedPorts = started.lease.resources.ports.map(port => port.name).sort();
|
|
191
207
|
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
// A shared probe's stray listener: the lease stopped it and revoked the repository (see unproven).
|
|
210
|
+
if (!(error instanceof ForgeFailureError && error.failureCode === "host_runtime_isolation_violation"))
|
|
211
|
+
throw error;
|
|
212
|
+
isolationViolated = true;
|
|
213
|
+
}
|
|
192
214
|
finally {
|
|
193
215
|
stopPreparedHeadMonitor.abort();
|
|
194
216
|
await preparedHeadMonitor;
|
|
@@ -199,25 +221,15 @@ export class PreparedRuntimeReadiness {
|
|
|
199
221
|
if (!cleanupConfirmed) {
|
|
200
222
|
throw new Error("host_runtime_prepared_probe_cleanup_unconfirmed: matching probe teardown was not confirmed.");
|
|
201
223
|
}
|
|
224
|
+
if (isolationViolated)
|
|
225
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
202
226
|
// Probe-owned processes may create transient, untracked files while they
|
|
203
227
|
// are alive. Verify the prepared source only after matching teardown is
|
|
204
228
|
// confirmed: persistent source edits still fail closed, while files that
|
|
205
229
|
// belong to the probe lifecycle cannot create a false source-change loop.
|
|
206
230
|
const currentDiagnostics = { entries: new Map() };
|
|
207
231
|
const currentIdentity = await preparedRuntimeIdentity(worktree, controller.signal, currentDiagnostics);
|
|
208
|
-
const changed =
|
|
209
|
-
if (verifiedRuntimeContractFingerprint !== identity.runtimeContractFingerprint
|
|
210
|
-
|| currentIdentity.runtimeContractFingerprint !== identity.runtimeContractFingerprint) {
|
|
211
|
-
changed.push("runtime contract");
|
|
212
|
-
}
|
|
213
|
-
if (currentIdentity.inputCommitSha !== identity.inputCommitSha)
|
|
214
|
-
changed.push("HEAD");
|
|
215
|
-
if (currentIdentity.sourceFingerprint !== identity.sourceFingerprint) {
|
|
216
|
-
const paths = changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries);
|
|
217
|
-
changed.push(paths.length > 0
|
|
218
|
-
? `source fingerprint (${paths.join(", ")})`
|
|
219
|
-
: "source fingerprint");
|
|
220
|
-
}
|
|
232
|
+
const changed = identityChanges(identity, currentIdentity, verifiedRuntimeContractFingerprint, changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries));
|
|
221
233
|
if (changed.length > 0) {
|
|
222
234
|
throw new Error(`host_runtime_prepared_source_changed: ${changed.join(", ")} changed during isolation verification.`);
|
|
223
235
|
}
|
|
@@ -225,9 +237,26 @@ export class PreparedRuntimeReadiness {
|
|
|
225
237
|
throw new Error("host_runtime_prepared_probe_incomplete: assigned-port verification did not confirm every configured launch port.");
|
|
226
238
|
}
|
|
227
239
|
controller.signal.throwIfAborted();
|
|
228
|
-
await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint)
|
|
240
|
+
const recorded = await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint, identity.isolationFingerprint, revocationGeneration)
|
|
241
|
+
.then(() => true, (error) => errorMessage(error).startsWith("host_parallel_promotion_revoked:")
|
|
242
|
+
? false : Promise.reject(error));
|
|
243
|
+
if (!recorded)
|
|
244
|
+
return await this.unproven(entry, identity, checkpoint);
|
|
229
245
|
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
230
|
-
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its
|
|
246
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its proof is retained for every head with the same isolation inputs.` });
|
|
247
|
+
return identity;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
|
|
251
|
+
* contract is quarantined, records no proof. The agent's admission then finds none and runs under
|
|
252
|
+
* exclusive admission.
|
|
253
|
+
*/
|
|
254
|
+
async unproven(entry, identity, checkpoint, quarantined = false) {
|
|
255
|
+
const reason = quarantined
|
|
256
|
+
? "its runtime contract is quarantined after a recent isolation violation, so it was not probed"
|
|
257
|
+
: "the repository's promotion was revoked during the probe";
|
|
258
|
+
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
259
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} did not prove isolation (${reason}); its runs are serialized.` });
|
|
231
260
|
return identity;
|
|
232
261
|
}
|
|
233
262
|
}
|
|
@@ -274,6 +303,24 @@ async function waitForPreparedHeadPoll(signal) {
|
|
|
274
303
|
function errorMessage(error) {
|
|
275
304
|
return error instanceof Error ? error.message : String(error);
|
|
276
305
|
}
|
|
306
|
+
/** What changed between the identity a probe started from and the one after its teardown. */
|
|
307
|
+
function identityChanges(prepared, current, verifiedRuntimeContractFingerprint, changedPaths) {
|
|
308
|
+
const changed = [];
|
|
309
|
+
if (verifiedRuntimeContractFingerprint !== prepared.runtimeContractFingerprint
|
|
310
|
+
|| current.runtimeContractFingerprint !== prepared.runtimeContractFingerprint) {
|
|
311
|
+
changed.push("runtime contract");
|
|
312
|
+
}
|
|
313
|
+
if (current.inputCommitSha !== prepared.inputCommitSha)
|
|
314
|
+
changed.push("HEAD");
|
|
315
|
+
// Ignored launch inputs change only the isolation fingerprint; either change voids the proof.
|
|
316
|
+
if (current.sourceFingerprint !== prepared.sourceFingerprint
|
|
317
|
+
|| current.isolationFingerprint !== prepared.isolationFingerprint) {
|
|
318
|
+
changed.push(changedPaths.length > 0
|
|
319
|
+
? `source or isolation inputs (${changedPaths.join(", ")})`
|
|
320
|
+
: "source or isolation inputs");
|
|
321
|
+
}
|
|
322
|
+
return changed;
|
|
323
|
+
}
|
|
277
324
|
function changedIdentityPaths(before, after) {
|
|
278
325
|
const paths = new Set([...before.keys(), ...after.keys()]);
|
|
279
326
|
const changed = [...paths]
|
|
@@ -20,6 +20,10 @@ export declare class BridgeSessionService implements SessionService {
|
|
|
20
20
|
runtimeCapacity(): HostRuntimeCapacitySnapshot | null;
|
|
21
21
|
probeHostRuntime(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
|
|
22
22
|
runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
|
|
23
|
+
/** Launches a parallel-eligible probe's project, unless its contract is quarantined and so could never earn proof. */
|
|
24
|
+
private probeConfiguredProject;
|
|
25
|
+
/** A late isolation violation stopped the attempt's project in the background: fail rather than report success. */
|
|
26
|
+
private throwIfAbortedOrIsolationViolated;
|
|
23
27
|
/** Reports the provider's peak memory and releases the attempt's host runtime lease. */
|
|
24
28
|
private releaseHostRuntime;
|
|
25
29
|
}
|
|
@@ -77,7 +77,7 @@ export class BridgeSessionService {
|
|
|
77
77
|
signal,
|
|
78
78
|
});
|
|
79
79
|
assertReadinessProbeStartupBudget(request.expiresAt);
|
|
80
|
-
|
|
80
|
+
const started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
|
|
81
81
|
runtimeStarted = true;
|
|
82
82
|
const discovery = started.runtimeContract.discovery;
|
|
83
83
|
if (!hostRuntimeParallelEligible(started.runtimeContract)) {
|
|
@@ -92,23 +92,7 @@ export class BridgeSessionService {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
|
-
|
|
96
|
-
started = await this.hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal);
|
|
97
|
-
const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
|
|
98
|
-
const verifiedPorts = started.lease.resources.ports.map(port => port.name);
|
|
99
|
-
const verified = requiredPorts.length > 0 && requiredPorts.every(name => verifiedPorts.includes(name));
|
|
100
|
-
result = verified
|
|
101
|
-
? {
|
|
102
|
-
status: "parallel_ready",
|
|
103
|
-
runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
|
|
104
|
-
runtimeContractSource: started.runtimeContract.source,
|
|
105
|
-
runtimeRequirements: started.runtimeContract.contract.requires ?? null,
|
|
106
|
-
reasonCode: null,
|
|
107
|
-
reasonMessage: null,
|
|
108
|
-
qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
|
|
109
|
-
checkedAt: new Date().toISOString(),
|
|
110
|
-
}
|
|
111
|
-
: failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
|
|
95
|
+
result = await this.probeConfiguredProject(this.hostRuntime, request, started, signal);
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
98
|
catch (error) {
|
|
@@ -366,6 +350,8 @@ export class BridgeSessionService {
|
|
|
366
350
|
// Set while the stack may not match the workspace: a failed restart is retried on the next pass.
|
|
367
351
|
let restartPending = false;
|
|
368
352
|
refreshRuntimeEnvironment = async (refreshSignal) => {
|
|
353
|
+
// A late violation stopped the stack: fail this validation pass rather than run it against closed ports.
|
|
354
|
+
this.throwIfAbortedOrIsolationViolated(undefined, dispatch, hostLease);
|
|
369
355
|
const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
|
|
370
356
|
if (!restartPending && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
|
|
371
357
|
return null;
|
|
@@ -455,7 +441,7 @@ export class BridgeSessionService {
|
|
|
455
441
|
emit,
|
|
456
442
|
signal
|
|
457
443
|
});
|
|
458
|
-
|
|
444
|
+
this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
|
|
459
445
|
const draftArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
|
|
460
446
|
// Redaction can throw (a secret in a structural field); only a returned result is a success.
|
|
461
447
|
const draftResult = redactRunOnceResultPacket({
|
|
@@ -510,7 +496,7 @@ export class BridgeSessionService {
|
|
|
510
496
|
}
|
|
511
497
|
throw error;
|
|
512
498
|
}
|
|
513
|
-
|
|
499
|
+
this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
|
|
514
500
|
const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
|
|
515
501
|
const result = redactRunOnceResultPacket({
|
|
516
502
|
schemaVersion: 2, exitCode: 0, summary: run.summary,
|
|
@@ -531,6 +517,29 @@ export class BridgeSessionService {
|
|
|
531
517
|
}
|
|
532
518
|
}
|
|
533
519
|
}
|
|
520
|
+
/** Launches a parallel-eligible probe's project, unless its contract is quarantined and so could never earn proof. */
|
|
521
|
+
async probeConfiguredProject(hostRuntime, request, started, signal) {
|
|
522
|
+
if (await hostRuntime.promotionQuarantined?.(request.repoId, hostRuntimeContractFingerprint(started.runtimeContract))) {
|
|
523
|
+
// Not launched; the server retries on its backoff, and the check passes once the quarantine expires.
|
|
524
|
+
return failedProbe("host_runtime_isolation_quarantined", "The runtime contract is quarantined after a recent isolation violation, so it was not probed; its runs stay serialized.");
|
|
525
|
+
}
|
|
526
|
+
assertReadinessProbeStartupBudget(request.expiresAt);
|
|
527
|
+
let isolationDetail = null;
|
|
528
|
+
const launched = await hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal, async (checkpoint) => {
|
|
529
|
+
if (checkpoint.code === "host_runtime_isolation_serialized")
|
|
530
|
+
isolationDetail = checkpoint.message;
|
|
531
|
+
});
|
|
532
|
+
return configuredProbeResult(launched, isolationDetail);
|
|
533
|
+
}
|
|
534
|
+
/** A late isolation violation stopped the attempt's project in the background: fail rather than report success. */
|
|
535
|
+
throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease) {
|
|
536
|
+
throwIfAborted(signal);
|
|
537
|
+
const violation = hostLease && dispatch.sandbox
|
|
538
|
+
? this.hostRuntime?.isolationViolation?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken)
|
|
539
|
+
: null;
|
|
540
|
+
if (violation)
|
|
541
|
+
throw violation;
|
|
542
|
+
}
|
|
534
543
|
/** Reports the provider's peak memory and releases the attempt's host runtime lease. */
|
|
535
544
|
async releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle) {
|
|
536
545
|
if (hostLease && dispatch.sandbox) {
|
|
@@ -682,6 +691,31 @@ function readinessProbeDispatch(request) {
|
|
|
682
691
|
artifacts: [],
|
|
683
692
|
};
|
|
684
693
|
}
|
|
694
|
+
/**
|
|
695
|
+
* A probe is parallel_ready only when every configured port proved readiness and the launch earned the
|
|
696
|
+
* parallel promotion, which an isolation violation or a quarantined contract withholds while it runs.
|
|
697
|
+
*/
|
|
698
|
+
function configuredProbeResult(started, isolationDetail) {
|
|
699
|
+
const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
|
|
700
|
+
const verifiedPorts = started.lease.resources.ports.map(port => port.name);
|
|
701
|
+
if (requiredPorts.length === 0 || !requiredPorts.every(name => verifiedPorts.includes(name))) {
|
|
702
|
+
return failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
|
|
703
|
+
}
|
|
704
|
+
if (started.environment.FORGE_HOST_CONCURRENCY !== "host_parallel_safe") {
|
|
705
|
+
return failedProbe("host_runtime_isolation_violation", isolationDetail
|
|
706
|
+
?? "The application served every Forge-assigned port, but did not earn parallel-safety proof for this runtime contract.");
|
|
707
|
+
}
|
|
708
|
+
return {
|
|
709
|
+
status: "parallel_ready",
|
|
710
|
+
runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
|
|
711
|
+
runtimeContractSource: started.runtimeContract.source,
|
|
712
|
+
runtimeRequirements: started.runtimeContract.contract.requires ?? null,
|
|
713
|
+
reasonCode: null,
|
|
714
|
+
reasonMessage: null,
|
|
715
|
+
qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
|
|
716
|
+
checkedAt: new Date().toISOString(),
|
|
717
|
+
};
|
|
718
|
+
}
|
|
685
719
|
function failedProbe(reasonCode, reasonMessage) {
|
|
686
720
|
return { status: "failed", reasonCode, reasonMessage, checkedAt: new Date().toISOString() };
|
|
687
721
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.2.1-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.2.1-dev.4f11ffc822f9";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.2.1-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.2.1-dev.4f11ffc822f9";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.2.1-dev.
|
|
3
|
+
"version": "0.2.1-dev.4f11ffc822f9",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -7,8 +7,10 @@ param(
|
|
|
7
7
|
|
|
8
8
|
$ErrorActionPreference = "Stop"
|
|
9
9
|
$parents = @{}
|
|
10
|
+
$created = @{}
|
|
10
11
|
Get-CimInstance Win32_Process | ForEach-Object {
|
|
11
12
|
$parents[[int]$_.ProcessId] = [int]$_.ParentProcessId
|
|
13
|
+
$created[[int]$_.ProcessId] = $_.CreationDate
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
$results = @()
|
|
@@ -25,7 +27,16 @@ foreach ($listenerText in $ListenerProcessIds.Split(',')) {
|
|
|
25
27
|
if (-not $parents.ContainsKey($current)) {
|
|
26
28
|
break
|
|
27
29
|
}
|
|
28
|
-
$
|
|
30
|
+
$parent = [int]$parents[$current]
|
|
31
|
+
# Windows keeps a child's ParentProcessId after the parent exits, and PIDs are reused. A
|
|
32
|
+
# "parent" created after the child is a different process that took the dead parent's PID,
|
|
33
|
+
# so the chain ends here; following it could attribute a foreign listener to the root.
|
|
34
|
+
if ($created.ContainsKey($parent) -and $created.ContainsKey($current) `
|
|
35
|
+
-and $null -ne $created[$parent] -and $null -ne $created[$current] `
|
|
36
|
+
-and $created[$parent] -gt $created[$current]) {
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
$current = $parent
|
|
29
40
|
}
|
|
30
41
|
$results += $owned
|
|
31
42
|
}
|