@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b

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.
Files changed (260) hide show
  1. package/README.md +128 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
  5. package/dist/bridge/bridge-chat-provider-command.js +131 -26
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.service.d.ts +29 -12
  17. package/dist/bridge/bridge.service.js +215 -380
  18. package/dist/bridge/bridge.types.d.ts +21 -0
  19. package/dist/bridge/bridge.types.js +2 -1
  20. package/dist/bridge/default-session-service.d.ts +13 -0
  21. package/dist/bridge/default-session-service.js +22 -0
  22. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  23. package/dist/bridge/dispatch-offer-policy.js +58 -0
  24. package/dist/bridge/in-flight-registry.d.ts +62 -0
  25. package/dist/bridge/in-flight-registry.js +207 -0
  26. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  27. package/dist/bridge/readiness-result-outbox.js +20 -0
  28. package/dist/bridge/runner-host-capabilities.js +14 -1
  29. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  30. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  31. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  32. package/dist/bridge/windows-bash-resolution.js +153 -0
  33. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  34. package/dist/cleanup/cleanup-wip.js +66 -0
  35. package/dist/cleanup/cleanup.service.d.ts +11 -1
  36. package/dist/cleanup/cleanup.service.js +80 -62
  37. package/dist/cleanup/cleanup.types.d.ts +2 -0
  38. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  39. package/dist/cleanup/forge-owned-paths.js +9 -0
  40. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  41. package/dist/cleanup/host-runtime-ledger.js +30 -9
  42. package/dist/cli/cli.help.js +57 -13
  43. package/dist/cli/cli.service.d.ts +3 -10
  44. package/dist/cli/cli.service.js +20 -213
  45. package/dist/cli/idle-status.d.ts +84 -0
  46. package/dist/cli/idle-status.js +181 -0
  47. package/dist/cli/local-config.d.ts +14 -1
  48. package/dist/cli/local-config.js +42 -2
  49. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  50. package/dist/cli/provider-cli-advertising.js +88 -0
  51. package/dist/cli/provider-cli-detection.d.ts +10 -0
  52. package/dist/cli/provider-cli-detection.js +160 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  54. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  55. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  56. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  57. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  58. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  59. package/dist/runtime/attempt-process-supervisor.js +12 -6
  60. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  61. package/dist/runtime/docker-engine-probe.js +7 -0
  62. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  63. package/dist/runtime/dotnet-build-outputs.js +402 -0
  64. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  65. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  66. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  67. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  68. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  69. package/dist/runtime/host-listener-inspector.js +84 -3
  70. package/dist/runtime/host-load-admission.d.ts +5 -0
  71. package/dist/runtime/host-load-capacity.d.ts +198 -0
  72. package/dist/runtime/host-load-capacity.js +353 -0
  73. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  74. package/dist/runtime/host-load-child-environment.js +35 -1
  75. package/dist/runtime/host-load-governor-config.d.ts +33 -3
  76. package/dist/runtime/host-load-governor-config.js +24 -3
  77. package/dist/runtime/host-load-governor.d.ts +91 -2
  78. package/dist/runtime/host-load-governor.js +217 -18
  79. package/dist/runtime/host-load-ledger-lock.js +6 -4
  80. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  81. package/dist/runtime/host-load-live-test-slots.js +193 -0
  82. package/dist/runtime/host-load-runtime-settings.js +4 -2
  83. package/dist/runtime/host-load-sampler.d.ts +25 -1
  84. package/dist/runtime/host-load-sampler.js +38 -7
  85. package/dist/runtime/host-load-step-run.d.ts +37 -3
  86. package/dist/runtime/host-load-step-run.js +63 -7
  87. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  88. package/dist/runtime/host-load-test-slot.js +26 -7
  89. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  90. package/dist/runtime/host-runtime-contract.js +35 -5
  91. package/dist/runtime/host-runtime-lease.d.ts +28 -3
  92. package/dist/runtime/host-runtime-lease.js +140 -296
  93. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  94. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  95. package/dist/runtime/host-runtime-promotion.d.ts +78 -2
  96. package/dist/runtime/host-runtime-promotion.js +307 -14
  97. package/dist/runtime/managed-command-teardown.js +5 -16
  98. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  99. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  100. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  101. package/dist/runtime/prepared-runtime-identity.js +130 -9
  102. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  103. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  104. package/dist/runtime/runner-settings.d.ts +4 -0
  105. package/dist/runtime/runner-settings.js +22 -0
  106. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  107. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  108. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  109. package/dist/sandbox/host-capacity-broker.js +4 -2
  110. package/dist/sandbox/managed-branch.d.ts +13 -0
  111. package/dist/sandbox/managed-branch.js +90 -0
  112. package/dist/sandbox/provider-auth/codex.js +11 -11
  113. package/dist/sandbox/runtime.d.ts +1 -2
  114. package/dist/sandbox/runtime.js +9 -19
  115. package/dist/sandbox/sandbox-input.d.ts +22 -0
  116. package/dist/sandbox/sandbox-input.js +49 -0
  117. package/dist/sandbox/workspace.service.js +15 -2
  118. package/dist/session/managed-attempt-tools.d.ts +0 -7
  119. package/dist/session/managed-attempt-tools.js +54 -109
  120. package/dist/session/managed-build-coordinator.d.ts +16 -0
  121. package/dist/session/managed-build-coordinator.js +10 -0
  122. package/dist/session/managed-build-receipt.d.ts +7 -0
  123. package/dist/session/managed-build-receipt.js +11 -3
  124. package/dist/session/managed-command-environment.d.ts +8 -0
  125. package/dist/session/managed-command-environment.js +28 -0
  126. package/dist/session/managed-command-host-load.d.ts +10 -5
  127. package/dist/session/managed-command-host-load.js +18 -14
  128. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  129. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  130. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  131. package/dist/session/phase-completion.artifacts.js +65 -166
  132. package/dist/session/phase-completion.d.ts +27 -2
  133. package/dist/session/phase-completion.helpers.js +5 -53
  134. package/dist/session/phase-completion.js +15 -32
  135. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  136. package/dist/session/phase-completion.mcp-args.js +195 -0
  137. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  138. package/dist/session/phase-completion.phase-aliases.js +43 -0
  139. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  140. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  141. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  142. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  143. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  144. package/dist/session/phase-completion.pr-review.js +294 -0
  145. package/dist/session/phase-completion.prompts.d.ts +1 -1
  146. package/dist/session/phase-completion.prompts.js +14 -0
  147. package/dist/session/phase-completion.runtime.d.ts +8 -9
  148. package/dist/session/phase-completion.runtime.js +65 -196
  149. package/dist/session/phase-completion.schemas.js +12 -2
  150. package/dist/session/phase-completion.validation.d.ts +1 -0
  151. package/dist/session/phase-completion.validation.js +9 -1
  152. package/dist/session/pr-review-diff-base.d.ts +18 -0
  153. package/dist/session/pr-review-diff-base.js +44 -0
  154. package/dist/session/pr-review-placement.d.ts +50 -0
  155. package/dist/session/pr-review-placement.js +91 -0
  156. package/dist/session/pre-publication-change-set.d.ts +62 -0
  157. package/dist/session/pre-publication-change-set.js +166 -0
  158. package/dist/session/pre-publication-host-load.js +6 -5
  159. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  160. package/dist/session/pre-publication-native-postgres.js +111 -0
  161. package/dist/session/pre-publication-process.js +13 -12
  162. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  163. package/dist/session/pre-publication-step-execution.js +6 -5
  164. package/dist/session/pre-publication-validation.d.ts +9 -4
  165. package/dist/session/pre-publication-validation.js +62 -65
  166. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  167. package/dist/session/provider-cli/claude-background-work.js +4 -3
  168. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  169. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  170. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  171. package/dist/session/provider-cli/host-build-lock.js +30 -0
  172. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  173. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  174. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  175. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  176. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  177. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  178. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  179. package/dist/session/provider-cli/pre-publication-repair.js +41 -3
  180. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  181. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  182. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  183. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  184. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  185. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  186. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  188. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  189. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  190. package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
  191. package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
  192. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  193. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  195. package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
  196. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  197. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  198. package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
  199. package/dist/session/provider-cli/provider-cli.service.js +59 -190
  200. package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
  201. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  202. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  203. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  204. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  205. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  206. package/dist/session/qa-sidecar-validation.js +28 -0
  207. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  208. package/dist/session/sandbox-host-capacity-gate.js +63 -22
  209. package/dist/session/session-host-project.d.ts +22 -0
  210. package/dist/session/session-host-project.js +98 -0
  211. package/dist/session/session-redaction.js +31 -181
  212. package/dist/session/session.parse-helpers.d.ts +10 -0
  213. package/dist/session/session.parse-helpers.js +84 -0
  214. package/dist/session/session.runtime-refresh.d.ts +46 -0
  215. package/dist/session/session.runtime-refresh.js +116 -0
  216. package/dist/session/session.service.d.ts +8 -1
  217. package/dist/session/session.service.js +177 -239
  218. package/dist/session/session.types.d.ts +5 -0
  219. package/dist/session/session.types.js +9 -79
  220. package/dist/session/session.types.pr-review.d.ts +48 -0
  221. package/dist/session/session.types.pr-review.js +51 -0
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/shared/fs/file-identity.d.ts +10 -0
  225. package/dist/shared/fs/file-identity.js +15 -0
  226. package/dist/shared/fs/replace-file.d.ts +7 -0
  227. package/dist/shared/fs/replace-file.js +33 -0
  228. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  229. package/dist/shared/process/host-process-recovery.js +23 -3
  230. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  231. package/dist/shared/process/host-process-supervisor.js +66 -14
  232. package/dist/shared/provider-capabilities.d.ts +2 -0
  233. package/dist/shared/provider-capabilities.js +18 -1
  234. package/dist/version.d.ts +1 -1
  235. package/dist/version.js +1 -1
  236. package/dist/worktree/artifact-injector.js +24 -0
  237. package/dist/worktree/orphan-relink.d.ts +19 -0
  238. package/dist/worktree/orphan-relink.js +106 -0
  239. package/dist/worktree/wip-git.d.ts +58 -0
  240. package/dist/worktree/wip-git.js +182 -0
  241. package/dist/worktree/wip-refs.d.ts +85 -0
  242. package/dist/worktree/wip-refs.js +169 -0
  243. package/dist/worktree/wip-restore.d.ts +51 -0
  244. package/dist/worktree/wip-restore.js +324 -0
  245. package/dist/worktree/wip-snapshot.d.ts +53 -0
  246. package/dist/worktree/wip-snapshot.js +270 -0
  247. package/dist/worktree/worktree-inputs.d.ts +8 -0
  248. package/dist/worktree/worktree-inputs.js +134 -0
  249. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  250. package/dist/worktree/worktree-origin-sync.js +128 -0
  251. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  252. package/dist/worktree/worktree-wip-events.js +148 -0
  253. package/dist/worktree/worktree-wip.d.ts +57 -0
  254. package/dist/worktree/worktree-wip.js +200 -0
  255. package/dist/worktree/worktree.base.d.ts +7 -1
  256. package/dist/worktree/worktree.service.d.ts +49 -5
  257. package/dist/worktree/worktree.service.js +223 -187
  258. package/dist/worktree/worktree.types.d.ts +47 -0
  259. package/package.json +1 -1
  260. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { readCanonicalSourceFile } from "./canonical-source-file.js";
