@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
@@ -1,12 +1,15 @@
1
+ // forge-bridge run-once's review placement guard (pr-review-placement.ts).
2
+ export { runOnceWithReviewPlacement } from "./pr-review-placement.js";
1
3
  import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "./session-redaction.js";
2
4
  import { randomUUID } from "node:crypto";
3
5
  import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.js";
4
6
  import { ForgeFailureError, waitKindForEvent, waitWakeCondition } from "./session.types.js";
5
- import { GitWorktreeService } from "../worktree/worktree.service.js";
7
+ import { emitWorktreePreparedEvents, GitWorktreeService, sessionWipOutcome, settleWorktree, } from "../worktree/worktree.service.js";
6
8
  import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
7
9
  import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
8
10
  import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
9
- import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
11
+ import { managedQaLaunchTarget, startOrDeferConfiguredProject, withMaterializedManagedQaTarget, } from "./session-host-project.js";
12
+ import { createConfiguredRuntimeRefresh, readWorkspaceRuntimeFingerprint, } from "./session.runtime-refresh.js";
10
13
  const minimumReadinessProbeStartupBudgetMs = 150_000;
11
14
  export class BridgeSessionService {
12
15
  worktrees;
@@ -77,7 +80,7 @@ export class BridgeSessionService {
77
80
  signal,
78
81
  });
79
82
  assertReadinessProbeStartupBudget(request.expiresAt);
80
- let started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
83
+ const started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
81
84
  runtimeStarted = true;
82
85
  const discovery = started.runtimeContract.discovery;
83
86
  if (!hostRuntimeParallelEligible(started.runtimeContract)) {
@@ -92,23 +95,7 @@ export class BridgeSessionService {
92
95
  };
93
96
  }
94
97
  else {
95
- assertReadinessProbeStartupBudget(request.expiresAt);
96
- started = await this.hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal);
97
- const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
98
- const verifiedPorts = started.lease.resources.ports.map(port => port.name);
99
- const verified = requiredPorts.length > 0 && requiredPorts.every(name => verifiedPorts.includes(name));
100
- result = verified
101
- ? {
102
- status: "parallel_ready",
103
- runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
104
- runtimeContractSource: started.runtimeContract.source,
105
- runtimeRequirements: started.runtimeContract.contract.requires ?? null,
106
- reasonCode: null,
107
- reasonMessage: null,
108
- qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
109
- checkedAt: new Date().toISOString(),
110
- }
111
- : failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
98
+ result = await this.probeConfiguredProject(this.hostRuntime, request, started, signal);
112
99
  }
113
100
  }
114
101
  catch (error) {
@@ -190,6 +177,7 @@ export class BridgeSessionService {
190
177
  let worktree = null;
191
178
  let hostSingletonKeys = null;
192
179
  let hostLease = null;
180
+ let succeeded = false;
193
181
  try {
194
182
  if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
195
183
  const capacity = this.hostRuntime.snapshot?.() ?? null;
@@ -265,10 +253,10 @@ export class BridgeSessionService {
265
253
  warmPathOverrides: dispatch.warmPathOverrides,
266
254
  applicationRuntimeRequired: dispatch.runtimeIntent.applicationRuntimeRequired,
267
255
  preserveExistingState: Boolean(dispatch.session.resumedFromSessionId),
268
- hostLoadOwner: {
269
- dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null,
270
- priority: runtimeAdmissionPriority(dispatch),
271
- },
256
+ // A review reads the exact pull request head, detached; it never works on a lease branch.
257
+ detachedHeadSha: prReviewHeadSha(dispatch),
258
+ sessionId: dispatch.session.id,
259
+ ...preparedAttemptOwner(dispatch),
272
260
  signal,
273
261
  });
274
262
  }
@@ -285,6 +273,7 @@ export class BridgeSessionService {
285
273
  : `Prepared worktree ${worktree.branchName}.`,
286
274
  eventType: dispatch.session.resumedFromSessionId ? "worktree_reattached" : "worktree_prepared"
287
275
  });
