deepline 0.3.484 → 0.3.486

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 (210) 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/ledger-safe-payload.ts +8 -4
  18. package/dist/bundling-sources/shared_libs/play-runtime/log-provenance.ts +11 -6
  19. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +3 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +2 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +2 -1
  22. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +30 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +195 -2
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +20 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +15 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +2 -2
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +139 -67
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/progress-sidecar.ts +9 -1
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +25 -5
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +133 -82
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +58 -16
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-sandbox-absence.ts +171 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +69 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +100 -40
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +8 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -9
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +5 -5
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +6 -3
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +14 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-writer.ts +87 -31
  41. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +18 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +19 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +14 -0
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +206 -7
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +12 -1
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +28 -9
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +44 -15
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +60 -11
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +656 -64
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +6 -1
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +17 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +25 -33
  54. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +12 -0
  55. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +21 -0
  56. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +1 -1
  57. package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +1 -1
  58. package/dist/cli/auth-ARKH3OAU.js +43 -0
  59. package/dist/cli/{auth-EBFOTF7X.mjs → auth-B4DJO4FB.mjs} +5 -5
  60. package/dist/cli/{billing-G2G3EF3I.js → billing-GDWAMARK.js} +80 -80
  61. package/dist/cli/{billing-2ZOIMW5V.mjs → billing-IIQ3VNXU.mjs} +7 -7
  62. package/dist/cli/{chunk-YWC5AN26.mjs → chunk-2DVFQYPG.mjs} +62 -34
  63. package/dist/cli/{chunk-UWOY74RU.js → chunk-5DUP4ZUE.js} +21 -21
  64. package/dist/cli/{chunk-EACX7QXO.mjs → chunk-5QYZ4MEW.mjs} +2 -2
  65. package/dist/cli/{chunk-HEI3BWIV.mjs → chunk-5RLVCOKH.mjs} +1 -1
  66. package/dist/cli/{chunk-TIRSKEZH.mjs → chunk-5Y7LLRWO.mjs} +1 -1
  67. package/dist/cli/{chunk-IXWQOVNW.js → chunk-5YILTBF7.js} +87 -76
  68. package/dist/cli/{chunk-OHKKDPA5.js → chunk-7FTQKEZ6.js} +13 -13
  69. package/dist/cli/{chunk-TN2GW57M.mjs → chunk-A456YVDE.mjs} +1 -1
  70. package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
  71. package/dist/cli/{chunk-3XQIVEAT.js → chunk-BJL7RYQN.js} +3 -3
  72. package/dist/cli/{chunk-2AWYJXBX.js → chunk-BNB2RK4L.js} +5 -5
  73. package/dist/cli/{chunk-U7IJAGWB.js → chunk-BYEDI5PM.js} +7 -7
  74. package/dist/cli/{chunk-RLLEH2SP.js → chunk-C4GFBB52.js} +26 -26
  75. package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
  76. package/dist/cli/{chunk-UT4YMA2N.js → chunk-DFHS5XVZ.js} +5 -4
  77. package/dist/cli/{chunk-XZXIWPT3.mjs → chunk-F3G2HAUQ.mjs} +1 -1
  78. package/dist/cli/{chunk-C62NI2X6.js → chunk-FCAKAW6S.js} +5 -5
  79. package/dist/cli/{chunk-AF7MOUZP.mjs → chunk-FGPJXQEJ.mjs} +2 -2
  80. package/dist/cli/chunk-FSCOYTRV.js +42 -0
  81. package/dist/cli/{chunk-6GRZEYSG.js → chunk-GCEUOHJW.js} +7 -7
  82. package/dist/cli/{chunk-SD7QWZTV.mjs → chunk-INW22YP7.mjs} +1 -1
  83. package/dist/cli/{chunk-OWUZKXE7.mjs → chunk-J7EENGKJ.mjs} +1 -1
  84. package/dist/cli/{chunk-QIDDTIVZ.js → chunk-KPIVQFXZ.js} +322 -294
  85. package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
  86. package/dist/cli/{chunk-WYUCDLVR.mjs → chunk-MJ56FCYU.mjs} +2 -1
  87. package/dist/cli/{chunk-DBJ62RAO.js → chunk-NSPMJLYA.js} +3 -3
  88. package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
  89. package/dist/cli/{chunk-PU52JXKA.mjs → chunk-P6KGYOCM.mjs} +13 -4
  90. package/dist/cli/{chunk-VEVGM6B5.js → chunk-PCYZDTDC.js} +14 -14
  91. package/dist/cli/{chunk-NW4QJE54.js → chunk-PHWFY26F.js} +2 -2
  92. package/dist/cli/{chunk-LTZXLYKE.mjs → chunk-PKOFEHZL.mjs} +93 -17
  93. package/dist/cli/{chunk-7K5CWKKZ.mjs → chunk-PQHDZHZG.mjs} +2 -2
  94. package/dist/cli/{chunk-UKM74PAA.js → chunk-PTM3QRAT.js} +37 -37
  95. package/dist/cli/{chunk-YGN77QA5.mjs → chunk-PV7AYBKQ.mjs} +3 -3
  96. package/dist/cli/{chunk-4OEOM6GP.mjs → chunk-PYDHVRAF.mjs} +5 -5
  97. package/dist/cli/{chunk-FRD5WFT4.js → chunk-QD22TY33.js} +323 -247
  98. package/dist/cli/{chunk-5KNRQWHE.js → chunk-QEQ3KHVY.js} +3 -3
  99. package/dist/cli/{chunk-KGOC6HGI.js → chunk-S5EYODEG.js} +53 -53
  100. package/dist/cli/{chunk-FQK7BULS.js → chunk-S7OILDJH.js} +1 -1
  101. package/dist/cli/{chunk-TRLDJNVE.mjs → chunk-T3Q6BMVH.mjs} +1 -1
  102. package/dist/cli/{chunk-5K5CAND4.mjs → chunk-TBE2K5W4.mjs} +4 -4
  103. package/dist/cli/{chunk-YHA3EV3I.mjs → chunk-TE2QT2MX.mjs} +15 -4
  104. package/dist/cli/{chunk-ZOKM7DVA.js → chunk-TNHY3ATN.js} +8 -8
  105. package/dist/cli/{chunk-4OVHIWE7.mjs → chunk-U23L57VU.mjs} +2 -2
  106. package/dist/cli/{chunk-5GOG5ZGC.mjs → chunk-UEJLWUJ3.mjs} +2 -2
  107. package/dist/cli/{chunk-6NPWXE32.mjs → chunk-VJLL5XIP.mjs} +1 -1
  108. package/dist/cli/{chunk-WXRM3UC6.mjs → chunk-WCOJH4W4.mjs} +3 -3
  109. package/dist/cli/{chunk-4SFC2XUF.mjs → chunk-XAZWUW6I.mjs} +5 -5
  110. package/dist/cli/{chunk-ZM2YPJQJ.js → chunk-XK5DMLZE.js} +5 -1
  111. package/dist/cli/{chunk-LJ5747UC.mjs → chunk-XRDXNAAY.mjs} +5 -1
  112. package/dist/cli/{chunk-V7JCMBLU.mjs → chunk-YIKHNZ6B.mjs} +4 -4
  113. package/dist/cli/{chunk-M4PG7FGC.js → chunk-YS6JOYYS.js} +2 -2
  114. package/dist/cli/{chunk-DEXSQGXB.mjs → chunk-ZMRZ3BXG.mjs} +5 -5
  115. package/dist/cli/{chunk-CYWBAV5H.js → chunk-ZQI26KE4.js} +16 -16
  116. package/dist/cli/{csv-S3CHUKI6.js → csv-3PSMPZM5.js} +13 -13
  117. package/dist/cli/{csv-NLWVWD3H.mjs → csv-LFCT3WQ4.mjs} +4 -4
  118. package/dist/cli/{db-OGRPAEEM.mjs → db-HULKVAMU.mjs} +7 -7
  119. package/dist/cli/{db-WBSKMMOH.js → db-R7I2PPTV.js} +28 -28
  120. package/dist/cli/{describe-FAD3Z7LN.mjs → describe-D55V42LH.mjs} +21 -21
  121. package/dist/cli/describe-H47BLOEP.js +49 -0
  122. package/dist/cli/describe-core.d.mts +3 -3
  123. package/dist/cli/describe-core.d.ts +3 -3
  124. package/dist/cli/describe-core.js +4 -4
  125. package/dist/cli/describe-core.mjs +3 -3
  126. package/dist/cli/{executions-LYCL344R.mjs → executions-ICVVOYVG.mjs} +7 -7
  127. package/dist/cli/{executions-SOAZHCY4.js → executions-O37FN2SK.js} +9 -9
  128. package/dist/cli/{feedback-AVF6V7SV.mjs → feedback-3K3QPGCQ.mjs} +4 -4
  129. package/dist/cli/{feedback-OROUPUNJ.js → feedback-MAZQ7C6S.js} +8 -8
  130. package/dist/cli/{git-J5N5M57H.mjs → git-2MMD5KJS.mjs} +5 -5
  131. package/dist/cli/git-RQ2XLFYZ.js +25 -0
  132. package/dist/cli/index.js +142 -139
  133. package/dist/cli/index.mjs +45 -42
  134. package/dist/cli/{legacy-noops-QAQMZMEG.js → legacy-noops-2OX2Y3Y2.js} +8 -8
  135. package/dist/cli/{legacy-noops-ENRRM7BL.mjs → legacy-noops-VLSWJ6VE.mjs} +5 -5
  136. package/dist/cli/{monitors-CKQ65WRL.mjs → monitors-2NODQQWG.mjs} +8 -8
  137. package/dist/cli/{monitors-SFMQ5LFR.js → monitors-UCSV5FOR.js} +92 -92
  138. package/dist/cli/{org-3UNTDLT2.js → org-4YY73VTW.js} +73 -73
  139. package/dist/cli/{org-K4UIEU5P.mjs → org-W7AUQCDE.mjs} +7 -7
  140. package/dist/cli/{pages-NKZTGB4C.js → pages-FBZEUMXK.js} +18 -18
  141. package/dist/cli/{pages-6GPGBIAH.mjs → pages-ZRP7U5PO.mjs} +7 -7
  142. package/dist/cli/{play-BDEADESI.js → play-LFCTQJXA.js} +858 -632
  143. package/dist/cli/{play-62BEE7IX.mjs → play-XF2BSGTP.mjs} +372 -146
  144. package/dist/cli/{providers-SXGP44GH.js → providers-5456JNHP.js} +10 -10
  145. package/dist/cli/{providers-X3CUWMFP.mjs → providers-SICAPKGI.mjs} +7 -7
  146. package/dist/cli/{quickstart-XQ4426M4.js → quickstart-2KLLIPIU.js} +6 -6
  147. package/dist/cli/{quickstart-7LN22BKX.mjs → quickstart-IBVG6GX6.mjs} +4 -4
  148. package/dist/cli/{run-PBJ4ZJ4W.js → run-DNLDGJRC.js} +41 -41
  149. package/dist/cli/{run-XXSN3B5A.mjs → run-XPIZIQ7H.mjs} +26 -26
  150. package/dist/cli/search-2KQA65LH.js +32 -0
  151. package/dist/cli/{search-M75VMADD.mjs → search-PW22AEAL.mjs} +8 -8
  152. package/dist/cli/{search-output-F6HCFYEI.js → search-output-H6F6QMRF.js} +22 -16
  153. package/dist/cli/{search-output-NUQAKWDM.mjs → search-output-JFD53H2N.mjs} +14 -8
  154. package/dist/cli/{secrets-J2H6V33R.mjs → secrets-542CTZRZ.mjs} +7 -7
  155. package/dist/cli/{secrets-LRYY4QPE.js → secrets-LCCRRAN7.js} +16 -16
  156. package/dist/cli/{sessions-YPF62CZE.js → sessions-5FYDQE3N.js} +6 -6
  157. package/dist/cli/{sessions-IMT336UV.mjs → sessions-CALLS2XD.mjs} +5 -5
  158. package/dist/cli/{settings-PDWVQIGH.mjs → settings-GSKPHUEC.mjs} +12 -12
  159. package/dist/cli/{settings-35YYC5WA.js → settings-ORGKOBP6.js} +79 -79
  160. package/dist/cli/{setup-UR7GOR7H.js → setup-4BUWJKB6.js} +47 -47
  161. package/dist/cli/{setup-DG5DISSE.mjs → setup-V57GHVAF.mjs} +9 -9
  162. package/dist/cli/skills-KYZPPGSN.js +33 -0
  163. package/dist/cli/{skills-U6NJD5J7.mjs → skills-NGLCFQFT.mjs} +7 -7
  164. package/dist/cli/tools-AFYXUEMD.js +56 -0
  165. package/dist/cli/{tools-2HGEOELR.mjs → tools-G2YNCFNX.mjs} +19 -19
  166. package/dist/cli/{update-FRAYBAHK.mjs → update-IZ3Z5T5C.mjs} +9 -9
  167. package/dist/cli/update-T6JJ7A3K.js +33 -0
  168. package/dist/cli/{workflow-JKKLOMBX.js → workflow-7AHST2XV.js} +18 -18
  169. package/dist/cli/{workflow-DDKVTF36.mjs → workflow-L7ROQIM7.mjs} +8 -8
  170. package/dist/{client-DJ3r8VQJ.d.mts → client-BkbDHRIg.d.mts} +1 -1
  171. package/dist/{client-JPSNljtj.d.ts → client-D3hVHXjK.d.ts} +1 -1
  172. package/dist/{client-core-3SJlNsKU.d.mts → client-core-BZoSMKcY.d.mts} +30 -15
  173. package/dist/{client-core-rCoQ5Xz3.d.ts → client-core-DUdVqO_m.d.ts} +30 -15
  174. package/dist/{compiler-manifest-gkO9ZkVg.d.mts → compiler-manifest-BFTwq1HI.d.mts} +1 -1
  175. package/dist/{compiler-manifest-gkO9ZkVg.d.ts → compiler-manifest-BFTwq1HI.d.ts} +1 -1
  176. package/dist/{errors-Cc92LKH-.d.ts → errors-c3pMsylw.d.ts} +1 -1
  177. package/dist/{errors-CeCCOKSA.d.mts → errors-w31ybrQM.d.mts} +1 -1
  178. package/dist/{index-DJQKdV76.d.ts → index-CQ-15-QL.d.ts} +1 -1
  179. package/dist/{index-DsqWJL3Q.d.mts → index-DvNtxucX.d.mts} +1 -1
  180. package/dist/index.d.mts +7 -7
  181. package/dist/index.d.ts +7 -7
  182. package/dist/index.js +10 -10
  183. package/dist/index.mjs +7 -7
  184. package/dist/install-integrity.json +117 -116
  185. package/dist/plays/bundle-play-file.d.mts +3 -3
  186. package/dist/plays/bundle-play-file.d.ts +3 -3
  187. package/dist/plays/bundle-play-file.mjs +2 -2
  188. package/dist/plays/play-description.d.mts +2 -2
  189. package/dist/plays/play-description.d.ts +2 -2
  190. package/dist/plays/run-request.d.mts +2 -2
  191. package/dist/plays/run-request.d.ts +2 -2
  192. package/dist/plays/run-request.js +12 -2
  193. package/dist/plays/run-request.mjs +11 -1
  194. package/dist/release.d.mts +1 -1
  195. package/dist/release.d.ts +1 -1
  196. package/dist/release.js +2 -2
  197. package/dist/release.mjs +1 -1
  198. package/dist/server.d.mts +4 -4
  199. package/dist/server.d.ts +4 -4
  200. package/dist/server.js +6 -6
  201. package/dist/server.mjs +4 -4
  202. package/package.json +1 -1
  203. package/dist/cli/auth-L5CSV3UO.js +0 -43
  204. package/dist/cli/chunk-KA2LNIUP.js +0 -33
  205. package/dist/cli/describe-UIAYCHWW.js +0 -49
  206. package/dist/cli/git-ATMWC27D.js +0 -25
  207. package/dist/cli/search-IGHLRLBD.js +0 -32
  208. package/dist/cli/skills-4U5WC4MJ.js +0 -33
  209. package/dist/cli/tools-PYJTQVVS.js +0 -56
  210. package/dist/cli/update-344OTRFM.js +0 -33
