deepline 0.3.571 → 0.3.572

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 (147) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +11 -0
  3. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +28 -17
  4. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +360 -3
  5. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +274 -3
  6. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +35 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +28 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +2 -2
  9. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +11 -1
  10. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +67 -43
  11. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +23 -6
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-listener-hint.ts +62 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +11 -2
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +54 -5
  15. package/dist/cli/auth-PXIVGUVZ.js +44 -0
  16. package/dist/cli/{auth-ARGNQK7A.mjs → auth-YUDM3YOC.mjs} +5 -5
  17. package/dist/cli/{billing-KAKODYTN.js → billing-F3ZGOWKL.js} +99 -99
  18. package/dist/cli/{billing-QRZTHCBX.mjs → billing-O7WUC4TU.mjs} +8 -8
  19. package/dist/cli/{chunk-C27FK36H.js → chunk-3SFLY3T3.js} +5 -5
  20. package/dist/cli/{chunk-GOUKX6XD.js → chunk-43GCEVHO.js} +3 -3
  21. package/dist/cli/{chunk-PTM5V5FV.js → chunk-4W5EFHHY.js} +7 -7
  22. package/dist/cli/{chunk-2IZOCGOA.js → chunk-5EMYPLTW.js} +53 -53
  23. package/dist/cli/{chunk-IXFFOZZQ.js → chunk-5VUD7HGD.js} +2 -2
  24. package/dist/cli/{chunk-7HAYEKC4.mjs → chunk-6R57HEPF.mjs} +1 -1
  25. package/dist/cli/{chunk-H6QMUX7Y.mjs → chunk-72WI67H4.mjs} +2 -2
  26. package/dist/cli/{chunk-MFBFQUQK.js → chunk-AHNJGA6Z.js} +6 -6
  27. package/dist/cli/{chunk-CR6IPQBB.mjs → chunk-AJO3I3LL.mjs} +1 -1
  28. package/dist/cli/{chunk-UBNRPJKO.mjs → chunk-BWWDU6FN.mjs} +5 -5
  29. package/dist/cli/{chunk-ETGM6PIR.mjs → chunk-CYW6PE3G.mjs} +5 -5
  30. package/dist/cli/{chunk-Z3DSCE5F.mjs → chunk-EDAG7ZU4.mjs} +1 -1
  31. package/dist/cli/{chunk-FQP5VSVF.mjs → chunk-EKIWY5DD.mjs} +1 -1
  32. package/dist/cli/{chunk-336AHC7H.mjs → chunk-EKWDSE6H.mjs} +4 -4
  33. package/dist/cli/{chunk-6OP5UW7C.js → chunk-EL4LME5Y.js} +48 -48
  34. package/dist/cli/{chunk-7JGHNZTD.js → chunk-FGBX2WVJ.js} +4 -4
  35. package/dist/cli/{chunk-TJU2BECV.mjs → chunk-GX4VZL4Z.mjs} +3 -3
  36. package/dist/cli/{chunk-YGGHPEWP.js → chunk-HYCJNHZ4.js} +15 -15
  37. package/dist/cli/{chunk-QRMTITKL.mjs → chunk-I4WKB3HO.mjs} +2 -2
  38. package/dist/cli/{chunk-A5HDA22N.js → chunk-ITQPBWDS.js} +3 -3
  39. package/dist/cli/{chunk-A3IVPA6Q.mjs → chunk-JEI7PHET.mjs} +1 -1
  40. package/dist/cli/{chunk-J5KW2ZDB.mjs → chunk-JJEN7TRR.mjs} +1 -1
  41. package/dist/cli/{chunk-ILKUKEWX.js → chunk-K4LAEKHS.js} +41 -41
  42. package/dist/cli/{chunk-HGER4CJA.js → chunk-LBNP52C4.js} +5 -5
  43. package/dist/cli/{chunk-A3B54QEW.mjs → chunk-MVQ5XGRO.mjs} +3 -3
  44. package/dist/cli/{chunk-IFKZQCPX.js → chunk-NOKSEYMS.js} +1 -1
  45. package/dist/cli/{chunk-PO3NOBHU.mjs → chunk-OUVQKSVC.mjs} +1 -1
  46. package/dist/cli/{chunk-CITDBSXI.js → chunk-PI4TKE2B.js} +26 -26
  47. package/dist/cli/{chunk-WZOUXILM.mjs → chunk-PQ6PM4V6.mjs} +1 -1
  48. package/dist/cli/{chunk-6N3NTEJ6.js → chunk-PRDCU7BY.js} +20 -20
  49. package/dist/cli/{chunk-RBPR5ZNN.js → chunk-PZGK6EEB.js} +100 -100
  50. package/dist/cli/{chunk-CF6CSAMJ.mjs → chunk-Q6H5RRTG.mjs} +4 -4
  51. package/dist/cli/{chunk-UTGHPC5D.mjs → chunk-QA733N7N.mjs} +1 -1
  52. package/dist/cli/{chunk-VLQB65HI.js → chunk-QMIMGKR2.js} +9 -9
  53. package/dist/cli/{chunk-YDULFKDL.mjs → chunk-RIA73OAZ.mjs} +2 -2
  54. package/dist/cli/{chunk-GCE5KOJJ.mjs → chunk-SJI56XPM.mjs} +11 -11
  55. package/dist/cli/{chunk-GRD3DLH7.mjs → chunk-UFUXGMHL.mjs} +2 -2
  56. package/dist/cli/{chunk-NAGGCF6Y.js → chunk-UKD5ZBQD.js} +5 -5
  57. package/dist/cli/{chunk-C6XV2DPY.mjs → chunk-UMP76GYQ.mjs} +3 -3
  58. package/dist/cli/{chunk-VULSFPD4.mjs → chunk-UQWYDNGB.mjs} +5 -5
  59. package/dist/cli/{chunk-SJYLLHHZ.js → chunk-UUYB6IXC.js} +13 -13
  60. package/dist/cli/{chunk-Z6OUUAIV.mjs → chunk-UY6Z3XWW.mjs} +2 -2
  61. package/dist/cli/{chunk-CFMIWRGD.mjs → chunk-V2W7GX2I.mjs} +2 -2
  62. package/dist/cli/{chunk-GACQOGRS.js → chunk-VGPHXXPI.js} +15 -15
  63. package/dist/cli/{chunk-WOU2WS6S.js → chunk-VZ4S5JRC.js} +23 -23
  64. package/dist/cli/{chunk-AOMVAXGX.js → chunk-W3HLZ24Q.js} +10 -10
  65. package/dist/cli/{chunk-XD4MT4BH.js → chunk-W3RHISD6.js} +8 -8
  66. package/dist/cli/{chunk-YDM5WSXO.mjs → chunk-W742U53L.mjs} +5 -5
  67. package/dist/cli/{chunk-AD7BGMTL.mjs → chunk-X6F4XOT2.mjs} +2 -2
  68. package/dist/cli/{chunk-YQ36Z23U.js → chunk-XNJXRS3B.js} +2 -2
  69. package/dist/cli/{chunk-C3FHMJ4A.js → chunk-XVQE6IBS.js} +2 -2
  70. package/dist/cli/{chunk-73P76DCN.js → chunk-YOST7EJF.js} +20 -20
  71. package/dist/cli/{concurrent-runs-help-VPYB4ODC.mjs → concurrent-runs-help-5BKCGFGL.mjs} +6 -6
  72. package/dist/cli/concurrent-runs-help-KGELXJIQ.js +22 -0
  73. package/dist/cli/{csv-GHGDSFNV.js → csv-7ZAWND7L.js} +13 -13
  74. package/dist/cli/{csv-RALLG3MG.mjs → csv-MO5WZZDN.mjs} +4 -4
  75. package/dist/cli/{db-722SKSIB.js → db-36LX7JBQ.js} +27 -27
  76. package/dist/cli/{db-HB65VYRR.mjs → db-OYMULINA.mjs} +6 -6
  77. package/dist/cli/describe-AVGE4MH6.js +50 -0
  78. package/dist/cli/{describe-Q6M7PUBU.mjs → describe-JLAERB6X.mjs} +18 -18
  79. package/dist/cli/{executions-GQNV3LNU.js → executions-AQ32J4BZ.js} +8 -8
  80. package/dist/cli/{executions-G3M75HW2.mjs → executions-IZAB2XNC.mjs} +6 -6
  81. package/dist/cli/{feedback-B43F2FBL.js → feedback-3IV54HOH.js} +14 -14
  82. package/dist/cli/{feedback-CSDBYSRS.mjs → feedback-WA6EBE5H.mjs} +6 -6
  83. package/dist/cli/{git-IZ4Y3RAW.mjs → git-OSLU6HIK.mjs} +5 -5
  84. package/dist/cli/git-VOFO6V5W.js +26 -0
  85. package/dist/cli/index.js +143 -143
  86. package/dist/cli/index.mjs +45 -45
  87. package/dist/cli/{integrations-OLCUWZ6Z.js → integrations-65SYNL53.js} +29 -29
  88. package/dist/cli/{integrations-DT7EGM2Y.mjs → integrations-WOXFOC4M.mjs} +7 -7
  89. package/dist/cli/{legacy-noops-FTGNTO3U.js → legacy-noops-3SGXDAV6.js} +9 -9
  90. package/dist/cli/{legacy-noops-4TPT534L.mjs → legacy-noops-4FNG2JY3.mjs} +6 -6
  91. package/dist/cli/{mcp-3IDWLBKK.js → mcp-PX27RHCY.js} +24 -24
  92. package/dist/cli/{mcp-5KDJJT7M.mjs → mcp-RZLWMZHH.mjs} +4 -4
  93. package/dist/cli/{monitors-7GOZBKJR.js → monitors-F5BLGS4R.js} +100 -100
  94. package/dist/cli/{monitors-EOAA5RQO.mjs → monitors-VK2LW7VU.mjs} +7 -7
  95. package/dist/cli/{org-H5I56A4F.mjs → org-7AEBTN6Y.mjs} +6 -6
  96. package/dist/cli/{org-UJ5SWQJ5.js → org-UU3V7U4K.js} +121 -121
  97. package/dist/cli/{outcomes-MG57YXJX.mjs → outcomes-BWERSUJL.mjs} +6 -6
  98. package/dist/cli/{outcomes-24KFY2X5.js → outcomes-GCTBGPMK.js} +14 -14
  99. package/dist/cli/{play-PPPACSQE.js → play-7NBCCL26.js} +324 -324
  100. package/dist/cli/{play-MXPXRAUM.mjs → play-TX3RAAYS.mjs} +19 -19
  101. package/dist/cli/{providers-LTYNEXLB.js → providers-IL2IVKHB.js} +9 -9
  102. package/dist/cli/{providers-5ZN3MO6E.mjs → providers-KFWZXDCV.mjs} +6 -6
  103. package/dist/cli/{quickstart-UBDHX7PT.js → quickstart-MPA6TUK5.js} +6 -6
  104. package/dist/cli/{quickstart-ENDTTNLE.mjs → quickstart-RAMDGRRI.mjs} +4 -4
  105. package/dist/cli/{run-QJJSP35C.mjs → run-QNJSKPBN.mjs} +23 -23
  106. package/dist/cli/{run-6O6LQVWD.js → run-WBUSXBUS.js} +44 -44
  107. package/dist/cli/{search-PXZPVXDK.mjs → search-2X4P2FXR.mjs} +7 -7
  108. package/dist/cli/search-CJHG3VA4.js +32 -0
  109. package/dist/cli/{search-output-KRR4YOJX.mjs → search-output-MNJ4AQLV.mjs} +4 -4
  110. package/dist/cli/{search-output-H3ZQLJUF.js → search-output-P2WNCHA3.js} +6 -6
  111. package/dist/cli/{secrets-QZMXBI64.js → secrets-K5CNDUVR.js} +15 -15
  112. package/dist/cli/{secrets-HIGERL4N.mjs → secrets-XX54OU22.mjs} +6 -6
  113. package/dist/cli/sessions-3RMRBBJZ.js +23 -0
  114. package/dist/cli/{sessions-4SGQAX3F.mjs → sessions-C4GQ6ZVO.mjs} +6 -6
  115. package/dist/cli/{settings-UQLHVBOP.mjs → settings-7HBTADGW.mjs} +12 -12
  116. package/dist/cli/{settings-FFTTVDRV.js → settings-QP3DVFPS.js} +85 -85
  117. package/dist/cli/{setup-R5MBUG5M.mjs → setup-VPDAKY2G.mjs} +9 -9
  118. package/dist/cli/{setup-SS3MABJP.js → setup-X6J7U6B4.js} +49 -49
  119. package/dist/cli/skills-JUGXGSX2.js +37 -0
  120. package/dist/cli/{skills-X6PNEVWX.mjs → skills-UGY6W4AC.mjs} +7 -7
  121. package/dist/cli/{tools-YFW3FXAB.mjs → tools-SVBUAHDD.mjs} +17 -17
  122. package/dist/cli/tools-ZEI42NSP.js +57 -0
  123. package/dist/cli/{update-HX5BNFLQ.mjs → update-SDNKNDNW.mjs} +9 -9
  124. package/dist/cli/update-VC4UEGMR.js +37 -0
  125. package/dist/cli/{views-BGCRC22G.js → views-JBFSHQBU.js} +21 -21
  126. package/dist/cli/{views-FH5XL2PU.mjs → views-M6RBPC65.mjs} +6 -6
  127. package/dist/cli/{workflow-VLNDGNJI.mjs → workflow-RYVRAIHV.mjs} +7 -7
  128. package/dist/cli/{workflow-UY5PZBIK.js → workflow-UAMTGHQC.js} +17 -17
  129. package/dist/index.js +9 -9
  130. package/dist/index.mjs +6 -6
  131. package/dist/install-integrity.json +112 -112
  132. package/dist/release.d.mts +1 -1
  133. package/dist/release.d.ts +1 -1
  134. package/dist/release.js +2 -2
  135. package/dist/release.mjs +1 -1
  136. package/dist/server.js +5 -5
  137. package/dist/server.mjs +3 -3
  138. package/package.json +1 -1
  139. package/dist/cli/auth-FKYYYCME.js +0 -44
  140. package/dist/cli/concurrent-runs-help-VUMIMYO7.js +0 -22
  141. package/dist/cli/describe-SG2N62VE.js +0 -50
  142. package/dist/cli/git-IJHKRWTR.js +0 -26
  143. package/dist/cli/search-TYPJWK4I.js +0 -32
  144. package/dist/cli/sessions-OS4ZBU4K.js +0 -23
  145. package/dist/cli/skills-FVDSEEUL.js +0 -37
  146. package/dist/cli/tools-ORTGWD63.js +0 -57
  147. package/dist/cli/update-RWVNNNHN.js +0 -37
