deepline 0.3.534 → 0.3.536

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 (235) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +254 -147
  2. package/dist/bundling-sources/sdk/src/index.ts +4 -0
  3. package/dist/bundling-sources/sdk/src/plays/local-file-discovery.ts +27 -1
  4. package/dist/bundling-sources/sdk/src/plays/run-request.ts +16 -5
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/types.ts +2 -23
  7. package/dist/bundling-sources/shared_libs/integration-contracts/monitor-fleet-contract.ts +26 -14
  8. package/dist/bundling-sources/shared_libs/integration-contracts/monitor-input-contract.ts +33 -8
  9. package/dist/bundling-sources/shared_libs/monitors/fleets/count-drift-alert.ts +121 -0
  10. package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +8 -0
  11. package/dist/bundling-sources/shared_libs/monitors/fleets/plan.ts +14 -82
  12. package/dist/bundling-sources/shared_libs/monitors/package.json +1 -0
  13. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +4 -4
  14. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +0 -26
  15. package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +36 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +21 -31
  17. package/dist/bundling-sources/shared_libs/play-runtime/call-requeue-state-machine.ts +420 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +727 -102
  19. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +26 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/durable-retry-policy.ts +624 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +12 -10
  22. package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +3 -1
  23. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +71 -2
  24. package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +60 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +2 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +1 -0
  27. package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +372 -10
  28. package/dist/bundling-sources/shared_libs/play-runtime/memory-ledger.ts +15 -2
  29. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +21 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/prebuilt-result-quality.ts +1 -1
  31. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +6 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/fixture-capacity-simulator.ts +1 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/gradient2-concurrency-controller.ts +41 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-capacity-policy.ts +6 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-concurrency-policy.ts +9 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/provider-no-progress.ts +6 -2
  37. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +17 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +2 -2
  39. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +5 -2
  40. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +63 -3
  41. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +7 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-compute-usage.ts +31 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +6 -0
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +26 -1
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +11 -4
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +73 -18
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +169 -2
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +26 -4
  49. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +90 -49
  50. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +136 -30
  51. package/dist/bundling-sources/shared_libs/plays/launch/input-contract.ts +13 -1
  52. package/dist/bundling-sources/shared_libs/plays/local-file-discovery.ts +68 -1
  53. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +63 -13
  54. package/dist/bundling-sources/shared_libs/product-notifications/configuration-draft.ts +57 -1
  55. package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +22 -9
  56. package/dist/cli/auth-6XQKFOLG.js +43 -0
  57. package/dist/cli/{auth-MHQYIMVX.mjs → auth-KCTCUO7P.mjs} +7 -7
  58. package/dist/cli/{billing-YQLNP4S5.js → billing-4VBGZ3CT.js} +273 -112
  59. package/dist/cli/{billing-LX2PSBJ4.mjs → billing-OOJHKLNS.mjs} +185 -24
  60. package/dist/cli/{chunk-DGKTHWWH.js → chunk-2B4IOGFD.js} +406 -382
  61. package/dist/cli/{chunk-MQORQ7WL.js → chunk-2FCSUOYN.js} +55 -55
  62. package/dist/cli/{chunk-T2N3B7IQ.js → chunk-2GJZLIKW.js} +8 -8
  63. package/dist/cli/{chunk-6IFZPEJE.mjs → chunk-2YWJS76L.mjs} +1 -1
  64. package/dist/cli/{chunk-E7TP25I2.mjs → chunk-3PCYV6ZJ.mjs} +2 -2
  65. package/dist/cli/{chunk-LGRZCHKC.js → chunk-4E5JXZ3W.js} +18 -20
  66. package/dist/cli/{chunk-R4RG4FV5.mjs → chunk-4KWD3MX2.mjs} +13 -10
  67. package/dist/cli/{chunk-SUWTLXCV.js → chunk-6BBGUQJJ.js} +67 -146
  68. package/dist/cli/{chunk-JBBJDFUJ.js → chunk-6VUGBQZQ.js} +5 -5
  69. package/dist/cli/{chunk-2P3NVX65.mjs → chunk-AB2GBOD4.mjs} +40 -27
  70. package/dist/cli/{chunk-62SOZ67Y.mjs → chunk-ANUKBZ6W.mjs} +475 -11
  71. package/dist/cli/{chunk-MG6YL4M7.mjs → chunk-BASLYGXK.mjs} +101 -77
  72. package/dist/cli/{chunk-SQWET4SL.js → chunk-BBTKAASQ.js} +2 -1
  73. package/dist/cli/{chunk-NRO3NTVO.js → chunk-CBV7AKWM.js} +5 -5
  74. package/dist/cli/{chunk-RH3YRMUY.js → chunk-CIDN5K23.js} +1 -1
  75. package/dist/cli/{chunk-QNHHZ63P.mjs → chunk-CQBIO6HW.mjs} +1 -1
  76. package/dist/cli/{chunk-2KHUFWTK.js → chunk-CQDQNZGH.js} +42 -37
  77. package/dist/cli/{chunk-UWNVFAFN.js → chunk-CWSLUNA6.js} +33 -33
  78. package/dist/cli/{chunk-5FXMEEF4.mjs → chunk-CXTW7SRW.mjs} +67 -146
  79. package/dist/cli/{chunk-O53LHONF.mjs → chunk-DA2I2M7D.mjs} +2 -2
  80. package/dist/cli/{chunk-EYXUAJAU.mjs → chunk-DQHUJMCL.mjs} +5 -5
  81. package/dist/cli/{chunk-7GFR5Y4J.mjs → chunk-DUYAMLOC.mjs} +1 -1
  82. package/dist/cli/{chunk-OMVVHX4U.mjs → chunk-E24UGPGG.mjs} +13 -15
  83. package/dist/cli/{chunk-STR5LXK4.mjs → chunk-FSIVF2SI.mjs} +1 -1
  84. package/dist/cli/{chunk-KJVY7V2X.mjs → chunk-GF32SBST.mjs} +1 -1
  85. package/dist/cli/{chunk-AK622KIG.mjs → chunk-GHLDCLSC.mjs} +1 -1
  86. package/dist/cli/{chunk-A6HNT4EE.js → chunk-GTVZKY3F.js} +2 -2
  87. package/dist/cli/{chunk-BXIUZM5N.mjs → chunk-HAJQGP5V.mjs} +2 -2
  88. package/dist/cli/{chunk-6CEUQYMB.js → chunk-HWDKRN7L.js} +3 -3
  89. package/dist/cli/{chunk-5YAJGRWB.js → chunk-IPVRMYWT.js} +7 -7
  90. package/dist/cli/{chunk-ZPGGW27Q.mjs → chunk-JL2OTMSG.mjs} +1 -0
  91. package/dist/cli/{chunk-WR4WETRU.mjs → chunk-JUHDJNSI.mjs} +4 -4
  92. package/dist/cli/{chunk-TQH3533L.mjs → chunk-KPQHUVYW.mjs} +5 -5
  93. package/dist/cli/{chunk-V7SCRUFQ.js → chunk-KWYGWO4Y.js} +9 -6
  94. package/dist/cli/{chunk-DZS4JC7I.js → chunk-LDGZFDUB.js} +2 -2
  95. package/dist/cli/{chunk-EGTUOYYG.js → chunk-LN6RXDTB.js} +523 -59
  96. package/dist/cli/{chunk-DQ5ADV2J.mjs → chunk-LZXZQPA2.mjs} +4 -1
  97. package/dist/cli/{chunk-MYSKWJMA.js → chunk-MSP4DTSD.js} +13 -13
  98. package/dist/cli/{chunk-BNH4Y35W.mjs → chunk-OLH2PHMC.mjs} +2 -2
  99. package/dist/cli/{chunk-NNAE7E23.mjs → chunk-OUDTOMZC.mjs} +7 -9
  100. package/dist/cli/{chunk-GESIFFQX.mjs → chunk-OVX3Q5Q3.mjs} +1 -1
  101. package/dist/cli/{chunk-ENCA6O2D.mjs → chunk-PNY3BWHP.mjs} +2 -2
  102. package/dist/cli/{chunk-KSA2XE4T.js → chunk-Q4MNUOS4.js} +316 -303
  103. package/dist/cli/{chunk-GTXSUPCJ.js → chunk-Q5CXV3E3.js} +2 -2
  104. package/dist/cli/{chunk-VAG5YKP6.mjs → chunk-RVSSQPQO.mjs} +1 -1
  105. package/dist/cli/{chunk-VE7ZPLN2.js → chunk-SLPJ3LXI.js} +22 -22
  106. package/dist/cli/{chunk-IX45S5VC.js → chunk-TX5TUHJN.js} +17 -19
  107. package/dist/cli/{chunk-IF75RD6U.js → chunk-U2LVWCTD.js} +18 -6
  108. package/dist/cli/{chunk-ZS2WHWWL.js → chunk-UNDLNT3V.js} +1 -1
  109. package/dist/cli/{chunk-NDFNBJGL.js → chunk-VBDZIMWD.js} +26 -26
  110. package/dist/cli/{chunk-GVGQ6NZW.js → chunk-W7AEIGZR.js} +41 -41
  111. package/dist/cli/{chunk-WDNRPZED.mjs → chunk-WC5M3JXE.mjs} +2 -2
  112. package/dist/cli/{chunk-C374C22Y.js → chunk-WOQO3GV4.js} +14 -11
  113. package/dist/cli/{chunk-MQX363YF.js → chunk-XBAH3TKU.js} +5 -5
  114. package/dist/cli/{chunk-BDWZBMGV.mjs → chunk-XJD2GYUP.mjs} +5 -5
  115. package/dist/cli/{chunk-XRZJKHUA.mjs → chunk-XVZRJJDS.mjs} +4 -4
  116. package/dist/cli/{chunk-TVINIDHB.js → chunk-Y2NTPYGS.js} +17 -17
  117. package/dist/cli/{chunk-6GTGWZJG.mjs → chunk-YBMHOH6H.mjs} +4 -4
  118. package/dist/cli/{chunk-TG2UB3A5.mjs → chunk-YRLAUGQY.mjs} +3 -3
  119. package/dist/cli/{chunk-FKD3KL5Q.mjs → chunk-Z2XA6YU4.mjs} +10 -5
  120. package/dist/cli/{chunk-KXQCUX3X.mjs → chunk-Z7UIOGW4.mjs} +3 -3
  121. package/dist/cli/{chunk-HCD36BP6.js → chunk-ZEV2Y56V.js} +44 -44
  122. package/dist/cli/{chunk-MI6ZP7XI.mjs → chunk-ZG7BOECV.mjs} +18 -6
  123. package/dist/cli/{chunk-XBK6WCVA.js → chunk-ZILSRDIN.js} +8 -8
  124. package/dist/cli/{chunk-B2AS3R5W.js → chunk-ZISEH7OL.js} +16 -16
  125. package/dist/cli/{chunk-HPJAE6PP.js → chunk-ZZ4MF2GI.js} +6 -6
  126. package/dist/cli/command-docs.js +2 -2
  127. package/dist/cli/command-docs.mjs +1 -1
  128. package/dist/cli/{csv-U3M2G76R.js → csv-2V2DIFNG.js} +15 -15
  129. package/dist/cli/{csv-4ID4E5W3.mjs → csv-P3HLK4GO.mjs} +6 -6
  130. package/dist/cli/{db-IHAQIKEQ.js → db-MREAQVW6.js} +36 -36
  131. package/dist/cli/{db-LHX5BBCZ.mjs → db-ZYOY3QRQ.mjs} +9 -9
  132. package/dist/cli/describe-IKZFOADR.mjs +49 -0
  133. package/dist/cli/describe-WW3OQRLP.js +49 -0
  134. package/dist/cli/describe-core.d.mts +3 -3
  135. package/dist/cli/describe-core.d.ts +3 -3
  136. package/dist/cli/describe-core.js +5 -5
  137. package/dist/cli/describe-core.mjs +4 -4
  138. package/dist/cli/{executions-CJ5LV23G.js → executions-H5IJ7QSQ.js} +11 -11
  139. package/dist/cli/{executions-UJ6JZUL5.mjs → executions-KTSY5M34.mjs} +9 -9
  140. package/dist/cli/{feedback-TGUBVGRP.js → feedback-724QK3Z5.js} +16 -16
  141. package/dist/cli/{feedback-YGTPJBRJ.mjs → feedback-WWJRIXEU.mjs} +8 -8
  142. package/dist/cli/git-PHYRD56H.js +25 -0
  143. package/dist/cli/{git-3DOTQHJO.mjs → git-R5VRG7X6.mjs} +7 -7
  144. package/dist/cli/index.js +151 -157
  145. package/dist/cli/index.mjs +51 -57
  146. package/dist/cli/{legacy-noops-BHEHVFHI.js → legacy-noops-C6GDEGPU.js} +11 -11
  147. package/dist/cli/{legacy-noops-RBBYRVLG.mjs → legacy-noops-PWZ5XLAO.mjs} +8 -8
  148. package/dist/cli/{monitors-XECKLAXA.js → monitors-VAVQ4WCE.js} +125 -122
  149. package/dist/cli/{monitors-5AJCG6IV.mjs → monitors-WQSKMHAP.mjs} +19 -16
  150. package/dist/cli/{org-DOBAIYWG.js → org-CWWRWXZQ.js} +89 -89
  151. package/dist/cli/{org-ZAAIEZKB.mjs → org-MAL4QPVF.mjs} +9 -9
  152. package/dist/cli/{play-KLYRMQPF.mjs → play-ILW6MSNG.mjs} +174 -80
  153. package/dist/cli/{play-E74VN6B7.js → play-WJOWK5PQ.js} +690 -596
  154. package/dist/cli/{providers-XTQXV5LB.mjs → providers-4V2NMLZZ.mjs} +9 -9
  155. package/dist/cli/{providers-APZ6SOSK.js → providers-W662ANCH.js} +12 -12
  156. package/dist/cli/{quickstart-S6WN6NWW.js → quickstart-BW6EBUYX.js} +8 -8
  157. package/dist/cli/{quickstart-X7RHHQCH.mjs → quickstart-C22BR743.mjs} +6 -6
  158. package/dist/cli/{run-3YLIJJ57.js → run-KW7KW4FX.js} +50 -53
  159. package/dist/cli/{run-TZPBBSPX.mjs → run-SPAU5IMW.mjs} +31 -34
  160. package/dist/cli/search-HLE54W5G.js +32 -0
  161. package/dist/cli/{search-VLHE2CMZ.mjs → search-XPC75HLM.mjs} +10 -11
  162. package/dist/cli/{search-output-73BYB7UE.mjs → search-output-JKYJSEPM.mjs} +6 -6
  163. package/dist/cli/{search-output-GCT7PQIT.js → search-output-VJYE7USJ.js} +8 -8
  164. package/dist/cli/{secrets-RLOTGKQZ.mjs → secrets-OJG73GXQ.mjs} +9 -9
  165. package/dist/cli/{secrets-J6CEKXKQ.js → secrets-YB57KGSB.js} +18 -18
  166. package/dist/cli/{sessions-7HZ7OZ62.mjs → sessions-7ZL37BW4.mjs} +8 -8
  167. package/dist/cli/sessions-VEBYZIEU.js +22 -0
  168. package/dist/cli/{settings-WRV5XEZC.js → settings-A7DD2ZYE.js} +88 -89
  169. package/dist/cli/{settings-72K5YCIS.mjs → settings-RKSQB7FA.mjs} +15 -16
  170. package/dist/cli/{setup-KQFY6WT4.mjs → setup-NXDUTITY.mjs} +11 -12
  171. package/dist/cli/{setup-QVXWT2EQ.js → setup-S3K5YU62.js} +51 -52
  172. package/dist/cli/skills-NVQ744CN.js +36 -0
  173. package/dist/cli/{skills-C3K3E473.mjs → skills-VMFAIDO6.mjs} +9 -10
  174. package/dist/cli/{tools-4A2OH6MB.mjs → tools-52NTHBSJ.mjs} +20 -21
  175. package/dist/cli/tools-SBDUL3WB.js +56 -0
  176. package/dist/cli/update-HHVFZPCV.js +34 -0
  177. package/dist/cli/{update-BS6USKPR.mjs → update-SAKBEKMV.mjs} +11 -12
  178. package/dist/cli/{views-WB6GFTRX.mjs → views-ACRV7MD6.mjs} +54 -10
  179. package/dist/cli/{views-4NZGAXHL.js → views-C3GJOBDG.js} +66 -22
  180. package/dist/cli/{workflow-2D4WX55R.mjs → workflow-CS22E7TC.mjs} +10 -10
  181. package/dist/cli/{workflow-L2QTQZYV.js → workflow-ZNWCZEGN.js} +20 -20
  182. package/dist/{client-DoUVSkqC.d.mts → client-BlLYQDNo.d.mts} +1 -1
  183. package/dist/{client-DQm56zMs.d.ts → client-DSQlkIDO.d.ts} +1 -1
  184. package/dist/{client-core-C7KkUIE_.d.ts → client-core-CDwapXy5.d.ts} +167 -108
  185. package/dist/{client-core-CPlwsC1Q.d.mts → client-core-rX7n2H8U.d.mts} +167 -108
  186. package/dist/{compiler-manifest-DsxsQP-T.d.mts → compiler-manifest-BHNC4RL-.d.mts} +58 -21
  187. package/dist/{compiler-manifest-DsxsQP-T.d.ts → compiler-manifest-BHNC4RL-.d.ts} +58 -21
  188. package/dist/{errors-qdJUVQ3g.d.mts → errors-D7sPXrvB.d.mts} +1 -1
  189. package/dist/{errors-Bk5h1D-C.d.ts → errors-lhtIWG5Z.d.ts} +1 -1
  190. package/dist/{index-bL66eHYz.d.ts → index-CQTBHXHr.d.ts} +1 -1
  191. package/dist/{index-PaupwX1B.d.mts → index-NaDZq2xf.d.mts} +1 -1
  192. package/dist/index.d.mts +7 -7
  193. package/dist/index.d.ts +7 -7
  194. package/dist/index.js +15 -15
  195. package/dist/index.mjs +11 -11
  196. package/dist/install-integrity.json +131 -132
  197. package/dist/monitor-fleet-contract.d.mts +17 -11
  198. package/dist/monitor-fleet-contract.d.ts +17 -11
  199. package/dist/monitor-fleet-contract.js +3 -3
  200. package/dist/monitor-fleet-contract.mjs +2 -2
  201. package/dist/monitor-input-contract.js +2 -2
  202. package/dist/monitor-input-contract.mjs +1 -1
  203. package/dist/plays/bundle-play-file.d.mts +3 -3
  204. package/dist/plays/bundle-play-file.d.ts +3 -3
  205. package/dist/plays/bundle-play-file.mjs +67 -3
  206. package/dist/plays/csv-data-input.js +3 -3
  207. package/dist/plays/csv-data-input.mjs +2 -2
  208. package/dist/plays/play-description.d.mts +2 -2
  209. package/dist/plays/play-description.d.ts +2 -2
  210. package/dist/plays/run-request.d.mts +2 -2
  211. package/dist/plays/run-request.d.ts +2 -2
  212. package/dist/plays/run-request.js +3 -3
  213. package/dist/plays/run-request.mjs +2 -2
  214. package/dist/release.d.mts +1 -1
  215. package/dist/release.d.ts +1 -1
  216. package/dist/release.js +2 -2
  217. package/dist/release.mjs +1 -1
  218. package/dist/server.d.mts +4 -4
  219. package/dist/server.d.ts +4 -4
  220. package/dist/server.js +12 -12
  221. package/dist/server.mjs +6 -6
  222. package/package.json +1 -1
  223. package/dist/cli/auth-UP2RGPI6.js +0 -43
  224. package/dist/cli/chunk-5LZ5VSOK.mjs +0 -405
  225. package/dist/cli/chunk-D3J2Y2BP.js +0 -405
  226. package/dist/cli/describe-CI4MREFF.mjs +0 -50
  227. package/dist/cli/describe-IVTSD7ST.js +0 -50
  228. package/dist/cli/git-R3W25XIF.js +0 -25
  229. package/dist/cli/pages-FUOSF6BE.mjs +0 -266
  230. package/dist/cli/pages-TLC2N6L7.js +0 -266
  231. package/dist/cli/search-NB5CBALV.js +0 -33
  232. package/dist/cli/sessions-SFCZSB77.js +0 -22
  233. package/dist/cli/skills-WIJEHVLA.js +0 -37
  234. package/dist/cli/tools-VMMERMLO.js +0 -57
  235. package/dist/cli/update-54WZQDTS.js +0 -35
