deepline 0.3.545 → 0.3.546

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/bundling-sources/sdk/src/errors.ts +1 -1
  2. package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
  3. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  4. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +2 -2
  5. package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
  6. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +4 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +8 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +40 -3
  10. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
  15. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +32 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +30 -2
  20. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +30 -1
  21. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +35 -2
  22. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +35 -1
  23. package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
  24. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +2 -0
  25. package/dist/cli/{auth-VZAMAMFW.mjs → auth-KFWG72AZ.mjs} +6 -6
  26. package/dist/cli/auth-W32GMYND.js +43 -0
  27. package/dist/cli/{billing-DADQUQEZ.mjs → billing-MMZ336HO.mjs} +10 -10
  28. package/dist/cli/{billing-ASZJDFH2.js → billing-OQVOAZ4S.js} +98 -98
  29. package/dist/cli/{chunk-HLUNTJBO.mjs → chunk-3DUNNZB6.mjs} +4 -4
  30. package/dist/cli/{chunk-YRQKRQDU.js → chunk-4AZLGNXV.js} +36 -26
  31. package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-5OEFXAKP.mjs} +5 -1
  32. package/dist/cli/{chunk-ERLW6RPA.js → chunk-5V7NZKGG.js} +2 -2
  33. package/dist/cli/{chunk-34UKDHRL.js → chunk-5VNQMVCU.js} +26 -26
  34. package/dist/cli/{chunk-DZTVDL2X.js → chunk-5W4ENHWM.js} +12 -12
  35. package/dist/cli/{chunk-7JZ27AFH.mjs → chunk-6FBDTYR2.mjs} +2 -2
  36. package/dist/cli/{chunk-QM7PHHYZ.js → chunk-6LG7MLJ2.js} +44 -44
  37. package/dist/cli/{chunk-7MFATEUC.mjs → chunk-6Y5TU3R7.mjs} +2 -2
  38. package/dist/cli/{chunk-52C6W7FG.mjs → chunk-7MY7KWJS.mjs} +1 -1
  39. package/dist/cli/{chunk-7P72EGLK.mjs → chunk-7ZW67ME6.mjs} +1 -1
  40. package/dist/cli/{chunk-TQKHXMV3.js → chunk-BTFUAGHC.js} +16 -16
  41. package/dist/cli/{chunk-LWPFMYSO.mjs → chunk-EEG46QZY.mjs} +2 -2
  42. package/dist/cli/{chunk-NCX2JH2F.js → chunk-EEJHB76U.js} +9 -9
  43. package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
  44. package/dist/cli/{chunk-DGKDCZGC.js → chunk-F2VEFMU5.js} +13 -13
  45. package/dist/cli/{chunk-4JQEAYN3.js → chunk-F5YQXCP3.js} +5 -1
  46. package/dist/cli/{chunk-2CBX43LP.mjs → chunk-GOOF7E2B.mjs} +5 -5
  47. package/dist/cli/{chunk-YWTRCKGD.mjs → chunk-GYTSDSQD.mjs} +11 -11
  48. package/dist/cli/{chunk-G5TV6WLV.js → chunk-H7Q5IDO3.js} +19 -19
  49. package/dist/cli/{chunk-3TCHX7YK.mjs → chunk-HJR2DDJS.mjs} +2 -2
  50. package/dist/cli/{chunk-OGQYAJSO.js → chunk-IVWU7SJC.js} +5 -5
  51. package/dist/cli/{chunk-XGEUPU3L.mjs → chunk-J65HJCJO.mjs} +2 -2
  52. package/dist/cli/{chunk-Z4Y4BLW7.mjs → chunk-JA633HRV.mjs} +3 -3
  53. package/dist/cli/{chunk-LTCEZWPZ.mjs → chunk-JARZ47OP.mjs} +2 -2
  54. package/dist/cli/{chunk-5YYWZ43J.js → chunk-JCH4UNNS.js} +2 -2
  55. package/dist/cli/{chunk-7MHBJU73.js → chunk-JCWNF44W.js} +22 -22
  56. package/dist/cli/{chunk-C6XYSTBW.js → chunk-JVOUQFHT.js} +1 -1
  57. package/dist/cli/{chunk-HR5BT42R.js → chunk-JYG4XZLT.js} +99 -99
  58. package/dist/cli/{chunk-KYO2FICL.mjs → chunk-K2XELBPF.mjs} +5 -5
  59. package/dist/cli/{chunk-2HFSYH7V.mjs → chunk-KUK7ARXA.mjs} +2 -2
  60. package/dist/cli/{chunk-WP36UBRY.mjs → chunk-LHE2TSV6.mjs} +1 -1
  61. package/dist/cli/{chunk-N4LADLCO.js → chunk-LIJKRDDG.js} +6 -6
  62. package/dist/cli/{chunk-KRW727W6.mjs → chunk-LX2TC3HO.mjs} +4 -4
  63. package/dist/cli/{chunk-QI57XUGA.js → chunk-MEGHIX4M.js} +5 -5
  64. package/dist/cli/{chunk-Z7QM244Q.mjs → chunk-MI7X6V6V.mjs} +3 -3
  65. package/dist/cli/{chunk-CJ7DBYEQ.js → chunk-MXQP7CXZ.js} +8 -8
  66. package/dist/cli/{chunk-GFRJU2KB.js → chunk-ND7SFRQL.js} +2 -2
  67. package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
  68. package/dist/cli/{chunk-GWDPNOA7.mjs → chunk-OAKWSLKS.mjs} +2 -2
  69. package/dist/cli/{chunk-XBYQZEUE.mjs → chunk-P7A3H6G5.mjs} +1 -1
  70. package/dist/cli/{chunk-NZDZGK35.js → chunk-PMDHY2YK.js} +7 -7
  71. package/dist/cli/{chunk-4NZ3OZNO.mjs → chunk-PU3ZAG6V.mjs} +1 -1
  72. package/dist/cli/{chunk-3M2QH3KA.mjs → chunk-RO66FPTS.mjs} +22 -12
  73. package/dist/cli/{chunk-3NG43NXB.js → chunk-SH32HL7I.js} +53 -53
  74. package/dist/cli/{chunk-IYJO3RWR.js → chunk-SYTWWVIQ.js} +5 -5
  75. package/dist/cli/{chunk-FB7UPZ6M.js → chunk-TBWYZOSV.js} +3 -3
  76. package/dist/cli/{chunk-CXETRZ3G.js → chunk-UQJBV5PM.js} +10 -10
  77. package/dist/cli/{chunk-HPX7LLAM.mjs → chunk-UREAIHUU.mjs} +2 -2
  78. package/dist/cli/{chunk-2FF3O2Y2.js → chunk-VAT2SXFF.js} +12 -12
  79. package/dist/cli/{chunk-NAN3A4IF.mjs → chunk-VPERQ3U6.mjs} +5 -5
  80. package/dist/cli/{chunk-XMUPZINS.mjs → chunk-VTK3HGMN.mjs} +5 -5
  81. package/dist/cli/{chunk-JL5JU3LD.mjs → chunk-VXTTAYOT.mjs} +2 -2
  82. package/dist/cli/{chunk-EK5C2R7S.js → chunk-WKHPLBJK.js} +15 -15
  83. package/dist/cli/{chunk-EWA3M54M.mjs → chunk-X5KOHDJN.mjs} +1 -1
  84. package/dist/cli/{chunk-D3SXB2NX.js → chunk-Z3UEBFIN.js} +41 -41
  85. package/dist/cli/command-docs.js +2 -2
  86. package/dist/cli/command-docs.mjs +1 -1
  87. package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +21 -0
  88. package/dist/cli/{concurrent-runs-help-YP7ALTDB.mjs → concurrent-runs-help-C2O5YKQA.mjs} +7 -7
  89. package/dist/cli/{csv-67WT5EGR.js → csv-MJDNOIQJ.js} +14 -14
  90. package/dist/cli/{csv-D5ITFSYI.mjs → csv-Z4DNGR54.mjs} +5 -5
  91. package/dist/cli/{db-SZYBRFYG.mjs → db-4RL2BNOF.mjs} +7 -7
  92. package/dist/cli/{db-GZS76X7R.js → db-S5QVPK5E.js} +32 -32
  93. package/dist/cli/{describe-YJ7ZLLLI.mjs → describe-L4P5SZLQ.mjs} +19 -19
  94. package/dist/cli/describe-VLU2LUDJ.js +50 -0
  95. package/dist/cli/describe-core.d.mts +3 -3
  96. package/dist/cli/describe-core.d.ts +3 -3
  97. package/dist/cli/describe-core.js +1 -1
  98. package/dist/cli/describe-core.mjs +1 -1
  99. package/dist/cli/{executions-O5USTYGL.js → executions-MFZ2Z36O.js} +9 -9
  100. package/dist/cli/{executions-HMYGR32E.mjs → executions-RR6O3XK5.mjs} +7 -7
  101. package/dist/cli/{feedback-Z3NXWYUO.mjs → feedback-EQBQ3ABB.mjs} +7 -7
  102. package/dist/cli/{feedback-RHLFDCRS.js → feedback-YDAG7VH2.js} +15 -15
  103. package/dist/cli/git-E6W44F5M.js +25 -0
  104. package/dist/cli/{git-CLFKXELB.mjs → git-YGLCCU35.mjs} +6 -6
  105. package/dist/cli/index.js +150 -150
  106. package/dist/cli/index.mjs +46 -46
  107. package/dist/cli/{integrations-FOACOBQB.mjs → integrations-FWYXSBHK.mjs} +8 -8
  108. package/dist/cli/{integrations-TZ4QEQGV.js → integrations-IQXYMRMW.js} +16 -16
  109. package/dist/cli/{legacy-noops-6F6Y3BV7.mjs → legacy-noops-I4YRIX5F.mjs} +7 -7
  110. package/dist/cli/{legacy-noops-QRDOS33V.js → legacy-noops-U7LI7UXC.js} +10 -10
  111. package/dist/cli/{mcp-ETMMDDGB.js → mcp-GX2UKKWU.js} +25 -25
  112. package/dist/cli/{mcp-UXRCWOZU.mjs → mcp-QJBMB6VS.mjs} +5 -5
  113. package/dist/cli/{monitors-DITT7QTV.js → monitors-WCJYINGX.js} +102 -102
  114. package/dist/cli/{monitors-6XEWR46R.mjs → monitors-Z6EGKYJP.mjs} +8 -8
  115. package/dist/cli/{org-4DE37X3L.js → org-7SKG423N.js} +89 -89
  116. package/dist/cli/{org-CVSSH73G.mjs → org-NNHICBR2.mjs} +7 -7
  117. package/dist/cli/{play-RH6P45CI.js → play-4P4DTG3Q.js} +318 -318
  118. package/dist/cli/{play-Y5NCHOKK.mjs → play-CXDFPJ7Z.mjs} +18 -18
  119. package/dist/cli/{providers-DU42DLOL.js → providers-EE4TUE3O.js} +10 -10
  120. package/dist/cli/{providers-VHUHC4IZ.mjs → providers-VQLQ7DTR.mjs} +7 -7
  121. package/dist/cli/{quickstart-HJY5YYE5.mjs → quickstart-IYNJRB5G.mjs} +5 -5
  122. package/dist/cli/{quickstart-XJ43JLEC.js → quickstart-RVXHK4WA.js} +7 -7
  123. package/dist/cli/{run-JXUS7QFI.js → run-R3F34KU3.js} +44 -44
  124. package/dist/cli/{run-JAIXHVH7.mjs → run-VBQPPMEX.mjs} +24 -24
  125. package/dist/cli/{search-RDMNM2AX.mjs → search-B7R62HX5.mjs} +8 -8
  126. package/dist/cli/search-UUVFXZRA.js +32 -0
  127. package/dist/cli/{search-output-ZKTR3WTJ.mjs → search-output-LNQQXIGZ.mjs} +5 -5
  128. package/dist/cli/{search-output-RKAM2HBH.js → search-output-LWHWEPOT.js} +7 -7
  129. package/dist/cli/{secrets-WSW3FTF6.mjs → secrets-NM3VAJLO.mjs} +7 -7
  130. package/dist/cli/{secrets-TKFVMAYX.js → secrets-QBOZ7WTD.js} +16 -16
  131. package/dist/cli/sessions-K3PD73Q2.js +22 -0
  132. package/dist/cli/{sessions-724BK6VP.mjs → sessions-R5BSIJ4I.mjs} +7 -7
  133. package/dist/cli/{settings-5LJZDAZU.js → settings-POYWKNRD.js} +86 -86
  134. package/dist/cli/{settings-YRC7J75G.mjs → settings-S4PN7WLY.mjs} +13 -13
  135. package/dist/cli/{setup-STNPX5MK.mjs → setup-PFLXVBTL.mjs} +10 -10
  136. package/dist/cli/{setup-2F3DBSOS.js → setup-VHB4Z654.js} +50 -50
  137. package/dist/cli/skills-QNE2EYT3.js +36 -0
  138. package/dist/cli/{skills-D5PK56FO.mjs → skills-W2TELEU7.mjs} +8 -8
  139. package/dist/cli/tools-3RLI4HGF.js +57 -0
  140. package/dist/cli/{tools-WOGWMBA3.mjs → tools-M4FA6N3Y.mjs} +18 -18
  141. package/dist/cli/update-UT6KIW2W.js +34 -0
  142. package/dist/cli/{update-PC6XSWMI.mjs → update-W7LIHEA7.mjs} +10 -10
  143. package/dist/cli/{views-HLCLAPWN.js → views-DJXAGD7V.js} +22 -22
  144. package/dist/cli/{views-IIHT4RYQ.mjs → views-KTVPV6UP.mjs} +7 -7
  145. package/dist/cli/{workflow-HK4MZ7LK.mjs → workflow-LGKCRODX.mjs} +8 -8
  146. package/dist/cli/{workflow-CCZ2A7DI.js → workflow-NVZDJKH2.js} +18 -18
  147. package/dist/{client-BQ6yuSjM.d.ts → client-CCyWJqAI.d.ts} +1 -1
  148. package/dist/{client-DfdUc_MY.d.mts → client-Tp1LSULB.d.mts} +1 -1
  149. package/dist/{client-core-3GQ8WMuk.d.ts → client-core-BpYiYEfu.d.ts} +1 -1
  150. package/dist/{client-core-ClsNRytk.d.mts → client-core-D8eCZz3O.d.mts} +1 -1
  151. package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-EBWEUj0b.d.mts} +35 -0
  152. package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-EBWEUj0b.d.ts} +35 -0
  153. package/dist/{errors-Lm9_vJHZ.d.ts → errors-CParKUQR.d.mts} +2 -2
  154. package/dist/{errors-CwKXXtuu.d.mts → errors-Qt0OTA7_.d.ts} +2 -2
  155. package/dist/{index-DjwsAt82.d.mts → index-BMUVCNp7.d.mts} +1 -1
  156. package/dist/{index-3vJ-V9yw.d.ts → index-CoqDkIw0.d.ts} +1 -1
  157. package/dist/index.d.mts +7 -7
  158. package/dist/index.d.ts +7 -7
  159. package/dist/index.js +10 -10
  160. package/dist/index.mjs +7 -7
  161. package/dist/install-integrity.json +126 -124
  162. package/dist/plays/bundle-play-file.d.mts +3 -3
  163. package/dist/plays/bundle-play-file.d.ts +3 -3
  164. package/dist/plays/bundle-play-file.mjs +20 -1
  165. package/dist/plays/play-description.d.mts +2 -2
  166. package/dist/plays/play-description.d.ts +2 -2
  167. package/dist/plays/run-request.d.mts +2 -2
  168. package/dist/plays/run-request.d.ts +2 -2
  169. package/dist/release.d.mts +1 -1
  170. package/dist/release.d.ts +1 -1
  171. package/dist/release.js +2 -2
  172. package/dist/release.mjs +1 -1
  173. package/dist/server.d.mts +4 -4
  174. package/dist/server.d.ts +4 -4
  175. package/dist/server.js +10 -10
  176. package/dist/server.mjs +4 -4
  177. package/package.json +1 -1
  178. package/dist/cli/auth-455MB4K6.js +0 -43
  179. package/dist/cli/concurrent-runs-help-GFWXOKF5.js +0 -21
  180. package/dist/cli/describe-ZRGYAEBT.js +0 -50
  181. package/dist/cli/git-RC4XDATD.js +0 -25
  182. package/dist/cli/search-O5VVMXII.js +0 -32
  183. package/dist/cli/sessions-3PWFWCHO.js +0 -22
  184. package/dist/cli/skills-RFOMVXIT.js +0 -36
  185. package/dist/cli/tools-CAO6EVUW.js +0 -57
  186. 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`,
@@ -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
+ }
@@ -273,9 +273,11 @@ export type PlaySchedulerSubmitInput = RetainedPipelineCarrier & {
273
273
  experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
274
274
  /**
275
275
  * The runtime speed profile (`runtime-speed-profile.ts`) the run was
276
- * admitted with, such as `fast_launch@1`. Attribution only: its switch map
277
- * is already in `experimentSwitchOverrides`, and no reader branches on this
278
- * id. Absent on every run admitted without a profile.
276
+ * admitted with, such as `fast_launch@1`. Its switch map is already in
277
+ * `experimentSwitchOverrides`, and no reader resolves a switch from this id.
278
+ * The worker relays it to the executor-token route, which accepts the
279
+ * profile's exact frozen map without the experiment-override capability.
280
+ * Absent on every run admitted without a profile.
279
281
  */
280
282
  runtimeSpeedProfile?: string | null;
281
283
  /**
@@ -150,6 +150,7 @@ import { createFleetSandboxSweep } from '../fleet-sandbox-sweep';
150
150
  import {
151
151
  earlySandboxFleetSweepAdapter,
152
152
  earlySandboxSweepAdapters,
153
+ type EarlySandboxWorkerCapacity,
153
154
  } from './early-sandbox-lane';
154
155
  import {
155
156
  resolveDetachedRunnerRuntimeLimitSeconds,
@@ -1388,6 +1389,14 @@ export async function requestAttemptExecutorToken(input: {
1388
1389
  input.launch.experimentSwitchOverrides,
1389
1390
  }
1390
1391
  : {}),
1392
+ // The runtime speed profile those overrides came from, so the
1393
+ // route accepts the profile's exact frozen map without the
1394
+ // experiment-override capability (refused on Production). Optional:
1395
+ // the route also matches an old worker's map without it.
1396
+ ...(input.launch.experimentSwitchOverrides &&
1397
+ input.launch.runtimeSpeedProfile
1398
+ ? { runtimeSpeedProfile: input.launch.runtimeSpeedProfile }
1399
+ : {}),
1391
1400
  // Expand-before-enable rollout fence. An old worker never sends this,
1392
1401
  // so a newly deployed app cannot activate direct terminal reduction
1393
1402
  // before the owning Fly lane has the cleanup controller.
@@ -11522,6 +11531,12 @@ export type RuntimeWorkerHost = {
11522
11531
  id: string;
11523
11532
  startOwnerProbe(): void;
11524
11533
  };
11534
+ /**
11535
+ * E2: the drain and claim-slot state an early-sandbox hint is admitted
11536
+ * against (`startWorkerLaneEarlySandbox`). A draining worker or one with
11537
+ * no idle claim slot refuses the hint.
11538
+ */
11539
+ earlySandboxCapacity?: EarlySandboxWorkerCapacity;
11525
11540
  };
11526
11541
 
11527
11542
  /** Own shutdown ordering across the primary queue, listener and maintenance.
@@ -11532,16 +11547,29 @@ export function createAbsurdRuntimeWorkerHostLifecycle(input: {
11532
11547
  closeWake: () => void;
11533
11548
  wake?: () => boolean;
11534
11549
  earlySandboxClaimOwner?: RuntimeWorkerHost['earlySandboxClaimOwner'];
11550
+ earlySandboxCapacity?: RuntimeWorkerHost['earlySandboxCapacity'];
11535
11551
  stopControllers: () => void;
11536
11552
  controllers: readonly (Promise<unknown> | null)[];
11537
11553
  }): RuntimeWorkerHost {
11538
11554
  let closing: Promise<void> | null = null;
11539
11555
  let wake = input.wake;
11556
+ const capacity = input.earlySandboxCapacity;
11540
11557
  return {
11541
11558
  ...(wake ? { wake: () => wake?.() ?? false } : {}),
11542
11559
  ...(input.earlySandboxClaimOwner
11543
11560
  ? { earlySandboxClaimOwner: input.earlySandboxClaimOwner }
11544
11561
  : {}),
11562
+ // A closing host claims nothing more, so it reports itself draining.
11563
+ ...(capacity
11564
+ ? {
11565
+ earlySandboxCapacity: {
11566
+ get draining() {
11567
+ return closing !== null || capacity.draining;
11568
+ },
11569
+ hasIdleSlot: () => closing === null && capacity.hasIdleSlot(),
11570
+ },
11571
+ }
11572
+ : {}),
11545
11573
  close: () => {
11546
11574
  if (closing) return closing;
11547
11575
  wake = undefined;
@@ -12075,6 +12103,10 @@ export async function startRuntimeWorkerHost(
12075
12103
  worker,
12076
12104
  ...(onWake ? { wake: () => onWake.wake() } : {}),
12077
12105
  ...(earlySandboxClaimOwner ? { earlySandboxClaimOwner } : {}),
12106
+ earlySandboxCapacity: {
12107
+ draining: drainExit,
12108
+ hasIdleSlot: claimLoop.hasIdleSlot,
12109
+ },
12078
12110
  // Release LISTEN before joining accepted work, so a replacement can elect
12079
12111
  // its listener without exhausting primary scheduler sessions.
12080
12112
  closeWake: () => onWake?.close(),