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
@@ -75,6 +75,11 @@ export const SOURCE_IMAGE_METADATA_KEY = 'deepline_source_image';
75
75
  export const ROLLBACK_HOLD_UNTIL_METADATA_KEY = 'rollback_hold_until_ms';
76
76
  export const RUNTIME_DEPLOY_VERSION_ENV = 'DEEPLINE_RUNTIME_DEPLOY_VERSION';
77
77
  export const DRAIN_EXIT_ENV = 'DEEPLINE_ABSURD_DRAIN_EXIT';
78
+ /** Fly's `worker_alive` check grace period on a booted worker Machine. The
79
+ * scaler treats a Machine started within it, whose check has not passed or
80
+ * failed yet, as capacity still booting. */
81
+ export const ABSURD_WORKER_ALIVE_GRACE_PERIOD_SECONDS = 30;
82
+
78
83
  // This is an image compatibility contract, not the current source location.
79
84
  // Historical images only have this path; new images retain it as a thin entrypoint
80
85
  // so both old and new scalers can boot, drain, or recover either generation.
@@ -622,7 +627,7 @@ export function buildBootMachineConfig(input: {
622
627
  path: '/healthz',
623
628
  interval: '15s',
624
629
  timeout: '5s',
625
- grace_period: '30s',
630
+ grace_period: `${ABSURD_WORKER_ALIVE_GRACE_PERIOD_SECONDS}s`,
626
631
  },
627
632
  },
628
633
  guest: {
@@ -730,6 +735,66 @@ export function buildRollbackHoldUpdateConfig(
730
735
  };
731
736
  }
732
737
 