@@ -1,3 +1,7 @@
1
+ import {
2
+ deleteDaytonaSandboxAndConfirmAbsence,
3
+ waitForDaytonaSandboxAbsence,
4
+ } from './daytona-sandbox-absence';
1
5
  import {
2
6
  Configuration,
3
7
  SandboxApi,
@@ -15,7 +19,6 @@ import {
15
19
  } from '@daytonaio/sdk';
16
20
  import axios, { type InternalAxiosRequestConfig } from 'axios';
17
21
  import { Readable } from 'node:stream';
18
- import { setTimeout as delay } from 'node:timers/promises';
19
22
  import type { DaytonaClientOptions } from '../../daytona-runtime-config';
20
23
  import type { CreateSandboxFromSnapshotParams } from '@daytonaio/sdk';
21
24
  import type { DaytonaDeleteRetryAuthorization } from './daytona-lifecycle';
@@ -88,11 +91,6 @@ const DAYTONA_SDK_ERROR_NAMES: ReadonlySet<string> = new Set([
88
91
  ]);
89
92
  const DAYTONA_PROVIDER_ERROR_CODE_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]{1,63}$/;
90
93
  const DAYTONA_PROVIDER_DETAIL_PATTERN = / \[provider [^\]]*\]/g;
91
- // A pass costs two provider calls and one fenced scheduler write, so a sandbox
92
- // stuck in transition must not repeat it every 100 ms for the whole phase.
93
- const DAYTONA_RETIREMENT_BACKOFF_INITIAL_MS = 100;
94
- const DAYTONA_RETIREMENT_BACKOFF_MAX_MS = 5_000;
95
-
96
94
  /** A provider state from Daytona's published enum, or `unrecognized`. */
