deepline 0.3.523 → 0.3.525

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 (177) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +68 -60
  2. package/dist/bundling-sources/sdk/src/http-core.ts +14 -0
  3. package/dist/bundling-sources/sdk/src/plays/play-description.ts +1 -0
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/sdk/src/types.ts +10 -0
  6. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +60 -14
  7. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +9 -3
  8. package/dist/bundling-sources/shared_libs/observability/dlq.ts +19 -0
  9. package/dist/bundling-sources/shared_libs/observability/queue-health.ts +9 -0
  10. package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
  11. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
  12. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +397 -22
  13. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +473 -13
  14. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +28 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/run-retry-summary.ts +202 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +60 -8
  17. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +112 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +39 -1
  19. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +13 -5
  20. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +10 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-retry-facts.ts +62 -0
  22. package/dist/cli/auth-K7PMRXNG.js +43 -0
  23. package/dist/cli/{auth-ENQUQS56.mjs → auth-TH3VGYBK.mjs} +5 -5
  24. package/dist/cli/{billing-6A27ULCX.mjs → billing-CMHFI2LN.mjs} +8 -8
  25. package/dist/cli/{billing-6HONTJOY.js → billing-TWKVUFU2.js} +83 -83
  26. package/dist/cli/{chunk-JMMNCJ7Z.js → chunk-2WFVLOB7.js} +1 -1
  27. package/dist/cli/{chunk-S4YKRH3W.js → chunk-4UWXFXQF.js} +3 -3
  28. package/dist/cli/{chunk-PCORO245.mjs → chunk-5BSGWIQD.mjs} +2 -2
  29. package/dist/cli/{chunk-SBGKKOCC.js → chunk-5JFAQUZS.js} +26 -26
  30. package/dist/cli/{chunk-RVHUW4TN.js → chunk-5YAJGRWB.js} +17 -17
  31. package/dist/cli/{chunk-ITJ7NB2D.mjs → chunk-7AOFSZJM.mjs} +3 -1
  32. package/dist/cli/{chunk-JVEFMOY2.mjs → chunk-7C4F4TLR.mjs} +1 -1
  33. package/dist/cli/{chunk-QMBL5ZIQ.mjs → chunk-7OF3A4KJ.mjs} +3 -3
  34. package/dist/cli/{chunk-326WVSWS.js → chunk-AVDEYOVP.js} +269 -269
  35. package/dist/cli/{chunk-GJYLC4JB.mjs → chunk-BNH4Y35W.mjs} +2 -2
  36. package/dist/cli/{chunk-ZWN4RXC2.js → chunk-CKTRQSRA.js} +22 -22
  37. package/dist/cli/{chunk-I62LJ7NU.mjs → chunk-CLTL7ZJI.mjs} +1 -1
  38. package/dist/cli/{chunk-IEVXYHGJ.js → chunk-CQSANB3V.js} +5 -5
  39. package/dist/cli/{chunk-QYXIODWH.js → chunk-CWRL6IQP.js} +44 -29
  40. package/dist/cli/{chunk-WVQOXYTQ.mjs → chunk-CZNEQMJR.mjs} +37 -34
  41. package/dist/cli/{chunk-4NWY7JBB.js → chunk-DYS3KWYF.js} +11 -11
  42. package/dist/cli/{chunk-HSVGP4CI.mjs → chunk-EP6YH6QJ.mjs} +2 -2
  43. package/dist/cli/{chunk-XYL26236.js → chunk-ESWM2JW4.js} +2 -2
  44. package/dist/cli/{chunk-6OZ2WSHD.mjs → chunk-ETHVJ2ZE.mjs} +1 -1
  45. package/dist/cli/{chunk-6DBRBWHC.mjs → chunk-GCLNX72G.mjs} +2 -2
  46. package/dist/cli/{chunk-R2VZVHJP.mjs → chunk-GESIFFQX.mjs} +1 -1
  47. package/dist/cli/{chunk-QSAC3IVI.mjs → chunk-IMO3HXWZ.mjs} +1 -1
  48. package/dist/cli/{chunk-JGZQBDYG.mjs → chunk-JVWSIA2V.mjs} +4 -4
  49. package/dist/cli/{chunk-7GNKAACY.js → chunk-KBOSALBI.js} +10 -10
  50. package/dist/cli/{chunk-K326BEVR.js → chunk-KEZ3KBWW.js} +10 -10
  51. package/dist/cli/{chunk-7M5FRSFP.mjs → chunk-KPINGHIF.mjs} +2 -2
  52. package/dist/cli/{chunk-UH3EAFFN.mjs → chunk-LAMGJQDY.mjs} +2 -2
  53. package/dist/cli/{chunk-UQN4VTZL.js → chunk-LE537GBC.js} +13 -6
  54. package/dist/cli/{chunk-PESMXAUG.js → chunk-LXKH4MKH.js} +6 -6
  55. package/dist/cli/{chunk-4V63IJCL.mjs → chunk-M43ZYNDA.mjs} +5 -5
  56. package/dist/cli/{chunk-XVXEARHC.js → chunk-MHBSRNI7.js} +41 -41
  57. package/dist/cli/{chunk-HUC5SGJQ.js → chunk-MRUFGOJR.js} +2 -2
  58. package/dist/cli/{chunk-RQN4PHRE.js → chunk-N4MMU3QF.js} +21 -21
  59. package/dist/cli/{chunk-2BRDHM4S.js → chunk-NB2ECLQE.js} +9 -9
  60. package/dist/cli/{chunk-DNXP3D5H.mjs → chunk-NO4URKKT.mjs} +5 -5
  61. package/dist/cli/{chunk-MZROKQV3.js → chunk-NRBCETWL.js} +44 -44
  62. package/dist/cli/{chunk-JCTTXLAZ.mjs → chunk-OWQF6WVH.mjs} +10 -3
  63. package/dist/cli/{chunk-NWTMQGPP.mjs → chunk-OXFIJYN3.mjs} +8 -8
  64. package/dist/cli/{chunk-FBMOBNJY.js → chunk-P62LON53.js} +2 -2
  65. package/dist/cli/{chunk-NMU3VR5U.js → chunk-PMH4GLMD.js} +1 -0
  66. package/dist/cli/{chunk-S3A4IXBQ.mjs → chunk-PSX3WHIH.mjs} +1 -0
  67. package/dist/cli/{chunk-N5MLEXZ7.js → chunk-QR7VYYNM.js} +176 -173
  68. package/dist/cli/{chunk-RKREB7MU.mjs → chunk-RMZ6CISE.mjs} +3 -3
  69. package/dist/cli/{chunk-V46J3UTM.js → chunk-S5LUY3KJ.js} +7 -7
  70. package/dist/cli/{chunk-MCXPJYBN.js → chunk-TFEGJEYO.js} +3 -3
  71. package/dist/cli/{chunk-MT3WG3KR.js → chunk-TO72GW5I.js} +16 -16
  72. package/dist/cli/{chunk-H7275EZU.mjs → chunk-TXSBPBHB.mjs} +5 -5
  73. package/dist/cli/{chunk-SXTVJIGB.mjs → chunk-U4M32NFS.mjs} +1 -1
  74. package/dist/cli/{chunk-5WFQXAD4.mjs → chunk-UQYKSOGO.mjs} +5 -5
  75. package/dist/cli/{chunk-KILRUAXF.mjs → chunk-UXF3ODJJ.mjs} +2 -2
  76. package/dist/cli/{chunk-36LQQL5C.js → chunk-V2GN4PLK.js} +5 -5
  77. package/dist/cli/{chunk-HUIFUE4L.js → chunk-V65J64FL.js} +53 -53
  78. package/dist/cli/{chunk-U6DLLV3S.mjs → chunk-VYIAWAKJ.mjs} +1 -1
  79. package/dist/cli/{chunk-WGVJA4I5.js → chunk-WA3FG7DH.js} +14 -14
  80. package/dist/cli/{chunk-MHTRYBXY.mjs → chunk-WEYFSBAD.mjs} +44 -29
  81. package/dist/cli/{chunk-LZL6V5M5.mjs → chunk-WGRDOPAK.mjs} +2 -2
  82. package/dist/cli/{chunk-NTLBZUHD.js → chunk-XYIECA7M.js} +4 -2
  83. package/dist/cli/{chunk-QOO5W5XS.mjs → chunk-YC7FKAJ4.mjs} +12 -12
  84. package/dist/cli/{chunk-BN5VKY4X.js → chunk-ZS2WHWWL.js} +7 -7
  85. package/dist/cli/{chunk-F3WRLFFM.mjs → chunk-ZWFTHEPT.mjs} +2 -2
  86. package/dist/cli/command-docs.js +2 -2
  87. package/dist/cli/command-docs.mjs +1 -1
  88. package/dist/cli/{csv-UBACJK75.js → csv-5JHWVJ5N.js} +13 -13
  89. package/dist/cli/{csv-YFJ2JLUP.mjs → csv-OO554TPX.mjs} +4 -4
  90. package/dist/cli/{db-2ZPA2LZ7.js → db-CYQJ4OXF.js} +28 -28
  91. package/dist/cli/{db-NKGYTAQO.mjs → db-SQKJ6RKU.mjs} +7 -7
  92. package/dist/cli/describe-N7AKTUQV.mjs +50 -0
  93. package/dist/cli/describe-PASXOL3R.js +50 -0
  94. package/dist/cli/describe-core.d.mts +4 -2
  95. package/dist/cli/describe-core.d.ts +4 -2
  96. package/dist/cli/describe-core.js +5 -5
  97. package/dist/cli/describe-core.mjs +4 -4
  98. package/dist/cli/{executions-HTHQ7KKD.mjs → executions-F34DORW6.mjs} +7 -7
  99. package/dist/cli/{executions-NXMRGPIL.js → executions-K7EGCRKX.js} +9 -9
  100. package/dist/cli/{feedback-USP4T34P.mjs → feedback-GQHKCS66.mjs} +5 -5
  101. package/dist/cli/{feedback-TGVQACRO.js → feedback-NOQVCA3Q.js} +10 -10
  102. package/dist/cli/{git-KUONEHCD.mjs → git-2EEITXDB.mjs} +5 -5
  103. package/dist/cli/git-UU4YFJ2Q.js +25 -0
  104. package/dist/cli/index.js +146 -146
  105. package/dist/cli/index.mjs +45 -45
  106. package/dist/cli/{legacy-noops-B2GMHU42.mjs → legacy-noops-JHMY5XRB.mjs} +6 -6
  107. package/dist/cli/{legacy-noops-2JY3CQ24.js → legacy-noops-RFNHQ7RG.js} +9 -9
  108. package/dist/cli/{monitors-2OVBZJ6Z.mjs → monitors-RDMP6SPZ.mjs} +8 -8
  109. package/dist/cli/{monitors-XI6I52AX.js → monitors-UKRZ4BDK.js} +101 -101
  110. package/dist/cli/{org-5TUQ2H6Y.js → org-OX7TYTHV.js} +87 -87
  111. package/dist/cli/{org-BNJW764Y.mjs → org-RF3G4KMB.mjs} +7 -7
  112. package/dist/cli/{pages-QC3TQIPW.mjs → pages-FBM3MGSP.mjs} +7 -7
  113. package/dist/cli/{pages-UXCLX53Y.js → pages-MKQT5LFV.js} +19 -19
  114. package/dist/cli/{play-KRWMZ7FG.js → play-OOVX2DMV.js} +802 -713
  115. package/dist/cli/{play-45PPG5SZ.mjs → play-YWC2UORM.mjs} +197 -108
  116. package/dist/cli/{providers-RBUJ72Y3.js → providers-2CGZYLER.js} +10 -10
  117. package/dist/cli/{providers-JDT35MRL.mjs → providers-3PEQESIU.mjs} +7 -7
  118. package/dist/cli/{quickstart-JZ4Q3HFT.js → quickstart-6AANHKQZ.js} +6 -6
  119. package/dist/cli/{quickstart-GD2SWGAC.mjs → quickstart-KVB36SOW.mjs} +4 -4
  120. package/dist/cli/{run-JEAHA367.js → run-NJ7WV5TK.js} +46 -46
  121. package/dist/cli/{run-KIZ3HBI2.mjs → run-QC23NRKO.mjs} +27 -27
  122. package/dist/cli/{search-5UFNXHFK.mjs → search-7BMFFZI2.mjs} +9 -9
  123. package/dist/cli/search-NH4DTXUK.js +33 -0
  124. package/dist/cli/{search-output-HAXPKQO6.mjs → search-output-CALZ4ZI2.mjs} +4 -4
  125. package/dist/cli/{search-output-W3RDSVLE.js → search-output-XC2AVBFX.js} +6 -6
  126. package/dist/cli/{secrets-JAWT66B2.mjs → secrets-7ZHA57DI.mjs} +7 -7
  127. package/dist/cli/{secrets-PC7C2Q32.js → secrets-VHU4B2D4.js} +16 -16
  128. package/dist/cli/sessions-2TE5JWVP.js +18 -0
  129. package/dist/cli/{sessions-325V7G35.mjs → sessions-YYULWFZE.mjs} +6 -6
  130. package/dist/cli/{settings-FKHTA65P.mjs → settings-AVY4NNHI.mjs} +14 -14
  131. package/dist/cli/{settings-RGU6Y2QR.js → settings-WV77QJGD.js} +87 -87
  132. package/dist/cli/{setup-43GOYTFC.mjs → setup-AOUJ3RMU.mjs} +10 -10
  133. package/dist/cli/{setup-ZMZ7HU2I.js → setup-GE5TLTC4.js} +50 -50
  134. package/dist/cli/{skills-Q2VAHSXM.mjs → skills-FVWO2G66.mjs} +8 -8
  135. package/dist/cli/skills-OL7LD6QX.js +37 -0
  136. package/dist/cli/{tools-BUH7ZWDS.mjs → tools-URE655B4.mjs} +20 -20
  137. package/dist/cli/tools-VQ5JO6DI.js +57 -0
  138. package/dist/cli/{update-JFALWOHD.mjs → update-5B4G4345.mjs} +10 -10
  139. package/dist/cli/update-7ZOIOTZN.js +35 -0
  140. package/dist/cli/{artifacts-RBHR2DG4.mjs → views-GSECJ5IK.mjs} +77 -77
  141. package/dist/cli/views-IC762HEQ.js +270 -0
  142. package/dist/cli/{workflow-ISJKLY6X.mjs → workflow-6UQM565I.mjs} +8 -8
  143. package/dist/cli/{workflow-YELST32A.js → workflow-EME7ZEOV.js} +18 -18
  144. package/dist/{client-C2N7MofG.d.mts → client-Bd2meveV.d.mts} +1 -1
  145. package/dist/{client-C7lTRJjw.d.ts → client-CBCVhL8U.d.ts} +1 -1
  146. package/dist/{client-core-BTkDSKGn.d.mts → client-core-CGj8V9mw.d.mts} +110 -43
  147. package/dist/{client-core-hmhBi7Ib.d.ts → client-core-CsRRWCFy.d.ts} +110 -43
  148. package/dist/index.d.mts +3 -3
  149. package/dist/index.d.ts +3 -3
  150. package/dist/index.js +10 -10
  151. package/dist/index.mjs +7 -7
  152. package/dist/install-integrity.json +120 -118
  153. package/dist/plays/play-description.d.mts +1 -1
  154. package/dist/plays/play-description.d.ts +1 -1
  155. package/dist/plays/play-description.js +2 -2
  156. package/dist/plays/play-description.mjs +1 -1
  157. package/dist/plays/run-request.d.mts +1 -1
  158. package/dist/plays/run-request.d.ts +1 -1
  159. package/dist/release.d.mts +1 -1
  160. package/dist/release.d.ts +1 -1
  161. package/dist/release.js +2 -2
  162. package/dist/release.mjs +1 -1
  163. package/dist/server.d.mts +2 -2
  164. package/dist/server.d.ts +2 -2
  165. package/dist/server.js +6 -6
  166. package/dist/server.mjs +4 -4
  167. package/package.json +1 -1
  168. package/dist/cli/artifacts-RZTS2JHZ.js +0 -270
  169. package/dist/cli/auth-DPWYFQR5.js +0 -43
  170. package/dist/cli/describe-GX7DRKWZ.mjs +0 -50
  171. package/dist/cli/describe-WQZF7MEG.js +0 -50
  172. package/dist/cli/git-X3SCQREB.js +0 -25
  173. package/dist/cli/search-6JULJMD7.js +0 -33
  174. package/dist/cli/sessions-WFUCOJHZ.js +0 -18
  175. package/dist/cli/skills-3XTQ6FFM.js +0 -37
  176. package/dist/cli/tools-UK2R4YXQ.js +0 -57
  177. package/dist/cli/update-LNKPHS54.js +0 -35
