deepline 0.3.544 → 0.3.546

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 (192) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +5 -0
  2. package/dist/bundling-sources/sdk/src/errors.ts +1 -1
  3. package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/shared_libs/monitors/fleets/errors.ts +5 -0
  6. package/dist/bundling-sources/shared_libs/monitors/fleets/issues.ts +5 -1
  7. package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +6 -0
  8. package/dist/bundling-sources/shared_libs/monitors/fleets/plan.ts +35 -3
  9. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +2 -2
  10. package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
  11. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +4 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +8 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +40 -3
  15. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
  17. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
  18. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +32 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +10 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +30 -2
  26. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +30 -1
  27. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +35 -2
  28. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +35 -1
  29. package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
  30. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +2 -0
  31. package/dist/cli/{auth-IMWJAHPU.mjs → auth-KFWG72AZ.mjs} +6 -6
  32. package/dist/cli/auth-W32GMYND.js +43 -0
  33. package/dist/cli/{billing-YQMW3QJI.mjs → billing-MMZ336HO.mjs} +10 -10
  34. package/dist/cli/{billing-Y55PR2PV.js → billing-OQVOAZ4S.js} +98 -98
  35. package/dist/cli/{chunk-RJPDCSTD.mjs → chunk-3DUNNZB6.mjs} +4 -4
  36. package/dist/cli/{chunk-G26VJCNT.js → chunk-4AZLGNXV.js} +36 -26
  37. package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-5OEFXAKP.mjs} +5 -1
  38. package/dist/cli/{chunk-RG34YBDE.js → chunk-5V7NZKGG.js} +2 -2
  39. package/dist/cli/{chunk-UHIAQPVA.js → chunk-5VNQMVCU.js} +26 -26
  40. package/dist/cli/{chunk-PDJ4UDCO.js → chunk-5W4ENHWM.js} +12 -12
  41. package/dist/cli/{chunk-3JDA23NN.mjs → chunk-6FBDTYR2.mjs} +2 -2
  42. package/dist/cli/{chunk-KE6CSCUF.js → chunk-6LG7MLJ2.js} +44 -44
  43. package/dist/cli/{chunk-HXM2JUGD.mjs → chunk-6Y5TU3R7.mjs} +2 -2
  44. package/dist/cli/{chunk-PFGOCUH3.mjs → chunk-7MY7KWJS.mjs} +1 -1
  45. package/dist/cli/{chunk-57G4NYOL.mjs → chunk-7ZW67ME6.mjs} +1 -1
  46. package/dist/cli/{chunk-JBWOE6AP.js → chunk-BTFUAGHC.js} +16 -16
  47. package/dist/cli/{chunk-5PR4VLLL.mjs → chunk-EEG46QZY.mjs} +2 -2
  48. package/dist/cli/{chunk-3I26HMJ7.js → chunk-EEJHB76U.js} +9 -9
  49. package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
  50. package/dist/cli/{chunk-Z44YTSTA.js → chunk-F2VEFMU5.js} +13 -13
  51. package/dist/cli/{chunk-4JQEAYN3.js → chunk-F5YQXCP3.js} +5 -1
  52. package/dist/cli/{chunk-BEQ7RQLT.mjs → chunk-GOOF7E2B.mjs} +5 -5
  53. package/dist/cli/{chunk-PMW5YP72.mjs → chunk-GYTSDSQD.mjs} +11 -11
  54. package/dist/cli/{chunk-ZY6FL4O4.js → chunk-H7Q5IDO3.js} +19 -19
  55. package/dist/cli/{chunk-GV45TTI6.mjs → chunk-HJR2DDJS.mjs} +2 -2
  56. package/dist/cli/{chunk-7HMMTSDA.js → chunk-IVWU7SJC.js} +5 -5
  57. package/dist/cli/{chunk-WBSGPLH5.mjs → chunk-J65HJCJO.mjs} +2 -2
  58. package/dist/cli/{chunk-REEOMNCO.mjs → chunk-JA633HRV.mjs} +3 -3
  59. package/dist/cli/{chunk-HVJQF5BI.mjs → chunk-JARZ47OP.mjs} +2 -2
  60. package/dist/cli/{chunk-IFIJ4DBJ.js → chunk-JCH4UNNS.js} +2 -2
  61. package/dist/cli/{chunk-COJHT2KF.js → chunk-JCWNF44W.js} +22 -22
  62. package/dist/cli/{chunk-3KGMM4KS.js → chunk-JVOUQFHT.js} +1 -1
  63. package/dist/cli/{chunk-W7X4KH45.js → chunk-JYG4XZLT.js} +99 -99
  64. package/dist/cli/{chunk-HBSWATOU.mjs → chunk-K2XELBPF.mjs} +5 -5
  65. package/dist/cli/{chunk-HAQRF6DJ.mjs → chunk-KUK7ARXA.mjs} +2 -2
  66. package/dist/cli/{chunk-WUEORIOY.mjs → chunk-LHE2TSV6.mjs} +1 -1
  67. package/dist/cli/{chunk-7GNZEOTH.js → chunk-LIJKRDDG.js} +6 -6
  68. package/dist/cli/{chunk-SKS53WM6.mjs → chunk-LX2TC3HO.mjs} +4 -4
  69. package/dist/cli/{chunk-GQHRGBHV.js → chunk-MEGHIX4M.js} +5 -5
  70. package/dist/cli/{chunk-H4SAHB3Q.mjs → chunk-MI7X6V6V.mjs} +3 -3
  71. package/dist/cli/{chunk-ON56ISO6.js → chunk-MXQP7CXZ.js} +8 -8
  72. package/dist/cli/{chunk-PKRW76XG.js → chunk-ND7SFRQL.js} +2 -2
  73. package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
  74. package/dist/cli/{chunk-Q7ZOWNKR.mjs → chunk-OAKWSLKS.mjs} +2 -2
  75. package/dist/cli/{chunk-SK3HPU2J.mjs → chunk-P7A3H6G5.mjs} +1 -1
  76. package/dist/cli/{chunk-UNMNGRPB.js → chunk-PMDHY2YK.js} +7 -7
  77. package/dist/cli/{chunk-LW274RO7.mjs → chunk-PU3ZAG6V.mjs} +1 -1
  78. package/dist/cli/{chunk-ZHY4T5M6.mjs → chunk-RO66FPTS.mjs} +22 -12
  79. package/dist/cli/{chunk-DYDHLBSK.js → chunk-SH32HL7I.js} +53 -53
  80. package/dist/cli/{chunk-DF2X7GJG.js → chunk-SYTWWVIQ.js} +5 -5
  81. package/dist/cli/{chunk-JWVG7ZPX.js → chunk-TBWYZOSV.js} +3 -3
  82. package/dist/cli/{chunk-RUFR4PUO.js → chunk-UQJBV5PM.js} +10 -10
  83. package/dist/cli/{chunk-LPUBBUKX.mjs → chunk-UREAIHUU.mjs} +2 -2
  84. package/dist/cli/{chunk-22OBDYHP.js → chunk-VAT2SXFF.js} +12 -12
  85. package/dist/cli/{chunk-LQ6RRYXN.mjs → chunk-VPERQ3U6.mjs} +5 -5
  86. package/dist/cli/{chunk-456RRXAP.mjs → chunk-VTK3HGMN.mjs} +5 -5
  87. package/dist/cli/{chunk-DVDWAC2M.mjs → chunk-VXTTAYOT.mjs} +2 -2
  88. package/dist/cli/{chunk-4PKHFW56.js → chunk-WKHPLBJK.js} +15 -15
  89. package/dist/cli/{chunk-YIRVKMON.mjs → chunk-X5KOHDJN.mjs} +1 -1
  90. package/dist/cli/{chunk-C4P2KLWT.js → chunk-Z3UEBFIN.js} +41 -41
  91. package/dist/cli/command-docs.js +2 -2
  92. package/dist/cli/command-docs.mjs +1 -1
  93. package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +21 -0
  94. package/dist/cli/{concurrent-runs-help-KBWPKSTP.mjs → concurrent-runs-help-C2O5YKQA.mjs} +7 -7
  95. package/dist/cli/{csv-XGGDZTQI.js → csv-MJDNOIQJ.js} +14 -14
  96. package/dist/cli/{csv-M5EBEMZH.mjs → csv-Z4DNGR54.mjs} +5 -5
  97. package/dist/cli/{db-M6FJ6J6E.mjs → db-4RL2BNOF.mjs} +7 -7
  98. package/dist/cli/{db-CVPR54XK.js → db-S5QVPK5E.js} +32 -32
  99. package/dist/cli/{describe-X6QA2U3C.mjs → describe-L4P5SZLQ.mjs} +19 -19
  100. package/dist/cli/describe-VLU2LUDJ.js +50 -0
  101. package/dist/cli/describe-core.d.mts +3 -3
  102. package/dist/cli/describe-core.d.ts +3 -3
  103. package/dist/cli/describe-core.js +1 -1
  104. package/dist/cli/describe-core.mjs +1 -1
  105. package/dist/cli/{executions-VJEEWN22.js → executions-MFZ2Z36O.js} +9 -9
  106. package/dist/cli/{executions-EHTS2XJX.mjs → executions-RR6O3XK5.mjs} +7 -7
  107. package/dist/cli/{feedback-76VGY4GP.mjs → feedback-EQBQ3ABB.mjs} +7 -7
  108. package/dist/cli/{feedback-DQPUCUXO.js → feedback-YDAG7VH2.js} +15 -15
  109. package/dist/cli/git-E6W44F5M.js +25 -0
  110. package/dist/cli/{git-IY6DKKLR.mjs → git-YGLCCU35.mjs} +6 -6
  111. package/dist/cli/index.js +150 -150
  112. package/dist/cli/index.mjs +46 -46
  113. package/dist/cli/{integrations-242LE3TQ.mjs → integrations-FWYXSBHK.mjs} +8 -8
  114. package/dist/cli/{integrations-CQSTIKFY.js → integrations-IQXYMRMW.js} +16 -16
  115. package/dist/cli/{legacy-noops-SWTSTMRY.mjs → legacy-noops-I4YRIX5F.mjs} +7 -7
  116. package/dist/cli/{legacy-noops-U72DO6ZF.js → legacy-noops-U7LI7UXC.js} +10 -10
  117. package/dist/cli/{mcp-L473BKLJ.js → mcp-GX2UKKWU.js} +25 -25
  118. package/dist/cli/{mcp-JJH6JR52.mjs → mcp-QJBMB6VS.mjs} +5 -5
  119. package/dist/cli/{monitors-3TF2DOFD.js → monitors-WCJYINGX.js} +164 -106
  120. package/dist/cli/{monitors-VSYHUBKC.mjs → monitors-Z6EGKYJP.mjs} +70 -12
  121. package/dist/cli/{org-YKVI2ZTI.js → org-7SKG423N.js} +89 -89
  122. package/dist/cli/{org-S5VIKU2E.mjs → org-NNHICBR2.mjs} +7 -7
  123. package/dist/cli/{play-DOWEG45Y.js → play-4P4DTG3Q.js} +318 -318
  124. package/dist/cli/{play-C7T5A3QM.mjs → play-CXDFPJ7Z.mjs} +18 -18
  125. package/dist/cli/{providers-TAZPPFTB.js → providers-EE4TUE3O.js} +10 -10
  126. package/dist/cli/{providers-BMVVX3VD.mjs → providers-VQLQ7DTR.mjs} +7 -7
  127. package/dist/cli/{quickstart-A3WKMKTW.mjs → quickstart-IYNJRB5G.mjs} +5 -5
  128. package/dist/cli/{quickstart-HD6FQXGR.js → quickstart-RVXHK4WA.js} +7 -7
  129. package/dist/cli/{run-BVVV2UX7.js → run-R3F34KU3.js} +44 -44
  130. package/dist/cli/{run-FV7TWNOC.mjs → run-VBQPPMEX.mjs} +24 -24
  131. package/dist/cli/{search-MGK6WIKS.mjs → search-B7R62HX5.mjs} +8 -8
  132. package/dist/cli/search-UUVFXZRA.js +32 -0
  133. package/dist/cli/{search-output-GM7LDZKE.mjs → search-output-LNQQXIGZ.mjs} +5 -5
  134. package/dist/cli/{search-output-6Y7KEPIE.js → search-output-LWHWEPOT.js} +7 -7
  135. package/dist/cli/{secrets-4RFAR7YI.mjs → secrets-NM3VAJLO.mjs} +7 -7
  136. package/dist/cli/{secrets-SISXIXSZ.js → secrets-QBOZ7WTD.js} +16 -16
  137. package/dist/cli/sessions-K3PD73Q2.js +22 -0
  138. package/dist/cli/{sessions-CE3OMEG7.mjs → sessions-R5BSIJ4I.mjs} +7 -7
  139. package/dist/cli/{settings-4HPM3K4A.js → settings-POYWKNRD.js} +86 -86
  140. package/dist/cli/{settings-E22IDSX2.mjs → settings-S4PN7WLY.mjs} +13 -13
  141. package/dist/cli/{setup-BK65MDZ6.mjs → setup-PFLXVBTL.mjs} +10 -10
  142. package/dist/cli/{setup-BDRSNLKX.js → setup-VHB4Z654.js} +50 -50
  143. package/dist/cli/skills-QNE2EYT3.js +36 -0
  144. package/dist/cli/{skills-FI2GZMR4.mjs → skills-W2TELEU7.mjs} +8 -8
  145. package/dist/cli/tools-3RLI4HGF.js +57 -0
  146. package/dist/cli/{tools-HMMWYUNW.mjs → tools-M4FA6N3Y.mjs} +18 -18
  147. package/dist/cli/update-UT6KIW2W.js +34 -0
  148. package/dist/cli/{update-WDKBSXV5.mjs → update-W7LIHEA7.mjs} +10 -10
  149. package/dist/cli/{views-775AUDWQ.js → views-DJXAGD7V.js} +22 -22
  150. package/dist/cli/{views-JYIJCO23.mjs → views-KTVPV6UP.mjs} +7 -7
  151. package/dist/cli/{workflow-FKKHE3IU.mjs → workflow-LGKCRODX.mjs} +8 -8
  152. package/dist/cli/{workflow-4H6KQRFQ.js → workflow-NVZDJKH2.js} +18 -18
  153. package/dist/{client-DD_FyJVd.d.ts → client-CCyWJqAI.d.ts} +1 -1
  154. package/dist/{client-ANT3pyoa.d.mts → client-Tp1LSULB.d.mts} +1 -1
  155. package/dist/{client-core-QHmo73k1.d.ts → client-core-BpYiYEfu.d.ts} +10 -1
  156. package/dist/{client-core-Dg9tKhdB.d.mts → client-core-D8eCZz3O.d.mts} +10 -1
  157. package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-EBWEUj0b.d.mts} +35 -0
  158. package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-EBWEUj0b.d.ts} +35 -0
  159. package/dist/{errors-Lm9_vJHZ.d.ts → errors-CParKUQR.d.mts} +2 -2
  160. package/dist/{errors-CwKXXtuu.d.mts → errors-Qt0OTA7_.d.ts} +2 -2
  161. package/dist/{index-DjwsAt82.d.mts → index-BMUVCNp7.d.mts} +1 -1
  162. package/dist/{index-3vJ-V9yw.d.ts → index-CoqDkIw0.d.ts} +1 -1
  163. package/dist/index.d.mts +7 -7
  164. package/dist/index.d.ts +7 -7
  165. package/dist/index.js +10 -10
  166. package/dist/index.mjs +7 -7
  167. package/dist/install-integrity.json +126 -124
  168. package/dist/plays/bundle-play-file.d.mts +3 -3
  169. package/dist/plays/bundle-play-file.d.ts +3 -3
  170. package/dist/plays/bundle-play-file.mjs +20 -1
  171. package/dist/plays/play-description.d.mts +2 -2
  172. package/dist/plays/play-description.d.ts +2 -2
  173. package/dist/plays/run-request.d.mts +2 -2
  174. package/dist/plays/run-request.d.ts +2 -2
  175. package/dist/release.d.mts +1 -1
  176. package/dist/release.d.ts +1 -1
  177. package/dist/release.js +2 -2
  178. package/dist/release.mjs +1 -1
  179. package/dist/server.d.mts +4 -4
  180. package/dist/server.d.ts +4 -4
  181. package/dist/server.js +10 -10
  182. package/dist/server.mjs +4 -4
  183. package/package.json +1 -1
  184. package/dist/cli/auth-ENBXAKQS.js +0 -43
  185. package/dist/cli/concurrent-runs-help-TOMLCMV7.js +0 -21
  186. package/dist/cli/describe-RUODIS6M.js +0 -50
  187. package/dist/cli/git-RLHTSYRY.js +0 -25
  188. package/dist/cli/search-VJFCWUZN.js +0 -32
  189. package/dist/cli/sessions-OWWZJZXH.js +0 -22
  190. package/dist/cli/skills-ZLBFUAFR.js +0 -36
  191. package/dist/cli/tools-3K72VE33.js +0 -57
  192. package/dist/cli/update-QZV6DH5V.js +0 -34