@@ -68,7 +68,7 @@ import type { CompiledRequestBatch } from './batch-runtime';
68
68
  import type { AnyBatchOperationStrategy } from './batching-types';
69
69
  import {
70
70
  getBillingEntitlementsViaAppRuntime,
71
- writePageViaAppRuntime,
71
+ listViewsViaAppRuntime,
72
72
  type RuntimeApiResponseMeta,
73
73
  } from './app-runtime-api';
74
74
  import {
@@ -262,6 +262,7 @@ import {
262
262
  TOOL_EXECUTE_PROVIDER_RATE_RETRY_SNAPSHOT_HEADER,
263
263
  TOOL_EXECUTE_PROVIDER_PERMIT_PATH_SUFFIX,
264
264
  TOOL_EXECUTE_PROVIDER_PERMIT_RECEIVER_HEADER,
265
+ isProviderPacingWaitResponse,
265
266
  isProviderPermitExecuteReceiverUnavailable,
266
267
  TOOL_EXECUTE_APP_PACING_REFUSAL_HEADER,
267
268
  TOOL_EXECUTE_APP_PACING_REFUSAL_VALUE,
@@ -275,6 +276,7 @@ import {
275
276
  ToolExecuteAuthScopeChangedError,
276
277
  toolExecuteBillingRetryIdentity,
277
278
  type ToolExecuteHttpFailureOutcome,
279
+ type ProviderServerErrorReplay,
278
280
  } from './tool-execute-retry-policy';
279
281
  import {
280
282
  createToolHttpError,
@@ -320,16 +322,17 @@ import {
320
322
  normalizePlayAuthoringCustomerDbStatement,
321
323
  validateOptionalPlayAuthoringField,
322
324
  validatePlayAuthoringField,
325
+ validatePlayToolCallRetryPolicy,
323
326
  type PlayAuthoringContractEdition,
327
+ type PlayToolCallRetryPolicy,
324
328
  type PlaySecretAuth,
325
329
  type PlaySecretAwareRequestInit,
326
330
  type PlaySecretPromise,
327
331
  type PlaySqlQuery,
328
332
  type PlayAuthoringRunScope,
329
- type PlayAuthoringPageWriteOptions,
330
- type PlayAuthoringPageWriteResult,
331
333
  type PlayAuthoringRuntimeContext,
332
334
  type PlayAuthoringRunStepsOptions,
335
+ hostedPagesRemovedMessage,
333
336
  } from '../plays/authoring-contract';
334
337
  import {
335
338
  resolvePlayArtifactRuntimeContract,
@@ -445,6 +448,7 @@ import {
445
448
  resolveRuntimeMapMemoryLimits,
446
449
  RuntimeMapMemoryLimitError,
447
450
  type RuntimeMapHeapAdmissionSnapshot,
451
+ type RuntimeMapTrackedRow,
448
452
  } from './map-memory-limits';
449
453
  import { RuntimeMapRowFeed } from './runtime-map-row-feed';
450
454
  import {
@@ -461,6 +465,7 @@ import type { RuntimeMapRowFeedSnapshot } from './runtime-map-row-feed';
461
465
  import { createRuntimeDispatchFlow, createRuntimeFlow } from './runtime-flow';
462
466
  import {
463
467
  createRuntimeMemoryLedger,
468
+ RUNTIME_MEMORY_LEDGER_OBJECT_PRIOR_FACTOR,
464
469
  type RuntimeMemoryLedger,
465
470
  type RuntimeMemoryLedgerHandle,
466
471
  } from './memory-ledger';
@@ -474,6 +479,16 @@ import {
474
479
  isPlayRowExecutionSuspendedError,
475
480
  type PlayExecutionSuspension,
476
481
  } from './suspension';
482
+ import type { DurableRetryErrorClass } from './durable-retry-policy';
483
+ import {
484
+ BILLING_ERROR_CLASSES,
485
+ callRequeueSends,
486
+ classifyDurableRetryErrorClass,
487
+ decideCallRequeue,
488
+ genericHttpWriteIdempotency,
489
+ transitionCallRequeue,
490
+ type CallRequeueRecord,
491
+ } from './call-requeue-state-machine';
477
492
  import {
478
493
  createRequestHeaderSecretRedactionContext,
479
494
  createSecretRedactionContext,
@@ -2153,7 +2168,95 @@ function settleToolBatchGroups(
2153
2168
  );
2154
2169
  }
2155
2170
 
2171
+ /**
2172
+ * The Durable retry class of one in-call HTTP failure, from structured fields
2173
+ * only (the outcome, its ToolExecutionError, and the failure body's `code`,
2174
+ * `upstream_status`, `error_category` and `network_kind`). null: the failure never retries
2175
+ * durably.
2176
+ */
2177
+ function durableRetryErrorClassForHttpFailure(input: {
2178
+ status: number;
2179
+ failure: ToolExecuteHttpFailureOutcome;
2180
+ responseText: string;
2181
+ }): DurableRetryErrorClass | null {
2182
+ let bodyCode: string | null = null;
2183
+ let bodyUpstreamStatus: number | null = null;
2184
+ let bodyCategory: string | null = null;
2185
+ let bodyNetworkKind: string | null = null;
2186
+ try {
2187
+ const body = JSON.parse(input.responseText) as unknown;
2188
+ if (body && typeof body === 'object' && !Array.isArray(body)) {
2189
+ const fields = body as Record<string, unknown>;
2190
+ bodyCode = typeof fields.code === 'string' ? fields.code : null;
2191
+ bodyUpstreamStatus =
2192
+ typeof fields.upstream_status === 'number'
2193
+ ? fields.upstream_status
2194
+ : null;
2195
+ bodyCategory =
2196
+ typeof fields.error_category === 'string'
2197
+ ? fields.error_category
2198
+ : null;
2199
+ bodyNetworkKind =
2200
+ typeof fields.network_kind === 'string' ? fields.network_kind : null;
2201
+ }
2202
+ } catch {
2203
+ bodyCode = null;
2204
+ }
2205
+ const { failure } = input;
2206
+ return classifyDurableRetryErrorClass({
2207
+ status: input.status,
2208
+ reason: failure.reason,
2209
+ knownNotDispatched: failure.knownNotDispatched,
2210
+ origin:
2211
+ failure.error instanceof ToolExecutionError ? failure.error.origin : null,
2212
+ code:
2213
+ failure.error instanceof ToolExecutionError && failure.error.code
2214
+ ? failure.error.code
2215
+ : bodyCode,
2216
+ upstreamStatus: bodyUpstreamStatus,
2217
+ category: bodyCategory,
2218
+ networkKind: bodyNetworkKind,
2219
+ });
2220
+ }
2221
+
2222
+ /**
2223
+ * A call's own `retry` governs its in-call resends too, like an activity
2224
+ * RetryPolicy counts every attempt. A class it lists as `nonRetryable`, or
2225
+ * `maximumAttempts: 1` for a request the provider received, is not resent and
2226
+ * not paced inside the call: the error reaches the Play after this attempt.
2227
+ * Deepline's own pre-dispatch refusals are not attempts and keep pacing.
2228
+ */
2229
+ export function callRetryStopsInCallRetry(input: {
2230
+ callRetry: PlayToolCallRetryPolicy | undefined;
2231
+ errorClass: DurableRetryErrorClass | null;
2232
+ preDispatchRefusal: boolean;
2233
+ /**
2234
+ * Requests the provider received for this call so far, this one included:
2235
+ * earlier bursts (the requeue record) plus this burst.
2236
+ */
2237
+ sends: number;
2238
+ }): boolean {
2239
+ const { callRetry, errorClass } = input;
2240
+ if (!callRetry) return false;
2241
+ if (errorClass !== null && callRetry.nonRetryable?.includes(errorClass)) {
2242
+ return true;
2243
+ }
2244
+ // Like an activity retry policy, the limit bounds every attempt, whatever
2245
+ // the failure's class.
2246
+ return (
2247
+ callRetry.maximumAttempts !== undefined &&
2248
+ !input.preDispatchRefusal &&
2249
+ input.sends >= callRetry.maximumAttempts
2250
+ );
2251
+ }
2252
+
2156
2253
  type ToolExecutionApiOptions = {
2254
+ /**
2255
+ * The call's own retry policy (`ctx.tools.execute({ retry })`). It governs
2256
+ * the in-call resends and the durable retries; a call that sets it never
2257
+ * joins a native provider batch.
2258
+ */
2259
+ retry?: PlayToolCallRetryPolicy;
2157
2260
  /**
2158
2261
  * The call's replay-stable identity in the run, for an async provider wait
2159
2262
  * that has no other durable identity. A retried attempt sends the same
@@ -2952,7 +3055,7 @@ type ScalarPlayAuthoringRuntimeContext = Pick<
2952
3055
  | 'tools'
2953
3056
  | 'customerDb'
2954
3057
  | 'billing'
2955
- | 'pages'
3058
+ | 'views'
2956
3059
  | 'run'
2957
3060
  | 'tool'
2958
3061
  | 'step'
@@ -2963,36 +3066,6 @@ type ScalarPlayAuthoringRuntimeContext = Pick<
2963
3066
  | 'sleep'
2964
3067
  >;
2965
3068
 
2966
- /** Text stays text on the wire, so only real binary pays the base64 overhead. */
2967
- function encodePageContent(
2968
- name: string,
2969
- options: PlayAuthoringPageWriteOptions,
2970
- ): { contentType: string } & (
2971
- | { contentText: string }
2972
- | { contentBase64: string }
2973
- ) {
2974
- const { content, contentType } = options;
2975
- if (typeof content === 'string') {
2976
- return {
2977
- contentType: contentType ?? 'text/plain; charset=utf-8',
2978
- contentText: content,
2979
- };
2980
- }
2981
- if (content instanceof Uint8Array || content instanceof ArrayBuffer) {
2982
- return {
2983
- contentType: contentType ?? 'application/octet-stream',
2984
- contentBase64: Buffer.from(content as Uint8Array).toString('base64'),
2985
- };
2986
- }
2987
- const contentText = JSON.stringify(content);
2988
- if (contentText === undefined) {
2989
- throw new Error(
2990
- `ctx.pages.write("${name}") requires content: a string, bytes, or a JSON value.`,
2991
- );
2992
- }
2993
- return { contentType: contentType ?? 'application/json', contentText };
2994
- }
2995
-
2996
3069
  export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
2997
3070
  private rowStates = new Map<number, RowState>();
2998
3071
  private toolCallQueue: ToolCallRequest[] = [];
@@ -3350,6 +3423,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3350
3423
  staleAfterSeconds?: number | null;
3351
3424
  timeoutMs?: number;
3352
3425
  receiptWaitMs?: number;
3426
+ retry?: PlayToolCallRetryPolicy;
3353
3427
  }): Promise<TOutput> => {
3354
3428
  this.assertNoPendingDurableSuspension();
3355
3429
  if (!request || typeof request !== 'object' || Array.isArray(request)) {
@@ -3388,6 +3462,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3388
3462
  request.receiptWaitMs,
3389
3463
  );
3390
3464
  }
3465
+ // The call's own retry policy replaces the class rule where it sets a
3466
+ // field; without it, the live Durable retry policy decides.
3467
+ const retry = request.retry;
3468
+ if (retry !== undefined) validatePlayToolCallRetryPolicy(retry);
3391
3469
  const force =
3392
3470
  request.force === true ||
3393
3471
  toolExecutionOverrides.getStore()?.force === true;
@@ -3399,7 +3477,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3399
3477
  force ||
3400
3478
  request.staleAfterSeconds !== undefined ||
3401
3479
  request.timeoutMs !== undefined ||
3402
- request.receiptWaitMs !== undefined
3480
+ request.receiptWaitMs !== undefined ||
3481
+ retry !== undefined
3403
3482
  ? {
3404
3483
  ...(request.description
3405
3484
  ? { description: request.description }
@@ -3414,6 +3493,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3414
3493
  ...(request.receiptWaitMs !== undefined
3415
3494
  ? { receiptWaitMs: request.receiptWaitMs }
3416
3495
  : {}),
3496
+ ...(retry !== undefined ? { retry } : {}),
3417
3497
  }
3418
3498
  : undefined,
3419
3499
  ).catch((error: unknown) => {
@@ -3646,37 +3726,26 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3646
3726
  },
3647
3727
  };
3648
3728
 
3649
- readonly pages = {
3650
- write: async (
3651
- name: string,
3652
- options: PlayAuthoringPageWriteOptions,
3653
- ): Promise<PlayAuthoringPageWriteResult> => {
3729
+ readonly views = {
3730
+ list: () => {
3654
3731
  this.assertNoPendingDurableSuspension();
3655
- if (typeof name !== 'string' || !name) {
3656
- throw new Error('ctx.pages.write(name, options) requires a page name.');
3657
- }
3658
- if (typeof options?.public !== 'boolean') {
3659
- throw new Error(
3660
- `ctx.pages.write("${name}") requires public: true or false, so the write always says who can see the page.`,
3661
- );
3662
- }
3663
- const result = await writePageViaAppRuntime(
3664
- {
3665
- baseUrl: this.#options.baseUrl ?? '',
3666
- executorToken: this.#options.executorToken ?? '',
3667
- vercelProtectionBypassToken:
3668
- this.#options.vercelProtectionBypassToken,
3669
- signal: this.#options.executionSignal,
3670
- },
3671
- {
3672
- name,
3673
- public: options.public,
3674
- description: options.description,
3675
- ...encodePageContent(name, options),
3676
- },
3677
- );
3678
- for (const warning of result.warnings) this.log(warning);
3679
- return result;
3732
+ return listViewsViaAppRuntime({
3733
+ baseUrl: this.#options.baseUrl ?? '',
3734
+ executorToken: this.#options.executorToken ?? '',
3735
+ vercelProtectionBypassToken: this.#options.vercelProtectionBypassToken,
3736
+ signal: this.#options.executionSignal,
3737
+ });
3738
+ },
3739
+ };
3740
+
3741
+ /**
3742
+ * Hosted pages were removed. Plays bundled before the removal still call
3743
+ * this, so it fails with a message the author can act on instead of a
3744
+ * TypeError on an undefined property.
3745
+ */
3746
+ readonly pages = {
3747
+ write: async (name: unknown): Promise<never> => {
3748
+ throw new Error(hostedPagesRemovedMessage(name));
3680
3749
  },
3681
3750
  };
3682
3751
 
@@ -4830,7 +4899,19 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4830
4899
  bytes: 0,
4831
4900
  });
4832
4901
  }
4833
- this.activeMapCheckpointMemory?.update(this.activeMapCheckpointBytes);
4902
+ this.updateActiveMapCheckpointMemory();
4903
+ }
4904
+
4905
+ /**
4906
+ * `materializedRows` registers resident bytes and opens at a factor of 1.
4907
+ * Checkpoint patches are measured as JSON length, so they register that
4908
+ * length at the object prior: the charge the category's old prior of 3 gave
4909
+ * them, rather than a third of it.
4910
+ */
4911
+ private updateActiveMapCheckpointMemory(): void {
4912
+ this.activeMapCheckpointMemory?.update(
4913
+ this.activeMapCheckpointBytes * RUNTIME_MEMORY_LEDGER_OBJECT_PRIOR_FACTOR,
4914
+ );
4834
4915
  }
4835
4916
 
4836
4917
  private releaseActiveMapCheckpointBytes(checkpointKey: string): void {
@@ -4845,7 +4926,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4845
4926
  0,
4846
4927
  this.activeMapCheckpointBytes - releasedBytes,
4847
4928
  );
4848
- this.activeMapCheckpointMemory?.update(this.activeMapCheckpointBytes);
4929
+ this.updateActiveMapCheckpointMemory();
4849
4930
  }
4850
4931
 
4851
4932
  private emitExecutionEvent(event: PlayExecutionEvent): void {
@@ -12030,6 +12111,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12030
12111
  mapName: normalizedTableNamespace,
12031
12112
  budgetBytes: runtimeOptions?.retainedRowsMemoryBudgetBytes,
12032
12113
  });
