deepline 0.3.542 → 0.3.543

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 (243) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +106 -2
  2. package/dist/bundling-sources/sdk/src/index.ts +7 -0
  3. package/dist/bundling-sources/sdk/src/integrations.ts +198 -0
  4. package/dist/bundling-sources/sdk/src/plays/run-request.ts +3 -0
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/tool-calls.ts +35 -11
  7. package/dist/bundling-sources/sdk/src/types.ts +10 -0
  8. package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +132 -0
  9. package/dist/bundling-sources/shared_libs/integration-contracts/tool-connection.ts +13 -0
  10. package/dist/bundling-sources/shared_libs/monitors/package.json +1 -1
  11. package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
  12. package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
  13. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +5 -5
  14. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +34 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +11 -5
  16. package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +9 -7
  17. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +235 -12
  18. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +20 -1
  19. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +39 -30
  20. package/dist/bundling-sources/shared_libs/play-runtime/event-wait-tools.ts +2 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +10 -4
  22. package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +209 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +4 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +24 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +2 -1
  26. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +6 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +37 -0
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +42 -3
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +7 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +15 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +23 -5
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +320 -836
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/vercel-sandbox.ts +1061 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +862 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +45 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/sandbox-create-outcome.ts +3 -1
  37. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +11 -5
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-contract.ts +20 -2
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-placement-policy.ts +71 -34
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-provider-profile.ts +286 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +4 -1
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +12 -3
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +7 -0
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +46 -55
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +127 -5
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +7 -1
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +214 -0
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/managed-sandbox-resource-sql.ts +118 -0
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +1 -0
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +226 -144
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +1 -1
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +2 -1
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +11 -13
  54. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +42 -7
  55. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +2 -1
  56. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +2 -2
  57. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +17 -0
  58. package/dist/bundling-sources/shared_libs/play-runtime/vercel-sandbox-runtime-config.ts +217 -0
  59. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +23 -0
  60. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +1 -0
  61. package/dist/bundling-sources/shared_libs/plays/script-entry.ts +76 -6
  62. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +1 -0
  63. package/dist/bundling-sources/shared_libs/security/credential-revision.ts +50 -0
  64. package/dist/bundling-sources/shared_libs/security/internal-actor.ts +2 -1
  65. package/dist/bundling-sources/shared_libs/security/receipt-admission-token.ts +37 -0
  66. package/dist/cli/{auth-IGBGOB4E.mjs → auth-ITAELTOA.mjs} +5 -5
  67. package/dist/cli/auth-S6B5WUU5.js +43 -0
  68. package/dist/cli/{billing-IB2TWE74.js → billing-33XVFDUJ.js} +101 -101
  69. package/dist/cli/{billing-N37W2I62.mjs → billing-WZ7RVZW4.mjs} +12 -12
  70. package/dist/cli/{chunk-D44DP4KJ.js → chunk-23D224GI.js} +37 -17
  71. package/dist/cli/{chunk-B5NP3SHX.mjs → chunk-274WKLSY.mjs} +2 -2
  72. package/dist/cli/{chunk-GBAT5NMI.mjs → chunk-2HSZCQMT.mjs} +48 -6
  73. package/dist/cli/{chunk-VLEVVDWG.js → chunk-2JHYYB3F.js} +3 -3
  74. package/dist/cli/{chunk-FGGPCAGC.js → chunk-2KTGZKRE.js} +18 -18
  75. package/dist/cli/{chunk-AWLPERL3.js → chunk-2LNTKICO.js} +3 -3
  76. package/dist/cli/{chunk-5CAVURVS.js → chunk-2NCJQEZH.js} +53 -53
  77. package/dist/cli/{chunk-6SLEHAXX.js → chunk-3JZXU5OB.js} +5 -5
  78. package/dist/cli/{chunk-4I47NCRI.js → chunk-46BEBZ3M.js} +497 -328
  79. package/dist/cli/{chunk-V4EYJKGJ.js → chunk-4JQEAYN3.js} +156 -17
  80. package/dist/cli/{chunk-DADH3WPE.mjs → chunk-4SKDSSPU.mjs} +2 -2
  81. package/dist/cli/{chunk-FX4OWXKK.mjs → chunk-52YK3EII.mjs} +2 -2
  82. package/dist/cli/{chunk-HAITCPCG.js → chunk-5MN3BKNB.js} +16 -16
  83. package/dist/cli/{chunk-FFDZT255.mjs → chunk-5VIPTLRX.mjs} +1 -1
  84. package/dist/cli/{chunk-OLH2PHMC.mjs → chunk-6P7TGCHQ.mjs} +1 -1
  85. package/dist/cli/{chunk-YK7NNZD4.mjs → chunk-6SJZMMD5.mjs} +37 -190
  86. package/dist/cli/chunk-7AUQTNLB.mjs +455 -0
  87. package/dist/cli/{chunk-I5EAIFGO.mjs → chunk-AACKPOGA.mjs} +1 -1
  88. package/dist/cli/{chunk-GM73TZ2W.js → chunk-BGAUADV4.js} +41 -41
  89. package/dist/cli/{chunk-KQSTV4MW.js → chunk-BLYW6FFB.js} +60 -18
  90. package/dist/cli/{chunk-LFMQVSEI.js → chunk-C35NLLSA.js} +5 -5
  91. package/dist/cli/{chunk-5APOJWJF.mjs → chunk-D6YAU3CF.mjs} +182 -13
  92. package/dist/cli/{chunk-TT4JUUC3.mjs → chunk-DH43ECTN.mjs} +7 -3
  93. package/dist/cli/{chunk-TTBHOMAA.js → chunk-DI3GL3T6.js} +316 -469
  94. package/dist/cli/{chunk-D7GWEBMF.js → chunk-DUGTPVT7.js} +7 -7
  95. package/dist/cli/{chunk-UNDLNT3V.js → chunk-ECWOIXAV.js} +1 -1
  96. package/dist/cli/{chunk-CFZCRM6R.js → chunk-EHUG6EUT.js} +26 -26
  97. package/dist/cli/chunk-F6VSQ5LN.js +455 -0
  98. package/dist/cli/{chunk-ACVTMAW4.mjs → chunk-FNW2SGPD.mjs} +2 -2
  99. package/dist/cli/{chunk-EHLCWGWN.js → chunk-GRCFX2EG.js} +4 -4
  100. package/dist/cli/{chunk-OVX3Q5Q3.mjs → chunk-GWNYLIF7.mjs} +1 -1
  101. package/dist/cli/{chunk-6WQDHEVF.mjs → chunk-HKJ26NRN.mjs} +5 -5
  102. package/dist/cli/{chunk-L2VKAASU.mjs → chunk-HXIR3VQL.mjs} +21 -0
  103. package/dist/cli/{chunk-WL2GUGNZ.js → chunk-J2F6F5GL.js} +7 -7
  104. package/dist/cli/{chunk-2VRKBHMD.mjs → chunk-JXG7HWBA.mjs} +1 -1
  105. package/dist/cli/{chunk-Z2XA6YU4.mjs → chunk-LX35AXTN.mjs} +1 -0
  106. package/dist/cli/{chunk-DNGACHFX.js → chunk-MCBUWK5K.js} +22 -22
  107. package/dist/cli/{chunk-Q7WDXLYO.js → chunk-NHKP2NSU.js} +2 -2
  108. package/dist/cli/{chunk-FANIRW74.mjs → chunk-NIPLY25A.mjs} +0 -2
  109. package/dist/cli/{chunk-AKY7KZRJ.js → chunk-NLENABRU.js} +6 -6
  110. package/dist/cli/{chunk-ORA5TMML.mjs → chunk-NR3O56FT.mjs} +5 -5
  111. package/dist/cli/{chunk-3XXXMSSP.js → chunk-O2KLWUNI.js} +44 -44
  112. package/dist/cli/{chunk-ZVNYBQ77.mjs → chunk-OAFKUHN5.mjs} +4 -4
  113. package/dist/cli/{chunk-2ZGSHVZE.mjs → chunk-OELJKQOL.mjs} +24 -4
  114. package/dist/cli/{chunk-E7B73LGT.js → chunk-PX7XAVUC.js} +24 -20
  115. package/dist/cli/{chunk-VHJUH3TB.js → chunk-QFRMVI4S.js} +3 -3
  116. package/dist/cli/{chunk-Z5YRKX7K.mjs → chunk-R57UCXQG.mjs} +1 -1
  117. package/dist/cli/{chunk-IPVRMYWT.js → chunk-RKF263LR.js} +5 -5
  118. package/dist/cli/{chunk-CQDQNZGH.js → chunk-SL6MYJYM.js} +1 -0
  119. package/dist/cli/{chunk-JPT6VE54.js → chunk-STXG2LFC.js} +2 -2
  120. package/dist/cli/{chunk-SCLP5H4P.mjs → chunk-SU4K4SUU.mjs} +1 -1
  121. package/dist/cli/{chunk-NLZHLEHD.mjs → chunk-SYOPHFKB.mjs} +6 -6
  122. package/dist/cli/{chunk-WACIN4PR.mjs → chunk-SZNJENGT.mjs} +3 -3
  123. package/dist/cli/{chunk-QXNOSCYL.js → chunk-TBCNL2T5.js} +1 -1
  124. package/dist/cli/{chunk-E4CABWXL.js → chunk-TI6DTURF.js} +22 -1
  125. package/dist/cli/{chunk-NDNEARE3.js → chunk-UJ6GOV7K.js} +13 -13
  126. package/dist/cli/{chunk-GWHA4DAC.js → chunk-UV4RU2TE.js} +0 -2
  127. package/dist/cli/{chunk-P4MDTBAA.mjs → chunk-VSJEOSYL.mjs} +1 -1
  128. package/dist/cli/{chunk-EGOCGWCI.mjs → chunk-W2OPPSAZ.mjs} +3 -3
  129. package/dist/cli/{chunk-46V7QSJE.mjs → chunk-XBM3KABD.mjs} +3 -3
  130. package/dist/cli/{chunk-QONO7FRF.mjs → chunk-XFPVFWZR.mjs} +1 -1
  131. package/dist/cli/{chunk-PLIKPGOO.mjs → chunk-XSN6BAZT.mjs} +5 -5
  132. package/dist/cli/{chunk-IDDKNMFX.mjs → chunk-Y3T5GWYK.mjs} +153 -14
  133. package/dist/cli/{chunk-AUFE624T.js → chunk-YE3T73BV.js} +10 -10
  134. package/dist/cli/{chunk-DMXLZ57N.js → chunk-YJYKZ2U3.js} +2 -2
  135. package/dist/cli/{chunk-F6QV42MC.mjs → chunk-Z7SXGOIQ.mjs} +1 -1
  136. package/dist/cli/{chunk-SWO5QOXB.mjs → chunk-ZRT2PNYY.mjs} +1 -1
  137. package/dist/cli/{chunk-3LEUSRV3.mjs → chunk-ZSPBJB7I.mjs} +4 -4
  138. package/dist/cli/command-docs.js +3 -3
  139. package/dist/cli/command-docs.mjs +2 -2
  140. package/dist/cli/concurrent-runs-help-E4OYD3DS.js +21 -0
  141. package/dist/cli/{concurrent-runs-help-DIBGMEIN.mjs → concurrent-runs-help-Z6ODNL4E.mjs} +7 -7
  142. package/dist/cli/{csv-CAVA3EMS.mjs → csv-5QW2HPHT.mjs} +4 -4
  143. package/dist/cli/{csv-XZAM7EYZ.js → csv-SSOFTXHU.js} +13 -13
  144. package/dist/cli/{db-PPGEOBNG.js → db-4LK5AJNO.js} +29 -29
  145. package/dist/cli/{db-HD332QI7.mjs → db-K2JMR6EM.mjs} +8 -8
  146. package/dist/cli/describe-AC6PLEFP.js +50 -0
  147. package/dist/cli/describe-AXHQZHTT.mjs +50 -0
  148. package/dist/cli/describe-core.d.mts +3 -3
  149. package/dist/cli/describe-core.d.ts +3 -3
  150. package/dist/cli/describe-core.js +3 -3
  151. package/dist/cli/describe-core.mjs +2 -2
  152. package/dist/cli/{executions-4ZKBL7IC.js → executions-AATJQQAQ.js} +10 -10
  153. package/dist/cli/{executions-AFEOLB4A.mjs → executions-FY2XTX2W.mjs} +8 -8
  154. package/dist/cli/{feedback-J2YPLKMF.mjs → feedback-MKBPRGS6.mjs} +6 -6
  155. package/dist/cli/{feedback-M6Y33JKT.js → feedback-QPVJER75.js} +14 -14
  156. package/dist/cli/{git-632RYEF6.mjs → git-AGRFZR3K.mjs} +5 -5
  157. package/dist/cli/git-RUYFQEJX.js +25 -0
  158. package/dist/cli/index.js +150 -146
  159. package/dist/cli/index.mjs +49 -45
  160. package/dist/cli/integrations-OUQ6U33M.mjs +98 -0
  161. package/dist/cli/integrations-R6OUFZXI.js +98 -0
  162. package/dist/cli/{legacy-noops-KWZMXYAU.mjs → legacy-noops-DVL2RRKL.mjs} +6 -6
  163. package/dist/cli/{legacy-noops-4Y62TKPC.js → legacy-noops-H7INM2QN.js} +9 -9
  164. package/dist/cli/{mcp-PESLHAAC.mjs → mcp-2Z2YVOLK.mjs} +72 -15
  165. package/dist/cli/{mcp-35QA6YG7.js → mcp-33F7D7WI.js} +89 -32
  166. package/dist/cli/{monitors-4DTUZLAI.js → monitors-KDUJHAKJ.js} +102 -102
  167. package/dist/cli/{monitors-YVBKBJBU.mjs → monitors-NZD2WIKK.mjs} +9 -9
  168. package/dist/cli/{org-FWCBZMER.js → org-4PQGHLEB.js} +90 -90
  169. package/dist/cli/{org-DJNKMFCZ.mjs → org-EJW45RUA.mjs} +8 -8
  170. package/dist/cli/{play-PHVQEEEZ.mjs → play-3CM5RT5J.mjs} +44 -25
  171. package/dist/cli/{play-FZ45M4KD.js → play-MLHMQL4G.js} +374 -355
  172. package/dist/cli/{providers-46E67QG7.mjs → providers-BHYBJI4R.mjs} +10 -9
  173. package/dist/cli/{providers-QJU6FMDD.js → providers-YBJG7277.js} +13 -12
  174. package/dist/cli/{quickstart-6HMJJ4RR.mjs → quickstart-LL3MR562.mjs} +4 -4
  175. package/dist/cli/{quickstart-HOL7H5FS.js → quickstart-O7L2NNGJ.js} +6 -6
  176. package/dist/cli/{run-WKSIRXEC.js → run-HJ2AR6CM.js} +49 -48
  177. package/dist/cli/{run-2W2TJ6QA.mjs → run-OK545H5Q.mjs} +28 -27
  178. package/dist/cli/search-UUNS6BCC.js +32 -0
  179. package/dist/cli/{search-Y2CFLSYB.mjs → search-Z5ZKMRTX.mjs} +9 -9
  180. package/dist/cli/{search-output-FCZ35PHF.mjs → search-output-Q5VHNUWG.mjs} +4 -4
  181. package/dist/cli/{search-output-2IK6ZZDY.js → search-output-SVW4DETG.js} +6 -6
  182. package/dist/cli/{secrets-JVJIHGU4.js → secrets-ENQWMCB5.js} +17 -17
  183. package/dist/cli/{secrets-PNPNUZLX.mjs → secrets-QIKIEFWB.mjs} +8 -8
  184. package/dist/cli/{sessions-GY5VVQGO.mjs → sessions-AETO22RF.mjs} +6 -6
  185. package/dist/cli/sessions-FNSUDERA.js +22 -0
  186. package/dist/cli/{settings-YQOPF3AI.mjs → settings-G5RGRPFV.mjs} +16 -16
  187. package/dist/cli/{settings-5WHMFRNQ.js → settings-OFLIFTMZ.js} +89 -89
  188. package/dist/cli/{setup-O5U5IEVW.mjs → setup-G4N3X6KG.mjs} +9 -9
  189. package/dist/cli/{setup-3VJMKDEU.js → setup-QW7Y62XD.js} +49 -49
  190. package/dist/cli/skills-3IXIY2IV.js +36 -0
  191. package/dist/cli/{skills-G6J5PF35.mjs → skills-QRFQGHNA.mjs} +7 -7
  192. package/dist/cli/{tools-AG7SWL5Y.mjs → tools-52BH7UTF.mjs} +20 -19
  193. package/dist/cli/tools-MYBUMPKH.js +57 -0
  194. package/dist/cli/update-GT7574UU.js +34 -0
  195. package/dist/cli/{update-K73DD6CR.mjs → update-SDGZLAGL.mjs} +9 -9
  196. package/dist/cli/{views-MO6DIOMR.mjs → views-3BIJFJMQ.mjs} +8 -8
  197. package/dist/cli/{views-4D2OTLIO.js → views-5QKAWYPI.js} +23 -23
  198. package/dist/cli/{workflow-ZEMFCS4Y.js → workflow-G67RPWVY.js} +19 -19
  199. package/dist/cli/{workflow-MMZMAELI.mjs → workflow-QAK773FR.mjs} +9 -9
  200. package/dist/{client-X-FJD5Dp.d.ts → client-D1ga52xq.d.ts} +1 -1
  201. package/dist/{client-DLG9mHDh.d.mts → client-bd4QQIXo.d.mts} +1 -1
  202. package/dist/{client-core-0jmHfFBv.d.ts → client-core-B6eMVx8h.d.ts} +334 -3
  203. package/dist/{client-core-WtnqyBwY.d.mts → client-core-CqfWNf2Q.d.mts} +334 -3
  204. package/dist/{compiler-manifest-Cys06iYg.d.mts → compiler-manifest-BWFtsQIC.d.mts} +21 -0
  205. package/dist/{compiler-manifest-Cys06iYg.d.ts → compiler-manifest-BWFtsQIC.d.ts} +21 -0
  206. package/dist/{errors-B6eMjKcr.d.mts → errors-CwKXXtuu.d.mts} +1 -1
  207. package/dist/{errors-rdOUqcU2.d.ts → errors-Lm9_vJHZ.d.ts} +1 -1
  208. package/dist/{index-ejWadAL5.d.ts → index-3vJ-V9yw.d.ts} +1 -1
  209. package/dist/{index-CZdYO81A.d.mts → index-DjwsAt82.d.mts} +1 -1
  210. package/dist/index.d.mts +7 -7
  211. package/dist/index.d.ts +7 -7
  212. package/dist/index.js +12 -12
  213. package/dist/index.mjs +8 -8
  214. package/dist/install-integrity.json +147 -133
  215. package/dist/plays/bundle-play-file.d.mts +3 -3
  216. package/dist/plays/bundle-play-file.d.ts +3 -3
  217. package/dist/plays/bundle-play-file.mjs +23 -4
  218. package/dist/plays/play-description.d.mts +2 -2
  219. package/dist/plays/play-description.d.ts +2 -2
  220. package/dist/plays/run-request.d.mts +2 -2
  221. package/dist/plays/run-request.d.ts +2 -2
  222. package/dist/plays/run-request.js +2 -2
  223. package/dist/plays/run-request.mjs +1 -1
  224. package/dist/release.d.mts +1 -1
  225. package/dist/release.d.ts +1 -1
  226. package/dist/release.js +2 -2
  227. package/dist/release.mjs +1 -1
  228. package/dist/server.d.mts +4 -4
  229. package/dist/server.d.ts +4 -4
  230. package/dist/server.js +7 -7
  231. package/dist/server.mjs +5 -5
  232. package/package.json +1 -1
  233. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal-resource-usage.ts +0 -222
  234. package/dist/cli/auth-2PH6RSKL.js +0 -43
  235. package/dist/cli/concurrent-runs-help-BNIDBKML.js +0 -21
  236. package/dist/cli/describe-5TFFB2PM.js +0 -49
  237. package/dist/cli/describe-THQU7N47.mjs +0 -49
  238. package/dist/cli/git-AQLQYWRI.js +0 -25
  239. package/dist/cli/search-YLJFCJTK.js +0 -32
  240. package/dist/cli/sessions-TZ33UCPS.js +0 -22
  241. package/dist/cli/skills-WZY3XDT3.js +0 -36
  242. package/dist/cli/tools-BXQBL72Q.js +0 -56
  243. package/dist/cli/update-XYP5EII6.js +0 -34
