deepline 0.3.484 → 0.3.485

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 (209) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +91 -30
  2. package/dist/bundling-sources/sdk/src/compat.ts +13 -0
  3. package/dist/bundling-sources/sdk/src/plays/client-core.ts +4 -1
  4. package/dist/bundling-sources/sdk/src/plays/run-request.ts +143 -9
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +31 -4
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +7 -1
  9. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-column-storage.ts +32 -3
  10. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +126 -41
  11. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +231 -25
  12. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +9 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +130 -19
  14. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-registry.ts +105 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/execute-server-timing.ts +4 -2
  16. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +194 -56
  17. package/dist/bundling-sources/shared_libs/play-runtime/log-provenance.ts +11 -6
  18. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +3 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +2 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +2 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +30 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +195 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +20 -1
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +15 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +2 -2
  26. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +102 -23
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/progress-sidecar.ts +9 -1
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +25 -5
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +133 -82
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +58 -16
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-sandbox-absence.ts +171 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +69 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +100 -40
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +8 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -9
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +5 -5
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +6 -3
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +14 -0
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-writer.ts +87 -31
  40. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +18 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +19 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +14 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +204 -6
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +12 -1
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +26 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +44 -15
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +60 -11
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +649 -38
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +6 -1
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +17 -0
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +25 -33
  53. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +12 -0
  54. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +21 -0
  55. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +1 -1
  56. package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +1 -1
  57. package/dist/cli/auth-ABZBH55L.js +43 -0
  58. package/dist/cli/{auth-EBFOTF7X.mjs → auth-OWMUENCU.mjs} +5 -5
  59. package/dist/cli/{billing-G2G3EF3I.js → billing-2FMNQGOX.js} +80 -80
  60. package/dist/cli/{billing-2ZOIMW5V.mjs → billing-JX4H3VFF.mjs} +7 -7
  61. package/dist/cli/{chunk-M4PG7FGC.js → chunk-2ILND7XX.js} +2 -2
  62. package/dist/cli/{chunk-WXRM3UC6.mjs → chunk-2ZEQ43B7.mjs} +3 -3
  63. package/dist/cli/{chunk-PU52JXKA.mjs → chunk-3DBW6C7M.mjs} +13 -4
  64. package/dist/cli/{chunk-4OVHIWE7.mjs → chunk-3DYU3JQN.mjs} +2 -2
  65. package/dist/cli/{chunk-QIDDTIVZ.js → chunk-3OF7NSGR.js} +322 -294
  66. package/dist/cli/{chunk-YWC5AN26.mjs → chunk-3Z24NKW7.mjs} +62 -34
  67. package/dist/cli/{chunk-RLLEH2SP.js → chunk-5DCQWQCP.js} +26 -26
  68. package/dist/cli/{chunk-DEXSQGXB.mjs → chunk-62PJ6PK7.mjs} +5 -5
  69. package/dist/cli/{chunk-6NPWXE32.mjs → chunk-676NZ7K4.mjs} +1 -1
  70. package/dist/cli/{chunk-FRD5WFT4.js → chunk-775AZTO7.js} +323 -247
  71. package/dist/cli/{chunk-4OEOM6GP.mjs → chunk-ACTUAZYP.mjs} +5 -5
  72. package/dist/cli/{chunk-ZOKM7DVA.js → chunk-AFADYKFE.js} +8 -8
  73. package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
  74. package/dist/cli/{chunk-U7IJAGWB.js → chunk-BSKPQB2P.js} +7 -7
  75. package/dist/cli/chunk-C6QWRSMQ.js +42 -0
  76. package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
  77. package/dist/cli/{chunk-YHA3EV3I.mjs → chunk-CW6TAQBF.mjs} +15 -4
  78. package/dist/cli/{chunk-UT4YMA2N.js → chunk-DMNVM34J.js} +5 -4
  79. package/dist/cli/{chunk-XZXIWPT3.mjs → chunk-E73JXJA3.mjs} +1 -1
  80. package/dist/cli/{chunk-5KNRQWHE.js → chunk-EC2CVPN5.js} +3 -3
  81. package/dist/cli/{chunk-IXWQOVNW.js → chunk-ECIXZNSW.js} +87 -76
  82. package/dist/cli/{chunk-LTZXLYKE.mjs → chunk-FJY6K3BG.mjs} +93 -17
  83. package/dist/cli/{chunk-TRLDJNVE.mjs → chunk-G5PI3RNT.mjs} +1 -1
  84. package/dist/cli/{chunk-WYUCDLVR.mjs → chunk-GHHJWCMD.mjs} +2 -1
  85. package/dist/cli/{chunk-FQK7BULS.js → chunk-HKGXGGIV.js} +1 -1
  86. package/dist/cli/{chunk-2AWYJXBX.js → chunk-IHMYIHF4.js} +5 -5
  87. package/dist/cli/{chunk-SD7QWZTV.mjs → chunk-INW22YP7.mjs} +1 -1
  88. package/dist/cli/{chunk-OWUZKXE7.mjs → chunk-J7EENGKJ.mjs} +1 -1
  89. package/dist/cli/{chunk-TIRSKEZH.mjs → chunk-JD6HKNKD.mjs} +1 -1
  90. package/dist/cli/{chunk-OHKKDPA5.js → chunk-JQXUWYWX.js} +13 -13
  91. package/dist/cli/{chunk-EACX7QXO.mjs → chunk-KZTNNLIL.mjs} +2 -2
  92. package/dist/cli/{chunk-7K5CWKKZ.mjs → chunk-L352NOE3.mjs} +2 -2
  93. package/dist/cli/{chunk-KGOC6HGI.js → chunk-L7IQ3DFH.js} +53 -53
  94. package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
  95. package/dist/cli/{chunk-6GRZEYSG.js → chunk-NKPTM7SK.js} +7 -7
  96. package/dist/cli/{chunk-VEVGM6B5.js → chunk-NLRTFJGH.js} +14 -14
  97. package/dist/cli/{chunk-UKM74PAA.js → chunk-NRNWPWBW.js} +37 -37
  98. package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
  99. package/dist/cli/{chunk-CYWBAV5H.js → chunk-OW4OTEFF.js} +16 -16
  100. package/dist/cli/{chunk-5K5CAND4.mjs → chunk-RZE5I2XJ.mjs} +4 -4
  101. package/dist/cli/{chunk-3XQIVEAT.js → chunk-S3WQJ5VG.js} +3 -3
  102. package/dist/cli/{chunk-4SFC2XUF.mjs → chunk-SR6S4EYG.mjs} +5 -5
  103. package/dist/cli/{chunk-UWOY74RU.js → chunk-T4G2T5DS.js} +21 -21
  104. package/dist/cli/{chunk-TN2GW57M.mjs → chunk-TMCC7ORQ.mjs} +1 -1
  105. package/dist/cli/{chunk-HEI3BWIV.mjs → chunk-TSCUWWTM.mjs} +1 -1
  106. package/dist/cli/{chunk-DBJ62RAO.js → chunk-TVW6USSG.js} +3 -3
  107. package/dist/cli/{chunk-NW4QJE54.js → chunk-U6WEGDD3.js} +2 -2
  108. package/dist/cli/{chunk-V7JCMBLU.mjs → chunk-UPHXGZCE.mjs} +4 -4
  109. package/dist/cli/{chunk-C62NI2X6.js → chunk-UQ3LQ6IF.js} +5 -5
  110. package/dist/cli/{chunk-5GOG5ZGC.mjs → chunk-VZYTLWOM.mjs} +2 -2
  111. package/dist/cli/{chunk-AF7MOUZP.mjs → chunk-W33OL4F2.mjs} +2 -2
  112. package/dist/cli/{chunk-ZM2YPJQJ.js → chunk-XK5DMLZE.js} +5 -1
  113. package/dist/cli/{chunk-LJ5747UC.mjs → chunk-XRDXNAAY.mjs} +5 -1
  114. package/dist/cli/{chunk-YGN77QA5.mjs → chunk-YDA3PMKK.mjs} +3 -3
  115. package/dist/cli/{csv-S3CHUKI6.js → csv-HFEQPGNY.js} +13 -13
  116. package/dist/cli/{csv-NLWVWD3H.mjs → csv-OHF3Y5KB.mjs} +4 -4
  117. package/dist/cli/{db-OGRPAEEM.mjs → db-M456OUXD.mjs} +7 -7
  118. package/dist/cli/{db-WBSKMMOH.js → db-VLQKCYQS.js} +28 -28
  119. package/dist/cli/describe-CP35DZ5Z.js +49 -0
  120. package/dist/cli/{describe-FAD3Z7LN.mjs → describe-M6VXFYVL.mjs} +21 -21
  121. package/dist/cli/describe-core.d.mts +3 -3
  122. package/dist/cli/describe-core.d.ts +3 -3
  123. package/dist/cli/describe-core.js +4 -4
  124. package/dist/cli/describe-core.mjs +3 -3
  125. package/dist/cli/{executions-LYCL344R.mjs → executions-4FGRBPJF.mjs} +7 -7
  126. package/dist/cli/{executions-SOAZHCY4.js → executions-GKINJZI6.js} +9 -9
  127. package/dist/cli/{feedback-AVF6V7SV.mjs → feedback-D2WMGK3V.mjs} +4 -4
  128. package/dist/cli/{feedback-OROUPUNJ.js → feedback-ZH5K7WV7.js} +8 -8
  129. package/dist/cli/git-IDALMZDN.js +25 -0
  130. package/dist/cli/{git-J5N5M57H.mjs → git-OCIJ5ME4.mjs} +5 -5
  131. package/dist/cli/index.js +142 -139
  132. package/dist/cli/index.mjs +45 -42
  133. package/dist/cli/{legacy-noops-QAQMZMEG.js → legacy-noops-QNIVP7LO.js} +8 -8
  134. package/dist/cli/{legacy-noops-ENRRM7BL.mjs → legacy-noops-V6Q2X34P.mjs} +5 -5
  135. package/dist/cli/{monitors-CKQ65WRL.mjs → monitors-2USHTG5G.mjs} +8 -8
  136. package/dist/cli/{monitors-SFMQ5LFR.js → monitors-5DNK7W2K.js} +92 -92
  137. package/dist/cli/{org-3UNTDLT2.js → org-RPGM5AN4.js} +73 -73
  138. package/dist/cli/{org-K4UIEU5P.mjs → org-TL2YPYSE.mjs} +7 -7
  139. package/dist/cli/{pages-NKZTGB4C.js → pages-PNUKPFWV.js} +18 -18
  140. package/dist/cli/{pages-6GPGBIAH.mjs → pages-XDEW6EE3.mjs} +7 -7
  141. package/dist/cli/{play-BDEADESI.js → play-F5LHRKV5.js} +858 -632
  142. package/dist/cli/{play-62BEE7IX.mjs → play-WINNQ4HZ.mjs} +372 -146
  143. package/dist/cli/{providers-SXGP44GH.js → providers-BD4IS5U5.js} +10 -10
  144. package/dist/cli/{providers-X3CUWMFP.mjs → providers-PXGL3FRE.mjs} +7 -7
  145. package/dist/cli/{quickstart-XQ4426M4.js → quickstart-7LVF6HZF.js} +6 -6
  146. package/dist/cli/{quickstart-7LN22BKX.mjs → quickstart-XTH3UQWZ.mjs} +4 -4
  147. package/dist/cli/{run-XXSN3B5A.mjs → run-MBMUENR7.mjs} +26 -26
  148. package/dist/cli/{run-PBJ4ZJ4W.js → run-NH2BAWPA.js} +41 -41
  149. package/dist/cli/{search-M75VMADD.mjs → search-BMRWBV66.mjs} +8 -8
  150. package/dist/cli/search-R3MQJQMT.js +32 -0
  151. package/dist/cli/{search-output-F6HCFYEI.js → search-output-5NNT337U.js} +22 -16
  152. package/dist/cli/{search-output-NUQAKWDM.mjs → search-output-QKKRD4MF.mjs} +14 -8
  153. package/dist/cli/{secrets-J2H6V33R.mjs → secrets-AWEXBTJV.mjs} +7 -7
  154. package/dist/cli/{secrets-LRYY4QPE.js → secrets-KQSTOREN.js} +16 -16
  155. package/dist/cli/{sessions-YPF62CZE.js → sessions-DSPLZYCJ.js} +6 -6
  156. package/dist/cli/{sessions-IMT336UV.mjs → sessions-RO25Q67X.mjs} +5 -5
  157. package/dist/cli/{settings-35YYC5WA.js → settings-7JXIKNKI.js} +79 -79
  158. package/dist/cli/{settings-PDWVQIGH.mjs → settings-JMGXGK4Z.mjs} +12 -12
  159. package/dist/cli/{setup-UR7GOR7H.js → setup-5QFAQQRW.js} +47 -47
  160. package/dist/cli/{setup-DG5DISSE.mjs → setup-ZQZ47FHB.mjs} +9 -9
  161. package/dist/cli/skills-EDZXY7DV.js +33 -0
  162. package/dist/cli/{skills-U6NJD5J7.mjs → skills-W3H2DL56.mjs} +7 -7
  163. package/dist/cli/{tools-2HGEOELR.mjs → tools-2BZCVNBS.mjs} +19 -19
  164. package/dist/cli/tools-2EY2ETCZ.js +56 -0
  165. package/dist/cli/{update-FRAYBAHK.mjs → update-GAWYMGAW.mjs} +9 -9
  166. package/dist/cli/update-UKDQKNBY.js +33 -0
  167. package/dist/cli/{workflow-DDKVTF36.mjs → workflow-M6LLHQ2I.mjs} +8 -8
  168. package/dist/cli/{workflow-JKKLOMBX.js → workflow-ZPTDFPKW.js} +18 -18
  169. package/dist/{client-DJ3r8VQJ.d.mts → client-BkbDHRIg.d.mts} +1 -1
  170. package/dist/{client-JPSNljtj.d.ts → client-D3hVHXjK.d.ts} +1 -1
  171. package/dist/{client-core-3SJlNsKU.d.mts → client-core-BZoSMKcY.d.mts} +30 -15
  172. package/dist/{client-core-rCoQ5Xz3.d.ts → client-core-DUdVqO_m.d.ts} +30 -15
  173. package/dist/{compiler-manifest-gkO9ZkVg.d.mts → compiler-manifest-BFTwq1HI.d.mts} +1 -1
  174. package/dist/{compiler-manifest-gkO9ZkVg.d.ts → compiler-manifest-BFTwq1HI.d.ts} +1 -1
  175. package/dist/{errors-Cc92LKH-.d.ts → errors-c3pMsylw.d.ts} +1 -1
  176. package/dist/{errors-CeCCOKSA.d.mts → errors-w31ybrQM.d.mts} +1 -1
  177. package/dist/{index-DJQKdV76.d.ts → index-CQ-15-QL.d.ts} +1 -1
  178. package/dist/{index-DsqWJL3Q.d.mts → index-DvNtxucX.d.mts} +1 -1
  179. package/dist/index.d.mts +7 -7
  180. package/dist/index.d.ts +7 -7
  181. package/dist/index.js +10 -10
  182. package/dist/index.mjs +7 -7
  183. package/dist/install-integrity.json +117 -116
  184. package/dist/plays/bundle-play-file.d.mts +3 -3
  185. package/dist/plays/bundle-play-file.d.ts +3 -3
  186. package/dist/plays/bundle-play-file.mjs +2 -2
  187. package/dist/plays/play-description.d.mts +2 -2
  188. package/dist/plays/play-description.d.ts +2 -2
  189. package/dist/plays/run-request.d.mts +2 -2
  190. package/dist/plays/run-request.d.ts +2 -2
  191. package/dist/plays/run-request.js +12 -2
  192. package/dist/plays/run-request.mjs +11 -1
  193. package/dist/release.d.mts +1 -1
  194. package/dist/release.d.ts +1 -1
  195. package/dist/release.js +2 -2
  196. package/dist/release.mjs +1 -1
  197. package/dist/server.d.mts +4 -4
  198. package/dist/server.d.ts +4 -4
  199. package/dist/server.js +6 -6
  200. package/dist/server.mjs +4 -4
  201. package/package.json +1 -1
  202. package/dist/cli/auth-L5CSV3UO.js +0 -43
  203. package/dist/cli/chunk-KA2LNIUP.js +0 -33
  204. package/dist/cli/describe-UIAYCHWW.js +0 -49
  205. package/dist/cli/git-ATMWC27D.js +0 -25
  206. package/dist/cli/search-IGHLRLBD.js +0 -32
  207. package/dist/cli/skills-4U5WC4MJ.js +0 -33
  208. package/dist/cli/tools-PYJTQVVS.js +0 -56
  209. package/dist/cli/update-344OTRFM.js +0 -33