5
5
  import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
6
+ import { replaceFile } from "../shared/fs/replace-file.js";
6
7
  import { ExactHostProcessRecovery } from "../shared/process/host-process-recovery.js";
7
8
  import { captureHostProcessIdentity, } from "../shared/process/host-process-supervisor.js";
8
9
  import { monotonicNowMs } from "../shared/time/monotonic.js";
@@ -14,8 +15,7 @@ const maximumReceiptBytes = 16 * 1024 * 1024;
14
15
  const maximumCapturedCharacters = 200_000;
15
16
  const defaultGraceMs = 2_000;
16
17
  const receiptReadAttempts = 5;
17
- const receiptReplaceAttempts = 40;
18
- const receiptReplaceRetryMs = 25;
18
+ const receiptReadRetryMs = 25;
19
19
  const invalidMetadata = Symbol("invalid managed-command metadata");
20
20
  let procRoot = "/proc";
21
21
  /** Test support: points the Linux process inventory at another directory (null restores /proc). */
@@ -363,7 +363,7 @@ async function readReceipt(store, name) {
363
363
  }
364
364
  catch {
365
365
  if (attempt < receiptReadAttempts)
366
- await delay(receiptReplaceRetryMs);
366
+ await delay(receiptReadRetryMs);
367
367
  }