@@ -22,7 +22,10 @@ import {
22
22
  loadModalClientConfig,
23
23
  loadModalRequiredConfig,
24
24
  resolveModalSandboxMemoryPolicy,
25
+ resolveModalSandboxNetworkPolicy,
26
+ ModalSandboxAllowlistRequiredError,
25
27
  isModalPreviewEvaluation,
28
+ MODAL_SANDBOX_REGIONS,
26
29
  withModalCallSignal,
27
30
  } from '../../modal-runtime-config';
28
31
  import type { PlaySandboxRuntimeLimits } from '../../../plays/sandbox-runtime-limits';
@@ -102,6 +105,17 @@ import {
102
105
  type EarlySandboxStartRequest,
103
106
  type EarlySandboxSweepOutcome,
104
107
  } from '../early-sandbox';
108
+ import {
109
+ assertEarlySandboxEgress,
110
+ earlySandboxEgressKey,
111
+ earlySandboxEnvironment,
112
+ earlySandboxGatewayHosts,
113
+ EarlySandboxEnvironmentError,
114
+ EarlySandboxGatewayAddressWatch,
115
+ type EarlySandboxEgressRefusal,
116
+ type EarlySandboxEnvironment,
117
+ type EarlySandboxScope,
118
+ } from '../early-sandbox-egress';
105
119
 