12114
+ // What each retained row was charged, so a row the map stops retaining
12115
+ // gives its charge back.
12116
+ const retainedRowCharges = new WeakMap<
12117
+ PersistableMapRow,
12118
+ RuntimeMapTrackedRow
12119
+ >();
12033
12120
  // The Runtime Sheet is already the authoritative result store for these
12034
12121
  // maps. Once live RSS says response bodies are constraining row admission,
12035
12122
  // retain only rows whose terminal write has not committed yet. This keeps
@@ -12049,6 +12136,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12049
12136
  for (const row of rows) {
12050
12137
  if (incrementalPersistence.isPersisted(row)) {
12051
12138
  released += 1;
12139
+ const charge = retainedRowCharges.get(row);
12140
+ if (charge) {
12141
+ retainedRowsMemoryTracker.release(charge);
12142
+ retainedRowCharges.delete(row);
12143
+ }
12052
12144
  continue;
12053
12145
  }
12054
12146
  rows[retained] = row;
@@ -12058,6 +12150,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12058
12150
  }
12059
12151
  if (released > 0) {
12060
12152
  retainedRowsComplete = false;
12153
+ // The ledger now reads only the rows still retained. Left at the
12154
+ // charge it carried when the rows went, occupancy stayed at the heap
12155
+ // target with the rows gone and kept re-arming the hold: a 600-row
12156
+ // map crossing a 64 MiB target took 17 pressure episodes and 55
12157
+ // holds, against one of each with the charge given back.
12158
+ trackMaterializedRowBytes();
12061
12159
  this.runtimeLog(
12062
12160
  `Dataset ${normalizedTableNamespace} released ${released} durably persisted row(s) under live memory pressure; using the Runtime Sheet.`,
12063
12161
  );
@@ -12065,10 +12163,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12065
12163
  };
