deepline 0.3.535 → 0.3.537

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 (229) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +232 -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 +22 -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/context.ts +88 -96
  18. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +12 -10
  19. package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +3 -1
  20. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +71 -2
  21. package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +9 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +2 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +1 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +127 -9
  25. package/dist/bundling-sources/shared_libs/play-runtime/memory-ledger.ts +15 -2
  26. package/dist/bundling-sources/shared_libs/play-runtime/prebuilt-result-quality.ts +1 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +6 -0
  28. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/fixture-capacity-simulator.ts +1 -0
  29. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/gradient2-concurrency-controller.ts +41 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-capacity-policy.ts +6 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-concurrency-policy.ts +9 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +7 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +2 -2
  34. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +5 -2
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +8 -3
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +7 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-compute-usage.ts +31 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +6 -0
  39. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +26 -1
  40. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +11 -4
  41. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +73 -18
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +169 -2
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +26 -4
  44. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +84 -49
  45. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +37 -32
  46. package/dist/bundling-sources/shared_libs/plays/launch/input-contract.ts +13 -1
  47. package/dist/bundling-sources/shared_libs/plays/local-file-discovery.ts +68 -1
  48. package/dist/bundling-sources/shared_libs/product-notifications/configuration-draft.ts +57 -1
  49. package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +22 -9
  50. package/dist/cli/{auth-ZCTMB5RA.mjs → auth-4SUPGDIM.mjs} +7 -7
  51. package/dist/cli/auth-Y2K2ZYYA.js +43 -0
  52. package/dist/cli/{billing-OU2ZHL72.mjs → billing-5JUA3ZM3.mjs} +185 -24
  53. package/dist/cli/{billing-GVFKZQH3.js → billing-SQU726P7.js} +273 -112
  54. package/dist/cli/{chunk-T2N3B7IQ.js → chunk-2GJZLIKW.js} +8 -8
  55. package/dist/cli/{chunk-ZUVE63Y7.js → chunk-2Q7VXTMS.js} +2 -2
  56. package/dist/cli/{chunk-WAIBM6KX.mjs → chunk-37AZHCTP.mjs} +5 -5
  57. package/dist/cli/{chunk-D4MHCCIR.js → chunk-3PMCQ3LK.js} +33 -33
  58. package/dist/cli/{chunk-R4RG4FV5.mjs → chunk-4KWD3MX2.mjs} +13 -10
  59. package/dist/cli/{chunk-PI5R65OQ.js → chunk-5EOEJKSV.js} +1 -1
  60. package/dist/cli/{chunk-XSOTEVOB.js → chunk-6BBGUQJJ.js} +50 -141
  61. package/dist/cli/{chunk-OM732MGV.js → chunk-ALHKB3AE.js} +17 -17
  62. package/dist/cli/{chunk-6LHX33VN.js → chunk-AVQET3NR.js} +9 -6
  63. package/dist/cli/{chunk-W6T23EUC.mjs → chunk-AX2OAXDL.mjs} +1 -1
  64. package/dist/cli/{chunk-SQWET4SL.js → chunk-BBTKAASQ.js} +2 -1
  65. package/dist/cli/{chunk-G2DLG32W.mjs → chunk-BFHR7IC2.mjs} +40 -27
  66. package/dist/cli/{chunk-KWGXHPHL.js → chunk-BGXEMTIG.js} +523 -59
  67. package/dist/cli/{chunk-AUEUAPVS.mjs → chunk-BRRCWUOW.mjs} +1 -1
  68. package/dist/cli/{chunk-QYBAHYP4.mjs → chunk-C37VELBR.mjs} +7 -9
  69. package/dist/cli/{chunk-H6SWS5CG.mjs → chunk-C3XD2WHM.mjs} +2 -2
  70. package/dist/cli/{chunk-NRO3NTVO.js → chunk-CBV7AKWM.js} +5 -5
  71. package/dist/cli/{chunk-CIDATNTY.js → chunk-CFND2ACL.js} +16 -16
  72. package/dist/cli/{chunk-J75DANZY.mjs → chunk-CGDW2CRR.mjs} +2 -2
  73. package/dist/cli/{chunk-RFQWSH6I.js → chunk-CHIGEDAE.js} +3 -3
  74. package/dist/cli/{chunk-QNHHZ63P.mjs → chunk-CQBIO6HW.mjs} +1 -1
  75. package/dist/cli/{chunk-2KHUFWTK.js → chunk-CQDQNZGH.js} +42 -37
  76. package/dist/cli/{chunk-E3CLOVG5.mjs → chunk-CXTW7SRW.mjs} +50 -141
  77. package/dist/cli/{chunk-4NLRWKZB.js → chunk-D77W6Q67.js} +26 -26
  78. package/dist/cli/{chunk-JWWYLGUT.mjs → chunk-EEFSUCYP.mjs} +475 -11
  79. package/dist/cli/{chunk-STR5LXK4.mjs → chunk-FSIVF2SI.mjs} +1 -1
  80. package/dist/cli/{chunk-6TYRRNXY.mjs → chunk-GI3V4D7K.mjs} +2 -2
  81. package/dist/cli/{chunk-DFJODFMC.mjs → chunk-GPMS6OPX.mjs} +5 -5
  82. package/dist/cli/{chunk-5YAJGRWB.js → chunk-IPVRMYWT.js} +7 -7
  83. package/dist/cli/{chunk-DAPKLYST.js → chunk-IQOIT6E3.js} +41 -41
  84. package/dist/cli/{chunk-ZPGGW27Q.mjs → chunk-JL2OTMSG.mjs} +1 -0
  85. package/dist/cli/{chunk-FGN75ZN6.js → chunk-JMHYDDBQ.js} +390 -382
  86. package/dist/cli/{chunk-KA6ZERJL.js → chunk-JS2SBCWD.js} +6 -6
  87. package/dist/cli/{chunk-W5YJYU4G.mjs → chunk-K4WJ4BYO.mjs} +2 -2
  88. package/dist/cli/{chunk-LVISZFYO.mjs → chunk-KH27B2HJ.mjs} +2 -2
  89. package/dist/cli/{chunk-UUQ2OXMH.js → chunk-KULT6O5K.js} +18 -20
  90. package/dist/cli/{chunk-YFZLZNTH.mjs → chunk-L3JVGNAT.mjs} +4 -4
  91. package/dist/cli/{chunk-HYBZWSSH.js → chunk-L6QAIZNZ.js} +44 -44
  92. package/dist/cli/{chunk-TCVCFZP6.mjs → chunk-NU7B5X6J.mjs} +4 -1
  93. package/dist/cli/{chunk-7PXP2FQK.js → chunk-NXGLJGPB.js} +2 -2
  94. package/dist/cli/{chunk-BNH4Y35W.mjs → chunk-OLH2PHMC.mjs} +2 -2
  95. package/dist/cli/{chunk-GESIFFQX.mjs → chunk-OVX3Q5Q3.mjs} +1 -1
  96. package/dist/cli/{chunk-2D6SWQTK.js → chunk-PJ4ZGZAN.js} +13 -13
  97. package/dist/cli/{chunk-HWPOXCCK.js → chunk-PU42VOBI.js} +8 -8
  98. package/dist/cli/{chunk-RKY4LBX3.mjs → chunk-QDBGPRR2.mjs} +3 -3
  99. package/dist/cli/{chunk-KOZBZPRM.js → chunk-QPDLG7DQ.js} +55 -55
  100. package/dist/cli/{chunk-DWPY6ZID.mjs → chunk-R7JYG6XO.mjs} +1 -1
  101. package/dist/cli/{chunk-K76AEBFY.mjs → chunk-RMVZTBI5.mjs} +4 -4
  102. package/dist/cli/{chunk-IF75RD6U.js → chunk-U2LVWCTD.js} +18 -6
  103. package/dist/cli/{chunk-WNNA4L6Z.js → chunk-UGA5KI4A.js} +22 -22
  104. package/dist/cli/{chunk-ZS2WHWWL.js → chunk-UNDLNT3V.js} +1 -1
  105. package/dist/cli/{chunk-7CWSAEYS.mjs → chunk-V5IIBG2E.mjs} +1 -1
  106. package/dist/cli/{chunk-BF65LB7X.mjs → chunk-VP2K5B3R.mjs} +4 -4
  107. package/dist/cli/{chunk-DYIWDUY4.js → chunk-VRYX2BR4.js} +316 -303
  108. package/dist/cli/{chunk-R2KKEHJN.mjs → chunk-W3J3LT22.mjs} +5 -5
  109. package/dist/cli/{chunk-PHLNYBAA.js → chunk-WBFOV5HT.js} +5 -5
  110. package/dist/cli/{chunk-5EKNDNFQ.js → chunk-WBTYWJLN.js} +2 -2
  111. package/dist/cli/{chunk-C374C22Y.js → chunk-WOQO3GV4.js} +14 -11
  112. package/dist/cli/{chunk-K3IPGMGP.js → chunk-XDS26J7Z.js} +17 -19
  113. package/dist/cli/{chunk-JQQG4QL4.mjs → chunk-Y6AMMXWS.mjs} +3 -3
  114. package/dist/cli/{chunk-7R5DAANG.mjs → chunk-Z2PPB3IO.mjs} +1 -1
  115. package/dist/cli/{chunk-FKD3KL5Q.mjs → chunk-Z2XA6YU4.mjs} +10 -5
  116. package/dist/cli/{chunk-243O3FH5.js → chunk-ZFSB7GXF.js} +5 -5
  117. package/dist/cli/{chunk-MI6ZP7XI.mjs → chunk-ZG7BOECV.mjs} +18 -6
  118. package/dist/cli/{chunk-FZKPPB5P.mjs → chunk-ZHPSJ3LJ.mjs} +85 -77
  119. package/dist/cli/{chunk-K53NKWZO.mjs → chunk-ZUAMXZXC.mjs} +13 -15
  120. package/dist/cli/command-docs.js +2 -2
  121. package/dist/cli/command-docs.mjs +1 -1
  122. package/dist/cli/{csv-CLPVMIRF.mjs → csv-HZP6QMG7.mjs} +6 -6
  123. package/dist/cli/{csv-CD55KEIO.js → csv-JITYN27L.js} +15 -15
  124. package/dist/cli/{db-MQKLDAEO.js → db-FYSRB7O4.js} +36 -36
  125. package/dist/cli/{db-AU4SMWUN.mjs → db-QRIRTOMM.mjs} +9 -9
  126. package/dist/cli/describe-LSOHOLFI.js +49 -0
  127. package/dist/cli/describe-REXJVJC3.mjs +49 -0
  128. package/dist/cli/describe-core.d.mts +3 -3
  129. package/dist/cli/describe-core.d.ts +3 -3
  130. package/dist/cli/describe-core.js +5 -5
  131. package/dist/cli/describe-core.mjs +4 -4
  132. package/dist/cli/{executions-TFIJPUX7.mjs → executions-53KJAFOW.mjs} +9 -9
  133. package/dist/cli/{executions-77GOLWRM.js → executions-BSTF4DDS.js} +11 -11
  134. package/dist/cli/{feedback-OV5YAL3A.js → feedback-6MW3QOXX.js} +16 -16
  135. package/dist/cli/{feedback-2WRSZ5WL.mjs → feedback-CWUJJF3J.mjs} +8 -8
  136. package/dist/cli/{git-VNS4ATLZ.mjs → git-CKVZTJFS.mjs} +7 -7
  137. package/dist/cli/git-S7SWUZ3T.js +25 -0
  138. package/dist/cli/index.js +151 -157
  139. package/dist/cli/index.mjs +51 -57
  140. package/dist/cli/{legacy-noops-HDOB5C6F.js → legacy-noops-QBL4PNGB.js} +11 -11
  141. package/dist/cli/{legacy-noops-C732QDCY.mjs → legacy-noops-USTBRFRX.mjs} +8 -8
  142. package/dist/cli/{monitors-2LYEFXOU.mjs → monitors-6UCG5D7W.mjs} +19 -16
  143. package/dist/cli/{monitors-5IUMHH3E.js → monitors-VCR6SUZD.js} +125 -122
  144. package/dist/cli/{org-G4YGZPHS.mjs → org-GSRBOJVO.mjs} +9 -9
  145. package/dist/cli/{org-ADW2EVAC.js → org-HPILTEG4.js} +89 -89
  146. package/dist/cli/{play-7GQ56C2D.mjs → play-QRTYQNG4.mjs} +123 -76
  147. package/dist/cli/{play-EHSOSSHT.js → play-TK7WOP5H.js} +641 -594
  148. package/dist/cli/{providers-PWCF6OOO.js → providers-HEXNJ5QC.js} +12 -12
  149. package/dist/cli/{providers-WL3YTCSV.mjs → providers-OAQJWVBS.mjs} +9 -9
  150. package/dist/cli/{quickstart-323XOPGI.mjs → quickstart-FFVHTPSP.mjs} +6 -6
  151. package/dist/cli/{quickstart-ZKI5MURA.js → quickstart-PYZTFXZX.js} +8 -8
  152. package/dist/cli/{run-XZPWA6JS.js → run-4DWJXJRO.js} +50 -53
  153. package/dist/cli/{run-ZCNZU3K2.mjs → run-HLN6YYZH.mjs} +31 -34
  154. package/dist/cli/search-WERQBC6V.js +32 -0
  155. package/dist/cli/{search-CVLVSFMJ.mjs → search-ZHRCXGEL.mjs} +10 -11
  156. package/dist/cli/{search-output-7HRSSRBS.js → search-output-2KY6PFDH.js} +8 -8
  157. package/dist/cli/{search-output-6PY6RN2R.mjs → search-output-N7QXACVK.mjs} +6 -6
  158. package/dist/cli/{secrets-6S2ZWDIM.mjs → secrets-FKMWBLHU.mjs} +9 -9
  159. package/dist/cli/{secrets-IYD5VKY4.js → secrets-WXQ7XO5C.js} +18 -18
  160. package/dist/cli/{sessions-GVEX5TUJ.mjs → sessions-3YDTEDA5.mjs} +8 -8
  161. package/dist/cli/sessions-LXQ4Q6BS.js +22 -0
  162. package/dist/cli/{settings-CANK4HJQ.js → settings-67TWLQ6E.js} +88 -89
  163. package/dist/cli/{settings-BN5MJZ3C.mjs → settings-JTPASUZN.mjs} +15 -16
  164. package/dist/cli/{setup-YSGKGLSJ.js → setup-KUERQJUX.js} +51 -52
  165. package/dist/cli/{setup-JNMSCCU4.mjs → setup-VYNGXUJ6.mjs} +11 -12
  166. package/dist/cli/skills-EFRLHY3F.js +36 -0
  167. package/dist/cli/{skills-QCQN2UM2.mjs → skills-KI4KYHH6.mjs} +9 -10
  168. package/dist/cli/tools-C3EIGFFP.js +56 -0
  169. package/dist/cli/{tools-CDPOID7V.mjs → tools-UQDJS2RS.mjs} +20 -21
  170. package/dist/cli/{update-D3ZERUQ3.mjs → update-7FQQUBOD.mjs} +11 -12
  171. package/dist/cli/update-KCY72RXH.js +34 -0
  172. package/dist/cli/{views-RDZRWQBQ.mjs → views-JAM4MNNV.mjs} +54 -10
  173. package/dist/cli/{views-4NV2KQKA.js → views-MJK7JGZG.js} +66 -22
  174. package/dist/cli/{workflow-RABJCAZC.js → workflow-AQPRIWQX.js} +20 -20
  175. package/dist/cli/{workflow-2CG3TVCG.mjs → workflow-TQRV5FGO.mjs} +10 -10
  176. package/dist/{client-DhSvMO3A.d.mts → client-BlLYQDNo.d.mts} +1 -1
  177. package/dist/{client-oGNJMQFd.d.ts → client-DSQlkIDO.d.ts} +1 -1
  178. package/dist/{client-core-CdWH6Sii.d.ts → client-core-CDwapXy5.d.ts} +159 -108
  179. package/dist/{client-core-CVG1Et-4.d.mts → client-core-rX7n2H8U.d.mts} +159 -108
  180. package/dist/{compiler-manifest-D2ZlBGxj.d.ts → compiler-manifest-BHNC4RL-.d.mts} +15 -22
  181. package/dist/{compiler-manifest-D2ZlBGxj.d.mts → compiler-manifest-BHNC4RL-.d.ts} +15 -22
  182. package/dist/{errors-B-gOQdj-.d.mts → errors-D7sPXrvB.d.mts} +1 -1
  183. package/dist/{errors-CB0KAmmV.d.ts → errors-lhtIWG5Z.d.ts} +1 -1
  184. package/dist/{index-c3nvUGCS.d.ts → index-CQTBHXHr.d.ts} +1 -1
  185. package/dist/{index-BbJADro4.d.mts → index-NaDZq2xf.d.mts} +1 -1
  186. package/dist/index.d.mts +7 -7
  187. package/dist/index.d.ts +7 -7
  188. package/dist/index.js +15 -15
  189. package/dist/index.mjs +11 -11
  190. package/dist/install-integrity.json +129 -132
  191. package/dist/monitor-fleet-contract.d.mts +17 -11
  192. package/dist/monitor-fleet-contract.d.ts +17 -11
  193. package/dist/monitor-fleet-contract.js +3 -3
  194. package/dist/monitor-fleet-contract.mjs +2 -2
  195. package/dist/monitor-input-contract.js +2 -2
  196. package/dist/monitor-input-contract.mjs +1 -1
  197. package/dist/plays/bundle-play-file.d.mts +3 -3
  198. package/dist/plays/bundle-play-file.d.ts +3 -3
  199. package/dist/plays/bundle-play-file.mjs +17 -5
  200. package/dist/plays/csv-data-input.js +3 -3
  201. package/dist/plays/csv-data-input.mjs +2 -2
  202. package/dist/plays/play-description.d.mts +2 -2
  203. package/dist/plays/play-description.d.ts +2 -2
  204. package/dist/plays/run-request.d.mts +2 -2
  205. package/dist/plays/run-request.d.ts +2 -2
  206. package/dist/plays/run-request.js +3 -3
  207. package/dist/plays/run-request.mjs +2 -2
  208. package/dist/release.d.mts +1 -1
  209. package/dist/release.d.ts +1 -1
  210. package/dist/release.js +2 -2
  211. package/dist/release.mjs +1 -1
  212. package/dist/server.d.mts +4 -4
  213. package/dist/server.d.ts +4 -4
  214. package/dist/server.js +12 -12
  215. package/dist/server.mjs +6 -6
  216. package/package.json +1 -1
  217. package/dist/cli/auth-VDCU3T6A.js +0 -43
  218. package/dist/cli/chunk-4QELPWUW.mjs +0 -405
  219. package/dist/cli/chunk-T7RBM2WX.js +0 -405
  220. package/dist/cli/describe-5BFNHT5V.js +0 -50
  221. package/dist/cli/describe-AWJUXE2U.mjs +0 -50
  222. package/dist/cli/git-HGMX52XU.js +0 -25
  223. package/dist/cli/pages-KXKWSCEV.mjs +0 -266
  224. package/dist/cli/pages-VTJGAI2D.js +0 -266
  225. package/dist/cli/search-J6EY7DQN.js +0 -33
  226. package/dist/cli/sessions-7HPIVSQ4.js +0 -22
  227. package/dist/cli/skills-WDGSSKJZ.js +0 -37
  228. package/dist/cli/tools-URNVXSTZ.js +0 -57
  229. package/dist/cli/update-Q6JW32IA.js +0 -35
