deepline 0.3.522 → 0.3.524

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 (176) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +178 -60
  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/monitors/signal-radars/inbound-dead-letter.ts +60 -14
  5. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +9 -3
  6. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +406 -40
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +1 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/db-session-renewal.ts +209 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -6
  11. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +388 -13
  12. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +28 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +5 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +1 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +38 -5
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +92 -10
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +96 -25
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +29 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +139 -17
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +26 -3
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +145 -5
  22. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +190 -10
  23. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +85 -5
  24. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +21 -11
  25. package/dist/cli/auth-OKPHHMMP.js +43 -0
  26. package/dist/cli/{auth-YIBY5IKT.mjs → auth-QXJMVLPN.mjs} +5 -5
  27. package/dist/cli/{billing-UDKL53GI.js → billing-N5R4HTHT.js} +82 -82
  28. package/dist/cli/{billing-G3IX3SNY.mjs → billing-SNSIFM4B.mjs} +7 -7
  29. package/dist/cli/{chunk-EJBW7Y6Z.js → chunk-2ZWNIS54.js} +108 -96
  30. package/dist/cli/{chunk-3KMGVOBM.mjs → chunk-2ZX7XSAQ.mjs} +4 -4
  31. package/dist/cli/{chunk-4TUMKJZX.mjs → chunk-3WWTBQHC.mjs} +2 -2
  32. package/dist/cli/{chunk-MD524MRB.mjs → chunk-536TGWR6.mjs} +1 -1
  33. package/dist/cli/{chunk-37SXIFIU.js → chunk-66N76YZG.js} +44 -44
  34. package/dist/cli/{chunk-BZY335JP.js → chunk-7E6B7VMS.js} +5 -5
  35. package/dist/cli/{chunk-HYR34KFA.js → chunk-7OQGZBDG.js} +109 -24
  36. package/dist/cli/{chunk-GVKW3LCA.js → chunk-7QM6DNR4.js} +11 -11
  37. package/dist/cli/{chunk-DNJJ3ULJ.js → chunk-ANKD3AIR.js} +2 -2
  38. package/dist/cli/{chunk-4DFWDA2Q.js → chunk-ATATJNJ6.js} +9 -9
  39. package/dist/cli/{chunk-ZZ7U4YJS.mjs → chunk-BXIQD2IY.mjs} +1 -1
  40. package/dist/cli/{chunk-XT25FX6T.js → chunk-BXVYVIMB.js} +3 -3
  41. package/dist/cli/{chunk-XR6TN5DT.mjs → chunk-CH7JVSA7.mjs} +6 -6
  42. package/dist/cli/{chunk-RKE5YTHY.mjs → chunk-EO55Y4QW.mjs} +5 -5
  43. package/dist/cli/{chunk-RI672VNY.js → chunk-EQNAQENZ.js} +2 -2
  44. package/dist/cli/{chunk-LFSOBW7E.mjs → chunk-FXTV5B3D.mjs} +22 -10
  45. package/dist/cli/{chunk-C6WGMODR.mjs → chunk-GMO3JDZA.mjs} +2 -2
  46. package/dist/cli/{chunk-DRDZBRXV.js → chunk-GTGJBZVH.js} +7 -7
  47. package/dist/cli/{chunk-SFMCKB57.mjs → chunk-HLAFGQPV.mjs} +76 -34
  48. package/dist/cli/{chunk-534YYHIF.js → chunk-HTYT2OHB.js} +6 -6
  49. package/dist/cli/{chunk-ZZLZCO6Y.js → chunk-I75VRGQG.js} +22 -22
  50. package/dist/cli/{chunk-Y3LDRCMB.mjs → chunk-II3BJKCH.mjs} +2 -2
  51. package/dist/cli/{chunk-5BQPEHEP.js → chunk-JDIQBZ6O.js} +14 -14
  52. package/dist/cli/{chunk-ENWJFUWK.mjs → chunk-KKPBCB6D.mjs} +2 -2
  53. package/dist/cli/{chunk-BONXEWYF.mjs → chunk-KSQXBLRW.mjs} +3 -3
  54. package/dist/cli/{chunk-7JEN3FX4.js → chunk-LRWDZDBS.js} +5 -5
  55. package/dist/cli/{chunk-5477PEHL.mjs → chunk-MW3YMPD2.mjs} +1 -1
  56. package/dist/cli/{chunk-VFCVH2LV.mjs → chunk-NUC7ZVDG.mjs} +5 -5
  57. package/dist/cli/{chunk-DLDWAPA5.js → chunk-OCT4SUJA.js} +4 -4
  58. package/dist/cli/{chunk-FQQAAR3Q.mjs → chunk-OQ5G7RFQ.mjs} +1 -1
  59. package/dist/cli/{chunk-VIM6I7RC.js → chunk-PFKKZVFK.js} +41 -41
  60. package/dist/cli/{chunk-OAQIVJFY.mjs → chunk-PFKWKWUJ.mjs} +2 -2
  61. package/dist/cli/{chunk-52MHE7B4.mjs → chunk-R457IMHJ.mjs} +1 -1
  62. package/dist/cli/{chunk-UV6XCHOZ.mjs → chunk-RIX26ZJD.mjs} +1 -1
  63. package/dist/cli/{chunk-RDJTCW3I.mjs → chunk-RTDX5NNN.mjs} +3 -3
  64. package/dist/cli/{chunk-FNHUDCJE.js → chunk-RUULUCBP.js} +10 -10
  65. package/dist/cli/{chunk-GMYDVW7Z.js → chunk-SF4QJVBE.js} +3 -3
  66. package/dist/cli/{chunk-DARD7TJ7.js → chunk-SMWFOGUT.js} +53 -53
  67. package/dist/cli/{chunk-XXY4E57R.mjs → chunk-T43FF5PF.mjs} +2 -2
  68. package/dist/cli/{chunk-ZUAKRBZB.js → chunk-TZTWH53O.js} +1 -1
  69. package/dist/cli/{chunk-7J5PLHII.mjs → chunk-V2YIBBVT.mjs} +1 -1
  70. package/dist/cli/{chunk-6SJPZV5E.js → chunk-V4RJ57MA.js} +2 -2
  71. package/dist/cli/{chunk-4MF44THR.js → chunk-V7KUBDEB.js} +82 -40
  72. package/dist/cli/{chunk-ISUUSSS4.js → chunk-VHTVXS5A.js} +16 -16
  73. package/dist/cli/{chunk-NDNG3MAT.mjs → chunk-WCVIPZWX.mjs} +5 -5
  74. package/dist/cli/{chunk-F5D623KO.js → chunk-WOEPDSO3.js} +26 -26
  75. package/dist/cli/{chunk-VE6FHVXZ.mjs → chunk-XURWFEXM.mjs} +109 -24
  76. package/dist/cli/{chunk-G65FJ5JX.mjs → chunk-YCIXY66B.mjs} +2 -2
  77. package/dist/cli/{chunk-CFXERH7F.mjs → chunk-YGOI5ZE5.mjs} +1 -1
  78. package/dist/cli/{chunk-PDLRUZ42.mjs → chunk-YKFW3NNA.mjs} +5 -5
  79. package/dist/cli/{chunk-5H22VJPE.js → chunk-YXVYPYIP.js} +6 -6
  80. package/dist/cli/{chunk-KMBF3N2Z.js → chunk-Z4MOEQSY.js} +16 -16
  81. package/dist/cli/command-docs.js +2 -2
  82. package/dist/cli/command-docs.mjs +1 -1
  83. package/dist/cli/{csv-PE35WGRO.mjs → csv-HT2JBCW2.mjs} +4 -4
  84. package/dist/cli/{csv-3HIE4VCO.js → csv-Q2LWKXAV.js} +13 -13
  85. package/dist/cli/{db-L7ZMMQKW.mjs → db-CS3XQ2LX.mjs} +6 -6
  86. package/dist/cli/{db-O2YRTTDO.js → db-XEV4WEE4.js} +27 -27
  87. package/dist/cli/describe-5G5NXO5E.js +50 -0
  88. package/dist/cli/{describe-NI324Y2M.mjs → describe-OUTXLDGZ.mjs} +18 -18
  89. package/dist/cli/describe-core.d.mts +3 -3
  90. package/dist/cli/describe-core.d.ts +3 -3
  91. package/dist/cli/{executions-VH4DKLFI.js → executions-JCC34WAD.js} +8 -8
  92. package/dist/cli/{executions-T6KU2OKK.mjs → executions-L6XFG5MP.mjs} +6 -6
  93. package/dist/cli/{feedback-SCSJC3FX.mjs → feedback-AWBDO5I6.mjs} +5 -5
  94. package/dist/cli/{feedback-ZLC6G5OK.js → feedback-HV2M2G7N.js} +10 -10
  95. package/dist/cli/git-GDPTG52F.js +25 -0
  96. package/dist/cli/{git-I4LVQCID.mjs → git-S4LRXTRX.mjs} +5 -5
  97. package/dist/cli/index.js +146 -146
  98. package/dist/cli/index.mjs +45 -45
  99. package/dist/cli/{legacy-noops-44FQ2256.mjs → legacy-noops-7MOKBL4O.mjs} +6 -6
  100. package/dist/cli/{legacy-noops-UPFWEHPG.js → legacy-noops-RGSZUD6V.js} +9 -9
  101. package/dist/cli/{monitors-JN6IQGK6.js → monitors-JEFM2C5W.js} +100 -100
  102. package/dist/cli/{monitors-LMSASWXE.mjs → monitors-XQNXDZPQ.mjs} +7 -7
  103. package/dist/cli/{org-F7O3ZU5O.js → org-GYLA5V32.js} +235 -72
  104. package/dist/cli/{org-QYLVEE7A.mjs → org-KTMJZGTN.mjs} +169 -6
  105. package/dist/cli/{pages-KEL3Y4L4.js → pages-RY4U7OCL.js} +18 -18
  106. package/dist/cli/{pages-5XE4LBZN.mjs → pages-WOMU2T2O.mjs} +6 -6
  107. package/dist/cli/{play-OURHH6KV.js → play-2Q6MWJ3D.js} +363 -323
  108. package/dist/cli/{play-MWQG3G32.mjs → play-KOYGGNYS.mjs} +64 -24
  109. package/dist/cli/{providers-IQY7LUBB.mjs → providers-7YKDITJC.mjs} +6 -6
  110. package/dist/cli/{providers-ZCBWPE3C.js → providers-HOIRHMN2.js} +9 -9
  111. package/dist/cli/{quickstart-O53OXTN6.js → quickstart-OWCJOSQA.js} +6 -6
  112. package/dist/cli/{quickstart-L45NGRMI.mjs → quickstart-RDXHSMVX.mjs} +4 -4
  113. package/dist/cli/{run-W745Z3Z5.js → run-MT2ABKO5.js} +41 -41
  114. package/dist/cli/{run-VCSIWLEU.mjs → run-RT73NDP5.mjs} +23 -23
  115. package/dist/cli/search-7VBA6IGS.js +33 -0
  116. package/dist/cli/{search-THELKULN.mjs → search-CJPKIGSA.mjs} +8 -8
  117. package/dist/cli/{search-output-N7MJLYYD.mjs → search-output-AREMA544.mjs} +4 -4
  118. package/dist/cli/{search-output-SJW7LEOM.js → search-output-OSBZ7WK6.js} +6 -6
  119. package/dist/cli/{secrets-44ST3FJH.mjs → secrets-BTIY2FEJ.mjs} +6 -6
  120. package/dist/cli/{secrets-GDXPX3KB.js → secrets-OV6KH633.js} +15 -15
  121. package/dist/cli/{sessions-LYCBI77S.mjs → sessions-3CO3ZFOD.mjs} +6 -6
  122. package/dist/cli/sessions-B3WNEWRW.js +18 -0
  123. package/dist/cli/{settings-GXPDMJFG.mjs → settings-7BQIC7QN.mjs} +13 -13
  124. package/dist/cli/{settings-3WOFF642.js → settings-LBIECYDB.js} +86 -86
  125. package/dist/cli/{setup-YHLMBJP4.js → setup-QZE7QR3F.js} +50 -50
  126. package/dist/cli/{setup-YM6JEB64.mjs → setup-XPTSNNES.mjs} +10 -10
  127. package/dist/cli/{skills-WX4XWEAT.mjs → skills-TGGKIQLT.mjs} +8 -8
  128. package/dist/cli/skills-TXBRTWEV.js +37 -0
  129. package/dist/cli/{tools-K24VSQ7S.mjs → tools-MKIFX2TQ.mjs} +17 -17
  130. package/dist/cli/tools-RZJV4X3J.js +57 -0
  131. package/dist/cli/{update-PSSCF5AT.mjs → update-5R3D3WNH.mjs} +10 -10
  132. package/dist/cli/update-YWGGPWUA.js +35 -0
  133. package/dist/cli/{artifacts-RY2MK74N.mjs → views-VHKDHHUP.mjs} +76 -76
  134. package/dist/cli/views-VPWEINIA.js +270 -0
  135. package/dist/cli/{workflow-FPVI3NIA.js → workflow-7K2VEQ4V.js} +17 -17
  136. package/dist/cli/{workflow-DGOPYATO.mjs → workflow-D5DF65N6.mjs} +7 -7
  137. package/dist/{client-DA71-2_u.d.mts → client-C5_6W8yd.d.mts} +1 -1
  138. package/dist/{client-core-C0IzDKMJ.d.ts → client-core-B-GPfmaC.d.ts} +121 -44
  139. package/dist/{client-core-BXbds1cb.d.mts → client-core-Dob428Z4.d.mts} +121 -44
  140. package/dist/{client-B-2Am2y6.d.ts → client-iXW4TOat.d.ts} +1 -1
  141. package/dist/{compiler-manifest-B4mIIbw7.d.mts → compiler-manifest-DsxsQP-T.d.mts} +14 -7
  142. package/dist/{compiler-manifest-B4mIIbw7.d.ts → compiler-manifest-DsxsQP-T.d.ts} +14 -7
  143. package/dist/{errors-Gj9i5Rkd.d.ts → errors-Bk5h1D-C.d.ts} +1 -1
  144. package/dist/{errors-C2F4qzAq.d.mts → errors-qdJUVQ3g.d.mts} +1 -1
  145. package/dist/{index-5JZBufdF.d.mts → index-PaupwX1B.d.mts} +1 -1
  146. package/dist/{index-BXtSj8bv.d.ts → index-bL66eHYz.d.ts} +1 -1
  147. package/dist/index.d.mts +7 -7
  148. package/dist/index.d.ts +7 -7
  149. package/dist/index.js +9 -9
  150. package/dist/index.mjs +6 -6
  151. package/dist/install-integrity.json +117 -116
  152. package/dist/plays/bundle-play-file.d.mts +3 -3
  153. package/dist/plays/bundle-play-file.d.ts +3 -3
  154. package/dist/plays/bundle-play-file.mjs +7 -5
  155. package/dist/plays/play-description.d.mts +2 -2
  156. package/dist/plays/play-description.d.ts +2 -2
  157. package/dist/plays/run-request.d.mts +2 -2
  158. package/dist/plays/run-request.d.ts +2 -2
  159. package/dist/release.d.mts +1 -1
  160. package/dist/release.d.ts +1 -1
  161. package/dist/release.js +2 -2
  162. package/dist/release.mjs +1 -1
  163. package/dist/server.d.mts +4 -4
  164. package/dist/server.d.ts +4 -4
  165. package/dist/server.js +5 -5
  166. package/dist/server.mjs +3 -3
  167. package/package.json +1 -1
  168. package/dist/cli/artifacts-GIZZH5VA.js +0 -270
  169. package/dist/cli/auth-JSES2JOQ.js +0 -43
  170. package/dist/cli/describe-EB336DAO.js +0 -50
  171. package/dist/cli/git-23T7TXAH.js +0 -25
  172. package/dist/cli/search-R6K7ZAMU.js +0 -33
  173. package/dist/cli/sessions-2V5ZFOWL.js +0 -18
  174. package/dist/cli/skills-XNGADDO6.js +0 -37
  175. package/dist/cli/tools-ROUMCB7B.js +0 -57
  176. package/dist/cli/update-RXURGIRW.js +0 -35
