deepline 0.3.545 → 0.3.547

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 (222) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +13 -0
  2. package/dist/bundling-sources/sdk/src/errors.ts +1 -1
  3. package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
  4. package/dist/bundling-sources/sdk/src/index.ts +7 -1
  5. package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
  6. package/dist/bundling-sources/sdk/src/play.ts +71 -0
  7. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
  9. package/dist/bundling-sources/sdk/src/types.ts +33 -0
  10. package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
  11. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
  12. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
  13. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +21 -3
  14. package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
  15. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
  16. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
  18. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +299 -52
  19. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +18 -1
  20. package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
  24. package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +40 -3
  26. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
  31. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
  32. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
  33. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
  34. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +53 -2
  35. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
  36. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +11 -3
  39. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +30 -2
  40. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
  41. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
  42. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +36 -2
  43. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
  44. package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
  45. package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
  46. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
  47. package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
  48. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
  49. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +41 -2
  50. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
  51. package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
  52. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +35 -1
  53. package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
  54. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +58 -0
  55. package/dist/cli/auth-AC5277PI.js +43 -0
  56. package/dist/cli/{auth-VZAMAMFW.mjs → auth-WJEY4IDX.mjs} +6 -6
  57. package/dist/cli/{billing-ASZJDFH2.js → billing-IJITDDRQ.js} +99 -99
  58. package/dist/cli/{billing-DADQUQEZ.mjs → billing-PHJUDYF3.mjs} +11 -11
  59. package/dist/cli/{chunk-FB7UPZ6M.js → chunk-2AHY47SI.js} +3 -3
  60. package/dist/cli/{chunk-CJ7DBYEQ.js → chunk-2HPTLBNB.js} +8 -8
  61. package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
  62. package/dist/cli/{chunk-LTCEZWPZ.mjs → chunk-56MEAGWA.mjs} +2 -2
  63. package/dist/cli/{chunk-YWTRCKGD.mjs → chunk-5SFHPMBY.mjs} +11 -11
  64. package/dist/cli/{chunk-D3SXB2NX.js → chunk-ABLTVG3J.js} +41 -41
  65. package/dist/cli/{chunk-KRW727W6.mjs → chunk-AEQ5VWZ5.mjs} +4 -4
  66. package/dist/cli/{chunk-Z7QM244Q.mjs → chunk-CKIRKYW7.mjs} +3 -3
  67. package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
  68. package/dist/cli/{chunk-OGQYAJSO.js → chunk-D6OIEH47.js} +5 -5
  69. package/dist/cli/{chunk-2HFSYH7V.mjs → chunk-DIUNDLSX.mjs} +2 -2
  70. package/dist/cli/{chunk-3M2QH3KA.mjs → chunk-DJI5CLLW.mjs} +22 -12
  71. package/dist/cli/{chunk-N4LADLCO.js → chunk-DZC7LMYM.js} +6 -6
  72. package/dist/cli/{chunk-CXETRZ3G.js → chunk-E2OIYPB4.js} +10 -10
  73. package/dist/cli/{chunk-Z4Y4BLW7.mjs → chunk-ECUD4QPD.mjs} +3 -3
  74. package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
  75. package/dist/cli/{chunk-NAN3A4IF.mjs → chunk-ESCVHDNY.mjs} +5 -5
  76. package/dist/cli/{chunk-C6XYSTBW.js → chunk-FFBXLFKV.js} +1 -1
  77. package/dist/cli/{chunk-HLUNTJBO.mjs → chunk-FMQXAOVE.mjs} +4 -4
  78. package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
  79. package/dist/cli/{chunk-4NZ3OZNO.mjs → chunk-G6KW764N.mjs} +1 -1
  80. package/dist/cli/{chunk-LWPFMYSO.mjs → chunk-G6XTCG3J.mjs} +2 -2
  81. package/dist/cli/{chunk-NCX2JH2F.js → chunk-GIGAYLY6.js} +12 -12
  82. package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
  83. package/dist/cli/{chunk-G5TV6WLV.js → chunk-GJOGFWX3.js} +20 -20
  84. package/dist/cli/{chunk-7MFATEUC.mjs → chunk-GPAWLXW3.mjs} +2 -2
  85. package/dist/cli/{chunk-DZTVDL2X.js → chunk-GZFZZQL4.js} +289 -268
  86. package/dist/cli/{chunk-XBYQZEUE.mjs → chunk-HARZ4AAX.mjs} +1 -1
  87. package/dist/cli/{chunk-QI57XUGA.js → chunk-HFIFKP3A.js} +5 -5
  88. package/dist/cli/{chunk-WP36UBRY.mjs → chunk-IGAK22XO.mjs} +1 -1
  89. package/dist/cli/{chunk-XMUPZINS.mjs → chunk-IKYN6PLO.mjs} +5 -5
  90. package/dist/cli/{chunk-HPX7LLAM.mjs → chunk-ITLZBDSR.mjs} +3 -3
  91. package/dist/cli/{chunk-QM7PHHYZ.js → chunk-IVFFCAV2.js} +44 -44
  92. package/dist/cli/{chunk-IYJO3RWR.js → chunk-K3GMDSUX.js} +5 -5
  93. package/dist/cli/{chunk-EK5C2R7S.js → chunk-L5J6UJ2X.js} +15 -15
  94. package/dist/cli/{chunk-EWA3M54M.mjs → chunk-L6QE2XVM.mjs} +1 -1
  95. package/dist/cli/{chunk-3NG43NXB.js → chunk-LMLSOHTU.js} +53 -53
  96. package/dist/cli/{chunk-7MHBJU73.js → chunk-MBQELFL7.js} +22 -22
  97. package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
  98. package/dist/cli/{chunk-DGKDCZGC.js → chunk-MO7TGNXB.js} +13 -13
  99. package/dist/cli/{chunk-7P72EGLK.mjs → chunk-MOZEAGSR.mjs} +1 -1
  100. package/dist/cli/{chunk-34UKDHRL.js → chunk-N63U5CRG.js} +26 -26
  101. package/dist/cli/{chunk-5YYWZ43J.js → chunk-NBYFQZ6O.js} +2 -2
  102. package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
  103. package/dist/cli/{chunk-TQKHXMV3.js → chunk-OVYXYTEP.js} +16 -16
  104. package/dist/cli/{chunk-XGEUPU3L.mjs → chunk-PBMO36BP.mjs} +2 -2
  105. package/dist/cli/{chunk-4JQEAYN3.js → chunk-PVQCX6KQ.js} +55 -8
  106. package/dist/cli/{chunk-KYO2FICL.mjs → chunk-QLE3QKJ2.mjs} +5 -5
  107. package/dist/cli/{chunk-2FF3O2Y2.js → chunk-QU3K3IY6.js} +12 -12
  108. package/dist/cli/{chunk-HR5BT42R.js → chunk-REAFIEV5.js} +99 -99
  109. package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-RMCCB3XY.mjs} +55 -8
  110. package/dist/cli/{chunk-3TCHX7YK.mjs → chunk-RXRC2COC.mjs} +2 -2
  111. package/dist/cli/{chunk-YRQKRQDU.js → chunk-SAJWYN4B.js} +36 -26
  112. package/dist/cli/{chunk-JL5JU3LD.mjs → chunk-TNJG4ZPN.mjs} +3 -3
  113. package/dist/cli/{chunk-NZDZGK35.js → chunk-VNOQEDVC.js} +7 -7
  114. package/dist/cli/{chunk-2CBX43LP.mjs → chunk-VPF54TXQ.mjs} +5 -5
  115. package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
  116. package/dist/cli/{chunk-GWDPNOA7.mjs → chunk-XMBVHJPR.mjs} +29 -8
  117. package/dist/cli/{chunk-52C6W7FG.mjs → chunk-XNTDTAKC.mjs} +1 -1
  118. package/dist/cli/{chunk-ERLW6RPA.js → chunk-YURGAKI3.js} +2 -2
  119. package/dist/cli/{chunk-GFRJU2KB.js → chunk-YVKLF7RW.js} +2 -2
  120. package/dist/cli/{chunk-7JZ27AFH.mjs → chunk-Z2YGQZWV.mjs} +2 -2
  121. package/dist/cli/command-docs.js +2 -2
  122. package/dist/cli/command-docs.mjs +1 -1
  123. package/dist/cli/{concurrent-runs-help-YP7ALTDB.mjs → concurrent-runs-help-ZNGP563R.mjs} +7 -7
  124. package/dist/cli/concurrent-runs-help-ZYISYOQA.js +21 -0
  125. package/dist/cli/{csv-D5ITFSYI.mjs → csv-VAHQHYYV.mjs} +5 -5
  126. package/dist/cli/{csv-67WT5EGR.js → csv-X6D4ZELE.js} +14 -14
  127. package/dist/cli/{db-SZYBRFYG.mjs → db-4G4S2VOV.mjs} +8 -8
  128. package/dist/cli/{db-GZS76X7R.js → db-YA5ZGVEX.js} +33 -33
  129. package/dist/cli/{describe-YJ7ZLLLI.mjs → describe-EVXEM2S6.mjs} +20 -20
  130. package/dist/cli/describe-GYYSLZLV.js +50 -0
  131. package/dist/cli/describe-core.d.mts +4 -4
  132. package/dist/cli/describe-core.d.ts +4 -4
  133. package/dist/cli/describe-core.js +1 -1
  134. package/dist/cli/describe-core.mjs +1 -1
  135. package/dist/cli/{executions-O5USTYGL.js → executions-5YC7ABF6.js} +10 -10
  136. package/dist/cli/{executions-HMYGR32E.mjs → executions-HR6CTN5M.mjs} +8 -8
  137. package/dist/cli/{feedback-Z3NXWYUO.mjs → feedback-GEU5SPLR.mjs} +7 -7
  138. package/dist/cli/{feedback-RHLFDCRS.js → feedback-MJHSYLFF.js} +15 -15
  139. package/dist/cli/git-FZIQZNI4.js +25 -0
  140. package/dist/cli/{git-CLFKXELB.mjs → git-NPFF6QUS.mjs} +6 -6
  141. package/dist/cli/index.js +150 -150
  142. package/dist/cli/index.mjs +46 -46
  143. package/dist/cli/{integrations-TZ4QEQGV.js → integrations-YPHFI77G.js} +20 -18
  144. package/dist/cli/{integrations-FOACOBQB.mjs → integrations-Z7EGVBHF.mjs} +12 -10
  145. package/dist/cli/{legacy-noops-QRDOS33V.js → legacy-noops-246E3KKG.js} +10 -10
  146. package/dist/cli/{legacy-noops-6F6Y3BV7.mjs → legacy-noops-5IYCFWWX.mjs} +7 -7
  147. package/dist/cli/{mcp-UXRCWOZU.mjs → mcp-WUYGZXPI.mjs} +5 -5
  148. package/dist/cli/{mcp-ETMMDDGB.js → mcp-YTYTW67G.js} +25 -25
  149. package/dist/cli/{monitors-6XEWR46R.mjs → monitors-73DQKCU7.mjs} +27 -9
  150. package/dist/cli/{monitors-DITT7QTV.js → monitors-SA6ILD6Z.js} +121 -103
  151. package/dist/cli/{org-CVSSH73G.mjs → org-WVQRB2KX.mjs} +8 -8
  152. package/dist/cli/{org-4DE37X3L.js → org-X7ELDV7B.js} +90 -90
  153. package/dist/cli/{play-Y5NCHOKK.mjs → play-QI6V2EUQ.mjs} +296 -68
  154. package/dist/cli/{play-RH6P45CI.js → play-QTYOAJPE.js} +898 -670
  155. package/dist/cli/{providers-VHUHC4IZ.mjs → providers-DPVMVDS4.mjs} +8 -8
  156. package/dist/cli/{providers-DU42DLOL.js → providers-XXFLVREV.js} +11 -11
  157. package/dist/cli/{quickstart-XJ43JLEC.js → quickstart-33ISXQJU.js} +7 -7
  158. package/dist/cli/{quickstart-HJY5YYE5.mjs → quickstart-YWGNHULM.mjs} +5 -5
  159. package/dist/cli/{run-JXUS7QFI.js → run-BWHZXLTD.js} +46 -46
  160. package/dist/cli/{run-JAIXHVH7.mjs → run-J6FCAKQC.mjs} +26 -26
  161. package/dist/cli/search-JCWJX2XD.js +32 -0
  162. package/dist/cli/{search-RDMNM2AX.mjs → search-Z3UU3WBB.mjs} +9 -9
  163. package/dist/cli/{search-output-ZKTR3WTJ.mjs → search-output-OJYY4J7E.mjs} +5 -5
  164. package/dist/cli/{search-output-RKAM2HBH.js → search-output-YIPV74ME.js} +7 -7
  165. package/dist/cli/{secrets-TKFVMAYX.js → secrets-UXRJCEN4.js} +17 -17
  166. package/dist/cli/{secrets-WSW3FTF6.mjs → secrets-YZZN2WST.mjs} +8 -8
  167. package/dist/cli/{sessions-724BK6VP.mjs → sessions-ITCGPD7Z.mjs} +7 -7
  168. package/dist/cli/sessions-NA4SJH6Q.js +22 -0
  169. package/dist/cli/{settings-5LJZDAZU.js → settings-LAFYMILP.js} +87 -87
  170. package/dist/cli/{settings-YRC7J75G.mjs → settings-ZP2LSVNM.mjs} +14 -14
  171. package/dist/cli/{setup-2F3DBSOS.js → setup-4AL3XYM5.js} +50 -50
  172. package/dist/cli/{setup-STNPX5MK.mjs → setup-WEQAQSYC.mjs} +10 -10
  173. package/dist/cli/{skills-D5PK56FO.mjs → skills-NQH4HFW2.mjs} +8 -8
  174. package/dist/cli/skills-XZ4Y6SZ7.js +36 -0
  175. package/dist/cli/{tools-WOGWMBA3.mjs → tools-CXK2GSI4.mjs} +19 -19
  176. package/dist/cli/tools-WJQ6Y7E4.js +57 -0
  177. package/dist/cli/{update-PC6XSWMI.mjs → update-3ROF3Z75.mjs} +10 -10
  178. package/dist/cli/update-ZLRLTBRD.js +34 -0
  179. package/dist/cli/{views-IIHT4RYQ.mjs → views-AOUHVGV2.mjs} +8 -8
  180. package/dist/cli/{views-HLCLAPWN.js → views-XJFO5CEH.js} +23 -23
  181. package/dist/cli/{workflow-CCZ2A7DI.js → workflow-GY3DBHXX.js} +19 -19
  182. package/dist/cli/{workflow-HK4MZ7LK.mjs → workflow-KBS2QJK6.mjs} +9 -9
  183. package/dist/{client-DfdUc_MY.d.mts → client-D1uWA2Vc.d.mts} +1 -1
  184. package/dist/{client-BQ6yuSjM.d.ts → client-Hz7SsBXs.d.ts} +1 -1
  185. package/dist/{client-core-3GQ8WMuk.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
  186. package/dist/{client-core-ClsNRytk.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
  187. package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-BqwVrOri.d.mts} +73 -18
  188. package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-BqwVrOri.d.ts} +73 -18
  189. package/dist/{errors-Lm9_vJHZ.d.ts → errors-BU8FB99X.d.mts} +2 -2
  190. package/dist/{errors-CwKXXtuu.d.mts → errors-DfVN_FUG.d.ts} +2 -2
  191. package/dist/{index-3vJ-V9yw.d.ts → index-BGnvtYGc.d.ts} +6 -1
  192. package/dist/{index-DjwsAt82.d.mts → index-DjZgwpGw.d.mts} +6 -1
  193. package/dist/index.d.mts +28 -8
  194. package/dist/index.d.ts +28 -8
  195. package/dist/index.js +65 -40
  196. package/dist/index.mjs +33 -8
  197. package/dist/install-integrity.json +137 -130
  198. package/dist/plays/bundle-play-file.d.mts +3 -3
  199. package/dist/plays/bundle-play-file.d.ts +3 -3
  200. package/dist/plays/bundle-play-file.mjs +640 -125
  201. package/dist/plays/play-description.d.mts +3 -3
  202. package/dist/plays/play-description.d.ts +3 -3
  203. package/dist/plays/run-request.d.mts +2 -2
  204. package/dist/plays/run-request.d.ts +2 -2
  205. package/dist/release.d.mts +1 -1
  206. package/dist/release.d.ts +1 -1
  207. package/dist/release.js +2 -2
  208. package/dist/release.mjs +1 -1
  209. package/dist/server.d.mts +4 -4
  210. package/dist/server.d.ts +4 -4
  211. package/dist/server.js +11 -11
  212. package/dist/server.mjs +5 -5
  213. package/package.json +1 -1
  214. package/dist/cli/auth-455MB4K6.js +0 -43
  215. package/dist/cli/concurrent-runs-help-GFWXOKF5.js +0 -21
  216. package/dist/cli/describe-ZRGYAEBT.js +0 -50
  217. package/dist/cli/git-RC4XDATD.js +0 -25
  218. package/dist/cli/search-O5VVMXII.js +0 -32
  219. package/dist/cli/sessions-3PWFWCHO.js +0 -22
  220. package/dist/cli/skills-RFOMVXIT.js +0 -36
  221. package/dist/cli/tools-CAO6EVUW.js +0 -57
  222. package/dist/cli/update-L4DQZY3G.js +0 -34