12066
12164
  // The retained-result cache is the map's other resident budget. The
12067
12165
  // tracker already measures every row it admits, so the ledger reads that
12068
- // estimate rather than serializing the same rows a second time. It is an
12069
- // upper bound: the tracker is cumulative, so a partial release under
12070
- // pressure is not subtracted from it — and a memory ledger that overstates
12071
- // holds admission early, which is the safe direction to be wrong in.
12166
+ // estimate rather than serializing the same rows a second time: an upper
12167
+ // bound on what the rows still retained hold, which falls as rows are
12168
+ // released under pressure.
12072
12169
  // This mutable holder crosses asynchronous row workers. Keeping the
12073
12170
  // handle in an object also makes that ownership visible to TypeScript's
12074
12171
  // control-flow analysis; assignments inside the tracker closure are real
@@ -12091,7 +12188,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12091
12188
  ): void => {
12092
12189
  if (!retainedRowsComplete) return;
12093
12190
  try {
12094
- retainedRowsMemoryTracker.track(row);
12191
+ retainedRowCharges.set(row, retainedRowsMemoryTracker.track(row));
12095
12192
  target.push(row);
12096
12193
  trackMaterializedRowBytes();
12097
12194
  } catch (error) {
@@ -12289,6 +12386,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
12289
12386
  ? { heapProbe: this.#options.runtimeMapHeapProbe }
12290
12387
  : {}),
12291
12388
  getEventLoopLagMs: () => this.resourceGovernor.eventLoopLagEwmaMs(),
12389
+ callSlotBacklog: () =>
12390
+ this.resourceGovernor.externalExecutionBacklog?.() ?? null,
12292
12391
  onMemoryPressure: releaseCommittedRowsForMemoryPressure,
12293
12392
  // Provider bodies enter through `providerResponseBodyGate` below, which
12294
12393
  // reserves them at materialization and holds the measurement through the
@@ -13932,14 +14031,24 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
13932
14031
  }
13933
14032
  }
