deepline 0.3.542 → 0.3.544
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 +112 -2
- package/dist/bundling-sources/sdk/src/index.ts +7 -0
- package/dist/bundling-sources/sdk/src/integrations.ts +198 -0
- package/dist/bundling-sources/sdk/src/plays/run-request.ts +3 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/tool-calls.ts +35 -11
- package/dist/bundling-sources/sdk/src/types.ts +10 -0
- package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +132 -0
- package/dist/bundling-sources/shared_libs/integration-contracts/monitor-fleet-contract.ts +3 -1
- package/dist/bundling-sources/shared_libs/integration-contracts/tool-connection.ts +13 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/plan.ts +108 -1
- package/dist/bundling-sources/shared_libs/monitors/package.json +1 -1
- package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
- package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +5 -5
- package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +34 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +11 -5
- package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +9 -7
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +235 -12
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +20 -1
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +39 -30
- package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +29 -0
- package/dist/bundling-sources/shared_libs/play-runtime/event-wait-tools.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +10 -4
- package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +209 -0
- package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +24 -1
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +6 -1
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +37 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +43 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +23 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +320 -836
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/vercel-sandbox.ts +1061 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +862 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +45 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/sandbox-create-outcome.ts +3 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +11 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-contract.ts +20 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-placement-policy.ts +71 -34
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-provider-profile.ts +286 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +4 -1
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +12 -3
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +49 -55
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +127 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +7 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +214 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/managed-sandbox-resource-sql.ts +118 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +229 -144
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +11 -13
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +42 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +17 -0
- package/dist/bundling-sources/shared_libs/play-runtime/vercel-sandbox-runtime-config.ts +217 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +23 -0
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +1 -0
- package/dist/bundling-sources/shared_libs/plays/script-entry.ts +76 -6
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +1 -0
- package/dist/bundling-sources/shared_libs/security/credential-revision.ts +50 -0
- package/dist/bundling-sources/shared_libs/security/internal-actor.ts +2 -1
- package/dist/bundling-sources/shared_libs/security/receipt-admission-token.ts +37 -0
- package/dist/cli/auth-ENBXAKQS.js +43 -0
- package/dist/cli/{auth-IGBGOB4E.mjs → auth-IMWJAHPU.mjs} +5 -5
- package/dist/cli/{billing-IB2TWE74.js → billing-Y55PR2PV.js} +101 -101
- package/dist/cli/{billing-N37W2I62.mjs → billing-YQMW3QJI.mjs} +12 -12
- package/dist/cli/chunk-22OBDYHP.js +455 -0
- package/dist/cli/{chunk-GBAT5NMI.mjs → chunk-2HSZCQMT.mjs} +48 -6
- package/dist/cli/{chunk-VLEVVDWG.js → chunk-2JHYYB3F.js} +3 -3
- package/dist/cli/{chunk-D44DP4KJ.js → chunk-3I26HMJ7.js} +37 -17
- package/dist/cli/{chunk-B5NP3SHX.mjs → chunk-3JDA23NN.mjs} +2 -2
- package/dist/cli/{chunk-QXNOSCYL.js → chunk-3KGMM4KS.js} +1 -1
- package/dist/cli/{chunk-6WQDHEVF.mjs → chunk-456RRXAP.mjs} +5 -5
- package/dist/cli/{chunk-V4EYJKGJ.js → chunk-4JQEAYN3.js} +156 -17
- package/dist/cli/{chunk-FGGPCAGC.js → chunk-4PKHFW56.js} +18 -18
- package/dist/cli/{chunk-QONO7FRF.mjs → chunk-57G4NYOL.mjs} +1 -1
- package/dist/cli/{chunk-46V7QSJE.mjs → chunk-5PR4VLLL.mjs} +3 -3
- package/dist/cli/{chunk-OLH2PHMC.mjs → chunk-6P7TGCHQ.mjs} +1 -1
- package/dist/cli/{chunk-AKY7KZRJ.js → chunk-7GNZEOTH.js} +6 -6
- package/dist/cli/{chunk-LFMQVSEI.js → chunk-7HMMTSDA.js} +5 -5
- package/dist/cli/{chunk-ORA5TMML.mjs → chunk-BEQ7RQLT.mjs} +5 -5
- package/dist/cli/{chunk-KQSTV4MW.js → chunk-BLYW6FFB.js} +60 -18
- package/dist/cli/{chunk-GM73TZ2W.js → chunk-C4P2KLWT.js} +41 -41
- package/dist/cli/{chunk-DNGACHFX.js → chunk-COJHT2KF.js} +22 -22
- package/dist/cli/{chunk-6SLEHAXX.js → chunk-DF2X7GJG.js} +5 -5
- package/dist/cli/{chunk-TT4JUUC3.mjs → chunk-DVDWAC2M.mjs} +7 -3
- package/dist/cli/{chunk-5CAVURVS.js → chunk-DYDHLBSK.js} +53 -53
- package/dist/cli/{chunk-UNDLNT3V.js → chunk-ECWOIXAV.js} +1 -1
- package/dist/cli/{chunk-EHLCWGWN.js → chunk-G26VJCNT.js} +4 -4
- package/dist/cli/{chunk-WL2GUGNZ.js → chunk-GQHRGBHV.js} +7 -7
- package/dist/cli/{chunk-DADH3WPE.mjs → chunk-GV45TTI6.mjs} +2 -2
- package/dist/cli/{chunk-OVX3Q5Q3.mjs → chunk-GWNYLIF7.mjs} +1 -1
- package/dist/cli/{chunk-EGOCGWCI.mjs → chunk-H4SAHB3Q.mjs} +3 -3
- package/dist/cli/{chunk-FX4OWXKK.mjs → chunk-HAQRF6DJ.mjs} +2 -2
- package/dist/cli/{chunk-NLZHLEHD.mjs → chunk-HBSWATOU.mjs} +6 -6
- package/dist/cli/{chunk-ACVTMAW4.mjs → chunk-HVJQF5BI.mjs} +2 -2
- package/dist/cli/{chunk-L2VKAASU.mjs → chunk-HXIR3VQL.mjs} +21 -0
- package/dist/cli/{chunk-Z5YRKX7K.mjs → chunk-HXM2JUGD.mjs} +1 -1
- package/dist/cli/{chunk-JPT6VE54.js → chunk-IFIJ4DBJ.js} +2 -2
- package/dist/cli/{chunk-HAITCPCG.js → chunk-JBWOE6AP.js} +16 -16
- package/dist/cli/{chunk-AWLPERL3.js → chunk-JWVG7ZPX.js} +3 -3
- package/dist/cli/{chunk-3XXXMSSP.js → chunk-KE6CSCUF.js} +44 -44
- package/dist/cli/{chunk-2ZGSHVZE.mjs → chunk-LPUBBUKX.mjs} +24 -4
- package/dist/cli/{chunk-PLIKPGOO.mjs → chunk-LQ6RRYXN.mjs} +5 -5
- package/dist/cli/{chunk-FFDZT255.mjs → chunk-LW274RO7.mjs} +1 -1
- package/dist/cli/{chunk-Z2XA6YU4.mjs → chunk-LX35AXTN.mjs} +1 -0
- package/dist/cli/{chunk-FANIRW74.mjs → chunk-NIPLY25A.mjs} +0 -2
- package/dist/cli/{chunk-VHJUH3TB.js → chunk-ON56ISO6.js} +3 -3
- package/dist/cli/{chunk-4I47NCRI.js → chunk-PDJ4UDCO.js} +498 -328
- package/dist/cli/{chunk-SWO5QOXB.mjs → chunk-PFGOCUH3.mjs} +1 -1
- package/dist/cli/{chunk-Q7WDXLYO.js → chunk-PKRW76XG.js} +2 -2
- package/dist/cli/{chunk-YK7NNZD4.mjs → chunk-PMW5YP72.mjs} +37 -190
- package/dist/cli/{chunk-5APOJWJF.mjs → chunk-Q7ZOWNKR.mjs} +183 -13
- package/dist/cli/{chunk-WACIN4PR.mjs → chunk-REEOMNCO.mjs} +3 -3
- package/dist/cli/{chunk-DMXLZ57N.js → chunk-RG34YBDE.js} +2 -2
- package/dist/cli/{chunk-3LEUSRV3.mjs → chunk-RJPDCSTD.mjs} +4 -4
- package/dist/cli/{chunk-IPVRMYWT.js → chunk-RKF263LR.js} +5 -5
- package/dist/cli/{chunk-AUFE624T.js → chunk-RUFR4PUO.js} +10 -10
- package/dist/cli/{chunk-I5EAIFGO.mjs → chunk-SK3HPU2J.mjs} +1 -1
- package/dist/cli/{chunk-ZVNYBQ77.mjs → chunk-SKS53WM6.mjs} +4 -4
- package/dist/cli/{chunk-CQDQNZGH.js → chunk-SL6MYJYM.js} +1 -0
- package/dist/cli/{chunk-E4CABWXL.js → chunk-TI6DTURF.js} +22 -1
- package/dist/cli/{chunk-CFZCRM6R.js → chunk-UHIAQPVA.js} +26 -26
- package/dist/cli/{chunk-D7GWEBMF.js → chunk-UNMNGRPB.js} +7 -7
- package/dist/cli/{chunk-GWHA4DAC.js → chunk-UV4RU2TE.js} +0 -2
- package/dist/cli/{chunk-TTBHOMAA.js → chunk-W7X4KH45.js} +316 -469
- package/dist/cli/chunk-WBSGPLH5.mjs +455 -0
- package/dist/cli/{chunk-SCLP5H4P.mjs → chunk-WUEORIOY.mjs} +1 -1
- package/dist/cli/{chunk-IDDKNMFX.mjs → chunk-Y3T5GWYK.mjs} +153 -14
- package/dist/cli/{chunk-P4MDTBAA.mjs → chunk-YIRVKMON.mjs} +1 -1
- package/dist/cli/{chunk-NDNEARE3.js → chunk-Z44YTSTA.js} +13 -13
- package/dist/cli/{chunk-F6QV42MC.mjs → chunk-Z7SXGOIQ.mjs} +1 -1
- package/dist/cli/{chunk-2VRKBHMD.mjs → chunk-ZHY4T5M6.mjs} +1 -1
- package/dist/cli/{chunk-E7B73LGT.js → chunk-ZY6FL4O4.js} +24 -20
- package/dist/cli/command-docs.js +3 -3
- package/dist/cli/command-docs.mjs +2 -2
- package/dist/cli/{concurrent-runs-help-DIBGMEIN.mjs → concurrent-runs-help-KBWPKSTP.mjs} +7 -7
- package/dist/cli/concurrent-runs-help-TOMLCMV7.js +21 -0
- package/dist/cli/{csv-CAVA3EMS.mjs → csv-M5EBEMZH.mjs} +4 -4
- package/dist/cli/{csv-XZAM7EYZ.js → csv-XGGDZTQI.js} +13 -13
- package/dist/cli/{db-PPGEOBNG.js → db-CVPR54XK.js} +29 -29
- package/dist/cli/{db-HD332QI7.mjs → db-M6FJ6J6E.mjs} +8 -8
- package/dist/cli/describe-RUODIS6M.js +50 -0
- package/dist/cli/describe-X6QA2U3C.mjs +50 -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 +3 -3
- package/dist/cli/describe-core.mjs +2 -2
- package/dist/cli/{executions-AFEOLB4A.mjs → executions-EHTS2XJX.mjs} +8 -8
- package/dist/cli/{executions-4ZKBL7IC.js → executions-VJEEWN22.js} +10 -10
- package/dist/cli/{feedback-J2YPLKMF.mjs → feedback-76VGY4GP.mjs} +6 -6
- package/dist/cli/{feedback-M6Y33JKT.js → feedback-DQPUCUXO.js} +14 -14
- package/dist/cli/{git-632RYEF6.mjs → git-IY6DKKLR.mjs} +5 -5
- package/dist/cli/git-RLHTSYRY.js +25 -0
- package/dist/cli/index.js +150 -146
- package/dist/cli/index.mjs +49 -45
- package/dist/cli/integrations-242LE3TQ.mjs +98 -0
- package/dist/cli/integrations-CQSTIKFY.js +98 -0
- package/dist/cli/{legacy-noops-KWZMXYAU.mjs → legacy-noops-SWTSTMRY.mjs} +6 -6
- package/dist/cli/{legacy-noops-4Y62TKPC.js → legacy-noops-U72DO6ZF.js} +9 -9
- package/dist/cli/{mcp-PESLHAAC.mjs → mcp-JJH6JR52.mjs} +72 -15
- package/dist/cli/{mcp-35QA6YG7.js → mcp-L473BKLJ.js} +89 -32
- package/dist/cli/{monitors-4DTUZLAI.js → monitors-3TF2DOFD.js} +119 -104
- package/dist/cli/{monitors-YVBKBJBU.mjs → monitors-VSYHUBKC.mjs} +26 -11
- package/dist/cli/{org-DJNKMFCZ.mjs → org-S5VIKU2E.mjs} +8 -8
- package/dist/cli/{org-FWCBZMER.js → org-YKVI2ZTI.js} +90 -90
- package/dist/cli/{play-PHVQEEEZ.mjs → play-C7T5A3QM.mjs} +44 -25
- package/dist/cli/{play-FZ45M4KD.js → play-DOWEG45Y.js} +374 -355
- package/dist/cli/{providers-46E67QG7.mjs → providers-BMVVX3VD.mjs} +10 -9
- package/dist/cli/{providers-QJU6FMDD.js → providers-TAZPPFTB.js} +13 -12
- package/dist/cli/{quickstart-6HMJJ4RR.mjs → quickstart-A3WKMKTW.mjs} +4 -4
- package/dist/cli/{quickstart-HOL7H5FS.js → quickstart-HD6FQXGR.js} +6 -6
- package/dist/cli/{run-WKSIRXEC.js → run-BVVV2UX7.js} +49 -48
- package/dist/cli/{run-2W2TJ6QA.mjs → run-FV7TWNOC.mjs} +28 -27
- package/dist/cli/{search-Y2CFLSYB.mjs → search-MGK6WIKS.mjs} +9 -9
- package/dist/cli/search-VJFCWUZN.js +32 -0
- package/dist/cli/{search-output-2IK6ZZDY.js → search-output-6Y7KEPIE.js} +6 -6
- package/dist/cli/{search-output-FCZ35PHF.mjs → search-output-GM7LDZKE.mjs} +4 -4
- package/dist/cli/{secrets-PNPNUZLX.mjs → secrets-4RFAR7YI.mjs} +8 -8
- package/dist/cli/{secrets-JVJIHGU4.js → secrets-SISXIXSZ.js} +17 -17
- package/dist/cli/{sessions-GY5VVQGO.mjs → sessions-CE3OMEG7.mjs} +6 -6
- package/dist/cli/sessions-OWWZJZXH.js +22 -0
- package/dist/cli/{settings-5WHMFRNQ.js → settings-4HPM3K4A.js} +89 -89
- package/dist/cli/{settings-YQOPF3AI.mjs → settings-E22IDSX2.mjs} +16 -16
- package/dist/cli/{setup-3VJMKDEU.js → setup-BDRSNLKX.js} +49 -49
- package/dist/cli/{setup-O5U5IEVW.mjs → setup-BK65MDZ6.mjs} +9 -9
- package/dist/cli/{skills-G6J5PF35.mjs → skills-FI2GZMR4.mjs} +7 -7
- package/dist/cli/skills-ZLBFUAFR.js +36 -0
- package/dist/cli/tools-3K72VE33.js +57 -0
- package/dist/cli/{tools-AG7SWL5Y.mjs → tools-HMMWYUNW.mjs} +20 -19
- package/dist/cli/update-QZV6DH5V.js +34 -0
- package/dist/cli/{update-K73DD6CR.mjs → update-WDKBSXV5.mjs} +9 -9
- package/dist/cli/{views-4D2OTLIO.js → views-775AUDWQ.js} +23 -23
- package/dist/cli/{views-MO6DIOMR.mjs → views-JYIJCO23.mjs} +8 -8
- package/dist/cli/{workflow-ZEMFCS4Y.js → workflow-4H6KQRFQ.js} +19 -19
- package/dist/cli/{workflow-MMZMAELI.mjs → workflow-FKKHE3IU.mjs} +9 -9
- package/dist/{client-DLG9mHDh.d.mts → client-ANT3pyoa.d.mts} +1 -1
- package/dist/{client-X-FJD5Dp.d.ts → client-DD_FyJVd.d.ts} +1 -1
- package/dist/{client-core-WtnqyBwY.d.mts → client-core-Dg9tKhdB.d.mts} +339 -3
- package/dist/{client-core-0jmHfFBv.d.ts → client-core-QHmo73k1.d.ts} +339 -3
- package/dist/{compiler-manifest-Cys06iYg.d.mts → compiler-manifest-BWFtsQIC.d.mts} +21 -0
- package/dist/{compiler-manifest-Cys06iYg.d.ts → compiler-manifest-BWFtsQIC.d.ts} +21 -0
- package/dist/{errors-B6eMjKcr.d.mts → errors-CwKXXtuu.d.mts} +1 -1
- package/dist/{errors-rdOUqcU2.d.ts → errors-Lm9_vJHZ.d.ts} +1 -1
- package/dist/{index-ejWadAL5.d.ts → index-3vJ-V9yw.d.ts} +1 -1
- package/dist/{index-CZdYO81A.d.mts → index-DjwsAt82.d.mts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +12 -12
- package/dist/index.mjs +8 -8
- package/dist/install-integrity.json +147 -133
- 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 +23 -4
- 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 +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 +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +7 -7
- package/dist/server.mjs +5 -5
- package/package.json +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal-resource-usage.ts +0 -222
- package/dist/cli/auth-2PH6RSKL.js +0 -43
- package/dist/cli/concurrent-runs-help-BNIDBKML.js +0 -21
- package/dist/cli/describe-5TFFB2PM.js +0 -49
- package/dist/cli/describe-THQU7N47.mjs +0 -49
- package/dist/cli/git-AQLQYWRI.js +0 -25
- package/dist/cli/search-YLJFCJTK.js +0 -32
- package/dist/cli/sessions-TZ33UCPS.js +0 -22
- package/dist/cli/skills-WZY3XDT3.js +0 -36
- package/dist/cli/tools-BXQBL72Q.js +0 -56
- package/dist/cli/update-XYP5EII6.js +0 -34
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type { PlaySandboxRuntimeLimits } from '../../plays/sandbox-runtime-limits';
|
|
3
|
+
import {
|
|
4
|
+
resolveExperimentSwitch,
|
|
5
|
+
type ExperimentSwitchOverrides,
|
|
6
|
+
} from '../experiment-switches';
|
|
7
|
+
import type {
|
|
8
|
+
RuntimeSandboxProviderCapability,
|
|
9
|
+
RuntimeSandboxProviderId,
|
|
10
|
+
} from '../runtime-sandbox-provider-profile';
|
|
11
|
+
import { samePlaySandboxRuntimeLimits } from './backends/daytona-payload-transport';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Early sandbox: the provider-neutral Module behind early start (E2), runner
|
|
15
|
+
* pre-boot (PB) and in-process adoption (A1). It owns the per-process
|
|
16
|
+
* registry, the org-scoped key and identity refusal, the adoption-age rules,
|
|
17
|
+
* the exact-id reaper and the durable orphan sweep. A provider plugs in
|
|
18
|
+
* through an `EarlySandboxAdapter`: the create call, tag reads and writes,
|
|
19
|
+
* termination, a tag listing, and its pre-boot hooks. Claim affinity (CA/CAR)
|
|
20
|
+
* follows an early sandbox; its claim contract is
|
|
21
|
+
* `scheduler-backends/early-sandbox-claim-affinity.ts`.
|
|
22
|
+
*
|
|
23
|
+
* Which providers support each capability is declared in the Runtime Sandbox
|
|
24
|
+
* Provider Profile (`earlyStart`, `preboot`, `claimAffinity`). A lane whose
|
|
25
|
+
* providers lack one fails loudly: at worker boot for a static switch, and at
|
|
26
|
+
* adapter selection for a per-run one (`scheduler-backends/early-sandbox-lane.ts`).
|
|
27
|
+
*
|
|
28
|
+
* Pure: no provider SDK, scheduler or app imports.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Preview experiment E2: start the run's sandbox right after its admission
|
|
33
|
+
* authenticated and funded it, before the run is enqueued, claimed and
|
|
34
|
+
* launched. The early sandbox carries no token, no payload and no
|
|
35
|
+
* supervisor: only the image, the standard resource profile and a
|
|
36
|
+
* deterministic per-run tag. The launching worker adopts it by exact sandbox
|
|
37
|
+
* id (tag lookup, then re-tag with the ordinary create tags so every cleanup
|
|
38
|
+
* and reconciliation path sees an ordinary sandbox) and then launches as
|
|
39
|
+
* today; otherwise it creates its own. Orphans: a short provider idle
|
|
40
|
+
* timeout, plus an exact-id reaper that terminates the early sandbox if it is
|
|
41
|
+
* still unadopted after the reap delay, plus the durable sweep. Off.
|
|
42
|
+
*/
|
|
43
|
+
export const EARLY_SANDBOX_START = false;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A1 (off): adopting an early sandbox this process created checks the tags
|
|
47
|
+
* this process set instead of reading them back from the provider (one RPC
|
|
48
|
+
* fewer on the launch path, ~20 ms). Only for a fresh entry this process
|
|
49
|
+
* created and has not handed out (the registry's `take`), whose
|
|
50
|
+
* foreign-adoption claim is confirmed on the sandbox; every other adoption
|
|
51
|
+
* reads the tags back. The exit-code read, the identity check and the re-tag
|
|
52
|
+
* are unchanged. Per-run capable (experiment switch A1).
|
|
53
|
+
*/
|
|
54
|
+
export const ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ = false;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* PB (off): with E2 and the baked runner image, the early sandbox also starts
|
|
58
|
+
* the baked runner right after its create, before the run is adopted, so
|
|
59
|
+
* shell start, watchdog setup and runner bundle evaluation (~200-380 ms) are
|
|
60
|
+
* off the launch path. One exec runs, in order: the baked-runner verify guard
|
|
61
|
+
* (verdict line first; a non-ok verdict exits 98 before anything else), the
|
|
62
|
+
* runtime watchdog starting the runner as `--wait-config <configPath>`, and
|
|
63
|
+
* the crash-terminal epilogue, all at fixed per-sandbox paths. It holds no
|
|
64
|
+
* credentials or customer data: no envelope, config or token exists in the
|
|
65
|
+
* sandbox until the run is adopted. The watchdog's runtime/memory limits and
|
|
66
|
+
* the runner's V8 flags are fixed at pre-boot from the early sandbox's own
|
|
67
|
+
* (standard) profile, the same one its `limitsKey` encodes; adoption refuses a
|
|
68
|
+
* run whose limits differ, and staging asserts it again.
|
|
69
|
+
*
|
|
70
|
+
* Adoption (in this process only) delivers the envelope in one exec: stdin to
|
|
71
|
+
* a file (same guard as the inline launch), then the run's files, config LAST
|
|
72
|
+
* via rename; the waiting runner picks it up and proceeds exactly as today
|
|
73
|
+
* (heartbeat, readiness, park fence). Readiness is confirmed as today, and
|
|
74
|
+
* also fails fast (deferred to a new attempt) if the delivery exec fails or
|
|
75
|
+
* the pre-boot chain exits first.
|
|
76
|
+
*
|
|
77
|
+
* Not adopted (an ordinary sandbox is created and this one is reaped): a
|
|
78
|
+
* sandbox whose pre-boot another process started (tag), one whose pre-boot
|
|
79
|
+
* is ambiguous (exec error, late or missing verdict without a confirmed exit
|
|
80
|
+
* 98), one whose pre-boot already exited, one older than
|
|
81
|
+
* EARLY_PREBOOT_MAX_ADOPTION_AGE_MS, or a launch whose PB resolves off. A
|
|
82
|
+
* pre-boot that provably never started (exit 98 confirmed, or no baked plan)
|
|
83
|
+
* is adopted and launched today's way.
|
|
84
|
+
*
|
|
85
|
+
* Orphans: the exact-id reaper (EARLY_SANDBOX_REAP_AFTER_MS, 90 s after
|
|
86
|
+
* create) terminates an unadopted sandbox and the waiting runner with it; the
|
|
87
|
+
* running exec may keep the provider's idle timeout from firing, so the
|
|
88
|
+
* reaper is the killer. If the reap itself fails, the runner gives up its
|
|
89
|
+
* config wait at its own 120 s deadline (runner-app WAIT_CONFIG_TIMEOUT_MS),
|
|
90
|
+
* the chain exits (the epilogue has no crash pusher or config and pushes
|
|
91
|
+
* nothing), and the then-idle sandbox ends at the 60 s idle timeout; the
|
|
92
|
+
* watchdog's own 240 s startup deadline is a later backstop. Adoption itself
|
|
93
|
+
* is ~1-2 s after create, far inside every bound. Per-run capable (experiment
|
|
94
|
+
* switch PB).
|
|
95
|
+
*/
|
|
96
|
+
export const PREBOOT_RUNNER_IN_EARLY_SANDBOX = false;
|
|
97
|
+
|
|
98
|
+
/** Source tag an unadopted early sandbox carries from its create call. */
|
|
99
|
+
export const EARLY_SANDBOX_SOURCE_TAG = 'deepline-play-runner-early';
|
|
100
|
+
/**
|
|
101
|
+
* Source tag of the retired F2 hedged early create (docs/runtime-speed-
|
|
102
|
+
* experiments.md). Nothing creates it now; the reaper and the durable sweep
|
|
103
|
+
* still treat it as unadopted, so a leg left by an older worker is reaped.
|
|
104
|
+
*/
|
|
105
|
+
export const EARLY_SANDBOX_HEDGE_TAG = 'deepline-play-runner-early-hedge';
|
|
106
|
+
/** Orphan guard: an unadopted early sandbox that runs no command ends here. */
|
|
107
|
+
export const EARLY_SANDBOX_IDLE_TIMEOUT_MS = 60_000;
|
|
108
|
+
export const EARLY_SANDBOX_REAP_AFTER_MS = 90_000;
|
|
109
|
+
/**
|
|
110
|
+
* No launch adopts an early sandbox older than this (create request -> adopt
|
|
111
|
+
* check). Kept well under EARLY_SANDBOX_REAP_AFTER_MS so a reaper can never
|
|
112
|
+
* terminate a sandbox that a launch is in the middle of adopting. Adoption is
|
|
113
|
+
* normally ~1-2 s after create.
|
|
114
|
+
*/
|
|
115
|
+
export const EARLY_SANDBOX_MAX_ADOPTION_AGE_MS = 60_000;
|
|
116
|
+
/** Create-request time (epoch ms), set in the create tags. */
|
|
117
|
+
export const EARLY_CREATED_AT_TAG = 'earlyCreatedAtMs';
|
|
118
|
+
/** PB: the pre-boot claim, set in the create tags. */
|
|
119
|
+
export const EARLY_PREBOOT_TAG = 'earlyPreboot';
|
|
120
|
+
/**
|
|
121
|
+
* A pre-boot older than this is not adopted: its watchdog's startup deadline
|
|
122
|
+
* runs from pre-boot, and the runner's config wait has a 120 s deadline.
|
|
123
|
+
*/
|
|
124
|
+
export const EARLY_PREBOOT_MAX_ADOPTION_AGE_MS = 30_000;
|
|
125
|
+
/** Bound on the pre-boot's verdict line, and on its exit after a refusal. */
|
|
126
|
+
export const EARLY_PREBOOT_VERDICT_TIMEOUT_MS = 15_000;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The sandbox calls this Module makes. A provider's sandbox handle already
|
|
130
|
+
* has this shape (Modal's does), or its Adapter wraps one.
|
|
131
|
+
*/
|
|
132
|
+
export type EarlySandboxHandle = {
|
|
133
|
+
readonly sandboxId: string;
|
|
134
|
+
getTags(): Promise<Record<string, string>>;
|
|
135
|
+
setTags(tags: Record<string, string>): Promise<unknown>;
|
|
136
|
+
/** The exit code, or null while the sandbox runs. */
|
|
137
|
+
poll(): Promise<number | null>;
|
|
138
|
+
/** Idempotent. */
|
|
139
|
+
terminate(): Promise<unknown>;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** Provider lookups, bound to the provider app or project. */
|
|
143
|
+
export type EarlySandboxProviderCalls<
|
|
144
|
+
TSandbox extends EarlySandboxHandle = EarlySandboxHandle,
|
|
145
|
+
> = {
|
|
146
|
+
/** Log scope; Modal's is `play-runner.modal.early`. */
|
|
147
|
+
readonly logScope: string;
|
|
148
|
+
fromId(sandboxId: string): Promise<TSandbox>;
|
|
149
|
+
/** Sandboxes carrying every given tag. */
|
|
150
|
+
list(tags: Record<string, string>): AsyncIterable<{ sandboxId: string }>;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type EarlySandboxEntry<TSandbox = EarlySandboxHandle> = {
|
|
154
|
+
sandbox: TSandbox;
|
|
155
|
+
startedAtMs: number;
|
|
156
|
+
/** The tags this process last set on the early sandbox. */
|
|
157
|
+
tags: Record<string, string>;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* This process's unadopted early sandboxes, by org-scoped key. `take` removes
|
|
162
|
+
* the entry, so each early sandbox is handed to at most one in-process
|
|
163
|
+
* adoption; an unadopted entry expires after twice the reap delay.
|
|
164
|
+
*/
|
|
165
|
+
export class EarlySandboxRegistry<TSandbox = EarlySandboxHandle> {
|
|
166
|
+
readonly #entries = new Map<
|
|
167
|
+
string,
|
|
168
|
+
Promise<EarlySandboxEntry<TSandbox> | null>
|
|
169
|
+
>();
|
|
170
|
+
|
|
171
|
+
has(key: string): boolean {
|
|
172
|
+
return this.#entries.has(key);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
put(
|
|
176
|
+
key: string,
|
|
177
|
+
entry: Promise<EarlySandboxEntry<TSandbox> | null>,
|
|
178
|
+
ttlMs: number = EARLY_SANDBOX_REAP_AFTER_MS * 2,
|
|
179
|
+
): void {
|
|
180
|
+
this.#entries.set(key, entry);
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
if (this.#entries.get(key) === entry) this.#entries.delete(key);
|
|
183
|
+
}, ttlMs).unref?.();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
take(key: string): Promise<EarlySandboxEntry<TSandbox> | null> | undefined {
|
|
187
|
+
const entry = this.#entries.get(key);
|
|
188
|
+
this.#entries.delete(key);
|
|
189
|
+
return entry;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The early sandbox's key. Org-scoped: a workflow id is chosen by the caller,
|
|
195
|
+
* so two orgs can name the same one; neither may find the other's sandbox.
|
|
196
|
+
*/
|
|
197
|
+
export function earlySandboxKey(input: {
|
|
198
|
+
orgId: string;
|
|
199
|
+
workflowId: string;
|
|
200
|
+
}): string {
|
|
201
|
+
return createHash('sha256')
|
|
202
|
+
.update(JSON.stringify([input.orgId, input.workflowId]))
|
|
203
|
+
.digest('hex')
|
|
204
|
+
.slice(0, 40);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Why an early sandbox's tags do not belong to this launch's run, or null.
|
|
209
|
+
* Checked on every adoption path, before the sandbox is re-tagged or used.
|
|
210
|
+
*/
|
|
211
|
+
export function earlySandboxIdentityRefusal(
|
|
212
|
+
tags: Record<string, string>,
|
|
213
|
+
expected: { key: string; orgId: string; workflowId: string },
|
|
214
|
+
): 'key_mismatch' | 'org_mismatch' | 'workflow_mismatch' | null {
|
|
215
|
+
if (tags.earlyKey !== expected.key) return 'key_mismatch';
|
|
216
|
+
if (tags.orgId !== expected.orgId) return 'org_mismatch';
|
|
217
|
+
if (tags.workflowId !== expected.workflowId) return 'workflow_mismatch';
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Age of an early sandbox from its create tag; null when it has none. */
|
|
222
|
+
export function earlySandboxAgeMs(
|
|
223
|
+
tags: Record<string, string>,
|
|
224
|
+
nowMs: number,
|
|
225
|
+
): number | null {
|
|
226
|
+
const createdAtMs = Number(tags[EARLY_CREATED_AT_TAG]);
|
|
227
|
+
return Number.isSafeInteger(createdAtMs) && createdAtMs > 0
|
|
228
|
+
? nowMs - createdAtMs
|
|
229
|
+
: null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function earlySandboxLimitsKey(input: {
|
|
233
|
+
cpu: number;
|
|
234
|
+
memoryMiB: number;
|
|
235
|
+
timeoutMs: number;
|
|
236
|
+
}): string {
|
|
237
|
+
return `${input.cpu}:${input.memoryMiB}:${input.timeoutMs}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The create tags of an early sandbox: its source, key, identity and limits. */
|
|
241
|
+
export function earlySandboxCreateTags(input: {
|
|
242
|
+
key: string;
|
|
243
|
+
orgId: string;
|
|
244
|
+
workflowId: string;
|
|
245
|
+
createRequestedAtMs: number;
|
|
246
|
+
limitsKey: string;
|
|
247
|
+
preboot: boolean;
|
|
248
|
+
}): Record<string, string> {
|
|
249
|
+
return {
|
|
250
|
+
source: EARLY_SANDBOX_SOURCE_TAG,
|
|
251
|
+
earlyKey: input.key,
|
|
252
|
+
// Identity, checked at adoption against the launching run.
|
|
253
|
+
orgId: input.orgId,
|
|
254
|
+
workflowId: input.workflowId,
|
|
255
|
+
[EARLY_CREATED_AT_TAG]: String(input.createRequestedAtMs),
|
|
256
|
+
limitsKey: input.limitsKey,
|
|
257
|
+
...(input.preboot ? { [EARLY_PREBOOT_TAG]: '1' } : {}),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function logEarlySandbox(
|
|
262
|
+
logScope: string,
|
|
263
|
+
event: string,
|
|
264
|
+
extra: Record<string, unknown>,
|
|
265
|
+
) {
|
|
266
|
+
console.info(
|
|
267
|
+
`[${logScope}]`,
|
|
268
|
+
JSON.stringify({ event, ...extra, atMs: Date.now() }),
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function logEarlySandboxReapUnconfirmed(input: {
|
|
273
|
+
logScope: string;
|
|
274
|
+
event: string;
|
|
275
|
+
key: string;
|
|
276
|
+
sandboxId: string;
|
|
277
|
+
error: unknown;
|
|
278
|
+
}) {
|
|
279
|
+
// Loud: the sandbox keeps its early tag, so the durable sweep retries it.
|
|
280
|
+
console.error(
|
|
281
|
+
JSON.stringify({
|
|
282
|
+
event: `${input.logScope}.${input.event}`,
|
|
283
|
+
key: input.key,
|
|
284
|
+
sandboxId: input.sandboxId,
|
|
285
|
+
error:
|
|
286
|
+
input.error instanceof Error
|
|
287
|
+
? input.error.message
|
|
288
|
+
: String(input.error),
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export type EarlySandboxStartRequest = {
|
|
294
|
+
workflowId: string;
|
|
295
|
+
orgId?: string | null;
|
|
296
|
+
runtimeSchedulerSchema: string | null;
|
|
297
|
+
/** EXPERIMENT: the hinted run's overrides (E2, PB, S1); absent: static. */
|
|
298
|
+
experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A provider's early-sandbox Adapter. The shared Module decides whether and
|
|
303
|
+
* when; the Adapter makes the provider calls.
|
|
304
|
+
*/
|
|
305
|
+
export type EarlySandboxAdapter<
|
|
306
|
+
TSandbox extends EarlySandboxHandle = EarlySandboxHandle,
|
|
307
|
+
> = {
|
|
308
|
+
readonly provider: RuntimeSandboxProviderId;
|
|
309
|
+
readonly logScope: string;
|
|
310
|
+
/** This process's unadopted early sandboxes on this provider. */
|
|
311
|
+
readonly registry: EarlySandboxRegistry<TSandbox>;
|
|
312
|
+
/**
|
|
313
|
+
* Why this process cannot start an early sandbox on this provider now (a
|
|
314
|
+
* provider precondition), or null. Checked after E2 resolves on; not logged.
|
|
315
|
+
*/
|
|
316
|
+
startUnavailable(): string | null;
|
|
317
|
+
/**
|
|
318
|
+
* Create the early sandbox with `earlySandboxCreateTags`, then arm it: the
|
|
319
|
+
* exact-id reaper (`scheduleEarlySandboxReap`) and any pre-boot hook.
|
|
320
|
+
* Rejects on any failure; the caller logs it and records no entry.
|
|
321
|
+
*/
|
|
322
|
+
createEarly(
|
|
323
|
+
input: EarlySandboxStartRequest & {
|
|
324
|
+
key: string;
|
|
325
|
+
orgId: string;
|
|
326
|
+
hintAtMs: number;
|
|
327
|
+
},
|
|
328
|
+
): Promise<EarlySandboxEntry<TSandbox>>;
|
|
329
|
+
/** The durable orphan sweep pass this worker runs for the provider. */
|
|
330
|
+
sweepOrphansForWorker(input: {
|
|
331
|
+
runtimeSchedulerSchema: string | null;
|
|
332
|
+
}): Promise<EarlySandboxSweepOutcome | { skipped: string }>;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Start (fire and forget) the early sandbox for an admitted run. Idempotent
|
|
337
|
+
* per process; a second hint for the same run is ignored.
|
|
338
|
+
*/
|
|
339
|
+
export function startEarlySandbox<TSandbox extends EarlySandboxHandle>(
|
|
340
|
+
adapter: EarlySandboxAdapter<TSandbox>,
|
|
341
|
+
input: EarlySandboxStartRequest,
|
|
342
|
+
): boolean {
|
|
343
|
+
if (
|
|
344
|
+
!resolveExperimentSwitch(
|
|
345
|
+
'E2',
|
|
346
|
+
input.experimentSwitchOverrides,
|
|
347
|
+
EARLY_SANDBOX_START,
|
|
348
|
+
) ||
|
|
349
|
+
adapter.startUnavailable() !== null
|
|
350
|
+
)
|
|
351
|
+
return false;
|
|
352
|
+
// The key and the adoption check are org-scoped; a hint without an org
|
|
353
|
+
// cannot start a sandbox any launch could safely adopt.
|
|
354
|
+
const orgId = input.orgId?.trim();
|
|
355
|
+
if (!orgId) {
|
|
356
|
+
logEarlySandbox(adapter.logScope, 'hint_refused', { reason: 'no_org' });
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
|
|
360
|
+
if (adapter.registry.has(key)) return false;
|
|
361
|
+
const hintAtMs = Date.now();
|
|
362
|
+
const started = (async () =>
|
|
363
|
+
await adapter.createEarly({ ...input, key, orgId, hintAtMs }))().catch(
|
|
364
|
+
(error: unknown) => {
|
|
365
|
+
logEarlySandbox(adapter.logScope, 'create_failed', {
|
|
366
|
+
key,
|
|
367
|
+
error: error instanceof Error ? error.message : String(error),
|
|
368
|
+
});
|
|
369
|
+
return null;
|
|
370
|
+
},
|
|
371
|
+
);
|
|
372
|
+
adapter.registry.put(key, started);
|
|
373
|
+
logEarlySandbox(adapter.logScope, 'hint_accepted', {
|
|
374
|
+
key,
|
|
375
|
+
workflowId: input.workflowId,
|
|
376
|
+
});
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* An early sandbox on a slow host may not have a running container yet when
|
|
382
|
+
* it is terminated, so its exit code can stay unset for a while (FAST1c: 2 of
|
|
383
|
+
* 12 unconfirmed after ~11 s). Re-terminate and re-read with a backoff capped at
|
|
384
|
+
* 2 s, ~60 s in all, before handing it to the 90 s exact-id reaper.
|
|
385
|
+
*/
|
|
386
|
+
export const EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS = 35;
|
|
387
|
+
const earlyTerminateConfirmDelayMs = (attempt: number) =>
|
|
388
|
+
Math.min(200 * attempt, 2_000);
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Terminate a sandbox by exact id and confirm it by reading its exit code
|
|
392
|
+
* back, re-terminating with a capped backoff (a not-yet-running sandbox may
|
|
393
|
+
* miss a terminate). Returns the attempts it took; throws when the read-back
|
|
394
|
+
* never confirms within `attempts`, or on a provider error.
|
|
395
|
+
*/
|
|
396
|
+
export async function terminateEarlySandboxConfirmed(input: {
|
|
397
|
+
sandbox: Pick<EarlySandboxHandle, 'terminate' | 'sandboxId'>;
|
|
398
|
+
readExitCode: (sandboxId: string) => Promise<number | null>;
|
|
399
|
+
sleep: (ms: number) => Promise<void>;
|
|
400
|
+
attempts: number;
|
|
401
|
+
}): Promise<number> {
|
|
402
|
+
for (let attempt = 1; attempt <= input.attempts; attempt++) {
|
|
403
|
+
// Idempotent; repeated because a not-yet-running sandbox may miss it.
|
|
404
|
+
await input.sandbox.terminate();
|
|
405
|
+
if ((await input.readExitCode(input.sandbox.sandboxId)) !== null)
|
|
406
|
+
return attempt;
|
|
407
|
+
await input.sleep(earlyTerminateConfirmDelayMs(attempt));
|
|
408
|
+
}
|
|
409
|
+
throw new Error('termination not confirmed by read-back');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export const sleepMs = (ms: number) =>
|
|
413
|
+
new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
414
|
+
|
|
415
|
+
/** The exit-code read-back a confirmed termination polls. */
|
|
416
|
+
export const readEarlySandboxExitCode =
|
|
417
|
+
(calls: Pick<EarlySandboxProviderCalls, 'fromId'>) =>
|
|
418
|
+
async (sandboxId: string) =>
|
|
419
|
+
await (await calls.fromId(sandboxId)).poll();
|
|
420
|
+
|
|
421
|
+
export function isUnadoptedEarlySandbox(
|
|
422
|
+
tags: Record<string, string>,
|
|
423
|
+
): boolean {
|
|
424
|
+
return (
|
|
425
|
+
tags.source === EARLY_SANDBOX_SOURCE_TAG ||
|
|
426
|
+
tags.source === EARLY_SANDBOX_HEDGE_TAG
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Reap one early (or hedge) sandbox by exact id if it is still unadopted: a
|
|
432
|
+
* fresh tag read (an adopted sandbox carries ordinary launch tags), then a
|
|
433
|
+
* confirmed termination. An unconfirmed one keeps its early tag, so the
|
|
434
|
+
* durable sweep (sweepOrphanEarlySandboxes) still finds it.
|
|
435
|
+
*/
|
|
436
|
+
export async function reapEarlySandboxById(input: {
|
|
437
|
+
calls: Pick<EarlySandboxProviderCalls, 'fromId' | 'logScope'>;
|
|
438
|
+
key: string;
|
|
439
|
+
sandboxId: string;
|
|
440
|
+
attempts?: number;
|
|
441
|
+
sleep?: (ms: number) => Promise<void>;
|
|
442
|
+
}): Promise<'not_early' | 'terminated'> {
|
|
443
|
+
const fresh = await input.calls.fromId(input.sandboxId);
|
|
444
|
+
if (!isUnadoptedEarlySandbox(await fresh.getTags())) return 'not_early';
|
|
445
|
+
const confirmAttempts = await terminateEarlySandboxConfirmed({
|
|
446
|
+
sandbox: fresh,
|
|
447
|
+
readExitCode: readEarlySandboxExitCode(input.calls),
|
|
448
|
+
sleep: input.sleep ?? sleepMs,
|
|
449
|
+
attempts: input.attempts ?? EARLY_SANDBOX_TERMINATE_CONFIRM_ATTEMPTS,
|
|
450
|
+
});
|
|
451
|
+
logEarlySandbox(input.calls.logScope, 'reaped_unadopted', {
|
|
452
|
+
key: input.key,
|
|
453
|
+
sandboxId: input.sandboxId,
|
|
454
|
+
confirmAttempts,
|
|
455
|
+
});
|
|
456
|
+
return 'terminated';
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* In-process exact-id reaper: after EARLY_SANDBOX_REAP_AFTER_MS, terminate the
|
|
461
|
+
* sandbox (confirmed) if it still carries an early (or hedge) tag, i.e. no
|
|
462
|
+
* launch adopted it. The fast path only: the durable guarantee is the early
|
|
463
|
+
* tag itself, set by the create call, which the worker's sweep reads even
|
|
464
|
+
* after this process is gone.
|
|
465
|
+
*/
|
|
466
|
+
export function scheduleEarlySandboxReap(input: {
|
|
467
|
+
calls: Pick<EarlySandboxProviderCalls, 'fromId' | 'logScope'>;
|
|
468
|
+
key: string;
|
|
469
|
+
sandboxId: string;
|
|
470
|
+
}): void {
|
|
471
|
+
const reap = setTimeout(() => {
|
|
472
|
+
void reapEarlySandboxById(input).catch((error: unknown) =>
|
|
473
|
+
logEarlySandboxReapUnconfirmed({
|
|
474
|
+
logScope: input.calls.logScope,
|
|
475
|
+
event: 'reap_unconfirmed',
|
|
476
|
+
key: input.key,
|
|
477
|
+
sandboxId: input.sandboxId,
|
|
478
|
+
error,
|
|
479
|
+
}),
|
|
480
|
+
);
|
|
481
|
+
}, EARLY_SANDBOX_REAP_AFTER_MS);
|
|
482
|
+
reap.unref?.();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Durable orphan cleanup for E2/PB early sandboxes (and retired F2 legs). The
|
|
487
|
+
* cleanup obligation is recorded before (atomically with) every early create:
|
|
488
|
+
* the create request itself carries the early (or hedge) source tag and its
|
|
489
|
+
* create time, and the provider holds those tags for the sandbox's life. The
|
|
490
|
+
* main path's ambiguous-create row cannot be used here: the hint arrives
|
|
491
|
+
* before the run is enqueued, so there is no run row or attempt lease to
|
|
492
|
+
* fence it to. Once adopted, a sandbox carries the run's create tags and the
|
|
493
|
+
* main path's obligation (recorded before adoption) covers it.
|
|
494
|
+
*
|
|
495
|
+
* This pass lists only unadopted early sandboxes (the source-tag selector),
|
|
496
|
+
* skips any younger than EARLY_SANDBOX_REAP_AFTER_MS, re-reads each one's tags
|
|
497
|
+
* by exact id, and terminates it with a bounded confirmation. No launch adopts
|
|
498
|
+
* past EARLY_SANDBOX_MAX_ADOPTION_AGE_MS (60 s < 90 s), so whichever worker
|
|
499
|
+
* created it, an early sandbox this old is an orphan. One not confirmed this
|
|
500
|
+
* pass keeps its tag and is retried by the next.
|
|
501
|
+
*/
|
|
502
|
+
export const EARLY_SANDBOX_SWEEP_INTERVAL_MS = 60_000;
|
|
503
|
+
const EARLY_SANDBOX_SWEEP_LIMIT = 20;
|
|
504
|
+
const EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS = 5;
|
|
505
|
+
|
|
506
|
+
export type EarlySandboxSweepOutcome = {
|
|
507
|
+
observed: number;
|
|
508
|
+
terminated: number;
|
|
509
|
+
unconfirmed: number;
|
|
510
|
+
young: number;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
export async function sweepOrphanEarlySandboxes(input: {
|
|
514
|
+
calls: EarlySandboxProviderCalls;
|
|
515
|
+
nowMs?: () => number;
|
|
516
|
+
sleep?: (ms: number) => Promise<void>;
|
|
517
|
+
limit?: number;
|
|
518
|
+
}): Promise<EarlySandboxSweepOutcome> {
|
|
519
|
+
const nowMs = input.nowMs ?? Date.now;
|
|
520
|
+
const limit = input.limit ?? EARLY_SANDBOX_SWEEP_LIMIT;
|
|
521
|
+
const ids = new Set<string>();
|
|
522
|
+
for (const source of [EARLY_SANDBOX_SOURCE_TAG, EARLY_SANDBOX_HEDGE_TAG]) {
|
|
523
|
+
for await (const listed of input.calls.list({ source })) {
|
|
524
|
+
if (ids.size >= limit) break;
|
|
525
|
+
if (listed.sandboxId?.trim()) ids.add(listed.sandboxId.trim());
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
let terminated = 0;
|
|
529
|
+
let unconfirmed = 0;
|
|
530
|
+
let young = 0;
|
|
531
|
+
await Promise.all(
|
|
532
|
+
[...ids].map(async (sandboxId) => {
|
|
533
|
+
try {
|
|
534
|
+
const fresh = await input.calls.fromId(sandboxId);
|
|
535
|
+
const tags = await fresh.getTags();
|
|
536
|
+
if (!isUnadoptedEarlySandbox(tags)) return;
|
|
537
|
+
const ageMs = earlySandboxAgeMs(tags, nowMs());
|
|
538
|
+
// A sandbox without a create time predates the tag and is past any
|
|
539
|
+
// adoption (adoption refuses it), so it is reaped.
|
|
540
|
+
if (ageMs !== null && ageMs < EARLY_SANDBOX_REAP_AFTER_MS) {
|
|
541
|
+
young += 1;
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const confirmAttempts = await terminateEarlySandboxConfirmed({
|
|
545
|
+
sandbox: fresh,
|
|
546
|
+
readExitCode: readEarlySandboxExitCode(input.calls),
|
|
547
|
+
sleep: input.sleep ?? sleepMs,
|
|
548
|
+
attempts: EARLY_SANDBOX_SWEEP_CONFIRM_ATTEMPTS,
|
|
549
|
+
});
|
|
550
|
+
terminated += 1;
|
|
551
|
+
logEarlySandbox(input.calls.logScope, 'swept_orphan', {
|
|
552
|
+
key: tags.earlyKey ?? null,
|
|
553
|
+
sandboxId,
|
|
554
|
+
ageMs,
|
|
555
|
+
confirmAttempts,
|
|
556
|
+
});
|
|
557
|
+
} catch (error) {
|
|
558
|
+
unconfirmed += 1;
|
|
559
|
+
logEarlySandboxReapUnconfirmed({
|
|
560
|
+
logScope: input.calls.logScope,
|
|
561
|
+
event: 'sweep_unconfirmed',
|
|
562
|
+
key: 'sweep',
|
|
563
|
+
sandboxId,
|
|
564
|
+
error,
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}),
|
|
568
|
+
);
|
|
569
|
+
return { observed: ids.size, terminated, unconfirmed, young };
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** PB: the runner limits a pre-boot fixed, which a launch must match. */
|
|
573
|
+
export type EarlySandboxPrebootRunner = {
|
|
574
|
+
sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
|
|
575
|
+
memoryLimitMiB?: number;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
export type EarlySandboxPreboot<
|
|
579
|
+
TRunner extends EarlySandboxPrebootRunner = EarlySandboxPrebootRunner,
|
|
580
|
+
> =
|
|
581
|
+
| {
|
|
582
|
+
status: 'running';
|
|
583
|
+
runner: TRunner;
|
|
584
|
+
/** The pre-boot chain's exit code (runner, then epilogue). */
|
|
585
|
+
exited: Promise<number>;
|
|
586
|
+
/** Set once `exited` settles with a code. */
|
|
587
|
+
exitCode: number | null;
|
|
588
|
+
startedAtMs: number;
|
|
589
|
+
}
|
|
590
|
+
/** Provably nothing ran: today's launch may use this sandbox. */
|
|
591
|
+
| { status: 'not_started'; reason: string }
|
|
592
|
+
/** Cannot prove what ran: never adopted. */
|
|
593
|
+
| { status: 'ambiguous'; reason: string };
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* PB: why an in-process early sandbox with a pre-boot must not be adopted by
|
|
597
|
+
* this launch, or null when it may be (a running pre-boot this launch will
|
|
598
|
+
* deliver to, or one that provably never started).
|
|
599
|
+
*/
|
|
600
|
+
export function earlyPrebootAdoptionRefusal(input: {
|
|
601
|
+
preboot: EarlySandboxPreboot;
|
|
602
|
+
wanted: boolean;
|
|
603
|
+
sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
|
|
604
|
+
memoryLimitMiB?: number;
|
|
605
|
+
nowMs: number;
|
|
606
|
+
}): string | null {
|
|
607
|
+
const { preboot } = input;
|
|
608
|
+
if (preboot.status === 'not_started') return null;
|
|
609
|
+
if (preboot.status === 'ambiguous') return 'preboot_ambiguous';
|
|
610
|
+
// A running runner nobody will deliver to would share the sandbox with
|
|
611
|
+
// today's launch.
|
|
612
|
+
if (!input.wanted) return 'preboot_unwanted';
|
|
613
|
+
if (preboot.exitCode !== null) return 'preboot_exited';
|
|
614
|
+
if (input.nowMs - preboot.startedAtMs > EARLY_PREBOOT_MAX_ADOPTION_AGE_MS)
|
|
615
|
+
return 'preboot_stale';
|
|
616
|
+
if (
|
|
617
|
+
!samePlaySandboxRuntimeLimits(
|
|
618
|
+
preboot.runner.sandboxRuntimeLimits,
|
|
619
|
+
input.sandboxRuntimeLimits,
|
|
620
|
+
) ||
|
|
621
|
+
preboot.runner.memoryLimitMiB !== input.memoryLimitMiB
|
|
622
|
+
)
|
|
623
|
+
return 'preboot_limits_mismatch';
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Adopt this run's early sandbox by exact id, or return null so the launch
|
|
629
|
+
* creates its own. The in-process promise is awaited when this worker started
|
|
630
|
+
* it; otherwise one tag listing finds a sandbox another worker started. The
|
|
631
|
+
* key is org-scoped, and every path checks the sandbox's org and workflow
|
|
632
|
+
* tags against this run before re-tagging it; a mismatch is refused loudly.
|
|
633
|
+
*/
|
|
634
|
+
export async function adoptEarlySandbox<
|
|
635
|
+
TSandbox extends EarlySandboxHandle,
|
|
636
|
+
>(input: {
|
|
637
|
+
calls: EarlySandboxProviderCalls<TSandbox>;
|
|
638
|
+
/** This process's early sandboxes on this provider. */
|
|
639
|
+
registry: EarlySandboxRegistry<TSandbox>;
|
|
640
|
+
workflowId: string;
|
|
641
|
+
orgId: string | null | undefined;
|
|
642
|
+
runId: string | null | undefined;
|
|
643
|
+
experimentSwitchOverrides: ExperimentSwitchOverrides | null | undefined;
|
|
644
|
+
expectedLimitsKey: string;
|
|
645
|
+
createTags: Record<string, string>;
|
|
646
|
+
/** PB: whether this launch wants a pre-booted runner, and its limits. */
|
|
647
|
+
preboot: {
|
|
648
|
+
wanted: boolean;
|
|
649
|
+
sandboxRuntimeLimits: PlaySandboxRuntimeLimits;
|
|
650
|
+
memoryLimitMiB?: number;
|
|
651
|
+
};
|
|
652
|
+
/**
|
|
653
|
+
* Provider claims a sandbox started by another process may carry, checked
|
|
654
|
+
* in order before the pre-boot claim; each bars adoption from here.
|
|
655
|
+
*/
|
|
656
|
+
foreignClaimTags?: readonly { tag: string; reason: string }[];
|
|
657
|
+
/** PB hook: this process's pre-boot on an in-process sandbox, if any. */
|
|
658
|
+
inProcessPreboot(sandbox: TSandbox): Promise<EarlySandboxPreboot> | undefined;
|
|
659
|
+
/**
|
|
660
|
+
* A1 hook: settles once a tag that makes every other process refuse to
|
|
661
|
+
* adopt the sandbox is on it at the provider.
|
|
662
|
+
*/
|
|
663
|
+
inProcessForeignAdoptionClaim(sandbox: TSandbox): Promise<unknown> | undefined;
|
|
664
|
+
/** The launch's stage events (`early:adopted`, `early:adopt_miss`). */
|
|
665
|
+
emitStage(stage: string, extra: Record<string, unknown>): void;
|
|
666
|
+
nowMs?: () => number;
|
|
667
|
+
}): Promise<TSandbox | null> {
|
|
668
|
+
const nowMs = input.nowMs ?? Date.now;
|
|
669
|
+
const startedAt = nowMs();
|
|
670
|
+
const orgId = input.orgId?.trim();
|
|
671
|
+
if (!orgId) {
|
|
672
|
+
input.emitStage('early:adopt_miss', {
|
|
673
|
+
reason: 'no_org',
|
|
674
|
+
elapsedMs: 0,
|
|
675
|
+
});
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
const key = earlySandboxKey({ orgId, workflowId: input.workflowId });
|
|
679
|
+
const registry = input.registry;
|
|
680
|
+
let sandbox: TSandbox | null = null;
|
|
681
|
+
let localEntry: EarlySandboxEntry<TSandbox> | null = null;
|
|
682
|
+
let how = 'none';
|
|
683
|
+
try {
|
|
684
|
+
// Taken, not read: this entry is handed to this one adoption only.
|
|
685
|
+
const local = registry.take(key);
|
|
686
|
+
if (local) {
|
|
687
|
+
localEntry = await local;
|
|
688
|
+
sandbox = localEntry?.sandbox ?? null;
|
|
689
|
+
how = 'in_process';
|
|
690
|
+
}
|
|
691
|
+
if (!sandbox) {
|
|
692
|
+
for await (const listed of input.calls.list({
|
|
693
|
+
source: EARLY_SANDBOX_SOURCE_TAG,
|
|
694
|
+
earlyKey: key,
|
|
695
|
+
})) {
|
|
696
|
+
sandbox = await input.calls.fromId(listed.sandboxId);
|
|
697
|
+
how = 'by_tag';
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (!sandbox) {
|
|
702
|
+
input.emitStage('early:adopt_miss', {
|
|
703
|
+
key,
|
|
704
|
+
reason: 'not_found',
|
|
705
|
+
elapsedMs: nowMs() - startedAt,
|
|
706
|
+
});
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
// A1 may skip the read only for this process's own, fresh, untaken entry
|
|
710
|
+
// whose foreign-adoption claim is confirmed on the sandbox: then no other
|
|
711
|
+
// process can have adopted (re-tagged) it. Everything else is read back.
|
|
712
|
+
const foreignClaim =
|
|
713
|
+
how === 'in_process'
|
|
714
|
+
? input.inProcessForeignAdoptionClaim(sandbox)
|
|
715
|
+
: undefined;
|
|
716
|
+
const trustLocalTags =
|
|
717
|
+
how === 'in_process' &&
|
|
718
|
+
localEntry !== null &&
|
|
719
|
+
nowMs() - localEntry.startedAtMs < EARLY_SANDBOX_MAX_ADOPTION_AGE_MS &&
|
|
720
|
+
resolveExperimentSwitch(
|
|
721
|
+
'A1',
|
|
722
|
+
input.experimentSwitchOverrides,
|
|
723
|
+
ADOPT_IN_PROCESS_EARLY_SANDBOX_WITHOUT_TAG_READ,
|
|
724
|
+
) &&
|
|
725
|
+
foreignClaim !== undefined &&
|
|
726
|
+
(await foreignClaim.then(
|
|
727
|
+
() => true,
|
|
728
|
+
() => false,
|
|
729
|
+
));
|
|
730
|
+
const tags =
|
|
731
|
+
trustLocalTags && localEntry ? localEntry.tags : await sandbox.getTags();
|
|
732
|
+
const identityRefusal = earlySandboxIdentityRefusal(tags, {
|
|
733
|
+
key,
|
|
734
|
+
orgId,
|
|
735
|
+
workflowId: input.workflowId,
|
|
736
|
+
});
|
|
737
|
+
if (identityRefusal) {
|
|
738
|
+
// Never expected: the key already names this org and workflow. Loud,
|
|
739
|
+
// and the sandbox is left untouched for its own reaper.
|
|
740
|
+
console.error(
|
|
741
|
+
JSON.stringify({
|
|
742
|
+
event: `${input.calls.logScope}.adopt_refused_identity`,
|
|
743
|
+
reason: identityRefusal,
|
|
744
|
+
key,
|
|
745
|
+
how,
|
|
746
|
+
sandboxId: sandbox.sandboxId,
|
|
747
|
+
runId: input.runId ?? null,
|
|
748
|
+
}),
|
|
749
|
+
);
|
|
750
|
+
input.emitStage('early:adopt_miss', {
|
|
751
|
+
key,
|
|
752
|
+
reason: identityRefusal,
|
|
753
|
+
sandboxId: sandbox.sandboxId,
|
|
754
|
+
elapsedMs: nowMs() - startedAt,
|
|
755
|
+
});
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
const ageMs =
|
|
759
|
+
how === 'in_process' && localEntry
|
|
760
|
+
? nowMs() - localEntry.startedAtMs
|
|
761
|
+
: earlySandboxAgeMs(tags, nowMs());
|
|
762
|
+
if (ageMs === null || ageMs >= EARLY_SANDBOX_MAX_ADOPTION_AGE_MS) {
|
|
763
|
+
// Past the adoption window the reapers own it.
|
|
764
|
+
input.emitStage('early:adopt_miss', {
|
|
765
|
+
key,
|
|
766
|
+
reason: 'early_stale',
|
|
767
|
+
sandboxId: sandbox.sandboxId,
|
|
768
|
+
ageMs,
|
|
769
|
+
elapsedMs: nowMs() - startedAt,
|
|
770
|
+
});
|
|
771
|
+
return null;
|
|
772
|
+
}
|
|
773
|
+
// PB: another process started a runner here and holds its delivery
|
|
774
|
+
// plan; nothing may be delivered to it from this process. Provider
|
|
775
|
+
// claims (Modal's S1 sidecar) come first.
|
|
776
|
+
for (const claim of [
|
|
777
|
+
...(input.foreignClaimTags ?? []),
|
|
778
|
+
{ tag: EARLY_PREBOOT_TAG, reason: 'early_preboot_foreign' },
|
|
779
|
+
]) {
|
|
780
|
+
if (how !== 'in_process' && tags[claim.tag]) {
|
|
781
|
+
input.emitStage('early:adopt_miss', {
|
|
782
|
+
key,
|
|
783
|
+
reason: claim.reason,
|
|
784
|
+
sandboxId: sandbox.sandboxId,
|
|
785
|
+
elapsedMs: nowMs() - startedAt,
|
|
786
|
+
});
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const prebootPending =
|
|
791
|
+
how === 'in_process' ? input.inProcessPreboot(sandbox) : undefined;
|
|
792
|
+
const prebootRefusal = prebootPending
|
|
793
|
+
? earlyPrebootAdoptionRefusal({
|
|
794
|
+
preboot: await prebootPending,
|
|
795
|
+
...input.preboot,
|
|
796
|
+
nowMs: Date.now(),
|
|
797
|
+
})
|
|
798
|
+
: null;
|
|
799
|
+
if (prebootRefusal) {
|
|
800
|
+
input.emitStage('early:adopt_miss', {
|
|
801
|
+
key,
|
|
802
|
+
reason: prebootRefusal,
|
|
803
|
+
sandboxId: sandbox.sandboxId,
|
|
804
|
+
elapsedMs: nowMs() - startedAt,
|
|
805
|
+
});
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
if (
|
|
809
|
+
tags.source !== EARLY_SANDBOX_SOURCE_TAG ||
|
|
810
|
+
tags.earlyKey !== key ||
|
|
811
|
+
tags.limitsKey !== input.expectedLimitsKey ||
|
|
812
|
+
(await sandbox.poll()) !== null
|
|
813
|
+
) {
|
|
814
|
+
input.emitStage('early:adopt_miss', {
|
|
815
|
+
key,
|
|
816
|
+
reason: 'mismatch_or_exited',
|
|
817
|
+
sandboxId: sandbox.sandboxId,
|
|
818
|
+
elapsedMs: nowMs() - startedAt,
|
|
819
|
+
});
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
// Re-tag first: from here the sandbox is an ordinary launch sandbox for
|
|
823
|
+
// every cleanup and reconciliation path, and the reaper skips it.
|
|
824
|
+
await sandbox.setTags({ ...input.createTags, earlyKey: key });
|
|
825
|
+
input.emitStage('early:adopted', {
|
|
826
|
+
key,
|
|
827
|
+
how,
|
|
828
|
+
sandboxId: sandbox.sandboxId,
|
|
829
|
+
elapsedMs: nowMs() - startedAt,
|
|
830
|
+
});
|
|
831
|
+
return sandbox;
|
|
832
|
+
} catch (error) {
|
|
833
|
+
input.emitStage('early:adopt_miss', {
|
|
834
|
+
key,
|
|
835
|
+
reason: 'error',
|
|
836
|
+
error: error instanceof Error ? error.message : String(error),
|
|
837
|
+
elapsedMs: nowMs() - startedAt,
|
|
838
|
+
});
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* The early-sandbox switches a run (or, for the static defaults, a lane)
|
|
845
|
+
* resolves on. `claimAffinity` is CA's per-run value or the worker's CAR.
|
|
846
|
+
*/
|
|
847
|
+
export type EarlySandboxSwitches = Readonly<{
|
|
848
|
+
earlyStart: boolean;
|
|
849
|
+
preboot: boolean;
|
|
850
|
+
claimAffinity: boolean;
|
|
851
|
+
}>;
|
|
852
|
+
|
|
853
|
+
/** The provider capabilities these switches need: one per switch that is on. */
|
|
854
|
+
export function earlySandboxRequiredCapabilities(
|
|
855
|
+
switches: EarlySandboxSwitches,
|
|
856
|
+
): RuntimeSandboxProviderCapability[] {
|
|
857
|
+
const required: RuntimeSandboxProviderCapability[] = [];
|
|
858
|
+
if (switches.earlyStart) required.push('earlyStart');
|
|
859
|
+
if (switches.preboot) required.push('preboot');
|
|
860
|
+
if (switches.claimAffinity) required.push('claimAffinity');
|
|
861
|
+
return required;
|
|
862
|
+
}
|