@cnc-tools/storm 0.16.0 → 0.18.0

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 (290) hide show
  1. package/dist/bin/storm.js +54 -40
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
  4. package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
  5. package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
  6. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
  7. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  8. package/dist/chunks/chunk-AS37D43E.js +2173 -0
  9. package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
  10. package/dist/chunks/chunk-DZLU7BYK.js +340 -0
  11. package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
  12. package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
  13. package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
  14. package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
  15. package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
  16. package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
  17. package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
  18. package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
  19. package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
  20. package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
  21. package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
  22. package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
  23. package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
  24. package/dist/chunks/chunk-SZMYIIG2.js +88 -0
  25. package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
  26. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
  27. package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
  28. package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
  29. package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
  30. package/dist/cli.d.ts +28 -0
  31. package/dist/cli.js +64 -0
  32. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
  33. package/dist/commands/exec/across-sandboxes-outcomes.js +3 -3
  34. package/dist/commands/exec/before-run.d.ts +123 -0
  35. package/dist/commands/exec/before-run.js +105 -0
  36. package/dist/commands/exec/command.d.ts +67 -14
  37. package/dist/commands/exec/command.js +31 -95
  38. package/dist/commands/exec/driver-plan.d.ts +9 -4
  39. package/dist/commands/exec/driver-plan.js +8 -8
  40. package/dist/commands/exec/exec-words.js +1 -1
  41. package/dist/commands/exec/execute-run.d.ts +39 -0
  42. package/dist/commands/exec/execute-run.js +325 -0
  43. package/dist/commands/exec/live-view.d.ts +3 -3
  44. package/dist/commands/exec/live-view.js +16 -15
  45. package/dist/commands/exec/metadata.js +1 -1
  46. package/dist/commands/exec/mint-failed.d.ts +38 -0
  47. package/dist/commands/exec/mint-failed.js +27 -4
  48. package/dist/commands/exec/outcomes.d.ts +104 -22
  49. package/dist/commands/exec/outcomes.js +73 -26
  50. package/dist/commands/exec/plan-run.d.ts +58 -150
  51. package/dist/commands/exec/plan-run.js +239 -90
  52. package/dist/commands/exec/progress.d.ts +10 -6
  53. package/dist/commands/exec/progress.js +38 -25
  54. package/dist/commands/exec/run-bin.d.ts +11 -11
  55. package/dist/commands/exec/run-bin.js +9 -9
  56. package/dist/commands/exec/run-flags.d.ts +69 -0
  57. package/dist/commands/exec/run-flags.js +58 -0
  58. package/dist/commands/exec/run-metadata.js +4 -4
  59. package/dist/commands/exec/run-summary.d.ts +58 -0
  60. package/dist/commands/exec/run-summary.js +205 -0
  61. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  62. package/dist/commands/exec/runner-refusals.js +71 -0
  63. package/dist/commands/exec/sandbox-progress.js +3 -0
  64. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  65. package/dist/commands/exec/stopped-outcome.js +77 -0
  66. package/dist/commands/exec/view.d.ts +20 -11
  67. package/dist/commands/exec/view.js +103 -47
  68. package/dist/commands/runs/facts.d.ts +8 -4
  69. package/dist/commands/runs/facts.js +19 -10
  70. package/dist/commands/runs/list/command.d.ts +16 -8
  71. package/dist/commands/runs/list/command.js +10 -10
  72. package/dist/commands/runs/list/outcomes.d.ts +8 -4
  73. package/dist/commands/runs/logs/command.js +10 -10
  74. package/dist/commands/runs/show/command.d.ts +16 -8
  75. package/dist/commands/runs/show/command.js +31 -29
  76. package/dist/commands/runs/show/metadata.js +1 -1
  77. package/dist/commands/runs/show/outcomes.d.ts +8 -4
  78. package/dist/commands/runs/show/outcomes.js +8 -6
  79. package/dist/commands/snapshots/access.d.ts +111 -0
  80. package/dist/commands/snapshots/access.js +96 -0
  81. package/dist/commands/snapshots/build/command.d.ts +376 -101
  82. package/dist/commands/snapshots/build/command.js +447 -149
  83. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  84. package/dist/commands/snapshots/build/metadata.js +31 -11
  85. package/dist/commands/snapshots/build/outcomes.d.ts +242 -47
  86. package/dist/commands/snapshots/build/outcomes.js +200 -36
  87. package/dist/commands/snapshots/list/command.d.ts +368 -27
  88. package/dist/commands/snapshots/list/command.js +298 -68
  89. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  90. package/dist/commands/snapshots/list/metadata.js +29 -6
  91. package/dist/commands/snapshots/list/outcomes.d.ts +247 -15
  92. package/dist/commands/snapshots/list/outcomes.js +223 -52
  93. package/dist/commands/snapshots/metadata.js +1 -1
  94. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  95. package/dist/commands/snapshots/prune/command.js +161 -0
  96. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  97. package/dist/commands/snapshots/prune/metadata.js +39 -0
  98. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  99. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  100. package/dist/commands/suites/list/command.js +17 -17
  101. package/dist/commands/suites/list/outcomes.js +2 -2
  102. package/dist/commands/test/command.d.ts +67 -14
  103. package/dist/commands/test/command.js +49 -252
  104. package/dist/commands/test/outcomes.d.ts +33 -7
  105. package/dist/config/check-runner.d.ts +3 -3
  106. package/dist/config/check-runner.js +8 -7
  107. package/dist/config/credential-resolver.d.ts +50 -5
  108. package/dist/config/credential-resolver.js +51 -19
  109. package/dist/config/credential-settle.d.ts +6 -2
  110. package/dist/config/credential-settle.js +11 -5
  111. package/dist/config/index.d.ts +2 -2
  112. package/dist/config/index.js +1 -1
  113. package/dist/config/runner.d.ts +5 -5
  114. package/dist/config/runner.js +1 -1
  115. package/dist/config/schema.d.ts +2 -2
  116. package/dist/config/schema.js +1 -1
  117. package/dist/config-file/define.d.ts +1 -1
  118. package/dist/config-file/define.js +1 -1
  119. package/dist/config-file/runner.d.ts +5 -5
  120. package/dist/config-file/toolchain.d.ts +14 -4
  121. package/dist/config-file/toolchain.js +43 -7
  122. package/dist/context.d.ts +10 -6
  123. package/dist/context.js +8 -6
  124. package/dist/core/across-sandboxes.d.ts +7 -6
  125. package/dist/core/across-sandboxes.js +123 -152
  126. package/dist/core/coordinator.d.ts +166 -0
  127. package/dist/core/coordinator.js +233 -0
  128. package/dist/core/events.d.ts +2 -2
  129. package/dist/core/index.d.ts +4 -2
  130. package/dist/core/index.js +1 -1
  131. package/dist/core/outcomes.d.ts +148 -0
  132. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  133. package/dist/core/resources.d.ts +31 -53
  134. package/dist/core/resources.js +32 -70
  135. package/dist/core/run-state.d.ts +7 -1
  136. package/dist/core/run-state.js +2 -0
  137. package/dist/core/run.d.ts +32 -236
  138. package/dist/core/run.js +107 -267
  139. package/dist/core/state-directory.d.ts +1 -1
  140. package/dist/core/state-directory.js +2 -2
  141. package/dist/credential/gateways.d.ts +15 -1
  142. package/dist/credential/index.d.ts +4 -3
  143. package/dist/credential/index.js +3 -2
  144. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  145. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  146. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  147. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  148. package/dist/credential/source.d.ts +73 -6
  149. package/dist/credential/source.js +55 -2
  150. package/dist/extension-commands.d.ts +1 -1
  151. package/dist/extension-commands.js +2 -2
  152. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  153. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  154. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  155. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  156. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  157. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  158. package/dist/extensions/testserver/credential-facts.js +29 -11
  159. package/dist/extensions/testserver/lifecycle.js +7 -1
  160. package/dist/extensions/testserver/limit.d.ts +3 -0
  161. package/dist/extensions/testserver/limit.js +3 -0
  162. package/dist/extensions/testserver/provision.d.ts +8 -1
  163. package/dist/extensions/testserver/provision.js +8 -3
  164. package/dist/extensions/testserver/refusals.d.ts +6 -1
  165. package/dist/extensions/testserver/refusals.js +16 -1
  166. package/dist/extensions/testserver/resource.d.ts +1 -1
  167. package/dist/extensions/testserver/resource.js +1 -1
  168. package/dist/extensions/testserver/result.d.ts +1 -1
  169. package/dist/extensions/testserver/result.js +9 -4
  170. package/dist/planning/driver-file-lists.d.ts +0 -15
  171. package/dist/planning/driver-file-lists.js +2 -21
  172. package/dist/planning/plan-only.d.ts +3 -14
  173. package/dist/planning/plan-only.js +11 -20
  174. package/dist/planning/run-kind-flags.js +2 -2
  175. package/dist/planning/run-plan.d.ts +45 -12
  176. package/dist/planning/run-plan.js +4 -3
  177. package/dist/planning/suites.d.ts +1 -1
  178. package/dist/planning/suites.js +2 -2
  179. package/dist/planning/test-plan.d.ts +9 -0
  180. package/dist/planning/test-plan.js +9 -0
  181. package/dist/run-directory/recording.js +3 -3
  182. package/dist/run-directory/run-record.d.ts +26 -11
  183. package/dist/run-directory/run-record.js +16 -13
  184. package/dist/runner/base.js +1 -1
  185. package/dist/runner/build-snapshots.d.ts +60 -29
  186. package/dist/runner/build-snapshots.js +136 -29
  187. package/dist/runner/context.d.ts +15 -7
  188. package/dist/runner/context.js +19 -6
  189. package/dist/runner/events.d.ts +16 -10
  190. package/dist/runner/gateways.d.ts +122 -23
  191. package/dist/runner/gateways.js +1 -1
  192. package/dist/runner/gh.d.ts +42 -0
  193. package/dist/runner/gh.js +58 -0
  194. package/dist/runner/index.d.ts +13 -8
  195. package/dist/runner/index.js +12 -6
  196. package/dist/runner/live/checkout-gateway.js +7 -0
  197. package/dist/runner/live/gh-output.d.ts +17 -0
  198. package/dist/runner/live/gh-output.js +37 -0
  199. package/dist/runner/live/gh-token-gateway.d.ts +13 -0
  200. package/dist/runner/live/gh-token-gateway.js +51 -0
  201. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  202. package/dist/runner/live/sandbox-errors.js +4 -0
  203. package/dist/runner/live/sandbox-gateway.js +140 -4
  204. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  205. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  206. package/dist/runner/live/snapshot-records.js +12 -12
  207. package/dist/runner/local-snapshot-index.d.ts +205 -0
  208. package/dist/runner/local-snapshot-index.js +210 -0
  209. package/dist/runner/network-policy.d.ts +6 -6
  210. package/dist/runner/network-policy.js +7 -7
  211. package/dist/runner/policy-writes.d.ts +1 -1
  212. package/dist/runner/policy-writes.js +1 -1
  213. package/dist/runner/prepare.d.ts +14 -14
  214. package/dist/runner/prepare.js +20 -11
  215. package/dist/runner/ready.d.ts +19 -11
  216. package/dist/runner/ready.js +104 -33
  217. package/dist/runner/sandboxed-command.d.ts +3 -3
  218. package/dist/runner/sandboxed-command.js +3 -3
  219. package/dist/runner/scope.d.ts +15 -8
  220. package/dist/runner/scope.js +16 -5
  221. package/dist/runner/secrets.d.ts +41 -18
  222. package/dist/runner/secrets.js +226 -30
  223. package/dist/runner/session.d.ts +8 -8
  224. package/dist/runner/session.js +6 -3
  225. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  226. package/dist/runner/shared-snapshot-entry.js +168 -0
  227. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  228. package/dist/runner/shared-snapshot-list.js +155 -0
  229. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  230. package/dist/runner/shared-snapshot-lookup.js +118 -0
  231. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  232. package/dist/runner/shared-snapshot-prune.js +133 -0
  233. package/dist/runner/snapshot-build.d.ts +42 -14
  234. package/dist/runner/snapshot-build.js +79 -47
  235. package/dist/runner/snapshot-choice.js +2 -1
  236. package/dist/runner/snapshot-inspect.d.ts +39 -40
  237. package/dist/runner/snapshot-inspect.js +52 -35
  238. package/dist/runner/snapshot-key.d.ts +32 -17
  239. package/dist/runner/snapshot-key.js +43 -18
  240. package/dist/runner/snapshot-source.d.ts +31 -0
  241. package/dist/runner/snapshot-source.js +122 -0
  242. package/dist/runner/steps.d.ts +1 -1
  243. package/dist/runner/steps.js +1 -1
  244. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +4 -2
  245. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
  246. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
  247. package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
  248. package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
  249. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
  250. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  251. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  252. package/dist/sdk/extension/credential-source.d.ts +20 -3
  253. package/dist/sdk/extension/credential-source.js +4 -4
  254. package/dist/sdk/extension/index.d.ts +3 -2
  255. package/dist/sdk/extension/index.js +2 -1
  256. package/dist/sdk/extension/resource-definition.d.ts +1 -1
  257. package/dist/sdk/extension/secret-source.d.ts +1 -1
  258. package/dist/sdk/extension/secret-source.js +1 -1
  259. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  260. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  261. package/dist/shared/cleanup.d.ts +3 -3
  262. package/dist/shared/cleanup.js +15 -5
  263. package/dist/shared/snapshot-text.d.ts +4 -4
  264. package/dist/shared/snapshot-text.js +11 -11
  265. package/dist/time/duration.js +1 -1
  266. package/package.json +5 -3
  267. package/skills/overview.md +4 -4
  268. package/skills/plan-runs.md +1 -1
  269. package/skills/read-run-output.md +6 -6
  270. package/dist/application.d.ts +0 -21
  271. package/dist/application.js +0 -30
  272. package/dist/chunks/chunk-7EENF73W.js +0 -782
  273. package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
  274. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  275. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  276. package/dist/commands/exec/plan-only.d.ts +0 -10
  277. package/dist/commands/exec/plan-only.js +0 -45
  278. package/dist/commands/exec/run-command.d.ts +0 -475
  279. package/dist/commands/exec/run-command.js +0 -603
  280. package/dist/commands/exec/run-planned.d.ts +0 -20
  281. package/dist/commands/exec/run-planned.js +0 -22
  282. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  283. package/dist/commands/exec/sandbox-view.js +0 -72
  284. package/dist/commands/test/plan.d.ts +0 -92
  285. package/dist/commands/test/plan.js +0 -125
  286. package/dist/core/sandbox-end.d.ts +0 -64
  287. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  288. package/dist/runner/recipe-secrets.d.ts +0 -67
  289. package/dist/runner/snapshot-cache.d.ts +0 -148
  290. package/dist/runner/snapshot-cache.js +0 -126