13934
14033
 
14034
+ /**
14035
+ * A call that sets its own `retry` never joins a native provider batch: it
14036
+ * runs as its own request so its retry policy, not the batch's, applies.
14037
+ */
14038
+ private batchOperationStrategyFor(
14039
+ request: Pick<ToolCallRequest, 'toolId' | 'retry'>,
14040
+ ): AnyBatchOperationStrategy | null {
14041
+ if (request.retry !== undefined) return null;
14042
+ return this.#options.getBatchOperationStrategy?.(request.toolId) ?? null;
14043
+ }
14044
+
13935
14045
  private toolDispatchLane(request: ToolCallRequest): {
13936
14046
  key: string;
13937
14047
  readyCount: number;
13938
14048
  maxGroupSize: number;
13939
14049
  coalesceWindowMs: number;
13940
14050
  } {
13941
- const strategy =
13942
- this.#options.getBatchOperationStrategy?.(request.toolId) ?? null;
14051
+ const strategy = this.batchOperationStrategyFor(request);
13943
14052
  if (strategy) {
13944
14053
  return {
13945
14054
  key: [
@@ -14188,8 +14297,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14188
14297
  this.mappedResolverHostTurn &&
14189
14298
  requests.some(
14190
14299
  (request) =>
14191
- (this.#options.getBatchOperationStrategy?.(request.toolId)
14192
- ?.maxBatchSize ?? 1) > 1,
14300
+ (this.batchOperationStrategyFor(request)?.maxBatchSize ?? 1) > 1,
14193
14301
  )
14194
14302
  ) {
14195
14303
  return {
@@ -14427,9 +14535,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
14427
14535
  const admissionObserver: ToolBatchAdmissionObserver = {
14428
14536
  pending: (requests) => {
14429
14537
  for (const request of requests) {
14430
- const strategy = this.#options.getBatchOperationStrategy?.(
14431
- request.toolId,
14432
- );
14538
+ const strategy = this.batchOperationStrategyFor(request);
14433
14539
  // A scalar-only strategy has no arrivals to aggregate. Holding its
14434
14540
  // lane would serialize receipt I/O before provider admission.
14435
14541
  if (!strategy || strategy.maxBatchSize <= 1) continue;
@@ -15930,6 +16036,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
15930
16036
  startedAt: directCallStartedAt,
15931
16037
  input,
15932
16038
  options: {
16039
+ ...(options?.retry ? { retry: options.retry } : {}),
15933
16040
  ...(useDirectResultReceipts
15934
16041
  ? {
15935
16042
  durableCallReceiptKey: physicalDirectKey,
@@ -16280,6 +16387,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
16280
16387
  ...(options?.receiptWaitMs !== undefined
16281
16388
  ? { receiptWaitMs: options.receiptWaitMs }
16282
16389
  : {}),
16390
+ ...(options?.retry ? { retry: options.retry } : {}),
16283
16391
  tableNamespace: store.tableNamespace,
16284
16392
  rowKey: store.rowKey ?? null,
16285
16393
  description: normalizeStepDescription(options?.description),
@@ -17373,6 +17481,239 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
17373
17481
  });
17374
17482
  }
17375
17483
 
17484
+ /**
17485
+ * A call's in-call retries are spent. Park it per the Durable retry policy
17486
+ * snapshot this attempt read (a mapped row waits on its own; a call outside
17487
+ * a map suspends the run on a durable sleep), or return so the caller
17488
+ * throws the original error into the Play. Never returns after a park.
17489
+ */
17490
+ /** Durable retry policy snapshots whose warnings this attempt already logged. */
17491
+ private readonly loggedDurableRetryPolicyWarnings = new Set<string>();
17492
+
17493
+ private async parkExhaustedCallOrFail(input: {
17494
+ toolId: string;
17495
+ provider: string;
17496
+ callRequeueKey: string;
17497
+ status: number;
17498
+ /**
17499
+ * The failure to classify, or the class it already has (a provider hold
17500
+ * whose no-progress limit is spent is `rate_limit_429`).
17501
+ */
17502
+ failure:
17503
+ | ToolExecuteHttpFailureOutcome
17504
+ | { errorClass: DurableRetryErrorClass };
17505
+ responseText: string;
17506
+ /** Absent: an unclassified action. */
17507
+ providerServerErrorReplay: ProviderServerErrorReplay | undefined;
17508
+ rowScoped: boolean;
17509
+ /** The call's input, for a per-request write class (generic HTTP). */
17510
+ toolInput: Record<string, unknown>;
17511
+ /** The invocation attempt that just failed. */
17512
+ invocationAttempt: number;
17513
+ /** The call runs under the gateway's durable execution fence. */
17514
+ fenced: boolean;
17515
+ /** The call's own retry policy (`ctx.tools.execute({ retry })`). */
17516
+ callRetry?: PlayToolCallRetryPolicy;
17517
+ /** Requests the provider received in the burst that just failed. */
17518
+ sendsThisBurst: number;
17519
+ writeRecord: (record: CallRequeueRecord | null) => void;
17520
+ }): Promise<void> {
17521
+ const { failure } = input;
17522
+ const prior = this.checkpoint.callRequeueStates?.[input.callRequeueKey];
17523
+ // Every way out without a park ends a resumed call's record, so a later
17524
+ // failure of the same key never inherits stale counts.
17525
+ const exhaustPrior = () => {
17526
+ if (prior?.state === 'in_call') {
17527
+ input.writeRecord(transitionCallRequeue(prior, 'exhaust', Date.now()));
17528
+ }
17529
+ };
17530
+ const errorClass =
17531
+ 'errorClass' in failure
17532
+ ? failure.errorClass
17533
+ : durableRetryErrorClassForHttpFailure({
17534
+ status: input.status,
17535
+ failure,
17536
+ responseText: input.responseText,
17537
+ });
17538
+ if (!errorClass) {
17539
+ exhaustPrior();
17540
+ return;
17541
+ }
17542
+ // A billing refusal inside a map keeps its run-fatal behaviour: parking
17543
+ // each row would hold one record and one billing retry per row. A billing
17544
+ // hold outside a map parks the run once.
17545
+ if (input.rowScoped && BILLING_ERROR_CLASSES.has(errorClass)) {
17546
+ exhaustPrior();
17547
+ return;
17548
+ }
17549
+ // A fenced call's billing refusal is a recorded non-retryable outcome the
17550
+ // gateway would refuse to follow after the wait: keep it run-fatal.
17551
+ if (input.fenced && BILLING_ERROR_CLASSES.has(errorClass)) {
17552
+ exhaustPrior();
17553
+ return;
17554
+ }
17555
+ let retryContext: NonNullable<
17556
+ Awaited<
17557
+ ReturnType<NonNullable<ContextOptions['getToolDurableRetryContext']>>
17558
+ >
17559
+ >;
17560
+ try {
17561
+ const resolved = await this.#options.getToolDurableRetryContext!(
17562
+ input.toolId,
17563
+ );
17564
+ if (!resolved) {
17565
+ exhaustPrior();
17566
+ return;
17567
+ }
17568
+ retryContext = resolved;
17569
+ } catch (contextError) {
17570
+ this.runtimeLog(
17571
+ `[runtime.call_requeue.unavailable] ${JSON.stringify({
17572
+ tool_id: input.toolId,
17573
+ error_class: errorClass,
17574
+ error:
17575
+ contextError instanceof Error
17576
+ ? contextError.message
17577
+ : String(contextError),
17578
+ })}`,
17579
+ { level: 'error' },
17580
+ );
17581
+ exhaustPrior();
17582
+ return;
17583
+ }
17584
+ const policyLogKey = `${retryContext.policy.source}:${retryContext.policy.sequence}`;
17585
+ if (
17586
+ retryContext.policy.warnings.length > 0 &&
17587
+ !this.loggedDurableRetryPolicyWarnings.has(policyLogKey)
17588
+ ) {
17589
+ // Once per attempt per policy snapshot, not per exhausted call.
17590
+ this.loggedDurableRetryPolicyWarnings.add(policyLogKey);
17591
+ this.runtimeLog(
17592
+ `[runtime.call_requeue.policy] ${JSON.stringify({
17593
+ source: retryContext.policy.source,
17594
+ policy_sequence: retryContext.policy.sequence,
17595
+ warnings: retryContext.policy.warnings,
17596
+ })}`,
17597
+ {
17598
+ level:
17599
+ retryContext.policy.source === 'compiled_default'
17600
+ ? 'error'
17601
+ : 'warn',
17602
+ },
17603
+ );
17604
+ }
17605
+ const nowMs = Date.now();
17606
+ const decision = decideCallRequeue({
17607
+ record: prior,
17608
+ errorClass,
17609
+ snapshot: retryContext.policy,
17610
+ failedInvocationAttempt: input.invocationAttempt,
17611
+ fenced: input.fenced,
17612
+ effect: retryContext.effect,
17613
+ writeIdempotency:
17614
+ input.toolId === 'generic_http_request'
17615
+ ? genericHttpWriteIdempotency(input.toolInput.method)
17616
+ : retryContext.writeIdempotency,
17617
+ idempotencyKeyHonored:
17618
+ input.providerServerErrorReplay === 'idempotent_key',
17619
+ ...(input.callRetry ? { callRetry: input.callRetry } : {}),
17620
+ sends: callRequeueSends(prior) + input.sendsThisBurst,
17621
+ nowMs,
17622
+ });
17623
+ if (decision.kind === 'exhaust') {
17624
+ // Only a call this attempt is retrying can end here; a record parked by
17625
+ // a concurrent same-key call is left to that call.
17626
+ exhaustPrior();
17627
+ this.runtimeLog(
17628
+ `[runtime.call_requeue.exhausted] ${JSON.stringify({
17629
+ tool_id: input.toolId,
17630
+ error_class: errorClass,
17631
+ reason: decision.reason,
17632
+ parks: prior?.parks ?? 0,
17633
+ policy_sequence: retryContext.policy.sequence,
17634
+ })}`,
17635
+ { level: 'warn' },
17636
+ );
17637
+ return;
17638
+ }
17639
+ input.writeRecord(decision.record);
17640
+ const cause = BILLING_ERROR_CLASSES.has(errorClass)
17641
+ ? 'waiting for billing'
17642
+ : errorClass === 'rate_limit_429'
17643
+ ? `rate limited by ${input.provider}`
17644
+ : `${input.provider} unavailable`;
17645
+ this.runtimeLog(
17646
+ `[runtime.call_requeue.parked] ${cause}, retrying at ${new Date(decision.retryAtMs).toISOString()} ${JSON.stringify(
17647
+ {
17648
+ tool_id: input.toolId,
17649
+ error_class: errorClass,
17650
+ transition: decision.transition,
17651
+ parks: decision.record.parks,
17652
+ consecutive: decision.record.consecutive,
17653
+ wait_ms: decision.waitMs,
17654
+ policy_sequence: retryContext.policy.sequence,
17655
+ policy_source: retryContext.policy.source,
17656
+ },
17657
+ )}`,
17658
+ { level: 'warn' },
17659
+ );
17660
+ if (input.rowScoped) {
17661
+ throw new PlayRowProviderBackpressureError(
17662
+ input.provider,
17663
+ decision.retryAtMs,
17664
+ false,
17665
+ );
17666
+ }
17667
+ await this.waitForCallRequeue(input.callRequeueKey, decision.retryAtMs);
17668
+ throw new Error(
17669
+ `Call requeue for ${input.toolId} resumed without suspending the run.`,
17670
+ );
17671
+ }
17672
+
17673
+ /** A run-level durable sleep for one parked call; resumes after `retryAtMs`. */
17674
+ private async waitForCallRequeue(
17675
+ callRequeueKey: string,
17676
+ retryAtMs: number,
17677
+ ): Promise<void> {
17678
+ this.assertNoPendingDurableSuspension();
17679
+ const prefix = this.durableBoundaryId(
17680
+ `call-requeue-${callRequeueKey.slice(0, 16)}-`,
17681
+ );
17682
+ let completedWaits = 0;
17683
+ for (const [boundaryId, value] of Object.entries(
17684
+ this.checkpoint.resolvedBoundaries ?? {},
17685
+ )) {
17686
+ if (!boundaryId.startsWith(prefix)) continue;
17687
+ const boundary = assertKnownResolvedBoundary(boundaryId, value);
17688
+ if (boundary?.kind === 'sleep' && boundary.completedAt !== undefined) {
17689
+ completedWaits += 1;
17690
+ }
17691
+ }
17692
+ const boundaryId = `${prefix}${completedWaits}`;
17693
+ const existing = assertKnownResolvedBoundary(
17694
+ boundaryId,
17695
+ this.checkpoint.resolvedBoundaries?.[boundaryId],
17696
+ );
17697
+ const delayMs =
17698
+ existing?.kind === 'sleep'
17699
+ ? existing.delayMs
17700
+ : Math.max(1_000, Math.ceil(retryAtMs - Date.now()));
17701
+ const wakeAtMs =
17702
+ existing?.kind === 'sleep' && existing.wakeAtMs !== undefined
17703
+ ? existing.wakeAtMs
17704
+ : Date.now() + delayMs;
17705
+ this.checkpoint.resolvedBoundaries = {
17706
+ ...(this.checkpoint.resolvedBoundaries ?? {}),
17707
+ [boundaryId]: { ...existing, kind: 'sleep', delayMs, wakeAtMs },
17708
+ };
17709
+ await this.suspendForEarliestSleep({
17710
+ kind: 'sleep',
17711
+ boundaryId,
17712
+ delayMs,
17713
+ wakeAtMs,
17714
+ });
17715
+ }
17716
+
17376
17717
  private async waitForProviderBackpressure(
17377
17718
  provider: string,
17378
17719
  retryAtMs: number,
@@ -19088,6 +19429,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
19088
19429
  providerOperationKey,
19089
19430
  resultReceipts: receipts,
19090
19431
  apiOptions: {
19432
+ ...(request.retry ? { retry: request.retry } : {}),
19091
19433
  playNodeScope: playNodeScopeForToolCallRequest(request),
19092
19434
  durableCallReceiptKey: this.toolTransportReceiptKey({
19093
19435
  toolId,
@@ -19814,6 +20156,8 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
19814
20156
  const key = JSON.stringify([
19815
20157
  req.toolId,
19816
20158
  req.executionAuthScopeDigest ?? '',
20159
+ // Calls with their own `retry` dispatch apart from the native batch.
20160
+ req.retry !== undefined,
19817
20161
  ]);
19818
20162
  if (!byTool.has(key)) byTool.set(key, []);
19819
20163
  byTool.get(key)!.push(req);
@@ -19929,8 +20273,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
19929
20273
  };
19930
20274
  // The cohort reads completed results and publishes successful misses.
19931
20275
  // Always-fresh calls have no durable member result and stay below.
19932
- const operationStrategy =
19933
- this.#options.getBatchOperationStrategy?.(toolId) ?? null;
20276
+ const operationStrategy = this.batchOperationStrategyFor(requests[0]!);
19934
20277
  if (this.durableMappedToolResultsBackedByReceipts) {
19935
20278
  const cohortRequests = pendingRequests.filter(
19936
20279
  (request) =>
@@ -20240,6 +20583,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20240
20583
  resultReceiptKey: request.receiptKey ?? request.cacheKey,
20241
20584
  providerOperationKey,
20242
20585
  apiOptions: {
20586
+ ...(request.retry ? { retry: request.retry } : {}),
20243
20587
  playNodeScope: playNodeScopeForToolCallRequest(request),
20244
20588
  executionAuthScopeDigest:
20245
20589
  request.executionAuthScopeDigest,
@@ -20896,10 +21240,14 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20896
21240
  const providerAdmissionNoProgressScope = stableDigest(
20897
21241
  `admission\u0000${providerNoProgressScope}`,
20898
21242
  );
21243
+ // The provider no-progress limit. With durable call retries it is the
21244
+ // Durable retry policy's `rate_limit_429.inCall.noProgressMs` (read below,
21245
+ // once the call's policy context is known); the default is unchanged.
21246
+ let providerNoProgressMaxMs = PROVIDER_NO_PROGRESS_MAX_MS;
20899
21247
  const providerNoProgressError = (retryAtMs: number) =>
20900
21248
  createToolHttpError(
20901
21249
  toolErrorSchemaVersion,
20902
- `Provider ${provider} made no progress within ${PROVIDER_NO_PROGRESS_MAX_MS / 60_000} minutes. Completed work was saved; retry the failed work after the provider recovers.`,
21250
+ `Provider ${provider} made no progress within ${Math.round(providerNoProgressMaxMs / 60_000)} minutes. Completed work was saved; retry the failed work after the provider recovers.`,
20903
21251
  null,
20904
21252
  429,
20905
21253
  'repairable',
@@ -20953,6 +21301,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
20953
21301
  scope: providerNoProgressScope,
20954
21302
  retryAtMs: noProgressRetryAtMs,
20955
21303
  nowMs: Date.now(),
21304
+ maxMs: providerNoProgressMaxMs,
20956
21305
  });
20957
21306
  if (!outcome.exhausted) return;
20958
21307
  this.runtimeLog(
@@ -21025,6 +21374,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21025
21374
  async (span) => {
21026
21375
  const httpFailureAttempts =
21027
21376
  createToolExecuteHttpFailureAttemptTracker();
21377
+ // Requests the provider received in this burst; a refusal before
21378
+ // dispatch is not one. With the requeue record's count it is what a
21379
+ // call's `retry.maximumAttempts` bounds.
21380
+ let providerSendsThisBurst = 0;
21028
21381
  // Snapshot the caller-controlled payload exactly once. The replay
21029
21382
  // decision and every physical attempt must refer to the same bytes,
21030
21383
  // even if the original object has getters or is later mutated.
@@ -21050,8 +21403,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21050
21403
  .catch(() => null);
21051
21404
  const retrySafeTransientHttp =
21052
21405
  retryPolicy?.retrySafeTransientHttp === true;
21053
- const providerServerErrorReplay =
21054
- retryPolicy?.providerServerErrorReplay ?? 'never';
21406
+ // Owner rule (2026-11-16): a provider 5xx retries unless the action
21407
+ // declares `never`; absent is an unclassified action and retries.
21408
+ // A policy that could not be read is not known to allow it, so it
21409
+ // stays `never`.
21410
+ const providerServerErrorReplay:
21411
+ | ProviderServerErrorReplay
21412
+ | undefined = retryPolicy
21413
+ ? retryPolicy.providerServerErrorReplay
21414
+ : 'never';
21055
21415
  const requiresExecutionFence =
21056
21416
  retryPolicy?.requiresExecutionFence === true;
21057
21417
  // Fenced execution is an operation-specific opt-in. A gateway may
@@ -21311,6 +21671,11 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21311
21671
  // lifecycle key; it is not a general retry counter.
21312
21672
  let providerRateLimitRetryFromInvocationAttempt: number | null =
21313
21673
  savedProviderRetryCursor?.retryFromInvocationAttempt ?? null;
21674
+ // Set when a parked fenced call resumes: its Durable requeue claim.
21675
+ let callRequeueWire: {
21676
+ fromInvocationAttempt: number;
21677
+ parks: number;
21678
+ } | null = null;
21314
21679
  const serializedRequestBody = (invocationAttempt: number) =>
21315
21680
  JSON.stringify({
21316
21681
  payload: shouldResolveAsyncOperationInRuntime
@@ -21325,6 +21690,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21325
21690
  providerRateLimitRetryFromInvocationAttempt,
21326
21691
  }
21327
21692
  : {}),
21693
+ ...(callRequeueWire
21694
+ ? {
21695
+ requeue_from_invocation_attempt:
21696
+ callRequeueWire.fromInvocationAttempt,
21697
+ requeue_parks: callRequeueWire.parks,
21698
+ }
21699
+ : {}),
21328
21700
  // Every call through this execution path acquires a Postgres
21329
21701
  // AIMD provider permit before its network dispatch. Keep this
21330
21702
  // admission proof distinct from the optional provider fence:
@@ -21444,6 +21816,161 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21444
21816
  delete this.checkpoint.providerRetryCursors;
21445
21817
  }
21446
21818
  };
21819
+ // Durable requeue of a call whose in-call retries were spent. The
21820
+ // state lives in the checkpoint and changes only through
21821
+ // `transitionCallRequeue`; a parked call that runs again is resumed
21822
+ // and retried here, before its first send of this attempt.
21823
+ // A call retries per the live Durable retry policy and its own
21824
+ // `retry`; the policy (`park.enabled` per class) is the live off
21825
+ // switch.
21826
+ const callRequeueKey =
21827
+ this.#options.durableBoundaries &&
21828
+ // A durable retry must find its own record after a replay, so it
21829
+ // needs a replay-stable receipt key. A per-invocation transport
21830
+ // key (random each attempt) never retries durably.
21831
+ options?.durableCallReceiptKey?.trim() &&
21832
+ durableCallReceiptKey
21833
+ ? stableDigest(`call-requeue:${durableCallReceiptKey}`)
21834
+ : null;
21835
+ const durableCallRetryEnabled =
21836
+ callRequeueKey !== null &&
21837
+ !asyncExecutionRecovery &&
21838
+ this.#options.getToolDurableRetryContext !== undefined;
21839
+ if (durableCallRetryEnabled) {
21840
+ // In-call provider pacing gives up after the policy's no-progress
21841
+ // limit for 429s; the default equals PROVIDER_NO_PROGRESS_MAX_MS.
21842
+ try {
21843
+ const retryContext =
21844
+ await this.#options.getToolDurableRetryContext!(toolId);
21845
+ const noProgressMs =
21846
+ retryContext?.policy.policy.classes.rate_limit_429.inCall
21847
+ .noProgressMs;
21848
+ if (typeof noProgressMs === 'number') {
21849
+ providerNoProgressMaxMs = noProgressMs;
21850
+ }
21851
+ } catch (contextError) {
21852
+ this.runtimeLog(
21853
+ `[runtime.call_requeue.unavailable] ${JSON.stringify({
21854
+ tool_id: toolId,
21855
+ error_class: 'rate_limit_429',
21856
+ error:
21857
+ contextError instanceof Error
21858
+ ? contextError.message
21859
+ : String(contextError),
21860
+ })}`,
21861
+ { level: 'error' },
21862
+ );
21863
+ }
21864
+ }
21865
+ /**
21866
+ * A provider hold whose no-progress limit is spent: with durable
21867
+ * call retries the call is retried on a durable timer as
21868
+ * `rate_limit_429` (the next segment starts a fresh in-call
21869
+ * window); otherwise, or once the retries are spent, the
21870
+ * PROVIDER_EXHAUSTED error reaches the Play as before.
21871
+ */
21872
+ const retryProviderHoldDurablyOrThrow = async (
21873
+ error: unknown,
21874
+ ): Promise<never> => {
21875
+ if (
21876
+ durableCallRetryEnabled &&
21877
+ callRequeueKey &&
21878
+ error instanceof ToolExecutionError &&
21879
+ error.code === 'PROVIDER_EXHAUSTED' &&
21880
+ error.origin === 'provider'
21881
+ ) {
21882
+ await this.parkExhaustedCallOrFail({
21883
+ toolId,
21884
+ provider,
21885
+ callRequeueKey,
21886
+ status: 429,
21887
+ failure: { errorClass: 'rate_limit_429' },
21888
+ responseText: '',
21889
+ providerServerErrorReplay,
21890
+ toolInput: toolInputSnapshot,
21891
+ invocationAttempt,
21892
+ fenced: usesDurableInvocationFence,
21893
+ rowScoped: Boolean(
21894
+ options?.providerBackpressureMapRows || rowContext.getStore(),
21895
+ ),
21896
+ ...(options?.retry ? { callRetry: options.retry } : {}),
21897
+ sendsThisBurst: providerSendsThisBurst,
21898
+ writeRecord: writeCallRequeueRecord,
21899
+ });
21900
+ }
21901
+ throw error;
21902
+ };
21903
+ const writeCallRequeueRecord = (record: CallRequeueRecord | null) => {
21904
+ if (!callRequeueKey) return;
21905
+ if (record) {
21906
+ (this.checkpoint.callRequeueStates ??= {})[callRequeueKey] =
21907
+ record;
21908
+ } else if (this.checkpoint.callRequeueStates) {
21909
+ delete this.checkpoint.callRequeueStates[callRequeueKey];
21910
+ }
21911
+ };
21912
+ if (callRequeueKey) {
21913
+ const parked = this.checkpoint.callRequeueStates?.[callRequeueKey];
21914
+ if (
21915
+ parked &&
21916
+ (parked.state === 'parked' ||
21917
+ parked.state === 'waiting_for_billing')
21918
+ ) {
21919
+ // A run woken early (by another boundary) keeps waiting for
21920
+ // this call's own deadline; a mapped row's map honors it.
21921
+ if (
21922
+ parked.retryAtMs !== null &&
21923
+ Date.now() < parked.retryAtMs - 1_000 &&
21924
+ !options?.providerBackpressureMapRows &&
21925
+ !rowContext.getStore()
21926
+ ) {
21927
+ await this.waitForCallRequeue(callRequeueKey, parked.retryAtMs);
21928
+ }
21929
+ const nowMs = Date.now();
21930
+ // A provider hold retried durably gets a fresh in-call
21931
+ // no-progress window in its new attempt.
21932
+ if (
21933
+ parked.errorClass === 'rate_limit_429' &&
21934
+ this.checkpoint.providerNoProgressStartedAtMsByScope
21935
+ ) {
21936
+ delete this.checkpoint.providerNoProgressStartedAtMsByScope[
21937
+ providerNoProgressScope
21938
+ ];
21939
+ }
21940
+ const resumed = transitionCallRequeue(parked, 'resume', nowMs);
21941
+ writeCallRequeueRecord(
21942
+ transitionCallRequeue(resumed ?? undefined, 'retry', nowMs),
21943
+ );
21944
+ this.runtimeLog(
21945
+ `[runtime.call_requeue.resumed] ${JSON.stringify({
21946
+ tool_id: toolId,
21947
+ error_class: parked.errorClass,
21948
+ parks: parked.parks,
21949
+ policy_sequence: parked.policySequence,
21950
+ })}`,
21951
+ );
21952
+ }
21953
+ // Any non-terminal record (also an `in_call` one re-executed
21954
+ // after a crash or another suspension) fixes the attempt floor of
21955
+ // the current park segment. A fenced resend claims that segment
21956
+ // so the gateway checks prior outcomes from there; the claim
21957
+ // replaces any saved 429 retry claim, which belongs to an earlier
21958
+ // segment and would no longer name the preceding attempt.
21959
+ const live = this.checkpoint.callRequeueStates?.[callRequeueKey];
21960
+ const segmentFrom = live?.requeueFromInvocationAttempt;
21961
+ if (typeof segmentFrom === 'number') {
21962
+ if (segmentFrom > invocationAttempt) {
21963
+ invocationAttempt = segmentFrom;
21964
+ }
21965
+ if (usesDurableInvocationFence && segmentFrom >= 1) {
21966
+ providerRateLimitRetryFromInvocationAttempt = null;
21967
+ callRequeueWire = {
21968
+ fromInvocationAttempt: segmentFrom,
21969
+ parks: live!.parks,
21970
+ };
21971
+ }
21972
+ }
21973
+ }
21447
21974
  const persistProviderRetryCursor = (retryFrom: number) => {
21448
21975
  if (!providerRetryCursorKey) return;
21449
21976
  const cursor: ProviderRetryCursor = {
@@ -21726,9 +22253,12 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21726
22253
  this.checkpoint.providerNoProgressStartedAtMsByScope,
21727
22254
  scope: providerNoProgressScope,
21728
22255
  nowMs: Date.now(),
22256
+ maxMs: providerNoProgressMaxMs,
21729
22257
  })
21730
22258
  ) {
21731
- throw providerNoProgressError(Date.now());
22259
+ await retryProviderHoldDurablyOrThrow(
22260
+ providerNoProgressError(Date.now()),
22261
+ );
21732
22262
  }
21733
22263
  physicalAttempt += 1;
21734
22264
  providerConcurrencyGrant = null;
@@ -21749,8 +22279,10 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
21749
22279
  let dispatchedWithProviderPermit = false;
21750
22280
  let providerPermitReceiverRejected = false;
21751
22281
  let providerDispatchCounted = false;
22282
+ let providerPacingWaitRefusedDispatch = false;
21752
22283
  const recordProviderDispatch = () => {
21753
- if (providerDispatchCounted) return;
22284
+ if (providerDispatchCounted || providerPacingWaitRefusedDispatch)
22285
+ return;
21754
22286
  providerDispatchCounted = true;
21755
22287
  this.resourceGovernor.recordProviderDispatch();
21756
22288
  recordToolCallSend(retryFactsTargets, provider);
@@ -22179,12 +22711,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22179
22711
  // headers arrive; decoded body data stays scoped until
22180
22712
  // it has been read and verified below.
22181
22713
  response = dispatchedResponse;
22714
+ // A delegated 503 can attest that it never dispatched.
22715
+ // Read its body before counting it as a provider request.
22182
22716
  if (
22183
- dispatchedResponse.headers.has(
22717
+ dispatchedResponse.status !== 503 &&
22718
+ (dispatchedResponse.headers.has(
22184
22719
  TOOL_EXECUTE_PROVIDER_PERMIT_RECEIVER_HEADER,
22185
22720
  ) ||
22186
- (dispatchedResponse.status !== 403 &&
22187
- dispatchedResponse.status !== 404)
22721
+ (dispatchedResponse.status !== 403 &&
22722
+ dispatchedResponse.status !== 404))
22188
22723
  )
22189
22724
  recordProviderDispatch();
22190
22725
  if (dispatchedResponse.status === 429) {
@@ -22357,6 +22892,13 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22357
22892
  dispatchedResponse,
22358
22893
  dispatchedResponseErrorText ?? '',
22359
22894
  );
22895
+ providerPacingWaitRefusedDispatch =
22896
+ dispatchedWithProviderPermit &&
22897
+ dispatchedResponse.status === 503 &&
22898
+ isProviderPacingWaitResponse({
22899
+ status: dispatchedResponse.status,
22900
+ bodyText: dispatchedResponseErrorText ?? '',
22901
+ });
22360
22902
  if (!providerPermitReceiverRejected)
22361
22903
  recordProviderDispatch();
22362
22904
  if (dispatchedResponse.status === 429) {
@@ -22607,14 +23149,18 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22607
23149
  if (error instanceof ProviderExhaustedError) {
22608
23150
  const retryAtMs = Date.parse(error.retryAt);
22609
23151
  const localRetryAtMs = error.localRetryAtMs ?? retryAtMs;
22610
- observeProviderWait(
22611
- Number.isFinite(retryAtMs) ? retryAtMs : Date.now() + 1_000,
22612
- Number.isFinite(localRetryAtMs)
22613
- ? localRetryAtMs
22614
- : Number.isFinite(retryAtMs)
22615
- ? retryAtMs
22616
- : Date.now() + 1_000,
22617
- );
23152
+ try {
23153
+ observeProviderWait(
23154
+ Number.isFinite(retryAtMs) ? retryAtMs : Date.now() + 1_000,
23155
+ Number.isFinite(localRetryAtMs)
23156
+ ? localRetryAtMs
23157
+ : Number.isFinite(retryAtMs)
23158
+ ? retryAtMs
23159
+ : Date.now() + 1_000,
23160
+ );
23161
+ } catch (holdError) {
23162
+ await retryProviderHoldDurablyOrThrow(holdError);
23163
+ }
22618
23164
  const waitMs = Number.isFinite(localRetryAtMs)
22619
23165
  ? Math.max(0, Math.ceil(localRetryAtMs - Date.now()))
22620
23166
  : 1_000;
@@ -22995,6 +23541,33 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
22995
23541
  },
22996
23542
  );
22997
23543
  }
23544
+ const preDispatchRefusal =
23545
+ failure.reason === 'concurrency_backpressure' ||
23546
+ failure.reason === 'provider_pacing_wait' ||
23547
+ failure.reason === 'runtime_scheduler_capacity' ||
23548
+ failure.reason === 'billing_unavailable_before_dispatch' ||
23549
+ failure.reason === 'gateway_invocation_in_progress';
23550
+ if (!preDispatchRefusal) providerSendsThisBurst += 1;
23551
+ // The call's own `retry` may end this call's in-call retries: a
23552
+ // `nonRetryable` class, or `maximumAttempts` reached by every
23553
+ // request the provider received for the call so far.
23554
+ const stopInCallRetry = callRetryStopsInCallRetry({
23555
+ callRetry: options?.retry,
23556
+ errorClass: options?.retry
23557
+ ? durableRetryErrorClassForHttpFailure({
23558
+ status: response.status,
23559
+ failure,
23560
+ responseText: text,
23561
+ })
23562
+ : null,
23563
+ preDispatchRefusal,
23564
+ sends:
23565
+ callRequeueSends(
23566
+ callRequeueKey
23567
+ ? this.checkpoint.callRequeueStates?.[callRequeueKey]
23568
+ : undefined,
23569
+ ) + providerSendsThisBurst,
23570
+ });
22998
23571
  if (failure.reason === 'concurrency_backpressure') {
22999
23572
  // Our own relay shed. The classifier keeps it out of provider
23000
23573
  // backpressure (origin is not the provider); count it apart
@@ -23038,15 +23611,21 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
23038
23611
  ? null
23039
23612
  : Math.max(0, Math.ceil(providerHoldRetryAtMs - Date.now()));
23040
23613
  if (
23041
- failure.backpressureDelayMs !== null ||
23042
- failure.providerPacingWaitMs !== null
23614
+ !stopInCallRetry &&
23615
+ (failure.backpressureDelayMs !== null ||
23616
+ failure.providerPacingWaitMs !== null)
23043
23617
  ) {
23044
- observeProviderWait(
23045
- providerHoldRetryAtMs ?? Date.now() + 1_000,
23046
- );
23618
+ try {
23619
+ observeProviderWait(
23620
+ providerHoldRetryAtMs ?? Date.now() + 1_000,
23621
+ );
23622
+ } catch (holdError) {
23623
+ await retryProviderHoldDurablyOrThrow(holdError);
23624
+ }
23047
23625
  }
23048
23626
  if (
23049
23627
  failure.shouldRetry &&
23628
+ !stopInCallRetry &&
23050
23629
  this.#options.durableBoundaries &&
23051
23630
  remainingProviderWaitMs !== null &&
23052
23631
  !canWaitForProviderInSandbox(remainingProviderWaitMs)
@@ -23095,6 +23674,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
23095
23674
  failure.reason === 'billing_unavailable_before_dispatch';
23096
23675
  if (
23097
23676
  failure.shouldRetry &&
23677
+ !stopInCallRetry &&
23098
23678
  (failure.knownNotDispatched ||
23099
23679
  failure.reason === 'gateway_invocation_in_progress' ||
23100
23680
  // A provider 5xx is sent again with the same provider
@@ -23222,6 +23802,34 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
23222
23802
  });
23223
23803
  continue;
23224
23804
  }
23805
+ // In-call retries are spent. A retryable class parks the call
23806
+ // and requeues it per the Durable retry policy, instead of
23807
+ // throwing into the Play. A fenced call resumes with a requeue
23808
+ // claim the gateway checks per park segment (an older gateway
23809
+ // ignores the claim and refuses the resend, and the row fails as
23810
+ // before). Async recovery keeps
23811
+ // the old behaviour.
23812
+ if (durableCallRetryEnabled && callRequeueKey) {
23813
+ await this.parkExhaustedCallOrFail({
23814
+ toolId,
23815
+ provider,
23816
+ callRequeueKey,
23817
+ status: response.status,
23818
+ failure,
23819
+ responseText: text,
23820
+ providerServerErrorReplay,
23821
+ toolInput: toolInputSnapshot,
23822
+ invocationAttempt,
23823
+ fenced: usesDurableInvocationFence,
23824
+ rowScoped: Boolean(
23825
+ options?.providerBackpressureMapRows ||
23826
+ rowContext.getStore(),
23827
+ ),
23828
+ ...(options?.retry ? { callRetry: options.retry } : {}),
23829
+ sendsThisBurst: providerSendsThisBurst,
23830
+ writeRecord: writeCallRequeueRecord,
23831
+ });
23832
+ }
23225
23833
  // The row failure line is often the only evidence a customer
23226
23834
  // or operator sees; carry the identifiers that locate the
23227
23835
  // upstream request without the debug transport trace.
@@ -23244,6 +23852,23 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
23244
23852
  );
23245
23853
  }
23246
23854
  const parsed = parseToolExecuteResponse(toolId, responseData);
23855
+ if (callRequeueKey) {
23856
+ const requeued =
23857
+ this.checkpoint.callRequeueStates?.[callRequeueKey];
23858
+ if (requeued) {
23859
+ writeCallRequeueRecord(
23860
+ transitionCallRequeue(requeued, 'succeed', Date.now()),
23861
+ );
23862
+ this.runtimeLog(
23863
+ `[runtime.call_requeue.succeeded] ${JSON.stringify({
23864
+ tool_id: toolId,
23865
+ error_class: requeued.errorClass,
23866
+ parks: requeued.parks,
23867
+ policy_sequence: requeued.policySequence,
23868
+ })}`,
23869
+ );
23870
+ }
23871
+ }
23247
23872
  const resolved = shouldResolveAsyncOperationInRuntime
23248
23873
  ? await this.resolveAsyncOperationInRuntime({
23249
23874
  toolId,