@@ -1,4 +1,3 @@
1
- import { createHash } from 'node:crypto';
2
1
  import type { ModalClient, SidecarCreateParams } from 'modal';
3
2
  import type { PlayRunnerBackend, PlayRunnerCallbacks } from '../types';
4
3
  import {
@@ -42,7 +41,6 @@ import {
42
41
  INLINE_BAKED_RUNNER_UNVERIFIED_EXIT_CODE,
43
42
  INLINE_ENVELOPE_INCOMPLETE_EXIT_CODE,
44
43
  PrebootedRunnerLimitsMismatchError,
45
- samePlaySandboxRuntimeLimits,
46
44
  stageRunnerPayload,
47
45
  type BakedRunnerExpectation,
48
46
  type PrebootedRunnerLaunch,
@@ -78,10 +76,32 @@ import {
78
76
  executePrewarmSentAtAdmission,
79
77
  type ModalSupervisorRunPin,
80
78
  } from '../../modal-supervisor-sidecar';
79
+ import { resolveExperimentSwitch } from '../../experiment-switches';
81
80
  import {
82
- resolveExperimentSwitch,
83
- type ExperimentSwitchOverrides,
84
- } from '../../experiment-switches';
81
+ adoptEarlySandbox,
82
+ EARLY_PREBOOT_VERDICT_TIMEOUT_MS,
83
+ EARLY_SANDBOX_IDLE_TIMEOUT_MS,
84
+ EARLY_SANDBOX_START,
85
+ EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS,
86
+ earlySandboxCreateTags,
87
+ earlySandboxLimitsKey,
88
+ EarlySandboxRegistry,
89
+ logEarlySandbox,
90
+ logEarlySandboxReapUnconfirmed,
91
+ PREBOOT_RUNNER_IN_EARLY_SANDBOX,
92
+ readEarlySandboxExitCode,
93
+ reapEarlySandboxById,
94
+ scheduleEarlySandboxReap,
95
+ sleepMs,
96
+ sweepOrphanEarlySandboxes,
97
+ terminateEarlySandboxConfirmed,
98
+ type EarlySandboxAdapter,
99
+ type EarlySandboxEntry,
100
+ type EarlySandboxPreboot,
101
+ type EarlySandboxProviderCalls,
102
+ type EarlySandboxStartRequest,
103
+ type EarlySandboxSweepOutcome,
104
+ } from '../early-sandbox';
85
105
 
86
106
  const MODAL_RUNNER_READY_TIMEOUT_MS =
87
107
  RUNTIME_RELIABILITY_POLICY.sandbox.runnerReadyTimeoutMs;
@@ -1251,135 +1271,48 @@ export async function pinModalSupervisorSidecar(input: {
1251
1271
  }
1252
1272
 
1253
1273
  /**
1254
- * Preview experiment E2: start the Modal sandbox for a run right after its
1255
- * admission authenticated and funded it, before the run is enqueued, claimed
1256
- * and launched. The early sandbox carries no token, no payload and no
1257
- * supervisor: only the image, the standard resource profile and a
1258
- * deterministic per-run tag. The launching worker adopts it by exact sandbox
1259
- * id (tag lookup, then re-tag with the ordinary create tags so every cleanup
1260
- * and reconciliation path sees an ordinary sandbox) and then starts the
1261
- * supervisor and uploads the payload as today; otherwise it creates its own.
1262
- * Orphans: a short Modal idle timeout, plus an exact-id reaper that
1263
- * terminates the early sandbox if it is still unadopted after the reap delay.
1264
- * Off.
1274
+ * Modal's early-sandbox Adapter. The provider-neutral Module
1275
+ * (`../early-sandbox.ts`) owns early start (E2), pre-boot (PB) and in-process
1276
+ * adoption (A1): the registry, the org-scoped key and identity refusal, the
1277
+ * adoption-age rules, the exact-id reaper and the durable orphan sweep. This
1278
+ * Adapter supplies the Modal calls: the early create (image, CPU, regions,
1279
+ * create tags), tag reads and writes, termination, the tag listing, the PB
1280
+ * pre-boot exec, and S1, the supervisor sidecar, which only Modal has.
1265
1281
  */
1266
- export const EARLY_MODAL_SANDBOX_START = false;
1267
- const EARLY_MODAL_SANDBOX_SOURCE_TAG = 'deepline-play-runner-early';
1268
- const EARLY_MODAL_SANDBOX_IDLE_TIMEOUT_MS = 60_000;
1269
- const EARLY_MODAL_SANDBOX_REAP_AFTER_MS = 90_000;
1270
- /**
1271
- * No launch adopts an early sandbox older than this (create request -> adopt
1272
- * check). Kept well under EARLY_MODAL_SANDBOX_REAP_AFTER_MS so a reaper can
1273
- * never terminate a sandbox that a launch is in the middle of adopting.
1274
- * Adoption is normally ~1-2 s after create.
1275
- */
1276
- export const EARLY_MODAL_SANDBOX_MAX_ADOPTION_AGE_MS = 60_000;
1277
- /** Create-request time (epoch ms), set in the create tags. */
1278
- const EARLY_CREATED_AT_TAG = 'earlyCreatedAtMs';
1282
+ const EARLY_MODAL_LOG_SCOPE = 'play-runner.modal.early';
1279
1283
 
1280
- export type EarlyModalSandboxEntry = {
1281
- sandbox: ModalSandbox;
1282
- startedAtMs: number;
1283
- /** The tags this process last set on the early sandbox. */
1284
- tags: Record<string, string>;
1285
- };
1284
+ export type EarlyModalSandboxEntry = EarlySandboxEntry<ModalSandbox>;
1286
1285
 
1287
- /**
1288
- * This process's unadopted early sandboxes, by org-scoped key. `take` removes
1289
- * the entry, so each early sandbox is handed to at most one in-process
1290
- * adoption; an unadopted entry expires after twice the reap delay.
1291
- */
1292
- export class EarlyModalSandboxRegistry {
1293
- readonly #entries = new Map<string, Promise<EarlyModalSandboxEntry | null>>();
1294
-
1295
- has(key: string): boolean {
1296
- return this.#entries.has(key);
1297
- }
1298
-
1299
- put(
1300
- key: string,
1301
- entry: Promise<EarlyModalSandboxEntry | null>,
1302
- ttlMs: number = EARLY_MODAL_SANDBOX_REAP_AFTER_MS * 2,
1303
- ): void {
1304
- this.#entries.set(key, entry);
1305
- setTimeout(() => {
1306
- if (this.#entries.get(key) === entry) this.#entries.delete(key);
1307
- }, ttlMs).unref?.();
1308
- }
1309
-
1310
- take(key: string): Promise<EarlyModalSandboxEntry | null> | undefined {
1311
- const entry = this.#entries.get(key);
1312
- this.#entries.delete(key);
1313
- return entry;
1314
- }
1315
- }
1286
+ /** This process's unadopted early Modal sandboxes (see EarlySandboxRegistry). */
1287
+ export class EarlyModalSandboxRegistry extends EarlySandboxRegistry<ModalSandbox> {}
1316
1288
  const earlyModalSandboxes = new EarlyModalSandboxRegistry();
1317
1289
 
1318
- /**
1319
- * The early sandbox's key. Org-scoped: a workflow id is chosen by the caller,
1320
- * so two orgs can name the same one; neither may find the other's sandbox.
1321
- */
1322
- export function earlyModalSandboxKey(input: {
1323
- orgId: string;
1324
- workflowId: string;
1325
- }): string {
1326
- return createHash('sha256')
1327
- .update(JSON.stringify([input.orgId, input.workflowId]))
1328
- .digest('hex')
1329
- .slice(0, 40);
1330
- }
1331
-
1332
- /**
1333
- * Why an early sandbox's tags do not belong to this launch's run, or null.
1334
- * Checked on every adoption path, before the sandbox is re-tagged or used.
1335
- */
1336
- export function earlyModalSandboxIdentityRefusal(
1337
- tags: Record<string, string>,
1338
- expected: { key: string; orgId: string; workflowId: string },
1339
- ): 'key_mismatch' | 'org_mismatch' | 'workflow_mismatch' | null {
1340
- if (tags.earlyKey !== expected.key) return 'key_mismatch';
1341
- if (tags.orgId !== expected.orgId) return 'org_mismatch';
1342
- if (tags.workflowId !== expected.workflowId) return 'workflow_mismatch';
1343
- return null;
1344
- }
1345
-
1346
- /** Age of an early sandbox from its create tag; null when it has none. */
1347
- function earlyModalSandboxAgeMs(
1348
- tags: Record<string, string>,
1349
- nowMs: number,
1350
- ): number | null {
1351
- const createdAtMs = Number(tags[EARLY_CREATED_AT_TAG]);
1352
- return Number.isSafeInteger(createdAtMs) && createdAtMs > 0
1353
- ? nowMs - createdAtMs
1354
- : null;
1290
+ function logEarlyModalSandbox(event: string, extra: Record<string, unknown>) {
1291
+ logEarlySandbox(EARLY_MODAL_LOG_SCOPE, event, extra);
1355
1292
  }
1356
1293
 
1357
- function earlyModalLimitsKey(input: {
1358
- cpu: number;
1359
- memoryMiB: number;
1360
- timeoutMs: number;
1361
- }): string {
1362
- return `${input.cpu}:${input.memoryMiB}:${input.timeoutMs}`;
1294
+ /** Exact-id lookups; enough for the reaper and a confirmed termination. */
1295
+ function earlyModalSandboxLookups(
1296
+ client: Pick<ModalClient, 'sandboxes'>,
1297
+ ): Pick<EarlySandboxProviderCalls<ModalSandbox>, 'fromId' | 'logScope'> {
1298
+ return {
1299
+ logScope: EARLY_MODAL_LOG_SCOPE,
1300
+ fromId: (sandboxId) => client.sandboxes.fromId(sandboxId),
1301
+ };
1363
1302
  }
1364
1303
 
1365
- function logEarlyModalSandbox(event: string, extra: Record<string, unknown>) {
1366
- console.info(
1367
- '[play-runner.modal.early]',
1368
- JSON.stringify({ event, ...extra, atMs: Date.now() }),
1369
- );
1304
+ /** Lookups plus the tag listing, bound to the Modal app. */
1305
+ function earlyModalSandboxCalls(input: {
1306
+ client: Pick<ModalClient, 'sandboxes'>;
1307
+ modalAppId: string;
1308
+ }): EarlySandboxProviderCalls<ModalSandbox> {
1309
+ return {
1310
+ ...earlyModalSandboxLookups(input.client),
1311
+ list: (tags) =>
1312
+ input.client.sandboxes.list({ appId: input.modalAppId, tags }),
1313
+ };
1370
1314
  }
1371
1315
 
1372
- /**
1373
- * Start (fire and forget) the early sandbox for an admitted run. Idempotent
1374
- * per process; a second hint for the same run is ignored.
1375
- */
1376
- /**
1377
- * Source tag of the retired F2 hedged early create (docs/runtime-speed-
1378
- * experiments.md). Nothing creates it now; the reaper and the durable sweep
1379
- * still treat it as unadopted, so a leg left by an older worker is reaped.
1380
- */
1381
- const EARLY_MODAL_SANDBOX_HEDGE_TAG = 'deepline-play-runner-early-hedge';
1382
-
1383
1316
  /**
1384
1317
  * S1 (off): with E2, start the supervisor sidecar (both gateways) on the early
1385
1318
  * sandbox right after its create, so the gateways have listened and fetched
@@ -1407,79 +1340,7 @@ const earlyModalForeignAdoptionClaims = new WeakMap<
1407
1340
  Promise<unknown>
1408
1341
  >();
1409
1342
 
1410
- /**
1411
- * A1 (off): adopting an early sandbox this process created checks the tags
1412
- * this process set instead of reading them back from Modal (one RPC fewer on
1413
- * the launch path, ~20 ms). Only for a fresh entry this process created and
1414
- * has not handed out (the registry's `take`), whose foreign-adoption claim is
1415
- * confirmed on the sandbox; every other adoption reads the tags back. The
1416
- * exit-code read, the identity check and the re-tag are unchanged. Per-run
1417
- * capable (experiment switch A1).
1418
- */
1419
- export const ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ = false;
1420
-
1421
- /**
1422
- * PB (off): with E2 and the baked runner image, the early sandbox also starts
1423
- * the baked runner right after its create, before the run is adopted, so
1424
- * shell start, watchdog setup and runner bundle evaluation (~200-380 ms) are
1425
- * off the launch path. One exec runs, in order: the baked-runner verify guard
1426
- * (verdict line first; a non-ok verdict exits 98 before anything else), the
1427
- * runtime watchdog starting the runner as `--wait-config <configPath>`, and
1428
- * the crash-terminal epilogue, all at fixed per-sandbox paths. It holds no
1429
- * credentials or customer data: no envelope, config or token exists in the
1430
- * sandbox until the run is adopted. The watchdog's runtime/memory limits and
1431
- * the runner's V8 flags are fixed at pre-boot from the early sandbox's own
1432
- * (standard) profile, the same one its `limitsKey` encodes; adoption refuses a
1433
- * run whose limits differ, and staging asserts it again.
1434
- *
1435
- * Adoption (in this process only) delivers the envelope in one exec: stdin to
1436
- * a file (same guard as the inline launch), then the run's files, config LAST
1437
- * via rename; the waiting runner picks it up and proceeds exactly as today
1438
- * (heartbeat, readiness, park fence). Readiness is confirmed as today, and
1439
- * also fails fast (deferred to a new attempt) if the delivery exec fails or
1440
- * the pre-boot chain exits first.
1441
- *
1442
- * Not adopted (an ordinary sandbox is created and this one is reaped): a
1443
- * sandbox whose pre-boot another process started (tag), one whose pre-boot
1444
- * is ambiguous (exec error, late or missing verdict without a confirmed exit
1445
- * 98), one whose pre-boot already exited, one older than
1446
- * EARLY_PREBOOT_MAX_ADOPTION_AGE_MS, or a launch whose PB resolves off. A
1447
- * pre-boot that provably never started (exit 98 confirmed, or no baked plan)
1448
- * is adopted and launched today's way.
1449
- *
1450
- * Orphans: the exact-id reaper (EARLY_MODAL_SANDBOX_REAP_AFTER_MS, 90 s after
1451
- * create) terminates an unadopted sandbox and the waiting runner with it; the
1452
- * running exec may keep Modal's idle timeout from firing, so the reaper is the
1453
- * killer. If the reap itself fails, the runner gives up its config wait at
1454
- * its own 120 s deadline (runner-app WAIT_CONFIG_TIMEOUT_MS), the chain exits
1455
- * (the epilogue has no crash pusher or config and pushes nothing), and the
1456
- * then-idle sandbox ends at the 60 s idle timeout; the watchdog's own 240 s
1457
- * startup deadline is a later backstop. Adoption itself is ~1-2 s after
1458
- * create, far inside every bound. Per-run capable (experiment switch PB).
1459
- */
1460
- export const PREBOOT_RUNNER_IN_EARLY_SANDBOX = false;
1461
- const EARLY_PREBOOT_TAG = 'earlyPreboot';
1462
- /**
1463
- * A pre-boot older than this is not adopted: its watchdog's startup deadline
1464
- * runs from pre-boot, and the runner's config wait has a 120 s deadline.
1465
- */
1466
- const EARLY_PREBOOT_MAX_ADOPTION_AGE_MS = 30_000;
1467
- /** Bound on the pre-boot's verdict line, and on its exit after a refusal. */
1468
- const EARLY_PREBOOT_VERDICT_TIMEOUT_MS = 15_000;
1469
- export type EarlyModalPreboot =
1470
- | {
1471
- status: 'running';
1472
- runner: PrebootedRunnerLaunch;
1473
- /** The pre-boot chain's exit code (runner, then epilogue). */
1474
- exited: Promise<number>;
1475
- /** Set once `exited` settles with a code. */
1476
- exitCode: number | null;
1477
- startedAtMs: number;
1478
- }
1479
- /** Provably nothing ran: today's launch may use this sandbox. */
1480
- | { status: 'not_started'; reason: string }
1481
- /** Cannot prove what ran: never adopted. */
1482
- | { status: 'ambiguous'; reason: string };
1343
+ export type EarlyModalPreboot = EarlySandboxPreboot<PrebootedRunnerLaunch>;
1483
1344
  const earlyModalPreboots = new WeakMap<
1484
1345
  ModalSandbox,
1485
1346
  Promise<EarlyModalPreboot>
@@ -1597,57 +1458,10 @@ export async function startEarlyModalPreboot(input: {
1597
1458
  ? fail('not_started', `verdict_${verdict}`)
1598
1459
  : fail('ambiguous', `verdict_${verdict}_exit_${code ?? 'unknown'}`);
1599
1460
  }
1600
- /**
1601
- * An early sandbox on a slow host may not have a running container yet when
1602
- * it is terminated, so its exit code can stay unset for a while (FAST1c: 2 of
1603
- * 12 unconfirmed after ~11 s). Re-terminate and re-read with a backoff capped at
1604
- * 2 s, ~60 s in all, before handing it to the 90 s exact-id reaper.
1605
- */
1606
- const EARLY_MODAL_SANDBOX_HEDGE_CONFIRM_ATTEMPTS = 35;
1607
- const earlyHedgeConfirmDelayMs = (attempt: number) =>
1608
- Math.min(200 * attempt, 2_000);
1609
1461
 
1610
1462
  /**
1611
- * Terminate a sandbox by exact id and confirm it by reading its exit code
1612
- * back, re-terminating with a capped backoff (a not-yet-running sandbox may
1613
- * miss a terminate). Returns the attempts it took; throws when the read-back
1614
- * never confirms within `attempts`, or on a provider error.
1615
- */
1616
- export async function terminateModalSandboxConfirmed(input: {
1617
- sandbox: Pick<ModalSandbox, 'terminate' | 'sandboxId'>;
1618
- readExitCode: (sandboxId: string) => Promise<number | null>;
1619
- sleep: (ms: number) => Promise<void>;
1620
- attempts: number;
1621
- }): Promise<number> {
1622
- for (let attempt = 1; attempt <= input.attempts; attempt++) {
1623
- // Idempotent; repeated because a not-yet-running sandbox may miss it.
1624
- await input.sandbox.terminate();
1625
- if ((await input.readExitCode(input.sandbox.sandboxId)) !== null)
1626
- return attempt;
1627
- await input.sleep(earlyHedgeConfirmDelayMs(attempt));
1628
- }
1629
- throw new Error('termination not confirmed by read-back');
1630
- }
1631
-
1632
- const sleepMs = (ms: number) =>
1633
- new Promise<void>((resolve) => setTimeout(resolve, ms));
1634
-
1635
- const readModalExitCode =
1636
- (client: Pick<ModalClient, 'sandboxes'>) => async (sandboxId: string) =>
1637
- await (await client.sandboxes.fromId(sandboxId)).poll();
1638
-
1639
- function isUnadoptedEarlyModalSandbox(tags: Record<string, string>): boolean {
1640
- return (
1641
- tags.source === EARLY_MODAL_SANDBOX_SOURCE_TAG ||
1642
- tags.source === EARLY_MODAL_SANDBOX_HEDGE_TAG
1643
- );
1644
- }
1645
-
1646
- /**
1647
- * Reap one early (or hedge) sandbox by exact id if it is still unadopted: a
1648
- * fresh tag read (an adopted sandbox carries ordinary launch tags), then a
1649
- * confirmed termination. An unconfirmed one keeps its early tag, so the
1650
- * durable sweep (sweepOrphanEarlyModalSandboxes) still finds it.
1463
+ * Reap one early (or hedge) Modal sandbox by exact id if it is still
1464
+ * unadopted (see reapEarlySandboxById).
1651
1465
  */
1652
1466
  export async function reapEarlyModalSandboxById(input: {
1653
1467
  client: Pick<ModalClient, 'sandboxes'>;
@@ -1656,168 +1470,40 @@ export async function reapEarlyModalSandboxById(input: {
1656
1470
  attempts?: number;
1657
1471
  sleep?: (ms: number) => Promise<void>;
1658
1472
  }): Promise<'not_early' | 'terminated'> {
1659
- const fresh = await input.client.sandboxes.fromId(input.sandboxId);
1660
- if (!isUnadoptedEarlyModalSandbox(await fresh.getTags())) return 'not_early';
1661
- const confirmAttempts = await terminateModalSandboxConfirmed({
1662
- sandbox: fresh,
1663
- readExitCode: readModalExitCode(input.client),
1664
- sleep: input.sleep ?? sleepMs,
1665
- attempts: input.attempts ?? EARLY_MODAL_SANDBOX_HEDGE_CONFIRM_ATTEMPTS,
1666
- });
1667
- logEarlyModalSandbox('reaped_unadopted', {
1473
+ return await reapEarlySandboxById({
1474
+ calls: earlyModalSandboxLookups(input.client),
1668
1475
  key: input.key,
1669
1476
  sandboxId: input.sandboxId,
1670
- confirmAttempts,
1477
+ ...(input.attempts === undefined ? {} : { attempts: input.attempts }),
1478
+ ...(input.sleep === undefined ? {} : { sleep: input.sleep }),
1671
1479
  });
1672
- return 'terminated';
1673
- }
1674
-
1675
- function logEarlyModalSandboxReapUnconfirmed(input: {
1676
- event: string;
1677
- key: string;
1678
- sandboxId: string;
1679
- error: unknown;
1680
- }) {
1681
- // Loud: the sandbox keeps its early tag, so the durable sweep retries it.
1682
- console.error(
1683
- JSON.stringify({
1684
- event: `play-runner.modal.early.${input.event}`,
1685
- key: input.key,
1686
- sandboxId: input.sandboxId,
1687
- error:
1688
- input.error instanceof Error
1689
- ? input.error.message
1690
- : String(input.error),
1691
- }),
1692
- );
1693
1480
  }
1694
1481
 
1695
- /**
1696
- * In-process exact-id reaper: after EARLY_MODAL_SANDBOX_REAP_AFTER_MS,
1697
- * terminate the sandbox (confirmed) if it still carries an early (or hedge)
1698
- * tag, i.e. no launch adopted it. The fast path only: the durable guarantee is
1699
- * the early tag itself, set by the create call, which the worker's sweep reads
1700
- * even after this process is gone.
1701
- */
1702
- function scheduleEarlyModalSandboxReap(input: {
1703
- client: ModalClient;
1704
- key: string;
1705
- sandboxId: string;
1706
- }): void {
1707
- const reap = setTimeout(() => {
1708
- void reapEarlyModalSandboxById(input).catch((error: unknown) =>
1709
- logEarlyModalSandboxReapUnconfirmed({
1710
- event: 'reap_unconfirmed',
1711
- key: input.key,
1712
- sandboxId: input.sandboxId,
1713
- error,
1714
- }),
1715
- );
1716
- }, EARLY_MODAL_SANDBOX_REAP_AFTER_MS);
1717
- reap.unref?.();
1718
- }
1719
-
1720
- /**
1721
- * Durable orphan cleanup for E2/PB early sandboxes (and retired F2 legs). The cleanup
1722
- * obligation is recorded before (atomically with) every early create: the
1723
- * create request itself carries the early (or hedge) source tag and its
1724
- * create time, and Modal holds those tags for the sandbox's life. The main
1725
- * path's `ambiguous_modal_creates` row cannot be used here: the hint arrives
1726
- * before the run is enqueued, so there is no run row or attempt lease to
1727
- * fence it to. Once adopted, a sandbox carries the run's create tags and the
1728
- * main path's obligation (recorded before adoption) covers it.
1729
- *
1730
- * This pass lists only unadopted early sandboxes (the source-tag selector),
1731
- * skips any younger than EARLY_MODAL_SANDBOX_REAP_AFTER_MS, re-reads each
1732
- * one's tags by exact id, and terminates it with a bounded confirmation. No
1733
- * launch adopts past EARLY_MODAL_SANDBOX_MAX_ADOPTION_AGE_MS (60 s < 90 s), so
1734
- * whichever worker created it, an early sandbox this old is an orphan. One
1735
- * not confirmed this pass keeps its tag and is retried by the next.
1736
- */
1737
- export const EARLY_MODAL_SANDBOX_SWEEP_INTERVAL_MS = 60_000;
1738
- const EARLY_MODAL_SANDBOX_SWEEP_LIMIT = 20;
1739
- const EARLY_MODAL_SANDBOX_SWEEP_CONFIRM_ATTEMPTS = 5;
1740
-
1482
+ /** The durable orphan sweep over one Modal app (see sweepOrphanEarlySandboxes). */
1741
1483
  export async function sweepOrphanEarlyModalSandboxes(input: {
1742
1484
  client: Pick<ModalClient, 'sandboxes'>;
1743
1485
  modalAppId: string;
1744
1486
  nowMs?: () => number;
1745
1487
  sleep?: (ms: number) => Promise<void>;
1746
1488
  limit?: number;
1747
- }): Promise<{
1748
- observed: number;
1749
- terminated: number;
1750
- unconfirmed: number;
1751
- young: number;
1752
- }> {
1753
- const nowMs = input.nowMs ?? Date.now;
1754
- const limit = input.limit ?? EARLY_MODAL_SANDBOX_SWEEP_LIMIT;
1755
- const ids = new Set<string>();
1756
- for (const source of [
1757
- EARLY_MODAL_SANDBOX_SOURCE_TAG,
1758
- EARLY_MODAL_SANDBOX_HEDGE_TAG,
1759
- ]) {
1760
- for await (const listed of input.client.sandboxes.list({
1761
- appId: input.modalAppId,
1762
- tags: { source },
1763
- })) {
1764
- if (ids.size >= limit) break;
1765
- if (listed.sandboxId?.trim()) ids.add(listed.sandboxId.trim());
1766
- }
1767
- }
1768
- let terminated = 0;
1769
- let unconfirmed = 0;
1770
- let young = 0;
1771
- await Promise.all(
1772
- [...ids].map(async (sandboxId) => {
1773
- try {
1774
- const fresh = await input.client.sandboxes.fromId(sandboxId);
1775
- const tags = await fresh.getTags();
1776
- if (!isUnadoptedEarlyModalSandbox(tags)) return;
1777
- const ageMs = earlyModalSandboxAgeMs(tags, nowMs());
1778
- // A sandbox without a create time predates the tag and is past any
1779
- // adoption (adoption refuses it), so it is reaped.
1780
- if (ageMs !== null && ageMs < EARLY_MODAL_SANDBOX_REAP_AFTER_MS) {
1781
- young += 1;
1782
- return;
1783
- }
1784
- const confirmAttempts = await terminateModalSandboxConfirmed({
1785
- sandbox: fresh,
1786
- readExitCode: readModalExitCode(input.client),
1787
- sleep: input.sleep ?? sleepMs,
1788
- attempts: EARLY_MODAL_SANDBOX_SWEEP_CONFIRM_ATTEMPTS,
1789
- });
1790
- terminated += 1;
1791
- logEarlyModalSandbox('swept_orphan', {
1792
- key: tags.earlyKey ?? null,
1793
- sandboxId,
1794
- ageMs,
1795
- confirmAttempts,
1796
- });
1797
- } catch (error) {
1798
- unconfirmed += 1;
1799
- logEarlyModalSandboxReapUnconfirmed({
1800
- event: 'sweep_unconfirmed',
1801
- key: 'sweep',
1802
- sandboxId,
1803
- error,
1804
- });
1805
- }
1806
- }),
1807
- );
1808
- return { observed: ids.size, terminated, unconfirmed, young };
1489
+ }): Promise<EarlySandboxSweepOutcome> {
1490
+ return await sweepOrphanEarlySandboxes({
1491
+ calls: earlyModalSandboxCalls(input),
1492
+ ...(input.nowMs === undefined ? {} : { nowMs: input.nowMs }),
1493
+ ...(input.sleep === undefined ? {} : { sleep: input.sleep }),
1494
+ ...(input.limit === undefined ? {} : { limit: input.limit }),
1495
+ });
1809
1496
  }
1810
1497
 
1811
1498
  /**
1812
1499
  * The worker's sweep pass. Early sandboxes exist only under the
1813
- * modal_sidecar profile (startEarlyModalSandbox refuses otherwise), so with it
1500
+ * modal_sidecar profile (the Adapter's startUnavailable refuses otherwise), so with it
1814
1501
  * off this makes no provider call.
1815
1502
  */
1816
1503
  export async function sweepOrphanEarlyModalSandboxesForWorker(input: {
1817
1504
  runtimeSchedulerSchema: string | null;
1818
1505
  }): Promise<
1819
- | Awaited<ReturnType<typeof sweepOrphanEarlyModalSandboxes>>
1820
- | { skipped: 'sidecar_profile_off' | 'app_missing' }
1506
+ EarlySandboxSweepOutcome | { skipped: 'sidecar_profile_off' | 'app_missing' }
1821
1507
  > {
1822
1508
  if (!DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar)
1823
1509
  return { skipped: 'sidecar_profile_off' };
@@ -1840,290 +1526,246 @@ export async function sweepOrphanEarlyModalSandboxesForWorker(input: {
1840
1526
  });
1841
1527
  }
1842
1528
 
1843
- export function startEarlyModalSandbox(input: {
1844
- workflowId: string;
1845
- orgId?: string | null;
1846
- runtimeSchedulerSchema: string | null;
1847
- /** EXPERIMENT: the hinted run's overrides (E2, PB, S1); absent: static. */
1848
- experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
1849
- }): boolean {
1850
- if (
1851
- !resolveExperimentSwitch(
1852
- 'E2',
1853
- input.experimentSwitchOverrides,
1854
- EARLY_MODAL_SANDBOX_START,
1855
- ) ||
1856
- !DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar
1857
- )
1858
- return false;
1859
- // The key and the adoption check are org-scoped; a hint without an org
1860
- // cannot start a sandbox any launch could safely adopt.
1861
- const orgId = input.orgId?.trim();
1862
- if (!orgId) {
1863
- logEarlyModalSandbox('hint_refused', { reason: 'no_org' });
1864
- return false;
1865
- }
1866
- const key = earlyModalSandboxKey({ orgId, workflowId: input.workflowId });
1867
- if (earlyModalSandboxes.has(key)) return false;
1868
- const hintAtMs = Date.now();
1869
- const started = (async () => {
1870
- const modalConfig = await loadModalRequiredConfig({
1871
- runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1872
- limits: null,
1873
- });
1874
- const resources = modalSandboxResourcesForPlay(modalConfig.limits);
1875
- const memoryPolicy = resolveModalSandboxMemoryPolicy({
1876
- limits: modalConfig.limits,
1877
- runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1878
- });
1879
- const app = await modalLaunchLookup({
1880
- client: modalConfig.client,
1881
- key: `app:${modalConfig.appName}`,
1882
- enabled: true,
1883
- load: () =>
1884
- modalConfig.client.apps.fromName(modalConfig.appName, {
1885
- createIfMissing: true,
1886
- }),
1887
- });
1888
- const runnerImage = await resolveModalRunnerImage({
1889
- client: modalConfig.client,
1890
- configuredHash: await bakedRunnerLookupHash({
1891
- bundle: buildPlayRunnerBundle,
1529
+ /**
1530
+ * The Modal create behind startEarlySandbox: resolve the app and image, create
1531
+ * with the early tags, then arm the sandbox (exact-id reaper, PB pre-boot, S1
1532
+ * supervisor).
1533
+ */
1534
+ async function createEarlyModalSandbox(
1535
+ input: EarlySandboxStartRequest & {
1536
+ key: string;
1537
+ orgId: string;
1538
+ hintAtMs: number;
1539
+ },
1540
+ ): Promise<EarlyModalSandboxEntry> {
1541
+ const { key, orgId, hintAtMs } = input;
1542
+ const modalConfig = await loadModalRequiredConfig({
1543
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1544
+ limits: null,
1545
+ });
1546
+ const resources = modalSandboxResourcesForPlay(modalConfig.limits);
1547
+ const memoryPolicy = resolveModalSandboxMemoryPolicy({
1548
+ limits: modalConfig.limits,
1549
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1550
+ });
1551
+ const app = await modalLaunchLookup({
1552
+ client: modalConfig.client,
1553
+ key: `app:${modalConfig.appName}`,
1554
+ enabled: true,
1555
+ load: () =>
1556
+ modalConfig.client.apps.fromName(modalConfig.appName, {
1557
+ createIfMissing: true,
1892
1558
  }),
1893
- explicitImage: modalConfig.imageExplicit === true,
1894
- defaultImage: () =>
1895
- modalConfig.client.images.fromRegistry(modalConfig.image),
1896
- lookupPublished: (ref) => modalConfig.client.images.fromName(ref),
1897
- });
1898
- const baseImage = runnerImage.image;
1899
- const image = isModalPreviewEvaluation({
1900
- runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1901
- })
1902
- ? await modalLaunchLookup({
1903
- client: modalConfig.client,
1904
- key: `preview-python-image:${app.appId}:${runnerImage.ref ?? modalConfig.image}`,
1905
- enabled: true,
1906
- load: () =>
1907
- withModalCallSignal(
1908
- AbortSignal.timeout(MODAL_SANDBOX_CREATE_TIMEOUT_MS),
1909
- () =>
1910
- baseImage
1911
- .dockerfileCommands([
1912
- 'RUN apt-get update && apt-get install -y --no-install-recommends python3 python-is-python3 && rm -rf /var/lib/apt/lists/*',
1913
- ])
1914
- .build(app),
1915
- ),
1916
- })
1917
- : baseImage;
1918
- const cpu = modalSupervisorLaunch().cpu || resources.physicalCpuCores;
1919
- const timeoutMs = modalSandboxLifetimeMs(modalConfig.limits);
1920
- const createRequestedAtMs = Date.now();
1921
- const earlyParams = {
1559
+ });
1560
+ const runnerImage = await resolveModalRunnerImage({
1561
+ client: modalConfig.client,
1562
+ configuredHash: await bakedRunnerLookupHash({
1563
+ bundle: buildPlayRunnerBundle,
1564
+ }),
1565
+ explicitImage: modalConfig.imageExplicit === true,
1566
+ defaultImage: () =>
1567
+ modalConfig.client.images.fromRegistry(modalConfig.image),
1568
+ lookupPublished: (ref) => modalConfig.client.images.fromName(ref),
1569
+ });
1570
+ const baseImage = runnerImage.image;
1571
+ const image = isModalPreviewEvaluation({
1572
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1573
+ })
1574
+ ? await modalLaunchLookup({
1575
+ client: modalConfig.client,
1576
+ key: `preview-python-image:${app.appId}:${runnerImage.ref ?? modalConfig.image}`,
1577
+ enabled: true,
1578
+ load: () =>
1579
+ withModalCallSignal(
1580
+ AbortSignal.timeout(MODAL_SANDBOX_CREATE_TIMEOUT_MS),
1581
+ () =>
1582
+ baseImage
1583
+ .dockerfileCommands([
1584
+ 'RUN apt-get update && apt-get install -y --no-install-recommends python3 python-is-python3 && rm -rf /var/lib/apt/lists/*',
1585
+ ])
1586
+ .build(app),
1587
+ ),
1588
+ })
1589
+ : 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,
1601
+ workdir: modalConfig.workdir,
1602
+ memoryMiB: memoryPolicy.reservationMemoryMiB,
1603
+ memoryLimitMiB: memoryPolicy.memoryLimitMiB,
1604
+ outboundCidrAllowlist: [],
1605
+ regions:
1606
+ modalSupervisorLaunch().regions ?? MODAL_SUPERVISOR_DEFAULT_REGIONS,
1607
+ };
1608
+ // PB: the pre-boot claim rides on the create tags, so no other process
1609
+ // can see this sandbox without it.
1610
+ const preboot =
1611
+ runnerImage.baked &&
1612
+ resolveExperimentSwitch(
1613
+ 'PB',
1614
+ input.experimentSwitchOverrides,
1615
+ PREBOOT_RUNNER_IN_EARLY_SANDBOX,
1616
+ );
1617
+ const earlyTags = earlySandboxCreateTags({
1618
+ key,
1619
+ orgId,
1620
+ workflowId: input.workflowId,
1621
+ createRequestedAtMs,
1622
+ limitsKey: earlySandboxLimitsKey({
1922
1623
  cpu,
1923
- cpuLimit: cpu,
1624
+ memoryMiB: earlyParams.memoryMiB,
1924
1625
  timeoutMs,
1925
- // Orphan guard: an unadopted early sandbox runs no command and
1926
- // terminates after this idle window (PB runs one; the exact-id reaper
1927
- // ends that sandbox, see PREBOOT_RUNNER_IN_EARLY_SANDBOX).
1928
- idleTimeoutMs: EARLY_MODAL_SANDBOX_IDLE_TIMEOUT_MS,
1929
- workdir: modalConfig.workdir,
1930
- memoryMiB: memoryPolicy.reservationMemoryMiB,
1931
- memoryLimitMiB: memoryPolicy.memoryLimitMiB,
1932
- outboundCidrAllowlist: [],
1933
- regions:
1934
- modalSupervisorLaunch().regions ?? MODAL_SUPERVISOR_DEFAULT_REGIONS,
1935
- };
1936
- // PB: the pre-boot claim rides on the create tags, so no other process
1937
- // can see this sandbox without it.
1938
- const preboot =
1939
- runnerImage.baked &&
1940
- resolveExperimentSwitch(
1941
- 'PB',
1942
- input.experimentSwitchOverrides,
1943
- PREBOOT_RUNNER_IN_EARLY_SANDBOX,
1944
- );
1945
- const earlyTags = {
1946
- source: EARLY_MODAL_SANDBOX_SOURCE_TAG,
1947
- earlyKey: key,
1948
- // Identity, checked at adoption against the launching run.
1949
- orgId,
1950
- workflowId: input.workflowId,
1951
- [EARLY_CREATED_AT_TAG]: String(createRequestedAtMs),
1952
- limitsKey: earlyModalLimitsKey({
1953
- cpu,
1954
- memoryMiB: earlyParams.memoryMiB,
1955
- timeoutMs,
1956
- }),
1957
- ...(preboot ? { [EARLY_PREBOOT_TAG]: '1' } : {}),
1958
- };
1959
- const createEarly = () =>
1960
- modalConfig.client.sandboxes.create(app, image, {
1961
- ...earlyParams,
1962
- tags: earlyTags,
1963
- });
1964
- const awaitEarlyCreate = (create: Promise<ModalSandbox>) =>
1965
- awaitModalSandboxCreate({
1966
- create,
1967
- onLateSuccess: async (late) => {
1968
- try {
1969
- const confirmAttempts = await terminateModalSandboxConfirmed({
1970
- sandbox: late,
1971
- readExitCode: readModalExitCode(modalConfig.client),
1972
- sleep: sleepMs,
1973
- attempts: EARLY_MODAL_SANDBOX_HEDGE_CONFIRM_ATTEMPTS,
1974
- });
1975
- logEarlyModalSandbox('late_create_terminated', {
1976
- key,
1977
- sandboxId: late.sandboxId,
1978
- confirmAttempts,
1979
- });
1980
- } catch (error) {
1981
- // Its early tag (from the create) keeps it in the durable sweep.
1982
- logEarlyModalSandboxReapUnconfirmed({
1983
- event: 'late_create_terminate_unconfirmed',
1984
- key,
1985
- sandboxId: late.sandboxId,
1986
- error,
1987
- });
1988
- }
1989
- },
1990
- onLateFailure: async () => undefined,
1991
- });
1992
- const sandbox = await awaitEarlyCreate(createEarly());
1993
- logEarlyModalSandbox('created', {
1626
+ }),
1627
+ preboot,
1628
+ });
1629
+ const createEarly = () =>
1630
+ modalConfig.client.sandboxes.create(app, image, {
1631
+ ...earlyParams,
1632
+ tags: earlyTags,
1633
+ });
1634
+ const lookups = earlyModalSandboxLookups(modalConfig.client);
1635
+ const awaitEarlyCreate = (create: Promise<ModalSandbox>) =>
1636
+ awaitModalSandboxCreate({
1637
+ create,
1638
+ onLateSuccess: async (late) => {
1639
+ try {
1640
+ const confirmAttempts = await terminateEarlySandboxConfirmed({
1641
+ sandbox: late,
1642
+ readExitCode: readEarlySandboxExitCode(lookups),
1643
+ sleep: sleepMs,
1644
+ attempts: EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS,
1645
+ });
1646
+ logEarlyModalSandbox('late_create_terminated', {
1647
+ key,
1648
+ sandboxId: late.sandboxId,
1649
+ confirmAttempts,
1650
+ });
1651
+ } catch (error) {
1652
+ // Its early tag (from the create) keeps it in the durable sweep.
1653
+ logEarlySandboxReapUnconfirmed({
1654
+ logScope: EARLY_MODAL_LOG_SCOPE,
1655
+ event: 'late_create_terminate_unconfirmed',
1656
+ key,
1657
+ sandboxId: late.sandboxId,
1658
+ error,
1659
+ });
1660
+ }
1661
+ },
1662
+ onLateFailure: async () => undefined,
1663
+ });
1664
+ const sandbox = await awaitEarlyCreate(createEarly());
1665
+ logEarlyModalSandbox('created', {
1666
+ key,
1667
+ workflowId: input.workflowId,
1668
+ sandboxId: sandbox.sandboxId,
1669
+ hintToRequestMs: createRequestedAtMs - hintAtMs,
1670
+ createMs: Date.now() - createRequestedAtMs,
1671
+ });
1672
+ // Arm the early sandbox: exact-id reaper, PB pre-boot, S1 supervisor.
1673
+ const armEarlySandbox = (sandbox: ModalSandbox) => {
1674
+ // Exact-id reaper: if no launch adopted it, terminate it by id.
1675
+ scheduleEarlySandboxReap({
1676
+ calls: lookups,
1994
1677
  key,
1995
- workflowId: input.workflowId,
1996
1678
  sandboxId: sandbox.sandboxId,
1997
- hintToRequestMs: createRequestedAtMs - hintAtMs,
1998
- createMs: Date.now() - createRequestedAtMs,
1999
1679
  });
2000
- // Arm the early sandbox: exact-id reaper, PB pre-boot, S1 supervisor.
2001
- const armEarlySandbox = (sandbox: ModalSandbox) => {
2002
- // Exact-id reaper: if no launch adopted it, terminate it by id.
2003
- scheduleEarlyModalSandboxReap({
2004
- client: modalConfig.client,
2005
- key,
2006
- sandboxId: sandbox.sandboxId,
2007
- });
2008
- if (preboot) {
2009
- earlyModalPreboots.set(
1680
+ if (preboot) {
1681
+ earlyModalPreboots.set(
1682
+ sandbox,
1683
+ startEarlyModalPreboot({
1684
+ key,
2010
1685
  sandbox,
2011
- startEarlyModalPreboot({
1686
+ bakedRunner: modalBakedRunnerExpectation({
1687
+ imageBaked: true,
1688
+ bundlePromise: buildPlayRunnerBundle(),
1689
+ }),
1690
+ workDir: modalConfig.workdir,
1691
+ sandboxRuntimeLimits: modalConfig.limits,
1692
+ ...(memoryPolicy.memoryLimitMiB > memoryPolicy.reservationMemoryMiB
1693
+ ? { memoryLimitMiB: memoryPolicy.memoryLimitMiB }
1694
+ : {}),
1695
+ }),
1696
+ );
1697
+ }
1698
+ const earlySupervisor = resolveExperimentSwitch(
1699
+ 'S1',
1700
+ input.experimentSwitchOverrides,
1701
+ START_SUPERVISOR_WITH_EARLY_SANDBOX,
1702
+ );
1703
+ // PB's claim rode on the create tags, so it is already on the sandbox.
1704
+ if (preboot) earlyModalForeignAdoptionClaims.set(sandbox, Promise.resolve());
1705
+ let tags: Record<string, string> = earlyTags;
1706
+ if (earlySupervisor) {
1707
+ tags = { ...earlyTags, [EARLY_SUPERVISOR_TAG]: '1' };
1708
+ const supervisorStartedAtMs = Date.now();
1709
+ // Tag first (with the plan lookup): a launch in another process sees
1710
+ // the sidecar claim and does not adopt this sandbox.
1711
+ const claimTagged = sandbox.setTags(tags);
1712
+ claimTagged.catch(() => undefined);
1713
+ if (!preboot) earlyModalForeignAdoptionClaims.set(sandbox, claimTagged);
1714
+ const ready = (async () => {
1715
+ const [plan] = await Promise.all([
1716
+ resolveModalSupervisorPlan({
1717
+ client: modalConfig.client,
1718
+ runtimeSchedulerSchema: input.runtimeSchedulerSchema,
1719
+ }),
1720
+ claimTagged,
1721
+ ]);
1722
+ await createModalSupervisorSidecar({
1723
+ sandbox,
1724
+ plan,
1725
+ cancellation: new Promise<never>(() => undefined),
1726
+ });
1727
+ })();
1728
+ ready.then(
1729
+ () =>
1730
+ logEarlyModalSandbox('supervisor_created', {
2012
1731
  key,
2013
- sandbox,
2014
- bakedRunner: modalBakedRunnerExpectation({
2015
- imageBaked: true,
2016
- bundlePromise: buildPlayRunnerBundle(),
2017
- }),
2018
- workDir: modalConfig.workdir,
2019
- sandboxRuntimeLimits: modalConfig.limits,
2020
- ...(memoryPolicy.memoryLimitMiB > memoryPolicy.reservationMemoryMiB
2021
- ? { memoryLimitMiB: memoryPolicy.memoryLimitMiB }
2022
- : {}),
1732
+ sandboxId: sandbox.sandboxId,
1733
+ elapsedMs: Date.now() - supervisorStartedAtMs,
1734
+ }),
1735
+ (error: unknown) =>
1736
+ logEarlyModalSandbox('supervisor_failed', {
1737
+ key,
1738
+ sandboxId: sandbox.sandboxId,
1739
+ error: error instanceof Error ? error.message : String(error),
2023
1740
  }),
2024
- );
2025
- }
2026
- const earlySupervisor = resolveExperimentSwitch(
2027
- 'S1',
2028
- input.experimentSwitchOverrides,
2029
- START_SUPERVISOR_WITH_EARLY_SANDBOX,
2030
1741
  );
2031
- // PB's claim rode on the create tags, so it is already on the sandbox.
2032
- if (preboot)
2033
- earlyModalForeignAdoptionClaims.set(sandbox, Promise.resolve());
2034
- let tags: Record<string, string> = earlyTags;
2035
- if (earlySupervisor) {
2036
- tags = { ...earlyTags, [EARLY_SUPERVISOR_TAG]: '1' };
2037
- const supervisorStartedAtMs = Date.now();
2038
- // Tag first (with the plan lookup): a launch in another process sees
2039
- // the sidecar claim and does not adopt this sandbox.
2040
- const claimTagged = sandbox.setTags(tags);
2041
- claimTagged.catch(() => undefined);
2042
- if (!preboot) earlyModalForeignAdoptionClaims.set(sandbox, claimTagged);
2043
- const ready = (async () => {
2044
- const [plan] = await Promise.all([
2045
- resolveModalSupervisorPlan({
2046
- client: modalConfig.client,
2047
- runtimeSchedulerSchema: input.runtimeSchedulerSchema,
2048
- }),
2049
- claimTagged,
2050
- ]);
2051
- await createModalSupervisorSidecar({
2052
- sandbox,
2053
- plan,
2054
- cancellation: new Promise<never>(() => undefined),
2055
- });
2056
- })();
2057
- ready.then(
2058
- () =>
2059
- logEarlyModalSandbox('supervisor_created', {
2060
- key,
2061
- sandboxId: sandbox.sandboxId,
2062
- elapsedMs: Date.now() - supervisorStartedAtMs,
2063
- }),
2064
- (error: unknown) =>
2065
- logEarlyModalSandbox('supervisor_failed', {
2066
- key,
2067
- sandboxId: sandbox.sandboxId,
2068
- error: error instanceof Error ? error.message : String(error),
2069
- }),
2070
- );
2071
- earlyModalSupervisors.set(sandbox, ready);
2072
- }
2073
- return tags;
2074
- };
2075
- const tags = armEarlySandbox(sandbox);
2076
- return { sandbox, startedAtMs: createRequestedAtMs, tags };
2077
- })().catch((error: unknown) => {
2078
- logEarlyModalSandbox('create_failed', {
2079
- key,
2080
- error: error instanceof Error ? error.message : String(error),
2081
- });
2082
- return null;
2083
- });
2084
- earlyModalSandboxes.put(key, started);
2085
- logEarlyModalSandbox('hint_accepted', { key, workflowId: input.workflowId });
2086
- return true;
1742
+ earlyModalSupervisors.set(sandbox, ready);
1743
+ }
1744
+ return tags;
1745
+ };
1746
+ const tags = armEarlySandbox(sandbox);
1747
+ return { sandbox, startedAtMs: createRequestedAtMs, tags };
2087
1748
  }
2088
1749
 
2089
1750
  /**
2090
- * PB: why an in-process early sandbox with a pre-boot must not be adopted by
2091
- * this launch, or null when it may be (a running pre-boot this launch will
2092
- * deliver to, or one that provably never started).
1751
+ * Modal's early-sandbox Adapter. Early sandboxes start only under the
1752
+ * modal_sidecar profile.
2093
1753
  */
2094
- export function earlyPrebootAdoptionRefusal(input: {
2095
- preboot: EarlyModalPreboot;
2096
- wanted: boolean;
2097
- sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
2098
- memoryLimitMiB?: number;
2099
- nowMs: number;
2100
- }): string | null {
2101
- const { preboot } = input;
2102
- if (preboot.status === 'not_started') return null;
2103
- if (preboot.status === 'ambiguous') return 'preboot_ambiguous';
2104
- // A running runner nobody will deliver to would share the sandbox with
2105
- // today's launch.
2106
- if (!input.wanted) return 'preboot_unwanted';
2107
- if (preboot.exitCode !== null) return 'preboot_exited';
2108
- if (input.nowMs - preboot.startedAtMs > EARLY_PREBOOT_MAX_ADOPTION_AGE_MS)
2109
- return 'preboot_stale';
2110
- if (
2111
- !samePlaySandboxRuntimeLimits(
2112
- preboot.runner.sandboxRuntimeLimits,
2113
- input.sandboxRuntimeLimits,
2114
- ) ||
2115
- preboot.runner.memoryLimitMiB !== input.memoryLimitMiB
2116
- )
2117
- return 'preboot_limits_mismatch';
2118
- return null;
2119
- }
1754
+ export const modalEarlySandboxAdapter: EarlySandboxAdapter<ModalSandbox> = {
1755
+ provider: 'modal',
1756
+ logScope: EARLY_MODAL_LOG_SCOPE,
1757
+ registry: earlyModalSandboxes,
1758
+ startUnavailable: () =>
1759
+ DURABLE_RUNS_ROLLOUT.modalSupervisorSidecar ? null : 'sidecar_profile_off',
1760
+ createEarly: createEarlyModalSandbox,
1761
+ sweepOrphansForWorker: sweepOrphanEarlyModalSandboxesForWorker,
1762
+ };
1763
+
2120
1764
 
2121
1765
  /**
2122
- * Adopt this run's early sandbox by exact id, or return null so the launch
2123
- * creates its own. The in-process promise is awaited when this worker started
2124
- * it; otherwise one tag listing finds a sandbox another worker started. The
2125
- * key is org-scoped, and every path checks the sandbox's org and workflow
2126
- * tags against this run before re-tagging it; a mismatch is refused loudly.
1766
+ * Adopt this run's early Modal sandbox by exact id, or return null so the
1767
+ * launch creates its own (see adoptEarlySandbox). A sandbox whose S1 sidecar
1768
+ * another process started is refused, like a foreign pre-boot.
2127
1769
  */
2128
1770
  export async function adoptEarlyModalSandbox(input: {
2129
1771
  client: ModalClient;
@@ -2142,185 +1784,27 @@ export async function adoptEarlyModalSandbox(input: {
2142
1784
  registry?: EarlyModalSandboxRegistry;
2143
1785
  nowMs?: () => number;
2144
1786
  }): Promise<ModalSandbox | null> {
2145
- const nowMs = input.nowMs ?? Date.now;
2146
- const startedAt = nowMs();
2147
- const orgId = input.context.orgId?.trim();
2148
- if (!orgId) {
2149
- emitModalStage(input.context, 'early:adopt_miss', {
2150
- reason: 'no_org',
2151
- elapsedMs: 0,
2152
- });
2153
- return null;
2154
- }
2155
- const key = earlyModalSandboxKey({ orgId, workflowId: input.workflowId });
2156
- const registry = input.registry ?? earlyModalSandboxes;
2157
- let sandbox: ModalSandbox | null = null;
2158
- let localEntry: EarlyModalSandboxEntry | null = null;
2159
- let how = 'none';
2160
- try {
2161
- // Taken, not read: this entry is handed to this one adoption only.
2162
- const local = registry.take(key);
2163
- if (local) {
2164
- localEntry = await local;
2165
- sandbox = localEntry?.sandbox ?? null;
2166
- how = 'in_process';
2167
- }
2168
- if (!sandbox) {
2169
- for await (const listed of input.client.sandboxes.list({
2170
- appId: input.modalAppId,
2171
- tags: { source: EARLY_MODAL_SANDBOX_SOURCE_TAG, earlyKey: key },
2172
- })) {
2173
- sandbox = await input.client.sandboxes.fromId(listed.sandboxId);
2174
- how = 'by_tag';
2175
- break;
2176
- }
2177
- }
2178
- if (!sandbox) {
2179
- emitModalStage(input.context, 'early:adopt_miss', {
2180
- key,
2181
- reason: 'not_found',
2182
- elapsedMs: nowMs() - startedAt,
2183
- });
2184
- return null;
2185
- }
2186
- // A1 may skip the read only for this process's own, fresh, untaken entry
2187
- // whose foreign-adoption claim is confirmed on the sandbox: then no other
2188
- // process can have adopted (re-tagged) it. Everything else is read back.
2189
- const foreignClaim =
2190
- how === 'in_process'
2191
- ? earlyModalForeignAdoptionClaims.get(sandbox)
2192
- : undefined;
2193
- const trustLocalTags =
2194
- how === 'in_process' &&
2195
- localEntry !== null &&
2196
- nowMs() - localEntry.startedAtMs <
2197
- EARLY_MODAL_SANDBOX_MAX_ADOPTION_AGE_MS &&
2198
- resolveExperimentSwitch(
2199
- 'A1',
2200
- input.context.experimentSwitchOverrides,
2201
- ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ,
2202
- ) &&
2203
- foreignClaim !== undefined &&
2204
- (await foreignClaim.then(
2205
- () => true,
2206
- () => false,
2207
- ));
2208
- const tags =
2209
- trustLocalTags && localEntry ? localEntry.tags : await sandbox.getTags();
2210
- const identityRefusal = earlyModalSandboxIdentityRefusal(tags, {
2211
- key,
2212
- orgId,
2213
- workflowId: input.workflowId,
2214
- });
2215
- if (identityRefusal) {
2216
- // Never expected: the key already names this org and workflow. Loud,
2217
- // and the sandbox is left untouched for its own reaper.
2218
- console.error(
2219
- JSON.stringify({
2220
- event: 'play-runner.modal.early.adopt_refused_identity',
2221
- reason: identityRefusal,
2222
- key,
2223
- how,
2224
- sandboxId: sandbox.sandboxId,
2225
- runId: input.context.runId ?? null,
2226
- }),
2227
- );
2228
- emitModalStage(input.context, 'early:adopt_miss', {
2229
- key,
2230
- reason: identityRefusal,
2231
- sandboxId: sandbox.sandboxId,
2232
- elapsedMs: nowMs() - startedAt,
2233
- });
2234
- return null;
2235
- }
2236
- const ageMs =
2237
- how === 'in_process' && localEntry
2238
- ? nowMs() - localEntry.startedAtMs
2239
- : earlyModalSandboxAgeMs(tags, nowMs());
2240
- if (ageMs === null || ageMs >= EARLY_MODAL_SANDBOX_MAX_ADOPTION_AGE_MS) {
2241
- // Past the adoption window the reapers own it.
2242
- emitModalStage(input.context, 'early:adopt_miss', {
2243
- key,
2244
- reason: 'early_stale',
2245
- sandboxId: sandbox.sandboxId,
2246
- ageMs,
2247
- elapsedMs: nowMs() - startedAt,
2248
- });
2249
- return null;
2250
- }
2251
- if (how !== 'in_process' && tags[EARLY_SUPERVISOR_TAG]) {
2252
- // S1: another process started this sandbox's supervisor; a second
2253
- // sidecar create here would collide. Create an ordinary sandbox.
2254
- emitModalStage(input.context, 'early:adopt_miss', {
2255
- key,
2256
- reason: 'early_supervisor_foreign',
2257
- sandboxId: sandbox.sandboxId,
2258
- elapsedMs: nowMs() - startedAt,
2259
- });
2260
- return null;
2261
- }
2262
- if (how !== 'in_process' && tags[EARLY_PREBOOT_TAG]) {
2263
- // PB: another process started a runner here and holds its delivery
2264
- // plan; nothing may be delivered to it from this process.
2265
- emitModalStage(input.context, 'early:adopt_miss', {
2266
- key,
2267
- reason: 'early_preboot_foreign',
2268
- sandboxId: sandbox.sandboxId,
2269
- elapsedMs: nowMs() - startedAt,
2270
- });
2271
- return null;
2272
- }
2273
- const prebootPending =
2274
- how === 'in_process' ? earlyModalPreboots.get(sandbox) : undefined;
2275
- const prebootRefusal = prebootPending
2276
- ? earlyPrebootAdoptionRefusal({
2277
- preboot: await prebootPending,
2278
- ...input.preboot,
2279
- nowMs: Date.now(),
2280
- })
2281
- : null;
2282
- if (prebootRefusal) {
2283
- emitModalStage(input.context, 'early:adopt_miss', {
2284
- key,
2285
- reason: prebootRefusal,
2286
- sandboxId: sandbox.sandboxId,
2287
- elapsedMs: nowMs() - startedAt,
2288
- });
2289
- return null;
2290
- }
2291
- if (
2292
- tags.source !== EARLY_MODAL_SANDBOX_SOURCE_TAG ||
2293
- tags.earlyKey !== key ||
2294
- tags.limitsKey !== input.expectedLimitsKey ||
2295
- (await sandbox.poll()) !== null
2296
- ) {
2297
- emitModalStage(input.context, 'early:adopt_miss', {
2298
- key,
2299
- reason: 'mismatch_or_exited',
2300
- sandboxId: sandbox.sandboxId,
2301
- elapsedMs: nowMs() - startedAt,
2302
- });
2303
- return null;
2304
- }
2305
- // Re-tag first: from here the sandbox is an ordinary launch sandbox for
2306
- // every cleanup and reconciliation path, and the reaper skips it.
2307
- await sandbox.setTags({ ...input.createTags, earlyKey: key });
2308
- emitModalStage(input.context, 'early:adopted', {
2309
- key,
2310
- how,
2311
- sandboxId: sandbox.sandboxId,
2312
- elapsedMs: nowMs() - startedAt,
2313
- });
2314
- return sandbox;
2315
- } catch (error) {
2316
- emitModalStage(input.context, 'early:adopt_miss', {
2317
- key,
2318
- reason: 'error',
2319
- error: error instanceof Error ? error.message : String(error),
2320
- elapsedMs: nowMs() - startedAt,
2321
- });
2322
- return null;
2323
- }
1787
+ return await adoptEarlySandbox({
1788
+ calls: earlyModalSandboxCalls(input),
1789
+ registry: input.registry ?? earlyModalSandboxes,
1790
+ workflowId: input.workflowId,
1791
+ orgId: input.context.orgId,
1792
+ runId: input.context.runId,
1793
+ experimentSwitchOverrides: input.context.experimentSwitchOverrides,
1794
+ expectedLimitsKey: input.expectedLimitsKey,
1795
+ createTags: input.createTags,
1796
+ preboot: input.preboot,
1797
+ // S1: another process started this sandbox's supervisor; a second
1798
+ // sidecar create here would collide. Create an ordinary sandbox.
1799
+ foreignClaimTags: [
1800
+ { tag: EARLY_SUPERVISOR_TAG, reason: 'early_supervisor_foreign' },
1801
+ ],
1802
+ inProcessPreboot: (sandbox) => earlyModalPreboots.get(sandbox),
1803
+ inProcessForeignAdoptionClaim: (sandbox) =>
1804
+ earlyModalForeignAdoptionClaims.get(sandbox),
1805
+ emitStage: (stage, extra) => emitModalStage(input.context, stage, extra),
1806
+ ...(input.nowMs === undefined ? {} : { nowMs: input.nowMs }),
1807
+ });
2324
1808
  }
2325
1809
 
2326
1810
  export const modalPlayRunnerBackend: PlayRunnerBackend = {
@@ -2600,7 +2084,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2600
2084
  resolveExperimentSwitch(
2601
2085
  'E2',
2602
2086
  config.context.experimentSwitchOverrides,
2603
- EARLY_MODAL_SANDBOX_START,
2087
+ EARLY_SANDBOX_START,
2604
2088
  ) &&
2605
2089
  supervisorPlan &&
2606
2090
  config.context.workflowId
@@ -2608,7 +2092,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
2608
2092
  client: modalConfig.client,
2609
2093
  modalAppId: app.appId,
2610
2094
  workflowId: config.context.workflowId,
2611
- expectedLimitsKey: earlyModalLimitsKey({
2095
+ expectedLimitsKey: earlySandboxLimitsKey({
2612
2096
  cpu: createParams.cpu,
2613
2097
  memoryMiB: createParams.memoryMiB,
2614
2098
  timeoutMs: createParams.timeoutMs,