368
368
  }
369
369
  return null;
@@ -462,19 +462,8 @@ async function persistReceipt(receiptPath, receipt) {
462
462
  const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
463
463
  try {
464
464
  await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
465
- for (let attempt = 1;; attempt += 1) {
466
- try {
467
- await fs.rename(temporaryPath, receiptPath);
468
- return;
469
- }
470
- catch (error) {
471
- const code = error.code;
472
- // Windows refuses to replace a file another process briefly holds open.
473
- if (attempt >= receiptReplaceAttempts || (code !== "EPERM" && code !== "EBUSY" && code !== "EACCES"))
474
- throw error;
475
- await delay(receiptReplaceRetryMs);
476
- }
477
- }
465
+ // Windows refuses to replace a file another process briefly holds open.
466
+ await replaceFile(temporaryPath, receiptPath);
478
467
  }
479
468
  finally {
480
469
  await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
@@ -2,15 +2,51 @@ export declare const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE
2
2
  export declare const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
3
3
  export declare const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
4
4
  /**
5
- * A dedicated, operator-provisioned PostgreSQL cluster that runner-authored .NET
6
- * test tiers may use only while the Docker engine is unavailable. The cluster
7
- * must hold nothing but disposable test databases, so its capability carries no
8
- * more authority than the attempt-private container it replaces.
5
+ * The cluster serves the shared test server while Docker is up, so tests that need a
6
+ * pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
7
+ * first, which keeps test databases out of the Docker VM and saves RAM.
8
+ */
9
+ export declare const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
10
+ export type NativeTestPostgresDatabaseMode = typeof nativeTestPostgresFallbackDatabaseMode | typeof nativeTestPostgresPreferredDatabaseMode;
11
+ /**
12
+ * What runner-authored .NET test tiers get: `preferred` (the default) the provisioned
13
+ * cluster whenever it is configured; `docker_unavailable` that cluster only after a
14
+ * Docker probe fails; `ephemeral` a throwaway cluster of their own for each check, whose
15
+ * bootstrap superuser they hold (owner policy 2026-11-17). The provisioned cluster still
16
+ * hosts the attempt database broker in every mode.
17
+ */
18
+ export type NativeTestPostgresUse = "preferred" | "docker_unavailable" | "ephemeral";
19
+ /**
20
+ * A dedicated, operator-provisioned PostgreSQL cluster for runner-authored .NET
21
+ * test tiers, preferred over Docker unless its file says `docker_unavailable`.
22
+ * The cluster must hold nothing but disposable test databases, so its capability
23
+ * carries no more authority than the attempt-private container it replaces.
9
24
  */
10
25
  export interface NativeTestPostgresFallback {
11
26
  readonly connectionString: string;
12
27
  readonly endpoint: string;
28
+ readonly use: NativeTestPostgresUse;
29
+ /** The PostgreSQL bin directory an ephemeral cluster runs from; defaults to the one beside psql. */
30
+ readonly postgresBin?: string;
13
31
  }
32
+ /** The cluster as handed to one test process, with the mode its fixtures run in. */
33
+ export interface NativeTestPostgresGrant {
34
+ readonly connectionString: string;
35
+ readonly endpoint: string;
36
+ readonly mode: NativeTestPostgresDatabaseMode;
37
+ /** Set when the grant is a throwaway cluster of its own; the server reports it as `forge.ephemeral_cluster`. */
38
+ readonly ephemeralClusterId?: string;
39
+ /** Stops and deletes an ephemeral cluster once its check has finished. */
40
+ readonly release?: () => Promise<void>;
41
+ }
42
+ /**
43
+ * The provisioned cluster's grant for a check that can use it, or null to use Docker. A
44
+ * preferred cluster is granted whether or not Docker is up; the mode says which, because
45
+ * only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
46
+ * normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
47
+ * start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
48
+ */
49
+ export declare function nativeTestPostgresGrant(fallback: NativeTestPostgresFallback | null, dockerAvailable: boolean): NativeTestPostgresGrant | null;
14
50
  export declare class NativeTestPostgresFallbackError extends Error {
15
51
  readonly code = "native_test_postgres_fallback_invalid";
16
52
  constructor(detail: string);
@@ -20,6 +56,14 @@ export declare function resolveNativeTestPostgresFallbackPath(): string;
20
56
  export declare function configuredNativeTestPostgresFallbackPath(): string | null;
21
57
  /** Returns null when no fallback is configured; throws when one is configured unsafely. */
22
58
  export declare function readNativeTestPostgresFallback(configPath?: string): NativeTestPostgresFallback | null;
23
- export declare function parseNativeTestPostgresFallback(connectionString: string): NativeTestPostgresFallback;
24
- /** Environment for one runner-authored .NET test process using the fallback. */
25
- export declare function nativeTestPostgresFallbackEnvironment(fallback: NativeTestPostgresFallback): Readonly<Record<string, string>>;
59
+ export declare function parseNativeTestPostgresFallback(connectionString: string, use?: NativeTestPostgresUse): NativeTestPostgresFallback;
60
+ /** Environment for one runner-authored .NET test process using the cluster. */
61
+ export declare function nativeTestPostgresFallbackEnvironment(grant: Pick<NativeTestPostgresGrant, "connectionString" | "mode" | "ephemeralClusterId">): Readonly<Record<string, string>>;
62
+ /**
63
+ * Runner-authored verification uses the operator-provisioned native test cluster,
64
+ * which holds no real data, whenever its file prefers it (the default); Docker then
65
+ * only starts pinned-engine containers. A `docker_unavailable` cluster is used only
66
+ * when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
67
+ * database serves.
68
+ */
69
+ export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
@@ -1,12 +1,37 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { resolveLocalConfigPath } from "../cli/local-config.js";
4
+ import { DockerEngineProbe } from "./docker-engine-probe.js";
5
+ import { ephemeralTestPostgresClusterEnvironment } from "./ephemeral-test-postgres.js";
4
6
  import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "./host-runtime-contract.js";
5
7
  export const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE_TEST_POSTGRES_CONFIG";
6
8
  export const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
7
9
  export const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
10
+ /**
11
+ * The cluster serves the shared test server while Docker is up, so tests that need a
12
+ * pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
13
+ * first, which keeps test databases out of the Docker VM and saves RAM.
14
+ */
15
+ export const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
16
+ const nativeTestPostgresUses = ["preferred", "docker_unavailable", "ephemeral"];
8
17
  const defaultPostgresPort = 5432;
9
18
  const loopbackHosts = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
19
+ /**
20
+ * The provisioned cluster's grant for a check that can use it, or null to use Docker. A
21
+ * preferred cluster is granted whether or not Docker is up; the mode says which, because
22
+ * only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
23
+ * normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
24
+ * start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
25
+ */
26
+ export function nativeTestPostgresGrant(fallback, dockerAvailable) {
27
+ if (!fallback || (dockerAvailable && fallback.use !== "preferred"))
28
+ return null;
29
+ return {
30
+ connectionString: fallback.connectionString,
31
+ endpoint: fallback.endpoint,
32
+ mode: dockerAvailable ? nativeTestPostgresPreferredDatabaseMode : nativeTestPostgresFallbackDatabaseMode,
33
+ };
34
+ }
10
35
  export class NativeTestPostgresFallbackError extends Error {
11
36
  code = "native_test_postgres_fallback_invalid";
12
37
  constructor(detail) {
@@ -46,9 +71,17 @@ export function readNativeTestPostgresFallback(configPath = resolveNativeTestPos
46
71
  if (document.schemaVersion !== 1 || typeof document.connectionString !== "string") {
47
72
  throw new NativeTestPostgresFallbackError(`${configPath} must contain schemaVersion 1 and a connectionString.`);
48
73
  }
49
- return parseNativeTestPostgresFallback(document.connectionString);
74
+ if (document.use !== undefined && !nativeTestPostgresUses.includes(document.use)) {
75
+ throw new NativeTestPostgresFallbackError(`${configPath} 'use' must be 'preferred', 'docker_unavailable' or 'ephemeral'.`);
76
+ }
77
+ if (document.postgresBin !== undefined
78
+ && (typeof document.postgresBin !== "string" || !path.isAbsolute(document.postgresBin))) {
79
+ throw new NativeTestPostgresFallbackError(`${configPath} 'postgresBin' must be an absolute path.`);
80
+ }
81
+ const fallback = parseNativeTestPostgresFallback(document.connectionString, document.use ?? "preferred");
82
+ return typeof document.postgresBin === "string" ? { ...fallback, postgresBin: document.postgresBin } : fallback;
50
83
  }
51
- export function parseNativeTestPostgresFallback(connectionString) {
84
+ export function parseNativeTestPostgresFallback(connectionString, use = "preferred") {
52
85
  const fields = new Map();
53
86
  for (const segment of connectionString.split(";")) {
54
87
  const separator = segment.indexOf("=");
@@ -79,13 +112,32 @@ export function parseNativeTestPostgresFallback(connectionString) {
79
112
  if (!(fields.get("username") ?? fields.get("userid") ?? fields.get("user"))) {
80
113
  throw new NativeTestPostgresFallbackError("the fallback must name a dedicated test role.");
81
114
  }
82
- return { connectionString: connectionString.trim(), endpoint: `${host}:${port}` };
115
+ return { connectionString: connectionString.trim(), endpoint: `${host}:${port}`, use };
83
116
  }
84
- /** Environment for one runner-authored .NET test process using the fallback. */
85
- export function nativeTestPostgresFallbackEnvironment(fallback) {
117
+ /** Environment for one runner-authored .NET test process using the cluster. */
118
+ export function nativeTestPostgresFallbackEnvironment(grant) {
86
119
  return {
87
- [hostRuntimeTestPostgresAdminEnvironment]: fallback.connectionString,
88
- [hostRuntimeLegacyTestPostgresEnvironment]: fallback.connectionString,
89
- FORGE_MANAGED_VERIFICATION_DATABASE_MODE: nativeTestPostgresFallbackDatabaseMode,
120
+ [hostRuntimeTestPostgresAdminEnvironment]: grant.connectionString,
121
+ [hostRuntimeLegacyTestPostgresEnvironment]: grant.connectionString,
122
+ FORGE_MANAGED_VERIFICATION_DATABASE_MODE: grant.mode,
123
+ // The fixtures accept a superuser login only on the cluster that reports this id.
124
+ ...(grant.ephemeralClusterId ? { [ephemeralTestPostgresClusterEnvironment]: grant.ephemeralClusterId } : {}),
90
125
  };
91
126
  }
127
+ /**
128
+ * Runner-authored verification uses the operator-provisioned native test cluster,
129
+ * which holds no real data, whenever its file prefers it (the default); Docker then
130
+ * only starts pinned-engine containers. A `docker_unavailable` cluster is used only
131
+ * when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
132
+ * database serves.
133
+ */
134
+ export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().probeWithoutRecovery()).available, readFallback = () => {
135
+ const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
136
+ return configPath ? readNativeTestPostgresFallback(configPath) : null;
137
+ }) {
138
+ const fallback = readFallback();
139
+ if (!fallback)
140
+ return {};
141
+ const grant = nativeTestPostgresGrant(fallback, await dockerAvailable());
142
+ return grant ? nativeTestPostgresFallbackEnvironment(grant) : {};
143
+ }
@@ -4,3 +4,7 @@ export interface PreparedRuntimeIdentityDiagnostics {
4
4
  }
5
5
  /** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
6
6
  export declare function preparedRuntimeIdentity(worktreePath: string, signal?: AbortSignal, diagnostics?: PreparedRuntimeIdentityDiagnostics): Promise<HostParallelProofIdentity>;
7
+ /** Total bytes of git-ignored launch inputs one identity pass may read. */
8
+ export declare const ignoredLaunchInputByteBudget: number;
9
+ /** Whether a worktree-relative path is an isolation input (see isolationInputBasenames). */
10
+ export declare function isIsolationInputPath(name: string): boolean;
@@ -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?.entries.clear();
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
- diagnostics?.entries.set(name, digest.toString("hex"));
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
- diagnostics?.entries.set(name, disposition);
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
- diagnostics?.entries.set(`runtime-discovery:${name}`, digest?.toString("hex") ?? "absent");
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
- inputCommitSha: head,
209
- runtimeContractFingerprint: hostRuntimeContractFingerprint(contract),
210
- sourceFingerprint: `sha256:${hash.digest("hex")}`,
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 { RunOnceDispatchPacket } from "../session/session.types.js";
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,20 @@ export declare class PreparedRuntimeReadiness {
27
33
  private drain;
28
34
  private scheduleDeadline;
29
35
  private check;
36
+ /**
37
+ * The identity when the worktree needs no probe, or null to probe it. Recorded proof for the same
38
+ * isolation inputs already covers it: a re-apply conflict changes source, not those inputs, and the
39
+ * stack it defers starts at validation from the agent's resolved source, as any edited source does.
40
+ * Without proof, nothing is probed (no exclusive admission, no stack launch) when no proof could be
41
+ * recorded: a quarantined contract, or restored work with unresolved re-apply conflicts, which
42
+ * cannot build and which the agent resolves first (deferredProjectStartEvent in
43
+ * worktree-wip-events.ts). Those runs take exclusive admission.
44
+ */
45
+ private settledWithoutProbe;
46
+ /**
47
+ * A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
48
+ * contract is quarantined, or whose worktree still has unresolved WIP re-apply conflicts, records
49
+ * no proof. The agent's admission then finds none and runs under exclusive admission.
50
+ */
51
+ private unproven;
30
52
  }
@@ -1,8 +1,10 @@
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";
7
+ import { unresolvedReapplyConflicts, WipGit } from "../worktree/wip-git.js";
6
8
  /** Foreground barrier: prepare a wave, verify its exact runtimes, then release agents. */
7
9
  export class PreparedRuntimeReadiness {
8
10
  runtime;
@@ -43,6 +45,15 @@ export class PreparedRuntimeReadiness {
43
45
  }
44
46
  }
45
47
  has(id) { return this.preparations.has(id); }
48
+ /**
49
+ * Whether this fenced attempt is a live prepared-readiness probe. A probe exists only after
50
+ * check() found the prepared contract parallel-eligible, so the lease manager may admit it
51
+ * beside other shared-admission runs of the same repository instead of exclusively.
52
+ */
53
+ isParallelEligibleProbe(id, fence) {
54
+ return [...this.preparations.values()].some(entry => entry.probe?.sandbox.dispatchAttemptId === id
55
+ && entry.probe.lease.fencingToken === fence);
56
+ }
46
57
  hasPending() { return this.preparations.size > 0; }
47
58
  pendingSnapshots() {
48
59
  return [...this.preparations.values()].map(entry => ({
@@ -160,8 +171,9 @@ export class PreparedRuntimeReadiness {
160
171
  if (hostRuntimeContractFingerprint(contract) !== identity.runtimeContractFingerprint) {
161
172
  throw new Error("host_runtime_prepared_source_changed: runtime contract changed while capturing its source identity.");
162
173
  }
163
- if (await this.store.load(dispatch.repo.id, identity))
164
- return identity;
174
+ const settled = await this.settledWithoutProbe(entry, identity, worktree, checkpoint);
175
+ if (settled)
176
+ return settled;
165
177
  await checkpoint?.({ code: "host_runtime_prepared_probe_started", expiresAt: entry.expiresAt,
166
178
  message: `Verifying prepared runtime ${identity.inputCommitSha.slice(0, 12)} before agent admission; project-default readiness is not a substitute.` });
167
179
  const probeId = randomUUID();
@@ -172,11 +184,14 @@ export class PreparedRuntimeReadiness {
172
184
  inputCommitSha: identity.inputCommitSha },
173
185
  };
174
186
  entry.probe = probe;
187
+ // Any revocation from here on (this probe's own violation or a sibling's) voids its proof.
188
+ const revocationGeneration = await this.store.revocationGeneration(dispatch.repo.id);
175
189
  const stopPreparedHeadMonitor = new AbortController();
176
190
  const preparedHeadMonitor = monitorPreparedHead(worktree, identity.inputCommitSha, controller, stopPreparedHeadMonitor.signal);
177
191
  let cleanupConfirmed;
178
192
  let verifiedRuntimeContractFingerprint;
179
- let verifiedPorts;
193
+ let verifiedPorts = [];
194
+ let isolationViolated = false;
180
195
  try {
181
196
  controller.signal.throwIfAborted();
182
197
  await this.runtime.acquire(probe, controller.signal);
@@ -189,6 +204,12 @@ export class PreparedRuntimeReadiness {
189
204
  verifiedRuntimeContractFingerprint = hostRuntimeContractFingerprint(started.runtimeContract);
190
205
  verifiedPorts = started.lease.resources.ports.map(port => port.name).sort();
191
206
  }
207
+ catch (error) {
208
+ // A shared probe's stray listener: the lease stopped it and revoked the repository (see unproven).
209
+ if (!(error instanceof ForgeFailureError && error.failureCode === "host_runtime_isolation_violation"))
210
+ throw error;
211
+ isolationViolated = true;
212
+ }
192
213
  finally {
193
214
  stopPreparedHeadMonitor.abort();
194
215
  await preparedHeadMonitor;
@@ -199,25 +220,15 @@ export class PreparedRuntimeReadiness {
199
220
  if (!cleanupConfirmed) {
200
221
  throw new Error("host_runtime_prepared_probe_cleanup_unconfirmed: matching probe teardown was not confirmed.");
201
222
  }
223
+ if (isolationViolated)
224
+ return await this.unproven(entry, identity, checkpoint);
202
225
  // Probe-owned processes may create transient, untracked files while they
203
226
  // are alive. Verify the prepared source only after matching teardown is
204
227
  // confirmed: persistent source edits still fail closed, while files that
205
228
  // belong to the probe lifecycle cannot create a false source-change loop.
206
229
  const currentDiagnostics = { entries: new Map() };
207
230
  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
- }
231
+ const changed = identityChanges(identity, currentIdentity, verifiedRuntimeContractFingerprint, changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries));
221
232
  if (changed.length > 0) {
222
233
  throw new Error(`host_runtime_prepared_source_changed: ${changed.join(", ")} changed during isolation verification.`);
223
234
  }
@@ -225,12 +236,54 @@ export class PreparedRuntimeReadiness {
225
236
  throw new Error("host_runtime_prepared_probe_incomplete: assigned-port verification did not confirm every configured launch port.");
226
237
  }
227
238
  controller.signal.throwIfAborted();
228
- await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint);
239
+ const recorded = await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint, identity.isolationFingerprint, revocationGeneration)
240
+ .then(() => true, (error) => errorMessage(error).startsWith("host_parallel_promotion_revoked:")
241
+ ? false : Promise.reject(error));
242
+ if (!recorded)
243
+ return await this.unproven(entry, identity, checkpoint);
229
244
  await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
230
- message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its source-bound proof is retained independently.` });
245
+ message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its proof is retained for every head with the same isolation inputs.` });
246
+ return identity;
247
+ }
248
+ /**
249
+ * The identity when the worktree needs no probe, or null to probe it. Recorded proof for the same
250
+ * isolation inputs already covers it: a re-apply conflict changes source, not those inputs, and the
251
+ * stack it defers starts at validation from the agent's resolved source, as any edited source does.
252
+ * Without proof, nothing is probed (no exclusive admission, no stack launch) when no proof could be
253
+ * recorded: a quarantined contract, or restored work with unresolved re-apply conflicts, which
254
+ * cannot build and which the agent resolves first (deferredProjectStartEvent in
255
+ * worktree-wip-events.ts). Those runs take exclusive admission.
256
+ */
257
+ async settledWithoutProbe(entry, identity, worktree, checkpoint) {
258
+ const repoId = entry.dispatch.repo.id;
259
+ if (await this.store.load(repoId, identity))
260
+ return identity;
261
+ if (await this.store.quarantined(repoId, identity.runtimeContractFingerprint)) {
262
+ return await this.unproven(entry, identity, checkpoint, "quarantined");
263
+ }
264
+ // An unreadable conflict state is not probed either: the stack may not build.
265
+ const conflicted = await unresolvedReapplyConflicts(new WipGit(), worktree)
266
+ .then(conflicts => conflicts.length > 0 ? "reapply_conflicts" : null, () => "reapply_conflicts_unreadable");
267
+ return conflicted ? await this.unproven(entry, identity, checkpoint, conflicted) : null;
268
+ }
269
+ /**
270
+ * A probe whose repository was revoked while it ran (its own violation or a sibling's), or whose
271
+ * contract is quarantined, or whose worktree still has unresolved WIP re-apply conflicts, records
272
+ * no proof. The agent's admission then finds none and runs under exclusive admission.
273
+ */
274
+ async unproven(entry, identity, checkpoint, cause = "revoked") {
275
+ const reason = unprovenReasons[cause];
276
+ await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
277
+ message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} did not prove isolation (${reason}); its runs are serialized.` });
231
278
  return identity;
232
279
  }
233
280
  }
281
+ const unprovenReasons = {
282
+ revoked: "the repository's promotion was revoked during the probe",
283
+ quarantined: "its runtime contract is quarantined after a recent isolation violation, so it was not probed",
284
+ reapply_conflicts: "its worktree has unresolved conflicts from re-applied saved work, which the agent resolves first, so it was not probed",
285
+ reapply_conflicts_unreadable: "its worktree's record of conflicts from re-applied saved work could not be read, so it was not probed",
286
+ };
234
287
  const preparedHeadPollIntervalMs = 1_000;
235
288
  async function monitorPreparedHead(worktree, expectedCommitSha, preparationController, stopSignal) {
236
289
  const git = new GitClient();
@@ -274,6 +327,24 @@ async function waitForPreparedHeadPoll(signal) {
274
327
  function errorMessage(error) {
275
328
  return error instanceof Error ? error.message : String(error);
276
329
  }
330
+ /** What changed between the identity a probe started from and the one after its teardown. */
331
+ function identityChanges(prepared, current, verifiedRuntimeContractFingerprint, changedPaths) {
332
+ const changed = [];
333
+ if (verifiedRuntimeContractFingerprint !== prepared.runtimeContractFingerprint
334
+ || current.runtimeContractFingerprint !== prepared.runtimeContractFingerprint) {
335
+ changed.push("runtime contract");
336
+ }
337
+ if (current.inputCommitSha !== prepared.inputCommitSha)
338
+ changed.push("HEAD");
339
+ // Ignored launch inputs change only the isolation fingerprint; either change voids the proof.
340
+ if (current.sourceFingerprint !== prepared.sourceFingerprint
341
+ || current.isolationFingerprint !== prepared.isolationFingerprint) {
342
+ changed.push(changedPaths.length > 0
343
+ ? `source or isolation inputs (${changedPaths.join(", ")})`
344
+ : "source or isolation inputs");
345
+ }
346
+ return changed;
347
+ }
277
348
  function changedIdentityPaths(before, after) {
278
349
  const paths = new Set([...before.keys(), ...after.keys()]);
279
350
  const changed = [...paths]
@@ -98,3 +98,7 @@ export declare function parseRunnerSettingsDocument(raw: unknown): RunnerSetting
98
98
  export declare function runnerSettingsInForce(report: RunnerSettingsReport, previous: RunnerSettingsReport, failures: readonly RunnerSettingRejection[]): RunnerSettingsReport;
99
99
  /** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
100
100
  export declare function sameRunnerSettingsReport(left: RunnerSettingsReport, right: RunnerSettingsReport): boolean;
101
+ /** The offer refusal message while the runner yields to foreground work. */
102
+ export declare function runnerYieldingMessage(report: RunnerSettingsReport): string;
103
+ /** One line describing the effective settings, for the bridge log. */
104
+ export declare function describeRunnerSettings(report: RunnerSettingsReport): string;