deepline 0.3.527 → 0.3.529

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 (147) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +197 -207
  3. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +5 -0
  4. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +66 -1
  5. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +156 -161
  6. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +56 -1
  7. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +11 -1
  8. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +36 -6
  9. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +35 -5
  10. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +12 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +1 -0
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +16 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +26 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +129 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +6 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-claim-loop-timing.ts +145 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +48 -5
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +475 -101
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +13 -5
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +30 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +43 -16
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +105 -13
  23. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/result-receipt-policy.ts +10 -1
  24. package/dist/cli/auth-P7M7SXM5.js +43 -0
  25. package/dist/cli/{auth-LRMMQFJ4.mjs → auth-V7A6TU4G.mjs} +5 -5
  26. package/dist/cli/{billing-WZZDXVRJ.mjs → billing-5VBUYPWW.mjs} +6 -6
  27. package/dist/cli/{billing-M76MMWZB.js → billing-XF6SAA5Y.js} +79 -79
  28. package/dist/cli/{chunk-HB3YUHEL.js → chunk-2GV54JFN.js} +44 -44
  29. package/dist/cli/{chunk-ETXQZGQU.js → chunk-4722FTYU.js} +16 -16
  30. package/dist/cli/{chunk-AXFHQWGA.mjs → chunk-4A4OQMJX.mjs} +1 -1
  31. package/dist/cli/{chunk-66YLAQ2X.js → chunk-4BKE63Q7.js} +26 -26
  32. package/dist/cli/{chunk-UKOG6PCB.mjs → chunk-5NZEA2YV.mjs} +1 -1
  33. package/dist/cli/{chunk-JEIGNX3G.mjs → chunk-6XZIXDLC.mjs} +5 -5
  34. package/dist/cli/{chunk-RGL2YGJZ.js → chunk-7RTDSHMB.js} +2 -2
  35. package/dist/cli/{chunk-2A6IRSE6.js → chunk-7SRZTSHU.js} +5 -5
  36. package/dist/cli/{chunk-7DPWGAOU.js → chunk-7Z3ZXSOX.js} +3 -3
  37. package/dist/cli/{chunk-JSEISVAZ.js → chunk-AP7DNG6D.js} +4 -4
  38. package/dist/cli/{chunk-P5ZU5ZHA.mjs → chunk-BOWZ3OOU.mjs} +1 -1
  39. package/dist/cli/{chunk-YUYDP2EG.js → chunk-BRQDN67G.js} +6 -6
  40. package/dist/cli/{chunk-VV2AFJ3I.mjs → chunk-C2WTS7WY.mjs} +5 -5
  41. package/dist/cli/{chunk-GIRMVMXP.mjs → chunk-DKX5CGTG.mjs} +1 -1
  42. package/dist/cli/{chunk-OXHY3LD3.js → chunk-DPGPXARU.js} +53 -53
  43. package/dist/cli/{chunk-JSVHBJE2.mjs → chunk-E7CN5GEM.mjs} +2 -2
  44. package/dist/cli/{chunk-KDFUQRVU.mjs → chunk-ETCGTKLF.mjs} +1 -1
  45. package/dist/cli/{chunk-UJHS2O5O.mjs → chunk-EW33RCLA.mjs} +3 -3
  46. package/dist/cli/{chunk-OLSATEDQ.js → chunk-FCNSJHED.js} +6 -6
  47. package/dist/cli/{chunk-YKPMIJJ2.mjs → chunk-FWC47SCG.mjs} +2 -2
  48. package/dist/cli/{chunk-VTXBV4AX.mjs → chunk-FXHKNZM2.mjs} +1 -1
  49. package/dist/cli/{chunk-MMM2WMTF.mjs → chunk-G4SYSUDB.mjs} +5 -5
  50. package/dist/cli/{chunk-HA2J2OAS.mjs → chunk-GPU4ULMY.mjs} +10 -10
  51. package/dist/cli/{chunk-3L2DNG5X.js → chunk-H2JAXOPP.js} +11 -11
  52. package/dist/cli/{chunk-QKY3H3HA.mjs → chunk-HV4UKMBB.mjs} +4 -4
  53. package/dist/cli/{chunk-QKKT5G4K.mjs → chunk-K55VBSCA.mjs} +3 -3
  54. package/dist/cli/{chunk-EOL7PXLW.js → chunk-KAI64HV7.js} +7 -7
  55. package/dist/cli/{chunk-YJ4YVFXC.js → chunk-KSUWW26I.js} +13 -13
  56. package/dist/cli/{chunk-XI47UAVU.js → chunk-L3J7IAYE.js} +9 -9
  57. package/dist/cli/{chunk-R6IWWPY7.js → chunk-M47I47FK.js} +14 -14
  58. package/dist/cli/{chunk-E4TEZE62.mjs → chunk-NDVCVFZW.mjs} +2 -2
  59. package/dist/cli/{chunk-UAQ7ZWRP.js → chunk-NVH6ULDP.js} +22 -22
  60. package/dist/cli/{chunk-M45S7JAY.mjs → chunk-NVSMSP2J.mjs} +2 -2
  61. package/dist/cli/{chunk-SRQQAUXN.js → chunk-OA4FI5ZM.js} +2 -2
  62. package/dist/cli/{chunk-NVII3RWQ.mjs → chunk-PAAREIKG.mjs} +2 -2
  63. package/dist/cli/{chunk-5YR6CDJ2.mjs → chunk-PJDYY5JL.mjs} +6 -6
  64. package/dist/cli/{chunk-LHMHUA5D.js → chunk-PNWBODCB.js} +7 -7
  65. package/dist/cli/{chunk-C7A44BZ7.js → chunk-QTQWPSAK.js} +3 -3
  66. package/dist/cli/{chunk-MIL5YDKZ.mjs → chunk-R62Z4INU.mjs} +2 -2
  67. package/dist/cli/{chunk-YSDPYQBH.js → chunk-RWY2QLJ4.js} +41 -41
  68. package/dist/cli/{chunk-XYG4IOJK.js → chunk-TEFO5AS2.js} +98 -98
  69. package/dist/cli/{chunk-ZHY7AY5V.js → chunk-UMCEXTRM.js} +16 -16
  70. package/dist/cli/{chunk-77VNC2KF.mjs → chunk-XE4PQE2O.mjs} +1 -1
  71. package/dist/cli/{chunk-OKRBGXDI.js → chunk-XEZSORKG.js} +5 -5
  72. package/dist/cli/{chunk-3PQDEBO6.js → chunk-XZ6OY3BH.js} +1 -1
  73. package/dist/cli/{chunk-2L3HVEBM.mjs → chunk-Y4P6XJHU.mjs} +1 -1
  74. package/dist/cli/{chunk-RMCKTV4R.mjs → chunk-YVJJEMNQ.mjs} +1 -1
  75. package/dist/cli/{chunk-HQZLTK3P.js → chunk-ZEIN5YJS.js} +2 -2
  76. package/dist/cli/{chunk-RTPLRMEB.mjs → chunk-ZULLXAJJ.mjs} +5 -5
  77. package/dist/cli/{chunk-4YN7DZEA.mjs → chunk-ZYMX7KZE.mjs} +2 -2
  78. package/dist/cli/{csv-FEFNXZF7.mjs → csv-IHLVHG35.mjs} +4 -4
  79. package/dist/cli/{csv-IRP6VT7Q.js → csv-VEKMGGOE.js} +13 -13
  80. package/dist/cli/{db-Y5VNPNRD.js → db-NTFFISQG.js} +27 -27
  81. package/dist/cli/{db-IHECMWZ3.mjs → db-RKLVYARP.mjs} +6 -6
  82. package/dist/cli/{describe-XCVC2WLL.mjs → describe-62ELB5DZ.mjs} +18 -18
  83. package/dist/cli/describe-JXOGKT6C.js +50 -0
  84. package/dist/cli/{executions-3FWZYUJV.mjs → executions-5BMZW4C7.mjs} +6 -6
  85. package/dist/cli/{executions-QH3KJ6MA.js → executions-X7NMKMXW.js} +8 -8
  86. package/dist/cli/{feedback-BGHWMOLH.js → feedback-RDN5O4AT.js} +14 -14
  87. package/dist/cli/{feedback-F3OZXOPM.mjs → feedback-UHHWCIFD.mjs} +6 -6
  88. package/dist/cli/{git-RWPH3D75.mjs → git-3M33GKOW.mjs} +5 -5
  89. package/dist/cli/git-7VZGGIGZ.js +25 -0
  90. package/dist/cli/index.js +141 -141
  91. package/dist/cli/index.mjs +43 -43
  92. package/dist/cli/{legacy-noops-5ADSTBJ5.mjs → legacy-noops-7RVRPF5B.mjs} +6 -6
  93. package/dist/cli/{legacy-noops-G6CYD5LM.js → legacy-noops-ENKN6JU4.js} +9 -9
  94. package/dist/cli/{monitors-AFNAU3A2.mjs → monitors-FJPDMUQ6.mjs} +7 -7
  95. package/dist/cli/{monitors-VZCBZO26.js → monitors-YOWDFGIR.js} +100 -100
  96. package/dist/cli/{org-X4QRYBC4.js → org-4GBLI75H.js} +86 -86
  97. package/dist/cli/{org-JVLYTU24.mjs → org-H24LOZAC.mjs} +6 -6
  98. package/dist/cli/{pages-VELKZKBL.mjs → pages-BKM2D6BV.mjs} +6 -6
  99. package/dist/cli/{pages-YMM4KBW5.js → pages-WWVLYB5K.js} +18 -18
  100. package/dist/cli/{play-MIY6BYRB.mjs → play-M3CSYH3A.mjs} +18 -18
  101. package/dist/cli/{play-J7DEBHI7.js → play-TXHKCG6B.js} +317 -317
  102. package/dist/cli/{providers-2H3W3W7G.mjs → providers-EW5WTMTX.mjs} +6 -6
  103. package/dist/cli/{providers-TOUB7Y2A.js → providers-XL4SNFHU.js} +9 -9
  104. package/dist/cli/{quickstart-LHY2LN3P.js → quickstart-AFQ5MCDL.js} +6 -6
  105. package/dist/cli/{quickstart-GKAS5265.mjs → quickstart-SZSLS553.mjs} +4 -4
  106. package/dist/cli/{run-QCAVDPE5.js → run-MOFHGYSN.js} +41 -41
  107. package/dist/cli/{run-KYGNOWYD.mjs → run-TWXFNH6U.mjs} +23 -23
  108. package/dist/cli/{search-YPGAIFDX.mjs → search-2SW4V4IR.mjs} +8 -8
  109. package/dist/cli/search-V2AGWRLO.js +33 -0
  110. package/dist/cli/{search-output-ASELNQ2U.js → search-output-CJGRPJYD.js} +6 -6
  111. package/dist/cli/{search-output-OOC3VK4T.mjs → search-output-I6DNYXNT.mjs} +4 -4
  112. package/dist/cli/{secrets-VJ4XYSMZ.mjs → secrets-4XXLR6QO.mjs} +6 -6
  113. package/dist/cli/{secrets-KX3TQB4R.js → secrets-SD43HSLX.js} +15 -15
  114. package/dist/cli/{sessions-KUN7H7E5.mjs → sessions-7G32HW5R.mjs} +6 -6
  115. package/dist/cli/sessions-FIRDFPIZ.js +22 -0
  116. package/dist/cli/{settings-JKFYZ2IT.mjs → settings-HSYRY2L5.mjs} +13 -13
  117. package/dist/cli/{settings-5NIF4BU7.js → settings-SYEBDDDJ.js} +86 -86
  118. package/dist/cli/{setup-MYV3IHPS.js → setup-VTWCVCTK.js} +50 -50
  119. package/dist/cli/{setup-5AX3TN6G.mjs → setup-XZVBPKZK.mjs} +10 -10
  120. package/dist/cli/{skills-JLS4CINQ.mjs → skills-OMPEUMRT.mjs} +8 -8
  121. package/dist/cli/skills-RUY7CION.js +37 -0
  122. package/dist/cli/tools-KLIW7G6T.js +57 -0
  123. package/dist/cli/{tools-VBYKD3MJ.mjs → tools-UEDNJI4G.mjs} +17 -17
  124. package/dist/cli/{update-QWAIVJRI.mjs → update-4YVCUSSI.mjs} +10 -10
  125. package/dist/cli/update-FDUZRKKU.js +35 -0
  126. package/dist/cli/{views-TBWGZAVZ.mjs → views-4FP4AJQ2.mjs} +6 -6
  127. package/dist/cli/{views-ZW56JZB5.js → views-ZCCSKWMP.js} +18 -18
  128. package/dist/cli/{workflow-X7UQPJMQ.mjs → workflow-A2D5FALP.mjs} +7 -7
  129. package/dist/cli/{workflow-EKSZST6M.js → workflow-SM4OD4VJ.js} +17 -17
  130. package/dist/index.js +9 -9
  131. package/dist/index.mjs +6 -6
  132. package/dist/install-integrity.json +105 -104
  133. package/dist/release.d.mts +1 -1
  134. package/dist/release.d.ts +1 -1
  135. package/dist/release.js +2 -2
  136. package/dist/release.mjs +1 -1
  137. package/dist/server.js +5 -5
  138. package/dist/server.mjs +3 -3
  139. package/package.json +1 -1
  140. package/dist/cli/auth-C7BBYIQD.js +0 -43
  141. package/dist/cli/describe-MNJVJHRE.js +0 -50
  142. package/dist/cli/git-MDOHEW5J.js +0 -25
  143. package/dist/cli/search-G67CEHR7.js +0 -33
  144. package/dist/cli/sessions-QILPX4XQ.js +0 -22
  145. package/dist/cli/skills-NG32XTZI.js +0 -37
  146. package/dist/cli/tools-OZG3V77R.js +0 -57
  147. package/dist/cli/update-YL5WVSKU.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.527',