@@ -25,8 +25,122 @@ export type CompletedCall = {
25
25
  /** Reuse a result already stored by its canonical receipt without copying it. */
26
26
  valueReceiptKey?: string;
27
27
  undefinedValue?: true;
28
+ /**
29
+ * Optional, reader-first: `sha256(semanticKey)` of the call that recorded
30
+ * this operation, i.e. the org, authored request (tool id and normalized
31
+ * input, or fetch method, URL and body), credential scope and action
32
+ * revision. Operation recovery returns a recorded result only to a call
33
+ * with the same fingerprint. Receipts written before it existed lack it;
34
+ * older readers ignore it.
35
+ */
36
+ requestFingerprint?: string;
37
+ /**
38
+ * Optional, reader-first: digest of the authored request alone (tool id and
39
+ * normalized input, or fetch method, URL and body), without credential
40
+ * scope or action revision. Distinguishes a changed input from a changed
41
+ * credential or action revision when `requestFingerprint` differs.
42
+ */
43
+ inputFingerprint?: string;
44
+ };
45
+
46
+ /**
47
+ * One replay refusal, as decided. Carries no input, output or secret: only
48
+ * identities the authored source already names and which check failed.
49
+ */
50
+ export type ReplayRefusal = {
51
+ code: 'DURABLE_REPLAY_INPUT_MISMATCH' | 'DURABLE_REPLAY_UNVERIFIABLE_LEGACY_SLOT';
52
+ operation: string;
53
+ callId: string;
54
+ /** This call's call-order occurrence in its scope, when known. */
55
+ ordinal: number | null;
56
+ /**
57
+ * The check that refused:
58
+ * - `binding`: a bound receipt of another request identity;
59
+ * - `legacy_ownership`: a pre-binding receipt nothing proves is this call's.
60
+ */
61
+ rung: 'binding' | 'legacy_ownership';
62
+ reason:
63
+ | 'input_changed'
64
+ | 'credential_or_action_changed'
65
+ | 'no_identity_source'
66
+ | 'no_recorded_identity'
67
+ | 'recorded_identity_mismatch'
68
+ | 'slot_taken_by_sibling';
69
+ /** Binding refusals: which slot held the other request. */
70
+ slot?: 'exact_request' | 'call_order' | 'legacy_key';
71
+ /** Legacy refusals: where the recorded identities came from. */
72
+ recordedIdentitySources?: Array<'value_receipt_key' | 'result_metadata'>;
73
+ };
74
+
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;
28
89
  };