@@ -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({
@@ -14,7 +14,8 @@
14
14
  * retain lazy queue setup for local app-before-worker startup.
15
15
  * observe/result → reuse the postgres LISTEN/NOTIFY run handle.
16
16
  * cancel → commit the Absurd stop and a durable cancellation request;
17
- * the worker deletes sandboxes before the final run write.
17
+ * the worker deletes sandboxes before the final run write. A run
18
+ * no worker ever claimed is cancelled in that same transaction.
18
19
  * signal → durable signal row (authoritative payload) + absurd emitEvent
19
20
  * (the wakeup only; payload is re-read from the signal row).
20
21
  */
@@ -30,6 +31,7 @@ import {
30
31
  } from '../scheduler-backend';
31
32
  import {
32
33
  cancelPostgresSchedulerRun,
34
+ postgresSchedulerCancellationOutboxLease,
33
35
  postgresSchedulerRunHandle,
34
36
  readPostgresSchedulerLaunch,
35
37
  readPostgresSchedulerAbsurdTaskId,
@@ -49,6 +51,7 @@ import {
49
51
  withWorkspaceAdmissionLock,
50
52
  } from './postgres-pool';
51
53
  import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
54
+ import { noteUndrainedRuntimeCancellations } from './absurd-deadline-reconciliation';
52
55
  import { withRuntimeSchedulerSubmitAdmission } from './submit-admission';
53
56
  import {
54
57
  ABSURD_PLAY_RUN_MAX_ATTEMPTS,
@@ -81,6 +84,7 @@ const cancellationFlights = new Map<
81
84
  Promise<PlaySchedulerCancelOutcome>
82
85
  >();
83
86
  const ABSURD_CANCEL_TASK_SAVEPOINT = 'deepline_cancel_absurd_task';
87
+ const ABSURD_FINALIZE_UNCLAIMED_SAVEPOINT = 'deepline_finalize_unclaimed_run';
84
88
 
85
89
  function quotePostgresIdentifier(identifier: string): string {
86
90
  return `"${identifier.replaceAll('"', '""')}"`;
@@ -167,6 +171,93 @@ export async function cancelPostgresSchedulerRunWithoutProjection(
167
171
  return { cancelled, engineTaskCancelled };
168
172
  }
169
173
 
174
+ /**
175
+ * Finish a caller stop inline when no worker ever claimed the run.
176
+ *
177
+ * Runs inside the stop transaction, after `absurd.cancel_task` has locked and
178
+ * cancelled the engine run and task rows. A concurrent `claim_task` either
179
+ * committed first, so this statement's fresh READ COMMITTED snapshot sees its
180
+ * `first_started_at`, or it now re-checks the cancelled run row under its
181
+ * lock and cannot start customer code. `cancel_task` never clears
182
+ * `first_started_at`, so a claimed task always keeps the worker-owned path.
183
+ *
184
+ * Returns false, leaving the transaction as it was, when the run was claimed,
185
+ * fails the scheduler fence, or the terminal write fails; the caller then
186
+ * records the durable request the worker drain finalizes.
187
+ */
188
+ async function finalizeUnclaimedAbsurdRunInline(
189
+ client: PostgresSchedulerQueryClient,
190
+ input: {
191
+ queue: string;
192
+ taskId: string;
193
+ runId: string;
194
+ reason: string;
195
+ schedulerSchema: string;
196
+ schedulerOptions: Pick<AbsurdSchedulerOptions, 'schema'>;
197
+ },
198
+ ): Promise<boolean> {
199
+ await client.query(`SAVEPOINT ${ABSURD_FINALIZE_UNCLAIMED_SAVEPOINT}`);
200
+ const rollBack = async () => {
201
+ await client.query(
202
+ `ROLLBACK TO SAVEPOINT ${ABSURD_FINALIZE_UNCLAIMED_SAVEPOINT}`,
203
+ );
204
+ await client.query(
205
+ `RELEASE SAVEPOINT ${ABSURD_FINALIZE_UNCLAIMED_SAVEPOINT}`,
206
+ );
207
+ };
208
+ let cancelled: boolean;
209
+ try {
210
+ const engineTask = await client.query<{ claimed: boolean }>(
211
+ `SELECT first_started_at IS NOT NULL AS claimed
212
+ FROM absurd.${quotePostgresIdentifier(`t_${input.queue}`)}
213
+ WHERE task_id = $1::uuid`,
214
+ [input.taskId],
215
+ );
216
+ cancelled =
217
+ engineTask.rows[0]?.claimed === false &&
218
+ (await cancelPostgresSchedulerRun(
219
+ client,
220
+ {
221
+ runId: input.runId,
222
+ reason: input.reason,
223
+ onlyIfUnclaimed: { absurdTaskId: input.taskId },
224
+ outboxLease: postgresSchedulerCancellationOutboxLease(input.runId),
225
+ },
226
+ input.schedulerOptions,
227
+ ));
228
+ if (cancelled) {
229
+ // A request queued by an earlier stop (or an older server) is now done.
230
+ await client.query(
231
+ `DELETE FROM ${input.schedulerSchema}.control WHERE key = $1`,
232
+ [`runtime_cancel:${input.runId}`],
233
+ );
234
+ await client.query(
235
+ `RELEASE SAVEPOINT ${ABSURD_FINALIZE_UNCLAIMED_SAVEPOINT}`,
236
+ );
237
+ }
238
+ } catch (error) {
239
+ try {
240
+ await rollBack();
241
+ } catch (rollbackError) {
242
+ throw new AggregateError(
243
+ [error, rollbackError],
244
+ 'Unclaimed cancellation savepoint rollback failed.',
245
+ { cause: error },
246
+ );
247
+ }
248
+ // The durable request below keeps the stop safe; the worker drain
249
+ // finalizes it exactly as before this fast path existed.
250
+ console.warn('[absurd-runtime.cancel] unclaimed_finalize_deferred', {
251
+ runId: input.runId,
252
+ error: error instanceof Error ? error.message : String(error),
253
+ });
254
+ return false;
255
+ }
256
+ // Claimed or fenced out: undo only this savepoint's work.
257
+ if (!cancelled) await rollBack();
258
+ return cancelled;
259
+ }
260
+
170
261
  function runCancellationSingleFlight(
171
262
  key: string,
172
263
  operation: () => Promise<PlaySchedulerCancelOutcome>,
@@ -279,14 +370,16 @@ function absurdRunHandle(input: {
279
370
  effectiveOptions,
280
371
  )
281
372
  ) {
282
- return false;
373
+ return 'stopped' as const;
283
374
  }
375
+ let engineTaskCancelled = false;
284
376
  if (taskId) {
285
377
  const engineTaskPresent = await cancelAbsurdTaskIfPresent(client, {
286
378
  queue: cancellationQueue,
287
379
  taskId,
288
380
  runId: input.runId,
289
381
  });
382
+ engineTaskCancelled = engineTaskPresent;
290
383
  if (engineTaskPresent) {
291
384
  // Older workers only reconcile `manual` or `max_delay`. This
292
385
  // marker is diagnostic; the control row is the cross-lane queue.
@@ -305,19 +398,49 @@ function absurdRunHandle(input: {
305
398
  resolveRuntimeSchedulerSchemaEnv() ||
306
399
  'runtime_scheduler',
307
400
  );
308
- await client.query(
401
+ const cancellationReason = reason?.trim() || 'Cancelled play run.';
402
+ if (
403
+ taskId &&
404
+ engineTaskCancelled &&
405
+ (await finalizeUnclaimedAbsurdRunInline(client, {
406
+ queue: cancellationQueue,
407
+ taskId,
408
+ runId: input.runId,
409
+ reason: cancellationReason,
410
+ schedulerSchema,
411
+ schedulerOptions: effectiveOptions,
412
+ }))
413
+ ) {
414
+ return 'stopped' as const;
415
+ }
416
+ const recorded = await client.query(
309
417
  `INSERT INTO ${schedulerSchema}.control (key, value)
310
418
  VALUES ($1, jsonb_build_object(
311
419
  'reason', left($2::text, 4000),
312
420
  'requestedAt', clock_timestamp()
313
421
  ))
314
- ON CONFLICT (key) DO NOTHING`,
315
- [
316
- `runtime_cancel:${input.runId}`,
317
- reason?.trim() || 'Cancelled play run.',
318
- ],
422
+ ON CONFLICT (key) DO NOTHING
423
+ RETURNING key`,
424
+ [`runtime_cancel:${input.runId}`, cancellationReason],
319
425
  );
320
- return true;
426
+ if (recorded.rows.length === 0) {
427
+ // A repeated stop is the one caller that can see a request no worker
428
+ // drained; report its age without adding a poll.
429
+ const existing = await client.query<{ requested_at: string | null }>(
430
+ `SELECT value->>'requestedAt' AS requested_at
431
+ FROM ${schedulerSchema}.control
432
+ WHERE key = $1`,
433
+ [`runtime_cancel:${input.runId}`],
434
+ );
435
+ noteUndrainedRuntimeCancellations({
436
+ source: 'repeat_stop',
437
+ requests: existing.rows.map((row) => ({
438
+ runId: input.runId,
439
+ requestedAt: row.requested_at,
440
+ })),
441
+ });
442
+ }
443
+ return 'cancelling' as const;
321
444
  },
322
445
  {
323
446
  runId: input.runId,
@@ -327,17 +450,16 @@ function absurdRunHandle(input: {
327
450
  { maxAttempts: 1 },
328
451
  );
329
452
 
330
- // A queued cancellation is the normal Absurd outcome: the worker owns
331
- // sandbox cleanup and the final run update. Report it as a typed state, not
332
- // an error; `stopped` means the scheduler result was already terminal.
453
+ // A queued cancellation is the normal Absurd outcome for a claimed run: the
454
+ // worker owns sandbox cleanup and the final run update. Report it as a typed
455
+ // state, not an error. `stopped` means the scheduler result is terminal:
456
+ // already, or now because no worker ever claimed the run.
333
457
  const requestCancellation = (
334
458
  reason?: string,
335
459
  ): Promise<PlaySchedulerCancelOutcome> =>
336
- runCancellationSingleFlight(cancellationKey, async () =>
337
- (await queueCancellation(reason))
338
- ? { state: 'cancelling' }
339
- : { state: 'stopped' },
340
- );
460
+ runCancellationSingleFlight(cancellationKey, async () => ({
461
+ state: await queueCancellation(reason),
462
+ }));
341
463
 
342
464
  return {
343
465
  ...delegate,