208
+ version: '0.3.529',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -293,9 +293,9 @@ import {
293
293
  completedCallForResult,
294
294
  type DeferredReceiptPublication,
295
295
  executeWithFreshnessReceipt,
296
+ type FreshExecutionReplay,
296
297
  latestCacheResultKey,
297
298
  latestCacheResultOutput,
298
- type LegacySlotSearch,
299
299
  type ReplayRefusal,
300
300
  parseLatestCacheResult,
301
301
  type ReplayMismatchPolicy,
@@ -657,12 +657,11 @@ function recordReplayCallAdvance(key: string, advance: number): void {
657
657
  }
658
658
  }
659
659
 
660
- /**
661
- * Call-order slots past the highest one allocated in this attempt that the
662
- * pre-binding slot search also inspects: siblings that started earlier in
663
- * the original attempt but have not started yet in this one.
664
- */
665
- const LEGACY_SLOT_SEARCH_LOOKAHEAD = 16;
660
+ /** Memoizes a lazy computation. */
661
+ function once<T>(compute: () => Promise<T>): () => Promise<T> {
662
+ let computed: Promise<T> | null = null;
663
+ return () => (computed ??= compute());
664
+ }
666
665
 
667
666
  function nextReplayableCallIndex(key: string, freshIndex: number): number {
668
667
  const indexes = rowContext.getStore()?.replayCallIndexes;
@@ -3185,33 +3184,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3185
3184
  inputFingerprint: string;
3186
3185
  /** The invocation id itself is numbered among identical requests. */
3187
3186
  keyEncodesRequest?: true;
3188
- /** This call's call-order slot, for the pre-binding slot search. */
3189
- legacySlot?: { scope: string; index: number };
3190
- }
3191
- >();
3192
- /**
3193
- * Per call-order scope, for receipts recorded before bindings: whether each
3194
- * slot read in this attempt held an unbound receipt, and which slots a call
3195
- * has already proven and taken.
3196
- */
3197
- private readonly legacySlotVerdicts = new Map<
3198
- string,
3199
- (unbound: boolean) => void
3200
- >();
3201
- private readonly legacySlotScopes = new Map<
3202
- string,
3203
- {
3204
- /** Verdicts of slots allocated but not yet read, by index. */
3205
- pending: Map<number, Promise<boolean>>;
3206
- /** A slot of this scope held an unbound receipt in this attempt. */
3207
- anyUnbound: boolean;
3208
- /**
3209
- * Slots taken by a proven pre-binding recovery, with the invocation
3210
- * that took them. The same invocation may take its slot again (a row
3211
- * re-entered after provider backpressure restores its call index);
3212
- * a sibling may not.
3213
- */
3214
- consumed: Map<number, string>;
3187
+ /** A tool call's call-order slot, for the legacy empty-slot guard. */
3188
+ callOrderSlot?: { scope: string; index: number };
3215
3189
  }
