deepline 0.3.537 → 0.3.538
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 -5
- package/dist/bundling-sources/sdk/src/index.ts +2 -0
- package/dist/bundling-sources/sdk/src/plays/client-core.ts +18 -1
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +33 -4
- package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +1 -1
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/baked-runner-image.ts +330 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +717 -133
- package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +22 -1
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +123 -0
- package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +480 -0
- package/dist/bundling-sources/shared_libs/play-runtime/fixture-egress-fetch.ts +24 -16
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +293 -53
- package/dist/bundling-sources/shared_libs/play-runtime/governor/block-reserving-budget-state-backend.ts +57 -2
- package/dist/bundling-sources/shared_libs/play-runtime/governor/budget-state-backend.ts +43 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +141 -9
- package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/modal-supervisor-sidecar.ts +556 -0
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +19 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +155 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/relay-connection-counter.ts +103 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +75 -6
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +59 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +544 -73
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +8 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +19 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +2390 -110
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-flow.ts +42 -8
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-read-through.ts +287 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-finish.ts +606 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +274 -119
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-traffic-policy.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-work-counters.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +18 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +18 -4
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +219 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-claim-affinity.ts +340 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +623 -7
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +340 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +61 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +269 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +238 -5
- package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +47 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +5 -4
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +11 -0
- package/dist/cli/auth-4WEVLYK4.js +43 -0
- package/dist/cli/{auth-4SUPGDIM.mjs → auth-KYH7N7RQ.mjs} +5 -5
- package/dist/cli/{billing-SQU726P7.js → billing-4KTUVZ4S.js} +114 -90
- package/dist/cli/{billing-5JUA3ZM3.mjs → billing-WK346KAI.mjs} +31 -7
- package/dist/cli/{chunk-KULT6O5K.js → chunk-25RGHJQL.js} +15 -15
- package/dist/cli/{chunk-PJ4ZGZAN.js → chunk-34PLG5OE.js} +13 -13
- package/dist/cli/{chunk-37AZHCTP.mjs → chunk-35OCRH5C.mjs} +5 -5
- package/dist/cli/{chunk-JMHYDDBQ.js → chunk-3I5TU5XE.js} +292 -279
- package/dist/cli/{chunk-Y6AMMXWS.mjs → chunk-4KZF6OYY.mjs} +3 -3
- package/dist/cli/{chunk-BRRCWUOW.mjs → chunk-4NEOGPKD.mjs} +1 -1
- package/dist/cli/{chunk-NU7B5X6J.mjs → chunk-4WQR4DG4.mjs} +1 -1
- package/dist/cli/{chunk-AVQET3NR.js → chunk-5VSPRRTI.js} +7 -7
- package/dist/cli/{chunk-EEFSUCYP.mjs → chunk-6JG3MRTM.mjs} +2 -2
- package/dist/cli/{chunk-D77W6Q67.js → chunk-6SLQLWWL.js} +26 -26
- package/dist/cli/{chunk-ZUAMXZXC.mjs → chunk-7XDJKIM2.mjs} +4 -4
- package/dist/cli/{chunk-C37VELBR.mjs → chunk-A6E7TCK2.mjs} +5 -5
- package/dist/cli/{chunk-JS2SBCWD.js → chunk-ADLDU2QG.js} +6 -6
- package/dist/cli/{chunk-VP2K5B3R.mjs → chunk-ALARRSMZ.mjs} +3 -3
- package/dist/cli/{chunk-CHIGEDAE.js → chunk-B2BTBHX2.js} +3 -3
- package/dist/cli/{chunk-CFND2ACL.js → chunk-BBS2BLPV.js} +16 -16
- package/dist/cli/{chunk-QDBGPRR2.mjs → chunk-CLO562KG.mjs} +3 -1
- package/dist/cli/{chunk-CXTW7SRW.mjs → chunk-E7D37PLM.mjs} +8 -0
- package/dist/cli/{chunk-UGA5KI4A.js → chunk-ESX3H7Q7.js} +22 -22
- package/dist/cli/{chunk-BFHR7IC2.mjs → chunk-FJ5KPGCS.mjs} +10 -10
- package/dist/cli/{chunk-R7JYG6XO.mjs → chunk-FWE37N2P.mjs} +1 -1
- package/dist/cli/{chunk-K4WJ4BYO.mjs → chunk-ICTA5ICE.mjs} +1 -1
- package/dist/cli/{chunk-PU42VOBI.js → chunk-IMLFB66A.js} +3 -3
- package/dist/cli/{chunk-GI3V4D7K.mjs → chunk-IP3XJTWA.mjs} +2 -2
- package/dist/cli/{chunk-WBFOV5HT.js → chunk-JCLRSMUP.js} +5 -5
- package/dist/cli/{chunk-L3JVGNAT.mjs → chunk-JPEBKN3K.mjs} +2 -2
- package/dist/cli/{chunk-Z2PPB3IO.mjs → chunk-JTOV5RUA.mjs} +1 -1
- package/dist/cli/{chunk-WBTYWJLN.js → chunk-KCUQNH4K.js} +2 -2
- package/dist/cli/{chunk-C3XD2WHM.mjs → chunk-KNIYEZVV.mjs} +2 -2
- package/dist/cli/{chunk-3PMCQ3LK.js → chunk-LPTBHNGB.js} +7 -5
- package/dist/cli/{chunk-KH27B2HJ.mjs → chunk-M3NCXGNN.mjs} +2 -2
- package/dist/cli/{chunk-XDS26J7Z.js → chunk-MNBIGX6O.js} +10 -10
- package/dist/cli/{chunk-L6QAIZNZ.js → chunk-MYSPQUAO.js} +44 -44
- package/dist/cli/{chunk-W3J3LT22.mjs → chunk-N2BCPZVR.mjs} +5 -5
- package/dist/cli/{chunk-ZFSB7GXF.js → chunk-N5HSG4OV.js} +5 -5
- package/dist/cli/{chunk-2Q7VXTMS.js → chunk-O765M4LT.js} +2 -2
- package/dist/cli/{chunk-QPDLG7DQ.js → chunk-OOLBE6FR.js} +53 -53
- package/dist/cli/{chunk-IQOIT6E3.js → chunk-P3DP56HB.js} +41 -41
- package/dist/cli/{chunk-BGXEMTIG.js → chunk-PQKD5DMT.js} +19 -19
- package/dist/cli/{chunk-V5IIBG2E.mjs → chunk-T6GPTJ5F.mjs} +1 -1
- package/dist/cli/{chunk-GPMS6OPX.mjs → chunk-TWWYCJJW.mjs} +5 -5
- package/dist/cli/{chunk-ZHPSJ3LJ.mjs → chunk-UE7JHAZ2.mjs} +29 -16
- package/dist/cli/{chunk-VRYX2BR4.js → chunk-UEZNIPFO.js} +107 -107
- package/dist/cli/{chunk-AX2OAXDL.mjs → chunk-VCHV4LS3.mjs} +1 -1
- package/dist/cli/{chunk-NXGLJGPB.js → chunk-VIFLWQXS.js} +2 -2
- package/dist/cli/{chunk-6BBGUQJJ.js → chunk-XTYHZEJ2.js} +8 -0
- package/dist/cli/{chunk-5EOEJKSV.js → chunk-YQURGSRB.js} +1 -1
- package/dist/cli/{chunk-ALHKB3AE.js → chunk-YZ2ZPHWR.js} +9 -9
- package/dist/cli/{chunk-CGDW2CRR.mjs → chunk-ZDLDCXY3.mjs} +2 -2
- package/dist/cli/{chunk-RMVZTBI5.mjs → chunk-ZU6JBRV5.mjs} +4 -4
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-HZP6QMG7.mjs → csv-2YKLUKDR.mjs} +4 -4
- package/dist/cli/{csv-JITYN27L.js → csv-LM7FBECI.js} +13 -13
- package/dist/cli/{db-QRIRTOMM.mjs → db-234UBWJH.mjs} +6 -6
- package/dist/cli/{db-FYSRB7O4.js → db-5PMA4IVW.js} +27 -27
- package/dist/cli/describe-C7GOSGYB.js +49 -0
- package/dist/cli/{describe-REXJVJC3.mjs → describe-W26LW5O7.mjs} +17 -17
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/{executions-BSTF4DDS.js → executions-3S736GXX.js} +8 -8
- package/dist/cli/{executions-53KJAFOW.mjs → executions-GD7GXTJM.mjs} +6 -6
- package/dist/cli/{feedback-6MW3QOXX.js → feedback-BUWTDY4R.js} +14 -14
- package/dist/cli/{feedback-CWUJJF3J.mjs → feedback-GBV5HJJZ.mjs} +6 -6
- package/dist/cli/git-YG36MROC.js +25 -0
- package/dist/cli/{git-CKVZTJFS.mjs → git-YXJGTDQL.mjs} +5 -5
- package/dist/cli/index.js +143 -143
- package/dist/cli/index.mjs +42 -42
- package/dist/cli/{legacy-noops-USTBRFRX.mjs → legacy-noops-UJM6GBNP.mjs} +6 -6
- package/dist/cli/{legacy-noops-QBL4PNGB.js → legacy-noops-ZSF64V2U.js} +9 -9
- package/dist/cli/{monitors-6UCG5D7W.mjs → monitors-UERUQ6CT.mjs} +7 -7
- package/dist/cli/{monitors-VCR6SUZD.js → monitors-XQ2GNH6D.js} +100 -100
- package/dist/cli/{org-GSRBOJVO.mjs → org-CP4VLH6M.mjs} +6 -6
- package/dist/cli/{org-HPILTEG4.js → org-IF6MPVNR.js} +86 -86
- package/dist/cli/{play-TK7WOP5H.js → play-2NHQO5MO.js} +317 -317
- package/dist/cli/{play-QRTYQNG4.mjs → play-ZWDYYVPI.mjs} +17 -17
- package/dist/cli/{providers-OAQJWVBS.mjs → providers-2CVIATU4.mjs} +6 -6
- package/dist/cli/{providers-HEXNJ5QC.js → providers-LOPXQN56.js} +9 -9
- package/dist/cli/{quickstart-FFVHTPSP.mjs → quickstart-KVCFXLID.mjs} +4 -4
- package/dist/cli/{quickstart-PYZTFXZX.js → quickstart-N4WDEQZY.js} +6 -6
- package/dist/cli/{run-4DWJXJRO.js → run-BDT5LK3I.js} +42 -42
- package/dist/cli/{run-HLN6YYZH.mjs → run-RUXHYWLF.mjs} +22 -22
- package/dist/cli/search-ATDDVADT.js +32 -0
- package/dist/cli/{search-ZHRCXGEL.mjs → search-BFUTNPA5.mjs} +7 -7
- package/dist/cli/{search-output-2KY6PFDH.js → search-output-CTXI2QZU.js} +6 -6
- package/dist/cli/{search-output-N7QXACVK.mjs → search-output-WUGH4PZA.mjs} +4 -4
- package/dist/cli/{secrets-WXQ7XO5C.js → secrets-BZJZYFOU.js} +15 -15
- package/dist/cli/{secrets-FKMWBLHU.mjs → secrets-Z4XQVTC6.mjs} +6 -6
- package/dist/cli/sessions-HNU35AFM.js +22 -0
- package/dist/cli/{sessions-3YDTEDA5.mjs → sessions-VZXR3MQZ.mjs} +6 -6
- package/dist/cli/{settings-JTPASUZN.mjs → settings-VYEZFR4L.mjs} +12 -12
- package/dist/cli/{settings-67TWLQ6E.js → settings-WBYA4JMM.js} +85 -85
- package/dist/cli/{setup-KUERQJUX.js → setup-FS2RMSS2.js} +49 -49
- package/dist/cli/{setup-VYNGXUJ6.mjs → setup-H7KCI4SO.mjs} +9 -9
- package/dist/cli/skills-VPIURCAZ.js +36 -0
- package/dist/cli/{skills-KI4KYHH6.mjs → skills-YQNSJUUG.mjs} +7 -7
- package/dist/cli/tools-273GS5HU.js +56 -0
- package/dist/cli/{tools-UQDJS2RS.mjs → tools-ZF6SVEGW.mjs} +16 -16
- package/dist/cli/{update-7FQQUBOD.mjs → update-RKQNNJM4.mjs} +9 -9
- package/dist/cli/update-TOD3XY55.js +34 -0
- package/dist/cli/{views-JAM4MNNV.mjs → views-JHHOTWDU.mjs} +6 -6
- package/dist/cli/{views-MJK7JGZG.js → views-KN7FEDGT.js} +21 -21
- package/dist/cli/{workflow-AQPRIWQX.js → workflow-2WHSKTTV.js} +17 -17
- package/dist/cli/{workflow-TQRV5FGO.mjs → workflow-AAYLCLWA.mjs} +7 -7
- package/dist/{client-BlLYQDNo.d.mts → client-D0uDBybG.d.mts} +1 -1
- package/dist/{client-DSQlkIDO.d.ts → client-DZTnAv4B.d.ts} +1 -1
- package/dist/{client-core-rX7n2H8U.d.mts → client-core-BhWf8Y1b.d.mts} +15 -2
- package/dist/{client-core-CDwapXy5.d.ts → client-core-og3AP1LL.d.ts} +15 -2
- package/dist/{compiler-manifest-BHNC4RL-.d.ts → compiler-manifest-Bes3OVA3.d.mts} +1 -1
- package/dist/{compiler-manifest-BHNC4RL-.d.mts → compiler-manifest-Bes3OVA3.d.ts} +1 -1
- package/dist/{errors-lhtIWG5Z.d.ts → errors-BJm4lLWc.d.ts} +1 -1
- package/dist/{errors-D7sPXrvB.d.mts → errors-Dc5r42ks.d.mts} +1 -1
- package/dist/{index-CQTBHXHr.d.ts → index-BfV7mRPF.d.ts} +1 -1
- package/dist/{index-NaDZq2xf.d.mts → index-DTkiz_Ur.d.mts} +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 +120 -112
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- 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-Y2K2ZYYA.js +0 -43
- package/dist/cli/describe-LSOHOLFI.js +0 -49
- package/dist/cli/git-S7SWUZ3T.js +0 -25
- package/dist/cli/search-WERQBC6V.js +0 -32
- package/dist/cli/sessions-LXQ4Q6BS.js +0 -22
- package/dist/cli/skills-EFRLHY3F.js +0 -36
- package/dist/cli/tools-C3EIGFFP.js +0 -56
- package/dist/cli/update-KCY72RXH.js +0 -34
|
@@ -165,11 +165,33 @@ import {
|
|
|
165
165
|
import { CTX_FETCH_EGRESS_TOOL_ID } from './builtin-pacing';
|
|
166
166
|
import {
|
|
167
167
|
legacyRawFromToolResponseRawV2,
|
|
168
|
-
providerMetaFromToolResponseRawV2,
|
|
169
168
|
RAW_V2_TOOL_RESPONSE_CONTRACT,
|
|
170
169
|
type ToolResponseContract,
|
|
171
|
-
type ToolResponseView,
|
|
172
170
|
} from '../plays/tool-response-contract';
|
|
171
|
+
import {
|
|
172
|
+
buildLiveToolExecuteResult,
|
|
173
|
+
EXECUTION_GATEWAY_RECEIPT_FINISH_HEADER,
|
|
174
|
+
parseRuntimeReceiptFinishAck,
|
|
175
|
+
encodeRuntimeReceiptFinishPlan,
|
|
176
|
+
RUNTIME_RECEIPT_FINISH_PLAN_HEADER,
|
|
177
|
+
runtimeReceiptFinishAckCovers,
|
|
178
|
+
toolResultCompletedAtMs,
|
|
179
|
+
type RuntimeReceiptFinishPlan,
|
|
180
|
+
} from './runtime-receipt-finish';
|
|
181
|
+
import {
|
|
182
|
+
createRuntimeReadThroughGrant,
|
|
183
|
+
encodeRuntimeReadThroughKeys,
|
|
184
|
+
isReadThroughExecuteReceiverUnavailable,
|
|
185
|
+
isReadThroughUnavailable,
|
|
186
|
+
isRuntimeReadThroughFallback,
|
|
187
|
+
parseRuntimeReadThroughHit,
|
|
188
|
+
rememberReadThroughUnavailable,
|
|
189
|
+
RUNTIME_READ_THROUGH_KEYS_HEADER,
|
|
190
|
+
RuntimeReadThroughFallback,
|
|
191
|
+
runtimeReadThroughOutcome,
|
|
192
|
+
TOOL_EXECUTE_READ_THROUGH_PATH_SUFFIX,
|
|
193
|
+
type RuntimeReadThroughGrant,
|
|
194
|
+
} from './runtime-read-through';
|
|
173
195
|
import {
|
|
174
196
|
AllAdmittedRowsFailedError,
|
|
175
197
|
isProviderExhaustedFailure,
|
|
@@ -1723,70 +1745,6 @@ const NO_SECRET_RESOLUTION_RETRY: SecretResolutionRetryDecision = {
|
|
|
1723
1745
|
retryAfterExceedsCap: false,
|
|
1724
1746
|
};
|
|
1725
1747
|
|
|
1726
|
-
function publicToolResponseEnvelope(value: unknown): {
|
|
1727
|
-
status: string;
|
|
1728
|
-
raw: unknown;
|
|
1729
|
-
rawV2?: unknown;
|
|
1730
|
-
view?: ToolResponseView;
|
|
1731
|
-
meta?: Record<string, unknown>;
|
|
1732
|
-
} | null {
|
|
1733
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1734
|
-
return null;
|
|
1735
|
-
}
|
|
1736
|
-
const record = value as Record<string, unknown>;
|
|
1737
|
-
if (typeof record.status !== 'string') return null;
|
|
1738
|
-
const toolResponse = record.toolResponse;
|
|
1739
|
-
if (
|
|
1740
|
-
!toolResponse ||
|
|
1741
|
-
typeof toolResponse !== 'object' ||
|
|
1742
|
-
Array.isArray(toolResponse)
|
|
1743
|
-
) {
|
|
1744
|
-
return null;
|
|
1745
|
-
}
|
|
1746
|
-
const response = toolResponse as Record<string, unknown>;
|
|
1747
|
-
const rawV2 = Object.prototype.hasOwnProperty.call(response, 'rawV2')
|
|
1748
|
-
? response.rawV2
|
|
1749
|
-
: undefined;
|
|
1750
|
-
const view =
|
|
1751
|
-
response.view === 'data' || response.view === 'rawV2'
|
|
1752
|
-
? response.view
|
|
1753
|
-
: undefined;
|
|
1754
|
-
if (
|
|
1755
|
-
!Object.prototype.hasOwnProperty.call(response, 'raw') &&
|
|
1756
|
-
rawV2 === undefined
|
|
1757
|
-
) {
|
|
1758
|
-
return null;
|
|
1759
|
-
}
|
|
1760
|
-
const providerMeta = providerMetaFromToolResponseRawV2(
|
|
1761
|
-
rawV2,
|
|
1762
|
-
view ?? 'rawV2',
|
|
1763
|
-
);
|
|
1764
|
-
const toolResponseMeta =
|
|
1765
|
-
response.meta &&
|
|
1766
|
-
typeof response.meta === 'object' &&
|
|
1767
|
-
!Array.isArray(response.meta)
|
|
1768
|
-
? (response.meta as Record<string, unknown>)
|
|
1769
|
-
: {};
|
|
1770
|
-
const responseMeta =
|
|
1771
|
-
response.responseMeta &&
|
|
1772
|
-
typeof response.responseMeta === 'object' &&
|
|
1773
|
-
!Array.isArray(response.responseMeta)
|
|
1774
|
-
? (response.responseMeta as Record<string, unknown>)
|
|
1775
|
-
: {};
|
|
1776
|
-
return {
|
|
1777
|
-
status: record.status,
|
|
1778
|
-
raw: Object.prototype.hasOwnProperty.call(response, 'raw')
|
|
1779
|
-
? response.raw
|
|
1780
|
-
: legacyRawFromToolResponseRawV2(rawV2, view ?? 'rawV2', responseMeta),
|
|
1781
|
-
...(rawV2 !== undefined ? { rawV2 } : {}),
|
|
1782
|
-
...(view ? { view } : {}),
|
|
1783
|
-
...(Object.keys({ ...toolResponseMeta, ...providerMeta, ...responseMeta })
|
|
1784
|
-
.length > 0
|
|
1785
|
-
? { meta: { ...toolResponseMeta, ...providerMeta, ...responseMeta } }
|
|
1786
|
-
: {}),
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
1748
|
function nativeBatchResponseMeta(result: unknown): Record<string, unknown> {
|
|
1791
1749
|
return {
|
|
1792
1750
|
nativeBatchResponseView:
|
|
@@ -1977,6 +1935,9 @@ function toolAttemptOutcomeForResult(
|
|
|
1977
1935
|
return record.status === 'no_result' ? 'no_result' : 'completed';
|
|
1978
1936
|
}
|
|
1979
1937
|
|
|
1938
|
+
/** A tool node a fallen-back read-through attempt started and left open. */
|
|
1939
|
+
type ReadThroughToolLifecycle = { openStartedAt: number | null };
|
|
1940
|
+
|
|
1980
1941
|
function isControlledPlaySuspension(error: unknown): boolean {
|
|
1981
1942
|
return (
|
|
1982
1943
|
isPlayExecutionSuspendedError(error) ||
|
|
@@ -2279,6 +2240,18 @@ type ToolExecutionApiOptions = {
|
|
|
2279
2240
|
execution: ToolResultExecutionMetadata;
|
|
2280
2241
|
metadata: ToolResultMetadataInput;
|
|
2281
2242
|
} | null;
|
|
2243
|
+
/**
|
|
2244
|
+
* Finishing receipt writes the execution owner may commit inside this
|
|
2245
|
+
* execute request (finish-in-execute). Absent keeps the established wire.
|
|
2246
|
+
*/
|
|
2247
|
+
relayReceiptFinish?: { plan: RuntimeReceiptFinishPlan } | null;
|
|
2248
|
+
/**
|
|
2249
|
+
* Local-permit read-through: the caller skipped its receipt read and took
|
|
2250
|
+
* this dispatch's capacity without waiting. The first dispatch uses that
|
|
2251
|
+
* capacity on the relay's read-through action; until a relay answers that
|
|
2252
|
+
* it read and executed, every attempt stays on that action.
|
|
2253
|
+
*/
|
|
2254
|
+
readThrough?: RuntimeReadThroughGrant<RuntimeProviderPermit> | null;
|
|
2282
2255
|
/** The receipt key is a completed-result cache for this read-only call. */
|
|
2283
2256
|
completedResultCache?: boolean;
|
|
2284
2257
|
/** Runner-local projection required by this native batch's splitter. */
|
|
@@ -3249,6 +3222,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3249
3222
|
messageRef?: { channel: string; ts: string };
|
|
3250
3223
|
}> = [];
|
|
3251
3224
|
private processedRowCount = 0;
|
|
3225
|
+
/** New retained-result consumers in this runner invocation; recovery is excluded. */
|
|
3226
|
+
private reusableResultCalls = 0;
|
|
3227
|
+
private reuseCountSupported = true;
|
|
3252
3228
|
/**
|
|
3253
3229
|
* Sleep call positions are scoped per mapped row. A single global counter is
|
|
3254
3230
|
* not replay-stable when concurrent rows reach ctx.sleep in a different
|
|
@@ -4517,6 +4493,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4517
4493
|
publication: DeferredReceiptPublication,
|
|
4518
4494
|
replay?: FreshExecutionReplay,
|
|
4519
4495
|
) => Promise<T>;
|
|
4496
|
+
companionReceiptKeys?: readonly string[];
|
|
4497
|
+
readThrough?: {
|
|
4498
|
+
begin(keys: readonly string[]): Promise<RuntimeReadThroughGrant | null>;
|
|
4499
|
+
} | null;
|
|
4520
4500
|
completedAt?: (value: T) => number | undefined;
|
|
4521
4501
|
sharesResult?: (value: T) => boolean;
|
|
4522
4502
|
eligibleAnswer?: (value: T) => boolean;
|
|
@@ -4588,7 +4568,27 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4588
4568
|
}),
|
|
4589
4569
|
requestedStaleAfterSeconds: input.policy.requested,
|
|
4590
4570
|
effectiveStaleAfterSeconds: input.policy.effective,
|
|
4571
|
+
// An acknowledgement that does not cover the call's writes is safe
|
|
4572
|
+
// (the runner writes as before, insert-if-absent) but means the owner
|
|
4573
|
+
// and runner disagreed. Make that loud rather than silent.
|
|
4574
|
+
onRemoteFinish: (outcome) => {
|
|
4575
|
+
if (outcome === 'not_covered') {
|
|
4576
|
+
this.runtimeLog(
|
|
4577
|
+
JSON.stringify({
|
|
4578
|
+
event: 'finish_in_execute_not_covered',
|
|
4579
|
+
operation: input.operation,
|
|
4580
|
+
call_key: input.id,
|
|
4581
|
+
...(input.toolId ? { tool_id: input.toolId } : {}),
|
|
4582
|
+
}),
|
|
4583
|
+
{ level: 'warn' },
|
|
4584
|
+
);
|
|
4585
|
+
}
|
|
4586
|
+
},
|
|
4591
4587
|
store: this.durableReceiptExecutionStore(),
|
|
4588
|
+
...(input.companionReceiptKeys?.length
|
|
4589
|
+
? { companionReceiptKeys: input.companionReceiptKeys }
|
|
4590
|
+
: {}),
|
|
4591
|
+
...(input.readThrough ? { readThrough: input.readThrough } : {}),
|
|
4592
4592
|
completedAt: input.completedAt,
|
|
4593
4593
|
sharesResult: input.sharesResult,
|
|
4594
4594
|
eligibleAnswer: input.eligibleAnswer,
|
|
@@ -5536,6 +5536,70 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
5536
5536
|
}
|
|
5537
5537
|
}
|
|
5538
5538
|
|
|
5539
|
+
/**
|
|
5540
|
+
* The finish-in-execute plan for one direct call: the keys and inputs the
|
|
5541
|
+
* execution owner needs to build exactly the finishing writes this runner
|
|
5542
|
+
* would make. Built with the same functions the runner's own path uses.
|
|
5543
|
+
*/
|
|
5544
|
+
private async runtimeReceiptFinishPlan(input: {
|
|
5545
|
+
toolId: string;
|
|
5546
|
+
input: Record<string, unknown>;
|
|
5547
|
+
logicalCallId: string;
|
|
5548
|
+
executionAuthScopeDigest: string;
|
|
5549
|
+
resultReceiptKey: string;
|
|
5550
|
+
execution: ToolResultExecutionMetadata;
|
|
5551
|
+
targets: NonNullable<DeferredReceiptPublication['finishTargets']>;
|
|
5552
|
+
}): Promise<{ plan: RuntimeReceiptFinishPlan }> {
|
|
5553
|
+
const providerActionVersion =
|
|
5554
|
+
(await this.#options.getToolActionCacheVersion?.(input.toolId))?.trim() ??
|
|
5555
|
+
'';
|
|
5556
|
+
const [manifest] = this.sourceRunToolReceiptManifestCompletionInputs([
|
|
5557
|
+
{
|
|
5558
|
+
toolId: input.toolId,
|
|
5559
|
+
logicalCallId: input.logicalCallId,
|
|
5560
|
+
executionAuthScopeDigest: input.executionAuthScopeDigest,
|
|
5561
|
+
resultReceiptKey: input.resultReceiptKey,
|
|
5562
|
+
providerActionVersion,
|
|
5563
|
+
},
|
|
5564
|
+
]);
|
|
5565
|
+
return {
|
|
5566
|
+
plan: {
|
|
5567
|
+
tool_id: input.toolId,
|
|
5568
|
+
run_attempt: this.currentRunAttempt,
|
|
5569
|
+
execution_auth_scope_digest: input.executionAuthScopeDigest,
|
|
5570
|
+
result: {
|
|
5571
|
+
key: input.resultReceiptKey,
|
|
5572
|
+
execution: input.execution,
|
|
5573
|
+
metadata: await this.resolveToolResultMetadata(input.toolId),
|
|
5574
|
+
call_evidence_input: this.secretRedactor.redact(input.input),
|
|
5575
|
+
},
|
|
5576
|
+
...(manifest
|
|
5577
|
+
? {
|
|
5578
|
+
source_run_manifest: {
|
|
5579
|
+
key: manifest.key,
|
|
5580
|
+
output: manifest.output,
|
|
5581
|
+
},
|
|
5582
|
+
}
|
|
5583
|
+
: {}),
|
|
5584
|
+
operation: {
|
|
5585
|
+
key: input.targets.operationKey,
|
|
5586
|
+
...(input.targets.exactRequestOperationKey
|
|
5587
|
+
? { exact_request_key: input.targets.exactRequestOperationKey }
|
|
5588
|
+
: {}),
|
|
5589
|
+
fingerprints: { ...input.targets.fingerprints },
|
|
5590
|
+
},
|
|
5591
|
+
...(input.targets.reusable
|
|
5592
|
+
? {
|
|
5593
|
+
reusable: {
|
|
5594
|
+
prefix: input.targets.reusable.prefix,
|
|
5595
|
+
ttl_seconds: input.targets.reusable.ttlSeconds,
|
|
5596
|
+
},
|
|
5597
|
+
}
|
|
5598
|
+
: {}),
|
|
5599
|
+
},
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5539
5603
|
/**
|
|
5540
5604
|
* Same pointer as `persistSourceRunToolReceiptManifests`, handed to the
|
|
5541
5605
|
* freshness layer to publish in its finishing request. A failure to build
|
|
@@ -8842,50 +8906,28 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
8842
8906
|
)
|
|
8843
8907
|
: wrapped;
|
|
8844
8908
|
}
|
|
8845
|
-
|
|
8909
|
+
// Shared with the execution owner's remote finish, so a receipt it
|
|
8910
|
+
// commits is the receipt this wrapper would have produced.
|
|
8911
|
+
const metadata =
|
|
8912
|
+
input.metadata ?? (await this.resolveToolResultMetadata(input.toolId));
|
|
8913
|
+
const requestInput = input.requestInput;
|
|
8846
8914
|
const wrapped = await this.attachCustomerDbDatasetResult(
|
|
8847
8915
|
input.toolId,
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
status:
|
|
8916
|
+
requestInput,
|
|
8917
|
+
buildLiveToolExecuteResult({
|
|
8918
|
+
status: input.status,
|
|
8851
8919
|
jobId: input.jobId,
|
|
8852
|
-
result:
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
...(publicToolResult.meta ? { meta: publicToolResult.meta } : {}),
|
|
8856
|
-
}
|
|
8857
|
-
: input.result,
|
|
8858
|
-
response: publicToolResult
|
|
8859
|
-
? {
|
|
8860
|
-
...(Object.prototype.hasOwnProperty.call(
|
|
8861
|
-
publicToolResult,
|
|
8862
|
-
'rawV2',
|
|
8863
|
-
)
|
|
8864
|
-
? { rawV2: publicToolResult.rawV2 }
|
|
8865
|
-
: {}),
|
|
8866
|
-
...(publicToolResult.view ? { view: publicToolResult.view } : {}),
|
|
8867
|
-
...(publicToolResult.meta ? { meta: publicToolResult.meta } : {}),
|
|
8868
|
-
}
|
|
8869
|
-
: input.toolResponse,
|
|
8870
|
-
metadata:
|
|
8871
|
-
input.metadata ??
|
|
8872
|
-
(await this.resolveToolResultMetadata(input.toolId)),
|
|
8920
|
+
result: input.result,
|
|
8921
|
+
toolResponse: input.toolResponse,
|
|
8922
|
+
metadata,
|
|
8873
8923
|
execution: input.execution,
|
|
8874
|
-
meta:
|
|
8875
|
-
...input.meta,
|
|
8876
|
-
...(input.execution.source === 'live' &&
|
|
8877
|
-
input.requestInput &&
|
|
8878
|
-
!input.meta?.callEvidence
|
|
8879
|
-
? {
|
|
8880
|
-
callEvidence: {
|
|
8881
|
-
input: this.secretRedactor.redact(input.requestInput),
|
|
8882
|
-
providerRequestsUnavailable:
|
|
8883
|
-
'This response did not retain provider HTTP evidence.',
|
|
8884
|
-
},
|
|
8885
|
-
}
|
|
8886
|
-
: {}),
|
|
8887
|
-
},
|
|
8924
|
+
meta: input.meta,
|
|
8888
8925
|
billing: input.billing,
|
|
8926
|
+
...(requestInput
|
|
8927
|
+
? {
|
|
8928
|
+
callEvidenceInput: () => this.secretRedactor.redact(requestInput),
|
|
8929
|
+
}
|
|
8930
|
+
: {}),
|
|
8889
8931
|
}),
|
|
8890
8932
|
);
|
|
8891
8933
|
return input.receiptOutputRef
|
|
@@ -15062,6 +15104,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15062
15104
|
);
|
|
15063
15105
|
}
|
|
15064
15106
|
if (!this.usesExplicitFreshness) {
|
|
15107
|
+
this.reuseCountSupported = false;
|
|
15065
15108
|
return this.executeToolLegacyInternal(key, toolId, input, options);
|
|
15066
15109
|
}
|
|
15067
15110
|
const policy = resolveExplicitDurableCallPolicy(options ?? {});
|
|
@@ -15332,7 +15375,55 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15332
15375
|
: value;
|
|
15333
15376
|
}
|
|
15334
15377
|
|
|
15335
|
-
|
|
15378
|
+
const plannedResultReceiptKey = DURABLE_RUNS_ROLLOUT.toolResultCompanionRead
|
|
15379
|
+
? await this.plannedDirectToolResultReceiptKey(
|
|
15380
|
+
key,
|
|
15381
|
+
toolId,
|
|
15382
|
+
requestInput,
|
|
15383
|
+
{
|
|
15384
|
+
...options,
|
|
15385
|
+
force: true,
|
|
15386
|
+
},
|
|
15387
|
+
reservedCallIndex,
|
|
15388
|
+
)
|
|
15389
|
+
: null;
|
|
15390
|
+
// Local-permit read-through: an authored-0 direct call may hand its
|
|
15391
|
+
// receipt read to the execution relay when its dispatch capacity is
|
|
15392
|
+
// already on hand. Everything else keeps the read below.
|
|
15393
|
+
const readThrough =
|
|
15394
|
+
DURABLE_RUNS_ROLLOUT.localPermitReadThrough &&
|
|
15395
|
+
plannedResultReceiptKey &&
|
|
15396
|
+
policy.effective === 0 &&
|
|
15397
|
+
policy.requested === 0 &&
|
|
15398
|
+
!publishLatestOnRefresh &&
|
|
15399
|
+
(await this.toolReadThroughEligible(toolId, requestInput))
|
|
15400
|
+
? {
|
|
15401
|
+
begin: (keys: readonly string[]) =>
|
|
15402
|
+
this.beginToolReadThrough(toolId, keys),
|
|
15403
|
+
}
|
|
15404
|
+
: null;
|
|
15405
|
+
// A read-through attempt that falls back leaves its tool node started;
|
|
15406
|
+
// the same call's re-run settles it, or this caller does when the
|
|
15407
|
+
// freshness layer answers without running it again.
|
|
15408
|
+
const readThroughLifecycle: ReadThroughToolLifecycle | null = readThrough
|
|
15409
|
+
? { openStartedAt: null }
|
|
15410
|
+
: null;
|
|
15411
|
+
const settleOpenReadThroughLifecycle = (
|
|
15412
|
+
outcome: 'cached' | 'failed',
|
|
15413
|
+
error?: unknown,
|
|
15414
|
+
) => {
|
|
15415
|
+
const startedAt = readThroughLifecycle?.openStartedAt ?? null;
|
|
15416
|
+
if (startedAt === null) return;
|
|
15417
|
+
readThroughLifecycle!.openStartedAt = null;
|
|
15418
|
+
this.emitToolCallLifecycle('settled', toolId, normalizedKey, {
|
|
15419
|
+
outcome,
|
|
15420
|
+
durationMs: Date.now() - startedAt,
|
|
15421
|
+
...(error !== undefined
|
|
15422
|
+
? { error: this.formatRuntimeError(error) }
|
|
15423
|
+
: {}),
|
|
15424
|
+
});
|
|
15425
|
+
};
|
|
15426
|
+
const freshnessControlledCall = this.executeFreshnessControlledCall({
|
|
15336
15427
|
operation: 'tool',
|
|
15337
15428
|
id: normalizedKey,
|
|
15338
15429
|
semanticKey,
|
|
@@ -15346,20 +15437,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15346
15437
|
legacyOwnOccurrenceIdentities: once(
|
|
15347
15438
|
ownOccurrenceIdentities(options?.staleAfterSeconds),
|
|
15348
15439
|
),
|
|
15440
|
+
...(plannedResultReceiptKey
|
|
15441
|
+
? { companionReceiptKeys: [plannedResultReceiptKey] }
|
|
15442
|
+
: {}),
|
|
15443
|
+
...(readThrough ? { readThrough } : {}),
|
|
15349
15444
|
...(publishLatestOnRefresh
|
|
15350
15445
|
? { publishLatestOnRefresh: true as const }
|
|
15351
15446
|
: {}),
|
|
15352
|
-
|
|
15353
|
-
|
|
15354
|
-
const raw = value.toolResponse.raw as {
|
|
15355
|
-
operation?: { completed_at_ms?: unknown };
|
|
15356
|
-
} | null;
|
|
15357
|
-
const completedAt = raw?.operation?.completed_at_ms;
|
|
15358
|
-
return typeof completedAt === 'number' &&
|
|
15359
|
-
Number.isSafeInteger(completedAt)
|
|
15360
|
-
? completedAt
|
|
15361
|
-
: value._metadata.execution.completedAt;
|
|
15362
|
-
},
|
|
15447
|
+
// Shared with the execution owner's remote finish.
|
|
15448
|
+
completedAt: toolResultCompletedAtMs,
|
|
15363
15449
|
sharesResult: isCompletedSuccessfulAnswer,
|
|
15364
15450
|
eligibleAnswer: isCompletedSuccessfulAnswer,
|
|
15365
15451
|
execute: async (publication, replay) => {
|
|
@@ -15376,6 +15462,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15376
15462
|
publication,
|
|
15377
15463
|
reservedCallIndex,
|
|
15378
15464
|
replay?.freshInvocation ? freshLogicalCallId() : undefined,
|
|
15465
|
+
readThroughLifecycle ?? undefined,
|
|
15379
15466
|
);
|
|
15380
15467
|
if ((await this.resolveToolAuthScopeDigest(toolId)) !== authScope) {
|
|
15381
15468
|
throw new Error(
|
|
@@ -15386,6 +15473,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15386
15473
|
},
|
|
15387
15474
|
onOutcome: (value, freshness) => {
|
|
15388
15475
|
if (!isToolExecuteResult(value)) return value;
|
|
15476
|
+
if (freshness.source === 'reusable_result') {
|
|
15477
|
+
if (this.reusableResultCalls < Number.MAX_SAFE_INTEGER)
|
|
15478
|
+
this.reusableResultCalls += 1;
|
|
15479
|
+
else this.reuseCountSupported = false;
|
|
15480
|
+
}
|
|
15389
15481
|
if (freshness.source !== 'executed') {
|
|
15390
15482
|
const row = rowContext.getStore();
|
|
15391
15483
|
if (row?.fieldName && row.tableNamespace && row.rowKey) {
|
|
@@ -15474,6 +15566,21 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15474
15566
|
);
|
|
15475
15567
|
},
|
|
15476
15568
|
});
|
|
15569
|
+
if (!readThroughLifecycle) return freshnessControlledCall;
|
|
15570
|
+
try {
|
|
15571
|
+
const value = await freshnessControlledCall;
|
|
15572
|
+
settleOpenReadThroughLifecycle('cached');
|
|
15573
|
+
return value;
|
|
15574
|
+
} catch (error) {
|
|
15575
|
+
// A durable pause leaves the node open for the resumed attempt, as the
|
|
15576
|
+
// direct path does.
|
|
15577
|
+
if (isControlledPlaySuspension(error)) {
|
|
15578
|
+
readThroughLifecycle.openStartedAt = null;
|
|
15579
|
+
} else {
|
|
15580
|
+
settleOpenReadThroughLifecycle('failed', error);
|
|
15581
|
+
}
|
|
15582
|
+
throw error;
|
|
15583
|
+
}
|
|
15477
15584
|
}
|
|
15478
15585
|
|
|
15479
15586
|
/** The occurrence counter key of a tool request in its row/workflow scope. */
|
|
@@ -15498,6 +15605,140 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15498
15605
|
return `${this.currentExecutionScope.receipt.namespace}:${logicalCallScope}:${normalizedKey}:${toolRequestIdentity}`;
|
|
15499
15606
|
}
|
|
15500
15607
|
|
|
15608
|
+
/**
|
|
15609
|
+
* Whether a policy-0 direct call can use the relay's read-through action:
|
|
15610
|
+
* finish-in-execute is on, the relay has not refused the action, and the
|
|
15611
|
+
* call takes the plain direct execute path (no row, event wait, async
|
|
15612
|
+
* lifecycle, execution fence or dataset augmentation).
|
|
15613
|
+
*/
|
|
15614
|
+
private async toolReadThroughEligible(
|
|
15615
|
+
toolId: string,
|
|
15616
|
+
input: Record<string, unknown>,
|
|
15617
|
+
): Promise<boolean> {
|
|
15618
|
+
const relay = this.#options.executionGatewayBaseUrl?.trim();
|
|
15619
|
+
if (!DURABLE_RUNS_ROLLOUT.finishInExecute || !relay) return false;
|
|
15620
|
+
if (isReadThroughUnavailable(relay)) return false;
|
|
15621
|
+
if (rowContext.getStore() || this.pureMapExecutionActive) return false;
|
|
15622
|
+
if (isQueryResultDatasetTool(toolId)) return false;
|
|
15623
|
+
if (await this.#options.getIntegrationEventWaitHandler?.(toolId)) {
|
|
15624
|
+
return false;
|
|
15625
|
+
}
|
|
15626
|
+
if (await this.#options.getToolAsyncOperation?.(toolId)) return false;
|
|
15627
|
+
const retryPolicy = await this.#options
|
|
15628
|
+
.getToolRetryPolicy?.(toolId, input)
|
|
15629
|
+
.catch(() => null);
|
|
15630
|
+
return retryPolicy?.requiresExecutionFence !== true;
|
|
15631
|
+
}
|
|
15632
|
+
|
|
15633
|
+
/**
|
|
15634
|
+
* Take one dispatch's capacity without waiting, or nothing: a due permit
|
|
15635
|
+
* from the local rate block, an execution slot, a transport slot (live
|
|
15636
|
+
* calls) and the tool-call budget from the reserved block. Any miss returns
|
|
15637
|
+
* what was taken (the permit back to its block) and keeps today's read.
|
|
15638
|
+
*/
|
|
15639
|
+
private async beginToolReadThrough(
|
|
15640
|
+
toolId: string,
|
|
15641
|
+
keys: readonly string[],
|
|
15642
|
+
): Promise<RuntimeReadThroughGrant<RuntimeProviderPermit> | null> {
|
|
15643
|
+
const providerPermit = this.resourceGovernor.tryAcquireProviderPermit({
|
|
15644
|
+
toolId,
|
|
15645
|
+
});
|
|
15646
|
+
if (!providerPermit) return null;
|
|
15647
|
+
const fixture = this.#options.integrationMode === 'fixture';
|
|
15648
|
+
const executionSlot = this.resourceGovernor.tryAcquireExternalExecutionSlot(
|
|
15649
|
+
{
|
|
15650
|
+
providerResourceKey: `tool:${toolId}`,
|
|
15651
|
+
},
|
|
15652
|
+
);
|
|
15653
|
+
const integrationRequestLease =
|
|
15654
|
+
executionSlot && !fixture
|
|
15655
|
+
? this.resourceGovernor.tryAcquireIntegrationRequestSlot()
|
|
15656
|
+
: null;
|
|
15657
|
+
const budget =
|
|
15658
|
+
executionSlot && (fixture || integrationRequestLease)
|
|
15659
|
+
? this.resourceGovernor.tryChargeToolCall()
|
|
15660
|
+
: null;
|
|
15661
|
+
if (!executionSlot || !budget) {
|
|
15662
|
+
integrationRequestLease?.release();
|
|
15663
|
+
executionSlot?.release();
|
|
15664
|
+
await providerPermit.park();
|
|
15665
|
+
return null;
|
|
15666
|
+
}
|
|
15667
|
+
return createRuntimeReadThroughGrant({
|
|
15668
|
+
keys,
|
|
15669
|
+
providerPermit,
|
|
15670
|
+
executionSlot,
|
|
15671
|
+
integrationRequestLease,
|
|
15672
|
+
budget,
|
|
15673
|
+
});
|
|
15674
|
+
}
|
|
15675
|
+
|
|
15676
|
+
/**
|
|
15677
|
+
* The result receipt a direct (non-row) forced tool call claims first if it
|
|
15678
|
+
* executes, derived as `executeToolLegacyInternal` derives it for the call's
|
|
15679
|
+
* reserved index (or, unreserved, its next index without taking it). It rides the operation receipt's
|
|
15680
|
+
* read; the call uses that read only when the key it then allocates is the
|
|
15681
|
+
* same, otherwise it reads its own key as before. Null when the call would
|
|
15682
|
+
* not claim a result receipt this way.
|
|
15683
|
+
*/
|
|
15684
|
+
private async plannedDirectToolResultReceiptKey(
|
|
15685
|
+
key: string,
|
|
15686
|
+
toolId: string,
|
|
15687
|
+
input: Record<string, unknown>,
|
|
15688
|
+
options: ToolCallOptions,
|
|
15689
|
+
/** The occurrence the caller reserved with the operation slot (#10027). */
|
|
15690
|
+
reservedCallIndex: number | undefined,
|
|
15691
|
+
): Promise<string | null> {
|
|
15692
|
+
if (rowContext.getStore() || this.pureMapExecutionActive) return null;
|
|
15693
|
+
if (!this.durableDirectToolResultsBackedByReceipts) return null;
|
|
15694
|
+
if (
|
|
15695
|
+
toolId === 'run_javascript' ||
|
|
15696
|
+
isQueryResultDatasetReadRequest(toolId, input) ||
|
|
15697
|
+
isAlwaysFreshIntegrationTool(toolId)
|
|
15698
|
+
) {
|
|
15699
|
+
return null;
|
|
15700
|
+
}
|
|
15701
|
+
const toolCachePolicy = this.effectiveToolCallCachePolicy(options);
|
|
15702
|
+
if (!toolCachePolicy.force) return null;
|
|
15703
|
+
const normalizedKey = this.normalizeContextKey(key, 'tool');
|
|
15704
|
+
const callIndexKey = this.toolCallIndexKey(normalizedKey, toolId, input);
|
|
15705
|
+
const logicalCallId = stableDigest(
|
|
15706
|
+
`${callIndexKey}:${
|
|
15707
|
+
reservedCallIndex ?? this.toolCallIndexByKey.get(callIndexKey) ?? 0
|
|
15708
|
+
}`,
|
|
15709
|
+
);
|
|
15710
|
+
// The same memoized tool identity the call resolved before this.
|
|
15711
|
+
const executionAuthScopeDigest =
|
|
15712
|
+
(await this.resolveToolAuthScopeDigest(toolId))?.trim() ?? null;
|
|
15713
|
+
const invocationScoped =
|
|
15714
|
+
(await this.#options.getToolIdempotencyScope?.(toolId)) === 'invocation';
|
|
15715
|
+
const [primary] = await this.compatibleDurableToolCallCacheKeys({
|
|
15716
|
+
toolId,
|
|
15717
|
+
requestInput: input,
|
|
15718
|
+
executionAuthScopeDigest,
|
|
15719
|
+
staleAfterSeconds: toolCachePolicy.staleAfterSeconds,
|
|
15720
|
+
});
|
|
15721
|
+
if (!primary) return null;
|
|
15722
|
+
const resultReceiptKey = invocationScoped
|
|
15723
|
+
? scopeToolReceiptToInvocation({
|
|
15724
|
+
orgId: this.#options.orgId,
|
|
15725
|
+
toolId,
|
|
15726
|
+
receiptKey: primary,
|
|
15727
|
+
invocationIdentity: `${this.historyRunId}:${logicalCallId}`,
|
|
15728
|
+
})
|
|
15729
|
+
: primary;
|
|
15730
|
+
return resolveToolCallResultReceiptPolicy({
|
|
15731
|
+
orgId: this.#options.orgId,
|
|
15732
|
+
toolId,
|
|
15733
|
+
resultReceiptKey,
|
|
15734
|
+
runId: this.currentReceiptOwnerRunId,
|
|
15735
|
+
logicalCallId,
|
|
15736
|
+
force: true,
|
|
15737
|
+
canStoreResult: true,
|
|
15738
|
+
...(reservedCallIndex !== undefined ? { occurrenceBound: true } : {}),
|
|
15739
|
+
}).resultReceiptKey;
|
|
15740
|
+
}
|
|
15741
|
+
|
|
15501
15742
|
/**
|
|
15502
15743
|
* Next occurrence of an identical tool request. It names the call's
|
|
15503
15744
|
* logical identity (forced result receipt, provider operation key). A held
|
|
@@ -15538,6 +15779,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15538
15779
|
* receipt and provider operation key) for a fresh dispatch.
|
|
15539
15780
|
*/
|
|
15540
15781
|
logicalCallIdOverride?: string,
|
|
15782
|
+
/**
|
|
15783
|
+
* The tool node a fallen-back read-through attempt of this same call
|
|
15784
|
+
* already started. A re-run settles it instead of starting another.
|
|
15785
|
+
*/
|
|
15786
|
+
readThroughLifecycle?: ReadThroughToolLifecycle,
|
|
15541
15787
|
): Promise<unknown> {
|
|
15542
15788
|
if (!rowContext.getStore()) this.assertRowAdmissionOpen();
|
|
15543
15789
|
this.assertNoPendingDurableSuspension();
|
|
@@ -15569,6 +15815,19 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15569
15815
|
);
|
|
15570
15816
|
}
|
|
15571
15817
|
const normalizedKey = this.normalizeContextKey(key, 'tool');
|
|
15818
|
+
/**
|
|
15819
|
+
* Starts this call's tool node, unless a fallen-back read-through attempt
|
|
15820
|
+
* of the same call already did: then it returns that start time and this
|
|
15821
|
+
* run settles the node it left open.
|
|
15822
|
+
*/
|
|
15823
|
+
const startToolNode = (): number | null => {
|
|
15824
|
+
const carried = readThroughLifecycle?.openStartedAt ?? null;
|
|
15825
|
+
if (readThroughLifecycle) readThroughLifecycle.openStartedAt = null;
|
|
15826
|
+
if (carried === null) {
|
|
15827
|
+
this.emitToolCallLifecycle('started', toolId, normalizedKey);
|
|
15828
|
+
}
|
|
15829
|
+
return carried;
|
|
15830
|
+
};
|
|
15572
15831
|
const presentResult = (result: unknown): unknown =>
|
|
15573
15832
|
isToolExecuteResult(result) && !deferResponseMaterialization
|
|
15574
15833
|
? this.materializeToolExecutionResult(result)
|
|
@@ -15576,7 +15835,17 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15576
15835
|
const toolCachePolicy = this.effectiveToolCallCachePolicy(options);
|
|
15577
15836
|
const store = rowContext.getStore();
|
|
15578
15837
|
const callIndexKey = this.toolCallIndexKey(normalizedKey, toolId, input);
|
|
15838
|
+
// Only an unreserved index is taken here; a read-through fallback gives
|
|
15839
|
+
// that one back (a reserved index belongs to the operation slot).
|
|
15840
|
+
const indexBeforeCall =
|
|
15841
|
+
reservedCallIndex === undefined
|
|
15842
|
+
? this.toolCallIndexByKey.get(callIndexKey)
|
|
15843
|
+
: undefined;
|
|
15579
15844
|
const callIndex = reservedCallIndex ?? this.nextToolCallIndex(callIndexKey);
|
|
15845
|
+
const indexAfterCall =
|
|
15846
|
+
reservedCallIndex === undefined
|
|
15847
|
+
? this.toolCallIndexByKey.get(callIndexKey)
|
|
15848
|
+
: undefined;
|
|
15580
15849
|
const logicalCallId =
|
|
15581
15850
|
logicalCallIdOverride ?? stableDigest(`${callIndexKey}:${callIndex}`);
|
|
15582
15851
|
// Reserved with its operation slot (or a fresh replay identity): its forced
|
|
@@ -15584,10 +15853,33 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15584
15853
|
const occurrenceBound =
|
|
15585
15854
|
reservedCallIndex !== undefined || logicalCallIdOverride !== undefined;
|
|
15586
15855
|
this.resourceGovernor.recordLogicalToolCall();
|
|
15856
|
+
// A read-through attempt that falls back never happened: the same
|
|
15857
|
+
// logical call runs again, so it keeps this index and counts once.
|
|
15858
|
+
const unwindReadThrough = () => {
|
|
15859
|
+
if (
|
|
15860
|
+
indexAfterCall !== undefined &&
|
|
15861
|
+
this.toolCallIndexByKey.get(callIndexKey) === indexAfterCall
|
|
15862
|
+
) {
|
|
15863
|
+
if (indexBeforeCall === undefined) {
|
|
15864
|
+
this.toolCallIndexByKey.delete(callIndexKey);
|
|
15865
|
+
} else {
|
|
15866
|
+
this.toolCallIndexByKey.set(callIndexKey, indexBeforeCall);
|
|
15867
|
+
}
|
|
15868
|
+
}
|
|
15869
|
+
this.resourceGovernor.forgetLogicalToolCall();
|
|
15870
|
+
};
|
|
15871
|
+
if (publication?.readThrough && (store || this.pureMapExecutionActive)) {
|
|
15872
|
+
unwindReadThrough();
|
|
15873
|
+
throw new RuntimeReadThroughFallback('not_finishable');
|
|
15874
|
+
}
|
|
15587
15875
|
let executionAuthScopeDigest =
|
|
15588
15876
|
(await this.resolveToolAuthScopeDigest(toolId))?.trim() ?? null;
|
|
15589
15877
|
const eventWaitHandler =
|
|
15590
15878
|
(await this.#options.getIntegrationEventWaitHandler?.(toolId)) ?? null;
|
|
15879
|
+
if (publication?.readThrough && eventWaitHandler) {
|
|
15880
|
+
unwindReadThrough();
|
|
15881
|
+
throw new RuntimeReadThroughFallback('not_finishable');
|
|
15882
|
+
}
|
|
15591
15883
|
const invocationScoped =
|
|
15592
15884
|
!eventWaitHandler &&
|
|
15593
15885
|
(await this.#options.getToolIdempotencyScope?.(toolId)) === 'invocation';
|
|
@@ -15698,7 +15990,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15698
15990
|
this.runtimeLog(
|
|
15699
15991
|
`Calling tool: ${toolId} recovered from source run ${this.#options.replayedFromRunId}`,
|
|
15700
15992
|
);
|
|
15701
|
-
|
|
15993
|
+
startToolNode();
|
|
15702
15994
|
this.emitToolCallLifecycle('settled', toolId, normalizedKey, {
|
|
15703
15995
|
outcome: 'cached',
|
|
15704
15996
|
durationMs: 0,
|
|
@@ -15740,7 +16032,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15740
16032
|
// Started and settled are paired in a finally: an uncovered throw
|
|
15741
16033
|
// between them strands the tool node `running` forever in the
|
|
15742
16034
|
// snapshot, which is exactly the lossy state ADR 0018 removed.
|
|
15743
|
-
|
|
16035
|
+
startToolNode();
|
|
15744
16036
|
let settled = false;
|
|
15745
16037
|
try {
|
|
15746
16038
|
const recovered = await this.wrapToolExecutionResult({
|
|
@@ -15951,8 +16243,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15951
16243
|
);
|
|
15952
16244
|
// ADR 0018: the tool node's lifecycle is an explicit typed event, not a
|
|
15953
16245
|
// regex over this log line.
|
|
15954
|
-
const directCallStartedAt = Date.now();
|
|
15955
|
-
this.emitToolCallLifecycle('started', toolId, normalizedKey);
|
|
16246
|
+
const directCallStartedAt = startToolNode() ?? Date.now();
|
|
15956
16247
|
// Settled exactly once, including on paths that throw before the
|
|
15957
16248
|
// explicit settle below (result wrapping, receipt-ownership failures,
|
|
15958
16249
|
// authoring validation). `executeDirectToolCall` settles its own
|
|
@@ -16030,12 +16321,54 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16030
16321
|
'Direct Tool Call operation identity changed in transit.',
|
|
16031
16322
|
);
|
|
16032
16323
|
}
|
|
16324
|
+
// Finish-in-execute: the relay may commit this call's result,
|
|
16325
|
+
// replay pointer and operation receipts in the execute request.
|
|
16326
|
+
// Only for the immutable completed-cache path the freshness
|
|
16327
|
+
// layer publishes; a fenced call keeps its lock-held write.
|
|
16328
|
+
const relayReceiptFinish =
|
|
16329
|
+
DURABLE_RUNS_ROLLOUT.finishInExecute &&
|
|
16330
|
+
useDirectResultReceipts &&
|
|
16331
|
+
!resultReceiptPolicy.force &&
|
|
16332
|
+
toolRetryPolicy?.requiresExecutionFence !== true &&
|
|
16333
|
+
!isQueryResultDatasetTool(toolId) &&
|
|
16334
|
+
publication?.finishTargets &&
|
|
16335
|
+
publication.acknowledgeRemoteFinish &&
|
|
16336
|
+
executionAuthScopeDigest &&
|
|
16337
|
+
this.#options.executionGatewayBaseUrl?.trim()
|
|
16338
|
+
? await this.runtimeReceiptFinishPlan({
|
|
16339
|
+
toolId,
|
|
16340
|
+
input,
|
|
16341
|
+
logicalCallId,
|
|
16342
|
+
executionAuthScopeDigest,
|
|
16343
|
+
resultReceiptKey: resultReceiptPolicy.resultReceiptKey,
|
|
16344
|
+
execution: toolExecutionMetadataForOutcome({
|
|
16345
|
+
kind: 'live',
|
|
16346
|
+
cacheKey: directCacheKey,
|
|
16347
|
+
receiptKey: resultReceiptKey,
|
|
16348
|
+
}),
|
|
16349
|
+
targets: publication.finishTargets,
|
|
16350
|
+
})
|
|
16351
|
+
: null;
|
|
16352
|
+
// A read-through attempt skipped the sandbox's receipt read. It
|
|
16353
|
+
// may execute only on the relay's read-through action, which
|
|
16354
|
+
// finishes in the same request and so needs the plan.
|
|
16355
|
+
if (publication?.readThrough && !relayReceiptFinish) {
|
|
16356
|
+
throw new RuntimeReadThroughFallback('not_finishable');
|
|
16357
|
+
}
|
|
16033
16358
|
const execution = await this.executeDirectToolCall({
|
|
16034
16359
|
toolId,
|
|
16035
16360
|
callKey: normalizedKey,
|
|
16036
16361
|
startedAt: directCallStartedAt,
|
|
16037
16362
|
input,
|
|
16038
16363
|
options: {
|
|
16364
|
+
...(relayReceiptFinish ? { relayReceiptFinish } : {}),
|
|
16365
|
+
...(relayReceiptFinish && publication?.readThrough
|
|
16366
|
+
? {
|
|
16367
|
+
// Minted by this context's `beginToolReadThrough`.
|
|
16368
|
+
readThrough:
|
|
16369
|
+
publication.readThrough as RuntimeReadThroughGrant<RuntimeProviderPermit>,
|
|
16370
|
+
}
|
|
16371
|
+
: {}),
|
|
16039
16372
|
...(options?.retry ? { retry: options.retry } : {}),
|
|
16040
16373
|
...(useDirectResultReceipts
|
|
16041
16374
|
? {
|
|
@@ -16083,6 +16416,16 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16083
16416
|
),
|
|
16084
16417
|
},
|
|
16085
16418
|
});
|
|
16419
|
+
const finishAck = relayReceiptFinish
|
|
16420
|
+
? execution.receiptFinishAck
|
|
16421
|
+
: undefined;
|
|
16422
|
+
if (finishAck) {
|
|
16423
|
+
publication?.acknowledgeRemoteFinish?.({
|
|
16424
|
+
completedAtMs: finishAck.completedAtMs,
|
|
16425
|
+
covers: (writes) =>
|
|
16426
|
+
runtimeReceiptFinishAckCovers(finishAck, writes),
|
|
16427
|
+
});
|
|
16428
|
+
}
|
|
16086
16429
|
return await this.wrapToolExecutionResult({
|
|
16087
16430
|
toolId,
|
|
16088
16431
|
status: execution.status,
|
|
@@ -16104,6 +16447,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16104
16447
|
});
|
|
16105
16448
|
},
|
|
16106
16449
|
};
|
|
16450
|
+
// Read in the operation receipt's request when its key matches.
|
|
16451
|
+
const prefetchedResultReceipt =
|
|
16452
|
+
useDirectResultReceipts && initialDirectReceipt === undefined
|
|
16453
|
+
? publication?.takeCompanionReceipt?.(
|
|
16454
|
+
resultReceiptPolicy.resultReceiptKey,
|
|
16455
|
+
)
|
|
16456
|
+
: undefined;
|
|
16107
16457
|
const toolCall = useDirectResultReceipts
|
|
16108
16458
|
? createToolCallJob({
|
|
16109
16459
|
resultReceipts: createRuntimeStepToolResultReceipts({
|
|
@@ -16116,7 +16466,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16116
16466
|
receipt: initialDirectReceipt,
|
|
16117
16467
|
},
|
|
16118
16468
|
}
|
|
16119
|
-
:
|
|
16469
|
+
: prefetchedResultReceipt
|
|
16470
|
+
? {
|
|
16471
|
+
initialReceipt: {
|
|
16472
|
+
key: resultReceiptPolicy.resultReceiptKey,
|
|
16473
|
+
receipt: prefetchedResultReceipt.receipt,
|
|
16474
|
+
},
|
|
16475
|
+
}
|
|
16476
|
+
: {}),
|
|
16120
16477
|
withCompletedReceiptHydration: (hydrate) =>
|
|
16121
16478
|
this.withRuntimeReceiptHydrationTurn(hydrate, {
|
|
16122
16479
|
source: 'direct_tool_result_receipt',
|
|
@@ -16238,6 +16595,19 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
16238
16595
|
}
|
|
16239
16596
|
return presentResult(wrapped);
|
|
16240
16597
|
} catch (error) {
|
|
16598
|
+
if (isRuntimeReadThroughFallback(error)) {
|
|
16599
|
+
// Nothing executed. A hit was served from receipts; any other
|
|
16600
|
+
// fallback runs this same call again through today's read.
|
|
16601
|
+
unwindReadThrough();
|
|
16602
|
+
if (readThroughLifecycle) {
|
|
16603
|
+
// Settled exactly once: by this call's re-run, or by the
|
|
16604
|
+
// caller when the freshness layer answers from receipts.
|
|
16605
|
+
directSettled = true;
|
|
16606
|
+
readThroughLifecycle.openStartedAt = directCallStartedAt;
|
|
16607
|
+
} else if (error.reason === 'hit') settleDirectCall('cached');
|
|
16608
|
+
else directSettled = true;
|
|
16609
|
+
throw error;
|
|
16610
|
+
}
|
|
16241
16611
|
if (isControlledPlaySuspension(error)) {
|
|
16242
16612
|
// A durable pause is not a terminal tool failure. Leave the start
|
|
16243
16613
|
// event open so the resumed attempt can settle the same node.
|
|
@@ -18772,8 +19142,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
18772
19142
|
logicalCalls: number;
|
|
18773
19143
|
providerRequests: number;
|
|
18774
19144
|
provider429s: number;
|
|
19145
|
+
reusableResultCalls?: number;
|
|
18775
19146
|
} {
|
|
18776
|
-
return
|
|
19147
|
+
return {
|
|
19148
|
+
...this.resourceGovernor.workCounters(),
|
|
19149
|
+
...(this.reuseCountSupported && this.usesExplicitFreshness
|
|
19150
|
+
? { reusableResultCalls: this.reusableResultCalls }
|
|
19151
|
+
: {}),
|
|
19152
|
+
};
|
|
18777
19153
|
}
|
|
18778
19154
|
|
|
18779
19155
|
/**
|
|
@@ -21671,6 +22047,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
21671
22047
|
// lifecycle key; it is not a general retry counter.
|
|
21672
22048
|
let providerRateLimitRetryFromInvocationAttempt: number | null =
|
|
21673
22049
|
savedProviderRetryCursor?.retryFromInvocationAttempt ?? null;
|
|
22050
|
+
// Finish-in-execute travels as a bounded header so the execute body
|
|
22051
|
+
// stays byte-identical. Same boundary as the relay output: the owner
|
|
22052
|
+
// can only finish the body it returns, never a runtime-polled one.
|
|
22053
|
+
const receiptFinishPlanHeader =
|
|
22054
|
+
options?.relayReceiptFinish &&
|
|
22055
|
+
!shouldResolveAsyncOperationInRuntime &&
|
|
22056
|
+
this.#options.executionGatewayBaseUrl?.trim()
|
|
22057
|
+
? encodeRuntimeReceiptFinishPlan(options.relayReceiptFinish.plan)
|
|
22058
|
+
: null;
|
|
21674
22059
|
// Set when a parked fenced call resumes: its Durable requeue claim.
|
|
21675
22060
|
let callRequeueWire: {
|
|
21676
22061
|
fromInvocationAttempt: number;
|
|
@@ -22227,6 +22612,41 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22227
22612
|
return permit;
|
|
22228
22613
|
};
|
|
22229
22614
|
|
|
22615
|
+
// Local-permit read-through: the caller did not read this call's
|
|
22616
|
+
// receipts. It may execute only on the relay's read-through action,
|
|
22617
|
+
// which reads them first; a call that cannot use that action goes
|
|
22618
|
+
// back to the caller's own read before any dispatch.
|
|
22619
|
+
const readThroughGrant = options?.readThrough ?? null;
|
|
22620
|
+
const readThroughKeysHeader = readThroughGrant
|
|
22621
|
+
? encodeRuntimeReadThroughKeys(readThroughGrant.keys)
|
|
22622
|
+
: null;
|
|
22623
|
+
if (
|
|
22624
|
+
readThroughGrant &&
|
|
22625
|
+
(!readThroughKeysHeader ||
|
|
22626
|
+
!receiptFinishPlanHeader ||
|
|
22627
|
+
usesDurableInvocationFence ||
|
|
22628
|
+
asyncExecutionRecovery ||
|
|
22629
|
+
shouldWaitForAsyncOperation ||
|
|
22630
|
+
shouldResolveAsyncOperationInRuntime ||
|
|
22631
|
+
!this.#options.executionGatewayBaseUrl?.trim() ||
|
|
22632
|
+
isReadThroughUnavailable(executionBaseUrl))
|
|
22633
|
+
) {
|
|
22634
|
+
throw new RuntimeReadThroughFallback('not_finishable');
|
|
22635
|
+
}
|
|
22636
|
+
// Until a relay answers that it read nothing and executed, every
|
|
22637
|
+
// attempt (including a transport retry) stays on that action.
|
|
22638
|
+
let readThroughPending = readThroughGrant !== null;
|
|
22639
|
+
// An earlier read-through attempt was sent without a definite answer
|
|
22640
|
+
// (a lost response or transport failure). It may have executed, so a
|
|
22641
|
+
// later hit does not prove this call's budget went unused.
|
|
22642
|
+
let readThroughEarlierAttemptMayHaveRun = false;
|
|
22643
|
+
let readThroughAttemptsSent = 0;
|
|
22644
|
+
if (readThroughGrant) {
|
|
22645
|
+
// The grant already charged this logical call from the block.
|
|
22646
|
+
readThroughGrant.markChargeUsed();
|
|
22647
|
+
toolCallCharged = true;
|
|
22648
|
+
}
|
|
22649
|
+
|
|
22230
22650
|
// Charge the logical call before entering the physical-attempt
|
|
22231
22651
|
// transport loop. A budget breach is a run-control outcome, never a
|
|
22232
22652
|
// transport failure that may be retried or row-isolated.
|
|
@@ -22278,6 +22698,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22278
22698
|
let fetchDispatched = false;
|
|
22279
22699
|
let dispatchedWithProviderPermit = false;
|
|
22280
22700
|
let providerPermitReceiverRejected = false;
|
|
22701
|
+
/** Set when the relay definitely did no provider work. */
|
|
22702
|
+
let readThroughFallback: RuntimeReadThroughFallback | null = null;
|
|
22703
|
+
const readThroughDispatch = readThroughPending;
|
|
22704
|
+
if (readThroughDispatch && readThroughAttemptsSent > 0) {
|
|
22705
|
+
readThroughEarlierAttemptMayHaveRun = true;
|
|
22706
|
+
}
|
|
22281
22707
|
let providerDispatchCounted = false;
|
|
22282
22708
|
let providerPacingWaitRefusedDispatch = false;
|
|
22283
22709
|
const recordProviderDispatch = () => {
|
|
@@ -22423,6 +22849,16 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22423
22849
|
signal,
|
|
22424
22850
|
}),
|
|
22425
22851
|
});
|
|
22852
|
+
const preAdmitted =
|
|
22853
|
+
readThroughGrant?.takeDispatchCapacity() ?? null;
|
|
22854
|
+
if (preAdmitted) {
|
|
22855
|
+
const permit = preAdmitted.providerPermit;
|
|
22856
|
+
providerConcurrencyGrant = permit.concurrencyGrant ?? null;
|
|
22857
|
+
providerPacingGrant = permit.pacingGrant ?? null;
|
|
22858
|
+
providerGatewayDispatchProof =
|
|
22859
|
+
permit.gatewayDispatchProof ?? null;
|
|
22860
|
+
providerTelemetryKey = permit.provider;
|
|
22861
|
+
}
|
|
22426
22862
|
const dispatched = await dispatchFlow.run(
|
|
22427
22863
|
{
|
|
22428
22864
|
providerResourceKey: `tool:${toolId}`,
|
|
@@ -22431,6 +22867,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22431
22867
|
deferProviderPermitValidation: true,
|
|
22432
22868
|
providerDispatchAtGateway:
|
|
22433
22869
|
!providerPermitReceiverUnavailable,
|
|
22870
|
+
...(preAdmitted ? { preAdmitted } : {}),
|
|
22434
22871
|
onTransportAdmitted: (waitMs) => {
|
|
22435
22872
|
transportSlotWaitMs = waitMs;
|
|
22436
22873
|
},
|
|
@@ -22630,7 +23067,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22630
23067
|
!providerPermitReceiverUnavailable &&
|
|
22631
23068
|
providerGatewayDispatchProof?.dispatchValidationSupported ===
|
|
22632
23069
|
true;
|
|
22633
|
-
if (
|
|
23070
|
+
if (
|
|
23071
|
+
!dispatchedWithProviderPermit &&
|
|
23072
|
+
!readThroughDispatch
|
|
23073
|
+
)
|
|
22634
23074
|
recordProviderDispatch();
|
|
22635
23075
|
const dispatchPhaseClock =
|
|
22636
23076
|
toolCallPhaseClock.getStore();
|
|
@@ -22640,10 +23080,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22640
23080
|
dispatchPhaseClock.providerDispatches += 1;
|
|
22641
23081
|
dispatchPhaseClock.lastResponseParsedAt = null;
|
|
22642
23082
|
}
|
|
23083
|
+
if (readThroughDispatch) readThroughAttemptsSent += 1;
|
|
22643
23084
|
const dispatchedResponse = await fetch(
|
|
22644
|
-
|
|
22645
|
-
? `${url}${
|
|
22646
|
-
:
|
|
23085
|
+
readThroughDispatch
|
|
23086
|
+
? `${url}${TOOL_EXECUTE_READ_THROUGH_PATH_SUFFIX}`
|
|
23087
|
+
: dispatchedWithProviderPermit
|
|
23088
|
+
? `${url}${TOOL_EXECUTE_PROVIDER_PERMIT_PATH_SUFFIX}`
|
|
23089
|
+
: url,
|
|
22647
23090
|
{
|
|
22648
23091
|
method: 'POST',
|
|
22649
23092
|
// A followed redirect could fail to connect after
|
|
@@ -22682,6 +23125,18 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22682
23125
|
}
|
|
22683
23126
|
: {}),
|
|
22684
23127
|
'x-deepline-request-id': deeplineRequestId,
|
|
23128
|
+
...(receiptFinishPlanHeader
|
|
23129
|
+
? {
|
|
23130
|
+
[RUNTIME_RECEIPT_FINISH_PLAN_HEADER]:
|
|
23131
|
+
receiptFinishPlanHeader,
|
|
23132
|
+
}
|
|
23133
|
+
: {}),
|
|
23134
|
+
...(readThroughDispatch && readThroughKeysHeader
|
|
23135
|
+
? {
|
|
23136
|
+
[RUNTIME_READ_THROUGH_KEYS_HEADER]:
|
|
23137
|
+
readThroughKeysHeader,
|
|
23138
|
+
}
|
|
23139
|
+
: {}),
|
|
22685
23140
|
...(asyncRecoveryKey(invocationAttempt)
|
|
22686
23141
|
? {
|
|
22687
23142
|
'idempotency-key':
|
|
@@ -22711,6 +23166,87 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22711
23166
|
// headers arrive; decoded body data stays scoped until
|
|
22712
23167
|
// it has been read and verified below.
|
|
22713
23168
|
response = dispatchedResponse;
|
|
23169
|
+
const readThroughAnswer = readThroughDispatch
|
|
23170
|
+
? runtimeReadThroughOutcome(dispatchedResponse)
|
|
23171
|
+
: null;
|
|
23172
|
+
if (readThroughAnswer === 'miss') {
|
|
23173
|
+
// The relay read nothing, executed and owns this
|
|
23174
|
+
// outcome. Later attempts are ordinary.
|
|
23175
|
+
readThroughPending = false;
|
|
23176
|
+
} else if (
|
|
23177
|
+
readThroughAnswer === 'hit' ||
|
|
23178
|
+
readThroughAnswer === 'declined'
|
|
23179
|
+
) {
|
|
23180
|
+
// The receiver header, sent before any body,
|
|
23181
|
+
// proves no provider work happened. Return
|
|
23182
|
+
// capacity to where it came from and classify on
|
|
23183
|
+
// the caller. A hit whose records cannot be read
|
|
23184
|
+
// is still no work: the caller reads for itself.
|
|
23185
|
+
const keys = readThroughGrant!.keys;
|
|
23186
|
+
let receipts: Array<RuntimeStepReceipt | null> | null =
|
|
23187
|
+
null;
|
|
23188
|
+
if (readThroughAnswer === 'hit') {
|
|
23189
|
+
try {
|
|
23190
|
+
let readThroughBody = '';
|
|
23191
|
+
await this.withProviderResponseBodyTurn(
|
|
23192
|
+
dispatchedResponse,
|
|
23193
|
+
async (bodyTurn) => {
|
|
23194
|
+
readThroughBody =
|
|
23195
|
+
await readToolExecuteResponseBody({
|
|
23196
|
+
toolId,
|
|
23197
|
+
abortController,
|
|
23198
|
+
read: () => dispatchedResponse.text(),
|
|
23199
|
+
});
|
|
23200
|
+
bodyTurn.settleBytes(
|
|
23201
|
+
Buffer.byteLength(
|
|
23202
|
+
readThroughBody,
|
|
23203
|
+
'utf8',
|
|
23204
|
+
),
|
|
23205
|
+
);
|
|
23206
|
+
},
|
|
23207
|
+
abortController?.signal,
|
|
23208
|
+
);
|
|
23209
|
+
receipts = parseRuntimeReadThroughHit(
|
|
23210
|
+
readThroughBody,
|
|
23211
|
+
keys.length,
|
|
23212
|
+
);
|
|
23213
|
+
} catch (error) {
|
|
23214
|
+
if (toolAbortSignal?.aborted) throw error;
|
|
23215
|
+
receipts = null;
|
|
23216
|
+
}
|
|
23217
|
+
} else {
|
|
23218
|
+
await dispatchedResponse.body
|
|
23219
|
+
?.cancel()
|
|
23220
|
+
.catch(() => undefined);
|
|
23221
|
+
}
|
|
23222
|
+
readThroughFallback =
|
|
23223
|
+
new RuntimeReadThroughFallback(
|
|
23224
|
+
receipts ? 'hit' : 'declined',
|
|
23225
|
+
receipts?.map((receipt, index) =>
|
|
23226
|
+
receipt === null
|
|
23227
|
+
? null
|
|
23228
|
+
: (this.normalizeRuntimeStepReceipt(
|
|
23229
|
+
keys[index]!,
|
|
23230
|
+
receipt,
|
|
23231
|
+
) ?? null),
|
|
23232
|
+
) ?? null,
|
|
23233
|
+
readThroughEarlierAttemptMayHaveRun,
|
|
23234
|
+
);
|
|
23235
|
+
activeProviderRequest?.release();
|
|
23236
|
+
activeProviderRequest = null;
|
|
23237
|
+
return {
|
|
23238
|
+
response: dispatchedResponse,
|
|
23239
|
+
responseData: null,
|
|
23240
|
+
responseErrorText: null,
|
|
23241
|
+
integrationFetchStartedAt: fetchedAt,
|
|
23242
|
+
providerCallStartedAt:
|
|
23243
|
+
dispatchedProviderCallStartedAt,
|
|
23244
|
+
fetchToHeadersMs: Date.now() - fetchedAt,
|
|
23245
|
+
executeServerTiming: null,
|
|
23246
|
+
bodyReadMs: 0,
|
|
23247
|
+
providerBodyAdmissionWaitMs: 0,
|
|
23248
|
+
};
|
|
23249
|
+
}
|
|
22714
23250
|
// A delegated 503 can attest that it never dispatched.
|
|
22715
23251
|
// Read its body before counting it as a provider request.
|
|
22716
23252
|
if (
|
|
@@ -22886,7 +23422,26 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22886
23422
|
);
|
|
22887
23423
|
providerBodyAdmissionWaitMs += bodyRead.waitMs;
|
|
22888
23424
|
}
|
|
23425
|
+
if (
|
|
23426
|
+
readThroughDispatch &&
|
|
23427
|
+
readThroughAnswer === null &&
|
|
23428
|
+
isReadThroughExecuteReceiverUnavailable(
|
|
23429
|
+
dispatchedResponse,
|
|
23430
|
+
dispatchedResponseErrorText ?? '',
|
|
23431
|
+
)
|
|
23432
|
+
) {
|
|
23433
|
+
// An older relay refused the named action before
|
|
23434
|
+
// any work. Keep today's read for it from now on.
|
|
23435
|
+
rememberReadThroughUnavailable(executionBaseUrl);
|
|
23436
|
+
readThroughFallback =
|
|
23437
|
+
new RuntimeReadThroughFallback(
|
|
23438
|
+
'receiver_unavailable',
|
|
23439
|
+
null,
|
|
23440
|
+
readThroughEarlierAttemptMayHaveRun,
|
|
23441
|
+
);
|
|
23442
|
+
}
|
|
22889
23443
|
providerPermitReceiverRejected =
|
|
23444
|
+
!readThroughFallback &&
|
|
22890
23445
|
dispatchedWithProviderPermit &&
|
|
22891
23446
|
isProviderPermitExecuteReceiverUnavailable(
|
|
22892
23447
|
dispatchedResponse,
|
|
@@ -22899,7 +23454,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22899
23454
|
status: dispatchedResponse.status,
|
|
22900
23455
|
bodyText: dispatchedResponseErrorText ?? '',
|
|
22901
23456
|
});
|
|
22902
|
-
if (
|
|
23457
|
+
if (
|
|
23458
|
+
!providerPermitReceiverRejected &&
|
|
23459
|
+
!readThroughFallback
|
|
23460
|
+
)
|
|
22903
23461
|
recordProviderDispatch();
|
|
22904
23462
|
if (dispatchedResponse.status === 429) {
|
|
22905
23463
|
const bodyText = dispatchedResponseErrorText ?? '';
|
|
@@ -22992,6 +23550,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
22992
23550
|
// diagnostic counter now; the flow still holds the
|
|
22993
23551
|
// real provider lease until this callback returns.
|
|
22994
23552
|
releaseProviderExecution();
|
|
23553
|
+
if (readThroughFallback)
|
|
23554
|
+
return 'returned_unused' as const;
|
|
22995
23555
|
if (providerPermitReceiverRejected)
|
|
22996
23556
|
return 'not_dispatched' as const;
|
|
22997
23557
|
const failure =
|
|
@@ -23038,7 +23598,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23038
23598
|
} catch (error) {
|
|
23039
23599
|
// A failed exchange whose dispatch is unknown remains a
|
|
23040
23600
|
// physical attempt, including failure before headers.
|
|
23041
|
-
if (
|
|
23601
|
+
if (
|
|
23602
|
+
fetchDispatched &&
|
|
23603
|
+
!providerPermitReceiverRejected &&
|
|
23604
|
+
!readThroughFallback
|
|
23605
|
+
)
|
|
23042
23606
|
recordProviderDispatch();
|
|
23043
23607
|
// `request()` can fail while waiting for its transport
|
|
23044
23608
|
// lease, before its beforeRelease callback runs.
|
|
@@ -23075,7 +23639,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23075
23639
|
providerCallElapsedMs =
|
|
23076
23640
|
providerBodyCompletedAtMs - providerCallStartedAt;
|
|
23077
23641
|
options?.onProviderBodyCompleted?.(providerBodyCompletedAtMs);
|
|
23078
|
-
if (!providerPermitReceiverRejected)
|
|
23642
|
+
if (!providerPermitReceiverRejected && !readThroughFallback)
|
|
23079
23643
|
this.resourceGovernor.observe({
|
|
23080
23644
|
toolId,
|
|
23081
23645
|
providerResourceKey: `tool:${toolId}`,
|
|
@@ -23352,6 +23916,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23352
23916
|
earlierDeliveryMayHaveArrived = true;
|
|
23353
23917
|
span.setAttribute('plays.http_status_code', response.status);
|
|
23354
23918
|
|
|
23919
|
+
if (readThroughFallback) {
|
|
23920
|
+
// The relay did no provider work; its capacity is already back.
|
|
23921
|
+
// The caller classifies the receipts it read, or reads itself.
|
|
23922
|
+
throw readThroughFallback;
|
|
23923
|
+
}
|
|
23355
23924
|
if (providerPermitReceiverRejected) {
|
|
23356
23925
|
// This named action was rejected before provider work. Retry the
|
|
23357
23926
|
// same invocation once through the legacy worker validation path.
|
|
@@ -23893,6 +24462,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23893
24462
|
),
|
|
23894
24463
|
)
|
|
23895
24464
|
: null;
|
|
24465
|
+
// Minted only by the execution relay after it committed the
|
|
24466
|
+
// planned finishing writes. The caller still proves coverage.
|
|
24467
|
+
const receiptFinishAck = receiptFinishPlanHeader
|
|
24468
|
+
? parseRuntimeReceiptFinishAck(
|
|
24469
|
+
response.headers.get(EXECUTION_GATEWAY_RECEIPT_FINISH_HEADER),
|
|
24470
|
+
)
|
|
24471
|
+
: null;
|
|
23896
24472
|
setSpanAttributes(span, {
|
|
23897
24473
|
'plays.tool_result_kind':
|
|
23898
24474
|
resolved.result == null
|
|
@@ -23910,8 +24486,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23910
24486
|
providerAdmissionNoProgressScope
|
|
23911
24487
|
];
|
|
23912
24488
|
}
|
|
23913
|
-
return receiptOutputRef
|
|
23914
|
-
? {
|
|
24489
|
+
return receiptOutputRef || receiptFinishAck
|
|
24490
|
+
? {
|
|
24491
|
+
...resolved,
|
|
24492
|
+
...(receiptOutputRef ? { receiptOutputRef } : {}),
|
|
24493
|
+
...(receiptFinishAck ? { receiptFinishAck } : {}),
|
|
24494
|
+
}
|
|
23915
24495
|
: resolved;
|
|
23916
24496
|
}
|
|
23917
24497
|
},
|
|
@@ -23920,10 +24500,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
23920
24500
|
// The checkpoint becomes durable with the scheduler's suspension handoff.
|
|
23921
24501
|
// Keep cursors only on that path; terminal failures and cancellation must
|
|
23922
24502
|
// not leave retry state behind for an unrelated future execution.
|
|
24503
|
+
// A read-through fallback did not finish this logical call: the
|
|
24504
|
+
// freshness layer runs the same call again, which must resume from the
|
|
24505
|
+
// saved retry position (a 429-resumed attempt keeps its identity).
|
|
23923
24506
|
preserveProviderRetryCursorForSuspension =
|
|
23924
24507
|
preserveProviderRetryCursorForSuspension ||
|
|
23925
24508
|
error instanceof PlayRowProviderBackpressureError ||
|
|
23926
|
-
isPlayExecutionSuspendedError(error)
|
|
24509
|
+
isPlayExecutionSuspendedError(error) ||
|
|
24510
|
+
isRuntimeReadThroughFallback(error);
|
|
23927
24511
|
throw error;
|
|
23928
24512
|
} finally {
|
|
23929
24513
|
if (!preserveProviderRetryCursorForSuspension) {
|