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.
- package/dist/bundling-sources/sdk/src/client-core.ts +91 -30
- package/dist/bundling-sources/sdk/src/compat.ts +13 -0
- package/dist/bundling-sources/sdk/src/plays/client-core.ts +4 -1
- package/dist/bundling-sources/sdk/src/plays/run-request.ts +143 -9
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +31 -4
- package/dist/bundling-sources/sdk/src/tool-calls.ts +1 -1
- package/dist/bundling-sources/sdk/src/types.ts +7 -1
- package/dist/bundling-sources/shared_libs/play-data-plane/sheet-column-storage.ts +32 -3
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +126 -41
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +231 -25
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +130 -19
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-registry.ts +105 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execute-server-timing.ts +4 -2
- package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +194 -56
- package/dist/bundling-sources/shared_libs/play-runtime/ledger-safe-payload.ts +8 -4
- package/dist/bundling-sources/shared_libs/play-runtime/log-provenance.ts +11 -6
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +30 -0
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +195 -2
- package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +20 -1
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +139 -67
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/progress-sidecar.ts +9 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +25 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +133 -82
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +58 -16
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-sandbox-absence.ts +171 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +69 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +100 -40
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +8 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -9
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +5 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +6 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +14 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-writer.ts +87 -31
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +19 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +14 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +206 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +12 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +28 -9
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +44 -15
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +60 -11
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +656 -64
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +6 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +17 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +25 -33
- package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +12 -0
- package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +21 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +1 -1
- package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +1 -1
- package/dist/cli/auth-ARKH3OAU.js +43 -0
- package/dist/cli/{auth-EBFOTF7X.mjs → auth-B4DJO4FB.mjs} +5 -5
- package/dist/cli/{billing-G2G3EF3I.js → billing-GDWAMARK.js} +80 -80
- package/dist/cli/{billing-2ZOIMW5V.mjs → billing-IIQ3VNXU.mjs} +7 -7
- package/dist/cli/{chunk-YWC5AN26.mjs → chunk-2DVFQYPG.mjs} +62 -34
- package/dist/cli/{chunk-UWOY74RU.js → chunk-5DUP4ZUE.js} +21 -21
- package/dist/cli/{chunk-EACX7QXO.mjs → chunk-5QYZ4MEW.mjs} +2 -2
- package/dist/cli/{chunk-HEI3BWIV.mjs → chunk-5RLVCOKH.mjs} +1 -1
- package/dist/cli/{chunk-TIRSKEZH.mjs → chunk-5Y7LLRWO.mjs} +1 -1
- package/dist/cli/{chunk-IXWQOVNW.js → chunk-5YILTBF7.js} +87 -76
- package/dist/cli/{chunk-OHKKDPA5.js → chunk-7FTQKEZ6.js} +13 -13
- package/dist/cli/{chunk-TN2GW57M.mjs → chunk-A456YVDE.mjs} +1 -1
- package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
- package/dist/cli/{chunk-3XQIVEAT.js → chunk-BJL7RYQN.js} +3 -3
- package/dist/cli/{chunk-2AWYJXBX.js → chunk-BNB2RK4L.js} +5 -5
- package/dist/cli/{chunk-U7IJAGWB.js → chunk-BYEDI5PM.js} +7 -7
- package/dist/cli/{chunk-RLLEH2SP.js → chunk-C4GFBB52.js} +26 -26
- package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
- package/dist/cli/{chunk-UT4YMA2N.js → chunk-DFHS5XVZ.js} +5 -4
- package/dist/cli/{chunk-XZXIWPT3.mjs → chunk-F3G2HAUQ.mjs} +1 -1
- package/dist/cli/{chunk-C62NI2X6.js → chunk-FCAKAW6S.js} +5 -5
- package/dist/cli/{chunk-AF7MOUZP.mjs → chunk-FGPJXQEJ.mjs} +2 -2
- package/dist/cli/chunk-FSCOYTRV.js +42 -0
- package/dist/cli/{chunk-6GRZEYSG.js → chunk-GCEUOHJW.js} +7 -7
- package/dist/cli/{chunk-SD7QWZTV.mjs → chunk-INW22YP7.mjs} +1 -1
- package/dist/cli/{chunk-OWUZKXE7.mjs → chunk-J7EENGKJ.mjs} +1 -1
- package/dist/cli/{chunk-QIDDTIVZ.js → chunk-KPIVQFXZ.js} +322 -294
- package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
- package/dist/cli/{chunk-WYUCDLVR.mjs → chunk-MJ56FCYU.mjs} +2 -1
- package/dist/cli/{chunk-DBJ62RAO.js → chunk-NSPMJLYA.js} +3 -3
- package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
- package/dist/cli/{chunk-PU52JXKA.mjs → chunk-P6KGYOCM.mjs} +13 -4
- package/dist/cli/{chunk-VEVGM6B5.js → chunk-PCYZDTDC.js} +14 -14
- package/dist/cli/{chunk-NW4QJE54.js → chunk-PHWFY26F.js} +2 -2
- package/dist/cli/{chunk-LTZXLYKE.mjs → chunk-PKOFEHZL.mjs} +93 -17
- package/dist/cli/{chunk-7K5CWKKZ.mjs → chunk-PQHDZHZG.mjs} +2 -2
- package/dist/cli/{chunk-UKM74PAA.js → chunk-PTM3QRAT.js} +37 -37
- package/dist/cli/{chunk-YGN77QA5.mjs → chunk-PV7AYBKQ.mjs} +3 -3
- package/dist/cli/{chunk-4OEOM6GP.mjs → chunk-PYDHVRAF.mjs} +5 -5
- package/dist/cli/{chunk-FRD5WFT4.js → chunk-QD22TY33.js} +323 -247
- package/dist/cli/{chunk-5KNRQWHE.js → chunk-QEQ3KHVY.js} +3 -3
- package/dist/cli/{chunk-KGOC6HGI.js → chunk-S5EYODEG.js} +53 -53
- package/dist/cli/{chunk-FQK7BULS.js → chunk-S7OILDJH.js} +1 -1
- package/dist/cli/{chunk-TRLDJNVE.mjs → chunk-T3Q6BMVH.mjs} +1 -1
- package/dist/cli/{chunk-5K5CAND4.mjs → chunk-TBE2K5W4.mjs} +4 -4
- package/dist/cli/{chunk-YHA3EV3I.mjs → chunk-TE2QT2MX.mjs} +15 -4
- package/dist/cli/{chunk-ZOKM7DVA.js → chunk-TNHY3ATN.js} +8 -8
- package/dist/cli/{chunk-4OVHIWE7.mjs → chunk-U23L57VU.mjs} +2 -2
- package/dist/cli/{chunk-5GOG5ZGC.mjs → chunk-UEJLWUJ3.mjs} +2 -2
- package/dist/cli/{chunk-6NPWXE32.mjs → chunk-VJLL5XIP.mjs} +1 -1
- package/dist/cli/{chunk-WXRM3UC6.mjs → chunk-WCOJH4W4.mjs} +3 -3
- package/dist/cli/{chunk-4SFC2XUF.mjs → chunk-XAZWUW6I.mjs} +5 -5
- package/dist/cli/{chunk-ZM2YPJQJ.js → chunk-XK5DMLZE.js} +5 -1
- package/dist/cli/{chunk-LJ5747UC.mjs → chunk-XRDXNAAY.mjs} +5 -1
- package/dist/cli/{chunk-V7JCMBLU.mjs → chunk-YIKHNZ6B.mjs} +4 -4
- package/dist/cli/{chunk-M4PG7FGC.js → chunk-YS6JOYYS.js} +2 -2
- package/dist/cli/{chunk-DEXSQGXB.mjs → chunk-ZMRZ3BXG.mjs} +5 -5
- package/dist/cli/{chunk-CYWBAV5H.js → chunk-ZQI26KE4.js} +16 -16
- package/dist/cli/{csv-S3CHUKI6.js → csv-3PSMPZM5.js} +13 -13
- package/dist/cli/{csv-NLWVWD3H.mjs → csv-LFCT3WQ4.mjs} +4 -4
- package/dist/cli/{db-OGRPAEEM.mjs → db-HULKVAMU.mjs} +7 -7
- package/dist/cli/{db-WBSKMMOH.js → db-R7I2PPTV.js} +28 -28
- package/dist/cli/{describe-FAD3Z7LN.mjs → describe-D55V42LH.mjs} +21 -21
- package/dist/cli/describe-H47BLOEP.js +49 -0
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/describe-core.js +4 -4
- package/dist/cli/describe-core.mjs +3 -3
- package/dist/cli/{executions-LYCL344R.mjs → executions-ICVVOYVG.mjs} +7 -7
- package/dist/cli/{executions-SOAZHCY4.js → executions-O37FN2SK.js} +9 -9
- package/dist/cli/{feedback-AVF6V7SV.mjs → feedback-3K3QPGCQ.mjs} +4 -4
- package/dist/cli/{feedback-OROUPUNJ.js → feedback-MAZQ7C6S.js} +8 -8
- package/dist/cli/{git-J5N5M57H.mjs → git-2MMD5KJS.mjs} +5 -5
- package/dist/cli/git-RQ2XLFYZ.js +25 -0
- package/dist/cli/index.js +142 -139
- package/dist/cli/index.mjs +45 -42
- package/dist/cli/{legacy-noops-QAQMZMEG.js → legacy-noops-2OX2Y3Y2.js} +8 -8
- package/dist/cli/{legacy-noops-ENRRM7BL.mjs → legacy-noops-VLSWJ6VE.mjs} +5 -5
- package/dist/cli/{monitors-CKQ65WRL.mjs → monitors-2NODQQWG.mjs} +8 -8
- package/dist/cli/{monitors-SFMQ5LFR.js → monitors-UCSV5FOR.js} +92 -92
- package/dist/cli/{org-3UNTDLT2.js → org-4YY73VTW.js} +73 -73
- package/dist/cli/{org-K4UIEU5P.mjs → org-W7AUQCDE.mjs} +7 -7
- package/dist/cli/{pages-NKZTGB4C.js → pages-FBZEUMXK.js} +18 -18
- package/dist/cli/{pages-6GPGBIAH.mjs → pages-ZRP7U5PO.mjs} +7 -7
- package/dist/cli/{play-BDEADESI.js → play-LFCTQJXA.js} +858 -632
- package/dist/cli/{play-62BEE7IX.mjs → play-XF2BSGTP.mjs} +372 -146
- package/dist/cli/{providers-SXGP44GH.js → providers-5456JNHP.js} +10 -10
- package/dist/cli/{providers-X3CUWMFP.mjs → providers-SICAPKGI.mjs} +7 -7
- package/dist/cli/{quickstart-XQ4426M4.js → quickstart-2KLLIPIU.js} +6 -6
- package/dist/cli/{quickstart-7LN22BKX.mjs → quickstart-IBVG6GX6.mjs} +4 -4
- package/dist/cli/{run-PBJ4ZJ4W.js → run-DNLDGJRC.js} +41 -41
- package/dist/cli/{run-XXSN3B5A.mjs → run-XPIZIQ7H.mjs} +26 -26
- package/dist/cli/search-2KQA65LH.js +32 -0
- package/dist/cli/{search-M75VMADD.mjs → search-PW22AEAL.mjs} +8 -8
- package/dist/cli/{search-output-F6HCFYEI.js → search-output-H6F6QMRF.js} +22 -16
- package/dist/cli/{search-output-NUQAKWDM.mjs → search-output-JFD53H2N.mjs} +14 -8
- package/dist/cli/{secrets-J2H6V33R.mjs → secrets-542CTZRZ.mjs} +7 -7
- package/dist/cli/{secrets-LRYY4QPE.js → secrets-LCCRRAN7.js} +16 -16
- package/dist/cli/{sessions-YPF62CZE.js → sessions-5FYDQE3N.js} +6 -6
- package/dist/cli/{sessions-IMT336UV.mjs → sessions-CALLS2XD.mjs} +5 -5
- package/dist/cli/{settings-PDWVQIGH.mjs → settings-GSKPHUEC.mjs} +12 -12
- package/dist/cli/{settings-35YYC5WA.js → settings-ORGKOBP6.js} +79 -79
- package/dist/cli/{setup-UR7GOR7H.js → setup-4BUWJKB6.js} +47 -47
- package/dist/cli/{setup-DG5DISSE.mjs → setup-V57GHVAF.mjs} +9 -9
- package/dist/cli/skills-KYZPPGSN.js +33 -0
- package/dist/cli/{skills-U6NJD5J7.mjs → skills-NGLCFQFT.mjs} +7 -7
- package/dist/cli/tools-AFYXUEMD.js +56 -0
- package/dist/cli/{tools-2HGEOELR.mjs → tools-G2YNCFNX.mjs} +19 -19
- package/dist/cli/{update-FRAYBAHK.mjs → update-IZ3Z5T5C.mjs} +9 -9
- package/dist/cli/update-T6JJ7A3K.js +33 -0
- package/dist/cli/{workflow-JKKLOMBX.js → workflow-7AHST2XV.js} +18 -18
- package/dist/cli/{workflow-DDKVTF36.mjs → workflow-L7ROQIM7.mjs} +8 -8
- package/dist/{client-DJ3r8VQJ.d.mts → client-BkbDHRIg.d.mts} +1 -1
- package/dist/{client-JPSNljtj.d.ts → client-D3hVHXjK.d.ts} +1 -1
- package/dist/{client-core-3SJlNsKU.d.mts → client-core-BZoSMKcY.d.mts} +30 -15
- package/dist/{client-core-rCoQ5Xz3.d.ts → client-core-DUdVqO_m.d.ts} +30 -15
- package/dist/{compiler-manifest-gkO9ZkVg.d.mts → compiler-manifest-BFTwq1HI.d.mts} +1 -1
- package/dist/{compiler-manifest-gkO9ZkVg.d.ts → compiler-manifest-BFTwq1HI.d.ts} +1 -1
- package/dist/{errors-Cc92LKH-.d.ts → errors-c3pMsylw.d.ts} +1 -1
- package/dist/{errors-CeCCOKSA.d.mts → errors-w31ybrQM.d.mts} +1 -1
- package/dist/{index-DJQKdV76.d.ts → index-CQ-15-QL.d.ts} +1 -1
- package/dist/{index-DsqWJL3Q.d.mts → index-DvNtxucX.d.mts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +10 -10
- package/dist/index.mjs +7 -7
- package/dist/install-integrity.json +117 -116
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- package/dist/plays/bundle-play-file.mjs +2 -2
- package/dist/plays/play-description.d.mts +2 -2
- package/dist/plays/play-description.d.ts +2 -2
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +2 -2
- package/dist/plays/run-request.js +12 -2
- package/dist/plays/run-request.mjs +11 -1
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +6 -6
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-L5CSV3UO.js +0 -43
- package/dist/cli/chunk-KA2LNIUP.js +0 -33
- package/dist/cli/describe-UIAYCHWW.js +0 -49
- package/dist/cli/git-ATMWC27D.js +0 -25
- package/dist/cli/search-IGHLRLBD.js +0 -32
- package/dist/cli/skills-4U5WC4MJ.js +0 -33
- package/dist/cli/tools-PYJTQVVS.js +0 -56
- 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(
|
|
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
|
-
|
|
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
|
|
665
|
-
|
|
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
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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(
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
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
|
-
|
|
702
|
-
|
|
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
|
|
745
|
+
throw phase.signal.reason;
|
|
713
746
|
}
|
|
747
|
+
throw providerError(error);
|
|
714
748
|
}
|
|
715
|
-
}
|
|
716
|
-
|
|
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 (
|
|
755
|
-
|
|
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)
|
package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts
CHANGED
|
@@ -23,7 +23,8 @@ import {
|
|
|
23
23
|
playSandboxSizeForLimits,
|
|
24
24
|
validatePlaySandboxRuntimeLimits,
|
|
25
25
|
} from '../../../plays/sandbox-runtime-limits';
|
|
26
|
-
import
|
|
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
|
-
|
|
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: (
|
|
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: (
|
|
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(
|
|
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'] {
|