@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5

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 (275) hide show
  1. package/README.md +146 -5
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +137 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  6. package/dist/bridge/bridge.base.d.ts +13 -1
  7. package/dist/bridge/bridge.service.d.ts +155 -4
  8. package/dist/bridge/bridge.service.js +1805 -155
  9. package/dist/bridge/bridge.types.d.ts +68 -1
  10. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  11. package/dist/bridge/dispatch-result-outbox.js +87 -0
  12. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  13. package/dist/bridge/dispatch-result-worker.js +122 -0
  14. package/dist/bridge/internals.d.ts +2 -0
  15. package/dist/bridge/internals.js +1 -0
  16. package/dist/bridge/local-yield-flag.d.ts +6 -0
  17. package/dist/bridge/local-yield-flag.js +34 -0
  18. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  19. package/dist/bridge/readiness-result-outbox.js +54 -0
  20. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  21. package/dist/bridge/readiness-result-worker.js +121 -0
  22. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  23. package/dist/bridge/runner-host-capabilities.js +110 -0
  24. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  25. package/dist/bridge/test-postgres-capability.js +120 -0
  26. package/dist/cleanup/cleanup.service.d.ts +10 -0
  27. package/dist/cleanup/cleanup.service.js +128 -104
  28. package/dist/cleanup/cleanup.types.d.ts +4 -0
  29. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  30. package/dist/cleanup/forge-owned-paths.js +53 -0
  31. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  32. package/dist/cleanup/host-runtime-ledger.js +109 -0
  33. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  34. package/dist/cleanup/managed-branch-sweep.js +111 -0
  35. package/dist/cli/cli.help.js +22 -4
  36. package/dist/cli/cli.service.d.ts +30 -6
  37. package/dist/cli/cli.service.js +216 -31
  38. package/dist/cli/local-config.d.ts +5 -0
  39. package/dist/cli/local-config.js +30 -4
  40. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  41. package/dist/runtime/aspnet-runtime-prebuild.js +429 -0
  42. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  43. package/dist/runtime/attempt-database-broker.js +390 -0
  44. package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
  45. package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
  46. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  47. package/dist/runtime/attempt-path-operation.js +94 -0
  48. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  49. package/dist/runtime/attempt-private-directory.js +54 -0
  50. package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
  51. package/dist/runtime/attempt-process-supervisor.js +144 -23
  52. package/dist/runtime/canonical-source-file.d.ts +3 -0
  53. package/dist/runtime/canonical-source-file.js +54 -0
  54. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  55. package/dist/runtime/docker-engine-probe.js +333 -0
  56. package/dist/runtime/generated-output-reset.d.ts +10 -0
  57. package/dist/runtime/generated-output-reset.js +62 -8
  58. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  59. package/dist/runtime/host-database-capability-boundary.js +63 -0
  60. package/dist/runtime/host-diagnostics.d.ts +11 -0
  61. package/dist/runtime/host-diagnostics.js +192 -0
  62. package/dist/runtime/host-execution-root.d.ts +4 -0
  63. package/dist/runtime/host-execution-root.js +39 -0
  64. package/dist/runtime/host-facts.d.ts +36 -0
  65. package/dist/runtime/host-facts.js +95 -0
  66. package/dist/runtime/host-listener-inspector.d.ts +8 -1
  67. package/dist/runtime/host-listener-inspector.js +121 -60
  68. package/dist/runtime/host-load-admission.d.ts +67 -0
  69. package/dist/runtime/host-load-admission.js +99 -0
  70. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  71. package/dist/runtime/host-load-child-environment.js +76 -0
  72. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  73. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  74. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  75. package/dist/runtime/host-load-governor-config.js +83 -0
  76. package/dist/runtime/host-load-governor.d.ts +184 -0
  77. package/dist/runtime/host-load-governor.js +632 -0
  78. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  79. package/dist/runtime/host-load-ledger-lock.js +185 -0
  80. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  81. package/dist/runtime/host-load-runtime-settings.js +78 -0
  82. package/dist/runtime/host-load-sampler.d.ts +149 -0
  83. package/dist/runtime/host-load-sampler.js +291 -0
  84. package/dist/runtime/host-load-step-class.d.ts +70 -0
  85. package/dist/runtime/host-load-step-class.js +161 -0
  86. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  87. package/dist/runtime/host-load-step-reaper.js +95 -0
  88. package/dist/runtime/host-load-step-run.d.ts +73 -0
  89. package/dist/runtime/host-load-step-run.js +102 -0
  90. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  91. package/dist/runtime/host-load-test-slot.js +81 -0
  92. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  93. package/dist/runtime/host-load-token-ledger.js +453 -0
  94. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  95. package/dist/runtime/host-load-windows-cpu.js +85 -0
  96. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  97. package/dist/runtime/host-pressure-stall.js +168 -0
  98. package/dist/runtime/host-runtime-contract.d.ts +16 -1
  99. package/dist/runtime/host-runtime-contract.js +174 -56
  100. package/dist/runtime/host-runtime-lease.d.ts +163 -9
  101. package/dist/runtime/host-runtime-lease.js +1464 -121
  102. package/dist/runtime/host-runtime-promotion.d.ts +35 -3
  103. package/dist/runtime/host-runtime-promotion.js +107 -12
  104. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  105. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  106. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  107. package/dist/runtime/host-runtime-requirements.js +117 -0
  108. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  109. package/dist/runtime/managed-command-teardown.js +607 -0
  110. package/dist/runtime/memory-capacity.d.ts +70 -0
  111. package/dist/runtime/memory-capacity.js +123 -0
  112. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  113. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  114. package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
  115. package/dist/runtime/node-host-runtime-adapter.js +29 -11
  116. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  117. package/dist/runtime/pinned-directory-process.js +61 -0
  118. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  119. package/dist/runtime/pinned-source-directory.js +94 -0
  120. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  121. package/dist/runtime/playwright-browser-cache.js +227 -0
  122. package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
  123. package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
  124. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  125. package/dist/runtime/prepared-runtime-identity.js +218 -0
  126. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  127. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  128. package/dist/runtime/runner-settings.d.ts +100 -0
  129. package/dist/runtime/runner-settings.js +214 -0
  130. package/dist/runtime/runtime-isolation-lease.js +4 -1
  131. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  132. package/dist/runtime/workspace-resource-estimator.js +174 -0
  133. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  134. package/dist/sandbox/host-capacity-broker.js +334 -0
  135. package/dist/sandbox/preflight.d.ts +31 -1
  136. package/dist/sandbox/preflight.js +237 -51
  137. package/dist/sandbox/repository-lock.d.ts +2 -1
  138. package/dist/sandbox/repository-lock.js +19 -9
  139. package/dist/sandbox/runtime.d.ts +16 -2
  140. package/dist/sandbox/runtime.js +182 -109
  141. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  142. package/dist/sandbox/sandbox-cgroups.js +42 -0
  143. package/dist/sandbox/sandbox.types.d.ts +7 -0
  144. package/dist/sandbox/workspace.service.js +2 -0
  145. package/dist/session/architect-waits.d.ts +2 -0
  146. package/dist/session/architect-waits.js +138 -0
  147. package/dist/session/managed-attempt-tools.d.ts +44 -1
  148. package/dist/session/managed-attempt-tools.js +816 -46
  149. package/dist/session/managed-build-coordinator.d.ts +5 -0
  150. package/dist/session/managed-build-coordinator.js +109 -0
  151. package/dist/session/managed-build-receipt.d.ts +21 -0
  152. package/dist/session/managed-build-receipt.js +337 -0
  153. package/dist/session/managed-command-host-load.d.ts +47 -0
  154. package/dist/session/managed-command-host-load.js +83 -0
  155. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  156. package/dist/session/managed-verification-timeouts.js +17 -0
  157. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  158. package/dist/session/mcp-argument-coercion.js +121 -0
  159. package/dist/session/phase-completion.artifacts.d.ts +24 -0
  160. package/dist/session/phase-completion.artifacts.js +319 -44
  161. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  162. package/dist/session/phase-completion.command-validation.js +77 -0
  163. package/dist/session/phase-completion.d.ts +15 -1
  164. package/dist/session/phase-completion.helpers.d.ts +5 -0
  165. package/dist/session/phase-completion.helpers.js +43 -19
  166. package/dist/session/phase-completion.js +18 -3
  167. package/dist/session/phase-completion.prompts.js +22 -18
  168. package/dist/session/phase-completion.runtime.d.ts +6 -2
  169. package/dist/session/phase-completion.runtime.js +191 -47
  170. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  171. package/dist/session/phase-completion.schema-parts.js +188 -0
  172. package/dist/session/phase-completion.schemas.d.ts +3 -3
  173. package/dist/session/phase-completion.schemas.js +250 -226
  174. package/dist/session/phase-completion.validation.d.ts +3 -3
  175. package/dist/session/phase-completion.validation.js +135 -89
  176. package/dist/session/pre-publication-host-load.d.ts +27 -0
  177. package/dist/session/pre-publication-host-load.js +111 -0
  178. package/dist/session/pre-publication-pass.d.ts +61 -0
  179. package/dist/session/pre-publication-pass.js +148 -0
  180. package/dist/session/pre-publication-process.d.ts +23 -0
  181. package/dist/session/pre-publication-process.js +109 -0
  182. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  183. package/dist/session/pre-publication-skipped-tests.js +109 -0
  184. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  185. package/dist/session/pre-publication-step-execution.js +49 -0
  186. package/dist/session/pre-publication-validation.d.ts +87 -0
  187. package/dist/session/pre-publication-validation.js +668 -0
  188. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  189. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  190. package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
  191. package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
  192. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  193. package/dist/session/provider-cli/claude-background-work.js +180 -0
  194. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  195. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  196. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
  197. package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
  198. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  199. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  200. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  201. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  202. package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
  203. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  204. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  205. package/dist/session/provider-cli/provider-cli.process.d.ts +92 -14
  206. package/dist/session/provider-cli/provider-cli.process.js +583 -210
  207. package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
  208. package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
  209. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  210. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  211. package/dist/session/provider-cli/provider-cli.runtime.d.ts +14 -1
  212. package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
  213. package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
  214. package/dist/session/provider-cli/provider-cli.service.js +819 -84
  215. package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
  216. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  217. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  218. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  219. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  220. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  221. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  222. package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
  223. package/dist/session/provider-cli/provider-output-state.js +376 -17
  224. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  225. package/dist/session/provider-cli/provider-usage.js +28 -5
  226. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  227. package/dist/session/publishable-worktree-changes.js +193 -0
  228. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  229. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  230. package/dist/session/session-redaction.js +434 -9
  231. package/dist/session/session.base.d.ts +9 -1
  232. package/dist/session/session.service.d.ts +9 -2
  233. package/dist/session/session.service.js +264 -27
  234. package/dist/session/session.types.d.ts +150 -2
  235. package/dist/session/session.types.js +599 -7
  236. package/dist/session/unreferenced-exports.d.ts +12 -0
  237. package/dist/session/unreferenced-exports.js +59 -0
  238. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  239. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  240. package/dist/shared/format/format-bytes.d.ts +1 -0
  241. package/dist/shared/format/format-bytes.js +9 -0
  242. package/dist/shared/git/git.js +2 -1
  243. package/dist/shared/path/path.d.ts +1 -0
  244. package/dist/shared/path/path.js +18 -0
  245. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  246. package/dist/shared/process/dotnet-toolchain.js +307 -0
  247. package/dist/shared/process/host-process-recovery.js +3 -2
  248. package/dist/shared/process/host-process-supervisor.d.ts +3 -0
  249. package/dist/shared/process/host-process-supervisor.js +61 -12
  250. package/dist/shared/process/process-tree.d.ts +52 -0
  251. package/dist/shared/process/process-tree.js +144 -0
  252. package/dist/shared/process/process.d.ts +69 -0
  253. package/dist/shared/process/process.js +223 -16
  254. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  255. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  256. package/dist/shared/process/windows-launch.d.ts +18 -0
  257. package/dist/shared/process/windows-launch.js +68 -0
  258. package/dist/shared/provider-capabilities.d.ts +3 -0
  259. package/dist/shared/provider-capabilities.js +84 -0
  260. package/dist/shared/redaction/redaction.d.ts +1 -0
  261. package/dist/shared/redaction/redaction.js +39 -3
  262. package/dist/shared/time/monotonic.d.ts +1 -0
  263. package/dist/shared/time/monotonic.js +8 -0
  264. package/dist/version.d.ts +1 -1
  265. package/dist/version.js +1 -1
  266. package/dist/worktree/dependency-warmer.d.ts +66 -9
  267. package/dist/worktree/dependency-warmer.js +609 -24
  268. package/dist/worktree/index.d.ts +1 -1
  269. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  270. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  271. package/dist/worktree/worktree.service.d.ts +17 -1
  272. package/dist/worktree/worktree.service.js +293 -21
  273. package/dist/worktree/worktree.types.d.ts +14 -1
  274. package/package.json +8 -6
  275. package/runtime/windows-job-supervisor.ps1 +380 -14