@@ -13,6 +13,7 @@ type PendingTerminal<Row> = {
13
13
  key: string;
14
14
  value: Row;
15
15
  bytes: number;
16
+ queuedAt: number;
16
17
  committed: Deferred[];
17
18
  };
18
19
 
@@ -21,6 +22,7 @@ type PendingCheckpoint<Update> = {
21
22
  key: string;
22
23
  value: Update;
23
24
  bytes: number;
25
+ queuedAt: number;
24
26
  };
25
27
 
26
28
  type PendingWrite<Row, Update> =
@@ -32,6 +34,7 @@ type BlockedTerminal<Row> = {
32
34
  key: string;
33
35
  value: Row;
34
36
  bytes: number;
37
+ queuedAt: number;
35
38
  admitted: Deferred;
36
39
  committed: Deferred;
37
40
  };
@@ -41,6 +44,7 @@ type BlockedCheckpoint<Update> = {
41
44
  key: string;
42
45
  value: Update;
43
46
  bytes: number;
47
+ queuedAt: number;
44
48
  admitted: Deferred;
45
49
  };
46
50
 
@@ -170,8 +174,11 @@ export class RuntimeSheetRowWriter<Row, Update> {
170
174
  #activeStartedAt: number | null = null;
171
175
  #bufferedBytes = 0;
172
176
  #liveBytes = 0;
177
+ #oldestLiveQueuedAt = Infinity;
173
178
  #timer: ReturnType<typeof setTimeout> | null = null;
179
+ #timerDueAt: number | null = null;
174
180
  #pump: Promise<void> | null = null;
181
+ #draining = 0;
175
182
  #checkpointPromise: Promise<RuntimeSheetRowWriterSummary> | null = null;
176
183
  #finishPromise: Promise<RuntimeSheetRowWriterSummary> | null = null;
177
184
  #stateWaiters: Deferred[] = [];
@@ -199,7 +206,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
199
206
  positiveInteger(options.maxBatchBytes, 1024 * 1024),
200
207
  this.#maxBufferedBytes,
201
208
  );