@@ -73,12 +73,35 @@ const FAIR_SHARE_SLOT_WAIT_MS = 100;
73
73
  const FAIR_SHARE_REQUESTER_IDLE_WINDOWS = 2;
74
74
  /** Opportunistically reclaim idle requester rows without a whole-table lock. */
75
75
  const FAIR_SHARE_REQUESTER_CLEANUP_BATCH_SIZE = 64;
76
- /** Conservative warm-start width for a previously unobserved provider scope. */
77
- const INITIAL_CONCURRENCY_DISCOVERY_LIMIT = 8;
76
+ // A declared concurrency rule opens at its declared limit; Gradient2 only
77
+ // lowers it from there on 429s or rising latency.
78
78
  // Rate spacing cannot bound requests delayed between admission and the
79
79
  // physical provider. Unknown scopes discover with at most two shared leases
80
80
  // until a productive rate epoch establishes that the provider can sustain more.
81
81
  const UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT = 2;
82
+ // Leaving discovery opens the lane one doubling above the discovery width at
83
+ // most. Gradient2 then grows it only after calls run near each new limit.
84
+ const UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT =
85
+ 2 * UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT;
86
+
87
+ /**
88
+ * SET clauses for a bucket UPDATE aliased `b`. When `endsDiscovery` holds,
89
+ * cap the learned limit at the first post-discovery width. A limit learned
90
+ * while the lane was held at the discovery width was never exercised there,
91
+ * so it must not take effect all at once when the gate opens.
92
+ */
93
+ function capLearnedLimitAtDiscoveryExitSql(endsDiscovery: string): string {
94
+ const capped = `(${endsDiscovery})
95
+ AND b.learned_concurrency_limit > ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}`;
96
+ return `learned_concurrency_limit = CASE WHEN ${capped}
97
+ THEN ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}
98
+ ELSE b.learned_concurrency_limit END,
99
+ concurrency_window_limit = CASE WHEN ${capped}
100
+ THEN ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}
101
+ ELSE b.concurrency_window_limit END,
102
+ concurrency_successful_samples = CASE WHEN ${capped}
103
+ THEN 0 ELSE b.concurrency_successful_samples END`;
104
+ }
82
105
  /** A transport batch must stay bounded even when a runner completes huge maps. */