97
95
  export function daytonaSandboxStateForLog(state: unknown): string | null {
98
96
  if (state === undefined || state === null) return null;
@@ -403,7 +401,16 @@ function createTransport(signal: () => AbortSignal | undefined) {
403
401
  return transport;
404
402
  }
405
403
 
406
- function deadline(timeoutMs: number, signal?: AbortSignal) {
404
+ function deadline(
405
+ timeoutMs: number,
406
+ signal?: AbortSignal,
407
+ absoluteDeadlineAtMs?: number,
408
+ ) {
409
+ const deadlineAtMs = Math.min(
410
+ Date.now() + timeoutMs,
411
+ absoluteDeadlineAtMs ?? Infinity,
412
+ );
413
+ timeoutMs = deadlineAtMs - Date.now();
407
414
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
408
415
  throw new Error('Daytona phase deadline must be positive.');
409
416
  const controller = new AbortController();
@@ -415,7 +422,6 @@ function deadline(timeoutMs: number, signal?: AbortSignal) {
415
422
  const combined = signal
416
423
  ? AbortSignal.any([controller.signal, signal])
417
424
  : controller.signal;
418
- const deadlineAtMs = Date.now() + timeoutMs;
419
425
  return {
420
426
  get signal() {
421
427
  if (Date.now() >= deadlineAtMs)
@@ -450,7 +456,8 @@ export function createDaytonaLaunchClient(
450
456
  },
451
457
  },
452
458
  });
453
- const dataBySandbox = new WeakMap<Sandbox, SandboxData>();
459
+ const dataBySandbox = new WeakMap<Pick<Sandbox, 'id'>, SandboxData>();
460
+ const resolvedDomains = new WeakMap<Pick<Sandbox, 'id'>, string>();
454
461
  const makeSandbox = (
455
462
  data: SandboxData,
456
463
  signal: () => AbortSignal | undefined,
@@ -536,6 +543,20 @@ export function createDaytonaLaunchClient(
536
543
  };
537
544
  const optionsTarget = options.target;
538
545
  return {
546
+ bindSandboxOrganization(sandbox: Sandbox, organizationId: string) {
547
+ const owned = dataBySandbox.get(sandbox);
548
+ if (
549
+ owned?.id !== sandbox.id ||
550
+ !organizationId.trim() ||
551
+ (owned.organizationId?.trim() &&
552
+ owned.organizationId.trim() !== organizationId.trim())
553
+ ) {
554
+ throw new Error(
555
+ 'Daytona organization binding contradicts its owned resource.',
556
+ );
557
+ }
558
+ resolvedDomains.set(sandbox, organizationId.trim());
559
+ },
539
560
  async create(
540
561
  params: CreateSandboxFromSnapshotParams,
541
562
  options: { timeout?: number } = {},
@@ -657,12 +678,30 @@ export function createDaytonaLaunchClient(
657
678
  async delete(
658
679
  sandbox: Pick<Sandbox, 'id'>,
659
680
  timeoutSeconds = 30,
660
- retry?: DaytonaDeleteRetryAuthorization,
681
+ retryOrDeadline?: DaytonaDeleteRetryAuthorization | number,
682
+ deadlineAtMs?: number,
661
683
  ) {
662
684
  // Cleanup must survive execution cancellation and must not trigger the
663
685
  // SDK's unawaited refreshDataSafe after a confirmed delete response.
664
- const phase = deadline(timeoutSeconds * 1_000);
665
- let absenceOnlyConflict: DaytonaConflictError | null = null;
686
+ const retry =
687
+ typeof retryOrDeadline === 'object' ? retryOrDeadline : undefined;
688
+ deadlineAtMs ??=
689
+ typeof retryOrDeadline === 'number' ? retryOrDeadline : undefined;
690
+ const timeoutMs = Math.min(
691
+ timeoutSeconds * 1_000,
692
+ deadlineAtMs === undefined ? Infinity : deadlineAtMs - Date.now(),
693
+ );
694
+ if (timeoutMs <= 0) throw new DaytonaControlTimeoutError();
695
+ const phase = deadline(timeoutMs, undefined, deadlineAtMs);
696
+ const owned = dataBySandbox.get(sandbox);
697
+ const organizationId =
698
+ resolvedDomains.get(sandbox) ?? owned?.organizationId?.trim();
699
+ if (owned?.id !== sandbox.id || !organizationId) {
700
+ phase.dispose();
701
+ throw new Error(
702
+ 'Daytona deletion requires this client’s exact owned sandbox and organization.',
703
+ );
704
+ }
666
705
  try {
667
706
  const api = new SandboxApi(
668
707
  new Configuration({
@@ -670,89 +709,55 @@ export function createDaytonaLaunchClient(
670
709
  baseOptions: { ...configuration.baseOptions, signal: phase.signal },
671
710
  }),
672
711
  );
673
- let backoffMs = DAYTONA_RETIREMENT_BACKOFF_INITIAL_MS;
674
- for (;;) {
675
- phase.signal.throwIfAborted();
676
- if (!absenceOnlyConflict) {
712
+ await deleteDaytonaSandboxAndConfirmAbsence({
713
+ sandboxId: owned.id,
714
+ organizationId,
715
+ retry,
716
+ signal: phase.signal,
717
+ assertWithinDeadline: () => phase.signal.throwIfAborted(),
718
+ delete: async () => {
677
719
  try {
678
- await api.deleteSandbox(sandbox.id);
679
- return;
680
- } catch (caught) {
681
- // The phase signal is the authoritative local deadline. Axios
682
- // reports its cancellation as ERR_CANCELED, which loses the
683
- // distinction between an ambiguous local timeout and a provider
684
- // rejection unless we preserve the signal's typed reason here.
720
+ await api.deleteSandbox(owned.id, undefined, {
721
+ timeout: timeoutMs,
722
+ });
723
+ } catch (error) {
685
724
  if (
686
725
  phase.signal.aborted &&
687
726
  phase.signal.reason instanceof DaytonaControlTimeoutError
688
727
  ) {
689
728
  throw phase.signal.reason;
690
729
  }
691
- const error = providerError(caught);
692
- // A prior accepted delete can already have removed this exact ID.
693
- if (retry && error instanceof DaytonaNotFoundError) return;
694
- if (
695
- !retry ||
696
- !(error instanceof DaytonaConflictError) ||
697
- error.statusCode !== 409
698
- )
699
- throw error;
730
+ throw providerError(error);
731
+ }
732
+ },
733
+ read: async () => {
734
+ try {
735
+ return (
736
+ await api.getSandbox(owned.id, undefined, undefined, {
737
+ signal: phase.signal,
738
+ })
739
+ ).data;
740
+ } catch (error) {
700
741
  if (
701
- error.message.trim() ===
702
- 'Sandbox was modified by another operation'
703
- ) {
704
- // This conflict does not authorize mutation replay. A concurrent
705
- // cleanup is deleting this exact ID, so only prove its absence.
706
- absenceOnlyConflict = error;
707
- } else if (
708
- !/^Sandbox state change in progress[.!]?$/i.test(
709
- error.message.trim(),
710
- )
742
+ phase.signal.aborted &&
743
+ phase.signal.reason instanceof DaytonaControlTimeoutError
711
744
  ) {
712
- throw error;
745
+ throw phase.signal.reason;
713
746
  }
747
+ throw providerError(error);
714
748
  }
715
- }
716
- // Give the in-progress transition (including durable cleanup) its
717
- // backoff before observing absence, so a closed resource need not
718
- // be re-reported just to learn that deletion succeeded.
719
- await delay(backoffMs, undefined, { signal: phase.signal });
720
- backoffMs = Math.min(
721
- backoffMs * 2,
722
- DAYTONA_RETIREMENT_BACKOFF_MAX_MS,
723
- );
724
- // Reconcile only the acquired ID. Never resolve a name, start it, or
725
- // infer absence from a failed/ambiguous provider read.
726
- try {
727
- await api.getSandbox(sandbox.id, undefined, undefined, {
728
- signal: phase.signal,
729
- });
730
- } catch (caught) {
731
- const error = providerError(caught);
732
- if (error instanceof DaytonaNotFoundError) return;
733
- throw error;
734
- }
735
- if (absenceOnlyConflict) continue;
736
- // Authorization and every provider call share this ONE phase budget.
737
- // A delayed ACK after expiry must never authorize another DELETE.
738
- const signal = phase.signal;
739
- signal.throwIfAborted();
740
- await new Promise<void>((resolve, reject) => {
741
- const abort = () => reject(signal.reason);
742
- signal.addEventListener('abort', abort, { once: true });
743
- Promise.resolve()
744
- // Only managed callers get here: the DELETE branch rethrows
745
- // every failure when retry is absent.
746
- .then(retry!.authorizeRetry)
747
- .then(resolve, reject)
748
- .finally(() => signal.removeEventListener('abort', abort));
749
- });
750
- phase.signal.throwIfAborted();
751
- }
749
+ },
750
+ });
752
751
  } catch (error) {
753
752
  // Absence never arrived, so the provider's conflict is the real cause.
754
- if (absenceOnlyConflict && phase.signal.aborted)
755
- throw absenceOnlyConflict;
753
+ if (
754
+ phase.signal.aborted &&
755
+ error instanceof DaytonaConflictError &&
756
+ error.statusCode === 409 &&
757
+ error.message.trim() === 'Sandbox was modified by another operation'
758
+ ) {
759
+ throw error;
760
+ }
756
761
  if (
757
762
  phase.signal.aborted &&
758
763
  phase.signal.reason instanceof DaytonaControlTimeoutError
@@ -764,6 +769,52 @@ export function createDaytonaLaunchClient(
764
769
  phase.dispose();
765
770
  }
766
771
  },
772
+ async confirmAbsent(
773
+ sandbox: Sandbox,
774
+ organizationId: string,
775
+ timeoutMs: number,
776
+ signal?: AbortSignal,
777
+ deadlineAtMs?: number,
778
+ ) {
779
+ const owned = dataBySandbox.get(sandbox);
780
+ if (
781
+ owned?.id !== sandbox.id ||
782
+ (resolvedDomains.get(sandbox) ?? owned.organizationId?.trim()) !==
783
+ organizationId.trim()
784
+ ) {
785
+ throw new Error(
786
+ 'Daytona absence join requires this client’s exact owned sandbox and organization.',
787
+ );
788
+ }
789
+ const phase = deadline(timeoutMs, signal, deadlineAtMs);
790
+ const api = new SandboxApi(
791
+ new Configuration({
792
+ basePath: configuration.basePath,
793
+ baseOptions: { ...configuration.baseOptions, signal: phase.signal },
794
+ }),
795
+ );
796
+ try {
797
+ await waitForDaytonaSandboxAbsence({
798
+ sandboxId: owned.id,
799
+ organizationId: organizationId.trim(),
800
+ signal: phase.signal,
801
+ assertWithinDeadline: () => phase.signal.throwIfAborted(),
802
+ read: async () => {
803
+ try {
804
+ return (
805
+ await api.getSandbox(owned.id, undefined, undefined, {
806
+ signal: phase.signal,
807
+ })
808
+ ).data;
809
+ } catch (error) {
810
+ throw providerError(error);
811
+ }
812
+ },
813
+ });
814
+ } finally {
815
+ phase.dispose();
816
+ }
817
+ },
767
818
  scope(sandbox: Sandbox, timeoutMs: number) {
768
819
  const data = dataBySandbox.get(sandbox);
769
820
  if (!data)
@@ -23,7 +23,8 @@ import {
23
23
  playSandboxSizeForLimits,
24
24
  validatePlaySandboxRuntimeLimits,
25
25
  } from '../../../plays/sandbox-runtime-limits';
26
- import type { PlaySandboxSize } from '../../../plays/sandbox-runtime-limits';
26
+ import { DAYTONA_SNAPSHOT_BY_PLAY_SANDBOX_SIZE } from '../../daytona-runtime-config';
27
+ export { DAYTONA_SNAPSHOT_BY_PLAY_SANDBOX_SIZE } from '../../daytona-runtime-config';
27
28
  import type {
28
29
  PlayRunnerDaytonaCleanupIntent,
29
30
  PlayRunnerRuntimeLifecycleEvent,
@@ -67,15 +68,6 @@ const DAYTONA_ABSENT_OPERATION_RECREATE_AFTER_MS = 3 * 60_000;
67
68
  // inactivity stop is a wider crash backstop measured from sandbox creation, so
68
69
  // setup time cannot consume the terminal-flush grace.
69
70
  const DAYTONA_AUTO_ARCHIVE_INTERVAL_MINUTES = 15;
70
- // Daytona snapshots carry fixed resource allocations. The API rejects resource
71
- // fields on snapshot creates, so select the provider snapshot that matches each
72
- // Deepline profile instead of trying to resize after creation.
73
- export const DAYTONA_SNAPSHOT_BY_PLAY_SANDBOX_SIZE = {
74
- standard: 'daytona-small',
75
- large: 'daytona-medium',
76
- xlarge: 'daytona-large',
77
- } as const satisfies Record<PlaySandboxSize, string>;
78
-
79
71
  export const DAYTONA_SANDBOX_CPU = STANDARD_PLAY_SANDBOX_RUNTIME_LIMITS.cpu;
80
72
  export const DAYTONA_SANDBOX_MEMORY_GIB =
81
73
  STANDARD_PLAY_SANDBOX_RUNTIME_LIMITS.memoryGiB;
@@ -100,7 +92,16 @@ export type DaytonaClient = {
100
92
  delete(
101
93
  sandbox: Pick<Sandbox, 'id'>,
102
94
  timeoutSeconds?: number,
103
- retry?: DaytonaDeleteRetryAuthorization,
95
+ retryOrDeadline?: DaytonaDeleteRetryAuthorization | number,
96
+ deadlineAtMs?: number,
97
+ ): Promise<void>;
98
+ bindSandboxOrganization?(sandbox: Sandbox, organizationId: string): void;
99
+ confirmAbsent?(
100
+ sandbox: Sandbox,
101
+ organizationId: string,
102
+ timeoutMs: number,
103
+ signal?: AbortSignal,
104
+ deadlineAtMs?: number,
104
105
  ): Promise<void>;
105
106
  scope(
106
107
  sandbox: Sandbox,
@@ -121,7 +122,16 @@ type DaytonaCreateCallObserver = (
121
122
 
122
123
  export type AcquiredDaytonaSandbox = {
123
124
  sandbox: DaytonaSandbox;
124
- deleteSandbox: (retry?: DaytonaDeleteRetryAuthorization) => Promise<void>;
125
+ deleteSandbox: (
126
+ timeoutSeconds?: number,
127
+ deadlineAtMs?: number,
128
+ retry?: DaytonaDeleteRetryAuthorization,
129
+ ) => Promise<void>;
130
+ confirmAbsent?: (
131
+ timeoutMs: number,
132
+ signal?: AbortSignal,
133
+ deadlineAtMs?: number,
134
+ ) => Promise<void>;
125
135
  daytonaOrganizationId: string;
126
136
  billingStartedAt: number;
127
137
  billingEndedAt?: number;
@@ -1307,6 +1317,10 @@ async function acquireOneShotDaytonaSandbox(input: {
1307
1317
  confirmDeleted,
1308
1318
  );
1309
1319
  }
1320
+ input.daytona.bindSandboxOrganization?.(
1321
+ result.sandbox,
1322
+ daytonaOrganizationId,
1323
+ );
1310
1324
  const billingStartedAt = Date.now();
1311
1325
  const sandbox = result.sandbox;
1312
1326
  input.emitStage('create:done', {
@@ -1325,7 +1339,32 @@ async function acquireOneShotDaytonaSandbox(input: {
1325
1339
  });
1326
1340
  return {
1327
1341
  sandbox,
1328
- deleteSandbox: (retry) => input.daytona.delete(sandbox, 30, retry),
1342
+ deleteSandbox: (
1343
+ timeoutSeconds = 30,
1344
+ deadlineAtMs?: number,
1345
+ retry?: DaytonaDeleteRetryAuthorization,
1346
+ ) =>
1347
+ retry
1348
+ ? input.daytona.delete(sandbox, timeoutSeconds, retry, deadlineAtMs)
1349
+ : deadlineAtMs === undefined
1350
+ ? input.daytona.delete(sandbox, timeoutSeconds)
1351
+ : input.daytona.delete(sandbox, timeoutSeconds, deadlineAtMs),
1352
+ ...(input.daytona.confirmAbsent
1353
+ ? {
1354
+ confirmAbsent: (
1355
+ timeoutMs: number,
1356
+ signal?: AbortSignal,
1357
+ deadlineAtMs?: number,
1358
+ ) =>
1359
+ input.daytona.confirmAbsent!(
1360
+ sandbox,
1361
+ daytonaOrganizationId,
1362
+ timeoutMs,
1363
+ signal,
1364
+ deadlineAtMs,
1365
+ ),
1366
+ }
1367
+ : {}),
1329
1368
  daytonaOrganizationId,
1330
1369
  billingStartedAt,
1331
1370
  ...(result.sandboxCapacityLeaseId
@@ -1444,7 +1483,10 @@ export function createOneShotDaytonaSandboxLifecycle(input: {
1444
1483
  * worker's wake leg owns that delete.
1445
1484
  */
1446
1485
  export function createDaytonaSandboxCleanupManager(): {
1447
- activate(acquired: AcquiredDaytonaSandbox): void;
1486
+ activate(
1487
+ acquired: AcquiredDaytonaSandbox,
1488
+ retire?: () => Promise<void>,
1489
+ ): void;
1448
1490
  currentSandbox(): DaytonaSandbox | null;
1449
1491
  cleanupActiveSandboxForCancellation(): boolean;
1450
1492
  stashActiveSandboxForRetry(): Promise<void>;
@@ -1493,9 +1535,9 @@ export function createDaytonaSandboxCleanupManager(): {
1493
1535
  };
1494
1536
 
1495
1537
  return {
1496
- activate(acquired) {
1538
+ activate(acquired, retire) {
1497
1539
  sandbox = acquired.sandbox;
1498
- deleteActive = acquired.deleteSandbox;
1540
+ deleteActive = retire ?? acquired.deleteSandbox;
1499
1541
  retirement = null;
1500
1542
  sandboxBillingStartedAt = acquired.billingStartedAt;
1501
1543
  },
@@ -0,0 +1,171 @@
1
+ import { setTimeout as sleep } from 'node:timers/promises';
2
+ import type { DaytonaDeleteRetryAuthorization } from './daytona-lifecycle';
3
+
4
+ export function daytonaResponseStatus(error: unknown): number | null {
5
+ const value = error as {
6
+ statusCode?: number;
7
+ response?: { status?: number };
8
+ } | null;
9
+ return value?.statusCode ?? value?.response?.status ?? null;
10
+ }
11
+
12
+ /** An accepted DELETE is not absence. Only this exact scoped lookup can prove it. */
13
+ export async function waitForDaytonaSandboxAbsence(input: {
14
+ sandboxId: string;
15
+ organizationId: string;
16
+ read: () => Promise<{ id: string; organizationId?: string }>;
17
+ signal: AbortSignal;
18
+ assertWithinDeadline: () => void;
19
+ unresolvedConflict?: unknown;
20
+ }): Promise<void> {
21
+ if (!input.sandboxId.trim() || !input.organizationId.trim()) {
22
+ throw new Error(
23
+ 'Daytona absence confirmation requires exact sandbox and organization identity.',
24
+ );
25
+ }
26
+ for (;;) {
27
+ input.assertWithinDeadline();
28
+ input.signal.throwIfAborted();
29
+ let observed;
30
+ try {
31
+ observed = await input.read();
32
+ } catch (error) {
33
+ input.assertWithinDeadline();
34
+ input.signal.throwIfAborted();
35
+ if (daytonaResponseStatus(error) === 404) return;
36
+ throw error;
37
+ }
38
+ input.assertWithinDeadline();
39
+ input.signal.throwIfAborted();
40
+ if (
41
+ observed.id !== input.sandboxId ||
42
+ observed.organizationId?.trim() !== input.organizationId
43
+ ) {
44
+ throw new Error(
45
+ 'Daytona absence confirmation returned a different sandbox or organization.',
46
+ );
47
+ }
48
+ // A conflict remains a provider failure unless the exact lookup proves absence.
49
+ if (input.unresolvedConflict) throw input.unresolvedConflict;
50
+ // A visible record, including destroying/destroyed, is not an absence proof.
51
+ await sleep(100, undefined, { signal: input.signal });
52
+ }
53
+ }
54
+
55
+ export function isDaytonaDeleteAlreadyInProgress(error: unknown): boolean {
56
+ const status = daytonaResponseStatus(error);
57
+ const body = (error as { response?: { data?: { message?: unknown } } } | null)
58
+ ?.response?.data;
59
+ const message =
60
+ typeof body?.message === 'string'
61
+ ? body.message
62
+ : error instanceof Error
63
+ ? error.message
64
+ : '';
65
+ return (
66
+ status === 404 ||
67
+ (status === 409 && message.trim() === 'Sandbox state change in progress')
68
+ );
69
+ }
70
+
71
+ /** One owned retirement policy shared by launch and durable control cleanup. */
72
+ export async function deleteDaytonaSandboxAndConfirmAbsence(input: {
73
+ sandboxId: string;
74
+ organizationId: string;
75
+ delete: () => Promise<unknown>;
76
+ read: () => Promise<{ id: string; organizationId?: string }>;
77
+ signal: AbortSignal;
78
+ assertWithinDeadline: () => void;
79
+ retry?: DaytonaDeleteRetryAuthorization;
80
+ }): Promise<void> {
81
+ const check = () => {
82
+ input.assertWithinDeadline();
83
+ input.signal.throwIfAborted();
84
+ };
85
+ const confirmAbsent = (unresolvedConflict?: unknown) =>
86
+ waitForDaytonaSandboxAbsence({ ...input, unresolvedConflict });
87
+ let absenceOnlyConflict: unknown;
88
+ // Existing retirement backoff: each mutating pass costs provider calls and
89
+ // a durable ownership proof, so a stuck transition must not hot-loop writes.
90
+ let backoffMs = 100;
91
+ try {
92
+ for (;;) {
93
+ check();
94
+ if (!absenceOnlyConflict) {
95
+ let accepted = false;
96
+ try {
97
+ await input.delete();
98
+ accepted = true;
99
+ } catch (error) {
100
+ const status = daytonaResponseStatus(error);
101
+ if (
102
+ status === 404 ||
103
+ (!input.retry && isDaytonaDeleteAlreadyInProgress(error))
104
+ ) {
105
+ await confirmAbsent(error);
106
+ return;
107
+ }
108
+ if (!input.retry || status !== 409) throw error;
109
+ const message = daytonaResponseMessage(error).trim();
110
+ if (message === 'Sandbox was modified by another operation')
111
+ absenceOnlyConflict = error;
112
+ else if (!/^Sandbox state change in progress[.!]?$/i.test(message))
113
+ throw error;
114
+ }
115
+ // Read failures after acceptance are never DELETE retry authority.
116
+ if (accepted) {
117
+ await confirmAbsent();
118
+ return;
119
+ }
120
+ }
121
+ await sleep(backoffMs, undefined, { signal: input.signal });
122
+ backoffMs = Math.min(backoffMs * 2, 5_000);
123
+ check();
124
+ let observed;
125
+ try {
126
+ observed = await input.read();
127
+ } catch (error) {
128
+ check();
129
+ if (daytonaResponseStatus(error) === 404) return;
130
+ throw error;
131
+ }
132
+ check();
133
+ if (
134
+ observed.id !== input.sandboxId ||
135
+ observed.organizationId?.trim() !== input.organizationId
136
+ )
137
+ throw new Error(
138
+ 'Daytona absence confirmation returned a different sandbox or organization.',
139
+ );
140
+ if (absenceOnlyConflict) continue;
141
+ // Both the initiating attempt and cleanup claim must still authorize
142
+ // this exact resource. The caller owns that proof, never the provider.
143
+ const signal = input.signal;
144
+ await new Promise<void>((resolve, reject) => {
145
+ const abort = () => reject(signal.reason);
146
+ signal.addEventListener('abort', abort, { once: true });
147
+ Promise.resolve()
148
+ .then(() => {
149
+ check();
150
+ return input.retry!.authorizeRetry();
151
+ })
152
+ .then(resolve, reject)
153
+ .finally(() => signal.removeEventListener('abort', abort));
154
+ });
155
+ check();
156
+ }
157
+ } catch (error) {
158
+ if (absenceOnlyConflict && input.signal.aborted) throw absenceOnlyConflict;
159
+ throw error;
160
+ }
161
+ }
162
+
163
+ function daytonaResponseMessage(error: unknown): string {
164
+ const body = (error as { response?: { data?: { message?: unknown } } } | null)
165
+ ?.response?.data;
166
+ return typeof body?.message === 'string'
167
+ ? body.message
168
+ : error instanceof Error
169
+ ? error.message
170
+ : '';
171
+ }
@@ -44,6 +44,75 @@ export type DetachedDaytonaStartupDiagnostic = {
44
44
  errors: string[];
45
45
  };
46
46
 
47
+ /** A fixed, non-secret projection; never log the diagnostic object wholesale. */
48
+ export function detachedDaytonaStartupDiagnosticForLog(
49
+ diagnostic: DetachedDaytonaStartupDiagnostic,
50
+ ) {
51
+ const count = (value: number | null | undefined): number | null =>
52
+ typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
53
+ ? value
54
+ : null;
55
+ const exitCode = (value: number | null): number | null =>
56
+ count(value) !== null && value! <= 255 ? value : null;
57
+ const startup = diagnostic.runnerStartup;
58
+ const phase = (['booted', 'heartbeat_transport'] as const).find(
59
+ (value) => value === startup?.phase,
60
+ );
61
+ const outcome = (
62
+ [
63
+ 'ok',
64
+ 'terminal',
65
+ 'redirect',
66
+ 'gateway_4xx',
67
+ 'gateway_5xx',
68
+ 'protocol_error',
69
+ 'timeout',
70
+ 'network_error',
71
+ ] as const
72
+ ).find((value) => value === startup?.outcome);
73
+ const allowedErrors = [
74
+ 'get_session_command_failed',
75
+ 'get_session_failed',
76
+ 'exit_code_file_unavailable',
77
+ 'startup_diagnostic_invalid',
78
+ 'startup_diagnostic_unavailable',
79
+ 'process_snapshot_failed',
80
+ ] as const;
81
+ const status = startup?.status;
82
+ return {
83
+ schedulerReadinessObserved: diagnostic.schedulerReadinessObserved,
84
+ schedulerReadinessResponses: count(diagnostic.schedulerReadinessResponses),
85
+ commandFound: diagnostic.commandFound,
86
+ exitCode: exitCode(diagnostic.exitCode),
87
+ sessionFound: diagnostic.sessionFound,
88
+ sessionCommandCount: count(diagnostic.sessionCommandCount),
89
+ exitCodeFile: exitCode(diagnostic.exitCodeFile),
90
+ processSummary: diagnostic.processSummary
91
+ ? {
92
+ total: count(diagnostic.processSummary.total),
93
+ node: count(diagnostic.processSummary.node),
94
+ }
95
+ : null,
96
+ runnerStartup: phase
97
+ ? {
98
+ phase,
99
+ outcome: outcome ?? null,
100
+ status:
101
+ typeof status === 'number' &&
102
+ Number.isSafeInteger(status) &&
103
+ status >= 100 &&
104
+ status <= 599
105
+ ? status
106
+ : null,
107
+ }
108
+ : null,
109
+ errors: allowedErrors.filter((value) => diagnostic.errors.includes(value)),
110
+ unrecognizedErrorCount: diagnostic.errors.filter(
111
+ (value) => !allowedErrors.some((allowed) => allowed === value),
112
+ ).length,
113
+ };
114
+ }
115
+
47
116
  function parseRunnerStartupDiagnostic(
48
117
  value: Buffer,
49
118
  ): DetachedDaytonaStartupDiagnostic['runnerStartup'] {