202
- this.#maxFlushMs = Math.max(0, Math.floor(options.maxFlushMs ?? 500));
209
+ const maxFlushMs = Math.floor(options.maxFlushMs ?? 500);
210
+ // Native timers treat unsupported delays as a next-turn wake. They must
211
+ // not become an unreachable age deadline in the accumulator.
212
+ this.#maxFlushMs =
213
+ Number.isFinite(maxFlushMs) && maxFlushMs <= 2_147_483_647
214
+ ? Math.max(0, maxFlushMs)
215
+ : 0;
203
216
  this.#classifyRetryableError =
204
217
  options.classifyRetryableError ?? (() => null);
205
218
  this.#sleep = options.sleep ?? abortableSleep;
@@ -219,11 +232,15 @@ export class RuntimeSheetRowWriter<Row, Update> {
219
232
  key,
220
233
  value: row,
221
234
  bytes,
235
+ queuedAt: performance.now(),
222
236
  admitted,
223
237
  committed,
224
238
  };
225
239
  if (this.#canAdmit(blocked)) this.#admit(blocked);
226
- else this.#blocked.push(blocked);
240
+ else {
241
+ this.#blocked.push(blocked);
242
+ this.#scheduleOrStart();
243
+ }
227
244
  return {
228
245
  admitted: admitted.promise,
229
246
  committed: committed.promise,
@@ -310,11 +327,15 @@ export class RuntimeSheetRowWriter<Row, Update> {
310
327
  key,
311
328
  value: update,
312
329
  bytes: this.#inputBytes(this.#estimateCheckpointBytes(update)),
330
+ queuedAt: performance.now(),
313
331
  admitted,
314
332
  };
315
333
  try {
316
334
  if (this.#canAdmit(blocked)) this.#admit(blocked);
317
- else this.#blocked.push(blocked);
335
+ else {
336
+ this.#blocked.push(blocked);
337
+ this.#scheduleOrStart();
338
+ }
318
339
  } catch (error) {
319
340
  // A merged checkpoint can exceed the item limit even when each patch
320
341
  // fits independently. Reject only the incoming checkpoint.
@@ -345,6 +366,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
345
366
 
346
367
  #admit(write: BlockedWrite<Row, Update>): void {
347
368
  const existing = this.#live.get(write.key);
369
+ const queuedAt = Math.min(write.queuedAt, existing?.queuedAt ?? Infinity);
348
370
  if (write.kind === 'terminal') {
349
371
  this.#terminalAcceptedKeys.add(write.key);
350
372
  if (existing) {
@@ -360,6 +382,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
360
382
  key: write.key,
361
383
  value: write.value,
362
384
  bytes: write.bytes,
385
+ queuedAt,
363
386
  committed,
364
387
  };
365
388
  this.#live.set(write.key, terminal);
@@ -382,6 +405,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
382
405
  key: write.key,
383
406
  value: merged,
384
407
  bytes: mergedBytes,
408
+ queuedAt,
385
409
  };
386
410
  this.#live.set(write.key, checkpoint);
387
411
  write = { ...write, bytes: checkpoint.bytes };
@@ -391,11 +415,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
391
415
  key: write.key,
392
416
  value: write.value,
393
417
  bytes: write.bytes,
418
+ queuedAt,
394
419
  };
395
420
  this.#live.set(write.key, checkpoint);
396
421
  }
397
422
  this.#liveBytes += write.bytes;
398
423
  this.#bufferedBytes += write.bytes;
424
+ this.#oldestLiveQueuedAt = Math.min(this.#oldestLiveQueuedAt, queuedAt);
399
425
  write.admitted.resolve();
400
426
  this.#scheduleOrStart();
401
427
  this.#notifyStateChanged();
@@ -403,19 +429,32 @@ export class RuntimeSheetRowWriter<Row, Update> {
403
429
 
404
430
  #scheduleOrStart(): void {
405
431
  if (this.#pump || this.#live.size === 0 || this.#failure !== null) return;
406
- if (
407
- this.#live.size >= this.#maxBatchRows ||
408
- this.#liveBytes >= this.#maxBatchBytes
409
- ) {
432
+ if (this.#mustFlushImmediately()) {
410
433
  this.#clearTimer();
411
434
  this.#startPump();
412
435
  return;
413
436
  }
414
- if (this.#timer) return;
415
- this.#timer = setTimeout(() => {
416
- this.#timer = null;
417
- this.#startPump();
418
- }, this.#maxFlushMs);
437
+ const dueAt = this.#oldestLiveQueuedAt + this.#maxFlushMs;
438
+ if (this.#timer && this.#timerDueAt === dueAt) return;
439
+ this.#clearTimer();
440
+ this.#timerDueAt = dueAt;
441
+ this.#timer = setTimeout(
442
+ () => {
443
+ this.#timer = null;
444
+ this.#timerDueAt = null;
445
+ this.#startPump();
446
+ },
447
+ Math.max(0, Math.ceil(dueAt - performance.now())),
448
+ );
449
+ }
450
+
451
+ #mustFlushImmediately(): boolean {
452
+ return (
453
+ this.#draining > 0 ||
454
+ this.#blocked.length > 0 ||
455
+ this.#live.size >= this.#maxBatchRows ||
456
+ this.#liveBytes >= this.#maxBatchBytes
457
+ );
419
458
  }
420
459
 
421
460
  #startPump(): void {
@@ -425,17 +464,20 @@ export class RuntimeSheetRowWriter<Row, Update> {
425
464
  this.#pump = this.#runPump().finally(() => {
426
465
  this.#pump = null;
427
466
  this.#notifyStateChanged();
428
- if (this.#failure === null && this.#live.size > 0) {
429
- // Rows accumulated behind an active write are real backlog. Drain the
430
- // largest available next batch immediately instead of starting a new
431
- // age window and manufacturing latency.
432
- this.#startPump();
433
- }
467
+ this.#scheduleOrStart();
434
468
  });
435
469
  }
436
470
 
437
471
  async #runPump(): Promise<void> {
438
472
  while (this.#live.size > 0 && this.#failure === null) {
473
+ // A small backlog may have arrived only moments before the active
474
+ // write ended. Keep its original age window instead of turning one
475
+ // timer wake into a continuous train of underfull writes.
476
+ if (
477
+ !this.#mustFlushImmediately() &&
478
+ performance.now() - this.#oldestLiveQueuedAt < this.#maxFlushMs
479
+ )
480
+ return;
439
481
  const batch = this.#takeBatch();
440
482
  if (batch.length === 0) return;
441
483
  const batchKind = batch[0]!.kind;
@@ -491,6 +533,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
491
533
  batch.push(entry);
492
534
  bytes += entry.bytes;
493
535
  }
536
+ this.#oldestLiveQueuedAt = Infinity;
537
+ for (const entry of this.#live.values()) {
538
+ this.#oldestLiveQueuedAt = Math.min(
539
+ this.#oldestLiveQueuedAt,
540
+ entry.queuedAt,
541
+ );
542
+ }
494
543
  return batch;