3216
3190
  >();
3217
3191
  /** Authored calls whose unverified recovery was already reported. */
@@ -4323,14 +4297,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4323
4297
  this.exactRequestInvocationIds.set(callOrder.id, {
4324
4298
  exactRequestInvocationId: slot(exactRequestScope).id,
4325
4299
  inputFingerprint: requestDigest,
4326
- // Only tools record request identities a slot search can prove.
4327
4300
  ...(operation === 'tool'
4328
- ? { legacySlot: { scope: callOrderScope, index: callOrder.index } }
4301
+ ? { callOrderSlot: { scope: callOrderScope, index: callOrder.index } }
4329
4302
  : {}),
4330
4303
  });
4331
- if (operation === 'tool') {
4332
- this.registerLegacySlot(callOrder.id, callOrderScope, callOrder.index);
4333
- }
4334
4304
  }
4335
4305
  return callOrder.id;
4336
4306
  }
@@ -4376,106 +4346,6 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4376
4346
  * in. Only receipts proven by a recorded request identity are taken, each
4377
4347
  * at most once per attempt.
4378
4348
  */
4379
- /**
4380
- * Registered when the slot is allocated, in allocation order, so a later
4381
- * sibling can wait for this slot's verdict. Settled by the freshness layer
4382
- * once the slot is read, or by `settleLegacySlot` when the call ends first.
4383
- * A scope without unbound receipts is dropped once its slots settle, so
4384
- * runs without pre-binding receipts keep no state here.
4385
- */
4386
- private registerLegacySlot(
4387
- invocationId: string,
4388
- scopeKey: string,
4389
- index: number,
4390
- ): void {
4391
- // A re-entered row reuses its slot; release the earlier registration.
4392
- this.settleLegacySlot(invocationId, { keepSlotEntry: true });
4393
- let scope = this.legacySlotScopes.get(scopeKey);
4394
- if (!scope) {
4395
- scope = { pending: new Map(), anyUnbound: false, consumed: new Map() };
4396
- this.legacySlotScopes.set(scopeKey, scope);
4397
- }
4398
- const state = scope;
4399
- let resolve!: (unbound: boolean) => void;
4400
- const verdict: Promise<boolean> = new Promise<boolean>(
4401
- (settle) => (resolve = settle),
4402
- ).then((unbound) => {
4403
- if (unbound) state.anyUnbound = true;
4404
- if (state.pending.get(index) === verdict) state.pending.delete(index);
4405
- if (
4406
- state.pending.size === 0 &&
4407
- !state.anyUnbound &&
4408
- state.consumed.size === 0 &&
4409
- this.legacySlotScopes.get(scopeKey) === state
4410
- ) {
4411
- this.legacySlotScopes.delete(scopeKey);
4412
- }
4413
- return unbound;
4414
- });
4415
- state.pending.set(index, verdict);
4416
- this.legacySlotVerdicts.set(invocationId, resolve);
4417
- }
4418
-
4419
- /** The call ended (or never reached the freshness layer): release waiters. */
4420
- private settleLegacySlot(
4421
- invocationId: string,
4422
- options?: { keepSlotEntry: true },
4423
- ): void {
4424
- this.legacySlotVerdicts.get(invocationId)?.(false);
4425
- this.legacySlotVerdicts.delete(invocationId);
4426
- if (!options?.keepSlotEntry) {
4427
- this.exactRequestInvocationIds.delete(invocationId);
4428
- }
4429
- }
4430
-
4431
- private legacySlotSearch(
4432
- invocationId: string,
4433
- slot: { scope: string; index: number },
4434
- ): LegacySlotSearch {
4435
- const scope = this.legacySlotScopes.get(slot.scope)!;
4436
- const verdict = this.legacySlotVerdicts.get(invocationId);
4437
- return {
4438
- ownIndex: slot.index,
4439
- reportOwnSlot: (unbound) => verdict?.(unbound),
4440
- priorSlotsUnbound: async () => {
4441
- await Promise.all(
4442
- [...scope.pending]
4443
- .filter(([index]) => index < slot.index)
4444
- .map(([, observed]) => observed),
4445
- );
4446
- return scope.anyUnbound;
4447
- },
4448
- candidates: () => {
4449
- const candidates: Array<{ index: number; invocationId: string }> = [];
4450
- const allocated = Math.max(
4451
- this.freshnessCallIndexByKey.get(slot.scope) ?? 0,
4452
- slot.index + 1,
4453
- );
4454
- const end = allocated + LEGACY_SLOT_SEARCH_LOOKAHEAD;
4455
- for (let index = 0; index < end; index += 1) {
4456
- const claimant = scope.consumed.get(index);
4457
- if (
4458
- index === slot.index ||
4459
- (claimant !== undefined && claimant !== invocationId)
4460
- ) {
4461
- continue;
4462
- }
4463
- candidates.push({
4464
- index,
4465
- invocationId: sha256Hex(`${slot.scope}:${index}`),
4466
- });
4467
- }
4468
- return candidates;
4469
- },
4470
- consume: (index) => {
4471
- const claimant = scope.consumed.get(index);
4472
- if (claimant !== undefined && claimant !== invocationId) return false;
4473
- scope.consumed.set(index, invocationId);
4474
- return true;
4475
- },
4476
- };
4477
- }
4478
-
4479
4349
  /**
4480
4350
  * One structured line per replay refusal, emitted where the refusal is
4481
4351
  * decided, so a Play that catches the error cannot hide it. Rate-limited
@@ -4535,7 +4405,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4535
4405
  semanticKey: string;
4536
4406
  invocationId: string;
4537
4407
  policy: { requested: number | null; effective: number | null };
4538
- execute: (publication: DeferredReceiptPublication) => Promise<T>;
4408
+ execute: (
4409
+ publication: DeferredReceiptPublication,
4410
+ replay?: FreshExecutionReplay,
4411
+ ) => Promise<T>;
4539
4412
  completedAt?: (value: T) => number | undefined;
4540
4413
  sharesResult?: (value: T) => boolean;
4541
4414
  eligibleAnswer?: (value: T) => boolean;
@@ -4549,7 +4422,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4549
4422
  */
