deepline 0.3.527 → 0.3.528

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 (146) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +141 -211
  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 +135 -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 +25 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +6 -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 +281 -66
  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.ts +105 -13
  22. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/result-receipt-policy.ts +10 -1
  23. package/dist/cli/auth-CWJZYLTB.js +43 -0
  24. package/dist/cli/{auth-LRMMQFJ4.mjs → auth-PPOTNK4T.mjs} +5 -5
  25. package/dist/cli/{billing-M76MMWZB.js → billing-3C7T7CUQ.js} +79 -79
  26. package/dist/cli/{billing-WZZDXVRJ.mjs → billing-OEZUQ2K6.mjs} +6 -6
  27. package/dist/cli/{chunk-R6IWWPY7.js → chunk-237PKFIQ.js} +14 -14
  28. package/dist/cli/{chunk-YSDPYQBH.js → chunk-36UD7H7Y.js} +41 -41
  29. package/dist/cli/{chunk-M45S7JAY.mjs → chunk-42ZSDTOC.mjs} +2 -2
  30. package/dist/cli/{chunk-YJ4YVFXC.js → chunk-4SBUXDKZ.js} +13 -13
  31. package/dist/cli/{chunk-HB3YUHEL.js → chunk-5MJ4CDAQ.js} +44 -44
  32. package/dist/cli/{chunk-UJHS2O5O.mjs → chunk-6OLQWQU5.mjs} +3 -3
  33. package/dist/cli/{chunk-EOL7PXLW.js → chunk-7WZXUAQW.js} +7 -7
  34. package/dist/cli/{chunk-YUYDP2EG.js → chunk-7X3NLHI7.js} +6 -6
  35. package/dist/cli/{chunk-XYG4IOJK.js → chunk-ADZGTMLU.js} +98 -98
  36. package/dist/cli/{chunk-MIL5YDKZ.mjs → chunk-AFIAVG5T.mjs} +2 -2
  37. package/dist/cli/{chunk-3L2DNG5X.js → chunk-B3HQF2CA.js} +11 -11
  38. package/dist/cli/{chunk-HA2J2OAS.mjs → chunk-B6YWCGVC.mjs} +10 -10
  39. package/dist/cli/{chunk-NVII3RWQ.mjs → chunk-CMTY6SVY.mjs} +2 -2
  40. package/dist/cli/{chunk-AXFHQWGA.mjs → chunk-DCVNL5XN.mjs} +1 -1
  41. package/dist/cli/{chunk-RTPLRMEB.mjs → chunk-FPHAUP55.mjs} +5 -5
  42. package/dist/cli/{chunk-JSEISVAZ.js → chunk-FXYWEKUK.js} +4 -4
  43. package/dist/cli/{chunk-HQZLTK3P.js → chunk-G7RTPKRJ.js} +2 -2
  44. package/dist/cli/{chunk-OKRBGXDI.js → chunk-GCBFSFLA.js} +5 -5
  45. package/dist/cli/{chunk-VTXBV4AX.mjs → chunk-GFGFAAY2.mjs} +1 -1
  46. package/dist/cli/{chunk-JSVHBJE2.mjs → chunk-GP7E4TE4.mjs} +2 -2
  47. package/dist/cli/{chunk-4YN7DZEA.mjs → chunk-GSBKODMU.mjs} +2 -2
  48. package/dist/cli/{chunk-RMCKTV4R.mjs → chunk-HJVNCRXY.mjs} +1 -1
  49. package/dist/cli/{chunk-7DPWGAOU.js → chunk-IJAEYEJM.js} +3 -3
  50. package/dist/cli/{chunk-VV2AFJ3I.mjs → chunk-IM5XQ4DG.mjs} +5 -5
  51. package/dist/cli/{chunk-XI47UAVU.js → chunk-IXEEXYE2.js} +9 -9
  52. package/dist/cli/{chunk-JEIGNX3G.mjs → chunk-IYCRX34W.mjs} +5 -5
  53. package/dist/cli/{chunk-ZHY7AY5V.js → chunk-KHVCHFE3.js} +16 -16
  54. package/dist/cli/{chunk-KDFUQRVU.mjs → chunk-KLGYBOGZ.mjs} +1 -1
  55. package/dist/cli/{chunk-UKOG6PCB.mjs → chunk-KWIKFR7Y.mjs} +1 -1
  56. package/dist/cli/{chunk-ETXQZGQU.js → chunk-LT4IEJ6V.js} +16 -16
  57. package/dist/cli/{chunk-RGL2YGJZ.js → chunk-LU4EA3ET.js} +2 -2
  58. package/dist/cli/{chunk-UAQ7ZWRP.js → chunk-MLNH4DK2.js} +22 -22
  59. package/dist/cli/{chunk-YKPMIJJ2.mjs → chunk-NCOTOGTK.mjs} +2 -2
  60. package/dist/cli/{chunk-MMM2WMTF.mjs → chunk-NZM4KWWV.mjs} +5 -5
  61. package/dist/cli/{chunk-C7A44BZ7.js → chunk-OEI7YUEF.js} +3 -3
  62. package/dist/cli/{chunk-LHMHUA5D.js → chunk-OGVUT2KM.js} +7 -7
  63. package/dist/cli/{chunk-OXHY3LD3.js → chunk-OVZSNBDJ.js} +53 -53
  64. package/dist/cli/{chunk-5YR6CDJ2.mjs → chunk-PS2UYVAE.mjs} +6 -6
  65. package/dist/cli/{chunk-66YLAQ2X.js → chunk-R5ZQVQ3K.js} +26 -26
  66. package/dist/cli/{chunk-QKY3H3HA.mjs → chunk-RC5CG5SE.mjs} +4 -4
  67. package/dist/cli/{chunk-SRQQAUXN.js → chunk-RFTBMEWL.js} +2 -2
  68. package/dist/cli/{chunk-P5ZU5ZHA.mjs → chunk-RML3VSTN.mjs} +1 -1
  69. package/dist/cli/{chunk-2L3HVEBM.mjs → chunk-SP2KZ7SH.mjs} +1 -1
  70. package/dist/cli/{chunk-QKKT5G4K.mjs → chunk-T4QPRL3P.mjs} +3 -3
  71. package/dist/cli/{chunk-GIRMVMXP.mjs → chunk-ULUI2FEM.mjs} +1 -1
  72. package/dist/cli/{chunk-3PQDEBO6.js → chunk-WXHBD6H7.js} +1 -1
  73. package/dist/cli/{chunk-OLSATEDQ.js → chunk-XD2DRBPH.js} +6 -6
  74. package/dist/cli/{chunk-77VNC2KF.mjs → chunk-Z25KC5V2.mjs} +1 -1
  75. package/dist/cli/{chunk-E4TEZE62.mjs → chunk-Z44S7VWO.mjs} +2 -2
  76. package/dist/cli/{chunk-2A6IRSE6.js → chunk-ZFD5FJCZ.js} +5 -5
  77. package/dist/cli/{csv-FEFNXZF7.mjs → csv-K7TRWOFJ.mjs} +4 -4
  78. package/dist/cli/{csv-IRP6VT7Q.js → csv-OTRVTHD2.js} +13 -13
  79. package/dist/cli/{db-IHECMWZ3.mjs → db-C7GQU3TZ.mjs} +6 -6
  80. package/dist/cli/{db-Y5VNPNRD.js → db-UO2ZFLFN.js} +27 -27
  81. package/dist/cli/describe-IK4UYJ5M.js +50 -0
  82. package/dist/cli/{describe-XCVC2WLL.mjs → describe-LG4CPTIV.mjs} +18 -18
  83. package/dist/cli/{executions-QH3KJ6MA.js → executions-LHFVPO7E.js} +8 -8
  84. package/dist/cli/{executions-3FWZYUJV.mjs → executions-P3INNVZE.mjs} +6 -6
  85. package/dist/cli/{feedback-F3OZXOPM.mjs → feedback-H22FWG63.mjs} +6 -6
  86. package/dist/cli/{feedback-BGHWMOLH.js → feedback-M3HZQAWX.js} +14 -14
  87. package/dist/cli/git-72ADWRUQ.js +25 -0
  88. package/dist/cli/{git-RWPH3D75.mjs → git-G2N7PVFI.mjs} +5 -5
  89. package/dist/cli/index.js +141 -141
  90. package/dist/cli/index.mjs +43 -43
  91. package/dist/cli/{legacy-noops-G6CYD5LM.js → legacy-noops-2RVROWBY.js} +9 -9
  92. package/dist/cli/{legacy-noops-5ADSTBJ5.mjs → legacy-noops-LDYSWTL2.mjs} +6 -6
  93. package/dist/cli/{monitors-AFNAU3A2.mjs → monitors-IYT3VON7.mjs} +7 -7
  94. package/dist/cli/{monitors-VZCBZO26.js → monitors-U4RE6KN5.js} +100 -100
  95. package/dist/cli/{org-JVLYTU24.mjs → org-R3JE22GS.mjs} +6 -6
  96. package/dist/cli/{org-X4QRYBC4.js → org-SO52ZGRP.js} +86 -86
  97. package/dist/cli/{pages-VELKZKBL.mjs → pages-5RLT5YTF.mjs} +6 -6
  98. package/dist/cli/{pages-YMM4KBW5.js → pages-SWXJQJXH.js} +18 -18
  99. package/dist/cli/{play-MIY6BYRB.mjs → play-2ELYCSXZ.mjs} +18 -18
  100. package/dist/cli/{play-J7DEBHI7.js → play-J4UXOQOJ.js} +317 -317
  101. package/dist/cli/{providers-2H3W3W7G.mjs → providers-IXITXHTS.mjs} +6 -6
  102. package/dist/cli/{providers-TOUB7Y2A.js → providers-VVUDGV2D.js} +9 -9
  103. package/dist/cli/{quickstart-GKAS5265.mjs → quickstart-HQCGDPPL.mjs} +4 -4
  104. package/dist/cli/{quickstart-LHY2LN3P.js → quickstart-XPH6MT47.js} +6 -6
  105. package/dist/cli/{run-KYGNOWYD.mjs → run-H2HQPWC4.mjs} +23 -23
  106. package/dist/cli/{run-QCAVDPE5.js → run-OR646AC6.js} +41 -41
  107. package/dist/cli/search-D27DZH2D.js +33 -0
  108. package/dist/cli/{search-YPGAIFDX.mjs → search-MBPI5SBW.mjs} +8 -8
  109. package/dist/cli/{search-output-OOC3VK4T.mjs → search-output-CYOMJNRV.mjs} +4 -4
  110. package/dist/cli/{search-output-ASELNQ2U.js → search-output-YGNSHBXX.js} +6 -6
  111. package/dist/cli/{secrets-KX3TQB4R.js → secrets-HVZKNNLZ.js} +15 -15
  112. package/dist/cli/{secrets-VJ4XYSMZ.mjs → secrets-NK2CN7WI.mjs} +6 -6
  113. package/dist/cli/sessions-MTISSOZ4.js +22 -0
  114. package/dist/cli/{sessions-KUN7H7E5.mjs → sessions-NY4G427U.mjs} +6 -6
  115. package/dist/cli/{settings-5NIF4BU7.js → settings-PVJRDEN2.js} +86 -86
  116. package/dist/cli/{settings-JKFYZ2IT.mjs → settings-RC4FGYY2.mjs} +13 -13
  117. package/dist/cli/{setup-MYV3IHPS.js → setup-B7QB4YV2.js} +50 -50
  118. package/dist/cli/{setup-5AX3TN6G.mjs → setup-YT3XSY6X.mjs} +10 -10
  119. package/dist/cli/{skills-JLS4CINQ.mjs → skills-5ILFNAHR.mjs} +8 -8
  120. package/dist/cli/skills-BHF35NLX.js +37 -0
  121. package/dist/cli/{tools-VBYKD3MJ.mjs → tools-7PAY32OZ.mjs} +17 -17
  122. package/dist/cli/tools-W5BZ37L6.js +57 -0
  123. package/dist/cli/update-M65CGK42.js +35 -0
  124. package/dist/cli/{update-QWAIVJRI.mjs → update-Z27QYB6O.mjs} +10 -10
  125. package/dist/cli/{views-TBWGZAVZ.mjs → views-2IANF6KR.mjs} +6 -6
  126. package/dist/cli/{views-ZW56JZB5.js → views-NP2SCMOV.js} +18 -18
  127. package/dist/cli/{workflow-EKSZST6M.js → workflow-2GNQL646.js} +17 -17
  128. package/dist/cli/{workflow-X7UQPJMQ.mjs → workflow-CAMEZLLY.mjs} +7 -7
  129. package/dist/index.js +9 -9
  130. package/dist/index.mjs +6 -6
  131. package/dist/install-integrity.json +105 -104
  132. package/dist/release.d.mts +1 -1
  133. package/dist/release.d.ts +1 -1
  134. package/dist/release.js +2 -2
  135. package/dist/release.mjs +1 -1
  136. package/dist/server.js +5 -5
  137. package/dist/server.mjs +3 -3
  138. package/package.json +1 -1
  139. package/dist/cli/auth-C7BBYIQD.js +0 -43
  140. package/dist/cli/describe-MNJVJHRE.js +0 -50
  141. package/dist/cli/git-MDOHEW5J.js +0 -25
  142. package/dist/cli/search-G67CEHR7.js +0 -33
  143. package/dist/cli/sessions-QILPX4XQ.js +0 -22
  144. package/dist/cli/skills-NG32XTZI.js +0 -37
  145. package/dist/cli/tools-OZG3V77R.js +0 -57
  146. package/dist/cli/update-YL5WVSKU.js +0 -35