495
544
  }
496
545
 
@@ -562,21 +611,26 @@ export class RuntimeSheetRowWriter<Row, Update> {
562
611
  }
563
612
 
564
613
  async #drain(): Promise<void> {
614
+ this.#draining += 1;
565
615
  this.#clearTimer();
566
- for (;;) {
567
- if (this.#failure !== null) throw this.#failure;
568
- this.#admitBlocked();
569
- if (
570
- this.#active === null &&
571
- this.#live.size === 0 &&
572
- this.#blocked.length === 0
573
- ) {
574
- return;
616
+ try {
617
+ for (;;) {
618
+ if (this.#failure !== null) throw this.#failure;
619
+ this.#admitBlocked();
620
+ if (
621
+ this.#active === null &&
622
+ this.#live.size === 0 &&
623
+ this.#blocked.length === 0
624
+ ) {
625
+ return;
626
+ }
627
+ this.#startPump();
628
+ const stateChanged = deferred();
629
+ this.#stateWaiters.push(stateChanged);
630
+ await stateChanged.promise;
575
631
  }
576
- this.#startPump();
577
- const stateChanged = deferred();
578
- this.#stateWaiters.push(stateChanged);
579
- await stateChanged.promise;
632
+ } finally {
633
+ this.#draining -= 1;
580
634
  }
581
635
  }
582
636
 
@@ -599,6 +653,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
599
653
  }
600
654
  this.#live.clear();
601
655
  this.#liveBytes = 0;
656
+ this.#oldestLiveQueuedAt = Infinity;
602
657
  for (const blocked of this.#blocked.splice(0)) {
603
658
  blocked.admitted.reject(error);
604
659
  if (blocked.kind === 'terminal') blocked.committed.reject(error);
@@ -636,6 +691,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
636
691
  if (!this.#timer) return;
637
692
  clearTimeout(this.#timer);
638
693
  this.#timer = null;
694
+ this.#timerDueAt = null;
639
695
  }
640
696
 
641
697
  #notifyStateChanged(error?: unknown): void {
@@ -346,6 +346,14 @@ export type SandboxExecutionLifecycle = {
346
346
  ): Promise<void>;
347
347
  /** Must resolve before the Adapter can accept a command for this resource. */
348
348
  recordResource(input: SandboxExecutionResource): Promise<void>;
349
+ /** Optional owner operation: persist retirement, then join exact fenced cleanup. */
350
+ retireResource?(
351
+ resource: SandboxExecutionResource,
352
+ options: {
353
+ deadlineAtMs: number;
354
+ signal?: AbortSignal;
355
+ },
356
+ ): Promise<void>;
349
357
  /** Same durable rule for a create that settles after the caller timed out. */
350
358
  recordLateResource(input: SandboxExecutionResource): Promise<void>;
351
359
  /**
@@ -404,6 +412,16 @@ export type SandboxExecutionDependencies<
404
412
  execution: SandboxExecutionPort<Launch, Checkpoint, Suspension, RunnerResult>;
405
413
  /** Every resource record binds its capacity lease in the scheduler fence. */
406
414
  resourceFacts: SandboxExecutionResourceFacts;
415
+ /** Internal owner seam; absence retains the prior backend contract. */
416
+ retirement?: {
417
+ retire(input: {
418
+ attempt: SandboxRunInput['attempt'];
419
+ authority: SandboxRunInput['authority'];
420
+ resource: SandboxExecutionResource;
421
+ deadlineAtMs: number;
422
+ signal?: AbortSignal;
423
+ }): Promise<{ kind: 'retired' } | { kind: 'fence_lost' }>;
424
+ };
407
425
  /** Required when the Adapter crosses Modal's ambiguous-create boundary. */
408
426
  createIntents?: SandboxExecutionCreateIntents;
409
427
  /** Required when the Adapter emits provider-edge lifecycle evidence. */
@@ -301,6 +301,25 @@ function createExecutionLifecycle<Launch, Checkpoint, Suspension, RunnerResult>(
301
301
  );
302
302
  acceptedResources.add(resourceIdentity(resource));
303
303
  },
304
+ ...(dependencies.retirement
305
+ ? {
306
+ retireResource: async (
307
+ resource: SandboxExecutionResource,
308
+ options: { deadlineAtMs: number; signal?: AbortSignal },
309
+ ) => {
310
+ validateResource(resource);
311
+ const outcome = await dependencies.retirement!.retire({
312
+ attempt: input.attempt,
313
+ authority: input.authority,
314
+ resource,
315
+ ...options,
316
+ });
317
+ if (outcome.kind === 'fence_lost')
318
+ throw new SandboxResourceFenceLostError();
319
+ rememberResource(resource);
320
+ },
321
+ }
322
+ : {}),
304
323
  recordLateResource: async (resource) => {
305
324
  rememberResource(resource);
306
325
  recordResult(
@@ -154,6 +154,20 @@ function createRunnerCallbacks(input: {
154
154
  onWorkCounters: input.progress?.onWorkCounters,
155
155
  readDetachedRunnerReadiness: async (baselineHeartbeatAt) =>
156
156
  await input.readiness({ baselineHeartbeatAt }),
157
+ ...(input.lifecycle.retireResource
158
+ ? {
159
+ retireRuntimeResource: async (
160
+ resource: PlayRunnerRuntimeResource,
161
+ options: { deadlineAtMs: number; signal?: AbortSignal },
162
+ ) => {
163
+ await input.lifecycle.retireResource!(
164
+ toSandboxResource(resource),
165
+ options,
166
+ );
167
+ remember(resource);
168
+ },
169
+ }
170
+ : {}),
157
171
  onRuntimeResourceAcquired: async (resource) => {
158
172
  await input.lifecycle.recordResource(remember(resource));
159
173
  },
@@ -1,3 +1,4 @@
1
+ import type { DaytonaDeleteRetryAuthorization } from '../runner-backends/backends/daytona-lifecycle';
1
2
  /**
2
3
  * `absurd` durable task handler + worker startup.
3
4
  *
@@ -140,6 +141,8 @@ import {
140
141
  buildPostgresSchedulerRunnerContext,
141
142
  claimPostgresSchedulerComputeBillingJobs,
142
143
  claimPostgresSchedulerSandboxCleanupJobs,
144
+ readPostgresSchedulerSandboxRetirement,
145
+ readPostgresSchedulerSandboxCleanupClaim,
143
146
  claimPostgresSchedulerRecoveryCircuit,
144
147
  claimPostgresSchedulerOverdueDetachedRunnerCeilings,
145
148
  closePostgresSchedulerRecoveryCircuit,
@@ -840,6 +843,8 @@ export type AbsurdRuntimeWorkerDeps = {
840
843
  deleteRuntimeSandboxWithOutcome?: (
841
844
  sandboxId: string,
842
845
  expectedOrganizationId: string | null,
846
+ timeoutMs?: number,
847
+ retry?: DaytonaDeleteRetryAuthorization,
843
848
  deleteAcceptance?: PostgresSchedulerSandboxDeleteAcceptance | null,
844
849
  ) => Promise<DaytonaSandboxDeleteOutcome>;
845
850
  /** Maximum time a best-effort sandbox deletion may occupy a worker slot. */
@@ -935,13 +940,16 @@ function buildDefaultDeps(absurd: Absurd): AbsurdRuntimeWorkerDeps {
935
940
  deleteRuntimeSandboxWithOutcome: (
936
941
  sandboxId,
937
942
  expectedOrganizationId,
943
+ timeoutMs,
944
+ retry,
938
945
  deleteAcceptance,
939
946
  ) =>
940
947
  deleteDaytonaSandboxByIdWithOutcome({
941
948
  sandboxId,
942
949
  expectedOrganizationId,
950
+ retry,
951
+ timeoutSeconds: (timeoutMs ?? ABSURD_SANDBOX_GC_TIMEOUT_MS) / 1_000,
943
952
  deleteAcceptance,
944
- timeoutSeconds: ABSURD_SANDBOX_GC_TIMEOUT_MS / 1_000,
945
953
  }),
946
954
  sandboxGcTimeoutMs: ABSURD_SANDBOX_GC_TIMEOUT_MS,
947
955
  readDetachedRunnerRuntimeCompletion: (suspension) =>
@@ -4765,6 +4773,29 @@ async function executeAssignedAbsurdAttempt(input: {
4765
4773
  );
4766
4774
  },
4767
4775
  },
4776
+ retirement: {
4777
+ async retire({ resource, deadlineAtMs, signal }) {
4778
+ const retired =
4779
+ await retirePostgresSchedulerSandboxForReplacement({
4780
+ deps,
4781
+ runId,
4782
+ attempt: generation,
4783
+ leaseToken,
4784
+ resource:
4785
+ playRunnerRuntimeResourceFromSandboxExecutionResource(
4786
+ resource,
4787
+ ),
4788
+ deadlineAtMs,
4789
+ signal,
4790
+ schedulerOptions: options,
4791
+ });
4792
+ return {
4793
+ kind: retired
4794
+ ? ('retired' as const)
4795
+ : ('fence_lost' as const),
4796
+ };
4797
+ },
4798
+ },
4768
4799
  resourceFacts: {
4769
4800
  async record({ resource }) {
4770
4801
  const runnerResource =
@@ -8684,6 +8715,130 @@ function unavailableSandboxCrashDiagnostic(
8684
8715
  };
8685
8716
  }
8686
8717
 
8718
+ /** Persist retirement first; only the existing exact-resource cleanup owner deletes. */
8719
+ export async function retirePostgresSchedulerSandboxForReplacement(input: {
8720
+ deps: Pick<
8721
+ AbsurdRuntimeWorkerDeps,
8722
+ | 'runWithClient'
8723
+ | 'deleteRuntimeSandbox'
8724
+ | 'deleteRuntimeSandboxRef'
8725
+ | 'deleteRuntimeSandboxWithOutcome'
8726
+ >;
8727
+ runId: string;
8728
+ attempt: number;
8729
+ leaseToken: string;
8730
+ resource: PlayRunnerRuntimeResource;
8731
+ deadlineAtMs: number;
8732
+ signal?: AbortSignal;
8733
+ schedulerOptions?: Pick<PostgresSchedulerOptions, 'schema'>;
8734
+ }): Promise<boolean> {
8735
+ const { resource } = input;
8736
+ if (
8737
+ resource.kind !== 'daytona_sandbox' ||
8738
+ !isManagedSandboxCapacityResource(resource) ||
8739
+ !resource.daytonaOrganizationId?.trim() ||
8740
+ !Number.isFinite(resource.billingEndedAt)
8741
+ ) {
8742
+ throw new Error(
8743
+ 'Managed sandbox retirement requires the exact owned resource and billing end.',
8744
+ );
8745
+ }
8746
+ const options = input.schedulerOptions ?? {};
8747
+ const identity = {
8748
+ runId: input.runId,
8749
+ attempt: input.attempt,
8750
+ leaseToken: input.leaseToken,
8751
+ provider: 'daytona' as const,
8752
+ sandboxId: resource.sandboxId,
8753
+ routingDomain: resource.daytonaOrganizationId.trim(),
8754
+ };
8755
+ const observe = () =>
8756
+ input.deps.runWithClient((client) =>
8757
+ readPostgresSchedulerSandboxRetirement(client, identity, options),
8758
+ );
8759
+ const remaining = () => {
8760
+ const ms = input.deadlineAtMs - Date.now();
8761
+ if (ms <= 0)
8762
+ throw new Error(
8763
+ 'Sandbox retirement exceeded its original 30000ms deadline.',
8764
+ );
8765
+ return ms;
8766
+ };
8767
+ remaining();
8768
+ const before = await observe();
8769
+ if (!before.fenced) return false;
8770
+ if (before.status !== 'deleted') {
8771
+ const recorded = await input.deps.runWithClient((client) =>
8772
+ recordPostgresSchedulerManagedSandboxOperationLive(
8773
+ client,
8774
+ {
8775
+ runId: input.runId,
8776
+ attempt: input.attempt,
8777
+ leaseToken: input.leaseToken,
8778
+ resource,
8779
+ },
8780
+ options,
8781
+ ),
8782
+ );
8783
+ if (!recorded) return false;
8784
+ }
8785
+ // Cancellation ends the join, never the already-persisted cleanup obligation.
8786
+ let claimedHere = false;
8787
+ const leaseOwner = `retirement:${randomUUID()}`;
8788
+ for (;;) {
8789
+ remaining();
8790
+ input.signal?.throwIfAborted();
8791
+ const state = await observe();
8792
+ if (!state.fenced) return false;
8793
+ if (state.status === 'deleted') return true;
8794
+ if (!state.status || state.blocked || state.error) {
8795
+ throw new Error(
8796
+ `Sandbox retirement is unresolved: ${state.error ?? state.status ?? 'missing obligation'}.`,
8797
+ );
8798
+ }
8799
+ if (!claimedHere) {
8800
+ const jobs = await input.deps.runWithClient((client) =>
8801
+ claimPostgresSchedulerSandboxCleanupJobs(
8802
+ client,
8803
+ {
8804
+ leaseOwner,
8805
+ runId: input.runId,
8806
+ environment:
8807
+ resource.runtimeEnvironment ??
8808
+ resource.daytonaEnvironment ??
8809
+ 'production',
8810
+ exactResource: {
8811
+ provider: identity.provider,
8812
+ sandboxId: identity.sandboxId,
8813
+ routingDomain: identity.routingDomain,
8814
+ attempt: input.attempt,
8815
+ },
8816
+ limit: 1,
8817
+ leaseSeconds: SANDBOX_CLEANUP_STAGE_1_LEASE_SECONDS,
8818
+ },
8819
+ options,
8820
+ ),
8821
+ );
8822
+ if (jobs.length > 0) {
8823
+ claimedHere = true;
8824
+ await processPostgresSchedulerSandboxCleanupJob({
8825
+ job: jobs[0],
8826
+ ...input.deps,
8827
+ leaseOwner,
8828
+ schedulerOptions: options,
8829
+ timeoutMs: remaining(),
8830
+ deadlineAtMs: input.deadlineAtMs,
8831
+ retirement: { identity, signal: input.signal },
8832
+ });
8833
+ continue;
8834
+ }
8835
+ }
8836
+ await sleep(Math.min(100, remaining()), undefined, {
8837
+ signal: input.signal,
8838
+ });
8839
+ }
8840
+ }
8841
+
8687
8842
  async function claimPostgresSchedulerSandboxCleanupBatch(input: {
8688
8843
  runWithClient: AbsurdRuntimeWorkerDeps['runWithClient'];
8689
8844
  leaseOwner: string;
@@ -8722,6 +8877,11 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
8722
8877
  leaseOwner: string;
8723
8878
  schedulerOptions: Pick<PostgresSchedulerOptions, 'schema'>;
8724
8879
  timeoutMs: number;
8880
+ deadlineAtMs?: number;
8881
+ retirement?: {
8882
+ identity: Parameters<typeof readPostgresSchedulerSandboxRetirement>[1];
8883
+ signal?: AbortSignal;
8884
+ };
8725
8885
  readSandboxCrashDiagnostic?: AbsurdRuntimeWorkerDeps['readSandboxCrashDiagnostic'];
8726
8886
  }): Promise<SandboxCleanupJobOutcome> {
8727
8887
  const { job } = input;
@@ -8893,6 +9053,15 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
8893
9053
  if (!deleteProof.acceptance) {
8894
9054
  await recordCleanupEvent('provider_delete_started', { timeoutMs });
8895
9055
  }
9056
+ const remainingMs =
9057
+ input.deadlineAtMs === undefined
9058
+ ? timeoutMs
9059
+ : Math.min(timeoutMs, input.deadlineAtMs - Date.now());
9060
+ if (remainingMs <= 0)
9061
+ throw new RuntimeSandboxGcTimeoutError(
9062
+ resource.sandboxId,
9063
+ timeoutMs,
9064
+ );
8896
9065
  const providerOutcome = await deleteRuntimeSandboxBounded({
8897
9066
  deleteRuntimeSandbox: async (sandboxId) => {
8898
9067
  if (resource.provider === 'modal') {
@@ -8928,6 +9097,39 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
8928
9097
  return await input.deleteRuntimeSandboxWithOutcome(
8929
9098
  sandboxId,
8930
9099
  resource.routingDomain,
9100
+ remainingMs,
9101
+ input.retirement && input.deadlineAtMs !== undefined
9102
+ ? {
9103
+ authorizeRetry: async () => {
9104
+ const assertBudget = () => {
9105
+ input.retirement!.signal?.throwIfAborted();
9106
+ if (Date.now() >= input.deadlineAtMs!)
9107
+ throw new Error(
9108
+ 'Sandbox retirement exceeded its original 30000ms deadline.',
9109
+ );
9110
+ };
9111
+ assertBudget();
9112
+ const authorized = await input.runWithClient(
9113
+ (client) =>
9114
+ readPostgresSchedulerSandboxCleanupClaim(
9115
+ client,
9116
+ {
9117
+ ...resource,
9118
+ leaseOwner: input.leaseOwner,
9119
+ leaseToken:
9120
+ input.retirement!.identity.leaseToken,
9121
+ },
9122
+ input.schedulerOptions,
9123
+ ),
9124
+ );
9125
+ assertBudget();
9126
+ if (!authorized)
9127
+ throw new Error(
9128
+ 'Sandbox retirement retry lost its initiating attempt or exact cleanup claim.',
9129
+ );
9130
+ },
9131
+ }
9132
+ : undefined,
8931
9133
  deleteProof.acceptance,
8932
9134
  );
8933
9135
  }
@@ -8944,7 +9146,7 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
8944
9146
  } satisfies DaytonaSandboxDeleteOutcome);
8945
9147
  },
8946
9148
  sandboxId: resource.sandboxId,
8947
- timeoutMs,
9149
+ timeoutMs: remainingMs,
8948
9150
  });
8949
9151
  if (
8950
9152
  providerOutcome.kind === 'deleted' ||
@@ -8962,10 +9164,6 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
8962
9164
  await recordCleanupEvent('provider_delete_accepted', {
8963
9165
  routingDomain: providerOutcome.organizationId,
8964
9166
  });
8965
- } else {
8966
- await recordCleanupEvent('provider_delete_pending', {
8967
- code: providerOutcome.code,
8968
- });
8969
9167
  }
8970
9168
  return {
8971
9169
  kind: 'pending',
@@ -29,6 +29,7 @@ import {
29
29
  type PlaySchedulerSubmitInput,
30
30
  } from '../scheduler-backend';
31
31
  import {
32
+ cancelPostgresSchedulerRun,
32
33
  postgresSchedulerRunHandle,
33
34
  readPostgresSchedulerLaunch,
34
35
  readPostgresSchedulerAbsurdTaskId,
@@ -127,6 +128,44 @@ async function cancelAbsurdTaskIfPresent(
127
128
  }
128
129
  }
129
130
 
131
+ /**
132
+ * Cancel a queued run that never reached Convex, inside the caller's
133
+ * transaction. Ordinary cancellation resolves the run through its Convex row,
134
+ * which a failed run.created projection never wrote. The scheduler fence
135
+ * proves the run is still queued with zero attempts and its run.created
136
+ * failed, then the engine task is cancelled so no worker can start it. The
137
+ * scheduler's run.cancelled fact waits behind the failed run.created.
138
+ */
139
+ export async function cancelPostgresSchedulerRunWithoutProjection(
140
+ client: PostgresSchedulerQueryClient,
141
+ input: { runId: string; absurdTaskId: string; reason: string },
142
+ options?: { schema?: string },
143
+ ): Promise<{ cancelled: boolean; engineTaskCancelled: boolean }> {
144
+ const launch = await readPostgresSchedulerLaunch(
145
+ client,
146
+ input.runId,
147
+ options,
148
+ { caller: 'play_run_control' },
149
+ );
150
+ if (!launch) return { cancelled: false, engineTaskCancelled: false };
151
+ const cancelled = await cancelPostgresSchedulerRun(
152
+ client,
153
+ {
154
+ runId: input.runId,
155
+ reason: input.reason,
156
+ onlyIfCreatedProjectionFailed: { absurdTaskId: input.absurdTaskId },
157
+ },
158
+ options,
159
+ );
160
+ if (!cancelled) return { cancelled: false, engineTaskCancelled: false };
161
+ const engineTaskCancelled = await cancelAbsurdTaskIfPresent(client, {
162
+ queue: absurdQueueNameForRelease(absurdReleaseIdForLaunch(launch)),
163
+ taskId: input.absurdTaskId,
164
+ runId: input.runId,
165
+ });
166
+ return { cancelled, engineTaskCancelled };
167
+ }
168
+
130
169
  function runCancellationSingleFlight(
131
170
  key: string,
132
171
  operation: () => Promise<PlaySchedulerCancelOutcome>,