4550
4423
  replayMismatchPolicy?: () => Promise<ReplayMismatchPolicy>;
4551
4424
  /** See `executeWithFreshnessReceipt`. */
4552
- legacyRequestIdentities?: () => Promise<readonly string[]>;
4425
+ legacyRequestIdentities?: () => Promise<readonly string[] | null>;
4426
+ /** See `executeWithFreshnessReceipt`. */
4427
+ legacyOwnOccurrenceIdentities?: () => Promise<readonly string[]>;
4553
4428
  operationKeyEncodesRequest?: true;
4554
4429
  }): Promise<T> {
4555
4430
  const orgId = this.#options.orgId?.trim();
@@ -4560,7 +4435,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4560
4435
  }
4561
4436
  const slots = this.exactRequestInvocationIds.get(input.invocationId);
4562
4437
  this.exactRequestInvocationIds.delete(input.invocationId);
4563
- return executeWithFreshnessReceipt({
4438
+ return await executeWithFreshnessReceipt({
4564
4439
  orgId,
4565
4440
  semanticKey: input.semanticKey,
4566
4441
  invocationId: input.invocationId,
@@ -4574,13 +4449,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4574
4449
  ...(input.legacyRequestIdentities
4575
4450
  ? { legacyRequestIdentities: input.legacyRequestIdentities }
4576
4451
  : {}),
4577
- ...(slots?.legacySlot &&
4578
- this.legacySlotScopes.has(slots.legacySlot.scope)
4452
+ ...(input.legacyOwnOccurrenceIdentities
4579
4453
  ? {
4580
- legacySlotSearch: this.legacySlotSearch(
4581
- input.invocationId,
4582
- slots.legacySlot,
4583
- ),
4454
+ legacyOwnOccurrenceIdentities: input.legacyOwnOccurrenceIdentities,
4584
4455
  }
4585
4456
  : {}),
4586
4457
  ...(input.replayMismatchPolicy
@@ -4591,6 +4462,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4591
4462
  onLegacyRecoveryProven: () =>
4592
4463
  this.reportLegacyOperationRecovery(input.operation, input.id),
4593
4464
  onRefusal: (refusal) => this.reportReplayRefusal(refusal),
4465
+ ...(slots?.callOrderSlot
4466
+ ? { callOrdinal: slots.callOrderSlot.index }
4467
+ : {}),
4594
4468
  runId: this.currentReceiptOwnerRunId,
4595
4469
  receiptOwnerRunId: this.currentReceiptOwnerRunId,
4596
4470
  // Launches admitted without run-scoped keys wrote this operation under
@@ -4621,8 +4495,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4621
4495
  ),
4622
4496
  { ...options, source: 'durable_operation' },
4623
4497
  ),
4624
- execute: async (publication) => {
4625
- const value = await input.execute(publication);
4498
+ execute: async (publication, replay) => {
4499
+ const value = await input.execute(publication, replay);
4626
4500
  this.assertNoPendingDurableSuspension();
4627
4501
  return value;
4628
4502
  },
@@ -7993,6 +7867,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
7993
7867
  runId: this.currentReceiptOwnerRunId,
7994
7868
  logicalCallId: request.logicalCallId,
7995
7869
  force: request.force === true,
7870
+ ...(request.occurrenceBound ? { occurrenceBound: true } : {}),
7996
7871
  });
7997
7872
  }
7998
7873
 
@@ -14983,27 +14858,6 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14983
14858
  toolId: string,
14984
14859
  input: Record<string, unknown>,
14985
14860
  options?: ToolCallOptions,
14986
- ): Promise<unknown> {
14987
- let invocationId: string | null = null;
14988
- try {
14989
- return await this.executeToolInternalWithSlot(
14990
- key,
14991
- toolId,
14992
- input,
14993
- options,
14994
- (allocated) => (invocationId = allocated),
14995
- );
14996
- } finally {
14997
- if (invocationId) this.settleLegacySlot(invocationId);
14998
- }
14999
- }
15000
-
15001
- private async executeToolInternalWithSlot(
15002
- key: string,
15003
- toolId: string,
15004
- input: Record<string, unknown>,
15005
- options: ToolCallOptions | undefined,
15006
- onSlotAllocated: (invocationId: string) => void,
15007
14861
  ): Promise<unknown> {
15008
14862
  if (!this.usesExplicitFreshness) {
15009
14863
  return this.executeToolLegacyInternal(key, toolId, input, options);
@@ -15031,7 +14885,28 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15031
14885
  normalizedKey,
15032
14886
  this.callSlotRequestDigest({ toolId, input }),
15033
14887
  );
15034
- onSlotAllocated(invocationId);
14888
+ // Reserve the call's occurrence among identical requests now, in the same
14889
+ // order as its operation slot, whether the call later recovers or
14890
+ // executes. Otherwise a recovered occurrence would not advance it, and the
14891
+ // next identical occurrence would take the recovered one's logical
14892
+ // identity and its forced result receipt instead of executing. SQL
14893
+ // requests carry their own operation key, so they never repeat.
14894
+ const reservedCallIndexKey = isCustomerDbDatasetTool(toolId)
14895
+ ? undefined
14896
+ : this.toolCallIndexKey(normalizedKey, toolId, input);
14897
+ const reservedCallIndex =
14898
+ reservedCallIndexKey === undefined
14899
+ ? undefined
14900
+ : this.nextToolCallIndex(reservedCallIndexKey);
14901
+ /**
14902
+ * A call that may not reuse the tool layer's pre-binding result receipts
14903
+ * (its own slot held a pre-binding record it could not reuse) dispatches
14904
+ * under this identity instead: deterministic from its operation slot, so a
14905
+ * later replay of the same call reuses its new receipt rather than
14906
+ * sending again.
14907
+ */
14908
+ const freshLogicalCallId = () =>
14909
+ stableDigest(`replay-fresh:${invocationId}`);
15035
14910
  const sqlTool = isCustomerDbDatasetTool(toolId);
15036
14911
  const scalarCustomerDbQuery = sqlTool && input.result_mode === 'rows';
15037
14912
  const liveDataset =
@@ -15111,8 +14986,60 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15111
14986
  * scope, action version and the run's cache epoch. They prove an unbound
15112
14987
  * recorded operation is this call's.
15113
14988
  */
15114
- const legacyRequestIdentities =
14989
+ const legacyIdentities =
14990
+ (staleAfterSeconds: number | null | undefined) => async () => {
14991
+ const identity = {
14992
+ toolId,
14993
+ requestInput,
14994
+ executionAuthScopeDigest: authScope?.trim() || null,
14995
+ staleAfterSeconds: this.effectiveToolCallCachePolicy({
14996
+ ...options,
14997
+ force: true,
14998
+ staleAfterSeconds,
14999
+ }).staleAfterSeconds,
15000
+ };
15001
+ const [keys, legacy, idempotencyScope, eventWait] = await Promise.all([
15002
+ this.compatibleDurableToolCallCacheKeys(identity),
15003
+ this.legacyDurableToolCallCacheKey(identity),
15004
+ this.#options.getToolIdempotencyScope?.(toolId),
15005
+ this.#options.getIntegrationEventWaitHandler?.(toolId),
15006
+ ]);
15007
+ // An invocation-scoped tool recorded its keys scoped by an old
15008
+ // logical call whose numbering cannot be reconstructed: nothing it
15009
+ // retained can prove or disprove this request.
15010
+ if (!eventWait && idempotencyScope === 'invocation') return null;
15011
+ const cacheKeys = legacy ? [...keys, legacy] : keys;
15012
+ // Request identity only (input, credential scope, action revision,
15013
+ // policy, run cache epoch). A build before bindings numbered identical
15014
+ // requests in tool-layer entry order, so no key it recorded proves
15015
+ // WHICH identical occurrence it was; the call-order slot is the only
15016
+ // occurrence evidence. SQL requests also carry their slot's runtime
15017
+ // operation key.
15018
+ return cacheKeys;
15019
+ };
15020
+ /**
15021
+ * An invocation-scoped tool scoped its recorded result keys by the run
15022
+ * and its logical call id: the digest of its tool-layer occurrence key
15023
+ * (authored id, row/workflow scope and request identity) and its
15024
+ * occurrence index among identical requests. Recomputed for this call's
15025
+ * own reserved index, an exact match names the same (id, scope, request,
15026
+ * index) occurrence. A miss proves nothing: an older build numbered
15027
+ * occurrences at the tool layer, so a recovered sibling may have shifted
15028
+ * the index. Those calls execute as before.
15029
+ */
15030
+ const ownOccurrenceIdentities =
15115
15031
  (staleAfterSeconds: number | null | undefined) => async () => {
15032
+ if (
15033
+ reservedCallIndexKey === undefined ||
15034
+ reservedCallIndex === undefined
15035
+ ) {
15036
+ return [];
15037
+ }
15038
+ const [idempotencyScope, eventWait] = await Promise.all([
15039
+ this.#options.getToolIdempotencyScope?.(toolId),
15040
+ this.#options.getIntegrationEventWaitHandler?.(toolId),
15041
+ ]);
15042
+ if (eventWait || idempotencyScope !== 'invocation') return [];
15116
15043
  const identity = {
15117
15044
  toolId,
15118
15045
  requestInput,
@@ -15127,7 +15054,17 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15127
15054
  this.compatibleDurableToolCallCacheKeys(identity),
15128
15055
  this.legacyDurableToolCallCacheKey(identity),
15129
15056
  ]);
15130
- return legacy ? [...keys, legacy] : keys;
15057
+ const invocationIdentity = `${this.historyRunId}:${stableDigest(
15058
+ `${reservedCallIndexKey}:${reservedCallIndex}`,
15059
+ )}`;
15060
+ return (legacy ? [...keys, legacy] : keys).map((receiptKey) =>
15061
+ scopeToolReceiptToInvocation({
15062
+ orgId: this.#options.orgId,
15063
+ toolId,
15064
+ receiptKey,
15065
+ invocationIdentity,
15066
+ }),
15067
+ );
15131
15068
  };
15132
15069
 
15133
15070
  if (
@@ -15145,13 +15082,19 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15145
15082
  semanticKey,
15146
15083
  invocationId,
15147
15084
  policy: { requested: policy.requested, effective: 0 },
15148
- legacyRequestIdentities: legacyRequestIdentities(0),
15149
- execute: async () =>
15150
- await this.executeToolLegacyInternal(key, toolId, requestInput, {
15151
- ...options,
15152
- force: true,
15153
- staleAfterSeconds: 0,
15154
- }),
15085
+ legacyRequestIdentities: once(legacyIdentities(0)),
15086
+ legacyOwnOccurrenceIdentities: once(ownOccurrenceIdentities(0)),
15087
+ execute: async (_publication, replay) =>
15088
+ await this.executeToolLegacyInternal(
15089
+ key,
15090
+ toolId,
15091
+ requestInput,
15092
+ { ...options, force: true, staleAfterSeconds: 0 },
15093
+ false,
15094
+ undefined,
15095
+ reservedCallIndex,
15096
+ replay?.freshInvocation ? freshLogicalCallId() : undefined,
15097
+ ),
15155
15098
  });