106
120
  const MODAL_RUNNER_READY_TIMEOUT_MS =
107
121
  RUNTIME_RELIABILITY_POLICY.sandbox.runnerReadyTimeoutMs;
@@ -1021,6 +1035,137 @@ const MODAL_SUPERVISOR_READY_TIMEOUT_MS = 30_000;
1021
1035
  /** The `modal_sidecar` profile's default sandbox region (us-east). */
1022
1036
  const MODAL_SUPERVISOR_DEFAULT_REGIONS = ['us-east'];
1023
1037
 
1038
+ /**
1039
+ * A Modal sandbox's network placement. Under the modal_sidecar profile the
1040
+ * runner has no outbound network at all (the supervisor sidecar is its only
1041
+ * peer) and runs in the profile's regions. Otherwise it carries the
1042
+ * deployment's outbound allowlist (absent: OPEN egress, which Production
1043
+ * refuses at config load) and runs in `MODAL_SANDBOX_REGIONS` (us-east).
1044
+ */
1045
+ export function modalSandboxNetworkParams(input: {
1046
+ supervisorSidecar: boolean;
1047
+ outboundCidrAllowlist: string[] | null;
1048
+ }): { outboundCidrAllowlist?: string[]; regions?: string[] } {
1049
+ if (input.supervisorSidecar)
1050
+ return {
1051
+ outboundCidrAllowlist: [],
1052
+ regions:
1053
+ modalSupervisorLaunch().regions ?? MODAL_SUPERVISOR_DEFAULT_REGIONS,
1054
+ };
1055
+ // Unpinned, Modal places a sandbox anywhere in the world; every Play
1056
+ // sandbox runs in us-east, beside the iad gateways and relay.
1057
+ return input.outboundCidrAllowlist
1058
+ ? {
1059
+ outboundCidrAllowlist: input.outboundCidrAllowlist,
1060
+ regions: [...MODAL_SANDBOX_REGIONS],
1061
+ }
1062
+ : { regions: [...MODAL_SANDBOX_REGIONS] };
1063
+ }
1064
+
1065
+ export type ModalSandboxCreateParams = {
1066
+ cpu: number;
1067
+ cpuLimit: number;
1068
+ timeoutMs: number;
1069
+ idleTimeoutMs: number;
1070
+ workdir: string;
1071
+ memoryMiB: number;
1072
+ memoryLimitMiB: number;
1073
+ outboundCidrAllowlist?: string[];
1074
+ regions?: string[];
1075
+ };
1076
+
1077
+ /**
1078
+ * The one builder of a run sandbox's create parameters (all but its tags),
1079
+ * shared by the ordinary create and the early (E2) create so egress, CPU,
1080
+ * memory and regions cannot drift between a sandbox and the launch that
1081
+ * adopts it. CPU is the billed `physicalCpuCores` unless the modal_sidecar
1082
+ * profile overrides it.
1083
+ */
1084
+ export function modalSandboxCreateParams(input: {
1085
+ limits: PlaySandboxRuntimeLimits;
1086
+ memoryPolicy: { reservationMemoryMiB: number; memoryLimitMiB: number };
1087
+ workdir: string;
1088
+ outboundCidrAllowlist: string[] | null;
1089
+ supervisorSidecar: boolean;
1090
+ }): ModalSandboxCreateParams {
1091
+ const resources = modalSandboxResourcesForPlay(input.limits);
1092
+ const cpu =
1093
+ (input.supervisorSidecar && modalSupervisorLaunch().cpu) ||
1094
+ resources.physicalCpuCores;
1095
+ const lifetimeMs = modalSandboxLifetimeMs(input.limits);
1096
+ return {
1097
+ cpu,
1098
+ cpuLimit: cpu,
1099
+ timeoutMs: lifetimeMs,
1100
+ idleTimeoutMs: lifetimeMs,
1101
+ workdir: input.workdir,
1102
+ memoryMiB: input.memoryPolicy.reservationMemoryMiB,
1103
+ memoryLimitMiB: input.memoryPolicy.memoryLimitMiB,
1104
+ ...modalSandboxNetworkParams(input),
1105
+ };
1106
+ }
1107
+
1108
+ /**
1109
+ * The early create's parameters: the ordinary ones, with the orphan guard's
1110
+ * short idle timeout (an unadopted early sandbox runs no command and ends
1111
+ * after this window; PB runs one, and the exact-id reaper ends that sandbox).
1112
+ */
1113
+ export function earlyModalSandboxCreateParams(
1114
+ input: Parameters<typeof modalSandboxCreateParams>[0],
1115
+ ): ModalSandboxCreateParams {
1116
+ return {
1117
+ ...modalSandboxCreateParams(input),
1118
+ idleTimeoutMs: EARLY_SANDBOX_IDLE_TIMEOUT_MS,
1119
+ };
1120
+ }
1121
+
1122
+ /**
1123
+ * The early-sandbox scope (environment, egress) of a create's parameters.
1124
+ * `environment`, when given, is one the caller already resolved (the ordinary
1125
+ * launch resolves it before its circuit probe); otherwise it is read from
1126
+ * `env` and an unknown value throws.
1127
+ */
1128
+ export function modalSandboxCreateScope(
1129
+ params: Pick<ModalSandboxCreateParams, 'outboundCidrAllowlist'>,
1130
+ options: {
1131
+ environment?: EarlySandboxEnvironment;
1132
+ env?: Readonly<Record<string, string | undefined>>;
1133
+ } = {},
1134
+ ): EarlySandboxScope {
1135
+ return {
1136
+ environment:
1137
+ options.environment ??
1138
+ earlySandboxEnvironment(options.env ?? process.env),
1139
+ egressKey: earlySandboxEgressKey(params.outboundCidrAllowlist),
1140
+ };
1141
+ }
1142
+
1143
+ /**
1144
+ * The ordinary launch's deployment environment, for its cleanup and resource
1145
+ * records: exactly `preview` is Preview, anything else (unset, `native`, a
1146
+ * typo) is Production, as before early sandboxes existed. It never throws;
1147
+ * only the early-sandbox paths refuse an unknown value.
1148
+ */
1149
+ export function modalLaunchRuntimeEnvironment(
1150
+ env: Readonly<Record<string, string | undefined>> = process.env,
1151
+ ): EarlySandboxEnvironment {
1152
+ return env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
1153
+ ? 'preview'
1154
+ : 'production';
1155
+ }
1156
+
1157
+ /** The limits an early sandbox's create fixed, which adoption must match. */
1158
+ export function modalSandboxLimitsKey(
1159
+ params: ModalSandboxCreateParams,
1160
+ ): string {
1161
+ return earlySandboxLimitsKey({
1162
+ cpu: params.cpu,
1163
+ memoryMiB: params.memoryMiB,
1164
+ memoryLimitMiB: params.memoryLimitMiB,
1165
+ timeoutMs: params.timeoutMs,
1166
+ });
1167
+ }
1168
+
1024
1169
  type ModalSupervisorPlan = {
1025
1170
  image: Awaited<ReturnType<ModalClient['images']['fromName']>>;
1026
1171
  secret: Awaited<ReturnType<ModalClient['secrets']['fromObject']>>;
@@ -1460,7 +1605,7 @@ export async function startEarlyModalPreboot(input: {
1460
1605
  }
1461
1606
 
1462
1607
  /**
1463
- * Reap one early (or hedge) Modal sandbox by exact id if it is still
1608
+ * Reap one early Modal sandbox by exact id if it is still
1464
1609
  * unadopted (see reapEarlySandboxById).
1465
1610
  */
1466
1611
  export async function reapEarlyModalSandboxById(input: {
@@ -1483,47 +1628,106 @@ export async function reapEarlyModalSandboxById(input: {
1483
1628
  export async function sweepOrphanEarlyModalSandboxes(input: {
1484
1629
  client: Pick<ModalClient, 'sandboxes'>;
1485
1630
  modalAppId: string;
1631
+ environment: EarlySandboxScope['environment'];
1632
+ /** This process's early sandboxes; the module registry unless injected. */
1633
+ registry?: Pick<EarlyModalSandboxRegistry, 'settle'>;
1486
1634
  nowMs?: () => number;
1487
1635
  sleep?: (ms: number) => Promise<void>;
1488
1636
  limit?: number;
1489
1637
  }): Promise<EarlySandboxSweepOutcome> {
1490
1638
  return await sweepOrphanEarlySandboxes({
1491
1639
  calls: earlyModalSandboxCalls(input),
1640
+ environment: input.environment,
1641
+ registry: input.registry ?? earlyModalSandboxes,
1492
1642
  ...(input.nowMs === undefined ? {} : { nowMs: input.nowMs }),
1493
1643
  ...(input.sleep === undefined ? {} : { sleep: input.sleep }),
1494
1644
  ...(input.limit === undefined ? {} : { limit: input.limit }),
1495
1645
  });
1496
1646
  }
1497
1647
 
1648
+ function isModalNotFoundError(error: unknown): boolean {
1649
+ return error instanceof Error && error.name === 'NotFoundError';
1650
+ }
1651
+
1498
1652
  /**
1499
- * The worker's sweep pass. Early sandboxes exist only under the
1500
- * modal_sidecar profile (the Adapter's startUnavailable refuses otherwise), so with it
1501
- * off this makes no provider call.
1653
+ * The sweep's Modal app id, per client and app name, for this process: each
1654
+ * pass within the TTL is one listing, not an app lookup plus a listing. The
1655
+ * id is re-resolved after the TTL (an app deleted and recreated under the
1656
+ * same name gets a new id, which a stale listing would never see), and a
1657
+ * NotFound (the app was deleted) drops it at once.
1502
1658
  */
1503
- export async function sweepOrphanEarlyModalSandboxesForWorker(input: {
1659
+ export const EARLY_MODAL_SWEEP_APP_ID_TTL_MS = 10 * 60_000;
1660
+ const earlyModalSweepAppIds = new WeakMap<
1661
+ object,
1662
+ Map<string, { appId: string; resolvedAtMs: number }>
1663
+ >();
1664
+
1665
+ /**
1666
+ * The worker's sweep pass over this deployment environment's unadopted early
1667
+ * sandboxes. It runs whether or not the modal_sidecar profile is on: early
1668
+ * sandboxes start without it (behind the egress gate), and a sandbox another
1669
+ * process created must still be reaped after that process is gone. With none
1670
+ * in this environment, the pass is one tag-filtered listing. An unknown
1671
+ * DEEPLINE_RUNTIME_ENVIRONMENT sweeps nothing, loudly.
1672
+ */
1673
+ export async function sweepOrphanEarlyModalSandboxesForWorker(_input: {
1504
1674
  runtimeSchedulerSchema: string | null;
1505
1675
  }): Promise<
1506
- EarlySandboxSweepOutcome | { skipped: 'sidecar_profile_off' | 'app_missing' }
1676
+ EarlySandboxSweepOutcome | { skipped: 'app_missing' | 'environment_unknown' }
1507
1677
  > {
1508
- if (!DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar)
1509
- return { skipped: 'sidecar_profile_off' };
1510
- const modalConfig = await loadModalRequiredConfig({
1511
- runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1512
- limits: null,
1513
- });
1678
+ let environment: EarlySandboxScope['environment'];
1679
+ try {
1680
+ environment = earlySandboxEnvironment();
1681
+ } catch (error) {
1682
+ if (!(error instanceof EarlySandboxEnvironmentError)) throw error;
1683
+ console.error(
1684
+ JSON.stringify({
1685
+ event: `${EARLY_MODAL_LOG_SCOPE}.sweep_refused`,
1686
+ reason: 'environment_unknown',
1687
+ error: error.message,
1688
+ }),
1689
+ );
1690
+ return { skipped: 'environment_unknown' };
1691
+ }
1692
+ // Client config only: the sweep creates nothing, so it needs no network
1693
+ // policy (whose Production check would otherwise fail every pass).
1694
+ const modalConfig = await loadModalClientConfig();
1695
+ let appIds = earlyModalSweepAppIds.get(modalConfig.client);
1696
+ if (!appIds) {
1697
+ appIds = new Map();
1698
+ earlyModalSweepAppIds.set(modalConfig.client, appIds);
1699
+ }
1700
+ const cached = appIds.get(modalConfig.appName);
1514
1701
  let modalAppId: string;
1702
+ if (
1703
+ cached &&
1704
+ Date.now() - cached.resolvedAtMs < EARLY_MODAL_SWEEP_APP_ID_TTL_MS
1705
+ ) {
1706
+ modalAppId = cached.appId;
1707
+ } else {
1708
+ appIds.delete(modalConfig.appName);
1709
+ const resolvedAtMs = Date.now();
1710
+ try {
1711
+ modalAppId = (await modalConfig.client.apps.fromName(modalConfig.appName))
1712
+ .appId;
1713
+ } catch (error) {
1714
+ if (isModalNotFoundError(error)) return { skipped: 'app_missing' };
1715
+ throw error;
1716
+ }
1717
+ appIds.set(modalConfig.appName, { appId: modalAppId, resolvedAtMs });
1718
+ }
1515
1719
  try {
1516
- modalAppId = (await modalConfig.client.apps.fromName(modalConfig.appName))
1517
- .appId;
1720
+ return await sweepOrphanEarlyModalSandboxes({
1721
+ client: modalConfig.client,
1722
+ modalAppId,
1723
+ environment,
1724
+ });
1518
1725
  } catch (error) {
1519
- if (error instanceof Error && error.name === 'NotFoundError')
1520
- return { skipped: 'app_missing' };
1521
- throw error;
1726
+ if (!isModalNotFoundError(error)) throw error;
1727
+ // The cached app is gone: look it up again next pass.
1728
+ appIds.delete(modalConfig.appName);
1729
+ return { skipped: 'app_missing' };
1522
1730
  }
1523
- return await sweepOrphanEarlyModalSandboxes({
1524
- client: modalConfig.client,
1525
- modalAppId,
1526
- });
1527
1731
  }
1528
1732
 
1529
1733
  /**
@@ -1536,6 +1740,7 @@ async function createEarlyModalSandbox(
1536
1740
  key: string;
1537
1741
  orgId: string;
1538
1742
  hintAtMs: number;
1743
+ scope: EarlySandboxScope;
1539
1744
  },
1540
1745
  ): Promise<EarlyModalSandboxEntry> {
1541
1746
  const { key, orgId, hintAtMs } = input;
@@ -1543,7 +1748,7 @@ async function createEarlyModalSandbox(
1543
1748
  runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1544
1749
  limits: null,
1545
1750
  });
1546
- const resources = modalSandboxResourcesForPlay(modalConfig.limits);
1751
+ const supervisorSidecar = DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar;
1547
1752
  const memoryPolicy = resolveModalSandboxMemoryPolicy({
1548
1753
  limits: modalConfig.limits,
1549
1754
  runtimeSchedulerSchema: input.runtimeSchedulerSchema,
@@ -1587,24 +1792,29 @@ async function createEarlyModalSandbox(
1587
1792
  ),
1588
1793
  })
1589
1794
  : baseImage;
1590
- const cpu = modalSupervisorLaunch().cpu || resources.physicalCpuCores;
1591
- const timeoutMs = modalSandboxLifetimeMs(modalConfig.limits);
1592
- const createRequestedAtMs = Date.now();
1593
- const earlyParams = {
1594
- cpu,
1595
- cpuLimit: cpu,
1596
- timeoutMs,
1597
- // Orphan guard: an unadopted early sandbox runs no command and
1598
- // terminates after this idle window (PB runs one; the exact-id reaper
1599
- // ends that sandbox, see PREBOOT_RUNNER_IN_EARLY_SANDBOX).
1600
- idleTimeoutMs: EARLY_SANDBOX_IDLE_TIMEOUT_MS,
1795
+ const earlyParams = earlyModalSandboxCreateParams({
1796
+ limits: modalConfig.limits,
1797
+ memoryPolicy,
1601
1798
  workdir: modalConfig.workdir,
1602
- memoryMiB: memoryPolicy.reservationMemoryMiB,
1603
- memoryLimitMiB: memoryPolicy.memoryLimitMiB,
1604
- outboundCidrAllowlist: [],
1605
- regions:
1606
- modalSupervisorLaunch().regions ?? MODAL_SUPERVISOR_DEFAULT_REGIONS,
1607
- };
1799
+ outboundCidrAllowlist: modalConfig.outboundCidrAllowlist,
1800
+ supervisorSidecar,
1801
+ });
1802
+ // The key names the scope the hint was accepted for; the create must carry
1803
+ // exactly that egress policy, in this environment.
1804
+ const createScope = modalSandboxCreateScope(earlyParams);
1805
+ if (
1806
+ createScope.environment !== input.scope.environment ||
1807
+ createScope.egressKey !== input.scope.egressKey
1808
+ ) {
1809
+ throw new Error(
1810
+ `EARLY_MODAL_SANDBOX_SCOPE_CHANGED: the early create's ${
1811
+ createScope.environment !== input.scope.environment
1812
+ ? 'environment'
1813
+ : 'egress policy'
1814
+ } differs from the one its key names; no early sandbox was created.`,
1815
+ );
1816
+ }
1817
+ const createRequestedAtMs = Date.now();
1608
1818
  // PB: the pre-boot claim rides on the create tags, so no other process
1609
1819
  // can see this sandbox without it.
1610
1820
  const preboot =
@@ -1619,12 +1829,9 @@ async function createEarlyModalSandbox(
1619
1829
  orgId,
1620
1830
  workflowId: input.workflowId,
1621
1831
  createRequestedAtMs,
1622
- limitsKey: earlySandboxLimitsKey({
1623
- cpu,
1624
- memoryMiB: earlyParams.memoryMiB,
1625
- timeoutMs,
1626
- }),
1832
+ limitsKey: modalSandboxLimitsKey(earlyParams),
1627
1833
  preboot,
1834
+ ...input.scope,
1628
1835
  });
1629
1836
  const createEarly = () =>
1630
1837
  modalConfig.client.sandboxes.create(app, image, {
@@ -1676,6 +1883,7 @@ async function createEarlyModalSandbox(
1676
1883
  calls: lookups,
1677
1884
  key,
1678
1885
  sandboxId: sandbox.sandboxId,
1886
+ registry: earlyModalSandboxes,
1679
1887
  });
1680
1888
  if (preboot) {
1681
1889
  earlyModalPreboots.set(
@@ -1695,13 +1903,17 @@ async function createEarlyModalSandbox(
1695
1903
  }),
1696
1904
  );
1697
1905
  }
1698
- const earlySupervisor = resolveExperimentSwitch(
1699
- 'S1',
1700
- input.experimentSwitchOverrides,
1701
- START_SUPERVISOR_WITH_EARLY_SANDBOX,
1702
- );
1906
+ // S1 needs the sidecar profile: without it there is no sidecar to start.
1907
+ const earlySupervisor =
1908
+ supervisorSidecar &&
1909
+ resolveExperimentSwitch(
1910
+ 'S1',
1911
+ input.experimentSwitchOverrides,
1912
+ START_SUPERVISOR_WITH_EARLY_SANDBOX,
1913
+ );
1703
1914
  // PB's claim rode on the create tags, so it is already on the sandbox.
1704
- if (preboot) earlyModalForeignAdoptionClaims.set(sandbox, Promise.resolve());
1915
+ if (preboot)
1916
+ earlyModalForeignAdoptionClaims.set(sandbox, Promise.resolve());
1705
1917
  let tags: Record<string, string> = earlyTags;
1706
1918
  if (earlySupervisor) {
1707
1919
  tags = { ...earlyTags, [EARLY_SUPERVISOR_TAG]: '1' };
@@ -1747,21 +1959,162 @@ async function createEarlyModalSandbox(
1747
1959
  return { sandbox, startedAtMs: createRequestedAtMs, tags };
1748
1960
  }
1749
1961
 
1962
+ /** The deployment's outbound allowlist; null when unset. */
1963
+ export type ModalOutboundCidrAllowlistRead = {
1964
+ allowlist: string[] | null;
1965
+ /** Set when reading failed for any reason but an unset allowlist. */
1966
+ error: string | null;
1967
+ };
1968
+
1969
+ /**
1970
+ * The deployment's outbound allowlist. Production refuses an unset one
1971
+ * (`ModalSandboxAllowlistRequiredError`), which reads as unset; any other
1972
+ * failure is returned with its message, and the gate refuses on it.
1973
+ */
1974
+ export function readModalOutboundCidrAllowlist(input: {
1975
+ runtimeSchedulerSchema: string | null;
1976
+ resolve?: typeof resolveModalSandboxNetworkPolicy;
1977
+ }): ModalOutboundCidrAllowlistRead {
1978
+ const resolve = input.resolve ?? resolveModalSandboxNetworkPolicy;
1979
+ try {
1980
+ return {
1981
+ allowlist: resolve({
1982
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1983
+ }).outboundCidrAllowlist,
1984
+ error: null,
1985
+ };
1986
+ } catch (error) {
1987
+ if (error instanceof ModalSandboxAllowlistRequiredError)
1988
+ return { allowlist: null, error: null };
1989
+ return {
1990
+ allowlist: null,
1991
+ error: error instanceof Error ? error.message : String(error),
1992
+ };
1993
+ }
1994
+ }
1995
+
1996
+ /** The gateways' IPv4 addresses, for the early-sandbox egress gate. */
1997
+ const earlyModalGatewayAddresses = new EarlySandboxGatewayAddressWatch();
1998
+
1999
+ /**
2000
+ * Resolve the gateway addresses now and every 5 minutes, so the first
2001
+ * early-start hint after boot is not refused as `egress_gateway_dns_pending`.
2002
+ * Idempotent. The gate also starts it on first use.
2003
+ */
2004
+ export function startEarlyModalSandboxEgressWatch(): void {
2005
+ earlyModalGatewayAddresses.start();
2006
+ }
2007
+
2008
+ /**
2009
+ * The fail-closed egress gate for an early sandbox without the sidecar (see
2010
+ * `../early-sandbox-egress.ts`): refuse, loudly, unless the early create's
2011
+ * allowlist is non-empty, no entry is wider than /24, and every resolved IPv4
2012
+ * address of both gateways is covered. A refusal starts nothing; the launch
2013
+ * creates its own sandbox, as today.
2014
+ */
2015
+ export function earlyModalSandboxEgressRefusal(
2016
+ input: {
2017
+ runtimeSchedulerSchema?: string | null;
2018
+ gateway?: EarlySandboxGatewayAddressWatch;
2019
+ readAllowlist?: () => ModalOutboundCidrAllowlistRead;
2020
+ nowMs?: number;
2021
+ } = {},
2022
+ ): EarlySandboxEgressRefusal | null {
2023
+ const gateway = input.gateway ?? earlyModalGatewayAddresses;
2024
+ gateway.start();
2025
+ const read = (
2026
+ input.readAllowlist ??
2027
+ (() =>
2028
+ readModalOutboundCidrAllowlist({
2029
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema ?? null,
2030
+ }))
2031
+ )();
2032
+ return assertEarlySandboxEgress({
2033
+ logScope: EARLY_MODAL_LOG_SCOPE,
2034
+ outboundCidrAllowlist: read.allowlist,
2035
+ allowlistError: read.error,
2036
+ gatewayHosts: earlySandboxGatewayHosts(),
2037
+ gateway: gateway.state(),
2038
+ nowMs: input.nowMs ?? Date.now(),
2039
+ });
2040
+ }
2041
+
1750
2042
  /**
1751
- * Modal's early-sandbox Adapter. Early sandboxes start only under the
1752
- * modal_sidecar profile.
2043
+ * Why this process may not start an early Modal sandbox now, or null. An
2044
+ * unknown DEEPLINE_RUNTIME_ENVIRONMENT refuses first (nothing is tagged with
2045
+ * a guessed environment); then, without the sidecar, the egress gate.
2046
+ */
2047
+ export function earlyModalSandboxStartUnavailable(
2048
+ input: Parameters<typeof earlyModalSandboxEgressRefusal>[0] = {},
2049
+ ): EarlySandboxEgressRefusal | null {
2050
+ try {
2051
+ earlySandboxEnvironment();
2052
+ } catch (error) {
2053
+ if (!(error instanceof EarlySandboxEnvironmentError)) throw error;
2054
+ console.error(
2055
+ JSON.stringify({
2056
+ event: `${EARLY_MODAL_LOG_SCOPE}.start_refused`,
2057
+ reason: 'environment_unknown',
2058
+ error: error.message,
2059
+ }),
2060
+ );
2061
+ return 'environment_unknown';
2062
+ }
2063
+ return DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar
2064
+ ? null
2065
+ : earlyModalSandboxEgressRefusal(input);
2066
+ }
2067
+
2068
+ /**
2069
+ * The environment an ordinary launch adopts an early sandbox under, or null
2070
+ * (one loud line) when DEEPLINE_RUNTIME_ENVIRONMENT is unknown: the launch
2071
+ * then creates its own sandbox, as with E2 off. When known, it equals
2072
+ * modalLaunchRuntimeEnvironment.
2073
+ */
2074
+ export function earlyModalAdoptionEnvironment(
2075
+ env: Readonly<Record<string, string | undefined>> = process.env,
2076
+ ): EarlySandboxEnvironment | null {
2077
+ try {
2078
+ return earlySandboxEnvironment(env);
2079
+ } catch (error) {
2080
+ if (!(error instanceof EarlySandboxEnvironmentError)) throw error;
2081
+ console.error(
2082
+ JSON.stringify({
2083
+ event: `${EARLY_MODAL_LOG_SCOPE}.adoption_refused`,
2084
+ reason: 'environment_unknown',
2085
+ error: error.message,
2086
+ }),
2087
+ );
2088
+ return null;
2089
+ }
2090
+ }
2091
+
2092
+ /**
2093
+ * Modal's early-sandbox Adapter. Under the modal_sidecar profile the early
2094
+ * sandbox has no egress (the sidecar is its only peer). Without it, it
2095
+ * carries the launch's outbound allowlist, behind the egress gate.
1753
2096
  */
1754
2097
  export const modalEarlySandboxAdapter: EarlySandboxAdapter<ModalSandbox> = {
1755
2098
  provider: 'modal',
1756
2099
  logScope: EARLY_MODAL_LOG_SCOPE,
1757
2100
  registry: earlyModalSandboxes,
1758
- startUnavailable: () =>
1759
- DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar ? null : 'sidecar_profile_off',
2101
+ startUnavailable: () => earlyModalSandboxStartUnavailable(),
2102
+ scope: (input) => {
2103
+ const read = readModalOutboundCidrAllowlist({
2104
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
2105
+ });
2106
+ if (read.error) throw new Error(read.error);
2107
+ return modalSandboxCreateScope(
2108
+ modalSandboxNetworkParams({
2109
+ supervisorSidecar: DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar,
2110
+ outboundCidrAllowlist: read.allowlist,
2111
+ }),
2112
+ );
2113
+ },
1760
2114
  createEarly: createEarlyModalSandbox,
1761
2115
  sweepOrphansForWorker: sweepOrphanEarlyModalSandboxesForWorker,
1762
2116
  };
1763
2117
 
1764
-
1765
2118
  /**
1766
2119
  * Adopt this run's early Modal sandbox by exact id, or return null so the
1767
2120
  * launch creates its own (see adoptEarlySandbox). A sandbox whose S1 sidecar
@@ -1771,6 +2124,8 @@ export async function adoptEarlyModalSandbox(input: {
1771
2124
  client: ModalClient;
1772
2125
  modalAppId: string;
1773
2126
  workflowId: string;
2127
+ /** This launch's environment and the egress of the create it would make. */
2128
+ scope: EarlySandboxScope;
1774
2129
  expectedLimitsKey: string;
1775
2130
  createTags: Record<string, string>;
1776
2131
  context: PlayRunnerExecutionConfig['context'];
@@ -1791,6 +2146,7 @@ export async function adoptEarlyModalSandbox(input: {
1791
2146
  orgId: input.context.orgId,
1792
2147
  runId: input.context.runId,
1793
2148
  experimentSwitchOverrides: input.context.experimentSwitchOverrides,
2149
+ scope: input.scope,
1794
2150
  expectedLimitsKey: input.expectedLimitsKey,
1795
2151
  createTags: input.createTags,
1796
2152
  preboot: input.preboot,
@@ -1853,6 +2209,18 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
1853
2209
  // build failure still surfaces where the payload is staged.
1854
2210
  const bundlePromise = buildPlayRunnerBundle();
1855
2211
  bundlePromise.catch(() => undefined);
2212
+ // Resolved before the circuit probe claim; neither throws. The records'
2213
+ // environment keeps its original mapping; an unknown value only turns
2214
+ // early-sandbox adoption off (loudly), never the launch.
2215
+ const runtimeEnvironment = modalLaunchRuntimeEnvironment();
2216
+ const earlyAdoptionEnvironment =
2217
+ resolveExperimentSwitch(
2218
+ 'E2',
2219
+ config.context.experimentSwitchOverrides,
2220
+ EARLY_SANDBOX_START,
2221
+ ) && config.context.workflowId
2222
+ ? earlyModalAdoptionEnvironment()
2223
+ : null;
1856
2224
  const providerCircuitClaim =
1857
2225
  await callbacks?.shouldAttemptSandboxProvider?.('modal');
1858
2226
  if (providerCircuitClaim && !providerCircuitClaim.allowed) {
@@ -2038,10 +2406,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2038
2406
  }
2039
2407
  await callbacks.onAmbiguousModalCreateIntent({
2040
2408
  modalAppId: app.appId,
2041
- runtimeEnvironment:
2042
- process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
2043
- ? 'preview'
2044
- : 'production',
2409
+ runtimeEnvironment,
2045
2410
  tags: createTags,
2046
2411
  ...(capacityReservation
2047
2412
  ? { sandboxCapacityLeaseId: capacityReservation.leaseId }
@@ -2051,52 +2416,31 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2051
2416
  elapsedMs: Date.now() - startedAt,
2052
2417
  });
2053
2418
  createSent = true;
2054
- const createParams = {
2055
- cpu:
2056
- (supervisorPlan && modalSupervisorLaunch().cpu) ||
2057
- resources.physicalCpuCores,
2058
- cpuLimit:
2059
- (supervisorPlan && modalSupervisorLaunch().cpu) ||
2060
- resources.physicalCpuCores,
2061
- timeoutMs: modalSandboxLifetimeMs(modalConfig.limits),
2062
- idleTimeoutMs: modalSandboxLifetimeMs(modalConfig.limits),
2419
+ // The same builder as the early create, so a sandbox this launch
2420
+ // adopts was created with these parameters (its limits key and
2421
+ // egress key say so).
2422
+ const sandboxParams = modalSandboxCreateParams({
2423
+ limits: modalConfig.limits,
2424
+ memoryPolicy,
2063
2425
  workdir: modalConfig.workdir,
2064
- tags: createTags,
2065
- memoryMiB: memoryPolicy.reservationMemoryMiB,
2066
- memoryLimitMiB: memoryPolicy.memoryLimitMiB,
2067
- // Under the profile the runner has no outbound network at all:
2068
- // the supervisor sidecar is its only peer.
2069
- ...(supervisorPlan
2070
- ? {
2071
- outboundCidrAllowlist: [],
2072
- regions:
2073
- modalSupervisorLaunch().regions ??
2074
- MODAL_SUPERVISOR_DEFAULT_REGIONS,
2075
- }
2076
- : modalConfig.outboundCidrAllowlist
2077
- ? { outboundCidrAllowlist: modalConfig.outboundCidrAllowlist }
2078
- : {}),
2079
- };
2426
+ outboundCidrAllowlist: modalConfig.outboundCidrAllowlist,
2427
+ supervisorSidecar: supervisorPlan !== null,
2428
+ });
2429
+ const createParams = { ...sandboxParams, tags: createTags };
2080
2430
  const createSandbox = () =>
2081
2431
  modalConfig.client.sandboxes.create(app, image, createParams);
2082
2432
  sandbox = await awaitModalSandboxCreate({
2083
2433
  create:
2084
- resolveExperimentSwitch(
2085
- 'E2',
2086
- config.context.experimentSwitchOverrides,
2087
- EARLY_SANDBOX_START,
2088
- ) &&
2089
- supervisorPlan &&
2090
- config.context.workflowId
2434
+ earlyAdoptionEnvironment && config.context.workflowId
2091
2435
  ? adoptEarlyModalSandbox({
2092
2436
  client: modalConfig.client,
2093
2437
  modalAppId: app.appId,
2094
2438
  workflowId: config.context.workflowId,
2095
- expectedLimitsKey: earlySandboxLimitsKey({
2096
- cpu: createParams.cpu,
2097
- memoryMiB: createParams.memoryMiB,
2098
- timeoutMs: createParams.timeoutMs,
2439
+ // The early create's scope builder, so the two cannot drift.
2440
+ scope: modalSandboxCreateScope(sandboxParams, {
2441
+ environment: earlyAdoptionEnvironment,
2099
2442
  }),
2443
+ expectedLimitsKey: modalSandboxLimitsKey(sandboxParams),
2100
2444
  createTags,
2101
2445
  context: config.context,
2102
2446
  preboot: {
@@ -2131,10 +2475,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2131
2475
  resource: {
2132
2476
  kind: 'modal_sandbox',
2133
2477
  sandboxId: lateSandbox.sandboxId,
2134
- runtimeEnvironment:
2135
- process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
2136
- ? 'preview'
2137
- : 'production',
2478
+ runtimeEnvironment,
2138
2479
  modalAppId: app.appId,
2139
2480
  billingStartedAt: modalCreateRequestedAt,
2140
2481
  lateAcquired: true,
@@ -2335,10 +2676,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2335
2676
  await callbacks?.onRuntimeResourceAcquired?.({
2336
2677
  kind: 'modal_sandbox',
2337
2678
  sandboxId: sandbox.sandboxId,
2338
- runtimeEnvironment:
2339
- process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
2340
- ? 'preview'
2341
- : 'production',
2679
+ runtimeEnvironment,
2342
2680
  modalAppId: app.appId,
2343
2681
  billingStartedAt,
2344
2682
  maxBillingDurationSeconds: