deepline 0.3.527 → 0.3.529

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/context.ts +197 -207
  3. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +5 -0
  4. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +66 -1
  5. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +156 -161
  6. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +56 -1
  7. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +11 -1
  8. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +36 -6
  9. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +35 -5
  10. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +12 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +1 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +16 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +26 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +129 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +6 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-claim-loop-timing.ts +145 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +48 -5
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +475 -101
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +13 -5
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +30 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +43 -16
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +105 -13
  23. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/result-receipt-policy.ts +10 -1
  24. package/dist/cli/auth-P7M7SXM5.js +43 -0
  25. package/dist/cli/{auth-LRMMQFJ4.mjs → auth-V7A6TU4G.mjs} +5 -5
  26. package/dist/cli/{billing-WZZDXVRJ.mjs → billing-5VBUYPWW.mjs} +6 -6
  27. package/dist/cli/{billing-M76MMWZB.js → billing-XF6SAA5Y.js} +79 -79
  28. package/dist/cli/{chunk-HB3YUHEL.js → chunk-2GV54JFN.js} +44 -44
  29. package/dist/cli/{chunk-ETXQZGQU.js → chunk-4722FTYU.js} +16 -16
  30. package/dist/cli/{chunk-AXFHQWGA.mjs → chunk-4A4OQMJX.mjs} +1 -1
  31. package/dist/cli/{chunk-66YLAQ2X.js → chunk-4BKE63Q7.js} +26 -26
  32. package/dist/cli/{chunk-UKOG6PCB.mjs → chunk-5NZEA2YV.mjs} +1 -1
  33. package/dist/cli/{chunk-JEIGNX3G.mjs → chunk-6XZIXDLC.mjs} +5 -5
  34. package/dist/cli/{chunk-RGL2YGJZ.js → chunk-7RTDSHMB.js} +2 -2
  35. package/dist/cli/{chunk-2A6IRSE6.js → chunk-7SRZTSHU.js} +5 -5
  36. package/dist/cli/{chunk-7DPWGAOU.js → chunk-7Z3ZXSOX.js} +3 -3
  37. package/dist/cli/{chunk-JSEISVAZ.js → chunk-AP7DNG6D.js} +4 -4
  38. package/dist/cli/{chunk-P5ZU5ZHA.mjs → chunk-BOWZ3OOU.mjs} +1 -1
  39. package/dist/cli/{chunk-YUYDP2EG.js → chunk-BRQDN67G.js} +6 -6
  40. package/dist/cli/{chunk-VV2AFJ3I.mjs → chunk-C2WTS7WY.mjs} +5 -5
  41. package/dist/cli/{chunk-GIRMVMXP.mjs → chunk-DKX5CGTG.mjs} +1 -1
  42. package/dist/cli/{chunk-OXHY3LD3.js → chunk-DPGPXARU.js} +53 -53
  43. package/dist/cli/{chunk-JSVHBJE2.mjs → chunk-E7CN5GEM.mjs} +2 -2
  44. package/dist/cli/{chunk-KDFUQRVU.mjs → chunk-ETCGTKLF.mjs} +1 -1
  45. package/dist/cli/{chunk-UJHS2O5O.mjs → chunk-EW33RCLA.mjs} +3 -3
  46. package/dist/cli/{chunk-OLSATEDQ.js → chunk-FCNSJHED.js} +6 -6
  47. package/dist/cli/{chunk-YKPMIJJ2.mjs → chunk-FWC47SCG.mjs} +2 -2
  48. package/dist/cli/{chunk-VTXBV4AX.mjs → chunk-FXHKNZM2.mjs} +1 -1
  49. package/dist/cli/{chunk-MMM2WMTF.mjs → chunk-G4SYSUDB.mjs} +5 -5
  50. package/dist/cli/{chunk-HA2J2OAS.mjs → chunk-GPU4ULMY.mjs} +10 -10
  51. package/dist/cli/{chunk-3L2DNG5X.js → chunk-H2JAXOPP.js} +11 -11
  52. package/dist/cli/{chunk-QKY3H3HA.mjs → chunk-HV4UKMBB.mjs} +4 -4
  53. package/dist/cli/{chunk-QKKT5G4K.mjs → chunk-K55VBSCA.mjs} +3 -3
  54. package/dist/cli/{chunk-EOL7PXLW.js → chunk-KAI64HV7.js} +7 -7
  55. package/dist/cli/{chunk-YJ4YVFXC.js → chunk-KSUWW26I.js} +13 -13
  56. package/dist/cli/{chunk-XI47UAVU.js → chunk-L3J7IAYE.js} +9 -9
  57. package/dist/cli/{chunk-R6IWWPY7.js → chunk-M47I47FK.js} +14 -14
  58. package/dist/cli/{chunk-E4TEZE62.mjs → chunk-NDVCVFZW.mjs} +2 -2
  59. package/dist/cli/{chunk-UAQ7ZWRP.js → chunk-NVH6ULDP.js} +22 -22
  60. package/dist/cli/{chunk-M45S7JAY.mjs → chunk-NVSMSP2J.mjs} +2 -2
  61. package/dist/cli/{chunk-SRQQAUXN.js → chunk-OA4FI5ZM.js} +2 -2
  62. package/dist/cli/{chunk-NVII3RWQ.mjs → chunk-PAAREIKG.mjs} +2 -2
  63. package/dist/cli/{chunk-5YR6CDJ2.mjs → chunk-PJDYY5JL.mjs} +6 -6
  64. package/dist/cli/{chunk-LHMHUA5D.js → chunk-PNWBODCB.js} +7 -7
  65. package/dist/cli/{chunk-C7A44BZ7.js → chunk-QTQWPSAK.js} +3 -3
  66. package/dist/cli/{chunk-MIL5YDKZ.mjs → chunk-R62Z4INU.mjs} +2 -2
  67. package/dist/cli/{chunk-YSDPYQBH.js → chunk-RWY2QLJ4.js} +41 -41
  68. package/dist/cli/{chunk-XYG4IOJK.js → chunk-TEFO5AS2.js} +98 -98
  69. package/dist/cli/{chunk-ZHY7AY5V.js → chunk-UMCEXTRM.js} +16 -16
  70. package/dist/cli/{chunk-77VNC2KF.mjs → chunk-XE4PQE2O.mjs} +1 -1
  71. package/dist/cli/{chunk-OKRBGXDI.js → chunk-XEZSORKG.js} +5 -5
  72. package/dist/cli/{chunk-3PQDEBO6.js → chunk-XZ6OY3BH.js} +1 -1
  73. package/dist/cli/{chunk-2L3HVEBM.mjs → chunk-Y4P6XJHU.mjs} +1 -1
  74. package/dist/cli/{chunk-RMCKTV4R.mjs → chunk-YVJJEMNQ.mjs} +1 -1
  75. package/dist/cli/{chunk-HQZLTK3P.js → chunk-ZEIN5YJS.js} +2 -2
  76. package/dist/cli/{chunk-RTPLRMEB.mjs → chunk-ZULLXAJJ.mjs} +5 -5
  77. package/dist/cli/{chunk-4YN7DZEA.mjs → chunk-ZYMX7KZE.mjs} +2 -2
  78. package/dist/cli/{csv-FEFNXZF7.mjs → csv-IHLVHG35.mjs} +4 -4
  79. package/dist/cli/{csv-IRP6VT7Q.js → csv-VEKMGGOE.js} +13 -13
  80. package/dist/cli/{db-Y5VNPNRD.js → db-NTFFISQG.js} +27 -27
  81. package/dist/cli/{db-IHECMWZ3.mjs → db-RKLVYARP.mjs} +6 -6
  82. package/dist/cli/{describe-XCVC2WLL.mjs → describe-62ELB5DZ.mjs} +18 -18
  83. package/dist/cli/describe-JXOGKT6C.js +50 -0
  84. package/dist/cli/{executions-3FWZYUJV.mjs → executions-5BMZW4C7.mjs} +6 -6
  85. package/dist/cli/{executions-QH3KJ6MA.js → executions-X7NMKMXW.js} +8 -8
  86. package/dist/cli/{feedback-BGHWMOLH.js → feedback-RDN5O4AT.js} +14 -14
  87. package/dist/cli/{feedback-F3OZXOPM.mjs → feedback-UHHWCIFD.mjs} +6 -6
  88. package/dist/cli/{git-RWPH3D75.mjs → git-3M33GKOW.mjs} +5 -5
  89. package/dist/cli/git-7VZGGIGZ.js +25 -0
  90. package/dist/cli/index.js +141 -141
  91. package/dist/cli/index.mjs +43 -43
  92. package/dist/cli/{legacy-noops-5ADSTBJ5.mjs → legacy-noops-7RVRPF5B.mjs} +6 -6
  93. package/dist/cli/{legacy-noops-G6CYD5LM.js → legacy-noops-ENKN6JU4.js} +9 -9
  94. package/dist/cli/{monitors-AFNAU3A2.mjs → monitors-FJPDMUQ6.mjs} +7 -7
  95. package/dist/cli/{monitors-VZCBZO26.js → monitors-YOWDFGIR.js} +100 -100
  96. package/dist/cli/{org-X4QRYBC4.js → org-4GBLI75H.js} +86 -86
  97. package/dist/cli/{org-JVLYTU24.mjs → org-H24LOZAC.mjs} +6 -6
  98. package/dist/cli/{pages-VELKZKBL.mjs → pages-BKM2D6BV.mjs} +6 -6
  99. package/dist/cli/{pages-YMM4KBW5.js → pages-WWVLYB5K.js} +18 -18
  100. package/dist/cli/{play-MIY6BYRB.mjs → play-M3CSYH3A.mjs} +18 -18
  101. package/dist/cli/{play-J7DEBHI7.js → play-TXHKCG6B.js} +317 -317
  102. package/dist/cli/{providers-2H3W3W7G.mjs → providers-EW5WTMTX.mjs} +6 -6
  103. package/dist/cli/{providers-TOUB7Y2A.js → providers-XL4SNFHU.js} +9 -9
  104. package/dist/cli/{quickstart-LHY2LN3P.js → quickstart-AFQ5MCDL.js} +6 -6
  105. package/dist/cli/{quickstart-GKAS5265.mjs → quickstart-SZSLS553.mjs} +4 -4
  106. package/dist/cli/{run-QCAVDPE5.js → run-MOFHGYSN.js} +41 -41
  107. package/dist/cli/{run-KYGNOWYD.mjs → run-TWXFNH6U.mjs} +23 -23
  108. package/dist/cli/{search-YPGAIFDX.mjs → search-2SW4V4IR.mjs} +8 -8
  109. package/dist/cli/search-V2AGWRLO.js +33 -0
  110. package/dist/cli/{search-output-ASELNQ2U.js → search-output-CJGRPJYD.js} +6 -6
  111. package/dist/cli/{search-output-OOC3VK4T.mjs → search-output-I6DNYXNT.mjs} +4 -4
  112. package/dist/cli/{secrets-VJ4XYSMZ.mjs → secrets-4XXLR6QO.mjs} +6 -6
  113. package/dist/cli/{secrets-KX3TQB4R.js → secrets-SD43HSLX.js} +15 -15
  114. package/dist/cli/{sessions-KUN7H7E5.mjs → sessions-7G32HW5R.mjs} +6 -6
  115. package/dist/cli/sessions-FIRDFPIZ.js +22 -0
  116. package/dist/cli/{settings-JKFYZ2IT.mjs → settings-HSYRY2L5.mjs} +13 -13
  117. package/dist/cli/{settings-5NIF4BU7.js → settings-SYEBDDDJ.js} +86 -86
  118. package/dist/cli/{setup-MYV3IHPS.js → setup-VTWCVCTK.js} +50 -50
  119. package/dist/cli/{setup-5AX3TN6G.mjs → setup-XZVBPKZK.mjs} +10 -10
  120. package/dist/cli/{skills-JLS4CINQ.mjs → skills-OMPEUMRT.mjs} +8 -8
  121. package/dist/cli/skills-RUY7CION.js +37 -0
  122. package/dist/cli/tools-KLIW7G6T.js +57 -0
  123. package/dist/cli/{tools-VBYKD3MJ.mjs → tools-UEDNJI4G.mjs} +17 -17
  124. package/dist/cli/{update-QWAIVJRI.mjs → update-4YVCUSSI.mjs} +10 -10
  125. package/dist/cli/update-FDUZRKKU.js +35 -0
  126. package/dist/cli/{views-TBWGZAVZ.mjs → views-4FP4AJQ2.mjs} +6 -6
  127. package/dist/cli/{views-ZW56JZB5.js → views-ZCCSKWMP.js} +18 -18
  128. package/dist/cli/{workflow-X7UQPJMQ.mjs → workflow-A2D5FALP.mjs} +7 -7
  129. package/dist/cli/{workflow-EKSZST6M.js → workflow-SM4OD4VJ.js} +17 -17
  130. package/dist/index.js +9 -9
  131. package/dist/index.mjs +6 -6
  132. package/dist/install-integrity.json +105 -104
  133. package/dist/release.d.mts +1 -1
  134. package/dist/release.d.ts +1 -1
  135. package/dist/release.js +2 -2
  136. package/dist/release.mjs +1 -1
  137. package/dist/server.js +5 -5
  138. package/dist/server.mjs +3 -3
  139. package/package.json +1 -1
  140. package/dist/cli/auth-C7BBYIQD.js +0 -43
  141. package/dist/cli/describe-MNJVJHRE.js +0 -50
  142. package/dist/cli/git-MDOHEW5J.js +0 -25
  143. package/dist/cli/search-G67CEHR7.js +0 -33
  144. package/dist/cli/sessions-QILPX4XQ.js +0 -22
  145. package/dist/cli/skills-NG32XTZI.js +0 -37
  146. package/dist/cli/tools-OZG3V77R.js +0 -57
  147. package/dist/cli/update-YL5WVSKU.js +0 -35