83
106
  const MAX_CONCURRENCY_OBSERVATIONS_PER_ACQUIRE = 4_096;
84
107
  /** Keep retry identities long enough for failed runtime work to recover. */
@@ -634,9 +657,10 @@ export async function ensurePostgresRateStateSchema(
634
657
  ALTER TABLE ${bucketTableName(options)}
635
658
  ADD COLUMN IF NOT EXISTS adaptive_max_configured boolean NOT NULL DEFAULT false
636
659
  `);
637
- // v37: durable Gradient2 checkpoint. Null limit marks a pre-v37 bucket and
638
- // starts its next concurrency-bearing acquire at the conservative discovery
639
- // width; rate-only rules leave these fields unused.
660
+ // v37: durable Gradient2 checkpoint. Null limit marks a pre-v37 or new
661
+ // bucket: its next concurrency-bearing acquire starts an undeclared scope at
662
+ // the discovery width and a declared rule at its declared limit; rate-only
663
+ // rules leave these fields unused.
640
664
  await client.query(`
641
665
  ALTER TABLE ${bucketTableName(options)}
642
666
  ADD COLUMN IF NOT EXISTS learned_concurrency_limit float8
@@ -2180,12 +2204,14 @@ async function grantWithConcurrency(
2180
2204
  AND bucket.last_ramp_at_ms = 0
2181
2205
  THEN ${UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT}
2182
2206
  ELSE lim.max_concurrency END,
2207
+ -- A declared lane opens at its declared limit: the provider
2208
+ -- publishes it, so there is nothing to discover below it.
2183
2209
  CEIL(
2184
2210
  COALESCE(
2185
2211
  bucket.learned_concurrency_limit,
2186
- LEAST(lim.max_concurrency, CASE WHEN bucket.rule_id = 'default:provider-scope'
2212
+ CASE WHEN bucket.rule_id = 'default:provider-scope'
2187
2213
  THEN ${UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT}
2188
- ELSE ${INITIAL_CONCURRENCY_DISCOVERY_LIMIT} END)
2214
+ ELSE lim.max_concurrency END
2189
2215
  )
2190
2216
  )
2191
2217
  )::int AS max_concurrency
@@ -2320,7 +2346,12 @@ async function grantWithConcurrency(
2320
2346
  -- confirmed success is sufficient demand; concurrency leases change
2321
2347
  -- admission accounting, not the AIMD learning contract.
2322
2348
  refill_per_sec = LEAST(r.max_rps, (SELECT next_refill_per_sec FROM provider_hold)),
2323
- last_ramp_at_ms = (SELECT next_ramp_at_ms FROM provider_hold)
2349
+ last_ramp_at_ms = (SELECT next_ramp_at_ms FROM provider_hold),
2350
+ -- This statement's first ramp ends cold discovery for the next grant.
2351
+ ${capLearnedLimitAtDiscoveryExitSql(`r.rule_id = 'default:provider-scope'
2352
+ AND NOT r.seen_backpressure
2353
+ AND r.last_ramp_at_ms = 0
2354
+ AND (SELECT next_ramp_at_ms FROM provider_hold) > 0`)}
2324
2355
  FROM refreshed r
2325
2356
  WHERE b.bucket_id = $1
2326
2357
  AND b.rule_id = r.rule_id
@@ -2918,13 +2949,30 @@ function concurrencyObservationsFrom(
2918
2949
  if (!Array.isArray(observations)) return [];
2919
2950
  return observations
2920
2951
  .slice(0, MAX_CONCURRENCY_OBSERVATIONS_PER_ACQUIRE)
2921
- .flatMap((observation) =>
2922
- (observation.kind === 'success' || observation.kind === 'throttled') &&
2923
- Number.isFinite(observation.latencyMs) &&
2924
- observation.latencyMs > 0
2925
- ? [{ kind: observation.kind, latencyMs: observation.latencyMs }]
2926
- : [],
2927
- );
2952
+ .flatMap((observation) => {
2953
+ if (
2954
+ (observation.kind !== 'success' && observation.kind !== 'throttled') ||
2955
+ !Number.isFinite(observation.latencyMs) ||
2956
+ observation.latencyMs <= 0
2957
+ ) {
2958
+ return [];
2959
+ }
2960
+ // Optional success occupancy from newer runners. Anything malformed is
2961
+ // treated as absent, which keeps the older counting rule for that
2962
+ // sample. Throttle attribution stays with the penalty's lease lookup.
2963
+ const inFlightAtStart = observation.inFlightAtStart;
2964
+ return [
2965
+ {
2966
+ kind: observation.kind,
2967
+ latencyMs: observation.latencyMs,
2968
+ ...(observation.kind === 'success' &&
2969
+ Number.isSafeInteger(inFlightAtStart) &&
2970
+ (inFlightAtStart as number) >= 1
2971
+ ? { inFlightAtStart: inFlightAtStart as number }
2972
+ : {}),
2973
+ },
2974
+ ];
2975
+ });
2928
2976
  }
2929
2977
 
2930
2978
  async function concurrencyThrottleFrom(
@@ -3232,7 +3280,7 @@ async function applyConcurrencyObservations(
3232
3280
  row.learned_concurrency_limit ??
3233
3281
  (rule.ruleId === 'default:provider-scope'
3234
3282
  ? UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT
3235
- : INITIAL_CONCURRENCY_DISCOVERY_LIMIT),
3283
+ : maximumLimit),
3236
3284
  ),
3237
3285
  );
3238
3286
  limitsBefore.push(initialLimit);
@@ -3792,7 +3840,9 @@ async function penalizeRateStateStatements(
3792
3840
  next_dispatch_at_ms = CASE WHEN e.new_episode
3793
3841
  THEN e.deadline ELSE GREATEST(e.next_dispatch_at_ms, e.deadline) END
3794
3842
  FROM learned e WHERE h.bucket_id = e.bucket_id
3795
- RETURNING h.*, e.new_episode, e.cycle_ms, e.rate_successes AS successes_before
3843
+ RETURNING h.*, e.new_episode, e.cycle_ms, e.rate_successes AS successes_before,
3844
+ e.seen_backpressure AS seen_backpressure_before,
3845
+ e.last_ramp_at_ms AS last_ramp_at_ms_before
3796
3846
  ), locked_bucket_rows AS (
3797
3847
  SELECT b.bucket_id, b.rule_id, b.refill_per_sec AS refill_before
3798
3848
  FROM ${bucketTableName(input)} b
@@ -3814,7 +3864,12 @@ async function penalizeRateStateStatements(
3814
3864
  tokens = CASE WHEN h.new_episode THEN 0 ELSE b.tokens END,
3815
3865
  next_dispatch_at_ms = CASE WHEN h.new_episode
3816
3866
  THEN h.next_dispatch_at_ms
3817
- ELSE GREATEST(b.next_dispatch_at_ms, h.next_dispatch_at_ms) END
3867
+ ELSE GREATEST(b.next_dispatch_at_ms, h.next_dispatch_at_ms) END,
3868
+ -- The first backpressure also ends cold discovery.
3869
+ ${capLearnedLimitAtDiscoveryExitSql(`b.rule_id = 'default:provider-scope'
3870
+ AND h.new_episode
3871
+ AND NOT h.seen_backpressure_before
3872
+ AND h.last_ramp_at_ms_before = 0`)}
3818
3873
  FROM locked_bucket_rows locked CROSS JOIN provider_hold h
3819
3874
  WHERE b.bucket_id = locked.bucket_id AND b.rule_id = locked.rule_id
3820
3875
  RETURNING locked.refill_before, h.cycle_ms, h.successes_before,
@@ -1,4 +1,7 @@
1
- import { PLATFORM_RECOVERY_ACTIVITY_ID } from '../activity-observation';
1
+ import {
2
+ PLATFORM_RECOVERY_ACTIVITY_ID,
3
+ SANDBOX_CAPACITY_ACTIVITY_ID,
4
+ } from '../activity-observation';
2
5
  import { readPrebuiltResultQuality } from '../prebuilt-result-quality';
3
6
  import {
4
7
  terminalRuntimePerformanceFromStats,
@@ -221,6 +224,7 @@ import {
221
224
  type WorkerRuntimeApiContext,
222
225
  } from '../app-runtime-api';
223
226
  import {
227
+ resolveAbsorbedLateRuntimeSandboxComputeItems,
224
228
  resolveLateRuntimeSandboxComputeItems,
225
229
  resolveRuntimeSandboxComputeItems,
226
230
  } from '../sandbox-compute-usage';
@@ -9081,9 +9085,18 @@ export async function deferPostgresSchedulerAttemptForCapacity(
9081
9085
  attempt: number;
9082
9086
  leaseToken: string;
9083
9087
  reason: string;
9088
+ /**
9089
+ * Set only when the workspace's live-sandbox cap is full. The first
9090
+ * deferral of an unbroken streak publishes a queued activity carrying the
9091
+ * limit, atomically with the requeue; later deferrals publish nothing
9092
+ * until an attempt records a sandbox, so a long wait does not rewrite the
9093
+ * projection every retry.
9094
+ */
9095
+ sandboxCapacity?: { limit: number; nowMs: number };
9084
9096
  },
9085
9097
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
9086
9098
  ): Promise<boolean> {
9099
+ const sandboxCapacity = input.sandboxCapacity ?? null;
9087
9100
  const deferred = await client.query<{ run_id: string }>(
9088
9101
  `
9089
9102
  WITH ${runtimeSandboxCustodyLocksSql('run.run_id = $1', options)}, deferred_attempt AS (
@@ -9108,7 +9121,24 @@ export async function deferPostgresSchedulerAttemptForCapacity(
9108
9121
  updated_at = now()
9109
9122
  WHERE run_id IN (SELECT run_id FROM deferred_attempt)
9110
9123
  AND status IN ('queued', 'running', 'waiting')
9111
- RETURNING run_id
9124
+ RETURNING run_id, launch_json
9125
+ ),
9126
+ sandbox_capacity_activity AS (
9127
+ INSERT INTO ${tableName('outbox', options)} (
9128
+ event_id, run_id, event_type, payload_json, created_at
9129
+ )
9130
+ SELECT 'run-sandbox-capacity:' || requeued_run.run_id || ':' || $2::text,
9131
+ requeued_run.run_id,
9132
+ ${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents},
9133
+ jsonb_build_object('events', jsonb_build_array(
9134
+ ${sandboxCapacityActivityEventSql("jsonb_build_object('kind', 'queued', 'reason', 'capacity')", '$5::integer', '$6::bigint')}
9135
+ )),
9136
+ ${causalOutboxCreatedAt('requeued_run.run_id', options)}
9137
+ FROM requeued_run
9138
+ WHERE $5::integer IS NOT NULL
9139
+ AND NOT ${outstandingSandboxCapacityWaitSql('requeued_run.run_id', '$2::integer', options)}
9140
+ ON CONFLICT (event_id) DO NOTHING
9141
+ RETURNING event_id
9112
9142
  )
9113
9143
  SELECT run_id FROM requeued_run
9114
9144
  `,
@@ -9119,12 +9149,106 @@ export async function deferPostgresSchedulerAttemptForCapacity(
9119
9149
  stringifyPostgresJson({
9120
9150
  kind: 'scheduler_capacity',
9121
9151
  message: input.reason,
9152
+ ...(sandboxCapacity ? { sandboxCapacity: true } : {}),
9122
9153
  }),
9154
+ sandboxCapacity?.limit ?? null,
9155
+ sandboxCapacity?.nowMs ?? null,
9123
9156
  ],
9124
9157
  );
9125
9158
  return deferred.rows.length > 0;
9126
9159
  }
9127
9160
 
9161
+ /**
9162
+ * True while an earlier attempt's sandbox-capacity wait is still published:
9163
+ * some attempt before `attemptSql` deferred for sandbox capacity and no attempt
9164
+ * after it (and before `attemptSql`) recorded a sandbox, which would have
9165
+ * cleared it. Other deferrals in between (an executor-token outage, say) do
9166
+ * not end the wait.
9167
+ */
9168
+ function outstandingSandboxCapacityWaitSql(
9169
+ runIdSql: string,
9170
+ attemptSql: string,
9171
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
9172
+ ): string {
9173
+ return `EXISTS (
9174
+ SELECT 1 FROM ${tableName('attempts', options)} AS waited
9175
+ WHERE waited.run_id = ${runIdSql}
9176
+ AND waited.attempt < ${attemptSql}
9177
+ AND waited.error_json->>'sandboxCapacity' = 'true'
9178
+ AND NOT EXISTS (
9179
+ SELECT 1 FROM ${tableName('attempts', options)} AS started
9180
+ WHERE started.run_id = waited.run_id
9181
+ AND started.attempt > waited.attempt
9182
+ AND started.attempt < ${attemptSql}
9183
+ AND jsonb_path_exists(started.resource_json, '$[*].sandboxId')
9184
+ )
9185
+ )`;
9186
+ }
9187
+
9188
+ /**
9189
+ * The queued (or cleared) sandbox-capacity activity. The target carries the
9190
+ * optional `limit` so readers can name the plan limit without another read.
9191
+ */
9192
+ function sandboxCapacityActivityEventSql(
9193
+ stateSql: string,
9194
+ limitSql: string,
9195
+ nowSql: string,
9196
+ ): string {
9197
+ return `jsonb_build_object(
9198
+ 'type', ${RUN_EVENT_KIND_SQL_LITERAL.activityObserved},
9199
+ 'runId', requeued_run.run_id,
9200
+ 'source', 'worker',
9201
+ 'occurredAt', ${nowSql},
9202
+ 'resumeEpoch', coalesce(requeued_run.launch_json->'resumeEpoch', '0'::jsonb),
9203
+ 'observation', jsonb_build_object(
9204
+ 'activityId', ${escapeLiteral(SANDBOX_CAPACITY_ACTIVITY_ID)},
9205
+ 'target', jsonb_strip_nulls(jsonb_build_object(
9206
+ 'kind', 'capacity', 'pool', 'runner',
9207
+ 'label', 'a concurrency slot', 'limit', ${limitSql}
9208
+ )),
9209
+ 'state', ${stateSql},
9210
+ 'observedAt', ${nowSql}
9211
+ )
9212
+ )`;
9213
+ }
9214
+
9215
+ /**
9216
+ * Clear the sandbox-capacity activity once a run that waited for a slot has
9217
+ * its sandbox. Publishes only while a sandbox-capacity wait is outstanding, so
9218
+ * ordinary starts write nothing. Idempotent per attempt.
9219
+ */
9220
+ export async function clearPostgresSandboxCapacityActivity(
9221
+ client: PostgresSchedulerQueryClient,
9222
+ input: { runId: string; attempt: number; nowMs: number },
9223
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
9224
+ ): Promise<boolean> {
9225
+ const cleared = await client.query<{ event_id: string }>(
9226
+ `
9227
+ WITH requeued_run AS (
9228
+ SELECT run.run_id, run.launch_json
9229
+ FROM ${tableName('runs', options)} AS run
9230
+ WHERE run.run_id = $1
9231
+ AND ${outstandingSandboxCapacityWaitSql('run.run_id', '$2::integer', options)}
9232
+ )
9233
+ INSERT INTO ${tableName('outbox', options)} (
9234
+ event_id, run_id, event_type, payload_json, created_at
9235
+ )
9236
+ SELECT 'run-sandbox-capacity-cleared:' || requeued_run.run_id || ':' || $2::text,
9237
+ requeued_run.run_id,
9238
+ ${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents},
9239
+ jsonb_build_object('events', jsonb_build_array(
9240
+ ${sandboxCapacityActivityEventSql("jsonb_build_object('kind', 'completed')", 'NULL::integer', '$3::bigint')}
9241
+ )),
9242
+ ${causalOutboxCreatedAt('requeued_run.run_id', options)}
9243
+ FROM requeued_run
9244
+ ON CONFLICT (event_id) DO NOTHING
9245
+ RETURNING event_id
9246
+ `,
9247
+ [input.runId, input.attempt, input.nowMs],
9248
+ );
9249
+ return cleared.rows.length > 0;
9250
+ }
9251
+
9128
9252
  /** `error_json.kind` stamped on an attempt retired by an executor-token
9129
9253
  * outage. Consecutive attempts carrying it form one bounded outage. */
9130
9254
  export const EXECUTOR_TOKEN_UNAVAILABLE_ATTEMPT_ERROR_KIND =
@@ -17901,6 +18025,49 @@ export async function finalizePostgresSchedulerComputeBilling(
17901
18025
  workflowId: launch.runId,
17902
18026
  runId: launch.runId,
17903
18027
  });
18028
+ // Provider time the run did not plan for: a create that resolved after
18029
+ // its attempt ended, or one handed to cleanup. Logged once per settled
18030
+ // adjustment so that cost can be sized without reading billing rows.
18031
+ // Settlement is at-least-once; count distinct `sessionId`.
18032
+ console.info('[runtime.compute.late_resource_settled]', {
18033
+ event: 'runtime.compute.late_resource_settled',
18034
+ runId: launch.runId,
18035
+ orgId: launch.orgId,
18036
+ sessionId: adjustmentSessionId,
18037
+ itemId: item.itemId,
18038
+ source: item.source,
18039
+ billableSeconds: item.units,
18040
+ providerCostUsd: item.providerCostUsd,
18041
+ runSucceeded: success,
18042
+ customerBilled: true,
18043
+ });
18044
+ }
18045
+ // A sandbox handed to cleanup before it could run customer code is not
18046
+ // billed. Its provider time is Deepline's cost, so it is still logged, with
18047
+ // no billing session. Count distinct `runId` + `itemId`.
18048
+ const absorbedItems =
18049
+ lateResources.length === 0
18050
+ ? []
18051
+ : resolveAbsorbedLateRuntimeSandboxComputeItems({
18052
+ resources: lateResources,
18053
+ endedAt: Date.now(),
18054
+ maxBillingDurationSeconds:
18055
+ sandboxRuntimeLimitsFromContractSnapshot(launch.contractSnapshot)
18056
+ .timeoutSeconds + PLAY_RUNNER_TERMINAL_GRACE_SECONDS,
18057
+ });
18058
+ for (const item of absorbedItems) {
18059
+ console.info('[runtime.compute.late_resource_settled]', {
18060
+ event: 'runtime.compute.late_resource_settled',
18061
+ runId: launch.runId,
18062
+ orgId: launch.orgId,
18063
+ sessionId: null,
18064
+ itemId: item.itemId,
18065
+ source: item.source,
18066
+ billableSeconds: item.units,
18067
+ providerCostUsd: item.providerCostUsd,
18068
+ runSucceeded: success,
18069
+ customerBilled: false,
18070
+ });
17904
18071
  }
17905
18072
  }
