deepline 0.3.517 → 0.3.519

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.
Files changed (167) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/bounded-batch-function.ts +21 -3
  3. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +163 -63
  4. package/dist/bundling-sources/shared_libs/play-runtime/durable-call-policy.ts +8 -13
  5. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +14 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +7 -1
  7. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +119 -9
  8. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +8 -2
  9. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +12 -11
  10. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/detached-runner-readiness-pacing.ts +44 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +16 -6
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +142 -68
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +42 -1
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-completion-coalescer.ts +8 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +22 -0
  16. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -7
  17. package/dist/cli/{artifacts-7KCI2YKZ.js → artifacts-YRKH7KNC.js} +21 -19
  18. package/dist/cli/{artifacts-LGDMUNP5.mjs → artifacts-ZZULJ6X5.mjs} +9 -7
  19. package/dist/cli/auth-DF6WJLN2.js +43 -0
  20. package/dist/cli/{auth-W75IFBH3.mjs → auth-WU2BDO3T.mjs} +5 -5
  21. package/dist/cli/{billing-WF2UJVMC.mjs → billing-DG62VVXW.mjs} +7 -7
  22. package/dist/cli/{billing-SWBINQZC.js → billing-MUMMBMQK.js} +82 -82
  23. package/dist/cli/{chunk-G7DNBQQE.js → chunk-25WXWSFS.js} +22 -22
  24. package/dist/cli/{chunk-PHP674RR.mjs → chunk-3CUIIVGR.mjs} +1 -1
  25. package/dist/cli/{chunk-ZWPRFZAF.js → chunk-4ECU5DI3.js} +26 -26
  26. package/dist/cli/{chunk-4T6AUBI7.js → chunk-4PWBHYH4.js} +7 -7
  27. package/dist/cli/{chunk-SQ4KGLWP.js → chunk-52DFTRVC.js} +16 -16
  28. package/dist/cli/{chunk-ZA3DRRHR.mjs → chunk-5A2SIIPH.mjs} +1 -1
  29. package/dist/cli/{chunk-ASMUKT2H.mjs → chunk-A7W3CCU5.mjs} +5 -5
  30. package/dist/cli/{chunk-QGLY4XXN.mjs → chunk-AL7FDMD6.mjs} +1 -1
  31. package/dist/cli/{chunk-3XV2UGZ7.mjs → chunk-AXA5DFY5.mjs} +1 -1
  32. package/dist/cli/{chunk-5A6UQOYE.js → chunk-BQYXIAJM.js} +3 -3
  33. package/dist/cli/{chunk-TYFTBB24.js → chunk-C7ZD4LXZ.js} +2 -2
  34. package/dist/cli/{chunk-T6KXZNWM.mjs → chunk-CBMTBMIJ.mjs} +1 -1
  35. package/dist/cli/{chunk-IKBC5NYO.mjs → chunk-CRE3OGHH.mjs} +2 -2
  36. package/dist/cli/{chunk-UIIUCB4A.js → chunk-E6YWCXII.js} +16 -16
  37. package/dist/cli/{chunk-CDRBJOTJ.js → chunk-EMV6EHK2.js} +9 -9
  38. package/dist/cli/{chunk-STHTJ56U.js → chunk-F6XD4CRW.js} +1 -1
  39. package/dist/cli/{chunk-AQUV5AXP.mjs → chunk-FEJKDR67.mjs} +1 -1
  40. package/dist/cli/{chunk-IUFWQ5HW.mjs → chunk-FJAGGBDR.mjs} +1 -1
  41. package/dist/cli/{chunk-C5QDX54T.mjs → chunk-FTJ2D3XD.mjs} +3 -3
  42. package/dist/cli/{chunk-7P4BIRFS.js → chunk-G2QD575P.js} +6 -6
  43. package/dist/cli/{chunk-RHF5UIYX.js → chunk-GO467AXG.js} +41 -41
  44. package/dist/cli/{chunk-KQKUPUVG.mjs → chunk-HKKC7J6K.mjs} +6 -6
  45. package/dist/cli/{chunk-SWAXMOMW.js → chunk-HXPHRSNM.js} +14 -14
  46. package/dist/cli/{chunk-D4OZSC3C.js → chunk-HYR34KFA.js} +5 -4
  47. package/dist/cli/{chunk-TRIFS75L.js → chunk-I3ICKVYH.js} +53 -53
  48. package/dist/cli/{chunk-PGQ24IXZ.mjs → chunk-IMIHYCJ5.mjs} +5 -5
  49. package/dist/cli/{chunk-4XJL4F5U.mjs → chunk-J4X4RNSP.mjs} +3 -3
  50. package/dist/cli/{chunk-BNWI33W3.js → chunk-LKYLIZ5X.js} +2 -2
  51. package/dist/cli/{chunk-HN3M54JJ.mjs → chunk-MI5DKOBD.mjs} +2 -2
  52. package/dist/cli/{chunk-YLI5CKGB.mjs → chunk-N3LUYBOB.mjs} +10 -10
  53. package/dist/cli/{chunk-NQL2KV3T.mjs → chunk-NH22WUUG.mjs} +2 -2
  54. package/dist/cli/{chunk-S25URYNM.mjs → chunk-NIJE62ZD.mjs} +1 -1
  55. package/dist/cli/{chunk-NKFVUGSA.js → chunk-O655PVT4.js} +7 -7
  56. package/dist/cli/{chunk-6VFY6ZZJ.js → chunk-ORNLTNBN.js} +44 -44
  57. package/dist/cli/{chunk-PTJFL3WW.js → chunk-P62S3ZMS.js} +11 -11
  58. package/dist/cli/{chunk-QMJGNAK4.js → chunk-PK6VYYEY.js} +5 -5
  59. package/dist/cli/{chunk-TJZAYI77.mjs → chunk-R3OAKFHJ.mjs} +5 -5
  60. package/dist/cli/{chunk-R7MNIJZN.mjs → chunk-RHQKDHCX.mjs} +2 -2
  61. package/dist/cli/{chunk-PGSAISXG.mjs → chunk-RQ2BHYUM.mjs} +2 -2
  62. package/dist/cli/{chunk-MZBQTSAX.js → chunk-RQDD2VV3.js} +5 -5
  63. package/dist/cli/{chunk-HRHAX2IU.mjs → chunk-RU5JRQKJ.mjs} +2 -2
  64. package/dist/cli/{chunk-VPM64DAL.js → chunk-S7R4O62I.js} +6 -6
  65. package/dist/cli/{chunk-22S2QG2H.mjs → chunk-SBF4K3QF.mjs} +4 -4
  66. package/dist/cli/{chunk-U6QC4WT6.js → chunk-TT2XB433.js} +4 -4
  67. package/dist/cli/{chunk-PIXPD62R.mjs → chunk-UB2REJPL.mjs} +2 -2
  68. package/dist/cli/{chunk-JH43VNY6.js → chunk-UMPHUAGZ.js} +3 -3
  69. package/dist/cli/{chunk-YXGTO5XA.mjs → chunk-VE6FHVXZ.mjs} +5 -4
  70. package/dist/cli/{chunk-AUQQCAGW.js → chunk-XBS4RDKU.js} +96 -96
  71. package/dist/cli/{chunk-5ANZ57SA.js → chunk-XUCAH3LN.js} +10 -10
  72. package/dist/cli/{chunk-HM42PD4D.mjs → chunk-Y7D6L4M7.mjs} +5 -5
  73. package/dist/cli/{chunk-EP4NPHKZ.mjs → chunk-YRU46P7H.mjs} +1 -1
  74. package/dist/cli/{chunk-N7L76I62.js → chunk-ZQ23WQP3.js} +2 -2
  75. package/dist/cli/command-docs.js +2 -2
  76. package/dist/cli/command-docs.mjs +1 -1
  77. package/dist/cli/{csv-I22P5M5Y.mjs → csv-3TUJHAOW.mjs} +4 -4
  78. package/dist/cli/{csv-MEQSN7FP.js → csv-BKWIYPMK.js} +13 -13
  79. package/dist/cli/{db-RSDJF4D7.js → db-EJMJDKDA.js} +27 -27
  80. package/dist/cli/{db-X7SQQW34.mjs → db-I75IQ7XI.mjs} +6 -6
  81. package/dist/cli/describe-EAK3MPTG.js +50 -0
  82. package/dist/cli/{describe-H6KM4KPD.mjs → describe-RUFLLRIN.mjs} +18 -18
  83. package/dist/cli/describe-core.d.mts +3 -3
  84. package/dist/cli/describe-core.d.ts +3 -3
  85. package/dist/cli/{executions-KPEOFSKD.js → executions-TQJCMUUG.js} +8 -8
  86. package/dist/cli/{executions-SCID4WZT.mjs → executions-VW3MYJEE.mjs} +6 -6
  87. package/dist/cli/{feedback-PQRD6XLU.mjs → feedback-76342G7E.mjs} +5 -5
  88. package/dist/cli/{feedback-R3R7CENU.js → feedback-UFAEXH5B.js} +10 -10
  89. package/dist/cli/{git-IWUFEG56.mjs → git-L5XKAODI.mjs} +5 -5
  90. package/dist/cli/git-OOCPCIGZ.js +25 -0
  91. package/dist/cli/index.js +145 -145
  92. package/dist/cli/index.mjs +44 -44
  93. package/dist/cli/{legacy-noops-42W5OOGA.mjs → legacy-noops-DKAZ7JG3.mjs} +6 -6
  94. package/dist/cli/{legacy-noops-S2EQ3DW6.js → legacy-noops-DM66YISP.js} +9 -9
  95. package/dist/cli/{monitors-Q6WIKBLU.js → monitors-NKDIH4TY.js} +100 -100
  96. package/dist/cli/{monitors-WS7SZ4X6.mjs → monitors-QXEJI54B.mjs} +7 -7
  97. package/dist/cli/{org-RLGVNZQ7.mjs → org-KZQCVREB.mjs} +6 -6
  98. package/dist/cli/{org-XAYQWGZK.js → org-NKIIBUNO.js} +72 -72
  99. package/dist/cli/{pages-H5QIFW6M.mjs → pages-E7IT5SWT.mjs} +6 -6
  100. package/dist/cli/{pages-RHET3HGT.js → pages-UJUFCJEL.js} +18 -18
  101. package/dist/cli/{play-4ZWS7CAF.mjs → play-AKL5E2DF.mjs} +18 -18
  102. package/dist/cli/{play-OPQJACQN.js → play-SPI5MO67.js} +317 -317
  103. package/dist/cli/{providers-HQ47SEXO.js → providers-4NVQ3FSC.js} +9 -9
  104. package/dist/cli/{providers-276TVAW5.mjs → providers-6HSSVI74.mjs} +6 -6
  105. package/dist/cli/{quickstart-VYTNG7KH.mjs → quickstart-EHLEHSMI.mjs} +4 -4
  106. package/dist/cli/{quickstart-C2B32MOC.js → quickstart-FEQD7S4Z.js} +6 -6
  107. package/dist/cli/{run-O4MJLK2I.js → run-GH6ECTJF.js} +41 -41
  108. package/dist/cli/{run-4SIWK5Y2.mjs → run-IWVM7BD6.mjs} +23 -23
  109. package/dist/cli/search-NIRYA3VL.js +33 -0
  110. package/dist/cli/{search-ZC4SHHDP.mjs → search-X4CDMN7J.mjs} +8 -8
  111. package/dist/cli/{search-output-7LZ4T33R.js → search-output-IIYMGZTQ.js} +6 -6
  112. package/dist/cli/{search-output-EZN2UETF.mjs → search-output-PJ7N5WUQ.mjs} +4 -4
  113. package/dist/cli/{secrets-JHJSUL6I.mjs → secrets-4YPMC7XZ.mjs} +6 -6
  114. package/dist/cli/{secrets-QRNMUW5O.js → secrets-QPP2FXID.js} +15 -15
  115. package/dist/cli/sessions-5I2IFTW7.js +18 -0
  116. package/dist/cli/{sessions-CAZ4FK7F.mjs → sessions-BEOI47VZ.mjs} +6 -6
  117. package/dist/cli/{settings-52P7HHH4.js → settings-FZDONKPW.js} +86 -86
  118. package/dist/cli/{settings-PI3F4DXU.mjs → settings-VHULXNY3.mjs} +13 -13
  119. package/dist/cli/{setup-KVZ4AMHC.mjs → setup-5IV3NHGD.mjs} +10 -10
  120. package/dist/cli/{setup-Y5BFQAWN.js → setup-LZ6IN5JS.js} +50 -50
  121. package/dist/cli/{skills-FG64C72D.mjs → skills-FZAFBW5J.mjs} +8 -8
  122. package/dist/cli/skills-WJWLFSHI.js +37 -0
  123. package/dist/cli/tools-SH35NRGU.js +57 -0
  124. package/dist/cli/{tools-2SPVUFNO.mjs → tools-TLBH3RFK.mjs} +17 -17
  125. package/dist/cli/{update-GJD5NYSO.mjs → update-KPLIZYOV.mjs} +10 -10
  126. package/dist/cli/update-MA46YSGR.js +35 -0
  127. package/dist/cli/{workflow-LGITND7U.js → workflow-ACHPT3DD.js} +17 -17
  128. package/dist/cli/{workflow-JGGDTRCA.mjs → workflow-GYJOYYWK.mjs} +7 -7
  129. package/dist/{client-K1g4ab5Y.d.mts → client-CpSiHSti.d.mts} +1 -1
  130. package/dist/{client-CQSPuqxh.d.ts → client-CswZYCGj.d.ts} +1 -1
  131. package/dist/{client-core-BksGf5Gd.d.mts → client-core-C1xVOg8Y.d.mts} +1 -1
  132. package/dist/{client-core-BlaqOlQ7.d.ts → client-core-D2pLt36Q.d.ts} +1 -1
  133. package/dist/{compiler-manifest-BliMS7ax.d.mts → compiler-manifest-B4mIIbw7.d.mts} +3 -3
  134. package/dist/{compiler-manifest-BliMS7ax.d.ts → compiler-manifest-B4mIIbw7.d.ts} +3 -3
  135. package/dist/{errors-BZ6Zq1cz.d.mts → errors-C2F4qzAq.d.mts} +1 -1
  136. package/dist/{errors-xfNscfS1.d.ts → errors-Gj9i5Rkd.d.ts} +1 -1
  137. package/dist/{index-DbvCg4zg.d.mts → index-5JZBufdF.d.mts} +1 -1
  138. package/dist/{index-FGdQv8J8.d.ts → index-BXtSj8bv.d.ts} +1 -1
  139. package/dist/index.d.mts +7 -7
  140. package/dist/index.d.ts +7 -7
  141. package/dist/index.js +9 -9
  142. package/dist/index.mjs +6 -6
  143. package/dist/install-integrity.json +117 -116
  144. package/dist/plays/bundle-play-file.d.mts +3 -3
  145. package/dist/plays/bundle-play-file.d.ts +3 -3
  146. package/dist/plays/bundle-play-file.mjs +3 -4
  147. package/dist/plays/play-description.d.mts +2 -2
  148. package/dist/plays/play-description.d.ts +2 -2
  149. package/dist/plays/run-request.d.mts +2 -2
  150. package/dist/plays/run-request.d.ts +2 -2
  151. package/dist/release.d.mts +1 -1
  152. package/dist/release.d.ts +1 -1
  153. package/dist/release.js +2 -2
  154. package/dist/release.mjs +1 -1
  155. package/dist/server.d.mts +4 -4
  156. package/dist/server.d.ts +4 -4
  157. package/dist/server.js +5 -5
  158. package/dist/server.mjs +3 -3
  159. package/package.json +1 -1
  160. package/dist/cli/auth-MHMCB7ND.js +0 -43
  161. package/dist/cli/describe-BCKVF2DC.js +0 -50
  162. package/dist/cli/git-NJGV6I6K.js +0 -25
  163. package/dist/cli/search-NLMIJYHK.js +0 -33
  164. package/dist/cli/sessions-4BVQJDIE.js +0 -18
  165. package/dist/cli/skills-LI4UH6FW.js +0 -37
  166. package/dist/cli/tools-GUC4BGUK.js +0 -57
  167. 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.517',
