deepline 0.3.521 → 0.3.523

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 (170) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +118 -0
  2. package/dist/bundling-sources/sdk/src/index.ts +3 -0
  3. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  4. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +47 -18
  5. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +1 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/db-session-renewal.ts +209 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +24 -7
  8. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +5 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +1 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +38 -5
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +92 -10
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +96 -25
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +29 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +139 -17
  15. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +26 -3
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +145 -5
  17. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +190 -10
  18. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +85 -5
  19. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +21 -11
  20. package/dist/cli/{artifacts-TYPU37IU.mjs → artifacts-RBHR2DG4.mjs} +6 -6
  21. package/dist/cli/{artifacts-JGH464N2.js → artifacts-RZTS2JHZ.js} +18 -18
  22. package/dist/cli/auth-DPWYFQR5.js +43 -0
  23. package/dist/cli/{auth-XPQT6NUB.mjs → auth-ENQUQS56.mjs} +5 -5
  24. package/dist/cli/{billing-47AMHOMP.mjs → billing-6A27ULCX.mjs} +7 -7
  25. package/dist/cli/{billing-6D4KXBFJ.js → billing-6HONTJOY.js} +82 -82
  26. package/dist/cli/{chunk-DY6634MN.js → chunk-2BRDHM4S.js} +9 -9
  27. package/dist/cli/{chunk-LGU2NIOT.js → chunk-326WVSWS.js} +108 -96
  28. package/dist/cli/{chunk-UAZKOH3J.js → chunk-36LQQL5C.js} +5 -5
  29. package/dist/cli/{chunk-VYY5V4M5.js → chunk-4NWY7JBB.js} +11 -11
  30. package/dist/cli/{chunk-2DQPB5HT.mjs → chunk-4V63IJCL.mjs} +5 -5
  31. package/dist/cli/{chunk-4MONKWYE.mjs → chunk-5WFQXAD4.mjs} +5 -5
  32. package/dist/cli/{chunk-A6USUS4L.mjs → chunk-6DBRBWHC.mjs} +2 -2
  33. package/dist/cli/{chunk-4I7I5CGB.mjs → chunk-6OZ2WSHD.mjs} +1 -1
  34. package/dist/cli/{chunk-MD43YAL6.js → chunk-7GNKAACY.js} +6 -6
  35. package/dist/cli/{chunk-7IYDCHTG.mjs → chunk-7M5FRSFP.mjs} +2 -2
  36. package/dist/cli/{chunk-HHBJJYKL.mjs → chunk-DNXP3D5H.mjs} +5 -5
  37. package/dist/cli/{chunk-4DB6JV7X.mjs → chunk-F3WRLFFM.mjs} +2 -2
  38. package/dist/cli/{chunk-AMVKLEPH.js → chunk-FBMOBNJY.js} +2 -2
  39. package/dist/cli/{chunk-EZNZDOAG.mjs → chunk-H7275EZU.mjs} +5 -5
  40. package/dist/cli/{chunk-CBBCUYIN.mjs → chunk-HSVGP4CI.mjs} +2 -2
  41. package/dist/cli/{chunk-FTZX4QZN.js → chunk-HUC5SGJQ.js} +2 -2
  42. package/dist/cli/{chunk-4MN65FRF.js → chunk-HUIFUE4L.js} +53 -53
  43. package/dist/cli/{chunk-5T7QKHQL.mjs → chunk-I62LJ7NU.mjs} +1 -1
  44. package/dist/cli/{chunk-EW3EAEWZ.js → chunk-IEVXYHGJ.js} +5 -5
  45. package/dist/cli/{chunk-E4ZS2B2J.mjs → chunk-JCTTXLAZ.mjs} +1 -1
  46. package/dist/cli/{chunk-LNBMEFOI.mjs → chunk-JGZQBDYG.mjs} +4 -4
  47. package/dist/cli/{chunk-GNYSODBR.js → chunk-JMMNCJ7Z.js} +1 -1
  48. package/dist/cli/{chunk-7AUXX6M5.mjs → chunk-JVEFMOY2.mjs} +1 -1
  49. package/dist/cli/{chunk-3Q7HEEH2.js → chunk-K326BEVR.js} +10 -10
  50. package/dist/cli/{chunk-TBIWR7M2.mjs → chunk-KILRUAXF.mjs} +1 -1
  51. package/dist/cli/{chunk-6UHYXNCP.mjs → chunk-LZL6V5M5.mjs} +2 -2
  52. package/dist/cli/{chunk-EILHJRPW.js → chunk-MCXPJYBN.js} +3 -3
  53. package/dist/cli/{chunk-VE6FHVXZ.mjs → chunk-MHTRYBXY.mjs} +78 -1
  54. package/dist/cli/{chunk-VSH3AE5E.js → chunk-MT3WG3KR.js} +16 -16
  55. package/dist/cli/{chunk-PUKWFJXW.js → chunk-MZROKQV3.js} +44 -44
  56. package/dist/cli/{chunk-QGTWGHYD.js → chunk-N5MLEXZ7.js} +50 -8
  57. package/dist/cli/{chunk-ZO2XJVFH.mjs → chunk-NWTMQGPP.mjs} +6 -6
  58. package/dist/cli/{chunk-6V2RI3AL.mjs → chunk-PCORO245.mjs} +2 -2
  59. package/dist/cli/{chunk-MRU4N33M.js → chunk-PESMXAUG.js} +6 -6
  60. package/dist/cli/{chunk-4GGXAYKI.mjs → chunk-QMBL5ZIQ.mjs} +3 -3
  61. package/dist/cli/{chunk-A2B5AAU3.mjs → chunk-QOO5W5XS.mjs} +22 -10
  62. package/dist/cli/{chunk-HRWVEIAX.mjs → chunk-QSAC3IVI.mjs} +1 -1
  63. package/dist/cli/{chunk-HYR34KFA.js → chunk-QYXIODWH.js} +78 -1
  64. package/dist/cli/{chunk-Y7IR4LBU.mjs → chunk-RKREB7MU.mjs} +3 -3
  65. package/dist/cli/{chunk-JFQJNYTB.js → chunk-RQN4PHRE.js} +16 -16
  66. package/dist/cli/{chunk-6DCBTJZP.js → chunk-S4YKRH3W.js} +3 -3
  67. package/dist/cli/{chunk-ULW2KBKL.js → chunk-SBGKKOCC.js} +26 -26
  68. package/dist/cli/{chunk-DQURY3WH.mjs → chunk-SXTVJIGB.mjs} +1 -1
  69. package/dist/cli/{chunk-7LRALARF.mjs → chunk-U6DLLV3S.mjs} +1 -1
  70. package/dist/cli/{chunk-NNDAVVBG.mjs → chunk-UH3EAFFN.mjs} +2 -2
  71. package/dist/cli/{chunk-HSFLMTED.js → chunk-UQN4VTZL.js} +4 -4
  72. package/dist/cli/{chunk-HD3KYCDC.js → chunk-V46J3UTM.js} +7 -7
  73. package/dist/cli/{chunk-WL6WPW6X.js → chunk-WGVJA4I5.js} +14 -14
  74. package/dist/cli/{chunk-FQJFONFT.mjs → chunk-WVQOXYTQ.mjs} +44 -2
  75. package/dist/cli/{chunk-Y23TOHNV.js → chunk-XVXEARHC.js} +41 -41
  76. package/dist/cli/{chunk-6N72GHAV.js → chunk-XYL26236.js} +2 -2
  77. package/dist/cli/{chunk-YROP3H6T.js → chunk-ZWN4RXC2.js} +22 -22
  78. package/dist/cli/command-docs.js +2 -2
  79. package/dist/cli/command-docs.mjs +1 -1
  80. package/dist/cli/{csv-5TM2OSYP.js → csv-UBACJK75.js} +13 -13
  81. package/dist/cli/{csv-PM3WDXDF.mjs → csv-YFJ2JLUP.mjs} +4 -4
  82. package/dist/cli/{db-3LJ32FZM.js → db-2ZPA2LZ7.js} +27 -27
  83. package/dist/cli/{db-5P72NPRL.mjs → db-NKGYTAQO.mjs} +6 -6
  84. package/dist/cli/{describe-ZLCMBGHG.mjs → describe-GX7DRKWZ.mjs} +18 -18
  85. package/dist/cli/describe-WQZF7MEG.js +50 -0
  86. package/dist/cli/describe-core.d.mts +3 -3
  87. package/dist/cli/describe-core.d.ts +3 -3
  88. package/dist/cli/{executions-JMFL6AV7.mjs → executions-HTHQ7KKD.mjs} +6 -6
  89. package/dist/cli/{executions-4AJ5TQVY.js → executions-NXMRGPIL.js} +8 -8
  90. package/dist/cli/{feedback-I2BLXMGH.js → feedback-TGVQACRO.js} +10 -10
  91. package/dist/cli/{feedback-DKMG2QB7.mjs → feedback-USP4T34P.mjs} +5 -5
  92. package/dist/cli/{git-ARG223MY.mjs → git-KUONEHCD.mjs} +5 -5
  93. package/dist/cli/git-X3SCQREB.js +25 -0
  94. package/dist/cli/index.js +145 -145
  95. package/dist/cli/index.mjs +44 -44
  96. package/dist/cli/{legacy-noops-N7SVA7PL.js → legacy-noops-2JY3CQ24.js} +9 -9
  97. package/dist/cli/{legacy-noops-24LOAOZN.mjs → legacy-noops-B2GMHU42.mjs} +6 -6
  98. package/dist/cli/{monitors-RYQFWM2T.mjs → monitors-2OVBZJ6Z.mjs} +7 -7
  99. package/dist/cli/{monitors-XNCYLOJM.js → monitors-XI6I52AX.js} +100 -100
  100. package/dist/cli/{org-I33TKZXF.js → org-5TUQ2H6Y.js} +235 -72
  101. package/dist/cli/{org-ORIH56E5.mjs → org-BNJW764Y.mjs} +169 -6
  102. package/dist/cli/{pages-ME43HSBL.mjs → pages-QC3TQIPW.mjs} +6 -6
  103. package/dist/cli/{pages-2UXXGIMF.js → pages-UXCLX53Y.js} +18 -18
  104. package/dist/cli/{play-XEKNY46M.mjs → play-45PPG5SZ.mjs} +18 -18
  105. package/dist/cli/{play-F4QOFU37.js → play-KRWMZ7FG.js} +317 -317
  106. package/dist/cli/{providers-XKU44G74.mjs → providers-JDT35MRL.mjs} +6 -6
  107. package/dist/cli/{providers-E7DPCBNX.js → providers-RBUJ72Y3.js} +9 -9
  108. package/dist/cli/{quickstart-J7NVEXV5.mjs → quickstart-GD2SWGAC.mjs} +4 -4
  109. package/dist/cli/{quickstart-ICLF2F6A.js → quickstart-JZ4Q3HFT.js} +6 -6
  110. package/dist/cli/{run-HJMHUQBN.js → run-JEAHA367.js} +41 -41
  111. package/dist/cli/{run-MQ5ZONGL.mjs → run-KIZ3HBI2.mjs} +23 -23
  112. package/dist/cli/{search-GGRC77CV.mjs → search-5UFNXHFK.mjs} +8 -8
  113. package/dist/cli/search-6JULJMD7.js +33 -0
  114. package/dist/cli/{search-output-NY4GDBRU.mjs → search-output-HAXPKQO6.mjs} +4 -4
  115. package/dist/cli/{search-output-MXZTZI2P.js → search-output-W3RDSVLE.js} +6 -6
  116. package/dist/cli/{secrets-FA37G4Q2.mjs → secrets-JAWT66B2.mjs} +6 -6
  117. package/dist/cli/{secrets-PFESG72B.js → secrets-PC7C2Q32.js} +15 -15
  118. package/dist/cli/{sessions-BLLXPETU.mjs → sessions-325V7G35.mjs} +6 -6
  119. package/dist/cli/sessions-WFUCOJHZ.js +18 -0
  120. package/dist/cli/{settings-U26S7MPH.mjs → settings-FKHTA65P.mjs} +13 -13
  121. package/dist/cli/{settings-32VPG4Z2.js → settings-RGU6Y2QR.js} +86 -86
  122. package/dist/cli/{setup-4AXBCX7C.mjs → setup-43GOYTFC.mjs} +10 -10
  123. package/dist/cli/{setup-R6NSENH7.js → setup-ZMZ7HU2I.js} +50 -50
  124. package/dist/cli/skills-3XTQ6FFM.js +37 -0
  125. package/dist/cli/{skills-JUH7AVUL.mjs → skills-Q2VAHSXM.mjs} +8 -8
  126. package/dist/cli/{tools-FOYLU3FH.mjs → tools-BUH7ZWDS.mjs} +17 -17
  127. package/dist/cli/tools-UK2R4YXQ.js +57 -0
  128. package/dist/cli/{update-FUVX22VM.mjs → update-JFALWOHD.mjs} +10 -10
  129. package/dist/cli/update-LNKPHS54.js +35 -0
  130. package/dist/cli/{workflow-QLT22BLT.mjs → workflow-ISJKLY6X.mjs} +7 -7
  131. package/dist/cli/{workflow-JACZW4GJ.js → workflow-YELST32A.js} +17 -17
  132. package/dist/{client-DA71-2_u.d.mts → client-C2N7MofG.d.mts} +1 -1
  133. package/dist/{client-B-2Am2y6.d.ts → client-C7lTRJjw.d.ts} +1 -1
  134. package/dist/{client-core-BXbds1cb.d.mts → client-core-BTkDSKGn.d.mts} +79 -2
  135. package/dist/{client-core-C0IzDKMJ.d.ts → client-core-hmhBi7Ib.d.ts} +79 -2
  136. package/dist/{compiler-manifest-B4mIIbw7.d.ts → compiler-manifest-DsxsQP-T.d.mts} +14 -7
  137. package/dist/{compiler-manifest-B4mIIbw7.d.mts → compiler-manifest-DsxsQP-T.d.ts} +14 -7
  138. package/dist/{errors-Gj9i5Rkd.d.ts → errors-Bk5h1D-C.d.ts} +1 -1
  139. package/dist/{errors-C2F4qzAq.d.mts → errors-qdJUVQ3g.d.mts} +1 -1
  140. package/dist/{index-5JZBufdF.d.mts → index-PaupwX1B.d.mts} +1 -1
  141. package/dist/{index-BXtSj8bv.d.ts → index-bL66eHYz.d.ts} +1 -1
  142. package/dist/index.d.mts +7 -7
  143. package/dist/index.d.ts +7 -7
  144. package/dist/index.js +9 -9
  145. package/dist/index.mjs +6 -6
  146. package/dist/install-integrity.json +117 -116
  147. package/dist/plays/bundle-play-file.d.mts +3 -3
  148. package/dist/plays/bundle-play-file.d.ts +3 -3
  149. package/dist/plays/bundle-play-file.mjs +7 -5
  150. package/dist/plays/play-description.d.mts +2 -2
  151. package/dist/plays/play-description.d.ts +2 -2
  152. package/dist/plays/run-request.d.mts +2 -2
  153. package/dist/plays/run-request.d.ts +2 -2
  154. package/dist/release.d.mts +1 -1
  155. package/dist/release.d.ts +1 -1
  156. package/dist/release.js +2 -2
  157. package/dist/release.mjs +1 -1
  158. package/dist/server.d.mts +4 -4
  159. package/dist/server.d.ts +4 -4
  160. package/dist/server.js +5 -5
  161. package/dist/server.mjs +3 -3
  162. package/package.json +1 -1
  163. package/dist/cli/auth-JWR3VSNT.js +0 -43
  164. package/dist/cli/describe-GRS3IRSX.js +0 -50
  165. package/dist/cli/git-2LNT43A2.js +0 -25
  166. package/dist/cli/search-V6IBJ4TX.js +0 -33
  167. package/dist/cli/sessions-DNFTQOQH.js +0 -18
  168. package/dist/cli/skills-G4ZE3OS5.js +0 -37
  169. package/dist/cli/tools-27LHZFJD.js +0 -57
  170. package/dist/cli/update-KNZ7N242.js +0 -35
