deepline 0.3.537 → 0.3.539
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 +22 -5
- package/dist/bundling-sources/sdk/src/index.ts +2 -0
- package/dist/bundling-sources/sdk/src/plays/client-core.ts +18 -1
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +33 -4
- package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +1 -1
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +9 -1
- package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +392 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +717 -133
- package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +22 -1
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +123 -0
- package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +480 -0
- package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +24 -16
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +293 -53
- package/dist/bundling-sources/shared_libs/play-runtime/governor/block-reserving-budget-state-backend.ts +57 -2
- package/dist/bundling-sources/shared_libs/play-runtime/governor/budget-state-backend.ts +43 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +141 -9
- package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/modal-supervisor-sidecar.ts +556 -0
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +19 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +155 -7
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/relay-connection-counter.ts +103 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +75 -6
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +59 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +544 -73
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +8 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +19 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2399 -110
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-flow.ts +42 -8
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-read-through.ts +287 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-finish.ts +606 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +274 -119
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +136 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-traffic-policy.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-work-counters.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +22 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +18 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +18 -4
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +219 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +340 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +623 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +340 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +61 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +269 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +238 -5
- package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +47 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +5 -4
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +11 -0
- package/dist/cli/auth-O5Y2VYXK.js +43 -0
- package/dist/cli/{auth-4SUPGDIM.mjs → auth-QD7QGD3B.mjs} +5 -5
- package/dist/cli/{billing-5JUA3ZM3.mjs → billing-FIZXMHBW.mjs} +31 -7
- package/dist/cli/{billing-SQU726P7.js → billing-KOQAF6WS.js} +114 -90
- package/dist/cli/{chunk-R7JYG6XO.mjs → chunk-2XMFT44N.mjs} +1 -1
- package/dist/cli/{chunk-XDS26J7Z.js → chunk-3YDI2PTN.js} +10 -10
- package/dist/cli/{chunk-KH27B2HJ.mjs → chunk-55ITVU2V.mjs} +2 -2
- package/dist/cli/{chunk-2Q7VXTMS.js → chunk-5QL4GJB2.js} +2 -2
- package/dist/cli/{chunk-D77W6Q67.js → chunk-5RUB53KG.js} +26 -26
- package/dist/cli/{chunk-JS2SBCWD.js → chunk-5YF35HAV.js} +6 -6
- package/dist/cli/{chunk-C37VELBR.mjs → chunk-6KG4KVTH.mjs} +5 -5
- package/dist/cli/{chunk-AX2OAXDL.mjs → chunk-6NZBLFL4.mjs} +1 -1
- package/dist/cli/{chunk-C3XD2WHM.mjs → chunk-6V3LNYK5.mjs} +2 -2
- package/dist/cli/{chunk-GPMS6OPX.mjs → chunk-ADV2IB2C.mjs} +5 -5
- package/dist/cli/{chunk-ZUAMXZXC.mjs → chunk-APKZGUTU.mjs} +4 -4
- package/dist/cli/{chunk-IQOIT6E3.js → chunk-CQJCLHBE.js} +41 -41
- package/dist/cli/{chunk-W3J3LT22.mjs → chunk-DZFVVP3S.mjs} +5 -5
- package/dist/cli/{chunk-V5IIBG2E.mjs → chunk-E4QHTDPF.mjs} +1 -1
- package/dist/cli/{chunk-CXTW7SRW.mjs → chunk-E7D37PLM.mjs} +8 -0
- package/dist/cli/{chunk-KULT6O5K.js → chunk-EAZS52DL.js} +15 -15
- package/dist/cli/{chunk-L3JVGNAT.mjs → chunk-F43MXIN3.mjs} +2 -2
- package/dist/cli/{chunk-WBTYWJLN.js → chunk-FH3P3E4S.js} +2 -2
- package/dist/cli/{chunk-K4WJ4BYO.mjs → chunk-FIRV7BXJ.mjs} +1 -1
- package/dist/cli/{chunk-NXGLJGPB.js → chunk-FSQCB5SJ.js} +2 -2
- package/dist/cli/{chunk-AVQET3NR.js → chunk-FTBWFDF3.js} +7 -7
- package/dist/cli/{chunk-QDBGPRR2.mjs → chunk-G3UFDUYU.mjs} +3 -1
- package/dist/cli/{chunk-ZHPSJ3LJ.mjs → chunk-GEO2EMM7.mjs} +29 -16
- package/dist/cli/{chunk-CGDW2CRR.mjs → chunk-GLEGINSP.mjs} +2 -2
- package/dist/cli/{chunk-EEFSUCYP.mjs → chunk-GLKUC5PO.mjs} +2 -2
- package/dist/cli/{chunk-BFHR7IC2.mjs → chunk-GNCIMHO2.mjs} +10 -10
- package/dist/cli/{chunk-PU42VOBI.js → chunk-ISXX5DUD.js} +3 -3
- package/dist/cli/{chunk-Y6AMMXWS.mjs → chunk-JBCQFG7G.mjs} +3 -3
- package/dist/cli/{chunk-Z2PPB3IO.mjs → chunk-JHEZQMOM.mjs} +1 -1
- package/dist/cli/{chunk-WBFOV5HT.js → chunk-K22EKW6L.js} +5 -5
- package/dist/cli/{chunk-CHIGEDAE.js → chunk-K5MZHTK7.js} +3 -3
- package/dist/cli/{chunk-L6QAIZNZ.js → chunk-KAEVL62Q.js} +44 -44
- package/dist/cli/{chunk-PJ4ZGZAN.js → chunk-KQTX545E.js} +13 -13
- package/dist/cli/{chunk-VP2K5B3R.mjs → chunk-LE5KN7CZ.mjs} +3 -3
- package/dist/cli/{chunk-BGXEMTIG.js → chunk-LEREPTAE.js} +19 -19
- package/dist/cli/{chunk-QPDLG7DQ.js → chunk-MI53W4DN.js} +53 -53
- package/dist/cli/{chunk-RMVZTBI5.mjs → chunk-MKESK3SW.mjs} +4 -4
- package/dist/cli/{chunk-NU7B5X6J.mjs → chunk-N3LPGGWD.mjs} +1 -1
- package/dist/cli/{chunk-VRYX2BR4.js → chunk-NR5PLMNG.js} +107 -107
- package/dist/cli/{chunk-JMHYDDBQ.js → chunk-Q4HNK7JX.js} +292 -279
- package/dist/cli/{chunk-37AZHCTP.mjs → chunk-RULRGMMM.mjs} +5 -5
- package/dist/cli/{chunk-GI3V4D7K.mjs → chunk-SDAP5MCO.mjs} +2 -2
- package/dist/cli/{chunk-5EOEJKSV.js → chunk-TZBCJHV6.js} +1 -1
- package/dist/cli/{chunk-3PMCQ3LK.js → chunk-V7DEGIYO.js} +7 -5
- package/dist/cli/{chunk-ALHKB3AE.js → chunk-VK5UTS5B.js} +9 -9
- package/dist/cli/{chunk-ZFSB7GXF.js → chunk-W32KT6LM.js} +5 -5
- package/dist/cli/{chunk-6BBGUQJJ.js → chunk-XTYHZEJ2.js} +8 -0
- package/dist/cli/{chunk-UGA5KI4A.js → chunk-XZBXQCRJ.js} +22 -22
- package/dist/cli/{chunk-BRRCWUOW.mjs → chunk-Y66ZMOJI.mjs} +1 -1
- package/dist/cli/{chunk-CFND2ACL.js → chunk-YMQFQO3K.js} +16 -16
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-JITYN27L.js → csv-BWWJYV2C.js} +13 -13
- package/dist/cli/{csv-HZP6QMG7.mjs → csv-G5RQQ74W.mjs} +4 -4
- package/dist/cli/{db-FYSRB7O4.js → db-5KNDLADE.js} +27 -27
- package/dist/cli/{db-QRIRTOMM.mjs → db-AJZHWB3V.mjs} +6 -6
- package/dist/cli/describe-B6CN6CFJ.js +49 -0
- package/dist/cli/{describe-REXJVJC3.mjs → describe-QY5TKWVD.mjs} +17 -17
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/{executions-BSTF4DDS.js → executions-BCCW76BI.js} +8 -8
- package/dist/cli/{executions-53KJAFOW.mjs → executions-SJPH3MZT.mjs} +6 -6
- package/dist/cli/{feedback-6MW3QOXX.js → feedback-GF65JKK6.js} +14 -14
- package/dist/cli/{feedback-CWUJJF3J.mjs → feedback-S6SZOFGK.mjs} +6 -6
- package/dist/cli/git-DX6NB7VF.js +25 -0
- package/dist/cli/{git-CKVZTJFS.mjs → git-F5FT5YVB.mjs} +5 -5
- package/dist/cli/index.js +143 -143
- package/dist/cli/index.mjs +42 -42
- package/dist/cli/{legacy-noops-QBL4PNGB.js → legacy-noops-ECR6FS6U.js} +9 -9
- package/dist/cli/{legacy-noops-USTBRFRX.mjs → legacy-noops-NOA4P5NE.mjs} +6 -6
- package/dist/cli/{monitors-6UCG5D7W.mjs → monitors-CTYSAGP4.mjs} +7 -7
- package/dist/cli/{monitors-VCR6SUZD.js → monitors-DEWBSURN.js} +100 -100
- package/dist/cli/{org-GSRBOJVO.mjs → org-EKSKKT7H.mjs} +6 -6
- package/dist/cli/{org-HPILTEG4.js → org-ZM2UUMZZ.js} +86 -86
- package/dist/cli/{play-TK7WOP5H.js → play-6JQOM6DE.js} +317 -317
- package/dist/cli/{play-QRTYQNG4.mjs → play-R2BH374J.mjs} +17 -17
- package/dist/cli/{providers-HEXNJ5QC.js → providers-CMIYHEMN.js} +9 -9
- package/dist/cli/{providers-OAQJWVBS.mjs → providers-X7WMIWO4.mjs} +6 -6
- package/dist/cli/{quickstart-PYZTFXZX.js → quickstart-6HVPAMSW.js} +6 -6
- package/dist/cli/{quickstart-FFVHTPSP.mjs → quickstart-ZZ7L6VZJ.mjs} +4 -4
- package/dist/cli/{run-HLN6YYZH.mjs → run-FP32RKBU.mjs} +22 -22
- package/dist/cli/{run-4DWJXJRO.js → run-OOHYH3GI.js} +42 -42
- package/dist/cli/search-34C6LFOJ.js +32 -0
- package/dist/cli/{search-ZHRCXGEL.mjs → search-BDDNC23Z.mjs} +7 -7
- package/dist/cli/{search-output-2KY6PFDH.js → search-output-5VZIQQAM.js} +6 -6
- package/dist/cli/{search-output-N7QXACVK.mjs → search-output-QXJ6CV5G.mjs} +4 -4
- package/dist/cli/{secrets-WXQ7XO5C.js → secrets-EN2HQCO3.js} +15 -15
- package/dist/cli/{secrets-FKMWBLHU.mjs → secrets-Z7CQSQGC.mjs} +6 -6
- package/dist/cli/{sessions-3YDTEDA5.mjs → sessions-I2H37OTJ.mjs} +6 -6
- package/dist/cli/sessions-RYQX3NDD.js +22 -0
- package/dist/cli/{settings-67TWLQ6E.js → settings-CTRAPFNZ.js} +85 -85
- package/dist/cli/{settings-JTPASUZN.mjs → settings-IYSC5PPQ.mjs} +12 -12
- package/dist/cli/{setup-VYNGXUJ6.mjs → setup-PU3HOVI3.mjs} +9 -9
- package/dist/cli/{setup-KUERQJUX.js → setup-XIN53GEW.js} +49 -49
- package/dist/cli/skills-576CX7DK.js +36 -0
- package/dist/cli/{skills-KI4KYHH6.mjs → skills-TYBML2ZO.mjs} +7 -7
- package/dist/cli/tools-EXMUWA3Z.js +56 -0
- package/dist/cli/{tools-UQDJS2RS.mjs → tools-ZVNE6M6J.mjs} +16 -16
- package/dist/cli/{update-7FQQUBOD.mjs → update-54WENBNT.mjs} +9 -9
- package/dist/cli/update-RAHETNL2.js +34 -0
- package/dist/cli/{views-MJK7JGZG.js → views-7L75EZOJ.js} +21 -21
- package/dist/cli/{views-JAM4MNNV.mjs → views-EUBB4ONT.mjs} +6 -6
- package/dist/cli/{workflow-AQPRIWQX.js → workflow-EZVYCR6Y.js} +17 -17
- package/dist/cli/{workflow-TQRV5FGO.mjs → workflow-GUKGFJ72.mjs} +7 -7
- package/dist/{client-BlLYQDNo.d.mts → client-D0uDBybG.d.mts} +1 -1
- package/dist/{client-DSQlkIDO.d.ts → client-DZTnAv4B.d.ts} +1 -1
- package/dist/{client-core-rX7n2H8U.d.mts → client-core-BhWf8Y1b.d.mts} +15 -2
- package/dist/{client-core-CDwapXy5.d.ts → client-core-og3AP1LL.d.ts} +15 -2
- package/dist/{compiler-manifest-BHNC4RL-.d.ts → compiler-manifest-Bes3OVA3.d.mts} +1 -1
- package/dist/{compiler-manifest-BHNC4RL-.d.mts → compiler-manifest-Bes3OVA3.d.ts} +1 -1
- package/dist/{errors-lhtIWG5Z.d.ts → errors-BJm4lLWc.d.ts} +1 -1
- package/dist/{errors-D7sPXrvB.d.mts → errors-Dc5r42ks.d.mts} +1 -1
- package/dist/{index-CQTBHXHr.d.ts → index-BfV7mRPF.d.ts} +1 -1
- package/dist/{index-NaDZq2xf.d.mts → index-DTkiz_Ur.d.mts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +121 -112
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- 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/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 +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-Y2K2ZYYA.js +0 -43
- package/dist/cli/describe-LSOHOLFI.js +0 -49
- package/dist/cli/git-S7SWUZ3T.js +0 -25
- package/dist/cli/search-WERQBC6V.js +0 -32
- package/dist/cli/sessions-LXQ4Q6BS.js +0 -22
- package/dist/cli/skills-EFRLHY3F.js +0 -36
- package/dist/cli/tools-C3EIGFFP.js +0 -56
- package/dist/cli/update-KCY72RXH.js +0 -34
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import type { RuntimeSchedulerQueryClient } from './postgres-pool';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Preview experiment CA: claim affinity for the early (E2/PB) sandbox.
|
|
5
|
+
*
|
|
6
|
+
* The early-sandbox hint reaches whichever worker Machine the private
|
|
7
|
+
* `.internal` name resolves to, while the run is claimed by the queue's elected
|
|
8
|
+
* LISTEN worker. When they differ, the claimer refuses the other process's
|
|
9
|
+
* pre-booted sandbox (`early_supervisor_foreign`, which stays strict) and boots
|
|
10
|
+
* its own. With CA, the hinted worker names itself in the hint reply, admission
|
|
11
|
+
* records that name on the run's durable task (`earlySandboxClaimOwner`, an
|
|
12
|
+
* optional task param), and every other worker yields that task's first claim
|
|
13
|
+
* for a short window after enqueue. The owner meanwhile probes for the task
|
|
14
|
+
* and claims it. After the window any worker claims as today, so a lost owner
|
|
15
|
+
* costs at most the window. A task without the param (no hint, CA off, older
|
|
16
|
+
* admission) is claimed exactly as before.
|
|
17
|
+
*
|
|
18
|
+
* Two switches, both off:
|
|
19
|
+
* - `CLAIM_AFFINITY_FOR_EARLY_SANDBOX` (CA, per run): the hinted worker
|
|
20
|
+
* replies with its name and probes for the run; admission records it.
|
|
21
|
+
* - `EARLY_SANDBOX_CLAIM_AFFINITY_READER` (CAR, worker process): the claim
|
|
22
|
+
* gate that reads the param before each claim. It runs before any run is
|
|
23
|
+
* known, so it cannot be a per-run switch.
|
|
24
|
+
*/
|
|
25
|
+
export const CLAIM_AFFINITY_FOR_EARLY_SANDBOX = false;
|
|
26
|
+
export const EARLY_SANDBOX_CLAIM_AFFINITY_READER = false;
|
|
27
|
+
|
|
28
|
+
/** Task param naming the worker that started the run's early sandbox. */
|
|
29
|
+
export const EARLY_SANDBOX_CLAIM_OWNER_PARAM = 'earlySandboxClaimOwner';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* How long other workers yield a recorded owner's first claim, from the task's
|
|
33
|
+
* enqueue time. Derived from the measured path: the hint reply returns in p50
|
|
34
|
+
* 38 ms (max 163) and the run is enqueued ~360 ms after the hint, so the owner
|
|
35
|
+
* is already probing when the task appears; with a 20 ms probe it claims
|
|
36
|
+
* within ~30 ms of enqueue. 300 ms leaves room for a slow probe query while
|
|
37
|
+
* bounding the cost of a lost owner.
|
|
38
|
+
*/
|
|
39
|
+
export const EARLY_SANDBOX_CLAIM_AFFINITY_WINDOW_MS = 300;
|
|
40
|
+
/** The owner's probe cadence while it waits for its run's task. */
|
|
41
|
+
export const EARLY_SANDBOX_OWNER_PROBE_INTERVAL_MS = 20;
|
|
42
|
+
/**
|
|
43
|
+
* How long after the hint the owner keeps probing. Admission enqueues ~0.4 s
|
|
44
|
+
* after the hint (slow admissions up to ~2 s); past this the window still
|
|
45
|
+
* hands the run to any worker.
|
|
46
|
+
*/
|
|
47
|
+
export const EARLY_SANDBOX_OWNER_PROBE_DEADLINE_MS = 2_500;
|
|
48
|
+
|
|
49
|
+
const OWNER_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
50
|
+
|
|
51
|
+
/** A worker name carried in a hint reply or task param, or null. */
|
|
52
|
+
export function parseEarlySandboxClaimOwner(value: unknown): string | null {
|
|
53
|
+
if (typeof value !== 'string') return null;
|
|
54
|
+
const owner = value.trim();
|
|
55
|
+
return OWNER_PATTERN.test(owner) ? owner : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function quoteIdentifier(identifier: string): string {
|
|
59
|
+
return `"${identifier.replaceAll('"', '""')}"`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** One due pending run as the claim gate sees it. */
|
|
63
|
+
export type ClaimAffinityDueRun = {
|
|
64
|
+
owner: string | null;
|
|
65
|
+
attempt: number;
|
|
66
|
+
/** Milliseconds left in the owner's window (0 when it has passed). */
|
|
67
|
+
remainingMs: number;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Whether this worker should skip its next claim, and for how long. Yields
|
|
72
|
+
* only when every due run is a first attempt recorded for ANOTHER owner whose
|
|
73
|
+
* window is still open, and nothing else is due (expired claims, due sleeps
|
|
74
|
+
* and due cancellations are claim_task work too). Anything else claims now.
|
|
75
|
+
*/
|
|
76
|
+
export function decideEarlySandboxClaimYield(input: {
|
|
77
|
+
self: string;
|
|
78
|
+
dueRuns: readonly ClaimAffinityDueRun[];
|
|
79
|
+
otherDueWork: boolean;
|
|
80
|
+
}): number | null {
|
|
81
|
+
if (input.otherDueWork || input.dueRuns.length === 0) return null;
|
|
82
|
+
let yieldMs = Number.POSITIVE_INFINITY;
|
|
83
|
+
for (const run of input.dueRuns) {
|
|
84
|
+
const owner = parseEarlySandboxClaimOwner(run.owner);
|
|
85
|
+
if (
|
|
86
|
+
!owner ||
|
|
87
|
+
owner === input.self ||
|
|
88
|
+
run.attempt !== 1 ||
|
|
89
|
+
!(run.remainingMs > 0)
|
|
90
|
+
) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
yieldMs = Math.min(yieldMs, run.remainingMs);
|
|
94
|
+
}
|
|
95
|
+
return Number.isFinite(yieldMs) ? Math.ceil(yieldMs) : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Read the claim gate's inputs: the first `limit` due pending runs (the same
|
|
100
|
+
* ordered index seek `claim_task` uses) with their recorded owner and window,
|
|
101
|
+
* and whether any other claim_task work is due.
|
|
102
|
+
*/
|
|
103
|
+
export async function readEarlySandboxClaimAffinity(input: {
|
|
104
|
+
client: RuntimeSchedulerQueryClient;
|
|
105
|
+
queue: string;
|
|
106
|
+
limit: number;
|
|
107
|
+
windowMs: number;
|
|
108
|
+
}): Promise<{ dueRuns: ClaimAffinityDueRun[]; otherDueWork: boolean }> {
|
|
109
|
+
const runTable = quoteIdentifier(`r_${input.queue}`);
|
|
110
|
+
const taskTable = quoteIdentifier(`t_${input.queue}`);
|
|
111
|
+
const result = await input.client.query<{
|
|
112
|
+
owner: string | null;
|
|
113
|
+
attempt: number | null;
|
|
114
|
+
remaining_ms: number | null;
|
|
115
|
+
other_due: boolean;
|
|
116
|
+
}>(
|
|
117
|
+
`WITH clock AS MATERIALIZED (SELECT absurd.current_time() AS now),
|
|
118
|
+
due AS MATERIALIZED (
|
|
119
|
+
SELECT run_id, task_id, attempt FROM absurd.${runTable}
|
|
120
|
+
WHERE state = 'pending'
|
|
121
|
+
AND available_at <= (SELECT now FROM clock)
|
|
122
|
+
ORDER BY available_at LIMIT $1
|
|
123
|
+
),
|
|
124
|
+
other AS MATERIALIZED (
|
|
125
|
+
SELECT (
|
|
126
|
+
(SELECT run_id FROM absurd.${runTable}
|
|
127
|
+
WHERE state = 'sleeping'
|
|
128
|
+
AND available_at <= (SELECT now FROM clock)
|
|
129
|
+
ORDER BY available_at LIMIT 1) IS NOT NULL
|
|
130
|
+
OR (SELECT run_id FROM absurd.${runTable}
|
|
131
|
+
WHERE state = 'running'
|
|
132
|
+
AND claim_expires_at IS NOT NULL
|
|
133
|
+
AND claim_expires_at <= (SELECT now FROM clock)
|
|
134
|
+
ORDER BY claim_expires_at LIMIT 1) IS NOT NULL
|
|
135
|
+
OR (SELECT task_id FROM absurd.${taskTable}
|
|
136
|
+
WHERE state IN ('pending', 'sleeping', 'running')
|
|
137
|
+
AND cancel_at IS NOT NULL
|
|
138
|
+
AND cancel_at <= (SELECT now FROM clock)
|
|
139
|
+
ORDER BY cancel_at LIMIT 1) IS NOT NULL
|
|
140
|
+
) AS other_due
|
|
141
|
+
)
|
|
142
|
+
SELECT task.params ->> '${EARLY_SANDBOX_CLAIM_OWNER_PARAM}' AS owner,
|
|
143
|
+
due.attempt,
|
|
144
|
+
GREATEST(0, CEIL(EXTRACT(EPOCH FROM (
|
|
145
|
+
task.enqueue_at + make_interval(secs => $2::double precision / 1000)
|
|
146
|
+
- (SELECT now FROM clock))) * 1000))::integer AS remaining_ms,
|
|
147
|
+
(SELECT other_due FROM other) AS other_due
|
|
148
|
+
FROM other
|
|
149
|
+
LEFT JOIN due ON true
|
|
150
|
+
LEFT JOIN absurd.${taskTable} AS task ON task.task_id = due.task_id`,
|
|
151
|
+
[Math.max(1, Math.floor(input.limit)), input.windowMs],
|
|
152
|
+
);
|
|
153
|
+
const otherDueWork = result.rows[0]?.other_due === true;
|
|
154
|
+
const dueRuns = result.rows.flatMap((row) =>
|
|
155
|
+
row.attempt === null || row.attempt === undefined
|
|
156
|
+
? []
|
|
157
|
+
: [
|
|
158
|
+
{
|
|
159
|
+
owner: row.owner ?? null,
|
|
160
|
+
attempt: Number(row.attempt),
|
|
161
|
+
remainingMs: Number(row.remaining_ms ?? 0),
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
);
|
|
165
|
+
return { dueRuns, otherDueWork };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The vendored engine's claim statement (`Absurd.claimTasks`). */
|
|
169
|
+
const ABSURD_CLAIM_TASK_SQL = 'absurd.claim_task(';
|
|
170
|
+
|
|
171
|
+
export type EarlySandboxClaimGate = (
|
|
172
|
+
client: RuntimeSchedulerQueryClient,
|
|
173
|
+
claimParams: readonly unknown[],
|
|
174
|
+
) => Promise<boolean>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The claim gate the worker's scheduler queryable runs on the claim's own
|
|
178
|
+
* pooled client, before `claim_task`. It returns false (skip this claim) only
|
|
179
|
+
* while another owner's window is open, and then wakes the engine when that
|
|
180
|
+
* window closes, so the run is claimed by someone within the window plus one
|
|
181
|
+
* wake. A failed read claims as today.
|
|
182
|
+
*/
|
|
183
|
+
export function createEarlySandboxClaimGate(input: {
|
|
184
|
+
self: string;
|
|
185
|
+
queue: string;
|
|
186
|
+
windowMs?: number;
|
|
187
|
+
wake: () => boolean;
|
|
188
|
+
setTimer?: (callback: () => void, ms: number) => unknown;
|
|
189
|
+
log?: (line: string, fields: Record<string, unknown>) => void;
|
|
190
|
+
}): EarlySandboxClaimGate {
|
|
191
|
+
const windowMs = input.windowMs ?? EARLY_SANDBOX_CLAIM_AFFINITY_WINDOW_MS;
|
|
192
|
+
const setTimer =
|
|
193
|
+
input.setTimer ??
|
|
194
|
+
((callback: () => void, ms: number) => {
|
|
195
|
+
const timer = setTimeout(callback, ms);
|
|
196
|
+
timer.unref?.();
|
|
197
|
+
return timer;
|
|
198
|
+
});
|
|
199
|
+
const log = input.log ?? ((line, fields) => console.info(line, fields));
|
|
200
|
+
let wakeAt: number | null = null;
|
|
201
|
+
return async (client, claimParams) => {
|
|
202
|
+
const startedAt = performance.now();
|
|
203
|
+
const limit = Number(claimParams[3] ?? 1);
|
|
204
|
+
let decision: number | null;
|
|
205
|
+
try {
|
|
206
|
+
const read = await readEarlySandboxClaimAffinity({
|
|
207
|
+
client,
|
|
208
|
+
queue: input.queue,
|
|
209
|
+
limit: Number.isFinite(limit) && limit > 0 ? limit : 1,
|
|
210
|
+
windowMs,
|
|
211
|
+
});
|
|
212
|
+
decision = decideEarlySandboxClaimYield({
|
|
213
|
+
self: input.self,
|
|
214
|
+
dueRuns: read.dueRuns,
|
|
215
|
+
otherDueWork: read.otherDueWork,
|
|
216
|
+
});
|
|
217
|
+
} catch (error) {
|
|
218
|
+
log('[runtime.claim_affinity]', {
|
|
219
|
+
event: 'gate_failed',
|
|
220
|
+
error: error instanceof Error ? error.message : String(error),
|
|
221
|
+
});
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
const gateMs = Math.round(performance.now() - startedAt);
|
|
225
|
+
if (decision === null) {
|
|
226
|
+
log('[runtime.claim_affinity]', { event: 'gate_claim', gateMs });
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
// One timer per open window: a later yield inside it reuses the wake.
|
|
230
|
+
const due = Date.now() + decision + 1;
|
|
231
|
+
if (wakeAt === null || wakeAt <= Date.now() || due < wakeAt) {
|
|
232
|
+
wakeAt = due;
|
|
233
|
+
setTimer(() => {
|
|
234
|
+
wakeAt = null;
|
|
235
|
+
input.wake();
|
|
236
|
+
}, decision + 1);
|
|
237
|
+
}
|
|
238
|
+
log('[runtime.claim_affinity]', {
|
|
239
|
+
event: 'gate_yield',
|
|
240
|
+
yieldMs: decision,
|
|
241
|
+
gateMs,
|
|
242
|
+
});
|
|
243
|
+
return false;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Run `claim` unless `gate` says to yield; a yielded claim returns no rows,
|
|
249
|
+
* exactly like a claim that found nothing. Non-claim statements pass through.
|
|
250
|
+
*/
|
|
251
|
+
export async function runGatedAbsurdClaimQuery<Row>(input: {
|
|
252
|
+
sql: string;
|
|
253
|
+
params: readonly unknown[] | undefined;
|
|
254
|
+
client: RuntimeSchedulerQueryClient;
|
|
255
|
+
gate: EarlySandboxClaimGate | undefined;
|
|
256
|
+
run: () => Promise<{ rows: Row[] }>;
|
|
257
|
+
}): Promise<{ rows: Row[] }> {
|
|
258
|
+
if (
|
|
259
|
+
input.gate &&
|
|
260
|
+
input.sql.includes(ABSURD_CLAIM_TASK_SQL) &&
|
|
261
|
+
!(await input.gate(input.client, input.params ?? []))
|
|
262
|
+
) {
|
|
263
|
+
return { rows: [] };
|
|
264
|
+
}
|
|
265
|
+
return input.run();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Probe whether a pending task recorded for `owner` exists (due or not).
|
|
270
|
+
* One ordered seek over the pending partial index plus the task row.
|
|
271
|
+
*/
|
|
272
|
+
export async function hasPendingEarlySandboxClaim(input: {
|
|
273
|
+
client: RuntimeSchedulerQueryClient;
|
|
274
|
+
queue: string;
|
|
275
|
+
owner: string;
|
|
276
|
+
}): Promise<boolean> {
|
|
277
|
+
const runTable = quoteIdentifier(`r_${input.queue}`);
|
|
278
|
+
const taskTable = quoteIdentifier(`t_${input.queue}`);
|
|
279
|
+
const result = await input.client.query<{ found: boolean }>(
|
|
280
|
+
`SELECT EXISTS (
|
|
281
|
+
SELECT 1
|
|
282
|
+
FROM (SELECT task_id, attempt FROM absurd.${runTable}
|
|
283
|
+
WHERE state = 'pending'
|
|
284
|
+
ORDER BY available_at LIMIT 32) AS pending
|
|
285
|
+
JOIN absurd.${taskTable} AS task ON task.task_id = pending.task_id
|
|
286
|
+
WHERE pending.attempt = 1
|
|
287
|
+
AND task.params ->> '${EARLY_SANDBOX_CLAIM_OWNER_PARAM}' = $1
|
|
288
|
+
) AS found`,
|
|
289
|
+
[input.owner],
|
|
290
|
+
);
|
|
291
|
+
return result.rows[0]?.found === true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The owner's side: after accepting a CA hint, probe every `intervalMs` for a
|
|
296
|
+
* pending task recorded for this worker and wake the claim loop when one
|
|
297
|
+
* appears. Stops once that task has been seen and is gone (claimed), or at the
|
|
298
|
+
* deadline. Errors are reported and the probe continues; the window bounds the
|
|
299
|
+
* cost of any miss.
|
|
300
|
+
*/
|
|
301
|
+
export async function runEarlySandboxOwnerClaimProbe(input: {
|
|
302
|
+
probe: () => Promise<boolean>;
|
|
303
|
+
wake: () => boolean;
|
|
304
|
+
intervalMs?: number;
|
|
305
|
+
deadlineMs?: number;
|
|
306
|
+
now?: () => number;
|
|
307
|
+
sleep?: (ms: number) => Promise<void>;
|
|
308
|
+
onError?: (error: unknown) => void;
|
|
309
|
+
}): Promise<{ outcome: 'claimed' | 'deadline'; probes: number; wakes: number }> {
|
|
310
|
+
const intervalMs = Math.max(
|
|
311
|
+
1,
|
|
312
|
+
input.intervalMs ?? EARLY_SANDBOX_OWNER_PROBE_INTERVAL_MS,
|
|
313
|
+
);
|
|
314
|
+
const now = input.now ?? Date.now;
|
|
315
|
+
const sleep =
|
|
316
|
+
input.sleep ??
|
|
317
|
+
((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
|
|
318
|
+
const deadline =
|
|
319
|
+
now() + (input.deadlineMs ?? EARLY_SANDBOX_OWNER_PROBE_DEADLINE_MS);
|
|
320
|
+
let seen = false;
|
|
321
|
+
let probes = 0;
|
|
322
|
+
let wakes = 0;
|
|
323
|
+
while (now() < deadline) {
|
|
324
|
+
let pending = false;
|
|
325
|
+
try {
|
|
326
|
+
probes += 1;
|
|
327
|
+
pending = await input.probe();
|
|
328
|
+
} catch (error) {
|
|
329
|
+
input.onError?.(error);
|
|
330
|
+
}
|
|
331
|
+
if (pending) {
|
|
332
|
+
seen = true;
|
|
333
|
+
if (input.wake()) wakes += 1;
|
|
334
|
+
} else if (seen) {
|
|
335
|
+
return { outcome: 'claimed', probes, wakes };
|
|
336
|
+
}
|
|
337
|
+
await sleep(intervalMs);
|
|
338
|
+
}
|
|
339
|
+
return { outcome: 'deadline', probes, wakes };
|
|
340
|
+
}
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts
CHANGED
|
@@ -1440,6 +1440,7 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1440
1440
|
logicalCalls?: unknown;
|
|
1441
1441
|
providerRequests?: unknown;
|
|
1442
1442
|
provider429s?: unknown;
|
|
1443
|
+
reusableResultCalls?: unknown;
|
|
1443
1444
|
};
|
|
1444
1445
|
if (
|
|
1445
1446
|
typeof observed.attempt !== 'number' ||
|
|
@@ -1471,6 +1472,10 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1471
1472
|
logicalCalls: observed.logicalCalls as number,
|
|
1472
1473
|
providerRequests: observed.providerRequests as number,
|
|
1473
1474
|
provider429s: observed.provider429s as number,
|
|
1475
|
+
...(Number.isSafeInteger(observed.reusableResultCalls) &&
|
|
1476
|
+
(observed.reusableResultCalls as number) >= 0
|
|
1477
|
+
? { reusableResultCalls: observed.reusableResultCalls as number }
|
|
1478
|
+
: {}),
|
|
1474
1479
|
final: false,
|
|
1475
1480
|
};
|
|
1476
1481
|
if (
|
|
@@ -1480,7 +1485,8 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1480
1485
|
workCounters.segmentId === next.segmentId &&
|
|
1481
1486
|
workCounters.logicalCalls >= next.logicalCalls &&
|
|
1482
1487
|
workCounters.providerRequests >= next.providerRequests &&
|
|
1483
|
-
workCounters.provider429s >= next.provider429s
|
|
1488
|
+
workCounters.provider429s >= next.provider429s &&
|
|
1489
|
+
workCounters.reusableResultCalls === next.reusableResultCalls
|
|
1484
1490
|
)
|
|
1485
1491
|
return;
|
|
1486
1492
|
workCounters = next;
|
|
@@ -1766,6 +1772,9 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1766
1772
|
logicalCalls: terminalCounters.logicalCalls,
|
|
1767
1773
|
providerRequests: terminalCounters.providerRequests,
|
|
1768
1774
|
provider429s: terminalCounters.provider429s,
|
|
1775
|
+
...(terminalCounters.reusableResultCalls !== undefined
|
|
1776
|
+
? { reusableResultCalls: terminalCounters.reusableResultCalls }
|
|
1777
|
+
: {}),
|
|
1769
1778
|
final: true,
|
|
1770
1779
|
};
|
|
1771
1780
|
workCountersDirty = true;
|