276
+ await emitWorktreePreparedEvents(worktree, emit);
288
277
  if ((worktree.hydratedPriorPhaseArtifactCount ?? 0) > 0) {
289
278
  await emit({
290
279
  role: "runner",
@@ -296,6 +285,10 @@ export class BridgeSessionService {
296
285
  if (worktree.dependencyWarm) {
297
286
  await emitDependencyWarmEvents(worktree.dependencyWarm, emit);
298
287
  }
288
+ // Conflicts a WIP re-apply left for the agent (deferredProjectStartEvent): the project stack
289
+ // is not started on them, and the prompt names them.
290
+ const reapplyConflicts = worktree.reapplyConflicts;
291
+ let projectStartDeferred = false;
299
292
  if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
300
293
  hostLease = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal, async (checkpoint) => {
301
294
  const observation = waitObservation(checkpoint.code);
@@ -326,114 +319,25 @@ export class BridgeSessionService {
326
319
  remediation: "Enable Run in Docker in Project Settings.",
327
320
  }),
328
321
  });
329
- const unconfiguredPortCount = hostLease.lease.resources.ports.length;
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
- });
339
- if (hostLease.lease.resources.ports.length > unconfiguredPortCount) {
340
- const assigned = hostLease.lease.resources.ports.at(-1);
341
- await emitLifecycle({
342
- role: "runner",
343
- kind: "checkpoint",
344
- content: `Verified supervised project runtime ${assigned.name} on ${assigned.hostIp}:${assigned.hostPort}.`,
345
- eventType: "host_runtime_project_ready",
346
- data: JSON.stringify(hostRuntimeEventResources(hostLease.lease, hostLease.runtimeContract, hostLease.executionClass)),
347
- });
348
- }
322
+ ({ hostLease, deferred: projectStartDeferred } = await startOrDeferConfiguredProject(this.hostRuntime, hostLease, dispatch, reapplyConflicts, signal, emitLifecycle));
349
323
  }
350
324
  // The stack was built and launched from this workspace state. Pre-publication
351
325
  // 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
- }
326
+ const refreshRuntimeEnvironment = await createConfiguredRuntimeRefresh({
327
+ hostLease,
328
+ dispatch,
329
+ hostRuntime: this.hostRuntime,
330
+ worktreePath: worktree.worktreePath,
331
+ readFingerprint: this.workspaceFingerprint,
332
+ emitLifecycle,
333
+ signal,
334
+ assertRunning: () => this.throwIfAbortedOrIsolationViolated(undefined, dispatch, hostLease),
335
+ onRestarted: restarted => {
420
336
  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
- }
436
- providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease);
337
+ },
338
+ startDeferred: projectStartDeferred
339
+ });
340
+ providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease, projectStartDeferred);
437
341
  const providerEnvironment = {
438
342
  runtimeEnvironment: hostLease?.environment,
439
343
  // Only the completion MCP server gets these: its managed commands share the host ledger.
@@ -452,17 +356,18 @@ export class BridgeSessionService {
452
356
  emit,
453
357
  signal
454
358
  });
455
- throwIfAborted(signal);
359
+ this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
456
360
  const draftArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