@@ -1328,6 +1328,8 @@ function emitDaytonaStage(
1328
1328
  playName: context.playName ?? null,
1329
1329
  stage,
1330
1330
  ...extra,
1331
+ // This worker's clock at the stage; log rows carry the shipper's.
1332
+ atMs: Date.now(),
1331
1333
  };
1332
1334
  try {
1333
1335
  console.info('[play-runner.daytona.stage]', JSON.stringify(payload));
@@ -1531,6 +1533,24 @@ function isFailedDaytonaRunnerStart(error: unknown): boolean {
1531
1533
  );
1532
1534
  }
1533
1535
 
1536
+ /**
1537
+ * The last sandbox of an attempt breached the upload deadline, but an earlier
1538
+ * sandbox of the same attempt failed for another, Daytona-side reason (for
1539
+ * example a control-request timeout). The upload never finished, so no command
1540
+ * was sent and no customer code ran. One breach is not evidence of an input
1541
+ * too large for any sandbox, so it defers like any other failed start. When
1542
+ * every sandbox of the attempt breached, the upload stays loud.
1543
+ */
1544
+ function isUploadDeadlineAfterOtherStartFailure(
1545
+ error: unknown,
1546
+ executionAttempt: number,
1547
+ ): boolean {
1548
+ return (
1549
+ error instanceof DaytonaUploadDeadlineBreachError &&
1550
+ error.attemptTimings.length < executionAttempt
1551
+ );
1552
+ }
1553
+
1534
1554
  /** Which failure ended a start, for the stage log: the run error has less. */