@@ -0,0 +1,233 @@
1
+ // Shared 1..N run coordination inside `core/`: run opening events, runner credential obtainment, concurrent setup &
2
+ // deterministic failure ranking (`coordinateSetup`), running a command in a ready runner sandbox, resource cleanup
3
+ // framing (`withResourceCleanup`), fail-closed multi-session fence tracking (`sandboxFenceTracker`), and merging
4
+ // runner cleanup facts (`mergedRunnerCleanup`).
5
+ import { posix } from "node:path";
6
+ import { vercelProjectSource, } from "../credential/index.js";
7
+ import { parseTestEvent } from "../sdk/run/launcher.js";
8
+ import { canceledStop } from "./outcomes.js";
9
+ import { releasedResources, releaseResources, runInstances, startResourceLanes, } from "./resources.js";
10
+ /**
11
+ * Shared opening events emitted at the start of every run (1 or N runner sandboxes): `started`, skips, and
12
+ * `runner-prepared`.
13
+ */
14
+ export async function emitRunOpening(progress, request, instances) {
15
+ await progress.emit({
16
+ kind: "started",
17
+ version: request.version,
18
+ commit: request.commit,
19
+ configFile: request.configFile,
20
+ resources: runInstances(instances),
21
+ });
22
+ for (const skip of request.skipped ?? [])
23
+ await progress.emit({ kind: "resource-skipped", ...skip });
24
+ if (request.runner !== undefined) {
25
+ const { prepared } = request.runner;
26
+ await progress.emit({
27
+ kind: "runner-prepared",
28
+ base: prepared.base,
29
+ baseRef: prepared.baseRef,
30
+ nestedRepositories: prepared.upload.nestedRepositories,
31
+ notes: prepared.notes,
32
+ });
33
+ }
34
+ }
35
+ /**
36
+ * Obtains a Vercel OIDC credential for `choice` (`mint` or `vercel-oidc`) with the team and project it names
37
+ * (`vercelProjectSource`), and honors `signal`. Shared by 1 and N runner-sandbox runs.
38
+ */
39
+ export async function obtainRunnerCredential(context, choice, signal, progress) {
40
+ const canceled = () => ({ ...canceledStop(), commandStopped: false });
41
+ if (signal.aborted)
42
+ return { ok: false, outcome: canceled() };
43
+ const { source, obtain } = vercelProjectSource(choice, context, progress);
44
+ const obtained = await obtain();
45
+ if (!obtained.ok) {
46
+ const { failure } = obtained;
47
+ switch (failure.source) {
48
+ case "mint":
49
+ return {
50
+ ok: false,
51
+ outcome: { kind: "mint_failed", failure: failure.failure, target: failure.target, runner: true },
52
+ };
53
+ case "vercel-oidc":
54
+ return { ok: false, outcome: { kind: "vercel_oidc_token_failed", failure: failure.failure, runner: true } };
55
+ case "claims-missing":
56
+ return {
57
+ ok: false,
58
+ outcome: { kind: "runner_failed", failure: { kind: "credential-claims-missing", target: failure.target } },
59
+ };
60
+ }
61
+ }
62
+ if (signal.aborted)
63
+ return { ok: false, outcome: canceled() };
64
+ return { ok: true, mint: source, access: { credential: obtained.credential, ...obtained.project } };
65
+ }
66
+ /** Emits `lanes-started` followed by `lane-started` for every resource instance that has a lane, in order. */
67
+ export async function emitLanesStarted(instances, progress) {
68
+ await progress.emit({ kind: "lanes-started" });
69
+ await startResourceLanes(instances, progress);
70
+ }
71
+ /**
72
+ * Runs resource setup and runner setup concurrently under a shared internal sibling-stop controller, waits for both
73
+ * lanes to settle, and ranks failures deterministically:
74
+ *
75
+ * 1. Throws (runner lane throw first, then resource lane throw).
76
+ * 2. User cancellation (`cancelSignal.aborted`).
77
+ * 3. Runner or snapshot failure (`runner_failed`, `snapshot_gone`).
78
+ * 4. Resource refusal, `mint_failed`, or split refusal.
79
+ * 5. Explicit cancellation (`canceled`).
80
+ *
81
+ * Passes the settled resource promise and a `stopResources` callback to `runRunner` so multi-sandbox runs can stream
82
+ * sandboxes from a chosen snapshot while resources acquire and split, and stop any still-pending resource acquire once
83
+ * all runner sandboxes have ended (an `internal-stopped` resource lane then resolves as `ready` with `resources:
84
+ * undefined`, not `canceled`).
85
+ */
86
+ export async function coordinateSetup(input) {
87
+ const stop = new AbortController();
88
+ const stopResources = () => stop.abort();
89
+ const settledResources = input.runResources(stop.signal).then((outcome) => {
90
+ if (outcome.kind !== "ready" && outcome.kind !== "internal-stopped")
91
+ stop.abort();
92
+ return outcome;
93
+ }, (error) => {
94
+ stop.abort();
95
+ return { kind: "threw", error };
96
+ });
97
+ const settledRunner = input
98
+ .runRunner(stop.signal, settledResources, stopResources)
99
+ .then((outcome) => {
100
+ if (outcome.kind !== "ready" && outcome.kind !== "internal-stopped")
101
+ stop.abort();
102
+ return outcome;
103
+ }, (error) => {
104
+ stop.abort();
105
+ return { kind: "threw", error };
106
+ });
107
+ const [runner, resources] = await Promise.all([settledRunner, settledResources]);
108
+ if (runner.kind === "threw")
109
+ return { kind: "threw", error: runner.error, lane: "runner" };
110
+ if (resources.kind === "threw")
111
+ return { kind: "threw", error: resources.error, lane: "resources" };
112
+ if (input.cancelSignal.aborted)
113
+ return { kind: "stopped", outcome: canceledStop() };
114
+ if (runner.kind === "stopped")
115
+ return { kind: "stopped", outcome: runner.outcome };
116
+ if (resources.kind === "stopped")
117
+ return { kind: "stopped", outcome: resources.outcome };
118
+ if (runner.kind === "ready" && resources.kind === "ready")
119
+ return { kind: "ready", runner: runner.value, resources: resources.value };
120
+ if (runner.kind === "ready" && resources.kind === "internal-stopped")
121
+ return { kind: "ready", runner: runner.value, resources: undefined };
122
+ return { kind: "stopped", outcome: canceledStop() };
123
+ }
124
+ /**
125
+ * Runs `request.argv` in `session` with `request.runPayload`, pumping test events in arrival order and mapping sandbox
126
+ * exit, kill, and failure outcomes into `RanCommand` or `RunStopped`. Shared by 1 and N runner-sandbox runs.
127
+ */
128
+ export async function runCommandInSandbox(session, request, signal, progress, onStarted) {
129
+ await progress.emit({ kind: "command-started", argv: request.argv });
130
+ if (signal.aborted)
131
+ return { ok: false, outcome: { ...canceledStop(), commandStopped: false } };
132
+ onStarted?.();
133
+ // Test events arrive from a callback that can't wait, so they are emitted in order through a chain.
134
+ let testEvents = Promise.resolve();
135
+ const ended = await session.runCommand({
136
+ argv: request.argv,
137
+ runPayload: request.runPayload,
138
+ ...(request.credentials === undefined ? {} : { credentials: request.credentials }),
139
+ testEvents: {
140
+ onLine: (line) => {
141
+ const event = parseTestEvent(line);
142
+ testEvents = testEvents.then(() => progress.emit(event === undefined ? { kind: "test-event-unreadable" } : { kind: "test", event }));
143
+ },
144
+ onIncomplete: (message) => {
145
+ testEvents = testEvents.then(() => progress.emit({ kind: "test-events-incomplete", message }));
146
+ },
147
+ },
148
+ });
149
+ await testEvents;
150
+ // Closing on a signal can stop the runner sandbox under the command, so a failed call then is the stop too.
151
+ if (ended.kind === "killed" || (ended.kind === "failed" && signal.aborted))
152
+ return { ok: false, outcome: { ...canceledStop(), commandStopped: true } };
153
+ if (ended.kind === "failed")
154
+ return { ok: false, outcome: { kind: "runner_failed", failure: ended.failure } };
155
+ const command = ended.exitCode === null ? { kind: "no-exit-code" } : { kind: "exited", code: ended.exitCode };
156
+ await progress.emit({
157
+ kind: "command-ended",
158
+ command: posix.basename(request.argv[0] ?? ""),
159
+ outcome: command,
160
+ ms: ended.ms,
161
+ });
162
+ return { ok: true, command };
163
+ }
164
+ /**
165
+ * Runs `body` with idempotent `startCleanup` and `release` hooks, guarantees every acquired resource instance is
166
+ * released in `finally`, and returns both `body`'s result and the collected `resourceCleanup`.
167
+ */
168
+ export async function withResourceCleanup(instances, keepMs, progress, body) {
169
+ let cleanupStarted = false;
170
+ const startCleanup = async () => {
171
+ if (cleanupStarted)
172
+ return;
173
+ cleanupStarted = true;
174
+ await progress.emit({ kind: "cleanup-started", keepMs, resources: releasedResources(instances) });
175
+ };
176
+ let resourceCleanup = {};
177
+ let releasing;
178
+ const release = (runner) => (releasing ??= (async () => {
179
+ try {
180
+ await startCleanup();
181
+ }
182
+ finally {
183
+ resourceCleanup = await releaseResources(instances, progress, runner);
184
+ }
185
+ })());
186
+ let value;
187
+ try {
188
+ value = await body({ startCleanup, release });
189
+ }
190
+ finally {
191
+ // A run with no runner (`keepMs` null) has nothing to fence, so the release hears true. With a runner, a session
192
+ // that ended without releasing never confirmed its fence, so the release hears false.
193
+ await release({ runnerSandboxFenced: keepMs === null });
194
+ }
195
+ return { value, resourceCleanup };
196
+ }
197
+ /**
198
+ * Creates a fail-closed multi-session fence tracker. Each call to `sessionCleanup` registers a session as unfenced
199
+ * (`false`) until its `release` hook confirms `fence.runnerSandboxFenced === true`, and makes `startCleanup`
200
+ * idempotent per session. When no session registered, `allFenced()` returns `true`.
201
+ */
202
+ export function sandboxFenceTracker() {
203
+ const sessions = [];
204
+ return {
205
+ sessionCleanup(onStart) {
206
+ const entry = { fenced: false };
207
+ sessions.push(entry);
208
+ let cleanupStarted = false;
209
+ return {
210
+ startCleanup: async () => {
211
+ if (cleanupStarted)
212
+ return;
213
+ cleanupStarted = true;
214
+ await onStart();
215
+ },
216
+ release: async (fence) => {
217
+ entry.fenced = fence.runnerSandboxFenced;
218
+ },
219
+ };
220
+ },
221
+ allFenced: () => sessions.every(({ fenced }) => fenced),
222
+ };
223
+ }
224
+ /** Merges per-sandbox `RunnerCleanupFacts` into one run-level cleanup summary. */
225
+ export function mergedRunnerCleanup(target, cleanups) {
226
+ return {
227
+ kept: null,
228
+ notKept: null,
229
+ notStopped: cleanups.flatMap(({ notStopped }) => notStopped),
230
+ notDeleted: cleanups.flatMap(({ notDeleted }) => notDeleted),
231
+ target,
232
+ };
233
+ }
@@ -1,6 +1,6 @@
1
1
  import type { CredentialEvent } from "../credential/index.ts";
