deepline 0.3.578 → 0.3.580
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 +20 -2
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/billing/public-pricing.ts +470 -15
- package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +12 -0
- package/dist/bundling-sources/shared_libs/monitors/billing/types.ts +59 -0
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-capability.ts +5 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +3 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +124 -57
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +182 -80
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +39 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +25 -0
- package/dist/bundling-sources/shared_libs/plays/sandbox-runtime-limits.ts +83 -0
- package/dist/cli/{agents-MCU3ITQZ.js → agents-BF5VX5ZB.js} +31 -31
- package/dist/cli/{agents-LRBANBZH.mjs → agents-JRFTZE7G.mjs} +4 -4
- package/dist/cli/auth-25MVD7TK.js +44 -0
- package/dist/cli/{auth-5BJKVYMQ.mjs → auth-XJXZ64R4.mjs} +5 -5
- package/dist/cli/{billing-EBBI4MVL.mjs → billing-TXJBGP2I.mjs} +69 -64
- package/dist/cli/{billing-NT57POHH.js → billing-VGMTJI7W.js} +158 -153
- package/dist/cli/{chunk-XBO4ERH6.js → chunk-2ZCFAUCV.js} +3 -3
- package/dist/cli/{chunk-P35YQAUC.js → chunk-3OSNEWGR.js} +281 -275
- package/dist/cli/{chunk-7J473OJ5.mjs → chunk-3P4QZIJ5.mjs} +1 -1
- package/dist/cli/{chunk-SKHUWQZE.js → chunk-3S5KFHQH.js} +17 -7
- package/dist/cli/{chunk-4LMTY4RQ.mjs → chunk-3ZBPXNSW.mjs} +2 -2
- package/dist/cli/{chunk-H7DY5NQ3.mjs → chunk-5BPJW6X5.mjs} +5 -5
- package/dist/cli/{chunk-A7NKOXBV.js → chunk-6VSUP4WN.js} +4 -4
- package/dist/cli/{chunk-4KNRCUKY.mjs → chunk-7HOG3JZE.mjs} +21 -15
- package/dist/cli/{chunk-OAQYLTUN.mjs → chunk-7ORX33JX.mjs} +5 -5
- package/dist/cli/{chunk-24FGR73C.js → chunk-ANX3PYLT.js} +13 -13
- package/dist/cli/{chunk-VVZ7JZMQ.js → chunk-APJ7IPRT.js} +15 -15
- package/dist/cli/{chunk-MXPCTF57.js → chunk-AZTQJJH7.js} +17 -2
- package/dist/cli/{chunk-3GF33QJJ.mjs → chunk-BAXLPQTM.mjs} +4 -4
- package/dist/cli/{chunk-DDJN4RR6.mjs → chunk-BK4Z62CF.mjs} +4 -4
- package/dist/cli/{chunk-IFWB4BYZ.mjs → chunk-C6YXUGX2.mjs} +3 -3
- package/dist/cli/{chunk-J7PCSLRY.js → chunk-COAAKSFX.js} +5 -5
- package/dist/cli/{chunk-Y2TK7OXN.js → chunk-D6I7QWOZ.js} +2 -2
- package/dist/cli/{chunk-W47SXEWQ.js → chunk-DQEHBAHL.js} +9 -9
- package/dist/cli/{chunk-ITYSPUKD.mjs → chunk-EI7KTESB.mjs} +2 -2
- package/dist/cli/{chunk-HZXF2HFF.mjs → chunk-FCJJPEKN.mjs} +5 -5
- package/dist/cli/{chunk-NEH7NZFT.js → chunk-GDBNH57Z.js} +10 -10
- package/dist/cli/{chunk-CFG3ZM7M.mjs → chunk-GE4ZEMMA.mjs} +2 -2
- package/dist/cli/{chunk-4YSJOSBG.mjs → chunk-GIZIWNL5.mjs} +1 -1
- package/dist/cli/{chunk-PJXPHUAR.mjs → chunk-H3B6QM6V.mjs} +3 -3
- package/dist/cli/{chunk-25SSGQJJ.js → chunk-HEZ24K5F.js} +2 -2
- package/dist/cli/{chunk-LYZPGP3P.mjs → chunk-HLMF53HZ.mjs} +1 -1
- package/dist/cli/{chunk-T2CCLYHV.mjs → chunk-IERWFFDB.mjs} +7 -7
- package/dist/cli/{chunk-CFLAGRWL.mjs → chunk-IG3CXIJY.mjs} +1 -1
- package/dist/cli/{chunk-ALXYCC4K.mjs → chunk-IM322G7M.mjs} +1 -1
- package/dist/cli/{chunk-RW3URFZK.mjs → chunk-KLBIHDZB.mjs} +2 -2
- package/dist/cli/{chunk-VMCJKGZS.mjs → chunk-LC4ETCOA.mjs} +2 -2
- package/dist/cli/{chunk-CS36W3RL.js → chunk-LHV3HPAY.js} +26 -26
- package/dist/cli/{chunk-CPNTDIJK.js → chunk-MBOPKQJF.js} +1 -1
- package/dist/cli/{chunk-BPMA4S3O.js → chunk-MCYZO3RB.js} +21 -21
- package/dist/cli/{chunk-JQPFICW3.mjs → chunk-MEDA3STC.mjs} +1 -1
- package/dist/cli/{chunk-ZO65VJRJ.js → chunk-MOZDEYQC.js} +11 -1
- package/dist/cli/{chunk-6UFTWNC5.mjs → chunk-MP6XUVAJ.mjs} +2 -2
- package/dist/cli/{chunk-HGQT6EGK.js → chunk-NNWEQDZR.js} +20 -20
- package/dist/cli/{chunk-AZFSCPYK.mjs → chunk-NV5IJ3NY.mjs} +17 -2
- package/dist/cli/{chunk-QPOJLAFT.mjs → chunk-O7AWGIDD.mjs} +2 -2
- package/dist/cli/{chunk-G7PH2QVM.js → chunk-PFNYLTCZ.js} +5 -5
- package/dist/cli/{chunk-DWUESXDD.mjs → chunk-QXQBTTRD.mjs} +11 -1
- package/dist/cli/{chunk-5IMWXYVB.js → chunk-R77IVVEZ.js} +53 -53
- package/dist/cli/{chunk-MXK4M7HP.js → chunk-S2YKIWCD.js} +17 -17
- package/dist/cli/{chunk-FYKHAT2F.mjs → chunk-SECFDB27.mjs} +10 -0
- package/dist/cli/{chunk-NTHN7ODR.mjs → chunk-SQBSK74D.mjs} +7 -3
- package/dist/cli/{chunk-M3ITWEGS.js → chunk-TSOXJZSW.js} +41 -41
- package/dist/cli/{chunk-CSPOWVWS.mjs → chunk-U4VCAECC.mjs} +8 -3
- package/dist/cli/{chunk-RLPPLS6A.js → chunk-URZPR54R.js} +6 -6
- package/dist/cli/{chunk-27HAQRGH.js → chunk-V5NDHTBB.js} +23 -23
- package/dist/cli/{chunk-HKZN33F2.mjs → chunk-VF3EGTHU.mjs} +3 -3
- package/dist/cli/{chunk-5LCV36BR.js → chunk-VOQWPUIF.js} +20 -20
- package/dist/cli/{chunk-3ZUKYLC6.js → chunk-WJUAVMQC.js} +217 -213
- package/dist/cli/{chunk-W66GXHYR.mjs → chunk-X5RXG6VS.mjs} +1 -1
- package/dist/cli/{chunk-UKSOIH2P.js → chunk-XFVJ3JNA.js} +5 -5
- package/dist/cli/{chunk-RWDYULX2.js → chunk-XQUVLYOL.js} +17 -12
- package/dist/cli/{chunk-XE66BGLB.js → chunk-YY6EB252.js} +2 -2
- package/dist/cli/{chunk-XX7TZM4N.js → chunk-Z6DERGHY.js} +48 -48
- package/dist/cli/{chunk-PXMCPEE2.js → chunk-ZADJC22U.js} +3 -3
- package/dist/cli/{chunk-4CNHOBUO.mjs → chunk-ZR7PDXIA.mjs} +2 -2
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/concurrent-runs-help-DEN63DUM.js +22 -0
- package/dist/cli/{concurrent-runs-help-2MHLIUC6.mjs → concurrent-runs-help-DSUQRWZQ.mjs} +6 -6
- package/dist/cli/{csv-RYYDAC76.js → csv-HSHF6JYZ.js} +13 -13
- package/dist/cli/{csv-J6SRBMOT.mjs → csv-QNXJBT5T.mjs} +4 -4
- package/dist/cli/{db-WK226TM7.mjs → db-RAWY3SWS.mjs} +6 -6
- package/dist/cli/{db-5QLH6QK5.js → db-VHYWVLLU.js} +27 -27
- package/dist/cli/{describe-UBSCFPH5.mjs → describe-WZOVHWAM.mjs} +21 -21
- package/dist/cli/describe-YHZ2EGBQ.js +50 -0
- package/dist/cli/describe-core.d.mts +4 -2
- package/dist/cli/describe-core.d.ts +4 -2
- package/dist/cli/describe-core.js +4 -4
- package/dist/cli/describe-core.mjs +3 -3
- package/dist/cli/{executions-AGV5V7SD.js → executions-DQIFH4Z6.js} +8 -8
- package/dist/cli/{executions-XF5BNCFS.mjs → executions-QABOXV4K.mjs} +6 -6
- package/dist/cli/{feedback-3RDEZE2M.js → feedback-6IER2W4G.js} +14 -14
- package/dist/cli/{feedback-LT3PDK72.mjs → feedback-DW4O63DG.mjs} +6 -6
- package/dist/cli/{git-7VBTCCBV.mjs → git-3NAPGZGR.mjs} +5 -5
- package/dist/cli/git-SQ2MAKAH.js +26 -0
- package/dist/cli/index.js +148 -148
- package/dist/cli/index.mjs +47 -47
- package/dist/cli/{integrations-JP732FQB.js → integrations-5LHIBBXB.js} +29 -29
- package/dist/cli/{integrations-E7QRWMKZ.mjs → integrations-TSRUTENK.mjs} +7 -7
- package/dist/cli/{legacy-noops-UFNQBPIT.mjs → legacy-noops-4N63A6H7.mjs} +6 -6
- package/dist/cli/{legacy-noops-UTL4W5WE.js → legacy-noops-S22XGYGN.js} +9 -9
- package/dist/cli/{mcp-YHETA3AU.mjs → mcp-4EJHRRFV.mjs} +4 -4
- package/dist/cli/{mcp-5X4XFB4V.js → mcp-JERBGJYE.js} +24 -24
- package/dist/cli/{monitors-WFVZ42OQ.mjs → monitors-7BTLBD6S.mjs} +16 -11
- package/dist/cli/{monitors-AN6KH4XY.js → monitors-FF35CGC4.js} +109 -104
- package/dist/cli/{org-CN3XJZLA.js → org-ADCDO7KU.js} +121 -121
- package/dist/cli/{org-OMDV7WDF.mjs → org-QYIIBKA2.mjs} +6 -6
- package/dist/cli/{outcomes-7HCZ6K3Q.js → outcomes-2LW4GK2L.js} +14 -14
- package/dist/cli/{outcomes-I4ZTG5ND.mjs → outcomes-C5DIBG4Q.mjs} +6 -6
- package/dist/cli/{play-TSNBSHGA.mjs → play-DTTDTISL.mjs} +20 -20
- package/dist/cli/{play-45VXZ57A.js → play-S5MZ2GRA.js} +349 -349
- package/dist/cli/{providers-4TB56ZLK.mjs → providers-AXOEFQ6Q.mjs} +6 -6
- package/dist/cli/{providers-RB3TT7AE.js → providers-N2IWEJBW.js} +9 -9
- package/dist/cli/{quickstart-XHZ3PG5I.mjs → quickstart-ADWSZBV6.mjs} +4 -4
- package/dist/cli/{quickstart-ZNDM6VUD.js → quickstart-UC5AJZWU.js} +6 -6
- package/dist/cli/{run-XNEJGAKV.js → run-6TDYUL7L.js} +49 -48
- package/dist/cli/{run-7PY4G6GB.mjs → run-R2FVH3K6.mjs} +27 -26
- package/dist/cli/{search-BG7KCIOG.mjs → search-GRHUFSLY.mjs} +7 -7
- package/dist/cli/search-V7ANBX3J.js +32 -0
- package/dist/cli/{search-output-3ZBNTHGO.js → search-output-O7NY3VMD.js} +8 -8
- package/dist/cli/{search-output-TWKKP2BE.mjs → search-output-UPQNAFAF.mjs} +5 -5
- package/dist/cli/{secrets-FNR6MX6A.js → secrets-72GJHFER.js} +15 -15
- package/dist/cli/{secrets-AZZCE7E3.mjs → secrets-NKAEJLIQ.mjs} +6 -6
- package/dist/cli/sessions-EO6RTMUC.js +23 -0
- package/dist/cli/{sessions-ZAMKN3AF.mjs → sessions-VIMF3UF5.mjs} +6 -6
- package/dist/cli/{settings-QGASFWV3.js → settings-HFAW5HIF.js} +85 -85
- package/dist/cli/{settings-WKWOOOI2.mjs → settings-KCQHBFNZ.mjs} +12 -12
- package/dist/cli/{setup-KUZDCR3F.js → setup-2MHWGEAD.js} +49 -49
- package/dist/cli/{setup-U36W42LE.mjs → setup-2ZD5ZIUH.mjs} +9 -9
- package/dist/cli/skills-ID6KKDLH.js +37 -0
- package/dist/cli/{skills-25CSZQIK.mjs → skills-X2DZZG5P.mjs} +7 -7
- package/dist/cli/tools-7UY7GERW.js +57 -0
- package/dist/cli/{tools-4NZQ22AA.mjs → tools-KPTOWKD4.mjs} +19 -19
- package/dist/cli/{update-CJYP36TG.mjs → update-6PMQCEUP.mjs} +9 -9
- package/dist/cli/update-T2RDLLSY.js +37 -0
- package/dist/cli/{views-76UIPWJD.js → views-MNBHNO6C.js} +37 -24
- package/dist/cli/{views-GYGE7FSV.mjs → views-VRZ5CTFL.mjs} +21 -8
- package/dist/cli/{workflow-LZSWALZS.mjs → workflow-7JUJWA5S.mjs} +7 -7
- package/dist/cli/{workflow-NCVXBATM.js → workflow-SSMFO7YE.js} +17 -17
- package/dist/{client-CF-bsrtI.d.mts → client-CmG8MT0x.d.mts} +1 -1
- package/dist/{client-BrdMPFCM.d.ts → client-QznpkWrk.d.ts} +1 -1
- package/dist/{client-core-rMoUWSYM.d.ts → client-core-CXDqfeiB.d.ts} +12 -1
- package/dist/{client-core-DM1ZedOG.d.mts → client-core-CY0jNW0e.d.mts} +12 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +126 -126
- package/dist/plays/play-description.d.mts +1 -1
- package/dist/plays/play-description.d.ts +1 -1
- package/dist/plays/run-request.d.mts +1 -1
- package/dist/plays/run-request.d.ts +1 -1
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-VSW3MTFO.js +0 -44
- package/dist/cli/concurrent-runs-help-ATT2GVTQ.js +0 -22
- package/dist/cli/describe-Q27SRQWM.js +0 -50
- package/dist/cli/git-BBTP3H7J.js +0 -26
- package/dist/cli/search-ZBU5GW4W.js +0 -32
- package/dist/cli/sessions-GCY62GAW.js +0 -23
- package/dist/cli/skills-43DHMLRW.js +0 -37
- package/dist/cli/tools-5BGKNMFU.js +0 -57
- package/dist/cli/update-CUO2MTB6.js +0 -37
|
@@ -600,6 +600,11 @@ export type EarlySandboxStartRequest = {
|
|
|
600
600
|
runtimeSchedulerSchema: string | null;
|
|
601
601
|
/** EXPERIMENT: the hinted run's overrides (E2, PB, S1); absent: static. */
|
|
602
602
|
experimentSwitchOverrides?: ExperimentSwitchOverrides | null;
|
|
603
|
+
/**
|
|
604
|
+
* The hinted run's validated sandbox runtime limits (its launch's own).
|
|
605
|
+
* Absent: the standard profile, as before.
|
|
606
|
+
*/
|
|
607
|
+
sandboxRuntimeLimits?: PlaySandboxRuntimeLimits | null;
|
|
603
608
|
};
|
|
604
609
|
|
|
605
610
|
/**
|
|
@@ -1220,6 +1225,19 @@ export async function adoptEarlySandbox<
|
|
|
1220
1225
|
});
|
|
1221
1226
|
return null;
|
|
1222
1227
|
}
|
|
1228
|
+
// A sandbox created at other limits (size or timeout) than this launch's
|
|
1229
|
+
// can never be adopted. Decide that from the create tags first: it is an
|
|
1230
|
+
// ordinary miss, not a pre-boot plan failure (the plan's MAC binds the
|
|
1231
|
+
// limits too, and would otherwise report a mismatch as invalid).
|
|
1232
|
+
if (tags.limitsKey !== input.expectedLimitsKey) {
|
|
1233
|
+
input.emitStage('early:adopt_miss', {
|
|
1234
|
+
key,
|
|
1235
|
+
reason: 'limits_mismatch',
|
|
1236
|
+
sandboxId: sandbox.sandboxId,
|
|
1237
|
+
elapsedMs: nowMs() - startedAt,
|
|
1238
|
+
});
|
|
1239
|
+
return null;
|
|
1240
|
+
}
|
|
1223
1241
|
// PB: another process started a runner here and holds its delivery
|
|
1224
1242
|
// plan; nothing may be delivered to it from this process. Provider
|
|
1225
1243
|
// claims (Modal's S1 sidecar) come first.
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts
CHANGED
|
@@ -215,6 +215,7 @@ import {
|
|
|
215
215
|
enqueuePostgresSchedulerSandboxCleanupForRun,
|
|
216
216
|
hasPostgresSchedulerRecoverableDetachedRunner,
|
|
217
217
|
executePostgresSchedulerClaim,
|
|
218
|
+
PostgresSchedulerAttemptFenceRefusedError,
|
|
218
219
|
ensurePostgresSchedulerTerminalComputeBillingJob,
|
|
219
220
|
failPostgresSchedulerAttempt,
|
|
220
221
|
getPostgresSchedulerObservations,
|
|
@@ -8361,45 +8362,46 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
|
|
|
8361
8362
|
));
|
|
8362
8363
|
let recovered = 0;
|
|
8363
8364
|
let skipped = 0;
|
|
8365
|
+
const failures: unknown[] = [];
|
|
8364
8366
|
|
|
8365
8367
|
for (const terminal of terminals) {
|
|
8366
|
-
const runnerResult = parseDetachedRunnerResult(terminal.result);
|
|
8367
|
-
if (
|
|
8368
|
-
runnerResult?.status !== 'completed' &&
|
|
8369
|
-
runnerResult?.status !== 'failed'
|
|
8370
|
-
) {
|
|
8371
|
-
skipped += 1;
|
|
8372
|
-
continue;
|
|
8373
|
-
}
|
|
8374
|
-
const absurdRun = await readOpenAbsurdEngineRunId({
|
|
8375
|
-
client: input.client,
|
|
8376
|
-
queue: input.queue,
|
|
8377
|
-
schedulerRunId: terminal.runId,
|
|
8378
|
-
});
|
|
8379
|
-
// A platform failure retries the same run. While its engine task is open,
|
|
8380
|
-
// the parked worker decides that when it wakes; committing the terminal
|
|
8381
|
-
// here would end the run. A run with no open task has no one to wake it,
|
|
8382
|
-
// so it still ends here.
|
|
8383
|
-
if (
|
|
8384
|
-
absurdRun &&
|
|
8385
|
-
DURABLE_RUNS_ROLLOUT.automaticPostCodeRecovery &&
|
|
8386
|
-
classifyPostCodeAttemptOutcome(runnerResult).kind === 'platform'
|
|
8387
|
-
) {
|
|
8388
|
-
skipped += 1;
|
|
8389
|
-
continue;
|
|
8390
|
-
}
|
|
8391
|
-
const launch = await readPostgresSchedulerLaunch(
|
|
8392
|
-
input.client,
|
|
8393
|
-
terminal.runId,
|
|
8394
|
-
options,
|
|
8395
|
-
{ caller: 'runtime_worker_terminal_recovery' },
|
|
8396
|
-
);
|
|
8397
|
-
if (!launch) {
|
|
8398
|
-
skipped += 1;
|
|
8399
|
-
continue;
|
|
8400
|
-
}
|
|
8401
|
-
|
|
8402
8368
|
try {
|
|
8369
|
+
const runnerResult = parseDetachedRunnerResult(terminal.result);
|
|
8370
|
+
if (
|
|
8371
|
+
runnerResult?.status !== 'completed' &&
|
|
8372
|
+
runnerResult?.status !== 'failed'
|
|
8373
|
+
) {
|
|
8374
|
+
skipped += 1;
|
|
8375
|
+
continue;
|
|
8376
|
+
}
|
|
8377
|
+
const absurdRun = await readOpenAbsurdEngineRunId({
|
|
8378
|
+
client: input.client,
|
|
8379
|
+
queue: input.queue,
|
|
8380
|
+
schedulerRunId: terminal.runId,
|
|
8381
|
+
});
|
|
8382
|
+
// A platform failure retries the same run. While its engine task is open,
|
|
8383
|
+
// the parked worker decides that when it wakes; committing the terminal
|
|
8384
|
+
// here would end the run. A run with no open task has no one to wake it,
|
|
8385
|
+
// so it still ends here.
|
|
8386
|
+
if (
|
|
8387
|
+
absurdRun &&
|
|
8388
|
+
DURABLE_RUNS_ROLLOUT.automaticPostCodeRecovery &&
|
|
8389
|
+
classifyPostCodeAttemptOutcome(runnerResult).kind === 'platform'
|
|
8390
|
+
) {
|
|
8391
|
+
skipped += 1;
|
|
8392
|
+
continue;
|
|
8393
|
+
}
|
|
8394
|
+
const launch = await readPostgresSchedulerLaunch(
|
|
8395
|
+
input.client,
|
|
8396
|
+
terminal.runId,
|
|
8397
|
+
options,
|
|
8398
|
+
{ caller: 'runtime_worker_terminal_recovery' },
|
|
8399
|
+
);
|
|
8400
|
+
if (!launch) {
|
|
8401
|
+
skipped += 1;
|
|
8402
|
+
continue;
|
|
8403
|
+
}
|
|
8404
|
+
|
|
8403
8405
|
// Reuse the fenced normal completion implementation. This preserves the
|
|
8404
8406
|
// terminal output envelope, resource settlement, billing, and ledger
|
|
8405
8407
|
// outbox semantics instead of inventing a recovery-only terminal write.
|
|
@@ -8531,9 +8533,24 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
|
|
|
8531
8533
|
);
|
|
8532
8534
|
}
|
|
8533
8535
|
} catch (error) {
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8536
|
+
if (error instanceof PostgresSchedulerAttemptFenceRefusedError) {
|
|
8537
|
+
// The scan raced the attempt's owner: it terminalized the attempt, or
|
|
8538
|
+
// a reclaim replaced this lease, after the scan read it. The owner
|
|
8539
|
+
// settles the run; this pass has nothing to recover and the next scan
|
|
8540
|
+
// re-reads the row. Retrying here would lose the same fence.
|
|
8541
|
+
skipped += 1;
|
|
8542
|
+
console.warn(
|
|
8543
|
+
'[absurd-runtime.worker] completed_runner_recovery_fenced',
|
|
8544
|
+
{
|
|
8545
|
+
runId: terminal.runId,
|
|
8546
|
+
attempt: terminal.attempt,
|
|
8547
|
+
queue: input.queue,
|
|
8548
|
+
reason: 'attempt_fence_refused',
|
|
8549
|
+
error: error.message,
|
|
8550
|
+
},
|
|
8551
|
+
);
|
|
8552
|
+
continue;
|
|
8553
|
+
}
|
|
8537
8554
|
console.error(
|
|
8538
8555
|
'[absurd-runtime.worker] completed_runner_recovery_failed',
|
|
8539
8556
|
{
|
|
@@ -8543,12 +8560,49 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminals(input: {
|
|
|
8543
8560
|
error: error instanceof Error ? error.message : String(error),
|
|
8544
8561
|
},
|
|
8545
8562
|
);
|
|
8546
|
-
|
|
8547
|
-
|
|
8563
|
+
// One run's failure must not strand every other durable terminal in
|
|
8564
|
+
// this pass. Finish the pass, then reject below.
|
|
8565
|
+
failures.push(error);
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8568
|
+
// Do not start the claim loop after this function rejects: startup must
|
|
8569
|
+
// fail loudly rather than reclaiming an acknowledged runner terminal and
|
|
8570
|
+
// risking a duplicate play execution. Every other terminal in this pass
|
|
8571
|
+
// has already been attempted.
|
|
8572
|
+
if (failures.length > 0) {
|
|
8573
|
+
throw completedRunnerRecoveryFailure(
|
|
8574
|
+
failures,
|
|
8575
|
+
`${failures.length} of ${terminals.length} terminals on ${input.queue}`,
|
|
8576
|
+
);
|
|
8548
8577
|
}
|
|
8549
8578
|
return { recovered, skipped };
|
|
8550
8579
|
}
|
|
8551
8580
|
|
|
8581
|
+
/**
|
|
8582
|
+
* One failure rethrows as-is. Several become an AggregateError that keeps the
|
|
8583
|
+
* first retryable transaction SQLSTATE (deadlock, serialization, lock) as its
|
|
8584
|
+
* own `code`, so the scheduler pool still re-runs the idempotent recovery
|
|
8585
|
+
* operation instead of surfacing a transient lock conflict as a failed pass.
|
|
8586
|
+
*/
|
|
8587
|
+
function completedRunnerRecoveryFailure(
|
|
8588
|
+
failures: unknown[],
|
|
8589
|
+
scope: string,
|
|
8590
|
+
): unknown {
|
|
8591
|
+
if (failures.length === 1) return failures[0];
|
|
8592
|
+
const first = failures[0];
|
|
8593
|
+
const aggregate = new AggregateError(
|
|
8594
|
+
failures,
|
|
8595
|
+
`Completed runner terminal recovery failed for ${scope}; first: ${first instanceof Error ? first.message : String(first)}`,
|
|
8596
|
+
);
|
|
8597
|
+
const retryable = failures.find((failure): failure is { code: unknown } =>
|
|
8598
|
+
isRuntimeSchedulerRetryableTransactionError(failure),
|
|
8599
|
+
);
|
|
8600
|
+
if (retryable) {
|
|
8601
|
+
Object.assign(aggregate, { code: retryable.code });
|
|
8602
|
+
}
|
|
8603
|
+
return aggregate;
|
|
8604
|
+
}
|
|
8605
|
+
|
|
8552
8606
|
/**
|
|
8553
8607
|
* Fixed-controller recovery across all registered lanes.
|
|
8554
8608
|
*
|
|
@@ -8591,17 +8645,30 @@ export async function recoverAbsurdRuntimeCompletedRunnerTerminalsAcrossLanes(in
|
|
|
8591
8645
|
|
|
8592
8646
|
let recovered = 0;
|
|
8593
8647
|
let skipped = 0;
|
|
8648
|
+
const failures: unknown[] = [];
|
|
8594
8649
|
for (const releaseId of releaseIds) {
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8604
|
-
|
|
8650
|
+
try {
|
|
8651
|
+
const outcome = await recoverAbsurdRuntimeCompletedRunnerTerminals({
|
|
8652
|
+
client: input.client,
|
|
8653
|
+
queue: absurdQueueNameForRelease(releaseId),
|
|
8654
|
+
absurdReleaseId: releaseId,
|
|
8655
|
+
schedulerOptions: input.schedulerOptions,
|
|
8656
|
+
limit: input.limitPerLane,
|
|
8657
|
+
terminals: terminalsByReleaseId.get(releaseId) ?? [],
|
|
8658
|
+
});
|
|
8659
|
+
recovered += outcome.recovered;
|
|
8660
|
+
skipped += outcome.skipped;
|
|
8661
|
+
} catch (error) {
|
|
8662
|
+
// Each failed terminal was already logged with its run identity. One
|
|
8663
|
+
// lane's failure must not strand every later lane's terminals.
|
|
8664
|
+
failures.push(error);
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8667
|
+
if (failures.length > 0) {
|
|
8668
|
+
throw completedRunnerRecoveryFailure(
|
|
8669
|
+
failures,
|
|
8670
|
+
`${failures.length} of ${releaseIds.length} lanes`,
|
|
8671
|
+
);
|
|
8605
8672
|
}
|
|
8606
8673
|
return { recovered, skipped };
|
|
8607
8674
|
}
|
|
@@ -12060,12 +12127,12 @@ export async function startRuntimeWorkerHost(
|
|
|
12060
12127
|
let claimAffinityWake: (() => boolean) | null = null;
|
|
12061
12128
|
const claimAffinityGate =
|
|
12062
12129
|
EARLY_SANDBOX_CLAIM_AFFINITY_READER || previewClaimAffinityReader
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12068
|
-
|
|
12130
|
+
? createEarlySandboxClaimGate({
|
|
12131
|
+
self: workerBase,
|
|
12132
|
+
queue,
|
|
12133
|
+
wake: () => claimAffinityWake?.() ?? false,
|
|
12134
|
+
})
|
|
12135
|
+
: undefined;
|
|
12069
12136
|
// LH: live slot use, from claimed task ids and running handlers; the
|
|
12070
12137
|
// engine's saturation reading is bound below once the claim loop exists.
|
|
12071
12138
|
let claimLoopHasIdleSlot: () => boolean = () => false;
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts
CHANGED
|
@@ -402,6 +402,10 @@ export function startWorkerLaneEarlySandbox(
|
|
|
402
402
|
orgId: input.orgId ?? null,
|
|
403
403
|
runtimeSchedulerSchema: input.runtimeSchedulerSchema,
|
|
404
404
|
experimentSwitchOverrides: input.experimentSwitchOverrides ?? null,
|
|
405
|
+
// Only when the hint carried them: a run without keeps today's request.
|
|
406
|
+
...(input.sandboxRuntimeLimits
|
|
407
|
+
? { sandboxRuntimeLimits: input.sandboxRuntimeLimits }
|
|
408
|
+
: {}),
|
|
405
409
|
};
|
|
406
410
|
if (
|
|
407
411
|
!resolveExperimentSwitch(
|
|
@@ -119,11 +119,7 @@ import {
|
|
|
119
119
|
type ToolResponseContract,
|
|
120
120
|
} from '../../plays/tool-response-contract';
|
|
121
121
|
import { normalizePlayRunFailure } from '../run-failure';
|
|
122
|
-
import {
|
|
123
|
-
resolvePlaySandboxRuntimeLimits,
|
|
124
|
-
validatePlaySandboxRuntimeLimits,
|
|
125
|
-
type PlaySandboxRuntimeLimits,
|
|
126
|
-
} from '../sandbox-runtime-limits';
|
|
122
|
+
import { sandboxRuntimeLimitsFromContractSnapshot } from '../sandbox-runtime-limits';
|
|
127
123
|
import type {
|
|
128
124
|
ClaimRuntimeStepReceiptInput,
|
|
129
125
|
ClaimRuntimeStepReceiptsInput,
|
|
@@ -12929,7 +12925,7 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
|
|
|
12929
12925
|
// a fence loss, never success (PX: two launches adopted one early sandbox).
|
|
12930
12926
|
const recorded = await client
|
|
12931
12927
|
.query<{ operation_key: string }>(
|
|
12932
|
-
|
|
12928
|
+
`
|
|
12933
12929
|
WITH ${runtimeSandboxCustodyLocksSql('run.run_id = $1', options)}, eligible_attempt AS (
|
|
12934
12930
|
SELECT run_id
|
|
12935
12931
|
FROM custody_attempts
|
|
@@ -12996,20 +12992,20 @@ export async function recordPostgresSchedulerManagedSandboxOperationLive(
|
|
|
12996
12992
|
FROM live_operation
|
|
12997
12993
|
JOIN bound_capacity ON bound_capacity.lease_id = live_operation.operation_key
|
|
12998
12994
|
`,
|
|
12999
|
-
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
12995
|
+
[
|
|
12996
|
+
input.runId,
|
|
12997
|
+
input.attempt,
|
|
12998
|
+
input.leaseToken,
|
|
12999
|
+
stringifyPostgresJson(input.resource),
|
|
13000
|
+
input.resource.sandboxCapacityLeaseId,
|
|
13001
|
+
input.resource.sandboxId,
|
|
13002
|
+
routingDomain,
|
|
13003
|
+
environment,
|
|
13004
|
+
runtimeSandboxOperationTargetState('bind_live'),
|
|
13005
|
+
provider,
|
|
13006
|
+
runtimeSandboxOperationFromStates('bind_live'),
|
|
13007
|
+
],
|
|
13008
|
+
)
|
|
13013
13009
|
.catch((error: unknown) => {
|
|
13014
13010
|
if ((error as { code?: unknown } | null)?.code === '23505')
|
|
13015
13011
|
return { rows: [] as { operation_key: string }[] };
|
|
@@ -20079,6 +20075,28 @@ export function attachRunnerWorkProgressMetadata(
|
|
|
20079
20075
|
};
|
|
20080
20076
|
}
|
|
20081
20077
|
|
|
20078
|
+
/**
|
|
20079
|
+
* The fenced failure write refused this claim: the attempt is no longer
|
|
20080
|
+
* `running` under this lease token (its owner already terminalized it, or a
|
|
20081
|
+
* reclaim replaced the lease), or an authoritative runner terminal won. The
|
|
20082
|
+
* caller no longer owns the attempt, so this is a fence outcome, not a
|
|
20083
|
+
* service failure. The message is unchanged from the untyped error it
|
|
20084
|
+
* replaces so existing log searches and `lease_expired` classification hold.
|
|
20085
|
+
*/
|
|
20086
|
+
export class PostgresSchedulerAttemptFenceRefusedError extends Error {
|
|
20087
|
+
readonly runId: string;
|
|
20088
|
+
readonly attempt: number;
|
|
20089
|
+
|
|
20090
|
+
constructor(input: { runId: string; attempt: number; message: string }) {
|
|
20091
|
+
super(
|
|
20092
|
+
`Postgres scheduler worker failed after losing lease for ${input.runId}/${input.attempt}: ${input.message}`,
|
|
20093
|
+
);
|
|
20094
|
+
this.name = 'PostgresSchedulerAttemptFenceRefusedError';
|
|
20095
|
+
this.runId = input.runId;
|
|
20096
|
+
this.attempt = input.attempt;
|
|
20097
|
+
}
|
|
20098
|
+
}
|
|
20099
|
+
|
|
20082
20100
|
export async function executePostgresSchedulerClaim(
|
|
20083
20101
|
client: PostgresSchedulerQueryClient,
|
|
20084
20102
|
claim: PostgresSchedulerAttemptClaim,
|
|
@@ -20332,9 +20350,11 @@ export async function executePostgresSchedulerClaim(
|
|
|
20332
20350
|
options,
|
|
20333
20351
|
);
|
|
20334
20352
|
if (!failed) {
|
|
20335
|
-
throw new
|
|
20336
|
-
|
|
20337
|
-
|
|
20353
|
+
throw new PostgresSchedulerAttemptFenceRefusedError({
|
|
20354
|
+
runId: claim.runId,
|
|
20355
|
+
attempt: claim.attempt,
|
|
20356
|
+
message,
|
|
20357
|
+
});
|
|
20338
20358
|
}
|
|
20339
20359
|
emitPlayRunFinished({
|
|
20340
20360
|
orgId: claim.launch.orgId ?? null,
|
|
@@ -20432,47 +20452,6 @@ function toolResponseReceiptRevisionFromLaunch(
|
|
|
20432
20452
|
);
|
|
20433
20453
|
}
|
|
20434
20454
|
|
|
20435
|
-
function sandboxRuntimeLimitsFromContractSnapshot(
|
|
20436
|
-
contractSnapshot: unknown,
|
|
20437
|
-
): PlaySandboxRuntimeLimits {
|
|
20438
|
-
if (
|
|
20439
|
-
!contractSnapshot ||
|
|
20440
|
-
typeof contractSnapshot !== 'object' ||
|
|
20441
|
-
Array.isArray(contractSnapshot)
|
|
20442
|
-
) {
|
|
20443
|
-
return resolvePlaySandboxRuntimeLimits(null);
|
|
20444
|
-
}
|
|
20445
|
-
const runtimeLimit = (contractSnapshot as Record<string, unknown>)
|
|
20446
|
-
.runtimeLimit;
|
|
20447
|
-
if (
|
|
20448
|
-
!runtimeLimit ||
|
|
20449
|
-
typeof runtimeLimit !== 'object' ||
|
|
20450
|
-
Array.isArray(runtimeLimit)
|
|
20451
|
-
) {
|
|
20452
|
-
return resolvePlaySandboxRuntimeLimits(null);
|
|
20453
|
-
}
|
|
20454
|
-
const value = runtimeLimit as Record<string, unknown>;
|
|
20455
|
-
const timeoutSeconds = value.timeoutSeconds;
|
|
20456
|
-
const memoryGiB = value.memoryGiB;
|
|
20457
|
-
const cpu = value.cpu;
|
|
20458
|
-
const diskGiB = value.diskGiB;
|
|
20459
|
-
if (
|
|
20460
|
-
![timeoutSeconds, memoryGiB, cpu, diskGiB].every(
|
|
20461
|
-
(entry) => typeof entry === 'number' && Number.isFinite(entry),
|
|
20462
|
-
)
|
|
20463
|
-
) {
|
|
20464
|
-
throw new Error(
|
|
20465
|
-
'Persisted Play runtime limit is invalid. Re-submit the run with the current runtime contract.',
|
|
20466
|
-
);
|
|
20467
|
-
}
|
|
20468
|
-
return validatePlaySandboxRuntimeLimits({
|
|
20469
|
-
timeoutSeconds: timeoutSeconds as number,
|
|
20470
|
-
memoryGiB: memoryGiB as number,
|
|
20471
|
-
cpu: cpu as number,
|
|
20472
|
-
diskGiB: diskGiB as number,
|
|
20473
|
-
});
|
|
20474
|
-
}
|
|
20475
|
-
|
|
20476
20455
|
export function buildPostgresSchedulerRunnerContext(
|
|
20477
20456
|
launch: PlaySchedulerSubmitInput,
|
|
20478
20457
|
runAttempt: number,
|
|
@@ -23974,15 +23953,15 @@ function runLedgerDiscoveryHeadsSql(
|
|
|
23974
23953
|
)`;
|
|
23975
23954
|
}
|
|
23976
23955
|
|
|
23977
|
-
|
|
23956
|
+
/** Whether another delivery currently leases this run's lane. */
|
|
23957
|
+
function runLedgerRunLeasedSql(
|
|
23958
|
+
runIdSql: string,
|
|
23978
23959
|
options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
|
|
23979
23960
|
searchOnly: boolean,
|
|
23980
23961
|
): string {
|
|
23981
|
-
return `
|
|
23982
|
-
AND coalesce(head.next_attempt_at, head.created_at) <= now()
|
|
23983
|
-
AND NOT EXISTS (
|
|
23962
|
+
return `EXISTS (
|
|
23984
23963
|
SELECT 1 FROM ${tableName('outbox', options)} AS active
|
|
23985
|
-
WHERE active.run_id =
|
|
23964
|
+
WHERE active.run_id = ${runIdSql}
|
|
23986
23965
|
AND ${searchLaneSql('active')} = ${String(searchOnly)}
|
|
23987
23966
|
AND active.delivered_at IS NULL
|
|
23988
23967
|
AND active.lease_owner IS NOT NULL
|
|
@@ -23990,7 +23969,52 @@ function runLedgerReadyHeadSql(
|
|
|
23990
23969
|
)`;
|
|
23991
23970
|
}
|
|
23992
23971
|
|
|
23993
|
-
function
|
|
23972
|
+
function runLedgerReadyHeadSql(
|
|
23973
|
+
options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
|
|
23974
|
+
searchOnly: boolean,
|
|
23975
|
+
/** A lease already computed for this head (`head_workspace_share.leased`). */
|
|
23976
|
+
leasedSql?: string,
|
|
23977
|
+
): string {
|
|
23978
|
+
return `head.failed_at IS NULL
|
|
23979
|
+
AND coalesce(head.next_attempt_at, head.created_at) <= now()
|
|
23980
|
+
AND NOT ${leasedSql ?? runLedgerRunLeasedSql('runs.run_id', options, searchOnly)}`;
|
|
23981
|
+
}
|
|
23982
|
+
|
|
23983
|
+
/**
|
|
23984
|
+
* Workspace fair share for global claims and admission hints. Each discovered
|
|
23985
|
+
* head belongs to a run; a run leased by an in-flight delivery still has its
|
|
23986
|
+
* head pending. The count of such leased heads per workspace is that
|
|
23987
|
+
* workspace's current share of the drain. Ordering ready heads by it gives
|
|
23988
|
+
* the next free slot to the workspace with the fewest deliveries in flight,
|
|
23989
|
+
* so one workspace's backlog cannot delay every other workspace's projection
|
|
23990
|
+
* (Production 2026-12-01 06:09-06:51Z). It is work-conserving: a lone
|
|
23991
|
+
* backlogged workspace still receives every free slot. Admission class still
|
|
23992
|
+
* comes first and age orders heads within an equal share. Each head's lease
|
|
23993
|
+
* is read once here and reused by the ready filter. Window functions cannot
|
|
23994
|
+
* share a query level with FOR UPDATE, so the share is materialized beside
|
|
23995
|
+
* the heads.
|
|
23996
|
+
*/
|
|
23997
|
+
function runLedgerWorkspaceShareSql(
|
|
23998
|
+
options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
|
|
23999
|
+
searchOnly: boolean,
|
|
24000
|
+
): string {
|
|
24001
|
+
return `head_workspace_share AS MATERIALIZED (
|
|
24002
|
+
SELECT leased_head.run_id,
|
|
24003
|
+
leased_head.leased,
|
|
24004
|
+
count(*) FILTER (WHERE leased_head.leased)
|
|
24005
|
+
OVER (PARTITION BY leased_head.org_id) AS workspace_in_flight
|
|
24006
|
+
FROM (
|
|
24007
|
+
SELECT head.run_id,
|
|
24008
|
+
share_run.org_id,
|
|
24009
|
+
${runLedgerRunLeasedSql('head.run_id', options, searchOnly)} AS leased
|
|
24010
|
+
FROM heads AS head
|
|
24011
|
+
JOIN ${tableName('runs', options)} AS share_run
|
|
24012
|
+
ON share_run.run_id = head.run_id
|
|
24013
|
+
) AS leased_head
|
|
24014
|
+
)`;
|
|
24015
|
+
}
|
|
24016
|
+
|
|
24017
|
+
function runLedgerAdmissionClassSql(
|
|
23994
24018
|
options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
|
|
23995
24019
|
searchOnly: boolean,
|
|
23996
24020
|
): string {
|
|
@@ -23999,7 +24023,14 @@ function runLedgerAdmissionOrderSql(
|
|
|
23999
24023
|
WHEN ${runLedgerTerminalPendingSql('head', options)} THEN 1
|
|
24000
24024
|
${searchOnly ? '' : `WHEN ${runLedgerWaitingPendingSql('head', options)} THEN 2`}
|
|
24001
24025
|
ELSE 3
|
|
24002
|
-
END
|
|
24026
|
+
END`;
|
|
24027
|
+
}
|
|
24028
|
+
|
|
24029
|
+
function runLedgerAdmissionOrderSql(
|
|
24030
|
+
options: Pick<PostgresSchedulerOptions, 'schema'> | undefined,
|
|
24031
|
+
searchOnly: boolean,
|
|
24032
|
+
): string {
|
|
24033
|
+
return `${runLedgerAdmissionClassSql(options, searchOnly)},`;
|
|
24003
24034
|
}
|
|
24004
24035
|
|
|
24005
24036
|
export type RunLedgerOutboxAdmissionHint = {
|
|
@@ -24030,13 +24061,23 @@ export async function readPostgresSchedulerOutboxAdmissionHints(
|
|
|
24030
24061
|
);
|
|
24031
24062
|
const result = await client.query<{ run_id: string }>(
|
|
24032
24063
|
`
|
|
24033
|
-
${runLedgerDiscoveryHeadsSql(options, false)}
|
|
24064
|
+
${runLedgerDiscoveryHeadsSql(options, false)},
|
|
24065
|
+
${runLedgerWorkspaceShareSql(options, false)}
|
|
24034
24066
|
SELECT runs.run_id
|
|
24035
24067
|
FROM heads AS head
|
|
24068
|
+
JOIN head_workspace_share AS share ON share.run_id = head.run_id
|
|
24036
24069
|
JOIN ${tableName('runs', options)} AS runs ON runs.run_id = head.run_id
|
|
24037
|
-
WHERE ${runLedgerReadyHeadSql(options, false)}
|
|
24070
|
+
WHERE ${runLedgerReadyHeadSql(options, false, 'share.leased')}
|
|
24038
24071
|
AND NOT (runs.run_id = ANY($2::text[]))
|
|
24039
|
-
|
|
24072
|
+
-- These hints fill up to three slots before any is claimed. A head's
|
|
24073
|
+
-- rank within its workspace and class counts as in flight, so one batch
|
|
24074
|
+
-- interleaves workspaces instead of taking one workspace's oldest heads.
|
|
24075
|
+
ORDER BY ${runLedgerAdmissionOrderSql(options, false)}
|
|
24076
|
+
share.workspace_in_flight + row_number() OVER (
|
|
24077
|
+
PARTITION BY runs.org_id, ${runLedgerAdmissionClassSql(options, false)}
|
|
24078
|
+
ORDER BY head.created_at, runs.run_id
|
|
24079
|
+
),
|
|
24080
|
+
head.created_at, runs.run_id
|
|
24040
24081
|
LIMIT $1
|
|
24041
24082
|
`,
|
|
24042
24083
|
[input.limit, input.excludeRunIds],
|
|
@@ -25594,6 +25635,63 @@ export async function readPostgresSchedulerOutboxOldestPendingSeconds(
|
|
|
25594
25635
|
return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
|
|
25595
25636
|
}
|
|
25596
25637
|
|
|
25638
|
+
export type PostgresSchedulerOutboxBacklogOwner = {
|
|
25639
|
+
orgId: string;
|
|
25640
|
+
/** Runs with an undelivered lifecycle head. */
|
|
25641
|
+
pendingRuns: number;
|
|
25642
|
+
/** Of those, runs a delivery currently leases: the workspace's drain share. */
|
|
25643
|
+
inFlightRuns: number;
|
|
25644
|
+
oldestHeadSeconds: number;
|
|
25645
|
+
};
|
|
25646
|
+
|
|
25647
|
+
/**
|
|
25648
|
+
* Name the workspaces holding a lifecycle backlog, largest first. This reuses
|
|
25649
|
+
* the global claim's own head discovery (one indexed seek per pending run), so
|
|
25650
|
+
* it costs one claim's discovery. The projector reads it only from its periodic
|
|
25651
|
+
* drain probe while the oldest pending fact is already old, never per scrape.
|
|
25652
|
+
*/
|
|
25653
|
+
export async function readPostgresSchedulerOutboxBacklogOwners(
|
|
25654
|
+
client: PostgresSchedulerQueryClient,
|
|
25655
|
+
input: { limit: number },
|
|
25656
|
+
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
25657
|
+
): Promise<PostgresSchedulerOutboxBacklogOwner[]> {
|
|
25658
|
+
const limit = Math.max(1, Math.min(10, Math.floor(input.limit)));
|
|
25659
|
+
if (!(await runLedgerOutboxLaneHasPending(client, options, false))) return [];
|
|
25660
|
+
const result = await client.query<{
|
|
25661
|
+
org_id: string;
|
|
25662
|
+
pending_runs: number | string;
|
|
25663
|
+
in_flight_runs: number | string;
|
|
25664
|
+
oldest_head_seconds: number | string | null;
|
|
25665
|
+
}>(
|
|
25666
|
+
`
|
|
25667
|
+
${runLedgerDiscoveryHeadsSql(options, false)}
|
|
25668
|
+
SELECT owner_run.org_id,
|
|
25669
|
+
count(*) AS pending_runs,
|
|
25670
|
+
count(*) FILTER (
|
|
25671
|
+
WHERE ${runLedgerRunLeasedSql('head.run_id', options, false)}
|
|
25672
|
+
) AS in_flight_runs,
|
|
25673
|
+
extract(epoch FROM greatest(now() - min(head.created_at), interval '0 seconds')) AS oldest_head_seconds
|
|
25674
|
+
FROM heads AS head
|
|
25675
|
+
JOIN ${tableName('runs', options)} AS owner_run
|
|
25676
|
+
ON owner_run.run_id = head.run_id
|
|
25677
|
+
WHERE head.failed_at IS NULL
|
|
25678
|
+
GROUP BY owner_run.org_id
|
|
25679
|
+
ORDER BY count(*) DESC, min(head.created_at), owner_run.org_id
|
|
25680
|
+
LIMIT $1
|
|
25681
|
+
`,
|
|
25682
|
+
[limit],
|
|
25683
|
+
);
|
|
25684
|
+
return result.rows.map((row) => ({
|
|
25685
|
+
orgId: row.org_id,
|
|
25686
|
+
pendingRuns: Number(row.pending_runs),
|
|
25687
|
+
inFlightRuns: Number(row.in_flight_runs),
|
|
25688
|
+
oldestHeadSeconds: Math.max(
|
|
25689
|
+
0,
|
|
25690
|
+
Math.floor(Number(row.oldest_head_seconds ?? 0)),
|
|
25691
|
+
),
|
|
25692
|
+
}));
|
|
25693
|
+
}
|
|
25694
|
+
|
|
25597
25695
|
/**
|
|
25598
25696
|
* Read failed projection work separately from the retryable pending head.
|
|
25599
25697
|
* This is intentionally a bounded operator signal: failed facts require an
|
|
@@ -27583,21 +27681,25 @@ async function dispatchRunLedgerOutboxBatchWithScope(
|
|
|
27583
27681
|
dispatch_launch_json: unknown;
|
|
27584
27682
|
transport_head?: RunLedgerTransportCandidate | null;
|
|
27585
27683
|
}>(`
|
|
27586
|
-
${runLedgerDiscoveryHeadsSql(options, input.searchOnly === true, needsLaunch)}
|
|
27684
|
+
${runLedgerDiscoveryHeadsSql(options, input.searchOnly === true, needsLaunch)},
|
|
27685
|
+
${runLedgerWorkspaceShareSql(options, input.searchOnly === true)}
|
|
27587
27686
|
SELECT runs.run_id, ${launchSelection} AS dispatch_launch_json, ${transportHeadSelection} AS transport_head
|
|
27588
27687
|
FROM heads AS head
|
|
27688
|
+
JOIN head_workspace_share AS share ON share.run_id = head.run_id
|
|
27589
27689
|
JOIN ${tableName('runs', options)} AS runs ON runs.run_id = head.run_id
|
|
27590
|
-
WHERE ${runLedgerReadyHeadSql(options, input.searchOnly === true)}
|
|
27690
|
+
WHERE ${runLedgerReadyHeadSql(options, input.searchOnly === true, 'share.leased')}
|
|
27591
27691
|
-- admission_first: admission, then the causal head of a run with
|
|
27592
|
-
-- a pending terminal or public wait, then FIFO progress.
|
|
27593
|
-
--
|
|
27594
|
-
-- ordinary progress.
|
|
27692
|
+
-- a pending terminal or public wait, then FIFO progress.
|
|
27693
|
+
-- oldest_ready ignores admission class so continuous
|
|
27694
|
+
-- admissions/terminals cannot starve ordinary progress. Within
|
|
27695
|
+
-- either order, the workspace with the fewest in-flight
|
|
27696
|
+
-- deliveries claims first, then the oldest head.
|
|
27595
27697
|
ORDER BY ${
|
|
27596
27698
|
input.headPriority === 'oldest_ready'
|
|
27597
27699
|
? ''
|
|
27598
27700
|
: runLedgerAdmissionOrderSql(options, input.searchOnly === true)
|
|
27599
27701
|
}
|
|
27600
|
-
head.created_at, runs.run_id
|
|
27702
|
+
share.workspace_in_flight, head.created_at, runs.run_id
|
|
27601
27703
|
FOR UPDATE OF runs SKIP LOCKED LIMIT 1
|
|
27602
27704
|
`)));
|
|
27603
27705
|
};
|