1535
1555
  function startFailureForLog(error: unknown) {
1536
1556
  const diagnostic =
@@ -1590,19 +1610,28 @@ function isRetryableUnstartedDaytonaRunner(
1590
1610
  // that waiting state. Defer a runner with no exit evidence, or the observed
1591
1611
  // pre-start 127 shape (no Node process or startup marker). A fresh attempt
1592
1612
  // fences the old sandbox; persistent failures exhaust the existing budget.
1613
+ // A sandbox Daytona could not answer for at all (command and session both
1614
+ // unreadable) also has no exit evidence: it is the same unstarted runner,
1615
+ // only on a sandbox that vanished, so it defers too.
1593
1616
  const noExit =
1594
1617
  diagnostic.exitCode === null && diagnostic.exitCodeFile === null;
1595
1618
  const exitedBeforeStartup =
1619
+ diagnostic.commandFound &&
1620
+ diagnostic.sessionFound &&
1596
1621
  (diagnostic.exitCode === null || diagnostic.exitCode === 127) &&
1597
1622
  diagnostic.exitCodeFile === 127 &&
1598
1623
  diagnostic.processSummary?.node === 0 &&
1599
1624
  diagnostic.runnerStartup === null &&
1600
1625
  diagnostic.errors.includes('startup_diagnostic_unavailable');
1626
+ const sandboxUnreadable =
1627
+ !diagnostic.commandFound &&
1628
+ !diagnostic.sessionFound &&
1629
+ diagnostic.errors.includes('get_session_command_failed') &&
1630
+ diagnostic.errors.includes('get_session_failed');
1631
+ const runnerReadable = diagnostic.commandFound && diagnostic.sessionFound;
1601
1632
  return (
1602
- diagnostic.commandFound &&
1603
- diagnostic.sessionFound &&
1604
- (noExit || exitedBeforeStartup) &&
1605
- !diagnostic.schedulerReadinessObserved
1633
+ !diagnostic.schedulerReadinessObserved &&
1634
+ ((noExit && (runnerReadable || sandboxUnreadable)) || exitedBeforeStartup)
1606
1635
  );
1607
1636
  }
1608
1637
 
@@ -2239,7 +2268,11 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
2239
2268
  ? 'runner_startup_not_live'
2240
2269
  : sandboxForAttempt &&
2241
2270
  !parkStarted &&
2242
- isFailedDaytonaRunnerStart(error)
2271
+ (isFailedDaytonaRunnerStart(error) ||
2272
+ isUploadDeadlineAfterOtherStartFailure(
2273
+ error,
2274
+ executionAttempt,
2275
+ ))
2243
2276
  ? 'runner_start_failed'
2244
2277
  : isRetryableDaytonaInfrastructureFailure(error)
2245
2278
  ? 'daytona_infrastructure'
@@ -216,21 +216,32 @@ function failed(
216
216
  };
217
217
  }