29
90
 
91
+ /**
92
+ * What a replayed call does when its recorded slot holds a different request
93
+ * and no exact-request slot holds its own: a read executes (it never
94
+ * completed in this run); anything that may write fails loudly.
95
+ */
96
+ export type ReplayMismatchPolicy = 'execute' | 'fail';
97
+
98
+ /**
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.
103
+ */
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';
108
+
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
+ }
119
+
120
+ /**
121
+ * A replay reached a recorded operation of a different request and the call
122
+ * may write. Returning the recorded result would hand back another request's
123
+ * output; executing could repeat a write. Not retryable: the Play's input
124
+ * must be made deterministic, or each distinct call given its own id.
125
+ */
126
+ export class DurableReplayInputMismatchError extends Error {
127
+ readonly code = 'DURABLE_REPLAY_INPUT_MISMATCH';
128
+ readonly retryable = false;
129
+
130
+ constructor(
131
+ readonly operation: string,
132
+ readonly callId: string,
133
+ readonly reason: 'input_changed' | 'credential_or_action_changed',
134
+ ) {
135
+ super(
136
+ reason === 'input_changed'
137
+ ? `DURABLE_REPLAY_INPUT_MISMATCH: ctx.${operation}("${callId}") was replayed with a different input than the call recorded in this run. Deepline did not return the recorded result or repeat the call, because it may write. Make the input deterministic (no current time or random values), or give each distinct call its own id.`
138
+ : `DURABLE_REPLAY_INPUT_MISMATCH: ctx.${operation}("${callId}") was replayed with the same input but a different credential or action revision than the call recorded in this run. Deepline did not return the recorded result or repeat the call, because it may write.`,
139
+ );
140
+ this.name = 'DurableReplayInputMismatchError';
141
+ }
142
+ }
143
+
30
144
  /**
31
145
  * An immutable completed-cache receipt a call hands to the freshness layer
32
146
  * instead of writing it, so the call's finishing writes share one request.
@@ -187,7 +301,13 @@ function isCancellationError(error: unknown): boolean {
187
301
  export function latestCacheResultOutput(
188
302
  call: CompletedCall,
189
303
  ): PublishLatestCacheResultInput['output'] {
190
- const { completedAt: _completedAt, ...result } = call;
304
+ // The shared entry is keyed by the request itself; keep its shape unchanged.
305
+ const {
306
+ completedAt: _completedAt,
307
+ requestFingerprint: _requestFingerprint,
308
+ inputFingerprint: _inputFingerprint,
309
+ ...result
310
+ } = call;
191
311
  return { kind: LATEST_CACHE_RESULT_KIND, ...result };
192
312
  }
193
313
 
@@ -200,6 +320,53 @@ function sharesLatestResult<T>(
200
320
  return sharesResult ? sharesResult(value) : true;
201
321
  }
202
322
 
323
+ /**
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.
327
+ */
328
+ function recordedIdentitySources(
329
+ call: CompletedCall,
330
+ ): Array<'value_receipt_key' | 'result_metadata'> {
331
+ const sources: Array<'value_receipt_key' | 'result_metadata'> = [];
332
+ if (call.valueReceiptKey) sources.push('value_receipt_key');
333
+ const value = call.value;
334
+ const result = isSerializedToolExecuteResult(value)
335
+ ? deserializeToolExecuteResult(value)
336
+ : isToolExecuteResult(value)
337
+ ? value
338
+ : null;
339
+ const execution = result?._metadata?.execution;
340
+ if (
341
+ [execution?.cacheKey, execution?.receiptKey, execution?.resultReceiptKey].some(
342
+ (key) => typeof key === 'string' && key.trim(),
343
+ )
344
+ ) {
345
+ sources.push('result_metadata');
346
+ }
347
+ return sources;
348
+ }
349
+
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;
354
+ const result = isSerializedToolExecuteResult(value)
355
+ ? deserializeToolExecuteResult(value)
356
+ : isToolExecuteResult(value)
357
+ ? value
358
+ : null;
359
+ const execution = result?._metadata?.execution;
360
+ for (const key of [
361
+ execution?.cacheKey,
362
+ execution?.receiptKey,
363
+ execution?.resultReceiptKey,
364
+ ]) {
365
+ if (typeof key === 'string' && key.trim()) keys.add(key.trim());
366
+ }
367
+ return [...keys];
368
+ }
369
+
203
370
  function completedCall(
204
371
  receipt: RuntimeStepReceipt | null,
205
372
  ): CompletedCall | null {
@@ -223,7 +390,13 @@ function completedCall(
223
390
  (candidate.undefinedValue !== undefined &&
224
391
  candidate.undefinedValue !== true) ||
225
392
  (candidate.undefinedValue === true &&
226
- (hasReceiptReference || candidate.value !== null))
393
+ (hasReceiptReference || candidate.value !== null)) ||
394
+ (candidate.requestFingerprint !== undefined &&
395
+ (typeof candidate.requestFingerprint !== 'string' ||
396
+ !candidate.requestFingerprint)) ||
397
+ (candidate.inputFingerprint !== undefined &&
398
+ (typeof candidate.inputFingerprint !== 'string' ||
399
+ !candidate.inputFingerprint))
227
400
  ) {
228
401
  throw new Error('Invalid completed freshness receipt.');
229
402
  }