@@ -1,4 +1,4 @@
1
- import { createHash } from 'node:crypto';
1
+ import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
2
2
  import type { PlaySandboxRuntimeLimits } from '../../plays/sandbox-runtime-limits';
3
3
  import {
4
4
  resolveExperimentSwitch,
@@ -117,6 +117,179 @@ export const EARLY_PREBOOT_TAG = 'earlyPreboot';
117
117
  * runs from pre-boot, and the runner's config wait has a 120 s deadline.
118
118
  */
119
119
  export const EARLY_PREBOOT_MAX_ADOPTION_AGE_MS = 30_000;
120
+
121
+ /**
122
+ * Preview experiment PX: a pre-booted early sandbox may be adopted by ANY
123
+ * worker, not only the one that started its runner. The pre-booted runner
124
+ * already waits for its config on files inside the sandbox (the launch
125
+ * delivers them with its own exec by sandbox id), so the only process-local
126
+ * state is the runner's paths and limits. With PX the starting worker
127
+ * publishes them as tags once the pre-boot verified (`publishEarlyPrebootPlan`):
128
+ * one path nonce, the start time, and an HMAC under the workers' internal
129
+ * token over the early key, sandbox id, nonce, start, limits, memory and baked
130
+ * runner hash. A launch on another worker verifies that MAC with its own
131
+ * inputs (`verifyEarlyPrebootPlan`), so a forged or mismatched plan is never
132
+ * delivered to; nothing customer-related is in the tags. Exclusivity is the
133
+ * run attempt's own claim: only the worker running this attempt's launch
134
+ * adopts, and adoption re-tags the sandbox, which the reaper then skips.
135
+ * Liveness without the starting worker's exec handle is the launch's
136
+ * readiness deadline. Off: a foreign pre-boot is refused as today.
137
+ */
138
+ export const ADOPT_PREBOOTED_EARLY_SANDBOX_ACROSS_PROCESSES = false;
139
+ /**
140
+ * PX: the published plan rides in the existing `earlyPreboot` tag's value
141
+ * (see the format below), because a Modal sandbox holds at most
142
+ * 10 tags and an early sandbox already carries 9 (lane runtime-1eb0a98f1f44,
143
+ * 2026-11-30: three separate plan tags failed every write with "Sandboxes
144
+ * have a limit of 10 tags."). Readers that only test the tag's presence are
145
+ * unchanged.
146
+ *
147
+ * `plan2:<nonce>.<startedAtMs>.<mac>`: a 96-bit random path nonce and a 96-bit
148
+ * MAC in base64url, the start in base 36 (~49 bytes). A Modal sandbox's tags
149
+ * are also capped at 512 bytes in total, and plan1 (~121 bytes, hex and
150
+ * decimal) pushed every caller-owned run (its ~140-byte workflowId tag) to
151
+ * 535-545 bytes, so its plan was never published (lanes runtime-b026b69af07b,
152
+ * runtime-d65976cf8f14, runtime-0aa51deff3d9, 2026-11-30).
153
+ */
154
+ const EARLY_PREBOOT_PLAN_PREFIX = 'plan2:';
155
+ const EARLY_PREBOOT_PLAN_VALUE =
156
+ /^plan2:([A-Za-z0-9_-]{16})\.([1-9a-z][0-9a-z]{0,10})\.([A-Za-z0-9_-]{16})$/;
157
+ /** Modal's cap on a sandbox's cumulative tag size, in bytes. */
158
+ export const MODAL_SANDBOX_TAGS_MAX_BYTES = 512;
159
+
160
+ /** Bytes Modal counts toward that cap: every tag name and value (UTF-8). */
161
+ export function modalSandboxTagsBytes(tags: Record<string, string>): number {
162
+ return Object.entries(tags).reduce(
163
+ (sum, [name, value]) => sum + Buffer.byteLength(name) + Buffer.byteLength(value),
164
+ 0,
165
+ );
166
+ }
167
+ const MAC_BYTES = 12;
168
+
169
+ /** PX: a fresh 96-bit path nonce (base64url, safe in file names). */
170
+ export function newEarlyPrebootPathNonce(): string {
171
+ return randomBytes(12).toString('base64url');
172
+ }
173
+ /** A plan from a worker whose clock runs ahead by more than this is refused. */
174
+ export const EARLY_PREBOOT_PLAN_FUTURE_SKEW_MS = 5_000;
175
+ /**
176
+ * PX: when the creator re-reads a published sandbox's tags to settle it once
177
+ * another worker adopted it (past the 30 s pre-boot adoption age), instead of
178
+ * counting it against its caps until the 90 s reaper.
179
+ */
180
+ export const EARLY_PREBOOT_ADOPTION_PROBE_AFTER_MS = 35_000;
181
+
182
+ /** The fields a published pre-boot plan binds. */
183
+ export type EarlyPrebootPlan = {
184
+ key: string;
185
+ sandboxId: string;
186
+ nonce: string;
187
+ startedAtMs: number;
188
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
189
+ memoryLimitMiB?: number;
190
+ bakedRunnerHash: string;
191
+ /**
192
+ * sha256 of the pre-booted runner's command, as each side builds it, so a
193
+ * launch on a different build (another command for the same nonce) refuses
194
+ * instead of delivering to paths the runner is not watching.
195
+ */
196
+ runnerCommandSha256: string;
197
+ };
198
+
199
+ /** sha256 hex of a pre-booted runner's command. */
200
+ export function earlyPrebootRunnerCommandSha256(command: string): string {
201
+ return createHash('sha256').update(command).digest('hex');
202
+ }
203
+
204
+ function earlyPrebootPlanMac(secret: string, plan: EarlyPrebootPlan): Buffer {
205
+ return createHmac('sha256', `early-preboot-plan2:${secret}`)
206
+ .update(
207
+ JSON.stringify([
208
+ plan.key,
209
+ plan.sandboxId,
210
+ plan.nonce,
211
+ plan.startedAtMs,
212
+ plan.sandboxRuntimeLimits,
213
+ plan.memoryLimitMiB ?? null,
214
+ plan.bakedRunnerHash,
215
+ plan.runnerCommandSha256,
216
+ ]),
217
+ )
218
+ .digest()
219
+ .subarray(0, MAC_BYTES);
220
+ }
221
+
222
+ /** PX: the tag that publishes a verified pre-boot's plan (one tag). */
223
+ export function publishEarlyPrebootPlan(
224
+ secret: string,
225
+ plan: EarlyPrebootPlan,
226
+ ): Record<string, string> {
227
+ return {
228
+ [EARLY_PREBOOT_TAG]: `${EARLY_PREBOOT_PLAN_PREFIX}${plan.nonce}.${plan.startedAtMs.toString(36)}.${earlyPrebootPlanMac(secret, plan).toString('base64url')}`,
229
+ };
230
+ }
231
+
232
+ /**
233
+ * PX: the published plan another worker may deliver to, or why not. The MAC
234
+ * is recomputed from this launch's own limits, memory and baked runner, so a
235
+ * plan made for anything else (or forged by a tag writer without the token)
236
+ * is refused; so is a pre-boot past the in-process adoption age.
237
+ */
238
+ export function verifyEarlyPrebootPlan(input: {
239
+ secret: string;
240
+ tags: Record<string, string>;
241
+ key: string;
242
+ sandboxId: string;
243
+ sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
244
+ memoryLimitMiB?: number;
245
+ bakedRunnerHash: string;
246
+ /** This launch's own runner command for the plan's nonce, hashed. */
247
+ runnerCommandSha256: (nonce: string) => string;
248
+ nowMs: number;
249
+ }):
250
+ | { plan: EarlyPrebootPlan }
251
+ | { refused: 'preboot_plan_missing' | 'preboot_plan_invalid' | 'preboot_stale' } {
252
+ const value = input.tags[EARLY_PREBOOT_TAG];
253
+ // `1` (the create-time claim) or absent: not published (yet). Any other
254
+ // plan form (an older or newer build's) is refused, never guessed at.
255
+ if (!value?.startsWith('plan')) return { refused: 'preboot_plan_missing' };
256
+ const match = EARLY_PREBOOT_PLAN_VALUE.exec(value);
257
+ if (!match) return { refused: 'preboot_plan_invalid' };
258
+ const [, nonce, startedAtText, mac] = match as unknown as [
259
+ string,
260
+ string,
261
+ string,
262
+ string,
263
+ ];
264
+ const startedAtMs = parseInt(startedAtText, 36);
265
+ // One canonical form: the MAC covers the number, so refuse other spellings.
266
+ if (
267
+ !Number.isSafeInteger(startedAtMs) ||
268
+ startedAtMs.toString(36) !== startedAtText
269
+ )
270
+ return { refused: 'preboot_plan_invalid' };
271
+ const plan: EarlyPrebootPlan = {
272
+ key: input.key,
273
+ sandboxId: input.sandboxId,
274
+ nonce,
275
+ startedAtMs,
276
+ sandboxRuntimeLimits: input.sandboxRuntimeLimits,
277
+ ...(input.memoryLimitMiB === undefined
278
+ ? {}
279
+ : { memoryLimitMiB: input.memoryLimitMiB }),
280
+ bakedRunnerHash: input.bakedRunnerHash,
281
+ runnerCommandSha256: input.runnerCommandSha256(nonce),
282
+ };
283
+ const expected = earlyPrebootPlanMac(input.secret, plan);
284
+ const actual = Buffer.from(mac, 'base64url');
285
+ if (expected.length !== actual.length || !timingSafeEqual(expected, actual))
286
+ return { refused: 'preboot_plan_invalid' };
287
+ if (startedAtMs > input.nowMs + EARLY_PREBOOT_PLAN_FUTURE_SKEW_MS)
288
+ return { refused: 'preboot_plan_invalid' };
289
+ if (input.nowMs - startedAtMs > EARLY_PREBOOT_MAX_ADOPTION_AGE_MS)
290
+ return { refused: 'preboot_stale' };
291
+ return { plan };
292
+ }
120
293
  /** Bound on the pre-boot's verdict line, and on its exit after a refusal. */
121
294
  export const EARLY_PREBOOT_VERDICT_TIMEOUT_MS = 15_000;
122
295
 
@@ -636,7 +809,26 @@ export function scheduleEarlySandboxReap(input: {
636
809
  * until its entry's TTL (the sandbox may still be alive).
637
810
  */
638
811
  registry?: Pick<EarlySandboxRegistry, 'settle'>;
812
+ /**
813
+ * PX: also re-read the tags once at this age and settle the sandbox if
814
+ * another worker adopted it (it no longer carries early tags); never
815
+ * terminates. Absent: only the 90 s reap, as before.
816
+ */
817
+ adoptionProbeAfterMs?: number;
639
818
  }): void {
819
+ if (input.adoptionProbeAfterMs !== undefined && input.registry) {
820
+ const registry = input.registry;
821
+ const probe = setTimeout(() => {
822
+ void input.calls
823
+ .fromId(input.sandboxId)
824
+ .then((sandbox) => sandbox.getTags())
825
+ .then((tags) => {
826
+ if (!isUnadoptedEarlySandbox(tags)) registry.settle(input.sandboxId);
827
+ })
828
+ .catch(() => undefined);
829
+ }, input.adoptionProbeAfterMs);
830
+ probe.unref?.();
831
+ }
640
832
  const reap = setTimeout(() => {
641
833
  void reapEarlySandboxById(input)
642
834
  .then(() => input.registry?.settle(input.sandboxId))
@@ -876,6 +1068,29 @@ export async function adoptEarlySandbox<
876
1068
  foreignClaimTags?: readonly { tag: string; reason: string }[];
877
1069
  /** PB hook: this process's pre-boot on an in-process sandbox, if any. */
878
1070
  inProcessPreboot(sandbox: TSandbox): Promise<EarlySandboxPreboot> | undefined;
1071
+ /**
1072
+ * PX hook: whether this launch may deliver to a pre-boot another process
1073
+ * started (a verified published plan); null when it may, else the refusal
1074
+ * reason. Absent: every foreign pre-boot is refused.
1075
+ */
1076
+ foreignPrebootAdoption?: (
1077
+ sandbox: TSandbox,
1078
+ tags: Record<string, string>,
1079
+ ) => Promise<string | null>;
1080
+ /**
1081
+ * Called instead of re-tagging, on every adoption path: the launch re-tags
1082
+ * (with `tags`) only after its own resource record wins the durable sandbox
1083
+ * fence, so a launch that loses a same-run race never re-tags (or
1084
+ * terminates) a sandbox the winner owns; until then the sandbox keeps its
1085
+ * early tags and stays with its reaper. `createdAtMs` lets the launch refuse
1086
+ * a re-tag too close to the 90 s reap. Required for a foreign pre-boot
1087
+ * adoption; absent, other paths re-tag at adoption as before.
1088
+ */
1089
+ deferRetag?: (
1090
+ sandbox: TSandbox,
1091
+ tags: Record<string, string>,
1092
+ createdAtMs: number,
1093
+ ) => void;
879
1094
  /**
880
1095
  * A1 hook: settles once a tag that makes every other process refuse to
881
1096
  * adopt the sandbox is on it at the provider.
@@ -948,12 +1163,19 @@ export async function adoptEarlySandbox<
948
1163
  input.experimentSwitchOverrides,
949
1164
  ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ,
950
1165
  ) &&
1166
+ // PX invites other workers to adopt this sandbox, so its tags may have
1167
+ // changed since this process wrote them: always read them back.
1168
+ !resolveExperimentSwitch(
1169
+ 'PX',
1170
+ input.experimentSwitchOverrides,
1171
+ ADOPT_PREBOOTED_EARLY_SANDBOX_ACROSS_PROCESSES,
1172
+ ) &&
951
1173
  foreignClaim !== undefined &&
952
1174
  (await foreignClaim.then(
953
1175
  () => true,
954
1176
  () => false,
955
1177
  ));
956
- const tags =
1178
+ let tags =
957
1179
  trustLocalTags && localEntry ? localEntry.tags : await sandbox.getTags();
958
1180
  const identityRefusal = earlySandboxIdentityRefusal(tags, {
959
1181
  key,
@@ -1006,9 +1228,39 @@ export async function adoptEarlySandbox<
1006
1228
  { tag: EARLY_PREBOOT_TAG, reason: 'early_preboot_foreign' },
1007
1229
  ]) {
1008
1230
  if (how !== 'in_process' && tags[claim.tag]) {
1231
+ // PX: a verified published plan lets this launch deliver instead.
1232
+ const foreignRefusal =
1233
+ claim.tag === EARLY_PREBOOT_TAG && input.foreignPrebootAdoption
1234
+ ? await input.foreignPrebootAdoption(sandbox, tags)
1235
+ : claim.reason;
1236
+ if (foreignRefusal === null) {
1237
+ how = 'by_tag_preboot';
1238
+ // The hook may have waited for the plan: decide on the sandbox's
1239
+ // latest tags (another launch may have taken it meanwhile).
1240
+ tags = await sandbox.getTags();
1241
+ const latestRefusal = earlySandboxIdentityRefusal(tags, {
1242
+ key,
1243
+ orgId,
1244
+ workflowId: input.workflowId,
1245
+ ...input.scope,
1246
+ });
1247
+ if (latestRefusal) {
1248
+ input.emitStage('early:adopt_miss', {
1249
+ key,
1250
+ reason: latestRefusal,
1251
+ sandboxId: sandbox.sandboxId,
1252
+ elapsedMs: nowMs() - startedAt,
1253
+ });
1254
+ return null;
1255
+ }
1256
+ continue;
1257
+ }
1009
1258
  input.emitStage('early:adopt_miss', {
1010
1259
  key,
1011
- reason: claim.reason,
1260
+ reason:
1261
+ foreignRefusal === claim.reason
1262
+ ? claim.reason
1263
+ : `${claim.reason}:${foreignRefusal}`,
1012
1264
  sandboxId: sandbox.sandboxId,
1013
1265
  elapsedMs: nowMs() - startedAt,
1014
1266
  });
@@ -1047,6 +1299,25 @@ export async function adoptEarlySandbox<
1047
1299
  });
1048
1300
  return null;
1049
1301
  }
1302
+ if (input.deferRetag) {
1303
+ // Re-tagged by the launch once its resource record wins the fence.
1304
+ input.deferRetag(
1305
+ sandbox,
1306
+ { ...input.createTags, earlyKey: key },
1307
+ nowMs() - ageMs,
1308
+ );
1309
+ // Adopted: it is the launch's sandbox now, no longer early capacity.
1310
+ registry.settle(sandbox.sandboxId);
1311
+ input.emitStage('early:adopted', {
1312
+ key,
1313
+ how,
1314
+ sandboxId: sandbox.sandboxId,
1315
+ elapsedMs: nowMs() - startedAt,
1316
+ });
1317
+ return sandbox;
1318
+ }
1319
+ if (how === 'by_tag_preboot')
1320
+ throw new Error('A foreign pre-boot adoption needs a deferred re-tag.');
1050
1321
  // Re-tag first: from here the sandbox is an ordinary launch sandbox for
1051
1322
  // every cleanup and reconciliation path, and the reaper skips it.
1052
1323
  await sandbox.setTags({ ...input.createTags, earlyKey: key });
@@ -96,3 +96,38 @@ export function resolvePreviewWorkerListenerElection(
96
96
  }
97
97
  return 'direct_listen';
98
98
  }
99
+
100
+ /**
101
+ * Env turning on the CA claim gate (CAR) on an isolated Preview lane's
102
+ * workers, written only by the release gate from a typed target config
103
+ * (`runtime.claimAffinityReader`). CAR is a worker-process switch whose
104
+ * constant stays off everywhere else, so Production workers never read it.
105
+ */
106
+ export const PREVIEW_WORKER_CLAIM_AFFINITY_READER_ENV =
107
+ 'DEEPLINE_PREVIEW_WORKER_CLAIM_AFFINITY_READER';
108
+
109
+ /**
110
+ * Whether this worker runs the CA claim gate because its isolated Preview
111
+ * lane was configured for it. Unset or `off` (every Production worker and
112
+ * every other Preview lane) is off: unchanged. `on` on a non-isolated
113
+ * (Production-shaped) schema, or any other value, fails boot loudly instead
114
+ * of being ignored.
115
+ */
116
+ export function resolvePreviewWorkerClaimAffinityReader(
117
+ env: Readonly<Record<string, string | undefined>>,
118
+ schedulerSchema: string | null | undefined,
119
+ ): boolean {
120
+ const raw = env[PREVIEW_WORKER_CLAIM_AFFINITY_READER_ENV]?.trim();
121
+ if (!raw || raw === 'off') return false;
122
+ if (raw !== 'on') {
123
+ throw new Error(
124
+ `${PREVIEW_WORKER_CLAIM_AFFINITY_READER_ENV} must be off or on; got "${raw}".`,
125
+ );
126
+ }
127
+ if (!isIsolatedRuntimeSchedulerSchema(schedulerSchema)) {
128
+ throw new Error(
129
+ `${PREVIEW_WORKER_CLAIM_AFFINITY_READER_ENV}=on is valid only on an isolated Preview scheduler schema.`,
130
+ );
131
+ }
132
+ return true;
133
+ }
@@ -254,6 +254,34 @@ export const RUNTIME_SPEED_PROFILES = {
254
254
  PWV: false,
255
255
  },
256
256
  },
257
+ 'fast_launch@8': {
258
+ summary:
259
+ "fast_launch@7 plus PX and CA: a pre-booted early sandbox carries a MAC-signed runner plan, so a launch on any worker can adopt it instead of refusing it as early_preboot_foreign, and the gateway hints the queue worker with the most free slots (CA; the claim gate stays compiled off in Production, so claims are unchanged). Preview, 2 base workers + autoscaling, @7 map + CA + PX: 11 of 12 created early sandboxes adopted at 10/32/64 concurrent runs (4 by a worker other than the hinted one), heartbeat p50 below the E2-off control at every tier, 0 provider-verified leaks; @7 routing adopted 3/6, 0/1, 2/5. Registered before any grant.",
260
+ switches: {
261
+ B: true,
262
+ H1: true,
263
+ P1: true,
264
+ P2: true,
265
+ V3: true,
266
+ C3: true,
267
+ C4: true,
268
+ C5: true,
269
+ PI: true,
270
+ E2: true,
271
+ PB: true,
272
+ LH: true,
273
+ EN: true,
274
+ CA: true,
275
+ PX: true,
276
+ A1: false,
277
+ N1: false,
278
+ F3: false,
279
+ S1: false,
280
+ PWM: false,
281
+ PWT: false,
282
+ PWV: false,
283
+ },
284
+ },
257
285
  } as const satisfies Record<string, RuntimeSpeedProfileDefinition>;
258
286
 
259
287
  export type RuntimeSpeedProfileId = keyof typeof RUNTIME_SPEED_PROFILES;
@@ -130,10 +130,10 @@ export function absurdQueryableForRuntimeScheduler(
130
130
  params,
131
131
  client,
132
132
  gate: claimGate,
133
- run: async () => {
133
+ run: async (gatedParams) => {
134
134
  const queried = await client.query<Row & Record<string, unknown>>(
135
135
  sql,
136
- params,
136
+ gatedParams ? [...gatedParams] : gatedParams,
137
137
  );
138
138
  return { rows: queried.rows as Row[] };
139
139
  },
@@ -133,6 +133,7 @@ import {
133
133
  selectRuntimeSandboxCanary,
134
134
  } from '../runtime-sandbox-placement-policy';
135
135
  import {
136
+ resolvePreviewWorkerClaimAffinityReader,
136
137
  resolvePreviewWorkerListenerElection,
137
138
  shouldUseRuntimeSchedulerDirectNotify,
138
139
  } from '../runtime-scheduler-topology';
@@ -11987,6 +11988,14 @@ export async function startRuntimeWorkerHost(
11987
11988
  schema: options.schedulerSchema ?? null,
11988
11989
  }).schema,
11989
11990
  );
11991
+ // Same rule for the CA claim gate (CAR): only a typed isolated lane turns
11992
+ // it on; Production reads the compiled constant alone.
11993
+ const previewClaimAffinityReader = resolvePreviewWorkerClaimAffinityReader(
11994
+ process.env,
11995
+ normalizeAbsurdSchedulerOptions({
11996
+ schema: options.schedulerSchema ?? null,
11997
+ }).schema,
11998
+ );
11990
11999
  const poolOptions = resolveAbsurdPoolOptions();
11991
12000
  // Wait for the scheduler database beside the gateway check, before the pool
11992
12001
  // makes its first connections: their 5 s timeouts and breaker are for a
@@ -12049,7 +12058,8 @@ export async function startRuntimeWorkerHost(
12049
12058
  // CA: the claim gate needs the wake hook, which is created after the
12050
12059
  // client; it reads it late. Off unless the reader switch is on.
12051
12060
  let claimAffinityWake: (() => boolean) | null = null;
12052
- const claimAffinityGate = EARLY_SANDBOX_CLAIM_AFFINITY_READER
12061
+ const claimAffinityGate =
12062
+ EARLY_SANDBOX_CLAIM_AFFINITY_READER || previewClaimAffinityReader
12053
12063
  ? createEarlySandboxClaimGate({
12054
12064
  self: workerBase,
12055
12065
  queue,
@@ -68,31 +68,36 @@ export type ClaimAffinityDueRun = {
68
68
  };
69
69
 
70
70
  /**
71
- * Whether this worker should skip its next claim, and for how long. Yields
72
- * only when every due run is a first attempt recorded for ANOTHER owner whose
73
- * window is still open, and nothing else is due (expired claims, due sleeps
74
- * and due cancellations are claim_task work too). Anything else claims now.
71
+ * How much of its next claim this worker may take. `claim_task` takes due
72
+ * runs in order, so a worker may only take the leading due runs that are not
73
+ * another owner's first attempt inside its open window: it claims that
74
+ * prefix (`limit`), and when the head itself is such a run it yields until
75
+ * that window closes (`yieldMs`). A run's window is at most
76
+ * `EARLY_SANDBOX_CLAIM_AFFINITY_WINDOW_MS` from its enqueue, so a lost owner
77
+ * delays it, and any run queued behind it, by at most the window; then anyone
78
+ * claims it. Other due claim_task work (expired claims, due sleeps, due
79
+ * cancellations) always claims as requested.
75
80
  */
76
- export function decideEarlySandboxClaimYield(input: {
81
+ export function decideEarlySandboxClaimLimit(input: {
77
82
  self: string;
83
+ /** The first due pending runs, in claim order. */
78
84
  dueRuns: readonly ClaimAffinityDueRun[];
79
85
  otherDueWork: boolean;
80
- }): number | null {
86
+ }): { limit: number } | { yieldMs: number } | null {
81
87
  if (input.otherDueWork || input.dueRuns.length === 0) return null;
82
- let yieldMs = Number.POSITIVE_INFINITY;
83
- for (const run of input.dueRuns) {
88
+ const heldForAnother = (run: ClaimAffinityDueRun) => {
84
89
  const owner = parseEarlySandboxClaimOwner(run.owner);
85
- if (
86
- !owner ||
87
- owner === input.self ||
88
- run.attempt !== 1 ||
89
- !(run.remainingMs > 0)
90
- ) {
91
- return null;
92
- }
93
- yieldMs = Math.min(yieldMs, run.remainingMs);
94
- }
95
- return Number.isFinite(yieldMs) ? Math.ceil(yieldMs) : null;
90
+ return (
91
+ owner !== null &&
92
+ owner !== input.self &&
93
+ run.attempt === 1 &&
94
+ run.remainingMs > 0
95
+ );
96
+ };
97
+ const prefix = input.dueRuns.findIndex(heldForAnother);
98
+ if (prefix === -1) return null;
99
+ if (prefix > 0) return { limit: prefix };
100
+ return { yieldMs: Math.ceil(input.dueRuns[0]!.remainingMs) };
96
101
  }
97
102
 
98
103
  /**
@@ -168,17 +173,22 @@ export async function readEarlySandboxClaimAffinity(input: {
168
173
  /** The vendored engine's claim statement (`Absurd.claimTasks`). */
169
174
  const ABSURD_CLAIM_TASK_SQL = 'absurd.claim_task(';
170
175
 
176
+ /**
177
+ * The most runs this claim may take: null takes the requested batch as
178
+ * today, 0 skips this claim, and a smaller count claims only that many.
179
+ */
171
180
  export type EarlySandboxClaimGate = (
172
181
  client: RuntimeSchedulerQueryClient,
173
182
  claimParams: readonly unknown[],
174
- ) => Promise<boolean>;
183
+ ) => Promise<number | null>;
175
184
 
176
185
  /**
177
186
  * The claim gate the worker's scheduler queryable runs on the claim's own
178
- * pooled client, before `claim_task`. It returns false (skip this claim) only
179
- * while another owner's window is open, and then wakes the engine when that
180
- * window closes, so the run is claimed by someone within the window plus one
181
- * wake. A failed read claims as today.
187
+ * pooled client, before `claim_task`. It narrows the claim to the leading due
188
+ * runs no other owner holds, or skips it while another owner's window holds
189
+ * the head run, and then wakes the engine when that window closes, so the run
190
+ * is claimed by someone within the window plus one wake. A failed read claims
191
+ * as today.
182
192
  */
183
193
  export function createEarlySandboxClaimGate(input: {
184
194
  self: string;
@@ -201,7 +211,7 @@ export function createEarlySandboxClaimGate(input: {
201
211
  return async (client, claimParams) => {
202
212
  const startedAt = performance.now();
203
213
  const limit = Number(claimParams[3] ?? 1);
204
- let decision: number | null;
214
+ let decision: ReturnType<typeof decideEarlySandboxClaimLimit>;
205
215
  try {
206
216
  const read = await readEarlySandboxClaimAffinity({
207
217
  client,
@@ -209,7 +219,7 @@ export function createEarlySandboxClaimGate(input: {
209
219
  limit: Number.isFinite(limit) && limit > 0 ? limit : 1,
210
220
  windowMs,
211
221
  });
212
- decision = decideEarlySandboxClaimYield({
222
+ decision = decideEarlySandboxClaimLimit({
213
223
  self: input.self,
214
224
  dueRuns: read.dueRuns,
215
225
  otherDueWork: read.otherDueWork,
@@ -219,50 +229,64 @@ export function createEarlySandboxClaimGate(input: {
219
229
  event: 'gate_failed',
220
230
  error: error instanceof Error ? error.message : String(error),
221
231
  });
222
- return true;
232
+ return null;
223
233
  }
224
234
  const gateMs = Math.round(performance.now() - startedAt);
225
235
  if (decision === null) {
226
236
  log('[runtime.claim_affinity]', { event: 'gate_claim', gateMs });
227
- return true;
237
+ return null;
238
+ }
239
+ if ('limit' in decision) {
240
+ log('[runtime.claim_affinity]', {
241
+ event: 'gate_claim_prefix',
242
+ limit: decision.limit,
243
+ gateMs,
244
+ });
245
+ return decision.limit;
228
246
  }
229
247
  // One timer per open window: a later yield inside it reuses the wake.
230
- const due = Date.now() + decision + 1;
248
+ const due = Date.now() + decision.yieldMs + 1;
231
249
  if (wakeAt === null || wakeAt <= Date.now() || due < wakeAt) {
232
250
  wakeAt = due;
233
251
  setTimer(() => {
234
252
  wakeAt = null;
235
253
  input.wake();
236
- }, decision + 1);
254
+ }, decision.yieldMs + 1);
237
255
  }
238
256
  log('[runtime.claim_affinity]', {
239
257
  event: 'gate_yield',
240
- yieldMs: decision,
258
+ yieldMs: decision.yieldMs,
241
259
  gateMs,
242
260
  });
243
- return false;
261
+ return 0;
244
262
  };
245
263
  }
246
264
 
247
265
  /**
248
- * Run `claim` unless `gate` says to yield; a yielded claim returns no rows,
249
- * exactly like a claim that found nothing. Non-claim statements pass through.
266
+ * Run the claim as `gate` allows: as requested, narrowed to a smaller batch
267
+ * (the claim's fourth parameter is its count), or skipped, which returns no
268
+ * rows exactly like a claim that found nothing. Non-claim statements pass
269
+ * through.
250
270
  */
251
271
  export async function runGatedAbsurdClaimQuery<Row>(input: {
252
272
  sql: string;
253
273
  params: readonly unknown[] | undefined;
254
274
  client: RuntimeSchedulerQueryClient;
255
275
  gate: EarlySandboxClaimGate | undefined;
256
- run: () => Promise<{ rows: Row[] }>;
276
+ run: (params: readonly unknown[] | undefined) => Promise<{ rows: Row[] }>;
257
277
  }): Promise<{ rows: Row[] }> {
258
- if (
259
- input.gate &&
260
- input.sql.includes(ABSURD_CLAIM_TASK_SQL) &&
261
- !(await input.gate(input.client, input.params ?? []))
262
- ) {
263
- return { rows: [] };
264
- }
265
- return input.run();
278
+ if (!input.gate || !input.sql.includes(ABSURD_CLAIM_TASK_SQL))
279
+ return input.run(input.params);
280
+ const params = input.params ?? [];
281
+ const limit = await input.gate(input.client, params);
282
+ if (limit === null) return input.run(input.params);
283
+ if (limit < 1) return { rows: [] };
284
+ const requested = Number(params[3]);
285
+ if (!Number.isFinite(requested) || limit >= requested)
286
+ return input.run(input.params);
287
+ const narrowed = [...params];
288
+ narrowed[3] = limit;
289
+ return input.run(narrowed);
266
290
  }
267
291
 
268
292
  /**
@@ -424,12 +424,29 @@ export function startWorkerLaneEarlySandbox(
424
424
  workflowId: input.workflowId,
425
425
  ...adapter.scope(request),
426
426
  });
427
- const refusal = desk.admit({
428
- key,
429
- workflowId: input.workflowId,
430
- queue: input.listenerHint?.queue ?? '',
431
- listenerGeneration: input.listenerHint?.listenerGeneration ?? '',
432
- });
427
+ // CA spread: the gateway chose this worker for its free capacity and named
428
+ // no generation; the run's claim follows its recorded owner (this worker),
429
+ // so the desk binds the hint to the queue and one free slot only. Without
430
+ // CA a hint must still name this worker's current listener generation.
431
+ const claimOwnerHint =
432
+ !input.listenerHint?.listenerGeneration &&
433
+ resolveExperimentSwitch(
434
+ 'CA',
435
+ input.experimentSwitchOverrides,
436
+ CLAIM_AFFINITY_FOR_EARLY_SANDBOX,
437
+ );
438
+ const refusal = claimOwnerHint
439
+ ? desk.admitClaimOwner({
440
+ key,
441
+ workflowId: input.workflowId,
442
+ queue: input.listenerHint?.queue ?? '',
443
+ })
444
+ : desk.admit({
445
+ key,
446
+ workflowId: input.workflowId,
447
+ queue: input.listenerHint?.queue ?? '',
448
+ listenerGeneration: input.listenerHint?.listenerGeneration ?? '',
449
+ });
433
450
  if (refusal) {
434
451
  return refuseEarlySandboxHint({ ...hint, reason: `listener_${refusal}` });
435
452
  }