218
218
 
219
+ /**
220
+ * One fixed-size launch stage line, the Modal twin of
221
+ * `[play-runner.daytona.stage]`. `atMs` is this worker's clock when the stage
222
+ * happened, so a reader never has to use log ingest time. Callers pass only
223
+ * scalars: ids, counts, durations, booleans, never payloads or credentials.
224
+ */
219
225
  function emitModalStage(
220
226
  context: PlayRunnerExecutionConfig['context'],
221
227
  stage: string,
222
228
  extra: Record<string, unknown> = {},
223
229
  ): void {
224
- console.info(
225
- '[play-runner.modal.stage]',
226
- JSON.stringify({
227
- workflowId: context.workflowId ?? null,
228
- runId: context.runId ?? null,
229
- playName: context.playName ?? null,
230
- stage,
231
- ...extra,
232
- }),
233
- );
230
+ try {
231
+ console.info(
232
+ '[play-runner.modal.stage]',
233
+ JSON.stringify({
234
+ workflowId: context.workflowId ?? null,
235
+ runId: context.runId ?? null,
236
+ playName: context.playName ?? null,
237
+ stage,
238
+ ...extra,
239
+ atMs: Date.now(),
240
+ }),
241
+ );
242
+ } catch {
243
+ // Diagnostic delivery never changes the launch it describes.
244
+ }
234
245
  }
