deepline 0.3.534 → 0.3.535
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundling-sources/sdk/src/client-core.ts +22 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/call-requeue-state-machine.ts +420 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +658 -25
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +26 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-retry-policy.ts +624 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +51 -1
- package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +245 -1
- package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +21 -0
- package/dist/bundling-sources/shared_libs/play-runtime/provider-no-progress.ts +6 -2
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +10 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +55 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +6 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +101 -0
- package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +63 -13
- package/dist/cli/auth-VDCU3T6A.js +43 -0
- package/dist/cli/{auth-MHQYIMVX.mjs → auth-ZCTMB5RA.mjs} +5 -5
- package/dist/cli/{billing-YQLNP4S5.js → billing-GVFKZQH3.js} +82 -82
- package/dist/cli/{billing-LX2PSBJ4.mjs → billing-OU2ZHL72.mjs} +7 -7
- package/dist/cli/{chunk-MQX363YF.js → chunk-243O3FH5.js} +5 -5
- package/dist/cli/{chunk-MYSKWJMA.js → chunk-2D6SWQTK.js} +13 -13
- package/dist/cli/{chunk-NDFNBJGL.js → chunk-4NLRWKZB.js} +26 -26
- package/dist/cli/{chunk-5LZ5VSOK.mjs → chunk-4QELPWUW.mjs} +2 -2
- package/dist/cli/{chunk-GTXSUPCJ.js → chunk-5EKNDNFQ.js} +2 -2
- package/dist/cli/{chunk-V7SCRUFQ.js → chunk-6LHX33VN.js} +6 -6
- package/dist/cli/{chunk-ENCA6O2D.mjs → chunk-6TYRRNXY.mjs} +2 -2
- package/dist/cli/{chunk-AK622KIG.mjs → chunk-7CWSAEYS.mjs} +1 -1
- package/dist/cli/{chunk-DZS4JC7I.js → chunk-7PXP2FQK.js} +2 -2
- package/dist/cli/{chunk-KJVY7V2X.mjs → chunk-7R5DAANG.mjs} +1 -1
- package/dist/cli/{chunk-6IFZPEJE.mjs → chunk-AUEUAPVS.mjs} +1 -1
- package/dist/cli/{chunk-XRZJKHUA.mjs → chunk-BF65LB7X.mjs} +3 -3
- package/dist/cli/{chunk-B2AS3R5W.js → chunk-CIDATNTY.js} +16 -16
- package/dist/cli/{chunk-UWNVFAFN.js → chunk-D4MHCCIR.js} +4 -4
- package/dist/cli/{chunk-GVGQ6NZW.js → chunk-DAPKLYST.js} +41 -41
- package/dist/cli/{chunk-BDWZBMGV.mjs → chunk-DFJODFMC.mjs} +5 -5
- package/dist/cli/{chunk-7GFR5Y4J.mjs → chunk-DWPY6ZID.mjs} +1 -1
- package/dist/cli/{chunk-KSA2XE4T.js → chunk-DYIWDUY4.js} +104 -104
- package/dist/cli/{chunk-5FXMEEF4.mjs → chunk-E3CLOVG5.mjs} +17 -5
- package/dist/cli/{chunk-DGKTHWWH.js → chunk-FGN75ZN6.js} +23 -7
- package/dist/cli/{chunk-MG6YL4M7.mjs → chunk-FZKPPB5P.mjs} +17 -1
- package/dist/cli/{chunk-2P3NVX65.mjs → chunk-G2DLG32W.mjs} +10 -10
- package/dist/cli/{chunk-O53LHONF.mjs → chunk-H6SWS5CG.mjs} +2 -2
- package/dist/cli/{chunk-XBK6WCVA.js → chunk-HWPOXCCK.js} +3 -3
- package/dist/cli/{chunk-HCD36BP6.js → chunk-HYBZWSSH.js} +44 -44
- package/dist/cli/{chunk-BXIUZM5N.mjs → chunk-J75DANZY.mjs} +2 -2
- package/dist/cli/{chunk-KXQCUX3X.mjs → chunk-JQQG4QL4.mjs} +3 -3
- package/dist/cli/{chunk-62SOZ67Y.mjs → chunk-JWWYLGUT.mjs} +2 -2
- package/dist/cli/{chunk-IX45S5VC.js → chunk-K3IPGMGP.js} +11 -11
- package/dist/cli/{chunk-OMVVHX4U.mjs → chunk-K53NKWZO.mjs} +5 -5
- package/dist/cli/{chunk-WR4WETRU.mjs → chunk-K76AEBFY.mjs} +4 -4
- package/dist/cli/{chunk-HPJAE6PP.js → chunk-KA6ZERJL.js} +6 -6
- package/dist/cli/{chunk-MQORQ7WL.js → chunk-KOZBZPRM.js} +53 -53
- package/dist/cli/{chunk-EGTUOYYG.js → chunk-KWGXHPHL.js} +7 -7
- package/dist/cli/{chunk-WDNRPZED.mjs → chunk-LVISZFYO.mjs} +2 -2
- package/dist/cli/{chunk-TVINIDHB.js → chunk-OM732MGV.js} +9 -9
- package/dist/cli/{chunk-JBBJDFUJ.js → chunk-PHLNYBAA.js} +5 -5
- package/dist/cli/{chunk-RH3YRMUY.js → chunk-PI5R65OQ.js} +1 -1
- package/dist/cli/{chunk-NNAE7E23.mjs → chunk-QYBAHYP4.mjs} +6 -6
- package/dist/cli/{chunk-TQH3533L.mjs → chunk-R2KKEHJN.mjs} +5 -5
- package/dist/cli/{chunk-6CEUQYMB.js → chunk-RFQWSH6I.js} +3 -3
- package/dist/cli/{chunk-TG2UB3A5.mjs → chunk-RKY4LBX3.mjs} +1 -1
- package/dist/cli/{chunk-D3J2Y2BP.js → chunk-T7RBM2WX.js} +14 -14
- package/dist/cli/{chunk-DQ5ADV2J.mjs → chunk-TCVCFZP6.mjs} +1 -1
- package/dist/cli/{chunk-LGRZCHKC.js → chunk-UUQ2OXMH.js} +16 -16
- package/dist/cli/{chunk-E7TP25I2.mjs → chunk-W5YJYU4G.mjs} +1 -1
- package/dist/cli/{chunk-VAG5YKP6.mjs → chunk-W6T23EUC.mjs} +1 -1
- package/dist/cli/{chunk-EYXUAJAU.mjs → chunk-WAIBM6KX.mjs} +5 -5
- package/dist/cli/{chunk-VE7ZPLN2.js → chunk-WNNA4L6Z.js} +22 -22
- package/dist/cli/{chunk-SUWTLXCV.js → chunk-XSOTEVOB.js} +17 -5
- package/dist/cli/{chunk-6GTGWZJG.mjs → chunk-YFZLZNTH.mjs} +2 -2
- package/dist/cli/{chunk-A6HNT4EE.js → chunk-ZUVE63Y7.js} +2 -2
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-U3M2G76R.js → csv-CD55KEIO.js} +13 -13
- package/dist/cli/{csv-4ID4E5W3.mjs → csv-CLPVMIRF.mjs} +4 -4
- package/dist/cli/{db-LHX5BBCZ.mjs → db-AU4SMWUN.mjs} +6 -6
- package/dist/cli/{db-IHAQIKEQ.js → db-MQKLDAEO.js} +27 -27
- package/dist/cli/describe-5BFNHT5V.js +50 -0
- package/dist/cli/{describe-CI4MREFF.mjs → describe-AWJUXE2U.mjs} +18 -18
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/{executions-CJ5LV23G.js → executions-77GOLWRM.js} +8 -8
- package/dist/cli/{executions-UJ6JZUL5.mjs → executions-TFIJPUX7.mjs} +6 -6
- package/dist/cli/{feedback-YGTPJBRJ.mjs → feedback-2WRSZ5WL.mjs} +6 -6
- package/dist/cli/{feedback-TGUBVGRP.js → feedback-OV5YAL3A.js} +14 -14
- package/dist/cli/git-HGMX52XU.js +25 -0
- package/dist/cli/{git-3DOTQHJO.mjs → git-VNS4ATLZ.mjs} +5 -5
- package/dist/cli/index.js +145 -145
- package/dist/cli/index.mjs +44 -44
- package/dist/cli/{legacy-noops-RBBYRVLG.mjs → legacy-noops-C732QDCY.mjs} +6 -6
- package/dist/cli/{legacy-noops-BHEHVFHI.js → legacy-noops-HDOB5C6F.js} +9 -9
- package/dist/cli/{monitors-5AJCG6IV.mjs → monitors-2LYEFXOU.mjs} +7 -7
- package/dist/cli/{monitors-XECKLAXA.js → monitors-5IUMHH3E.js} +100 -100
- package/dist/cli/{org-DOBAIYWG.js → org-ADW2EVAC.js} +86 -86
- package/dist/cli/{org-ZAAIEZKB.mjs → org-G4YGZPHS.mjs} +6 -6
- package/dist/cli/{pages-FUOSF6BE.mjs → pages-KXKWSCEV.mjs} +6 -6
- package/dist/cli/{pages-TLC2N6L7.js → pages-VTJGAI2D.js} +18 -18
- package/dist/cli/{play-KLYRMQPF.mjs → play-7GQ56C2D.mjs} +69 -22
- package/dist/cli/{play-E74VN6B7.js → play-EHSOSSHT.js} +367 -320
- package/dist/cli/{providers-APZ6SOSK.js → providers-PWCF6OOO.js} +9 -9
- package/dist/cli/{providers-XTQXV5LB.mjs → providers-WL3YTCSV.mjs} +6 -6
- package/dist/cli/{quickstart-X7RHHQCH.mjs → quickstart-323XOPGI.mjs} +4 -4
- package/dist/cli/{quickstart-S6WN6NWW.js → quickstart-ZKI5MURA.js} +6 -6
- package/dist/cli/{run-3YLIJJ57.js → run-XZPWA6JS.js} +41 -41
- package/dist/cli/{run-TZPBBSPX.mjs → run-ZCNZU3K2.mjs} +23 -23
- package/dist/cli/{search-VLHE2CMZ.mjs → search-CVLVSFMJ.mjs} +8 -8
- package/dist/cli/search-J6EY7DQN.js +33 -0
- package/dist/cli/{search-output-73BYB7UE.mjs → search-output-6PY6RN2R.mjs} +4 -4
- package/dist/cli/{search-output-GCT7PQIT.js → search-output-7HRSSRBS.js} +6 -6
- package/dist/cli/{secrets-RLOTGKQZ.mjs → secrets-6S2ZWDIM.mjs} +6 -6
- package/dist/cli/{secrets-J6CEKXKQ.js → secrets-IYD5VKY4.js} +15 -15
- package/dist/cli/sessions-7HPIVSQ4.js +22 -0
- package/dist/cli/{sessions-7HZ7OZ62.mjs → sessions-GVEX5TUJ.mjs} +6 -6
- package/dist/cli/{settings-72K5YCIS.mjs → settings-BN5MJZ3C.mjs} +13 -13
- package/dist/cli/{settings-WRV5XEZC.js → settings-CANK4HJQ.js} +86 -86
- package/dist/cli/{setup-KQFY6WT4.mjs → setup-JNMSCCU4.mjs} +10 -10
- package/dist/cli/{setup-QVXWT2EQ.js → setup-YSGKGLSJ.js} +50 -50
- package/dist/cli/{skills-C3K3E473.mjs → skills-QCQN2UM2.mjs} +8 -8
- package/dist/cli/skills-WDGSSKJZ.js +37 -0
- package/dist/cli/{tools-4A2OH6MB.mjs → tools-CDPOID7V.mjs} +17 -17
- package/dist/cli/tools-URNVXSTZ.js +57 -0
- package/dist/cli/{update-BS6USKPR.mjs → update-D3ZERUQ3.mjs} +10 -10
- package/dist/cli/update-Q6JW32IA.js +35 -0
- package/dist/cli/{views-4NZGAXHL.js → views-4NV2KQKA.js} +18 -18
- package/dist/cli/{views-WB6GFTRX.mjs → views-RDZRWQBQ.mjs} +6 -6
- package/dist/cli/{workflow-2D4WX55R.mjs → workflow-2CG3TVCG.mjs} +7 -7
- package/dist/cli/{workflow-L2QTQZYV.js → workflow-RABJCAZC.js} +17 -17
- package/dist/{client-DoUVSkqC.d.mts → client-DhSvMO3A.d.mts} +1 -1
- package/dist/{client-core-CPlwsC1Q.d.mts → client-core-CVG1Et-4.d.mts} +9 -1
- package/dist/{client-core-C7KkUIE_.d.ts → client-core-CdWH6Sii.d.ts} +9 -1
- package/dist/{client-DQm56zMs.d.ts → client-oGNJMQFd.d.ts} +1 -1
- package/dist/{compiler-manifest-DsxsQP-T.d.mts → compiler-manifest-D2ZlBGxj.d.mts} +44 -0
- package/dist/{compiler-manifest-DsxsQP-T.d.ts → compiler-manifest-D2ZlBGxj.d.ts} +44 -0
- package/dist/{errors-qdJUVQ3g.d.mts → errors-B-gOQdj-.d.mts} +1 -1
- package/dist/{errors-Bk5h1D-C.d.ts → errors-CB0KAmmV.d.ts} +1 -1
- package/dist/{index-PaupwX1B.d.mts → index-BbJADro4.d.mts} +1 -1
- package/dist/{index-bL66eHYz.d.ts → index-c3nvUGCS.d.ts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +118 -116
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- package/dist/plays/bundle-play-file.mjs +52 -0
- package/dist/plays/play-description.d.mts +2 -2
- package/dist/plays/play-description.d.ts +2 -2
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +2 -2
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-UP2RGPI6.js +0 -43
- package/dist/cli/describe-IVTSD7ST.js +0 -50
- package/dist/cli/git-R3W25XIF.js +0 -25
- package/dist/cli/search-NB5CBALV.js +0 -33
- package/dist/cli/sessions-SFCZSB77.js +0 -22
- package/dist/cli/skills-WIJEHVLA.js +0 -37
- package/dist/cli/tools-VMMERMLO.js +0 -57
- package/dist/cli/update-54WZQDTS.js +0 -35
|
@@ -320,7 +320,9 @@ import {
|
|
|
320
320
|
normalizePlayAuthoringCustomerDbStatement,
|
|
321
321
|
validateOptionalPlayAuthoringField,
|
|
322
322
|
validatePlayAuthoringField,
|
|
323
|
+
validatePlayToolCallRetryPolicy,
|
|
323
324
|
type PlayAuthoringContractEdition,
|
|
325
|
+
type PlayToolCallRetryPolicy,
|
|
324
326
|
type PlaySecretAuth,
|
|
325
327
|
type PlaySecretAwareRequestInit,
|
|
326
328
|
type PlaySecretPromise,
|
|
@@ -474,6 +476,16 @@ import {
|
|
|
474
476
|
isPlayRowExecutionSuspendedError,
|
|
475
477
|
type PlayExecutionSuspension,
|
|
476
478
|
} from './suspension';
|
|
479
|
+
import type { DurableRetryErrorClass } from './durable-retry-policy';
|
|
480
|
+
import {
|
|
481
|
+
BILLING_ERROR_CLASSES,
|
|
482
|
+
callRequeueSends,
|
|
483
|
+
classifyDurableRetryErrorClass,
|
|
484
|
+
decideCallRequeue,
|
|
485
|
+
genericHttpWriteIdempotency,
|
|
486
|
+
transitionCallRequeue,
|
|
487
|
+
type CallRequeueRecord,
|
|
488
|
+
} from './call-requeue-state-machine';
|
|
477
489
|
import {
|
|
478
490
|
createRequestHeaderSecretRedactionContext,
|
|
479
491
|
createSecretRedactionContext,
|
|
@@ -2153,7 +2165,112 @@ function settleToolBatchGroups(
|
|
|
2153
2165
|
);
|
|
2154
2166
|
}
|
|
2155
2167
|
|
|
2168
|
+
/**
|
|
2169
|
+
* The Durable retry class of one in-call HTTP failure, from structured fields
|
|
2170
|
+
* only (the outcome, its ToolExecutionError, and the failure body's `code`,
|
|
2171
|
+
* `upstream_status`, `error_category` and `network_kind`). null: the failure never retries
|
|
2172
|
+
* durably.
|
|
2173
|
+
*/
|
|
2174
|
+
function durableRetryErrorClassForHttpFailure(input: {
|
|
2175
|
+
status: number;
|
|
2176
|
+
failure: ToolExecuteHttpFailureOutcome;
|
|
2177
|
+
responseText: string;
|
|
2178
|
+
}): DurableRetryErrorClass | null {
|
|
2179
|
+
let bodyCode: string | null = null;
|
|
2180
|
+
let bodyUpstreamStatus: number | null = null;
|
|
2181
|
+
let bodyCategory: string | null = null;
|
|
2182
|
+
let bodyNetworkKind: string | null = null;
|
|
2183
|
+
try {
|
|
2184
|
+
const body = JSON.parse(input.responseText) as unknown;
|
|
2185
|
+
if (body && typeof body === 'object' && !Array.isArray(body)) {
|
|
2186
|
+
const fields = body as Record<string, unknown>;
|
|
2187
|
+
bodyCode = typeof fields.code === 'string' ? fields.code : null;
|
|
2188
|
+
bodyUpstreamStatus =
|
|
2189
|
+
typeof fields.upstream_status === 'number'
|
|
2190
|
+
? fields.upstream_status
|
|
2191
|
+
: null;
|
|
2192
|
+
bodyCategory =
|
|
2193
|
+
typeof fields.error_category === 'string'
|
|
2194
|
+
? fields.error_category
|
|
2195
|
+
: null;
|
|
2196
|
+
bodyNetworkKind =
|
|
2197
|
+
typeof fields.network_kind === 'string' ? fields.network_kind : null;
|
|
2198
|
+
}
|
|
2199
|
+
} catch {
|
|
2200
|
+
bodyCode = null;
|
|
2201
|
+
}
|
|
2202
|
+
const { failure } = input;
|
|
2203
|
+
return classifyDurableRetryErrorClass({
|
|
2204
|
+
status: input.status,
|
|
2205
|
+
reason: failure.reason,
|
|
2206
|
+
knownNotDispatched: failure.knownNotDispatched,
|
|
2207
|
+
origin:
|
|
2208
|
+
failure.error instanceof ToolExecutionError ? failure.error.origin : null,
|
|
2209
|
+
code:
|
|
2210
|
+
failure.error instanceof ToolExecutionError && failure.error.code
|
|
2211
|
+
? failure.error.code
|
|
2212
|
+
: bodyCode,
|
|
2213
|
+
upstreamStatus: bodyUpstreamStatus,
|
|
2214
|
+
category: bodyCategory,
|
|
2215
|
+
networkKind: bodyNetworkKind,
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
/**
|
|
2220
|
+
* Whether a call retries durably. Only a call that sets its own `retry` does
|
|
2221
|
+
* for now; a call without one keeps the behaviour from before durable
|
|
2222
|
+
* retries (in-call retries, then the error reaches the Play).
|
|
2223
|
+
*
|
|
2224
|
+
* Temporary ordering, not a switch: prebuilt Plays typecheck against the SDK
|
|
2225
|
+
* Production runs, which gains `retry` only when this ships, so they cannot
|
|
2226
|
+
* bound their fallback legs yet. PR #10348 removes this predicate together
|
|
2227
|
+
* with the prebuilt `retry` legs, making durable retry every call's
|
|
2228
|
+
* behaviour.
|
|
2229
|
+
*/
|
|
2230
|
+
export function callOptsIntoDurableRetry(
|
|
2231
|
+
retry: PlayToolCallRetryPolicy | undefined,
|
|
2232
|
+
): boolean {
|
|
2233
|
+
return retry !== undefined;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
/**
|
|
2237
|
+
* A call's own `retry` governs its in-call resends too, like an activity
|
|
2238
|
+
* RetryPolicy counts every attempt. A class it lists as `nonRetryable`, or
|
|
2239
|
+
* `maximumAttempts: 1` for a request the provider received, is not resent and
|
|
2240
|
+
* not paced inside the call: the error reaches the Play after this attempt.
|
|
2241
|
+
* Deepline's own pre-dispatch refusals are not attempts and keep pacing.
|
|
2242
|
+
*/
|
|
2243
|
+
export function callRetryStopsInCallRetry(input: {
|
|
2244
|
+
callRetry: PlayToolCallRetryPolicy | undefined;
|
|
2245
|
+
errorClass: DurableRetryErrorClass | null;
|
|
2246
|
+
preDispatchRefusal: boolean;
|
|
2247
|
+
/**
|
|
2248
|
+
* Requests the provider received for this call so far, this one included:
|
|
2249
|
+
* earlier bursts (the requeue record) plus this burst.
|
|
2250
|
+
*/
|
|
2251
|
+
sends: number;
|
|
2252
|
+
}): boolean {
|
|
2253
|
+
const { callRetry, errorClass } = input;
|
|
2254
|
+
if (!callRetry) return false;
|
|
2255
|
+
if (errorClass !== null && callRetry.nonRetryable?.includes(errorClass)) {
|
|
2256
|
+
return true;
|
|
2257
|
+
}
|
|
2258
|
+
// Like an activity retry policy, the limit bounds every attempt, whatever
|
|
2259
|
+
// the failure's class.
|
|
2260
|
+
return (
|
|
2261
|
+
callRetry.maximumAttempts !== undefined &&
|
|
2262
|
+
!input.preDispatchRefusal &&
|
|
2263
|
+
input.sends >= callRetry.maximumAttempts
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2156
2267
|
type ToolExecutionApiOptions = {
|
|
2268
|
+
/**
|
|
2269
|
+
* The call's own retry policy (`ctx.tools.execute({ retry })`). It governs
|
|
2270
|
+
* the in-call resends and the durable retries; a call that sets it never
|
|
2271
|
+
* joins a native provider batch.
|
|
2272
|
+
*/
|
|
2273
|
+
retry?: PlayToolCallRetryPolicy;
|
|
2157
2274
|
/**
|
|
2158
2275
|
* The call's replay-stable identity in the run, for an async provider wait
|
|
2159
2276
|
* that has no other durable identity. A retried attempt sends the same
|
|
@@ -3350,6 +3467,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3350
3467
|
staleAfterSeconds?: number | null;
|
|
3351
3468
|
timeoutMs?: number;
|
|
3352
3469
|
receiptWaitMs?: number;
|
|
3470
|
+
retry?: PlayToolCallRetryPolicy;
|
|
3353
3471
|
}): Promise<TOutput> => {
|
|
3354
3472
|
this.assertNoPendingDurableSuspension();
|
|
3355
3473
|
if (!request || typeof request !== 'object' || Array.isArray(request)) {
|
|
@@ -3388,6 +3506,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3388
3506
|
request.receiptWaitMs,
|
|
3389
3507
|
);
|
|
3390
3508
|
}
|
|
3509
|
+
// The call's own retry policy replaces the class rule where it sets a
|
|
3510
|
+
// field; without it, the live Durable retry policy decides.
|
|
3511
|
+
const retry = request.retry;
|
|
3512
|
+
if (retry !== undefined) validatePlayToolCallRetryPolicy(retry);
|
|
3391
3513
|
const force =
|
|
3392
3514
|
request.force === true ||
|
|
3393
3515
|
toolExecutionOverrides.getStore()?.force === true;
|
|
@@ -3399,7 +3521,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3399
3521
|
force ||
|
|
3400
3522
|
request.staleAfterSeconds !== undefined ||
|
|
3401
3523
|
request.timeoutMs !== undefined ||
|
|
3402
|
-
request.receiptWaitMs !== undefined
|
|
3524
|
+
request.receiptWaitMs !== undefined ||
|
|
3525
|
+
retry !== undefined
|
|
3403
3526
|
? {
|
|
3404
3527
|
...(request.description
|
|
3405
3528
|
? { description: request.description }
|
|
@@ -3414,6 +3537,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3414
3537
|
...(request.receiptWaitMs !== undefined
|
|
3415
3538
|
? { receiptWaitMs: request.receiptWaitMs }
|
|
3416
3539
|
: {}),
|
|
3540
|
+
...(retry !== undefined ? { retry } : {}),
|
|
3417
3541
|
}
|
|
3418
3542
|
: undefined,
|
|
3419
3543
|
).catch((error: unknown) => {
|
|
@@ -12289,6 +12413,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
12289
12413
|
? { heapProbe: this.#options.runtimeMapHeapProbe }
|
|
12290
12414
|
: {}),
|
|
12291
12415
|
getEventLoopLagMs: () => this.resourceGovernor.eventLoopLagEwmaMs(),
|
|
12416
|
+
callSlotBacklog: () =>
|
|
12417
|
+
this.resourceGovernor.externalExecutionBacklog?.() ?? null,
|
|
12292
12418
|
onMemoryPressure: releaseCommittedRowsForMemoryPressure,
|
|
12293
12419
|
// Provider bodies enter through `providerResponseBodyGate` below, which
|
|
12294
12420
|
// reserves them at materialization and holds the measurement through the
|
|
@@ -13932,14 +14058,24 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
13932
14058
|
}
|
|
13933
14059
|
}
|
|
13934
14060
|
|
|
14061
|
+
/**
|
|
14062
|
+
* A call that sets its own `retry` never joins a native provider batch: it
|
|
14063
|
+
* runs as its own request so its retry policy, not the batch's, applies.
|
|
14064
|
+
*/
|
|
14065
|
+
private batchOperationStrategyFor(
|
|
14066
|
+
request: Pick<ToolCallRequest, 'toolId' | 'retry'>,
|
|
14067
|
+
): AnyBatchOperationStrategy | null {
|
|
14068
|
+
if (request.retry !== undefined) return null;
|
|
14069
|
+
return this.#options.getBatchOperationStrategy?.(request.toolId) ?? null;
|
|
14070
|
+
}
|
|
14071
|
+
|
|
13935
14072
|
private toolDispatchLane(request: ToolCallRequest): {
|
|
13936
14073
|
key: string;
|
|
13937
14074
|
readyCount: number;
|
|
13938
14075
|
maxGroupSize: number;
|
|
13939
14076
|
coalesceWindowMs: number;
|
|
13940
14077
|
} {
|
|
13941
|
-
const strategy =
|
|
13942
|
-
this.#options.getBatchOperationStrategy?.(request.toolId) ?? null;
|
|
14078
|
+
const strategy = this.batchOperationStrategyFor(request);
|
|
13943
14079
|
if (strategy) {
|
|
13944
14080
|
return {
|
|
13945
14081
|
key: [
|
|
@@ -14188,8 +14324,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14188
14324
|
this.mappedResolverHostTurn &&
|
|
14189
14325
|
requests.some(
|
|
14190
14326
|
(request) =>
|
|
14191
|
-
(this
|
|
14192
|
-
?.maxBatchSize ?? 1) > 1,
|
|
14327
|
+
(this.batchOperationStrategyFor(request)?.maxBatchSize ?? 1) > 1,
|
|
14193
14328
|
)
|
|
14194
14329
|
) {
|
|
14195
14330
|
return {
|
|
@@ -14427,9 +14562,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14427
14562
|
const admissionObserver: ToolBatchAdmissionObserver = {
|
|
14428
14563
|
pending: (requests) => {
|
|
14429
14564
|
for (const request of requests) {
|
|
14430
|
-
const strategy = this
|
|
14431
|
-
request.toolId,
|
|
14432
|
-
);
|
|
14565
|
+
const strategy = this.batchOperationStrategyFor(request);
|
|
14433
14566
|
// A scalar-only strategy has no arrivals to aggregate. Holding its
|
|
14434
14567
|
// lane would serialize receipt I/O before provider admission.
|
|
14435
14568
|
if (!strategy || strategy.maxBatchSize <= 1) continue;
|
|
@@ -15930,6 +16063,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15930
16063
|
startedAt: directCallStartedAt,
|
|
15931
16064
|
input,
|
|
15932
16065
|
options: {
|
|
16066
|
+
...(options?.retry ? { retry: options.retry } : {}),
|
|
15933
16067
|
...(useDirectResultReceipts
|
|
15934
16068
|
? {
|
|
15935
16069
|
durableCallReceiptKey: physicalDirectKey,
|
|
@@ -16280,6 +16414,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16280
16414
|
...(options?.receiptWaitMs !== undefined
|
|
16281
16415
|
? { receiptWaitMs: options.receiptWaitMs }
|
|
16282
16416
|
: {}),
|
|
16417
|
+
...(options?.retry ? { retry: options.retry } : {}),
|
|
16283
16418
|
tableNamespace: store.tableNamespace,
|
|
16284
16419
|
rowKey: store.rowKey ?? null,
|
|
16285
16420
|
description: normalizeStepDescription(options?.description),
|
|
@@ -17373,6 +17508,238 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17373
17508
|
});
|
|
17374
17509
|
}
|
|
17375
17510
|
|
|
17511
|
+
/**
|
|
17512
|
+
* A call's in-call retries are spent. Park it per the Durable retry policy
|
|
17513
|
+
* snapshot this attempt read (a mapped row waits on its own; a call outside
|
|
17514
|
+
* a map suspends the run on a durable sleep), or return so the caller
|
|
17515
|
+
* throws the original error into the Play. Never returns after a park.
|
|
17516
|
+
*/
|
|
17517
|
+
/** Durable retry policy snapshots whose warnings this attempt already logged. */
|
|
17518
|
+
private readonly loggedDurableRetryPolicyWarnings = new Set<string>();
|
|
17519
|
+
|
|
17520
|
+
private async parkExhaustedCallOrFail(input: {
|
|
17521
|
+
toolId: string;
|
|
17522
|
+
provider: string;
|
|
17523
|
+
callRequeueKey: string;
|
|
17524
|
+
status: number;
|
|
17525
|
+
/**
|
|
17526
|
+
* The failure to classify, or the class it already has (a provider hold
|
|
17527
|
+
* whose no-progress limit is spent is `rate_limit_429`).
|
|
17528
|
+
*/
|
|
17529
|
+
failure:
|
|
17530
|
+
| ToolExecuteHttpFailureOutcome
|
|
17531
|
+
| { errorClass: DurableRetryErrorClass };
|
|
17532
|
+
responseText: string;
|
|
17533
|
+
providerServerErrorReplay: 'idempotent_key' | 'read_safe' | 'never';
|
|
17534
|
+
rowScoped: boolean;
|
|
17535
|
+
/** The call's input, for a per-request write class (generic HTTP). */
|
|
17536
|
+
toolInput: Record<string, unknown>;
|
|
17537
|
+
/** The invocation attempt that just failed. */
|
|
17538
|
+
invocationAttempt: number;
|
|
17539
|
+
/** The call runs under the gateway's durable execution fence. */
|
|
17540
|
+
fenced: boolean;
|
|
17541
|
+
/** The call's own retry policy (`ctx.tools.execute({ retry })`). */
|
|
17542
|
+
callRetry?: PlayToolCallRetryPolicy;
|
|
17543
|
+
/** Requests the provider received in the burst that just failed. */
|
|
17544
|
+
sendsThisBurst: number;
|
|
17545
|
+
writeRecord: (record: CallRequeueRecord | null) => void;
|
|
17546
|
+
}): Promise<void> {
|
|
17547
|
+
const { failure } = input;
|
|
17548
|
+
const prior = this.checkpoint.callRequeueStates?.[input.callRequeueKey];
|
|
17549
|
+
// Every way out without a park ends a resumed call's record, so a later
|
|
17550
|
+
// failure of the same key never inherits stale counts.
|
|
17551
|
+
const exhaustPrior = () => {
|
|
17552
|
+
if (prior?.state === 'in_call') {
|
|
17553
|
+
input.writeRecord(transitionCallRequeue(prior, 'exhaust', Date.now()));
|
|
17554
|
+
}
|
|
17555
|
+
};
|
|
17556
|
+
const errorClass =
|
|
17557
|
+
'errorClass' in failure
|
|
17558
|
+
? failure.errorClass
|
|
17559
|
+
: durableRetryErrorClassForHttpFailure({
|
|
17560
|
+
status: input.status,
|
|
17561
|
+
failure,
|
|
17562
|
+
responseText: input.responseText,
|
|
17563
|
+
});
|
|
17564
|
+
if (!errorClass) {
|
|
17565
|
+
exhaustPrior();
|
|
17566
|
+
return;
|
|
17567
|
+
}
|
|
17568
|
+
// A billing refusal inside a map keeps its run-fatal behaviour: parking
|
|
17569
|
+
// each row would hold one record and one billing retry per row. A billing
|
|
17570
|
+
// hold outside a map parks the run once.
|
|
17571
|
+
if (input.rowScoped && BILLING_ERROR_CLASSES.has(errorClass)) {
|
|
17572
|
+
exhaustPrior();
|
|
17573
|
+
return;
|
|
17574
|
+
}
|
|
17575
|
+
// A fenced call's billing refusal is a recorded non-retryable outcome the
|
|
17576
|
+
// gateway would refuse to follow after the wait: keep it run-fatal.
|
|
17577
|
+
if (input.fenced && BILLING_ERROR_CLASSES.has(errorClass)) {
|
|
17578
|
+
exhaustPrior();
|
|
17579
|
+
return;
|
|
17580
|
+
}
|
|
17581
|
+
let retryContext: NonNullable<
|
|
17582
|
+
Awaited<
|
|
17583
|
+
ReturnType<NonNullable<ContextOptions['getToolDurableRetryContext']>>
|
|
17584
|
+
>
|
|
17585
|
+
>;
|
|
17586
|
+
try {
|
|
17587
|
+
const resolved = await this.#options.getToolDurableRetryContext!(
|
|
17588
|
+
input.toolId,
|
|
17589
|
+
);
|
|
17590
|
+
if (!resolved) {
|
|
17591
|
+
exhaustPrior();
|
|
17592
|
+
return;
|
|
17593
|
+
}
|
|
17594
|
+
retryContext = resolved;
|
|
17595
|
+
} catch (contextError) {
|
|
17596
|
+
this.runtimeLog(
|
|
17597
|
+
`[runtime.call_requeue.unavailable] ${JSON.stringify({
|
|
17598
|
+
tool_id: input.toolId,
|
|
17599
|
+
error_class: errorClass,
|
|
17600
|
+
error:
|
|
17601
|
+
contextError instanceof Error
|
|
17602
|
+
? contextError.message
|
|
17603
|
+
: String(contextError),
|
|
17604
|
+
})}`,
|
|
17605
|
+
{ level: 'error' },
|
|
17606
|
+
);
|
|
17607
|
+
exhaustPrior();
|
|
17608
|
+
return;
|
|
17609
|
+
}
|
|
17610
|
+
const policyLogKey = `${retryContext.policy.source}:${retryContext.policy.sequence}`;
|
|
17611
|
+
if (
|
|
17612
|
+
retryContext.policy.warnings.length > 0 &&
|
|
17613
|
+
!this.loggedDurableRetryPolicyWarnings.has(policyLogKey)
|
|
17614
|
+
) {
|
|
17615
|
+
// Once per attempt per policy snapshot, not per exhausted call.
|
|
17616
|
+
this.loggedDurableRetryPolicyWarnings.add(policyLogKey);
|
|
17617
|
+
this.runtimeLog(
|
|
17618
|
+
`[runtime.call_requeue.policy] ${JSON.stringify({
|
|
17619
|
+
source: retryContext.policy.source,
|
|
17620
|
+
policy_sequence: retryContext.policy.sequence,
|
|
17621
|
+
warnings: retryContext.policy.warnings,
|
|
17622
|
+
})}`,
|
|
17623
|
+
{
|
|
17624
|
+
level:
|
|
17625
|
+
retryContext.policy.source === 'compiled_default'
|
|
17626
|
+
? 'error'
|
|
17627
|
+
: 'warn',
|
|
17628
|
+
},
|
|
17629
|
+
);
|
|
17630
|
+
}
|
|
17631
|
+
const nowMs = Date.now();
|
|
17632
|
+
const decision = decideCallRequeue({
|
|
17633
|
+
record: prior,
|
|
17634
|
+
errorClass,
|
|
17635
|
+
snapshot: retryContext.policy,
|
|
17636
|
+
failedInvocationAttempt: input.invocationAttempt,
|
|
17637
|
+
fenced: input.fenced,
|
|
17638
|
+
effect: retryContext.effect,
|
|
17639
|
+
writeIdempotency:
|
|
17640
|
+
input.toolId === 'generic_http_request'
|
|
17641
|
+
? genericHttpWriteIdempotency(input.toolInput.method)
|
|
17642
|
+
: retryContext.writeIdempotency,
|
|
17643
|
+
idempotencyKeyHonored:
|
|
17644
|
+
input.providerServerErrorReplay === 'idempotent_key',
|
|
17645
|
+
...(input.callRetry ? { callRetry: input.callRetry } : {}),
|
|
17646
|
+
sends: callRequeueSends(prior) + input.sendsThisBurst,
|
|
17647
|
+
nowMs,
|
|
17648
|
+
});
|
|
17649
|
+
if (decision.kind === 'exhaust') {
|
|
17650
|
+
// Only a call this attempt is retrying can end here; a record parked by
|
|
17651
|
+
// a concurrent same-key call is left to that call.
|
|
17652
|
+
exhaustPrior();
|
|
17653
|
+
this.runtimeLog(
|
|
17654
|
+
`[runtime.call_requeue.exhausted] ${JSON.stringify({
|
|
17655
|
+
tool_id: input.toolId,
|
|
17656
|
+
error_class: errorClass,
|
|
17657
|
+
reason: decision.reason,
|
|
17658
|
+
parks: prior?.parks ?? 0,
|
|
17659
|
+
policy_sequence: retryContext.policy.sequence,
|
|
17660
|
+
})}`,
|
|
17661
|
+
{ level: 'warn' },
|
|
17662
|
+
);
|
|
17663
|
+
return;
|
|
17664
|
+
}
|
|
17665
|
+
input.writeRecord(decision.record);
|
|
17666
|
+
const cause = BILLING_ERROR_CLASSES.has(errorClass)
|
|
17667
|
+
? 'waiting for billing'
|
|
17668
|
+
: errorClass === 'rate_limit_429'
|
|
17669
|
+
? `rate limited by ${input.provider}`
|
|
17670
|
+
: `${input.provider} unavailable`;
|
|
17671
|
+
this.runtimeLog(
|
|
17672
|
+
`[runtime.call_requeue.parked] ${cause}, retrying at ${new Date(decision.retryAtMs).toISOString()} ${JSON.stringify(
|
|
17673
|
+
{
|
|
17674
|
+
tool_id: input.toolId,
|
|
17675
|
+
error_class: errorClass,
|
|
17676
|
+
transition: decision.transition,
|
|
17677
|
+
parks: decision.record.parks,
|
|
17678
|
+
consecutive: decision.record.consecutive,
|
|
17679
|
+
wait_ms: decision.waitMs,
|
|
17680
|
+
policy_sequence: retryContext.policy.sequence,
|
|
17681
|
+
policy_source: retryContext.policy.source,
|
|
17682
|
+
},
|
|
17683
|
+
)}`,
|
|
17684
|
+
{ level: 'warn' },
|
|
17685
|
+
);
|
|
17686
|
+
if (input.rowScoped) {
|
|
17687
|
+
throw new PlayRowProviderBackpressureError(
|
|
17688
|
+
input.provider,
|
|
17689
|
+
decision.retryAtMs,
|
|
17690
|
+
false,
|
|
17691
|
+
);
|
|
17692
|
+
}
|
|
17693
|
+
await this.waitForCallRequeue(input.callRequeueKey, decision.retryAtMs);
|
|
17694
|
+
throw new Error(
|
|
17695
|
+
`Call requeue for ${input.toolId} resumed without suspending the run.`,
|
|
17696
|
+
);
|
|
17697
|
+
}
|
|
17698
|
+
|
|
17699
|
+
/** A run-level durable sleep for one parked call; resumes after `retryAtMs`. */
|
|
17700
|
+
private async waitForCallRequeue(
|
|
17701
|
+
callRequeueKey: string,
|
|
17702
|
+
retryAtMs: number,
|
|
17703
|
+
): Promise<void> {
|
|
17704
|
+
this.assertNoPendingDurableSuspension();
|
|
17705
|
+
const prefix = this.durableBoundaryId(
|
|
17706
|
+
`call-requeue-${callRequeueKey.slice(0, 16)}-`,
|
|
17707
|
+
);
|
|
17708
|
+
let completedWaits = 0;
|
|
17709
|
+
for (const [boundaryId, value] of Object.entries(
|
|
17710
|
+
this.checkpoint.resolvedBoundaries ?? {},
|
|
17711
|
+
)) {
|
|
17712
|
+
if (!boundaryId.startsWith(prefix)) continue;
|
|
17713
|
+
const boundary = assertKnownResolvedBoundary(boundaryId, value);
|
|
17714
|
+
if (boundary?.kind === 'sleep' && boundary.completedAt !== undefined) {
|
|
17715
|
+
completedWaits += 1;
|
|
17716
|
+
}
|
|
17717
|
+
}
|
|
17718
|
+
const boundaryId = `${prefix}${completedWaits}`;
|
|
17719
|
+
const existing = assertKnownResolvedBoundary(
|
|
17720
|
+
boundaryId,
|
|
17721
|
+
this.checkpoint.resolvedBoundaries?.[boundaryId],
|
|
17722
|
+
);
|
|
17723
|
+
const delayMs =
|
|
17724
|
+
existing?.kind === 'sleep'
|
|
17725
|
+
? existing.delayMs
|
|
17726
|
+
: Math.max(1_000, Math.ceil(retryAtMs - Date.now()));
|
|
17727
|
+
const wakeAtMs =
|
|
17728
|
+
existing?.kind === 'sleep' && existing.wakeAtMs !== undefined
|
|
17729
|
+
? existing.wakeAtMs
|
|
17730
|
+
: Date.now() + delayMs;
|
|
17731
|
+
this.checkpoint.resolvedBoundaries = {
|
|
17732
|
+
...(this.checkpoint.resolvedBoundaries ?? {}),
|
|
17733
|
+
[boundaryId]: { ...existing, kind: 'sleep', delayMs, wakeAtMs },
|
|
17734
|
+
};
|
|
17735
|
+
await this.suspendForEarliestSleep({
|
|
17736
|
+
kind: 'sleep',
|
|
17737
|
+
boundaryId,
|
|
17738
|
+
delayMs,
|
|
17739
|
+
wakeAtMs,
|
|
17740
|
+
});
|
|
17741
|
+
}
|
|
17742
|
+
|
|
17376
17743
|
private async waitForProviderBackpressure(
|
|
17377
17744
|
provider: string,
|
|
17378
17745
|
retryAtMs: number,
|
|
@@ -19088,6 +19455,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
19088
19455
|
providerOperationKey,
|
|
19089
19456
|
resultReceipts: receipts,
|
|
19090
19457
|
apiOptions: {
|
|
19458
|
+
...(request.retry ? { retry: request.retry } : {}),
|
|
19091
19459
|
playNodeScope: playNodeScopeForToolCallRequest(request),
|
|
19092
19460
|
durableCallReceiptKey: this.toolTransportReceiptKey({
|
|
19093
19461
|
toolId,
|
|
@@ -19814,6 +20182,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
19814
20182
|
const key = JSON.stringify([
|
|
19815
20183
|
req.toolId,
|
|
19816
20184
|
req.executionAuthScopeDigest ?? '',
|
|
20185
|
+
// Calls with their own `retry` dispatch apart from the native batch.
|
|
20186
|
+
req.retry !== undefined,
|
|
19817
20187
|
]);
|
|
19818
20188
|
if (!byTool.has(key)) byTool.set(key, []);
|
|
19819
20189
|
byTool.get(key)!.push(req);
|
|
@@ -19929,8 +20299,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
19929
20299
|
};
|
|
19930
20300
|
// The cohort reads completed results and publishes successful misses.
|
|
19931
20301
|
// Always-fresh calls have no durable member result and stay below.
|
|
19932
|
-
const operationStrategy =
|
|
19933
|
-
this.#options.getBatchOperationStrategy?.(toolId) ?? null;
|
|
20302
|
+
const operationStrategy = this.batchOperationStrategyFor(requests[0]!);
|
|
19934
20303
|
if (this.durableMappedToolResultsBackedByReceipts) {
|
|
19935
20304
|
const cohortRequests = pendingRequests.filter(
|
|
19936
20305
|
(request) =>
|
|
@@ -20240,6 +20609,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
20240
20609
|
resultReceiptKey: request.receiptKey ?? request.cacheKey,
|
|
20241
20610
|
providerOperationKey,
|
|
20242
20611
|
apiOptions: {
|
|
20612
|
+
...(request.retry ? { retry: request.retry } : {}),
|
|
20243
20613
|
playNodeScope: playNodeScopeForToolCallRequest(request),
|
|
20244
20614
|
executionAuthScopeDigest:
|
|
20245
20615
|
request.executionAuthScopeDigest,
|
|
@@ -20896,10 +21266,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
20896
21266
|
const providerAdmissionNoProgressScope = stableDigest(
|
|
20897
21267
|
`admission\u0000${providerNoProgressScope}`,
|
|
20898
21268
|
);
|
|
21269
|
+
// The provider no-progress limit. With durable call retries it is the
|
|
21270
|
+
// Durable retry policy's `rate_limit_429.inCall.noProgressMs` (read below,
|
|
21271
|
+
// once the call's policy context is known); the default is unchanged.
|
|
21272
|
+
let providerNoProgressMaxMs = PROVIDER_NO_PROGRESS_MAX_MS;
|
|
20899
21273
|
const providerNoProgressError = (retryAtMs: number) =>
|
|
20900
21274
|
createToolHttpError(
|
|
20901
21275
|
toolErrorSchemaVersion,
|
|
20902
|
-
`Provider ${provider} made no progress within ${
|
|
21276
|
+
`Provider ${provider} made no progress within ${Math.round(providerNoProgressMaxMs / 60_000)} minutes. Completed work was saved; retry the failed work after the provider recovers.`,
|
|
20903
21277
|
null,
|
|
20904
21278
|
429,
|
|
20905
21279
|
'repairable',
|
|
@@ -20953,6 +21327,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
20953
21327
|
scope: providerNoProgressScope,
|
|
20954
21328
|
retryAtMs: noProgressRetryAtMs,
|
|
20955
21329
|
nowMs: Date.now(),
|
|
21330
|
+
maxMs: providerNoProgressMaxMs,
|
|
20956
21331
|
});
|
|
20957
21332
|
if (!outcome.exhausted) return;
|
|
20958
21333
|
this.runtimeLog(
|
|
@@ -21025,6 +21400,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21025
21400
|
async (span) => {
|
|
21026
21401
|
const httpFailureAttempts =
|
|
21027
21402
|
createToolExecuteHttpFailureAttemptTracker();
|
|
21403
|
+
// Requests the provider received in this burst; a refusal before
|
|
21404
|
+
// dispatch is not one. With the requeue record's count it is what a
|
|
21405
|
+
// call's `retry.maximumAttempts` bounds.
|
|
21406
|
+
let providerSendsThisBurst = 0;
|
|
21028
21407
|
// Snapshot the caller-controlled payload exactly once. The replay
|
|
21029
21408
|
// decision and every physical attempt must refer to the same bytes,
|
|
21030
21409
|
// even if the original object has getters or is later mutated.
|
|
@@ -21311,6 +21690,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21311
21690
|
// lifecycle key; it is not a general retry counter.
|
|
21312
21691
|
let providerRateLimitRetryFromInvocationAttempt: number | null =
|
|
21313
21692
|
savedProviderRetryCursor?.retryFromInvocationAttempt ?? null;
|
|
21693
|
+
// Set when a parked fenced call resumes: its Durable requeue claim.
|
|
21694
|
+
let callRequeueWire: {
|
|
21695
|
+
fromInvocationAttempt: number;
|
|
21696
|
+
parks: number;
|
|
21697
|
+
} | null = null;
|
|
21314
21698
|
const serializedRequestBody = (invocationAttempt: number) =>
|
|
21315
21699
|
JSON.stringify({
|
|
21316
21700
|
payload: shouldResolveAsyncOperationInRuntime
|
|
@@ -21325,6 +21709,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21325
21709
|
providerRateLimitRetryFromInvocationAttempt,
|
|
21326
21710
|
}
|
|
21327
21711
|
: {}),
|
|
21712
|
+
...(callRequeueWire
|
|
21713
|
+
? {
|
|
21714
|
+
requeue_from_invocation_attempt:
|
|
21715
|
+
callRequeueWire.fromInvocationAttempt,
|
|
21716
|
+
requeue_parks: callRequeueWire.parks,
|
|
21717
|
+
}
|
|
21718
|
+
: {}),
|
|
21328
21719
|
// Every call through this execution path acquires a Postgres
|
|
21329
21720
|
// AIMD provider permit before its network dispatch. Keep this
|
|
21330
21721
|
// admission proof distinct from the optional provider fence:
|
|
@@ -21444,6 +21835,162 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21444
21835
|
delete this.checkpoint.providerRetryCursors;
|
|
21445
21836
|
}
|
|
21446
21837
|
};
|
|
21838
|
+
// Durable requeue of a call whose in-call retries were spent. The
|
|
21839
|
+
// state lives in the checkpoint and changes only through
|
|
21840
|
+
// `transitionCallRequeue`; a parked call that runs again is resumed
|
|
21841
|
+
// and retried here, before its first send of this attempt.
|
|
21842
|
+
// A call retries per the live Durable retry policy and its own
|
|
21843
|
+
// `retry`; the policy (`park.enabled` per class) is the live off
|
|
21844
|
+
// switch.
|
|
21845
|
+
const callRequeueKey =
|
|
21846
|
+
callOptsIntoDurableRetry(options?.retry) &&
|
|
21847
|
+
this.#options.durableBoundaries &&
|
|
21848
|
+
// A durable retry must find its own record after a replay, so it
|
|
21849
|
+
// needs a replay-stable receipt key. A per-invocation transport
|
|
21850
|
+
// key (random each attempt) never retries durably.
|
|
21851
|
+
options?.durableCallReceiptKey?.trim() &&
|
|
21852
|
+
durableCallReceiptKey
|
|
21853
|
+
? stableDigest(`call-requeue:${durableCallReceiptKey}`)
|
|
21854
|
+
: null;
|
|
21855
|
+
const durableCallRetryEnabled =
|
|
21856
|
+
callRequeueKey !== null &&
|
|
21857
|
+
!asyncExecutionRecovery &&
|
|
21858
|
+
this.#options.getToolDurableRetryContext !== undefined;
|
|
21859
|
+
if (durableCallRetryEnabled) {
|
|
21860
|
+
// In-call provider pacing gives up after the policy's no-progress
|
|
21861
|
+
// limit for 429s; the default equals PROVIDER_NO_PROGRESS_MAX_MS.
|
|
21862
|
+
try {
|
|
21863
|
+
const retryContext =
|
|
21864
|
+
await this.#options.getToolDurableRetryContext!(toolId);
|
|
21865
|
+
const noProgressMs =
|
|
21866
|
+
retryContext?.policy.policy.classes.rate_limit_429.inCall
|
|
21867
|
+
.noProgressMs;
|
|
21868
|
+
if (typeof noProgressMs === 'number') {
|
|
21869
|
+
providerNoProgressMaxMs = noProgressMs;
|
|
21870
|
+
}
|
|
21871
|
+
} catch (contextError) {
|
|
21872
|
+
this.runtimeLog(
|
|
21873
|
+
`[runtime.call_requeue.unavailable] ${JSON.stringify({
|
|
21874
|
+
tool_id: toolId,
|
|
21875
|
+
error_class: 'rate_limit_429',
|
|
21876
|
+
error:
|
|
21877
|
+
contextError instanceof Error
|
|
21878
|
+
? contextError.message
|
|
21879
|
+
: String(contextError),
|
|
21880
|
+
})}`,
|
|
21881
|
+
{ level: 'error' },
|
|
21882
|
+
);
|
|
21883
|
+
}
|
|
21884
|
+
}
|
|
21885
|
+
/**
|
|
21886
|
+
* A provider hold whose no-progress limit is spent: with durable
|
|
21887
|
+
* call retries the call is retried on a durable timer as
|
|
21888
|
+
* `rate_limit_429` (the next segment starts a fresh in-call
|
|
21889
|
+
* window); otherwise, or once the retries are spent, the
|
|
21890
|
+
* PROVIDER_EXHAUSTED error reaches the Play as before.
|
|
21891
|
+
*/
|
|
21892
|
+
const retryProviderHoldDurablyOrThrow = async (
|
|
21893
|
+
error: unknown,
|
|
21894
|
+
): Promise<never> => {
|
|
21895
|
+
if (
|
|
21896
|
+
durableCallRetryEnabled &&
|
|
21897
|
+
callRequeueKey &&
|
|
21898
|
+
error instanceof ToolExecutionError &&
|
|
21899
|
+
error.code === 'PROVIDER_EXHAUSTED' &&
|
|
21900
|
+
error.origin === 'provider'
|
|
21901
|
+
) {
|
|
21902
|
+
await this.parkExhaustedCallOrFail({
|
|
21903
|
+
toolId,
|
|
21904
|
+
provider,
|
|
21905
|
+
callRequeueKey,
|
|
21906
|
+
status: 429,
|
|
21907
|
+
failure: { errorClass: 'rate_limit_429' },
|
|
21908
|
+
responseText: '',
|
|
21909
|
+
providerServerErrorReplay,
|
|
21910
|
+
toolInput: toolInputSnapshot,
|
|
21911
|
+
invocationAttempt,
|
|
21912
|
+
fenced: usesDurableInvocationFence,
|
|
21913
|
+
rowScoped: Boolean(
|
|
21914
|
+
options?.providerBackpressureMapRows || rowContext.getStore(),
|
|
21915
|
+
),
|
|
21916
|
+
...(options?.retry ? { callRetry: options.retry } : {}),
|
|
21917
|
+
sendsThisBurst: providerSendsThisBurst,
|
|
21918
|
+
writeRecord: writeCallRequeueRecord,
|
|
21919
|
+
});
|
|
21920
|
+
}
|
|
21921
|
+
throw error;
|
|
21922
|
+
};
|
|
21923
|
+
const writeCallRequeueRecord = (record: CallRequeueRecord | null) => {
|
|
21924
|
+
if (!callRequeueKey) return;
|
|
21925
|
+
if (record) {
|
|
21926
|
+
(this.checkpoint.callRequeueStates ??= {})[callRequeueKey] =
|
|
21927
|
+
record;
|
|
21928
|
+
} else if (this.checkpoint.callRequeueStates) {
|
|
21929
|
+
delete this.checkpoint.callRequeueStates[callRequeueKey];
|
|
21930
|
+
}
|
|
21931
|
+
};
|
|
21932
|
+
if (callRequeueKey) {
|
|
21933
|
+
const parked = this.checkpoint.callRequeueStates?.[callRequeueKey];
|
|
21934
|
+
if (
|
|
21935
|
+
parked &&
|
|
21936
|
+
(parked.state === 'parked' ||
|
|
21937
|
+
parked.state === 'waiting_for_billing')
|
|
21938
|
+
) {
|
|
21939
|
+
// A run woken early (by another boundary) keeps waiting for
|
|
21940
|
+
// this call's own deadline; a mapped row's map honors it.
|
|
21941
|
+
if (
|
|
21942
|
+
parked.retryAtMs !== null &&
|
|
21943
|
+
Date.now() < parked.retryAtMs - 1_000 &&
|
|
21944
|
+
!options?.providerBackpressureMapRows &&
|
|
21945
|
+
!rowContext.getStore()
|
|
21946
|
+
) {
|
|
21947
|
+
await this.waitForCallRequeue(callRequeueKey, parked.retryAtMs);
|
|
21948
|
+
}
|
|
21949
|
+
const nowMs = Date.now();
|
|
21950
|
+
// A provider hold retried durably gets a fresh in-call
|
|
21951
|
+
// no-progress window in its new attempt.
|
|
21952
|
+
if (
|
|
21953
|
+
parked.errorClass === 'rate_limit_429' &&
|
|
21954
|
+
this.checkpoint.providerNoProgressStartedAtMsByScope
|
|
21955
|
+
) {
|
|
21956
|
+
delete this.checkpoint.providerNoProgressStartedAtMsByScope[
|
|
21957
|
+
providerNoProgressScope
|
|
21958
|
+
];
|
|
21959
|
+
}
|
|
21960
|
+
const resumed = transitionCallRequeue(parked, 'resume', nowMs);
|
|
21961
|
+
writeCallRequeueRecord(
|
|
21962
|
+
transitionCallRequeue(resumed ?? undefined, 'retry', nowMs),
|
|
21963
|
+
);
|
|
21964
|
+
this.runtimeLog(
|
|
21965
|
+
`[runtime.call_requeue.resumed] ${JSON.stringify({
|
|
21966
|
+
tool_id: toolId,
|
|
21967
|
+
error_class: parked.errorClass,
|
|
21968
|
+
parks: parked.parks,
|
|
21969
|
+
policy_sequence: parked.policySequence,
|
|
21970
|
+
})}`,
|
|
21971
|
+
);
|
|
21972
|
+
}
|
|
21973
|
+
// Any non-terminal record (also an `in_call` one re-executed
|
|
21974
|
+
// after a crash or another suspension) fixes the attempt floor of
|
|
21975
|
+
// the current park segment. A fenced resend claims that segment
|
|
21976
|
+
// so the gateway checks prior outcomes from there; the claim
|
|
21977
|
+
// replaces any saved 429 retry claim, which belongs to an earlier
|
|
21978
|
+
// segment and would no longer name the preceding attempt.
|
|
21979
|
+
const live = this.checkpoint.callRequeueStates?.[callRequeueKey];
|
|
21980
|
+
const segmentFrom = live?.requeueFromInvocationAttempt;
|
|
21981
|
+
if (typeof segmentFrom === 'number') {
|
|
21982
|
+
if (segmentFrom > invocationAttempt) {
|
|
21983
|
+
invocationAttempt = segmentFrom;
|
|
21984
|
+
}
|
|
21985
|
+
if (usesDurableInvocationFence && segmentFrom >= 1) {
|
|
21986
|
+
providerRateLimitRetryFromInvocationAttempt = null;
|
|
21987
|
+
callRequeueWire = {
|
|
21988
|
+
fromInvocationAttempt: segmentFrom,
|
|
21989
|
+
parks: live!.parks,
|
|
21990
|
+
};
|
|
21991
|
+
}
|
|
21992
|
+
}
|
|
21993
|
+
}
|
|
21447
21994
|
const persistProviderRetryCursor = (retryFrom: number) => {
|
|
21448
21995
|
if (!providerRetryCursorKey) return;
|
|
21449
21996
|
const cursor: ProviderRetryCursor = {
|
|
@@ -21726,9 +22273,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21726
22273
|
this.checkpoint.providerNoProgressStartedAtMsByScope,
|
|
21727
22274
|
scope: providerNoProgressScope,
|
|
21728
22275
|
nowMs: Date.now(),
|
|
22276
|
+
maxMs: providerNoProgressMaxMs,
|
|
21729
22277
|
})
|
|
21730
22278
|
) {
|
|
21731
|
-
|
|
22279
|
+
await retryProviderHoldDurablyOrThrow(
|
|
22280
|
+
providerNoProgressError(Date.now()),
|
|
22281
|
+
);
|
|
21732
22282
|
}
|
|
21733
22283
|
physicalAttempt += 1;
|
|
21734
22284
|
providerConcurrencyGrant = null;
|
|
@@ -22607,14 +23157,18 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22607
23157
|
if (error instanceof ProviderExhaustedError) {
|
|
22608
23158
|
const retryAtMs = Date.parse(error.retryAt);
|
|
22609
23159
|
const localRetryAtMs = error.localRetryAtMs ?? retryAtMs;
|
|
22610
|
-
|
|
22611
|
-
|
|
22612
|
-
|
|
22613
|
-
|
|
22614
|
-
|
|
22615
|
-
|
|
22616
|
-
|
|
22617
|
-
|
|
23160
|
+
try {
|
|
23161
|
+
observeProviderWait(
|
|
23162
|
+
Number.isFinite(retryAtMs) ? retryAtMs : Date.now() + 1_000,
|
|
23163
|
+
Number.isFinite(localRetryAtMs)
|
|
23164
|
+
? localRetryAtMs
|
|
23165
|
+
: Number.isFinite(retryAtMs)
|
|
23166
|
+
? retryAtMs
|
|
23167
|
+
: Date.now() + 1_000,
|
|
23168
|
+
);
|
|
23169
|
+
} catch (holdError) {
|
|
23170
|
+
await retryProviderHoldDurablyOrThrow(holdError);
|
|
23171
|
+
}
|
|
22618
23172
|
const waitMs = Number.isFinite(localRetryAtMs)
|
|
22619
23173
|
? Math.max(0, Math.ceil(localRetryAtMs - Date.now()))
|
|
22620
23174
|
: 1_000;
|
|
@@ -22995,6 +23549,33 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22995
23549
|
},
|
|
22996
23550
|
);
|
|
22997
23551
|
}
|
|
23552
|
+
const preDispatchRefusal =
|
|
23553
|
+
failure.reason === 'concurrency_backpressure' ||
|
|
23554
|
+
failure.reason === 'provider_pacing_wait' ||
|
|
23555
|
+
failure.reason === 'runtime_scheduler_capacity' ||
|
|
23556
|
+
failure.reason === 'billing_unavailable_before_dispatch' ||
|
|
23557
|
+
failure.reason === 'gateway_invocation_in_progress';
|
|
23558
|
+
if (!preDispatchRefusal) providerSendsThisBurst += 1;
|
|
23559
|
+
// The call's own `retry` may end this call's in-call retries: a
|
|
23560
|
+
// `nonRetryable` class, or `maximumAttempts` reached by every
|
|
23561
|
+
// request the provider received for the call so far.
|
|
23562
|
+
const stopInCallRetry = callRetryStopsInCallRetry({
|
|
23563
|
+
callRetry: options?.retry,
|
|
23564
|
+
errorClass: options?.retry
|
|
23565
|
+
? durableRetryErrorClassForHttpFailure({
|
|
23566
|
+
status: response.status,
|
|
23567
|
+
failure,
|
|
23568
|
+
responseText: text,
|
|
23569
|
+
})
|
|
23570
|
+
: null,
|
|
23571
|
+
preDispatchRefusal,
|
|
23572
|
+
sends:
|
|
23573
|
+
callRequeueSends(
|
|
23574
|
+
callRequeueKey
|
|
23575
|
+
? this.checkpoint.callRequeueStates?.[callRequeueKey]
|
|
23576
|
+
: undefined,
|
|
23577
|
+
) + providerSendsThisBurst,
|
|
23578
|
+
});
|
|
22998
23579
|
if (failure.reason === 'concurrency_backpressure') {
|
|
22999
23580
|
// Our own relay shed. The classifier keeps it out of provider
|
|
23000
23581
|
// backpressure (origin is not the provider); count it apart
|
|
@@ -23038,15 +23619,21 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23038
23619
|
? null
|
|
23039
23620
|
: Math.max(0, Math.ceil(providerHoldRetryAtMs - Date.now()));
|
|
23040
23621
|
if (
|
|
23041
|
-
|
|
23042
|
-
failure.
|
|
23622
|
+
!stopInCallRetry &&
|
|
23623
|
+
(failure.backpressureDelayMs !== null ||
|
|
23624
|
+
failure.providerPacingWaitMs !== null)
|
|
23043
23625
|
) {
|
|
23044
|
-
|
|
23045
|
-
|
|
23046
|
-
|
|
23626
|
+
try {
|
|
23627
|
+
observeProviderWait(
|
|
23628
|
+
providerHoldRetryAtMs ?? Date.now() + 1_000,
|
|
23629
|
+
);
|
|
23630
|
+
} catch (holdError) {
|
|
23631
|
+
await retryProviderHoldDurablyOrThrow(holdError);
|
|
23632
|
+
}
|
|
23047
23633
|
}
|
|
23048
23634
|
if (
|
|
23049
23635
|
failure.shouldRetry &&
|
|
23636
|
+
!stopInCallRetry &&
|
|
23050
23637
|
this.#options.durableBoundaries &&
|
|
23051
23638
|
remainingProviderWaitMs !== null &&
|
|
23052
23639
|
!canWaitForProviderInSandbox(remainingProviderWaitMs)
|
|
@@ -23095,6 +23682,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23095
23682
|
failure.reason === 'billing_unavailable_before_dispatch';
|
|
23096
23683
|
if (
|
|
23097
23684
|
failure.shouldRetry &&
|
|
23685
|
+
!stopInCallRetry &&
|
|
23098
23686
|
(failure.knownNotDispatched ||
|
|
23099
23687
|
failure.reason === 'gateway_invocation_in_progress' ||
|
|
23100
23688
|
// A provider 5xx is sent again with the same provider
|
|
@@ -23222,6 +23810,34 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23222
23810
|
});
|
|
23223
23811
|
continue;
|
|
23224
23812
|
}
|
|
23813
|
+
// In-call retries are spent. A retryable class parks the call
|
|
23814
|
+
// and requeues it per the Durable retry policy, instead of
|
|
23815
|
+
// throwing into the Play. A fenced call resumes with a requeue
|
|
23816
|
+
// claim the gateway checks per park segment (an older gateway
|
|
23817
|
+
// ignores the claim and refuses the resend, and the row fails as
|
|
23818
|
+
// before). Async recovery keeps
|
|
23819
|
+
// the old behaviour.
|
|
23820
|
+
if (durableCallRetryEnabled && callRequeueKey) {
|
|
23821
|
+
await this.parkExhaustedCallOrFail({
|
|
23822
|
+
toolId,
|
|
23823
|
+
provider,
|
|
23824
|
+
callRequeueKey,
|
|
23825
|
+
status: response.status,
|
|
23826
|
+
failure,
|
|
23827
|
+
responseText: text,
|
|
23828
|
+
providerServerErrorReplay,
|
|
23829
|
+
toolInput: toolInputSnapshot,
|
|
23830
|
+
invocationAttempt,
|
|
23831
|
+
fenced: usesDurableInvocationFence,
|
|
23832
|
+
rowScoped: Boolean(
|
|
23833
|
+
options?.providerBackpressureMapRows ||
|
|
23834
|
+
rowContext.getStore(),
|
|
23835
|
+
),
|
|
23836
|
+
...(options?.retry ? { callRetry: options.retry } : {}),
|
|
23837
|
+
sendsThisBurst: providerSendsThisBurst,
|
|
23838
|
+
writeRecord: writeCallRequeueRecord,
|
|
23839
|
+
});
|
|
23840
|
+
}
|
|
23225
23841
|
// The row failure line is often the only evidence a customer
|
|
23226
23842
|
// or operator sees; carry the identifiers that locate the
|
|
23227
23843
|
// upstream request without the debug transport trace.
|
|
@@ -23244,6 +23860,23 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23244
23860
|
);
|
|
23245
23861
|
}
|
|
23246
23862
|
const parsed = parseToolExecuteResponse(toolId, responseData);
|
|
23863
|
+
if (callRequeueKey) {
|
|
23864
|
+
const requeued =
|
|
23865
|
+
this.checkpoint.callRequeueStates?.[callRequeueKey];
|
|
23866
|
+
if (requeued) {
|
|
23867
|
+
writeCallRequeueRecord(
|
|
23868
|
+
transitionCallRequeue(requeued, 'succeed', Date.now()),
|
|
23869
|
+
);
|
|
23870
|
+
this.runtimeLog(
|
|
23871
|
+
`[runtime.call_requeue.succeeded] ${JSON.stringify({
|
|
23872
|
+
tool_id: toolId,
|
|
23873
|
+
error_class: requeued.errorClass,
|
|
23874
|
+
parks: requeued.parks,
|
|
23875
|
+
policy_sequence: requeued.policySequence,
|
|
23876
|
+
})}`,
|
|
23877
|
+
);
|
|
23878
|
+
}
|
|
23879
|
+
}
|
|
23247
23880
|
const resolved = shouldResolveAsyncOperationInRuntime
|
|
23248
23881
|
? await this.resolveAsyncOperationInRuntime({
|
|
23249
23882
|
toolId,
|