15156
15099
  }
15157
15100
 
@@ -15163,6 +15106,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15163
15106
  toolId,
15164
15107
  requestInput,
15165
15108
  { ...options, force: true, staleAfterSeconds: 0 },
15109
+ false,
15110
+ undefined,
15111
+ reservedCallIndex,
15166
15112
  );
15167
15113
  const freshness: CallFreshnessMetadata = {
15168
15114
  requestedStaleAfterSeconds: policy.requested,
@@ -15190,8 +15136,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15190
15136
  policy,
15191
15137
  toolId,
15192
15138
  replayMismatchPolicy: () => this.toolReplayMismatchPolicy(toolId, input),
15193
- legacyRequestIdentities: legacyRequestIdentities(
15194
- options?.staleAfterSeconds,
15139
+ legacyRequestIdentities: once(
15140
+ legacyIdentities(options?.staleAfterSeconds),
15141
+ ),
15142
+ legacyOwnOccurrenceIdentities: once(
15143
+ ownOccurrenceIdentities(options?.staleAfterSeconds),
15195
15144
  ),
15196
15145
  ...(publishLatestOnRefresh
15197
15146
  ? { publishLatestOnRefresh: true as const }
@@ -15209,7 +15158,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15209
15158
  },
15210
15159
  sharesResult: isCompletedSuccessfulAnswer,
15211
15160
  eligibleAnswer: isCompletedSuccessfulAnswer,
15212
- execute: async (publication) => {
15161
+ execute: async (publication, replay) => {
15213
15162
  // The freshness layer is the only reuse authority here. The legacy
15214
15163
  // durable call cache below it would otherwise hand back an earlier
15215
15164
  // completed-but-ineligible answer (a pending or empty result) that the
@@ -15221,6 +15170,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15221
15170
  { ...options, force: true },
15222
15171
  true,
15223
15172
  publication,
15173
+ reservedCallIndex,
15174
+ replay?.freshInvocation ? freshLogicalCallId() : undefined,
15224
15175
  );
15225
15176
  if ((await this.resolveToolAuthScopeDigest(toolId)) !== authScope) {
15226
15177
  throw new Error(
@@ -15321,6 +15272,46 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15321
15272
  });
15322
15273
  }
15323
15274
 
15275
+ /** The occurrence counter key of a tool request in its row/workflow scope. */
15276
+ private toolCallIndexKey(
15277
+ normalizedKey: string,
15278
+ toolId: string,
15279
+ input: Record<string, unknown>,
15280
+ ): string {
15281
+ const toolRequestIdentity = deriveToolRequestIdentity({
15282
+ toolId,
15283
+ requestInput: input,
15284
+ });
15285
+ const store = rowContext.getStore();
15286
+ const logicalCallScope = store
15287
+ ? [
15288
+ 'row',
15289
+ store.tableNamespace?.trim() || 'map',
15290
+ store.rowKey?.trim() || String(store.rowId),
15291
+ store.fieldName?.trim() || 'field',
15292
+ ].join(':')
15293
+ : 'workflow';
15294
+ return `${this.currentExecutionScope.receipt.namespace}:${logicalCallScope}:${normalizedKey}:${toolRequestIdentity}`;
15295
+ }
15296
+
15297
+ /**
15298
+ * Next occurrence of an identical tool request. It names the call's
15299
+ * logical identity (forced result receipt, provider operation key). A held
15300
+ * row re-entered after backpressure restores its recorded positions.
15301
+ */
15302
+ private nextToolCallIndex(callIndexKey: string): number {
15303
+ const freshCallIndex = this.toolCallIndexByKey.get(callIndexKey) ?? 0;
15304
+ const callIndex = nextReplayableCallIndex(
15305
+ `tool:${callIndexKey}`,
15306
+ freshCallIndex,
15307
+ );
15308
+ this.toolCallIndexByKey.set(
15309
+ callIndexKey,
15310
+ Math.max(freshCallIndex, callIndex + 1),
15311
+ );
15312
+ return callIndex;
15313
+ }
15314
+
15324
15315
  private async executeToolLegacyInternal(
15325
15316
  key: string,
15326
15317
  toolId: string,
@@ -15332,6 +15323,17 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15332
15323
  * its own finishing writes, before the call returns to customer code.
15333
15324
  */
15334
15325
  publication?: DeferredReceiptPublication,
15326
+ /**
15327
+ * This call's occurrence among identical requests, reserved by the
15328
+ * edition-11 caller when it allocated the call's operation slot. See
15329
+ * `reserveToolCallIndex`.
15330
+ */
15331
+ reservedCallIndex?: number,
15332
+ /**
15333
+ * Replaces the call's logical identity (and with it the forced result
15334
+ * receipt and provider operation key) for a fresh dispatch.
15335
+ */
15336
+ logicalCallIdOverride?: string,
15335
15337
  ): Promise<unknown> {
15336
15338
  if (!rowContext.getStore()) this.assertRowAdmissionOpen();
15337
15339
  this.assertNoPendingDurableSuspension();
@@ -15368,30 +15370,16 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15368
15370
  ? this.materializeToolExecutionResult(result)
15369
15371
  : result;
15370
15372
  const toolCachePolicy = this.effectiveToolCallCachePolicy(options);
15371
- const toolRequestIdentity = deriveToolRequestIdentity({
15372
- toolId,
15373
- requestInput: input,
15374
- });
15375
15373
  const store = rowContext.getStore();
15376
- const logicalCallScope = store
15377
- ? [
15378
- 'row',
15379
- store.tableNamespace?.trim() || 'map',
15380
- store.rowKey?.trim() || String(store.rowId),
15381
- store.fieldName?.trim() || 'field',
15382
- ].join(':')
15383
- : 'workflow';
15384
- const callIndexKey = `${this.currentExecutionScope.receipt.namespace}:${logicalCallScope}:${normalizedKey}:${toolRequestIdentity}`;
15385
- const freshCallIndex = this.toolCallIndexByKey.get(callIndexKey) ?? 0;
15386
- const callIndex = nextReplayableCallIndex(
15387
- `tool:${callIndexKey}`,
15388
- freshCallIndex,
15389
- );
15390
- this.toolCallIndexByKey.set(
15391
- callIndexKey,
15392
- Math.max(freshCallIndex, callIndex + 1),
15393
- );
15394
- const logicalCallId = stableDigest(`${callIndexKey}:${callIndex}`);
15374
+ const callIndexKey = this.toolCallIndexKey(normalizedKey, toolId, input);
15375
+ const callIndex =
15376
+ reservedCallIndex ?? this.nextToolCallIndex(callIndexKey);
15377
+ const logicalCallId =
15378
+ logicalCallIdOverride ?? stableDigest(`${callIndexKey}:${callIndex}`);
15379
+ // Reserved with its operation slot (or a fresh replay identity): its forced
15380
+ // result receipt is keyed in the reserved namespace, never the older one.
15381
+ const occurrenceBound =
15382
+ reservedCallIndex !== undefined || logicalCallIdOverride !== undefined;
15395
15383
  this.resourceGovernor.recordLogicalToolCall();
15396
15384
  let executionAuthScopeDigest =
15397
15385
  (await this.resolveToolAuthScopeDigest(toolId))?.trim() ?? null;
@@ -15812,6 +15800,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15812
15800
  logicalCallId,
15813
15801
  force: toolCachePolicy.force,
15814
15802
  canStoreResult: this.durableDirectToolResultsBackedByReceipts,
15803
+ ...(occurrenceBound ? { occurrenceBound: true } : {}),
15815
15804
  });
15816
15805
  const toolRetryPolicy = await this.#options
15817
15806
  .getToolRetryPolicy?.(toolId, input)
@@ -16167,6 +16156,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
16167
16156
  const dispatchRequest: ToolCallRequest = {
16168
16157
  callId,
16169
16158
  logicalCallId,
16159
+ ...(occurrenceBound ? { occurrenceBound: true as const } : {}),
16170
16160
  cacheKey: toolResultCacheKey,
16171
16161
  providerIdempotencyKeyBase,
16172
16162
  providerActionVersion,
@@ -91,6 +91,11 @@ export interface ToolCallRequest {
91
91
  * result cache and the author-supplied call id.
92
92
  */
93
93
  logicalCallId?: string;
94
+ /**
95
+ * The logical call's occurrence index was reserved with its operation slot;
96
+ * its forced result receipt lives in the reserved namespace.
97
+ */
98
+ occurrenceBound?: true;
94
99
  cacheKey: string;
95
100
  /** Stable external-operation identity, independent of receipt serialization. */
96
101
  providerIdempotencyKeyBase?: string | null;