235
246
 
236
247
  export async function confirmDetachedModalRunnerReady(input: {
@@ -370,6 +381,10 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
370
381
  if (providerCircuitClaim && !providerCircuitClaim.allowed) {
371
382
  throw recoveryForOpenModalCircuit();
372
383
  }
384
+ emitModalStage(config.context, 'placement:admitted', {
385
+ circuitProbe: Boolean(providerCircuitClaim?.probeToken),
386
+ elapsedMs: Date.now() - startedAt,
387
+ });
373
388
  const modalConfig = await loadModalRequiredConfig({
374
389
  runtimeSchedulerSchema: config.context.runtimeSchedulerSchema,
375
390
  limits: config.context.sandboxRuntimeLimits,
@@ -379,9 +394,20 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
379
394
  limits: modalConfig.limits,
380
395
  runtimeSchedulerSchema: config.context.runtimeSchedulerSchema,
381
396
  });
397
+ emitModalStage(config.context, 'config:resolved', {
398
+ cpu: resources.physicalCpuCores,
399
+ memoryMiB: memoryPolicy.reservationMemoryMiB,
400
+ memoryLimitMiB: memoryPolicy.memoryLimitMiB,
401
+ timeoutSeconds: modalConfig.limits.timeoutSeconds,
402
+ elapsedMs: Date.now() - startedAt,
403
+ });
382
404
  const app = await modalConfig.client.apps.fromName(modalConfig.appName, {
383
405
  createIfMissing: true,
384
406
  });
407
+ emitModalStage(config.context, 'app:resolved', {
408
+ modalAppId: app.appId,
409
+ elapsedMs: Date.now() - startedAt,
410
+ });
385
411
  const baseImage = modalConfig.client.images.fromRegistry(
386
412
  modalConfig.image,
387
413
  );
@@ -401,8 +427,16 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
401
427
  .build(app),
402
428
  )
403
429
  : baseImage;
430
+ emitModalStage(config.context, 'image:resolved', {
431
+ built: image !== baseImage,
432
+ elapsedMs: Date.now() - startedAt,
433
+ });
404
434
  const capacityReservation =
405
435
  await callbacks?.reserveSandboxCapacity?.('modal');
436
+ emitModalStage(config.context, 'capacity:reserved', {
437
+ reserved: Boolean(capacityReservation),
438
+ elapsedMs: Date.now() - startedAt,
439
+ });
406
440
  const createTags = {
407
441
  source: 'deepline-play-runner',
408
442
  orgId: config.context.orgId ?? 'unknown',
@@ -451,6 +485,9 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
451
485
  ? { sandboxCapacityLeaseId: capacityReservation.leaseId }
452
486
  : {}),
453
487
  });
488
+ emitModalStage(config.context, 'create:requested', {
489
+ elapsedMs: Date.now() - startedAt,
490
+ });
454
491
  createSent = true;