@@ -48,7 +48,7 @@ export type CompletedCall = {
48
48
  * identities the authored source already names and which check failed.
49
49
  */
50
50
  export type ReplayRefusal = {
51
- code: 'DURABLE_REPLAY_INPUT_MISMATCH' | 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT';
51
+ code: 'DURABLE_REPLAY_INPUT_MISMATCH';
52
52
  operation: string;
53
53
  callId: string;
54
54
  /** This call's call-order occurrence in its scope, when known. */
@@ -56,38 +56,20 @@ export type ReplayRefusal = {
56
56
  /**
57
57
  * The check that refused:
58
58
  * - `binding`: a bound receipt of another request identity;
59
- * - `legacy_ownership`: a pre-binding receipt nothing proves is this call's.
59
+ * - `legacy_ownership`: a pre-binding receipt whose retained identity proves
60
+ * another request.
60
61
  */
61
62
  rung: 'binding' | 'legacy_ownership';
62
63
  reason:
63
64
  | 'input_changed'
64
65
  | 'credential_or_action_changed'
65
- | 'no_identity_source'
66
- | 'no_recorded_identity'
67
- | 'recorded_identity_mismatch'
68
- | 'slot_taken_by_sibling';
66
+ | 'recorded_identity_mismatch';
69
67
  /** Binding refusals: which slot held the other request. */
70
68
  slot?: 'exact_request' | 'call_order' | 'legacy_key';
71
69
  /** Legacy refusals: where the recorded identities came from. */
72
70
  recordedIdentitySources?: Array<'value_receipt_key' | 'result_metadata'>;
73
71
  };
74
72
 
75
- /**
76
- * A call's view of the other call-order slots of its authored id and scope,
77
- * used only for receipts recorded before bindings. See
78
- * `executeWithFreshnessReceipt`'s `legacySlotSearch`.
79
- */
80
- export type LegacySlotSearch = {
81
- ownIndex: number;
82
- /** Must be called once, as soon as this call's own slot was read. */
83
- reportOwnSlot: (unbound: boolean) => void;
84
- /** Whether an earlier slot of this scope, read in this attempt, is unbound. */
85
- priorSlotsUnbound: () => Promise<boolean>;
86
- candidates: () => Array<{ index: number; invocationId: string }>;
87
- /** Takes a slot for this call; false when another call already took it. */
88
- consume: (index: number) => boolean;
89
- };
90
-
91
73
  /**
92
74
  * What a replayed call does when its recorded slot holds a different request
93
75
  * and no exact-request slot holds its own: a read executes (it never
@@ -96,26 +78,16 @@ export type LegacySlotSearch = {
96
78
  export type ReplayMismatchPolicy = 'execute' | 'fail';
97
79
 
98
80
  /**
99
- * A recorded operation without an input binding (written before bindings, or
100
- * by a lane still running such a build) that nothing proves belongs to this
101
- * call. It is neither returned nor re-executed: zero dispatch, zero charge.
102
- * Not retryable.
81
+ * Passed to `execute` when this call executes because its own call-order slot
82
+ * held a pre-binding record that it may not reuse (a proven mismatch read, or
83
+ * nothing proved). The caller must not answer it from the tool layer's
84
+ * pre-binding result receipts, whose occurrence numbering cannot be trusted,
85
+ * and dispatches under a fresh, deterministic invocation identity instead.
103
86
  */
104
- export class DurableReplayUnverifiableLegacySlotError extends Error {
105
- readonly code = 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT';
106
- readonly retryable = false;
107
- readonly reason = 'no_recorded_request_identity_match';
87
+ export type FreshExecutionReplay = { freshInvocation: true };
108
88
 
109
- constructor(
110
- readonly operation: string,
111
- readonly callId: string,
112
- ) {
113
- super(
114
- `DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT: ctx.${operation}("${callId}") reached a result recorded before input binding, and no request identity recorded with it matches this call, so Deepline cannot prove it belongs to this input. It was neither returned nor repeated. Start a new run to execute it; giving each distinct call its own id avoids this.`,
115
- );
116
- this.name = 'DurableReplayUnverifiableLegacySlotError';
117
- }
118
- }
89
+ /** recoverUnbound's answer when the call should execute instead. */
90
+ const EXECUTE: unique symbol = Symbol('execute');
119
91
 
120
92
  /**
121
93
  * A replay reached a recorded operation of a different request and the call
@@ -321,9 +293,12 @@ function sharesLatestResult<T>(
321
293
  }
322
294
 
323
295
  /**
324
- * Request-derived identities recorded with a completed tool result: its
325
- * canonical result receipt and the cache/receipt keys in its execution
326
- * metadata. Each hashes the request it was recorded for.
296
+ * Request identities a tool result recorded about itself: the result-cache
297
+ * keys in its execution metadata, each a hash of the request input,
298
+ * credential scope, action revision, policy and run cache epoch. The stamped
299
+ * result receipt key is excluded: for a forced call it also names an
300
+ * occurrence index, which builds before bindings assigned in tool-layer entry
301
+ * order and which therefore proves nothing about occurrence.
327
302
  */
328
303
  function recordedIdentitySources(
329
304
  call: CompletedCall,
@@ -347,21 +322,15 @@ function recordedIdentitySources(
347
322
  return sources;
348
323
  }
349
324
 
350
- function recordedRequestIdentities(call: CompletedCall): string[] {
351
- const keys = new Set<string>();
352
- if (call.valueReceiptKey) keys.add(call.valueReceiptKey);
353
- const value = call.value;
325
+ function resultRequestIdentities(value: unknown): string[] {
354
326
  const result = isSerializedToolExecuteResult(value)
355
327
  ? deserializeToolExecuteResult(value)
356
328
  : isToolExecuteResult(value)
357
329
  ? value
358
330
  : null;
359
331
  const execution = result?._metadata?.execution;
360
- for (const key of [
361
- execution?.cacheKey,
362
- execution?.receiptKey,
363
- execution?.resultReceiptKey,
364
- ]) {
332
+ const keys = new Set<string>();
333
+ for (const key of [execution?.cacheKey, execution?.receiptKey]) {
365
334
  if (typeof key === 'string' && key.trim()) keys.add(key.trim());
366
335
  }
367
336
  return [...keys];
@@ -438,20 +407,13 @@ export async function executeWithFreshnessReceipt<T>(input: {
438
407
  * cache epoch). An unbound recorded operation is this call's only when one
439
408
  * of its recorded identities is in this set. Omitted: no proof exists.
440
409
  */
441
- legacyRequestIdentities?: () => Promise<readonly string[]>;
410
+ legacyRequestIdentities?: () => Promise<readonly string[] | null>;
442
411
  /**
443
412
  * The operation key itself already encodes the authored request (a
444
413
  * `ctx.step` with a `semanticKey`): an unbound receipt under it can only be
445
414
  * this request's or an identical declared request's.
446
415
  */
447
416
  operationKeyEncodesRequest?: true;
448
- /**
449
- * Call-order artifacts: a sibling started in another order on replay may
450
- * hold this call's pre-binding result in another slot of the same scope.
451
- * Searched only when this call's slot holds an unbound receipt that is not
452
- * its own, or is empty while an earlier slot of the scope is unbound.
453
- */
454
- legacySlotSearch?: LegacySlotSearch;
455
417
  /** Digest of the authored request alone; see `CompletedCall`. */
456
418
  inputFingerprint?: string;
457
419
  /**
@@ -464,6 +426,8 @@ export async function executeWithFreshnessReceipt<T>(input: {
464
426
  * thrown, so a Play that catches the error cannot hide it.
465
427
  */
466
428
  onRefusal?: (refusal: ReplayRefusal) => void;
429
+ /** This call's call-order occurrence in its scope, for refusal reports. */
430
+ callOrdinal?: number;
467
431
  /** Names the call in a mismatch error. */
468
432
  operation?: string;
469
433
  callId?: string;
@@ -476,7 +440,10 @@ export async function executeWithFreshnessReceipt<T>(input: {
476
440
  * They are published together with this call's operation receipt, before the
477
441
  * call returns, so customer code never observes a result that is not durable.
478
442
  */
479
- execute: (publication: DeferredReceiptPublication) => Promise<T>;
443
+ execute: (
444
+ publication: DeferredReceiptPublication,
445
+ replay?: FreshExecutionReplay,
446
+ ) => Promise<T>;
480
447
  completedAt?: (value: T) => number | undefined;
481
448
  /**
482
449
  * False keeps an empty or unsuccessful result out of the shared latest
@@ -533,24 +500,6 @@ export async function executeWithFreshnessReceipt<T>(input: {
533
500
  ) => Promise<Result>;
534
501
  now?: () => number;
535
502
  }): Promise<T> {
536
- let ownSlotReported = false;
537
- const reportOwnSlot = (unbound: boolean) => {
538
- if (ownSlotReported) return;
539
- ownSlotReported = true;
540
- input.legacySlotSearch?.reportOwnSlot(unbound);
541
- };
542
- try {
543
- return await executeWithFreshnessReceiptOnce(input, reportOwnSlot);
544
- } finally {
545
- // A sibling may be waiting on this slot's verdict; never leave it hanging.
546
- reportOwnSlot(false);
547
- }
548
- }
549
-
550
- async function executeWithFreshnessReceiptOnce<T>(
551
- input: Parameters<typeof executeWithFreshnessReceipt<T>>[0],
552
- reportOwnSlot: (unbound: boolean) => void,
553
- ): Promise<T> {
554
503
  if (!input.store.enabled) {
555
504
  throw new Error(
556
505
  'Durable operation recovery is unavailable in this runtime.',
@@ -864,7 +813,8 @@ async function executeWithFreshnessReceiptOnce<T>(
864
813
  ]);
865
814
  if (operation.status === 'rejected') throw operation.reason;
866
815
  const { exact, callOrder } = operation.value;
867
- reportOwnSlot(callOrder !== null && ownsOperation(callOrder) === 'unverified');
816
+ /** Set when a pre-binding record in this call's own slot may not be reused. */
817
+ let freshExecution = false;
868
818
  // Same-run recovery returns only this call's own recorded result.
869
819
  if (exact && ownsOperation(exact) === 'yes') {
870
820
  return outcome(exact, 'operation_recovery');
@@ -879,77 +829,98 @@ async function executeWithFreshnessReceiptOnce<T>(
879
829
  * with zero dispatch, read or write: an unverifiable slot may be another
880
830
  * request's result, and executing could repeat a paid call.
881
831
  */
882
- const recoverUnbound = async (recorded: CompletedCall) => {
883
- const search = input.legacySlotSearch;
884
- const proven =
832
+ /**
833
+ * A pre-binding receipt is reused only when it is a proven matching
834
+ * completed receipt: this call's own call-order slot, with a retained
835
+ * request identity that proves the same request. Builds before bindings
836
+ * numbered identical requests in tool-layer entry order, so nothing
837
+ * recorded proves which identical occurrence a receipt was; the own slot is
838
+ * the only occurrence evidence, and no result is taken from another slot.
839
+ *
840
+ * A slot whose identity proves a different request is a proven mismatch: a
841
+ * proven read executes and anything that may write refuses with zero
842
+ * dispatch. A slot that proves nothing (no retained identity, an unreadable
843
+ * referent) is not reused and the call executes: legacy history is
844
+ * at-least-once, so a call that may already have completed can repeat its
845
+ * effect, but never returns another call's output (founder decision,
846
+ * 2026-11-14 ~00:00Z).
847
+ */
848
+ const recoverUnbound = async (
849
+ recorded: CompletedCall,
850
+ ): Promise<T | typeof EXECUTE> => {
851
+ const recordedIdentities =
852
+ input.operationKeyEncodesRequest === true
853
+ ? []
854
+ : await recordedIdentitiesOf(recorded);
855
+ if (
885
856
  input.operationKeyEncodesRequest === true ||
886
- (await recordedIdentityMatches(recorded));
887
- const owned = proven && (!search || search.consume(search.ownIndex));
888
- if (!owned) {
889
- const found = await searchLegacySlots();
890
- if (found) return found;
891
- const sources = recordedIdentitySources(recorded);
892
- input.onRefusal?.({
893
- code: 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT',
894
- operation: input.operation ?? 'call',
895
- callId: input.callId ?? 'unknown',
896
- ordinal: search?.ownIndex ?? null,
897
- rung: 'legacy_ownership',
898
- reason: proven
899
- ? 'slot_taken_by_sibling'
900
- : !input.legacyRequestIdentities
901
- ? 'no_identity_source'
902
- : sources.length === 0
903
- ? 'no_recorded_identity'
904
- : 'recorded_identity_mismatch',
905
- recordedIdentitySources: sources,
906
- });
907
- throw new DurableReplayUnverifiableLegacySlotError(
908
- input.operation ?? 'call',
909
- input.callId ?? 'unknown',
910
- );
857
+ (await recordedIdentityMatches(recordedIdentities))
858
+ ) {
859
+ input.onLegacyRecoveryProven?.();
860
+ return outcome(recorded, 'operation_recovery');
861
+ }
862
+ if (
863
+ recordedIdentities.length === 0 ||
864
+ !input.legacyRequestIdentities ||
865
+ (await input.legacyRequestIdentities()) === null
866
+ ) {
867
+ return EXECUTE;
911
868
  }
912
- input.onLegacyRecoveryProven?.();
913
- return outcome(recorded, 'operation_recovery');
869
+ const policy = input.replayMismatchPolicy
870
+ ? await input.replayMismatchPolicy()
871
+ : 'fail';
872
+ if (policy === 'execute') return EXECUTE;
873
+ input.onRefusal?.({
874
+ code: 'DURABLE_REPLAY_INPUT_MISMATCH',
875
+ operation: input.operation ?? 'call',
876
+ callId: input.callId ?? 'unknown',
877
+ ordinal: input.callOrdinal ?? null,
878
+ rung: 'legacy_ownership',
879
+ reason: 'recorded_identity_mismatch',
880
+ recordedIdentitySources: recordedIdentitySources(recorded),
881
+ });
882
+ throw new DurableReplayInputMismatchError(
883
+ input.operation ?? 'call',
884
+ input.callId ?? 'unknown',
885
+ 'input_changed',
886
+ );
914
887
  };
915
888
  /**
916
- * Another slot of this scope holding this call's pre-binding result,
917
- * proven by a recorded request identity and not yet taken by another call.
889
+ * The request identities a pre-binding operation retained: an inline
890
+ * result's own metadata, or, for a relay reference, the metadata of that
891
+ * exact referent read through the receipt owner (one bounded read, only on
892
+ * this legacy path). Never business output, never the current request.
918
893
  */
919
- const searchLegacySlots = async (): Promise<T | null> => {
920
- const search = input.legacySlotSearch;
921
- if (!search || !input.legacyRequestIdentities) return null;
922
- const candidates = search.candidates();
923
- if (candidates.length === 0) return null;
924
- const receipts = await readMany(
925
- candidates.map(({ invocationId }) =>
926
- operationKeyFor(input.runId, invocationId),
927
- ),
928
- );
929
- const current = new Set(await input.legacyRequestIdentities());
930
- for (const [position, candidate] of candidates.entries()) {
931
- const call = completedCall(receipts[position] ?? null);
932
- if (!call || ownsOperation(call) !== 'unverified') continue;
933
- if (
934
- recordedRequestIdentities(call).some((identity) =>
935
- current.has(identity),
936
- ) &&
937
- search.consume(candidate.index)
938
- ) {
939
- input.onLegacyRecoveryProven?.();
940
- return outcome(call, 'operation_recovery');
941
- }
894
+ const recordedIdentitiesOf = async (
895
+ recorded: CompletedCall,
896
+ ): Promise<string[]> => {
897
+ if (!recorded.valueReceiptKey) {
898
+ return resultRequestIdentities(recorded.value);
942
899
  }
943
- return null;
900
+ const referent = await input.withHydration(async (measure) => {
901
+ const receipt = await input.store.get(recorded.valueReceiptKey!);
902
+ measure?.([receipt]);
903
+ return receipt;
904
+ });
905
+ if (
906
+ !referent ||
907
+ !['completed', 'skipped'].includes(referent.status) ||
908
+ referent.output === undefined
909
+ ) {
910
+ return [];
911
+ }
912
+ return resultRequestIdentities(referent.output);
944
913
  };
945
914
  const recordedIdentityMatches = async (
946
- recorded: CompletedCall,
915
+ recordedIdentities: readonly string[],
947
916
  ): Promise<boolean> => {
948
- if (!input.legacyRequestIdentities) return false;
949
- const recordedIdentities = recordedRequestIdentities(recorded);
950
- if (recordedIdentities.length === 0) return false;
951
- const current = new Set(await input.legacyRequestIdentities());
952
- return recordedIdentities.some((identity) => current.has(identity));
917
+ if (!input.legacyRequestIdentities || recordedIdentities.length === 0) {
918
+ return false;
919
+ }
920
+ const current = await input.legacyRequestIdentities();
921
+ if (!current) return false;
922
+ const currentKeys = new Set(current);
923
+ return recordedIdentities.some((identity) => currentKeys.has(identity));
953
924
  };
954
925
  /**
955
926
  * A recorded slot holds another request. A read never completed in this
@@ -973,7 +944,7 @@ async function executeWithFreshnessReceiptOnce<T>(
973
944
  code: 'DURABLE_REPLAY_INPUT_MISMATCH',
974
945
  operation: input.operation ?? 'call',
975
946
  callId: input.callId ?? 'unknown',
976
- ordinal: input.legacySlotSearch?.ownIndex ?? null,
947
+ ordinal: input.callOrdinal ?? null,
977
948
  rung: 'binding',
978
949
  reason,
979
950
  slot,
@@ -990,27 +961,27 @@ async function executeWithFreshnessReceiptOnce<T>(
990
961
  await refuseOrExecute(exact, 'exact_request');
991
962
  } else if (callOrder) {
992
963
  if (ownsOperation(callOrder) === 'unverified') {
993
- return recoverUnbound(callOrder);
964
+ const recovered = await recoverUnbound(callOrder);
965
+ if (recovered !== EXECUTE) return recovered;
966
+ freshExecution = true;
967
+ } else {
968
+ await refuseOrExecute(callOrder, 'call_order');
994
969
  }
995
- await refuseOrExecute(callOrder, 'call_order');
996
- } else if (
997
- !exact &&
998
- input.legacySlotSearch &&
999
- (await input.legacySlotSearch.priorSlotsUnbound())
1000
- ) {
1001
- // An empty slot in a scope holding pre-binding receipts: a sibling that
1002
- // started first may have taken this call's original slot.
1003
- const found = await searchLegacySlots();
1004
- if (found) return found;
1005
970
  }
1006
971
  if (legacyOperationKey && !exact && !callOrder) {
1007
972
  const legacy =
1008
973
  await readLegacyOperationWrittenByThisRun(legacyOperationKey);
1009
974
  if (legacy) {
1010
975
  const owner = ownsOperation(legacy);
1011
- if (owner === 'unverified') return recoverUnbound(legacy);
1012
- if (owner === 'yes') return outcome(legacy, 'operation_recovery');
1013
- await refuseOrExecute(legacy, 'legacy_key');
976
+ if (owner === 'unverified') {
977
+ const recovered = await recoverUnbound(legacy);
978
+ if (recovered !== EXECUTE) return recovered;
979
+ freshExecution = true;
980
+ } else if (owner === 'yes') {
981
+ return outcome(legacy, 'operation_recovery');
982
+ } else {
983
+ await refuseOrExecute(legacy, 'legacy_key');
984
+ }
1014
985
  }
1015
986
  }
1016
987
  if (candidateManifests.status === 'rejected') {
@@ -1063,11 +1034,14 @@ async function executeWithFreshnessReceiptOnce<T>(
1063
1034
  const deferred: DeferredReceiptWrite[] = [];
1064
1035
  let value: T;
1065
1036
  try {
1066
- value = await input.execute({
1067
- defer: (write) => {
1068
- deferred.push(write);
1037
+ value = await input.execute(
1038
+ {
1039
+ defer: (write) => {
1040
+ deferred.push(write);
1041
+ },
1069
1042
  },
1070
- });
1043
+ freshExecution ? { freshInvocation: true } : undefined,
1044
+ );
1071
1045
  } catch (error) {
1072
1046
  // A deferred write is a result the call already received (the provider
1073
1047
  // answered and was paid) before a later step threw, for example a durable
@@ -25,6 +25,25 @@ export const PLAY_RUN_RECOVERY_DEFER_POLICY = {
25
25
  horizonMs: RUNTIME_RELIABILITY_POLICY.recovery.horizonMs,
26
26
  deferBaseSeconds: RUNTIME_RELIABILITY_POLICY.recovery.deferBaseSeconds,
27
27
  deferMaxSeconds: RUNTIME_RELIABILITY_POLICY.recovery.deferMaxSeconds,
28
+ /**
29
+ * How long after a run's first compiled-pacing defer it may still be paced.
30
+ * Paced defers are uncounted, and the bucket keeps no queue order, so under
31
+ * demand above the start ceiling one run could otherwise lose every round
32
+ * and never start or fail. Past this, a pacing defer takes the counted
33
+ * outage ladder, which ends within maxDefers or horizonMs. Twice horizonMs.
34
+ */
35
+ startPacingHorizonMs: 60 * 60_000,
36
+ /**
37
+ * A run already paced for T waits at least T / startPacingBackoffDivisor,
38
+ * up to startPacingBackoffMaxMs, before its next try. Each paced retry is a
39
+ * full scheduler attempt and the bucket keeps no queue order, so under
40
+ * demand above the start ceiling a run would otherwise retry every 1-3 s
41
+ * for the whole horizon (hundreds of attempt rows). With this floor a run
42
+ * that loses for the full hour makes about 150 attempts, and one paced for
43
+ * a few seconds in a short burst still retries after the bucket's own wait.
44
+ */
45
+ startPacingBackoffDivisor: 10,
46
+ startPacingBackoffMaxMs: 30_000,
28
47
  } as const;
29
48
 
30
49
  export function recoveryDeferDelaySeconds(deferCount: number): number {
@@ -56,7 +75,9 @@ export type PlayRunRecoveryDecision = Readonly<{
56
75
  /**
57
76
  * `engine_retry` consumes the scheduler engine's bounded attempt ladder.
58
77
  * `defer` is for dependency-wide pressure and MUST consume the scheduler's
59
- * durable defer budget/deadline instead of looping in an adapter.
78
+ * durable defer budget/deadline instead of looping in an adapter. The one
79
+ * exception is compiled start pacing (`recoveryForCompiledStartPacing`),
80
+ * whose bucket keeps granting.
60
81
  */
61
82
  action: PlayRunRecoveryAction;
62
83
  reason: PlayRunRecoveryReason;
@@ -74,12 +95,18 @@ export class PlayRunRecoveryError extends Error {
74
95
  readonly cause?: unknown;
75
96
  /** Log-only provider facts; see `playRunRecoveryLogDetail`. */
76
97
  readonly recoveryLogDetail?: unknown;
98
+ /**
99
+ * Set only by `recoveryForCompiledStartPacing`: requeue after exactly this
100
+ * delay without consuming the defer budget or starting its horizon.
101
+ */
102
+ readonly pacingDelayMs?: number;
77
103
 
78
104
  constructor(input: {
79
105
  decision: PlayRunRecoveryDecision;
80
106
  message: string;
81
107
  cause?: unknown;
82
108
  recoveryLogDetail?: unknown;
109
+ pacingDelayMs?: number;
83
110
  }) {
84
111
  super(input.message);
85
112
  this.name = PLAY_RUN_RECOVERY_ERROR_NAME;
@@ -90,6 +117,9 @@ export class PlayRunRecoveryError extends Error {
90
117
  if (input.recoveryLogDetail !== undefined) {
91
118
  this.recoveryLogDetail = input.recoveryLogDetail;
92
119
  }
120
+ if (input.pacingDelayMs !== undefined) {
121
+ this.pacingDelayMs = input.pacingDelayMs;
122
+ }
93
123
  }
94
124
  }
95
125
 
@@ -304,6 +334,31 @@ export function recoveryForRuntimeTrafficPolicy(input: {
304
334
  });
305
335
  }
306
336
 
337
+ /**
338
+ * The compiled Daytona start pacing, not an operator policy, had no permit
339
+ * within the worker's local wait while the bucket was not holding for provider
340
+ * pressure. That is contention for a bucket that keeps granting, not an
341
+ * outage: the run is requeued after `delayMs` without consuming the defer
342
+ * budget or starting its horizon. On the outage ladder it waited 15 s, then
343
+ * 30 s, and counted toward PLATFORM_RECOVERY_EXHAUSTED (Preview load run
344
+ * 43234467564: 102 of 200 burst runs, code start p50 29.0 s against 9.7 s).
345
+ * The persisted reason is unchanged.
346
+ */
347
+ export function recoveryForCompiledStartPacing(input: {
348
+ delayMs: number;
349
+ }): PlayRunRecoveryError {
350
+ return new PlayRunRecoveryError({
351
+ decision: {
352
+ stage: 'pre_code',
353
+ action: 'defer',
354
+ reason: 'runtime_traffic_throttled_before_execution',
355
+ dependency: 'runtime',
356
+ },
357
+ message: 'New sandbox starts are paced by the compiled Daytona start rate.',
358
+ pacingDelayMs: Math.max(1, Math.ceil(input.delayMs)),
359
+ });
360
+ }
361
+
307
362
  /**
308
363
  * Scheduler admission must be durable before a provider create. If that
309
364
  * control-plane read/write is temporarily unavailable, defer through the
@@ -18,7 +18,17 @@ export type SandboxCleanupDeleteOutcome =
18
18
  | { kind: 'deleted'; routingDomain: string | null }
19
19
  | { kind: 'already_absent'; routingDomain: string | null }
20
20
  /** Nothing failed, but the provider has not yet shown the resource is gone. */
21
- | { kind: 'pending'; code: string; detail: string }
21
+ | {
22
+ kind: 'pending';
23
+ code: string;
24
+ detail: string;
25
+ /**
26
+ * How long ago the provider accepted a delete, when that time is known,
27
+ * so only its read-back is outstanding. Null while the provider has
28
+ * taken no delete, such as during a state change.
29
+ */
30
+ deleteAcceptedForMs: number | null;
31
+ }
22
32
  /** The provider outcome is ambiguous or failed; its resource remains live. */
23
33
  | { kind: 'failed'; code: string; detail: string };
24
34
 
@@ -42,7 +42,9 @@ export function createSandboxCleanupJob(
42
42
  ports,
43
43
  input,
44
44
  deletion.detail,
45
- confirmationReadDelay(input.resource.failureCount + 1),
45
+ deletion.deleteAcceptedForMs === null
46
+ ? busyProviderReadDelay(input.resource.failureCount + 1)
47
+ : confirmationReadDelay(deletion.deleteAcceptedForMs),
46
48
  { code: deletion.code },
47
49
  );
48
50
  }
@@ -155,16 +157,44 @@ function retryDelay(nextFailureCount: number): number {
155
157
  * delete on Oct 31 (115 sightings of 10,785 deletes, 5-minute passes). Reading
156
158
  * at 5 seconds usually needs one read, so a cleanup costs three control
157
159
  * requests. At 500,000 cleanups a month that is under 1 request per second, and
158
- * the 4/s dense-load peak stays near 12/s, against a budget of 25/s. Doubling
159
- * to 5 minutes leaves a stuck sandbox costing one read per interval.
160
+ * the 4/s dense-load peak stays near 12/s, against a budget of 25/s. Waiting
161
+ * as long as the delete has been accepted doubles the interval up to 5 minutes,
162
+ * so a stuck sandbox costs one read per interval. The interval counts from the
163
+ * acceptance, not from earlier refusals: in load run 43258059009 ten deletes
164
+ * accepted after nine 409s waited the full 5 minutes for a 404.
160
165
  */
161
166
  const CONFIRMATION_READ_DELAY_MS = 5_000;
162
167
 
163
- function confirmationReadDelay(nextFailureCount: number): number {
168
+ function confirmationReadDelay(deleteAcceptedForMs: number): number {
164
169
  return Math.min(
165
170
  5 * 60_000,
166
- CONFIRMATION_READ_DELAY_MS *
167
- 2 ** Math.min(6, Math.max(0, nextFailureCount - 1)),
171
+ Math.max(CONFIRMATION_READ_DELAY_MS, deleteAcceptedForMs),
172
+ );
173
+ }
174
+
175
+ /**
176
+ * A provider that has taken no delete yet, such as Daytona answering 409 while
177
+ * a sandbox is stuck creating, is asked again at most 30 seconds after it frees
178
+ * up, for its first 32 reads (about 15 minutes). Most 409s clear within about
179
+ * 25 seconds, and in load run 43258059009 they lasted 10 to 15 minutes. Each
180
+ * busy read costs two control requests, a lookup and the refused delete, so a
181
+ * sandbox still refused after that doubles back up to 5 minutes: an incident
182
+ * holding hundreds of sandboxes then costs what it did before this window,
183
+ * instead of two requests per sandbox every 30 seconds for as long as it lasts.
184
+ */
185
+ const BUSY_PROVIDER_FAST_READS = 32;
186
+
187
+ function busyProviderReadDelay(nextFailureCount: number): number {
188
+ if (nextFailureCount <= BUSY_PROVIDER_FAST_READS) {
189
+ return Math.min(
190
+ 30_000,
191
+ CONFIRMATION_READ_DELAY_MS *
192
+ 2 ** Math.min(6, Math.max(0, nextFailureCount - 1)),
193
+ );
194
+ }
195
+ return Math.min(
196
+ 5 * 60_000,
197
+ 30_000 * 2 ** Math.min(4, nextFailureCount - BUSY_PROVIDER_FAST_READS),
168
198
  );
169
199
  }
170
200