deepline 0.3.492 → 0.3.493
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 +11 -5
- package/dist/bundling-sources/sdk/src/plays/run-request.ts +1 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/types.ts +6 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/verdict.ts +25 -9
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +36 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +5 -4
- package/dist/bundling-sources/shared_libs/play-runtime/crustdata-company-identify-batching.ts +162 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +19 -3
- package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-batching-registry.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-sql.ts +17 -23
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +28 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-placement-policy.ts +75 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +20 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +412 -59
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +38 -10
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +19 -11
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +165 -12
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-state-machine.ts +358 -0
- package/dist/cli/{auth-4I6QY5WX.mjs → auth-3NAY3AST.mjs} +5 -5
- package/dist/cli/auth-KYQLDI6V.js +43 -0
- package/dist/cli/{billing-2H4GOJZY.js → billing-FSB4BBBO.js} +80 -80
- package/dist/cli/{billing-4F6L4JSI.mjs → billing-SBWQCC7B.mjs} +7 -7
- package/dist/cli/{chunk-MQ2LQOAM.mjs → chunk-2BRTYIAH.mjs} +23 -9
- package/dist/cli/{chunk-E47VAVAR.js → chunk-2H4OFVR5.js} +5 -5
- package/dist/cli/{chunk-ZDTPSVGF.js → chunk-2I7VN65H.js} +10 -10
- package/dist/cli/{chunk-LCCFGSV7.mjs → chunk-2IHGVAGT.mjs} +2 -2
- package/dist/cli/{chunk-BDUFZSUL.js → chunk-2NGIBJM2.js} +8 -8
- package/dist/cli/{chunk-OTUT3XTX.mjs → chunk-3QGUWB6E.mjs} +4 -4
- package/dist/cli/{chunk-3BRDP4UP.mjs → chunk-4IJFQV3O.mjs} +1 -1
- package/dist/cli/{chunk-PIC6M4X3.mjs → chunk-4NIGNT7X.mjs} +1 -1
- package/dist/cli/{chunk-YVOYZPMY.mjs → chunk-5DIZ2G74.mjs} +2 -2
- package/dist/cli/{chunk-TKLDKIJU.mjs → chunk-5JPKRDFC.mjs} +7 -5
- package/dist/cli/{chunk-FTXIJTV2.mjs → chunk-5WOPBX3H.mjs} +1 -1
- package/dist/cli/{chunk-R5MP3CIY.mjs → chunk-67ZG7XZV.mjs} +3 -3
- package/dist/cli/{chunk-W4FEX5ZF.js → chunk-7HABWOMB.js} +261 -261
- package/dist/cli/{chunk-FPLN7PHP.js → chunk-AGTXL6LZ.js} +5 -5
- package/dist/cli/{chunk-SE23YSBK.js → chunk-AWMCZAUR.js} +3 -3
- package/dist/cli/{chunk-HHTVRICE.js → chunk-C2MRDPA5.js} +17 -17
- package/dist/cli/{chunk-ONONSV2Q.mjs → chunk-DVQHG6AM.mjs} +1 -0
- package/dist/cli/{chunk-O3K22ZC7.js → chunk-DWJ4RXSA.js} +34 -11
- package/dist/cli/{chunk-6YO4OJPM.mjs → chunk-DYP27IWC.mjs} +99 -24
- package/dist/cli/{chunk-EANFUHRM.mjs → chunk-E5ILCMKQ.mjs} +1 -1
- package/dist/cli/{chunk-Y7QCMOGZ.mjs → chunk-EBAS3UT2.mjs} +6 -6
- package/dist/cli/{chunk-DJOLMS2A.js → chunk-EFO5GVYS.js} +1 -1
- package/dist/cli/{chunk-NF7NUKWF.js → chunk-EYG336YV.js} +132 -57
- package/dist/cli/{chunk-OKHBAAJG.mjs → chunk-GSC35TPZ.mjs} +2 -2
- package/dist/cli/{chunk-MPITIXW4.mjs → chunk-HLM2UFQ5.mjs} +13 -5
- package/dist/cli/{chunk-TVUE4CPW.js → chunk-HTUSTPP4.js} +32 -32
- package/dist/cli/{chunk-GDSZWTJK.mjs → chunk-IJJ6D5WL.mjs} +12 -12
- package/dist/cli/{chunk-3TISK5RQ.js → chunk-IJOHWGPF.js} +6 -6
- package/dist/cli/{chunk-NBL6JMIY.js → chunk-IOBPR2VO.js} +17 -17
- package/dist/cli/{chunk-EFFHRXKB.js → chunk-IOMEJKGK.js} +2 -2
- package/dist/cli/{chunk-A7ZMG2QZ.mjs → chunk-IRDYBMA7.mjs} +34 -11
- package/dist/cli/{chunk-B2JE3HD6.js → chunk-JO2JZUBR.js} +3 -3
- package/dist/cli/{chunk-4IP5MLWU.js → chunk-JO5FFSR7.js} +6 -1
- package/dist/cli/{chunk-O2FB42N2.js → chunk-KCDZWS2B.js} +56 -56
- package/dist/cli/{chunk-CGDUFVNE.mjs → chunk-KGDDQMI7.mjs} +2 -2
- package/dist/cli/{chunk-UUH4GQRL.mjs → chunk-KKSKYZO4.mjs} +1 -1
- package/dist/cli/{chunk-OTDX4A4W.js → chunk-LGTZYI5B.js} +21 -21
- package/dist/cli/{chunk-JJAHWKJ2.js → chunk-MLEUOTEQ.js} +73 -59
- package/dist/cli/{chunk-YOCEY4EI.mjs → chunk-NALJJTPS.mjs} +5 -5
- package/dist/cli/{chunk-HFEJ7JJT.js → chunk-NPNAEPY4.js} +26 -26
- package/dist/cli/{chunk-3IBKEOL4.js → chunk-NWIDPT7H.js} +4 -4
- package/dist/cli/{chunk-AUQQVDAB.js → chunk-PKV5CD3W.js} +1 -0
- package/dist/cli/{chunk-4RB74KJX.js → chunk-QTPS5RLG.js} +15 -15
- package/dist/cli/{chunk-4OLXMJ2L.js → chunk-RLX5ZFNX.js} +8 -6
- package/dist/cli/{chunk-DEJIN4DF.mjs → chunk-SAW3FBCA.mjs} +5 -0
- package/dist/cli/{chunk-RC366IJS.mjs → chunk-SXD2EYAH.mjs} +6 -6
- package/dist/cli/{chunk-YNWET57Z.js → chunk-TIFRRLZT.js} +7 -7
- package/dist/cli/{chunk-ZCKUNXXR.mjs → chunk-TNQOR6XQ.mjs} +1 -1
- package/dist/cli/{chunk-OGNIB64W.js → chunk-UCMY2SO2.js} +23 -15
- package/dist/cli/{chunk-O65HDVA7.mjs → chunk-VFHIYWMC.mjs} +5 -5
- package/dist/cli/{chunk-JHBRJDUC.js → chunk-WCZFCOMZ.js} +7 -7
- package/dist/cli/{chunk-FFOJRD53.mjs → chunk-WTFI7BVH.mjs} +3 -3
- package/dist/cli/{chunk-42Z6VC2Q.js → chunk-XLE7KXE7.js} +2 -2
- package/dist/cli/{chunk-Q3CCCTRQ.js → chunk-XQX476QK.js} +14 -14
- package/dist/cli/{chunk-F6EQWY4E.mjs → chunk-Y3NN2UAF.mjs} +2 -2
- package/dist/cli/{chunk-MJFVF5AW.mjs → chunk-ZQH4TXM2.mjs} +2 -2
- package/dist/cli/{chunk-DVGCPOEA.mjs → chunk-ZVW7EWTC.mjs} +7 -7
- package/dist/cli/{chunk-4GJIJHRQ.mjs → chunk-ZVXB7OU7.mjs} +1 -1
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-JGJNDRSA.js → csv-DKYZE2KM.js} +13 -13
- package/dist/cli/{csv-VGXGV7YM.mjs → csv-XR22YQXT.mjs} +4 -4
- package/dist/cli/{db-OYG27ZBM.mjs → db-EOKG36YN.mjs} +7 -7
- package/dist/cli/{db-W52WJ6E5.js → db-RNYRTCMV.js} +28 -28
- package/dist/cli/describe-ICFXOQBW.mjs +50 -0
- package/dist/cli/describe-RS75I33X.js +50 -0
- package/dist/cli/describe-core.d.mts +2 -2
- package/dist/cli/describe-core.d.ts +2 -2
- package/dist/cli/describe-core.js +4 -4
- package/dist/cli/describe-core.mjs +3 -3
- package/dist/cli/{executions-EVE4KUGL.mjs → executions-3RAOACNS.mjs} +7 -7
- package/dist/cli/{executions-LAJHZGPY.js → executions-OBWPSWH7.js} +9 -9
- package/dist/cli/{feedback-75QB7KVG.mjs → feedback-6EQRVBKF.mjs} +4 -4
- package/dist/cli/{feedback-ZABCN7RT.js → feedback-6GPEUBLF.js} +8 -8
- package/dist/cli/getting-started.d.mts +12 -10
- package/dist/cli/getting-started.d.ts +12 -10
- package/dist/cli/getting-started.js +4 -2
- package/dist/cli/getting-started.mjs +3 -1
- package/dist/cli/{git-QIFEYQGY.mjs → git-CVQ24DTR.mjs} +5 -5
- package/dist/cli/git-DEFE4SSB.js +25 -0
- package/dist/cli/index.js +143 -143
- package/dist/cli/index.mjs +43 -43
- package/dist/cli/{legacy-noops-PNTWBBGY.mjs → legacy-noops-QULJZYNH.mjs} +5 -5
- package/dist/cli/{legacy-noops-2TBIAMCM.js → legacy-noops-XPOATG5V.js} +8 -8
- package/dist/cli/{monitors-LOHUYJEI.mjs → monitors-AFT5YJPZ.mjs} +49 -9
- package/dist/cli/{monitors-UKBOEGBS.js → monitors-OJ4CMREE.js} +169 -129
- package/dist/cli/{org-E7A6QLBW.js → org-RKT52CSL.js} +73 -73
- package/dist/cli/{org-JRUKUOUF.mjs → org-WHKNXANG.mjs} +7 -7
- package/dist/cli/{pages-K76HA473.mjs → pages-EEAQFGVD.mjs} +7 -7
- package/dist/cli/{pages-EUDFFLLD.js → pages-SOE3R667.js} +18 -18
- package/dist/cli/{play-DG2N66SV.mjs → play-LXFWHUBP.mjs} +147 -52
- package/dist/cli/{play-UWHNUJRA.js → play-OTJJ4E4T.js} +661 -566
- package/dist/cli/{providers-DZX6TTC6.js → providers-RU4HIAT3.js} +10 -10
- package/dist/cli/{providers-RUTTPUZD.mjs → providers-U3CPKTMM.mjs} +7 -7
- package/dist/cli/{quickstart-RGZZN2YE.mjs → quickstart-75AO2AJC.mjs} +5 -5
- package/dist/cli/{quickstart-U4NMD7KX.js → quickstart-N72IVA2Y.js} +13 -13
- package/dist/cli/{run-MOJWQYFQ.mjs → run-IGWFL6WH.mjs} +29 -28
- package/dist/cli/{run-5UNF4FHG.js → run-MMYES3IW.js} +44 -43
- package/dist/cli/search-EQURI7SZ.js +32 -0
- package/dist/cli/{search-5B3ZDU7H.mjs → search-FIYESBLZ.mjs} +8 -8
- package/dist/cli/{search-output-VQWJS3FN.js → search-output-2FXN4ZWD.js} +9 -6
- package/dist/cli/{search-output-QS4IWWHA.mjs → search-output-3I5KSW36.mjs} +7 -4
- package/dist/cli/{secrets-S3PJMEAC.js → secrets-HCZQ6JNP.js} +16 -16
- package/dist/cli/{secrets-V5XVDBIS.mjs → secrets-O7IUQ3VT.mjs} +7 -7
- package/dist/cli/{sessions-Y5QMEZ3D.js → sessions-5AYTT4IW.js} +6 -6
- package/dist/cli/{sessions-5V3X24XI.mjs → sessions-KY7A3EZO.mjs} +5 -5
- package/dist/cli/{settings-3U6RRO5F.js → settings-P4VFYWJK.js} +80 -80
- package/dist/cli/{settings-LHZYY5PT.mjs → settings-WSMRR2GS.mjs} +13 -13
- package/dist/cli/{setup-MLLIGO2S.js → setup-J7CA3EJL.js} +57 -57
- package/dist/cli/{setup-AJLWXYAN.mjs → setup-YTVKVQC7.mjs} +13 -13
- package/dist/cli/skills-KKPEGLAR.js +36 -0
- package/dist/cli/{skills-5O2MUWKK.mjs → skills-W5WY764N.mjs} +10 -10
- package/dist/cli/tools-65Y4QTW6.js +57 -0
- package/dist/cli/{tools-PWNMI5CD.mjs → tools-YECI6N3N.mjs} +20 -20
- package/dist/cli/{update-SXT4QW7S.mjs → update-BIFBIEII.mjs} +10 -10
- package/dist/cli/update-WDG7VFOW.js +34 -0
- package/dist/cli/{workflow-3WTF5IYT.js → workflow-D2TUFFH6.js} +18 -18
- package/dist/cli/{workflow-KPRM6ARO.mjs → workflow-XZVDNARC.mjs} +8 -8
- package/dist/{client-Cb1ej1Vr.d.ts → client-BDB_VbE4.d.ts} +1 -1
- package/dist/{client-vWpbLNCB.d.mts → client-CNzJ1LTF.d.mts} +1 -1
- package/dist/{client-core-CoBTvsXG.d.mts → client-core-CSv3DlPD.d.mts} +10 -3
- package/dist/{client-core-BmVs6SP0.d.ts → client-core-xEa9x3pl.d.ts} +10 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -10
- package/dist/index.mjs +7 -7
- package/dist/install-integrity.json +115 -114
- package/dist/plays/play-description.d.mts +1 -1
- package/dist/plays/play-description.d.ts +1 -1
- package/dist/plays/run-request.d.mts +1 -1
- package/dist/plays/run-request.d.ts +1 -1
- package/dist/plays/run-request.js +2 -2
- package/dist/plays/run-request.mjs +1 -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 +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +6 -6
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-7BCLZU6K.js +0 -43
- package/dist/cli/describe-FIXCRO5N.mjs +0 -50
- package/dist/cli/describe-G3O6OUBG.js +0 -50
- package/dist/cli/git-QBAR46NW.js +0 -25
- package/dist/cli/search-3DAEJL6S.js +0 -32
- package/dist/cli/skills-BBLIML5M.js +0 -36
- package/dist/cli/tools-X5SQXUMM.js +0 -57
- package/dist/cli/update-AEJ2ZSZQ.js +0 -34
|
@@ -12,6 +12,10 @@ import { RUNTIME_SANDBOX_CAPACITY_LIMIT_ERROR_NAME } from '../runner-backends/ty
|
|
|
12
12
|
import {
|
|
13
13
|
RuntimeSandboxOperationState,
|
|
14
14
|
RuntimeSandboxProvider,
|
|
15
|
+
runtimeSandboxOperationFromStates,
|
|
16
|
+
runtimeSandboxOperationFromStatesSqlCast,
|
|
17
|
+
runtimeSandboxOperationStateSqlType,
|
|
18
|
+
runtimeSandboxOperationTargetState,
|
|
15
19
|
} from './runtime-sandbox-operation';
|
|
16
20
|
import type { ComputeBillingJobStatus } from './compute-billing-job-state';
|
|
17
21
|
import { readComputeBillingJobStatus } from './compute-billing-job-state';
|
|
@@ -84,6 +88,17 @@ function schemaTables(options?: Pick<PostgresSchedulerOptions, 'schema'>) {
|
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
90
|
|
|
91
|
+
/** Every state write below takes its set and target from the owner's table. */
|
|
92
|
+
function operationStateSqlTypes(
|
|
93
|
+
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
94
|
+
): { operationState: string; operationStates: string } {
|
|
95
|
+
const schema = quoteIdent(options?.schema ?? 'runtime_scheduler');
|
|
96
|
+
return {
|
|
97
|
+
operationState: runtimeSandboxOperationStateSqlType(schema),
|
|
98
|
+
operationStates: runtimeSandboxOperationFromStatesSqlCast(schema),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
87
102
|
function assertId(value: string, name: string): string {
|
|
88
103
|
const normalized = value.trim();
|
|
89
104
|
if (!normalized || normalized.length > 256) {
|
|
@@ -315,6 +330,7 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
315
330
|
cleanup,
|
|
316
331
|
} = schemaTables(options);
|
|
317
332
|
const leaseId = input.leaseId?.trim() || randomUUID();
|
|
333
|
+
const { operationState } = operationStateSqlTypes(options);
|
|
318
334
|
const unsentProviderOperationToken = unsentReservationInputs.get(input);
|
|
319
335
|
const providerOperationToken =
|
|
320
336
|
input.attempt === undefined
|
|
@@ -464,7 +480,7 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
464
480
|
INSERT INTO ${operations} (
|
|
465
481
|
operation_key, provider_operation_token, provider, run_id, attempt, org_id, environment, state
|
|
466
482
|
)
|
|
467
|
-
SELECT lease_id, $12, $4, $3, $8, $1, $9, $
|
|
483
|
+
SELECT lease_id, $12, $4, $3, $8, $1, $9, $13::${operationState}
|
|
468
484
|
FROM reserved_lease
|
|
469
485
|
ON CONFLICT (operation_key) DO NOTHING
|
|
470
486
|
RETURNING operation_key, provider_operation_token, provider,
|
|
@@ -500,6 +516,7 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
500
516
|
input.mode ?? 'enforce',
|
|
501
517
|
RUNTIME_SANDBOX_CAPACITY_LEASE_MS,
|
|
502
518
|
providerOperationToken,
|
|
519
|
+
runtimeSandboxOperationTargetState('reserve'),
|
|
503
520
|
],
|
|
504
521
|
);
|
|
505
522
|
const limit = Number(
|
|
@@ -939,6 +956,7 @@ export async function abandonRuntimeSandboxOperationReservation(
|
|
|
939
956
|
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
940
957
|
): Promise<boolean> {
|
|
941
958
|
const { leases, operations, runs } = schemaTables(options);
|
|
959
|
+
const { operationStates } = operationStateSqlTypes(options);
|
|
942
960
|
const result = await client.query<{ operation_key: string }>(
|
|
943
961
|
`
|
|
944
962
|
WITH custody_run AS MATERIALIZED (
|
|
@@ -959,7 +977,7 @@ export async function abandonRuntimeSandboxOperationReservation(
|
|
|
959
977
|
SET state = $2,
|
|
960
978
|
updated_at = clock_timestamp()
|
|
961
979
|
WHERE operation.operation_key = $1
|
|
962
|
-
AND operation.state = $3
|
|
980
|
+
AND operation.state = ANY($3::${operationStates})
|
|
963
981
|
AND ($4::integer IS NULL OR operation.attempt <= $4)
|
|
964
982
|
AND EXISTS (SELECT 1 FROM eligible_lease)
|
|
965
983
|
AND (
|
|
@@ -981,8 +999,8 @@ export async function abandonRuntimeSandboxOperationReservation(
|
|
|
981
999
|
`,
|
|
982
1000
|
[
|
|
983
1001
|
assertId(input.operationKey, 'operationKey'),
|
|
984
|
-
|
|
985
|
-
|
|
1002
|
+
runtimeSandboxOperationTargetState('abandon_reservation'),
|
|
1003
|
+
runtimeSandboxOperationFromStates('abandon_reservation'),
|
|
986
1004
|
input.attempt ?? null,
|
|
987
1005
|
input.onlyWhileRunActive ?? false,
|
|
988
1006
|
],
|
|
@@ -1060,6 +1078,7 @@ export async function recordRecoveredDaytonaCancellationSandbox(
|
|
|
1060
1078
|
): Promise<boolean> {
|
|
1061
1079
|
const { operations, leases, cleanup } = schemaTables(options);
|
|
1062
1080
|
const schema = quoteIdent(options?.schema ?? 'runtime_scheduler');
|
|
1081
|
+
const { operationStates } = operationStateSqlTypes(options);
|
|
1063
1082
|
const recorded = await client.query<{ operation_key: string }>(
|
|
1064
1083
|
`WITH custody_run AS MATERIALIZED (
|
|
1065
1084
|
SELECT run.run_id FROM ${schema}."runs" AS run
|
|
@@ -1079,7 +1098,7 @@ export async function recordRecoveredDaytonaCancellationSandbox(
|
|
|
1079
1098
|
WHERE operation.operation_key = $1 FOR UPDATE OF operation
|
|
1080
1099
|
), promoted AS (
|
|
1081
1100
|
UPDATE ${operations} AS operation
|
|
1082
|
-
SET state =
|
|
1101
|
+
SET state = $4,
|
|
1083
1102
|
sandbox_id = $2,
|
|
1084
1103
|
routing_domain = $3,
|
|
1085
1104
|
provider_created_at = clock_timestamp(),
|
|
@@ -1087,7 +1106,7 @@ export async function recordRecoveredDaytonaCancellationSandbox(
|
|
|
1087
1106
|
FROM custody_operation
|
|
1088
1107
|
WHERE operation.operation_key = custody_operation.operation_key
|
|
1089
1108
|
AND operation.provider = 'daytona'
|
|
1090
|
-
AND operation.state =
|
|
1109
|
+
AND operation.state = ANY($5::${operationStates})
|
|
1091
1110
|
RETURNING operation.operation_key, operation.run_id, operation.attempt,
|
|
1092
1111
|
operation.environment, operation.created_at
|
|
1093
1112
|
), resource AS (
|
|
@@ -1134,7 +1153,13 @@ export async function recordRecoveredDaytonaCancellationSandbox(
|
|
|
1134
1153
|
SELECT promoted.operation_key FROM promoted
|
|
1135
1154
|
JOIN recorded_attempt ON recorded_attempt.run_id = promoted.run_id
|
|
1136
1155
|
JOIN bound ON bound.lease_id = promoted.operation_key`,
|
|
1137
|
-
[
|
|
1156
|
+
[
|
|
1157
|
+
input.operationKey,
|
|
1158
|
+
input.sandboxId,
|
|
1159
|
+
input.routingDomain,
|
|
1160
|
+
runtimeSandboxOperationTargetState('recover_daytona_cancellation'),
|
|
1161
|
+
runtimeSandboxOperationFromStates('recover_daytona_cancellation'),
|
|
1162
|
+
],
|
|
1138
1163
|
);
|
|
1139
1164
|
return recorded.rows.length === 1;
|
|
1140
1165
|
}
|
|
@@ -1153,6 +1178,7 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1153
1178
|
): Promise<boolean> {
|
|
1154
1179
|
const { operations, leases, cleanup } = schemaTables(options);
|
|
1155
1180
|
const schema = quoteIdent(options?.schema ?? 'runtime_scheduler');
|
|
1181
|
+
const { operationStates } = operationStateSqlTypes(options);
|
|
1156
1182
|
const recorded = await client.query<{ operation_key: string }>(
|
|
1157
1183
|
`WITH custody_run AS MATERIALIZED (
|
|
1158
1184
|
SELECT run.run_id FROM ${schema}."runs" AS run
|
|
@@ -1186,7 +1212,7 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1186
1212
|
AND operation.org_id = $3
|
|
1187
1213
|
AND operation.provider_operation_token = $4
|
|
1188
1214
|
AND operation.provider = 'daytona'
|
|
1189
|
-
AND operation.state =
|
|
1215
|
+
AND operation.state = ANY($8::${operationStates})
|
|
1190
1216
|
AND lease.released_at IS NULL
|
|
1191
1217
|
AND lease.sandbox_id IS NULL
|
|
1192
1218
|
), queued AS (
|
|
@@ -1207,7 +1233,7 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1207
1233
|
job.environment, job.routing_domain
|
|
1208
1234
|
), promoted AS (
|
|
1209
1235
|
UPDATE ${operations} AS operation
|
|
1210
|
-
SET state =
|
|
1236
|
+
SET state = $7,
|
|
1211
1237
|
sandbox_id = $5,
|
|
1212
1238
|
routing_domain = $6,
|
|
1213
1239
|
provider_created_at = clock_timestamp(),
|
|
@@ -1217,7 +1243,7 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1217
1243
|
AND queued.attempt = eligible.attempt
|
|
1218
1244
|
AND queued.environment = eligible.environment
|
|
1219
1245
|
WHERE operation.operation_key = eligible.operation_key
|
|
1220
|
-
AND operation.state =
|
|
1246
|
+
AND operation.state = ANY($8::${operationStates})
|
|
1221
1247
|
RETURNING operation.operation_key, operation.run_id, operation.attempt,
|
|
1222
1248
|
operation.environment, operation.created_at
|
|
1223
1249
|
), resource AS (
|
|
@@ -1293,6 +1319,8 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1293
1319
|
input.providerOperationToken,
|
|
1294
1320
|
input.sandboxId,
|
|
1295
1321
|
input.routingDomain,
|
|
1322
|
+
runtimeSandboxOperationTargetState('record_daytona_cleanup_intent'),
|
|
1323
|
+
runtimeSandboxOperationFromStates('record_daytona_cleanup_intent'),
|
|
1296
1324
|
],
|
|
1297
1325
|
);
|
|
1298
1326
|
return recorded.rows.length === 1;
|
|
@@ -5,6 +5,10 @@ import type {
|
|
|
5
5
|
import {
|
|
6
6
|
RuntimeSandboxOperationState,
|
|
7
7
|
RuntimeSandboxProvider,
|
|
8
|
+
runtimeSandboxOperationFromStates,
|
|
9
|
+
runtimeSandboxOperationFromStatesSqlCast,
|
|
10
|
+
runtimeSandboxOperationStateSqlType,
|
|
11
|
+
runtimeSandboxOperationTargetState,
|
|
8
12
|
} from './runtime-sandbox-operation';
|
|
9
13
|
|
|
10
14
|
const DAYTONA_PROVIDER = RuntimeSandboxProvider.Daytona;
|
|
@@ -473,6 +477,9 @@ export async function backfillRuntimeSandboxOperationsFromAttemptResources(
|
|
|
473
477
|
throw new Error('Invalid runtime sandbox operation backfill cursor.');
|
|
474
478
|
}
|
|
475
479
|
const { attempts, runs, operations } = tables(options);
|
|
480
|
+
const operationState = runtimeSandboxOperationStateSqlType(
|
|
481
|
+
quoteIdent(options?.schema ?? 'runtime_scheduler'),
|
|
482
|
+
);
|
|
476
483
|
const result = await client.query<{
|
|
477
484
|
run_id: string;
|
|
478
485
|
attempt: number;
|
|
@@ -532,7 +539,7 @@ export async function backfillRuntimeSandboxOperationsFromAttemptResources(
|
|
|
532
539
|
environment,
|
|
533
540
|
(resource::jsonb)->>'sandboxId',
|
|
534
541
|
routing_domain,
|
|
535
|
-
$6,
|
|
542
|
+
$6::${operationState},
|
|
536
543
|
updated_at
|
|
537
544
|
FROM ranked_resources
|
|
538
545
|
WHERE conflict_rank = 1
|
|
@@ -563,7 +570,7 @@ export async function backfillRuntimeSandboxOperationsFromAttemptResources(
|
|
|
563
570
|
cursor?.attempt ?? 0,
|
|
564
571
|
cursor?.resourceOrdinal ?? 0,
|
|
565
572
|
limit,
|
|
566
|
-
|
|
573
|
+
runtimeSandboxOperationTargetState('backfill_live'),
|
|
567
574
|
],
|
|
568
575
|
);
|
|
569
576
|
const last = result.rows[0] ?? null;
|
|
@@ -673,9 +680,10 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
|
|
|
673
680
|
throw new Error('minimumAgeMs must be a non-negative safe integer.');
|
|
674
681
|
}
|
|
675
682
|
const { operations, cleanup, cleanupEvents, leases } = tables(options);
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
683
|
+
const quotedSchema = quoteIdent(options?.schema ?? 'runtime_scheduler');
|
|
684
|
+
const operationStateType = runtimeSandboxOperationStateSqlType(quotedSchema);
|
|
685
|
+
const operationStates =
|
|
686
|
+
runtimeSandboxOperationFromStatesSqlCast(quotedSchema);
|
|
679
687
|
const diagnostics: RuntimeSandboxLedgerReconciliationDiagnostic[] = [];
|
|
680
688
|
async function measuredQuery<Row extends Record<string, unknown>>(
|
|
681
689
|
phase: RuntimeSandboxLedgerReconciliationPhase,
|
|
@@ -801,7 +809,7 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
|
|
|
801
809
|
WHERE operation.provider_operation_token = inventory.operation_key
|
|
802
810
|
AND operation.provider = $2
|
|
803
811
|
AND operation.environment = 'production'
|
|
804
|
-
AND operation.state = $4
|
|
812
|
+
AND operation.state = ANY($4::${operationStates})
|
|
805
813
|
AND lease.lease_id = operation.operation_key
|
|
806
814
|
AND lease.released_at IS NULL
|
|
807
815
|
RETURNING operation.operation_key, operation.run_id, operation.attempt,
|
|
@@ -863,8 +871,8 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
|
|
|
863
871
|
[
|
|
864
872
|
inventoryJson,
|
|
865
873
|
DAYTONA_PROVIDER,
|
|
866
|
-
|
|
867
|
-
|
|
874
|
+
runtimeSandboxOperationTargetState('reconcile_recover_reserved'),
|
|
875
|
+
runtimeSandboxOperationFromStates('reconcile_recover_reserved'),
|
|
868
876
|
],
|
|
869
877
|
);
|
|
870
878
|
recoveredReservedOperations = recovered.rows.length;
|
|
@@ -1257,7 +1265,7 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
|
|
|
1257
1265
|
WHERE operation.provider = '${DAYTONA_PROVIDER}'
|
|
1258
1266
|
AND operation.sandbox_id = changed.sandbox_id
|
|
1259
1267
|
AND operation.routing_domain IS NOT DISTINCT FROM changed.routing_domain
|
|
1260
|
-
AND operation.state = $3
|
|
1268
|
+
AND operation.state = ANY($3::${operationStates})
|
|
1261
1269
|
RETURNING operation.operation_key
|
|
1262
1270
|
),
|
|
1263
1271
|
released_leases AS (
|
|
@@ -1282,8 +1290,8 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
|
|
|
1282
1290
|
routing_domain: row.routingDomain,
|
|
1283
1291
|
})),
|
|
1284
1292
|
),
|
|
1285
|
-
|
|
1286
|
-
|
|
1293
|
+
runtimeSandboxOperationTargetState('reconcile_confirmed_absent'),
|
|
1294
|
+
runtimeSandboxOperationFromStates('reconcile_confirmed_absent'),
|
|
1287
1295
|
],
|
|
1288
1296
|
)
|
|
1289
1297
|
: { rows: [] };
|
|
@@ -86,21 +86,174 @@ export type RuntimeSandboxOperation =
|
|
|
86
86
|
| RuntimeSandboxOperationDeleted
|
|
87
87
|
| RuntimeSandboxOperationAbandoned;
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
export const RUNTIME_SANDBOX_OPERATION_STATES = [
|
|
90
|
+
RuntimeSandboxOperationState.Reserved,
|
|
91
|
+
RuntimeSandboxOperationState.Live,
|
|
92
|
+
RuntimeSandboxOperationState.Deleting,
|
|
93
|
+
RuntimeSandboxOperationState.Deleted,
|
|
94
|
+
RuntimeSandboxOperationState.Abandoned,
|
|
95
|
+
] as const;
|
|
96
|
+
|
|
97
|
+
/** No writer moves an operation out of these; see the exits list below. */
|
|
98
|
+
export const RUNTIME_SANDBOX_OPERATION_TERMINAL_STATES = [
|
|
99
|
+
RuntimeSandboxOperationState.Deleted,
|
|
100
|
+
RuntimeSandboxOperationState.Abandoned,
|
|
101
|
+
] as const;
|
|
102
|
+
|
|
103
|
+
/** The source of an INSERT: no operation row exists yet. */
|
|
104
|
+
export const RUNTIME_SANDBOX_OPERATION_ABSENT = 'absent';
|
|
105
|
+
export type RuntimeSandboxOperationTransitionSource =
|
|
106
|
+
| RuntimeSandboxOperationState
|
|
107
|
+
| typeof RUNTIME_SANDBOX_OPERATION_ABSENT;
|
|
108
|
+
|
|
109
|
+
export type RuntimeSandboxOperationTransitionSpec = {
|
|
110
|
+
/** States (or `absent`, for an INSERT) the write may start from. */
|
|
111
|
+
readonly from: readonly RuntimeSandboxOperationTransitionSource[];
|
|
112
|
+
readonly to: RuntimeSandboxOperationState;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const {
|
|
116
|
+
Reserved: RESERVED,
|
|
117
|
+
Live: LIVE,
|
|
118
|
+
Deleting: DELETING,
|
|
119
|
+
Deleted: DELETED,
|
|
120
|
+
Abandoned: ABANDONED,
|
|
121
|
+
} = RuntimeSandboxOperationState;
|
|
122
|
+
const ABSENT = RUNTIME_SANDBOX_OPERATION_ABSENT;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* `runtime_sandbox_operations.state`, one entry per write. Every writer takes
|
|
126
|
+
* its allowed-from set from here (`state = ANY($n)`) and its target from `to`;
|
|
127
|
+
* the row fences (run, attempt, lease, sandbox identity, cleanup job) stay in
|
|
128
|
+
* each statement and only narrow the set. An INSERT starts from `absent` and
|
|
129
|
+
* never overwrites: its conflict clause is `DO NOTHING`.
|
|
130
|
+
*/
|
|
131
|
+
export const RUNTIME_SANDBOX_OPERATION_STATE_TRANSITIONS = {
|
|
132
|
+
/** reserveRuntimeSandboxCapacityLease: the create intent precedes provider I/O. */
|
|
133
|
+
reserve: { from: [ABSENT], to: RESERVED },
|
|
134
|
+
/** backfillRuntimeSandboxOperationsFromAttemptResources: a pre-ledger attempt resource. */
|
|
135
|
+
backfill_live: { from: [ABSENT], to: LIVE },
|
|
136
|
+
/** recordPostgresSchedulerReconciledModalResourcesForCleanup: a late Modal sandbox with no reservation. */
|
|
137
|
+
record_reconciled_modal: { from: [ABSENT], to: DELETING },
|
|
138
|
+
/** recordPostgresSchedulerManagedSandboxOperationLive: the provider create returned. */
|
|
139
|
+
bind_live: { from: [RESERVED], to: LIVE },
|
|
140
|
+
/**
|
|
141
|
+
* recordPostgresSchedulerManagedSandboxOperationLive with `billingEndedAt`:
|
|
142
|
+
* Daytona retired the sandbox before retrying acquisition. A repeat on a
|
|
143
|
+
* deleting row only refreshes `updated_at`.
|
|
144
|
+
*/
|
|
145
|
+
retire_live: { from: [LIVE, DELETING], to: DELETING },
|
|
146
|
+
/** recordPostgresSchedulerLateManagedSandboxOperationForCleanup: the create returned after the attempt lost its fence. */
|
|
147
|
+
record_late: { from: [RESERVED], to: DELETING },
|
|
148
|
+
/** recordPostgresSchedulerReconciledModalResourcesForCleanup: the reserved Modal create the provider later listed. */
|
|
149
|
+
promote_reconciled_modal: { from: [RESERVED], to: DELETING },
|
|
150
|
+
/** resolvePostgresSchedulerAmbiguousModalCreateIntentFromProvider: the provider confirmed no sandbox. */
|
|
151
|
+
abandon_unresolved_modal_intent: { from: [RESERVED], to: ABANDONED },
|
|
152
|
+
/** abandonUnstartedModalCancellationReservations: an old Modal reservation with no intent or resource. */
|
|
153
|
+
abandon_unstarted_modal: { from: [RESERVED], to: ABANDONED },
|
|
154
|
+
/** abandonRuntimeSandboxOperationReservation: a confirmed provider rejection. */
|
|
155
|
+
abandon_reservation: { from: [RESERVED], to: ABANDONED },
|
|
156
|
+
/** claimPostgresSchedulerSandboxCleanupJobs: the cleanup worker takes a live sandbox. */
|
|
157
|
+
cleanup_claim_live: { from: [LIVE], to: DELETING },
|
|
158
|
+
/** claimPostgresSchedulerSandboxCleanupJobs: a reservation whose lease is already bound to the sandbox. */
|
|
159
|
+
cleanup_claim_reserved: { from: [RESERVED], to: DELETING },
|
|
160
|
+
/** completePostgresSchedulerSandboxCleanupJob: the provider confirmed the delete. */
|
|
161
|
+
cleanup_complete: { from: [DELETING], to: DELETED },
|
|
162
|
+
/** recordRecoveredDaytonaCancellationSandbox: a cancelled run's create was found by its label. */
|
|
163
|
+
recover_daytona_cancellation: { from: [RESERVED], to: DELETING },
|
|
164
|
+
/** recordDaytonaSandboxCleanupIntent: queue cleanup for a labelled create before binding it. */
|
|
165
|
+
record_daytona_cleanup_intent: { from: [RESERVED], to: DELETING },
|
|
166
|
+
/** reconcileRuntimeDaytonaSandboxLedger: the inventory lists a reserved create by its label. */
|
|
167
|
+
reconcile_recover_reserved: { from: [RESERVED], to: DELETING },
|
|
168
|
+
/**
|
|
169
|
+
* reconcileRuntimeDaytonaSandboxLedger: an exact read confirmed a live
|
|
170
|
+
* sandbox is gone. It skips `deleting` because no cleanup worker holds it.
|
|
171
|
+
*/
|
|
172
|
+
reconcile_confirmed_absent: { from: [LIVE], to: DELETED },
|
|
173
|
+
/** createPostgresDaytonaJanitorOwnershipPort.authorizeCleanup: the janitor queued cleanup for a live sandbox. */
|
|
174
|
+
janitor_authorize_cleanup: { from: [LIVE], to: DELETING },
|
|
175
|
+
} as const satisfies Record<string, RuntimeSandboxOperationTransitionSpec>;
|
|
176
|
+
|
|
177
|
+
export type RuntimeSandboxOperationTransition =
|
|
178
|
+
keyof typeof RUNTIME_SANDBOX_OPERATION_STATE_TRANSITIONS;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Every move out of a terminal state, by name. None exists today: a table
|
|
182
|
+
* entry that leaves `deleted` or `abandoned` fails the table test until it is
|
|
183
|
+
* listed here with its reason.
|
|
184
|
+
*/
|
|
185
|
+
export const RUNTIME_SANDBOX_OPERATION_TERMINAL_EXITS: readonly {
|
|
186
|
+
transition: RuntimeSandboxOperationTransition;
|
|
187
|
+
from: RuntimeSandboxOperationState;
|
|
188
|
+
why: string;
|
|
189
|
+
}[] = [];
|
|
190
|
+
|
|
191
|
+
/** The allowed-from states of an UPDATE, for `state = ANY($n)`. */
|
|
192
|
+
export function runtimeSandboxOperationFromStates(
|
|
193
|
+
transition: RuntimeSandboxOperationTransition,
|
|
194
|
+
): RuntimeSandboxOperationState[] {
|
|
195
|
+
const states = (
|
|
196
|
+
RUNTIME_SANDBOX_OPERATION_STATE_TRANSITIONS[transition]
|
|
197
|
+
.from as readonly RuntimeSandboxOperationTransitionSource[]
|
|
198
|
+
).filter(
|
|
199
|
+
(state): state is RuntimeSandboxOperationState => state !== ABSENT,
|
|
200
|
+
);
|
|
201
|
+
if (states.length === 0) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Sandbox operation transition ${transition} only inserts; it has no from-state.`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return states;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The state an INSERT or UPDATE writes for a transition. */
|
|
210
|
+
export function runtimeSandboxOperationTargetState(
|
|
211
|
+
transition: RuntimeSandboxOperationTransition,
|
|
212
|
+
): RuntimeSandboxOperationState {
|
|
213
|
+
return RUNTIME_SANDBOX_OPERATION_STATE_TRANSITIONS[transition].to;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The column's enum type, given the writer's quoted schema. */
|
|
217
|
+
export function runtimeSandboxOperationStateSqlType(
|
|
218
|
+
quotedSchema: string,
|
|
219
|
+
): string {
|
|
220
|
+
return `${quotedSchema}."runtime_sandbox_operation_state"`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The cast for an allowed-from parameter: `state = ANY($n::<this>)`. The
|
|
225
|
+
* parameter travels as `text[]` (drivers cannot encode a custom enum array)
|
|
226
|
+
* and becomes the enum array, so the comparison stays enum to enum.
|
|
227
|
+
*/
|
|
228
|
+
export function runtimeSandboxOperationFromStatesSqlCast(
|
|
229
|
+
quotedSchema: string,
|
|
230
|
+
): string {
|
|
231
|
+
return `text[]::${runtimeSandboxOperationStateSqlType(quotedSchema)}[]`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The targets the writers' table reaches from one state. */
|
|
235
|
+
function runtimeSandboxOperationTargetsFrom(
|
|
236
|
+
state: RuntimeSandboxOperationState,
|
|
237
|
+
): readonly RuntimeSandboxOperationState[] {
|
|
238
|
+
const specs: readonly RuntimeSandboxOperationTransitionSpec[] = Object.values(
|
|
239
|
+
RUNTIME_SANDBOX_OPERATION_STATE_TRANSITIONS,
|
|
240
|
+
);
|
|
241
|
+
return [
|
|
242
|
+
...new Set(
|
|
243
|
+
specs.filter((spec) => spec.from.includes(state)).map((spec) => spec.to),
|
|
244
|
+
),
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Every legal state change, derived from the writers' table above. */
|
|
90
249
|
export const RUNTIME_SANDBOX_OPERATION_TRANSITIONS: Readonly<
|
|
91
250
|
Record<RuntimeSandboxOperationState, readonly RuntimeSandboxOperationState[]>
|
|
92
251
|
> = {
|
|
93
|
-
[
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
],
|
|
98
|
-
[RuntimeSandboxOperationState.Live]: [RuntimeSandboxOperationState.Deleting],
|
|
99
|
-
[RuntimeSandboxOperationState.Deleting]: [
|
|
100
|
-
RuntimeSandboxOperationState.Deleted,
|
|
101
|
-
],
|
|
102
|
-
[RuntimeSandboxOperationState.Deleted]: [],
|
|
103
|
-
[RuntimeSandboxOperationState.Abandoned]: [],
|
|
252
|
+
[RESERVED]: runtimeSandboxOperationTargetsFrom(RESERVED),
|
|
253
|
+
[LIVE]: runtimeSandboxOperationTargetsFrom(LIVE),
|
|
254
|
+
[DELETING]: runtimeSandboxOperationTargetsFrom(DELETING),
|
|
255
|
+
[DELETED]: runtimeSandboxOperationTargetsFrom(DELETED),
|
|
256
|
+
[ABANDONED]: runtimeSandboxOperationTargetsFrom(ABANDONED),
|
|
104
257
|
};
|
|
105
258
|
|
|
106
259
|
export function canTransitionRuntimeSandboxOperation(
|