455
492
  sandbox = await awaitModalSandboxCreate({
456
493
  create: modalConfig.client.sandboxes.create(app, image, {
@@ -535,12 +572,28 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
535
572
  await callbacks?.onAmbiguousModalCreateResolved?.();
536
573
  },
537
574
  });
575
+ emitModalStage(config.context, 'create:response', {
576
+ sandboxId: sandbox.sandboxId,
577
+ elapsedMs: Date.now() - startedAt,
578
+ });
538
579
  logSandboxCreateOutcome({
539
580
  provider: 'modal',
540
581
  outcome: 'succeeded',
541
582
  runId: config.context.runId,
542
583
  });
543
584
  } catch (error) {
585
+ emitModalStage(config.context, 'create:failed', {
586
+ sent: createSent,
587
+ outcome:
588
+ error instanceof ModalSandboxCreateOutcomeUnknownError
589
+ ? 'unknown'
590
+ : 'failed',
591
+ reason:
592
+ recoveryForModalSandboxCreateFailure(error)?.decision.reason ??
593
+ null,
594
+ errorName: error instanceof Error ? error.name : null,
595
+ elapsedMs: Date.now() - startedAt,
596
+ });
544
597
  if (createSent) {
545
598
  logSandboxCreateOutcome({
546
599
  provider: 'modal',
@@ -671,6 +724,10 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
671
724
  runtimeResourceRegistrationError = error;
672
725
  throw error;
673
726
  }
727
+ emitModalStage(config.context, 'resource:recorded', {
728
+ sandboxId: sandbox.sandboxId,
729
+ elapsedMs: Date.now() - startedAt,
730
+ });
674
731
 
675
732
  // The baseline only has to predate this runner's first heartbeat, which
676
733
  // cannot exist before exec. Read it while the payload uploads instead
@@ -679,6 +736,17 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
679
736
  captureDetachedDaytonaRunnerReadinessBaseline({
680
737
  readiness: readRunnerReadiness,
681
738
  });
739
+ baselineHeartbeatRead.then(
740
+ (heartbeatAt) =>
741
+ emitModalStage(config.context, 'readiness:baseline_read', {
742
+ hasBaseline: heartbeatAt !== null,
743
+ elapsedMs: Date.now() - startedAt,
744
+ }),
745
+ () =>
746
+ emitModalStage(config.context, 'readiness:baseline_failed', {
747
+ elapsedMs: Date.now() - startedAt,
748
+ }),
749
+ );
682
750
  // Awaited (and its failure surfaced) below; this only keeps an upload
683
751
  // failure from orphaning the read.
684
752
  baselineHeartbeatRead.catch(() => undefined);
@@ -727,6 +795,7 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
727
795
  sandboxId: sandbox.sandboxId,
728
796
  timeoutSeconds: modalConfig.limits.timeoutSeconds,
729
797
  mode: 'detached',
798
+ elapsedMs: Date.now() - startedAt,
730
799
  });
731
800
  const executeStartedAt = Date.now();
732
801
  await Promise.race([
@@ -734,6 +803,12 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
734
803
  cancellationPromise,
735
804
  ]);
736
805
  runtimeTiming.modalExecuteMs = Date.now() - executeStartedAt;
806
+ const commandAcceptedAtMs = Date.now();
807
+ emitModalStage(config.context, 'execute:accepted', {
808
+ sandboxId: sandbox.sandboxId,
809
+ execMs: runtimeTiming.modalExecuteMs,
810
+ elapsedMs: commandAcceptedAtMs - startedAt,
811
+ });
737
812
  await callbacks?.onRunnerCommandAccepted?.({
738
813
  provider: 'modal',
739
814
  sandboxId: sandbox.sandboxId,
@@ -747,6 +822,13 @@ export const modalPlayRunnerBackend: PlayRunnerBackend = {
747
822
  baselineHeartbeatAt,
748
823
  cancellation: cancellationPromise,
749
824
  });
825
+ const heartbeatReadyAtMs = Date.now();
826
+ emitModalStage(config.context, 'execute:heartbeat_ready', {
827
+ sandboxId: sandbox.sandboxId,
828
+ elapsedMs: heartbeatReadyAtMs - startedAt,
829
+ commandAcceptedToHeartbeatMs:
830
+ heartbeatReadyAtMs - commandAcceptedAtMs,
831
+ });
750
832
  const runnerAttempt = Math.max(
751
833
  0,
752
834
  Math.floor(config.context.runAttempt ?? 0),
@@ -25,6 +25,63 @@ import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
25
25
  export const ABSURD_CANCELLED_DEADLINE_RECONCILE_LIMIT = 100;
26
26
  const QUEUED_CANCELLATION_RECONCILE_LIMIT = 20;
27
27
 
28
+ /** A cancel request older than this has outlived ordinary sandbox cleanup. */
29
+ export const UNDRAINED_RUNTIME_CANCELLATION_WARNING_AFTER_MS = 5 * 60_000;
30
+ /** At most one undrained-cancellation warning per process per interval. */
31
+ export const UNDRAINED_RUNTIME_CANCELLATION_WARNING_INTERVAL_MS = 60_000;
32
+ const UNDRAINED_RUNTIME_CANCELLATION_SAMPLE_LIMIT = 5;
33
+ let lastUndrainedCancellationWarningAtMs: number | null = null;
34
+
35
+ /** Test seam: forget the process-wide warning rate limit. */
36
+ export function resetUndrainedRuntimeCancellationWarningForTests(): void {
37
+ lastUndrainedCancellationWarningAtMs = null;
38
+ }
39
+
40
+ /**
41
+ * Report cancel requests that have waited longer than the threshold, from
42
+ * paths that already read them (the worker drain and a repeated stop). Emits
43
+ * one bounded structured warning per process per interval: a count, the
44
+ * oldest age, and a fixed-size run sample. Requests without a parseable
45
+ * request clock (historical rows) are not reported.
46
+ */
47
+ export function noteUndrainedRuntimeCancellations(input: {
48
+ source: 'drain_pending' | 'repeat_stop';
49
+ requests: ReadonlyArray<{ runId: string; requestedAt: string | null }>;
50
+ nowMs?: number;
51
+ }): boolean {
52
+ const nowMs = input.nowMs ?? Date.now();
53
+ const overdue = input.requests
54
+ .map((request) => ({
55
+ runId: request.runId,
56
+ ageMs: nowMs - Date.parse(request.requestedAt ?? ''),
57
+ }))
58
+ .filter(
59
+ (request) =>
60
+ Number.isFinite(request.ageMs) &&
61
+ request.ageMs >= UNDRAINED_RUNTIME_CANCELLATION_WARNING_AFTER_MS,
62
+ )
63
+ .sort((left, right) => right.ageMs - left.ageMs);
64
+ if (overdue.length === 0) return false;
65
+ if (
66
+ lastUndrainedCancellationWarningAtMs !== null &&
67
+ nowMs - lastUndrainedCancellationWarningAtMs <
68
+ UNDRAINED_RUNTIME_CANCELLATION_WARNING_INTERVAL_MS
69
+ ) {
70
+ return false;
71
+ }
72
+ lastUndrainedCancellationWarningAtMs = nowMs;
73
+ console.warn('[absurd-runtime.cancel] undrained_cancellation', {
74
+ source: input.source,
75
+ overdueCount: overdue.length,
76
+ oldestAgeMs: overdue[0]!.ageMs,
77
+ thresholdMs: UNDRAINED_RUNTIME_CANCELLATION_WARNING_AFTER_MS,
78
+ sampleRunIds: overdue
79
+ .slice(0, UNDRAINED_RUNTIME_CANCELLATION_SAMPLE_LIMIT)
80
+ .map((request) => request.runId),
81
+ });
82
+ return true;
83
+ }
84
+
28
85
  function quoteAbsurdTable(table: string): string {
29
86
  return `"${table.replaceAll('"', '""')}"`;
30
87
  }
@@ -269,6 +326,7 @@ export async function reconcileQueuedAbsurdRuntimeCancellations(input: {
269
326
  const queued = await input.client.query<{
270
327
  key: string;
271
328
  reason: string | null;
329
+ requested_at: string | null;
272
330
  }>(
273
331
  `WITH selected AS (
274
332
  SELECT key FROM ${schedulerSchema}.control
@@ -281,37 +339,50 @@ export async function reconcileQueuedAbsurdRuntimeCancellations(input: {
281
339
  SET updated_at = clock_timestamp()
282
340
  FROM selected
283
341
  WHERE request.key = selected.key
284
- RETURNING request.key, request.value->>'reason' AS reason`,
342
+ RETURNING request.key, request.value->>'reason' AS reason,
343
+ request.value->>'requestedAt' AS requested_at`,
285
344
  [limit],
286
345
  );
287
346
  let reconciled = 0;
288
347
  let skipped = 0;
289
- for (const row of queued.rows) {
290
- const runId = row.key.slice('runtime_cancel:'.length);
291
- if (!runId) {
292
- throw new Error(`Malformed runtime cancellation request "${row.key}".`);
293
- }
294
- try {
295
- const outcome = await finalizeCancelledRunAfterCleanup({
296
- client: input.client,
297
- runId,
298
- reason: row.reason || 'Cancelled play run.',
299
- schedulerSchema,
300
- schedulerOptions: input.schedulerOptions,
301
- controlKey: row.key,
302
- });
303
- if (outcome === 'cancelled') reconciled += 1;
304
- else skipped += 1;
305
- } catch (error) {
306
- if (
307
- isRuntimeSchedulerQueryCancellationError(error) ||
308
- isRuntimeSchedulerRetryableTransactionError(error)
309
- ) {
310
- skipped += 1;
311
- break;
348
+ const stillPending: Array<{ runId: string; requestedAt: string | null }> = [];
349
+ try {
350
+ for (const row of queued.rows) {
351
+ const runId = row.key.slice('runtime_cancel:'.length);
352
+ if (!runId) {
353
+ throw new Error(`Malformed runtime cancellation request "${row.key}".`);
354
+ }
355
+ try {
356
+ const outcome = await finalizeCancelledRunAfterCleanup({
357
+ client: input.client,
358
+ runId,
359
+ reason: row.reason || 'Cancelled play run.',
360
+ schedulerSchema,
361
+ schedulerOptions: input.schedulerOptions,
362
+ controlKey: row.key,
363
+ });
364
+ if (outcome === 'cancelled') reconciled += 1;
365
+ else skipped += 1;
366
+ if (outcome === 'pending') {
367
+ stillPending.push({ runId, requestedAt: row.requested_at });
368
+ }
369
+ } catch (error) {
370
+ if (
371
+ isRuntimeSchedulerQueryCancellationError(error) ||
372
+ isRuntimeSchedulerRetryableTransactionError(error)
373
+ ) {
374
+ skipped += 1;
375
+ stillPending.push({ runId, requestedAt: row.requested_at });
376
+ break;
377
+ }
378
+ throw error;
312
379
  }
313
- throw error;
314
380
  }
381
+ } finally {
382
+ noteUndrainedRuntimeCancellations({
383
+ source: 'drain_pending',
384
+ requests: stillPending,
385
+ });
315
386
  }
316
387
  return { reconciled, skipped };
317
388
  }
@@ -56,6 +56,8 @@ import {
56
56
  isRuntimeTrafficPolicy,
57
57
  type RuntimeTrafficPolicy,
58
58
  } from '../runtime-traffic-policy';
59
+ import type { PreloadedRuntimeDbSession } from '../db-session';
60
+ import { parseRenewedPreloadedRuntimeDbSessions } from '../db-session-renewal';
59
61
  import { RUNTIME_CLAIM_HEARTBEAT_DIVISOR } from '../runtime-constants';
60
62
  import { runtimeLimitExceededCause } from '../run-failure';
61
63
  import {
@@ -853,6 +855,9 @@ export type AbsurdRuntimeWorkerDeps = {
853
855
  initializeComputeSession?: boolean;
854
856
  onComputeSessionInitialized?: () => void;
855
857
  onRuntimeTrafficPolicy?: (policy: RuntimeTrafficPolicy) => void;
858
+ onPreloadedDbSessionsRenewed?: (
859
+ sessions: PreloadedRuntimeDbSession[],
860
+ ) => void;
856
861
  }) => Promise<string>;
857
862
  /** This worker's release lane id. Seam so tests can drive the belt-and-
858
863
  * suspenders lane-mismatch guard without mutating process env. Defaults to
@@ -1108,6 +1113,9 @@ export async function requestAttemptExecutorToken(input: {
1108
1113
  initializeComputeSession?: boolean;
1109
1114
  onComputeSessionInitialized?: () => void;
1110
1115
  onRuntimeTrafficPolicy?: (policy: RuntimeTrafficPolicy) => void;
1116
+ onPreloadedDbSessionsRenewed?: (
1117
+ sessions: PreloadedRuntimeDbSession[],
1118
+ ) => void;
1111
1119
  }): Promise<string> {
1112
1120
  const internalToken = process.env.DEEPLINE_INTERNAL_TOKEN?.trim();
1113
1121
  if (!internalToken) {
@@ -1180,6 +1188,7 @@ export async function requestAttemptExecutorToken(input: {
1180
1188
  const responseForFingerprint = response.clone();
1181
1189
  const body = (await response.json().catch(() => null)) as {
1182
1190
  executorToken?: unknown;
1191
+ preloadedDbSessions?: unknown;
1183
1192
  error?: unknown;
1184
1193
  code?: unknown;
1185
1194
  capacitySource?: unknown;
@@ -1242,6 +1251,15 @@ export async function requestAttemptExecutorToken(input: {
1242
1251
  response.headers.get('x-request-id') ??
1243
1252
  null,
1244
1253
  });
1254
+ // An app that renewed this run's expired admission sessions returns them;
1255
+ // older apps omit the field and the launch's stored sessions stay in use.
1256
+ // A malformed array is ignored the same way, never half-applied.
1257
+ const renewedDbSessions = parseRenewedPreloadedRuntimeDbSessions(
1258
+ body.preloadedDbSessions,
1259
+ );
1260
+ if (renewedDbSessions) {
1261
+ input.onPreloadedDbSessionsRenewed?.(renewedDbSessions);
1262
+ }
1245
1263
  if (
1246
1264
  input.initializeComputeSession === true &&
1247
1265
  body.computeSessionInitialized?.sessionId ===
@@ -3570,6 +3588,7 @@ async function executeAbsurdAttemptAdapter(
3570
3588
  if (gated) return gated;
3571
3589
  }
3572
3590
  const tokenStartedAt = performance.now();
3591
+ let renewedDbSessions: PreloadedRuntimeDbSession[] | null = null;
3573
3592
  const executorToken = await runWithAbsurdExecutionLeaseHeartbeat({
3574
3593
  ctx,
3575
3594
  runId,
@@ -3593,6 +3612,11 @@ async function executeAbsurdAttemptAdapter(
3593
3612
  attempt: generation,
3594
3613
  leaseToken,
3595
3614
  schedulerSchema: options?.schema ?? null,
3615
+ onPreloadedDbSessionsRenewed: (
3616
+ sessions: PreloadedRuntimeDbSession[],
3617
+ ) => {
3618
+ renewedDbSessions = sessions;
3619
+ },
3596
3620
  ...(initializeComputeSession
3597
3621
  ? {
3598
3622
  initializeComputeSession: true,
@@ -3616,9 +3640,14 @@ async function executeAbsurdAttemptAdapter(
3616
3640
  }),
3617
3641
  );
3618
3642
  });
3643
+ // Assigned inside the mint callback; widen past control-flow narrowing.
3644
+ const renewedSessions = renewedDbSessions as
3645
+ | PreloadedRuntimeDbSession[]
3646
+ | null;
3619
3647
  executionLaunch = {
3620
3648
  ...launch,
3621
3649
  executorToken,
3650
+ ...(renewedSessions ? { preloadedDbSessions: renewedSessions } : {}),
3622
3651
  };
3623
3652
  const runtimeApi = deps.runtimeApiFromLaunch(executionLaunch);
3624
3653
  return await executeAssignedAbsurdAttempt({