457
- return redactRunOnceResultPacket({
458
- schemaVersion: 2,
459
- exitCode: 0,
460
- summary: run.summary,
361
+ // Redaction can throw (a secret in a structural field); only a returned result is a success.
362
+ const draftResult = redactRunOnceResultPacket({
363
+ schemaVersion: 2, exitCode: 0, summary: run.summary,
461
364
  events,
462
365
  spec: run.spec ?? null,
463
366
  artifact: run.artifact ?? null,
464
367
  artifacts: draftArtifacts
465
368
  }, redactionSecrets);
369
+ succeeded = true;
370
+ return draftResult;
466
371
  }
467
372
  throwIfAborted(signal);
468
373
  const lane = dispatch.execution.lane.trim().toLowerCase();
@@ -472,6 +377,7 @@ export class BridgeSessionService {
472
377
  const isArchitect = role === "architect" || lane === "architect" || cycleKind === "architect";
473
378
  const isCiRepair = role === "ci_repair" || lane === "ci_repair" || cycleKind === "pr_checks";
474
379
  const isConflictResolve = role === "conflict_resolve" || lane === "conflict_resolve";
380
+ const isPrReview = role === "pr_review" || lane === "pr_review" || cycleKind === "pr_review";
475
381
  const context = {
476
382
  dispatch: providerDispatch,
477
383
  worktree,
@@ -482,20 +388,24 @@ export class BridgeSessionService {
482
388
  ...(refreshRuntimeEnvironment && hostLease
483
389
  ? { refreshRuntimeEnvironment, runtimeStackEnvironmentKeys: hostRuntimeStackEnvironmentKeys(hostLease.runtimeContract) }
484
390
  : {}),
391
+ reapplyConflicts,
392
+ projectStartDeferred,
485
393
  emit,
486
394
  signal
487
395
  };
488
396
  let run;
489
397
  try {
490
- run = isQa
491
- ? await this.providerCli.runQa(context)
492
- : isArchitect
493
- ? await this.providerCli.runArchitect(context)
494
- : isCiRepair
495
- ? await this.providerCli.runCiRepair(context)
496
- : isConflictResolve
497
- ? await this.providerCli.runConflictResolve(context)
498
- : await this.providerCli.runImplementation(context);
398
+ run = isPrReview
399
+ ? await this.providerCli.runPrReview(context)
400
+ : isQa
401
+ ? await this.providerCli.runQa(context)
402
+ : isArchitect
403
+ ? await this.providerCli.runArchitect(context)
404
+ : isCiRepair
405
+ ? await this.providerCli.runCiRepair(context)
406
+ : isConflictResolve
407
+ ? await this.providerCli.runConflictResolve(context)
408
+ : await this.providerCli.runImplementation(context);
499
409
  }
500
410
  catch (error) {
501
411
  const message = failureMessage(error);
@@ -506,12 +416,10 @@ export class BridgeSessionService {
506
416
  }
507
417
  throw error;
508
418
  }
509
- throwIfAborted(signal);
419
+ this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
510
420
  const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
511
- return redactRunOnceResultPacket({
512
- schemaVersion: 2,
513
- exitCode: 0,
514
- summary: run.summary,
421
+ const result = redactRunOnceResultPacket({
422
+ schemaVersion: 2, exitCode: 0, summary: run.summary,
515
423
  resultCommitSha: run.resultCommitSha ?? null,
516
424
  publishedCommitSha: run.publishedCommitSha ?? null,
517
425
  events,
@@ -519,74 +427,113 @@ export class BridgeSessionService {
519
427
  artifact: run.artifact ?? null,
520
428
  artifacts: phaseArtifacts
521
429
  }, redactionSecrets);
430
+ succeeded = true;
431
+ return result;
522
432
  }
523
433
  finally {
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
- }
544
- const teardownAt = new Date().toISOString();
434
+ await this.releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle);
435
+ if (worktree) {
436
+ await settleWorktree(this.worktrees, worktree, sessionWipOutcome(signal, events, succeeded), signal, emitLifecycle);
437
+ }
438
+ }
439
+ }
440
+ /** Launches a parallel-eligible probe's project, unless its contract is quarantined and so could never earn proof. */
441
+ async probeConfiguredProject(hostRuntime, request, started, signal) {
442
+ if (await hostRuntime.promotionQuarantined?.(request.repoId, hostRuntimeContractFingerprint(started.runtimeContract))) {
443
+ // Not launched; the server retries on its backoff, and the check passes once the quarantine expires.
444
+ return failedProbe("host_runtime_isolation_quarantined", "The runtime contract is quarantined after a recent isolation violation, so it was not probed; its runs stay serialized.");
445
+ }
446
+ assertReadinessProbeStartupBudget(request.expiresAt);
447
+ let isolationDetail = null;
448
+ const launched = await hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal, async (checkpoint) => {
449
+ if (checkpoint.code === "host_runtime_isolation_serialized")
450
+ isolationDetail = checkpoint.message;
451
+ });
452
+ return configuredProbeResult(launched, isolationDetail);
453
+ }
454
+ /** A late isolation violation stopped the attempt's project in the background: fail rather than report success. */
455
+ throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease) {
456
+ throwIfAborted(signal);
457
+ const violation = hostLease && dispatch.sandbox
458
+ ? this.hostRuntime?.isolationViolation?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken)
459
+ : null;
460
+ if (violation)
461
+ throw violation;
462
+ }
463
+ /** Reports the provider's peak memory and releases the attempt's host runtime lease. */
464
+ async releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle) {
465
+ if (hostLease && dispatch.sandbox) {
466
+ const providerMemory = this.hostRuntime?.providerMemoryTelemetry?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
467
+ if (providerMemory) {
545
468
  await emitLifecycle({
546
469
  role: "runner",
547
470
  kind: "checkpoint",
548
- content: `Releasing host runtime lease ${hostLease.lease.leaseId}.`,
549
- eventType: "sandbox_teardown_started",
550
- occurredAt: teardownAt,
471
+ content: `Observed managed-host provider process-tree peak memory ${formatMemoryBytes(providerMemory.peakMemoryBytes)} from ${providerMemory.sampleCount} sample${providerMemory.sampleCount === 1 ? "" : "s"}.`,
472
+ eventType: "sandbox_peak_memory_observed",
473
+ occurredAt: providerMemory.observedAt,
474
+ data: JSON.stringify({
475
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
476
+ sampleCount: providerMemory.sampleCount,
477
+ source: providerMemory.source,
478
+ containers: [{
479
+ role: "agent",
480
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
481
+ }],
482
+ }),
551
483
  }).catch(() => undefined);
552
- try {
553
- const released = await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
554
- if (!released) {
555
- await emitLifecycle({
556
- role: "runner",
557
- kind: "error",
558
- content: "Host runtime cleanup requires reconciliation: the runtime lease was not current during release.",
559
- eventType: "teardown_failed",
560
- occurredAt: new Date().toISOString(),
561
- }).catch(() => undefined);
562
- }
563
- else {
564
- await emitLifecycle({
565
- role: "runner",
566
- kind: "checkpoint",
567
- content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
568
- eventType: "sandbox_teardown_completed",
569
- occurredAt: released.releasedAt,
570
- }).catch(() => undefined);
571
- }
572
- }
573
- catch (error) {
484
+ }
485
+ const teardownAt = new Date().toISOString();
486
+ await emitLifecycle({
487
+ role: "runner",
488
+ kind: "checkpoint",
489
+ content: `Releasing host runtime lease ${hostLease.lease.leaseId}.`,
490
+ eventType: "sandbox_teardown_started",
491
+ occurredAt: teardownAt,
492
+ }).catch(() => undefined);
493
+ try {
494
+ const released = await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
495
+ if (!released) {
574
496
  await emitLifecycle({
575
497
  role: "runner",
576
498
  kind: "error",
577
- content: `Host runtime cleanup requires reconciliation: ${error instanceof Error ? error.message : String(error)}`,
499
+ content: "Host runtime cleanup requires reconciliation: the runtime lease was not current during release.",
578
500
  eventType: "teardown_failed",
579
501
  occurredAt: new Date().toISOString(),
580
502
  }).catch(() => undefined);
581
503
  }
504
+ else {
505
+ await emitLifecycle({
506
+ role: "runner",
507
+ kind: "checkpoint",
508
+ content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
509
+ eventType: "sandbox_teardown_completed",
510
+ occurredAt: released.releasedAt,
511
+ }).catch(() => undefined);
512
+ }
582
513
  }
583
- if (!hostLease && hostSingletonKeys && dispatch.sandbox) {
584
- await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken).catch(() => undefined);
514
+ catch (error) {
515
+ await emitLifecycle({
516
+ role: "runner",
517
+ kind: "error",
518
+ content: `Host runtime cleanup requires reconciliation: ${error instanceof Error ? error.message : String(error)}`,
519
+ eventType: "teardown_failed",
520
+ occurredAt: new Date().toISOString(),
521
+ }).catch(() => undefined);
585
522
  }
586
- if (worktree && !isPauseCancellation(signal))
587
- await this.worktrees.release(worktree);
588
523
  }
524
+ if (!hostLease && hostSingletonKeys && dispatch.sandbox) {
525
+ await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken).catch(() => undefined);
526
+ }
527
+ }
528
+ }
529
+ function prReviewHeadSha(dispatch) {
530
+ const lane = dispatch.execution.lane.trim().toLowerCase();
531
+ const role = dispatch.execution.role.trim().toLowerCase();
532
+ const kind = dispatch.cycleRun.kind.trim().toLowerCase();
533
+ if (role !== "pr_review" && lane !== "pr_review" && kind !== "pr_review") {
534
+ return null;
589
535
  }
536
+ return (dispatch.prReview?.headSha || dispatch.pullRequest?.headSha || "").trim() || null;
590
537
  }