17906
18073
 
@@ -25,8 +25,8 @@ import { readComputeBillingJobStatus } from './compute-billing-job-state';
25
25
  * every ordinary organization's observed peak (at most 46 live sandboxes in the
26
26
  * week before 2026-10-29) and bounds a burst: on 2026-10-29 one organization
27
27
  * held 2,838 live sandboxes polling the receipt gateway. Keep in sync with the
28
- * Convex control plane's DEFAULT_PLAY_SANDBOX_CONCURRENCY in
29
- * packages/convex/auth.ts.
28
+ * `play.concurrent_runs` default and maximum in
29
+ * packages/billing/org-limits/registry.ts (a Convex test asserts it).
30
30
  */
31
31
  export const DEFAULT_PLAY_SANDBOX_CONCURRENCY = 50;
32
32
  export const MAX_PLAY_SANDBOX_CONCURRENCY = 250;
@@ -285,6 +285,16 @@ type RuntimeSandboxReservationProof = {
285
285
  sandbox_id: string | null;
286
286
  };
287
287
 
288
+ /** A launch-carried limit inside the runtime's bounds, or null to ignore it. */
289
+ function entitlementLimit(value: number | null | undefined): number | null {
290
+ return typeof value === 'number' &&
291
+ Number.isSafeInteger(value) &&
292
+ value >= 1 &&
293
+ value <= MAX_PLAY_SANDBOX_CONCURRENCY
294
+ ? value
295
+ : null;
296
+ }
297
+
288
298
  export async function reserveRuntimeSandboxCapacityLease(
289
299
  client: PostgresSchedulerQueryClient,
290
300
  input: {
@@ -298,6 +308,11 @@ export async function reserveRuntimeSandboxCapacityLease(
298
308
  mode?: RuntimeSandboxCapacityAdmissionMode;
299
309
  /** Resume the one unresolved Daytona create for this run, if present. */
300
310
  resumePendingDaytonaOperation?: boolean;
311
+ /**
312
+ * The `play.concurrent_runs` entitlement the launch carries. When set it
313
+ * is the limit; otherwise the mirrored cap, then the runtime default.
314
+ */
315
+ entitlementLimit?: number | null;
301
316
  },
302
317
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
303
318
  ): Promise<
@@ -376,7 +391,7 @@ export async function reserveRuntimeSandboxCapacityLease(
376
391
  `
377
392
  WITH observed AS MATERIALIZED (
378
393
  SELECT
379
- capacity.configured_limit AS "limit",
394
+ coalesce($14::integer, capacity.configured_limit) AS "limit",
380
395
  capacity.active_leases,
381
396
  coalesce((
382
397
  SELECT jsonb_agg(pending)
@@ -517,6 +532,7 @@ export async function reserveRuntimeSandboxCapacityLease(
517
532
  RUNTIME_SANDBOX_CAPACITY_LEASE_MS,
518
533
  providerOperationToken,
519
534
  runtimeSandboxOperationTargetState('reserve'),
535
+ entitlementLimit(input.entitlementLimit),
520
536
  ],
521
537
  );
522
538
  const limit = Number(
@@ -819,6 +835,7 @@ export async function reserveRuntimeSandboxOperation(
819
835
  environment: 'preview' | 'production';
820
836
  mode?: RuntimeSandboxCapacityAdmissionMode;
821
837
  resumePendingDaytonaOperation?: boolean;
838
+ entitlementLimit?: number | null;
822
839
  },
823
840
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
824
841
  ): ReturnType<typeof reserveRuntimeSandboxCapacityLease> {
@@ -836,6 +853,7 @@ export async function reserveRuntimeSandboxOperation(
836
853
  environment: input.environment,
837
854
  mode: input.mode,
838
855
  resumePendingDaytonaOperation: input.resumePendingDaytonaOperation,
856
+ entitlementLimit: input.entitlementLimit,
839
857
  },
840
858
  options,
841
859
  );
@@ -1267,7 +1285,11 @@ export async function recordDaytonaSandboxCleanupIntent(
1267
1285
  'daytonaOrganizationId', $6::text,
1268
1286
  'billingStartedAt', extract(epoch FROM promoted.created_at) * 1000,
1269
1287
  'sandboxCapacityLeaseId', promoted.operation_key,
1270
- 'lateAcquired', true
1288
+ 'lateAcquired', true,
1289
+ -- This operation is now deleting, which no writer promotes
1290
+ -- to live: the sandbox can never run customer code, so its
1291
+ -- provider time is Deepline's cost, not a customer charge.
1292
+ 'customerCodeUnreachable', true
1271
1293
  ) AS value
1272
1294
  FROM promoted
1273
1295
  ), recorded_attempt AS (
@@ -357,6 +357,26 @@ export function toolExecuteBillingRetryIdentity(input: {
357
357
  if (failure.reason === 'provider_pacing_wait') {
358
358
  return `app-pacing-refusal:${input.httpFailureAttempt}`;
359
359
  }
360
+ // The runner resends a provider 5xx even over the app's `retryable: false`
361
+ // (an outcome category the app does not map, such as a DataForSEO task
362
+ // 5xxxx), and `billingReservationReleased` infers a release only from an
363
+ // explicit `retryable: true`. The app's confirmation is direct proof that
364
+ // this attempt's reservation is terminal and can never settle, so renewing
365
+ // cannot open a second chargeable reservation beside it.
366
+ const providerServerErrorReleased =
367
+ failure.reason === 'provider_server_error' &&
368
+ failure.billingReservationReleased;
369
+ const confirmedProviderRelease =
370
+ failure.billingReservationReleaseConfirmed &&
371
+ input.asyncExecutionRecovery !== true &&
372
+ (failure.reason === 'provider_server_error' ||
373
+ failure.reason === 'retry_safe_transient_5xx');
374
+ // The release proof applies to both fenced and unfenced sends. Resolve it
375
+ // before the fenced fallback, which otherwise skips a confirmed release
376
+ // when the response lacks the fields used to infer one.
377
+ if (confirmedProviderRelease) {
378
+ return `transient-retry:${input.httpFailureAttempt}`;
379
+ }
360
380
  if (input.executionFenced) {
361
381
  return failure.billingReservationReleased
362
382
  ? `transient-retry:${input.httpFailureAttempt}`
@@ -367,25 +387,11 @@ export function toolExecuteBillingRetryIdentity(input: {
367
387
  // and halts the run. An unfenced call needs the renewal as much as a fenced
368
388
  // one: a billed read that is not declared retry-safe is resent after a
369
389
  // provider 5xx once `retryProviderServerErrors` is on.
370
- if (
371
- failure.billingReservationReleased &&
372
- failure.reason === 'provider_server_error'
373
- ) {
374
- return `transient-retry:${input.httpFailureAttempt}`;
375
- }
376
- // A `retrySafeTransientHttp` action bills through the same request identity,
377
- // but its 502 shape is also sent while a hold is retained (an async hold with
378
- // an attached provider job, an ambiguous launch) or after a release failed.
379
- // Renewing there would open a second reservation beside one that can still
380
- // settle, so only the app's explicit confirmation renews; without it the
381
- // retry keeps its identity and recovers the reservation it already has.
382
- if (
383
- failure.billingReservationReleaseConfirmed &&
384
- failure.reason === 'retry_safe_transient_5xx' &&
385
- input.asyncExecutionRecovery !== true
386
- ) {
390
+ if (providerServerErrorReleased) {
387
391
  return `transient-retry:${input.httpFailureAttempt}`;
388
392
  }
393
+ // An unconfirmed unfenced retry-safe 5xx may retain an async hold or an
394
+ // ambiguous launch; keep its identity to recover that reservation.
389
395
  return failure.backpressureDelayMs !== null ||
390
396
  (failure.reason === 'rate_limit' && failure.knownNotDispatched)
391
397
  ? `provider-rate-limit-retry:${input.invocationAttempt}`
@@ -555,7 +561,7 @@ function isRuntimeSchedulerCapacityResponse(input: {
555
561
  );
556
562
  }
557
563
 
558
- function isProviderPacingWaitResponse(input: {
564
+ export function isProviderPacingWaitResponse(input: {
559
565
  status: number;
560
566
  bodyText: string;
561
567
  }): boolean {
@@ -686,31 +692,55 @@ export function parseToolExecuteAuthScopeChangedError(input: {
686
692
  return new ToolExecuteAuthScopeChangedError(message);
687
693
  }
688
694
 
689
- /** A 5xx the provider itself returned, rather than one from Deepline. */
690
- function isProviderServerErrorResponse(input: {
695
+ /**
696
+ * A 5xx the provider itself returned, rather than one from Deepline, that is
697
+ * not a timeout and not a model's own invalid answer. Owner rule: a timeout
698
+ * (a transport failure, or a 504 from the provider or the execute route) is
699
+ * never retried, and `model_output` is the model's answer, not an outage.
700
+ */
701
+ export function isProviderServerErrorResponse(input: {
691
702
  status: number;
692
703
  bodyText: string;
693
704
  }): boolean {
694
- return (
695
- input.status >= 500 &&
696
- input.status < 600 &&
697
- parseJsonObject(input.bodyText)?.failure_origin === 'provider'
698
- );
705
+ if (input.status < 500 || input.status >= 600 || input.status === 504) {
706
+ return false;
707
+ }
708
+ const body = parseJsonObject(input.bodyText);
709
+ if (body?.failure_origin !== 'provider') return false;
710
+ if (body.error_category === 'model_output') return false;
711
+ if (body.error_category === 'network') return false;
712
+ if (typeof body.network_kind === 'string') return false;
713
+ // The execute route may answer a provider's 4xx (an ambiguous 402, say)
714
+ // with a 5xx; the provider's own status decides when it is present.
715
+ const upstream = body.upstream_status;
716
+ if (
717
+ typeof upstream === 'number' &&
718
+ upstream >= 400 &&
719
+ upstream <= 599 &&
720
+ (upstream < 500 || upstream === 504)
721
+ ) {
722
+ return false;
723
+ }
724
+ return true;
699
725
  }
700
726
 
701
727
  /**
702
728
  * How an action classifies for a provider 5xx (see
703
- * `retry.providerServerErrorReplay` in the provider registry). Anything but a
704
- * declared `idempotent_key` or `read_safe` is `never`.
729
+ * `retry.providerServerErrorReplay` in the provider registry). Absent means
730
+ * unclassified, which retries like `idempotent_key` and `read_safe`.
705
731
  */
706
732
  export type ProviderServerErrorReplay =
707
733
  | 'idempotent_key'
708
734
  | 'read_safe'
709
735
  | 'never';
710
736
 
711
- /** Only an explicit classification may replay; absent and unknown never do. */
737
+ /**
738
+ * Owner rule (2026-11-16): every provider 5xx is retried, writes included,
739
+ * because at-least-once beats a lost write. Only an action that explicitly
740
+ * declares `never` refuses; absent, unclassified and unknown values retry.
741
+ */
712
742
  export function providerServerErrorReplayAllowed(value: unknown): boolean {
713
- return value === 'idempotent_key' || value === 'read_safe';
743
+ return value !== 'never';
714
744
  }
715
745
 
716
746
  function decideToolExecuteHttpRetry(input: {
@@ -718,7 +748,7 @@ function decideToolExecuteHttpRetry(input: {
718
748
  /** A 5xx the provider itself returned (failure_origin provider). */
719
749
  providerServerError?: boolean;
720
750
  retryProviderServerErrors?: boolean;
721
- /** The action's classification; absent means `never`. */
751
+ /** The action's classification; only `never` refuses a provider 5xx. */
722
752
  providerServerErrorReplay?: ProviderServerErrorReplay;
723
753
  idempotencyInProgress?: boolean;
724
754
  gatewayInvocationInProgress?: boolean;
@@ -833,6 +863,25 @@ function decideToolExecuteHttpRetry(input: {
833
863
  };
834
864
  }
835
865
  if (input.status >= 500 && input.status < 600) {
866
+ // A provider 5xx retries even when the response says it is not
867
+ // retryable: an API built before the owner's retry-all-5xx rule refused
868
+ // every unclassified action, so its refusal is not a decision this
869
+ // runner honors. The runner itself excludes timeouts, model output and
870
+ // an action that declares `never`.
871
+ if (
872
+ !input.transientHttpRetrySafe &&
873
+ input.retryProviderServerErrors === true &&
874
+ input.providerServerError === true &&
875
+ providerServerErrorReplayAllowed(input.providerServerErrorReplay)
876
+ ) {
877
+ // Only successes are final: the same call is sent again with the same
878
+ // provider idempotency key, after a backoff with jitter.
879
+ return {
880
+ retryable: true,
881
+ attemptCap: TOOL_EXECUTE_TRANSIENT_HTTP_MAX_ATTEMPTS,
882
+ reason: 'provider_server_error',
883
+ };
884
+ }
836
885
  if (input.explicitRetryable === false) {
837
886
  return {
838
887
  retryable: false,
@@ -857,20 +906,6 @@ function decideToolExecuteHttpRetry(input: {
857
906
  reason: 'edge_gateway_transient',
858
907
  };
859
908
  }
860
- if (
861
- !input.transientHttpRetrySafe &&
862
- input.retryProviderServerErrors === true &&
863
- input.providerServerError === true &&
864
- providerServerErrorReplayAllowed(input.providerServerErrorReplay)
865
- ) {
866
- // Only successes are final: the same call is sent again with the same
867
- // provider idempotency key, after a backoff with jitter.
868
- return {
869
- retryable: true,
870
- attemptCap: TOOL_EXECUTE_TRANSIENT_HTTP_MAX_ATTEMPTS,
871
- reason: 'provider_server_error',
872
- };
873
- }
874
909
  if (!input.transientHttpRetrySafe) {
875
910
  return {
876
911
  retryable: false,
@@ -1024,11 +1059,11 @@ export function classifyToolExecuteHttpFailure(input: {
1024
1059
  /** Defaults to `DURABLE_RUNS_ROLLOUT.retryProviderServerErrors`. */
1025
1060
  retryProviderServerErrors?: boolean;
1026
1061
  /**
1027
- * The action's classification for a provider 5xx. Absent means `never`: a
1028
- * write, upsert, create or send, and a paid call whose 5xx is ambiguous
1029
- * after dispatch, is not replayed. The gateway previous-outcome check
1030
- * passes `idempotent_key` because it only validates the recorded outcome;
1031
- * the runner, which owns the resend, has already applied the classification.
1062
+ * The action's classification for a provider 5xx. Only `never` refuses;
1063
+ * absent (unclassified) retries, writes included (owner rule 2026-11-16).
1064
+ * The gateway previous-outcome check passes `idempotent_key` because it
1065
+ * only validates the recorded outcome; the runner, which owns the resend,
1066
+ * has already applied the classification.
1032
1067
  */
1033
1068
  providerServerErrorReplay?: ProviderServerErrorReplay;
1034
1069
  providerLatencyMs?: number;