deepline 0.3.517 → 0.3.518
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/bounded-batch-function.ts +21 -3
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +163 -63
- package/dist/bundling-sources/shared_libs/play-runtime/durable-call-policy.ts +8 -13
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +14 -0
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +119 -9
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +8 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +12 -11
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +44 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +16 -6
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +42 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-completion-coalescer.ts +8 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +22 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -7
- package/dist/cli/{artifacts-7KCI2YKZ.js → artifacts-EAOGAB5K.js} +21 -19
- package/dist/cli/{artifacts-LGDMUNP5.mjs → artifacts-LGFPVJSE.mjs} +9 -7
- package/dist/cli/auth-CLNPH65D.js +43 -0
- package/dist/cli/{auth-W75IFBH3.mjs → auth-FXXZIWLI.mjs} +5 -5
- package/dist/cli/{billing-WF2UJVMC.mjs → billing-4Q5WAB5D.mjs} +7 -7
- package/dist/cli/{billing-SWBINQZC.js → billing-ESZXVREA.js} +82 -82
- package/dist/cli/{chunk-T6KXZNWM.mjs → chunk-2DRW5ALK.mjs} +1 -1
- package/dist/cli/{chunk-NKFVUGSA.js → chunk-2G6MARKU.js} +7 -7
- package/dist/cli/{chunk-R7MNIJZN.mjs → chunk-2LBKIVIW.mjs} +2 -2
- package/dist/cli/{chunk-SWAXMOMW.js → chunk-3NMQ5EIV.js} +14 -14
- package/dist/cli/{chunk-AQUV5AXP.mjs → chunk-4YR3W2YB.mjs} +1 -1
- package/dist/cli/{chunk-CDRBJOTJ.js → chunk-5X4P3MNG.js} +9 -9
- package/dist/cli/{chunk-TYFTBB24.js → chunk-6IPKRQMH.js} +2 -2
- package/dist/cli/{chunk-AUQQCAGW.js → chunk-7X32UR2E.js} +96 -96
- package/dist/cli/{chunk-BNWI33W3.js → chunk-B26LSUCI.js} +2 -2
- package/dist/cli/{chunk-NQL2KV3T.mjs → chunk-B2MSOFEI.mjs} +2 -2
- package/dist/cli/{chunk-SQ4KGLWP.js → chunk-BVQDUYXJ.js} +16 -16
- package/dist/cli/{chunk-IUFWQ5HW.mjs → chunk-DYWQ72ZQ.mjs} +1 -1
- package/dist/cli/{chunk-6VFY6ZZJ.js → chunk-ENVSFG5E.js} +44 -44
- package/dist/cli/{chunk-HM42PD4D.mjs → chunk-G6BD4K3K.mjs} +5 -5
- package/dist/cli/{chunk-RHF5UIYX.js → chunk-GDMO6MMY.js} +41 -41
- package/dist/cli/{chunk-G7DNBQQE.js → chunk-HIJM54NU.js} +22 -22
- package/dist/cli/{chunk-D4OZSC3C.js → chunk-HYR34KFA.js} +5 -4
- package/dist/cli/{chunk-N7L76I62.js → chunk-ICHUGGZ3.js} +2 -2
- package/dist/cli/{chunk-TRIFS75L.js → chunk-J2UOHFDH.js} +53 -53
- package/dist/cli/{chunk-MZBQTSAX.js → chunk-JKSLK5PS.js} +5 -5
- package/dist/cli/{chunk-ZWPRFZAF.js → chunk-K5GUMXRT.js} +26 -26
- package/dist/cli/{chunk-IKBC5NYO.mjs → chunk-KIYDPAGX.mjs} +2 -2
- package/dist/cli/{chunk-EP4NPHKZ.mjs → chunk-KP5AAMJ3.mjs} +1 -1
- package/dist/cli/{chunk-YLI5CKGB.mjs → chunk-KQV75ZUA.mjs} +10 -10
- package/dist/cli/{chunk-HN3M54JJ.mjs → chunk-L256EFFV.mjs} +2 -2
- package/dist/cli/{chunk-PGQ24IXZ.mjs → chunk-L4RQDVCN.mjs} +5 -5
- package/dist/cli/{chunk-VPM64DAL.js → chunk-LLO5UYI5.js} +6 -6
- package/dist/cli/{chunk-ASMUKT2H.mjs → chunk-LTCNF6KG.mjs} +5 -5
- package/dist/cli/{chunk-UIIUCB4A.js → chunk-M4DA3HTT.js} +16 -16
- package/dist/cli/{chunk-3XV2UGZ7.mjs → chunk-MNWLM3FA.mjs} +1 -1
- package/dist/cli/{chunk-STHTJ56U.js → chunk-NQFVQCCV.js} +1 -1
- package/dist/cli/{chunk-QGLY4XXN.mjs → chunk-QX4QFGU7.mjs} +1 -1
- package/dist/cli/{chunk-U6QC4WT6.js → chunk-R4ZEJD5F.js} +4 -4
- package/dist/cli/{chunk-PIXPD62R.mjs → chunk-RASCFMYI.mjs} +2 -2
- package/dist/cli/{chunk-5ANZ57SA.js → chunk-REEWKGQZ.js} +10 -10
- package/dist/cli/{chunk-KQKUPUVG.mjs → chunk-RFUJBBJE.mjs} +6 -6
- package/dist/cli/{chunk-HRHAX2IU.mjs → chunk-RYHNKT4P.mjs} +2 -2
- package/dist/cli/{chunk-5A6UQOYE.js → chunk-SNFRDG7G.js} +3 -3
- package/dist/cli/{chunk-QMJGNAK4.js → chunk-ST7WCRVQ.js} +5 -5
- package/dist/cli/{chunk-4XJL4F5U.mjs → chunk-TH2AQ4VG.mjs} +3 -3
- package/dist/cli/{chunk-C5QDX54T.mjs → chunk-TU5RR775.mjs} +3 -3
- package/dist/cli/{chunk-PTJFL3WW.js → chunk-UY5JSZDA.js} +11 -11
- package/dist/cli/{chunk-S25URYNM.mjs → chunk-V6DIYGTK.mjs} +1 -1
- package/dist/cli/{chunk-YXGTO5XA.mjs → chunk-VE6FHVXZ.mjs} +5 -4
- package/dist/cli/{chunk-7P4BIRFS.js → chunk-VHFICSS7.js} +6 -6
- package/dist/cli/{chunk-ZA3DRRHR.mjs → chunk-W3UFYU63.mjs} +1 -1
- package/dist/cli/{chunk-22S2QG2H.mjs → chunk-WTQF2Z6X.mjs} +4 -4
- package/dist/cli/{chunk-PGSAISXG.mjs → chunk-X6H3JGOP.mjs} +2 -2
- package/dist/cli/{chunk-PHP674RR.mjs → chunk-XA7OTIYW.mjs} +1 -1
- package/dist/cli/{chunk-JH43VNY6.js → chunk-XJ5NVLIP.js} +3 -3
- package/dist/cli/{chunk-TJZAYI77.mjs → chunk-YNIH4YTR.mjs} +5 -5
- package/dist/cli/{chunk-4T6AUBI7.js → chunk-ZJ3HEEGF.js} +7 -7
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-I22P5M5Y.mjs → csv-KRGEVVN7.mjs} +4 -4
- package/dist/cli/{csv-MEQSN7FP.js → csv-RLFOF4P4.js} +13 -13
- package/dist/cli/{db-X7SQQW34.mjs → db-2B6G4YO3.mjs} +6 -6
- package/dist/cli/{db-RSDJF4D7.js → db-NJC3NPOL.js} +27 -27
- package/dist/cli/{describe-H6KM4KPD.mjs → describe-BLJFAM4U.mjs} +18 -18
- package/dist/cli/describe-DRMUODJN.js +50 -0
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/{executions-SCID4WZT.mjs → executions-25XYBGJ5.mjs} +6 -6
- package/dist/cli/{executions-KPEOFSKD.js → executions-ENELLT7A.js} +8 -8
- package/dist/cli/{feedback-PQRD6XLU.mjs → feedback-5OAKHVQE.mjs} +5 -5
- package/dist/cli/{feedback-R3R7CENU.js → feedback-UPI2JQPL.js} +10 -10
- package/dist/cli/{git-IWUFEG56.mjs → git-MRYSIZV4.mjs} +5 -5
- package/dist/cli/git-P4OPT6Q7.js +25 -0
- package/dist/cli/index.js +145 -145
- package/dist/cli/index.mjs +44 -44
- package/dist/cli/{legacy-noops-S2EQ3DW6.js → legacy-noops-DHEWQKER.js} +9 -9
- package/dist/cli/{legacy-noops-42W5OOGA.mjs → legacy-noops-OJD5KYUO.mjs} +6 -6
- package/dist/cli/{monitors-Q6WIKBLU.js → monitors-22AFKUQN.js} +100 -100
- package/dist/cli/{monitors-WS7SZ4X6.mjs → monitors-24JM24NV.mjs} +7 -7
- package/dist/cli/{org-XAYQWGZK.js → org-HNYKUDJB.js} +72 -72
- package/dist/cli/{org-RLGVNZQ7.mjs → org-I2X7ZZGQ.mjs} +6 -6
- package/dist/cli/{pages-H5QIFW6M.mjs → pages-4LSYUDES.mjs} +6 -6
- package/dist/cli/{pages-RHET3HGT.js → pages-OUSF2RNH.js} +18 -18
- package/dist/cli/{play-4ZWS7CAF.mjs → play-64XKQRA4.mjs} +18 -18
- package/dist/cli/{play-OPQJACQN.js → play-ESY43EFW.js} +317 -317
- package/dist/cli/{providers-HQ47SEXO.js → providers-ENWSSRYR.js} +9 -9
- package/dist/cli/{providers-276TVAW5.mjs → providers-VHK26CSP.mjs} +6 -6
- package/dist/cli/{quickstart-VYTNG7KH.mjs → quickstart-4NNLQMD7.mjs} +4 -4
- package/dist/cli/{quickstart-C2B32MOC.js → quickstart-TZ6IAUMS.js} +6 -6
- package/dist/cli/{run-4SIWK5Y2.mjs → run-DOH3AMYU.mjs} +23 -23
- package/dist/cli/{run-O4MJLK2I.js → run-RR7KPWP7.js} +41 -41
- package/dist/cli/search-SE6PM33H.js +33 -0
- package/dist/cli/{search-ZC4SHHDP.mjs → search-YFOCGXWL.mjs} +8 -8
- package/dist/cli/{search-output-7LZ4T33R.js → search-output-AOTV6C36.js} +6 -6
- package/dist/cli/{search-output-EZN2UETF.mjs → search-output-IV2HSRLQ.mjs} +4 -4
- package/dist/cli/{secrets-QRNMUW5O.js → secrets-ATPM2AXV.js} +15 -15
- package/dist/cli/{secrets-JHJSUL6I.mjs → secrets-GMFCHPTV.mjs} +6 -6
- package/dist/cli/sessions-NN3H2KSE.js +18 -0
- package/dist/cli/{sessions-CAZ4FK7F.mjs → sessions-X3M4H2WY.mjs} +6 -6
- package/dist/cli/{settings-52P7HHH4.js → settings-4V52LMWP.js} +86 -86
- package/dist/cli/{settings-PI3F4DXU.mjs → settings-GRXFOR5V.mjs} +13 -13
- package/dist/cli/{setup-KVZ4AMHC.mjs → setup-63WAXGPH.mjs} +10 -10
- package/dist/cli/{setup-Y5BFQAWN.js → setup-OCCXAVQL.js} +50 -50
- package/dist/cli/skills-6XXVKQP4.js +37 -0
- package/dist/cli/{skills-FG64C72D.mjs → skills-IVGTO4NE.mjs} +8 -8
- package/dist/cli/tools-5COWG5TH.js +57 -0
- package/dist/cli/{tools-2SPVUFNO.mjs → tools-KGHX6MLB.mjs} +17 -17
- package/dist/cli/{update-GJD5NYSO.mjs → update-2OBZ4IUJ.mjs} +10 -10
- package/dist/cli/update-SQD25OCL.js +35 -0
- package/dist/cli/{workflow-LGITND7U.js → workflow-HGLO4V7R.js} +17 -17
- package/dist/cli/{workflow-JGGDTRCA.mjs → workflow-ZZOATQYV.mjs} +7 -7
- package/dist/{client-K1g4ab5Y.d.mts → client-CpSiHSti.d.mts} +1 -1
- package/dist/{client-CQSPuqxh.d.ts → client-CswZYCGj.d.ts} +1 -1
- package/dist/{client-core-BksGf5Gd.d.mts → client-core-C1xVOg8Y.d.mts} +1 -1
- package/dist/{client-core-BlaqOlQ7.d.ts → client-core-D2pLt36Q.d.ts} +1 -1
- package/dist/{compiler-manifest-BliMS7ax.d.mts → compiler-manifest-B4mIIbw7.d.mts} +3 -3
- package/dist/{compiler-manifest-BliMS7ax.d.ts → compiler-manifest-B4mIIbw7.d.ts} +3 -3
- package/dist/{errors-BZ6Zq1cz.d.mts → errors-C2F4qzAq.d.mts} +1 -1
- package/dist/{errors-xfNscfS1.d.ts → errors-Gj9i5Rkd.d.ts} +1 -1
- package/dist/{index-DbvCg4zg.d.mts → index-5JZBufdF.d.mts} +1 -1
- package/dist/{index-FGdQv8J8.d.ts → index-BXtSj8bv.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 +117 -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 +3 -4
- 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-MHMCB7ND.js +0 -43
- package/dist/cli/describe-BCKVF2DC.js +0 -50
- package/dist/cli/git-NJGV6I6K.js +0 -25
- package/dist/cli/search-NLMIJYHK.js +0 -33
- package/dist/cli/sessions-4BVQJDIE.js +0 -18
- package/dist/cli/skills-LI4UH6FW.js +0 -37
- package/dist/cli/tools-GUC4BGUK.js +0 -57
- package/dist/cli/update-BBXSYFMA.js +0 -35
|
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
|
|
|
205
205
|
// getters keep their established compatibility behavior.
|
|
206
206
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
207
207
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
208
|
-
version: '0.3.
|
|
208
|
+
version: '0.3.518',
|
|
209
209
|
updateSummary: {
|
|
210
210
|
introducedIn: '0.3.90',
|
|
211
211
|
summary:
|
|
@@ -158,6 +158,7 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
158
158
|
readonly #maxOpenGroups: number;
|
|
159
159
|
readonly #maxInFlightBatches: number;
|
|
160
160
|
readonly #flushMs: number;
|
|
161
|
+
readonly #flushImmediatelyWhenIdle: boolean;
|
|
161
162
|
readonly #now: () => number;
|
|
162
163
|
readonly #closedController = new AbortController();
|
|
163
164
|
readonly #groups = new Map<string, OpenGroup<Value, Result, Key>>();
|
|
@@ -191,6 +192,14 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
191
192
|
maxOpenGroups?: number;
|
|
192
193
|
maxInFlightBatches?: number;
|
|
193
194
|
flushMs?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Flush a window opened on a completely idle function (no other open
|
|
197
|
+
* window, nothing ready, nothing in flight) on the next timer turn rather
|
|
198
|
+
* than after `flushMs`. Values arriving in that same turn still join the
|
|
199
|
+
* window; a lone value stops paying a hold that no peer can use. Windows
|
|
200
|
+
* opened while the function is busy keep the full `flushMs`.
|
|
201
|
+
*/
|
|
202
|
+
flushImmediatelyWhenIdle?: boolean;
|
|
194
203
|
now?: () => number;
|
|
195
204
|
}) {
|
|
196
205
|
this.#keyId = input.keyId;
|
|
@@ -226,6 +235,7 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
226
235
|
'maxInFlightBatches',
|
|
227
236
|
);
|
|
228
237
|
this.#flushMs = Math.max(0, Math.floor(input.flushMs ?? 0));
|
|
238
|
+
this.#flushImmediatelyWhenIdle = input.flushImmediatelyWhenIdle === true;
|
|
229
239
|
this.#now = input.now ?? Date.now;
|
|
230
240
|
}
|
|
231
241
|
|
|
@@ -354,6 +364,11 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
354
364
|
) {
|
|
355
365
|
this.#sealGroup(keyId);
|
|
356
366
|
}
|
|
367
|
+
const wasIdle =
|
|
368
|
+
this.#flushImmediatelyWhenIdle &&
|
|
369
|
+
this.#groups.size === 0 &&
|
|
370
|
+
this.#ready.length === 0 &&
|
|
371
|
+
this.#inFlight.size === 0;
|
|
357
372
|
const group = this.#groups.get(keyId) ?? {
|
|
358
373
|
key: input.key,
|
|
359
374
|
keyId,
|
|
@@ -375,7 +390,7 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
375
390
|
) {
|
|
376
391
|
this.#sealGroup(keyId);
|
|
377
392
|
} else {
|
|
378
|
-
this.#scheduleGroupFlush(group);
|
|
393
|
+
this.#scheduleGroupFlush(group, wasIdle ? 0 : this.#flushMs);
|
|
379
394
|
}
|
|
380
395
|
this.#scheduleDeadlineTimer();
|
|
381
396
|
this.#pump();
|
|
@@ -454,13 +469,16 @@ export class BoundedBatchFunction<Value, Result, Key> {
|
|
|
454
469
|
this.#retainedUnits -= pending.units;
|
|
455
470
|
}
|
|
456
471
|
|
|
457
|
-
#scheduleGroupFlush(
|
|
472
|
+
#scheduleGroupFlush(
|
|
473
|
+
group: OpenGroup<Value, Result, Key>,
|
|
474
|
+
delayMs: number,
|
|
475
|
+
): void {
|
|
458
476
|
if (group.timer !== null) return;
|
|
459
477
|
group.timer = setTimeout(() => {
|
|
460
478
|
group.timer = null;
|
|
461
479
|
this.#sealGroup(group.keyId);
|
|
462
480
|
this.#pump();
|
|
463
|
-
},
|
|
481
|
+
}, delayMs);
|
|
464
482
|
group.timer.unref?.();
|
|
465
483
|
}
|
|
466
484
|
|
|
@@ -291,6 +291,7 @@ import {
|
|
|
291
291
|
import { resolveExplicitDurableCallPolicy } from './durable-call-policy';
|
|
292
292
|
import {
|
|
293
293
|
completedCallForResult,
|
|
294
|
+
type DeferredReceiptPublication,
|
|
294
295
|
executeWithFreshnessReceipt,
|
|
295
296
|
latestCacheResultKey,
|
|
296
297
|
latestCacheResultOutput,
|
|
@@ -301,7 +302,6 @@ import {
|
|
|
301
302
|
CtxFetchHttpError,
|
|
302
303
|
LEGACY_PLAY_AUTHORING_CONTRACT_EDITION,
|
|
303
304
|
PLAY_AUTHORING_CONTRACT_EDITION,
|
|
304
|
-
PlayAuthoringFieldValidationError,
|
|
305
305
|
normalizePlayAuthoringCustomerDbStatement,
|
|
306
306
|
validateOptionalPlayAuthoringField,
|
|
307
307
|
validatePlayAuthoringField,
|
|
@@ -3379,16 +3379,6 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
3379
3379
|
options.staleAfterSeconds,
|
|
3380
3380
|
);
|
|
3381
3381
|
}
|
|
3382
|
-
if (
|
|
3383
|
-
this.usesExplicitFreshness &&
|
|
3384
|
-
options?.staleAfterSeconds === undefined
|
|
3385
|
-
) {
|
|
3386
|
-
throw new PlayAuthoringFieldValidationError(
|
|
3387
|
-
'ctx.customerDb.query.options.staleAfterSeconds',
|
|
3388
|
-
'play_authoring_durable_policy_invalid',
|
|
3389
|
-
'Edition 11 Customer DB queries require staleAfterSeconds: 0.',
|
|
3390
|
-
);
|
|
3391
|
-
}
|
|
3392
3382
|
if (options?.maxRows !== undefined) {
|
|
3393
3383
|
validatePlayAuthoringField(
|
|
3394
3384
|
'ctx.customerDb.query.options.maxRows',
|
|
@@ -4143,7 +4133,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4143
4133
|
semanticKey: string;
|
|
4144
4134
|
invocationId: string;
|
|
4145
4135
|
policy: { requested: number | null; effective: number | null };
|
|
4146
|
-
execute: () => Promise<T>;
|
|
4136
|
+
execute: (publication: DeferredReceiptPublication) => Promise<T>;
|
|
4147
4137
|
completedAt?: (value: T) => number | undefined;
|
|
4148
4138
|
sharesResult?: (value: T) => boolean;
|
|
4149
4139
|
eligibleAnswer?: (value: T) => boolean;
|
|
@@ -4192,8 +4182,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
4192
4182
|
),
|
|
4193
4183
|
{ ...options, source: 'durable_operation' },
|
|
4194
4184
|
),
|
|
4195
|
-
execute: async () => {
|
|
4196
|
-
const value = await input.execute();
|
|
4185
|
+
execute: async (publication) => {
|
|
4186
|
+
const value = await input.execute(publication);
|
|
4197
4187
|
this.assertNoPendingDurableSuspension();
|
|
4198
4188
|
return value;
|
|
4199
4189
|
},
|
|
@@ -5105,6 +5095,43 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
5105
5095
|
);
|
|
5106
5096
|
},
|
|
5107
5097
|
});
|
|
5098
|
+
} catch (error) {
|
|
5099
|
+
if (isAbortLikeError(error)) throw error;
|
|
5100
|
+
this.runtimeLog(
|
|
5101
|
+
`Tool source-run receipt manifest write skipped: ${error instanceof Error ? error.message : String(error)}`,
|
|
5102
|
+
);
|
|
5103
|
+
}
|
|
5104
|
+
}
|
|
5105
|
+
|
|
5106
|
+
/**
|
|
5107
|
+
* Same pointer as `persistSourceRunToolReceiptManifests`, handed to the
|
|
5108
|
+
* freshness layer to publish in its finishing request. A failure to build
|
|
5109
|
+
* it is logged, never raised: it is optional recovery metadata.
|
|
5110
|
+
*/
|
|
5111
|
+
private async deferSourceRunToolReceiptManifest(
|
|
5112
|
+
input: {
|
|
5113
|
+
toolId: string;
|
|
5114
|
+
logicalCallId?: string | null;
|
|
5115
|
+
executionAuthScopeDigest?: string | null;
|
|
5116
|
+
resultReceiptKey: string;
|
|
5117
|
+
},
|
|
5118
|
+
publication: DeferredReceiptPublication,
|
|
5119
|
+
): Promise<void> {
|
|
5120
|
+
try {
|
|
5121
|
+
const providerActionVersion =
|
|
5122
|
+
(
|
|
5123
|
+
await this.#options.getToolActionCacheVersion?.(input.toolId)
|
|
5124
|
+
)?.trim() ?? '';
|
|
5125
|
+
for (const manifest of this.sourceRunToolReceiptManifestCompletionInputs([
|
|
5126
|
+
{ ...input, providerActionVersion },
|
|
5127
|
+
])) {
|
|
5128
|
+
publication.defer({
|
|
5129
|
+
key: manifest.key,
|
|
5130
|
+
output: manifest.output,
|
|
5131
|
+
bestEffort: true,
|
|
5132
|
+
sourceRunManifest: true,
|
|
5133
|
+
});
|
|
5134
|
+
}
|
|
5108
5135
|
} catch (error) {
|
|
5109
5136
|
this.runtimeLog(
|
|
5110
5137
|
`Tool source-run receipt manifest write skipped: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -5495,6 +5522,29 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
5495
5522
|
return byKey;
|
|
5496
5523
|
}
|
|
5497
5524
|
|
|
5525
|
+
/**
|
|
5526
|
+
* Read independent keys of one call together. A host with a batch read
|
|
5527
|
+
* sends one request; otherwise each key is its own single read, issued at
|
|
5528
|
+
* once. Either way each key is answered under the key that was asked for.
|
|
5529
|
+
*/
|
|
5530
|
+
private async getRuntimeStepReceiptsByRequestedKey(
|
|
5531
|
+
keys: string[],
|
|
5532
|
+
): Promise<Map<string, RuntimeStepReceipt>> {
|
|
5533
|
+
if (this.#options.getRuntimeStepReceipts) {
|
|
5534
|
+
return await this.getRuntimeStepReceipts(keys);
|
|
5535
|
+
}
|
|
5536
|
+
const unique = [...new Set(keys.map((key) => key.trim()).filter(Boolean))];
|
|
5537
|
+
const receipts = await Promise.all(
|
|
5538
|
+
unique.map((key) => this.getRuntimeStepReceipt(key)),
|
|
5539
|
+
);
|
|
5540
|
+
const byKey = new Map<string, RuntimeStepReceipt>();
|
|
5541
|
+
unique.forEach((key, index) => {
|
|
5542
|
+
const receipt = receipts[index];
|
|
5543
|
+
if (receipt) byKey.set(key, receipt);
|
|
5544
|
+
});
|
|
5545
|
+
return byKey;
|
|
5546
|
+
}
|
|
5547
|
+
|
|
5498
5548
|
private async claimRuntimeStepReceipts(
|
|
5499
5549
|
keys: string[],
|
|
5500
5550
|
_runId: string,
|
|
@@ -5907,7 +5957,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
5907
5957
|
const outcome = settled[index];
|
|
5908
5958
|
if (outcome?.status !== 'rejected') continue;
|
|
5909
5959
|
const key = normalizedInputs[index]?.key.trim() ?? '';
|
|
5910
|
-
|
|
5960
|
+
// A cancellation is the run stopping, not a lost optional pointer.
|
|
5961
|
+
if (
|
|
5962
|
+
key &&
|
|
5963
|
+
options.bestEffortKeys?.has(key) &&
|
|
5964
|
+
!isAbortLikeError(outcome.reason)
|
|
5965
|
+
) {
|
|
5911
5966
|
options.onBestEffortFailure?.({ key, error: outcome.reason });
|
|
5912
5967
|
continue;
|
|
5913
5968
|
}
|
|
@@ -6899,6 +6954,40 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
6899
6954
|
: {}),
|
|
6900
6955
|
complete: (receiptKey, runId, output, leaseId) =>
|
|
6901
6956
|
this.completeRuntimeStepReceipt(receiptKey, runId, output, leaseId),
|
|
6957
|
+
...(this.#options.completeRuntimeStepReceipts
|
|
6958
|
+
? {
|
|
6959
|
+
completeMany: (writes) =>
|
|
6960
|
+
this.completeRuntimeStepReceipts(
|
|
6961
|
+
writes.map((write) => ({
|
|
6962
|
+
key: write.key,
|
|
6963
|
+
runId: this.currentReceiptOwnerRunId,
|
|
6964
|
+
runAttempt: this.currentRunAttempt,
|
|
6965
|
+
leaseId: COMPLETED_RECEIPT_CACHE_INSERT_LEASE_ID,
|
|
6966
|
+
output: write.output,
|
|
6967
|
+
...(write.sourceRunManifest
|
|
6968
|
+
? { sourceRunManifest: true }
|
|
6969
|
+
: {}),
|
|
6970
|
+
})),
|
|
6971
|
+
undefined,
|
|
6972
|
+
undefined,
|
|
6973
|
+
{
|
|
6974
|
+
// The caller keeps the live value it just produced; an
|
|
6975
|
+
// acknowledgement without a body must not trigger a read-back.
|
|
6976
|
+
retainLiveResult: true,
|
|
6977
|
+
bestEffortKeys: new Set(
|
|
6978
|
+
writes
|
|
6979
|
+
.filter((write) => write.bestEffort)
|
|
6980
|
+
.map((write) => write.key),
|
|
6981
|
+
),
|
|
6982
|
+
onBestEffortFailure: ({ key, error }) => {
|
|
6983
|
+
this.runtimeLog(
|
|
6984
|
+
`Tool source-run receipt manifest write skipped for ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
6985
|
+
);
|
|
6986
|
+
},
|
|
6987
|
+
},
|
|
6988
|
+
),
|
|
6989
|
+
}
|
|
6990
|
+
: {}),
|
|
6902
6991
|
...(this.#options.publishLatestCacheResult
|
|
6903
6992
|
? { publishLatestCacheResult: this.#options.publishLatestCacheResult }
|
|
6904
6993
|
: {}),
|
|
@@ -14491,9 +14580,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14491
14580
|
);
|
|
14492
14581
|
}
|
|
14493
14582
|
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14583
|
+
// Independent lookups of one tool's identity: the first call per tool pays
|
|
14584
|
+
// two gateway requests, so ask for both at once.
|
|
14585
|
+
const [authScope, rawActionVersion] = await Promise.all([
|
|
14586
|
+
this.resolveToolAuthScopeDigest(toolId),
|
|
14587
|
+
this.#options.getToolActionCacheVersion?.(toolId),
|
|
14588
|
+
]);
|
|
14589
|
+
const actionVersion = rawActionVersion?.trim() ?? '';
|
|
14497
14590
|
if (!actionVersion) {
|
|
14498
14591
|
throw new Error(`Tool ${toolId} has no action identity for freshness.`);
|
|
14499
14592
|
}
|
|
@@ -14586,7 +14679,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14586
14679
|
},
|
|
14587
14680
|
sharesResult: isCompletedSuccessfulAnswer,
|
|
14588
14681
|
eligibleAnswer: isCompletedSuccessfulAnswer,
|
|
14589
|
-
execute: async () => {
|
|
14682
|
+
execute: async (publication) => {
|
|
14590
14683
|
// The freshness layer is the only reuse authority here. The legacy
|
|
14591
14684
|
// durable call cache below it would otherwise hand back an earlier
|
|
14592
14685
|
// completed-but-ineligible answer (a pending or empty result) that the
|
|
@@ -14597,6 +14690,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14597
14690
|
requestInput,
|
|
14598
14691
|
{ ...options, force: true },
|
|
14599
14692
|
true,
|
|
14693
|
+
publication,
|
|
14600
14694
|
);
|
|
14601
14695
|
if ((await this.resolveToolAuthScopeDigest(toolId)) !== authScope) {
|
|
14602
14696
|
throw new Error(
|
|
@@ -14703,6 +14797,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14703
14797
|
input: Record<string, unknown>,
|
|
14704
14798
|
options?: ToolCallOptions,
|
|
14705
14799
|
deferResponseMaterialization = false,
|
|
14800
|
+
/**
|
|
14801
|
+
* The caller publishes this call's result receipt and replay pointer with
|
|
14802
|
+
* its own finishing writes, before the call returns to customer code.
|
|
14803
|
+
*/
|
|
14804
|
+
publication?: DeferredReceiptPublication,
|
|
14706
14805
|
): Promise<unknown> {
|
|
14707
14806
|
if (!rowContext.getStore()) this.assertRowAdmissionOpen();
|
|
14708
14807
|
this.assertNoPendingDurableSuspension();
|
|
@@ -14954,19 +15053,31 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14954
15053
|
// reader seam rather than teaching the deep Module an untyped result.
|
|
14955
15054
|
// New direct calls use the real Tool Result Receipt Adapter below.
|
|
14956
15055
|
if (cacheableToolResult && !toolCachePolicy.force) {
|
|
15056
|
+
// The compatibility receipts, the primary receipt, the request's
|
|
15057
|
+
// shared result and the response-contract recovery receipt are
|
|
15058
|
+
// independent keys of this one call. Read them in one request and
|
|
15059
|
+
// evaluate them below in the same priority order, instead of paying
|
|
15060
|
+
// a gateway round trip for each in turn.
|
|
15061
|
+
const sharedReadKey = latestCache?.read ? latestCache.key : null;
|
|
15062
|
+
const lookedUp = await this.withRuntimeReceiptHydrationTurn(
|
|
15063
|
+
async (turn) => {
|
|
15064
|
+
const byKey = await this.getRuntimeStepReceiptsByRequestedKey([
|
|
15065
|
+
...compatibleDurableCacheKeys.slice(1),
|
|
15066
|
+
directCacheKey,
|
|
15067
|
+
...(sharedReadKey ? [sharedReadKey] : []),
|
|
15068
|
+
...(legacyDurableCacheKey ? [legacyDurableCacheKey] : []),
|
|
15069
|
+
]);
|
|
15070
|
+
turn.settleBytes(
|
|
15071
|
+
runtimeStepReceiptPayloadBytes([...byKey.values()]),
|
|
15072
|
+
);
|
|
15073
|
+
return byKey;
|
|
15074
|
+
},
|
|
15075
|
+
{ source: 'direct_tool_legacy_cache' },
|
|
15076
|
+
);
|
|
14957
15077
|
for (const compatibleCacheKey of compatibleDurableCacheKeys.slice(
|
|
14958
15078
|
1,
|
|
14959
15079
|
)) {
|
|
14960
|
-
const compatibleReceipt =
|
|
14961
|
-
await this.withRuntimeReceiptHydrationTurn(
|
|
14962
|
-
async (turn) => {
|
|
14963
|
-
const receipt =
|
|
14964
|
-
await this.getRuntimeStepReceipt(compatibleCacheKey);
|
|
14965
|
-
turn.settleBytes(runtimeStepReceiptPayloadBytes([receipt]));
|
|
14966
|
-
return receipt;
|
|
14967
|
-
},
|
|
14968
|
-
{ source: 'direct_tool_legacy_cache' },
|
|
14969
|
-
);
|
|
15080
|
+
const compatibleReceipt = lookedUp.get(compatibleCacheKey) ?? null;
|
|
14970
15081
|
if (
|
|
14971
15082
|
compatibleReceipt &&
|
|
14972
15083
|
(compatibleReceipt.status === 'completed' ||
|
|
@@ -14996,27 +15107,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
14996
15107
|
// An older edition reads the request's shared result in the same
|
|
14997
15108
|
// batch as its play-local receipt; the play-local result wins.
|
|
14998
15109
|
const sharedRead = latestCache?.read ? latestCache : null;
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
const byKey = await this.getRuntimeStepReceipts([
|
|
15004
|
-
directCacheKey,
|
|
15005
|
-
sharedRead.key,
|
|
15006
|
-
]);
|
|
15007
|
-
const receipt = byKey.get(directCacheKey) ?? null;
|
|
15008
|
-
sharedReceipt = byKey.get(sharedRead.key) ?? null;
|
|
15009
|
-
turn.settleBytes(
|
|
15010
|
-
runtimeStepReceiptPayloadBytes([receipt, sharedReceipt]),
|
|
15011
|
-
);
|
|
15012
|
-
return receipt;
|
|
15013
|
-
}
|
|
15014
|
-
const receipt = await this.getRuntimeStepReceipt(directCacheKey);
|
|
15015
|
-
turn.settleBytes(runtimeStepReceiptPayloadBytes([receipt]));
|
|
15016
|
-
return receipt;
|
|
15017
|
-
},
|
|
15018
|
-
{ source: 'direct_tool_legacy_cache' },
|
|
15019
|
-
);
|
|
15110
|
+
const sharedReceipt: RuntimeStepReceipt | null = sharedRead
|
|
15111
|
+
? (lookedUp.get(sharedRead.key) ?? null)
|
|
15112
|
+
: null;
|
|
15113
|
+
const historicalReceipt = lookedUp.get(directCacheKey) ?? null;
|
|
15020
15114
|
const historicalOutput = historicalReceipt
|
|
15021
15115
|
? this.runtimeReceiptOutput<unknown>(historicalReceipt)
|
|
15022
15116
|
: undefined;
|
|
@@ -15060,16 +15154,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15060
15154
|
(!historicalReceipt || !historicalCanServeCurrentContract) &&
|
|
15061
15155
|
legacyDurableCacheKey
|
|
15062
15156
|
) {
|
|
15063
|
-
const legacyReceipt =
|
|
15064
|
-
async (turn) => {
|
|
15065
|
-
const receipt = await this.getRuntimeStepReceipt(
|
|
15066
|
-
legacyDurableCacheKey!,
|
|
15067
|
-
);
|
|
15068
|
-
turn.settleBytes(runtimeStepReceiptPayloadBytes([receipt]));
|
|
15069
|
-
return receipt;
|
|
15070
|
-
},
|
|
15071
|
-
{ source: 'direct_tool_legacy_cache' },
|
|
15072
|
-
);
|
|
15157
|
+
const legacyReceipt = lookedUp.get(legacyDurableCacheKey) ?? null;
|
|
15073
15158
|
if (
|
|
15074
15159
|
legacyReceipt &&
|
|
15075
15160
|
(legacyReceipt.status === 'completed' ||
|
|
@@ -15313,13 +15398,27 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
15313
15398
|
this.withRuntimeReceiptHydrationTurn(hydrate, {
|
|
15314
15399
|
source: 'direct_tool_result_receipt',
|
|
15315
15400
|
}),
|
|
15401
|
+
...(publication ? { deferPublication: publication } : {}),
|
|
15316
15402
|
onStored: async ({ resultReceiptKey }) => {
|
|
15317
|
-
|
|
15403
|
+
const pointer = {
|
|
15318
15404
|
toolId,
|
|
15319
15405
|
logicalCallId,
|
|
15320
15406
|
executionAuthScopeDigest,
|
|
15321
15407
|
resultReceiptKey,
|
|
15322
|
-
}
|
|
15408
|
+
};
|
|
15409
|
+
// An execution-fenced call keeps its own write path: its
|
|
15410
|
+
// lock is held until the result is durable.
|
|
15411
|
+
if (
|
|
15412
|
+
publication &&
|
|
15413
|
+
toolRetryPolicy?.requiresExecutionFence !== true
|
|
15414
|
+
) {
|
|
15415
|
+
await this.deferSourceRunToolReceiptManifest(
|
|
15416
|
+
pointer,
|
|
15417
|
+
publication,
|
|
15418
|
+
);
|
|
15419
|
+
return;
|
|
15420
|
+
}
|
|
15421
|
+
await this.persistSourceRunToolReceiptManifest(pointer);
|
|
15323
15422
|
},
|
|
15324
15423
|
...(toolRetryPolicy?.requiresExecutionFence === true
|
|
15325
15424
|
? {
|
|
@@ -17040,7 +17139,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
|
|
|
17040
17139
|
} else if (
|
|
17041
17140
|
this.usesExplicitFreshness &&
|
|
17042
17141
|
!reusableReadMethod &&
|
|
17043
|
-
options?.staleAfterSeconds !==
|
|
17142
|
+
options?.staleAfterSeconds !== undefined &&
|
|
17143
|
+
options.staleAfterSeconds !== 0
|
|
17044
17144
|
) {
|
|
17045
17145
|
throw new Error(
|
|
17046
17146
|
'Edition 11 mutating or non-read-only fetches require staleAfterSeconds: 0.',
|
|
@@ -18,26 +18,21 @@ export function resolveExplicitDurableCallPolicy(input: {
|
|
|
18
18
|
staleAfterSeconds?: number | null;
|
|
19
19
|
force?: boolean;
|
|
20
20
|
}): { requested: number | null; effective: number | null } {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
resolveDurableCallCachePolicy(input.staleAfterSeconds);
|
|
27
|
-
if (
|
|
28
|
-
input.staleAfterSeconds !== null &&
|
|
29
|
-
!Number.isSafeInteger(input.staleAfterSeconds)
|
|
30
|
-
) {
|
|
21
|
+
// Omitted means 0 (no cross-run reuse), the same as an authored 0.
|
|
22
|
+
const staleAfterSeconds =
|
|
23
|
+
input.staleAfterSeconds === undefined ? 0 : input.staleAfterSeconds;
|
|
24
|
+
resolveDurableCallCachePolicy(staleAfterSeconds);
|
|
25
|
+
if (staleAfterSeconds !== null && !Number.isSafeInteger(staleAfterSeconds)) {
|
|
31
26
|
throw new Error(DURABLE_CALL_STALE_AFTER_SECONDS_ERROR);
|
|
32
27
|
}
|
|
33
|
-
if (input.force === true &&
|
|
28
|
+
if (input.force === true && staleAfterSeconds !== 0) {
|
|
34
29
|
throw new Error(
|
|
35
30
|
'force: true contradicts reusable freshness. Use staleAfterSeconds: 0.',
|
|
36
31
|
);
|
|
37
32
|
}
|
|
38
33
|
return {
|
|
39
|
-
requested:
|
|
40
|
-
effective:
|
|
34
|
+
requested: staleAfterSeconds,
|
|
35
|
+
effective: staleAfterSeconds,
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
38
|
|
|
@@ -854,6 +854,20 @@ export type DurableReceiptExecutionStore = {
|
|
|
854
854
|
output: unknown | null,
|
|
855
855
|
leaseId?: string | null,
|
|
856
856
|
): Promise<RuntimeStepReceipt | null>;
|
|
857
|
+
/**
|
|
858
|
+
* Publish several immutable completed-cache receipts (the completed-cache
|
|
859
|
+
* insert lease) handed over together, so they share one gateway request.
|
|
860
|
+
* Receipts with `bestEffort` never fail the call; any other failure throws.
|
|
861
|
+
* Absent when the host cannot batch; callers then write them one by one.
|
|
862
|
+
*/
|
|
863
|
+
completeMany?(
|
|
864
|
+
writes: ReadonlyArray<{
|
|
865
|
+
key: string;
|
|
866
|
+
output: unknown;
|
|
867
|
+
bestEffort?: true;
|
|
868
|
+
sourceRunManifest?: true;
|
|
869
|
+
}>,
|
|
870
|
+
): Promise<ReadonlyMap<string, RuntimeStepReceipt | null>>;
|
|
857
871
|
/**
|
|
858
872
|
* Newest-wins shared read result (`ctx:{org}:cache:v1:*`). The receiver
|
|
859
873
|
* stamps the time; absent when the host has no receipt gateway.
|
|
@@ -27,12 +27,31 @@ export type CompletedCall = {
|
|
|
27
27
|
undefinedValue?: true;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* An immutable completed-cache receipt a call hands to the freshness layer
|
|
32
|
+
* instead of writing it, so the call's finishing writes share one request.
|
|
33
|
+
*/
|
|
34
|
+
export type DeferredReceiptWrite = {
|
|
35
|
+
key: string;
|
|
36
|
+
output: unknown;
|
|
37
|
+
/** A pointer whose failure never fails the call (source-run replay pointer). */
|
|
38
|
+
bestEffort?: true;
|
|
39
|
+
sourceRunManifest?: true;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type DeferredReceiptPublication = {
|
|
43
|
+
defer(write: DeferredReceiptWrite): void;
|
|
44
|
+
};
|
|
45
|
+
|
|
30
46
|
type FreshnessStore = Pick<
|
|
31
47
|
DurableReceiptExecutionStore,
|
|
32
48
|
'enabled' | 'get' | 'complete'
|
|
33
49
|
> &
|
|
34
50
|
Partial<
|
|
35
|
-
Pick<
|
|
51
|
+
Pick<
|
|
52
|
+
DurableReceiptExecutionStore,
|
|
53
|
+
'getMany' | 'publishLatestCacheResult' | 'completeMany'
|
|
54
|
+
>
|
|
36
55
|
>;
|
|
37
56
|
|
|
38
57
|
/** Shape tag of a newest shared result entry (`ctx:{org}:cache:v1:*`). */
|
|
@@ -226,7 +245,12 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
226
245
|
requestedStaleAfterSeconds: number | null;
|
|
227
246
|
effectiveStaleAfterSeconds: number | null;
|
|
228
247
|
store: FreshnessStore;
|
|
229
|
-
|
|
248
|
+
/**
|
|
249
|
+
* `publication` collects receipts the call would otherwise write one by one.
|
|
250
|
+
* They are published together with this call's operation receipt, before the
|
|
251
|
+
* call returns, so customer code never observes a result that is not durable.
|
|
252
|
+
*/
|
|
253
|
+
execute: (publication: DeferredReceiptPublication) => Promise<T>;
|
|
230
254
|
completedAt?: (value: T) => number | undefined;
|
|
231
255
|
/**
|
|
232
256
|
* False keeps an empty or unsuccessful result out of the shared latest
|
|
@@ -469,6 +493,53 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
469
493
|
return stored;
|
|
470
494
|
};
|
|
471
495
|
|
|
496
|
+
/**
|
|
497
|
+
* Publish immutable completed-cache receipts. Every one is durable, or the
|
|
498
|
+
* call fails, before this returns; only a best-effort pointer may be lost.
|
|
499
|
+
*/
|
|
500
|
+
const publishFinishingWrites = async (
|
|
501
|
+
writes: readonly DeferredReceiptWrite[],
|
|
502
|
+
): Promise<void> => {
|
|
503
|
+
if (writes.length === 0) return;
|
|
504
|
+
const verify = async (key: string, answer: RuntimeStepReceipt | null) => {
|
|
505
|
+
if (answer?.status === 'completed' || answer?.status === 'skipped') {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const stored = await input.store.get(key);
|
|
509
|
+
if (stored?.status !== 'completed' && stored?.status !== 'skipped') {
|
|
510
|
+
throw new Error(
|
|
511
|
+
key === operationKey || key.startsWith(`${cachePrefix}:reusable:`)
|
|
512
|
+
? 'Completed freshness receipt publication failed.'
|
|
513
|
+
: `Tool Result Receipt ${key} could not publish a completed result.`,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
const { completeMany } = input.store;
|
|
518
|
+
if (!completeMany) {
|
|
519
|
+
for (const write of writes) {
|
|
520
|
+
try {
|
|
521
|
+
await verify(
|
|
522
|
+
write.key,
|
|
523
|
+
await input.store.complete(
|
|
524
|
+
write.key,
|
|
525
|
+
input.runId,
|
|
526
|
+
write.output,
|
|
527
|
+
COMPLETED_RECEIPT_CACHE_INSERT_LEASE_ID,
|
|
528
|
+
),
|
|
529
|
+
);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (!write.bestEffort || isCancellationError(error)) throw error;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const required = writes.filter((write) => !write.bestEffort);
|
|
537
|
+
const answers = await completeMany.call(input.store, writes);
|
|
538
|
+
for (const write of required) {
|
|
539
|
+
await verify(write.key, answers.get(write.key) ?? null);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
472
543
|
const ttl = input.effectiveStaleAfterSeconds;
|
|
473
544
|
const admissionTime = now();
|
|
474
545
|
const currentPartition =
|
|
@@ -536,7 +607,29 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
536
607
|
}
|
|
537
608
|
}
|
|
538
609
|
|
|
539
|
-
const
|
|
610
|
+
const deferred: DeferredReceiptWrite[] = [];
|
|
611
|
+
let value: T;
|
|
612
|
+
try {
|
|
613
|
+
value = await input.execute({
|
|
614
|
+
defer: (write) => {
|
|
615
|
+
deferred.push(write);
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
} catch (error) {
|
|
619
|
+
// A deferred write is a result the call already received (the provider
|
|
620
|
+
// answered and was paid) before a later step threw, for example a durable
|
|
621
|
+
// suspension or a cancelled signal. Before deferral that result receipt
|
|
622
|
+
// was written at once, so a resumed call reused it instead of paying the
|
|
623
|
+
// provider again. Keep that: publish what was deferred, then rethrow the
|
|
624
|
+
// original error unchanged, because it may be suspension control flow.
|
|
625
|
+
// The operation and reusable pointers are not published, exactly as
|
|
626
|
+
// before. If this publication itself fails, the call keeps the documented
|
|
627
|
+
// at-least-once behavior and re-executes on resume.
|
|
628
|
+
if (deferred.length > 0) {
|
|
629
|
+
await publishFinishingWrites(deferred).catch(() => undefined);
|
|
630
|
+
}
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
540
633
|
assertNoSecretTaint(value, 'Freshness call result');
|
|
541
634
|
const completedAt = input.completedAt?.(value) ?? now();
|
|
542
635
|
if (!Number.isSafeInteger(completedAt) || completedAt < 0) {
|
|
@@ -545,7 +638,9 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
545
638
|
const completed = completedCallForResult(value, completedAt);
|
|
546
639
|
|
|
547
640
|
// Recover this exact operation even if reusable publication fails afterwards.
|
|
548
|
-
|
|
641
|
+
const pointers: DeferredReceiptWrite[] = [
|
|
642
|
+
{ key: operationKey, output: completed },
|
|
643
|
+
];
|
|
549
644
|
// The same eligibility gates the policy bucket and the newest shared
|
|
550
645
|
// result: a failed, empty or non-final answer recovers within this run but
|
|
551
646
|
// is never handed to another call.
|
|
@@ -557,12 +652,27 @@ export async function executeWithFreshnessReceipt<T>(input: {
|
|
|
557
652
|
ttl === null
|
|
558
653
|
? 'indefinite'
|
|
559
654
|
: Math.floor(completed.completedAt / (ttl * 1000));
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
655
|
+
pointers.push({
|
|
656
|
+
key:
|
|
657
|
+
ttl === null
|
|
658
|
+
? `${cachePrefix}:reusable:indefinite`
|
|
659
|
+
: `${cachePrefix}:reusable:${ttl}:${completionPartition}`,
|
|
660
|
+
output: completed,
|
|
661
|
+
});
|
|
565
662
|
}
|
|
663
|
+
// One request carries the call's result receipt, its replay pointer and its
|
|
664
|
+
// operation and reusable receipts. The operation and reusable receipts name
|
|
665
|
+
// the result receipt only when the result is stored by reference; a pointer
|
|
666
|
+
// must never be visible before its referent, so that one case publishes the
|
|
667
|
+
// referent first. An inline operation receipt holds its own value.
|
|
668
|
+
const referent = completed.valueReceiptKey;
|
|
669
|
+
const pointersNeedReferent =
|
|
670
|
+
referent !== undefined &&
|
|
671
|
+
deferred.some((write) => write.key === referent && !write.bestEffort);
|
|
672
|
+
await publishFinishingWrites(
|
|
673
|
+
pointersNeedReferent ? deferred : [...deferred, ...pointers],
|
|
674
|
+
);
|
|
675
|
+
if (pointersNeedReferent) await publishFinishingWrites(pointers);
|
|
566
676
|
// A refresh publishes only the newest shared result, not a policy bucket.
|
|
567
677
|
if (
|
|
568
678
|
(ttl !== 0 || input.publishLatestOnRefresh === true) &&
|