deepline 0.3.502 → 0.3.504
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 +26 -0
- package/dist/bundling-sources/sdk/src/index.ts +1 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/types.ts +9 -0
- package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +35 -0
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-public-aliases.ts +13 -0
- package/dist/bundling-sources/shared_libs/monitors/starter-templates.ts +0 -8
- package/dist/bundling-sources/shared_libs/observability/dlq.ts +174 -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/observability/scheduled-jobs.json +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +20 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +62 -2
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +667 -62
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +55 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +20 -2
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +46 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execution-gateway-invocation-fence.ts +80 -4
- package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +95 -0
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +292 -45
- package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-http-request.ts +7 -3
- package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-semantics.ts +31 -1
- package/dist/bundling-sources/shared_libs/play-runtime/post-code-recovery-policy.ts +231 -0
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-ending-event.ts +55 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +126 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +38 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +2 -9
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +51 -19
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/local-process.ts +9 -4
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +12 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +42 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +26 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +13 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +53 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +631 -19
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-inventory.ts +719 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +206 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/latest-cache-result.ts +83 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +1432 -157
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +61 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +29 -8
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-queue-health.ts +27 -2
- package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +45 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +129 -14
- package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +2 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +10 -1
- package/dist/cli/{auth-EFHLOVG4.mjs → auth-3L5AA5AX.mjs} +5 -5
- package/dist/cli/auth-UPK4IIIN.js +43 -0
- package/dist/cli/{billing-Q5XKEYPP.mjs → billing-E7EASVPO.mjs} +19 -12
- package/dist/cli/{billing-SKT2VE34.js → billing-HOGXVE2V.js} +92 -85
- package/dist/cli/{chunk-L5CTJY74.mjs → chunk-22OCKCYS.mjs} +2 -2
- package/dist/cli/{chunk-YWOQYYYS.mjs → chunk-2ABRDH3B.mjs} +2 -2
- package/dist/cli/{chunk-IL666WJE.js → chunk-2W77YCKH.js} +5 -5
- package/dist/cli/{chunk-2MVIS2UI.mjs → chunk-3MLFFWDM.mjs} +2 -2
- package/dist/cli/{chunk-HMZF2CSP.mjs → chunk-4CC67XH5.mjs} +2 -2
- package/dist/cli/{chunk-NXVYLX3F.mjs → chunk-5CHBIJIM.mjs} +10 -6
- package/dist/cli/chunk-5LUF4LAR.mjs +209 -0
- package/dist/cli/{chunk-JL6H4H3G.js → chunk-5Z6EULD5.js} +6 -6
- package/dist/cli/{chunk-32YQBJON.js → chunk-67OI26OE.js} +7 -7
- package/dist/cli/{chunk-LA3UYRVZ.js → chunk-6JNBMTCZ.js} +1 -1
- package/dist/cli/{chunk-DYHTXGLX.js → chunk-6SMR7LU7.js} +2 -2
- package/dist/cli/{chunk-OFBLT2LQ.mjs → chunk-7F4OEHQK.mjs} +1 -1
- package/dist/cli/{chunk-DRBD4IYQ.mjs → chunk-7MJYZ33I.mjs} +2 -6
- package/dist/cli/{chunk-UOANF3DR.js → chunk-7P2QVMBP.js} +26 -7
- package/dist/cli/{chunk-GINKIZ7S.js → chunk-A6LA42JY.js} +16 -16
- package/dist/cli/{chunk-FVM4PS5Q.js → chunk-BN5VKY4X.js} +25 -12
- package/dist/cli/{chunk-Z2H7OQ6E.mjs → chunk-BTWUNKKX.mjs} +2 -2
- package/dist/cli/{chunk-R5F7JXT4.mjs → chunk-BX45XMXZ.mjs} +2 -2
- package/dist/cli/{chunk-NKLM4J4X.mjs → chunk-DEAJVQEG.mjs} +1 -1
- package/dist/cli/{chunk-JFBJLNBI.js → chunk-FISP4LCK.js} +53 -53
- package/dist/cli/{chunk-OEUMXKR5.js → chunk-FTRVCIGC.js} +26 -26
- package/dist/cli/{chunk-YL2CCF6T.mjs → chunk-GGBXNQCR.mjs} +4 -4
- package/dist/cli/{chunk-YPTZJ7LO.js → chunk-GJ2DA35C.js} +100 -17
- package/dist/cli/{chunk-2S2F6YSI.js → chunk-GRAGUYIE.js} +41 -41
- package/dist/cli/{chunk-2JS3H6H6.mjs → chunk-HUX5DZO6.mjs} +3 -3
- package/dist/cli/{chunk-4CCMD7QM.mjs → chunk-IGNQKOWT.mjs} +32 -15
- package/dist/cli/{chunk-WKFAX2K7.js → chunk-IPAMOMGP.js} +21 -21
- package/dist/cli/{chunk-SAW3FBCA.mjs → chunk-ITJ7NB2D.mjs} +6 -0
- package/dist/cli/{chunk-Q3NM6ZL3.js → chunk-JPR2546F.js} +23 -21
- package/dist/cli/{chunk-X5MGQ7UT.js → chunk-KCKAFTPY.js} +10 -10
- package/dist/cli/{chunk-TAK3MVXY.js → chunk-KGUGNEKL.js} +284 -267
- package/dist/cli/{chunk-OVZOMSH2.js → chunk-LHXYCZYO.js} +8 -8
- package/dist/cli/{chunk-QOJBRCAS.js → chunk-MJTK6Q3G.js} +3 -3
- package/dist/cli/{chunk-MYUISF3P.mjs → chunk-MLMWM5DV.mjs} +5 -5
- package/dist/cli/{chunk-JO5FFSR7.js → chunk-NTLBZUHD.js} +6 -0
- package/dist/cli/{chunk-MP5QY4A2.mjs → chunk-NZ7Z7WNM.mjs} +2 -2
- package/dist/cli/{chunk-HIVRCTDR.mjs → chunk-OX2D6BG4.mjs} +20 -1
- package/dist/cli/{chunk-YDXEXVBV.js → chunk-QKKU2FH4.js} +7 -7
- package/dist/cli/{chunk-3KEZVGGV.mjs → chunk-QOLX2O2S.mjs} +4 -4
- package/dist/cli/{chunk-JFUXUSKB.mjs → chunk-R2VZVHJP.mjs} +15 -2
- package/dist/cli/chunk-R7J7CJPZ.js +209 -0
- package/dist/cli/{chunk-XMKUJ44Z.js → chunk-SMSQVRHE.js} +5 -5
- package/dist/cli/{chunk-54QXWK3C.mjs → chunk-SVFTZTCI.mjs} +1 -1
- package/dist/cli/{chunk-FWDAEWCD.js → chunk-TMQUMILM.js} +19 -23
- package/dist/cli/{chunk-TFFJ2PRN.mjs → chunk-UFYJTRSF.mjs} +98 -15
- package/dist/cli/{chunk-EUWRKWT4.js → chunk-UJMBG5JU.js} +5 -4
- package/dist/cli/{chunk-DKAMCJIT.js → chunk-USTJEEND.js} +17 -13
- package/dist/cli/{chunk-AJL2Q6IQ.js → chunk-UXQQPMYO.js} +2 -2
- package/dist/cli/{chunk-7ZYSXSJJ.mjs → chunk-VJVJWZ6I.mjs} +5 -5
- package/dist/cli/{chunk-JLYDLK6X.js → chunk-WBIDPDKJ.js} +3 -3
- package/dist/cli/{chunk-QNELA7SX.js → chunk-WZSFIJMG.js} +53 -53
- package/dist/cli/{chunk-NZXB27TP.mjs → chunk-XHZSPMNC.mjs} +4 -4
- package/dist/cli/{chunk-W5CHE5Q2.mjs → chunk-Y6XKCEPK.mjs} +1 -1
- package/dist/cli/{chunk-4WTC5SSN.mjs → chunk-Y7VEHKID.mjs} +10 -8
- package/dist/cli/{chunk-3MJSWVQ2.mjs → chunk-YOQ2NNDO.mjs} +2 -1
- package/dist/cli/{chunk-ZNB6GR3P.mjs → chunk-Z6FXUDIL.mjs} +1 -1
- package/dist/cli/command-docs.d.mts +2 -1
- package/dist/cli/command-docs.d.ts +2 -1
- package/dist/cli/command-docs.js +6 -2
- package/dist/cli/command-docs.mjs +5 -1
- package/dist/cli/{csv-OXGSCV75.js → csv-2XWGPITO.js} +13 -13
- package/dist/cli/{csv-6AEPKKCO.mjs → csv-433JEHLQ.mjs} +4 -4
- package/dist/cli/{db-K3KRK4CZ.mjs → db-K747DH43.mjs} +6 -6
- package/dist/cli/{db-6NVHDUZY.js → db-PJJMD4VH.js} +27 -27
- package/dist/cli/describe-OYS7LZJD.js +49 -0
- package/dist/cli/{describe-P3ZJS7TQ.mjs → describe-VEDDYW4P.mjs} +20 -20
- package/dist/cli/describe-core.d.mts +8 -4
- package/dist/cli/describe-core.d.ts +8 -4
- package/dist/cli/describe-core.js +4 -4
- package/dist/cli/describe-core.mjs +3 -3
- package/dist/cli/{executions-2C2FFG52.js → executions-HM5T72H6.js} +8 -8
- package/dist/cli/{executions-I7XW6WWK.mjs → executions-JWRX3XCT.mjs} +6 -6
- package/dist/cli/{feedback-47B57A5Y.js → feedback-34UG4BO3.js} +8 -8
- package/dist/cli/{feedback-RSTNBJAI.mjs → feedback-MNSIA63Y.mjs} +4 -4
- package/dist/cli/git-5YQJSJFR.js +25 -0
- package/dist/cli/{git-3G5AFKBT.mjs → git-ZKEOXV3A.mjs} +5 -5
- package/dist/cli/index.js +144 -142
- package/dist/cli/index.mjs +44 -42
- package/dist/cli/{legacy-noops-NQ262TKL.mjs → legacy-noops-5M4T4ZVT.mjs} +5 -5
- package/dist/cli/{legacy-noops-P665PBG4.js → legacy-noops-YXSI4FVU.js} +8 -8
- package/dist/cli/{monitors-KUPZODZS.mjs → monitors-C65OC4AW.mjs} +7 -7
- package/dist/cli/{monitors-IPWAD7LS.js → monitors-O25GDOYE.js} +95 -95
- package/dist/cli/{org-WFC3N672.js → org-2GSPLY2A.js} +72 -72
- package/dist/cli/{org-ZCQGEM3L.mjs → org-ZRMG5NS2.mjs} +6 -6
- package/dist/cli/{pages-N5BNC67L.js → pages-45DPADK6.js} +18 -18
- package/dist/cli/{pages-VE66IU7B.mjs → pages-TZZUFBRO.mjs} +6 -6
- package/dist/cli/{play-EIMDIAJB.mjs → play-3D7HH273.mjs} +138 -226
- package/dist/cli/{play-NKIRJSKX.js → play-RCGMND6X.js} +454 -542
- package/dist/cli/{providers-XU3AGY2F.js → providers-3N3ECMTY.js} +9 -9
- package/dist/cli/{providers-KDTJ63ED.mjs → providers-PSAKV6CJ.mjs} +6 -6
- package/dist/cli/{quickstart-TXFXUODF.mjs → quickstart-2A35SMGC.mjs} +4 -4
- package/dist/cli/{quickstart-OSCHOSXU.js → quickstart-6R6AIXM6.js} +6 -6
- package/dist/cli/{run-ODGML35U.mjs → run-F3TLDGUO.mjs} +25 -25
- package/dist/cli/{run-ET2KVTPK.js → run-F6ZXTASZ.js} +44 -44
- package/dist/cli/{search-DK67K6PR.mjs → search-CZLCY3D2.mjs} +7 -7
- package/dist/cli/search-R5VEWJO2.js +32 -0
- package/dist/cli/{search-output-6SOKQTCW.mjs → search-output-MQTSTLN5.mjs} +5 -5
- package/dist/cli/{search-output-KXP4FA62.js → search-output-R5XDNILW.js} +7 -7
- package/dist/cli/{secrets-C6SYTMU7.mjs → secrets-D3GF4B2Z.mjs} +6 -6
- package/dist/cli/{secrets-WPS6NMNK.js → secrets-DCJYHDSY.js} +15 -15
- package/dist/cli/{sessions-PXVOH34X.mjs → sessions-QGEQ2UYZ.mjs} +5 -5
- package/dist/cli/{sessions-IP562J5Z.js → sessions-Z4JYJSDP.js} +6 -6
- package/dist/cli/{settings-FBUQGYVJ.mjs → settings-G7QEXA4N.mjs} +11 -11
- package/dist/cli/{settings-SUDUIVMY.js → settings-UVXXAT4A.js} +78 -78
- package/dist/cli/{setup-I5H6IOEY.js → setup-5I42W7D4.js} +49 -49
- package/dist/cli/{setup-JSIMTR73.mjs → setup-QHJU3DUI.mjs} +9 -9
- package/dist/cli/{skills-FJQ3LX6N.mjs → skills-5LRF4UKX.mjs} +7 -7
- package/dist/cli/skills-FB6TV52O.js +36 -0
- package/dist/cli/tools-L2364RPA.js +56 -0
- package/dist/cli/{tools-IGBK4BVE.mjs → tools-PUT6STVG.mjs} +18 -18
- package/dist/cli/{update-7MTT6F5K.mjs → update-CJ2GA64X.mjs} +9 -9
- package/dist/cli/update-ESYJGYVZ.js +34 -0
- package/dist/cli/{workflow-PM2J2OU3.mjs → workflow-HVEWRTXD.mjs} +7 -7
- package/dist/cli/{workflow-UX3ZX6BQ.js → workflow-O67MEBCP.js} +17 -17
- package/dist/{client-Bn8FwKGO.d.ts → client-CIwenMFS.d.ts} +1 -1
- package/dist/{client-CfNRmjLK.d.mts → client-DYAfJpaN.d.mts} +1 -1
- package/dist/{client-core-B91EV0WS.d.ts → client-core-CRjtyMAI.d.ts} +25 -2
- package/dist/{client-core-BG8Cgrmk.d.mts → client-core-DlzP8vEs.d.mts} +25 -2
- package/dist/{compiler-manifest-DlXDyndN.d.mts → compiler-manifest-DaJrA2KV.d.mts} +1 -1
- package/dist/{compiler-manifest-DlXDyndN.d.ts → compiler-manifest-DaJrA2KV.d.ts} +1 -1
- package/dist/{errors-BtriA2ld.d.mts → errors-BKnSYueU.d.mts} +1 -1
- package/dist/{errors-DmcLykM7.d.ts → errors-KLga4bLr.d.ts} +1 -1
- package/dist/{index-DI0sR_fX.d.mts → index-C-8AFpWy.d.mts} +1 -1
- package/dist/{index--Jw-slHY.d.ts → index-C5nAZ-VS.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 +125 -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 +12 -5
- 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-VM3IKP5F.js +0 -43
- package/dist/cli/describe-JOUAXXPE.js +0 -49
- package/dist/cli/git-OPKIC6JQ.js +0 -25
- package/dist/cli/search-6U54Y3OK.js +0 -32
- package/dist/cli/skills-VHININXC.js +0 -36
- package/dist/cli/tools-XMBMHVKF.js +0 -56
- package/dist/cli/update-H7JVW43I.js +0 -34
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DURABLE_RUNS_ROLLOUT } from './durable-runs-rollout';
|
|
1
2
|
import { RuntimeSheetAdmissionRequestTooLargeError } from './runtime-sheet-errors';
|
|
2
3
|
import {
|
|
3
4
|
DatasetRowInputView,
|
|
@@ -286,7 +287,14 @@ import {
|
|
|
286
287
|
resolveDurableCallCachePolicy,
|
|
287
288
|
} from './durable-call-cache';
|
|
288
289
|
import { resolveExplicitDurableCallPolicy } from './durable-call-policy';
|
|
289
|
-
import {
|
|
290
|
+
import {
|
|
291
|
+
completedCallForResult,
|
|
292
|
+
executeWithFreshnessReceipt,
|
|
293
|
+
latestCacheResultKey,
|
|
294
|
+
latestCacheResultOutput,
|
|
295
|
+
parseLatestCacheResult,
|
|
296
|
+
toolReadSemanticKey,
|
|
297
|
+
} from './freshness-receipt-execution';
|
|
290
298
|
import {
|
|
291
299
|
CtxFetchHttpError,
|
|
292
300
|
LEGACY_PLAY_AUTHORING_CONTRACT_EDITION,
|
|
@@ -351,8 +359,15 @@ import {
|
|
|
351
359
|
isQueryResultDatasetReadRequest,
|
|
352
360
|
isQueryResultDatasetTool,
|
|
353
361
|
} from './query-result-dataset';
|
|
354
|
-
import {
|
|
362
|
+
import {
|
|
363
|
+
isAlwaysFreshIntegrationTool,
|
|
364
|
+
isAlwaysFreshIntegrationWriteTool,
|
|
365
|
+
} from './tool-cache-policy';
|
|
355
366
|
import { isRowIsolationExemptError } from './row-isolation';
|
|
367
|
+
import {
|
|
368
|
+
replayTrackedMarkerReceiptKey,
|
|
369
|
+
replayUnsafeMarkerReceiptKey,
|
|
370
|
+
} from './post-code-recovery-policy';
|
|
356
371
|
import {
|
|
357
372
|
createRuntimePersistenceLatch,
|
|
358
373
|
onRuntimePersistenceLatchTripped,
|
|
@@ -478,6 +493,7 @@ import type {
|
|
|
478
493
|
CsvOptions,
|
|
479
494
|
RowState,
|
|
480
495
|
RuntimeDatasetOptions,
|
|
496
|
+
LegacyLatestCacheAccess,
|
|
481
497
|
ToolCallRequest,
|
|
482
498
|
ToolBatchResult,
|
|
483
499
|
ContextOptions,
|
|
@@ -1971,6 +1987,12 @@ function settleToolBatchGroups(
|
|
|
1971
1987
|
}
|
|
1972
1988
|
|
|
1973
1989
|
type ToolExecutionApiOptions = {
|
|
1990
|
+
/**
|
|
1991
|
+
* The call's replay-stable identity in the run, for an async provider wait
|
|
1992
|
+
* that has no other durable identity. A retried attempt sends the same
|
|
1993
|
+
* recovery key, so the provider job is started once.
|
|
1994
|
+
*/
|
|
1995
|
+
asyncRecoveryCallIdentity?: string;
|
|
1974
1996
|
/** Runner-local scheduling signals; never part of a provider/wire payload. */
|
|
1975
1997
|
onProviderAdmissionPending?: () => void;
|
|
1976
1998
|
onProviderDispatched?: () => void;
|
|
@@ -4038,10 +4060,48 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4038
4060
|
);
|
|
4039
4061
|
}
|
|
4040
4062
|
|
|
4041
|
-
|
|
4063
|
+
/**
|
|
4064
|
+
* Digest of what a durable call asked for, used only by request-digest call
|
|
4065
|
+
* slots. Callers pass the authored request without credentials, auth scope,
|
|
4066
|
+
* or runtime-assigned keys, so the slot follows the authored effect.
|
|
4067
|
+
*/
|
|
4068
|
+
private callSlotRequestDigest(request: unknown): string | undefined {
|
|
4069
|
+
if (this.currentRuntimeSemantics.callSlotIdentity !== 'request_digest') {
|
|
4070
|
+
return undefined;
|
|
4071
|
+
}
|
|
4072
|
+
return sha256Hex(stableStringify(request));
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
/** Method, URL, and body; headers and secret auth stay out of the slot. */
|
|
4076
|
+
private fetchCallSlotRequestDigest(
|
|
4077
|
+
input: string | URL,
|
|
4078
|
+
init: PlaySecretAwareRequestInit | SecretAwareRequestInit,
|
|
4079
|
+
): string | undefined {
|
|
4080
|
+
if (this.currentRuntimeSemantics.callSlotIdentity !== 'request_digest') {
|
|
4081
|
+
return undefined;
|
|
4082
|
+
}
|
|
4083
|
+
const body = typeof init.body === 'string' ? init.body : null;
|
|
4084
|
+
return this.callSlotRequestDigest({
|
|
4085
|
+
method: (init.method ?? 'GET').toUpperCase(),
|
|
4086
|
+
url: input.toString(),
|
|
4087
|
+
body:
|
|
4088
|
+
body !== null &&
|
|
4089
|
+
this.secretRedactor.containsRegisteredSecret(body, {
|
|
4090
|
+
includeEncoded: true,
|
|
4091
|
+
})
|
|
4092
|
+
? this.secretRedactor.redactRegisteredSecrets(body)
|
|
4093
|
+
: body,
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
private freshnessInvocationId(
|
|
4098
|
+
operation: string,
|
|
4099
|
+
id: string,
|
|
4100
|
+
requestDigest?: string,
|
|
4101
|
+
): string {
|
|
4042
4102
|
const row = rowContext.getStore();
|
|
4043
4103
|
const step = authoredStepContext.getStore();
|
|
4044
|
-
const
|
|
4104
|
+
const slotScope = {
|
|
4045
4105
|
namespace: this.currentExecutionScope.receipt.namespace,
|
|
4046
4106
|
operation,
|
|
4047
4107
|
id,
|
|
@@ -4053,7 +4113,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4053
4113
|
field: row.fieldName ?? null,
|
|
4054
4114
|
}
|
|
4055
4115
|
: null,
|
|
4056
|
-
}
|
|
4116
|
+
};
|
|
4117
|
+
// Edition 12 numbers same-id calls only among identical requests, so
|
|
4118
|
+
// parallel calls started in another order on resume keep their own slot.
|
|
4119
|
+
// Call-order artifacts keep their exact historical scope string.
|
|
4120
|
+
const scope = stableStringify(
|
|
4121
|
+
this.currentRuntimeSemantics.callSlotIdentity === 'request_digest'
|
|
4122
|
+
? { ...slotScope, request: requestDigest ?? null }
|
|
4123
|
+
: slotScope,
|
|
4124
|
+
);
|
|
4057
4125
|
const freshIndex = this.freshnessCallIndexByKey.get(scope) ?? 0;
|
|
4058
4126
|
this.freshnessCallIndexByKey.set(scope, freshIndex + 1);
|
|
4059
4127
|
// Invocation identity follows authored scope and call order. Keep it
|
|
@@ -4074,6 +4142,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4074
4142
|
policy: { requested: number | null; effective: number | null };
|
|
4075
4143
|
execute: () => Promise<T>;
|
|
4076
4144
|
completedAt?: (value: T) => number | undefined;
|
|
4145
|
+
sharesResult?: (value: T) => boolean;
|
|
4146
|
+
publishLatestOnRefresh?: true;
|
|
4077
4147
|
onOutcome?: (value: T, metadata: CallFreshnessMetadata) => T;
|
|
4078
4148
|
}): Promise<T> {
|
|
4079
4149
|
const orgId = this.#options.orgId?.trim();
|
|
@@ -4086,20 +4156,22 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4086
4156
|
orgId,
|
|
4087
4157
|
semanticKey: input.semanticKey,
|
|
4088
4158
|
invocationId: input.invocationId,
|
|
4089
|
-
runId: this.
|
|
4159
|
+
runId: this.historyRunId,
|
|
4090
4160
|
requestedStaleAfterSeconds: input.policy.requested,
|
|
4091
4161
|
effectiveStaleAfterSeconds: input.policy.effective,
|
|
4092
4162
|
store: this.durableReceiptExecutionStore(),
|
|
4093
4163
|
completedAt: input.completedAt,
|
|
4094
|
-
|
|
4164
|
+
sharesResult: input.sharesResult,
|
|
4165
|
+
...(input.publishLatestOnRefresh
|
|
4166
|
+
? { publishLatestOnRefresh: true as const }
|
|
4167
|
+
: {}),
|
|
4168
|
+
withHydration: (read, options) =>
|
|
4095
4169
|
this.withRuntimeReceiptHydrationTurn(
|
|
4096
4170
|
(turn) =>
|
|
4097
|
-
read((
|
|
4098
|
-
turn.settleBytes(
|
|
4099
|
-
runtimeStepReceiptPayloadBytes(receipt ? [receipt] : []),
|
|
4100
|
-
),
|
|
4171
|
+
read((receipts) =>
|
|
4172
|
+
turn.settleBytes(runtimeStepReceiptPayloadBytes(receipts)),
|
|
4101
4173
|
),
|
|
4102
|
-
{ source: 'durable_operation' },
|
|
4174
|
+
{ ...options, source: 'durable_operation' },
|
|
4103
4175
|
),
|
|
4104
4176
|
execute: async () => {
|
|
4105
4177
|
const value = await input.execute();
|
|
@@ -6501,6 +6573,177 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6501
6573
|
});
|
|
6502
6574
|
}
|
|
6503
6575
|
|
|
6576
|
+
/**
|
|
6577
|
+
* Older editions cache tool results play-locally, so Plays with different
|
|
6578
|
+
* policies never shared. They also read and publish the request's newest
|
|
6579
|
+
* shared result, keyed exactly as edition-11 reads key it, under the same
|
|
6580
|
+
* eligibility: a declared reusable read that is not an event wait, live
|
|
6581
|
+
* dataset, SQL, invocation-scoped or fenced action, or always-fresh tool.
|
|
6582
|
+
* An authored 0 or `force` never shares; an operator refresh publishes but
|
|
6583
|
+
* reads nothing.
|
|
6584
|
+
*/
|
|
6585
|
+
private async legacyLatestCacheAccess(input: {
|
|
6586
|
+
toolId: string;
|
|
6587
|
+
requestInput: Record<string, unknown>;
|
|
6588
|
+
options?: ToolCallOptions;
|
|
6589
|
+
staleAfterSeconds?: number | null;
|
|
6590
|
+
cacheable: boolean;
|
|
6591
|
+
invocationScoped: boolean;
|
|
6592
|
+
executionAuthScopeDigest: string | null;
|
|
6593
|
+
providerActionVersion: string;
|
|
6594
|
+
}): Promise<LegacyLatestCacheAccess | null> {
|
|
6595
|
+
const orgId = this.#options.orgId?.trim();
|
|
6596
|
+
if (
|
|
6597
|
+
this.usesExplicitFreshness ||
|
|
6598
|
+
!orgId ||
|
|
6599
|
+
!input.cacheable ||
|
|
6600
|
+
input.invocationScoped ||
|
|
6601
|
+
!input.providerActionVersion ||
|
|
6602
|
+
isCustomerDbDatasetTool(input.toolId) ||
|
|
6603
|
+
input.options?.force === true ||
|
|
6604
|
+
input.options?.staleAfterSeconds === 0
|
|
6605
|
+
) {
|
|
6606
|
+
return null;
|
|
6607
|
+
}
|
|
6608
|
+
const read = !(
|
|
6609
|
+
this.#options.cachePolicy?.forceToolRefresh === true ||
|
|
6610
|
+
toolExecutionOverrides.getStore()?.force === true
|
|
6611
|
+
);
|
|
6612
|
+
const publish =
|
|
6613
|
+
DURABLE_RUNS_ROLLOUT.sharedReadCacheWrites &&
|
|
6614
|
+
Boolean(this.#options.publishLatestCacheResult);
|
|
6615
|
+
if (!read && !publish) return null;
|
|
6616
|
+
// Missing metadata means no declared reuse: the call keeps its
|
|
6617
|
+
// play-local behaviour instead of failing.
|
|
6618
|
+
const [retryPolicy, reusableSupport] = await Promise.all([
|
|
6619
|
+
Promise.resolve()
|
|
6620
|
+
.then(() =>
|
|
6621
|
+
this.#options.getToolRetryPolicy?.(input.toolId, input.requestInput),
|
|
6622
|
+
)
|
|
6623
|
+
.catch(() => null),
|
|
6624
|
+
Promise.resolve()
|
|
6625
|
+
.then(() => this.#options.getToolReusableResultSupport?.(input.toolId))
|
|
6626
|
+
.catch(() => null),
|
|
6627
|
+
]);
|
|
6628
|
+
if (
|
|
6629
|
+
retryPolicy?.requiresExecutionFence === true ||
|
|
6630
|
+
reusableSupport?.supported !== true
|
|
6631
|
+
) {
|
|
6632
|
+
return null;
|
|
6633
|
+
}
|
|
6634
|
+
const staleAfterSeconds = input.staleAfterSeconds ?? null;
|
|
6635
|
+
return {
|
|
6636
|
+
key: latestCacheResultKey(
|
|
6637
|
+
orgId,
|
|
6638
|
+
toolReadSemanticKey({
|
|
6639
|
+
orgId: this.#options.orgId,
|
|
6640
|
+
toolId: input.toolId,
|
|
6641
|
+
input: input.requestInput,
|
|
6642
|
+
authScope: input.executionAuthScopeDigest,
|
|
6643
|
+
actionVersion: input.providerActionVersion,
|
|
6644
|
+
}),
|
|
6645
|
+
),
|
|
6646
|
+
maxAgeMs: staleAfterSeconds === null ? null : staleAfterSeconds * 1000,
|
|
6647
|
+
read,
|
|
6648
|
+
publish,
|
|
6649
|
+
};
|
|
6650
|
+
}
|
|
6651
|
+
|
|
6652
|
+
/**
|
|
6653
|
+
* The shared entry when it is young enough for this call. A malformed or
|
|
6654
|
+
* unknown entry is a miss: an older edition never fails on the new cache.
|
|
6655
|
+
*/
|
|
6656
|
+
private freshLegacyLatestCacheEntry(
|
|
6657
|
+
access: LegacyLatestCacheAccess,
|
|
6658
|
+
receipt: RuntimeStepReceipt | null | undefined,
|
|
6659
|
+
nowMs: number,
|
|
6660
|
+
): ReturnType<typeof parseLatestCacheResult> {
|
|
6661
|
+
let entry: ReturnType<typeof parseLatestCacheResult>;
|
|
6662
|
+
try {
|
|
6663
|
+
entry = parseLatestCacheResult(receipt ?? null);
|
|
6664
|
+
} catch {
|
|
6665
|
+
return null;
|
|
6666
|
+
}
|
|
6667
|
+
if (!entry || entry.undefinedValue) return null;
|
|
6668
|
+
const age = nowMs - entry.completedAt;
|
|
6669
|
+
if (age < 0 || (access.maxAgeMs !== null && age >= access.maxAgeMs)) {
|
|
6670
|
+
return null;
|
|
6671
|
+
}
|
|
6672
|
+
return entry;
|
|
6673
|
+
}
|
|
6674
|
+
|
|
6675
|
+
/**
|
|
6676
|
+
* A fresh shared entry as a completed receipt this call can recover, or
|
|
6677
|
+
* null. `referenced` is the canonical result receipt the entry names.
|
|
6678
|
+
*/
|
|
6679
|
+
private legacyLatestCacheReceipt(
|
|
6680
|
+
access: LegacyLatestCacheAccess,
|
|
6681
|
+
entry: NonNullable<ReturnType<typeof parseLatestCacheResult>>,
|
|
6682
|
+
referenced?: RuntimeStepReceipt | null,
|
|
6683
|
+
): RuntimeStepReceipt | null {
|
|
6684
|
+
const receipt: RuntimeStepReceipt | null = entry.valueReceiptKey
|
|
6685
|
+
? referenced &&
|
|
6686
|
+
(referenced.status === 'completed' ||
|
|
6687
|
+
referenced.status === 'skipped') &&
|
|
6688
|
+
referenced.output !== undefined &&
|
|
6689
|
+
referenced.output !== null
|
|
6690
|
+
? {
|
|
6691
|
+
key: entry.valueReceiptKey,
|
|
6692
|
+
status: 'completed',
|
|
6693
|
+
output: referenced.output,
|
|
6694
|
+
}
|
|
6695
|
+
: null
|
|
6696
|
+
: { key: access.key, status: 'completed', output: entry.value };
|
|
6697
|
+
if (
|
|
6698
|
+
!receipt ||
|
|
6699
|
+
!(
|
|
6700
|
+
isSerializedToolExecuteResult(receipt.output) ||
|
|
6701
|
+
isToolExecuteResult(receipt.output)
|
|
6702
|
+
) ||
|
|
6703
|
+
!this.canReuseToolResultForCurrentResponseContract(receipt.output)
|
|
6704
|
+
) {
|
|
6705
|
+
return null;
|
|
6706
|
+
}
|
|
6707
|
+
return receipt;
|
|
6708
|
+
}
|
|
6709
|
+
|
|
6710
|
+
/**
|
|
6711
|
+
* Publish an older edition's live result as the request's newest shared
|
|
6712
|
+
* result. Best effort: a call that used to succeed never fails on it.
|
|
6713
|
+
*/
|
|
6714
|
+
private async publishLegacyLatestCacheResult(input: {
|
|
6715
|
+
toolId: string;
|
|
6716
|
+
access: LegacyLatestCacheAccess | undefined | null;
|
|
6717
|
+
result: unknown;
|
|
6718
|
+
storedResultReceiptKey?: string;
|
|
6719
|
+
}): Promise<void> {
|
|
6720
|
+
const publish = this.#options.publishLatestCacheResult;
|
|
6721
|
+
if (
|
|
6722
|
+
!input.access?.publish ||
|
|
6723
|
+
!publish ||
|
|
6724
|
+
!DURABLE_RUNS_ROLLOUT.sharedReadCacheWrites ||
|
|
6725
|
+
!isToolExecuteResult(input.result) ||
|
|
6726
|
+
input.result.status === 'no_result' ||
|
|
6727
|
+
input.result.status === 'failed'
|
|
6728
|
+
) {
|
|
6729
|
+
return;
|
|
6730
|
+
}
|
|
6731
|
+
try {
|
|
6732
|
+
assertNoSecretTaint(input.result, 'Shared read cache result');
|
|
6733
|
+
await publish({
|
|
6734
|
+
key: input.access.key,
|
|
6735
|
+
runId: this.historyRunId,
|
|
6736
|
+
output: latestCacheResultOutput(
|
|
6737
|
+
completedCallForResult(input.result, 0, input.storedResultReceiptKey),
|
|
6738
|
+
),
|
|
6739
|
+
});
|
|
6740
|
+
} catch (error) {
|
|
6741
|
+
this.runtimeLog(
|
|
6742
|
+
`Tool ${input.toolId} shared read cache publish skipped: ${error instanceof Error ? error.message : String(error)}`,
|
|
6743
|
+
);
|
|
6744
|
+
}
|
|
6745
|
+
}
|
|
6746
|
+
|
|
6504
6747
|
private async resolveToolAuthScopeDigest(
|
|
6505
6748
|
toolId: string,
|
|
6506
6749
|
): Promise<string | null> {
|
|
@@ -6515,11 +6758,64 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6515
6758
|
this.#options.invalidateToolAuthScopeDigest?.(toolId);
|
|
6516
6759
|
}
|
|
6517
6760
|
|
|
6761
|
+
#replayUnsafeMarker: Promise<void> | null = null;
|
|
6762
|
+
|
|
6763
|
+
/**
|
|
6764
|
+
* Record, before customer code runs, that this run records call history
|
|
6765
|
+
* on a build that also marks the calls it can't record. The worker only
|
|
6766
|
+
* replays a run that carries this marker and lacks the unsafe one; a run
|
|
6767
|
+
* started on an older build has neither, so it is never replayed.
|
|
6768
|
+
*/
|
|
6769
|
+
async markRunReplayTracked(): Promise<void> {
|
|
6770
|
+
if (!this.usesExplicitFreshness) return;
|
|
6771
|
+
await this.writeReplayMarker(
|
|
6772
|
+
replayTrackedMarkerReceiptKey(
|
|
6773
|
+
this.#options.orgId ?? '',
|
|
6774
|
+
this.currentReceiptOwnerRunId,
|
|
6775
|
+
),
|
|
6776
|
+
'root_records_call_history',
|
|
6777
|
+
);
|
|
6778
|
+
}
|
|
6779
|
+
|
|
6780
|
+
/**
|
|
6781
|
+
* Awaited before the first call that runs without a history row. Concurrent
|
|
6782
|
+
* callers share one write; a failed write is retried by the next caller.
|
|
6783
|
+
*/
|
|
6784
|
+
private async markRunReplayUnsafe(reason: string): Promise<void> {
|
|
6785
|
+
// Older parents never acquire the replay-tracked marker, so they cannot
|
|
6786
|
+
// be replayed. Preserve their receipt contract without extra marker writes.
|
|
6787
|
+
if (!this.usesExplicitFreshness) return;
|
|
6788
|
+
this.#replayUnsafeMarker ??= this.writeReplayMarker(
|
|
6789
|
+
replayUnsafeMarkerReceiptKey(
|
|
6790
|
+
this.#options.orgId ?? '',
|
|
6791
|
+
this.currentReceiptOwnerRunId,
|
|
6792
|
+
),
|
|
6793
|
+
reason,
|
|
6794
|
+
).catch((error: unknown) => {
|
|
6795
|
+
this.#replayUnsafeMarker = null;
|
|
6796
|
+
throw error;
|
|
6797
|
+
});
|
|
6798
|
+
await this.#replayUnsafeMarker;
|
|
6799
|
+
}
|
|
6800
|
+
|
|
6801
|
+
private async writeReplayMarker(key: string, reason: string): Promise<void> {
|
|
6802
|
+
const orgId = this.#options.orgId?.trim();
|
|
6803
|
+
const store = this.durableReceiptExecutionStore();
|
|
6804
|
+
if (!orgId || !store.enabled) return;
|
|
6805
|
+
await store.complete(
|
|
6806
|
+
key,
|
|
6807
|
+
this.currentReceiptOwnerRunId,
|
|
6808
|
+
{ reason, recordedAtMs: Date.now() },
|
|
6809
|
+
COMPLETED_RECEIPT_CACHE_INSERT_LEASE_ID,
|
|
6810
|
+
);
|
|
6811
|
+
}
|
|
6812
|
+
|
|
6518
6813
|
private durableReceiptExecutionStore(): DurableReceiptExecutionStore {
|
|
6519
6814
|
return {
|
|
6520
6815
|
enabled: this.durableDirectToolResultsBackedByReceipts,
|
|
6521
6816
|
get: (receiptKey) => this.getRuntimeStepReceipt(receiptKey),
|
|
6522
|
-
getMany: (receiptKeys) =>
|
|
6817
|
+
getMany: (receiptKeys, options) =>
|
|
6818
|
+
this.getRuntimeStepReceipts(receiptKeys, options),
|
|
6523
6819
|
claim: (
|
|
6524
6820
|
receiptKey,
|
|
6525
6821
|
runId,
|
|
@@ -6547,6 +6843,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6547
6843
|
: {}),
|
|
6548
6844
|
complete: (receiptKey, runId, output, leaseId) =>
|
|
6549
6845
|
this.completeRuntimeStepReceipt(receiptKey, runId, output, leaseId),
|
|
6846
|
+
...(this.#options.publishLatestCacheResult
|
|
6847
|
+
? { publishLatestCacheResult: this.#options.publishLatestCacheResult }
|
|
6848
|
+
: {}),
|
|
6550
6849
|
release: (receiptKey, runId, leaseId) =>
|
|
6551
6850
|
this.releaseRuntimeStepReceipt(receiptKey, runId, leaseId),
|
|
6552
6851
|
...(this.#options.heartbeatRuntimeStepReceipts
|
|
@@ -6677,9 +6976,22 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6677
6976
|
id,
|
|
6678
6977
|
semanticKey,
|
|
6679
6978
|
invocationId:
|
|
6680
|
-
opts.invocationId ??
|
|
6979
|
+
opts.invocationId ??
|
|
6980
|
+
this.freshnessInvocationId(
|
|
6981
|
+
operation,
|
|
6982
|
+
id,
|
|
6983
|
+
this.callSlotRequestDigest({
|
|
6984
|
+
semanticKey: opts.semanticKey ?? null,
|
|
6985
|
+
}),
|
|
6986
|
+
),
|
|
6681
6987
|
policy,
|
|
6682
6988
|
execute: () => execute(null),
|
|
6989
|
+
sharesResult: (value) =>
|
|
6990
|
+
!(
|
|
6991
|
+
value &&
|
|
6992
|
+
typeof value === 'object' &&
|
|
6993
|
+
(value as { ok?: unknown }).ok === false
|
|
6994
|
+
),
|
|
6683
6995
|
onOutcome: (value, freshness) => {
|
|
6684
6996
|
const output =
|
|
6685
6997
|
opts.onRecovered && freshness.source !== 'executed'
|
|
@@ -6773,6 +7085,33 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6773
7085
|
return this.currentExecutionScope.receipt.ownerRunId;
|
|
6774
7086
|
}
|
|
6775
7087
|
|
|
7088
|
+
/**
|
|
7089
|
+
* The run that owns run-scoped history, SQL and provider idempotency keys.
|
|
7090
|
+
* An inline child's logical run ID is its composition namespace, which
|
|
7091
|
+
* repeats across separate parent runs; keys built from it let a later run
|
|
7092
|
+
* recover an earlier run's child writes (ADR 0013: tool receipts stay under
|
|
7093
|
+
* the parent run). Launches pinned with `runScopedKeys` use the executing
|
|
7094
|
+
* run; older launches keep the derivation they were admitted with. For a
|
|
7095
|
+
* root run both values are the same, so its keys are byte-identical.
|
|
7096
|
+
*/
|
|
7097
|
+
private get historyRunId(): string {
|
|
7098
|
+
return this.#options.runScopedKeys === true
|
|
7099
|
+
? this.currentReceiptOwnerRunId
|
|
7100
|
+
: this.currentRunId;
|
|
7101
|
+
}
|
|
7102
|
+
|
|
7103
|
+
/**
|
|
7104
|
+
* Whether `historyRunId` names this run alone. Without run-scoped keys an
|
|
7105
|
+
* inline child's history namespace repeats across parent runs, so a key
|
|
7106
|
+
* built from it must not stand for "this call in this run".
|
|
7107
|
+
*/
|
|
7108
|
+
private get historyRunIdIsRunScoped(): boolean {
|
|
7109
|
+
return (
|
|
7110
|
+
this.#options.runScopedKeys === true ||
|
|
7111
|
+
this.currentExecutionScope.placement.kind !== 'inline_child'
|
|
7112
|
+
);
|
|
7113
|
+
}
|
|
7114
|
+
|
|
6776
7115
|
private get currentRunAttempt(): number {
|
|
6777
7116
|
return this.currentExecutionScope.receipt.ownerAttempt;
|
|
6778
7117
|
}
|
|
@@ -6893,6 +7232,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6893
7232
|
input.dispatchPayload,
|
|
6894
7233
|
{
|
|
6895
7234
|
...input.apiOptions,
|
|
7235
|
+
...(input.request.logicalCallId && this.historyRunIdIsRunScoped
|
|
7236
|
+
? {
|
|
7237
|
+
asyncRecoveryCallIdentity: `${this.historyRunId}:${input.request.logicalCallId}`,
|
|
7238
|
+
}
|
|
7239
|
+
: {}),
|
|
6896
7240
|
...(!alwaysFresh &&
|
|
6897
7241
|
input.resultReceiptKey &&
|
|
6898
7242
|
// This result is augmented locally with a deferred dataset handle
|
|
@@ -14020,10 +14364,16 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14020
14364
|
return this.executeToolLegacyInternal(key, toolId, input, options);
|
|
14021
14365
|
}
|
|
14022
14366
|
const policy = resolveExplicitDurableCallPolicy(options ?? {});
|
|
14023
|
-
|
|
14367
|
+
const refreshed =
|
|
14024
14368
|
this.#options.cachePolicy?.forceToolRefresh === true ||
|
|
14025
|
-
toolExecutionOverrides.getStore()?.force === true
|
|
14026
|
-
|
|
14369
|
+
toolExecutionOverrides.getStore()?.force === true;
|
|
14370
|
+
// A refresh of an authored reusable read still publishes its fresh result
|
|
14371
|
+
// as the request's newest shared result. An authored 0 never does.
|
|
14372
|
+
const refreshMayPublish =
|
|
14373
|
+
refreshed &&
|
|
14374
|
+
policy.requested !== 0 &&
|
|
14375
|
+
DURABLE_RUNS_ROLLOUT.sharedReadCacheWrites;
|
|
14376
|
+
if (refreshed) {
|
|
14027
14377
|
policy.effective = 0;
|
|
14028
14378
|
}
|
|
14029
14379
|
const normalizedKey = this.normalizeContextKey(key, 'tool');
|
|
@@ -14031,7 +14381,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14031
14381
|
// concurrent calls may share an authored id; assigning their identity
|
|
14032
14382
|
// after auth/action metadata resolves would make recovery depend on lookup
|
|
14033
14383
|
// completion order instead of authored call order.
|
|
14034
|
-
const invocationId = this.freshnessInvocationId(
|
|
14384
|
+
const invocationId = this.freshnessInvocationId(
|
|
14385
|
+
'tool',
|
|
14386
|
+
normalizedKey,
|
|
14387
|
+
this.callSlotRequestDigest({ toolId, input }),
|
|
14388
|
+
);
|
|
14035
14389
|
const sqlTool = isCustomerDbDatasetTool(toolId);
|
|
14036
14390
|
const scalarCustomerDbQuery = sqlTool && input.result_mode === 'rows';
|
|
14037
14391
|
const liveDataset =
|
|
@@ -14043,7 +14397,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14043
14397
|
result_mode: undefined,
|
|
14044
14398
|
});
|
|
14045
14399
|
const [eventWait, invocationScoped, retryPolicy, reusableSupport] =
|
|
14046
|
-
policy.effective === 0
|
|
14400
|
+
policy.effective === 0 && !refreshMayPublish
|
|
14047
14401
|
? ([null, false, null, null] as const)
|
|
14048
14402
|
: await Promise.all([
|
|
14049
14403
|
this.#options.getIntegrationEventWaitHandler?.(toolId) ?? null,
|
|
@@ -14059,15 +14413,21 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14059
14413
|
`Tool ${toolId} does not support reusable freshness; use staleAfterSeconds: 0. ${reusableSupport?.unavailableReason ?? 'No read-result reuse capability was supplied by the action owner.'}`,
|
|
14060
14414
|
);
|
|
14061
14415
|
}
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
|
|
14416
|
+
const mustExecuteEveryTime = Boolean(
|
|
14417
|
+
eventWait ||
|
|
14418
|
+
invocationScoped ||
|
|
14419
|
+
requiresExecutionFence ||
|
|
14420
|
+
liveDataset ||
|
|
14421
|
+
sqlMutation ||
|
|
14422
|
+
isAlwaysFreshIntegrationTool(toolId),
|
|
14423
|
+
);
|
|
14424
|
+
// Same eligibility as reuse: only a read whose result may serve a later
|
|
14425
|
+
// call is shared. Writes and live observations never publish.
|
|
14426
|
+
const publishLatestOnRefresh =
|
|
14427
|
+
refreshMayPublish &&
|
|
14428
|
+
reusableSupport?.supported === true &&
|
|
14429
|
+
!mustExecuteEveryTime;
|
|
14430
|
+
if (policy.effective !== 0 && mustExecuteEveryTime) {
|
|
14071
14431
|
throw new Error(
|
|
14072
14432
|
`Tool ${toolId} does not support reusable freshness; use staleAfterSeconds: 0. Live datasets, event waits, invocation-scoped actions, writes, and Workspace operations cannot reuse an older result.`,
|
|
14073
14433
|
);
|
|
@@ -14079,8 +14439,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14079
14439
|
if (!actionVersion) {
|
|
14080
14440
|
throw new Error(`Tool ${toolId} has no action identity for freshness.`);
|
|
14081
14441
|
}
|
|
14082
|
-
const semanticKey =
|
|
14083
|
-
kind: 'tool',
|
|
14442
|
+
const semanticKey = toolReadSemanticKey({
|
|
14084
14443
|
orgId: this.#options.orgId,
|
|
14085
14444
|
toolId,
|
|
14086
14445
|
input,
|
|
@@ -14094,9 +14453,33 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14094
14453
|
}
|
|
14095
14454
|
const requestInput =
|
|
14096
14455
|
sqlTool && (sqlMutation || scalarCustomerDbQuery)
|
|
14097
|
-
? { ...input, operation_key: `${this.
|
|
14456
|
+
? { ...input, operation_key: `${this.historyRunId}:${invocationId}` }
|
|
14098
14457
|
: input;
|
|
14099
14458
|
|
|
14459
|
+
if (
|
|
14460
|
+
isAlwaysFreshIntegrationWriteTool(toolId) &&
|
|
14461
|
+
!liveDataset &&
|
|
14462
|
+
// A later parent run must not recover an earlier run's write.
|
|
14463
|
+
this.historyRunIdIsRunScoped
|
|
14464
|
+
) {
|
|
14465
|
+
// Never reused across calls or runs (effective freshness 0), but the
|
|
14466
|
+
// run's history row lets a retry of this run recover the write instead
|
|
14467
|
+
// of repeating it.
|
|
14468
|
+
return this.executeFreshnessControlledCall({
|
|
14469
|
+
operation: 'tool',
|
|
14470
|
+
id: normalizedKey,
|
|
14471
|
+
semanticKey,
|
|
14472
|
+
invocationId,
|
|
14473
|
+
policy: { requested: policy.requested, effective: 0 },
|
|
14474
|
+
execute: async () =>
|
|
14475
|
+
await this.executeToolLegacyInternal(key, toolId, requestInput, {
|
|
14476
|
+
...options,
|
|
14477
|
+
force: true,
|
|
14478
|
+
staleAfterSeconds: 0,
|
|
14479
|
+
}),
|
|
14480
|
+
});
|
|
14481
|
+
}
|
|
14482
|
+
|
|
14100
14483
|
if (liveDataset || isAlwaysFreshIntegrationTool(toolId)) {
|
|
14101
14484
|
const value = await this.executeToolLegacyInternal(
|
|
14102
14485
|
key,
|
|
@@ -14128,6 +14511,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14128
14511
|
semanticKey,
|
|
14129
14512
|
invocationId,
|
|
14130
14513
|
policy,
|
|
14514
|
+
...(publishLatestOnRefresh
|
|
14515
|
+
? { publishLatestOnRefresh: true as const }
|
|
14516
|
+
: {}),
|
|
14131
14517
|
completedAt: (value) => {
|
|
14132
14518
|
if (!isToolExecuteResult(value)) return undefined;
|
|
14133
14519
|
const raw = value.toolResponse.raw as {
|
|
@@ -14139,6 +14525,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14139
14525
|
? completedAt
|
|
14140
14526
|
: value._metadata.execution.completedAt;
|
|
14141
14527
|
},
|
|
14528
|
+
sharesResult: (value) =>
|
|
14529
|
+
!isToolExecuteResult(value) ||
|
|
14530
|
+
(value.status !== 'no_result' && value.status !== 'failed'),
|
|
14142
14531
|
execute: async () => {
|
|
14143
14532
|
const value = await this.executeToolLegacyInternal(
|
|
14144
14533
|
key,
|
|
@@ -14320,7 +14709,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14320
14709
|
const invocationScoped =
|
|
14321
14710
|
!eventWaitHandler &&
|
|
14322
14711
|
(await this.#options.getToolIdempotencyScope?.(toolId)) === 'invocation';
|
|
14323
|
-
const invocationIdentity = `${this.
|
|
14712
|
+
const invocationIdentity = `${this.historyRunId}:${logicalCallId}`;
|
|
14324
14713
|
const scopeReceipt = (receiptKey: string): string =>
|
|
14325
14714
|
invocationScoped
|
|
14326
14715
|
? scopeToolReceiptToInvocation({
|
|
@@ -14379,6 +14768,18 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14379
14768
|
legacyDurableCacheKey = scopeReceipt(legacyDurableCacheKey);
|
|
14380
14769
|
providerIdempotencyKeyBase = scopeOperation(providerIdempotencyKeyBase);
|
|
14381
14770
|
let directResultReceiptKey = durableCacheKey;
|
|
14771
|
+
const resolveLatestCacheAccess = () =>
|
|
14772
|
+
this.legacyLatestCacheAccess({
|
|
14773
|
+
toolId,
|
|
14774
|
+
requestInput: input,
|
|
14775
|
+
options,
|
|
14776
|
+
staleAfterSeconds: toolCachePolicy.staleAfterSeconds,
|
|
14777
|
+
cacheable: cacheableToolResult,
|
|
14778
|
+
invocationScoped,
|
|
14779
|
+
executionAuthScopeDigest,
|
|
14780
|
+
providerActionVersion,
|
|
14781
|
+
});
|
|
14782
|
+
let latestCache = await resolveLatestCacheAccess();
|
|
14382
14783
|
// A raw-v2 artifact must never read an older receipt that cannot render
|
|
14383
14784
|
// raw-v2. If both the primary and its revisioned recovery receipt are
|
|
14384
14785
|
// unrenderable, make a live call rather than returning either cache entry.
|
|
@@ -14530,8 +14931,24 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14530
14931
|
}
|
|
14531
14932
|
}
|
|
14532
14933
|
}
|
|
14934
|
+
// An older edition reads the request's shared result in the same
|
|
14935
|
+
// batch as its play-local receipt; the play-local result wins.
|
|
14936
|
+
const sharedRead = latestCache?.read ? latestCache : null;
|
|
14937
|
+
let sharedReceipt: RuntimeStepReceipt | null = null;
|
|
14533
14938
|
const historicalReceipt = await this.withRuntimeReceiptHydrationTurn(
|
|
14534
14939
|
async (turn) => {
|
|
14940
|
+
if (sharedRead) {
|
|
14941
|
+
const byKey = await this.getRuntimeStepReceipts([
|
|
14942
|
+
directCacheKey,
|
|
14943
|
+
sharedRead.key,
|
|
14944
|
+
]);
|
|
14945
|
+
const receipt = byKey.get(directCacheKey) ?? null;
|
|
14946
|
+
sharedReceipt = byKey.get(sharedRead.key) ?? null;
|
|
14947
|
+
turn.settleBytes(
|
|
14948
|
+
runtimeStepReceiptPayloadBytes([receipt, sharedReceipt]),
|
|
14949
|
+
);
|
|
14950
|
+
return receipt;
|
|
14951
|
+
}
|
|
14535
14952
|
const receipt = await this.getRuntimeStepReceipt(directCacheKey);
|
|
14536
14953
|
turn.settleBytes(runtimeStepReceiptPayloadBytes([receipt]));
|
|
14537
14954
|
return receipt;
|
|
@@ -14615,6 +15032,49 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14615
15032
|
bypassDirectResultCache = true;
|
|
14616
15033
|
}
|
|
14617
15034
|
}
|
|
15035
|
+
const sharedEntry =
|
|
15036
|
+
sharedRead &&
|
|
15037
|
+
!(historicalIsTerminal && historicalCanServeCurrentContract)
|
|
15038
|
+
? this.freshLegacyLatestCacheEntry(
|
|
15039
|
+
sharedRead,
|
|
15040
|
+
sharedReceipt,
|
|
15041
|
+
Date.now(),
|
|
15042
|
+
)
|
|
15043
|
+
: null;
|
|
15044
|
+
if (sharedRead && sharedEntry) {
|
|
15045
|
+
const referenceKey = sharedEntry.valueReceiptKey;
|
|
15046
|
+
const referenced = referenceKey
|
|
15047
|
+
? await this.withRuntimeReceiptHydrationTurn(
|
|
15048
|
+
async (turn) => {
|
|
15049
|
+
const receipt =
|
|
15050
|
+
await this.getRuntimeStepReceipt(referenceKey);
|
|
15051
|
+
turn.settleBytes(runtimeStepReceiptPayloadBytes([receipt]));
|
|
15052
|
+
return receipt;
|
|
15053
|
+
},
|
|
15054
|
+
{ source: 'direct_tool_legacy_cache' },
|
|
15055
|
+
)
|
|
15056
|
+
: null;
|
|
15057
|
+
const shared = this.legacyLatestCacheReceipt(
|
|
15058
|
+
sharedRead,
|
|
15059
|
+
sharedEntry,
|
|
15060
|
+
referenced,
|
|
15061
|
+
);
|
|
15062
|
+
if (shared) {
|
|
15063
|
+
this.runtimeLog(
|
|
15064
|
+
`Calling tool: ${toolId} reused the request's shared result`,
|
|
15065
|
+
);
|
|
15066
|
+
return presentResult(
|
|
15067
|
+
markToolExecuteResultExecutionOutcome(
|
|
15068
|
+
this.runtimeReceiptOutput(shared),
|
|
15069
|
+
toolExecutionOutcomeForDurableReceipt({
|
|
15070
|
+
source: 'cache',
|
|
15071
|
+
receiptKey: shared.key,
|
|
15072
|
+
cacheKey: directCacheKey,
|
|
15073
|
+
}),
|
|
15074
|
+
),
|
|
15075
|
+
);
|
|
15076
|
+
}
|
|
15077
|
+
}
|
|
14618
15078
|
}
|
|
14619
15079
|
this.runtimeLog(
|
|
14620
15080
|
toolCachePolicy.force
|
|
@@ -14665,7 +15125,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14665
15125
|
: `${buildDurableToolReceiptPrefix({
|
|
14666
15126
|
orgId: this.#options.orgId ?? 'unknown-org',
|
|
14667
15127
|
toolId,
|
|
14668
|
-
})}${stableDigest(`${this.
|
|
15128
|
+
})}${stableDigest(`${this.historyRunId}:${logicalCallId}:always-fresh`)}`;
|
|
14669
15129
|
const resultReceiptKey = directResultReceiptKey;
|
|
14670
15130
|
const resultReceiptPolicy = resolveToolCallResultReceiptPolicy({
|
|
14671
15131
|
orgId: this.#options.orgId,
|
|
@@ -14801,18 +15261,28 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14801
15261
|
},
|
|
14802
15262
|
...(toolRetryPolicy?.requiresExecutionFence === true
|
|
14803
15263
|
? {
|
|
14804
|
-
executionLock: {
|
|
14805
|
-
|
|
14806
|
-
key: providerOperationKey,
|
|
14807
|
-
ttlMs: Math.min(
|
|
15264
|
+
executionLock: (() => {
|
|
15265
|
+
const ttlMs = Math.min(
|
|
14808
15266
|
600_000,
|
|
14809
15267
|
resolveToolRuntimeTimeoutMs(
|
|
14810
15268
|
toolId,
|
|
14811
15269
|
options?.timeoutMs,
|
|
14812
15270
|
this.currentAuthoringContractEdition,
|
|
14813
15271
|
) ?? 300_000,
|
|
14814
|
-
)
|
|
14815
|
-
|
|
15272
|
+
);
|
|
15273
|
+
return {
|
|
15274
|
+
required: true,
|
|
15275
|
+
key: providerOperationKey,
|
|
15276
|
+
ttlMs,
|
|
15277
|
+
// A retried attempt may find the lock held by the
|
|
15278
|
+
// attempt the platform lost; it waits that lease
|
|
15279
|
+
// out instead of failing the call. The gateway's
|
|
15280
|
+
// fence still sends the call at most once.
|
|
15281
|
+
...(DURABLE_RUNS_ROLLOUT.automaticPostCodeRecovery
|
|
15282
|
+
? { waitMs: ttlMs + 30_000 }
|
|
15283
|
+
: {}),
|
|
15284
|
+
};
|
|
15285
|
+
})(),
|
|
14816
15286
|
}
|
|
14817
15287
|
: {}),
|
|
14818
15288
|
recover: ({ result, source }) =>
|
|
@@ -14871,6 +15341,16 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14871
15341
|
'direct',
|
|
14872
15342
|
);
|
|
14873
15343
|
this.#options.onBatchComplete?.(this.checkpoint);
|
|
15344
|
+
if (
|
|
15345
|
+
isToolExecuteResult(wrapped) &&
|
|
15346
|
+
wrapped._metadata.execution.source === 'live'
|
|
15347
|
+
) {
|
|
15348
|
+
await this.publishLegacyLatestCacheResult({
|
|
15349
|
+
toolId,
|
|
15350
|
+
access: latestCache,
|
|
15351
|
+
result: wrapped,
|
|
15352
|
+
});
|
|
15353
|
+
}
|
|
14874
15354
|
}
|
|
14875
15355
|
return presentResult(wrapped);
|
|
14876
15356
|
} catch (error) {
|
|
@@ -15005,6 +15485,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15005
15485
|
...compatibleDurableCacheKeys.slice(1),
|
|
15006
15486
|
...(legacyDurableCacheKey ? [legacyDurableCacheKey] : []),
|
|
15007
15487
|
],
|
|
15488
|
+
...(latestCache ? { latestCache } : {}),
|
|
15008
15489
|
executionAuthScopeDigest,
|
|
15009
15490
|
requiresExecutionFence:
|
|
15010
15491
|
rowToolRetryPolicy?.requiresExecutionFence === true,
|
|
@@ -15152,6 +15633,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15152
15633
|
providerIdempotencyKeyBase = scopeOperation(providerIdempotencyKeyBase);
|
|
15153
15634
|
directResultReceiptKey = durableCacheKey;
|
|
15154
15635
|
bypassDirectResultCache = false;
|
|
15636
|
+
latestCache = await resolveLatestCacheAccess();
|
|
15155
15637
|
checkpointCacheKeys.splice(
|
|
15156
15638
|
0,
|
|
15157
15639
|
checkpointCacheKeys.length,
|
|
@@ -15611,6 +16093,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15611
16093
|
},
|
|
15612
16094
|
);
|
|
15613
16095
|
this.inlineChildAggregates.total += 1;
|
|
16096
|
+
if (
|
|
16097
|
+
childRuntimeContract.semantics.freshness !==
|
|
16098
|
+
'actual_age_with_operation_recovery'
|
|
16099
|
+
) {
|
|
16100
|
+
// This child keeps no call history, so a replay of the run could
|
|
16101
|
+
// repeat its writes. Durable before its first call goes out.
|
|
16102
|
+
await this.markRunReplayUnsafe('legacy_inline_child');
|
|
16103
|
+
}
|
|
15614
16104
|
try {
|
|
15615
16105
|
// A scalar child is a normal function call on the parent's context.
|
|
15616
16106
|
// Async-local identity changes receipt and recursion scope without
|
|
@@ -16451,7 +16941,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16451
16941
|
const normalizedKey = this.normalizeContextKey(key, 'fetch');
|
|
16452
16942
|
const invocationId =
|
|
16453
16943
|
this.usesExplicitFreshness && options?.transient !== true
|
|
16454
|
-
? this.freshnessInvocationId(
|
|
16944
|
+
? this.freshnessInvocationId(
|
|
16945
|
+
'fetch',
|
|
16946
|
+
normalizedKey,
|
|
16947
|
+
this.fetchCallSlotRequestDigest(input, init),
|
|
16948
|
+
)
|
|
16455
16949
|
: undefined;
|
|
16456
16950
|
const rowStore = rowContext.getStore();
|
|
16457
16951
|
const rowFetchScope = rowStore
|
|
@@ -16950,6 +17444,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16950
17444
|
invocationId: boundaryId,
|
|
16951
17445
|
policy: freshnessPolicy,
|
|
16952
17446
|
completedAt: (value) => value.completedAt,
|
|
17447
|
+
sharesResult: (value) =>
|
|
17448
|
+
!value.undefinedOutput && value.output !== null,
|
|
16953
17449
|
execute: async () => {
|
|
16954
17450
|
const before = this.sleepBoundaryIndex;
|
|
16955
17451
|
const value = await executeStep();
|
|
@@ -17376,21 +17872,54 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17376
17872
|
result,
|
|
17377
17873
|
};
|
|
17378
17874
|
};
|
|
17875
|
+
const candidatesFor = (receiptKey: string): string[] => {
|
|
17876
|
+
const request = input.requestForReceipt.get(receiptKey);
|
|
17877
|
+
return [
|
|
17878
|
+
receiptKey,
|
|
17879
|
+
...(request?.force === true ? [] : (request?.legacyReceiptKeys ?? [])),
|
|
17880
|
+
];
|
|
17881
|
+
};
|
|
17882
|
+
// Older editions only: the request's shared result, after its play-local
|
|
17883
|
+
// keys. A forced call never reads it.
|
|
17884
|
+
const sharedReadFor = (
|
|
17885
|
+
receiptKey: string,
|
|
17886
|
+
): LegacyLatestCacheAccess | null => {
|
|
17887
|
+
const request = input.requestForReceipt.get(receiptKey);
|
|
17888
|
+
return request?.force !== true && request?.latestCache?.read
|
|
17889
|
+
? request.latestCache
|
|
17890
|
+
: null;
|
|
17891
|
+
};
|
|
17892
|
+
const isTerminal = (receipt: RuntimeStepReceipt | null | undefined) =>
|
|
17893
|
+
receipt?.status === 'completed' || receipt?.status === 'skipped';
|
|
17894
|
+
const sharedReceiptFor = (
|
|
17895
|
+
receiptKey: string,
|
|
17896
|
+
receipts: Map<string, RuntimeStepReceipt>,
|
|
17897
|
+
nowMs: number,
|
|
17898
|
+
): RuntimeStepReceipt | null => {
|
|
17899
|
+
const access = sharedReadFor(receiptKey);
|
|
17900
|
+
if (!access) return null;
|
|
17901
|
+
const entry = this.freshLegacyLatestCacheEntry(
|
|
17902
|
+
access,
|
|
17903
|
+
receipts.get(access.key),
|
|
17904
|
+
nowMs,
|
|
17905
|
+
);
|
|
17906
|
+
return entry
|
|
17907
|
+
? this.legacyLatestCacheReceipt(
|
|
17908
|
+
access,
|
|
17909
|
+
entry,
|
|
17910
|
+
entry.valueReceiptKey ? receipts.get(entry.valueReceiptKey) : null,
|
|
17911
|
+
)
|
|
17912
|
+
: null;
|
|
17913
|
+
};
|
|
17379
17914
|
const recordsFor = async (
|
|
17380
17915
|
receiptKeys: string[],
|
|
17381
17916
|
receipts: Map<string, RuntimeStepReceipt>,
|
|
17917
|
+
nowMs: number,
|
|
17382
17918
|
): Promise<ToolCallReceiptRecord[]> =>
|
|
17383
17919
|
(
|
|
17384
17920
|
await Promise.all(
|
|
17385
17921
|
receiptKeys.map(async (receiptKey) => {
|
|
17386
|
-
const
|
|
17387
|
-
const candidates = [
|
|
17388
|
-
receiptKey,
|
|
17389
|
-
...(request?.force === true
|
|
17390
|
-
? []
|
|
17391
|
-
: (request?.legacyReceiptKeys ?? [])),
|
|
17392
|
-
];
|
|
17393
|
-
for (const candidate of candidates) {
|
|
17922
|
+
for (const candidate of candidatesFor(receiptKey)) {
|
|
17394
17923
|
const record = await asRecord(
|
|
17395
17924
|
receiptKey,
|
|
17396
17925
|
candidate,
|
|
@@ -17398,7 +17927,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17398
17927
|
);
|
|
17399
17928
|
if (record) return record;
|
|
17400
17929
|
}
|
|
17401
|
-
|
|
17930
|
+
const shared = sharedReceiptFor(receiptKey, receipts, nowMs);
|
|
17931
|
+
return shared
|
|
17932
|
+
? await asRecord(receiptKey, shared.key, shared)
|
|
17933
|
+
: null;
|
|
17402
17934
|
}),
|
|
17403
17935
|
)
|
|
17404
17936
|
).filter((record): record is ToolCallReceiptRecord => record !== null);
|
|
@@ -17406,16 +17938,17 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17406
17938
|
return {
|
|
17407
17939
|
read: async ({ resultReceiptKeys }) =>
|
|
17408
17940
|
await (async () => {
|
|
17941
|
+
const sharedKeys = new Set(
|
|
17942
|
+
resultReceiptKeys.flatMap((receiptKey) => {
|
|
17943
|
+
const access = sharedReadFor(receiptKey);
|
|
17944
|
+
return access ? [access.key] : [];
|
|
17945
|
+
}),
|
|
17946
|
+
);
|
|
17409
17947
|
const receiptKeys = [
|
|
17410
|
-
...new Set(
|
|
17411
|
-
resultReceiptKeys.flatMap(
|
|
17412
|
-
|
|
17413
|
-
|
|
17414
|
-
? []
|
|
17415
|
-
: (input.requestForReceipt.get(receiptKey)
|
|
17416
|
-
?.legacyReceiptKeys ?? [])),
|
|
17417
|
-
]),
|
|
17418
|
-
),
|
|
17948
|
+
...new Set([
|
|
17949
|
+
...resultReceiptKeys.flatMap(candidatesFor),
|
|
17950
|
+
...sharedKeys,
|
|
17951
|
+
]),
|
|
17419
17952
|
];
|
|
17420
17953
|
const claimStartedAt = Date.now();
|
|
17421
17954
|
// A fresh cache miss has no terminal result. Reading its manifest is
|
|
@@ -17425,10 +17958,25 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17425
17958
|
const manifests = await this.getRuntimeStepReceipts(receiptKeys, {
|
|
17426
17959
|
hydrateOutput: false,
|
|
17427
17960
|
});
|
|
17961
|
+
// A shared entry is hydrated only for a call whose play-local
|
|
17962
|
+
// keys all missed; a play-local hit never pays for its body.
|
|
17963
|
+
const neededSharedKeys = new Set(
|
|
17964
|
+
resultReceiptKeys.flatMap((receiptKey) => {
|
|
17965
|
+
const access = sharedReadFor(receiptKey);
|
|
17966
|
+
return access &&
|
|
17967
|
+
!candidatesFor(receiptKey).some((candidate) =>
|
|
17968
|
+
isTerminal(manifests.get(candidate)),
|
|
17969
|
+
)
|
|
17970
|
+
? [access.key]
|
|
17971
|
+
: [];
|
|
17972
|
+
}),
|
|
17973
|
+
);
|
|
17428
17974
|
const terminalReceiptKeys = [...manifests]
|
|
17429
17975
|
.filter(
|
|
17430
|
-
([, receipt]) =>
|
|
17431
|
-
receipt
|
|
17976
|
+
([receiptKey, receipt]) =>
|
|
17977
|
+
isTerminal(receipt) &&
|
|
17978
|
+
(!sharedKeys.has(receiptKey) ||
|
|
17979
|
+
neededSharedKeys.has(receiptKey)),
|
|
17432
17980
|
)
|
|
17433
17981
|
.map(([receiptKey]) => receiptKey);
|
|
17434
17982
|
const hasBoundedManifests = terminalReceiptKeys.every(
|
|
@@ -17464,6 +18012,41 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17464
18012
|
return await this.withRuntimeReceiptHydrationTurn(
|
|
17465
18013
|
async (turn) => {
|
|
17466
18014
|
const receipts = await this.getRuntimeStepReceipts(keysToHydrate);
|
|
18015
|
+
// A fresh shared entry may name its canonical result receipt.
|
|
18016
|
+
// Read those in one batch before the turn is measured.
|
|
18017
|
+
const nowMs = Date.now();
|
|
18018
|
+
const references = [
|
|
18019
|
+
...new Set(
|
|
18020
|
+
resultReceiptKeys.flatMap((receiptKey) => {
|
|
18021
|
+
const access = sharedReadFor(receiptKey);
|
|
18022
|
+
if (
|
|
18023
|
+
!access ||
|
|
18024
|
+
candidatesFor(receiptKey).some(
|
|
18025
|
+
(candidate) =>
|
|
18026
|
+
isTerminal(receipts.get(candidate)) &&
|
|
18027
|
+
receipts.get(candidate)?.output !== undefined,
|
|
18028
|
+
)
|
|
18029
|
+
) {
|
|
18030
|
+
return [];
|
|
18031
|
+
}
|
|
18032
|
+
const entry = this.freshLegacyLatestCacheEntry(
|
|
18033
|
+
access,
|
|
18034
|
+
receipts.get(access.key),
|
|
18035
|
+
nowMs,
|
|
18036
|
+
);
|
|
18037
|
+
return entry?.valueReceiptKey
|
|
18038
|
+
? [entry.valueReceiptKey]
|
|
18039
|
+
: [];
|
|
18040
|
+
}),
|
|
18041
|
+
),
|
|
18042
|
+
].filter((key) => !receipts.has(key));
|
|
18043
|
+
if (references.length > 0) {
|
|
18044
|
+
for (const [key, receipt] of await this.getRuntimeStepReceipts(
|
|
18045
|
+
references,
|
|
18046
|
+
)) {
|
|
18047
|
+
receipts.set(key, receipt);
|
|
18048
|
+
}
|
|
18049
|
+
}
|
|
17467
18050
|
this.resourceGovernor.observe({
|
|
17468
18051
|
receiptClaimMs: Date.now() - claimStartedAt,
|
|
17469
18052
|
});
|
|
@@ -17473,7 +18056,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17473
18056
|
turn.settleBytes(
|
|
17474
18057
|
runtimeStepReceiptPayloadBytes(receipts.values()),
|
|
17475
18058
|
);
|
|
17476
|
-
return await recordsFor(resultReceiptKeys, receipts);
|
|
18059
|
+
return await recordsFor(resultReceiptKeys, receipts, nowMs);
|
|
17477
18060
|
},
|
|
17478
18061
|
{
|
|
17479
18062
|
logicalCalls: resultReceiptKeys.length,
|
|
@@ -17511,6 +18094,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17511
18094
|
const canonicalReceiptKeys = new Set(
|
|
17512
18095
|
canonicalCompletions.map((receipt) => receipt.key),
|
|
17513
18096
|
);
|
|
18097
|
+
const storedReceiptKeys = new Set<string>();
|
|
17514
18098
|
const manifestCompletions =
|
|
17515
18099
|
this.sourceRunToolReceiptManifestCompletionInputs(
|
|
17516
18100
|
receipts.flatMap((receipt) =>
|
|
@@ -17551,6 +18135,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17551
18135
|
if (!canonicalReceiptKeys.has(settlement.key)) return;
|
|
17552
18136
|
if (settlement.status === 'failed') {
|
|
17553
18137
|
tripOnFailure(settlement.error);
|
|
18138
|
+
} else {
|
|
18139
|
+
storedReceiptKeys.add(settlement.key);
|
|
17554
18140
|
}
|
|
17555
18141
|
onReceiptSettled?.(
|
|
17556
18142
|
settlement.status === 'failed'
|
|
@@ -17574,6 +18160,21 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17574
18160
|
},
|
|
17575
18161
|
},
|
|
17576
18162
|
);
|
|
18163
|
+
// Older editions publish a stored live result as the request's
|
|
18164
|
+
// newest shared result. A reference names the stored receipt.
|
|
18165
|
+
await Promise.all(
|
|
18166
|
+
receipts.map(async (receipt) => {
|
|
18167
|
+
if (!storedReceiptKeys.has(receipt.resultReceiptKey)) return;
|
|
18168
|
+
await this.publishLegacyLatestCacheResult({
|
|
18169
|
+
toolId: input.toolId,
|
|
18170
|
+
access: requestsForPublication(receipt).find(
|
|
18171
|
+
(request) => request.latestCache?.publish,
|
|
18172
|
+
)?.latestCache,
|
|
18173
|
+
result: receipt.result,
|
|
18174
|
+
storedResultReceiptKey: receipt.resultReceiptKey,
|
|
18175
|
+
});
|
|
18176
|
+
}),
|
|
18177
|
+
);
|
|
17577
18178
|
} catch (error) {
|
|
17578
18179
|
tripOnFailure(error);
|
|
17579
18180
|
throw error;
|
|
@@ -18999,7 +19600,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
18999
19600
|
return buildProviderOperationIdempotencyKey({
|
|
19000
19601
|
operationKey: input.operationKey,
|
|
19001
19602
|
force: true,
|
|
19002
|
-
fallbackAttemptId: `${this.
|
|
19603
|
+
fallbackAttemptId: `${this.historyRunId}:${input.logicalCallId}${input.force === true ? '' : ':cache-miss'}`,
|
|
19003
19604
|
});
|
|
19004
19605
|
}
|
|
19005
19606
|
|
|
@@ -19808,6 +20409,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
19808
20409
|
(options?.providerOperationForceRefreshIdentities?.length
|
|
19809
20410
|
? options.providerOperationForceRefreshIdentities
|
|
19810
20411
|
: (options?.providerIdempotencyKey ??
|
|
20412
|
+
options?.asyncRecoveryCallIdentity ??
|
|
19811
20413
|
executionRequestNonce)),
|
|
19812
20414
|
payload: toolInputSnapshot,
|
|
19813
20415
|
authScope: executionAuthScopeDigest,
|
|
@@ -21614,6 +22216,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21614
22216
|
failure.shouldRetry &&
|
|
21615
22217
|
(failure.knownNotDispatched ||
|
|
21616
22218
|
failure.reason === 'gateway_invocation_in_progress' ||
|
|
22219
|
+
// A provider 5xx is sent again with the same provider
|
|
22220
|
+
// idempotency key on a new invocation attempt.
|
|
22221
|
+
failure.reason === 'provider_server_error' ||
|
|
21617
22222
|
ambiguousTransportReplayAllowed ||
|
|
21618
22223
|
Boolean(asyncExecutionRecovery) ||
|
|
21619
22224
|
retrySafeTransientHttp ||
|