@@ -241,6 +414,59 @@ export async function executeWithFreshnessReceipt<T>(input: {
241
414
  semanticKey: string;
242
415
  orgId: string;
243
416
  invocationId: string;
417
+ /**
418
+ * Call-order artifacts: the operation slot numbered among identical
419
+ * requests only. Recorded beside the call-order slot and recovered first,
420
+ * so a call whose call-order slot holds a sibling's result still finds its
421
+ * own. Omitted where `invocationId` is already request-scoped.
422
+ */
423
+ exactRequestInvocationId?: string;
424
+ /**
425
+ * A call-order slot was recovered from a receipt written before request
426
+ * fingerprints existed, so its request could not be verified. Recovery keeps
427
+ * the historical behavior for it; the caller reports it (rate-limited).
428
+ */
429
+ /**
430
+ * A recorded operation without a binding was proven to be this call's by a
431
+ * request identity recorded with it. Reported (rate-limited) by the caller.
432
+ */
433
+ onLegacyRecoveryProven?: () => void;
434
+ /**
435
+ * Request-derived identities of this call, as builds before bindings
436
+ * recorded them with a result (for tools: the durable result-cache keys,
437
+ * which hash the request input, credential scope, action version and run
438
+ * cache epoch). An unbound recorded operation is this call's only when one
439
+ * of its recorded identities is in this set. Omitted: no proof exists.
440
+ */
441
+ legacyRequestIdentities?: () => Promise<readonly string[]>;
442
+ /**
443
+ * The operation key itself already encodes the authored request (a
444
+ * `ctx.step` with a `semanticKey`): an unbound receipt under it can only be
445
+ * this request's or an identical declared request's.
446
+ */
447
+ 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
+ /** Digest of the authored request alone; see `CompletedCall`. */
456
+ inputFingerprint?: string;
457
+ /**
458
+ * Decided only when a recorded slot holds a different request. Omitted
459
+ * means `fail`: a call is a read only when its caller proves it.
460
+ */
461
+ replayMismatchPolicy?: () => Promise<ReplayMismatchPolicy>;
462
+ /**
463
+ * Called once per refusal, where it is decided and before the error is
464
+ * thrown, so a Play that catches the error cannot hide it.
465
+ */
466
+ onRefusal?: (refusal: ReplayRefusal) => void;
467
+ /** Names the call in a mismatch error. */
468
+ operation?: string;
469
+ callId?: string;
244
470
  runId: string;
245
471
  requestedStaleAfterSeconds: number | null;
246
472
  effectiveStaleAfterSeconds: number | null;
@@ -307,6 +533,24 @@ export async function executeWithFreshnessReceipt<T>(input: {
307
533
  ) => Promise<Result>;
308
534
  now?: () => number;
309
535
  }): 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> {
310
554
  if (!input.store.enabled) {
311
555
  throw new Error(
312
556
  'Durable operation recovery is unavailable in this runtime.',
@@ -325,11 +569,45 @@ export async function executeWithFreshnessReceipt<T>(input: {
325
569
  const semanticHash = sha256Hex(input.semanticKey);
326
570
  const cachePrefix = `ctx:${input.orgId}:freshness:${semanticHash}`;
327
571
  const latestCacheKey = latestCacheResultKey(input.orgId, input.semanticKey);
328
- const operationKeyFor = (runId: string) =>
572
+ const operationKeyFor = (
573
+ runId: string,
574
+ invocationId: string = input.invocationId,
575
+ ) =>
329
576
  `ctx:${input.orgId}:freshness:operation:${sha256Hex(
330
- stableStringify({ runId, invocationId: input.invocationId }),
577
+ stableStringify({ runId, invocationId }),
331
578
  )}`;
332
579
  const operationKey = operationKeyFor(input.runId);
580
+ const exactRequestOperationKey =
581
+ input.exactRequestInvocationId !== undefined
582
+ ? // Its own namespace, so per-run history counts (post-code recovery's
583
+ // saved calls) still count each call once.
584
+ `ctx:${input.orgId}:freshness:operation-exact:${sha256Hex(
585
+ stableStringify({
586
+ runId: input.runId,
587
+ invocationId: input.exactRequestInvocationId,
588
+ }),
589
+ )}`
590
+ : null;
591
+ /** The slot this call's own result is recorded and recovered under. */
592
+ const ownOperationKey = exactRequestOperationKey ?? operationKey;
593
+ const requestFingerprint = semanticHash;
594
+ const fingerprints = {
595
+ requestFingerprint,
596
+ ...(input.inputFingerprint
597
+ ? { inputFingerprint: input.inputFingerprint }
598
+ : {}),
599
+ };
600
+ /**
601
+ * Whether a recorded operation belongs to this call. A binding must match
602
+ * exactly. A receipt without one predates bindings; see
603
+ * `refuseAmbiguousUnbound` for when it may still be recovered.
604
+ */
605
+ const ownsOperation = (call: CompletedCall): 'yes' | 'no' | 'unverified' =>
606
+ call.requestFingerprint === undefined
607
+ ? 'unverified'
608
+ : call.requestFingerprint === requestFingerprint
609
+ ? 'yes'
610
+ : 'no';
333
611
  const legacyOperationKey =
334
612
  input.legacyOperationRunId !== undefined &&
335
613
  input.legacyOperationRunId !== input.runId
@@ -508,7 +786,9 @@ export async function executeWithFreshnessReceipt<T>(input: {
508
786
  const stored = await input.store.get(key);
509
787
  if (stored?.status !== 'completed' && stored?.status !== 'skipped') {
510
788
  throw new Error(
511
- key === operationKey || key.startsWith(`${cachePrefix}:reusable:`)
789
+ key === operationKey ||
790
+ key === exactRequestOperationKey ||
791
+ key.startsWith(`${cachePrefix}:reusable:`)
512
792
  ? 'Completed freshness receipt publication failed.'
513
793
  : `Tool Result Receipt ${key} could not publish a completed result.`,
514
794
  );
@@ -564,7 +844,18 @@ export async function executeWithFreshnessReceipt<T>(input: {
564
844
  // second read) beside the candidates' manifests. Own-run recovery still
565
845
  // wins whenever it exists.
566
846
  const [operation, candidateManifests] = await Promise.allSettled([
567
- read(operationKey),
847
+ exactRequestOperationKey
848
+ ? // One batch: the exact-request slot and the call-order slot.
849
+ readMany([exactRequestOperationKey, operationKey]).then(
850
+ ([exact, callOrder]) => ({
851
+ exact: completedCall(exact ?? null),
852
+ callOrder: completedCall(callOrder ?? null),
853
+ }),
854
+ )
855
+ : read(operationKey).then((callOrder) => ({
856
+ exact: null,
857
+ callOrder,
858
+ })),
568
859
  candidateKeys.length > 0 && input.store.getMany
569
860
  ? input.store
570
861
  .getMany([...candidateKeys], { hydrateOutput: false })
@@ -572,11 +863,155 @@ export async function executeWithFreshnessReceipt<T>(input: {
572
863
  : Promise.resolve(null),
573
864
  ]);
574
865
  if (operation.status === 'rejected') throw operation.reason;
575
- if (operation.value) return outcome(operation.value, 'operation_recovery');
576
- if (legacyOperationKey) {
866
+ const { exact, callOrder } = operation.value;
867
+ reportOwnSlot(callOrder !== null && ownsOperation(callOrder) === 'unverified');
868
+ // Same-run recovery returns only this call's own recorded result.
869
+ if (exact && ownsOperation(exact) === 'yes') {
870
+ return outcome(exact, 'operation_recovery');
871
+ }
872
+ if (callOrder && ownsOperation(callOrder) === 'yes') {
873
+ return outcome(callOrder, 'operation_recovery');
874
+ }
875
+ /**
876
+ * A recorded operation without a binding is returned only with proof that
877
+ * it is this call's: its operation key encodes the request, or a request
878
+ * identity recorded with it matches this call's. Otherwise the call refuses
879
+ * with zero dispatch, read or write: an unverifiable slot may be another
880
+ * request's result, and executing could repeat a paid call.
881
+ */
882
+ const recoverUnbound = async (recorded: CompletedCall) => {
883
+ const search = input.legacySlotSearch;
884
+ const proven =
885
+ 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
+ );
911
+ }
912
+ input.onLegacyRecoveryProven?.();
913
+ return outcome(recorded, 'operation_recovery');
914
+ };
915
+ /**
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.
918
+ */
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
+ }
942
+ }
943
+ return null;
944
+ };
945
+ const recordedIdentityMatches = async (
946
+ recorded: CompletedCall,
947
+ ): 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));
953
+ };
954
+ /**
955
+ * A recorded slot holds another request. A read never completed in this
956
+ * run and executes; a call that may write fails loudly instead of returning
957
+ * another request's output or repeating a write.
958
+ */
959
+ const refuseOrExecute = async (
960
+ recorded: CompletedCall,
961
+ slot: 'exact_request' | 'call_order' | 'legacy_key',
962
+ ) => {
963
+ const policy = input.replayMismatchPolicy
964
+ ? await input.replayMismatchPolicy()
965
+ : 'fail';
966
+ if (policy === 'execute') return;
967
+ const sameInput =
968
+ recorded.inputFingerprint !== undefined
969
+ ? recorded.inputFingerprint === input.inputFingerprint
970
+ : recorded === exact;
971
+ const reason = sameInput ? 'credential_or_action_changed' : 'input_changed';
972
+ input.onRefusal?.({
973
+ code: 'DURABLE_REPLAY_INPUT_MISMATCH',
974
+ operation: input.operation ?? 'call',
975
+ callId: input.callId ?? 'unknown',
976
+ ordinal: input.legacySlotSearch?.ownIndex ?? null,
977
+ rung: 'binding',
978
+ reason,
979
+ slot,
980
+ });
981
+ throw new DurableReplayInputMismatchError(
982
+ input.operation ?? 'call',
983
+ input.callId ?? 'unknown',
984
+ reason,
985
+ );
986
+ };
987
+ if (exact && ownsOperation(exact) === 'no') {
988
+ // The exact-request slot is keyed by the input itself: only the
989
+ // credential scope or action revision differs.
990
+ await refuseOrExecute(exact, 'exact_request');
991
+ } else if (callOrder) {
992
+ if (ownsOperation(callOrder) === 'unverified') {
993
+ return recoverUnbound(callOrder);
994
+ }
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
+ }
1006
+ if (legacyOperationKey && !exact && !callOrder) {
577
1007
  const legacy =
578
1008
  await readLegacyOperationWrittenByThisRun(legacyOperationKey);
579
- if (legacy) return outcome(legacy, 'operation_recovery');
1009
+ if (legacy) {
1010
+ 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');
1014
+ }
580
1015
  }
581
1016
  if (candidateManifests.status === 'rejected') {
582
1017
  throw candidateManifests.reason;
@@ -594,6 +1029,13 @@ export async function executeWithFreshnessReceipt<T>(input: {
594
1029
  for (const parse of reusable) {
595
1030
  const cached = parse();
596
1031
  if (!cached) continue;
1032
+ // Buckets are keyed by the request; a present binding must agree.
1033
+ if (
1034
+ cached.requestFingerprint !== undefined &&
1035
+ cached.requestFingerprint !== requestFingerprint
1036
+ ) {
1037
+ continue;
1038
+ }
597
1039
  const age = now() - cached.completedAt;
598
1040
  if (age < 0 || (ttl !== null && age >= ttl * 1000)) continue;
599
1041
  // Read applies the same eligibility as publish, so an entry an older
@@ -602,8 +1044,19 @@ export async function executeWithFreshnessReceipt<T>(input: {
602
1044
  ? await servedAnswer(cached)
603
1045
  : undefined;
604
1046
  if (served === null) continue;
605
- const own = await publish(operationKey, cached);
606
- return outcome(own, 'reusable_result', served);
1047
+ const hit: CompletedCall = { ...cached, ...fingerprints };
1048
+ if (!exactRequestOperationKey) {
1049
+ const own = await publish(operationKey, hit);
1050
+ return outcome(own, 'reusable_result', served);
1051
+ }
1052
+ // Both slots in one request: the exact-request slot for this build, the
1053
+ // call-order slot for older readers. A sibling may already hold the
1054
+ // call-order slot; the insert then keeps the sibling's.
1055
+ await publishFinishingWrites([
1056
+ { key: exactRequestOperationKey, output: hit },
1057
+ { key: operationKey, output: hit },
1058
+ ]);
1059
+ return outcome(hit, 'reusable_result', served);
607
1060
  }
608
1061
  }
609
1062
 
@@ -636,10 +1089,17 @@ export async function executeWithFreshnessReceipt<T>(input: {
636
1089
  throw new Error('Freshness call returned an invalid completion time.');
637
1090
  }
638
1091
  const completed = completedCallForResult(value, completedAt);
1092
+ const recorded: CompletedCall = { ...completed, ...fingerprints };
639
1093
 
640
1094
  // Recover this exact operation even if reusable publication fails afterwards.
1095
+ // A call-order artifact records both slots: its exact-request slot for this
1096
+ // and later builds, its call-order slot for older readers. A sibling may
1097
+ // already hold the call-order slot; the insert then keeps the sibling's.
641
1098
  const pointers: DeferredReceiptWrite[] = [
642
- { key: operationKey, output: completed },
1099
+ ...(exactRequestOperationKey
1100
+ ? [{ key: exactRequestOperationKey, output: recorded }]
1101
+ : []),
1102
+ { key: operationKey, output: recorded },
643
1103
  ];
644
1104
  // The same eligibility gates the policy bucket and the newest shared
645
1105
  // result: a failed, empty or non-final answer recovers within this run but
@@ -657,7 +1117,7 @@ export async function executeWithFreshnessReceipt<T>(input: {
657
1117
  ttl === null
658
1118
  ? `${cachePrefix}:reusable:indefinite`
659
1119
  : `${cachePrefix}:reusable:${ttl}:${completionPartition}`,
660
- output: completed,
1120
+ output: recorded,
661
1121
  });
662
1122
  }
663
1123
  // One request carries the call's result receipt, its replay pointer and its
@@ -245,3 +245,31 @@ export function withPlayLaunchIdentityDigest<
245
245
  launchIdentityDigest: buildPlayLaunchIdentityDigest(launch),
246
246
  };
247
247
  }
248
+
249
+ /**
250
+ * The launch identity a keyed rerun request controls: the owning org, the
251
+ * source run's pinned revision, and the exact input (the source run's
252
+ * retained input with the request's overrides applied). The run id already
253
+ * binds the source run, whose artifact and files are immutable.
254
+ *
255
+ * Read through `buildPlayLaunchIdentity`, the same normalizer the admission
256
+ * fence digests, so transport, authority and release details never count and
257
+ * an admitted launch from any build (it always stores `input`) is provable.
258
+ */
259
+ export const PLAY_RERUN_INTENT_IDENTITY_FIELDS = Object.freeze([
260
+ 'orgId',
261
+ 'revisionId',
262
+ 'inputDigest',
263
+ ] as const);
264
+
265
+ /** Rerun intent fields where an admitted launch differs from a request. */
266
+ export function playRerunIntentDifferences(
267
+ admitted: PlayLaunchIdentitySource,
268
+ requested: PlayLaunchIdentitySource,
269
+ ): string[] {
270
+ const stored = buildPlayLaunchIdentity(admitted);
271
+ const incoming = buildPlayLaunchIdentity(requested);
272
+ return PLAY_RERUN_INTENT_IDENTITY_FIELDS.filter(
273
+ (field) => stored[field] !== incoming[field],
274
+ );
275
+ }