@@ -1,20 +1,34 @@
1
1
  import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "./session-redaction.js";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.js";
4
+ import { ForgeFailureError, waitKindForEvent, waitWakeCondition } from "./session.types.js";
3
5
  import { GitWorktreeService } from "../worktree/worktree.service.js";
4
6
  import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
5
- import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, } from "../runtime/host-runtime-lease.js";
7
+ import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
6
8
  import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
9
+ import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
7
10
  const minimumReadinessProbeStartupBudgetMs = 150_000;
8
11
  export class BridgeSessionService {
9
12
  worktrees;
10
13
  providerCli;
11
14
  hostRuntime;
15
+ workspaceFingerprint;
12
16
  constructor(worktrees = process.env.FORGE_SANDBOX_ID
13
17
  ? new SandboxWorkspaceService()
14
- : new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime) {
18
+ : new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime, workspaceFingerprint = readWorkspaceRuntimeFingerprint) {
15
19
  this.worktrees = worktrees;
16
20
  this.providerCli = providerCli;
17
21
  this.hostRuntime = hostRuntime;
22
+ this.workspaceFingerprint = workspaceFingerprint;
23
+ }
24
+ setHostRequirementsCheck(check) {
25
+ this.hostRuntime?.setRequirementsCheck?.(check);
26
+ }
27
+ runnerLimitDefaults() {
28
+ return this.hostRuntime?.capacityLimitDefaults?.() ?? null;
29
+ }
30
+ applyRunnerLimits(limits) {
31
+ this.hostRuntime?.applyCapacityLimits?.(limits);
18
32
  }
19
33
  async updateLease(dispatchAttemptId, fencingToken, expiresAt) {
20
34
  await this.hostRuntime?.updateLease(dispatchAttemptId, fencingToken, expiresAt);
@@ -37,9 +51,12 @@ export class BridgeSessionService {
37
51
  let cleanupFailure = null;
38
52
  try {
39
53
  throwIfAborted(signal);
40
- await this.hostRuntime.invalidatePromotion?.(request.repoId);
41
54
  await this.hostRuntime.acquire(dispatch, signal);
42
55
  admissionAcquired = true;
56
+ // Readiness probes acquire background-exclusive project admission. Only
57
+ // invalidate the prior proof after that fence is held so a user lane can
58
+ // never observe the proof disappear underneath shared admission.
59
+ await this.hostRuntime.invalidatePromotion?.(request.repoId, "discovery");
43
60
  assertReadinessProbeStartupBudget(request.expiresAt);
44
61
  worktree = await this.worktrees.prepare({
45
62
  repo: dispatch.repo,
@@ -51,8 +68,13 @@ export class BridgeSessionService {
51
68
  lane: "runtime_readiness",
52
69
  phase: "readiness_probe",
53
70
  allowedRepoRoot: request.repoRoot,
54
- cleanupWorktrees: request.cleanupWorktrees,
71
+ // Readiness probes are disposable infrastructure checks, not agent lanes.
72
+ // Always remove their worktree even when the bridge is configured to retain
73
+ // failed agent worktrees for inspection.
74
+ cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
55
75
  artifacts: [],
76
+ hostLoadOwner: { dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null, priority: "background" },
77
+ signal,
56
78
  });
57
79
  assertReadinessProbeStartupBudget(request.expiresAt);
58
80
  let started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
@@ -63,6 +85,7 @@ export class BridgeSessionService {
63
85
  status: "serialized",
64
86
  runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
65
87
  runtimeContractSource: started.runtimeContract.source,
88
+ runtimeRequirements: started.runtimeContract.contract.requires ?? null,
66
89
  reasonCode: discovery?.reasonCode ?? "host_runtime_contract_serialized",
67
90
  reasonMessage: discovery?.summary ?? "The detected runtime requires serialized host execution.",
68
91
  checkedAt: new Date().toISOString(),
@@ -79,6 +102,7 @@ export class BridgeSessionService {
79
102
  status: "parallel_ready",
80
103
  runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
81
104
  runtimeContractSource: started.runtimeContract.source,
105
+ runtimeRequirements: started.runtimeContract.contract.requires ?? null,
82
106
  reasonCode: null,
83
107
  reasonMessage: null,
84
108
  qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
@@ -120,18 +144,39 @@ export class BridgeSessionService {
120
144
  validateApiKeySecretGrant(dispatch);
121
145
  const redactionSecrets = exactSecrets(dispatch);
122
146
  const events = [];
147
+ let waitObservationVersion = 0;
148
+ const waitFirstObservedAt = new Map();
149
+ const waitObservation = (eventType, queuePosition) => {
150
+ const occurredAt = new Date().toISOString();
151
+ const kind = waitKindForEvent(eventType);
152
+ const firstObservedAt = waitFirstObservedAt.get(kind) ?? occurredAt;
153
+ waitFirstObservedAt.set(kind, firstObservedAt);
154
+ waitObservationVersion += 1;
155
+ const wait = {
156
+ schemaVersion: 2,
157
+ kind,
158
+ scope: "project",
159
+ resourceKeys: [`project-runtime:${dispatch.repo.id}`],
160
+ ...(queuePosition === undefined ? {} : { queuePosition }),
161
+ wakeCondition: waitWakeCondition(kind),
162
+ firstObservedAt,
163
+ observationVersion: waitObservationVersion,
164
+ contractOrigin: "bridge_v2",
165
+ };
166
+ return { occurredAt, wait };
167
+ };
123
168
  const emit = async (event) => {
124
169
  if (signal?.aborted) {
125
170
  return;
126
171
  }
127
- const redacted = redactRunnerDispatchEvent(event, redactionSecrets);
172
+ const redacted = redactRunnerDispatchEvent({ ...event, eventId: event.eventId ?? randomUUID() }, redactionSecrets);
128
173
  if (redacted.eventType !== "provider_tool_heartbeat") {
129
174
  events.push(redacted);
130
175
  }
131
176
  await sink.emit(redacted);
132
177
  };
133
178
  const emitLifecycle = async (event) => {
134
- const redacted = redactRunnerDispatchEvent(event, redactionSecrets);
179
+ const redacted = redactRunnerDispatchEvent({ ...event, eventId: event.eventId ?? randomUUID() }, redactionSecrets);
135
180
  events.push(redacted);
136
181
  await sink.emit(redacted);
137
182
  };
@@ -147,14 +192,31 @@ export class BridgeSessionService {
147
192
  let hostLease = null;
148
193
  try {
149
194
  if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
195
+ const capacity = this.hostRuntime.snapshot?.() ?? null;
196
+ const projectCapacity = capacity?.projects.find(project => project.repoId === dispatch.repo.id) ?? null;
197
+ const admissionWait = waitObservation("host_runtime_admission_waiting", capacity ? capacity.waitingAttempts + 1 : undefined);
150
198
  await emitLifecycle({
151
199
  role: "runner",
152
200
  kind: "checkpoint",
153
- content: "Evaluating runner-local managed host admission before preparing the worktree.",
201
+ content: capacity
202
+ ? `Waiting for host-runtime admission before preparing the worktree (queue position ${capacity.waitingAttempts + 1}; runner ${capacity.activeAttempts} active, ${capacity.reservedAttempts} reserved; project ${projectCapacity?.activeAttempts ?? 0} active, ${projectCapacity?.waitingAttempts ?? 0} already waiting). This wait can be caused by the project serialization policy, readiness proof, or resource headroom; Forge will continue automatically when admission is available.`
203
+ : "Waiting for host-runtime admission before preparing the worktree. Forge will continue automatically when admission is available.",
154
204
  eventType: "host_runtime_admission_waiting",
205
+ ...admissionWait,
206
+ data: capacity ? JSON.stringify({
207
+ queue_position: capacity.waitingAttempts + 1,
208
+ runner_active_attempts: capacity.activeAttempts,
209
+ runner_reserved_attempts: capacity.reservedAttempts,
210
+ runner_waiting_attempts: capacity.waitingAttempts,
211
+ project_active_attempts: projectCapacity?.activeAttempts ?? 0,
212
+ project_reserved_attempts: projectCapacity?.reservedAttempts ?? 0,
213
+ project_waiting_attempts: projectCapacity?.waitingAttempts ?? 0,
214
+ project_safety_class: projectCapacity?.safetyClass ?? "unknown",
215
+ }) : undefined,
155
216
  });
156
217
  try {
157
- hostSingletonKeys = await this.hostRuntime.acquire(dispatch, signal);
218
+ hostSingletonKeys = await (this.hostRuntime.acquirePreparation?.(dispatch, signal)
219
+ ?? this.hostRuntime.acquire(dispatch, signal));
158
220
  }
159
221
  catch (error) {
160
222
  if (error instanceof HostRuntimeAdmissionExpiredError) {
@@ -168,13 +230,17 @@ export class BridgeSessionService {
168
230
  throw error;
169
231
  }
170
232
  throwIfAborted(signal);
233
+ const admissionAcquired = waitObservation("host_runtime_admission_acquired");
171
234
  await emitLifecycle({
172
235
  role: "runner",
173
236
  kind: "checkpoint",
174
- content: hostSingletonKeys.length > 0
175
- ? `Acquired managed host singleton ${hostSingletonKeys.join(", ")}.`
176
- : "Observed assigned-port evidence permits provisional parallel host admission; the prepared runtime contract must still match before launch.",
237
+ content: this.hostRuntime.acquirePreparation
238
+ ? "Acquired worktree-preparation capacity. Prepared runtime verification must finish before agent admission."
239
+ : hostSingletonKeys.length > 0
240
+ ? `Acquired managed host singleton ${hostSingletonKeys.join(", ")}.`
241
+ : "Observed assigned-port evidence permits provisional parallel host admission; the prepared runtime contract must still match before launch.",
177
242
  eventType: "host_runtime_admission_acquired",
243
+ ...admissionAcquired,
178
244
  });
179
245
  }
180
246
  try {
@@ -191,20 +257,33 @@ export class BridgeSessionService {
191
257
  cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
192
258
  artifacts: dispatch.artifacts,
193
259
  priorPhaseArtifacts: dispatch.priorPhaseArtifacts,
260
+ storyQa: dispatch.storyQa,
261
+ referenceRunId: dispatch.sandbox?.dispatchAttemptId ?? dispatch.cycleRun.id,
262
+ referenceCycleRunId: dispatch.cycleRun.id,
263
+ effectivePlanAmendmentHash: dispatch.cycleRun.effectivePlanAmendmentHash,
194
264
  qaRework: dispatch.qaRework,
195
- warmPathOverrides: dispatch.warmPathOverrides
265
+ warmPathOverrides: dispatch.warmPathOverrides,
266
+ applicationRuntimeRequired: dispatch.runtimeIntent.applicationRuntimeRequired,
267
+ preserveExistingState: Boolean(dispatch.session.resumedFromSessionId),
268
+ hostLoadOwner: {
269
+ dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null,
270
+ priority: runtimeAdmissionPriority(dispatch),
271
+ },
272
+ signal,
196
273
  });
197
274
  }
198
275
  catch (error) {
199
- throw new Error(`worktree_prepare_failed: ${failureMessage(error)}`, { cause: error });
276
+ throw new ForgeFailureError("worktree_prepare_failed", `worktree_prepare_failed: ${failureMessage(error)}`, "bridge", { cause: error });
200
277
  }
201
278
  let providerDispatch = withPreparedQaReworkPacket(dispatch, worktree.qaReworkPacketPath);
202
279
  throwIfAborted(signal);
203
280
  await emit({
204
281
  role: "runner",
205
282
  kind: "checkpoint",
206
- content: `Prepared worktree ${worktree.branchName}.`,
207
- eventType: "worktree_prepared"
283
+ content: dispatch.session.resumedFromSessionId
284
+ ? `Reattached to worktree ${worktree.branchName} without resetting source or clearing attempt artifacts.`
285
+ : `Prepared worktree ${worktree.branchName}.`,
286
+ eventType: dispatch.session.resumedFromSessionId ? "worktree_reattached" : "worktree_prepared"
208
287
  });
209
288
  if ((worktree.hydratedPriorPhaseArtifactCount ?? 0) > 0) {
210
289
  await emit({
@@ -218,7 +297,17 @@ export class BridgeSessionService {
218
297
  await emitDependencyWarmEvents(worktree.dependencyWarm, emit);
219
298
  }
220
299
  if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
221
- hostLease = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
300
+ hostLease = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal, async (checkpoint) => {
301
+ const observation = waitObservation(checkpoint.code);
302
+ await emitLifecycle({
303
+ role: "runner",
304
+ kind: "checkpoint",
305
+ content: checkpoint.message,
306
+ eventType: checkpoint.code,
307
+ ...observation,
308
+ data: JSON.stringify({ expires_at: checkpoint.expiresAt }),
309
+ });
310
+ });
222
311
  await emitLifecycle({
223
312
  role: "runner",
224
313
  kind: "checkpoint",
@@ -238,7 +327,15 @@ export class BridgeSessionService {
238
327
  }),
239
328
  });
240
329
  const unconfiguredPortCount = hostLease.lease.resources.ports.length;
241
- hostLease = await this.hostRuntime.startConfiguredProject(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken, signal);
330
+ hostLease = await this.hostRuntime.startConfiguredProject(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken, signal, async (checkpoint) => {
331
+ await emitLifecycle({
332
+ role: "runner",
333
+ kind: "checkpoint",
334
+ content: checkpoint.message,
335
+ eventType: checkpoint.code,
336
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
337
+ });
338
+ });
242
339
  if (hostLease.lease.resources.ports.length > unconfiguredPortCount) {
243
340
  const assigned = hostLease.lease.resources.ports.at(-1);
244
341
  await emitLifecycle({
@@ -250,7 +347,98 @@ export class BridgeSessionService {
250
347
  });
251
348
  }
252
349
  }
350
+ // The stack was built and launched from this workspace state. Pre-publication
351
+ // validation restarts it when the provider has changed the source since.
352
+ let refreshRuntimeEnvironment;
353
+ const hostRuntime = this.hostRuntime;
354
+ if (hostLease && dispatch.sandbox && hostRuntime?.restartConfiguredProject
355
+ && hostLease.executionClass === "managed_runtime"
356
+ && configuredLaunchPortNames(hostLease.runtimeContract).length > 0) {
357
+ const worktreePath = worktree.worktreePath;
358
+ const dispatchAttemptId = dispatch.sandbox.dispatchAttemptId;
359
+ const fencingToken = dispatch.lease.fencingToken;
360
+ const restartConfiguredProject = hostRuntime.restartConfiguredProject.bind(hostRuntime);
361
+ let launchFingerprint = await this.workspaceFingerprint(worktreePath)
362
+ .catch(() => null);
363
+ // Set while the stack may not match the workspace: a failed restart is retried on the next pass.
364
+ let restartPending = false;
365
+ refreshRuntimeEnvironment = async (refreshSignal) => {
366
+ const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
367
+ if (!restartPending && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
368
+ return null;
369
+ // Every cause that applies is reported; `reason` is the first of them. Changes are named
370
+ // only when both states were read: an unreadable baseline is not a workspace change.
371
+ const comparable = launchFingerprint !== null && current !== null;
372
+ const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
373
+ const causes = [
374
+ ...(restartPending ? ["previous_restart_incomplete"] : []),
375
+ ...(comparable ? [] : ["fingerprint_unavailable"]),
376
+ ...(changes.length > 0 ? ["workspace_changed"] : []),
377
+ ];
378
+ const reason = causes[0] ?? "workspace_changed";
379
+ const changeText = changes.length > 0 ? ` The workspace also changed since launch (${changes.join(", ")}).` : "";
380
+ await emitLifecycle({
381
+ role: "runner",
382
+ kind: "checkpoint",
383
+ content: reason === "workspace_changed"
384
+ ? `The workspace changed since the attempt runtime stack was launched (${changes.join(", ")}); restarting it so validation runs against the current source.`
385
+ : reason === "previous_restart_incomplete"
386
+ ? `The previous attempt runtime restart did not complete; restarting it again so validation runs against the current source.${changeText}`
387
+ : `The workspace state could not be compared with the attempt runtime stack; restarting it so validation runs against the current source.`,
388
+ eventType: "host_runtime_restart_started",
389
+ data: JSON.stringify({
390
+ reason,
391
+ causes,
392
+ changes,
393
+ head_sha: current?.headSha ?? null,
394
+ merge_in_progress: Boolean(current?.mergeHead),
395
+ }),
396
+ });
397
+ restartPending = true;
398
+ let restarted;
399
+ try {
400
+ restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
401
+ await emitLifecycle({
402
+ role: "runner",
403
+ kind: "checkpoint",
404
+ content: checkpoint.message,
405
+ eventType: checkpoint.code,
406
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
407
+ });
408
+ });
409
+ }
410
+ catch (error) {
411
+ await emitLifecycle({
412
+ role: "runner",
413
+ kind: "error",
414
+ content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
415
+ eventType: "host_runtime_restart_failed",
416
+ data: JSON.stringify({ reason, causes, changes }),
417
+ }).catch(() => undefined);
418
+ throw error;
419
+ }
420
+ hostLease = restarted;
421
+ // The restarted stack serves the workspace as it is now. Read that state again rather than
422
+ // keep the pre-restart reading, which is null when it could not be collected; a null
423
+ // baseline never matches, so every later pass would restart and rotate ports again.
424
+ launchFingerprint = await this.workspaceFingerprint(worktreePath).catch(() => current);
425
+ restartPending = false;
426
+ await emitLifecycle({
427
+ role: "runner",
428
+ kind: "checkpoint",
429
+ content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
430
+ eventType: "host_runtime_restarted",
431
+ data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
432
+ });
433
+ return { environment: restarted.environment, reason, changes };
434
+ };
435
+ }
253
436
  providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease);
437
+ const providerEnvironment = {
438
+ runtimeEnvironment: hostLease?.environment,
439
+ // Only the completion MCP server gets these: its managed commands share the host ledger.
440
+ hostLoadEnvironment: hostLease ? this.hostRuntime?.hostLoadChildEnvironment?.() : undefined,
441
+ };
254
442
  if (dispatch.draft) {
255
443
  throwIfAborted(signal);
256
444
  const processRunner = hostLease && dispatch.sandbox
@@ -259,7 +447,7 @@ export class BridgeSessionService {
259
447
  const run = await this.providerCli.runDraft({
260
448
  dispatch: providerDispatch,
261
449
  worktree,
262
- runtimeEnvironment: hostLease?.environment,
450
+ ...providerEnvironment,
263
451
  processRunner,
264
452
  emit,
265
453
  signal
@@ -267,7 +455,7 @@ export class BridgeSessionService {
267
455
  throwIfAborted(signal);
268
456
  const draftArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
269
457
  return redactRunOnceResultPacket({
270
- schemaVersion: 1,
458
+ schemaVersion: 2,
271
459
  exitCode: 0,
272
460
  summary: run.summary,
273
461
  events,
@@ -287,10 +475,13 @@ export class BridgeSessionService {
287
475
  const context = {
288
476
  dispatch: providerDispatch,
289
477
  worktree,
290
- runtimeEnvironment: hostLease?.environment,
478
+ ...providerEnvironment,
291
479
  processRunner: hostLease && dispatch.sandbox
292
480
  ? this.hostRuntime?.providerProcessRunner?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken) ?? undefined
293
481
  : undefined,
482
+ ...(refreshRuntimeEnvironment && hostLease
483
+ ? { refreshRuntimeEnvironment, runtimeStackEnvironmentKeys: hostRuntimeStackEnvironmentKeys(hostLease.runtimeContract) }
484
+ : {}),
294
485
  emit,
295
486
  signal
296
487
  };
@@ -308,18 +499,21 @@ export class BridgeSessionService {
308
499
  }
309
500
  catch (error) {
310
501
  const message = failureMessage(error);
311
- if (message.includes("attempt_process_supervisor_start_")
312
- || message.includes("host_process_supervisor_start_")) {
313
- throw new Error(`provider_start_unavailable: ${message}`, { cause: error });
502
+ if (error instanceof ForgeFailureError
503
+ && (error.failureCode === "attempt_process_supervisor_start_failed"
504
+ || error.failureCode === "attempt_process_supervisor_start_timeout")) {
505
+ throw new ForgeFailureError("provider_start_unavailable", `provider_start_unavailable: ${message}`, "bridge", { cause: error });
314
506
  }
315
507
  throw error;
316
508
  }
317
509
  throwIfAborted(signal);
318
510
  const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
319
511
  return redactRunOnceResultPacket({
320
- schemaVersion: 1,
512
+ schemaVersion: 2,
321
513
  exitCode: 0,
322
514
  summary: run.summary,
515
+ resultCommitSha: run.resultCommitSha ?? null,
516
+ publishedCommitSha: run.publishedCommitSha ?? null,
323
517
  events,
324
518
  spec: run.spec ?? null,
325
519
  artifact: run.artifact ?? null,
@@ -328,6 +522,25 @@ export class BridgeSessionService {
328
522
  }
329
523
  finally {
330
524
  if (hostLease && dispatch.sandbox) {
525
+ const providerMemory = this.hostRuntime?.providerMemoryTelemetry?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
526
+ if (providerMemory) {
527
+ await emitLifecycle({
528
+ role: "runner",
529
+ kind: "checkpoint",
530
+ content: `Observed managed-host provider process-tree peak memory ${formatMemoryBytes(providerMemory.peakMemoryBytes)} from ${providerMemory.sampleCount} sample${providerMemory.sampleCount === 1 ? "" : "s"}.`,
531
+ eventType: "sandbox_peak_memory_observed",
532
+ occurredAt: providerMemory.observedAt,
533
+ data: JSON.stringify({
534
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
535
+ sampleCount: providerMemory.sampleCount,
536
+ source: providerMemory.source,
537
+ containers: [{
538
+ role: "agent",
539
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
540
+ }],
541
+ }),
542
+ }).catch(() => undefined);
543
+ }
331
544
  const teardownAt = new Date().toISOString();
332
545
  await emitLifecycle({
333
546
  role: "runner",
@@ -351,7 +564,7 @@ export class BridgeSessionService {
351
564
  await emitLifecycle({
352
565
  role: "runner",
353
566
  kind: "checkpoint",
354
- content: `Released host runtime lease ${released.leaseId}.`,
567
+ content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
355
568
  eventType: "sandbox_teardown_completed",
356
569
  occurredAt: released.releasedAt,
357
570
  }).catch(() => undefined);
@@ -370,7 +583,7 @@ export class BridgeSessionService {
370
583
  if (!hostLease && hostSingletonKeys && dispatch.sandbox) {
371
584
  await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken).catch(() => undefined);
372
585
  }
373
- if (worktree)
586
+ if (worktree && !isPauseCancellation(signal))
374
587
  await this.worktrees.release(worktree);
375
588
  }
376
589
  }
@@ -378,6 +591,13 @@ export class BridgeSessionService {
378
591
  function failureMessage(error) {
379
592
  return error instanceof Error ? error.message : String(error);
380
593
  }
594
+ function formatMemoryBytes(bytes) {
595
+ return `${(bytes / (1024 ** 2)).toFixed(bytes >= 1024 ** 3 ? 0 : 1)} MiB`;
596
+ }
597
+ function isPauseCancellation(signal) {
598
+ return signal?.aborted === true
599
+ && String(signal.reason ?? "").trim().toLowerCase() === "session pause requested";
600
+ }
381
601
  function readinessProbeDispatch(request) {
382
602
  return {
383
603
  schemaVersion: 2,
@@ -433,7 +653,7 @@ function readinessProbeDispatch(request) {
433
653
  runnerRepoLocalPath: request.runnerRepoLocalPath,
434
654
  },
435
655
  runtimeIntent: { executionClass: "managed_runtime", applicationRuntimeRequired: true },
436
- serverLocal: { repoRoot: request.repoRoot, cleanupWorktrees: request.cleanupWorktrees },
656
+ serverLocal: { repoRoot: request.repoRoot, cleanupWorktrees: true },
437
657
  sandbox: {
438
658
  dispatchAttemptId: request.requestId,
439
659
  executionLeaseId: request.requestId,
@@ -552,6 +772,23 @@ function withPreparedQaReworkPacket(dispatch, packetPath) {
552
772
  };
553
773
  }
554
774
  async function emitDependencyWarmEvents(warm, emit) {
775
+ for (const receipt of warm.receipts) {
776
+ await emit({
777
+ role: "runner",
778
+ kind: "checkpoint",
779
+ content: receipt.cacheHit
780
+ ? `Reused verified ${receipt.ecosystem} dependency preparation receipt ${receipt.fingerprint} in ${receipt.packageRoot}.`
781
+ : `Published ${receipt.ecosystem} dependency preparation receipt ${receipt.fingerprint} in ${receipt.packageRoot}.`,
782
+ eventType: receipt.cacheHit ? "dependencies_preparation_cached" : "dependencies_preparation_receipt_published",
783
+ data: JSON.stringify({
784
+ ecosystem: receipt.ecosystem,
785
+ package_root: receipt.packageRoot,
786
+ cache_hit: receipt.cacheHit,
787
+ fingerprint: receipt.fingerprint,
788
+ receipt_path: receipt.receiptPath,
789
+ }),
790
+ });
791
+ }
555
792
  if (warm.linked.length > 0) {
556
793
  await emit({
557
794
  role: "runner",