deepline 0.3.529 → 0.3.531
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/monitors/fleets/limits.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +10 -8
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +95 -9
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +615 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +115 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +29 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +26 -8
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call-retry-facts.ts +317 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +129 -39
- package/dist/cli/{auth-V7A6TU4G.mjs → auth-33B3OEM4.mjs} +5 -5
- package/dist/cli/auth-3UDRBF5D.js +43 -0
- package/dist/cli/{billing-5VBUYPWW.mjs → billing-X4OQRH6D.mjs} +7 -7
- package/dist/cli/{billing-XF6SAA5Y.js → billing-Y2M2ABLW.js} +82 -82
- package/dist/cli/{chunk-C2WTS7WY.mjs → chunk-2CUPFDW5.mjs} +5 -5
- package/dist/cli/{chunk-TEFO5AS2.js → chunk-2WWTIR2G.js} +98 -98
- package/dist/cli/{chunk-UMCEXTRM.js → chunk-3PMVNMG4.js} +16 -16
- package/dist/cli/{chunk-KSUWW26I.js → chunk-4M4AASO3.js} +13 -13
- package/dist/cli/{chunk-2GV54JFN.js → chunk-4O7UET74.js} +44 -44
- package/dist/cli/{chunk-PNWBODCB.js → chunk-4WPHK2R3.js} +7 -7
- package/dist/cli/{chunk-Y4P6XJHU.mjs → chunk-567HD6G6.mjs} +1 -1
- package/dist/cli/{chunk-ZYMX7KZE.mjs → chunk-57PPAYDB.mjs} +2 -2
- package/dist/cli/{chunk-DPGPXARU.js → chunk-5M24K577.js} +132 -81
- package/dist/cli/{chunk-6XZIXDLC.mjs → chunk-623FFVZU.mjs} +5 -5
- package/dist/cli/{chunk-FWC47SCG.mjs → chunk-6W73VXMK.mjs} +2 -2
- package/dist/cli/{chunk-AP7DNG6D.js → chunk-BUK6WHY2.js} +4 -4
- package/dist/cli/{chunk-DKX5CGTG.mjs → chunk-CVOFP6BU.mjs} +1 -1
- package/dist/cli/{chunk-XZ6OY3BH.js → chunk-D5BLTX5L.js} +1 -1
- package/dist/cli/{chunk-RWY2QLJ4.js → chunk-DWYX5DFJ.js} +41 -41
- package/dist/cli/{chunk-4A4OQMJX.mjs → chunk-EURLINZT.mjs} +1 -1
- package/dist/cli/{chunk-7FCD34YS.mjs → chunk-EVXRQXNV.mjs} +3 -2
- package/dist/cli/{chunk-M47I47FK.js → chunk-H26ZSNLX.js} +14 -14
- package/dist/cli/{chunk-ZULLXAJJ.mjs → chunk-HYPLMUMA.mjs} +5 -5
- package/dist/cli/{chunk-7RTDSHMB.js → chunk-IOOWKPF7.js} +2 -2
- package/dist/cli/{chunk-7SRZTSHU.js → chunk-IXOEKHOY.js} +5 -5
- package/dist/cli/{chunk-KAI64HV7.js → chunk-JFTO33FK.js} +7 -7
- package/dist/cli/{chunk-L3J7IAYE.js → chunk-L4XVL4LW.js} +9 -9
- package/dist/cli/{chunk-BOWZ3OOU.mjs → chunk-MGWYYTZN.mjs} +1 -1
- package/dist/cli/{chunk-GPU4ULMY.mjs → chunk-MYTA37IL.mjs} +10 -10
- package/dist/cli/{chunk-ZEIN5YJS.js → chunk-NXEQMKSM.js} +2 -2
- package/dist/cli/{chunk-FCNSJHED.js → chunk-O267YGUV.js} +6 -6
- package/dist/cli/{chunk-4722FTYU.js → chunk-O4NTPEQV.js} +16 -16
- package/dist/cli/{chunk-HV4UKMBB.mjs → chunk-O7EFJR6Y.mjs} +4 -4
- package/dist/cli/{chunk-NVH6ULDP.js → chunk-PTKSHGUM.js} +22 -22
- package/dist/cli/{chunk-YVJJEMNQ.mjs → chunk-PTOPMO22.mjs} +1 -1
- package/dist/cli/{chunk-H2JAXOPP.js → chunk-RBPCXQBE.js} +11 -11
- package/dist/cli/{chunk-7Z3ZXSOX.js → chunk-RLRPEHQ3.js} +3 -3
- package/dist/cli/{chunk-4BKE63Q7.js → chunk-RZXSCWEB.js} +26 -26
- package/dist/cli/{chunk-PJDYY5JL.mjs → chunk-SPODXGBZ.mjs} +6 -6
- package/dist/cli/{chunk-XEZSORKG.js → chunk-TDJCNVDE.js} +5 -5
- package/dist/cli/{chunk-PAAREIKG.mjs → chunk-TU7HU5K2.mjs} +2 -2
- package/dist/cli/{chunk-NDVCVFZW.mjs → chunk-U5YBINPF.mjs} +2 -2
- package/dist/cli/{chunk-XE4PQE2O.mjs → chunk-UNTFERUX.mjs} +1 -1
- package/dist/cli/{chunk-WL6GAZBD.js → chunk-V6LUMGVI.js} +3 -2
- package/dist/cli/{chunk-ETCGTKLF.mjs → chunk-VGWUCBNA.mjs} +1 -1
- package/dist/cli/{chunk-FXHKNZM2.mjs → chunk-VHIHGMZD.mjs} +1 -1
- package/dist/cli/{chunk-E7CN5GEM.mjs → chunk-VWOOOU6G.mjs} +2 -2
- package/dist/cli/{chunk-BRQDN67G.js → chunk-WDLY4HST.js} +6 -6
- package/dist/cli/{chunk-OA4FI5ZM.js → chunk-WHAMLN6B.js} +2 -2
- package/dist/cli/{chunk-K55VBSCA.mjs → chunk-XOXKVLJZ.mjs} +82 -31
- package/dist/cli/{chunk-R62Z4INU.mjs → chunk-XQGLHKDI.mjs} +2 -2
- package/dist/cli/{chunk-5NZEA2YV.mjs → chunk-XWQI4TMS.mjs} +1 -1
- package/dist/cli/{chunk-G4SYSUDB.mjs → chunk-YMGQP7WI.mjs} +5 -5
- package/dist/cli/{chunk-NVSMSP2J.mjs → chunk-YVOFNLGN.mjs} +2 -2
- package/dist/cli/{chunk-QTQWPSAK.js → chunk-ZBL4CP75.js} +3 -3
- package/dist/cli/{chunk-EW33RCLA.mjs → chunk-ZJQITGPV.mjs} +3 -3
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-IHLVHG35.mjs → csv-CMUWCM46.mjs} +4 -4
- package/dist/cli/{csv-VEKMGGOE.js → csv-N4P2XOKP.js} +13 -13
- package/dist/cli/{db-NTFFISQG.js → db-GFI45WV5.js} +27 -27
- package/dist/cli/{db-RKLVYARP.mjs → db-J5HFGOUO.mjs} +6 -6
- package/dist/cli/describe-HFUWQN3A.js +50 -0
- package/dist/cli/{describe-62ELB5DZ.mjs → describe-NKHH3VVI.mjs} +18 -18
- package/dist/cli/{executions-5BMZW4C7.mjs → executions-54QEYYE6.mjs} +6 -6
- package/dist/cli/{executions-X7NMKMXW.js → executions-FMWHU72C.js} +8 -8
- package/dist/cli/{feedback-UHHWCIFD.mjs → feedback-HA4QUWMU.mjs} +6 -6
- package/dist/cli/{feedback-RDN5O4AT.js → feedback-R7C3AZKN.js} +14 -14
- package/dist/cli/git-ETBABM6D.js +25 -0
- package/dist/cli/{git-3M33GKOW.mjs → git-OVG63PJV.mjs} +5 -5
- package/dist/cli/index.js +145 -145
- package/dist/cli/index.mjs +44 -44
- package/dist/cli/{legacy-noops-ENKN6JU4.js → legacy-noops-GM2F7GMV.js} +9 -9
- package/dist/cli/{legacy-noops-7RVRPF5B.mjs → legacy-noops-PLQWYZ7A.mjs} +6 -6
- package/dist/cli/{monitors-FJPDMUQ6.mjs → monitors-QXK7JTRG.mjs} +7 -7
- package/dist/cli/{monitors-YOWDFGIR.js → monitors-SJBIPV4K.js} +100 -100
- package/dist/cli/{org-H24LOZAC.mjs → org-OFMMMVYT.mjs} +6 -6
- package/dist/cli/{org-4GBLI75H.js → org-XKO7BBT4.js} +86 -86
- package/dist/cli/{pages-BKM2D6BV.mjs → pages-NDI2K34M.mjs} +6 -6
- package/dist/cli/{pages-WWVLYB5K.js → pages-ZGXRON5S.js} +18 -18
- package/dist/cli/{play-TXHKCG6B.js → play-2YD5NTH6.js} +317 -317
- package/dist/cli/{play-M3CSYH3A.mjs → play-SMKNTBRK.mjs} +18 -18
- package/dist/cli/{providers-XL4SNFHU.js → providers-52PIA36O.js} +9 -9
- package/dist/cli/{providers-EW5WTMTX.mjs → providers-6SKF5W4Y.mjs} +6 -6
- package/dist/cli/{quickstart-AFQ5MCDL.js → quickstart-4Z22WVLK.js} +6 -6
- package/dist/cli/{quickstart-SZSLS553.mjs → quickstart-RVA335ED.mjs} +4 -4
- package/dist/cli/{run-MOFHGYSN.js → run-FDTSTMDM.js} +41 -41
- package/dist/cli/{run-TWXFNH6U.mjs → run-GMN4TCVV.mjs} +23 -23
- package/dist/cli/{search-2SW4V4IR.mjs → search-2FG2USCF.mjs} +8 -8
- package/dist/cli/search-63X5FPDM.js +33 -0
- package/dist/cli/{search-output-CJGRPJYD.js → search-output-5FKQYLFW.js} +6 -6
- package/dist/cli/{search-output-I6DNYXNT.mjs → search-output-AC3AAV6E.mjs} +4 -4
- package/dist/cli/{secrets-SD43HSLX.js → secrets-5A7AY2YU.js} +15 -15
- package/dist/cli/{secrets-4XXLR6QO.mjs → secrets-MA4ZTNVG.mjs} +6 -6
- package/dist/cli/{sessions-7G32HW5R.mjs → sessions-LBYKV5O4.mjs} +6 -6
- package/dist/cli/sessions-SMWWKKD4.js +22 -0
- package/dist/cli/{settings-HSYRY2L5.mjs → settings-6MQVNROV.mjs} +13 -13
- package/dist/cli/{settings-SYEBDDDJ.js → settings-HA3D4GNZ.js} +86 -86
- package/dist/cli/{setup-VTWCVCTK.js → setup-3JWTNSOK.js} +78 -63
- package/dist/cli/{setup-XZVBPKZK.mjs → setup-BXCUZOZH.mjs} +28 -13
- package/dist/cli/{skills-OMPEUMRT.mjs → skills-7ASML2WZ.mjs} +8 -8
- package/dist/cli/skills-OJ7NZL6S.js +37 -0
- package/dist/cli/{tools-UEDNJI4G.mjs → tools-7IJWJXZ3.mjs} +17 -17
- package/dist/cli/tools-Y2VMPUSI.js +57 -0
- package/dist/cli/{update-4YVCUSSI.mjs → update-JFKH4SVK.mjs} +10 -10
- package/dist/cli/update-JURCS2FE.js +35 -0
- package/dist/cli/{views-4FP4AJQ2.mjs → views-2EURG3P5.mjs} +6 -6
- package/dist/cli/{views-ZCCSKWMP.js → views-XTAIIX2Y.js} +18 -18
- package/dist/cli/{workflow-A2D5FALP.mjs → workflow-7FCQ34QD.mjs} +7 -7
- package/dist/cli/{workflow-SM4OD4VJ.js → workflow-AXOF74HO.js} +17 -17
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +108 -106
- 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-P7M7SXM5.js +0 -43
- package/dist/cli/describe-JXOGKT6C.js +0 -50
- package/dist/cli/git-7VZGGIGZ.js +0 -25
- package/dist/cli/search-V2AGWRLO.js +0 -33
- package/dist/cli/sessions-FIRDFPIZ.js +0 -22
- package/dist/cli/skills-RUY7CION.js +0 -37
- package/dist/cli/tools-KLIW7G6T.js +0 -57
- package/dist/cli/update-FDUZRKKU.js +0 -35
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts
CHANGED
|
@@ -60,7 +60,10 @@ import {
|
|
|
60
60
|
import type { PreloadedRuntimeDbSession } from '../db-session';
|
|
61
61
|
import { parseRenewedPreloadedRuntimeDbSessions } from '../db-session-renewal';
|
|
62
62
|
import { RUNTIME_CLAIM_HEARTBEAT_DIVISOR } from '../runtime-constants';
|
|
63
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
normalizePlayRunFailure,
|
|
65
|
+
runtimeLimitExceededCause,
|
|
66
|
+
} from '../run-failure';
|
|
64
67
|
import {
|
|
65
68
|
playRunRecoveryLogDetail,
|
|
66
69
|
playRunRecoveryProviderText,
|
|
@@ -286,6 +289,7 @@ import {
|
|
|
286
289
|
isRuntimeSchedulerRetryableTransactionError,
|
|
287
290
|
isRuntimeSchedulerServerUnavailableError,
|
|
288
291
|
parseRuntimeSchedulerCapacityError,
|
|
292
|
+
probeRuntimeSchedulerDatabaseReachable,
|
|
289
293
|
RuntimeSchedulerCapacityError,
|
|
290
294
|
runtimeSchedulerCapacityRetryAfterMs,
|
|
291
295
|
type PgNotifyHubLease,
|
|
@@ -372,6 +376,7 @@ import {
|
|
|
372
376
|
emitPlayRunRecoveryDecision,
|
|
373
377
|
emitPlayRuntimeSpan,
|
|
374
378
|
} from '../runtime-telemetry';
|
|
379
|
+
import { emitPlayRunFinished } from '../durable-summary-events';
|
|
375
380
|
|
|
376
381
|
/**
|
|
377
382
|
* A token exchange crosses an HTTP boundary, which otherwise erases the
|
|
@@ -8236,6 +8241,17 @@ export async function recoverAbsurdRuntimeOverdueDetachedRunnerCeilings(input: {
|
|
|
8236
8241
|
skipped += 1;
|
|
8237
8242
|
continue;
|
|
8238
8243
|
}
|
|
8244
|
+
emitPlayRunFinished({
|
|
8245
|
+
orgId: claim.launch.orgId ?? null,
|
|
8246
|
+
runId: claim.runId,
|
|
8247
|
+
playName: claim.launch.playName ?? null,
|
|
8248
|
+
attempt: claim.attempt,
|
|
8249
|
+
outcome: 'failed',
|
|
8250
|
+
failure: normalizePlayRunFailure(failedResult.error),
|
|
8251
|
+
runtimeBackend: claim.launch.runtimeBackend ?? null,
|
|
8252
|
+
triggerSource: claim.launch.triggerSource ?? null,
|
|
8253
|
+
committedBy: 'worker',
|
|
8254
|
+
});
|
|
8239
8255
|
if (absurdRun) {
|
|
8240
8256
|
await cancelAbsurdEngineTaskAfterSchedulerTerminal({
|
|
8241
8257
|
client: input.client,
|
|
@@ -11233,6 +11249,78 @@ export function createAbsurdWorkerWakeHook(input: {
|
|
|
11233
11249
|
return hook;
|
|
11234
11250
|
}
|
|
11235
11251
|
|
|
11252
|
+
/**
|
|
11253
|
+
* How long a booting worker waits for its scheduler database before failing
|
|
11254
|
+
* loudly. A new Production Machine cannot reach PlanetScale for about 5-15 s
|
|
11255
|
+
* after creation: the worker app egresses through an app-scoped Fly static
|
|
11256
|
+
* egress IP, which a new Machine cannot use at first. Before this wait, the
|
|
11257
|
+
* pool's first connections timed out (5 s, three attempts) and 66 of ~415
|
|
11258
|
+
* fresh boots crashed on "Connection terminated due to connection timeout"
|
|
11259
|
+
* (2026-11-10/11). Past the deadline a real outage still fails the boot.
|
|
11260
|
+
*/
|
|
11261
|
+
export const ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS = 60_000;
|
|
11262
|
+
/** Each reachability attempt's connect and query timeout. */
|
|
11263
|
+
export const ABSURD_WORKER_BOOT_DATABASE_ATTEMPT_TIMEOUT_MS = 2_000;
|
|
11264
|
+
const ABSURD_WORKER_BOOT_DATABASE_RETRY_DELAY_MS = 250;
|
|
11265
|
+
|
|
11266
|
+
export class RuntimeSchedulerDatabaseUnreachableAtBootError extends Error {
|
|
11267
|
+
constructor(attempts: number, waitedMs: number, lastError: unknown) {
|
|
11268
|
+
super(
|
|
11269
|
+
`Runtime scheduler database unreachable at worker boot after ${attempts} attempts over ${waitedMs} ms: ` +
|
|
11270
|
+
(lastError instanceof Error ? lastError.message : String(lastError)),
|
|
11271
|
+
{ cause: lastError },
|
|
11272
|
+
);
|
|
11273
|
+
this.name = 'RuntimeSchedulerDatabaseUnreachableAtBootError';
|
|
11274
|
+
}
|
|
11275
|
+
}
|
|
11276
|
+
|
|
11277
|
+
/**
|
|
11278
|
+
* Retry a short reachability probe until it succeeds or the deadline passes,
|
|
11279
|
+
* then fail loudly. Every failed attempt is reported; the deadline bounds how
|
|
11280
|
+
* many there can be. The caller keeps the worker unready meanwhile.
|
|
11281
|
+
*/
|
|
11282
|
+
export async function waitForRuntimeSchedulerDatabaseAtBoot(input: {
|
|
11283
|
+
probe: (timeoutMs: number) => Promise<void>;
|
|
11284
|
+
deadlineMs?: number;
|
|
11285
|
+
attemptTimeoutMs?: number;
|
|
11286
|
+
retryDelayMs?: number;
|
|
11287
|
+
now?: () => number;
|
|
11288
|
+
sleep?: (ms: number) => Promise<void>;
|
|
11289
|
+
onAttemptFailed?: (failure: {
|
|
11290
|
+
attempt: number;
|
|
11291
|
+
elapsedMs: number;
|
|
11292
|
+
error: unknown;
|
|
11293
|
+
}) => void;
|
|
11294
|
+
}): Promise<{ attempts: number; waitedMs: number }> {
|
|
11295
|
+
const now = input.now ?? Date.now;
|
|
11296
|
+
const pause = input.sleep ?? ((ms: number) => sleep(ms));
|
|
11297
|
+
const deadlineMs =
|
|
11298
|
+
input.deadlineMs ?? ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS;
|
|
11299
|
+
const attemptTimeoutMs =
|
|
11300
|
+
input.attemptTimeoutMs ?? ABSURD_WORKER_BOOT_DATABASE_ATTEMPT_TIMEOUT_MS;
|
|
11301
|
+
const retryDelayMs =
|
|
11302
|
+
input.retryDelayMs ?? ABSURD_WORKER_BOOT_DATABASE_RETRY_DELAY_MS;
|
|
11303
|
+
const startedAt = now();
|
|
11304
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
11305
|
+
const remainingMs = deadlineMs - (now() - startedAt);
|
|
11306
|
+
try {
|
|
11307
|
+
await input.probe(Math.max(1, Math.min(attemptTimeoutMs, remainingMs)));
|
|
11308
|
+
return { attempts: attempt, waitedMs: now() - startedAt };
|
|
11309
|
+
} catch (error) {
|
|
11310
|
+
const elapsedMs = now() - startedAt;
|
|
11311
|
+
input.onAttemptFailed?.({ attempt, elapsedMs, error });
|
|
11312
|
+
if (elapsedMs + retryDelayMs >= deadlineMs) {
|
|
11313
|
+
throw new RuntimeSchedulerDatabaseUnreachableAtBootError(
|
|
11314
|
+
attempt,
|
|
11315
|
+
elapsedMs,
|
|
11316
|
+
error,
|
|
11317
|
+
);
|
|
11318
|
+
}
|
|
11319
|
+
await pause(retryDelayMs);
|
|
11320
|
+
}
|
|
11321
|
+
}
|
|
11322
|
+
}
|
|
11323
|
+
|
|
11236
11324
|
export type RuntimeWorkerHostConfig = {
|
|
11237
11325
|
schedulerSchema?: string | null;
|
|
11238
11326
|
slots?: number | null;
|
|
@@ -11348,19 +11436,41 @@ export async function startRuntimeWorkerHost(
|
|
|
11348
11436
|
'gateway (apps/runtime-receipt-gateway/index.ts), never the Vercel app.',
|
|
11349
11437
|
);
|
|
11350
11438
|
}
|
|
11439
|
+
const poolOptions = resolveAbsurdPoolOptions();
|
|
11440
|
+
// Wait for the scheduler database beside the gateway check, before the pool
|
|
11441
|
+
// makes its first connections: their 5 s timeouts and breaker are for a
|
|
11442
|
+
// running worker, not for a new Machine's first seconds of egress.
|
|
11443
|
+
const databaseReachable = waitForRuntimeSchedulerDatabaseAtBoot({
|
|
11444
|
+
probe: (timeoutMs) =>
|
|
11445
|
+
probeRuntimeSchedulerDatabaseReachable({
|
|
11446
|
+
url: poolOptions.url,
|
|
11447
|
+
timeoutMs,
|
|
11448
|
+
applicationName: 'deepline-absurd-worker-boot',
|
|
11449
|
+
}),
|
|
11450
|
+
onAttemptFailed: ({ attempt, elapsedMs, error }) =>
|
|
11451
|
+
console.warn('[absurd-runtime.worker] boot_database_unreachable', {
|
|
11452
|
+
attempt,
|
|
11453
|
+
elapsedMs,
|
|
11454
|
+
deadlineMs: ABSURD_WORKER_BOOT_DATABASE_DEADLINE_MS,
|
|
11455
|
+
error: error instanceof Error ? error.message : String(error),
|
|
11456
|
+
}),
|
|
11457
|
+
});
|
|
11351
11458
|
// This is a liveness/identity check only. Named operation capability is
|
|
11352
11459
|
// checked by its caller, so a compatible receiver can serve draining older
|
|
11353
11460
|
// lanes without a global-version boot gate.
|
|
11354
|
-
await
|
|
11355
|
-
|
|
11356
|
-
|
|
11461
|
+
const [, reachable] = await Promise.all([
|
|
11462
|
+
verifyRuntimeReceiptGatewayHealth({
|
|
11463
|
+
gatewayBaseUrl: process.env.DEEPLINE_RUNTIME_RECEIPT_GATEWAY_URL,
|
|
11464
|
+
}),
|
|
11465
|
+
databaseReachable,
|
|
11466
|
+
]);
|
|
11467
|
+
console.info('[absurd-runtime.worker] boot_database_reachable', reachable);
|
|
11357
11468
|
// This is deliberately structured and non-secret. `runtime status` exposes
|
|
11358
11469
|
// the app/gateway copy; the worker boot record lets on-call verify that a
|
|
11359
11470
|
// coordinated SEV configuration reached the Fly execution lane as well.
|
|
11360
11471
|
console.info('[absurd-runtime.worker] reliability_policy', {
|
|
11361
11472
|
policy: RUNTIME_RELIABILITY_POLICY,
|
|
11362
11473
|
});
|
|
11363
|
-
const poolOptions = resolveAbsurdPoolOptions();
|
|
11364
11474
|
const schedulerOptions: AbsurdSchedulerOptions =
|
|
11365
11475
|
normalizeAbsurdSchedulerOptions({
|
|
11366
11476
|
schema: options.schedulerSchema ?? null,
|
|
@@ -1501,6 +1501,35 @@ export function deriveDirectDatabaseUrl(url: string): string {
|
|
|
1501
1501
|
}
|
|
1502
1502
|
}
|
|
1503
1503
|
|
|
1504
|
+
/**
|
|
1505
|
+
* One connect and `select 1` against the scheduler's pooled endpoint, with its
|
|
1506
|
+
* own short connect and query timeout. It never touches a pool, its admission
|
|
1507
|
+
* queue or its failure breaker, so a worker can ask "is the database reachable
|
|
1508
|
+
* yet?" at boot without tripping the circuit its real work depends on.
|
|
1509
|
+
*/
|
|
1510
|
+
export async function probeRuntimeSchedulerDatabaseReachable(input: {
|
|
1511
|
+
url: string;
|
|
1512
|
+
timeoutMs: number;
|
|
1513
|
+
applicationName?: string;
|
|
1514
|
+
createClient?: (
|
|
1515
|
+
config: ConstructorParameters<typeof Client>[0],
|
|
1516
|
+
) => Pick<Client, 'connect' | 'query' | 'end'>;
|
|
1517
|
+
}): Promise<void> {
|
|
1518
|
+
const client = (input.createClient ?? ((config) => new Client(config)))({
|
|
1519
|
+
connectionString: normalizePostgresConnectionStringForPg(input.url),
|
|
1520
|
+
application_name:
|
|
1521
|
+
input.applicationName ?? 'deepline-runtime-scheduler-reachability',
|
|
1522
|
+
connectionTimeoutMillis: input.timeoutMs,
|
|
1523
|
+
query_timeout: input.timeoutMs,
|
|
1524
|
+
});
|
|
1525
|
+
try {
|
|
1526
|
+
await client.connect();
|
|
1527
|
+
await client.query('select 1');
|
|
1528
|
+
} finally {
|
|
1529
|
+
await client.end().catch(() => undefined);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1504
1533
|
/**
|
|
1505
1534
|
* The runtime worker needs one direct Postgres session for its optional
|
|
1506
1535
|
* LISTEN wake hint. Preview gates must prove that this separate session budget
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts
CHANGED
|
@@ -41,6 +41,10 @@ import {
|
|
|
41
41
|
durableReplayRefusalFromRunLogLine,
|
|
42
42
|
emitPlayRunReplayRefusal,
|
|
43
43
|
} from '../runtime-telemetry';
|
|
44
|
+
import {
|
|
45
|
+
durableCallSummaryFromRunLogLine,
|
|
46
|
+
emitPlayCallFinished,
|
|
47
|
+
} from '../durable-summary-events';
|
|
44
48
|
import {
|
|
45
49
|
buildPlayRunLedgerEventsFromStatusPatch,
|
|
46
50
|
createEmptyPlayRunLedgerSnapshot,
|
|
@@ -768,19 +772,33 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
768
772
|
void flush({ force }).catch(() => undefined);
|
|
769
773
|
};
|
|
770
774
|
|
|
771
|
-
/**
|
|
772
|
-
|
|
775
|
+
/**
|
|
776
|
+
* Re-emit the runner's durable records to this process's shipped log
|
|
777
|
+
* stream: replay refusals, and the outcome of each call that hit trouble.
|
|
778
|
+
*/
|
|
779
|
+
const forwardDurableRecords = (
|
|
773
780
|
line: string,
|
|
774
781
|
attempt: number | null | undefined = producerAttempt,
|
|
775
782
|
) => {
|
|
776
783
|
const refusal = durableReplayRefusalFromRunLogLine(line);
|
|
777
|
-
if (
|
|
778
|
-
|
|
784
|
+
if (refusal) {
|
|
785
|
+
emitPlayRunReplayRefusal({
|
|
786
|
+
orgId: launch.orgId ?? null,
|
|
787
|
+
runId: launch.runId,
|
|
788
|
+
playName: launch.playName ?? null,
|
|
789
|
+
attempt: attempt ?? null,
|
|
790
|
+
refusal,
|
|
791
|
+
});
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const call = durableCallSummaryFromRunLogLine(line);
|
|
795
|
+
if (!call) return;
|
|
796
|
+
emitPlayCallFinished({
|
|
779
797
|
orgId: launch.orgId ?? null,
|
|
780
798
|
runId: launch.runId,
|
|
781
799
|
playName: launch.playName ?? null,
|
|
782
800
|
attempt: attempt ?? null,
|
|
783
|
-
|
|
801
|
+
call,
|
|
784
802
|
});
|
|
785
803
|
};
|
|
786
804
|
|
|
@@ -1489,7 +1507,7 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1489
1507
|
logEvent.entryId,
|
|
1490
1508
|
logEvent.metadata,
|
|
1491
1509
|
);
|
|
1492
|
-
|
|
1510
|
+
forwardDurableRecords(rawLine);
|
|
1493
1511
|
}
|
|
1494
1512
|
markMapStartedFromLog(rawLine);
|
|
1495
1513
|
markMapStartedFromPerfLog(rawLine);
|
|
@@ -1796,9 +1814,9 @@ export function createPostgresSchedulerProgressReporter(input: {
|
|
|
1796
1814
|
replayAllTerminalLogs: options.replayAllTerminalLogs === true,
|
|
1797
1815
|
producerAttempt: terminalReplayAttempt,
|
|
1798
1816
|
});
|
|
1799
|
-
// A detached runner that streamed no events delivers its
|
|
1817
|
+
// A detached runner that streamed no events delivers its records here.
|
|
1800
1818
|
for (const line of terminalLogReplay?.lines ?? []) {
|
|
1801
|
-
|
|
1819
|
+
forwardDurableRecords(line, terminalReplayAttempt);
|
|
1802
1820
|
}
|
|
1803
1821
|
await flush({
|
|
1804
1822
|
force: true,
|
|
@@ -295,6 +295,10 @@ import {
|
|
|
295
295
|
emitPlayRunLaunchConflictTelemetry,
|
|
296
296
|
emitPlayTelemetry,
|
|
297
297
|
} from '../runtime-telemetry';
|
|
298
|
+
import {
|
|
299
|
+
emitPlayRunFinished,
|
|
300
|
+
playRunFailureDetailsOf,
|
|
301
|
+
} from '../durable-summary-events';
|
|
298
302
|
import { buildAbsurdPlayRunTask } from './absurd-play-run-task';
|
|
299
303
|
import {
|
|
300
304
|
buildAbsurdCronFireTask,
|
|
@@ -18474,6 +18478,18 @@ export async function executePostgresSchedulerClaim(
|
|
|
18474
18478
|
`Postgres scheduler worker lost lease for ${claim.runId}/${claim.attempt}.`,
|
|
18475
18479
|
);
|
|
18476
18480
|
}
|
|
18481
|
+
// The fenced statement committed this run's terminal transition.
|
|
18482
|
+
emitPlayRunFinished({
|
|
18483
|
+
orgId: claim.launch.orgId ?? null,
|
|
18484
|
+
runId: claim.runId,
|
|
18485
|
+
playName: claim.launch.playName ?? null,
|
|
18486
|
+
attempt: claim.attempt,
|
|
18487
|
+
outcome: 'completed',
|
|
18488
|
+
failure: null,
|
|
18489
|
+
runtimeBackend: claim.launch.runtimeBackend ?? null,
|
|
18490
|
+
triggerSource: claim.launch.triggerSource ?? null,
|
|
18491
|
+
committedBy: 'worker',
|
|
18492
|
+
});
|
|
18477
18493
|
return {
|
|
18478
18494
|
status: 'completed',
|
|
18479
18495
|
runId: claim.runId,
|
|
@@ -18558,6 +18574,17 @@ export async function executePostgresSchedulerClaim(
|
|
|
18558
18574
|
`Postgres scheduler worker failed after losing lease for ${claim.runId}/${claim.attempt}: ${message}`,
|
|
18559
18575
|
);
|
|
18560
18576
|
}
|
|
18577
|
+
emitPlayRunFinished({
|
|
18578
|
+
orgId: claim.launch.orgId ?? null,
|
|
18579
|
+
runId: claim.runId,
|
|
18580
|
+
playName: claim.launch.playName ?? null,
|
|
18581
|
+
attempt: claim.attempt,
|
|
18582
|
+
outcome: 'failed',
|
|
18583
|
+
failure: playRunFailureDetailsOf(terminalFailureResult),
|
|
18584
|
+
runtimeBackend: claim.launch.runtimeBackend ?? null,
|
|
18585
|
+
triggerSource: claim.launch.triggerSource ?? null,
|
|
18586
|
+
committedBy: 'worker',
|
|
18587
|
+
});
|
|
18561
18588
|
// The failure statement already stamps every sandbox and persists its
|
|
18562
18589
|
// cleanup/billing obligations. Return to terminal projection without
|
|
18563
18590
|
// reacquiring custody locks or reading resources that this caller never uses.
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import type { ToolExecuteHttpRetryDecision } from './tool-execute-retry-policy';
|
|
3
|
+
import { ToolExecutionError } from '../plays/tool-execution-error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What one logical tool call went through on its way to a result, as a few
|
|
7
|
+
* fixed-size counters.
|
|
8
|
+
*
|
|
9
|
+
* The retry loop in `callToolExecutionAPI` records structured facts it already
|
|
10
|
+
* holds (its classified failure, the wait it is about to take); nothing here
|
|
11
|
+
* parses text, awaits, or grows with the call's history. The counters cover
|
|
12
|
+
* this runner process only: a call resumed from a checkpoint starts again at
|
|
13
|
+
* zero. The facts ride the existing `tool_call_completed` and
|
|
14
|
+
* `tool_call_failed` run-log lines as optional fields, and the ingesting
|
|
15
|
+
* server reads them back (`durable-summary-events.ts`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Every reason a failed delivery can be classified with: the retry policy's
|
|
20
|
+
* HTTP reasons, plus the two transport outcomes the loop handles itself.
|
|
21
|
+
*/
|
|
22
|
+
export const TOOL_CALL_RETRY_REASONS = [
|
|
23
|
+
'rate_limit',
|
|
24
|
+
'concurrency_backpressure',
|
|
25
|
+
'runtime_scheduler_capacity',
|
|
26
|
+
'provider_pacing_wait',
|
|
27
|
+
'idempotency_in_progress',
|
|
28
|
+
'gateway_invocation_in_progress',
|
|
29
|
+
'customer_db_storage_unavailable',
|
|
30
|
+
'billing_unavailable_before_dispatch',
|
|
31
|
+
'retry_safe_transient_5xx',
|
|
32
|
+
'edge_gateway_transient',
|
|
33
|
+
'unsafe_transient_5xx',
|
|
34
|
+
'provider_server_error',
|
|
35
|
+
'hard_billing_error',
|
|
36
|
+
'non_retryable_status',
|
|
37
|
+
/** The request may have been written, and no response came back. */
|
|
38
|
+
'transport',
|
|
39
|
+
/** No connection opened, so no byte of the request was written. */
|
|
40
|
+
'connect',
|
|
41
|
+
] as const;
|
|
42
|
+
|
|
43
|
+
export type ToolCallRetryReason = (typeof TOOL_CALL_RETRY_REASONS)[number];
|
|
44
|
+
|
|
45
|
+
// The list above must name every HTTP reason the policy can return, and
|
|
46
|
+
// nothing the policy cannot: adding a policy reason fails this check until
|
|
47
|
+
// the list (and the server's mapping) learns it.
|
|
48
|
+
type HttpRetryReason = ToolExecuteHttpRetryDecision['reason'];
|
|
49
|
+
type ListedHttpReason = Exclude<ToolCallRetryReason, 'transport' | 'connect'>;
|
|
50
|
+
const httpRetryReasonsAreListed: [HttpRetryReason] extends [ListedHttpReason]
|
|
51
|
+
? [ListedHttpReason] extends [HttpRetryReason]
|
|
52
|
+
? true
|
|
53
|
+
: never
|
|
54
|
+
: never = true;
|
|
55
|
+
void httpRetryReasonsAreListed;
|
|
56
|
+
|
|
57
|
+
export const TOOL_CALL_ERROR_ORIGINS = [
|
|
58
|
+
'caller',
|
|
59
|
+
'provider',
|
|
60
|
+
'deepline',
|
|
61
|
+
'unknown',
|
|
62
|
+
] as const;
|
|
63
|
+
export type ToolCallErrorOrigin = (typeof TOOL_CALL_ERROR_ORIGINS)[number];
|
|
64
|
+
|
|
65
|
+
export const TOOL_CALL_NETWORK_KINDS = [
|
|
66
|
+
'timeout',
|
|
67
|
+
'dns',
|
|
68
|
+
'connect',
|
|
69
|
+
'reset',
|
|
70
|
+
'unavailable',
|
|
71
|
+
'unknown',
|
|
72
|
+
] as const;
|
|
73
|
+
export type ToolCallNetworkKind = (typeof TOOL_CALL_NETWORK_KINDS)[number];
|
|
74
|
+
|
|
75
|
+
export type ToolCallRetryFacts = {
|
|
76
|
+
/** The provider the call's requests went to, from its last send. */
|
|
77
|
+
provider: string | null;
|
|
78
|
+
/** Requests this process dispatched for the call. */
|
|
79
|
+
sends: number;
|
|
80
|
+
/** Waits taken before sending again. */
|
|
81
|
+
retries: number;
|
|
82
|
+
/** Total of those waits, as planned when each began. */
|
|
83
|
+
retryWaitMs: number;
|
|
84
|
+
/** Any failed response carried a `Retry-After` header. */
|
|
85
|
+
retryAfterSeen: boolean;
|
|
86
|
+
/** The failure that caused the first retry. */
|
|
87
|
+
firstRetryReason: ToolCallRetryReason | null;
|
|
88
|
+
firstRetryStatus: number | null;
|
|
89
|
+
firstRetryOrigin: ToolCallErrorOrigin | null;
|
|
90
|
+
/** The most recent failure, retried or not. */
|
|
91
|
+
lastErrorReason: ToolCallRetryReason | null;
|
|
92
|
+
lastErrorStatus: number | null;
|
|
93
|
+
lastErrorOrigin: ToolCallErrorOrigin | null;
|
|
94
|
+
/** The last failure's network kind (`ToolExecutionError.networkKind`). */
|
|
95
|
+
lastErrorNetworkKind: ToolCallNetworkKind | null;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the last failed request reached the provider: false when the
|
|
98
|
+
* failure proves it was never sent, null when that is not known.
|
|
99
|
+
*/
|
|
100
|
+
lastErrorDispatched: false | null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export function createToolCallRetryFacts(): ToolCallRetryFacts {
|
|
104
|
+
return {
|
|
105
|
+
provider: null,
|
|
106
|
+
sends: 0,
|
|
107
|
+
retries: 0,
|
|
108
|
+
retryWaitMs: 0,
|
|
109
|
+
retryAfterSeen: false,
|
|
110
|
+
firstRetryReason: null,
|
|
111
|
+
firstRetryStatus: null,
|
|
112
|
+
firstRetryOrigin: null,
|
|
113
|
+
lastErrorReason: null,
|
|
114
|
+
lastErrorStatus: null,
|
|
115
|
+
lastErrorOrigin: null,
|
|
116
|
+
lastErrorNetworkKind: null,
|
|
117
|
+
lastErrorDispatched: null,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The logical call whose facts a provider request records into. `executeTool`
|
|
123
|
+
* opens it around a call. A dispatcher that sends on behalf of queued calls
|
|
124
|
+
* runs outside their async scope, so it names its members' facts explicitly
|
|
125
|
+
* (`ToolExecutionApiOptions.retryFactsTargets`) instead of reading this.
|
|
126
|
+
*/
|
|
127
|
+
export const toolCallRetryFactsScope =
|
|
128
|
+
new AsyncLocalStorage<ToolCallRetryFacts>();
|
|
129
|
+
|
|
130
|
+
/** One physical request, or a native batch sending for several calls. */
|
|
131
|
+
export type ToolCallRetryFactsTargets =
|
|
132
|
+
| ToolCallRetryFacts
|
|
133
|
+
| readonly ToolCallRetryFacts[]
|
|
134
|
+
| null
|
|
135
|
+
| undefined;
|
|
136
|
+
|
|
137
|
+
function forEachTarget(
|
|
138
|
+
targets: ToolCallRetryFactsTargets,
|
|
139
|
+
record: (facts: ToolCallRetryFacts) => void,
|
|
140
|
+
): void {
|
|
141
|
+
if (!targets) return;
|
|
142
|
+
if (Array.isArray(targets)) {
|
|
143
|
+
for (const facts of targets as readonly ToolCallRetryFacts[]) {
|
|
144
|
+
record(facts);
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
record(targets as ToolCallRetryFacts);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Targets as an explicit list, for a companion request (an async poll or
|
|
153
|
+
* finish) that may run outside the calling scope.
|
|
154
|
+
*/
|
|
155
|
+
export function toolCallRetryFactsTargetList(
|
|
156
|
+
targets: ToolCallRetryFactsTargets,
|
|
157
|
+
): readonly ToolCallRetryFacts[] {
|
|
158
|
+
const list: ToolCallRetryFacts[] = [];
|
|
159
|
+
forEachTarget(targets, (facts) => list.push(facts));
|
|
160
|
+
return list;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const PROVIDER_NAME = /^[a-z0-9][a-z0-9_.-]{0,63}$/u;
|
|
164
|
+
|
|
165
|
+
export function recordToolCallSend(
|
|
166
|
+
targets: ToolCallRetryFactsTargets,
|
|
167
|
+
provider: string,
|
|
168
|
+
): void {
|
|
169
|
+
const name = PROVIDER_NAME.test(provider) ? provider : null;
|
|
170
|
+
forEachTarget(targets, (facts) => {
|
|
171
|
+
facts.sends += 1;
|
|
172
|
+
facts.provider = name;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function errorOrigin(value: unknown): ToolCallErrorOrigin | null {
|
|
177
|
+
return typeof value === 'string' &&
|
|
178
|
+
(TOOL_CALL_ERROR_ORIGINS as readonly string[]).includes(value)
|
|
179
|
+
? (value as ToolCallErrorOrigin)
|
|
180
|
+
: null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function httpStatus(value: unknown): number | null {
|
|
184
|
+
return typeof value === 'number' &&
|
|
185
|
+
Number.isSafeInteger(value) &&
|
|
186
|
+
value >= 100 &&
|
|
187
|
+
value <= 599
|
|
188
|
+
? value
|
|
189
|
+
: null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** A failed delivery, before the loop decides whether to retry it. */
|
|
193
|
+
export function recordToolCallError(
|
|
194
|
+
targets: ToolCallRetryFactsTargets,
|
|
195
|
+
input: {
|
|
196
|
+
reason: ToolCallRetryReason;
|
|
197
|
+
status: number | null;
|
|
198
|
+
/** The classified error, whose `origin` is recorded when it has one. */
|
|
199
|
+
error?: unknown;
|
|
200
|
+
retryAfterPresent?: boolean;
|
|
201
|
+
/** The failure proves the request was never sent to the provider. */
|
|
202
|
+
knownNotDispatched?: boolean;
|
|
203
|
+
},
|
|
204
|
+
): void {
|
|
205
|
+
const status = httpStatus(input.status);
|
|
206
|
+
const origin =
|
|
207
|
+
input.error instanceof ToolExecutionError
|
|
208
|
+
? errorOrigin(input.error.origin)
|
|
209
|
+
: null;
|
|
210
|
+
const networkKind =
|
|
211
|
+
input.error instanceof ToolExecutionError &&
|
|
212
|
+
typeof input.error.networkKind === 'string' &&
|
|
213
|
+
(TOOL_CALL_NETWORK_KINDS as readonly string[]).includes(
|
|
214
|
+
input.error.networkKind,
|
|
215
|
+
)
|
|
216
|
+
? (input.error.networkKind as ToolCallNetworkKind)
|
|
217
|
+
: null;
|
|
218
|
+
const dispatched = input.knownNotDispatched === true ? false : null;
|
|
219
|
+
forEachTarget(targets, (facts) => {
|
|
220
|
+
facts.lastErrorReason = input.reason;
|
|
221
|
+
facts.lastErrorStatus = status;
|
|
222
|
+
facts.lastErrorOrigin = origin;
|
|
223
|
+
facts.lastErrorNetworkKind = networkKind;
|
|
224
|
+
facts.lastErrorDispatched = dispatched;
|
|
225
|
+
if (input.retryAfterPresent === true) facts.retryAfterSeen = true;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** The loop is about to wait and send again after the last recorded failure. */
|
|
230
|
+
export function recordToolCallRetry(
|
|
231
|
+
targets: ToolCallRetryFactsTargets,
|
|
232
|
+
waitMs: number,
|
|
233
|
+
): void {
|
|
234
|
+
const wait =
|
|
235
|
+
typeof waitMs === 'number' && Number.isFinite(waitMs) && waitMs > 0
|
|
236
|
+
? Math.round(waitMs)
|
|
237
|
+
: 0;
|
|
238
|
+
forEachTarget(targets, (facts) => {
|
|
239
|
+
facts.retries += 1;
|
|
240
|
+
facts.retryWaitMs += wait;
|
|
241
|
+
if (facts.firstRetryReason === null) {
|
|
242
|
+
facts.firstRetryReason = facts.lastErrorReason;
|
|
243
|
+
facts.firstRetryStatus = facts.lastErrorStatus;
|
|
244
|
+
facts.firstRetryOrigin = facts.lastErrorOrigin;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The optional fields a `tool_call_completed` / `tool_call_failed` line
|
|
251
|
+
* carries. Every field is a count, a boolean, a status, or a closed-vocabulary
|
|
252
|
+
* string, so the line stays a fixed size.
|
|
253
|
+
*/
|
|
254
|
+
export function toolCallRetryFactsLogFields(
|
|
255
|
+
facts: ToolCallRetryFacts,
|
|
256
|
+
): Record<string, number | boolean | string | null> {
|
|
257
|
+
return {
|
|
258
|
+
provider: facts.provider,
|
|
259
|
+
sends: facts.sends,
|
|
260
|
+
retries: facts.retries,
|
|
261
|
+
retry_wait_ms: facts.retryWaitMs,
|
|
262
|
+
retry_after_seen: facts.retryAfterSeen,
|
|
263
|
+
first_retry_reason: facts.firstRetryReason,
|
|
264
|
+
first_retry_status: facts.firstRetryStatus,
|
|
265
|
+
first_retry_origin: facts.firstRetryOrigin,
|
|
266
|
+
last_error_reason: facts.lastErrorReason,
|
|
267
|
+
last_error_status: facts.lastErrorStatus,
|
|
268
|
+
last_error_origin: facts.lastErrorOrigin,
|
|
269
|
+
last_error_network_kind: facts.lastErrorNetworkKind,
|
|
270
|
+
last_error_dispatched: facts.lastErrorDispatched,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const ERROR_CODE = /^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/u;
|
|
275
|
+
const ERROR_CLASS = /^[A-Za-z][A-Za-z0-9_]{0,63}$/u;
|
|
276
|
+
|
|
277
|
+
function boundedToken(value: unknown, pattern: RegExp): string | null {
|
|
278
|
+
return typeof value === 'string' && pattern.test(value) ? value : null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The structured identity of the error a call failed with: its class name
|
|
283
|
+
* and, for a tool execution failure, its code, category, origin, HTTP status
|
|
284
|
+
* and network kind. Never the message.
|
|
285
|
+
*/
|
|
286
|
+
export function toolCallFailureLogFields(
|
|
287
|
+
error: unknown,
|
|
288
|
+
): Record<string, number | string | null> {
|
|
289
|
+
const errorClass =
|
|
290
|
+
error instanceof Error
|
|
291
|
+
? boundedToken(error.name, ERROR_CLASS)
|
|
292
|
+
: error === null || error === undefined
|
|
293
|
+
? null
|
|
294
|
+
: 'NonError';
|
|
295
|
+
if (error instanceof ToolExecutionError) {
|
|
296
|
+
return {
|
|
297
|
+
error_class: errorClass,
|
|
298
|
+
error_code: boundedToken(error.code, ERROR_CODE),
|
|
299
|
+
error_category: boundedToken(error.category, ERROR_CLASS),
|
|
300
|
+
error_origin: errorOrigin(error.origin),
|
|
301
|
+
error_status: httpStatus(error.statusCode),
|
|
302
|
+
error_network_kind: boundedToken(error.networkKind, ERROR_CLASS),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const code =
|
|
306
|
+
error !== null && typeof error === 'object'
|
|
307
|
+
? (error as { code?: unknown }).code
|
|
308
|
+
: undefined;
|
|
309
|
+
return {
|
|
310
|
+
error_class: errorClass,
|
|
311
|
+
error_code: boundedToken(code, ERROR_CODE),
|
|
312
|
+
error_category: null,
|
|
313
|
+
error_origin: null,
|
|
314
|
+
error_status: null,
|
|
315
|
+
error_network_kind: null,
|
|
316
|
+
};
|
|
317
|
+
}
|