2
2
  import type { LaneOutcome } from "../sdk/extension/index.ts";
3
- import type { RunnerEvent, SnapshotCacheNote } from "../runner/index.ts";
3
+ import type { RunnerEvent, SnapshotIndexNote } from "../runner/index.ts";
4
4
  import type { Clock } from "../time/index.ts";
5
5
  import type { TestEvent } from "../sdk/run/launcher.ts";
6
6
  import type { RunInstance, ResourceAcquired, ResourceEvent, ResourceNoticeEvent, ResourceSkip, ResourceWarningEvent, RunLane } from "./resource.ts";
@@ -66,7 +66,7 @@ export type BaseRunEvent = {
66
66
  readonly base: string;
67
67
  readonly baseRef: string;
68
68
  readonly nestedRepositories: readonly string[];
69
- readonly notes: readonly SnapshotCacheNote[];
69
+ readonly notes: readonly SnapshotIndexNote[];
70
70
  } | CredentialEvent | {
71
71
  readonly kind: "lanes-started";
72
72
  } | ({
@@ -14,8 +14,10 @@ export { liveJobSummaryGateway } from "./live/job-summary-gateway.ts";
14
14
  export { liveProgressTerminal } from "./live/progress-terminal.ts";
15
15
  export { livePackageBinGateway } from "./live/package-bin-gateway.ts";
16
16
  export type { CoreLane, RunInstance, ResourceAcquired, ResourceCleanupRecords, ResourceEvent, ResourceNoticeEvent, ResourceWarningEvent, ResourceOptions, ResourcePayloads, ResourceRanRecords, ResourceRefusal, ResourceInputs, ResourceRequest, ResourceRequests, ResourceSkip, ResourceContextMap, RunLane, } from "./resource.ts";
17
- export { executeRun, type UnsandboxedRunRequest, type RanRun, type RanRunner, type SandboxedRunRequest, type RunCleanup, type RunContext, type RunnerCleanupFacts, type RunControl, type RunOutcome, type RunRequest, type RunRunnerFailure, type RunRunnerRequest, type RunStopped, type SingleRunOutcome, } from "./run.ts";
18
- export { type EndedSandbox, type SandboxEnd, sandboxEndFacts, acrossSandboxesExitStatus, type AcrossSandboxesOutcome, type SandboxesRanRun, } from "./sandbox-end.ts";
17
+ export type { RunnerCleanupFacts } from "../runner/index.ts";
18
+ export type { RunContext, RunControl, RunnerCredentialChoice, RunRunnerRequest } from "./coordinator.ts";
19
+ export { acrossSandboxesExitStatus, type AcrossSandboxesOutcome, type EndedSandbox, type RanRun, type RanRunner, type RunCleanup, type RunOutcome, type RunRunnerFailure, type RunStopped, type SandboxEnd, sandboxEndFacts, type SandboxesRanRun, type SingleRunOutcome, } from "./outcomes.ts";
20
+ export { executeRun, type LaunchMachineRunRunner, type RunRequest, type RunRunner, type VercelSandboxRunRunner, } from "./run.ts";
19
21
  export { executeAcrossSandboxes, type SandboxCommand, type AcrossSandboxesContext, type AcrossSandboxesRequest, } from "./across-sandboxes.ts";
20
22
  export { resolveStateDirectory, stateDirectoryPattern } from "./state-directory.ts";
21
23
  export { commandExitStatus, megabytesText, type RanCommand, secondsOf, secondsText } from "./timing.ts";
@@ -16,8 +16,8 @@ export { liveCommandGateway } from "./live/command-gateway.js";
16
16
  export { liveJobSummaryGateway } from "./live/job-summary-gateway.js";
17
17
  export { liveProgressTerminal } from "./live/progress-terminal.js";
18
18
  export { livePackageBinGateway } from "./live/package-bin-gateway.js";
19
+ export { acrossSandboxesExitStatus, sandboxEndFacts, } from "./outcomes.js";
19
20
  export { executeRun, } from "./run.js";
20
- export { sandboxEndFacts, acrossSandboxesExitStatus, } from "./sandbox-end.js";
21
21
  export { executeAcrossSandboxes, } from "./across-sandboxes.js";
22
22
  export { resolveStateDirectory, stateDirectoryPattern } from "./state-directory.js";
23
23
  export { commandExitStatus, megabytesText, secondsOf, secondsText } from "./timing.js";
@@ -0,0 +1,148 @@
1
+ import { type MintFailure, type MintTarget, type VercelOidcTokenFailure } from "../credential/index.ts";
2
+ import type { ChosenSnapshot, ReadyRunnerOutcome, RunnerCleanupFacts, RunnerFailure, RunnerSnapshotEntry, RunnerSnapshotIndexFailure } from "../runner/index.ts";
3
+ import type { LaneOutcome } from "../sdk/extension/index.ts";
4
+ import type { SandboxEndFacts } from "./events.ts";
5
+ import type { ResourceCleanupRecords, ResourceRanRecords, ResourceRefusal } from "./resource.ts";
6
+ import type { RanCommand } from "./timing.ts";
7
+ /**
8
+ * Why the runner couldn't run the command: a runner failure (`RunnerFailure`), or `credential-claims-missing`, a
9
+ * credential whose token names no team and project ids, found before any Sandbox call.
10
+ */
11
+ export type RunRunnerFailure = RunnerFailure | {
12
+ readonly kind: "credential-claims-missing";
13
+ readonly target: MintTarget;
14
+ };
15
+ /** What a run in a runner sandbox got from the runner sandbox, once the command ran in it. */
16
+ export interface RanRunner {
17
+ /** The runner snapshot it started from, and its base. */
18
+ readonly snapshotId: string;
19
+ readonly base: string;
20
+ /** Whether this run built the runner snapshot. */
21
+ readonly built: boolean;
22
+ /** How many commits HEAD has that the snapshot's base lacks. */
23
+ readonly builtBehind: number;
24
+ /** How many bytes of changes the run uploaded on top of the snapshot's base. */
25
+ readonly uploadBytes: number;
26
+ readonly vcpus: number;
27
+ readonly region: string;
28
+ readonly image: string;
29
+ /** How long the build step took, in milliseconds. */
30
+ readonly buildMs: number;
31
+ }
32
+ /** What a run reports of its cleanup. */
33
+ export interface RunCleanup {
34
+ readonly runnerCleanup: RunnerCleanupFacts | null;
35
+ readonly resourceCleanup: ResourceCleanupRecords;
36
+ }
37
+ /** The command ran and ended. */
38
+ export interface RanRun extends RunCleanup {
39
+ readonly kind: "ran";
40
+ readonly resources: ResourceRanRecords;
41
+ readonly command: RanCommand;
42
+ /** For a run with the Vercel Sandbox runner, the runner sandbox the command ran in; undefined otherwise. */
43
+ readonly runner: RanRunner | undefined;
44
+ }
45
+ /**
46
+ * How a run ended short of the command ending, before the run releases its resources and attaches the runner's
47
+ * cleanup report. A resource's refusal is one of these.
48
+ */
49
+ export type RunStopped = ResourceRefusal | {
50
+ readonly kind: "mint_failed";
51
+ readonly failure: MintFailure;
52
+ /** What the mint was for. */
53
+ readonly target: MintTarget;
54
+ /** Whether the mint was for the runner sandbox. */
55
+ readonly runner: boolean;
56
+ } | {
57
+ readonly kind: "vercel_oidc_token_failed";
58
+ readonly failure: VercelOidcTokenFailure;
59
+ /** Whether the credential was for the runner sandbox. */
60
+ readonly runner: boolean;
61
+ } | {
62
+ readonly kind: "spawn_failed";
63
+ readonly executable: string;
64
+ readonly message: string;
65
+ } | {
66
+ readonly kind: "canceled";
67
+ /** For a run in a runner sandbox, whether the command had started and was stopped. */
68
+ readonly commandStopped?: boolean;
69
+ } | {
70
+ readonly kind: "runner_failed";
71
+ readonly failure: RunRunnerFailure;
72
+ } | {
73
+ readonly kind: "snapshot_gone";
74
+ readonly entry: RunnerSnapshotEntry;
75
+ /** Why its local snapshot index entry couldn't be removed; undefined when it was. */
76
+ readonly removal: RunnerSnapshotIndexFailure | undefined;
77
+ };
78
+ /** How a run that is not across runner sandboxes ended. */
79
+ export type SingleRunOutcome = RanRun | (RunStopped & RunCleanup);
80
+ /**
81
+ * How one runner sandbox ended, in the kinds any other run ends with, and one more:
82
+ *
83
+ * - `ran`: its command ran and ended.
84
+ * - a run's stop (`RunStopped`).
85
+ * - `threw`: something in the runner sandbox threw, a mistake in storm, with the error's message.
86
+ */
87
+ export type SandboxEnd = {
88
+ readonly kind: "ran";
89
+ readonly command: RanCommand;
90
+ } | RunStopped | {
91
+ readonly kind: "threw";
92
+ readonly message: string;
93
+ };
94
+ /**
95
+ * One runner sandbox once it ended: its runner sandbox index, its command, how it ended (`end`), its runner sandbox
96
+ * state, exit code, and cause from that, and what closing its runner sandbox scope left (null when its session never
97
+ * opened).
98
+ */
99
+ export interface EndedSandbox extends SandboxEndFacts {
100
+ readonly sandbox: number;
101
+ readonly argv: readonly string[];
102
+ readonly end: SandboxEnd;
103
+ readonly runnerCleanup: RunnerCleanupFacts | null;
104
+ }
105
+ /**
106
+ * Every runner sandbox of a run across runner sandboxes ended, and no signal stopped one: each runner sandbox's end, in
107
+ * order of runner sandbox index (`sandboxes`), the runner snapshot each started from, and what it reports of each
108
+ * acquired resource instance that reports something (`resources`), for the whole run, as a `ran` outcome does.
109
+ */
110
+ export interface SandboxesRanRun extends RunCleanup {
111
+ readonly kind: "sandboxes_ran";
112
+ readonly sandboxes: readonly EndedSandbox[];
113
+ readonly snapshot: ChosenSnapshot;
114
+ readonly resources: ResourceRanRecords;
115
+ }
116
+ /**
117
+ * How a run across runner sandboxes ended: its runner sandboxes ran (`SandboxesRanRun`), or the run stopped before
118
+ * then, in one of the ways any run stops (`RunStopped`). It never ends as `ran`, which is the outcome of a run's one
119
+ * command.
120
+ */
121
+ export type AcrossSandboxesOutcome = SandboxesRanRun | (RunStopped & RunCleanup);
122
+ /**
123
+ * How a run ended, across runner sandboxes (`AcrossSandboxesOutcome`) or not (`SingleRunOutcome`): what `run.json`
124
+ * records of either.
125
+ */
126
+ export type RunOutcome = SingleRunOutcome | AcrossSandboxesOutcome;
127
+ /** The `canceled` stop of a run. */
128
+ export declare function canceledStop(): Extract<RunStopped, {
129
+ readonly kind: "canceled";
130
+ }>;
131
+ /**
132
+ * How the runner lane ended, by how readying did: ready when ready, stopped when aborted, else failed.
133
+ */
134
+ export declare function runnerLaneOutcome(outcome: ReadyRunnerOutcome): LaneOutcome;
135
+ /** The outcome a runner that couldn't get ready ends the run with; undefined when it is ready or was stopped. */
136
+ export declare function runnerStopped(outcome: ReadyRunnerOutcome): RunStopped | undefined;
137
+ /**
138
+ * The status storm exits with once a run's runner sandboxes ran: 0 when every runner sandbox passed, else 1. A cleanup
139
+ * failure never changes it.
140
+ */
141
+ export declare function acrossSandboxesExitStatus(sandboxes: readonly Pick<SandboxEndFacts, "state">[]): number;
142
+ /**
143
+ * A runner sandbox's state, exit code, and cause, from how it ended and whether its command started: a command that
144
+ * started and did not exit 0 is `failed`, a command that never started is `not-started`, and a signal makes the runner
145
+ * sandbox `canceled`. The Sandbox call that runs the command failing means the command started, whether or not its start
146
+ * was heard.
147
+ */
148
+ export declare function sandboxEndFacts(end: SandboxEnd, commandStarted: boolean): SandboxEndFacts;
@@ -1,7 +1,26 @@
1
- // Pure types and helpers for how a runner sandbox ends, shared by `core/across-sandboxes.ts`, `run-directory/`, and the
2
- // composition layer: how one runner sandbox ends, the exit status of a run across runner sandboxes, and the one-line
3
- // cause for a runner sandbox that did not pass.
4
- import { describeMintFailure } from "../credential/index.js";
1
+ // Acyclic leaf module for core run outcomes and runner-sandbox end helpers: shared by `core/resources.ts`,
2
+ // `core/coordinator.ts`, `core/run.ts`, `core/across-sandboxes.ts`, `run-directory/`, and the composition layer.
3
+ import { describeMintFailure, describeVercelOidcTokenFailure, } from "../credential/index.js";
4
+ /** The `canceled` stop of a run. */
5
+ export function canceledStop() {
6
+ return { kind: "canceled" };
7
+ }
8
+ /**
9
+ * How the runner lane ended, by how readying did: ready when ready, stopped when aborted, else failed.
10
+ */
11
+ export function runnerLaneOutcome(outcome) {
12
+ if (outcome.kind === "ready")
13
+ return "ready";
14
+ return outcome.kind === "aborted" ? "stopped" : "failed";
15
+ }
16
+ /** The outcome a runner that couldn't get ready ends the run with; undefined when it is ready or was stopped. */
17
+ export function runnerStopped(outcome) {
18
+ if (outcome.kind === "failed")
19
+ return { kind: "runner_failed", failure: outcome.failure };
20
+ if (outcome.kind === "snapshot-gone")
21
+ return { kind: "snapshot_gone", entry: outcome.entry, removal: outcome.removal };
22
+ return undefined;
23
+ }
5
24
  /**
6
25
  * The status storm exits with once a run's runner sandboxes ran: 0 when every runner sandbox passed, else 1. A cleanup
7
26
  * failure never changes it.
@@ -48,6 +67,8 @@ export function sandboxEndFacts(end, commandStarted) {
48
67
  }
49
68
  case "mint_failed":
50
69
  return short(`mint-failed: ${describeMintFailure(end.failure, end.target).cause}`, "mint");
70
+ case "vercel_oidc_token_failed":
71
+ return short(`vercel-oidc-token-failed: ${describeVercelOidcTokenFailure(end.failure).cause}`, "mint");
51
72
  case "snapshot_gone":
52
73
  return short("snapshot-gone", "snapshot");
53
74
  case "spawn_failed":
@@ -77,6 +98,9 @@ function runnerFailureStage(failure) {
77
98
  switch (failure.operation) {
78
99
  case "start-build-sandbox":
79
100
  case "save-snapshot":
101
+ case "get-named-sandbox":
102
+ case "get-snapshot":
103
+ case "delete-named-sandbox":
80
104
  return "snapshot";
81
105
  case "start-runner-sandbox":
82
106
  case "login-path":
@@ -1,10 +1,10 @@
1
1
  import type { CredentialSource } from "../credential/index.ts";
2
2
  import type { RunnerFenceOutcome } from "../runner/index.ts";
3
3
  import type { LaneOutcome, SandboxCredential } from "../sdk/extension/index.ts";
4
- import type { RunEvent, RunProgress } from "./events.ts";
5
4
  import type { DefinitionLookup } from "./definition-lookup.ts";
6
- import type { RunInstance, ResourceCleanupRecords, ResourcePayloads, ResourceRanRecords, ResourceRefusal, ResourceRequests, ResourceContextMap, RunLane } from "./resource.ts";
7
- import type { RunStopped } from "./run.ts";
5
+ import type { RunEvent, RunProgress } from "./events.ts";
6
+ import type { RunStopped } from "./outcomes.ts";
7
+ import type { ResourceCleanupRecords, ResourceContextMap, ResourcePayloads, ResourceRanRecords, ResourceRefusal, ResourceRequests, RunInstance, RunLane } from "./resource.ts";
8
8
  /**
9
9
  * How acquiring one resource instance ended, as the policy ranks it: what its acquire answered stays in the instance.
10
10
  * `refused` carries the outcome it ends the run with: its own refusal, or the run's `mint_failed`.
@@ -42,7 +42,7 @@ type LaneFinish = <V>(lane: RunLane | undefined, task: Promise<V>, outcomeOf: (v
42
42
  * definition.
43
43
  */
44
44
  export interface ResourceInstance {
45
- /** The instance as the `started` event lists it: its key, its definition's name and its lane's name. */
45
+ /** The instance as the `started` event lists it: its key, its definition's name, and its lane's name. */
46
46
  readonly listing: RunInstance;
47
47
  readonly lane: RunLane | undefined;
48
48
  /** Reports its lane's start, when it has a lane, just before the run acquires it. */
@@ -85,55 +85,40 @@ export interface ResourceInstance {
85
85
  * `lookup`, over the definition's Context from `resourceContexts`.
86
86
  */
87
87
  export declare function resourceInstances({ named }: DefinitionLookup, resourceContexts: ResourceContextMap, requests: ResourceRequests): readonly ResourceInstance[];
88
+ /** Emits `lane-started` for every resource instance that has a lane, in order. */
89
+ export declare function startResourceLanes(instances: readonly ResourceInstance[], progress: RunProgress): Promise<void>;
88
90
  /**
89
- * A lane beside the resources: the runner sandbox, readied by the runner. `stopped` is the outcome its value ends the
90
- * run with, which ranks above every resource's refusal; undefined when it doesn't end the run.
91
+ * How acquiring a run's resource instances ended:
92
+ * - `acquired`: every resource instance acquired cleanly.
93
+ * - `stopped`: a resource refused or failed a mint it needed.
94
+ * - `canceled`: the user's `cancelSignal` aborted (or a resource returned canceled on its own).
95
+ * - `internal-stopped`: a sibling lane aborted `stopSignal` (not a user cancellation).
91
96
  */
92
- export interface BesideLane<T> {
93
- readonly lane: RunLane;
94
- readonly start: (signal: AbortSignal) => Promise<T>;
95
- readonly outcomeOf: (value: T) => LaneOutcome;
96
- readonly stopped: (value: T) => RunStopped | undefined;
97
- }
98
- /**
99
- * How acquiring a run's resources ended: `stopped` with the outcome that ends the run before its command, or every
100
- * resource the run asked for `acquired`, with the beside lane's value, if it had one.
101
- */
102
- export type Acquisition<T> = {
97
+ export type ResourceAcquisition = {
98
+ readonly kind: "acquired";
99
+ } | {
103
100
  readonly kind: "stopped";
104
- readonly outcome: RunStopped;
101
+ readonly outcome: ResourceRefusal | MintFailedStop;
105
102
  } | {
106
- readonly kind: "acquired";
107
- readonly beside: T | undefined;
103
+ readonly kind: "canceled";
104
+ } | {
105
+ readonly kind: "internal-stopped";
108
106
  };
109
107
  /**
110
- * Acquires every resource instance of the run at once, in order, and readies the lane beside them (`beside`), when
111
- * there is one. Everything runs under one internal abort combined with the user's `signal`: an instance that
112
- * refuses or throws, a lane that ends short of ready, or a lane whose end can't be reported aborts the rest, so all end
113
- * soon. It waits for all of them before it answers, so the run's cleanup sees everything their acquires took. First
114
- * each instance with a lane reports its lane's start, in order, so every `acquireForRun` then starts at once, beside
115
- * the beside lane; each of those lanes reports how it ended as it ends, a throw as failed.
108
+ * Acquires every resource instance of the run concurrently. A resource refusal or throw aborts the remaining
109
+ * resources immediately via an internal controller; `stopSignal` lets a sibling lane stop acquisition without
110
+ * misclassifying it as a user cancellation (`internal-stopped` vs. `canceled`).
116
111
  *
117
- * A throw rethrows, the beside lane's first, then the resources' in order. Otherwise the outcome ranks, the same with
118
- * or without a lane beside them: the user's `signal` (`canceled`), then the beside lane's failure, then each instance's
119
- * refusal in order (its own, or the run's `mint_failed` when the mint it needed failed), then an instance's
120
- * cancellation. A refusal aborts the other instances, so one that stops on that abort answers `canceled`; ranking every
121
- * refusal above every cancellation keeps the refusal that caused it.
112
+ * Waits for every instance to settle so cleanup sees everything taken. Rethrows the first instance throw in order;
113
+ * otherwise ranks user cancellation (`cancelSignal`), then the first resource refusal in order, then
114
+ * `internal-stopped` (when `stopSignal` aborted), then `canceled`.
122
115
  */
123
- export declare function acquireResources<T>(instances: readonly ResourceInstance[], input: {
116
+ export declare function acquireResources(instances: readonly ResourceInstance[], input: {
124
117
  readonly credential: CredentialSource | undefined;
125
- readonly signal: AbortSignal;
118
+ readonly cancelSignal: AbortSignal;
119
+ readonly stopSignal?: AbortSignal;
126
120
  readonly progress: RunProgress;
127
- readonly beside?: BesideLane<T>;
128
- }): Promise<Acquisition<T>>;
129
- /**
130
- * The `canceled` stop of a run. What it says each resource instance changed comes from its cleanup record: what its
131
- * acquire said a canceled run changed, what its release finished, and its release's warnings
132
- * (`ResourceCleanupRecords`).
133
- */
134
- export declare function canceledStop(): Extract<RunStopped, {
135
- kind: "canceled";
136
- }>;
121
+ }): Promise<ResourceAcquisition>;
137
122
  /**
138
123
  * Says each acquired instance acquired, in order (`resource-acquired`), each followed by its acquire's `announce`, if
139
124
  * it answered one: once every instance is acquired, and the runner, when there is one, is ready, just before the
@@ -153,13 +138,7 @@ export interface InstanceCredential {
153
138
  /**
154
139
  * Every sandbox credential the acquired instances answered, in the instances' order, each normalized (lowercase domain
155
140
  * and header, `requests` defaulted to `"read"`) with its resource key, checked against each other and against
156
- * `configCredentials`, the run's own (`runner.credentials`), which share the command's network policy with them. Two
157
- * credentials can't hold together when they name the same domain and header (compared without case), since the firewall
158
- * sets one value per header, or the same domain with different `requests` (`read` when a credential says none), since
159
- * the firewall has one rule set per domain: either throws, naming both sources (each resource key, or
160
- * `runner.credentials`), the domain, and the header or both `requests`, never a value, before the command starts, and
161
- * the run's release still runs, as for any throw. One instance that names the same domain and header twice is the same
162
- * mistake, and throws too.
141
+ * `configCredentials`, the run's own (`runner.credentials`), which share the command's network policy with them.
163
142
  */
164
143
  export declare function resourcesCredentials(instances: readonly ResourceInstance[], configCredentials?: readonly Required<SandboxCredential>[]): readonly InstanceCredential[];
165
144
  /**
@@ -184,9 +163,8 @@ export declare function runInstances(instances: readonly ResourceInstance[]): re
184
163
  export declare function releasedResources(instances: readonly ResourceInstance[]): readonly string[];
185
164
  /**
186
165
  * Releases every resource instance of the run, in reverse order, and answers what that did, keyed by resource key:
187
- * only the instances whose release reported something. Each release gets `runner.runnerSandboxFenced`: false when the
188
- * run had a runner sandbox it couldn't confirm stopped, always true in a run with no runner. Each release runs even
189
- * when one before it threw; the first throw is rethrown once all have run.
166
+ * only the instances whose release reported something. Each release runs even when one before it threw; the first
167
+ * throw is rethrown once all have run.
190
168
  */
191
169
  export declare function releaseResources(instances: readonly ResourceInstance[], progress: RunProgress, runner: RunnerFenceOutcome): Promise<ResourceCleanupRecords>;
192
170
  /** How many warnings releasing the instances in `cleanup` reported, summed over them. */