deepline 0.3.483 → 0.3.485
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/monitors/signal-radars/inbound-dead-letter.ts +100 -9
- 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/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 +102 -23
- 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 +204 -6
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/ambiguous-modal-create-state.ts +21 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/compute-billing-job-state.ts +23 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/integration-operation-value-retirement-state.ts +25 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/integration-operation-value-retirement.ts +15 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/outbox-repair-operation-state.ts +30 -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 +26 -0
- 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 +743 -70
- 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 +34 -34
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/sandbox-cleanup-job-state.ts +23 -0
- 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/bundling-sources/shared_libs/product-notifications/destination-state.ts +93 -0
- package/dist/cli/auth-ABZBH55L.js +43 -0
- package/dist/cli/{auth-2NXF6Q3Q.mjs → auth-OWMUENCU.mjs} +5 -5
- package/dist/cli/{billing-5PW4L5WD.js → billing-2FMNQGOX.js} +80 -80
- package/dist/cli/{billing-W2Y4EOZP.mjs → billing-JX4H3VFF.mjs} +7 -7
- package/dist/cli/{chunk-UGBZ6MCR.js → chunk-2ILND7XX.js} +2 -2
- package/dist/cli/{chunk-25IGCYJP.mjs → chunk-2ZEQ43B7.mjs} +3 -3
- package/dist/cli/{chunk-J7S3DJB4.mjs → chunk-3DBW6C7M.mjs} +13 -4
- package/dist/cli/{chunk-7APXZ3CX.mjs → chunk-3DYU3JQN.mjs} +2 -2
- package/dist/cli/{chunk-VFEW53L5.js → chunk-3OF7NSGR.js} +322 -294
- package/dist/cli/{chunk-UDF2CY4D.mjs → chunk-3Z24NKW7.mjs} +62 -34
- package/dist/cli/{chunk-62XGOB2D.js → chunk-5DCQWQCP.js} +26 -26
- package/dist/cli/{chunk-4X23YY2E.mjs → chunk-62PJ6PK7.mjs} +5 -5
- package/dist/cli/{chunk-YL64JIQ7.mjs → chunk-676NZ7K4.mjs} +1 -1
- package/dist/cli/{chunk-T5GZZJ7O.js → chunk-775AZTO7.js} +323 -247
- package/dist/cli/{chunk-C3LJSOQ6.mjs → chunk-ACTUAZYP.mjs} +5 -5
- package/dist/cli/{chunk-R2OR4RHV.js → chunk-AFADYKFE.js} +8 -8
- package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
- package/dist/cli/{chunk-GONUMUBM.js → chunk-BSKPQB2P.js} +7 -7
- package/dist/cli/chunk-C6QWRSMQ.js +42 -0
- package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
- package/dist/cli/{chunk-PRL7EKJZ.mjs → chunk-CW6TAQBF.mjs} +15 -4
- package/dist/cli/{chunk-75IIHFN6.js → chunk-DMNVM34J.js} +5 -4
- package/dist/cli/{chunk-IEV5UWPN.mjs → chunk-E73JXJA3.mjs} +1 -1
- package/dist/cli/{chunk-DS455RPF.js → chunk-EC2CVPN5.js} +3 -3
- package/dist/cli/{chunk-B7HQL77V.js → chunk-ECIXZNSW.js} +87 -76
- package/dist/cli/{chunk-JJSLEMQQ.mjs → chunk-FJY6K3BG.mjs} +93 -17
- package/dist/cli/{chunk-FK47YUPC.mjs → chunk-G5PI3RNT.mjs} +1 -1
- package/dist/cli/{chunk-GRE3ID5E.mjs → chunk-GHHJWCMD.mjs} +2 -1
- package/dist/cli/{chunk-2JWG2H2N.js → chunk-HKGXGGIV.js} +1 -1
- package/dist/cli/{chunk-2MKX3HV3.js → chunk-IHMYIHF4.js} +5 -5
- 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-AWAFYRFV.mjs → chunk-JD6HKNKD.mjs} +1 -1
- package/dist/cli/{chunk-UY7OXFVU.js → chunk-JQXUWYWX.js} +13 -13
- package/dist/cli/{chunk-GGJQ4HJW.mjs → chunk-KZTNNLIL.mjs} +2 -2
- package/dist/cli/{chunk-NREZRYPU.mjs → chunk-L352NOE3.mjs} +2 -2
- package/dist/cli/{chunk-WI2HNYQX.js → chunk-L7IQ3DFH.js} +53 -53
- package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
- package/dist/cli/{chunk-XRIQN6EP.js → chunk-NKPTM7SK.js} +7 -7
- package/dist/cli/{chunk-5ICAG4RE.js → chunk-NLRTFJGH.js} +14 -14
- package/dist/cli/{chunk-WKB6Y43W.js → chunk-NRNWPWBW.js} +37 -37
- package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
- package/dist/cli/{chunk-MYB6JVSD.js → chunk-OW4OTEFF.js} +16 -16
- package/dist/cli/{chunk-ISP7ZENV.mjs → chunk-RZE5I2XJ.mjs} +4 -4
- package/dist/cli/{chunk-5LHU7NUS.js → chunk-S3WQJ5VG.js} +3 -3
- package/dist/cli/{chunk-EDMCD7MX.mjs → chunk-SR6S4EYG.mjs} +5 -5
- package/dist/cli/{chunk-2T4OSJEH.js → chunk-T4G2T5DS.js} +21 -21
- package/dist/cli/{chunk-EGHYGTJM.mjs → chunk-TMCC7ORQ.mjs} +1 -1
- package/dist/cli/{chunk-SCPFOH5Z.mjs → chunk-TSCUWWTM.mjs} +1 -1
- package/dist/cli/{chunk-7TKLISLM.js → chunk-TVW6USSG.js} +3 -3
- package/dist/cli/{chunk-QSYA6VE4.js → chunk-U6WEGDD3.js} +2 -2
- package/dist/cli/{chunk-FGEC5SWP.mjs → chunk-UPHXGZCE.mjs} +4 -4
- package/dist/cli/{chunk-5JCXS4MP.js → chunk-UQ3LQ6IF.js} +5 -5
- package/dist/cli/{chunk-JYEZ6BWX.mjs → chunk-VZYTLWOM.mjs} +2 -2
- package/dist/cli/{chunk-FAZTLYJO.mjs → chunk-W33OL4F2.mjs} +2 -2
- 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-S24CK3CJ.mjs → chunk-YDA3PMKK.mjs} +3 -3
- package/dist/cli/{csv-EKEFLUIW.js → csv-HFEQPGNY.js} +13 -13
- package/dist/cli/{csv-DIFVIR23.mjs → csv-OHF3Y5KB.mjs} +4 -4
- package/dist/cli/{db-DOW4EVEU.mjs → db-M456OUXD.mjs} +7 -7
- package/dist/cli/{db-S7DDRUHX.js → db-VLQKCYQS.js} +28 -28
- package/dist/cli/describe-CP35DZ5Z.js +49 -0
- package/dist/cli/{describe-KSZFOWKV.mjs → describe-M6VXFYVL.mjs} +21 -21
- 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-CAG7YC5K.mjs → executions-4FGRBPJF.mjs} +7 -7
- package/dist/cli/{executions-3DU5IXB6.js → executions-GKINJZI6.js} +9 -9
- package/dist/cli/{feedback-BQMPTE47.mjs → feedback-D2WMGK3V.mjs} +4 -4
- package/dist/cli/{feedback-I65JMCP2.js → feedback-ZH5K7WV7.js} +8 -8
- package/dist/cli/git-IDALMZDN.js +25 -0
- package/dist/cli/{git-UQUCD7XZ.mjs → git-OCIJ5ME4.mjs} +5 -5
- package/dist/cli/index.js +142 -139
- package/dist/cli/index.mjs +45 -42
- package/dist/cli/{legacy-noops-OLNT2BG5.js → legacy-noops-QNIVP7LO.js} +8 -8
- package/dist/cli/{legacy-noops-JXKLHUI3.mjs → legacy-noops-V6Q2X34P.mjs} +5 -5
- package/dist/cli/{monitors-DLTHHAFQ.mjs → monitors-2USHTG5G.mjs} +8 -8
- package/dist/cli/{monitors-Z5X56AZN.js → monitors-5DNK7W2K.js} +92 -92
- package/dist/cli/{org-XBHJLKUG.js → org-RPGM5AN4.js} +73 -73
- package/dist/cli/{org-6EZZHD3M.mjs → org-TL2YPYSE.mjs} +7 -7
- package/dist/cli/{pages-XVJ34SCN.js → pages-PNUKPFWV.js} +18 -18
- package/dist/cli/{pages-MYXROSVK.mjs → pages-XDEW6EE3.mjs} +7 -7
- package/dist/cli/{play-ACC4T2XQ.js → play-F5LHRKV5.js} +858 -632
- package/dist/cli/{play-5PV4LAHE.mjs → play-WINNQ4HZ.mjs} +372 -146
- package/dist/cli/{providers-JCI3KNE4.js → providers-BD4IS5U5.js} +10 -10
- package/dist/cli/{providers-2DLUGIFF.mjs → providers-PXGL3FRE.mjs} +7 -7
- package/dist/cli/{quickstart-PDSQEDLD.js → quickstart-7LVF6HZF.js} +6 -6
- package/dist/cli/{quickstart-NSL3C76K.mjs → quickstart-XTH3UQWZ.mjs} +4 -4
- package/dist/cli/{run-X5MXCM4P.mjs → run-MBMUENR7.mjs} +26 -26
- package/dist/cli/{run-UCFMHOQC.js → run-NH2BAWPA.js} +41 -41
- package/dist/cli/{search-RPEMXV6N.mjs → search-BMRWBV66.mjs} +8 -8
- package/dist/cli/search-R3MQJQMT.js +32 -0
- package/dist/cli/{search-output-MZH3HLVE.js → search-output-5NNT337U.js} +22 -16
- package/dist/cli/{search-output-6UO47B7G.mjs → search-output-QKKRD4MF.mjs} +14 -8
- package/dist/cli/{secrets-NLEQURD3.mjs → secrets-AWEXBTJV.mjs} +7 -7
- package/dist/cli/{secrets-UFBASYGY.js → secrets-KQSTOREN.js} +16 -16
- package/dist/cli/{sessions-JYH4DBEE.js → sessions-DSPLZYCJ.js} +6 -6
- package/dist/cli/{sessions-3ALFLWVU.mjs → sessions-RO25Q67X.mjs} +5 -5
- package/dist/cli/{settings-MQYKNAMB.js → settings-7JXIKNKI.js} +79 -79
- package/dist/cli/{settings-YPRILREA.mjs → settings-JMGXGK4Z.mjs} +12 -12
- package/dist/cli/{setup-5IGSHH4E.js → setup-5QFAQQRW.js} +47 -47
- package/dist/cli/{setup-DK4GM227.mjs → setup-ZQZ47FHB.mjs} +9 -9
- package/dist/cli/skills-EDZXY7DV.js +33 -0
- package/dist/cli/{skills-KYBZH3IT.mjs → skills-W3H2DL56.mjs} +7 -7
- package/dist/cli/{tools-4B2MHNBN.mjs → tools-2BZCVNBS.mjs} +19 -19
- package/dist/cli/tools-2EY2ETCZ.js +56 -0
- package/dist/cli/{update-S6VEO7NB.mjs → update-GAWYMGAW.mjs} +9 -9
- package/dist/cli/update-UKDQKNBY.js +33 -0
- package/dist/cli/{workflow-KXZZYFEF.mjs → workflow-M6LLHQ2I.mjs} +8 -8
- package/dist/cli/{workflow-FU2XVPUK.js → workflow-ZPTDFPKW.js} +18 -18
- 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 +123 -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-JHQKM6QY.js +0 -43
- package/dist/cli/chunk-PHDEQ6W3.js +0 -33
- package/dist/cli/describe-RXYQCJRR.js +0 -49
- package/dist/cli/git-ADIABNMQ.js +0 -25
- package/dist/cli/search-YILJZD36.js +0 -32
- package/dist/cli/skills-I4IUZN3U.js +0 -33
- package/dist/cli/tools-NLZR7ABS.js +0 -56
- package/dist/cli/update-RVDEUJTE.js +0 -33
|
@@ -13,6 +13,7 @@ type PendingTerminal<Row> = {
|
|
|
13
13
|
key: string;
|
|
14
14
|
value: Row;
|
|
15
15
|
bytes: number;
|
|
16
|
+
queuedAt: number;
|
|
16
17
|
committed: Deferred[];
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -21,6 +22,7 @@ type PendingCheckpoint<Update> = {
|
|
|
21
22
|
key: string;
|
|
22
23
|
value: Update;
|
|
23
24
|
bytes: number;
|
|
25
|
+
queuedAt: number;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
type PendingWrite<Row, Update> =
|
|
@@ -32,6 +34,7 @@ type BlockedTerminal<Row> = {
|
|
|
32
34
|
key: string;
|
|
33
35
|
value: Row;
|
|
34
36
|
bytes: number;
|
|
37
|
+
queuedAt: number;
|
|
35
38
|
admitted: Deferred;
|
|
36
39
|
committed: Deferred;
|
|
37
40
|
};
|
|
@@ -41,6 +44,7 @@ type BlockedCheckpoint<Update> = {
|
|
|
41
44
|
key: string;
|
|
42
45
|
value: Update;
|
|
43
46
|
bytes: number;
|
|
47
|
+
queuedAt: number;
|
|
44
48
|
admitted: Deferred;
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -170,8 +174,11 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
170
174
|
#activeStartedAt: number | null = null;
|
|
171
175
|
#bufferedBytes = 0;
|
|
172
176
|
#liveBytes = 0;
|
|
177
|
+
#oldestLiveQueuedAt = Infinity;
|
|
173
178
|
#timer: ReturnType<typeof setTimeout> | null = null;
|
|
179
|
+
#timerDueAt: number | null = null;
|
|
174
180
|
#pump: Promise<void> | null = null;
|
|
181
|
+
#draining = 0;
|
|
175
182
|
#checkpointPromise: Promise<RuntimeSheetRowWriterSummary> | null = null;
|
|
176
183
|
#finishPromise: Promise<RuntimeSheetRowWriterSummary> | null = null;
|
|
177
184
|
#stateWaiters: Deferred[] = [];
|
|
@@ -199,7 +206,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
199
206
|
positiveInteger(options.maxBatchBytes, 1024 * 1024),
|
|
200
207
|
this.#maxBufferedBytes,
|
|
201
208
|
);
|
|
202
|
-
|
|
209
|
+
const maxFlushMs = Math.floor(options.maxFlushMs ?? 500);
|
|
210
|
+
// Native timers treat unsupported delays as a next-turn wake. They must
|
|
211
|
+
// not become an unreachable age deadline in the accumulator.
|
|
212
|
+
this.#maxFlushMs =
|
|
213
|
+
Number.isFinite(maxFlushMs) && maxFlushMs <= 2_147_483_647
|
|
214
|
+
? Math.max(0, maxFlushMs)
|
|
215
|
+
: 0;
|
|
203
216
|
this.#classifyRetryableError =
|
|
204
217
|
options.classifyRetryableError ?? (() => null);
|
|
205
218
|
this.#sleep = options.sleep ?? abortableSleep;
|
|
@@ -219,11 +232,15 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
219
232
|
key,
|
|
220
233
|
value: row,
|
|
221
234
|
bytes,
|
|
235
|
+
queuedAt: performance.now(),
|
|
222
236
|
admitted,
|
|
223
237
|
committed,
|
|
224
238
|
};
|
|
225
239
|
if (this.#canAdmit(blocked)) this.#admit(blocked);
|
|
226
|
-
else
|
|
240
|
+
else {
|
|
241
|
+
this.#blocked.push(blocked);
|
|
242
|
+
this.#scheduleOrStart();
|
|
243
|
+
}
|
|
227
244
|
return {
|
|
228
245
|
admitted: admitted.promise,
|
|
229
246
|
committed: committed.promise,
|
|
@@ -310,11 +327,15 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
310
327
|
key,
|
|
311
328
|
value: update,
|
|
312
329
|
bytes: this.#inputBytes(this.#estimateCheckpointBytes(update)),
|
|
330
|
+
queuedAt: performance.now(),
|
|
313
331
|
admitted,
|
|
314
332
|
};
|
|
315
333
|
try {
|
|
316
334
|
if (this.#canAdmit(blocked)) this.#admit(blocked);
|
|
317
|
-
else
|
|
335
|
+
else {
|
|
336
|
+
this.#blocked.push(blocked);
|
|
337
|
+
this.#scheduleOrStart();
|
|
338
|
+
}
|
|
318
339
|
} catch (error) {
|
|
319
340
|
// A merged checkpoint can exceed the item limit even when each patch
|
|
320
341
|
// fits independently. Reject only the incoming checkpoint.
|
|
@@ -345,6 +366,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
345
366
|
|
|
346
367
|
#admit(write: BlockedWrite<Row, Update>): void {
|
|
347
368
|
const existing = this.#live.get(write.key);
|
|
369
|
+
const queuedAt = Math.min(write.queuedAt, existing?.queuedAt ?? Infinity);
|
|
348
370
|
if (write.kind === 'terminal') {
|
|
349
371
|
this.#terminalAcceptedKeys.add(write.key);
|
|
350
372
|
if (existing) {
|
|
@@ -360,6 +382,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
360
382
|
key: write.key,
|
|
361
383
|
value: write.value,
|
|
362
384
|
bytes: write.bytes,
|
|
385
|
+
queuedAt,
|
|
363
386
|
committed,
|
|
364
387
|
};
|
|
365
388
|
this.#live.set(write.key, terminal);
|
|
@@ -382,6 +405,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
382
405
|
key: write.key,
|
|
383
406
|
value: merged,
|
|
384
407
|
bytes: mergedBytes,
|
|
408
|
+
queuedAt,
|
|
385
409
|
};
|
|
386
410
|
this.#live.set(write.key, checkpoint);
|
|
387
411
|
write = { ...write, bytes: checkpoint.bytes };
|
|
@@ -391,11 +415,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
391
415
|
key: write.key,
|
|
392
416
|
value: write.value,
|
|
393
417
|
bytes: write.bytes,
|
|
418
|
+
queuedAt,
|
|
394
419
|
};
|
|
395
420
|
this.#live.set(write.key, checkpoint);
|
|
396
421
|
}
|
|
397
422
|
this.#liveBytes += write.bytes;
|
|
398
423
|
this.#bufferedBytes += write.bytes;
|
|
424
|
+
this.#oldestLiveQueuedAt = Math.min(this.#oldestLiveQueuedAt, queuedAt);
|
|
399
425
|
write.admitted.resolve();
|
|
400
426
|
this.#scheduleOrStart();
|
|
401
427
|
this.#notifyStateChanged();
|
|
@@ -403,19 +429,32 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
403
429
|
|
|
404
430
|
#scheduleOrStart(): void {
|
|
405
431
|
if (this.#pump || this.#live.size === 0 || this.#failure !== null) return;
|
|
406
|
-
if (
|
|
407
|
-
this.#live.size >= this.#maxBatchRows ||
|
|
408
|
-
this.#liveBytes >= this.#maxBatchBytes
|
|
409
|
-
) {
|
|
432
|
+
if (this.#mustFlushImmediately()) {
|
|
410
433
|
this.#clearTimer();
|
|
411
434
|
this.#startPump();
|
|
412
435
|
return;
|
|
413
436
|
}
|
|
414
|
-
|
|
415
|
-
this.#timer
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
437
|
+
const dueAt = this.#oldestLiveQueuedAt + this.#maxFlushMs;
|
|
438
|
+
if (this.#timer && this.#timerDueAt === dueAt) return;
|
|
439
|
+
this.#clearTimer();
|
|
440
|
+
this.#timerDueAt = dueAt;
|
|
441
|
+
this.#timer = setTimeout(
|
|
442
|
+
() => {
|
|
443
|
+
this.#timer = null;
|
|
444
|
+
this.#timerDueAt = null;
|
|
445
|
+
this.#startPump();
|
|
446
|
+
},
|
|
447
|
+
Math.max(0, Math.ceil(dueAt - performance.now())),
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
#mustFlushImmediately(): boolean {
|
|
452
|
+
return (
|
|
453
|
+
this.#draining > 0 ||
|
|
454
|
+
this.#blocked.length > 0 ||
|
|
455
|
+
this.#live.size >= this.#maxBatchRows ||
|
|
456
|
+
this.#liveBytes >= this.#maxBatchBytes
|
|
457
|
+
);
|
|
419
458
|
}
|
|
420
459
|
|
|
421
460
|
#startPump(): void {
|
|
@@ -425,17 +464,20 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
425
464
|
this.#pump = this.#runPump().finally(() => {
|
|
426
465
|
this.#pump = null;
|
|
427
466
|
this.#notifyStateChanged();
|
|
428
|
-
|
|
429
|
-
// Rows accumulated behind an active write are real backlog. Drain the
|
|
430
|
-
// largest available next batch immediately instead of starting a new
|
|
431
|
-
// age window and manufacturing latency.
|
|
432
|
-
this.#startPump();
|
|
433
|
-
}
|
|
467
|
+
this.#scheduleOrStart();
|
|
434
468
|
});
|
|
435
469
|
}
|
|
436
470
|
|
|
437
471
|
async #runPump(): Promise<void> {
|
|
438
472
|
while (this.#live.size > 0 && this.#failure === null) {
|
|
473
|
+
// A small backlog may have arrived only moments before the active
|
|
474
|
+
// write ended. Keep its original age window instead of turning one
|
|
475
|
+
// timer wake into a continuous train of underfull writes.
|
|
476
|
+
if (
|
|
477
|
+
!this.#mustFlushImmediately() &&
|
|
478
|
+
performance.now() - this.#oldestLiveQueuedAt < this.#maxFlushMs
|
|
479
|
+
)
|
|
480
|
+
return;
|
|
439
481
|
const batch = this.#takeBatch();
|
|
440
482
|
if (batch.length === 0) return;
|
|
441
483
|
const batchKind = batch[0]!.kind;
|
|
@@ -491,6 +533,13 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
491
533
|
batch.push(entry);
|
|
492
534
|
bytes += entry.bytes;
|
|
493
535
|
}
|
|
536
|
+
this.#oldestLiveQueuedAt = Infinity;
|
|
537
|
+
for (const entry of this.#live.values()) {
|
|
538
|
+
this.#oldestLiveQueuedAt = Math.min(
|
|
539
|
+
this.#oldestLiveQueuedAt,
|
|
540
|
+
entry.queuedAt,
|
|
541
|
+
);
|
|
542
|
+
}
|
|
494
543
|
return batch;
|
|
495
544
|
}
|
|
496
545
|
|
|
@@ -562,21 +611,26 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
562
611
|
}
|
|
563
612
|
|
|
564
613
|
async #drain(): Promise<void> {
|
|
614
|
+
this.#draining += 1;
|
|
565
615
|
this.#clearTimer();
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
616
|
+
try {
|
|
617
|
+
for (;;) {
|
|
618
|
+
if (this.#failure !== null) throw this.#failure;
|
|
619
|
+
this.#admitBlocked();
|
|
620
|
+
if (
|
|
621
|
+
this.#active === null &&
|
|
622
|
+
this.#live.size === 0 &&
|
|
623
|
+
this.#blocked.length === 0
|
|
624
|
+
) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
this.#startPump();
|
|
628
|
+
const stateChanged = deferred();
|
|
629
|
+
this.#stateWaiters.push(stateChanged);
|
|
630
|
+
await stateChanged.promise;
|
|
575
631
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
this.#stateWaiters.push(stateChanged);
|
|
579
|
-
await stateChanged.promise;
|
|
632
|
+
} finally {
|
|
633
|
+
this.#draining -= 1;
|
|
580
634
|
}
|
|
581
635
|
}
|
|
582
636
|
|
|
@@ -599,6 +653,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
599
653
|
}
|
|
600
654
|
this.#live.clear();
|
|
601
655
|
this.#liveBytes = 0;
|
|
656
|
+
this.#oldestLiveQueuedAt = Infinity;
|
|
602
657
|
for (const blocked of this.#blocked.splice(0)) {
|
|
603
658
|
blocked.admitted.reject(error);
|
|
604
659
|
if (blocked.kind === 'terminal') blocked.committed.reject(error);
|
|
@@ -636,6 +691,7 @@ export class RuntimeSheetRowWriter<Row, Update> {
|
|
|
636
691
|
if (!this.#timer) return;
|
|
637
692
|
clearTimeout(this.#timer);
|
|
638
693
|
this.#timer = null;
|
|
694
|
+
this.#timerDueAt = null;
|
|
639
695
|
}
|
|
640
696
|
|
|
641
697
|
#notifyStateChanged(error?: unknown): void {
|
|
@@ -346,6 +346,14 @@ export type SandboxExecutionLifecycle = {
|
|
|
346
346
|
): Promise<void>;
|
|
347
347
|
/** Must resolve before the Adapter can accept a command for this resource. */
|
|
348
348
|
recordResource(input: SandboxExecutionResource): Promise<void>;
|
|
349
|
+
/** Optional owner operation: persist retirement, then join exact fenced cleanup. */
|
|
350
|
+
retireResource?(
|
|
351
|
+
resource: SandboxExecutionResource,
|
|
352
|
+
options: {
|
|
353
|
+
deadlineAtMs: number;
|
|
354
|
+
signal?: AbortSignal;
|
|
355
|
+
},
|
|
356
|
+
): Promise<void>;
|
|
349
357
|
/** Same durable rule for a create that settles after the caller timed out. */
|
|
350
358
|
recordLateResource(input: SandboxExecutionResource): Promise<void>;
|
|
351
359
|
/**
|
|
@@ -404,6 +412,16 @@ export type SandboxExecutionDependencies<
|
|
|
404
412
|
execution: SandboxExecutionPort<Launch, Checkpoint, Suspension, RunnerResult>;
|
|
405
413
|
/** Every resource record binds its capacity lease in the scheduler fence. */
|
|
406
414
|
resourceFacts: SandboxExecutionResourceFacts;
|
|
415
|
+
/** Internal owner seam; absence retains the prior backend contract. */
|
|
416
|
+
retirement?: {
|
|
417
|
+
retire(input: {
|
|
418
|
+
attempt: SandboxRunInput['attempt'];
|
|
419
|
+
authority: SandboxRunInput['authority'];
|
|
420
|
+
resource: SandboxExecutionResource;
|
|
421
|
+
deadlineAtMs: number;
|
|
422
|
+
signal?: AbortSignal;
|
|
423
|
+
}): Promise<{ kind: 'retired' } | { kind: 'fence_lost' }>;
|
|
424
|
+
};
|
|
407
425
|
/** Required when the Adapter crosses Modal's ambiguous-create boundary. */
|
|
408
426
|
createIntents?: SandboxExecutionCreateIntents;
|
|
409
427
|
/** Required when the Adapter emits provider-edge lifecycle evidence. */
|
|
@@ -301,6 +301,25 @@ function createExecutionLifecycle<Launch, Checkpoint, Suspension, RunnerResult>(
|
|
|
301
301
|
);
|
|
302
302
|
acceptedResources.add(resourceIdentity(resource));
|
|
303
303
|
},
|
|
304
|
+
...(dependencies.retirement
|
|
305
|
+
? {
|
|
306
|
+
retireResource: async (
|
|
307
|
+
resource: SandboxExecutionResource,
|
|
308
|
+
options: { deadlineAtMs: number; signal?: AbortSignal },
|
|
309
|
+
) => {
|
|
310
|
+
validateResource(resource);
|
|
311
|
+
const outcome = await dependencies.retirement!.retire({
|
|
312
|
+
attempt: input.attempt,
|
|
313
|
+
authority: input.authority,
|
|
314
|
+
resource,
|
|
315
|
+
...options,
|
|
316
|
+
});
|
|
317
|
+
if (outcome.kind === 'fence_lost')
|
|
318
|
+
throw new SandboxResourceFenceLostError();
|
|
319
|
+
rememberResource(resource);
|
|
320
|
+
},
|
|
321
|
+
}
|
|
322
|
+
: {}),
|
|
304
323
|
recordLateResource: async (resource) => {
|
|
305
324
|
rememberResource(resource);
|
|
306
325
|
recordResult(
|
package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts
CHANGED
|
@@ -154,6 +154,20 @@ function createRunnerCallbacks(input: {
|
|
|
154
154
|
onWorkCounters: input.progress?.onWorkCounters,
|
|
155
155
|
readDetachedRunnerReadiness: async (baselineHeartbeatAt) =>
|
|
156
156
|
await input.readiness({ baselineHeartbeatAt }),
|
|
157
|
+
...(input.lifecycle.retireResource
|
|
158
|
+
? {
|
|
159
|
+
retireRuntimeResource: async (
|
|
160
|
+
resource: PlayRunnerRuntimeResource,
|
|
161
|
+
options: { deadlineAtMs: number; signal?: AbortSignal },
|
|
162
|
+
) => {
|
|
163
|
+
await input.lifecycle.retireResource!(
|
|
164
|
+
toSandboxResource(resource),
|
|
165
|
+
options,
|
|
166
|
+
);
|
|
167
|
+
remember(resource);
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
: {}),
|
|
157
171
|
onRuntimeResourceAcquired: async (resource) => {
|
|
158
172
|
await input.lifecycle.recordResource(remember(resource));
|
|
159
173
|
},
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DaytonaDeleteRetryAuthorization } from '../runner-backends/backends/daytona-lifecycle';
|
|
1
2
|
/**
|
|
2
3
|
* `absurd` durable task handler + worker startup.
|
|
3
4
|
*
|
|
@@ -140,6 +141,8 @@ import {
|
|
|
140
141
|
buildPostgresSchedulerRunnerContext,
|
|
141
142
|
claimPostgresSchedulerComputeBillingJobs,
|
|
142
143
|
claimPostgresSchedulerSandboxCleanupJobs,
|
|
144
|
+
readPostgresSchedulerSandboxRetirement,
|
|
145
|
+
readPostgresSchedulerSandboxCleanupClaim,
|
|
143
146
|
claimPostgresSchedulerRecoveryCircuit,
|
|
144
147
|
claimPostgresSchedulerOverdueDetachedRunnerCeilings,
|
|
145
148
|
closePostgresSchedulerRecoveryCircuit,
|
|
@@ -840,6 +843,8 @@ export type AbsurdRuntimeWorkerDeps = {
|
|
|
840
843
|
deleteRuntimeSandboxWithOutcome?: (
|
|
841
844
|
sandboxId: string,
|
|
842
845
|
expectedOrganizationId: string | null,
|
|
846
|
+
timeoutMs?: number,
|
|
847
|
+
retry?: DaytonaDeleteRetryAuthorization,
|
|
843
848
|
deleteAcceptance?: PostgresSchedulerSandboxDeleteAcceptance | null,
|
|
844
849
|
) => Promise<DaytonaSandboxDeleteOutcome>;
|
|
845
850
|
/** Maximum time a best-effort sandbox deletion may occupy a worker slot. */
|
|
@@ -935,13 +940,16 @@ function buildDefaultDeps(absurd: Absurd): AbsurdRuntimeWorkerDeps {
|
|
|
935
940
|
deleteRuntimeSandboxWithOutcome: (
|
|
936
941
|
sandboxId,
|
|
937
942
|
expectedOrganizationId,
|
|
943
|
+
timeoutMs,
|
|
944
|
+
retry,
|
|
938
945
|
deleteAcceptance,
|
|
939
946
|
) =>
|
|
940
947
|
deleteDaytonaSandboxByIdWithOutcome({
|
|
941
948
|
sandboxId,
|
|
942
949
|
expectedOrganizationId,
|
|
950
|
+
retry,
|
|
951
|
+
timeoutSeconds: (timeoutMs ?? ABSURD_SANDBOX_GC_TIMEOUT_MS) / 1_000,
|
|
943
952
|
deleteAcceptance,
|
|
944
|
-
timeoutSeconds: ABSURD_SANDBOX_GC_TIMEOUT_MS / 1_000,
|
|
945
953
|
}),
|
|
946
954
|
sandboxGcTimeoutMs: ABSURD_SANDBOX_GC_TIMEOUT_MS,
|
|
947
955
|
readDetachedRunnerRuntimeCompletion: (suspension) =>
|
|
@@ -4765,6 +4773,29 @@ async function executeAssignedAbsurdAttempt(input: {
|
|
|
4765
4773
|
);
|
|
4766
4774
|
},
|
|
4767
4775
|
},
|
|
4776
|
+
retirement: {
|
|
4777
|
+
async retire({ resource, deadlineAtMs, signal }) {
|
|
4778
|
+
const retired =
|
|
4779
|
+
await retirePostgresSchedulerSandboxForReplacement({
|
|
4780
|
+
deps,
|
|
4781
|
+
runId,
|
|
4782
|
+
attempt: generation,
|
|
4783
|
+
leaseToken,
|
|
4784
|
+
resource:
|
|
4785
|
+
playRunnerRuntimeResourceFromSandboxExecutionResource(
|
|
4786
|
+
resource,
|
|
4787
|
+
),
|
|
4788
|
+
deadlineAtMs,
|
|
4789
|
+
signal,
|
|
4790
|
+
schedulerOptions: options,
|
|
4791
|
+
});
|
|
4792
|
+
return {
|
|
4793
|
+
kind: retired
|
|
4794
|
+
? ('retired' as const)
|
|
4795
|
+
: ('fence_lost' as const),
|
|
4796
|
+
};
|
|
4797
|
+
},
|
|
4798
|
+
},
|
|
4768
4799
|
resourceFacts: {
|
|
4769
4800
|
async record({ resource }) {
|
|
4770
4801
|
const runnerResource =
|
|
@@ -8684,6 +8715,130 @@ function unavailableSandboxCrashDiagnostic(
|
|
|
8684
8715
|
};
|
|
8685
8716
|
}
|
|
8686
8717
|
|
|
8718
|
+
/** Persist retirement first; only the existing exact-resource cleanup owner deletes. */
|
|
8719
|
+
export async function retirePostgresSchedulerSandboxForReplacement(input: {
|
|
8720
|
+
deps: Pick<
|
|
8721
|
+
AbsurdRuntimeWorkerDeps,
|
|
8722
|
+
| 'runWithClient'
|
|
8723
|
+
| 'deleteRuntimeSandbox'
|
|
8724
|
+
| 'deleteRuntimeSandboxRef'
|
|
8725
|
+
| 'deleteRuntimeSandboxWithOutcome'
|
|
8726
|
+
>;
|
|
8727
|
+
runId: string;
|
|
8728
|
+
attempt: number;
|
|
8729
|
+
leaseToken: string;
|
|
8730
|
+
resource: PlayRunnerRuntimeResource;
|
|
8731
|
+
deadlineAtMs: number;
|
|
8732
|
+
signal?: AbortSignal;
|
|
8733
|
+
schedulerOptions?: Pick<PostgresSchedulerOptions, 'schema'>;
|
|
8734
|
+
}): Promise<boolean> {
|
|
8735
|
+
const { resource } = input;
|
|
8736
|
+
if (
|
|
8737
|
+
resource.kind !== 'daytona_sandbox' ||
|
|
8738
|
+
!isManagedSandboxCapacityResource(resource) ||
|
|
8739
|
+
!resource.daytonaOrganizationId?.trim() ||
|
|
8740
|
+
!Number.isFinite(resource.billingEndedAt)
|
|
8741
|
+
) {
|
|
8742
|
+
throw new Error(
|
|
8743
|
+
'Managed sandbox retirement requires the exact owned resource and billing end.',
|
|
8744
|
+
);
|
|
8745
|
+
}
|
|
8746
|
+
const options = input.schedulerOptions ?? {};
|
|
8747
|
+
const identity = {
|
|
8748
|
+
runId: input.runId,
|
|
8749
|
+
attempt: input.attempt,
|
|
8750
|
+
leaseToken: input.leaseToken,
|
|
8751
|
+
provider: 'daytona' as const,
|
|
8752
|
+
sandboxId: resource.sandboxId,
|
|
8753
|
+
routingDomain: resource.daytonaOrganizationId.trim(),
|
|
8754
|
+
};
|
|
8755
|
+
const observe = () =>
|
|
8756
|
+
input.deps.runWithClient((client) =>
|
|
8757
|
+
readPostgresSchedulerSandboxRetirement(client, identity, options),
|
|
8758
|
+
);
|
|
8759
|
+
const remaining = () => {
|
|
8760
|
+
const ms = input.deadlineAtMs - Date.now();
|
|
8761
|
+
if (ms <= 0)
|
|
8762
|
+
throw new Error(
|
|
8763
|
+
'Sandbox retirement exceeded its original 30000ms deadline.',
|
|
8764
|
+
);
|
|
8765
|
+
return ms;
|
|
8766
|
+
};
|
|
8767
|
+
remaining();
|
|
8768
|
+
const before = await observe();
|
|
8769
|
+
if (!before.fenced) return false;
|
|
8770
|
+
if (before.status !== 'deleted') {
|
|
8771
|
+
const recorded = await input.deps.runWithClient((client) =>
|
|
8772
|
+
recordPostgresSchedulerManagedSandboxOperationLive(
|
|
8773
|
+
client,
|
|
8774
|
+
{
|
|
8775
|
+
runId: input.runId,
|
|
8776
|
+
attempt: input.attempt,
|
|
8777
|
+
leaseToken: input.leaseToken,
|
|
8778
|
+
resource,
|
|
8779
|
+
},
|
|
8780
|
+
options,
|
|
8781
|
+
),
|
|
8782
|
+
);
|
|
8783
|
+
if (!recorded) return false;
|
|
8784
|
+
}
|
|
8785
|
+
// Cancellation ends the join, never the already-persisted cleanup obligation.
|
|
8786
|
+
let claimedHere = false;
|
|
8787
|
+
const leaseOwner = `retirement:${randomUUID()}`;
|
|
8788
|
+
for (;;) {
|
|
8789
|
+
remaining();
|
|
8790
|
+
input.signal?.throwIfAborted();
|
|
8791
|
+
const state = await observe();
|
|
8792
|
+
if (!state.fenced) return false;
|
|
8793
|
+
if (state.status === 'deleted') return true;
|
|
8794
|
+
if (!state.status || state.blocked || state.error) {
|
|
8795
|
+
throw new Error(
|
|
8796
|
+
`Sandbox retirement is unresolved: ${state.error ?? state.status ?? 'missing obligation'}.`,
|
|
8797
|
+
);
|
|
8798
|
+
}
|
|
8799
|
+
if (!claimedHere) {
|
|
8800
|
+
const jobs = await input.deps.runWithClient((client) =>
|
|
8801
|
+
claimPostgresSchedulerSandboxCleanupJobs(
|
|
8802
|
+
client,
|
|
8803
|
+
{
|
|
8804
|
+
leaseOwner,
|
|
8805
|
+
runId: input.runId,
|
|
8806
|
+
environment:
|
|
8807
|
+
resource.runtimeEnvironment ??
|
|
8808
|
+
resource.daytonaEnvironment ??
|
|
8809
|
+
'production',
|
|
8810
|
+
exactResource: {
|
|
8811
|
+
provider: identity.provider,
|
|
8812
|
+
sandboxId: identity.sandboxId,
|
|
8813
|
+
routingDomain: identity.routingDomain,
|
|
8814
|
+
attempt: input.attempt,
|
|
8815
|
+
},
|
|
8816
|
+
limit: 1,
|
|
8817
|
+
leaseSeconds: SANDBOX_CLEANUP_STAGE_1_LEASE_SECONDS,
|
|
8818
|
+
},
|
|
8819
|
+
options,
|
|
8820
|
+
),
|
|
8821
|
+
);
|
|
8822
|
+
if (jobs.length > 0) {
|
|
8823
|
+
claimedHere = true;
|
|
8824
|
+
await processPostgresSchedulerSandboxCleanupJob({
|
|
8825
|
+
job: jobs[0],
|
|
8826
|
+
...input.deps,
|
|
8827
|
+
leaseOwner,
|
|
8828
|
+
schedulerOptions: options,
|
|
8829
|
+
timeoutMs: remaining(),
|
|
8830
|
+
deadlineAtMs: input.deadlineAtMs,
|
|
8831
|
+
retirement: { identity, signal: input.signal },
|
|
8832
|
+
});
|
|
8833
|
+
continue;
|
|
8834
|
+
}
|
|
8835
|
+
}
|
|
8836
|
+
await sleep(Math.min(100, remaining()), undefined, {
|
|
8837
|
+
signal: input.signal,
|
|
8838
|
+
});
|
|
8839
|
+
}
|
|
8840
|
+
}
|
|
8841
|
+
|
|
8687
8842
|
async function claimPostgresSchedulerSandboxCleanupBatch(input: {
|
|
8688
8843
|
runWithClient: AbsurdRuntimeWorkerDeps['runWithClient'];
|
|
8689
8844
|
leaseOwner: string;
|
|
@@ -8722,6 +8877,11 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
8722
8877
|
leaseOwner: string;
|
|
8723
8878
|
schedulerOptions: Pick<PostgresSchedulerOptions, 'schema'>;
|
|
8724
8879
|
timeoutMs: number;
|
|
8880
|
+
deadlineAtMs?: number;
|
|
8881
|
+
retirement?: {
|
|
8882
|
+
identity: Parameters<typeof readPostgresSchedulerSandboxRetirement>[1];
|
|
8883
|
+
signal?: AbortSignal;
|
|
8884
|
+
};
|
|
8725
8885
|
readSandboxCrashDiagnostic?: AbsurdRuntimeWorkerDeps['readSandboxCrashDiagnostic'];
|
|
8726
8886
|
}): Promise<SandboxCleanupJobOutcome> {
|
|
8727
8887
|
const { job } = input;
|
|
@@ -8893,6 +9053,15 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
8893
9053
|
if (!deleteProof.acceptance) {
|
|
8894
9054
|
await recordCleanupEvent('provider_delete_started', { timeoutMs });
|
|
8895
9055
|
}
|
|
9056
|
+
const remainingMs =
|
|
9057
|
+
input.deadlineAtMs === undefined
|
|
9058
|
+
? timeoutMs
|
|
9059
|
+
: Math.min(timeoutMs, input.deadlineAtMs - Date.now());
|
|
9060
|
+
if (remainingMs <= 0)
|
|
9061
|
+
throw new RuntimeSandboxGcTimeoutError(
|
|
9062
|
+
resource.sandboxId,
|
|
9063
|
+
timeoutMs,
|
|
9064
|
+
);
|
|
8896
9065
|
const providerOutcome = await deleteRuntimeSandboxBounded({
|
|
8897
9066
|
deleteRuntimeSandbox: async (sandboxId) => {
|
|
8898
9067
|
if (resource.provider === 'modal') {
|
|
@@ -8928,6 +9097,39 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
8928
9097
|
return await input.deleteRuntimeSandboxWithOutcome(
|
|
8929
9098
|
sandboxId,
|
|
8930
9099
|
resource.routingDomain,
|
|
9100
|
+
remainingMs,
|
|
9101
|
+
input.retirement && input.deadlineAtMs !== undefined
|
|
9102
|
+
? {
|
|
9103
|
+
authorizeRetry: async () => {
|
|
9104
|
+
const assertBudget = () => {
|
|
9105
|
+
input.retirement!.signal?.throwIfAborted();
|
|
9106
|
+
if (Date.now() >= input.deadlineAtMs!)
|
|
9107
|
+
throw new Error(
|
|
9108
|
+
'Sandbox retirement exceeded its original 30000ms deadline.',
|
|
9109
|
+
);
|
|
9110
|
+
};
|
|
9111
|
+
assertBudget();
|
|
9112
|
+
const authorized = await input.runWithClient(
|
|
9113
|
+
(client) =>
|
|
9114
|
+
readPostgresSchedulerSandboxCleanupClaim(
|
|
9115
|
+
client,
|
|
9116
|
+
{
|
|
9117
|
+
...resource,
|
|
9118
|
+
leaseOwner: input.leaseOwner,
|
|
9119
|
+
leaseToken:
|
|
9120
|
+
input.retirement!.identity.leaseToken,
|
|
9121
|
+
},
|
|
9122
|
+
input.schedulerOptions,
|
|
9123
|
+
),
|
|
9124
|
+
);
|
|
9125
|
+
assertBudget();
|
|
9126
|
+
if (!authorized)
|
|
9127
|
+
throw new Error(
|
|
9128
|
+
'Sandbox retirement retry lost its initiating attempt or exact cleanup claim.',
|
|
9129
|
+
);
|
|
9130
|
+
},
|
|
9131
|
+
}
|
|
9132
|
+
: undefined,
|
|
8931
9133
|
deleteProof.acceptance,
|
|
8932
9134
|
);
|
|
8933
9135
|
}
|
|
@@ -8944,7 +9146,7 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
8944
9146
|
} satisfies DaytonaSandboxDeleteOutcome);
|
|
8945
9147
|
},
|
|
8946
9148
|
sandboxId: resource.sandboxId,
|
|
8947
|
-
timeoutMs,
|
|
9149
|
+
timeoutMs: remainingMs,
|
|
8948
9150
|
});
|
|
8949
9151
|
if (
|
|
8950
9152
|
providerOutcome.kind === 'deleted' ||
|
|
@@ -8962,10 +9164,6 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
8962
9164
|
await recordCleanupEvent('provider_delete_accepted', {
|
|
8963
9165
|
routingDomain: providerOutcome.organizationId,
|
|
8964
9166
|
});
|
|
8965
|
-
} else {
|
|
8966
|
-
await recordCleanupEvent('provider_delete_pending', {
|
|
8967
|
-
code: providerOutcome.code,
|
|
8968
|
-
});
|
|
8969
9167
|
}
|
|
8970
9168
|
return {
|
|
8971
9169
|
kind: 'pending',
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type PlaySchedulerSubmitInput,
|
|
30
30
|
} from '../scheduler-backend';
|
|
31
31
|
import {
|
|
32
|
+
cancelPostgresSchedulerRun,
|
|
32
33
|
postgresSchedulerRunHandle,
|
|
33
34
|
readPostgresSchedulerLaunch,
|
|
34
35
|
readPostgresSchedulerAbsurdTaskId,
|
|
@@ -127,6 +128,44 @@ async function cancelAbsurdTaskIfPresent(
|
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Cancel a queued run that never reached Convex, inside the caller's
|
|
133
|
+
* transaction. Ordinary cancellation resolves the run through its Convex row,
|
|
134
|
+
* which a failed run.created projection never wrote. The scheduler fence
|
|
135
|
+
* proves the run is still queued with zero attempts and its run.created
|
|
136
|
+
* failed, then the engine task is cancelled so no worker can start it. The
|
|
137
|
+
* scheduler's run.cancelled fact waits behind the failed run.created.
|
|
138
|
+
*/
|
|
139
|
+
export async function cancelPostgresSchedulerRunWithoutProjection(
|
|
140
|
+
client: PostgresSchedulerQueryClient,
|
|
141
|
+
input: { runId: string; absurdTaskId: string; reason: string },
|
|
142
|
+
options?: { schema?: string },
|
|
143
|
+
): Promise<{ cancelled: boolean; engineTaskCancelled: boolean }> {
|
|
144
|
+
const launch = await readPostgresSchedulerLaunch(
|
|
145
|
+
client,
|
|
146
|
+
input.runId,
|
|
147
|
+
options,
|
|
148
|
+
{ caller: 'play_run_control' },
|
|
149
|
+
);
|
|
150
|
+
if (!launch) return { cancelled: false, engineTaskCancelled: false };
|
|
151
|
+
const cancelled = await cancelPostgresSchedulerRun(
|
|
152
|
+
client,
|
|
153
|
+
{
|
|
154
|
+
runId: input.runId,
|
|
155
|
+
reason: input.reason,
|
|
156
|
+
onlyIfCreatedProjectionFailed: { absurdTaskId: input.absurdTaskId },
|
|
157
|
+
},
|
|
158
|
+
options,
|
|
159
|
+
);
|
|
160
|
+
if (!cancelled) return { cancelled: false, engineTaskCancelled: false };
|
|
161
|
+
const engineTaskCancelled = await cancelAbsurdTaskIfPresent(client, {
|
|
162
|
+
queue: absurdQueueNameForRelease(absurdReleaseIdForLaunch(launch)),
|
|
163
|
+
taskId: input.absurdTaskId,
|
|
164
|
+
runId: input.runId,
|
|
165
|
+
});
|
|
166
|
+
return { cancelled, engineTaskCancelled };
|
|
167
|
+
}
|
|
168
|
+
|
|
130
169
|
function runCancellationSingleFlight(
|
|
131
170
|
key: string,
|
|
132
171
|
operation: () => Promise<PlaySchedulerCancelOutcome>,
|