deepline 0.3.527 → 0.3.529
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/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +197 -207
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +66 -1
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +156 -161
- package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +56 -1
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +11 -1
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +36 -6
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +35 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +12 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +16 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +26 -5
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +129 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-claim-loop-timing.ts +145 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +48 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +475 -101
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +13 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +30 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +43 -16
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +105 -13
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/result-receipt-policy.ts +10 -1
- package/dist/cli/auth-P7M7SXM5.js +43 -0
- package/dist/cli/{auth-LRMMQFJ4.mjs → auth-V7A6TU4G.mjs} +5 -5
- package/dist/cli/{billing-WZZDXVRJ.mjs → billing-5VBUYPWW.mjs} +6 -6
- package/dist/cli/{billing-M76MMWZB.js → billing-XF6SAA5Y.js} +79 -79
- package/dist/cli/{chunk-HB3YUHEL.js → chunk-2GV54JFN.js} +44 -44
- package/dist/cli/{chunk-ETXQZGQU.js → chunk-4722FTYU.js} +16 -16
- package/dist/cli/{chunk-AXFHQWGA.mjs → chunk-4A4OQMJX.mjs} +1 -1
- package/dist/cli/{chunk-66YLAQ2X.js → chunk-4BKE63Q7.js} +26 -26
- package/dist/cli/{chunk-UKOG6PCB.mjs → chunk-5NZEA2YV.mjs} +1 -1
- package/dist/cli/{chunk-JEIGNX3G.mjs → chunk-6XZIXDLC.mjs} +5 -5
- package/dist/cli/{chunk-RGL2YGJZ.js → chunk-7RTDSHMB.js} +2 -2
- package/dist/cli/{chunk-2A6IRSE6.js → chunk-7SRZTSHU.js} +5 -5
- package/dist/cli/{chunk-7DPWGAOU.js → chunk-7Z3ZXSOX.js} +3 -3
- package/dist/cli/{chunk-JSEISVAZ.js → chunk-AP7DNG6D.js} +4 -4
- package/dist/cli/{chunk-P5ZU5ZHA.mjs → chunk-BOWZ3OOU.mjs} +1 -1
- package/dist/cli/{chunk-YUYDP2EG.js → chunk-BRQDN67G.js} +6 -6
- package/dist/cli/{chunk-VV2AFJ3I.mjs → chunk-C2WTS7WY.mjs} +5 -5
- package/dist/cli/{chunk-GIRMVMXP.mjs → chunk-DKX5CGTG.mjs} +1 -1
- package/dist/cli/{chunk-OXHY3LD3.js → chunk-DPGPXARU.js} +53 -53
- package/dist/cli/{chunk-JSVHBJE2.mjs → chunk-E7CN5GEM.mjs} +2 -2
- package/dist/cli/{chunk-KDFUQRVU.mjs → chunk-ETCGTKLF.mjs} +1 -1
- package/dist/cli/{chunk-UJHS2O5O.mjs → chunk-EW33RCLA.mjs} +3 -3
- package/dist/cli/{chunk-OLSATEDQ.js → chunk-FCNSJHED.js} +6 -6
- package/dist/cli/{chunk-YKPMIJJ2.mjs → chunk-FWC47SCG.mjs} +2 -2
- package/dist/cli/{chunk-VTXBV4AX.mjs → chunk-FXHKNZM2.mjs} +1 -1
- package/dist/cli/{chunk-MMM2WMTF.mjs → chunk-G4SYSUDB.mjs} +5 -5
- package/dist/cli/{chunk-HA2J2OAS.mjs → chunk-GPU4ULMY.mjs} +10 -10
- package/dist/cli/{chunk-3L2DNG5X.js → chunk-H2JAXOPP.js} +11 -11
- package/dist/cli/{chunk-QKY3H3HA.mjs → chunk-HV4UKMBB.mjs} +4 -4
- package/dist/cli/{chunk-QKKT5G4K.mjs → chunk-K55VBSCA.mjs} +3 -3
- package/dist/cli/{chunk-EOL7PXLW.js → chunk-KAI64HV7.js} +7 -7
- package/dist/cli/{chunk-YJ4YVFXC.js → chunk-KSUWW26I.js} +13 -13
- package/dist/cli/{chunk-XI47UAVU.js → chunk-L3J7IAYE.js} +9 -9
- package/dist/cli/{chunk-R6IWWPY7.js → chunk-M47I47FK.js} +14 -14
- package/dist/cli/{chunk-E4TEZE62.mjs → chunk-NDVCVFZW.mjs} +2 -2
- package/dist/cli/{chunk-UAQ7ZWRP.js → chunk-NVH6ULDP.js} +22 -22
- package/dist/cli/{chunk-M45S7JAY.mjs → chunk-NVSMSP2J.mjs} +2 -2
- package/dist/cli/{chunk-SRQQAUXN.js → chunk-OA4FI5ZM.js} +2 -2
- package/dist/cli/{chunk-NVII3RWQ.mjs → chunk-PAAREIKG.mjs} +2 -2
- package/dist/cli/{chunk-5YR6CDJ2.mjs → chunk-PJDYY5JL.mjs} +6 -6
- package/dist/cli/{chunk-LHMHUA5D.js → chunk-PNWBODCB.js} +7 -7
- package/dist/cli/{chunk-C7A44BZ7.js → chunk-QTQWPSAK.js} +3 -3
- package/dist/cli/{chunk-MIL5YDKZ.mjs → chunk-R62Z4INU.mjs} +2 -2
- package/dist/cli/{chunk-YSDPYQBH.js → chunk-RWY2QLJ4.js} +41 -41
- package/dist/cli/{chunk-XYG4IOJK.js → chunk-TEFO5AS2.js} +98 -98
- package/dist/cli/{chunk-ZHY7AY5V.js → chunk-UMCEXTRM.js} +16 -16
- package/dist/cli/{chunk-77VNC2KF.mjs → chunk-XE4PQE2O.mjs} +1 -1
- package/dist/cli/{chunk-OKRBGXDI.js → chunk-XEZSORKG.js} +5 -5
- package/dist/cli/{chunk-3PQDEBO6.js → chunk-XZ6OY3BH.js} +1 -1
- package/dist/cli/{chunk-2L3HVEBM.mjs → chunk-Y4P6XJHU.mjs} +1 -1
- package/dist/cli/{chunk-RMCKTV4R.mjs → chunk-YVJJEMNQ.mjs} +1 -1
- package/dist/cli/{chunk-HQZLTK3P.js → chunk-ZEIN5YJS.js} +2 -2
- package/dist/cli/{chunk-RTPLRMEB.mjs → chunk-ZULLXAJJ.mjs} +5 -5
- package/dist/cli/{chunk-4YN7DZEA.mjs → chunk-ZYMX7KZE.mjs} +2 -2
- package/dist/cli/{csv-FEFNXZF7.mjs → csv-IHLVHG35.mjs} +4 -4
- package/dist/cli/{csv-IRP6VT7Q.js → csv-VEKMGGOE.js} +13 -13
- package/dist/cli/{db-Y5VNPNRD.js → db-NTFFISQG.js} +27 -27
- package/dist/cli/{db-IHECMWZ3.mjs → db-RKLVYARP.mjs} +6 -6
- package/dist/cli/{describe-XCVC2WLL.mjs → describe-62ELB5DZ.mjs} +18 -18
- package/dist/cli/describe-JXOGKT6C.js +50 -0
- package/dist/cli/{executions-3FWZYUJV.mjs → executions-5BMZW4C7.mjs} +6 -6
- package/dist/cli/{executions-QH3KJ6MA.js → executions-X7NMKMXW.js} +8 -8
- package/dist/cli/{feedback-BGHWMOLH.js → feedback-RDN5O4AT.js} +14 -14
- package/dist/cli/{feedback-F3OZXOPM.mjs → feedback-UHHWCIFD.mjs} +6 -6
- package/dist/cli/{git-RWPH3D75.mjs → git-3M33GKOW.mjs} +5 -5
- package/dist/cli/git-7VZGGIGZ.js +25 -0
- package/dist/cli/index.js +141 -141
- package/dist/cli/index.mjs +43 -43
- package/dist/cli/{legacy-noops-5ADSTBJ5.mjs → legacy-noops-7RVRPF5B.mjs} +6 -6
- package/dist/cli/{legacy-noops-G6CYD5LM.js → legacy-noops-ENKN6JU4.js} +9 -9
- package/dist/cli/{monitors-AFNAU3A2.mjs → monitors-FJPDMUQ6.mjs} +7 -7
- package/dist/cli/{monitors-VZCBZO26.js → monitors-YOWDFGIR.js} +100 -100
- package/dist/cli/{org-X4QRYBC4.js → org-4GBLI75H.js} +86 -86
- package/dist/cli/{org-JVLYTU24.mjs → org-H24LOZAC.mjs} +6 -6
- package/dist/cli/{pages-VELKZKBL.mjs → pages-BKM2D6BV.mjs} +6 -6
- package/dist/cli/{pages-YMM4KBW5.js → pages-WWVLYB5K.js} +18 -18
- package/dist/cli/{play-MIY6BYRB.mjs → play-M3CSYH3A.mjs} +18 -18
- package/dist/cli/{play-J7DEBHI7.js → play-TXHKCG6B.js} +317 -317
- package/dist/cli/{providers-2H3W3W7G.mjs → providers-EW5WTMTX.mjs} +6 -6
- package/dist/cli/{providers-TOUB7Y2A.js → providers-XL4SNFHU.js} +9 -9
- package/dist/cli/{quickstart-LHY2LN3P.js → quickstart-AFQ5MCDL.js} +6 -6
- package/dist/cli/{quickstart-GKAS5265.mjs → quickstart-SZSLS553.mjs} +4 -4
- package/dist/cli/{run-QCAVDPE5.js → run-MOFHGYSN.js} +41 -41
- package/dist/cli/{run-KYGNOWYD.mjs → run-TWXFNH6U.mjs} +23 -23
- package/dist/cli/{search-YPGAIFDX.mjs → search-2SW4V4IR.mjs} +8 -8
- package/dist/cli/search-V2AGWRLO.js +33 -0
- package/dist/cli/{search-output-ASELNQ2U.js → search-output-CJGRPJYD.js} +6 -6
- package/dist/cli/{search-output-OOC3VK4T.mjs → search-output-I6DNYXNT.mjs} +4 -4
- package/dist/cli/{secrets-VJ4XYSMZ.mjs → secrets-4XXLR6QO.mjs} +6 -6
- package/dist/cli/{secrets-KX3TQB4R.js → secrets-SD43HSLX.js} +15 -15
- package/dist/cli/{sessions-KUN7H7E5.mjs → sessions-7G32HW5R.mjs} +6 -6
- package/dist/cli/sessions-FIRDFPIZ.js +22 -0
- package/dist/cli/{settings-JKFYZ2IT.mjs → settings-HSYRY2L5.mjs} +13 -13
- package/dist/cli/{settings-5NIF4BU7.js → settings-SYEBDDDJ.js} +86 -86
- package/dist/cli/{setup-MYV3IHPS.js → setup-VTWCVCTK.js} +50 -50
- package/dist/cli/{setup-5AX3TN6G.mjs → setup-XZVBPKZK.mjs} +10 -10
- package/dist/cli/{skills-JLS4CINQ.mjs → skills-OMPEUMRT.mjs} +8 -8
- package/dist/cli/skills-RUY7CION.js +37 -0
- package/dist/cli/tools-KLIW7G6T.js +57 -0
- package/dist/cli/{tools-VBYKD3MJ.mjs → tools-UEDNJI4G.mjs} +17 -17
- package/dist/cli/{update-QWAIVJRI.mjs → update-4YVCUSSI.mjs} +10 -10
- package/dist/cli/update-FDUZRKKU.js +35 -0
- package/dist/cli/{views-TBWGZAVZ.mjs → views-4FP4AJQ2.mjs} +6 -6
- package/dist/cli/{views-ZW56JZB5.js → views-ZCCSKWMP.js} +18 -18
- package/dist/cli/{workflow-X7UQPJMQ.mjs → workflow-A2D5FALP.mjs} +7 -7
- package/dist/cli/{workflow-EKSZST6M.js → workflow-SM4OD4VJ.js} +17 -17
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +105 -104
- 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.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-C7BBYIQD.js +0 -43
- package/dist/cli/describe-MNJVJHRE.js +0 -50
- package/dist/cli/git-MDOHEW5J.js +0 -25
- package/dist/cli/search-G67CEHR7.js +0 -33
- package/dist/cli/sessions-QILPX4XQ.js +0 -22
- package/dist/cli/skills-NG32XTZI.js +0 -37
- package/dist/cli/tools-OZG3V77R.js +0 -57
- package/dist/cli/update-YL5WVSKU.js +0 -35
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
TimeoutError,
|
|
41
41
|
type Absurd,
|
|
42
42
|
type TaskContext,
|
|
43
|
+
type WorkerClaimSnapshot,
|
|
43
44
|
type WorkerOptions,
|
|
44
45
|
} from '@deepline/absurd/sdk';
|
|
45
46
|
import {
|
|
@@ -63,6 +64,7 @@ import { runtimeLimitExceededCause } from '../run-failure';
|
|
|
63
64
|
import {
|
|
64
65
|
playRunRecoveryLogDetail,
|
|
65
66
|
playRunRecoveryProviderText,
|
|
67
|
+
recoveryForCompiledStartPacing,
|
|
66
68
|
recoveryForDaytonaSandboxAcquisitionUnavailable,
|
|
67
69
|
recoveryForRuntimeInitializationTransportFailure,
|
|
68
70
|
recoveryForRuntimeSchedulerAdmissionFailure,
|
|
@@ -83,6 +85,7 @@ import {
|
|
|
83
85
|
import {
|
|
84
86
|
RuntimeResourceFenceLostError,
|
|
85
87
|
type PlayRunnerRuntimeResource,
|
|
88
|
+
type PlayRunnerWorkerSlot,
|
|
86
89
|
} from '../runner-backends/types';
|
|
87
90
|
import { daytonaSandboxMatchesOperationIdentity } from '../runner-backends/backends/daytona-labels';
|
|
88
91
|
import type { PlayBundleArtifact } from '../../plays/artifact-types';
|
|
@@ -267,6 +270,7 @@ import {
|
|
|
267
270
|
import {
|
|
268
271
|
acquirePostgresRateState,
|
|
269
272
|
penalizePostgresRateState,
|
|
273
|
+
releasePostgresRateState,
|
|
270
274
|
} from './postgres-rate-state';
|
|
271
275
|
import { verifyRuntimeReceiptGatewayHealth } from './runtime-receipt-gateway-health';
|
|
272
276
|
import {
|
|
@@ -290,6 +294,10 @@ import {
|
|
|
290
294
|
withRuntimeSchedulerClient,
|
|
291
295
|
} from './postgres-pool';
|
|
292
296
|
import { runWithAbsurdSchedulerQuerySignal } from './absurd-pool';
|
|
297
|
+
import {
|
|
298
|
+
createAbsurdClaimLoopTiming,
|
|
299
|
+
type AbsurdClaimLoopTiming,
|
|
300
|
+
} from './absurd-claim-loop-timing';
|
|
293
301
|
import {
|
|
294
302
|
buildFailedTerminalSettledProgressEvents,
|
|
295
303
|
collectGatewayRunnerTerminalProgressLedgerEvents,
|
|
@@ -439,6 +447,124 @@ function isTransientExecutorTokenStatus(
|
|
|
439
447
|
export const ABSURD_RUNTIME_WORKER_SLOTS =
|
|
440
448
|
RUNTIME_CAPACITY_POLICY.absurd.workerSlotsPerMachine;
|
|
441
449
|
|
|
450
|
+
/**
|
|
451
|
+
* Runs whose slot an active worker may lend at once. A run lends its slot when
|
|
452
|
+
* it takes a Daytona start permit (`daytona-start-admission.ts`) and keeps the
|
|
453
|
+
* loan until it gets a slot back after its create, so a loan outlives its
|
|
454
|
+
* permit. Twice the per-process permits covers every create in flight plus as
|
|
455
|
+
* many finished creates waiting for a slot. With loans capped at the permits
|
|
456
|
+
* alone, those waiting runs used up the cap: the next permit holders created
|
|
457
|
+
* inside their slots, and the finished runs waited for those creates to end
|
|
458
|
+
* before they could stage (round 43357298524-2: 16 such creates, up to 3.1 s
|
|
459
|
+
* of waiting with a ready sandbox, and no claims for 4 s on each warm worker).
|
|
460
|
+
* On top of those, `ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS` runs may lend their
|
|
461
|
+
* slot while the pre-park lifecycle flush waits on the app, so flush loans can
|
|
462
|
+
* never use up the create loans. The worker holds at most
|
|
463
|
+
* slots + 2 x permits + flush loans runs; creates stay bounded by the permits,
|
|
464
|
+
* and pre-create work and staging by `slots`.
|
|
465
|
+
*/
|
|
466
|
+
export const ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS = 10;
|
|
467
|
+
export const ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS =
|
|
468
|
+
2 *
|
|
469
|
+
RUNTIME_CAPACITY_POLICY.sandboxAcquisition
|
|
470
|
+
.daytonaConcurrentStartsPerProcess +
|
|
471
|
+
ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Process-wide count of flush loans, against `max`. A flush takes a loan only
|
|
475
|
+
* while one is free here and the engine still has lending budget; otherwise
|
|
476
|
+
* it flushes in its slot, as before.
|
|
477
|
+
*/
|
|
478
|
+
export function createAbsurdFlushLoanBudget(max: number): {
|
|
479
|
+
tryTake(): boolean;
|
|
480
|
+
give(): void;
|
|
481
|
+
outstanding(): number;
|
|
482
|
+
} {
|
|
483
|
+
let out = 0;
|
|
484
|
+
return {
|
|
485
|
+
tryTake: () => {
|
|
486
|
+
if (out >= max) return false;
|
|
487
|
+
out += 1;
|
|
488
|
+
return true;
|
|
489
|
+
},
|
|
490
|
+
give: () => {
|
|
491
|
+
out = Math.max(0, out - 1);
|
|
492
|
+
},
|
|
493
|
+
outstanding: () => out,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const absurdFlushLoanBudget = createAbsurdFlushLoanBudget(
|
|
498
|
+
ABSURD_RUNTIME_WORKER_MAX_FLUSH_LOANS,
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Runs the pre-park lifecycle flush with the attempt's worker slot lent, and
|
|
503
|
+
* gets the slot back before returning, whether or not the flush throws. The
|
|
504
|
+
* flush only waits on the run-ledger outbox and the app (round 43377040223-1:
|
|
505
|
+
* detach -> park p50 1.2 s, p95 2.5 s, with the slot held), so the worker can
|
|
506
|
+
* claim another run meanwhile; the park that follows runs in a slot, as every
|
|
507
|
+
* step of the task does. Getting the slot back is in-memory in the engine and
|
|
508
|
+
* makes no scheduler-pool call, but it waits for a free slot, so the caller
|
|
509
|
+
* keeps the lease heartbeat running around this whole call. One
|
|
510
|
+
* `lifecycle_flush` phase line per flush reports the flush time, whether it
|
|
511
|
+
* was lent, and the wait for the slot.
|
|
512
|
+
*/
|
|
513
|
+
export async function runLifecycleFlushWithSlotLent<T>(input: {
|
|
514
|
+
workerSlot: PlayRunnerWorkerSlot | undefined;
|
|
515
|
+
budget?: ReturnType<typeof createAbsurdFlushLoanBudget>;
|
|
516
|
+
flush: () => Promise<T>;
|
|
517
|
+
log: (fields: {
|
|
518
|
+
totalMs: number;
|
|
519
|
+
lent: boolean;
|
|
520
|
+
slotWaitMs: number;
|
|
521
|
+
ok: boolean;
|
|
522
|
+
}) => void;
|
|
523
|
+
}): Promise<T> {
|
|
524
|
+
const budget = input.budget ?? absurdFlushLoanBudget;
|
|
525
|
+
let loan: { reclaim(): Promise<void> } | null = null;
|
|
526
|
+
if (input.workerSlot && budget.tryTake()) {
|
|
527
|
+
loan = input.workerSlot.lend();
|
|
528
|
+
if (!loan) budget.give();
|
|
529
|
+
}
|
|
530
|
+
const startedAt = performance.now();
|
|
531
|
+
let totalMs = 0;
|
|
532
|
+
let slotWaitMs = 0;
|
|
533
|
+
let ok = false;
|
|
534
|
+
try {
|
|
535
|
+
const result = await input.flush();
|
|
536
|
+
ok = true;
|
|
537
|
+
return result;
|
|
538
|
+
} finally {
|
|
539
|
+
totalMs = performance.now() - startedAt;
|
|
540
|
+
if (loan) {
|
|
541
|
+
const reclaimStartedAt = performance.now();
|
|
542
|
+
try {
|
|
543
|
+
await loan.reclaim();
|
|
544
|
+
} finally {
|
|
545
|
+
slotWaitMs = performance.now() - reclaimStartedAt;
|
|
546
|
+
budget.give();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
input.log({ totalMs, lent: loan !== null, slotWaitMs, ok });
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* The engine's lendable slot for a play-run attempt. Undefined when the task
|
|
555
|
+
* context cannot lend, such as a test double without the engine's slot
|
|
556
|
+
* lending patch; the attempt then keeps its slot through the create.
|
|
557
|
+
*/
|
|
558
|
+
export function absurdTaskWorkerSlot(
|
|
559
|
+
ctx: TaskContext,
|
|
560
|
+
): PlayRunnerWorkerSlot | undefined {
|
|
561
|
+
const lendSlot = (ctx as { lendSlot?: unknown }).lendSlot;
|
|
562
|
+
if (typeof lendSlot !== 'function') return undefined;
|
|
563
|
+
return {
|
|
564
|
+
lend: () => (lendSlot as TaskContext['lendSlot']).call(ctx),
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
442
568
|
/**
|
|
443
569
|
* Opt-in drain mode. The deploy system sets `DEEPLINE_ABSURD_DRAIN_EXIT=1` on
|
|
444
570
|
* OLD-lane machines after a new release goes live: the machine keeps finishing
|
|
@@ -1046,51 +1172,93 @@ function buildDefaultDeps(absurd: Absurd): AbsurdRuntimeWorkerDeps {
|
|
|
1046
1172
|
* outage keeps the outbox row durable for recovery, but is always loud instead
|
|
1047
1173
|
* of silently leaving the CLI stale.
|
|
1048
1174
|
*/
|
|
1049
|
-
async function projectLifecycleOutbox(input: {
|
|
1175
|
+
export async function projectLifecycleOutbox(input: {
|
|
1050
1176
|
ctx: TaskContext;
|
|
1051
|
-
deps: AbsurdRuntimeWorkerDeps
|
|
1177
|
+
deps: Pick<AbsurdRuntimeWorkerDeps, 'projectOutbox'>;
|
|
1052
1178
|
launch: PlaySchedulerSubmitInput;
|
|
1053
1179
|
lifecycle: PostgresSchedulerLifecycleOutboxEvent;
|
|
1054
1180
|
options?: Pick<PostgresSchedulerOptions, 'schema'>;
|
|
1055
1181
|
transition: 'waiting' | 'resumed';
|
|
1056
1182
|
}): Promise<void> {
|
|
1183
|
+
// Before a park the flush only waits on the outbox and the app, so the slot
|
|
1184
|
+
// is lent for it (`runLifecycleFlushWithSlotLent`). Execution follows a
|
|
1185
|
+
// 'resumed' flush, which keeps its slot. The lease heartbeat runs until the
|
|
1186
|
+
// slot is back, as it does around a create loan: on a full worker, getting
|
|
1187
|
+
// the slot back can outlast the claim lease.
|
|
1057
1188
|
await runWithAbsurdExecutionLeaseHeartbeat({
|
|
1058
1189
|
ctx: input.ctx,
|
|
1059
1190
|
runId: input.lifecycle.runId,
|
|
1060
1191
|
operation: async (signal) => {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
input.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
// transient app-runtime failure, but do not hide the visibility gap.
|
|
1083
|
-
console.error('[run-ledger-outbox.lifecycle_projection_failed]', {
|
|
1084
|
-
runId: input.lifecycle.runId,
|
|
1085
|
-
eventId: input.lifecycle.eventId,
|
|
1086
|
-
transition: input.transition,
|
|
1087
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1192
|
+
let delivered = false;
|
|
1193
|
+
await runLifecycleFlushWithSlotLent({
|
|
1194
|
+
workerSlot:
|
|
1195
|
+
input.transition === 'waiting'
|
|
1196
|
+
? absurdTaskWorkerSlot(input.ctx)
|
|
1197
|
+
: undefined,
|
|
1198
|
+
flush: async () => {
|
|
1199
|
+
delivered = await runLifecycleFlush(input, signal);
|
|
1200
|
+
},
|
|
1201
|
+
log: (fields) =>
|
|
1202
|
+
console.info(
|
|
1203
|
+
'[absurd-runtime.worker.phase] ' +
|
|
1204
|
+
JSON.stringify({
|
|
1205
|
+
runId: input.lifecycle.runId,
|
|
1206
|
+
phase: 'lifecycle_flush',
|
|
1207
|
+
transition: input.transition,
|
|
1208
|
+
...fields,
|
|
1209
|
+
delivered,
|
|
1210
|
+
}),
|
|
1211
|
+
),
|
|
1212
|
+
});
|
|
1090
1213
|
},
|
|
1091
1214
|
});
|
|
1092
1215
|
}
|
|
1093
1216
|
|
|
1217
|
+
/** True when the outbox delivered the lifecycle event to the app. */
|
|
1218
|
+
async function runLifecycleFlush(
|
|
1219
|
+
input: {
|
|
1220
|
+
deps: Pick<AbsurdRuntimeWorkerDeps, 'projectOutbox'>;
|
|
1221
|
+
launch: PlaySchedulerSubmitInput;
|
|
1222
|
+
lifecycle: PostgresSchedulerLifecycleOutboxEvent;
|
|
1223
|
+
options?: Pick<PostgresSchedulerOptions, 'schema'>;
|
|
1224
|
+
transition: 'waiting' | 'resumed';
|
|
1225
|
+
},
|
|
1226
|
+
signal: AbortSignal,
|
|
1227
|
+
): Promise<boolean> {
|
|
1228
|
+
try {
|
|
1229
|
+
const result = await input.deps.projectOutbox(
|
|
1230
|
+
input.launch,
|
|
1231
|
+
input.lifecycle.runId,
|
|
1232
|
+
input.options,
|
|
1233
|
+
input.lifecycle.eventId,
|
|
1234
|
+
signal,
|
|
1235
|
+
);
|
|
1236
|
+
if (result && !result.targetDelivered) {
|
|
1237
|
+
console.error('[run-ledger-outbox.lifecycle_projection_pending]', {
|
|
1238
|
+
runId: input.lifecycle.runId,
|
|
1239
|
+
eventId: input.lifecycle.eventId,
|
|
1240
|
+
transition: input.transition,
|
|
1241
|
+
projected: result.projected,
|
|
1242
|
+
failed: result.failed,
|
|
1243
|
+
failedEventIds: result.failedEventIds,
|
|
1244
|
+
});
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
return true;
|
|
1248
|
+
} catch (error) {
|
|
1249
|
+
// Scheduler truth and the outbox row were committed atomically before this
|
|
1250
|
+
// handoff. Keep the durable continuation live so recovery can heal a
|
|
1251
|
+
// transient app-runtime failure, but do not hide the visibility gap.
|
|
1252
|
+
console.error('[run-ledger-outbox.lifecycle_projection_failed]', {
|
|
1253
|
+
runId: input.lifecycle.runId,
|
|
1254
|
+
eventId: input.lifecycle.eventId,
|
|
1255
|
+
transition: input.transition,
|
|
1256
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1257
|
+
});
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1094
1262
|
function nonJsonResponseTitle(
|
|
1095
1263
|
value: string,
|
|
1096
1264
|
secrets: readonly string[],
|
|
@@ -5133,41 +5301,54 @@ async function executeAssignedAbsurdAttempt(input: {
|
|
|
5133
5301
|
.daytonaMaximumStartsPerMinute
|
|
5134
5302
|
: effectiveDaytonaStartRatePerMinute,
|
|
5135
5303
|
};
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
bucketId: 'runtime:traffic:sandbox-start',
|
|
5144
|
-
requested: 1,
|
|
5145
|
-
schedulerSchema: options.schema ?? null,
|
|
5146
|
-
rules: [
|
|
5147
|
-
{
|
|
5148
|
-
ruleId: 'runtime:traffic:sandbox-start',
|
|
5149
|
-
requestsPerWindow: 1,
|
|
5150
|
-
// A capacity of one gives the operator an actual
|
|
5151
|
-
// start-rate ceiling rather than a minute-sized burst.
|
|
5152
|
-
windowMs: Math.ceil(60_000 / sandboxStartsPerMinute),
|
|
5153
|
-
maxConcurrency: null,
|
|
5154
|
-
adaptiveMaxRps:
|
|
5155
|
-
(daytonaStartRateConfig?.maximumRatePerMinute ??
|
|
5156
|
-
sandboxStartsPerMinute) / 60,
|
|
5157
|
-
},
|
|
5158
|
-
],
|
|
5159
|
-
// The permit itself is the successful admission
|
|
5160
|
-
// observation that lets the fleet-wide AIMD controller
|
|
5161
|
-
// ramp. Provider pressure is fed back in the catch path.
|
|
5162
|
-
observedSuccesses: 1,
|
|
5163
|
-
}),
|
|
5164
|
-
),
|
|
5304
|
+
// Measurement only: one line per attempt with its acquires
|
|
5305
|
+
// (each a scheduler-pool call) and local waits at the limiter.
|
|
5306
|
+
const permitStore = sandboxStartPermitStore({
|
|
5307
|
+
runWithClient: deps.runWithClient,
|
|
5308
|
+
schedulerSchema: options.schema ?? null,
|
|
5309
|
+
maximumRatePerMinute:
|
|
5310
|
+
daytonaStartRateConfig?.maximumRatePerMinute ?? null,
|
|
5165
5311
|
});
|
|
5312
|
+
const limiterStartedAt = performance.now();
|
|
5313
|
+
const limiterCounts = { acquires: 0, waits: 0, waitMs: 0 };
|
|
5314
|
+
let limiterOk = false;
|
|
5315
|
+
try {
|
|
5316
|
+
await enforceRuntimeTrafficPolicyBeforeSandboxStart({
|
|
5317
|
+
policy: trafficPolicy,
|
|
5318
|
+
defaultSandboxStartsPerMinute:
|
|
5319
|
+
defaultDaytonaStartRatePerMinute,
|
|
5320
|
+
nowMs: Date.now(),
|
|
5321
|
+
acquireStartPermit: (startsPerMinute) => {
|
|
5322
|
+
limiterCounts.acquires += 1;
|
|
5323
|
+
return permitStore.acquireStartPermit(startsPerMinute);
|
|
5324
|
+
},
|
|
5325
|
+
refundStartPermit: permitStore.refundStartPermit,
|
|
5326
|
+
sleep: async (ms) => {
|
|
5327
|
+
limiterCounts.waits += 1;
|
|
5328
|
+
limiterCounts.waitMs += ms;
|
|
5329
|
+
await sleep(ms);
|
|
5330
|
+
},
|
|
5331
|
+
});
|
|
5332
|
+
limiterOk = true;
|
|
5333
|
+
} finally {
|
|
5334
|
+
console.info(
|
|
5335
|
+
'[absurd-runtime.worker.phase] ' +
|
|
5336
|
+
JSON.stringify({
|
|
5337
|
+
runId,
|
|
5338
|
+
attempt: generation,
|
|
5339
|
+
phase: 'sandbox_start_limiter',
|
|
5340
|
+
totalMs: performance.now() - limiterStartedAt,
|
|
5341
|
+
ok: limiterOk,
|
|
5342
|
+
...limiterCounts,
|
|
5343
|
+
}),
|
|
5344
|
+
);
|
|
5345
|
+
}
|
|
5166
5346
|
}
|
|
5167
5347
|
const sandboxRuns = createSandboxExecutionJob({
|
|
5168
5348
|
execution: createPlayRunnerBackendSandboxExecutionAdapter({
|
|
5169
5349
|
backend,
|
|
5170
5350
|
cancellationSignal,
|
|
5351
|
+
workerSlot: absurdTaskWorkerSlot(ctx),
|
|
5171
5352
|
readiness: ({ baselineHeartbeatAt }) =>
|
|
5172
5353
|
deps.runWithClient((client) =>
|
|
5173
5354
|
runnerReadiness(
|
|
@@ -5692,6 +5873,7 @@ async function executeAssignedAbsurdAttempt(input: {
|
|
|
5692
5873
|
deferCount: recovery.deferCount,
|
|
5693
5874
|
deadlineAtMs: recovery.deadlineAtMs,
|
|
5694
5875
|
delaySeconds: recovery.delaySeconds,
|
|
5876
|
+
...(recovery.paced ? { paced: true } : {}),
|
|
5695
5877
|
...(detail ? { detail } : {}),
|
|
5696
5878
|
...(providerText ? { providerText } : {}),
|
|
5697
5879
|
});
|
|
@@ -5704,7 +5886,8 @@ async function executeAssignedAbsurdAttempt(input: {
|
|
|
5704
5886
|
reason: recovery.reason,
|
|
5705
5887
|
dependency: recovery.dependency,
|
|
5706
5888
|
deferCount: recovery.deferCount,
|
|
5707
|
-
delayMs: recovery.
|
|
5889
|
+
delayMs: recovery.delayMs,
|
|
5890
|
+
paced: recovery.paced === true,
|
|
5708
5891
|
});
|
|
5709
5892
|
throw new DeferTask(
|
|
5710
5893
|
`Platform recovery deferred for ${recovery.dependency}: ${recovery.reason}`,
|
|
@@ -6101,23 +6284,124 @@ function throwRetryableRuntimeInitializationFailure(
|
|
|
6101
6284
|
throw recoveryForRuntimeInitializationTransportFailure(reason);
|
|
6102
6285
|
}
|
|
6103
6286
|
|
|
6287
|
+
/** A paced start returns no sooner than this: it already lost the bucket for
|
|
6288
|
+
* its whole local wait. */
|
|
6289
|
+
const PACED_START_DEFER_MIN_MS = 1_000;
|
|
6290
|
+
/** Paced starts return spread over the time the bucket needs to grant this
|
|
6291
|
+
* many starts (2 s at 600 a minute), so runs deferred in the same second do
|
|
6292
|
+
* not all come back in the same second. */
|
|
6293
|
+
const PACED_START_DEFER_SPREAD_PERMITS = 20;
|
|
6294
|
+
/** Never spread longer than the outage ladder's first step. */
|
|
6295
|
+
const PACED_START_DEFER_MAX_SPREAD_MS = 15_000;
|
|
6296
|
+
/** How long a run waits for a start it was not granted before deferring. */
|
|
6297
|
+
const UNGRANTED_START_LOCAL_WAIT_MS = 1_000;
|
|
6298
|
+
/**
|
|
6299
|
+
* The longest wait for a start the bucket has already granted. The bucket
|
|
6300
|
+
* books a grant at most one bucket ahead of now (its cursor is clamped to
|
|
6301
|
+
* capacity / refill, 1 s at the compiled 120 to 600 a minute), so at the
|
|
6302
|
+
* compiled rates every grant is used. A grant further out comes only from a
|
|
6303
|
+
* hold, a cooldown, or a slow operator rate; that run releases its slot.
|
|
6304
|
+
*/
|
|
6305
|
+
const GRANTED_START_MAX_LOCAL_WAIT_MS = 2_000;
|
|
6306
|
+
|
|
6307
|
+
const SANDBOX_START_BUCKET_ID = 'runtime:traffic:sandbox-start';
|
|
6308
|
+
|
|
6309
|
+
/**
|
|
6310
|
+
* Acquire and refund on the fleet-wide sandbox-start bucket, from one rule
|
|
6311
|
+
* definition so a refund always lands on the bucket that granted the permit.
|
|
6312
|
+
*/
|
|
6313
|
+
export function sandboxStartPermitStore(input: {
|
|
6314
|
+
runWithClient: AbsurdRuntimeWorkerDeps['runWithClient'];
|
|
6315
|
+
schedulerSchema: string | null;
|
|
6316
|
+
/** The AIMD ceiling; null holds the bucket at the requested rate. */
|
|
6317
|
+
maximumRatePerMinute: number | null;
|
|
6318
|
+
}): Pick<
|
|
6319
|
+
Parameters<typeof enforceRuntimeTrafficPolicyBeforeSandboxStart>[0],
|
|
6320
|
+
'acquireStartPermit' | 'refundStartPermit'
|
|
6321
|
+
> {
|
|
6322
|
+
const rules = (sandboxStartsPerMinute: number) => [
|
|
6323
|
+
{
|
|
6324
|
+
ruleId: SANDBOX_START_BUCKET_ID,
|
|
6325
|
+
requestsPerWindow: 1,
|
|
6326
|
+
// A capacity of one gives the operator an actual start-rate ceiling
|
|
6327
|
+
// rather than a minute-sized burst.
|
|
6328
|
+
windowMs: Math.ceil(60_000 / sandboxStartsPerMinute),
|
|
6329
|
+
maxConcurrency: null,
|
|
6330
|
+
adaptiveMaxRps:
|
|
6331
|
+
(input.maximumRatePerMinute ?? sandboxStartsPerMinute) / 60,
|
|
6332
|
+
},
|
|
6333
|
+
];
|
|
6334
|
+
return {
|
|
6335
|
+
acquireStartPermit: async (sandboxStartsPerMinute) =>
|
|
6336
|
+
await input.runWithClient((client) =>
|
|
6337
|
+
acquirePostgresRateState(client, {
|
|
6338
|
+
bucketId: SANDBOX_START_BUCKET_ID,
|
|
6339
|
+
requested: 1,
|
|
6340
|
+
schedulerSchema: input.schedulerSchema,
|
|
6341
|
+
rules: rules(sandboxStartsPerMinute),
|
|
6342
|
+
// The permit itself is the successful admission observation that
|
|
6343
|
+
// lets the fleet-wide AIMD controller ramp. Provider pressure is fed
|
|
6344
|
+
// back in the attempt's catch path.
|
|
6345
|
+
observedSuccesses: 1,
|
|
6346
|
+
}),
|
|
6347
|
+
),
|
|
6348
|
+
refundStartPermit: async ({ sandboxStartsPerMinute, reservationIds }) =>
|
|
6349
|
+
await input.runWithClient((client) =>
|
|
6350
|
+
releasePostgresRateState(client, {
|
|
6351
|
+
bucketId: SANDBOX_START_BUCKET_ID,
|
|
6352
|
+
schedulerSchema: input.schedulerSchema,
|
|
6353
|
+
rules: rules(sandboxStartsPerMinute),
|
|
6354
|
+
leaseIds: [],
|
|
6355
|
+
refundReservationIds: reservationIds,
|
|
6356
|
+
}),
|
|
6357
|
+
),
|
|
6358
|
+
};
|
|
6359
|
+
}
|
|
6360
|
+
|
|
6361
|
+
type SandboxStartPermit = {
|
|
6362
|
+
granted: number;
|
|
6363
|
+
waitMs: number;
|
|
6364
|
+
waitReason?: 'concurrency' | 'rate' | 'hold' | 'fair_share';
|
|
6365
|
+
serverNowMs?: number;
|
|
6366
|
+
scheduledAtMs?: number[];
|
|
6367
|
+
effectiveRequestsPerSecond?: number;
|
|
6368
|
+
coolUntilMs?: number;
|
|
6369
|
+
claimedRetryAtMs?: number;
|
|
6370
|
+
/** One per granted permit; the bucket's ticket for a refund. */
|
|
6371
|
+
reservationIds?: string[];
|
|
6372
|
+
};
|
|
6373
|
+
|
|
6104
6374
|
/**
|
|
6105
6375
|
* Consume one global start permit before a first sandbox create. The limiter's
|
|
6106
6376
|
* durable bucket is used for the compiled Daytona AIMD start ceiling and for
|
|
6107
|
-
* any short-lived operator policy.
|
|
6108
|
-
*
|
|
6377
|
+
* any short-lived operator policy.
|
|
6378
|
+
*
|
|
6379
|
+
* A granted start is waited for and used, however long the run already
|
|
6380
|
+
* waited: the grant took a token and a dispatch slot from the whole fleet.
|
|
6381
|
+
* Only a run granted nothing within 1 s defers. A grant too far out to wait
|
|
6382
|
+
* for is refunded before the run defers, so its token returns to the fleet.
|
|
6383
|
+
*
|
|
6384
|
+
* A defer under an operator policy, or while the bucket holds for provider
|
|
6385
|
+
* pressure, goes on the same finite recovery ledger used for platform
|
|
6386
|
+
* outages. Under the compiled pacing alone the bucket keeps granting, so the
|
|
6387
|
+
* run is requeued after the bucket's own wait plus jitter, outside the outage
|
|
6388
|
+
* budget.
|
|
6109
6389
|
*/
|
|
6110
6390
|
export async function enforceRuntimeTrafficPolicyBeforeSandboxStart(input: {
|
|
6111
6391
|
policy: RuntimeTrafficPolicy;
|
|
6112
6392
|
defaultSandboxStartsPerMinute?: number | null;
|
|
6113
6393
|
nowMs: number;
|
|
6114
|
-
acquireStartPermit: (
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6394
|
+
acquireStartPermit: (
|
|
6395
|
+
sandboxStartsPerMinute: number,
|
|
6396
|
+
) => Promise<SandboxStartPermit>;
|
|
6397
|
+
/** Return granted permits this start will not use. */
|
|
6398
|
+
refundStartPermit: (input: {
|
|
6399
|
+
sandboxStartsPerMinute: number;
|
|
6400
|
+
reservationIds: string[];
|
|
6401
|
+
}) => Promise<void>;
|
|
6120
6402
|
sleep?: (ms: number) => Promise<void>;
|
|
6403
|
+
/** Uniform [0, 1); injectable so tests can pin the jitter. */
|
|
6404
|
+
random?: () => number;
|
|
6121
6405
|
}): Promise<void> {
|
|
6122
6406
|
if (input.policy.admissionMode === 'hold_new_sandbox_starts') {
|
|
6123
6407
|
throw recoveryForRuntimeTrafficPolicy({ mode: 'hold' });
|
|
@@ -6127,30 +6411,92 @@ export async function enforceRuntimeTrafficPolicyBeforeSandboxStart(input: {
|
|
|
6127
6411
|
input.defaultSandboxStartsPerMinute ??
|
|
6128
6412
|
null;
|
|
6129
6413
|
if (sandboxStartsPerMinute === null) return;
|
|
6414
|
+
const deferStart = (
|
|
6415
|
+
permit: SandboxStartPermit,
|
|
6416
|
+
schedulerNowMs: number,
|
|
6417
|
+
delayMs: number,
|
|
6418
|
+
) => {
|
|
6419
|
+
const bucketHolding =
|
|
6420
|
+
permit.waitReason === 'hold' ||
|
|
6421
|
+
(permit.coolUntilMs ?? 0) > schedulerNowMs ||
|
|
6422
|
+
(permit.claimedRetryAtMs ?? 0) > schedulerNowMs;
|
|
6423
|
+
// Only a reply read from the bucket's state proves it is merely pacing.
|
|
6424
|
+
// A lock-busy reply carries no clock, cooldown or retry facts, so it
|
|
6425
|
+
// cannot rule out a hold and takes the counted ladder.
|
|
6426
|
+
const bucketStateRead = permit.serverNowMs !== undefined;
|
|
6427
|
+
if (
|
|
6428
|
+
input.policy.sandboxStartsPerMinute !== null ||
|
|
6429
|
+
bucketHolding ||
|
|
6430
|
+
!bucketStateRead
|
|
6431
|
+
) {
|
|
6432
|
+
return recoveryForRuntimeTrafficPolicy({ mode: 'throttle' });
|
|
6433
|
+
}
|
|
6434
|
+
const startsPerSecond =
|
|
6435
|
+
permit.effectiveRequestsPerSecond !== undefined &&
|
|
6436
|
+
permit.effectiveRequestsPerSecond > 0
|
|
6437
|
+
? permit.effectiveRequestsPerSecond
|
|
6438
|
+
: sandboxStartsPerMinute / 60;
|
|
6439
|
+
const spreadMs = Math.min(
|
|
6440
|
+
PACED_START_DEFER_MAX_SPREAD_MS,
|
|
6441
|
+
(PACED_START_DEFER_SPREAD_PERMITS / startsPerSecond) * 1_000,
|
|
6442
|
+
);
|
|
6443
|
+
return recoveryForCompiledStartPacing({
|
|
6444
|
+
delayMs:
|
|
6445
|
+
Math.max(PACED_START_DEFER_MIN_MS, delayMs) +
|
|
6446
|
+
(input.random ?? Math.random)() * spreadMs,
|
|
6447
|
+
});
|
|
6448
|
+
};
|
|
6130
6449
|
let locallyWaitedMs = 0;
|
|
6131
6450
|
for (;;) {
|
|
6132
6451
|
const permit = await input.acquireStartPermit(sandboxStartsPerMinute);
|
|
6133
6452
|
const scheduledAtMs = permit.scheduledAtMs?.[0] ?? input.nowMs;
|
|
6134
6453
|
const schedulerNowMs = permit.serverNowMs ?? input.nowMs;
|
|
6135
|
-
const delayMs =
|
|
6136
|
-
permit.granted > 0
|
|
6137
|
-
? Math.max(0, scheduledAtMs - schedulerNowMs)
|
|
6138
|
-
: Math.max(
|
|
6139
|
-
0,
|
|
6140
|
-
permit.waitMs,
|
|
6141
|
-
scheduledAtMs > input.nowMs ? scheduledAtMs - schedulerNowMs : 0,
|
|
6142
|
-
);
|
|
6143
|
-
// A sub-second schedule retains smooth pacing without spending a worker
|
|
6144
|
-
// attempt. Longer waits become a durable, bounded defer, allowing the
|
|
6145
|
-
// scheduler to serve unrelated traffic during a deliberate shed.
|
|
6146
|
-
if (delayMs > 1_000 || locallyWaitedMs + delayMs > 1_000) {
|
|
6147
|
-
throw recoveryForRuntimeTrafficPolicy({ mode: 'throttle' });
|
|
6148
|
-
}
|
|
6149
6454
|
if (permit.granted > 0) {
|
|
6150
|
-
|
|
6151
|
-
|
|
6455
|
+
const delayMs = Math.max(0, scheduledAtMs - schedulerNowMs);
|
|
6456
|
+
if (delayMs <= GRANTED_START_MAX_LOCAL_WAIT_MS) {
|
|
6457
|
+
if (delayMs > 0) {
|
|
6458
|
+
await (input.sleep ?? sleep)(delayMs);
|
|
6459
|
+
}
|
|
6460
|
+
return;
|
|
6152
6461
|
}
|
|
6153
|
-
|
|
6462
|
+
const reservationIds = permit.reservationIds ?? [];
|
|
6463
|
+
if (reservationIds.length !== permit.granted) {
|
|
6464
|
+
throw new Error(
|
|
6465
|
+
`Sandbox-start bucket granted ${permit.granted} permit(s) with ${reservationIds.length} reservation(s) to refund.`,
|
|
6466
|
+
);
|
|
6467
|
+
}
|
|
6468
|
+
try {
|
|
6469
|
+
await input.refundStartPermit({
|
|
6470
|
+
sandboxStartsPerMinute,
|
|
6471
|
+
reservationIds,
|
|
6472
|
+
});
|
|
6473
|
+
} catch (error) {
|
|
6474
|
+
// The reservation then expires unrefunded and the fleet loses one
|
|
6475
|
+
// start. Throwing here would replace the defer below with an
|
|
6476
|
+
// unclassified attempt error.
|
|
6477
|
+
console.error(
|
|
6478
|
+
'[absurd-runtime.worker] sandbox_start_permit_refund_failed',
|
|
6479
|
+
{
|
|
6480
|
+
reservations: reservationIds.length,
|
|
6481
|
+
error: error instanceof Error ? error.message : String(error),
|
|
6482
|
+
},
|
|
6483
|
+
);
|
|
6484
|
+
}
|
|
6485
|
+
throw deferStart(permit, schedulerNowMs, delayMs);
|
|
6486
|
+
}
|
|
6487
|
+
const delayMs = Math.max(
|
|
6488
|
+
0,
|
|
6489
|
+
permit.waitMs,
|
|
6490
|
+
scheduledAtMs > input.nowMs ? scheduledAtMs - schedulerNowMs : 0,
|
|
6491
|
+
);
|
|
6492
|
+
// A sub-second wait for a token keeps pacing smooth without spending a
|
|
6493
|
+
// worker attempt. A longer one becomes a durable defer, so the scheduler
|
|
6494
|
+
// can serve other traffic during a deliberate shed.
|
|
6495
|
+
if (
|
|
6496
|
+
delayMs > UNGRANTED_START_LOCAL_WAIT_MS ||
|
|
6497
|
+
locallyWaitedMs + delayMs > UNGRANTED_START_LOCAL_WAIT_MS
|
|
6498
|
+
) {
|
|
6499
|
+
throw deferStart(permit, schedulerNowMs, delayMs);
|
|
6154
6500
|
}
|
|
6155
6501
|
const waitMs = Math.max(1, delayMs);
|
|
6156
6502
|
await (input.sleep ?? sleep)(waitMs);
|
|
@@ -7210,6 +7556,8 @@ export function createAbsurdRuntimeTasks(
|
|
|
7210
7556
|
absurd: Absurd,
|
|
7211
7557
|
deps?: Partial<AbsurdRuntimeWorkerDeps>,
|
|
7212
7558
|
queue: string = ABSURD_RUNS_QUEUE,
|
|
7559
|
+
/** Logs task setup and handler end for each play run. */
|
|
7560
|
+
claimLoopTiming?: AbsurdClaimLoopTiming,
|
|
7213
7561
|
): void {
|
|
7214
7562
|
const resolved: AbsurdRuntimeWorkerDeps = {
|
|
7215
7563
|
...buildDefaultDeps(absurd),
|
|
@@ -7223,14 +7571,24 @@ export function createAbsurdRuntimeTasks(
|
|
|
7223
7571
|
if (deps?.deleteRuntimeSandbox && !deps.deleteRuntimeSandboxWithOutcome) {
|
|
7224
7572
|
resolved.deleteRuntimeSandboxWithOutcome = undefined;
|
|
7225
7573
|
}
|
|
7226
|
-
absurd.registerTask({ name: ABSURD_PLAY_RUN_TASK, queue }, (params, ctx) =>
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7574
|
+
absurd.registerTask({ name: ABSURD_PLAY_RUN_TASK, queue }, (params, ctx) => {
|
|
7575
|
+
const execute = () =>
|
|
7576
|
+
executeAbsurdRuntimeLaunch(
|
|
7577
|
+
params as AbsurdPlayRunTaskParams,
|
|
7578
|
+
ctx,
|
|
7579
|
+
resolved,
|
|
7580
|
+
queue,
|
|
7581
|
+
);
|
|
7582
|
+
return claimLoopTiming
|
|
7583
|
+
? claimLoopTiming.playRunHandler(
|
|
7584
|
+
{
|
|
7585
|
+
runId: (params as AbsurdPlayRunTaskParams).runId,
|
|
7586
|
+
taskId: ctx.taskID,
|
|
7587
|
+
},
|
|
7588
|
+
execute,
|
|
7589
|
+
)
|
|
7590
|
+
: execute();
|
|
7591
|
+
});
|
|
7234
7592
|
// Register on both the current lane and every adopted continuation lane.
|
|
7235
7593
|
// The task may sleep for days, but its handler schedules children on the
|
|
7236
7594
|
// current release through `resolved.currentReleaseId` after waking.
|
|
@@ -9958,6 +10316,13 @@ async function processPostgresSchedulerSandboxCleanupJob(input: {
|
|
|
9958
10316
|
kind: 'pending',
|
|
9959
10317
|
code: providerOutcome.code,
|
|
9960
10318
|
detail: `${providerOutcome.code}: ${providerOutcome.detail}`,
|
|
10319
|
+
// Only Daytona reads its acceptance back between claims.
|
|
10320
|
+
deleteAcceptedForMs: deleteProof.acceptance
|
|
10321
|
+
? Math.max(0, Date.now() - deleteProof.acceptance.acceptedAtMs)
|
|
10322
|
+
: providerOutcome.deleteAccepted &&
|
|
10323
|
+
resource.provider === 'daytona'
|
|
10324
|
+
? 0
|
|
10325
|
+
: null,
|
|
9961
10326
|
};
|
|
9962
10327
|
}
|
|
9963
10328
|
await recordCleanupEvent('provider_delete_failed', {
|
|
@@ -10682,18 +11047,18 @@ export async function hasAbsurdQueueDueWork(
|
|
|
10682
11047
|
* that claim.
|
|
10683
11048
|
*/
|
|
10684
11049
|
export function trackAbsurdClaimLoopCapacity(hooks: {
|
|
10685
|
-
afterClaim: () => Promise<void>;
|
|
11050
|
+
afterClaim: (claim: WorkerClaimSnapshot) => Promise<void>;
|
|
10686
11051
|
saturatedMaintenance: () => Promise<void>;
|
|
10687
11052
|
}): {
|
|
10688
|
-
afterClaim: () => Promise<void>;
|
|
11053
|
+
afterClaim: (claim: WorkerClaimSnapshot) => Promise<void>;
|
|
10689
11054
|
saturatedMaintenance: () => Promise<void>;
|
|
10690
11055
|
hasIdleSlot: () => boolean;
|
|
10691
11056
|
} {
|
|
10692
11057
|
let saturated = false;
|
|
10693
11058
|
return {
|
|
10694
|
-
afterClaim: () => {
|
|
11059
|
+
afterClaim: (claim) => {
|
|
10695
11060
|
saturated = false;
|
|
10696
|
-
return hooks.afterClaim();
|
|
11061
|
+
return hooks.afterClaim(claim);
|
|
10697
11062
|
},
|
|
10698
11063
|
saturatedMaintenance: () => {
|
|
10699
11064
|
saturated = true;
|
|
@@ -11016,11 +11381,18 @@ export async function startRuntimeWorkerHost(
|
|
|
11016
11381
|
const workerBase =
|
|
11017
11382
|
options.workerName?.trim() || `${hostname()}:${process.pid}`;
|
|
11018
11383
|
|
|
11019
|
-
|
|
11384
|
+
// Times the claim query, the afterClaim hook, task setup and handler end
|
|
11385
|
+
// on the active lane (`absurd-claim-loop-timing.ts`).
|
|
11386
|
+
const claimLoopTiming = createAbsurdClaimLoopTiming({ queue });
|
|
11387
|
+
const absurdClient = createAbsurdRuntimeClient(
|
|
11388
|
+
poolOptions,
|
|
11389
|
+
queue,
|
|
11390
|
+
claimLoopTiming.observer,
|
|
11391
|
+
);
|
|
11020
11392
|
const workerDeps: AbsurdRuntimeWorkerDeps = {
|
|
11021
11393
|
...buildDefaultDeps(absurdClient),
|
|
11022
11394
|
};
|
|
11023
|
-
createAbsurdRuntimeTasks(absurdClient, workerDeps, queue);
|
|
11395
|
+
createAbsurdRuntimeTasks(absurdClient, workerDeps, queue, claimLoopTiming);
|
|
11024
11396
|
// Must happen before `startWorker()` can call `claim_task()`: an expired
|
|
11025
11397
|
// engine claim otherwise retries a task whose signed completed runner
|
|
11026
11398
|
// terminal has already been durably persisted.
|
|
@@ -11088,7 +11460,7 @@ export async function startRuntimeWorkerHost(
|
|
|
11088
11460
|
// `claim_task` performs the indexed max_delay sweep. Reconcile after every
|
|
11089
11461
|
// sweep, including claims that return backlog work, so a saturated queue
|
|
11090
11462
|
// cannot postpone a cancellation's scheduler/outbox terminal indefinitely.
|
|
11091
|
-
afterClaim: reconcileRuntimeCancellations,
|
|
11463
|
+
afterClaim: claimLoopTiming.afterClaim(reconcileRuntimeCancellations),
|
|
11092
11464
|
// claim_task cannot run while every handler slot is occupied. Keep the
|
|
11093
11465
|
// enqueue deadline and cancellation lane independent from handler duration
|
|
11094
11466
|
// by sweeping without claiming, then project cancellation into the
|
|
@@ -11098,6 +11470,7 @@ export async function startRuntimeWorkerHost(
|
|
|
11098
11470
|
const worker = await absurdClient.startWorker({
|
|
11099
11471
|
workerId: `${workerBase}:${queue}`,
|
|
11100
11472
|
concurrency: slots,
|
|
11473
|
+
maxLentSlots: ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS,
|
|
11101
11474
|
claimTimeout: HEARTBEAT_CLAIM_TIMEOUT_SECONDS,
|
|
11102
11475
|
pollInterval: ABSURD_IDLE_POLL_INTERVAL_SECONDS,
|
|
11103
11476
|
afterClaim: claimLoop.afterClaim,
|
|
@@ -11344,6 +11717,7 @@ export async function startRuntimeWorkerHost(
|
|
|
11344
11717
|
console.info('[absurd-runtime.worker] started', {
|
|
11345
11718
|
schema: schedulerOptions.schema ?? null,
|
|
11346
11719
|
slots,
|
|
11720
|
+
maxLentSlots: ABSURD_RUNTIME_WORKER_MAX_LENT_SLOTS,
|
|
11347
11721
|
idlePollIntervalSeconds: ABSURD_IDLE_POLL_INTERVAL_SECONDS,
|
|
11348
11722
|
standbyProbeIntervalMs: standbyProbe
|
|
11349
11723
|
? ABSURD_ACTIVE_STANDBY_POLL_INTERVAL_MS
|