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
@@ -1,3 +1,4 @@
1
+ import type { DaytonaDeleteRetryAuthorization } from './daytona-lifecycle';
1
2
  import {
2
3
  boundedDaytonaProviderTextForLog,
3
4
  createDaytonaLaunchClient,
@@ -20,6 +21,7 @@ import {
20
21
  import { randomUUID } from 'node:crypto';
21
22
  import type {
22
23
  PlayRunnerBackend,
24
+ PlayRunnerRuntimeResource,
23
25
  PlayRunnerPreparedExecution,
24
26
  PlayRunnerPrepareInput,
25
27
  } from '../types';
@@ -1105,6 +1107,7 @@ export async function deleteDaytonaSandboxByIdWithOutcome(input: {
1105
1107
  timeoutSeconds?: number;
1106
1108
  expectedOrganizationId?: string | null;
1107
1109
  allowUnscopedAlreadyAbsent?: boolean;
1110
+ retry?: DaytonaDeleteRetryAuthorization;
1108
1111
  /** Durable proof that Daytona accepted this delete on an earlier pass. */
1109
1112
  deleteAcceptance?: { organizationId: string | null } | null;
1110
1113
  }): Promise<DaytonaSandboxDeleteOutcome> {
@@ -1142,9 +1145,10 @@ export async function deleteDaytonaSandboxByIdWithOutcome(input: {
1142
1145
  if (
1143
1146
  !DAYTONA_SANDBOX_DELETING_STATES.has(
1144
1147
  String(sandbox.state ?? '').toLowerCase(),
1145
- )
1148
+ ) &&
1149
+ !input.deleteAcceptance
1146
1150
  ) {
1147
- await control.delete(sandbox);
1151
+ await control.delete(sandbox, input.retry);
1148
1152
  }
1149
1153
  return {
1150
1154
  kind: 'delete_pending',
@@ -1755,6 +1759,37 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
1755
1759
  const reportedSandboxIds = new Set<string>();
1756
1760
  const reportedSandboxEndTimes = new Map<string, number | null>();
1757
1761
  const runtimeResourceReportErrors = new Set<unknown>();
1762
+ const resourceFact = (
1763
+ acquired: AcquiredDaytonaSandbox,
1764
+ ): PlayRunnerRuntimeResource => {
1765
+ const sandbox = acquired.sandbox;
1766
+ const billingEndedAt = acquired.billingEndedAt ?? null;
1767
+ return {
1768
+ kind: 'daytona_sandbox',
1769
+ sandboxId: sandbox.id,
1770
+ runtimeEnvironment:
1771
+ process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
1772
+ ? 'preview'
1773
+ : 'production',
1774
+ daytonaEnvironment:
1775
+ process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
1776
+ ? 'preview'
1777
+ : 'production',
1778
+ daytonaOrganizationId: acquired.daytonaOrganizationId,
1779
+ billingStartedAt: acquired.billingStartedAt,
1780
+ billingEndedAt,
1781
+ maxBillingDurationSeconds:
1782
+ (config.context.sandboxRuntimeLimits?.timeoutSeconds ??
1783
+ STANDARD_PLAY_RUNTIME_LIMIT_SECONDS) +
1784
+ PLAY_RUNNER_TERMINAL_GRACE_SECONDS,
1785
+ cpu: typeof sandbox.cpu === 'number' ? sandbox.cpu : null,
1786
+ memoryGiB: typeof sandbox.memory === 'number' ? sandbox.memory : null,
1787
+ diskGiB: typeof sandbox.disk === 'number' ? sandbox.disk : null,
1788
+ ...(acquired.sandboxCapacityLeaseId
1789
+ ? { sandboxCapacityLeaseId: acquired.sandboxCapacityLeaseId }
1790
+ : {}),
1791
+ };
1792
+ };
1758
1793
  const reportRuntimeResource = async (
1759
1794
  acquired: AcquiredDaytonaSandbox,
1760
1795
  revalidate = false,
@@ -1769,31 +1804,7 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
1769
1804
  return;
1770
1805
  }
1771
1806
  try {
1772
- await callbacks?.onRuntimeResourceAcquired?.({
1773
- kind: 'daytona_sandbox',
1774
- sandboxId: sandbox.id,
1775
- runtimeEnvironment:
1776
- process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
1777
- ? 'preview'
1778
- : 'production',
1779
- daytonaEnvironment:
1780
- process.env.DEEPLINE_RUNTIME_ENVIRONMENT === 'preview'
1781
- ? 'preview'
1782
- : 'production',
1783
- daytonaOrganizationId: acquired.daytonaOrganizationId,
1784
- billingStartedAt: acquired.billingStartedAt,
1785
- billingEndedAt,
1786
- maxBillingDurationSeconds:
1787
- (config.context.sandboxRuntimeLimits?.timeoutSeconds ??
1788
- STANDARD_PLAY_RUNTIME_LIMIT_SECONDS) +
1789
- PLAY_RUNNER_TERMINAL_GRACE_SECONDS,
1790
- cpu: typeof sandbox.cpu === 'number' ? sandbox.cpu : null,
1791
- memoryGiB: typeof sandbox.memory === 'number' ? sandbox.memory : null,
1792
- diskGiB: typeof sandbox.disk === 'number' ? sandbox.disk : null,
1793
- ...(acquired.sandboxCapacityLeaseId
1794
- ? { sandboxCapacityLeaseId: acquired.sandboxCapacityLeaseId }
1795
- : {}),
1796
- });
1807
+ await callbacks?.onRuntimeResourceAcquired?.(resourceFact(acquired));
1797
1808
  } catch (error) {
1798
1809
  runtimeResourceReportErrors.add(error);
1799
1810
  throw error;
@@ -1820,9 +1831,8 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
1820
1831
  });
1821
1832
  const onCancel = () => {
1822
1833
  cancellationRequested = true;
1823
- if (activeAcquiredResource && !activeAcquiredResource.billingEndedAt) {
1824
- activeAcquiredResource.billingEndedAt = Date.now();
1825
- }
1834
+ if (activeAcquiredResource)
1835
+ activeAcquiredResource.billingEndedAt ??= Date.now();
1826
1836
  // Publication may commit after a lost response or lose its attempt fence.
1827
1837
  // Join it before deciding whether this backend still owns deletion.
1828
1838
  if (resourceAccountingPending || resourceAccountingFailed) {
@@ -1883,20 +1893,66 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
1883
1893
  cancellationPromise,
1884
1894
  ]);
1885
1895
  activeAcquiredResource = acquiredSandbox;
1886
- sandboxCleanup.activate({
1887
- ...acquiredSandbox,
1888
- deleteSandbox: () =>
1889
- acquiredSandbox.deleteSandbox(
1896
+ sandboxCleanup.activate(acquiredSandbox, async () => {
1897
+ // One deadline and one retirement promise cover every exit path.
1898
+ const deadlineAtMs = Date.now() + 30_000;
1899
+ acquiredSandbox.billingEndedAt ??= Date.now();
1900
+ if (
1901
+ callbacks?.retireRuntimeResource &&
1902
+ acquiredSandbox.sandboxCapacityLeaseId?.trim()
1903
+ ) {
1904
+ try {
1905
+ await callbacks.retireRuntimeResource(
1906
+ resourceFact(acquiredSandbox),
1907
+ {
1908
+ deadlineAtMs,
1909
+ signal: callbacks.cancellationSignal,
1910
+ },
1911
+ );
1912
+ // An outgoing cleanup owner may have recorded DELETE acceptance.
1913
+ // Independently join exact physical absence without another DELETE.
1914
+ callbacks.cancellationSignal?.throwIfAborted();
1915
+ const remainingMs = deadlineAtMs - Date.now();
1916
+ if (remainingMs <= 0) throw new DaytonaControlTimeoutError();
1917
+ if (!acquiredSandbox.confirmAbsent) {
1918
+ throw new Error(
1919
+ 'Managed Daytona retirement requires an owned absence observer.',
1920
+ );
1921
+ }
1922
+ await acquiredSandbox.confirmAbsent(
1923
+ remainingMs,
1924
+ callbacks.cancellationSignal,
1925
+ deadlineAtMs,
1926
+ );
1927
+ throwIfCancellationRequested();
1928
+ // The retirement owner already persisted this end fact. Do not
1929
+ // re-promote a deleted operation when accounting the next sandbox.
1930
+ reportedSandboxIds.add(acquiredSandbox.sandbox.id);
1931
+ reportedSandboxEndTimes.set(
1932
+ acquiredSandbox.sandbox.id,
1933
+ acquiredSandbox.billingEndedAt,
1934
+ );
1935
+ } catch (error) {
1936
+ runtimeResourceReportErrors.add(error);
1937
+ throw error;
1938
+ }
1939
+ } else {
1940
+ if (callbacks?.onRuntimeResourceAcquired)
1941
+ await reportRetiringRuntimeResource(acquiredSandbox);
1942
+ const remainingMs = deadlineAtMs - Date.now();
1943
+ if (remainingMs <= 0) throw new DaytonaControlTimeoutError();
1944
+ await acquiredSandbox.deleteSandbox(
1945
+ 30,
1946
+ deadlineAtMs,
1890
1947
  callbacks?.onRuntimeResourceAcquired &&
1891
1948
  acquiredSandbox.sandboxCapacityLeaseId
1892
1949
  ? {
1893
- // Bypass the local report cache: the scheduler must prove this
1894
- // exact attempt still owns deletion before each mutating retry.
1895
1950
  authorizeRetry: () =>
1896
1951
  reportRuntimeResource(acquiredSandbox, true),
1897
1952
  }
1898
1953
  : undefined,
1899
- ),
1954
+ );
1955
+ }
1900
1956
  });
1901
1957
  runtimeTiming.daytonaCreateMs =
1902
1958
  acquiredSandbox.billingStartedAt - startedAt;
@@ -2069,8 +2125,6 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
2069
2125
  elapsedMs: Date.now() - startedAt,
2070
2126
  });
2071
2127
  if (executionAttempt < DAYTONA_UPLOAD_MAX_ATTEMPTS) {
2072
- acquiredSandbox.billingEndedAt = Date.now();
2073
- await reportRetiringRuntimeResource(acquiredSandbox);
2074
2128
  await sandboxCleanup.stashActiveSandboxForRetry();
2075
2129
  emitDaytonaStage(callbacks, config.context, 'recreate:start', {
2076
2130
  previousSandboxId: sandbox.id,
@@ -2078,6 +2132,7 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
2078
2132
  reason: 'upload_deadline',
2079
2133
  elapsedMs: Date.now() - startedAt,
2080
2134
  });
2135
+ throwIfCancellationRequested();
2081
2136
  acquiredSandboxPromise = sandboxLifecycle.createFreshSandbox();
2082
2137
  continue;
2083
2138
  }
@@ -2192,7 +2247,12 @@ export const daytonaPlayRunnerBackend: PlayRunnerBackend = {
2192
2247
  const retireSandboxForAttempt = async () => {
2193
2248
  if (!sandboxForAttempt) return;
2194
2249
  activeAcquiredResource!.billingEndedAt = Date.now();
2195
- await reportRetiringRuntimeResource(activeAcquiredResource!);
2250
+ if (
2251
+ !callbacks?.retireRuntimeResource ||
2252
+ !activeAcquiredResource!.sandboxCapacityLeaseId?.trim()
2253
+ ) {
2254
+ await reportRetiringRuntimeResource(activeAcquiredResource!);
2255
+ }
2196
2256
  try {
2197
2257
  await sandboxCleanup.stashActiveSandboxForRetry();
2198
2258
  } catch (retirementError) {
@@ -172,6 +172,14 @@ export interface PlayRunnerCallbacks {
172
172
  onWorkCounters?: (
173
173
  event: Extract<PlayRunnerEvent, { type: 'work_counters' }>,
174
174
  ) => void;
175
+ /** Managed cleanup owner; failure must never fall back to local deletion. */
176
+ retireRuntimeResource?: (
177
+ resource: PlayRunnerRuntimeResource,
178
+ options: {
179
+ deadlineAtMs: number;
180
+ signal?: AbortSignal;
181
+ },
182
+ ) => Promise<void>;
175
183
  onRuntimeResourceAcquired?: (
176
184
  resource: PlayRunnerRuntimeResource,
177
185
  ) => void | Promise<void>;
@@ -8,12 +8,14 @@ import {
8
8
  } from '../plays/cell-staleness';
9
9
  import {
10
10
  RuntimeSheetAttemptSupersededError,
11
+ RuntimeSheetAdmissionRequestTooLargeError,
11
12
  RuntimeSheetWriteIntentUnavailableError,
12
13
  type RuntimeMapRowsStaleReason,
13
14
  type RuntimeMapRowsStaleRow,
14
15
  } from './runtime-sheet-errors';
15
16
  export {
16
17
  RuntimeSheetAttemptSupersededError,
18
+ RuntimeSheetAdmissionRequestTooLargeError,
17
19
  RuntimeSheetWriteIntentUnavailableError,
18
20
  type RuntimeMapRowsStaleReason,
19
21
  type RuntimeMapRowsStaleRow,
@@ -7924,10 +7926,55 @@ export async function startRuntimeSheetDataset(
7924
7926
  return result;
7925
7927
  };
7926
7928
  if (context.dbSessionStrategy === 'gateway_only') {
7929
+ const body: RuntimeApiActionRequest = {
7930
+ // A named operation prevents an old gateway from silently ignoring the
7931
+ // intent opt-in and re-admitting this run under a new version.
7932
+ action:
7933
+ input.stableWriteIntent === true
7934
+ ? 'runtime_sheet_start_with_intent'
7935
+ : 'runtime_sheet_start',
7936
+ // Play input does not participate in sheet admission and can be large.
7937
+ input: { ...input, playInput: undefined, pendingRerunAdmission: true },
7938
+ };
7939
+ // Match the gateway's decoded-body guard. Check the common envelope and
7940
+ // every row before admitting any prefix, without allocating the entire
7941
+ // source page as JSON. A single oversized row/common envelope cannot split.
7942
+ if (input.stableWriteIntent === true) {
7943
+ const limit = RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES;
7944
+ const common = jsonByteLengthUpTo(
7945
+ prepareRetainedPlayPipelinesForTransport({
7946
+ ...body,
7947
+ input: { ...body.input, rows: [] },
7948
+ }),
7949
+ limit,
7950
+ );
7951
+ if (common.exceeded) {
7952
+ throw new RuntimeSheetAdmissionRequestTooLargeError(
7953
+ limit,
7954
+ common.bytes,
7955
+ );
7956
+ }
7957
+ for (let index = 0; index < input.rows.length; index += 1) {
7958
+ // The aggregate input may exceed one request because it is paged
7959
+ // below. Reject a row that cannot fit by itself, but do not add all
7960
+ // row sizes together here or the paging path is unreachable.
7961
+ const row = jsonByteLengthUpTo(input.rows[index], limit - common.bytes);
7962
+ if (row.exceeded) {
7963
+ throw new RuntimeSheetAdmissionRequestTooLargeError(
7964
+ limit,
7965
+ common.bytes + row.bytes,
7966
+ );
7967
+ }
7968
+ }
7969
+ }
7927
7970
  return checkedResult(
7928
- await startRuntimeSheetDatasetViaGateway(context, input),
7971
+ await startRuntimeSheetDatasetViaGateway(context, {
7972
+ ...input,
7973
+ playInput: undefined,
7974
+ }),
7929
7975
  );
7930
7976
  }
7977
+
7931
7978
  const totalStartedAt = Date.now();
7932
7979
  const timings: RuntimeSheetTiming[] = [];
7933
7980
  const playName = context.playName?.trim() || input.playName;
@@ -9304,17 +9351,20 @@ async function completeRuntimeMapRowChunksWithInputIndexRepair(
9304
9351
  schema: session.postgres.schema,
9305
9352
  table: session.postgres.sheetTable,
9306
9353
  columns: input.physicalColumnProjections,
9307
- rows: async () => {
9354
+ rows: async (inferableFields) => {
9308
9355
  const accepted = await client.query<{
9309
9356
  data_patch: Record<string, unknown>;
9310
9357
  }>(
9311
9358
  `${matchingUpdatesSql}
9312
- SELECT updates.data_patch
9359
+ SELECT ${RuntimeSheetColumns.jsonTypeEvidenceSql({
9360
+ jsonExpression: 'updates.data_patch',
9361
+ fieldsExpression: '$14::text[]',
9362
+ })} AS data_patch
9313
9363
  FROM matched_updates AS updates
9314
9364
  JOIN ${sheetTable(session)} AS target ON target._key = updates.matched_key
9315
9365
  WHERE ${writableRowsSql}
9316
9366
  FOR UPDATE OF target`,
9317
- mutationParams,
9367
+ [...mutationParams, inferableFields],
9318
9368
  );
9319
9369
  return accepted.rows.map((row) => row.data_patch);
9320
9370
  },
@@ -9491,7 +9541,7 @@ async function insertMissingCompletedMapRowChunks(
9491
9541
  schema: session.postgres.schema,
9492
9542
  table: session.postgres.sheetTable,
9493
9543
  columns: input.physicalColumnProjections,
9494
- rows: async () => {
9544
+ rows: async (inferableFields) => {
9495
9545
  const accepted = await client.query<{
9496
9546
  data_patch: Record<string, unknown>;
9497
9547
  }>(
@@ -9503,7 +9553,11 @@ async function insertMissingCompletedMapRowChunks(
9503
9553
  WHERE target._key = incoming.key
9504
9554
  )
9505
9555
  )
9506
- SELECT incoming.data_patch FROM exact_key_missing AS incoming
9556
+ SELECT ${RuntimeSheetColumns.jsonTypeEvidenceSql({
9557
+ jsonExpression: 'incoming.data_patch',
9558
+ fieldsExpression: '$3::text[]',
9559
+ })} AS data_patch
9560
+ FROM exact_key_missing AS incoming
9507
9561
  WHERE NOT EXISTS (
9508
9562
  SELECT 1 FROM ${sheetTable(session)} AS target
9509
9563
  WHERE incoming.input_index IS NOT NULL AND target._run_id = $2::text
@@ -9518,6 +9572,7 @@ async function insertMissingCompletedMapRowChunks(
9518
9572
  })),
9519
9573
  ),
9520
9574
  input.runId,
9575
+ inferableFields,
9521
9576
  ],
9522
9577
  );
9523
9578
  return accepted.rows.map((row) => row.data_patch);
@@ -9803,17 +9858,20 @@ async function failRuntimeMapRowChunks(
9803
9858
  schema: session.postgres.schema,
9804
9859
  table: session.postgres.sheetTable,
9805
9860
  columns: input.physicalColumnProjections,
9806
- rows: async () => {
9861
+ rows: async (inferableFields) => {
9807
9862
  const accepted = await client.query<{
9808
9863
  data_patch: Record<string, unknown>;
9809
9864
  }>(
9810
9865
  `${matchingUpdatesSql}
9811
- SELECT updates.data_patch
9866
+ SELECT ${RuntimeSheetColumns.jsonTypeEvidenceSql({
9867
+ jsonExpression: 'updates.data_patch',
9868
+ fieldsExpression: '$17::text[]',
9869
+ })} AS data_patch
9812
9870
  FROM matched_updates AS updates
9813
9871
  JOIN ${sheetTable(session)} AS target ON target._key = updates.matched_key
9814
9872
  WHERE ${writableRowsSql}
9815
9873
  FOR UPDATE OF target`,
9816
- mutationParams,
9874
+ [...mutationParams, inferableFields],
9817
9875
  );
9818
9876
  return accepted.rows.map((row) => row.data_patch);
9819
9877
  },
@@ -362,11 +362,11 @@ export const RUNTIME_INCIDENT_DRILL_CATALOG: readonly RuntimeIncidentDrill[] = [
362
362
  topologies: LOCAL_AND_PREVIEW_TOPOLOGIES,
363
363
  control: {
364
364
  kind: 'runtime_test_fault',
365
- // The 120-second lease plus 80 seconds of on-time confirmation is the
366
- // earliest provider read. Preview woke late enough to exhaust 300
367
- // seconds of silence before that read. Keep the synthetic runner quiet
368
- // for seven minutes without changing the worker's liveness policy.
369
- defaultValue: 420_000,
365
+ // The 120-second lease plus 80 seconds of confirmation puts the first
366
+ // provider read at about 200 seconds. A further 250 seconds absorbs
367
+ // delayed scheduler wakes in the shared Preview lane, so the read still
368
+ // lands inside the silence and not after it.
369
+ defaultValue: 450_000,
370
370
  valueMeaning: 'milliseconds',
371
371
  },
372
372
  expected: {
@@ -548,9 +548,12 @@ function classifyReceiptRetry(
548
548
  return { retryAfterMs: error.retryAfterMs };
549
549
  }
550
550
  if (error instanceof AppRuntimeApiTransportError) {
551
- // The one-attempt transport throws this only when no complete HTTP
552
- // response arrived: DNS, connect, reset, or its request timeout.
553
- return { retryAfterMs: 250, connectionFailure: true };
551
+ // Headers followed by a body timeout spend the ordinary response budget.
552
+ // An omitted fact keeps older/pre-response transport errors compatible.
553
+ return {
554
+ retryAfterMs: 250,
555
+ connectionFailure: error.responseReceived !== true,
556
+ };
554
557
  }
555
558
  if (error instanceof AppRuntimeApiResponseError && error.retryable) {
556
559
  return { retryAfterMs: 250 };
@@ -1,5 +1,19 @@
1
1
  import { resolveMapRowOutcomeKey } from './map-row-outcome';
2
2
 
3
+ /** Local preflight only: no sheet request was sent and no rows were admitted. */
4
+ export class RuntimeSheetAdmissionRequestTooLargeError extends Error {
5
+ constructor(
6
+ readonly limitBytes: number,
7
+ readonly observedBytes: number,
8
+ readonly canSplit = false,
9
+ ) {
10
+ super(
11
+ `Runtime Sheet admission request exceeds the ${limitBytes} byte decoded-body budget (observed at least ${observedBytes} bytes).`,
12
+ );
13
+ this.name = 'RuntimeSheetAdmissionRequestTooLargeError';
14
+ }
15
+ }
16
+
3
17
  /** An older gateway cannot safely translate durable intent to legacy start. */
4
18
  export class RuntimeSheetWriteIntentUnavailableError extends Error {
5
19
  readonly code = 'RUNTIME_SHEET_WRITE_INTENT_UNAVAILABLE';