deepline 0.3.524 → 0.3.525
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 +8 -0
- package/dist/bundling-sources/sdk/src/http-core.ts +14 -0
- package/dist/bundling-sources/sdk/src/plays/play-description.ts +1 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/types.ts +10 -0
- package/dist/bundling-sources/shared_libs/observability/dlq.ts +19 -0
- package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
- package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +38 -0
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +94 -9
- package/dist/bundling-sources/shared_libs/play-runtime/run-retry-summary.ts +202 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +60 -8
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +112 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +39 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +13 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-retry-facts.ts +62 -0
- package/dist/cli/auth-K7PMRXNG.js +43 -0
- package/dist/cli/{auth-QXJMVLPN.mjs → auth-TH3VGYBK.mjs} +5 -5
- package/dist/cli/{billing-SNSIFM4B.mjs → billing-CMHFI2LN.mjs} +8 -8
- package/dist/cli/{billing-N5R4HTHT.js → billing-TWKVUFU2.js} +83 -83
- package/dist/cli/{chunk-TZTWH53O.js → chunk-2WFVLOB7.js} +1 -1
- package/dist/cli/{chunk-BXVYVIMB.js → chunk-4UWXFXQF.js} +3 -3
- package/dist/cli/{chunk-II3BJKCH.mjs → chunk-5BSGWIQD.mjs} +2 -2
- package/dist/cli/{chunk-WOEPDSO3.js → chunk-5JFAQUZS.js} +26 -26
- package/dist/cli/{chunk-RVHUW4TN.js → chunk-5YAJGRWB.js} +17 -17
- package/dist/cli/{chunk-ITJ7NB2D.mjs → chunk-7AOFSZJM.mjs} +3 -1
- package/dist/cli/{chunk-RIX26ZJD.mjs → chunk-7C4F4TLR.mjs} +1 -1
- package/dist/cli/{chunk-RTDX5NNN.mjs → chunk-7OF3A4KJ.mjs} +3 -3
- package/dist/cli/{chunk-2ZWNIS54.js → chunk-AVDEYOVP.js} +269 -269
- package/dist/cli/{chunk-GJYLC4JB.mjs → chunk-BNH4Y35W.mjs} +2 -2
- package/dist/cli/{chunk-I75VRGQG.js → chunk-CKTRQSRA.js} +22 -22
- package/dist/cli/{chunk-R457IMHJ.mjs → chunk-CLTL7ZJI.mjs} +1 -1
- package/dist/cli/{chunk-7E6B7VMS.js → chunk-CQSANB3V.js} +5 -5
- package/dist/cli/{chunk-7OQGZBDG.js → chunk-CWRL6IQP.js} +13 -6
- package/dist/cli/{chunk-HLAFGQPV.mjs → chunk-CZNEQMJR.mjs} +5 -2
- package/dist/cli/{chunk-7QM6DNR4.js → chunk-DYS3KWYF.js} +11 -11
- package/dist/cli/{chunk-GMO3JDZA.mjs → chunk-EP6YH6QJ.mjs} +2 -2
- package/dist/cli/{chunk-V4RJ57MA.js → chunk-ESWM2JW4.js} +2 -2
- package/dist/cli/{chunk-YGOI5ZE5.mjs → chunk-ETHVJ2ZE.mjs} +1 -1
- package/dist/cli/{chunk-3WWTBQHC.mjs → chunk-GCLNX72G.mjs} +2 -2
- package/dist/cli/{chunk-R2VZVHJP.mjs → chunk-GESIFFQX.mjs} +1 -1
- package/dist/cli/{chunk-BXIQD2IY.mjs → chunk-IMO3HXWZ.mjs} +1 -1
- package/dist/cli/{chunk-2ZX7XSAQ.mjs → chunk-JVWSIA2V.mjs} +4 -4
- package/dist/cli/{chunk-YXVYPYIP.js → chunk-KBOSALBI.js} +10 -10
- package/dist/cli/{chunk-RUULUCBP.js → chunk-KEZ3KBWW.js} +10 -10
- package/dist/cli/{chunk-YCIXY66B.mjs → chunk-KPINGHIF.mjs} +2 -2
- package/dist/cli/{chunk-KKPBCB6D.mjs → chunk-LAMGJQDY.mjs} +2 -2
- package/dist/cli/{chunk-OCT4SUJA.js → chunk-LE537GBC.js} +13 -6
- package/dist/cli/{chunk-HTYT2OHB.js → chunk-LXKH4MKH.js} +6 -6
- package/dist/cli/{chunk-EO55Y4QW.mjs → chunk-M43ZYNDA.mjs} +5 -5
- package/dist/cli/{chunk-PFKKZVFK.js → chunk-MHBSRNI7.js} +41 -41
- package/dist/cli/{chunk-ANKD3AIR.js → chunk-MRUFGOJR.js} +2 -2
- package/dist/cli/{chunk-Z4MOEQSY.js → chunk-N4MMU3QF.js} +21 -21
- package/dist/cli/{chunk-ATATJNJ6.js → chunk-NB2ECLQE.js} +9 -9
- package/dist/cli/{chunk-YKFW3NNA.mjs → chunk-NO4URKKT.mjs} +5 -5
- package/dist/cli/{chunk-66N76YZG.js → chunk-NRBCETWL.js} +44 -44
- package/dist/cli/{chunk-OQ5G7RFQ.mjs → chunk-OWQF6WVH.mjs} +10 -3
- package/dist/cli/{chunk-CH7JVSA7.mjs → chunk-OXFIJYN3.mjs} +8 -8
- package/dist/cli/{chunk-EQNAQENZ.js → chunk-P62LON53.js} +2 -2
- package/dist/cli/{chunk-NMU3VR5U.js → chunk-PMH4GLMD.js} +1 -0
- package/dist/cli/{chunk-S3A4IXBQ.mjs → chunk-PSX3WHIH.mjs} +1 -0
- package/dist/cli/{chunk-V7KUBDEB.js → chunk-QR7VYYNM.js} +144 -141
- package/dist/cli/{chunk-KSQXBLRW.mjs → chunk-RMZ6CISE.mjs} +3 -3
- package/dist/cli/{chunk-GTGJBZVH.js → chunk-S5LUY3KJ.js} +7 -7
- package/dist/cli/{chunk-SF4QJVBE.js → chunk-TFEGJEYO.js} +3 -3
- package/dist/cli/{chunk-VHTVXS5A.js → chunk-TO72GW5I.js} +16 -16
- package/dist/cli/{chunk-WCVIPZWX.mjs → chunk-TXSBPBHB.mjs} +5 -5
- package/dist/cli/{chunk-MW3YMPD2.mjs → chunk-U4M32NFS.mjs} +1 -1
- package/dist/cli/{chunk-NUC7ZVDG.mjs → chunk-UQYKSOGO.mjs} +5 -5
- package/dist/cli/{chunk-536TGWR6.mjs → chunk-UXF3ODJJ.mjs} +2 -2
- package/dist/cli/{chunk-LRWDZDBS.js → chunk-V2GN4PLK.js} +5 -5
- package/dist/cli/{chunk-SMWFOGUT.js → chunk-V65J64FL.js} +53 -53
- package/dist/cli/{chunk-V2YIBBVT.mjs → chunk-VYIAWAKJ.mjs} +1 -1
- package/dist/cli/{chunk-JDIQBZ6O.js → chunk-WA3FG7DH.js} +14 -14
- package/dist/cli/{chunk-XURWFEXM.mjs → chunk-WEYFSBAD.mjs} +13 -6
- package/dist/cli/{chunk-T43FF5PF.mjs → chunk-WGRDOPAK.mjs} +2 -2
- package/dist/cli/{chunk-NTLBZUHD.js → chunk-XYIECA7M.js} +4 -2
- package/dist/cli/{chunk-FXTV5B3D.mjs → chunk-YC7FKAJ4.mjs} +12 -12
- package/dist/cli/{chunk-BN5VKY4X.js → chunk-ZS2WHWWL.js} +7 -7
- package/dist/cli/{chunk-PFKWKWUJ.mjs → chunk-ZWFTHEPT.mjs} +2 -2
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-Q2LWKXAV.js → csv-5JHWVJ5N.js} +13 -13
- package/dist/cli/{csv-HT2JBCW2.mjs → csv-OO554TPX.mjs} +4 -4
- package/dist/cli/{db-XEV4WEE4.js → db-CYQJ4OXF.js} +28 -28
- package/dist/cli/{db-CS3XQ2LX.mjs → db-SQKJ6RKU.mjs} +7 -7
- package/dist/cli/describe-N7AKTUQV.mjs +50 -0
- package/dist/cli/describe-PASXOL3R.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 +5 -5
- package/dist/cli/describe-core.mjs +4 -4
- package/dist/cli/{executions-L6XFG5MP.mjs → executions-F34DORW6.mjs} +7 -7
- package/dist/cli/{executions-JCC34WAD.js → executions-K7EGCRKX.js} +9 -9
- package/dist/cli/{feedback-AWBDO5I6.mjs → feedback-GQHKCS66.mjs} +5 -5
- package/dist/cli/{feedback-HV2M2G7N.js → feedback-NOQVCA3Q.js} +10 -10
- package/dist/cli/{git-S4LRXTRX.mjs → git-2EEITXDB.mjs} +5 -5
- package/dist/cli/git-UU4YFJ2Q.js +25 -0
- package/dist/cli/index.js +145 -145
- package/dist/cli/index.mjs +44 -44
- package/dist/cli/{legacy-noops-7MOKBL4O.mjs → legacy-noops-JHMY5XRB.mjs} +6 -6
- package/dist/cli/{legacy-noops-RGSZUD6V.js → legacy-noops-RFNHQ7RG.js} +9 -9
- package/dist/cli/{monitors-XQNXDZPQ.mjs → monitors-RDMP6SPZ.mjs} +8 -8
- package/dist/cli/{monitors-JEFM2C5W.js → monitors-UKRZ4BDK.js} +101 -101
- package/dist/cli/{org-GYLA5V32.js → org-OX7TYTHV.js} +87 -87
- package/dist/cli/{org-KTMJZGTN.mjs → org-RF3G4KMB.mjs} +7 -7
- package/dist/cli/{pages-WOMU2T2O.mjs → pages-FBM3MGSP.mjs} +7 -7
- package/dist/cli/{pages-RY4U7OCL.js → pages-MKQT5LFV.js} +19 -19
- package/dist/cli/{play-2Q6MWJ3D.js → play-OOVX2DMV.js} +756 -707
- package/dist/cli/{play-KOYGGNYS.mjs → play-YWC2UORM.mjs} +151 -102
- package/dist/cli/{providers-HOIRHMN2.js → providers-2CGZYLER.js} +10 -10
- package/dist/cli/{providers-7YKDITJC.mjs → providers-3PEQESIU.mjs} +7 -7
- package/dist/cli/{quickstart-OWCJOSQA.js → quickstart-6AANHKQZ.js} +6 -6
- package/dist/cli/{quickstart-RDXHSMVX.mjs → quickstart-KVB36SOW.mjs} +4 -4
- package/dist/cli/{run-MT2ABKO5.js → run-NJ7WV5TK.js} +46 -46
- package/dist/cli/{run-RT73NDP5.mjs → run-QC23NRKO.mjs} +27 -27
- package/dist/cli/{search-CJPKIGSA.mjs → search-7BMFFZI2.mjs} +9 -9
- package/dist/cli/search-NH4DTXUK.js +33 -0
- package/dist/cli/{search-output-AREMA544.mjs → search-output-CALZ4ZI2.mjs} +4 -4
- package/dist/cli/{search-output-OSBZ7WK6.js → search-output-XC2AVBFX.js} +6 -6
- package/dist/cli/{secrets-BTIY2FEJ.mjs → secrets-7ZHA57DI.mjs} +7 -7
- package/dist/cli/{secrets-OV6KH633.js → secrets-VHU4B2D4.js} +16 -16
- package/dist/cli/sessions-2TE5JWVP.js +18 -0
- package/dist/cli/{sessions-3CO3ZFOD.mjs → sessions-YYULWFZE.mjs} +6 -6
- package/dist/cli/{settings-7BQIC7QN.mjs → settings-AVY4NNHI.mjs} +14 -14
- package/dist/cli/{settings-LBIECYDB.js → settings-WV77QJGD.js} +87 -87
- package/dist/cli/{setup-XPTSNNES.mjs → setup-AOUJ3RMU.mjs} +10 -10
- package/dist/cli/{setup-QZE7QR3F.js → setup-GE5TLTC4.js} +50 -50
- package/dist/cli/{skills-TGGKIQLT.mjs → skills-FVWO2G66.mjs} +8 -8
- package/dist/cli/skills-OL7LD6QX.js +37 -0
- package/dist/cli/{tools-MKIFX2TQ.mjs → tools-URE655B4.mjs} +20 -20
- package/dist/cli/tools-VQ5JO6DI.js +57 -0
- package/dist/cli/{update-5R3D3WNH.mjs → update-5B4G4345.mjs} +10 -10
- package/dist/cli/update-7ZOIOTZN.js +35 -0
- package/dist/cli/{views-VHKDHHUP.mjs → views-GSECJ5IK.mjs} +7 -7
- package/dist/cli/{views-VPWEINIA.js → views-IC762HEQ.js} +19 -19
- package/dist/cli/{workflow-D5DF65N6.mjs → workflow-6UQM565I.mjs} +8 -8
- package/dist/cli/{workflow-7K2VEQ4V.js → workflow-EME7ZEOV.js} +18 -18
- package/dist/{client-C5_6W8yd.d.mts → client-Bd2meveV.d.mts} +1 -1
- package/dist/{client-iXW4TOat.d.ts → client-CBCVhL8U.d.ts} +1 -1
- package/dist/{client-core-Dob428Z4.d.mts → client-core-CGj8V9mw.d.mts} +67 -0
- package/dist/{client-core-B-GPfmaC.d.ts → client-core-CsRRWCFy.d.ts} +67 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -10
- package/dist/index.mjs +7 -7
- package/dist/install-integrity.json +120 -118
- package/dist/plays/play-description.d.mts +1 -1
- package/dist/plays/play-description.d.ts +1 -1
- package/dist/plays/play-description.js +2 -2
- package/dist/plays/play-description.mjs +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 +6 -6
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-OKPHHMMP.js +0 -43
- package/dist/cli/describe-5G5NXO5E.js +0 -50
- package/dist/cli/describe-OUTXLDGZ.mjs +0 -50
- package/dist/cli/git-GDPTG52F.js +0 -25
- package/dist/cli/search-7VBA6IGS.js +0 -33
- package/dist/cli/sessions-B3WNEWRW.js +0 -18
- package/dist/cli/skills-TXBRTWEV.js +0 -37
- package/dist/cli/tools-RZJV4X3J.js +0 -57
- package/dist/cli/update-YWGGPWUA.js +0 -35
|
@@ -639,6 +639,11 @@ export type RunsGetOptions = {
|
|
|
639
639
|
configuration?: boolean;
|
|
640
640
|
/** Include terminal runtime diagnostics (`run.performance`) without full results. */
|
|
641
641
|
performance?: boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Include `run.retries`: fixed-size attempt, sandbox, platform-recovery and
|
|
644
|
+
* resume counts. Costs one extra scheduler read, so polls should omit it.
|
|
645
|
+
*/
|
|
646
|
+
retries?: boolean;
|
|
642
647
|
/** Attach a bounded end-of-stream window for a failed run. */
|
|
643
648
|
failedLogs?: boolean;
|
|
644
649
|
/** Requested failed-log lines to attach (default 20, hard-capped at 20). */
|
|
@@ -5050,6 +5055,9 @@ export class DeeplineClient {
|
|
|
5050
5055
|
if (options?.performance === true) {
|
|
5051
5056
|
params.append('include', 'performance');
|
|
5052
5057
|
}
|
|
5058
|
+
if (options?.retries === true) {
|
|
5059
|
+
params.append('include', 'retries');
|
|
5060
|
+
}
|
|
5053
5061
|
const query = params.size > 0 ? `?${params.toString()}` : '';
|
|
5054
5062
|
const response = await this.http.get<Record<string, unknown>>(
|
|
5055
5063
|
`/api/v2/runs/${encodeURIComponent(runId)}${query}`,
|
|
@@ -66,6 +66,18 @@ const REQUEST_TIMEOUT_MARKER = Symbol('deeplineRequestTimeout');
|
|
|
66
66
|
const REQUEST_ABORT_MARKER = Symbol('deeplineRequestAbort');
|
|
67
67
|
const MAX_AUTOMATIC_RETRY_WAIT_MS = 30_000;
|
|
68
68
|
|
|
69
|
+
function deploymentProtectionRedirect(
|
|
70
|
+
headers: Record<string, string>,
|
|
71
|
+
): RequestRedirect | undefined {
|
|
72
|
+
// Fetch strips Authorization on cross-origin redirects, but keeps this
|
|
73
|
+
// custom credential. Stop at the first redirect when it is present.
|
|
74
|
+
return Object.keys(headers).some(
|
|
75
|
+
(name) => name.toLowerCase() === 'x-vercel-protection-bypass',
|
|
76
|
+
)
|
|
77
|
+
? 'manual'
|
|
78
|
+
: undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
69
81
|
interface RequestOptions {
|
|
70
82
|
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
71
83
|
body?: unknown;
|
|
@@ -605,6 +617,7 @@ export class HttpClient {
|
|
|
605
617
|
headers,
|
|
606
618
|
body: requestBody,
|
|
607
619
|
signal: controller.signal,
|
|
620
|
+
redirect: deploymentProtectionRedirect(headers),
|
|
608
621
|
});
|
|
609
622
|
|
|
610
623
|
networkPhase = 'reading_body';
|
|
@@ -946,6 +959,7 @@ export class HttpClient {
|
|
|
946
959
|
? JSON.stringify(options.body)
|
|
947
960
|
: undefined,
|
|
948
961
|
signal: options?.signal,
|
|
962
|
+
redirect: deploymentProtectionRedirect(headers),
|
|
949
963
|
});
|
|
950
964
|
options?.onResponse?.(response);
|
|
951
965
|
|
|
@@ -154,6 +154,7 @@ export function describePlayDetail(
|
|
|
154
154
|
const play = detail.play;
|
|
155
155
|
return {
|
|
156
156
|
...describePlayListItem(play, options),
|
|
157
|
+
...(play.ownerType === 'org' && play._id ? { playId: play._id } : {}),
|
|
157
158
|
currentPublishedVersion:
|
|
158
159
|
play.currentPublishedVersion ?? play.liveRevision?.version ?? null,
|
|
159
160
|
latestRunId: play.latestRunId ?? detail.latestRuns[0]?.workflowId ?? null,
|
|
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
|
|
|
205
205
|
// getters keep their established compatibility behavior.
|
|
206
206
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
207
207
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
208
|
-
version: '0.3.
|
|
208
|
+
version: '0.3.525',
|
|
209
209
|
updateSummary: {
|
|
210
210
|
introducedIn: '0.3.90',
|
|
211
211
|
summary:
|
|
@@ -11,6 +11,7 @@ export type {
|
|
|
11
11
|
import type { PlayCompilerManifest } from '../../shared_libs/plays/compiler-manifest';
|
|
12
12
|
import type { RunGetStatus, RunLifecycleStatus } from './client';
|
|
13
13
|
import type { PlayGrepMatch } from '../../shared_libs/plays/play-grep-search';
|
|
14
|
+
import type { RunRetrySummary } from '../../shared_libs/play-runtime/run-retry-summary';
|
|
14
15
|
import type { PlayRunRuntimeSelection } from '../../shared_libs/play-runtime/runtime-environment';
|
|
15
16
|
import type {
|
|
16
17
|
PlayActivityObservation,
|
|
@@ -934,6 +935,13 @@ export interface PlayRunPackage {
|
|
|
934
935
|
*/
|
|
935
936
|
performance?: TerminalRuntimePerformance;
|
|
936
937
|
performanceUnavailableReason?: TerminalRuntimePerformanceUnavailableReason;
|
|
938
|
+
/**
|
|
939
|
+
* Fixed-size failure-driven retry counts for the current resume epoch, on
|
|
940
|
+
* `include=retries` (`runs get` asks for it). Durable waits are not
|
|
941
|
+
* counted. Absent on older servers.
|
|
942
|
+
*/
|
|
943
|
+
retries?: RunRetrySummary;
|
|
944
|
+
retriesUnavailableReason?: 'not_recorded' | 'invalid_facts' | 'read_failed';
|
|
937
945
|
/** Canonical explanation of what this run is doing or waiting on. */
|
|
938
946
|
activity?: PlayRunActivityProjection | null;
|
|
939
947
|
};
|
|
@@ -1818,6 +1826,8 @@ export interface ProductNotificationConfigurationResponse {
|
|
|
1818
1826
|
|
|
1819
1827
|
export interface PlayDescription {
|
|
1820
1828
|
name: string;
|
|
1829
|
+
/** Stable workspace-owned Play definition ID. */
|
|
1830
|
+
playId?: string;
|
|
1821
1831
|
/** Stable registry key. Same value `plays list` reports for this play. */
|
|
1822
1832
|
playKey?: string;
|
|
1823
1833
|
reference?: string;
|
|
@@ -1425,6 +1425,25 @@ const DLQ_PATH_METADATA: Readonly<Record<string, DlqPathMetadata>> = {
|
|
|
1425
1425
|
},
|
|
1426
1426
|
],
|
|
1427
1427
|
},
|
|
1428
|
+
'mcp-event-deliveries': {
|
|
1429
|
+
lookupIndex: {
|
|
1430
|
+
table: 'mcpEventDeliveries',
|
|
1431
|
+
index: 'by_state_next_attempt',
|
|
1432
|
+
key: 'state + nextAttemptAt',
|
|
1433
|
+
bounded: true,
|
|
1434
|
+
},
|
|
1435
|
+
transitions: [
|
|
1436
|
+
{
|
|
1437
|
+
action: 'retry',
|
|
1438
|
+
fromStates: ['dead_lettered'],
|
|
1439
|
+
toState: 'pending',
|
|
1440
|
+
enabled: false,
|
|
1441
|
+
requiresApproval: true,
|
|
1442
|
+
reason:
|
|
1443
|
+
'Manual replay is unavailable because it must revalidate the grant and preserve the webhook event ID.',
|
|
1444
|
+
},
|
|
1445
|
+
],
|
|
1446
|
+
},
|
|
1428
1447
|
'notification-deliveries': {
|
|
1429
1448
|
lookupIndex: {
|
|
1430
1449
|
table: 'productNotificationDeliveries',
|
|
@@ -298,6 +298,15 @@ export const OPERATIONS_QUEUE_CATALOG = [
|
|
|
298
298
|
600_000,
|
|
299
299
|
3_600_000,
|
|
300
300
|
),
|
|
301
|
+
queue(
|
|
302
|
+
'mcp-event-deliveries',
|
|
303
|
+
'MCP event deliveries',
|
|
304
|
+
'leased_workset',
|
|
305
|
+
'mcp',
|
|
306
|
+
'Deliver authorized Play events to verified callbacks',
|
|
307
|
+
120_000,
|
|
308
|
+
300_000,
|
|
309
|
+
),
|
|
301
310
|
queue(
|
|
302
311
|
'notification-deliveries',
|
|
303
312
|
'Notification deliveries',
|
|
@@ -287,6 +287,7 @@ export const QUEUE_CONNECTOR_BACKENDS: Readonly<
|
|
|
287
287
|
'stripe-financial-inbox': 'provider',
|
|
288
288
|
'async-usage-recovery': 'postgres-outbox',
|
|
289
289
|
'notification-deliveries': 'workpool',
|
|
290
|
+
'mcp-event-deliveries': 'convex',
|
|
290
291
|
'inbound-demo-form-submissions': 'convex',
|
|
291
292
|
'inbound-demo-sales': 'convex',
|
|
292
293
|
'usage-rollup-fold': 'postgres-outbox',
|
|
@@ -296,6 +296,7 @@ import {
|
|
|
296
296
|
latestCacheResultKey,
|
|
297
297
|
latestCacheResultOutput,
|
|
298
298
|
type LegacySlotSearch,
|
|
299
|
+
type ReplayRefusal,
|
|
299
300
|
parseLatestCacheResult,
|
|
300
301
|
type ReplayMismatchPolicy,
|
|
301
302
|
toolReadSemanticKey,
|
|
@@ -3215,6 +3216,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3215
3216
|
>();
|
|
3216
3217
|
/** Authored calls whose unverified recovery was already reported. */
|
|
3217
3218
|
private readonly unverifiedRecoveryReported = new Set<string>();
|
|
3219
|
+
/** Replay refusals already reported, by code, operation and authored id. */
|
|
3220
|
+
private readonly replayRefusalsReported = new Map<string, number>();
|
|
3218
3221
|
/**
|
|
3219
3222
|
* Parent-level inline-child aggregates. Maintained only by the single-writer
|
|
3220
3223
|
* progress path (never per child) so concurrent fan-out cannot contend. See
|
|
@@ -4473,6 +4476,40 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4473
4476
|
};
|
|
4474
4477
|
}
|
|
4475
4478
|
|
|
4479
|
+
/**
|
|
4480
|
+
* One structured line per replay refusal, emitted where the refusal is
|
|
4481
|
+
* decided, so a Play that catches the error cannot hide it. Rate-limited
|
|
4482
|
+
* per code, operation and authored id: the first refusal and then powers of
|
|
4483
|
+
* two, each carrying the running count. Never carries inputs, outputs or
|
|
4484
|
+
* secrets. Written to the run log and to the runner's stderr, which the
|
|
4485
|
+
* runtime log shipper forwards.
|
|
4486
|
+
*/
|
|
4487
|
+
private reportReplayRefusal(refusal: ReplayRefusal): void {
|
|
4488
|
+
const reportKey = `${refusal.code}:${refusal.operation}:${refusal.callId}`;
|
|
4489
|
+
const count = (this.replayRefusalsReported.get(reportKey) ?? 0) + 1;
|
|
4490
|
+
this.replayRefusalsReported.set(reportKey, count);
|
|
4491
|
+
if ((count & (count - 1)) !== 0) return;
|
|
4492
|
+
const line = JSON.stringify({
|
|
4493
|
+
event: 'durable_replay_refused',
|
|
4494
|
+
code: refusal.code,
|
|
4495
|
+
operation: refusal.operation,
|
|
4496
|
+
call_key: refusal.callId,
|
|
4497
|
+
ordinal: refusal.ordinal,
|
|
4498
|
+
rung: refusal.rung,
|
|
4499
|
+
reason: refusal.reason,
|
|
4500
|
+
...(refusal.slot ? { slot: refusal.slot } : {}),
|
|
4501
|
+
...(refusal.recordedIdentitySources
|
|
4502
|
+
? { recorded_identity_sources: refusal.recordedIdentitySources }
|
|
4503
|
+
: {}),
|
|
4504
|
+
run_id: this.currentRunId,
|
|
4505
|
+
org_id: this.#options.orgId ?? null,
|
|
4506
|
+
play_name: this.#options.playName ?? null,
|
|
4507
|
+
refusal_count: count,
|
|
4508
|
+
});
|
|
4509
|
+
this.runtimeLog(line, { level: 'error' });
|
|
4510
|
+
console.error(line);
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4476
4513
|
/** Rate-limited: once per authored call per run context. */
|
|
4477
4514
|
private reportLegacyOperationRecovery(
|
|
4478
4515
|
operation: DurableCtxOperation,
|
|
@@ -4553,6 +4590,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4553
4590
|
callId: input.id,
|
|
4554
4591
|
onLegacyRecoveryProven: () =>
|
|
4555
4592
|
this.reportLegacyOperationRecovery(input.operation, input.id),
|
|
4593
|
+
onRefusal: (refusal) => this.reportReplayRefusal(refusal),
|
|
4556
4594
|
runId: this.currentReceiptOwnerRunId,
|
|
4557
4595
|
receiptOwnerRunId: this.currentReceiptOwnerRunId,
|
|
4558
4596
|
// Launches admitted without run-scoped keys wrote this operation under
|
|
@@ -43,6 +43,35 @@ export type CompletedCall = {
|
|
|
43
43
|
inputFingerprint?: string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* One replay refusal, as decided. Carries no input, output or secret: only
|
|
48
|
+
* identities the authored source already names and which check failed.
|
|
49
|
+
*/
|
|
50
|
+
export type ReplayRefusal = {
|
|
51
|
+
code: 'DURABLE_REPLAY_INPUT_MISMATCH' | 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT';
|
|
52
|
+
operation: string;
|
|
53
|
+
callId: string;
|
|
54
|
+
/** This call's call-order occurrence in its scope, when known. */
|
|
55
|
+
ordinal: number | null;
|
|
56
|
+
/**
|
|
57
|
+
* The check that refused:
|
|
58
|
+
* - `binding`: a bound receipt of another request identity;
|
|
59
|
+
* - `legacy_ownership`: a pre-binding receipt nothing proves is this call's.
|
|
60
|
+
*/
|
|
61
|
+
rung: 'binding' | 'legacy_ownership';
|
|
62
|
+
reason:
|
|
63
|
+
| 'input_changed'
|
|
64
|
+
| 'credential_or_action_changed'
|
|
65
|
+
| 'no_identity_source'
|
|
66
|
+
| 'no_recorded_identity'
|
|
67
|
+
| 'recorded_identity_mismatch'
|
|
68
|
+
| 'slot_taken_by_sibling';
|
|
69
|
+
/** Binding refusals: which slot held the other request. */
|
|
70
|
+
slot?: 'exact_request' | 'call_order' | 'legacy_key';
|
|
71
|
+
/** Legacy refusals: where the recorded identities came from. */
|
|
72
|
+
recordedIdentitySources?: Array<'value_receipt_key' | 'result_metadata'>;
|
|
73
|
+
};
|
|
74
|
+
|
|
46
75
|
/**
|
|
47
76
|
* A call's view of the other call-order slots of its authored id and scope,
|
|
48
77
|
* used only for receipts recorded before bindings. See
|
|
@@ -296,6 +325,28 @@ function sharesLatestResult<T>(
|
|
|
296
325
|
* canonical result receipt and the cache/receipt keys in its execution
|
|
297
326
|
* metadata. Each hashes the request it was recorded for.
|
|
298
327
|
*/
|
|
328
|
+
function recordedIdentitySources(
|
|
329
|
+
call: CompletedCall,
|
|
330
|
+
): Array<'value_receipt_key' | 'result_metadata'> {
|
|
331
|
+
const sources: Array<'value_receipt_key' | 'result_metadata'> = [];
|
|
332
|
+
if (call.valueReceiptKey) sources.push('value_receipt_key');
|
|
333
|
+
const value = call.value;
|
|
334
|
+
const result = isSerializedToolExecuteResult(value)
|
|
335
|
+
? deserializeToolExecuteResult(value)
|
|
336
|
+
: isToolExecuteResult(value)
|
|
337
|
+
? value
|
|
338
|
+
: null;
|
|
339
|
+
const execution = result?._metadata?.execution;
|
|
340
|
+
if (
|
|
341
|
+
[execution?.cacheKey, execution?.receiptKey, execution?.resultReceiptKey].some(
|
|
342
|
+
(key) => typeof key === 'string' && key.trim(),
|
|
343
|
+
)
|
|
344
|
+
) {
|
|
345
|
+
sources.push('result_metadata');
|
|
346
|
+
}
|
|
347
|
+
return sources;
|
|
348
|
+
}
|
|
349
|
+
|
|
299
350
|
function recordedRequestIdentities(call: CompletedCall): string[] {
|
|
300
351
|
const keys = new Set<string>();
|
|
301
352
|
if (call.valueReceiptKey) keys.add(call.valueReceiptKey);
|
|
@@ -408,6 +459,11 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
408
459
|
* means `fail`: a call is a read only when its caller proves it.
|
|
409
460
|
*/
|
|
410
461
|
replayMismatchPolicy?: () => Promise<ReplayMismatchPolicy>;
|
|
462
|
+
/**
|
|
463
|
+
* Called once per refusal, where it is decided and before the error is
|
|
464
|
+
* thrown, so a Play that catches the error cannot hide it.
|
|
465
|
+
*/
|
|
466
|
+
onRefusal?: (refusal: ReplayRefusal) => void;
|
|
411
467
|
/** Names the call in a mismatch error. */
|
|
412
468
|
operation?: string;
|
|
413
469
|
callId?: string;
|
|
@@ -825,13 +881,29 @@ async function executeWithFreshnessReceiptOnce<T>(
|
|
|
825
881
|
*/
|
|
826
882
|
const recoverUnbound = async (recorded: CompletedCall) => {
|
|
827
883
|
const search = input.legacySlotSearch;
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
884
|
+
const proven =
|
|
885
|
+
input.operationKeyEncodesRequest === true ||
|
|
886
|
+
(await recordedIdentityMatches(recorded));
|
|
887
|
+
const owned = proven && (!search || search.consume(search.ownIndex));
|
|
832
888
|
if (!owned) {
|
|
833
889
|
const found = await searchLegacySlots();
|
|
834
890
|
if (found) return found;
|
|
891
|
+
const sources = recordedIdentitySources(recorded);
|
|
892
|
+
input.onRefusal?.({
|
|
893
|
+
code: 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT',
|
|
894
|
+
operation: input.operation ?? 'call',
|
|
895
|
+
callId: input.callId ?? 'unknown',
|
|
896
|
+
ordinal: search?.ownIndex ?? null,
|
|
897
|
+
rung: 'legacy_ownership',
|
|
898
|
+
reason: proven
|
|
899
|
+
? 'slot_taken_by_sibling'
|
|
900
|
+
: !input.legacyRequestIdentities
|
|
901
|
+
? 'no_identity_source'
|
|
902
|
+
: sources.length === 0
|
|
903
|
+
? 'no_recorded_identity'
|
|
904
|
+
: 'recorded_identity_mismatch',
|
|
905
|
+
recordedIdentitySources: sources,
|
|
906
|
+
});
|
|
835
907
|
throw new DurableReplayUnverifiableLegacySlotError(
|
|
836
908
|
input.operation ?? 'call',
|
|
837
909
|
input.callId ?? 'unknown',
|
|
@@ -884,7 +956,10 @@ async function executeWithFreshnessReceiptOnce<T>(
|
|
|
884
956
|
* run and executes; a call that may write fails loudly instead of returning
|
|
885
957
|
* another request's output or repeating a write.
|
|
886
958
|
*/
|
|
887
|
-
const refuseOrExecute = async (
|
|
959
|
+
const refuseOrExecute = async (
|
|
960
|
+
recorded: CompletedCall,
|
|
961
|
+
slot: 'exact_request' | 'call_order' | 'legacy_key',
|
|
962
|
+
) => {
|
|
888
963
|
const policy = input.replayMismatchPolicy
|
|
889
964
|
? await input.replayMismatchPolicy()
|
|
890
965
|
: 'fail';
|
|
@@ -893,21 +968,31 @@ async function executeWithFreshnessReceiptOnce<T>(
|
|
|
893
968
|
recorded.inputFingerprint !== undefined
|
|
894
969
|
? recorded.inputFingerprint === input.inputFingerprint
|
|
895
970
|
: recorded === exact;
|
|
971
|
+
const reason = sameInput ? 'credential_or_action_changed' : 'input_changed';
|
|
972
|
+
input.onRefusal?.({
|
|
973
|
+
code: 'DURABLE_REPLAY_INPUT_MISMATCH',
|
|
974
|
+
operation: input.operation ?? 'call',
|
|
975
|
+
callId: input.callId ?? 'unknown',
|
|
976
|
+
ordinal: input.legacySlotSearch?.ownIndex ?? null,
|
|
977
|
+
rung: 'binding',
|
|
978
|
+
reason,
|
|
979
|
+
slot,
|
|
980
|
+
});
|
|
896
981
|
throw new DurableReplayInputMismatchError(
|
|
897
982
|
input.operation ?? 'call',
|
|
898
983
|
input.callId ?? 'unknown',
|
|
899
|
-
|
|
984
|
+
reason,
|
|
900
985
|
);
|
|
901
986
|
};
|
|
902
987
|
if (exact && ownsOperation(exact) === 'no') {
|
|
903
988
|
// The exact-request slot is keyed by the input itself: only the
|
|
904
989
|
// credential scope or action revision differs.
|
|
905
|
-
await refuseOrExecute(exact);
|
|
990
|
+
await refuseOrExecute(exact, 'exact_request');
|
|
906
991
|
} else if (callOrder) {
|
|
907
992
|
if (ownsOperation(callOrder) === 'unverified') {
|
|
908
993
|
return recoverUnbound(callOrder);
|
|
909
994
|
}
|
|
910
|
-
await refuseOrExecute(callOrder);
|
|
995
|
+
await refuseOrExecute(callOrder, 'call_order');
|
|
911
996
|
} else if (
|
|
912
997
|
!exact &&
|
|
913
998
|
input.legacySlotSearch &&
|
|
@@ -925,7 +1010,7 @@ async function executeWithFreshnessReceiptOnce<T>(
|
|
|
925
1010
|
const owner = ownsOperation(legacy);
|
|
926
1011
|
if (owner === 'unverified') return recoverUnbound(legacy);
|
|
927
1012
|
if (owner === 'yes') return outcome(legacy, 'operation_recovery');
|
|
928
|
-
await refuseOrExecute(legacy);
|
|
1013
|
+
await refuseOrExecute(legacy, 'legacy_key');
|
|
929
1014
|
}
|
|
930
1015
|
}
|
|
931
1016
|
if (candidateManifests.status === 'rejected') {
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How often the platform retried one Play run, as a fixed-size summary.
|
|
3
|
+
*
|
|
4
|
+
* Every count comes from the scheduler's durable run and attempt records, read
|
|
5
|
+
* by `readRunRetryFacts`; nothing here is inferred from logs or error text.
|
|
6
|
+
* The summary has the same keys for every run, so its size never grows with
|
|
7
|
+
* rows, calls, attempts or logs. Event-level detail stays in the paginated run
|
|
8
|
+
* events (`runs logs <run-id> --kind activity.observed`).
|
|
9
|
+
*
|
|
10
|
+
* Only failure-driven retries are counted. A durable wait (event wait, long
|
|
11
|
+
* sleep, rate hold) also ends one scheduler attempt and starts another, and the
|
|
12
|
+
* scheduler keeps no per-attempt record that tells such a wait apart from a
|
|
13
|
+
* lost worker or runner. So raw attempt and sandbox counts are deliberately not
|
|
14
|
+
* reported: a run that only slept must not look like it retried.
|
|
15
|
+
*
|
|
16
|
+
* A retried attempt can repeat work a previous attempt already did: Plays are
|
|
17
|
+
* at-least-once. These counts say how many times the platform retried, never
|
|
18
|
+
* that any effect happened exactly once.
|
|
19
|
+
*
|
|
20
|
+
* Provider HTTP retries inside one tool call, runner-to-gateway transport
|
|
21
|
+
* retries, and lost-worker replacements are not counted: no durable record
|
|
22
|
+
* holds an exact per-run count of any of them.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const RUN_RETRY_RECOVERY_OUTCOMES = [
|
|
26
|
+
'none',
|
|
27
|
+
'recovering',
|
|
28
|
+
'recovered',
|
|
29
|
+
'exhausted',
|
|
30
|
+
] as const;
|
|
31
|
+
export type RunRetryRecoveryOutcome =
|
|
32
|
+
(typeof RUN_RETRY_RECOVERY_OUTCOMES)[number];
|
|
33
|
+
|
|
34
|
+
export type RunRetrySummary = {
|
|
35
|
+
/**
|
|
36
|
+
* Counts cover the run's current resume epoch. `runs resume` starts a new
|
|
37
|
+
* epoch and clears the recovery counts of the previous one.
|
|
38
|
+
*/
|
|
39
|
+
scope: 'current_epoch';
|
|
40
|
+
/** How many times `runs resume` continued this run; 0 if never resumed. */
|
|
41
|
+
resumeEpoch: number;
|
|
42
|
+
/**
|
|
43
|
+
* Automatic platform recoveries in this epoch: an attempt that failed for a
|
|
44
|
+
* platform reason was retired and the run requeued. `preCode` failed before
|
|
45
|
+
* the Play's code started; `postCode` failed after it started. Exact: each
|
|
46
|
+
* is the scheduler's own fenced defer count.
|
|
47
|
+
*/
|
|
48
|
+
platformRecoveries: { preCode: number; postCode: number };
|
|
49
|
+
/**
|
|
50
|
+
* `recovering`: waiting out a recovery delay before the next attempt.
|
|
51
|
+
* `exhausted`: the recovery budget ran out, so the run failed.
|
|
52
|
+
* `recovered`: at least one recovery requeued the run and none is pending;
|
|
53
|
+
* it says nothing about how the run itself ended.
|
|
54
|
+
* `none`: no platform recovery in this epoch.
|
|
55
|
+
*/
|
|
56
|
+
recoveryOutcome: RunRetryRecoveryOutcome;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Raw durable scheduler facts for one run, as read from runtime Postgres. */
|
|
60
|
+
export type RunRetryFacts = {
|
|
61
|
+
/** `launch.resumeEpoch`; absent before the first resume. */
|
|
62
|
+
resumeEpoch: unknown;
|
|
63
|
+
/** `runs.recovery_json`, or null for a run that was never recovered. */
|
|
64
|
+
recovery: unknown;
|
|
65
|
+
/** Whether the queued run is waiting out a recovery delay right now. */
|
|
66
|
+
recovering: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
70
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
71
|
+
? (value as Record<string, unknown>)
|
|
72
|
+
: null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const MISSING = Symbol('missing');
|
|
76
|
+
/** A stored JSON value the reader could not parse. */
|
|
77
|
+
export const MALFORMED_STORED_JSON = Symbol('malformed-stored-json');
|
|
78
|
+
|
|
79
|
+
/** A stored count; absent is `MISSING`, anything malformed is `null`. */
|
|
80
|
+
function storedCount(value: unknown): number | null | typeof MISSING {
|
|
81
|
+
if (value === undefined || value === null) return MISSING;
|
|
82
|
+
const parsed = typeof value === 'string' ? Number(value) : value;
|
|
83
|
+
return Number.isSafeInteger(parsed) && (parsed as number) >= 0
|
|
84
|
+
? (parsed as number)
|
|
85
|
+
: null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function storedTime(value: unknown): boolean | null {
|
|
89
|
+
const parsed = storedCount(value);
|
|
90
|
+
if (parsed === MISSING) return false;
|
|
91
|
+
return parsed === null ? null : true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Project the scheduler's facts into the summary. Returns undefined when a
|
|
96
|
+
* stored fact is malformed, so a reader reports the summary as unavailable
|
|
97
|
+
* instead of showing an invented zero.
|
|
98
|
+
*/
|
|
99
|
+
export function projectRunRetrySummary(
|
|
100
|
+
facts: RunRetryFacts,
|
|
101
|
+
): RunRetrySummary | undefined {
|
|
102
|
+
const epoch = storedCount(facts.resumeEpoch);
|
|
103
|
+
if (epoch === null) return undefined;
|
|
104
|
+
// Recovery state is an object or absent; anything else is malformed.
|
|
105
|
+
if (
|
|
106
|
+
facts.recovery !== null &&
|
|
107
|
+
facts.recovery !== undefined &&
|
|
108
|
+
!record(facts.recovery)
|
|
109
|
+
)
|
|
110
|
+
return undefined;
|
|
111
|
+
const recovery = record(facts.recovery) ?? {};
|
|
112
|
+
const postCode = record(recovery.postCode) ?? {};
|
|
113
|
+
const preCode = recovery.kind === 'platform_pre_code' ? recovery : {};
|
|
114
|
+
const postCodeDefers = storedCount(postCode.deferCount);
|
|
115
|
+
const preCodeDefers = storedCount(preCode.deferCount);
|
|
116
|
+
const postCodeExhausted = storedTime(postCode.exhaustedAtMs);
|
|
117
|
+
const preCodeExhausted = storedTime(preCode.exhaustedAtMs);
|
|
118
|
+
if (
|
|
119
|
+
postCodeDefers === null ||
|
|
120
|
+
preCodeDefers === null ||
|
|
121
|
+
postCodeExhausted === null ||
|
|
122
|
+
preCodeExhausted === null
|
|
123
|
+
) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const platformRecoveries = {
|
|
127
|
+
preCode: preCodeDefers === MISSING ? 0 : preCodeDefers,
|
|
128
|
+
postCode: postCodeDefers === MISSING ? 0 : postCodeDefers,
|
|
129
|
+
};
|
|
130
|
+
const recoveryOutcome: RunRetryRecoveryOutcome = facts.recovering
|
|
131
|
+
? 'recovering'
|
|
132
|
+
: postCodeExhausted || preCodeExhausted
|
|
133
|
+
? 'exhausted'
|
|
134
|
+
: platformRecoveries.preCode + platformRecoveries.postCode > 0
|
|
135
|
+
? 'recovered'
|
|
136
|
+
: 'none';
|
|
137
|
+
return {
|
|
138
|
+
scope: 'current_epoch',
|
|
139
|
+
resumeEpoch: epoch === MISSING ? 0 : epoch,
|
|
140
|
+
platformRecoveries,
|
|
141
|
+
recoveryOutcome,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Read a summary from an API response. Older servers omit it, and a value
|
|
147
|
+
* that does not match the contract is treated as absent.
|
|
148
|
+
*/
|
|
149
|
+
export function normalizeRunRetrySummary(
|
|
150
|
+
value: unknown,
|
|
151
|
+
): RunRetrySummary | undefined {
|
|
152
|
+
const source = record(value);
|
|
153
|
+
const recoveries = record(source?.platformRecoveries);
|
|
154
|
+
const count = (field: unknown): field is number =>
|
|
155
|
+
Number.isSafeInteger(field) && (field as number) >= 0;
|
|
156
|
+
if (
|
|
157
|
+
!source ||
|
|
158
|
+
!recoveries ||
|
|
159
|
+
source.scope !== 'current_epoch' ||
|
|
160
|
+
!count(source.resumeEpoch) ||
|
|
161
|
+
!count(recoveries.preCode) ||
|
|
162
|
+
!count(recoveries.postCode) ||
|
|
163
|
+
!(RUN_RETRY_RECOVERY_OUTCOMES as readonly unknown[]).includes(
|
|
164
|
+
source.recoveryOutcome,
|
|
165
|
+
)
|
|
166
|
+
) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
scope: 'current_epoch',
|
|
171
|
+
resumeEpoch: source.resumeEpoch,
|
|
172
|
+
platformRecoveries: {
|
|
173
|
+
preCode: recoveries.preCode,
|
|
174
|
+
postCode: recoveries.postCode,
|
|
175
|
+
},
|
|
176
|
+
recoveryOutcome: source.recoveryOutcome as RunRetryRecoveryOutcome,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Whether the platform retried or someone resumed the run. */
|
|
181
|
+
export function runWasRetried(summary: RunRetrySummary): boolean {
|
|
182
|
+
return (
|
|
183
|
+
summary.resumeEpoch > 0 ||
|
|
184
|
+
summary.recoveryOutcome !== 'none' ||
|
|
185
|
+
summary.platformRecoveries.preCode + summary.platformRecoveries.postCode > 0
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** One line for people. */
|
|
190
|
+
export function formatRunRetrySummary(summary: RunRetrySummary): string {
|
|
191
|
+
const { preCode, postCode } = summary.platformRecoveries;
|
|
192
|
+
const parts = [
|
|
193
|
+
preCode + postCode > 0 || summary.recoveryOutcome !== 'none'
|
|
194
|
+
? `platform recoveries ${preCode} before code, ${postCode} after code (${summary.recoveryOutcome})`
|
|
195
|
+
: 'no platform recovery',
|
|
196
|
+
];
|
|
197
|
+
if (summary.resumeEpoch > 0)
|
|
198
|
+
parts.push(
|
|
199
|
+
`resumed ${summary.resumeEpoch} ${summary.resumeEpoch === 1 ? 'time' : 'times'}; counts are since the last resume`,
|
|
200
|
+
);
|
|
201
|
+
return parts.join(' · ');
|
|
202
|
+
}
|