deepline 0.3.526 → 0.3.528

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 (148) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +141 -211
  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 +135 -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 +59 -8
  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 +25 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +6 -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 +316 -71
  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.ts +105 -13
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +12 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/result-receipt-policy.ts +10 -1
  24. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +50 -8
  25. package/dist/cli/auth-CWJZYLTB.js +43 -0
  26. package/dist/cli/{auth-JATW5XZE.mjs → auth-PPOTNK4T.mjs} +5 -5
  27. package/dist/cli/{billing-TSHBJIJS.js → billing-3C7T7CUQ.js} +79 -79
  28. package/dist/cli/{billing-UT5LIESH.mjs → billing-OEZUQ2K6.mjs} +6 -6
  29. package/dist/cli/{chunk-UWCEBS7F.js → chunk-237PKFIQ.js} +14 -14
  30. package/dist/cli/{chunk-TBQC2XS3.js → chunk-36UD7H7Y.js} +41 -41
  31. package/dist/cli/{chunk-26ULNPQ7.mjs → chunk-42ZSDTOC.mjs} +2 -2
  32. package/dist/cli/{chunk-O7WUATQC.js → chunk-4SBUXDKZ.js} +13 -13
  33. package/dist/cli/{chunk-SCLRGDF4.js → chunk-5MJ4CDAQ.js} +44 -44
  34. package/dist/cli/{chunk-BFH3DJYV.mjs → chunk-6OLQWQU5.mjs} +3 -3
  35. package/dist/cli/{chunk-UTCGCES2.js → chunk-7WZXUAQW.js} +7 -7
  36. package/dist/cli/{chunk-CYN2AHR6.js → chunk-7X3NLHI7.js} +6 -6
  37. package/dist/cli/{chunk-D5OEUPPM.js → chunk-ADZGTMLU.js} +98 -98
  38. package/dist/cli/{chunk-6COGHW7B.mjs → chunk-AFIAVG5T.mjs} +2 -2
  39. package/dist/cli/{chunk-BYEF4RBX.js → chunk-B3HQF2CA.js} +11 -11
  40. package/dist/cli/{chunk-DY2AT3JQ.mjs → chunk-B6YWCGVC.mjs} +10 -10
  41. package/dist/cli/{chunk-BVITYMBK.mjs → chunk-CMTY6SVY.mjs} +2 -2
  42. package/dist/cli/{chunk-WOLY6SU4.mjs → chunk-DCVNL5XN.mjs} +1 -1
  43. package/dist/cli/{chunk-6JMWATX5.mjs → chunk-FPHAUP55.mjs} +5 -5
  44. package/dist/cli/{chunk-7COEN3IR.js → chunk-FXYWEKUK.js} +4 -4
  45. package/dist/cli/{chunk-J5OXJ4JI.js → chunk-G7RTPKRJ.js} +2 -2
  46. package/dist/cli/{chunk-RZJWHL7L.js → chunk-GCBFSFLA.js} +5 -5
  47. package/dist/cli/{chunk-C3EW6I65.mjs → chunk-GFGFAAY2.mjs} +1 -1
  48. package/dist/cli/{chunk-XVIMOB2U.mjs → chunk-GP7E4TE4.mjs} +2 -2
  49. package/dist/cli/{chunk-HPACLONQ.mjs → chunk-GSBKODMU.mjs} +2 -2
  50. package/dist/cli/{chunk-EEYZLTXX.mjs → chunk-HJVNCRXY.mjs} +1 -1
  51. package/dist/cli/{chunk-WITNIMLE.js → chunk-IJAEYEJM.js} +3 -3
  52. package/dist/cli/{chunk-YNFPZVII.mjs → chunk-IM5XQ4DG.mjs} +5 -5
  53. package/dist/cli/{chunk-46HEYGLY.js → chunk-IXEEXYE2.js} +9 -9
  54. package/dist/cli/{chunk-MQB25LMV.mjs → chunk-IYCRX34W.mjs} +5 -5
  55. package/dist/cli/{chunk-6H56LKJB.js → chunk-KHVCHFE3.js} +16 -16
  56. package/dist/cli/{chunk-TVHDWS5U.mjs → chunk-KLGYBOGZ.mjs} +1 -1
  57. package/dist/cli/{chunk-UUIC2JFZ.mjs → chunk-KWIKFR7Y.mjs} +1 -1
  58. package/dist/cli/{chunk-ED2N4NRI.js → chunk-LT4IEJ6V.js} +16 -16
  59. package/dist/cli/{chunk-WBY3R55B.js → chunk-LU4EA3ET.js} +2 -2
  60. package/dist/cli/{chunk-477PXM65.js → chunk-MLNH4DK2.js} +22 -22
  61. package/dist/cli/{chunk-77RAGJIZ.mjs → chunk-NCOTOGTK.mjs} +2 -2
  62. package/dist/cli/{chunk-IMP7WR22.mjs → chunk-NZM4KWWV.mjs} +5 -5
  63. package/dist/cli/{chunk-B33J4YCC.js → chunk-OEI7YUEF.js} +3 -3
  64. package/dist/cli/{chunk-3MYI3IXW.js → chunk-OGVUT2KM.js} +7 -7
  65. package/dist/cli/{chunk-SJ6KUCGM.js → chunk-OVZSNBDJ.js} +53 -53
  66. package/dist/cli/{chunk-D2XMFXFM.mjs → chunk-PS2UYVAE.mjs} +6 -6
  67. package/dist/cli/{chunk-3ZEV5BS5.js → chunk-R5ZQVQ3K.js} +26 -26
  68. package/dist/cli/{chunk-TCLJXJAG.mjs → chunk-RC5CG5SE.mjs} +4 -4
  69. package/dist/cli/{chunk-6DHEV6IA.js → chunk-RFTBMEWL.js} +2 -2
  70. package/dist/cli/{chunk-2GJW4RAQ.mjs → chunk-RML3VSTN.mjs} +1 -1
  71. package/dist/cli/{chunk-2JNX3MDG.mjs → chunk-SP2KZ7SH.mjs} +1 -1
  72. package/dist/cli/{chunk-IWLDJQGV.mjs → chunk-T4QPRL3P.mjs} +3 -3
  73. package/dist/cli/{chunk-Y47OCS5V.mjs → chunk-ULUI2FEM.mjs} +1 -1
  74. package/dist/cli/{chunk-FMPGWAIR.js → chunk-WXHBD6H7.js} +1 -1
  75. package/dist/cli/{chunk-CDP3LMDT.js → chunk-XD2DRBPH.js} +6 -6
  76. package/dist/cli/{chunk-TXJW6RIM.mjs → chunk-Z25KC5V2.mjs} +1 -1
  77. package/dist/cli/{chunk-U6OUX47C.mjs → chunk-Z44S7VWO.mjs} +2 -2
  78. package/dist/cli/{chunk-F5KFGF45.js → chunk-ZFD5FJCZ.js} +5 -5
  79. package/dist/cli/{csv-4BLFRED6.mjs → csv-K7TRWOFJ.mjs} +4 -4
  80. package/dist/cli/{csv-KSJB5Z3M.js → csv-OTRVTHD2.js} +13 -13
  81. package/dist/cli/{db-OVW6C3DV.mjs → db-C7GQU3TZ.mjs} +6 -6
  82. package/dist/cli/{db-G7Z5CKO2.js → db-UO2ZFLFN.js} +27 -27
  83. package/dist/cli/describe-IK4UYJ5M.js +50 -0
  84. package/dist/cli/{describe-OEFTD7WQ.mjs → describe-LG4CPTIV.mjs} +18 -18
  85. package/dist/cli/{executions-O7USCBCW.js → executions-LHFVPO7E.js} +8 -8
  86. package/dist/cli/{executions-7ZKQ4ZU3.mjs → executions-P3INNVZE.mjs} +6 -6
  87. package/dist/cli/{feedback-KUBL5E3I.mjs → feedback-H22FWG63.mjs} +6 -6
  88. package/dist/cli/{feedback-Y55WCRIQ.js → feedback-M3HZQAWX.js} +14 -14
  89. package/dist/cli/git-72ADWRUQ.js +25 -0
  90. package/dist/cli/{git-C6ZAU5JA.mjs → git-G2N7PVFI.mjs} +5 -5
  91. package/dist/cli/index.js +141 -141
  92. package/dist/cli/index.mjs +43 -43
  93. package/dist/cli/{legacy-noops-OVWX4KB3.js → legacy-noops-2RVROWBY.js} +9 -9
  94. package/dist/cli/{legacy-noops-MUXD4HRC.mjs → legacy-noops-LDYSWTL2.mjs} +6 -6
  95. package/dist/cli/{monitors-2ZSGBY52.mjs → monitors-IYT3VON7.mjs} +7 -7
  96. package/dist/cli/{monitors-3QVYGYWA.js → monitors-U4RE6KN5.js} +100 -100
  97. package/dist/cli/{org-RDSPE5FB.mjs → org-R3JE22GS.mjs} +6 -6
  98. package/dist/cli/{org-S6Z3SDLI.js → org-SO52ZGRP.js} +86 -86
  99. package/dist/cli/{pages-K5DSMHLJ.mjs → pages-5RLT5YTF.mjs} +6 -6
  100. package/dist/cli/{pages-VUWF2OR7.js → pages-SWXJQJXH.js} +18 -18
  101. package/dist/cli/{play-PZLXOYEX.mjs → play-2ELYCSXZ.mjs} +18 -18
  102. package/dist/cli/{play-SQOJTUFC.js → play-J4UXOQOJ.js} +317 -317
  103. package/dist/cli/{providers-AMIGP3D4.mjs → providers-IXITXHTS.mjs} +6 -6
  104. package/dist/cli/{providers-FZBEPUOI.js → providers-VVUDGV2D.js} +9 -9
  105. package/dist/cli/{quickstart-HNOQKGOF.mjs → quickstart-HQCGDPPL.mjs} +4 -4
  106. package/dist/cli/{quickstart-QIHZDBGM.js → quickstart-XPH6MT47.js} +6 -6
  107. package/dist/cli/{run-JDW6BDNT.mjs → run-H2HQPWC4.mjs} +23 -23
  108. package/dist/cli/{run-IQGM3TO2.js → run-OR646AC6.js} +41 -41
  109. package/dist/cli/search-D27DZH2D.js +33 -0
  110. package/dist/cli/{search-DMVUKJ23.mjs → search-MBPI5SBW.mjs} +8 -8
  111. package/dist/cli/{search-output-5UAPUUHH.mjs → search-output-CYOMJNRV.mjs} +4 -4
  112. package/dist/cli/{search-output-UUW6UNHF.js → search-output-YGNSHBXX.js} +6 -6
  113. package/dist/cli/{secrets-U532KN24.js → secrets-HVZKNNLZ.js} +15 -15
  114. package/dist/cli/{secrets-46KSTPFN.mjs → secrets-NK2CN7WI.mjs} +6 -6
  115. package/dist/cli/sessions-MTISSOZ4.js +22 -0
  116. package/dist/cli/{sessions-RUNWYHYX.mjs → sessions-NY4G427U.mjs} +6 -6
  117. package/dist/cli/{settings-O2A37FFA.js → settings-PVJRDEN2.js} +86 -86
  118. package/dist/cli/{settings-56L3WHCY.mjs → settings-RC4FGYY2.mjs} +13 -13
  119. package/dist/cli/{setup-ETFSMSCH.js → setup-B7QB4YV2.js} +50 -50
  120. package/dist/cli/{setup-Q27X6JZY.mjs → setup-YT3XSY6X.mjs} +10 -10
  121. package/dist/cli/{skills-WFQRZL4D.mjs → skills-5ILFNAHR.mjs} +8 -8
  122. package/dist/cli/skills-BHF35NLX.js +37 -0
  123. package/dist/cli/{tools-EV6CKJOX.mjs → tools-7PAY32OZ.mjs} +17 -17
  124. package/dist/cli/tools-W5BZ37L6.js +57 -0
  125. package/dist/cli/update-M65CGK42.js +35 -0
  126. package/dist/cli/{update-KIPPFVCH.mjs → update-Z27QYB6O.mjs} +10 -10
  127. package/dist/cli/{views-LMJXWD4N.mjs → views-2IANF6KR.mjs} +6 -6
  128. package/dist/cli/{views-DNZ2HFTA.js → views-NP2SCMOV.js} +18 -18
  129. package/dist/cli/{workflow-ZUDTIOK6.js → workflow-2GNQL646.js} +17 -17
  130. package/dist/cli/{workflow-3XKUQ73U.mjs → workflow-CAMEZLLY.mjs} +7 -7
  131. package/dist/index.js +9 -9
  132. package/dist/index.mjs +6 -6
  133. package/dist/install-integrity.json +105 -104
  134. package/dist/release.d.mts +1 -1
  135. package/dist/release.d.ts +1 -1
  136. package/dist/release.js +2 -2
  137. package/dist/release.mjs +1 -1
  138. package/dist/server.js +5 -5
  139. package/dist/server.mjs +3 -3
  140. package/package.json +1 -1
  141. package/dist/cli/auth-L2POG3LL.js +0 -43
  142. package/dist/cli/describe-KMYR2JBC.js +0 -50
  143. package/dist/cli/git-NBVQ3VGW.js +0 -25
  144. package/dist/cli/search-BNWRL3YY.js +0 -33
  145. package/dist/cli/sessions-JZUONXH4.js +0 -22
  146. package/dist/cli/skills-IKDJ5JDN.js +0 -37
  147. package/dist/cli/tools-B735AA67.js +0 -57
  148. package/dist/cli/update-CNNURAM3.js +0 -35