@@ -9,6 +9,7 @@ import type {
9
9
  RuntimeSandboxProviderId,
10
10
  } from '../runtime-sandbox-provider-profile';
11
11
  import { samePlaySandboxRuntimeLimits } from './backends/daytona-payload-transport';
12
+ import type { EarlySandboxScope } from './early-sandbox-egress';
12
13
 
13
14
  /**
14
15
  * Early sandbox: the provider-neutral Module behind early start (E2), runner
@@ -97,12 +98,6 @@ export const PREBOOT_RUNNER_IN_EARLY_SANDBOX = false;
97
98
 
98
99
  /** Source tag an unadopted early sandbox carries from its create call. */
99
100
  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
101
  /** Orphan guard: an unadopted early sandbox that runs no command ends here. */
107
102
  export const EARLY_SANDBOX_IDLE_TIMEOUT_MS = 60_000;
108
103
  export const EARLY_SANDBOX_REAP_AFTER_MS = 90_000;
@@ -161,57 +156,141 @@ export type EarlySandboxEntry<TSandbox = EarlySandboxHandle> = {
161
156
  * This process's unadopted early sandboxes, by org-scoped key. `take` removes
162
157
  * the entry, so each early sandbox is handed to at most one in-process
163
158
  * adoption; an unadopted entry expires after twice the reap delay.
159
+ *
160
+ * It also counts this process's outstanding early sandboxes (`outstanding`);
161
+ * the worker lane's per-process cap reads it. One counts from `put` until the
162
+ * first of: its create fails (the entry resolves null), a launch takes it
163
+ * (adoption), the reaper or sweep settles its sandbox id (`settle`), or the
164
+ * entry's TTL. Each path releases at most once, so no path double-counts and
165
+ * an error path never leaks a slot past the TTL.
164
166
  */
165
- export class EarlySandboxRegistry<TSandbox = EarlySandboxHandle> {
167
+ export class EarlySandboxRegistry<
168
+ TSandbox extends { readonly sandboxId: string } = EarlySandboxHandle,
169
+ > {
166
170
  readonly #entries = new Map<
167
171
  string,
168
172
  Promise<EarlySandboxEntry<TSandbox> | null>
169
173
  >();
174
+ readonly #outstanding = new Set<
175
+ Promise<EarlySandboxEntry<TSandbox> | null>
176
+ >();
177
+ readonly #outstandingBySandboxId = new Map<
178
+ string,
179
+ Promise<EarlySandboxEntry<TSandbox> | null>
180
+ >();
170
181
 
171
182
  has(key: string): boolean {
172
183
  return this.#entries.has(key);
173
184
  }
174
185
 
186
+ /** This process's early sandboxes not yet adopted, reaped or expired. */
187
+ outstanding(): number {
188
+ return this.#outstanding.size;
189
+ }
190
+
175
191
  put(
176
192
  key: string,
177
193
  entry: Promise<EarlySandboxEntry<TSandbox> | null>,
178
194
  ttlMs: number = EARLY_SANDBOX_REAP_AFTER_MS * 2,
179
195
  ): void {
180
196
  this.#entries.set(key, entry);
197
+ this.#outstanding.add(entry);
198
+ void entry.then(
199
+ (resolved) => {
200
+ if (!this.#outstanding.has(entry)) return;
201
+ if (resolved === null) this.#release(entry);
202
+ else
203
+ this.#outstandingBySandboxId.set(resolved.sandbox.sandboxId, entry);
204
+ },
205
+ () => this.#release(entry),
206
+ );
181
207
  setTimeout(() => {
182
208
  if (this.#entries.get(key) === entry) this.#entries.delete(key);
209
+ this.#release(entry);
183
210
  }, ttlMs).unref?.();
184
211
  }
185
212
 
186
213
  take(key: string): Promise<EarlySandboxEntry<TSandbox> | null> | undefined {
187
214
  const entry = this.#entries.get(key);
188
215
  this.#entries.delete(key);
216
+ if (entry) this.#release(entry);
189
217
  return entry;
190
218
  }
219
+
220
+ /**
221
+ * The reaper or sweep has settled this sandbox (terminated, or found it
222
+ * adopted by a launch elsewhere): it no longer counts as outstanding. A
223
+ * sandbox id this process did not create is ignored.
224
+ */
225
+ settle(sandboxId: string): void {
226
+ const entry = this.#outstandingBySandboxId.get(sandboxId);
227
+ if (entry) this.#release(entry);
228
+ }
229
+
230
+ #release(entry: Promise<EarlySandboxEntry<TSandbox> | null>): void {
231
+ if (!this.#outstanding.delete(entry)) return;
232
+ for (const [sandboxId, held] of this.#outstandingBySandboxId) {
233
+ if (held === entry) this.#outstandingBySandboxId.delete(sandboxId);
234
+ }
235
+ }
191
236
  }
192
237
 
193
238
  /**
194
239
  * The early sandbox's key. Org-scoped: a workflow id is chosen by the caller,
195
240
  * so two orgs can name the same one; neither may find the other's sandbox.
241
+ * Environment- and egress-scoped: Preview and Production share one provider
242
+ * workspace and app, and a sandbox's network policy is fixed at its create,
243
+ * so a launch only finds a sandbox created in its own environment with its
244
+ * own outbound allowlist.
196
245
  */
197
- export function earlySandboxKey(input: {
198
- orgId: string;
199
- workflowId: string;
200
- }): string {
246
+ export function earlySandboxKey(
247
+ input: {
248
+ orgId: string;
249
+ workflowId: string;
250
+ } & EarlySandboxScope,
251
+ ): string {
201
252
  return createHash('sha256')
202
- .update(JSON.stringify([input.orgId, input.workflowId]))
253
+ .update(
254
+ JSON.stringify([
255
+ input.orgId,
256
+ input.workflowId,
257
+ input.environment,
258
+ input.egressKey,
259
+ ]),
260
+ )
203
261
  .digest('hex')
204
262
  .slice(0, 40);
205
263
  }
206
264
 
265
+ /** Environment and egress-policy tags, set at create, checked at adoption. */
266
+ export const EARLY_ENVIRONMENT_TAG = 'earlyEnvironment';
267
+ export const EARLY_EGRESS_KEY_TAG = 'egressKey';
268
+
269
+ export type EarlySandboxIdentityRefusal =
270
+ | 'environment_mismatch'
271
+ | 'egress_mismatch'
272
+ | 'key_mismatch'
273
+ | 'org_mismatch'
274
+ | 'workflow_mismatch';
275
+
207
276
  /**
208
277
  * Why an early sandbox's tags do not belong to this launch's run, or null.
209
278
  * Checked on every adoption path, before the sandbox is re-tagged or used.
279
+ * A sandbox without the environment or egress tag (created before they
280
+ * existed) is refused.
210
281
  */
211
282
  export function earlySandboxIdentityRefusal(
212
283
  tags: Record<string, string>,
213
- expected: { key: string; orgId: string; workflowId: string },
214
- ): 'key_mismatch' | 'org_mismatch' | 'workflow_mismatch' | null {
284
+ expected: {
285
+ key: string;
286
+ orgId: string;
287
+ workflowId: string;
288
+ } & EarlySandboxScope,
289
+ ): EarlySandboxIdentityRefusal | null {
290
+ if (tags[EARLY_ENVIRONMENT_TAG] !== expected.environment)
291
+ return 'environment_mismatch';
292
+ if (tags[EARLY_EGRESS_KEY_TAG] !== expected.egressKey)
293
+ return 'egress_mismatch';
215
294
  if (tags.earlyKey !== expected.key) return 'key_mismatch';
216
295
  if (tags.orgId !== expected.orgId) return 'org_mismatch';
217
296
  if (tags.workflowId !== expected.workflowId) return 'workflow_mismatch';
@@ -232,26 +311,31 @@ export function earlySandboxAgeMs(
232
311
  export function earlySandboxLimitsKey(input: {
233
312
  cpu: number;
234
313
  memoryMiB: number;
314
+ memoryLimitMiB: number;
235
315
  timeoutMs: number;
236
316
  }): string {
237
- return `${input.cpu}:${input.memoryMiB}:${input.timeoutMs}`;
317
+ return `${input.cpu}:${input.memoryMiB}:${input.memoryLimitMiB}:${input.timeoutMs}`;
238
318
  }
239
319
 
240
320
  /** 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> {
321
+ export function earlySandboxCreateTags(
322
+ input: {
323
+ key: string;
324
+ orgId: string;
325
+ workflowId: string;
326
+ createRequestedAtMs: number;
327
+ limitsKey: string;
328
+ preboot: boolean;
329
+ } & EarlySandboxScope,
330
+ ): Record<string, string> {
249
331
  return {
250
332
  source: EARLY_SANDBOX_SOURCE_TAG,
251
333
  earlyKey: input.key,
252
334
  // Identity, checked at adoption against the launching run.
253
335
  orgId: input.orgId,
254
336
  workflowId: input.workflowId,
337
+ [EARLY_ENVIRONMENT_TAG]: input.environment,
338
+ [EARLY_EGRESS_KEY_TAG]: input.egressKey,
255
339
  [EARLY_CREATED_AT_TAG]: String(input.createRequestedAtMs),
256
340
  limitsKey: input.limitsKey,
257
341
  ...(input.preboot ? { [EARLY_PREBOOT_TAG]: '1' } : {}),
@@ -314,9 +398,15 @@ export type EarlySandboxAdapter<
314
398
  * provider precondition), or null. Checked after E2 resolves on; not logged.
315
399
  */
316
400
  startUnavailable(): string | null;
401
+ /**
402
+ * The environment and egress policy this process's early create would
403
+ * carry; part of the key. Called only after `startUnavailable` is null.
404
+ */
405
+ scope(input: EarlySandboxStartRequest): EarlySandboxScope;
317
406
  /**
318
407
  * Create the early sandbox with `earlySandboxCreateTags`, then arm it: the
319
- * exact-id reaper (`scheduleEarlySandboxReap`) and any pre-boot hook.
408
+ * exact-id reaper (`scheduleEarlySandboxReap`) and any pre-boot hook. Its
409
+ * create must carry exactly `scope`; it rejects otherwise.
320
410
  * Rejects on any failure; the caller logs it and records no entry.
321
411
  */
322
412
  createEarly(
@@ -324,6 +414,7 @@ export type EarlySandboxAdapter<
324
414
  key: string;
325
415
  orgId: string;
326
416
  hintAtMs: number;
417
+ scope: EarlySandboxScope;
327
418
  },
328
419
  ): Promise<EarlySandboxEntry<TSandbox>>;
329
420
  /** The durable orphan sweep pass this worker runs for the provider. */
@@ -356,19 +447,28 @@ export function startEarlySandbox<TSandbox extends EarlySandboxHandle>(
356
447
  logEarlySandbox(adapter.logScope, 'hint_refused', { reason: 'no_org' });
357
448
  return false;
358
449
  }
359
- const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
450
+ const scope = adapter.scope(input);
451
+ const key = earlySandboxKey({
452
+ orgId,
453
+ workflowId: input.workflowId,
454
+ ...scope,
455
+ });
360
456
  if (adapter.registry.has(key)) return false;
361
457
  const hintAtMs = Date.now();
362
458
  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
- );
459
+ await adapter.createEarly({
460
+ ...input,
461
+ key,
462
+ orgId,
463
+ hintAtMs,
464
+ scope,
465
+ }))().catch((error: unknown) => {
466
+ logEarlySandbox(adapter.logScope, 'create_failed', {
467
+ key,
468
+ error: error instanceof Error ? error.message : String(error),
469
+ });
470
+ return null;
471
+ });
372
472
  adapter.registry.put(key, started);
373
473
  logEarlySandbox(adapter.logScope, 'hint_accepted', {
374
474
  key,
@@ -418,17 +518,12 @@ export const readEarlySandboxExitCode =
418
518
  async (sandboxId: string) =>
419
519
  await (await calls.fromId(sandboxId)).poll();
420
520
 
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
- );
521
+ export function isUnadoptedEarlySandbox(tags: Record<string, string>): boolean {
522
+ return tags.source === EARLY_SANDBOX_SOURCE_TAG;
428
523
  }
429
524
 
430
525
  /**
431
- * Reap one early (or hedge) sandbox by exact id if it is still unadopted: a
526
+ * Reap one early sandbox by exact id if it is still unadopted: a
432
527
  * fresh tag read (an adopted sandbox carries ordinary launch tags), then a
433
528
  * confirmed termination. An unconfirmed one keeps its early tag, so the
434
529
  * durable sweep (sweepOrphanEarlySandboxes) still finds it.
@@ -458,7 +553,7 @@ export async function reapEarlySandboxById(input: {
458
553
 
459
554
  /**
460
555
  * 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
556
+ * sandbox (confirmed) if it still carries the early source tag, i.e. no
462
557
  * launch adopted it. The fast path only: the durable guarantee is the early
463
558
  * tag itself, set by the create call, which the worker's sweep reads even
464
559
  * after this process is gone.
@@ -467,25 +562,33 @@ export function scheduleEarlySandboxReap(input: {
467
562
  calls: Pick<EarlySandboxProviderCalls, 'fromId' | 'logScope'>;
468
563
  key: string;
469
564
  sandboxId: string;
565
+ /**
566
+ * The registry counting this sandbox as outstanding: settled once the reap
567
+ * terminates it or finds it adopted. An unconfirmed reap leaves it counted
568
+ * until its entry's TTL (the sandbox may still be alive).
569
+ */
570
+ registry?: Pick<EarlySandboxRegistry, 'settle'>;
470
571
  }): void {
471
572
  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
- );
573
+ void reapEarlySandboxById(input)
574
+ .then(() => input.registry?.settle(input.sandboxId))
575
+ .catch((error: unknown) =>
576
+ logEarlySandboxReapUnconfirmed({
577
+ logScope: input.calls.logScope,
578
+ event: 'reap_unconfirmed',
579
+ key: input.key,
580
+ sandboxId: input.sandboxId,
581
+ error,
582
+ }),
583
+ );
481
584
  }, EARLY_SANDBOX_REAP_AFTER_MS);
482
585
  reap.unref?.();
483
586
  }