@@ -42,7 +42,9 @@ export function createSandboxCleanupJob(
42
42
  ports,
43
43
  input,
44
44
  deletion.detail,
45
- confirmationReadDelay(input.resource.failureCount + 1),
45
+ deletion.deleteAcceptedForMs === null
46
+ ? busyProviderReadDelay(input.resource.failureCount + 1)
47
+ : confirmationReadDelay(deletion.deleteAcceptedForMs),
46
48
  { code: deletion.code },
47
49
  );
48
50
  }
@@ -155,16 +157,44 @@ function retryDelay(nextFailureCount: number): number {
155
157
  * delete on Oct 31 (115 sightings of 10,785 deletes, 5-minute passes). Reading
156
158
  * at 5 seconds usually needs one read, so a cleanup costs three control
157
159
  * requests. At 500,000 cleanups a month that is under 1 request per second, and
158
- * the 4/s dense-load peak stays near 12/s, against a budget of 25/s. Doubling
159
- * to 5 minutes leaves a stuck sandbox costing one read per interval.
160
+ * the 4/s dense-load peak stays near 12/s, against a budget of 25/s. Waiting
161
+ * as long as the delete has been accepted doubles the interval up to 5 minutes,
162
+ * so a stuck sandbox costs one read per interval. The interval counts from the
163
+ * acceptance, not from earlier refusals: in load run 43258059009 ten deletes
164
+ * accepted after nine 409s waited the full 5 minutes for a 404.
160
165
  */
161
166
  const CONFIRMATION_READ_DELAY_MS = 5_000;
162
167
 
163
- function confirmationReadDelay(nextFailureCount: number): number {
168
+ function confirmationReadDelay(deleteAcceptedForMs: number): number {
164
169
  return Math.min(
165
170
  5 * 60_000,
166
- CONFIRMATION_READ_DELAY_MS *
167
- 2 ** Math.min(6, Math.max(0, nextFailureCount - 1)),
171
+ Math.max(CONFIRMATION_READ_DELAY_MS, deleteAcceptedForMs),
172
+ );
173
+ }
174
+
175
+ /**
176
+ * A provider that has taken no delete yet, such as Daytona answering 409 while
177
+ * a sandbox is stuck creating, is asked again at most 30 seconds after it frees
178
+ * up, for its first 32 reads (about 15 minutes). Most 409s clear within about
179
+ * 25 seconds, and in load run 43258059009 they lasted 10 to 15 minutes. Each
180
+ * busy read costs two control requests, a lookup and the refused delete, so a
181
+ * sandbox still refused after that doubles back up to 5 minutes: an incident
182
+ * holding hundreds of sandboxes then costs what it did before this window,
183
+ * instead of two requests per sandbox every 30 seconds for as long as it lasts.
184
+ */
185
+ const BUSY_PROVIDER_FAST_READS = 32;
186
+
187
+ function busyProviderReadDelay(nextFailureCount: number): number {
188
+ if (nextFailureCount <= BUSY_PROVIDER_FAST_READS) {
189
+ return Math.min(
190
+ 30_000,
191
+ CONFIRMATION_READ_DELAY_MS *
192
+ 2 ** Math.min(6, Math.max(0, nextFailureCount - 1)),
193
+ );
194
+ }
195
+ return Math.min(
196
+ 5 * 60_000,
197
+ 30_000 * 2 ** Math.min(4, nextFailureCount - BUSY_PROVIDER_FAST_READS),
168
198
  );
169
199
  }
170
200
 
@@ -29,6 +29,7 @@ export { DAYTONA_SNAPSHOT_BY_PLAY_SANDBOX_SIZE } from '../../daytona-runtime-con
29
29
  import type {
30
30
  PlayRunnerDaytonaCleanupIntent,
31
31
  PlayRunnerRuntimeLifecycleEvent,
32
+ PlayRunnerWorkerSlot,
32
33
  } from '../types';
33
34
  import {
34
35
  daytonaSandboxMatchesOperationIdentity,
@@ -1369,6 +1370,8 @@ async function acquireOneShotDaytonaSandbox(input: {
1369
1370
  nextProviderAttempt: () => number;
1370
1371
  startedAt: number;
1371
1372
  startAdmission?: DaytonaSandboxStartAdmission;
1373
+ /** Lent to the worker while this create holds a start permit. */
1374
+ workerSlot?: PlayRunnerWorkerSlot;
1372
1375
  cancellationSignal?: AbortSignal;
1373
1376
  }): Promise<AcquiredDaytonaSandbox> {
1374
1377
  const limits = validatePlaySandboxRuntimeLimits(
@@ -1387,11 +1390,34 @@ async function acquireOneShotDaytonaSandbox(input: {
1387
1390
  }
1388
1391
  return createRetriedOneShotDaytonaSandbox(input);
1389
1392
  };
1393
+ // The time the run waited to get its worker slot back after the create. It
1394
+ // is not create time: billing and the create:done timing leave it out.
1395
+ let slotWaitMs = 0;
1396
+ const lendingSlot = input.workerSlot;
1397
+ const workerSlot: PlayRunnerWorkerSlot | undefined = lendingSlot && {
1398
+ lend: () => {
1399
+ const loan = lendingSlot.lend();
1400
+ if (!loan) return null;
1401
+ return {
1402
+ reclaim: async () => {
1403
+ const waitStartedAt = Date.now();
1404
+ await loan.reclaim();
1405
+ slotWaitMs = Date.now() - waitStartedAt;
1406
+ input.emitStage('create:slot_reclaimed', { slotWaitMs });
1407
+ },
1408
+ };
1409
+ },
1410
+ };
1390
1411
  const result = input.startAdmission
1391
- ? await input.startAdmission.run(create, input.cancellationSignal, () => {
1392
- admissionQueued = true;
1393
- input.emitStage('create:admission_wait');
1394
- })
1412
+ ? await input.startAdmission.run(
1413
+ create,
1414
+ input.cancellationSignal,
1415
+ () => {
1416
+ admissionQueued = true;
1417
+ input.emitStage('create:admission_wait');
1418
+ },
1419
+ workerSlot,
1420
+ )
1395
1421
  : await create();
1396
1422
  // The runner's egress probe measures the sandbox-to-estate round trip; the
1397
1423
  // sandbox's target names the region that round trip crosses.
@@ -1479,13 +1505,15 @@ async function acquireOneShotDaytonaSandbox(input: {
1479
1505
  result.sandbox,
1480
1506
  daytonaOrganizationId,
1481
1507
  );
1482
- const billingStartedAt = Date.now();
1508
+ // The sandbox was ready before the slot wait, so billing starts there.
1509
+ const billingStartedAt = Date.now() - slotWaitMs;
1483
1510
  const sandbox = result.sandbox;
1484
1511
  input.emitStage('create:done', {
1485
1512
  sandboxId: sandbox.id,
1486
1513
  attempt: result.attempt,
1487
1514
  elapsedMs: billingStartedAt - input.startedAt,
1488
1515
  admissionWaitMs,
1516
+ slotWaitMs,
1489
1517
  attemptElapsedMs: result.attemptElapsedMs,
1490
1518
  // Record the resolved immutable snapshot identifier so slow acquisition
1491
1519
  // can be distinguished from a bad profile snapshot without logging
@@ -1548,6 +1576,7 @@ export function createOneShotDaytonaSandboxLifecycle(input: {
1548
1576
  intent: PlayRunnerDaytonaCleanupIntent,
1549
1577
  ) => Promise<void>;
1550
1578
  startAdmission?: DaytonaSandboxStartAdmission;
1579
+ workerSlot?: PlayRunnerWorkerSlot;
1551
1580
  cancellationSignal?: AbortSignal;
1552
1581
  startedAt?: number;
1553
1582
  }): OneShotDaytonaSandboxLifecycle {
@@ -1568,6 +1597,7 @@ export function createOneShotDaytonaSandboxLifecycle(input: {
1568
1597
  releaseSandboxCapacity: input.releaseSandboxCapacity,
1569
1598
  recordCleanupIntent: input.recordCleanupIntent,
1570
1599
  startAdmission: input.startAdmission,
1600
+ workerSlot: input.workerSlot,
1571
1601
  cancellationSignal: input.cancellationSignal,
1572
1602
  nextProviderAttempt: () => {
1573
1603
  providerAttempt += 1;
@@ -1,10 +1,12 @@
1
1
  import { RUNTIME_CAPACITY_POLICY } from '../../runtime-capacity-policy';
2
+ import type { PlayRunnerWorkerSlot } from '../types';
2
3
 
3
4
  export type DaytonaSandboxStartAdmission = {
4
5
  run<T>(
5
6
  operation: () => Promise<T>,
6
7
  signal?: AbortSignal,
7
8
  onQueued?: () => void,
9
+ workerSlot?: PlayRunnerWorkerSlot,
8
10
  ): Promise<T>;
9
11
  };
10
12
 
@@ -15,6 +17,12 @@ export type DaytonaSandboxStartAdmission = {
15
17
  * transition. A permit covers timeout reconciliation too: releasing it when
16
18
  * `create` times out would admit another create while the first named sandbox
17
19
  * is still transitioning, recreating the unsafe overlap this gate prevents.
20
+ *
21
+ * A run lends its worker slot when it takes a permit, so the worker can claim
22
+ * another run during the create, and keeps the loan until it gets a slot back.
23
+ * The permit is released before the slot is reclaimed: a run waiting here for
24
+ * a permit holds a slot, so reclaiming first could leave each side waiting on
25
+ * the other.
18
26
  */
19
27
  export function createDaytonaSandboxStartAdmission(
20
28
  concurrency = RUNTIME_CAPACITY_POLICY.sandboxAcquisition
@@ -50,6 +58,7 @@ export function createDaytonaSandboxStartAdmission(
50
58
  operation: () => Promise<T>,
51
59
  signal?: AbortSignal,
52
60
  onQueued?: () => void,
61
+ workerSlot?: PlayRunnerWorkerSlot,
53
62
  ): Promise<T> {
54
63
  signal?.throwIfAborted();
55
64
  // Preserve eager prepare semantics when capacity is free: the provider
@@ -76,11 +85,14 @@ export function createDaytonaSandboxStartAdmission(
76
85
  signal?.addEventListener('abort', abort, { once: true });
77
86
  if (signal?.aborted) abort();
78
87
  });
88
+ let loan: { reclaim(): Promise<void> } | null = null;
79
89
  try {
80
90
  signal?.throwIfAborted();
91
+ loan = workerSlot?.lend() ?? null;
81
92
  return await operation();
82
93
  } finally {
83
94
  release();
95
+ if (loan) await loan.reclaim();
84
96
  }
85
97
  },
86
98
  };
@@ -1669,6 +1669,7 @@ function prepareDaytonaExecution(
1669
1669
  releaseSandboxCapacity: callbacks?.releaseSandboxCapacity,
1670
1670
  recordCleanupIntent: callbacks?.recordDaytonaCleanupIntent,
1671
1671
  startAdmission: daytonaSandboxStartAdmission,
1672
+ workerSlot: callbacks?.workerSlot,
1672
1673
  cancellationSignal: callbacks?.cancellationSignal,
1673
1674
  });
1674
1675
  return {
@@ -164,6 +164,16 @@ export function isRuntimeSandboxCapacityLimitError(
164
164
  );
165
165
  }
166
166
 
167
+ /**
168
+ * A scheduler worker slot that can be lent. `lend()` returns null when the
169
+ * worker does not lend slots or its lending budget is spent; the attempt then
170
+ * keeps its slot. A loan keeps the attempt's claim and lease; the attempt must
171
+ * await `reclaim()` before it does more work.
172
+ */
173
+ export type PlayRunnerWorkerSlot = {
174
+ lend(): { reclaim(): Promise<void> } | null;
175
+ };
176
+
167
177
  export interface PlayRunnerCallbacks {
168
178
  onLog?: (event: PlayRunnerLogEvent) => void;
169
179
  onCheckpoint?: (checkpoint: PlayCheckpoint) => void;
@@ -200,6 +210,12 @@ export interface PlayRunnerCallbacks {
200
210
  intent: PlayRunnerAmbiguousModalCreateIntent,
201
211
  ) => void | Promise<void>;
202
212
  onAmbiguousModalCreateResolved?: () => void | Promise<void>;
213
+ /**
214
+ * The scheduler worker slot this attempt runs in. A backend may lend it
215
+ * while the attempt only waits on a provider sandbox create, so the worker
216
+ * can claim another run meanwhile.
217
+ */
218
+ workerSlot?: PlayRunnerWorkerSlot;
203
219
  /** Reserve one physical-sandbox slot immediately before a provider create. */
204
220
  reserveSandboxCapacity?: (
205
221
  provider: 'daytona' | 'modal' | 'agentcore_runtime',
@@ -38,6 +38,18 @@ export const RUNTIME_CAPACITY_POLICY = {
38
38
  maxScaleUpMachinesPerReconcile: 4,
39
39
  /** Do not tear down burst capacity on the first empty observation. */
40
40
  scaleDownQuietMs: 120_000,
41
+ /**
42
+ * Stopped active-lane workers kept for restart instead of deleted. A
43
+ * restart reuses the Machine's Fly egress wiring and image: Production
44
+ * boots it in about 1.3 s, against about 12 s for a new Machine, which
45
+ * waits for its app-scoped static egress IP before it can reach the
46
+ * database (16% of fresh boots crashed on that wait, 2026-11-10/11).
47
+ * Six is the whole burst headroom (maxFleetMachines - activeLaneMachines);
48
+ * 99% of 161 Production bursts added at most six Machines in their first
49
+ * minute. More could never start at once inside the fleet budget. Fly
50
+ * bills a stopped Machine's rootfs at $0.15 per GB-month.
51
+ */
52
+ retainedStoppedActiveLaneMachines: 6,
41
53
  },
42
54
  executionRelay: {
43
55
  /** Keep two relay Machines available for deploys and one-machine faults. */
@@ -78,12 +90,21 @@ export const RUNTIME_CAPACITY_POLICY = {
78
90
  sandboxAcquisition: {
79
91
  /**
80
92
  * Starting a Daytona sandbox is a provider control-plane transition, not
81
- * an Absurd execution slot. Allow up to five concurrent starts within one
82
- * worker process; the fleet-wide limiter paces lifecycle admissions, and
83
- * this semaphore bounds concurrent create/retry ladders. A worker has
84
- * eight execution slots.
93
+ * an Absurd execution slot. The fleet-wide limiter paces lifecycle
94
+ * admissions; this semaphore bounds concurrent create/retry ladders in one
95
+ * worker process. A run lends its execution slot from taking a permit
96
+ * until it gets a slot back after its create, and during its pre-park
97
+ * lifecycle flush, so a worker holds at most 8 slots + twice this many
98
+ * runs + 10 flush loans (`ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS`).
99
+ *
100
+ * Ten lets the two warm workers reach the limiter's 10 starts a second on
101
+ * their own: a create took 1.5-2.2 s mean in the 2026-11-12 bursts, so
102
+ * 5 a second per worker needs 8-11 in flight. At five, a worker's creates
103
+ * topped out near 5 / 1.8 s = 2.8 a second, and 40% of warm-phase runs
104
+ * waited for a permit. Across 8 workers the limiter, not this bound, caps
105
+ * new creates.
85
106
  */
86
- daytonaConcurrentStartsPerProcess: 5,
107
+ daytonaConcurrentStartsPerProcess: 10,
87
108
  /** Fleet-wide AIMD lifecycle-admission pacing. */
88
109
  daytonaInitialStartsPerMinute: 120,
89
110
  daytonaMaximumStartsPerMinute: 600,
@@ -2,6 +2,8 @@ import {
2
2
  createTelemetry,
3
3
  TELEMETRY_TRIAGE_SCHEMA_VERSION,
4
4
  } from '../observability/telemetry';
5
+ import { sha256Hex } from '../plays/row-identity';
6
+ import { readProvenanceTag } from './log-provenance';
5
7
 
6
8
  type PlayRuntimeTelemetryInput = {
7
9
  phase: string;
@@ -277,6 +279,11 @@ export type PlayRunRecoveryDecision = {
277
279
  deferCount: number | null;
278
280
  /** Deferred only: how long until the retry is due. */
279
281
  delayMs: number | null;
282
+ /**
283
+ * Deferred only: compiled start pacing, uncounted, which shares its reason
284
+ * with an operator throttle. Omitted means not paced.
285
+ */
286
+ paced?: boolean;
280
287
  };
281
288
 
282
289
  /**
@@ -303,6 +310,7 @@ export function emitPlayRunRecoveryDecision(
303
310
  input.outcome === 'deferred'
304
311
  ? durabilityDecisionCount(input.delayMs)
305
312
  : null,
313
+ paced: input.outcome === 'deferred' && input.paced === true,
306
314
  },
307
315
  });
308
316
  }
@@ -347,3 +355,124 @@ export function emitPlayRunResumeDecision(input: PlayRunResumeDecision): void {
347
355
  },
348
356
  });
349
357
  }
358
+
359
+ /**
360
+ * A runner-decided durable replay refusal, read back from the structured
361
+ * `durable_replay_refused` run-log record the runner writes where it refuses
362
+ * (`reportReplayRefusal` in `context.ts`). Runner stderr is not shipped from
363
+ * Modal or Daytona sandboxes, so the server that ingests the run's log lines
364
+ * re-emits each record as one fleet-visible line.
365
+ */
366
+ export type DurableReplayRefusalRecord = {
367
+ code: string;
368
+ operation: string;
369
+ rung: string;
370
+ reason: string;
371
+ slot: string | null;
372
+ ordinal: number | null;
373
+ /** The runner's running count for this code, operation and authored id. */
374
+ refusalCount: number;
375
+ /** Fingerprint of the authored call id: a dedupe key, never the id itself. */
376
+ callKeyHash: string;
377
+ };
378
+
379
+ const RUN_LOG_RECORD_FRAME =
380
+ /^\[[^\]\s]+\] (?:\[(?:debug|info|warn|error)\] )?(\{[\s\S]*\})$/u;
381
+ const DURABLE_REPLAY_REFUSAL_CODE = /^DURABLE_REPLAY_[A-Z_]{1,64}$/;
382
+
383
+ function shortFingerprint(value: string): string {
384
+ return sha256Hex(value).slice(0, 16);
385
+ }
386
+
387
+ /**
388
+ * The refusal carried by one ingested run-log line, or null. Only the
389
+ * runtime's own structured record counts: a customer-authored line
390
+ * (`ctx.log` and captured console output are always tagged `user`) never
391
+ * does, whatever its text, and the record must be the line's whole JSON
392
+ * object with `event: 'durable_replay_refused'`. The runner already
393
+ * rate-limits each refusal key to counts 1, 2, 4, 8 and so on; a record off
394
+ * that sequence is not forwarded, so the server line keeps the same limit.
395
+ */
396
+ export function durableReplayRefusalFromRunLogLine(
397
+ line: unknown,
398
+ ): DurableReplayRefusalRecord | null {
399
+ if (typeof line !== 'string' || line.length === 0) return null;
400
+ const tagged = readProvenanceTag(line.trim());
401
+ if (tagged.provenance !== null && tagged.provenance !== 'diagnostic') {
402
+ return null;
403
+ }
404
+ const json = tagged.line.match(RUN_LOG_RECORD_FRAME)?.[1];
405
+ if (!json) return null;
406
+ let record: unknown;
407
+ try {
408
+ record = JSON.parse(json);
409
+ } catch {
410
+ return null;
411
+ }
412
+ if (!record || typeof record !== 'object' || Array.isArray(record)) {
413
+ return null;
414
+ }
415
+ const fields = record as Record<string, unknown>;
416
+ if (fields.event !== 'durable_replay_refused') return null;
417
+ const code = fields.code;
418
+ if (typeof code !== 'string' || !DURABLE_REPLAY_REFUSAL_CODE.test(code)) {
419
+ return null;
420
+ }
421
+ const refusalCount = durabilityDecisionCount(fields.refusal_count);
422
+ if (
423
+ refusalCount === null ||
424
+ refusalCount < 1 ||
425
+ (refusalCount & (refusalCount - 1)) !== 0
426
+ ) {
427
+ return null;
428
+ }
429
+ return {
430
+ code,
431
+ operation: durabilityDecisionReason(fields.operation),
432
+ rung: durabilityDecisionReason(fields.rung),
433
+ reason: durabilityDecisionReason(fields.reason),
434
+ slot:
435
+ fields.slot === undefined || fields.slot === null
436
+ ? null
437
+ : durabilityDecisionReason(fields.slot),
438
+ ordinal: durabilityDecisionCount(fields.ordinal),
439
+ refusalCount,
440
+ callKeyHash: shortFingerprint(
441
+ typeof fields.call_key === 'string' ? fields.call_key : '',
442
+ ),
443
+ };
444
+ }
445
+
446
+ /**
447
+ * One line per forwarded runner refusal: `play.run.replay_refused`. Identities
448
+ * come from the ingesting server's authenticated launch, not from the record.
449
+ * Distinct refusals are `dcount(runId, attempt, callKeyHash, code,
450
+ * operation, refusalCount)`: live ingest and terminal replay can both carry one record.
451
+ */
452
+ export function emitPlayRunReplayRefusal(input: {
453
+ orgId: string | null;
454
+ runId: string;
455
+ playName: string | null;
456
+ attempt: number | null;
457
+ refusal: DurableReplayRefusalRecord;
458
+ }): void {
459
+ emitPlayTelemetry({
460
+ level: 'warn',
461
+ event: 'play.run.replay_refused',
462
+ tag: '[play.run.replay_refused]',
463
+ fields: {
464
+ orgId: input.orgId,
465
+ runId: input.runId,
466
+ playName: input.playName,
467
+ attempt: durabilityDecisionCount(input.attempt),
468
+ code: input.refusal.code,
469
+ operation: input.refusal.operation,
470
+ rung: input.refusal.rung,
471
+ reason: input.refusal.reason,
472
+ slot: input.refusal.slot,
473
+ ordinal: input.refusal.ordinal,
474
+ refusalCount: input.refusal.refusalCount,
475
+ callKeyHash: input.refusal.callKeyHash,
476
+ },
477
+ });
478
+ }
@@ -3,6 +3,7 @@ import type {
3
3
  PlayRunnerCallbacks,
4
4
  PlayRunnerRuntimeLifecycleEvent,
5
5
  PlayRunnerRuntimeResource,
6
+ PlayRunnerWorkerSlot,
6
7
  } from '../runner-backends/types';
7
8
  import { SandboxRunnerPreCodeDeferralError } from '../runner-backends/types';
8
9
  import type {
@@ -61,6 +62,8 @@ export type SandboxRunnerBackendAdapterDependencies = {
61
62
  interpretResult: SandboxRunnerResultInterpreter;
62
63
  cancellationSignal?: AbortSignal;
63
64
  progress?: SandboxRunnerProgress;
65
+ /** The scheduler worker slot this attempt runs in, lendable during a create. */
66
+ workerSlot?: PlayRunnerWorkerSlot;
64
67
  };
65
68
 
66
69
  /**
@@ -97,6 +100,7 @@ export function createPlayRunnerBackendSandboxExecutionAdapter(
97
100
  readiness: dependencies.readiness,
98
101
  cancellationSignal: dependencies.cancellationSignal,
99
102
  progress: dependencies.progress,
103
+ workerSlot: dependencies.workerSlot,
100
104
  });
101
105
  let result: PlayRunnerResult;
102
106
  try {
@@ -126,6 +130,7 @@ function createRunnerCallbacks(input: {
126
130
  readiness: SandboxRunnerReadiness;
127
131
  cancellationSignal?: AbortSignal;
128
132
  progress?: SandboxRunnerProgress;
133
+ workerSlot?: PlayRunnerWorkerSlot;
129
134
  }): PlayRunnerCallbacks {
130
135
  const remember = (resource: PlayRunnerRuntimeResource) => {
131
136
  const converted = toSandboxResource(resource);
@@ -147,6 +152,7 @@ function createRunnerCallbacks(input: {
147
152
 
148
153
  return {
149
154
  cancellationSignal: input.cancellationSignal,
155
+ ...(input.workerSlot ? { workerSlot: input.workerSlot } : {}),
150
156
  onLog: input.progress?.onLog,
151
157
  onCheckpoint: input.progress?.onCheckpoint,
152
158
  onRowUpdate: input.progress?.onRowUpdate,
@@ -0,0 +1,145 @@
1
+ import {
2
+ CancelledTask,
3
+ SuspendTask,
4
+ type WorkerClaimSnapshot,
5
+ } from '@deepline/absurd/sdk';
6
+ import type {
7
+ AbsurdClaimQueryTiming,
8
+ AbsurdSchedulerQueryObserver,
9
+ } from './absurd-pool';
10
+
11
+ /**
12
+ * Timing for the parts of a worker slot's hold that no other line logs: the
13
+ * engine's claim query, the `afterClaim` hook that runs after every claim
14
+ * before the claimed tasks start, the task setup before a handler starts,
15
+ * and the end of the handler once its run parks. On the two warm workers of
16
+ * round 43371126678-1 about 0.4 s of the 1.9 s each run held a slot fell
17
+ * there. Logging only: no claim, slot, lease or durable state changes.
18
+ *
19
+ * Lines (one physical line each):
20
+ * - `[absurd-runtime.worker.claim_cycle]` per claim that returned tasks:
21
+ * pool wait and query time of the claim, the `afterClaim` time,
22
+ * `heldTasks`, and `handlersRunning`. `heldTasks` is the engine's count of
23
+ * every task the worker holds once the claim's tasks start (in a slot or
24
+ * with it lent, any task name, setup and finalization included), bounded by
25
+ * slots + lent slots. `handlersRunning` is the play-run handlers already
26
+ * running in this process, a subset of it.
27
+ * - `[absurd-runtime.worker.phase]` `task_setup`: claim returned -> handler
28
+ * started (the `afterClaim` hook plus the engine's task context load).
29
+ * - `[absurd-runtime.worker.phase]` `handler_end`: handler started -> ended,
30
+ * with `outcome` `parked` when the run suspended (its slot frees then).
31
+ */
32
+ export type AbsurdClaimLoopTiming = {
33
+ /** Pass to `createAbsurdRuntimeClient` so claim queries are timed. */
34
+ observer: AbsurdSchedulerQueryObserver;
35
+ /** Wraps the worker's `afterClaim` hook. */
36
+ afterClaim(
37
+ hook: () => Promise<void>,
38
+ ): (claim: WorkerClaimSnapshot) => Promise<void>;
39
+ /** Wraps one play-run handler invocation. */
40
+ playRunHandler<T>(
41
+ run: { runId: string; taskId: string },
42
+ handler: () => Promise<T>,
43
+ ): Promise<T>;
44
+ };
45
+
46
+ /** A claimed task whose handler never started is forgotten after this. */
47
+ const CLAIMED_TASK_RETENTION_MS = 60_000;
48
+
49
+ export function createAbsurdClaimLoopTiming(input: {
50
+ queue: string;
51
+ log?: (line: string) => void;
52
+ now?: () => number;
53
+ }): AbsurdClaimLoopTiming {
54
+ const log = input.log ?? ((line: string) => console.info(line));
55
+ const now = input.now ?? (() => performance.now());
56
+ // The engine awaits `afterClaim` right after each claim query, one claim at
57
+ // a time, so the latest claim is the one the hook follows.
58
+ let lastClaim: AbsurdClaimQueryTiming | null = null;
59
+ const claimReturnedAt = new Map<string, number>();
60
+ let handlersRunning = 0;
61
+ return {
62
+ observer: {
63
+ onClaimTask(timing) {
64
+ lastClaim = timing;
65
+ for (const [taskId, returnedAt] of claimReturnedAt) {
66
+ if (timing.returnedAt - returnedAt > CLAIMED_TASK_RETENTION_MS) {
67
+ claimReturnedAt.delete(taskId);
68
+ }
69
+ }
70
+ for (const taskId of timing.taskIds) {
71
+ claimReturnedAt.set(taskId, timing.returnedAt);
72
+ }
73
+ },
74
+ },
75
+ afterClaim: (hook) => async (snapshot) => {
76
+ const claim = lastClaim;
77
+ lastClaim = null;
78
+ const startedAt = now();
79
+ let ok = false;
80
+ try {
81
+ await hook();
82
+ ok = true;
83
+ } finally {
84
+ if (claim && claim.taskIds.length > 0) {
85
+ log(
86
+ '[absurd-runtime.worker.claim_cycle] ' +
87
+ JSON.stringify({
88
+ queue: input.queue,
89
+ claimed: claim.taskIds.length,
90
+ taskIds: claim.taskIds,
91
+ claimPoolWaitMs: claim.poolWaitMs,
92
+ claimQueryMs: claim.queryMs,
93
+ claimMs: claim.totalMs,
94
+ afterClaimMs: now() - startedAt,
95
+ afterClaimOk: ok,
96
+ heldTasks: snapshot.heldTasks,
97
+ handlersRunning,
98
+ }),
99
+ );
100
+ }
101
+ }
102
+ },
103
+ async playRunHandler(run, handler) {
104
+ const startedAt = now();
105
+ const returnedAt = claimReturnedAt.get(run.taskId);
106
+ claimReturnedAt.delete(run.taskId);
107
+ if (returnedAt !== undefined) {
108
+ log(
109
+ '[absurd-runtime.worker.phase] ' +
110
+ JSON.stringify({
111
+ runId: run.runId,
112
+ taskId: run.taskId,
113
+ phase: 'task_setup',
114
+ totalMs: startedAt - returnedAt,
115
+ ok: true,
116
+ }),
117
+ );
118
+ }
119
+ let outcome: 'returned' | 'parked' | 'cancelled' | 'threw' = 'threw';
120
+ handlersRunning += 1;
121
+ try {
122
+ const result = await handler();
123
+ outcome = 'returned';
124
+ return result;
125
+ } catch (error) {
126
+ if (error instanceof SuspendTask) outcome = 'parked';
127
+ else if (error instanceof CancelledTask) outcome = 'cancelled';
128
+ throw error;
129
+ } finally {
130
+ handlersRunning -= 1;
131
+ log(
132
+ '[absurd-runtime.worker.phase] ' +
133
+ JSON.stringify({
134
+ runId: run.runId,
135
+ taskId: run.taskId,
136
+ phase: 'handler_end',
137
+ totalMs: now() - startedAt,
138
+ ok: outcome !== 'threw',
139
+ outcome,
140
+ }),
141
+ );
142
+ }
143
+ },
144
+ };
145
+ }