deepline 0.3.541 → 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 +17 -1
  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-WJXA7XGM.mjs → auth-ITAELTOA.mjs} +5 -5
  67. package/dist/cli/auth-S6B5WUU5.js +43 -0
  68. package/dist/cli/{billing-34IV5DSV.js → billing-33XVFDUJ.js} +101 -101
  69. package/dist/cli/{billing-SHS4HMWT.mjs → billing-WZ7RVZW4.mjs} +12 -12
  70. package/dist/cli/{chunk-UKO6POLZ.js → chunk-23D224GI.js} +37 -17
  71. package/dist/cli/{chunk-DF7ARQRB.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-FVZ5Y5L6.js → chunk-2KTGZKRE.js} +18 -18
  75. package/dist/cli/{chunk-6TZEDCN7.js → chunk-2LNTKICO.js} +3 -3
  76. package/dist/cli/{chunk-FYQWTENQ.js → chunk-2NCJQEZH.js} +53 -53
  77. package/dist/cli/{chunk-CNBPATLI.js → chunk-3JZXU5OB.js} +5 -5
  78. package/dist/cli/{chunk-323I5KQ5.js → chunk-46BEBZ3M.js} +497 -328
  79. package/dist/cli/{chunk-V4EYJKGJ.js → chunk-4JQEAYN3.js} +156 -17
  80. package/dist/cli/{chunk-XO2SGONT.mjs → chunk-4SKDSSPU.mjs} +2 -2
  81. package/dist/cli/{chunk-53QZ24DP.mjs → chunk-52YK3EII.mjs} +2 -2
  82. package/dist/cli/{chunk-S7NKIEHL.js → chunk-5MN3BKNB.js} +16 -16
  83. package/dist/cli/{chunk-XTR32PMA.mjs → chunk-5VIPTLRX.mjs} +1 -1
  84. package/dist/cli/{chunk-OLH2PHMC.mjs → chunk-6P7TGCHQ.mjs} +1 -1
  85. package/dist/cli/{chunk-QI76LGE3.mjs → chunk-6SJZMMD5.mjs} +37 -190
  86. package/dist/cli/chunk-7AUQTNLB.mjs +455 -0
  87. package/dist/cli/{chunk-GLINYHY7.mjs → chunk-AACKPOGA.mjs} +1 -1
  88. package/dist/cli/{chunk-Q66ADD4O.js → chunk-BGAUADV4.js} +41 -41
  89. package/dist/cli/{chunk-KQSTV4MW.js → chunk-BLYW6FFB.js} +60 -18
  90. package/dist/cli/{chunk-F3TLGM2U.js → chunk-C35NLLSA.js} +5 -5
  91. package/dist/cli/{chunk-LRPFCB2P.mjs → chunk-D6YAU3CF.mjs} +182 -13
  92. package/dist/cli/{chunk-FRPJSFNL.mjs → chunk-DH43ECTN.mjs} +7 -3
  93. package/dist/cli/{chunk-IZXMX65M.js → chunk-DI3GL3T6.js} +316 -469
  94. package/dist/cli/{chunk-OK4JMVTM.js → chunk-DUGTPVT7.js} +7 -7
  95. package/dist/cli/{chunk-UNDLNT3V.js → chunk-ECWOIXAV.js} +1 -1
  96. package/dist/cli/{chunk-KIYETQ6K.js → chunk-EHUG6EUT.js} +26 -26
  97. package/dist/cli/chunk-F6VSQ5LN.js +455 -0
  98. package/dist/cli/{chunk-JZNKEHXQ.mjs → chunk-FNW2SGPD.mjs} +2 -2
  99. package/dist/cli/{chunk-M6XIKHBS.js → chunk-GRCFX2EG.js} +4 -4
  100. package/dist/cli/{chunk-OVX3Q5Q3.mjs → chunk-GWNYLIF7.mjs} +1 -1
  101. package/dist/cli/{chunk-FTKX7OGB.mjs → chunk-HKJ26NRN.mjs} +5 -5
  102. package/dist/cli/{chunk-L2VKAASU.mjs → chunk-HXIR3VQL.mjs} +21 -0
  103. package/dist/cli/{chunk-POZPEDW7.js → chunk-J2F6F5GL.js} +7 -7
  104. package/dist/cli/{chunk-7AUQSK24.mjs → chunk-JXG7HWBA.mjs} +1 -1
  105. package/dist/cli/{chunk-Z2XA6YU4.mjs → chunk-LX35AXTN.mjs} +1 -0
  106. package/dist/cli/{chunk-WIV3E6Y7.js → chunk-MCBUWK5K.js} +22 -22
  107. package/dist/cli/{chunk-2TAGAPLL.js → chunk-NHKP2NSU.js} +2 -2
  108. package/dist/cli/{chunk-FANIRW74.mjs → chunk-NIPLY25A.mjs} +0 -2
  109. package/dist/cli/{chunk-UXXFCOE3.js → chunk-NLENABRU.js} +6 -6
  110. package/dist/cli/{chunk-DHC7EGI7.mjs → chunk-NR3O56FT.mjs} +5 -5
  111. package/dist/cli/{chunk-MPYM6TUO.js → chunk-O2KLWUNI.js} +44 -44
  112. package/dist/cli/{chunk-BMNLD63A.mjs → chunk-OAFKUHN5.mjs} +4 -4
  113. package/dist/cli/{chunk-RYYGNUNO.mjs → chunk-OELJKQOL.mjs} +24 -4
  114. package/dist/cli/{chunk-ZD673XAL.js → chunk-PX7XAVUC.js} +24 -20
  115. package/dist/cli/{chunk-FOCNY4GV.js → chunk-QFRMVI4S.js} +3 -3
  116. package/dist/cli/{chunk-AU7ZKXW5.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-BUCTWJBM.js → chunk-STXG2LFC.js} +2 -2
  120. package/dist/cli/{chunk-ECPCZVDM.mjs → chunk-SU4K4SUU.mjs} +1 -1
  121. package/dist/cli/{chunk-ABDXKELH.mjs → chunk-SYOPHFKB.mjs} +6 -6
  122. package/dist/cli/{chunk-H74CLEMB.mjs → chunk-SZNJENGT.mjs} +3 -3
  123. package/dist/cli/{chunk-5N4ENMYE.js → chunk-TBCNL2T5.js} +1 -1
  124. package/dist/cli/{chunk-E4CABWXL.js → chunk-TI6DTURF.js} +22 -1
  125. package/dist/cli/{chunk-C2LYJ3EX.js → chunk-UJ6GOV7K.js} +13 -13
  126. package/dist/cli/{chunk-GWHA4DAC.js → chunk-UV4RU2TE.js} +0 -2
  127. package/dist/cli/{chunk-6PJAC3P5.mjs → chunk-VSJEOSYL.mjs} +1 -1
  128. package/dist/cli/{chunk-NB4AIXEA.mjs → chunk-W2OPPSAZ.mjs} +3 -3
  129. package/dist/cli/{chunk-5LNWLEO3.mjs → chunk-XBM3KABD.mjs} +3 -3
  130. package/dist/cli/{chunk-VMIIUMAN.mjs → chunk-XFPVFWZR.mjs} +1 -1
  131. package/dist/cli/{chunk-UC5QFQGC.mjs → chunk-XSN6BAZT.mjs} +5 -5
  132. package/dist/cli/{chunk-IDDKNMFX.mjs → chunk-Y3T5GWYK.mjs} +153 -14
  133. package/dist/cli/{chunk-S6FF7Q5P.js → chunk-YE3T73BV.js} +10 -10
  134. package/dist/cli/{chunk-CY5LW6DW.js → chunk-YJYKZ2U3.js} +2 -2
  135. package/dist/cli/{chunk-F6QV42MC.mjs → chunk-Z7SXGOIQ.mjs} +1 -1
  136. package/dist/cli/{chunk-ZL2DER5D.mjs → chunk-ZRT2PNYY.mjs} +1 -1
  137. package/dist/cli/{chunk-WZMG2M65.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-ZJ77SAEU.mjs → concurrent-runs-help-Z6ODNL4E.mjs} +7 -7
  142. package/dist/cli/{csv-PX7F5YJN.mjs → csv-5QW2HPHT.mjs} +4 -4
  143. package/dist/cli/{csv-MJLIZZOR.js → csv-SSOFTXHU.js} +13 -13
  144. package/dist/cli/{db-BNCNAY4G.js → db-4LK5AJNO.js} +29 -29
  145. package/dist/cli/{db-KPKGTHPA.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-YNOFR7T2.js → executions-AATJQQAQ.js} +10 -10
  153. package/dist/cli/{executions-NMQY4GEY.mjs → executions-FY2XTX2W.mjs} +8 -8
  154. package/dist/cli/{feedback-LWYEO5LL.mjs → feedback-MKBPRGS6.mjs} +6 -6
  155. package/dist/cli/{feedback-RCP5DPO6.js → feedback-QPVJER75.js} +14 -14
  156. package/dist/cli/{git-3O4PFP3Q.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-KFP674JT.mjs → legacy-noops-DVL2RRKL.mjs} +6 -6
  163. package/dist/cli/{legacy-noops-ZPZRG366.js → legacy-noops-H7INM2QN.js} +9 -9
  164. package/dist/cli/{mcp-OCYUXQ6L.mjs → mcp-2Z2YVOLK.mjs} +72 -15
  165. package/dist/cli/{mcp-HCXDW6PL.js → mcp-33F7D7WI.js} +89 -32
  166. package/dist/cli/{monitors-7Q7YT22Y.js → monitors-KDUJHAKJ.js} +102 -102
  167. package/dist/cli/{monitors-V5KJIJJE.mjs → monitors-NZD2WIKK.mjs} +9 -9
  168. package/dist/cli/{org-S37K6QYH.js → org-4PQGHLEB.js} +164 -88
  169. package/dist/cli/{org-C3QLHX7U.mjs → org-EJW45RUA.mjs} +84 -8
  170. package/dist/cli/{play-MXQ2DKML.mjs → play-3CM5RT5J.mjs} +44 -25
  171. package/dist/cli/{play-MLREAYHJ.js → play-MLHMQL4G.js} +374 -355
  172. package/dist/cli/{providers-FDJ4ZOST.mjs → providers-BHYBJI4R.mjs} +10 -9
  173. package/dist/cli/{providers-PPDWY7DH.js → providers-YBJG7277.js} +13 -12
  174. package/dist/cli/{quickstart-2Z57AMB7.mjs → quickstart-LL3MR562.mjs} +4 -4
  175. package/dist/cli/{quickstart-BOWQM7S7.js → quickstart-O7L2NNGJ.js} +6 -6
  176. package/dist/cli/{run-66HXNJNV.js → run-HJ2AR6CM.js} +49 -48
  177. package/dist/cli/{run-5RNJGPQ2.mjs → run-OK545H5Q.mjs} +28 -27
  178. package/dist/cli/search-UUNS6BCC.js +32 -0
  179. package/dist/cli/{search-7G4FYQYO.mjs → search-Z5ZKMRTX.mjs} +9 -9
  180. package/dist/cli/{search-output-6K4FHCVI.mjs → search-output-Q5VHNUWG.mjs} +4 -4
  181. package/dist/cli/{search-output-L6ICQDBL.js → search-output-SVW4DETG.js} +6 -6
  182. package/dist/cli/{secrets-PWFJKF7G.js → secrets-ENQWMCB5.js} +17 -17
  183. package/dist/cli/{secrets-FTQPCU7O.mjs → secrets-QIKIEFWB.mjs} +8 -8
  184. package/dist/cli/{sessions-YSSAAQVJ.mjs → sessions-AETO22RF.mjs} +6 -6
  185. package/dist/cli/sessions-FNSUDERA.js +22 -0
  186. package/dist/cli/{settings-KN7GNZ5J.mjs → settings-G5RGRPFV.mjs} +16 -16
  187. package/dist/cli/{settings-CZEMF2WD.js → settings-OFLIFTMZ.js} +89 -89
  188. package/dist/cli/{setup-5WLHGH57.mjs → setup-G4N3X6KG.mjs} +9 -9
  189. package/dist/cli/{setup-RW4X6DX4.js → setup-QW7Y62XD.js} +49 -49
  190. package/dist/cli/skills-3IXIY2IV.js +36 -0
  191. package/dist/cli/{skills-DLVI7IZK.mjs → skills-QRFQGHNA.mjs} +7 -7
  192. package/dist/cli/{tools-JVYQF7P3.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-XKLXU7YS.mjs → update-SDGZLAGL.mjs} +9 -9
  196. package/dist/cli/{views-QRRCWP6B.mjs → views-3BIJFJMQ.mjs} +8 -8
  197. package/dist/cli/{views-YNUYFS3S.js → views-5QKAWYPI.js} +23 -23
  198. package/dist/cli/{workflow-YUKADKCJ.js → workflow-G67RPWVY.js} +19 -19
  199. package/dist/cli/{workflow-KYFMA4LM.mjs → workflow-QAK773FR.mjs} +9 -9
  200. package/dist/{client-B1fixtK1.d.ts → client-D1ga52xq.d.ts} +1 -1
  201. package/dist/{client-CE4QBVbp.d.mts → client-bd4QQIXo.d.mts} +1 -1
  202. package/dist/{client-core-C-3FVlVq.d.ts → client-core-B6eMVx8h.d.ts} +335 -4
  203. package/dist/{client-core-2BkNBgrx.d.mts → client-core-CqfWNf2Q.d.mts} +335 -4
  204. package/dist/{compiler-manifest-Cys06iYg.d.ts → compiler-manifest-BWFtsQIC.d.mts} +21 -0
  205. package/dist/{compiler-manifest-Cys06iYg.d.mts → 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-V76O674K.js +0 -43
  235. package/dist/cli/concurrent-runs-help-MFEPUP6Y.js +0 -21
  236. package/dist/cli/describe-5OUJA5TH.mjs +0 -49
  237. package/dist/cli/describe-7MF5AHIU.js +0 -49
  238. package/dist/cli/git-WLQ3BS6K.js +0 -25
  239. package/dist/cli/search-LTUIIV6W.js +0 -32
  240. package/dist/cli/sessions-2IVFGTPA.js +0 -22
  241. package/dist/cli/skills-WT42AZVH.js +0 -36
  242. package/dist/cli/tools-D6STYBQG.js +0 -56
  243. package/dist/cli/update-XTUKBC3J.js +0 -34
@@ -0,0 +1,862 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type { PlaySandboxRuntimeLimits } from '../../plays/sandbox-runtime-limits';
3
+ import {
4
+ resolveExperimentSwitch,
5
+ type ExperimentSwitchOverrides,
6
+ } from '../experiment-switches';
7
+ import type {
8
+ RuntimeSandboxProviderCapability,
9
+ RuntimeSandboxProviderId,
10
+ } from '../runtime-sandbox-provider-profile';
11
+ import { samePlaySandboxRuntimeLimits } from './backends/daytona-payload-transport';
12
+
13
+ /**
14
+ * Early sandbox: the provider-neutral Module behind early start (E2), runner
15
+ * pre-boot (PB) and in-process adoption (A1). It owns the per-process
16
+ * registry, the org-scoped key and identity refusal, the adoption-age rules,
17
+ * the exact-id reaper and the durable orphan sweep. A provider plugs in
18
+ * through an `EarlySandboxAdapter`: the create call, tag reads and writes,
19
+ * termination, a tag listing, and its pre-boot hooks. Claim affinity (CA/CAR)
20
+ * follows an early sandbox; its claim contract is
21
+ * `scheduler-backends/early-sandbox-claim-affinity.ts`.
22
+ *
23
+ * Which providers support each capability is declared in the Runtime Sandbox
24
+ * Provider Profile (`earlyStart`, `preboot`, `claimAffinity`). A lane whose
25
+ * providers lack one fails loudly: at worker boot for a static switch, and at
26
+ * adapter selection for a per-run one (`scheduler-backends/early-sandbox-lane.ts`).
27
+ *
28
+ * Pure: no provider SDK, scheduler or app imports.
29
+ */
30
+
31
+ /**
32
+ * Preview experiment E2: start the run's sandbox right after its admission
33
+ * authenticated and funded it, before the run is enqueued, claimed and
34
+ * launched. The early sandbox carries no token, no payload and no
35
+ * supervisor: only the image, the standard resource profile and a
36
+ * deterministic per-run tag. The launching worker adopts it by exact sandbox
37
+ * id (tag lookup, then re-tag with the ordinary create tags so every cleanup
38
+ * and reconciliation path sees an ordinary sandbox) and then launches as
39
+ * today; otherwise it creates its own. Orphans: a short provider idle
40
+ * timeout, plus an exact-id reaper that terminates the early sandbox if it is
41
+ * still unadopted after the reap delay, plus the durable sweep. Off.
42
+ */
43
+ export const EARLY_SANDBOX_START = false;
44
+
45
+ /**
46
+ * A1 (off): adopting an early sandbox this process created checks the tags
47
+ * this process set instead of reading them back from the provider (one RPC
48
+ * fewer on the launch path, ~20 ms). Only for a fresh entry this process
49
+ * created and has not handed out (the registry's `take`), whose
50
+ * foreign-adoption claim is confirmed on the sandbox; every other adoption
51
+ * reads the tags back. The exit-code read, the identity check and the re-tag
52
+ * are unchanged. Per-run capable (experiment switch A1).
53
+ */
54
+ export const ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ = false;
55
+
56
+ /**
57
+ * PB (off): with E2 and the baked runner image, the early sandbox also starts
58
+ * the baked runner right after its create, before the run is adopted, so
59
+ * shell start, watchdog setup and runner bundle evaluation (~200-380 ms) are
60
+ * off the launch path. One exec runs, in order: the baked-runner verify guard
61
+ * (verdict line first; a non-ok verdict exits 98 before anything else), the
62
+ * runtime watchdog starting the runner as `--wait-config <configPath>`, and
63
+ * the crash-terminal epilogue, all at fixed per-sandbox paths. It holds no
64
+ * credentials or customer data: no envelope, config or token exists in the
65
+ * sandbox until the run is adopted. The watchdog's runtime/memory limits and
66
+ * the runner's V8 flags are fixed at pre-boot from the early sandbox's own
67
+ * (standard) profile, the same one its `limitsKey` encodes; adoption refuses a
68
+ * run whose limits differ, and staging asserts it again.
69
+ *
70
+ * Adoption (in this process only) delivers the envelope in one exec: stdin to
71
+ * a file (same guard as the inline launch), then the run's files, config LAST
72
+ * via rename; the waiting runner picks it up and proceeds exactly as today
73
+ * (heartbeat, readiness, park fence). Readiness is confirmed as today, and
74
+ * also fails fast (deferred to a new attempt) if the delivery exec fails or
75
+ * the pre-boot chain exits first.
76
+ *
77
+ * Not adopted (an ordinary sandbox is created and this one is reaped): a
78
+ * sandbox whose pre-boot another process started (tag), one whose pre-boot
79
+ * is ambiguous (exec error, late or missing verdict without a confirmed exit
80
+ * 98), one whose pre-boot already exited, one older than
81
+ * EARLY_PREBOOT_MAX_ADOPTION_AGE_MS, or a launch whose PB resolves off. A
82
+ * pre-boot that provably never started (exit 98 confirmed, or no baked plan)
83
+ * is adopted and launched today's way.
84
+ *
85
+ * Orphans: the exact-id reaper (EARLY_SANDBOX_REAP_AFTER_MS, 90 s after
86
+ * create) terminates an unadopted sandbox and the waiting runner with it; the
87
+ * running exec may keep the provider's idle timeout from firing, so the
88
+ * reaper is the killer. If the reap itself fails, the runner gives up its
89
+ * config wait at its own 120 s deadline (runner-app WAIT_CONFIG_TIMEOUT_MS),
90
+ * the chain exits (the epilogue has no crash pusher or config and pushes
91
+ * nothing), and the then-idle sandbox ends at the 60 s idle timeout; the
92
+ * watchdog's own 240 s startup deadline is a later backstop. Adoption itself
93
+ * is ~1-2 s after create, far inside every bound. Per-run capable (experiment
94
+ * switch PB).
95
+ */
96
+ export const PREBOOT_RUNNER_IN_EARLY_SANDBOX = false;
97
+
98
+ /** Source tag an unadopted early sandbox carries from its create call. */
99
+ export const EARLY_SANDBOX_SOURCE_TAG = 'deepline-play-runner-early';
100
+ /**
101
+ * Source tag of the retired F2 hedged early create (docs/runtime-speed-
102
+ * experiments.md). Nothing creates it now; the reaper and the durable sweep
103
+ * still treat it as unadopted, so a leg left by an older worker is reaped.
104
+ */
105
+ export const EARLY_SANDBOX_HEDGE_TAG = 'deepline-play-runner-early-hedge';
106
+ /** Orphan guard: an unadopted early sandbox that runs no command ends here. */
107
+ export const EARLY_SANDBOX_IDLE_TIMEOUT_MS = 60_000;
108
+ export const EARLY_SANDBOX_REAP_AFTER_MS = 90_000;
109
+ /**
110
+ * No launch adopts an early sandbox older than this (create request -> adopt
111
+ * check). Kept well under EARLY_SANDBOX_REAP_AFTER_MS so a reaper can never
112
+ * terminate a sandbox that a launch is in the middle of adopting. Adoption is
113
+ * normally ~1-2 s after create.
114
+ */
115
+ export const EARLY_SANDBOX_MAX_ADOPTION_AGE_MS = 60_000;
116
+ /** Create-request time (epoch ms), set in the create tags. */
117
+ export const EARLY_CREATED_AT_TAG = 'earlyCreatedAtMs';
118
+ /** PB: the pre-boot claim, set in the create tags. */
119
+ export const EARLY_PREBOOT_TAG = 'earlyPreboot';
120
+ /**
121
+ * A pre-boot older than this is not adopted: its watchdog's startup deadline
122
+ * runs from pre-boot, and the runner's config wait has a 120 s deadline.
123
+ */
124
+ export const EARLY_PREBOOT_MAX_ADOPTION_AGE_MS = 30_000;
125
+ /** Bound on the pre-boot's verdict line, and on its exit after a refusal. */
126
+ export const EARLY_PREBOOT_VERDICT_TIMEOUT_MS = 15_000;
127
+
128
+ /**
129
+ * The sandbox calls this Module makes. A provider's sandbox handle already
130
+ * has this shape (Modal's does), or its Adapter wraps one.
131
+ */
132
+ export type EarlySandboxHandle = {
133
+ readonly sandboxId: string;
134
+ getTags(): Promise<Record<string, string>>;
135
+ setTags(tags: Record<string, string>): Promise<unknown>;
136
+ /** The exit code, or null while the sandbox runs. */
137
+ poll(): Promise<number | null>;
138
+ /** Idempotent. */
139
+ terminate(): Promise<unknown>;
140
+ };
141
+
142
+ /** Provider lookups, bound to the provider app or project. */
143
+ export type EarlySandboxProviderCalls<
144
+ TSandbox extends EarlySandboxHandle = EarlySandboxHandle,
145
+ > = {
146
+ /** Log scope; Modal's is `play-runner.modal.early`. */
147
+ readonly logScope: string;
148
+ fromId(sandboxId: string): Promise<TSandbox>;
149
+ /** Sandboxes carrying every given tag. */
150
+ list(tags: Record<string, string>): AsyncIterable<{ sandboxId: string }>;
151
+ };
152
+
153
+ export type EarlySandboxEntry<TSandbox = EarlySandboxHandle> = {
154
+ sandbox: TSandbox;
155
+ startedAtMs: number;
156
+ /** The tags this process last set on the early sandbox. */
157
+ tags: Record<string, string>;
158
+ };
159
+
160
+ /**
161
+ * This process's unadopted early sandboxes, by org-scoped key. `take` removes
162
+ * the entry, so each early sandbox is handed to at most one in-process
163
+ * adoption; an unadopted entry expires after twice the reap delay.
164
+ */
165
+ export class EarlySandboxRegistry<TSandbox = EarlySandboxHandle> {
166
+ readonly #entries = new Map<
167
+ string,
168
+ Promise<EarlySandboxEntry<TSandbox> | null>
169
+ >();
170
+
171
+ has(key: string): boolean {
172
+ return this.#entries.has(key);
173
+ }
174
+
175
+ put(
176
+ key: string,
177
+ entry: Promise<EarlySandboxEntry<TSandbox> | null>,
178
+ ttlMs: number = EARLY_SANDBOX_REAP_AFTER_MS * 2,
179
+ ): void {
180
+ this.#entries.set(key, entry);
181
+ setTimeout(() => {
182
+ if (this.#entries.get(key) === entry) this.#entries.delete(key);
183
+ }, ttlMs).unref?.();
184
+ }
185
+
186
+ take(key: string): Promise<EarlySandboxEntry<TSandbox> | null> | undefined {
187
+ const entry = this.#entries.get(key);
188
+ this.#entries.delete(key);
189
+ return entry;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * The early sandbox's key. Org-scoped: a workflow id is chosen by the caller,
195
+ * so two orgs can name the same one; neither may find the other's sandbox.
196
+ */
197
+ export function earlySandboxKey(input: {
198
+ orgId: string;
199
+ workflowId: string;
200
+ }): string {
201
+ return createHash('sha256')
202
+ .update(JSON.stringify([input.orgId, input.workflowId]))
203
+ .digest('hex')
204
+ .slice(0, 40);
205
+ }
206
+
207
+ /**
208
+ * Why an early sandbox's tags do not belong to this launch's run, or null.
209
+ * Checked on every adoption path, before the sandbox is re-tagged or used.
210
+ */
211
+ export function earlySandboxIdentityRefusal(
212
+ tags: Record<string, string>,
213
+ expected: { key: string; orgId: string; workflowId: string },
214
+ ): 'key_mismatch' | 'org_mismatch' | 'workflow_mismatch' | null {
215
+ if (tags.earlyKey !== expected.key) return 'key_mismatch';
216
+ if (tags.orgId !== expected.orgId) return 'org_mismatch';
217
+ if (tags.workflowId !== expected.workflowId) return 'workflow_mismatch';
218
+ return null;
219
+ }
220
+
221
+ /** Age of an early sandbox from its create tag; null when it has none. */
222
+ export function earlySandboxAgeMs(
223
+ tags: Record<string, string>,
224
+ nowMs: number,
225
+ ): number | null {
226
+ const createdAtMs = Number(tags[EARLY_CREATED_AT_TAG]);
227
+ return Number.isSafeInteger(createdAtMs) && createdAtMs > 0
228
+ ? nowMs - createdAtMs
229
+ : null;
230
+ }
231
+
232
+ export function earlySandboxLimitsKey(input: {
233
+ cpu: number;
234
+ memoryMiB: number;
235
+ timeoutMs: number;
236
+ }): string {
237
+ return `${input.cpu}:${input.memoryMiB}:${input.timeoutMs}`;
238
+ }
239
+
240
+ /** The create tags of an early sandbox: its source, key, identity and limits. */
241
+ export function earlySandboxCreateTags(input: {
242
+ key: string;
243
+ orgId: string;
244
+ workflowId: string;
245
+ createRequestedAtMs: number;
246
+ limitsKey: string;
247
+ preboot: boolean;
248
+ }): Record<string, string> {
249
+ return {
250
+ source: EARLY_SANDBOX_SOURCE_TAG,
251
+ earlyKey: input.key,
252
+ // Identity, checked at adoption against the launching run.
253
+ orgId: input.orgId,
254
+ workflowId: input.workflowId,
255
+ [EARLY_CREATED_AT_TAG]: String(input.createRequestedAtMs),
256
+ limitsKey: input.limitsKey,
257
+ ...(input.preboot ? { [EARLY_PREBOOT_TAG]: '1' } : {}),
258
+ };
259
+ }
260
+
261
+ export function logEarlySandbox(
262
+ logScope: string,
263
+ event: string,
264
+ extra: Record<string, unknown>,
265
+ ) {
266
+ console.info(
267
+ `[${logScope}]`,
268
+ JSON.stringify({ event, ...extra, atMs: Date.now() }),
269
+ );
270
+ }
271
+
272
+ export function logEarlySandboxReapUnconfirmed(input: {
273
+ logScope: string;
274
+ event: string;
275
+ key: string;
276
+ sandboxId: string;
277
+ error: unknown;
278
+ }) {
279
+ // Loud: the sandbox keeps its early tag, so the durable sweep retries it.
280
+ console.error(
281
+ JSON.stringify({
282
+ event: `${input.logScope}.${input.event}`,
283
+ key: input.key,
284
+ sandboxId: input.sandboxId,
285
+ error:
286
+ input.error instanceof Error
287
+ ? input.error.message
288
+ : String(input.error),
289
+ }),
290
+ );
291
+ }
292
+
293
+ export type EarlySandboxStartRequest = {
294
+ workflowId: string;
295
+ orgId?: string | null;
296
+ runtimeSchedulerSchema: string | null;
297
+ /** EXPERIMENT: the hinted run's overrides (E2, PB, S1); absent: static. */
298
+ experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
299
+ };
300
+
301
+ /**
302
+ * A provider's early-sandbox Adapter. The shared Module decides whether and
303
+ * when; the Adapter makes the provider calls.
304
+ */
305
+ export type EarlySandboxAdapter<
306
+ TSandbox extends EarlySandboxHandle = EarlySandboxHandle,
307
+ > = {
308
+ readonly provider: RuntimeSandboxProviderId;
309
+ readonly logScope: string;
310
+ /** This process's unadopted early sandboxes on this provider. */
311
+ readonly registry: EarlySandboxRegistry<TSandbox>;
312
+ /**
313
+ * Why this process cannot start an early sandbox on this provider now (a
314
+ * provider precondition), or null. Checked after E2 resolves on; not logged.
315
+ */
316
+ startUnavailable(): string | null;
317
+ /**
318
+ * Create the early sandbox with `earlySandboxCreateTags`, then arm it: the
319
+ * exact-id reaper (`scheduleEarlySandboxReap`) and any pre-boot hook.
320
+ * Rejects on any failure; the caller logs it and records no entry.
321
+ */
322
+ createEarly(
323
+ input: EarlySandboxStartRequest & {
324
+ key: string;
325
+ orgId: string;
326
+ hintAtMs: number;
327
+ },
328
+ ): Promise<EarlySandboxEntry<TSandbox>>;
329
+ /** The durable orphan sweep pass this worker runs for the provider. */
330
+ sweepOrphansForWorker(input: {
331
+ runtimeSchedulerSchema: string | null;
332
+ }): Promise<EarlySandboxSweepOutcome | { skipped: string }>;
333
+ };
334
+
335
+ /**
336
+ * Start (fire and forget) the early sandbox for an admitted run. Idempotent
337
+ * per process; a second hint for the same run is ignored.
338
+ */
339
+ export function startEarlySandbox<TSandbox extends EarlySandboxHandle>(
340
+ adapter: EarlySandboxAdapter<TSandbox>,
341
+ input: EarlySandboxStartRequest,
342
+ ): boolean {
343
+ if (
344
+ !resolveExperimentSwitch(
345
+ 'E2',
346
+ input.experimentSwitchOverrides,
347
+ EARLY_SANDBOX_START,
348
+ ) ||
349
+ adapter.startUnavailable() !== null
350
+ )
351
+ return false;
352
+ // The key and the adoption check are org-scoped; a hint without an org
353
+ // cannot start a sandbox any launch could safely adopt.
354
+ const orgId = input.orgId?.trim();
355
+ if (!orgId) {
356
+ logEarlySandbox(adapter.logScope, 'hint_refused', { reason: 'no_org' });
357
+ return false;
358
+ }
359
+ const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
360
+ if (adapter.registry.has(key)) return false;
361
+ const hintAtMs = Date.now();
362
+ const started = (async () =>
363
+ await adapter.createEarly({ ...input, key, orgId, hintAtMs }))().catch(
364
+ (error: unknown) => {
365
+ logEarlySandbox(adapter.logScope, 'create_failed', {
366
+ key,
367
+ error: error instanceof Error ? error.message : String(error),
368
+ });
369
+ return null;
370
+ },
371
+ );
372
+ adapter.registry.put(key, started);
373
+ logEarlySandbox(adapter.logScope, 'hint_accepted', {
374
+ key,
375
+ workflowId: input.workflowId,
376
+ });
377
+ return true;
378
+ }
379
+
380
+ /**
381
+ * An early sandbox on a slow host may not have a running container yet when
382
+ * it is terminated, so its exit code can stay unset for a while (FAST1c: 2 of
383
+ * 12 unconfirmed after ~11 s). Re-terminate and re-read with a backoff capped at
384
+ * 2 s, ~60 s in all, before handing it to the 90 s exact-id reaper.
385
+ */
386
+ export const EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS = 35;
387
+ const earlyTerminateConfirmDelayMs = (attempt: number) =>
388
+ Math.min(200 * attempt, 2_000);
389
+
390
+ /**
391
+ * Terminate a sandbox by exact id and confirm it by reading its exit code
392
+ * back, re-terminating with a capped backoff (a not-yet-running sandbox may
393
+ * miss a terminate). Returns the attempts it took; throws when the read-back
394
+ * never confirms within `attempts`, or on a provider error.
395
+ */
396
+ export async function terminateEarlySandboxConfirmed(input: {
397
+ sandbox: Pick<EarlySandboxHandle, 'terminate' | 'sandboxId'>;
398
+ readExitCode: (sandboxId: string) => Promise<number | null>;
399
+ sleep: (ms: number) => Promise<void>;
400
+ attempts: number;
401
+ }): Promise<number> {
402
+ for (let attempt = 1; attempt <= input.attempts; attempt++) {
403
+ // Idempotent; repeated because a not-yet-running sandbox may miss it.
404
+ await input.sandbox.terminate();
405
+ if ((await input.readExitCode(input.sandbox.sandboxId)) !== null)
406
+ return attempt;
407
+ await input.sleep(earlyTerminateConfirmDelayMs(attempt));
408
+ }
409
+ throw new Error('termination not confirmed by read-back');
410
+ }
411
+
412
+ export const sleepMs = (ms: number) =>
413
+ new Promise<void>((resolve) => setTimeout(resolve, ms));
414
+
415
+ /** The exit-code read-back a confirmed termination polls. */
416
+ export const readEarlySandboxExitCode =
417
+ (calls: Pick<EarlySandboxProviderCalls, 'fromId'>) =>
418
+ async (sandboxId: string) =>
419
+ await (await calls.fromId(sandboxId)).poll();
420
+
421
+ export function isUnadoptedEarlySandbox(
422
+ tags: Record<string, string>,
423
+ ): boolean {
424
+ return (
425
+ tags.source === EARLY_SANDBOX_SOURCE_TAG ||
426
+ tags.source === EARLY_SANDBOX_HEDGE_TAG
427
+ );
428
+ }
429
+
430
+ /**
431
+ * Reap one early (or hedge) sandbox by exact id if it is still unadopted: a
432
+ * fresh tag read (an adopted sandbox carries ordinary launch tags), then a
433
+ * confirmed termination. An unconfirmed one keeps its early tag, so the
434
+ * durable sweep (sweepOrphanEarlySandboxes) still finds it.
435
+ */
436
+ export async function reapEarlySandboxById(input: {
437
+ calls: Pick<EarlySandboxProviderCalls, 'fromId' | 'logScope'>;
438
+ key: string;
439
+ sandboxId: string;
440
+ attempts?: number;
441
+ sleep?: (ms: number) => Promise<void>;
442
+ }): Promise<'not_early' | 'terminated'> {
443
+ const fresh = await input.calls.fromId(input.sandboxId);
444
+ if (!isUnadoptedEarlySandbox(await fresh.getTags())) return 'not_early';
445
+ const confirmAttempts = await terminateEarlySandboxConfirmed({
446
+ sandbox: fresh,
447
+ readExitCode: readEarlySandboxExitCode(input.calls),
448
+ sleep: input.sleep ?? sleepMs,
449
+ attempts: input.attempts ?? EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS,
450
+ });
451
+ logEarlySandbox(input.calls.logScope, 'reaped_unadopted', {
452
+ key: input.key,
453
+ sandboxId: input.sandboxId,
454
+ confirmAttempts,
455
+ });
456
+ return 'terminated';
457
+ }
458
+
459
+ /**
460
+ * In-process exact-id reaper: after EARLY_SANDBOX_REAP_AFTER_MS, terminate the
461
+ * sandbox (confirmed) if it still carries an early (or hedge) tag, i.e. no
462
+ * launch adopted it. The fast path only: the durable guarantee is the early
463
+ * tag itself, set by the create call, which the worker's sweep reads even
464
+ * after this process is gone.
465
+ */
466
+ export function scheduleEarlySandboxReap(input: {
467
+ calls: Pick<EarlySandboxProviderCalls, 'fromId' | 'logScope'>;
468
+ key: string;
469
+ sandboxId: string;
470
+ }): void {
471
+ const reap = setTimeout(() => {
472
+ void reapEarlySandboxById(input).catch((error: unknown) =>
473
+ logEarlySandboxReapUnconfirmed({
474
+ logScope: input.calls.logScope,
475
+ event: 'reap_unconfirmed',
476
+ key: input.key,
477
+ sandboxId: input.sandboxId,
478
+ error,
479
+ }),
480
+ );
481
+ }, EARLY_SANDBOX_REAP_AFTER_MS);
482
+ reap.unref?.();
483
+ }
484
+
485
+ /**
486
+ * Durable orphan cleanup for E2/PB early sandboxes (and retired F2 legs). The
487
+ * cleanup obligation is recorded before (atomically with) every early create:
488
+ * the create request itself carries the early (or hedge) source tag and its
489
+ * create time, and the provider holds those tags for the sandbox's life. The
490
+ * main path's ambiguous-create row cannot be used here: the hint arrives
491
+ * before the run is enqueued, so there is no run row or attempt lease to
492
+ * fence it to. Once adopted, a sandbox carries the run's create tags and the
493
+ * main path's obligation (recorded before adoption) covers it.
494
+ *
495
+ * This pass lists only unadopted early sandboxes (the source-tag selector),
496
+ * skips any younger than EARLY_SANDBOX_REAP_AFTER_MS, re-reads each one's tags
497
+ * by exact id, and terminates it with a bounded confirmation. No launch adopts
498
+ * past EARLY_SANDBOX_MAX_ADOPTION_AGE_MS (60 s < 90 s), so whichever worker
499
+ * created it, an early sandbox this old is an orphan. One not confirmed this
500
+ * pass keeps its tag and is retried by the next.
501
+ */
502
+ export const EARLY_SANDBOX_SWEEP_INTERVAL_MS = 60_000;
503
+ const EARLY_SANDBOX_SWEEP_LIMIT = 20;
504
+ const EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS = 5;
505
+
506
+ export type EarlySandboxSweepOutcome = {
507
+ observed: number;
508
+ terminated: number;
509
+ unconfirmed: number;
510
+ young: number;
511
+ };
512
+
513
+ export async function sweepOrphanEarlySandboxes(input: {
514
+ calls: EarlySandboxProviderCalls;
515
+ nowMs?: () => number;
516
+ sleep?: (ms: number) => Promise<void>;
517
+ limit?: number;
518
+ }): Promise<EarlySandboxSweepOutcome> {
519
+ const nowMs = input.nowMs ?? Date.now;
520
+ const limit = input.limit ?? EARLY_SANDBOX_SWEEP_LIMIT;
521
+ const ids = new Set<string>();
522
+ for (const source of [EARLY_SANDBOX_SOURCE_TAG, EARLY_SANDBOX_HEDGE_TAG]) {
523
+ for await (const listed of input.calls.list({ source })) {
524
+ if (ids.size >= limit) break;
525
+ if (listed.sandboxId?.trim()) ids.add(listed.sandboxId.trim());
526
+ }
527
+ }
528
+ let terminated = 0;
529
+ let unconfirmed = 0;
530
+ let young = 0;
531
+ await Promise.all(
532
+ [...ids].map(async (sandboxId) => {
533
+ try {
534
+ const fresh = await input.calls.fromId(sandboxId);
535
+ const tags = await fresh.getTags();
536
+ if (!isUnadoptedEarlySandbox(tags)) return;
537
+ const ageMs = earlySandboxAgeMs(tags, nowMs());
538
+ // A sandbox without a create time predates the tag and is past any
539
+ // adoption (adoption refuses it), so it is reaped.
540
+ if (ageMs !== null && ageMs < EARLY_SANDBOX_REAP_AFTER_MS) {
541
+ young += 1;
542
+ return;
543
+ }
544
+ const confirmAttempts = await terminateEarlySandboxConfirmed({
545
+ sandbox: fresh,
546
+ readExitCode: readEarlySandboxExitCode(input.calls),
547
+ sleep: input.sleep ?? sleepMs,
548
+ attempts: EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS,
549
+ });
550
+ terminated += 1;
551
+ logEarlySandbox(input.calls.logScope, 'swept_orphan', {
552
+ key: tags.earlyKey ?? null,
553
+ sandboxId,
554
+ ageMs,
555
+ confirmAttempts,
556
+ });
557
+ } catch (error) {
558
+ unconfirmed += 1;
559
+ logEarlySandboxReapUnconfirmed({
560
+ logScope: input.calls.logScope,
561
+ event: 'sweep_unconfirmed',
562
+ key: 'sweep',
563
+ sandboxId,
564
+ error,
565
+ });
566
+ }
567
+ }),
568
+ );
569
+ return { observed: ids.size, terminated, unconfirmed, young };
570
+ }
571
+
572
+ /** PB: the runner limits a pre-boot fixed, which a launch must match. */
573
+ export type EarlySandboxPrebootRunner = {
574
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
575
+ memoryLimitMiB?: number;
576
+ };
577
+
578
+ export type EarlySandboxPreboot<
579
+ TRunner extends EarlySandboxPrebootRunner = EarlySandboxPrebootRunner,
580
+ > =
581
+ | {
582
+ status: 'running';
583
+ runner: TRunner;
584
+ /** The pre-boot chain's exit code (runner, then epilogue). */
585
+ exited: Promise<number>;
586
+ /** Set once `exited` settles with a code. */
587
+ exitCode: number | null;
588
+ startedAtMs: number;
589
+ }
590
+ /** Provably nothing ran: today's launch may use this sandbox. */
591
+ | { status: 'not_started'; reason: string }
592
+ /** Cannot prove what ran: never adopted. */
593
+ | { status: 'ambiguous'; reason: string };
594
+
595
+ /**
596
+ * PB: why an in-process early sandbox with a pre-boot must not be adopted by
597
+ * this launch, or null when it may be (a running pre-boot this launch will
598
+ * deliver to, or one that provably never started).
599
+ */
600
+ export function earlyPrebootAdoptionRefusal(input: {
601
+ preboot: EarlySandboxPreboot;
602
+ wanted: boolean;
603
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
604
+ memoryLimitMiB?: number;
605
+ nowMs: number;
606
+ }): string | null {
607
+ const { preboot } = input;
608
+ if (preboot.status === 'not_started') return null;
609
+ if (preboot.status === 'ambiguous') return 'preboot_ambiguous';
610
+ // A running runner nobody will deliver to would share the sandbox with
611
+ // today's launch.
612
+ if (!input.wanted) return 'preboot_unwanted';
613
+ if (preboot.exitCode !== null) return 'preboot_exited';
614
+ if (input.nowMs - preboot.startedAtMs > EARLY_PREBOOT_MAX_ADOPTION_AGE_MS)
615
+ return 'preboot_stale';
616
+ if (
617
+ !samePlaySandboxRuntimeLimits(
618
+ preboot.runner.sandboxRuntimeLimits,
619
+ input.sandboxRuntimeLimits,
620
+ ) ||
621
+ preboot.runner.memoryLimitMiB !== input.memoryLimitMiB
622
+ )
623
+ return 'preboot_limits_mismatch';
624
+ return null;
625
+ }
626
+
627
+ /**
628
+ * Adopt this run's early sandbox by exact id, or return null so the launch
629
+ * creates its own. The in-process promise is awaited when this worker started
630
+ * it; otherwise one tag listing finds a sandbox another worker started. The
631
+ * key is org-scoped, and every path checks the sandbox's org and workflow
632
+ * tags against this run before re-tagging it; a mismatch is refused loudly.
633
+ */
634
+ export async function adoptEarlySandbox<
635
+ TSandbox extends EarlySandboxHandle,
636
+ >(input: {
637
+ calls: EarlySandboxProviderCalls<TSandbox>;
638
+ /** This process's early sandboxes on this provider. */
639
+ registry: EarlySandboxRegistry<TSandbox>;
640
+ workflowId: string;
641
+ orgId: string | null | undefined;
642
+ runId: string | null | undefined;
643
+ experimentSwitchOverrides: ExperimentSwitchOverrides | null | undefined;
644
+ expectedLimitsKey: string;
645
+ createTags: Record<string, string>;
646
+ /** PB: whether this launch wants a pre-booted runner, and its limits. */
647
+ preboot: {
648
+ wanted: boolean;
649
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
650
+ memoryLimitMiB?: number;
651
+ };
652
+ /**
653
+ * Provider claims a sandbox started by another process may carry, checked
654
+ * in order before the pre-boot claim; each bars adoption from here.
655
+ */
656
+ foreignClaimTags?: readonly { tag: string; reason: string }[];
657
+ /** PB hook: this process's pre-boot on an in-process sandbox, if any. */
658
+ inProcessPreboot(sandbox: TSandbox): Promise<EarlySandboxPreboot> | undefined;
659
+ /**
660
+ * A1 hook: settles once a tag that makes every other process refuse to
661
+ * adopt the sandbox is on it at the provider.
662
+ */
663
+ inProcessForeignAdoptionClaim(sandbox: TSandbox): Promise<unknown> | undefined;
664
+ /** The launch's stage events (`early:adopted`, `early:adopt_miss`). */
665
+ emitStage(stage: string, extra: Record<string, unknown>): void;
666
+ nowMs?: () => number;
667
+ }): Promise<TSandbox | null> {
668
+ const nowMs = input.nowMs ?? Date.now;
669
+ const startedAt = nowMs();
670
+ const orgId = input.orgId?.trim();
671
+ if (!orgId) {
672
+ input.emitStage('early:adopt_miss', {
673
+ reason: 'no_org',
674
+ elapsedMs: 0,
675
+ });
676
+ return null;
677
+ }
678
+ const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
679
+ const registry = input.registry;
680
+ let sandbox: TSandbox | null = null;
681
+ let localEntry: EarlySandboxEntry<TSandbox> | null = null;
682
+ let how = 'none';
683
+ try {
684
+ // Taken, not read: this entry is handed to this one adoption only.
685
+ const local = registry.take(key);
686
+ if (local) {
687
+ localEntry = await local;
688
+ sandbox = localEntry?.sandbox ?? null;
689
+ how = 'in_process';
690
+ }
691
+ if (!sandbox) {
692
+ for await (const listed of input.calls.list({
693
+ source: EARLY_SANDBOX_SOURCE_TAG,
694
+ earlyKey: key,
695
+ })) {
696
+ sandbox = await input.calls.fromId(listed.sandboxId);
697
+ how = 'by_tag';
698
+ break;
699
+ }
700
+ }
701
+ if (!sandbox) {
702
+ input.emitStage('early:adopt_miss', {
703
+ key,
704
+ reason: 'not_found',
705
+ elapsedMs: nowMs() - startedAt,
706
+ });
707
+ return null;
708
+ }
709
+ // A1 may skip the read only for this process's own, fresh, untaken entry
710
+ // whose foreign-adoption claim is confirmed on the sandbox: then no other
711
+ // process can have adopted (re-tagged) it. Everything else is read back.
712
+ const foreignClaim =
713
+ how === 'in_process'
714
+ ? input.inProcessForeignAdoptionClaim(sandbox)
715
+ : undefined;
716
+ const trustLocalTags =
717
+ how === 'in_process' &&
718
+ localEntry !== null &&
719
+ nowMs() - localEntry.startedAtMs < EARLY_SANDBOX_MAX_ADOPTION_AGE_MS &&
720
+ resolveExperimentSwitch(
721
+ 'A1',
722
+ input.experimentSwitchOverrides,
723
+ ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ,
724
+ ) &&
725
+ foreignClaim !== undefined &&
726
+ (await foreignClaim.then(
727
+ () => true,
728
+ () => false,
729
+ ));
730
+ const tags =
731
+ trustLocalTags && localEntry ? localEntry.tags : await sandbox.getTags();
732
+ const identityRefusal = earlySandboxIdentityRefusal(tags, {
733
+ key,
734
+ orgId,
735
+ workflowId: input.workflowId,
736
+ });
737
+ if (identityRefusal) {
738
+ // Never expected: the key already names this org and workflow. Loud,
739
+ // and the sandbox is left untouched for its own reaper.
740
+ console.error(
741
+ JSON.stringify({
742
+ event: `${input.calls.logScope}.adopt_refused_identity`,
743
+ reason: identityRefusal,
744
+ key,
745
+ how,
746
+ sandboxId: sandbox.sandboxId,
747
+ runId: input.runId ?? null,
748
+ }),
749
+ );
750
+ input.emitStage('early:adopt_miss', {
751
+ key,
752
+ reason: identityRefusal,
753
+ sandboxId: sandbox.sandboxId,
754
+ elapsedMs: nowMs() - startedAt,
755
+ });
756
+ return null;
757
+ }
758
+ const ageMs =
759
+ how === 'in_process' && localEntry
760
+ ? nowMs() - localEntry.startedAtMs
761
+ : earlySandboxAgeMs(tags, nowMs());
762
+ if (ageMs === null || ageMs >= EARLY_SANDBOX_MAX_ADOPTION_AGE_MS) {
763
+ // Past the adoption window the reapers own it.
764
+ input.emitStage('early:adopt_miss', {
765
+ key,
766
+ reason: 'early_stale',
767
+ sandboxId: sandbox.sandboxId,
768
+ ageMs,
769
+ elapsedMs: nowMs() - startedAt,
770
+ });
771
+ return null;
772
+ }
773
+ // PB: another process started a runner here and holds its delivery
774
+ // plan; nothing may be delivered to it from this process. Provider
775
+ // claims (Modal's S1 sidecar) come first.
776
+ for (const claim of [
777
+ ...(input.foreignClaimTags ?? []),
778
+ { tag: EARLY_PREBOOT_TAG, reason: 'early_preboot_foreign' },
779
+ ]) {
780
+ if (how !== 'in_process' && tags[claim.tag]) {
781
+ input.emitStage('early:adopt_miss', {
782
+ key,
783
+ reason: claim.reason,
784
+ sandboxId: sandbox.sandboxId,
785
+ elapsedMs: nowMs() - startedAt,
786
+ });
787
+ return null;
788
+ }
789
+ }
790
+ const prebootPending =
791
+ how === 'in_process' ? input.inProcessPreboot(sandbox) : undefined;
792
+ const prebootRefusal = prebootPending
793
+ ? earlyPrebootAdoptionRefusal({
794
+ preboot: await prebootPending,
795
+ ...input.preboot,
796
+ nowMs: Date.now(),
797
+ })
798
+ : null;
799
+ if (prebootRefusal) {
800
+ input.emitStage('early:adopt_miss', {
801
+ key,
802
+ reason: prebootRefusal,
803
+ sandboxId: sandbox.sandboxId,
804
+ elapsedMs: nowMs() - startedAt,
805
+ });
806
+ return null;
807
+ }
808
+ if (
809
+ tags.source !== EARLY_SANDBOX_SOURCE_TAG ||
810
+ tags.earlyKey !== key ||
811
+ tags.limitsKey !== input.expectedLimitsKey ||
812
+ (await sandbox.poll()) !== null
813
+ ) {
814
+ input.emitStage('early:adopt_miss', {
815
+ key,
816
+ reason: 'mismatch_or_exited',
817
+ sandboxId: sandbox.sandboxId,
818
+ elapsedMs: nowMs() - startedAt,
819
+ });
820
+ return null;
821
+ }
822
+ // Re-tag first: from here the sandbox is an ordinary launch sandbox for
823
+ // every cleanup and reconciliation path, and the reaper skips it.
824
+ await sandbox.setTags({ ...input.createTags, earlyKey: key });
825
+ input.emitStage('early:adopted', {
826
+ key,
827
+ how,
828
+ sandboxId: sandbox.sandboxId,
829
+ elapsedMs: nowMs() - startedAt,
830
+ });
831
+ return sandbox;
832
+ } catch (error) {
833
+ input.emitStage('early:adopt_miss', {
834
+ key,
835
+ reason: 'error',
836
+ error: error instanceof Error ? error.message : String(error),
837
+ elapsedMs: nowMs() - startedAt,
838
+ });
839
+ return null;
840
+ }
841
+ }
842
+
843
+ /**
844
+ * The early-sandbox switches a run (or, for the static defaults, a lane)
845
+ * resolves on. `claimAffinity` is CA's per-run value or the worker's CAR.
846
+ */
847
+ export type EarlySandboxSwitches = Readonly<{
848
+ earlyStart: boolean;
849
+ preboot: boolean;
850
+ claimAffinity: boolean;
851
+ }>;
852
+
853
+ /** The provider capabilities these switches need: one per switch that is on. */
854
+ export function earlySandboxRequiredCapabilities(
855
+ switches: EarlySandboxSwitches,
856
+ ): RuntimeSandboxProviderCapability[] {
857
+ const required: RuntimeSandboxProviderCapability[] = [];
858
+ if (switches.earlyStart) required.push('earlyStart');
859
+ if (switches.preboot) required.push('preboot');
860
+ if (switches.claimAffinity) required.push('claimAffinity');
861
+ return required;
862
+ }