@@ -19,6 +19,7 @@ import type {
19
19
  import { isIsolatedRuntimeSchedulerSchema } from '../../runtime-scheduler-topology';
20
20
  import { PLAY_RUNNER_TIMEOUT_SECONDS } from '../../runtime-constants';
21
21
  import {
22
+ MAX_PLAY_SANDBOX_RUNTIME_LIMITS,
22
23
  STANDARD_PLAY_SANDBOX_RUNTIME_LIMITS,
23
24
  playSandboxSizeForLimits,
24
25
  validatePlaySandboxRuntimeLimits,
@@ -28,6 +29,7 @@ export { DAYTONA_SNAPSHOT_BY_PLAY_SANDBOX_SIZE } from '../../daytona-runtime-con
28
29
  import type {
29
30
  PlayRunnerDaytonaCleanupIntent,
30
31
  PlayRunnerRuntimeLifecycleEvent,
32
+ PlayRunnerWorkerSlot,
31
33
  } from '../types';
32
34
  import {
33
35
  daytonaSandboxMatchesOperationIdentity,
@@ -78,6 +80,28 @@ const DAYTONA_ABSENT_OPERATION_RECREATE_AFTER_MS = 3 * 60_000;
78
80
  // `reserved`, and `deleting` can never be promoted to `live`, so no runner
79
81
  // command can reach it afterwards.
80
82
  export const DAYTONA_STUCK_CREATING_REPLACE_AFTER_MS = 2 * 60_000;
83
+
84
+ /** Daytona's inactivity stop for a one-shot sandbox of this Play timeout. */
85
+ export function daytonaAutoStopIntervalMinutes(timeoutSeconds: number): number {
86
+ return Math.ceil(
87
+ (timeoutSeconds + PLAY_RUNNER_TIMEOUT_SECONDS - 30 * 60) / 60,
88
+ );
89
+ }
90
+
91
+ /**
92
+ * How long after it was sent a one-shot create that landed late is certainly
93
+ * gone. Every one-shot sandbox is ephemeral: Daytona deletes it as soon as it
94
+ * stops, and it stops at the latest after the longest Play's inactivity
95
+ * interval. Thirty minutes on top cover a create the provider accepted but had
96
+ * not yet made visible, and a create sent a few minutes after its reservation
97
+ * was read.
98
+ */
99
+ export const DAYTONA_SENT_CREATE_GONE_AFTER_MS =
100
+ daytonaAutoStopIntervalMinutes(
101
+ MAX_PLAY_SANDBOX_RUNTIME_LIMITS.timeoutSeconds,
102
+ ) *
103
+ 60_000 +
104
+ 30 * 60_000;
81
105
  // Explicit runner deadline + scheduler GC own the normal lifecycle. Daytona's
82
106
  // inactivity stop is a wider crash backstop measured from sandbox creation, so
83
107
  // setup time cannot consume the terminal-flush grace.
@@ -642,9 +666,7 @@ async function createOneShotDaytonaSandbox(input: {
642
666
  // Daytona deletes an ephemeral sandbox immediately when it stops.
643
667
  ephemeral: true,
644
668
  autoDeleteInterval: 0,
645
- autoStopInterval: Math.ceil(
646
- (limits.timeoutSeconds + PLAY_RUNNER_TIMEOUT_SECONDS - 30 * 60) / 60,
647
- ),
669
+ autoStopInterval: daytonaAutoStopIntervalMinutes(limits.timeoutSeconds),
648
670
  autoArchiveInterval: DAYTONA_AUTO_ARCHIVE_INTERVAL_MINUTES,
649
671
  // A non-empty `networkAllowList` IS the "block all egress except these
650
672
  // CIDRs" control; Daytona rejects create when `networkBlockAll: true` is
@@ -1348,6 +1370,8 @@ async function acquireOneShotDaytonaSandbox(input: {
1348
1370
  nextProviderAttempt: () => number;
1349
1371
  startedAt: number;
1350
1372
  startAdmission?: DaytonaSandboxStartAdmission;
1373
+ /** Lent to the worker while this create holds a start permit. */
1374
+ workerSlot?: PlayRunnerWorkerSlot;
1351
1375
  cancellationSignal?: AbortSignal;
1352
1376
  }): Promise<AcquiredDaytonaSandbox> {
1353
1377
  const limits = validatePlaySandboxRuntimeLimits(
@@ -1366,11 +1390,34 @@ async function acquireOneShotDaytonaSandbox(input: {
1366
1390
  }
1367
1391
  return createRetriedOneShotDaytonaSandbox(input);
1368
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
+ };
1369
1411
  const result = input.startAdmission
1370
- ? await input.startAdmission.run(create, input.cancellationSignal, () => {
1371
- admissionQueued = true;
1372
- input.emitStage('create:admission_wait');
1373
- })
1412
+ ? await input.startAdmission.run(
1413
+ create,
1414
+ input.cancellationSignal,
1415
+ () => {
1416
+ admissionQueued = true;
1417
+ input.emitStage('create:admission_wait');
1418
+ },
1419
+ workerSlot,
1420
+ )
1374
1421
  : await create();
1375
1422
  // The runner's egress probe measures the sandbox-to-estate round trip; the
1376
1423
  // sandbox's target names the region that round trip crosses.
@@ -1458,13 +1505,15 @@ async function acquireOneShotDaytonaSandbox(input: {
1458
1505
  result.sandbox,
1459
1506
  daytonaOrganizationId,
1460
1507
  );
1461
- const billingStartedAt = Date.now();
1508
+ // The sandbox was ready before the slot wait, so billing starts there.
1509
+ const billingStartedAt = Date.now() - slotWaitMs;
1462
1510
  const sandbox = result.sandbox;
1463
1511
  input.emitStage('create:done', {
1464
1512
  sandboxId: sandbox.id,
1465
1513
  attempt: result.attempt,
1466
1514
  elapsedMs: billingStartedAt - input.startedAt,
1467
1515
  admissionWaitMs,
1516
+ slotWaitMs,
1468
1517
  attemptElapsedMs: result.attemptElapsedMs,
1469
1518
  // Record the resolved immutable snapshot identifier so slow acquisition
1470
1519
  // can be distinguished from a bad profile snapshot without logging
@@ -1527,6 +1576,7 @@ export function createOneShotDaytonaSandboxLifecycle(input: {
1527
1576
  intent: PlayRunnerDaytonaCleanupIntent,
1528
1577
  ) => Promise<void>;
1529
1578
  startAdmission?: DaytonaSandboxStartAdmission;
1579
+ workerSlot?: PlayRunnerWorkerSlot;
1530
1580
  cancellationSignal?: AbortSignal;
1531
1581
  startedAt?: number;
1532
1582
  }): OneShotDaytonaSandboxLifecycle {
@@ -1547,6 +1597,7 @@ export function createOneShotDaytonaSandboxLifecycle(input: {
1547
1597
  releaseSandboxCapacity: input.releaseSandboxCapacity,
1548
1598
  recordCleanupIntent: input.recordCleanupIntent,
1549
1599
  startAdmission: input.startAdmission,
1600
+ workerSlot: input.workerSlot,
1550
1601
  cancellationSignal: input.cancellationSignal,
1551
1602
  nextProviderAttempt: () => {
1552
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,20 @@ 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, so a worker holds at most
97
+ * 8 slots + twice this many runs (`ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS`).
98
+ *
99
+ * Ten lets the two warm workers reach the limiter's 10 starts a second on
100
+ * their own: a create took 1.5-2.2 s mean in the 2026-11-12 bursts, so
101
+ * 5 a second per worker needs 8-11 in flight. At five, a worker's creates
102
+ * topped out near 5 / 1.8 s = 2.8 a second, and 40% of warm-phase runs
103
+ * waited for a permit. Across 8 workers the limiter, not this bound, caps
104
+ * new creates.
85
105
  */
86
- daytonaConcurrentStartsPerProcess: 5,
106
+ daytonaConcurrentStartsPerProcess: 10,
87
107
  /** Fleet-wide AIMD lifecycle-admission pacing. */
88
108
  daytonaInitialStartsPerMinute: 120,
89
109
  daytonaMaximumStartsPerMinute: 600,
@@ -277,6 +277,11 @@ export type PlayRunRecoveryDecision = {
277
277
  deferCount: number | null;
278
278
  /** Deferred only: how long until the retry is due. */
279
279
  delayMs: number | null;
280
+ /**
281
+ * Deferred only: compiled start pacing, uncounted, which shares its reason
282
+ * with an operator throttle. Omitted means not paced.
283
+ */
284
+ paced?: boolean;
280
285
  };
281
286
 
282
287
  /**
@@ -303,6 +308,7 @@ export function emitPlayRunRecoveryDecision(
303
308
  input.outcome === 'deferred'
304
309
  ? durabilityDecisionCount(input.delayMs)
305
310
  : null,
311
+ paced: input.outcome === 'deferred' && input.paced === true,
306
312
  },
307
313
  });
308
314
  }
@@ -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
+ }
@@ -44,13 +44,35 @@ export function runWithAbsurdSchedulerQuerySignal<T>(
44
44
  return absurdSchedulerQuerySignal.run(signal, operation);
45
45
  }
46
46
 
47
+ /** One `absurd.claim_task` call made by the engine's claim loop. */
48
+ export type AbsurdClaimQueryTiming = {
49
+ /** From the call until the pool handed over a client. */
50
+ poolWaitMs: number;
51
+ /** From then until the claim returned, including any pool retry. */
52
+ queryMs: number;
53
+ totalMs: number;
54
+ taskIds: string[];
55
+ /** `performance.now()` when the claim returned. */
56
+ returnedAt: number;
57
+ };
58
+
59
+ /** Observes the engine's scheduler queries; measurement only. */
60
+ export type AbsurdSchedulerQueryObserver = {
61
+ onClaimTask(timing: AbsurdClaimQueryTiming): void;
62
+ };
63
+
64
+ // The vendored engine's claim statement (`Absurd.claimTasks`).
65
+ const ABSURD_CLAIM_TASK_SQL = 'absurd.claim_task(';
66
+
47
67
  /**
48
68
  * Builds an SDK `Queryable` backed by the hardened runtime scheduler pool.
49
69
  * Every query runs on a freshly checked-out pooled client and releases it,
50
- * inheriting the pool's backpressure/breaker/retry guarantees.
70
+ * inheriting the pool's backpressure/breaker/retry guarantees. An observer
71
+ * is told the timing of each claim query.
51
72
  */
52
73
  export function absurdQueryableForRuntimeScheduler(
53
74
  poolOptions: RuntimeSchedulerPoolOptions,
75
+ observer?: AbsurdSchedulerQueryObserver,
54
76
  ): Queryable {
55
77
  return {
56
78
  query: async <Row = Record<string, unknown>>(
@@ -58,18 +80,38 @@ export function absurdQueryableForRuntimeScheduler(
58
80
  params?: unknown[],
59
81
  ): Promise<QueryResult<Row>> => {
60
82
  const signal = absurdSchedulerQuerySignal.getStore();
61
- return withRuntimeSchedulerClient(
83
+ const timed =
84
+ observer !== undefined && sql.includes(ABSURD_CLAIM_TASK_SQL);
85
+ const startedAt = timed ? performance.now() : 0;
86
+ let clientAt: number | undefined;
87
+ const result = await withRuntimeSchedulerClient(
62
88
  poolOptions,
63
89
  async (client) => {
64
- const result = await client.query<Row & Record<string, unknown>>(
90
+ if (timed) clientAt ??= performance.now();
91
+ const queried = await client.query<Row & Record<string, unknown>>(
65
92
  sql,
66
93
  params,
67
94
  );
68
- return { rows: result.rows as Row[] };
95
+ return { rows: queried.rows as Row[] };
69
96
  },
70
97
  undefined,
71
98
  { signal },
72
99
  );
100
+ if (timed) {
101
+ const returnedAt = performance.now();
102
+ const queryStartedAt = clientAt ?? returnedAt;
103
+ observer.onClaimTask({
104
+ poolWaitMs: queryStartedAt - startedAt,
105
+ queryMs: returnedAt - queryStartedAt,
106
+ totalMs: returnedAt - startedAt,
107
+ taskIds: result.rows.flatMap((row) => {
108
+ const taskId = (row as { task_id?: unknown }).task_id;
109
+ return typeof taskId === 'string' ? [taskId] : [];
110
+ }),
111
+ returnedAt,
112
+ });
113
+ }
114
+ return result;
73
115
  },
74
116
  };
75
117
  }
@@ -80,10 +122,11 @@ export function absurdQueryableForRuntimeScheduler(
80
122
  export function createAbsurdForRuntimeScheduler(
81
123
  poolOptions: RuntimeSchedulerPoolOptions,
82
124
  options: Omit<AbsurdOptions, 'db'> = {},
125
+ observer?: AbsurdSchedulerQueryObserver,
83
126
  ): Absurd {
84
127
  return new Absurd({
85
128
  ...options,
86
- db: absurdQueryableForRuntimeScheduler(poolOptions),
129
+ db: absurdQueryableForRuntimeScheduler(poolOptions, observer),
87
130
  });
88
131
  }
89
132