484
587
 
485
588
  /**
486
- * Durable orphan cleanup for E2/PB early sandboxes (and retired F2 legs). The
589
+ * Durable orphan cleanup for E2/PB early sandboxes. The
487
590
  * cleanup obligation is recorded before (atomically with) every early create:
488
- * the create request itself carries the early (or hedge) source tag and its
591
+ * the create request itself carries the early source tag and its
489
592
  * create time, and the provider holds those tags for the sandbox's life. The
490
593
  * main path's ambiguous-create row cannot be used here: the hint arrives
491
594
  * before the run is enqueued, so there is no run row or attempt lease to
@@ -500,6 +603,8 @@ export function scheduleEarlySandboxReap(input: {
500
603
  * pass keeps its tag and is retried by the next.
501
604
  */
502
605
  export const EARLY_SANDBOX_SWEEP_INTERVAL_MS = 60_000;
606
+ /** ±20% per interval, and a first pass in [0, 40%] of it. */
607
+ export const EARLY_SANDBOX_SWEEP_JITTER_RATIO = 0.2;
503
608
  const EARLY_SANDBOX_SWEEP_LIMIT = 20;
504
609
  const EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS = 5;
505
610
 
@@ -512,6 +617,16 @@ export type EarlySandboxSweepOutcome = {
512
617
 
513
618
  export async function sweepOrphanEarlySandboxes(input: {
514
619
  calls: EarlySandboxProviderCalls;
620
+ /**
621
+ * This process's registry: a sandbox it created that this pass terminates,
622
+ * or finds adopted, stops counting as outstanding.
623
+ */
624
+ registry?: Pick<EarlySandboxRegistry, 'settle'>;
625
+ /**
626
+ * Only this environment's early sandboxes: Preview and Production share
627
+ * one provider workspace and app, and neither reaps the other's.
628
+ */
629
+ environment: EarlySandboxScope['environment'];
515
630
  nowMs?: () => number;
516
631
  sleep?: (ms: number) => Promise<void>;
517
632
  limit?: number;
@@ -519,11 +634,14 @@ export async function sweepOrphanEarlySandboxes(input: {
519
634
  const nowMs = input.nowMs ?? Date.now;
520
635
  const limit = input.limit ?? EARLY_SANDBOX_SWEEP_LIMIT;
521
636
  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
- }
637
+ // One listing: the retired F2 hedge tag is no longer swept (nothing
638
+ // creates it, and no hedge leg ever carried an environment tag).
639
+ for await (const listed of input.calls.list({
640
+ source: EARLY_SANDBOX_SOURCE_TAG,
641
+ [EARLY_ENVIRONMENT_TAG]: input.environment,
642
+ })) {
643
+ if (ids.size >= limit) break;
644
+ if (listed.sandboxId?.trim()) ids.add(listed.sandboxId.trim());
527
645
  }
528
646
  let terminated = 0;
529
647
  let unconfirmed = 0;
@@ -533,7 +651,11 @@ export async function sweepOrphanEarlySandboxes(input: {
533
651
  try {
534
652
  const fresh = await input.calls.fromId(sandboxId);
535
653
  const tags = await fresh.getTags();
536
- if (!isUnadoptedEarlySandbox(tags)) return;
654
+ if (!isUnadoptedEarlySandbox(tags)) {
655
+ input.registry?.settle(sandboxId);
656
+ return;
657
+ }
658
+ if (tags[EARLY_ENVIRONMENT_TAG] !== input.environment) return;
537
659
  const ageMs = earlySandboxAgeMs(tags, nowMs());
538
660
  // A sandbox without a create time predates the tag and is past any
539
661
  // adoption (adoption refuses it), so it is reaped.
@@ -548,6 +670,7 @@ export async function sweepOrphanEarlySandboxes(input: {
548
670
  attempts: EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS,
549
671
  });
550
672
  terminated += 1;
673
+ input.registry?.settle(sandboxId);
551
674
  logEarlySandbox(input.calls.logScope, 'swept_orphan', {
552
675
  key: tags.earlyKey ?? null,
553
676
  sandboxId,
@@ -641,6 +764,11 @@ export async function adoptEarlySandbox<
641
764
  orgId: string | null | undefined;
642
765
  runId: string | null | undefined;
643
766
  experimentSwitchOverrides: ExperimentSwitchOverrides | null | undefined;
767
+ /**
768
+ * This launch's environment and the egress key of the create it would
769
+ * otherwise make; only an early sandbox created with both is adopted.
770
+ */
771
+ scope: EarlySandboxScope;
644
772
  expectedLimitsKey: string;
645
773
  createTags: Record<string, string>;
646
774
  /** PB: whether this launch wants a pre-booted runner, and its limits. */
@@ -660,7 +788,9 @@ export async function adoptEarlySandbox<
660
788
  * A1 hook: settles once a tag that makes every other process refuse to
661
789
  * adopt the sandbox is on it at the provider.
662
790
  */
663
- inProcessForeignAdoptionClaim(sandbox: TSandbox): Promise<unknown> | undefined;
791
+ inProcessForeignAdoptionClaim(
792
+ sandbox: TSandbox,
793
+ ): Promise<unknown> | undefined;
664
794
  /** The launch's stage events (`early:adopted`, `early:adopt_miss`). */
665
795
  emitStage(stage: string, extra: Record<string, unknown>): void;
666
796
  nowMs?: () => number;
@@ -675,7 +805,11 @@ export async function adoptEarlySandbox<
675
805
  });
676
806
  return null;
677
807
  }
678
- const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
808
+ const key = earlySandboxKey({
809
+ orgId,
810
+ workflowId: input.workflowId,
811
+ ...input.scope,
812
+ });
679
813
  const registry = input.registry;
680
814
  let sandbox: TSandbox | null = null;
681
815
  let localEntry: EarlySandboxEntry<TSandbox> | null = null;
@@ -733,10 +867,12 @@ export async function adoptEarlySandbox<
733
867
  key,
734
868
  orgId,
735
869
  workflowId: input.workflowId,
870
+ ...input.scope,
736
871
  });
737
872
  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.
873
+ // Never expected: the key already names this org, workflow,
874
+ // environment and egress policy. Loud, and the sandbox is left
875
+ // untouched for its own reaper.
740
876
  console.error(
741
877
  JSON.stringify({
742
878
  event: `${input.calls.logScope}.adopt_refused_identity`,
@@ -26,9 +26,10 @@ export const RUNTIME_CAPACITY_POLICY = {
26
26
  */
27
27
  maxActiveLaneMachines: 8,
28
28
  /**
29
- * Shared started/pending worker budget across every release lane. Existing
30
- * claim owners and rollback holds are retained; restoring the active warm
31
- * floor may temporarily exceed this budget without forcing any worker off.
29
+ * Started/pending worker budget shared by historical (draining) release
30
+ * lanes, counted over their own Machines. The active lane grows against
31
+ * maxActiveLaneMachines instead, so draining lanes cannot hold new runs at
32
+ * the warm floor. Existing claim owners and rollback holds are retained.
32
33
  */
33
34
  maxFleetMachines: 8,
34
35
  workerSlotsPerMachine: 8,
@@ -44,7 +45,7 @@ export const RUNTIME_CAPACITY_POLICY = {
44
45
  * boots it in about 1.3 s, against about 12 s for a new Machine, which
45
46
  * waits for its app-scoped static egress IP before it can reach the
46
47
  * database (16% of fresh boots crashed on that wait, 2026-11-10/11).
47
- * Six is the whole burst headroom (maxFleetMachines - activeLaneMachines);
48
+ * Six is the whole burst headroom (maxActiveLaneMachines - activeLaneMachines);
48
49
  * 99% of 161 Production bursts added at most six Machines in their first
49
50
  * minute. More could never start at once inside the fleet budget. Fly
50
51
  * bills a stopped Machine's rootfs at $0.15 per GB-month.
@@ -169,13 +170,23 @@ export function desiredAbsurdLaneMachines(input: {
169
170
  * not free budget until Fly confirms them. This function never removes workers.
170
171
  *
171
172
  * Restore the active warm floor first, even when that reports budget debt.
172
- * Give freed budget to historical runnable lanes in round-robin order before
173
- * active burst growth. Persist nextCursor between reconciliations so repeated
173
+ * Historical runnable lanes share maxFleetMachines (counted over their own
174
+ * Machines) in round-robin order; the active lane grows to
175
+ * maxActiveLaneMachines (counted over its own Machines). Neither partition can
176
+ * starve the other. Persist nextCursor between reconciliations so repeated
174
177
  * single-slot openings do not always favor the first historical release.
175
178
  */
176
179
  export function planAbsurdWorkerFleetGrowth(input: {
177
180
  existingMachines: number;
181
+ /**
182
+ * Started and pending Machines on the active release lane, out of
183
+ * existingMachines. The active lane grows against maxActiveLaneMachines and
184
+ * historical lanes against maxFleetMachines, each counting only its own
185
+ * Machines, so neither can starve the other.
186
+ */
187
+ activeLaneMachines: number;
178
188
  maxFleetMachines?: number;
189
+ maxActiveLaneMachines?: number;
179
190
  activeWarmFloorMissing: number;
180
191
  demands: readonly {
181
192
  releaseId: string;
@@ -203,6 +214,17 @@ export function planAbsurdWorkerFleetGrowth(input: {
203
214
  const maxFleetMachines = requireMachineCount(
204
215
  input.maxFleetMachines ?? RUNTIME_CAPACITY_POLICY.absurd.maxFleetMachines,
205
216
  );
217
+ const maxActiveLaneMachines = requireMachineCount(
218
+ input.maxActiveLaneMachines ??
219
+ RUNTIME_CAPACITY_POLICY.absurd.maxActiveLaneMachines,
220
+ );
221
+ const activeLaneMachines = requireMachineCount(input.activeLaneMachines);
222
+ if (activeLaneMachines > physicalCount) {
223
+ throw new Error(
224
+ 'Active-lane Machines cannot exceed the physical worker fleet.',
225
+ );
226
+ }
227
+ const historicalPhysicalCount = physicalCount - activeLaneMachines;
206
228
  const warmFloorMissing = requireMachineCount(input.activeWarmFloorMissing);
207
229
  const cursor = input.cursor ?? '';
208
230
  if (typeof cursor !== 'string') {
@@ -259,10 +281,10 @@ export function planAbsurdWorkerFleetGrowth(input: {
259
281
  activeLane?.remaining ?? 0,
260
282
  );
261
283
  for (let seat = 0; seat < warmFloorGrowth; seat += 1) grant(activeLane!);
262
- let available = Math.max(
263
- 0,
264
- maxFleetMachines - physicalCount - warmFloorGrowth,
265
- );
284
+ // Historical lanes share maxFleetMachines, counted over their own Machines.
285
+ // On 2026-11-18 one shared budget let nine draining lanes (18 Machines) hold
286
+ // the active lane at its 2-Machine warm floor, and new runs queued 6-12 s.
287
+ let available = Math.max(0, maxFleetMachines - historicalPhysicalCount);
266
288
  const historical = lanes
267
289
  .filter((lane) => !lane.demand.active && lane.remaining > 0)
268
290
  .sort((a, b) =>
@@ -294,27 +316,43 @@ export function planAbsurdWorkerFleetGrowth(input: {
294
316
  }
295
317
  index = (index + 1) % historical.length;
296
318
  }
297
- while (available > 0 && activeLane && activeLane.remaining > 0) {
319
+ // The active lane grows against its own cap, after its warm floor.
320
+ let activeAvailable = Math.max(
321
+ 0,
322
+ maxActiveLaneMachines - activeLaneMachines - warmFloorGrowth,
323
+ );
324
+ while (activeAvailable > 0 && activeLane && activeLane.remaining > 0) {
298
325
  grant(activeLane);
299
- available -= 1;
326
+ activeAvailable -= 1;
300
327
  }
301
328
  let allocatedCount = 0;
329
+ let activeAllocated = 0;
302
330
  let deferredCount = 0;
303
331
  const allocations = lanes.map((lane) => {
304
- allocatedCount +=
332
+ const laneAllocated =
305
333
  lane.allocation.startMachineIds.length + lane.allocation.createCount;
334
+ allocatedCount += laneAllocated;
335
+ if (lane.demand.active) activeAllocated += laneAllocated;
306
336
  deferredCount += lane.remaining;
307
337
  return { ...lane.allocation, deferredCount: lane.remaining };
308
338
  });
309
339
  const projectedPhysicalCount = requireMachineCount(
310
340
  physicalCount + allocatedCount,
311
341
  );
342
+ const historicalAllocated = allocatedCount - activeAllocated;
312
343
  return {
313
344
  allocations,
314
345
  nextCursor,
315
346
  physicalCount,
316
347
  projectedPhysicalCount,
317
- budgetDebt: Math.max(0, projectedPhysicalCount - maxFleetMachines),
348
+ // Debt is reported per partition; the warm floor may exceed the active
349
+ // cap only when protected capacity already fills it.
350
+ budgetDebt:
351
+ Math.max(
352
+ 0,
353
+ historicalPhysicalCount + historicalAllocated - maxFleetMachines,
354
+ ) +
355
+ Math.max(0, activeLaneMachines + activeAllocated - maxActiveLaneMachines),
318
356
  deferredCount,
319
357
  warmFloorGrowth,
320
358
  maxFleetMachines,
@@ -9,8 +9,10 @@
9
9
  * the profile's switch map into the launch's existing optional
10
10
  * `experimentSwitchOverrides` field, which Production workers, the
11
11
  * executor-token route and the Modal backend already read. The profile id is
12
- * also stamped as `runtimeSpeedProfile`, for attribution only: no reader
13
- * branches on it.
12
+ * also stamped as `runtimeSpeedProfile`. No reader resolves a switch from it;
13
+ * the worker relays it to the executor-token route, which accepts the
14
+ * profile's exact frozen map without the experiment-override capability
15
+ * (`admittedRuntimeSpeedProfileForCarriedOverrides`).
14
16
  *
15
17
  * Every claim, resume and recovery re-reads the durable launch, never the
16
18
  * rollout, so a run keeps the switch values it was admitted with. A worker
@@ -134,3 +136,64 @@ export function applyRuntimeSpeedProfile(
134
136
  ...(explicitOverrides ?? {}),
135
137
  };
136
138
  }
139
+
140
+ /**
141
+ * True when `value` is exactly this profile's frozen switch map: the same
142
+ * switch ids, the same values, and nothing else.
143
+ */
144
+ export function isRuntimeSpeedProfileSwitchMap(
145
+ profileId: RuntimeSpeedProfileId,
146
+ value: unknown,
147
+ ): boolean {
148
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
149
+ return false;
150
+ }
151
+ const expected: Readonly<Record<string, boolean>> =
152
+ RUNTIME_SPEED_PROFILES[profileId].switches;
153
+ const carried = value as Record<string, unknown>;
154
+ const carriedIds = Object.keys(carried);
155
+ const expectedIds = Object.keys(expected);
156
+ return (
157
+ carriedIds.length === expectedIds.length &&
158
+ expectedIds.every(
159
+ (id) =>
160
+ Object.prototype.hasOwnProperty.call(carried, id) &&
161
+ carried[id] === expected[id],
162
+ )
163
+ );
164
+ }
165
+
166
+ /**
167
+ * The profile whose admission decision produced overrides a worker relays,
168
+ * or null when the overrides are anything else.
169
+ *
170
+ * Admission is the only Production writer of a profile's map (the rollout
171
+ * grants it; explicit overrides are refused there), so an exact frozen map is
172
+ * proof of that decision and grants nothing admission could not. A carried map
173
+ * that differs in any id or value, or that names an unknown profile, is not a
174
+ * profile decision and stays behind the `play_run.experiment_switch_overrides`
175
+ * capability.
176
+ *
177
+ * `relayedProfileId` is absent from workers that predate the relay. They are
178
+ * matched against every registered map, which is no wider: each map is frozen
179
+ * and reachable in Production only through the rollout.
180
+ */
181
+ export function admittedRuntimeSpeedProfileForCarriedOverrides(input: {
182
+ relayedProfileId: unknown;
183
+ overrides: unknown;
184
+ }): RuntimeSpeedProfileId | null {
185
+ if (input.relayedProfileId !== undefined && input.relayedProfileId !== null) {
186
+ return isRuntimeSpeedProfileId(input.relayedProfileId) &&
187
+ isRuntimeSpeedProfileSwitchMap(input.relayedProfileId, input.overrides)
188
+ ? input.relayedProfileId
189
+ : null;
190
+ }
191
+ for (const profileId of Object.keys(
192
+ RUNTIME_SPEED_PROFILES,
193
+ ) as RuntimeSpeedProfileId[]) {
194
+ if (isRuntimeSpeedProfileSwitchMap(profileId, input.overrides)) {
195
+ return profileId;
196
+ }
197
+ }
198
+ return null;
199
+ }