738
+ const FLY_DURATION_UNIT_MS: Record<string, number> = {
739
+ h: 3_600_000,
740
+ m: 60_000,
741
+ s: 1_000,
742
+ ms: 1,
743
+ us: 0.001,
744
+ µs: 0.001,
745
+ ns: 0.000_001,
746
+ };
747
+
748
+ /** A Fly (Go) duration such as "300s", "5m0s" or "1h2m3.5s" in milliseconds;
749
+ * null when the value is not one. Fly echoes "300s" back as "5m0s". */
750
+ export function parseFlyDurationMs(value: unknown): number | null {
751
+ if (typeof value !== 'string') return null;
752
+ const text = value.trim();
753
+ if (!/^(?:\d+(?:\.\d+)?(?:h|ms|m|s|us|µs|ns))+$/.test(text)) return null;
754
+ let totalMs = 0;
755
+ for (const [, amount, unit] of text.matchAll(
756
+ /(\d+(?:\.\d+)?)(h|ms|m|s|us|µs|ns)/g,
757
+ )) {
758
+ totalMs += Number(amount) * FLY_DURATION_UNIT_MS[unit!]!;
759
+ }
760
+ return totalMs;
761
+ }
762
+
763
+ export type WorkerSlotCapUpdateReason =
764
+ | 'config_unreadable'
765
+ | 'exec_differs'
766
+ | 'stop_signal_differs'
767
+ | 'stop_timeout_differs';
768
+
769
+ /**
770
+ * Why `buildWorkerSlotCapUpdateConfig` would change this Machine, or null
771
+ * when its exec and stop config already match what the update writes. A
772
+ * config that cannot be read counts as different, so it is still updated.
773
+ */
774
+ export function workerSlotCapUpdateReason(
775
+ machine: FlyMachine,
776
+ ): WorkerSlotCapUpdateReason | null {
777
+ const exec = machine.config?.init?.exec;
778
+ const stop = machine.config?.stop_config;
779
+ const timeoutMs = parseFlyDurationMs(stop?.timeout);
780
+ if (!Array.isArray(exec) || !stop?.signal || timeoutMs === null) {
781
+ return 'config_unreadable';
782
+ }
783
+ if (
784
+ exec.length !== ABSURD_RUNTIME_WORKER_EXEC.length ||
785
+ exec.some((value, index) => value !== ABSURD_RUNTIME_WORKER_EXEC[index])
786
+ ) {
787
+ return 'exec_differs';
788
+ }
789
+ if (stop.signal !== DEFAULT_LANE_REPLACEMENT_STOP_SIGNAL) {
790
+ return 'stop_signal_differs';
791
+ }
792
+ if (timeoutMs !== parseFlyDurationMs(DEFAULT_LANE_REPLACEMENT_STOP_TIMEOUT)) {
793
+ return 'stop_timeout_differs';
794
+ }
795
+ return null;
796
+ }
797
+
733
798
  export function buildWorkerSlotCapUpdateConfig(machine: FlyMachine): {
734
799
  config: Record<string, unknown>;
735
800
  skip_launch?: boolean;
@@ -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,21 @@ 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>;
411
+ /**
412
+ * Identities that can only PROVE an unbound recorded operation is this
413
+ * occurrence's, never disprove it: an invocation-scoped tool's result keys
414
+ * recomputed for this call's own occurrence index. A match reuses the
415
+ * record; a miss proves nothing, so the call is decided as if this were
416
+ * absent.
417
+ */
418
+ legacyOwnOccurrenceIdentities?: () => Promise<readonly string[]>;
442
419
  /**
443
420
  * The operation key itself already encodes the authored request (a
444
421
  * `ctx.step` with a `semanticKey`): an unbound receipt under it can only be
445
422
  * this request's or an identical declared request's.
446
423
  */
447
424
  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
425
  /** Digest of the authored request alone; see `CompletedCall`. */
456
426
  inputFingerprint?: string;
457
427
  /**
@@ -464,6 +434,8 @@ export async function executeWithFreshnessReceipt<T>(input: {
464
434
  * thrown, so a Play that catches the error cannot hide it.
465
435
  */
466
436
  onRefusal?: (refusal: ReplayRefusal) => void;
437
+ /** This call's call-order occurrence in its scope, for refusal reports. */
438
+ callOrdinal?: number;
467
439
  /** Names the call in a mismatch error. */
468
440
  operation?: string;
469
441
  callId?: string;
@@ -476,7 +448,10 @@ export async function executeWithFreshnessReceipt<T>(input: {
476
448
  * They are published together with this call's operation receipt, before the
477
449
  * call returns, so customer code never observes a result that is not durable.
478
450
  */
479
- execute: (publication: DeferredReceiptPublication) => Promise<T>;
451
+ execute: (
452
+ publication: DeferredReceiptPublication,
453
+ replay?: FreshExecutionReplay,
454
+ ) => Promise<T>;
480
455
  completedAt?: (value: T) => number | undefined;
481
456
  /**
482
457
  * False keeps an empty or unsuccessful result out of the shared latest
@@ -533,24 +508,6 @@ export async function executeWithFreshnessReceipt<T>(input: {
533
508
  ) => Promise<Result>;
534
509
  now?: () => number;
535
510
  }): 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
511
  if (!input.store.enabled) {
555
512
  throw new Error(
556
513
  'Durable operation recovery is unavailable in this runtime.',
@@ -864,7 +821,8 @@ async function executeWithFreshnessReceiptOnce<T>(
864
821
  ]);
865
822
  if (operation.status === 'rejected') throw operation.reason;
866
823
  const { exact, callOrder } = operation.value;
867
- reportOwnSlot(callOrder !== null && ownsOperation(callOrder) === 'unverified');
824
+ /** Set when a pre-binding record in this call's own slot may not be reused. */
825
+ let freshExecution = false;
868
826
  // Same-run recovery returns only this call's own recorded result.
869
827
  if (exact && ownsOperation(exact) === 'yes') {
870
828
  return outcome(exact, 'operation_recovery');
@@ -879,78 +837,112 @@ async function executeWithFreshnessReceiptOnce<T>(
879
837
  * with zero dispatch, read or write: an unverifiable slot may be another
880
838
  * request's result, and executing could repeat a paid call.
881
839
  */
882
- const recoverUnbound = async (recorded: CompletedCall) => {
883
- const search = input.legacySlotSearch;
884
- const proven =
840
+ /**
841
+ * A pre-binding receipt is reused only when it is a proven matching
842
+ * completed receipt: this call's own call-order slot, with a retained
843
+ * request identity that proves the same request. Builds before bindings
844
+ * numbered identical requests in tool-layer entry order, so nothing
845
+ * recorded proves which identical occurrence a receipt was; the own slot is
846
+ * the only occurrence evidence, and no result is taken from another slot.
847
+ *
848
+ * A slot whose identity proves a different request is a proven mismatch: a
849
+ * proven read executes and anything that may write refuses with zero
850
+ * dispatch. A slot that proves nothing (no retained identity, an unreadable
851
+ * referent) is not reused and the call executes: legacy history is
852
+ * at-least-once, so a call that may already have completed can repeat its
853
+ * effect, but never returns another call's output (founder decision,
854
+ * 2026-11-14 ~00:00Z).
855
+ */
856
+ const recoverUnbound = async (
857
+ recorded: CompletedCall,
858
+ ): Promise<T | typeof EXECUTE> => {
859
+ const recordedIdentities =
860
+ input.operationKeyEncodesRequest === true
861
+ ? []
862
+ : await recordedIdentitiesOf(recorded);
863
+ if (
885
864
  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
- );
865
+ (await recordedIdentityMatches(recordedIdentities)) ||
866
+ (await recordedOwnOccurrenceMatches(recordedIdentities))
867
+ ) {
868
+ input.onLegacyRecoveryProven?.();
869
+ return outcome(recorded, 'operation_recovery');
870
+ }
871
+ if (
872
+ recordedIdentities.length === 0 ||
873
+ !input.legacyRequestIdentities ||
874
+ (await input.legacyRequestIdentities()) === null
875
+ ) {
876
+ return EXECUTE;
911
877
  }
912
- input.onLegacyRecoveryProven?.();
913
- return outcome(recorded, 'operation_recovery');
878
+ const policy = input.replayMismatchPolicy
879
+ ? await input.replayMismatchPolicy()
880
+ : 'fail';
881
+ if (policy === 'execute') return EXECUTE;
882
+ input.onRefusal?.({
883
+ code: 'DURABLE_REPLAY_INPUT_MISMATCH',
884
+ operation: input.operation ?? 'call',
885
+ callId: input.callId ?? 'unknown',
886
+ ordinal: input.callOrdinal ?? null,
887
+ rung: 'legacy_ownership',
888
+ reason: 'recorded_identity_mismatch',
889
+ recordedIdentitySources: recordedIdentitySources(recorded),
890
+ });
891
+ throw new DurableReplayInputMismatchError(
892
+ input.operation ?? 'call',
893
+ input.callId ?? 'unknown',
894
+ 'input_changed',
895
+ );
914
896
  };
915
897
  /**
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.
898
+ * The request identities a pre-binding operation retained: an inline
899
+ * result's own metadata, or, for a relay reference, the metadata of that
900
+ * exact referent read through the receipt owner (one bounded read, only on
901
+ * this legacy path). Never business output, never the current request.
918
902
  */
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
- }
903
+ const recordedIdentitiesOf = async (
904
+ recorded: CompletedCall,
905
+ ): Promise<string[]> => {
906
+ if (!recorded.valueReceiptKey) {
907
+ return resultRequestIdentities(recorded.value);
942
908
  }
943
- return null;
909
+ const referent = await input.withHydration(async (measure) => {
910
+ const receipt = await input.store.get(recorded.valueReceiptKey!);
911
+ measure?.([receipt]);
912
+ return receipt;
913
+ });
914
+ if (
915
+ !referent ||
916
+ !['completed', 'skipped'].includes(referent.status) ||
917
+ referent.output === undefined
918
+ ) {
919
+ return [];
920
+ }
921
+ return resultRequestIdentities(referent.output);
944
922
  };
945
- const recordedIdentityMatches = async (
946
- recorded: CompletedCall,
923
+ const recordedOwnOccurrenceMatches = async (
924
+ recordedIdentities: readonly string[],
947
925
  ): 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());
926
+ if (
927
+ !input.legacyOwnOccurrenceIdentities ||
928
+ recordedIdentities.length === 0
929
+ ) {
930
+ return false;
931
+ }
932
+ const current = new Set(await input.legacyOwnOccurrenceIdentities());
952
933
  return recordedIdentities.some((identity) => current.has(identity));
953
934
  };
935
+ const recordedIdentityMatches = async (
936
+ recordedIdentities: readonly string[],
937
+ ): Promise<boolean> => {
938
+ if (!input.legacyRequestIdentities || recordedIdentities.length === 0) {
939
+ return false;
940
+ }
941
+ const current = await input.legacyRequestIdentities();
942
+ if (!current) return false;
943
+ const currentKeys = new Set(current);
944
+ return recordedIdentities.some((identity) => currentKeys.has(identity));
945
+ };
954
946
  /**
955
947
  * A recorded slot holds another request. A read never completed in this
956
948
  * run and executes; a call that may write fails loudly instead of returning
@@ -973,7 +965,7 @@ async function executeWithFreshnessReceiptOnce<T>(
973
965
  code: 'DURABLE_REPLAY_INPUT_MISMATCH',
974
966
  operation: input.operation ?? 'call',
975
967
  callId: input.callId ?? 'unknown',
976
- ordinal: input.legacySlotSearch?.ownIndex ?? null,
968
+ ordinal: input.callOrdinal ?? null,
977
969
  rung: 'binding',
978
970
  reason,
979
971
  slot,
@@ -990,27 +982,27 @@ async function executeWithFreshnessReceiptOnce<T>(
990
982
  await refuseOrExecute(exact, 'exact_request');
991
983
  } else if (callOrder) {
992
984
  if (ownsOperation(callOrder) === 'unverified') {
993
- return recoverUnbound(callOrder);
985
+ const recovered = await recoverUnbound(callOrder);
986
+ if (recovered !== EXECUTE) return recovered;
987
+ freshExecution = true;
988
+ } else {
989
+ await refuseOrExecute(callOrder, 'call_order');
994
990
  }
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
991
  }
1006
992
  if (legacyOperationKey && !exact && !callOrder) {
1007
993
  const legacy =
1008
994
  await readLegacyOperationWrittenByThisRun(legacyOperationKey);
1009
995
  if (legacy) {
1010
996
  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');
997
+ if (owner === 'unverified') {
998
+ const recovered = await recoverUnbound(legacy);
999
+ if (recovered !== EXECUTE) return recovered;
1000
+ freshExecution = true;
1001
+ } else if (owner === 'yes') {
1002
+ return outcome(legacy, 'operation_recovery');
1003
+ } else {
1004
+ await refuseOrExecute(legacy, 'legacy_key');
1005
+ }
1014
1006
  }
1015
1007
  }
1016
1008
  if (candidateManifests.status === 'rejected') {
@@ -1063,11 +1055,14 @@ async function executeWithFreshnessReceiptOnce<T>(
1063
1055
  const deferred: DeferredReceiptWrite[] = [];
1064
1056
  let value: T;
1065
1057
  try {
1066
- value = await input.execute({
1067
- defer: (write) => {
1068
- deferred.push(write);
1058
+ value = await input.execute(
1059
+ {
1060
+ defer: (write) => {
1061
+ deferred.push(write);
1062
+ },
1069
1063
  },
1070
- });
1064
+ freshExecution ? { freshInvocation: true } : undefined,
1065
+ );
1071
1066
  } catch (error) {
1072
1067
  // A deferred write is a result the call already received (the provider
1073
1068
  // 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