208
+ version: '0.3.519',
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(group: OpenGroup<Value, Result, Key>): void {
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
- }, this.#flushMs);
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
- if (key && options.bestEffortKeys?.has(key)) {
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
- const authScope = await this.resolveToolAuthScopeDigest(toolId);
14495
- const actionVersion =
14496
- (await this.#options.getToolActionCacheVersion?.(toolId))?.trim() ?? '';
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
- let sharedReceipt: RuntimeStepReceipt | null = null;
15000
- const historicalReceipt = await this.withRuntimeReceiptHydrationTurn(
15001
- async (turn) => {
15002
- if (sharedRead) {
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 = await this.withRuntimeReceiptHydrationTurn(
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
- await this.persistSourceRunToolReceiptManifest({
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 !== 0
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
- if (input.staleAfterSeconds === undefined) {
22
- throw new Error(
23
- 'Choose staleAfterSeconds explicitly: 0 for a fresh call, a positive whole number of seconds to accept a completed answer up to that old, or null to accept any age.',
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 && input.staleAfterSeconds !== 0) {
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: input.staleAfterSeconds,
40
- effective: input.staleAfterSeconds,
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.
@@ -23,8 +23,14 @@ export const DURABLE_RUNS_ROLLOUT = {
23
23
  /**
24
24
  * The worker defers a replay-safe run whose attempt ended in a post-code
25
25
  * platform failure instead of failing it.
26
+ *
27
+ * The switch is read by the worker and the execution gateway of the
28
+ * release that runs it, so a lane built before this flip keeps failing such
29
+ * runs. Turned off again, a lane no longer continues a run already
30
+ * deferred (its start gate and fence-owner attempts are ignored), so roll
31
+ * back only after deferred runs drain.
26
32
  */
27
- automaticPostCodeRecovery: false,
33
+ automaticPostCodeRecovery: true,
28
34
  /**
29
35
  * After a live edition-11 read with `staleAfterSeconds` other than 0
30
36
  * (including one refreshed by `--refresh-cache`), also publish the result
@@ -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<DurableReceiptExecutionStore, 'getMany' | 'publishLatestCacheResult'>
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
- execute: () => Promise<T>;
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 value = await input.execute();
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
- await publish(operationKey, completed);
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
- const resultKey =
561
- ttl === null
562
- ? `${cachePrefix}:reusable:indefinite`
563
- : `${cachePrefix}:reusable:${ttl}:${completionPartition}`;
564
- await publish(resultKey, completed);
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) &&