591
538
  function failureMessage(error) {
592
539
  return error instanceof Error ? error.message : String(error);
@@ -594,10 +541,6 @@ function failureMessage(error) {
594
541
  function formatMemoryBytes(bytes) {
595
542
  return `${(bytes / (1024 ** 2)).toFixed(bytes >= 1024 ** 3 ? 0 : 1)} MiB`;
596
543
  }
597
- function isPauseCancellation(signal) {
598
- return signal?.aborted === true
599
- && String(signal.reason ?? "").trim().toLowerCase() === "session pause requested";
600
- }
601
544
  function readinessProbeDispatch(request) {
602
545
  return {
603
546
  schemaVersion: 2,
@@ -677,6 +620,31 @@ function readinessProbeDispatch(request) {
677
620
  artifacts: [],
678
621
  };
679
622
  }
623
+ /**
624
+ * A probe is parallel_ready only when every configured port proved readiness and the launch earned the
625
+ * parallel promotion, which an isolation violation or a quarantined contract withholds while it runs.
626
+ */
627
+ function configuredProbeResult(started, isolationDetail) {
628
+ const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
629
+ const verifiedPorts = started.lease.resources.ports.map(port => port.name);
630
+ if (requiredPorts.length === 0 || !requiredPorts.every(name => verifiedPorts.includes(name))) {
631
+ return failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
632
+ }
633
+ if (started.environment.FORGE_HOST_CONCURRENCY !== "host_parallel_safe") {
634
+ return failedProbe("host_runtime_isolation_violation", isolationDetail
635
+ ?? "The application served every Forge-assigned port, but did not earn parallel-safety proof for this runtime contract.");
636
+ }
637
+ return {
638
+ status: "parallel_ready",
639
+ runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
640
+ runtimeContractSource: started.runtimeContract.source,
641
+ runtimeRequirements: started.runtimeContract.contract.requires ?? null,
642
+ reasonCode: null,
643
+ reasonMessage: null,
644
+ qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
645
+ checkedAt: new Date().toISOString(),
646
+ };
647
+ }
680
648
  function failedProbe(reasonCode, reasonMessage) {
681
649
  return { status: "failed", reasonCode, reasonMessage, checkedAt: new Date().toISOString() };
682
650
  }
@@ -686,43 +654,6 @@ function assertReadinessProbeStartupBudget(expiresAt) {
686
654
  throw new Error("host_runtime_probe_deadline_insufficient: readiness admission completed too close to the probe deadline; Forge released the reservation before launching the application.");
687
655
  }
688
656
  }
689
- function managedQaLaunchTarget(runtimeContract) {
690
- const playwright = runtimeContract.contract.runtime.playwright;
691
- if (!playwright)
692
- return null;
693
- const port = runtimeContract.contract.runtime.ports.find(candidate => candidate.name === playwright.baseUrlPort);
694
- return port?.launch && port.baseUrlEnv && port.format
695
- ? { managedRuntimePort: port.name, routes: ["/"] }
696
- : null;
697
- }
698
- function withMaterializedManagedQaTarget(dispatch, hostLease) {
699
- const target = dispatch.qaBrowser?.launchTarget;
700
- const portName = target?.managed_runtime_port?.trim().toLowerCase();
701
- if (!target || !portName)
702
- return dispatch;
703
- if (!hostLease) {
704
- throw new Error("qa_managed_runtime_unavailable: Browser QA requires the verified managed host runtime selected during readiness.");
705
- }
706
- const normalizedName = portName.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
707
- const url = hostLease.environment[`FORGE_${normalizedName}_URL`];
708
- if (!url) {
709
- throw new Error(`qa_managed_runtime_unavailable: verified runtime port '${portName}' was not launched for this attempt.`);
710
- }
711
- return {
712
- ...dispatch,
713
- qaBrowser: dispatch.qaBrowser ? {
714
- ...dispatch.qaBrowser,
715
- launchTarget: {
716
- ...target,
717
- url: target.url ?? url,
718
- ready_url: target.ready_url ?? url,
719
- notes: [target.notes, "Forge launched and verified this URL inside the current fenced attempt."]
720
- .filter(Boolean)
721
- .join(" "),
722
- },
723
- } : dispatch.qaBrowser,
724
- };
725
- }
726
657
  function probeFailureCode(error) {
727
658
  const message = error instanceof Error ? error.message : String(error);
728
659
  const candidate = message.split(":", 1)[0]?.trim().toLowerCase() ?? "";
@@ -737,6 +668,13 @@ function throwIfAborted(signal) {
737
668
  throw new Error(String(signal.reason ?? "Dispatch cancelled."));
738
669
  }
739
670
  }
671
+ /** The dispatch attempt a worktree is prepared for: Forge's attempt for its WIP refs, and whose host load it reserves. */
672
+ function preparedAttemptOwner(dispatch) {
673
+ return {
674
+ wipAttempt: dispatch.wipAttempt ?? null,
675
+ hostLoadOwner: { dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null, priority: runtimeAdmissionPriority(dispatch) },
676
+ };
677
+ }
740
678
  function validateApiKeySecretGrant(dispatch) {
741
679
  if (!dispatch.execution.requiresApiKeySecretGrant) {
742
680
  return;
@@ -1,4 +1,6 @@
1
1
  import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
2
+ import { type DispatchPrReviewContext } from "./session.types.pr-review.js";
3
+ export type { DispatchPrReviewContext, DispatchPrReviewPriorReview, DispatchPrReviewThread, DispatchPrReviewThreadComment } from "./session.types.pr-review.js";
2
4
  export interface RunOnceDispatchPacket {
3
5
  readonly schemaVersion: 1 | 2;
4
6
  readonly userId: string;
@@ -11,7 +13,10 @@ export interface RunOnceDispatchPacket {
11
13
  readonly runtimeIntent: DispatchRuntimeIntent;
12
14
  readonly serverLocal: DispatchServerLocalConfig;
13
15
  readonly sandbox?: DispatchSandboxContext | null;
16
+ readonly wipAttempt?: number | null;
14
17
  readonly pullRequest?: DispatchPullRequestContext | null;
18
+ /** Review-only context for the pr_review lane: the head to review and the Story spec text. */
19
+ readonly prReview?: DispatchPrReviewContext | null;
15
20
  readonly apiKeySecretGrant?: ApiKeySecretGrant | null;
16
21
  readonly apiKeySecretGrantHandle?: ApiKeySecretGrantHandle | null;
17
22
  readonly artifacts: readonly DispatchResolvedArtifact[];