deepline 0.3.552 → 0.3.553

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 (319) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +107 -12
  2. package/dist/bundling-sources/sdk/src/compat.ts +239 -87
  3. package/dist/bundling-sources/sdk/src/config.ts +113 -2
  4. package/dist/bundling-sources/sdk/src/errors.ts +2 -0
  5. package/dist/bundling-sources/sdk/src/http-core.ts +118 -8
  6. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  7. package/dist/bundling-sources/sdk/src/integrations.ts +6 -4
  8. package/dist/bundling-sources/sdk/src/play.ts +3 -0
  9. package/dist/bundling-sources/sdk/src/plays/run-request.ts +1 -1
  10. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  11. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +8 -1
  12. package/dist/bundling-sources/sdk/src/tool-calls.ts +2 -1
  13. package/dist/bundling-sources/sdk/src/tool-failure-hint.ts +104 -0
  14. package/dist/bundling-sources/sdk/src/types.ts +9 -1
  15. package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +4 -2
  16. package/dist/bundling-sources/shared_libs/integration-contracts/billing-plan-skus.ts +25 -0
  17. package/dist/bundling-sources/shared_libs/monitors/action-actor.ts +2 -0
  18. package/dist/bundling-sources/shared_libs/monitors/billing/credit-recovery.ts +58 -4
  19. package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +8 -0
  20. package/dist/bundling-sources/shared_libs/monitors/billing/pricing.ts +11 -0
  21. package/dist/bundling-sources/shared_libs/monitors/billing/types.ts +13 -0
  22. package/dist/bundling-sources/shared_libs/monitors/deactivation-reasons.ts +103 -5
  23. package/dist/bundling-sources/shared_libs/monitors/fleets/converge-admission.ts +133 -0
  24. package/dist/bundling-sources/shared_libs/monitors/fleets/fence-attention.ts +165 -0
  25. package/dist/bundling-sources/shared_libs/monitors/fleets/fence-release.ts +726 -0
  26. package/dist/bundling-sources/shared_libs/monitors/fleets/fence-walk.ts +274 -0
  27. package/dist/bundling-sources/shared_libs/monitors/fleets/issues.ts +1 -0
  28. package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +28 -0
  29. package/dist/bundling-sources/shared_libs/monitors/fleets/provider-bulk-wait.ts +126 -0
  30. package/dist/bundling-sources/shared_libs/monitors/fleets/shared-payload.ts +189 -0
  31. package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +28 -0
  32. package/dist/bundling-sources/shared_libs/monitors/inbound-publish-key.ts +4 -0
  33. package/dist/bundling-sources/shared_libs/monitors/inventory-counter-errors.ts +25 -0
  34. package/dist/bundling-sources/shared_libs/monitors/org-monitor-limits.ts +65 -0
  35. package/dist/bundling-sources/shared_libs/monitors/package.json +9 -0
  36. package/dist/bundling-sources/shared_libs/monitors/provider-callback-verification.ts +152 -1
  37. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +6 -0
  38. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-capability.ts +390 -10
  39. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-errors.ts +34 -0
  40. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-identity-claims.ts +66 -30
  41. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-state.ts +30 -0
  42. package/dist/bundling-sources/shared_libs/monitors/provider-resource-failure.ts +26 -3
  43. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +41 -13
  44. package/dist/bundling-sources/shared_libs/monitors/signal-radars/raw-receipt-causes.ts +219 -0
  45. package/dist/bundling-sources/shared_libs/monitors/snitcher-ip2company.ts +21 -10
  46. package/dist/bundling-sources/shared_libs/monitors/starter-templates.ts +13 -0
  47. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +6 -0
  48. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-integrations.ts +13 -0
  49. package/dist/bundling-sources/shared_libs/observability/dlq.ts +1 -1
  50. package/dist/bundling-sources/shared_libs/observability/log-metadata.ts +5 -3
  51. package/dist/bundling-sources/shared_libs/observability/queue-health.ts +10 -1
  52. package/dist/bundling-sources/shared_libs/observability/queue-item-connectors.ts +1 -0
  53. package/dist/bundling-sources/shared_libs/observability/redaction.ts +24 -1
  54. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +168 -41
  55. package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +1 -2
  56. package/dist/bundling-sources/shared_libs/play-data-plane/preview-r2-oidc.ts +188 -0
  57. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +170 -16
  58. package/dist/bundling-sources/shared_libs/play-data-plane/runtime-sheet-storage-contract.ts +5 -0
  59. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +68 -2
  60. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +444 -39
  61. package/dist/bundling-sources/shared_libs/play-runtime/ctx-fetch-caller-deadline.ts +200 -0
  62. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +6 -0
  63. package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-topology.ts +21 -1
  64. package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +3 -2
  65. package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +70 -2
  66. package/dist/bundling-sources/shared_libs/play-runtime/durable-tool-identity.ts +3 -3
  67. package/dist/bundling-sources/shared_libs/play-runtime/execution-capabilities.ts +16 -0
  68. package/dist/bundling-sources/shared_libs/play-runtime/experiment-switches.ts +72 -0
  69. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +1 -0
  70. package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +7 -1
  71. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +62 -0
  72. package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +74 -3
  73. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +31 -3
  74. package/dist/bundling-sources/shared_libs/play-runtime/play-http-request.ts +6 -0
  75. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +8 -0
  76. package/dist/bundling-sources/shared_libs/play-runtime/query-result-dataset.ts +19 -0
  77. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +39 -2
  78. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +9 -1
  79. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +33 -0
  80. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +24 -0
  81. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +254 -44
  82. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +87 -6
  83. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +241 -10
  84. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +161 -14
  85. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +16 -3
  86. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-compression.ts +37 -0
  87. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-paths.ts +9 -0
  88. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +259 -52
  89. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +13 -0
  90. package/dist/bundling-sources/shared_libs/play-runtime/runtime-constants.ts +30 -0
  91. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +62 -1
  92. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +36 -0
  93. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-transition.ts +36 -0
  94. package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +206 -2
  95. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +42 -0
  96. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +185 -64
  97. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-slot-ledger.ts +157 -0
  98. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +110 -2
  99. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-listener-hint.ts +323 -0
  100. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/executor-attempt-standing.ts +72 -0
  101. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/integration-operation-value-storage.ts +23 -4
  102. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-workspace-purge.ts +199 -0
  103. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +632 -66
  104. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +517 -16
  105. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-api-origin.ts +1 -1
  106. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-value-storage.ts +9 -0
  107. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +599 -2
  108. package/dist/bundling-sources/shared_libs/play-runtime/secret-resolution-retry-policy.ts +26 -1
  109. package/dist/bundling-sources/shared_libs/play-runtime/startup-read-tool-ids.ts +60 -0
  110. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +51 -0
  111. package/dist/bundling-sources/shared_libs/play-runtime/tool-call-retry-facts.ts +2 -0
  112. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +113 -3
  113. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +5 -7
  114. package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-storage-contract.ts +2 -0
  115. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +3 -0
  116. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +40 -5
  117. package/dist/bundling-sources/shared_libs/plays/deploy/api-client.ts +3 -0
  118. package/dist/bundling-sources/shared_libs/plays/deploy/control-plane-types.ts +16 -0
  119. package/dist/bundling-sources/shared_libs/plays/deploy/run-deployment.ts +10 -41
  120. package/dist/bundling-sources/shared_libs/plays/extension-bridge.ts +33 -0
  121. package/dist/bundling-sources/shared_libs/plays/row-identity.ts +18 -1
  122. package/dist/bundling-sources/shared_libs/plays/tool-execution-error.ts +108 -0
  123. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +14 -0
  124. package/dist/bundling-sources/shared_libs/product-notifications/catalog.ts +171 -0
  125. package/dist/bundling-sources/shared_libs/product-notifications/events.ts +27 -1
  126. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +9 -24
  127. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +178 -5
  128. package/dist/bundling-sources/shared_libs/security/signup-email-dns-screen.ts +148 -0
  129. package/dist/bundling-sources/shared_libs/tool-execution-error.ts +108 -0
  130. package/dist/cli/{auth-KVSBJZOX.mjs → auth-I3QAU4RV.mjs} +8 -7
  131. package/dist/cli/auth-MQCN7WGZ.js +44 -0
  132. package/dist/cli/{billing-54RHFEBI.mjs → billing-3IC54OQQ.mjs} +197 -61
  133. package/dist/cli/{billing-FQREA7UA.js → billing-YGFFVAIC.js} +297 -161
  134. package/dist/cli/{chunk-4MK42735.js → chunk-2B5B5KAW.js} +210 -128
  135. package/dist/cli/{chunk-UBKA33KY.mjs → chunk-2MGZAI54.mjs} +17 -0
  136. package/dist/cli/{chunk-4NQF6KJ3.js → chunk-3NTP2OSG.js} +13 -13
  137. package/dist/cli/{chunk-HYC4MKGK.mjs → chunk-45OAVGU6.mjs} +5 -5
  138. package/dist/cli/{chunk-WLN3SUIA.js → chunk-4747TPLV.js} +3 -3
  139. package/dist/cli/{chunk-AZQ264ID.mjs → chunk-4BFTDNHU.mjs} +1 -1
  140. package/dist/cli/{chunk-BGBJV26E.mjs → chunk-4HYNMXXF.mjs} +4 -4
  141. package/dist/cli/{chunk-DJ2JDK4O.mjs → chunk-4SMCFQ23.mjs} +1 -1
  142. package/dist/cli/{chunk-QPKH23EC.mjs → chunk-55F6HNOY.mjs} +5 -5
  143. package/dist/cli/{chunk-LX35AXTN.mjs → chunk-5TYLSS4Q.mjs} +6 -6
  144. package/dist/cli/{chunk-634ZDA3F.js → chunk-6NE3RRRY.js} +1 -1
  145. package/dist/cli/{chunk-EITMD3A5.js → chunk-6VLFQZK6.js} +8 -8
  146. package/dist/cli/{chunk-EOPEYCY7.mjs → chunk-72V4PDH5.mjs} +18 -18
  147. package/dist/cli/{chunk-IHRKLXZN.js → chunk-74RES4DS.js} +5 -5
  148. package/dist/cli/{chunk-45PVGZST.js → chunk-7GEMELKI.js} +366 -320
  149. package/dist/cli/{chunk-4UUR4TCH.js → chunk-7O6J6A7P.js} +1871 -92
  150. package/dist/cli/{chunk-XVB7V4N7.js → chunk-7SERLBNR.js} +161 -53
  151. package/dist/cli/{chunk-F2LH7TGF.js → chunk-7YRJ5UC4.js} +21 -21
  152. package/dist/cli/{chunk-YJHE3O5M.mjs → chunk-A7DLBE5K.mjs} +136 -54
  153. package/dist/cli/{chunk-6PRW5UBA.mjs → chunk-AGICYWGN.mjs} +299 -69
  154. package/dist/cli/{chunk-S5S355UY.mjs → chunk-AGIQDA2T.mjs} +12 -12
  155. package/dist/cli/{chunk-RBEUVDZF.js → chunk-AGLR6QVN.js} +249 -107
  156. package/dist/cli/{chunk-NURW5XH4.mjs → chunk-ASB47RXJ.mjs} +1 -1
  157. package/dist/cli/{chunk-RQZQVFCJ.js → chunk-BVDKFS2T.js} +2 -2
  158. package/dist/cli/{chunk-PFO3ISXA.js → chunk-CACFJODG.js} +174 -129
  159. package/dist/cli/{chunk-6RZOWL2V.mjs → chunk-CAEBJOYU.mjs} +1 -1
  160. package/dist/cli/{chunk-XDVT3GOM.js → chunk-CFJFUVX2.js} +18 -1
  161. package/dist/cli/{chunk-6YCA5NKJ.js → chunk-DP2VH7CO.js} +12 -12
  162. package/dist/cli/{chunk-AWJPDPMA.mjs → chunk-DP64MD6U.mjs} +1 -1
  163. package/dist/cli/{chunk-PTVD2GVQ.mjs → chunk-DZA7RFGL.mjs} +5 -5
  164. package/dist/cli/{chunk-V436Z54K.js → chunk-E2G2DNAB.js} +3 -1
  165. package/dist/cli/{chunk-GGGAEVCX.mjs → chunk-E7WZOX2A.mjs} +22 -18
  166. package/dist/cli/{chunk-IDVVIXPJ.js → chunk-FM7LPUPA.js} +41 -41
  167. package/dist/cli/{chunk-AQWQ2BFX.mjs → chunk-GAVZ4EOD.mjs} +1 -1
  168. package/dist/cli/{chunk-GKYAYLRI.js → chunk-HEBO3XNZ.js} +27 -31
  169. package/dist/cli/{chunk-IYSTRCLX.mjs → chunk-HSJ6X2AQ.mjs} +4 -4
  170. package/dist/cli/{chunk-UPMRIVZB.js → chunk-HVI55MTK.js} +61 -10
  171. package/dist/cli/{chunk-KWSH5T7K.js → chunk-IH6GDNKW.js} +21 -21
  172. package/dist/cli/{chunk-HO3XK3R7.js → chunk-IMX7J4DU.js} +8 -8
  173. package/dist/cli/{chunk-EUPVF4SU.mjs → chunk-INEMTYMT.mjs} +8 -8
  174. package/dist/cli/{chunk-3FD5EQ62.js → chunk-IUOGII7D.js} +6 -7
  175. package/dist/cli/{chunk-U7QRMBIY.mjs → chunk-JJGWHITQ.mjs} +5 -5
  176. package/dist/cli/{chunk-SHLFOPD6.js → chunk-JLGP5XAJ.js} +5 -5
  177. package/dist/cli/{chunk-4TALT2M3.mjs → chunk-LFOERUQY.mjs} +69 -3
  178. package/dist/cli/{chunk-BBTKAASQ.js → chunk-LFQJW4S2.js} +42 -1
  179. package/dist/cli/{chunk-Z5TSLLOW.mjs → chunk-LH5PZKER.mjs} +63 -18
  180. package/dist/cli/{chunk-S46HWQKO.js → chunk-LRDHPOZW.js} +69 -69
  181. package/dist/cli/{chunk-6ZORHRKB.mjs → chunk-LRZGS6RZ.mjs} +2 -0
  182. package/dist/cli/{chunk-SL6MYJYM.js → chunk-MJTVX4QK.js} +35 -35
  183. package/dist/cli/{chunk-7IKQKKNX.js → chunk-MLABYI4M.js} +90 -24
  184. package/dist/cli/{chunk-ZIAXDBXX.mjs → chunk-NDNHYONK.mjs} +17 -21
  185. package/dist/cli/{chunk-YLTMXJFC.mjs → chunk-OTV2UUKW.mjs} +158 -16
  186. package/dist/cli/{chunk-G4O75EXF.js → chunk-Q6Z6N3A7.js} +18 -18
  187. package/dist/cli/{chunk-WE5HES3H.mjs → chunk-QG6JIWUL.mjs} +151 -43
  188. package/dist/cli/{chunk-QY3ZNU6Z.mjs → chunk-QI5S5HWB.mjs} +2 -2
  189. package/dist/cli/{chunk-CBV7AKWM.js → chunk-R6DZ6NQ2.js} +5 -5
  190. package/dist/cli/{chunk-57VZVF5D.mjs → chunk-RMNOZKRI.mjs} +3 -3
  191. package/dist/cli/{chunk-BAIST2BR.js → chunk-RTV4RF7N.js} +36 -36
  192. package/dist/cli/{chunk-JWUAX6OP.js → chunk-SBH4CKPN.js} +11 -11
  193. package/dist/cli/{chunk-FTJLJCE5.mjs → chunk-SG3LUONJ.mjs} +3 -3
  194. package/dist/cli/{chunk-2WFPHBR4.js → chunk-TFEXSHPM.js} +22 -18
  195. package/dist/cli/{chunk-QAORXEY3.mjs → chunk-TN4TY6TT.mjs} +6 -7
  196. package/dist/cli/{chunk-WEHCBH5R.mjs → chunk-UEVKMZLR.mjs} +54 -3
  197. package/dist/cli/{chunk-QILKGXYF.mjs → chunk-UVQJYV76.mjs} +2 -2
  198. package/dist/cli/{chunk-FSIVF2SI.mjs → chunk-VZGLIK5U.mjs} +1 -1
  199. package/dist/cli/{chunk-MF2GHZDO.js → chunk-WOCHZCUJ.js} +2 -2
  200. package/dist/cli/{chunk-VQALXEXO.js → chunk-XLIHTJVM.js} +348 -118
  201. package/dist/cli/{chunk-ADRC5I3R.js → chunk-Y6SP3JMI.js} +22 -22
  202. package/dist/cli/{chunk-77AAAGVB.js → chunk-YUA6HA6D.js} +2 -2
  203. package/dist/cli/{chunk-JL2OTMSG.mjs → chunk-Z3A2S3QM.mjs} +41 -0
  204. package/dist/cli/{chunk-6O5HOODW.mjs → chunk-Z6XPSHKM.mjs} +87 -41
  205. package/dist/cli/{chunk-QX7LFGJR.mjs → chunk-Z7AOIHFE.mjs} +1870 -91
  206. package/dist/cli/command-docs.js +3 -3
  207. package/dist/cli/command-docs.mjs +2 -2
  208. package/dist/cli/concurrent-runs-help-CFJH4KXV.js +22 -0
  209. package/dist/cli/{concurrent-runs-help-Q4KPAUJX.mjs → concurrent-runs-help-DNV2X5AZ.mjs} +9 -8
  210. package/dist/cli/{csv-F5VAGX4K.js → csv-SA6ELJY6.js} +16 -15
  211. package/dist/cli/{csv-2PTVDNO6.mjs → csv-ZXZGHWOM.mjs} +7 -6
  212. package/dist/cli/{db-IEDXAUF7.mjs → db-A54SP6AD.mjs} +16 -16
  213. package/dist/cli/{db-Z3OIUFMM.js → db-JHFEIQBU.js} +43 -43
  214. package/dist/cli/describe-PHQ33AGS.mjs +50 -0
  215. package/dist/cli/describe-RHJ4XRFI.js +50 -0
  216. package/dist/cli/describe-core.d.mts +3 -3
  217. package/dist/cli/describe-core.d.ts +3 -3
  218. package/dist/cli/describe-core.js +6 -6
  219. package/dist/cli/describe-core.mjs +5 -5
  220. package/dist/cli/{executions-R3LP74QN.mjs → executions-HL2M2DFU.mjs} +10 -10
  221. package/dist/cli/{executions-H6H5655J.js → executions-TLFZRHBJ.js} +12 -12
  222. package/dist/cli/{feedback-VFOUR66B.js → feedback-5UEX5UZK.js} +17 -16
  223. package/dist/cli/{feedback-WL3MRVT5.mjs → feedback-QMBTNXVG.mjs} +9 -8
  224. package/dist/cli/git-4JWOOHBG.js +26 -0
  225. package/dist/cli/{git-YX2J4GCI.mjs → git-LKGXVIVC.mjs} +8 -7
  226. package/dist/cli/index.js +170 -158
  227. package/dist/cli/index.mjs +60 -48
  228. package/dist/cli/{integrations-E2JZYKHS.js → integrations-6RUTLMN7.js} +23 -27
  229. package/dist/cli/{integrations-5ZK5KLVP.mjs → integrations-FGGRVUJ7.mjs} +15 -19
  230. package/dist/cli/{legacy-noops-3VW4IJTH.js → legacy-noops-J3Z7QRWZ.js} +12 -11
  231. package/dist/cli/{legacy-noops-SMN3GSXY.mjs → legacy-noops-YIPRMVXZ.mjs} +9 -8
  232. package/dist/cli/{mcp-UQV2K4EW.js → mcp-6LWFP7RW.js} +121 -48
  233. package/dist/cli/{mcp-V6MGCYAG.mjs → mcp-CHDYFO7F.mjs} +100 -27
  234. package/dist/cli/{monitors-R3BBDCRC.js → monitors-STM6A7OU.js} +221 -186
  235. package/dist/cli/{monitors-GGKS5W6M.mjs → monitors-UGRY2BXI.mjs} +58 -23
  236. package/dist/cli/org-3SYOUQCX.mjs +2289 -0
  237. package/dist/cli/org-ZOBSNSIB.js +2289 -0
  238. package/dist/cli/outcomes-H4YYAT5X.js +2865 -0
  239. package/dist/cli/outcomes-Z3P2JE67.mjs +2865 -0
  240. package/dist/cli/{play-2MVO27VO.js → play-SM4CW2GS.js} +1116 -846
  241. package/dist/cli/{play-MDWPR4XG.mjs → play-SN5YWLS7.mjs} +375 -105
  242. package/dist/cli/{providers-AKDYFZJZ.mjs → providers-WZ4YBR5Y.mjs} +10 -10
  243. package/dist/cli/{providers-2AACRUZH.js → providers-WZARYMCF.js} +13 -13
  244. package/dist/cli/{quickstart-QDGRJFZY.mjs → quickstart-2575BNKA.mjs} +7 -6
  245. package/dist/cli/{quickstart-H6IV3PV3.js → quickstart-PS4YHQJ6.js} +9 -8
  246. package/dist/cli/{run-2634REDK.js → run-FLZ6OTM7.js} +51 -51
  247. package/dist/cli/{run-RTSQNGRD.mjs → run-ZUHCZOJS.mjs} +31 -31
  248. package/dist/cli/run-identity-LMLFMACS.js +31 -0
  249. package/dist/cli/{run-identity-MRNCEGV2.mjs → run-identity-MAZ7ANH5.mjs} +9 -3
  250. package/dist/cli/{search-6AOJ4XPP.mjs → search-HLPPKQEO.mjs} +11 -11
  251. package/dist/cli/search-JJWVHR3N.js +32 -0
  252. package/dist/cli/{search-output-6ADMTOU5.mjs → search-output-PDAXNOGP.mjs} +9 -8
  253. package/dist/cli/{search-output-S5ODBL5E.js → search-output-RXJLU36B.js} +12 -11
  254. package/dist/cli/{secrets-TFIFBFB3.mjs → secrets-CGELYQ3H.mjs} +11 -11
  255. package/dist/cli/{secrets-LHCIIHMT.js → secrets-QJNG7G2Y.js} +20 -20
  256. package/dist/cli/sessions-DHTBT2GN.js +23 -0
  257. package/dist/cli/{sessions-WHBVUHVW.mjs → sessions-ELMWVR4M.mjs} +9 -8
  258. package/dist/cli/{settings-CP4FVK2W.js → settings-44I44P5F.js} +89 -89
  259. package/dist/cli/{settings-EBONWL5C.mjs → settings-RR3LZXL7.mjs} +16 -16
  260. package/dist/cli/{setup-I5AZE3IU.mjs → setup-KGWRWH4B.mjs} +20 -19
  261. package/dist/cli/{setup-LFGHTNLQ.js → setup-KTEYOCJO.js} +60 -59
  262. package/dist/cli/skills-EPZPEXI2.js +37 -0
  263. package/dist/cli/{skills-W76AO5XE.mjs → skills-FPRID2I5.mjs} +10 -9
  264. package/dist/cli/tools-IGQQ5TML.js +57 -0
  265. package/dist/cli/{tools-7IJHGF6W.mjs → tools-PI4WMDLY.mjs} +23 -23
  266. package/dist/cli/update-4RNCVYGE.js +37 -0
  267. package/dist/cli/{update-GFOPZTHY.mjs → update-VJOJAZ7B.mjs} +14 -11
  268. package/dist/cli/{views-BPL2TQJ4.js → views-NTUOLNQU.js} +62 -64
  269. package/dist/cli/{views-D4NX4SBG.mjs → views-OVPSINZO.mjs} +47 -49
  270. package/dist/cli/{workflow-ZYNAUCKC.js → workflow-2UDYDM6F.js} +23 -23
  271. package/dist/cli/{workflow-YXP42FUI.mjs → workflow-7OEFNXZC.mjs} +13 -13
  272. package/dist/{client-CyXGrO4D.d.mts → client-B8f7RNF8.d.mts} +1 -1
  273. package/dist/{client-Bf3IpUKN.d.ts → client-C5TgXmJQ.d.ts} +1 -1
  274. package/dist/{client-core-BxsLnXlm.d.mts → client-core-SLLGBTht.d.mts} +268 -23
  275. package/dist/{client-core-BWd0lX0Z.d.ts → client-core-p0sOxnkl.d.ts} +268 -23
  276. package/dist/{compiler-manifest-BqwVrOri.d.ts → compiler-manifest-D_zZEh9Q.d.mts} +70 -5
  277. package/dist/{compiler-manifest-BqwVrOri.d.mts → compiler-manifest-D_zZEh9Q.d.ts} +70 -5
  278. package/dist/{errors-BU8FB99X.d.mts → errors-CZCrBFrQ.d.mts} +1 -1
  279. package/dist/{errors-DfVN_FUG.d.ts → errors-DsUkLrdZ.d.ts} +1 -1
  280. package/dist/{index-BGnvtYGc.d.ts → index-B6RTOZGC.d.ts} +1 -1
  281. package/dist/{index-DjZgwpGw.d.mts → index-DeOVrEmX.d.mts} +1 -1
  282. package/dist/index.d.mts +7 -7
  283. package/dist/index.d.ts +7 -7
  284. package/dist/index.js +66 -55
  285. package/dist/index.mjs +25 -14
  286. package/dist/install-integrity.json +161 -142
  287. package/dist/plays/bundle-play-file.d.mts +3 -3
  288. package/dist/plays/bundle-play-file.d.ts +3 -3
  289. package/dist/plays/bundle-play-file.mjs +23 -4
  290. package/dist/plays/csv-data-input.js +3 -3
  291. package/dist/plays/csv-data-input.mjs +2 -2
  292. package/dist/plays/play-description.d.mts +2 -2
  293. package/dist/plays/play-description.d.ts +2 -2
  294. package/dist/plays/run-request.d.mts +2 -2
  295. package/dist/plays/run-request.d.ts +2 -2
  296. package/dist/plays/run-request.js +4 -4
  297. package/dist/plays/run-request.mjs +3 -3
  298. package/dist/release.d.mts +1 -1
  299. package/dist/release.d.ts +1 -1
  300. package/dist/release.js +2 -2
  301. package/dist/release.mjs +1 -1
  302. package/dist/server.d.mts +4 -4
  303. package/dist/server.d.ts +4 -4
  304. package/dist/server.js +15 -13
  305. package/dist/server.mjs +9 -7
  306. package/package.json +1 -1
  307. package/dist/cli/auth-MMNVWATX.js +0 -43
  308. package/dist/cli/concurrent-runs-help-FQAIHKKC.js +0 -21
  309. package/dist/cli/describe-QDANCTS3.mjs +0 -50
  310. package/dist/cli/describe-VUTT5ZKU.js +0 -50
  311. package/dist/cli/git-ETB3GH3K.js +0 -25
  312. package/dist/cli/org-GRYVMNSW.js +0 -1282
  313. package/dist/cli/org-Z37NGJV4.mjs +0 -1282
  314. package/dist/cli/run-identity-G257GQED.js +0 -25
  315. package/dist/cli/search-VTW2YNBS.js +0 -32
  316. package/dist/cli/sessions-CJ4FJ2WB.js +0 -22
  317. package/dist/cli/skills-R7EBXREW.js +0 -36
  318. package/dist/cli/tools-V7U2BDXM.js +0 -57
  319. package/dist/cli/update-4COPZETK.js +0 -34
@@ -198,6 +198,9 @@ import {
198
198
  } from '../log-provenance';
199
199
  import {
200
200
  buildRunLedgerEventsIdempotencyKey,
201
+ isRunLedgerDeliveryPrefixFacts,
202
+ RUN_LEDGER_PROJECTION_PREFIX_DEFAULT_FACTS,
203
+ RUN_LEDGER_TERMINAL_BACKLOG_PREFIX_MAX_FACTS,
201
204
  RunLedgerProgressAttemptSupersededError,
202
205
  RunLedgerProjectionLeaseLostError,
203
206
  type RunLedgerProjectionChunk,
@@ -512,9 +515,13 @@ const POSTGRES_SCHEDULER_TERMINAL_COMPUTE_BILLING_BACKFILL_INDEX =
512
515
  'runtime_scheduler_terminal_compute_billing_backfill_idx';
513
516
  const POSTGRES_SCHEDULER_TERMINAL_COMPUTE_BILLING_BACKFILL_CONTROL_KEY =
514
517
  'terminal_compute_billing_outbox_backfill_v1';
518
+ /**
519
+ * One artifact fetch per revision per worker. `claim` names the run attempt
520
+ * whose executor token authorized the fetch.
521
+ */
515
522
  const postgresSchedulerArtifactCache = new Map<
516
523
  string,
517
- Promise<StoredPlayArtifactPayload>
524
+ { claim: string; load: Promise<StoredPlayArtifactPayload> }
518
525
  >();
519
526
 
520
527
  export type PostgresSchedulerQueryClient = {
@@ -769,6 +776,11 @@ export type PostgresSchedulerRunStatusSnapshot = {
769
776
  orgId: string;
770
777
  /** Included only for callers that explicitly request admission identity. */
771
778
  definitionScope?: 'org' | 'system';
779
+ /**
780
+ * The run's team from its signed launch authority, included only when
781
+ * requested; null is the org's default team.
782
+ */
783
+ teamId?: string | null;
772
784
  status: string;
773
785
  /** Immutable log-store marker from the org-owned scheduler run row. */
774
786
  runLogStore?: 'planet_scale';
@@ -801,6 +813,7 @@ type RunStatusRow = RunRow & {
801
813
  runtime_profile: string | null;
802
814
  launch_json: unknown;
803
815
  definition_scope?: string | null;
816
+ team_id?: string | null;
804
817
  created_projection_pending?: boolean;
805
818
  suspension_json: unknown | null;
806
819
  updated_at: Date | null;
@@ -15503,6 +15516,163 @@ export async function approvePostgresSchedulerComputeBillingReconciliation(
15503
15516
  return requeued.rows.length > 0;
15504
15517
  }
15505
15518
 
15519
+ /**
15520
+ * Make one unleased, unsettled obligation whose recorded failures all name
15521
+ * `signature` due for the normal controller now: a quarantine becomes an
15522
+ * ordinary retry (its reason kept in last_error), and a waiting retry or
15523
+ * session bootstrap loses its backoff. Returns the failure count to compare a
15524
+ * later failure against, or null when the row no longer qualifies. Only the
15525
+ * Preview unpayable-billing recovery calls this.
15526
+ */
15527
+ export async function nudgePostgresSchedulerComputeBillingRefusal(
15528
+ client: PostgresSchedulerQueryClient,
15529
+ input: { runId: string; signature: string; reason: string },
15530
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
15531
+ ): Promise<{ failureCount: number } | null> {
15532
+ if (!input.signature.trim() || !input.reason.trim())
15533
+ throw new Error('Compute billing nudge requires a signature and reason.');
15534
+ const nudged = await client.query<{ failure_count: number }>(
15535
+ `
15536
+ UPDATE ${tableName('compute_billing_jobs_v2', options)} AS job
15537
+ SET last_error = CASE
15538
+ WHEN job.blocked_at IS NOT NULL
15539
+ THEN left($3 || ': ' || coalesce(job.block_reason, ''), 4000)
15540
+ ELSE job.last_error
15541
+ END,
15542
+ blocked_at = NULL,
15543
+ block_reason = NULL,
15544
+ -- Retained workers read only available_at; a pending session
15545
+ -- bootstrap stays behind its own retry clock (see the claim).
15546
+ available_at = CASE
15547
+ WHEN job.session_bootstrap_approved_at IS NOT NULL
15548
+ AND job.session_bootstrap_completed_at IS NULL
15549
+ THEN 'infinity'::timestamptz
15550
+ ELSE clock_timestamp()
15551
+ END,
15552
+ session_bootstrap_retry_at = CASE
15553
+ WHEN job.session_bootstrap_approved_at IS NOT NULL
15554
+ AND job.session_bootstrap_completed_at IS NULL
15555
+ THEN clock_timestamp()
15556
+ ELSE job.session_bootstrap_retry_at
15557
+ END,
15558
+ updated_at = clock_timestamp()
15559
+ WHERE job.run_id = $1
15560
+ AND job.status = 'pending'
15561
+ AND job.lease_owner IS NULL
15562
+ AND job.failure_count > 0
15563
+ AND position($2 in coalesce(job.last_error, '')) > 0
15564
+ AND (job.block_reason IS NULL OR position($2 in job.block_reason) > 0)
15565
+ RETURNING job.failure_count
15566
+ `,
15567
+ [input.runId, input.signature, input.reason],
15568
+ );
15569
+ const row = nudged.rows[0];
15570
+ return row ? { failureCount: row.failure_count } : null;
15571
+ }
15572
+
15573
+ /**
15574
+ * Retire one unsettled Preview obligation without posting anything: it is
15575
+ * marked settled with its reason and last failure kept in last_error (a real
15576
+ * settlement clears last_error). Two proofs, each checked in this statement:
15577
+ *
15578
+ * - `refused_again`: the obligation's newest compute (job creation, the run's
15579
+ * last ending, its attempts' last writes) is at least `minAgeHours` old, a
15580
+ * failure newer than `afterFailureCount` was recorded, and it, like every
15581
+ * recorded failure, names `signature`;
15582
+ * - `org`: the run belongs to `orgId` (a finished merge-queue attempt's own
15583
+ * workspace, whose deployment no successor resumes).
15584
+ *
15585
+ * A live lease, an unfinished run, or a changed row leaves it untouched.
15586
+ */
15587
+ export async function retirePostgresSchedulerComputeBillingObligation(
15588
+ client: PostgresSchedulerQueryClient,
15589
+ input: {
15590
+ runId: string;
15591
+ reason: string;
15592
+ proof:
15593
+ | {
15594
+ kind: 'refused_again';
15595
+ signature: string;
15596
+ afterFailureCount: number;
15597
+ minAgeHours: number;
15598
+ }
15599
+ | { kind: 'org'; orgId: string };
15600
+ },
15601
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
15602
+ ): Promise<boolean> {
15603
+ if (!input.reason.trim())
15604
+ throw new Error('Compute billing retirement requires a reason.');
15605
+ const proof = input.proof;
15606
+ if (
15607
+ proof.kind === 'refused_again' &&
15608
+ (!proof.signature.trim() ||
15609
+ !Number.isInteger(proof.minAgeHours) ||
15610
+ proof.minAgeHours < 1)
15611
+ )
15612
+ throw new Error(
15613
+ 'A refused-again retirement requires a signature and a minimum age of at least one hour.',
15614
+ );
15615
+ const retired = await client.query<{ run_id: string }>(
15616
+ `
15617
+ UPDATE ${tableName('compute_billing_jobs_v2', options)} AS job
15618
+ SET status = 'settled',
15619
+ settled_at = clock_timestamp(),
15620
+ lease_owner = NULL,
15621
+ lease_expires_at = NULL,
15622
+ blocked_at = NULL,
15623
+ block_reason = NULL,
15624
+ last_error = left(
15625
+ 'Retired without charge: ' || $2 || ' Last failure: ' ||
15626
+ coalesce(job.last_error, 'none'),
15627
+ 4000
15628
+ ),
15629
+ updated_at = clock_timestamp()
15630
+ FROM ${tableName('runs', options)} AS run
15631
+ WHERE job.run_id = $1
15632
+ AND run.run_id = job.run_id
15633
+ AND run.status IN ('completed', 'failed', 'cancelled')
15634
+ AND (
15635
+ (job.status = 'pending' AND job.lease_owner IS NULL)
15636
+ OR (job.status = 'settling' AND job.lease_expires_at <= now())
15637
+ )
15638
+ AND CASE $3::text
15639
+ WHEN 'refused_again' THEN
15640
+ -- Reopens (a resumed epoch, a late resource) keep created_at, so
15641
+ -- the current obligation is dated by its newest compute: the
15642
+ -- run's last ending and its attempts' last writes.
15643
+ greatest(
15644
+ job.created_at,
15645
+ coalesce(run.finished_at, job.created_at),
15646
+ coalesce(
15647
+ (
15648
+ SELECT max(attempt.updated_at)
15649
+ FROM ${tableName('attempts', options)} AS attempt
15650
+ WHERE attempt.run_id = job.run_id
15651
+ ),
15652
+ job.created_at
15653
+ )
15654
+ ) <= now() - make_interval(hours => $7::int)
15655
+ AND job.failure_count > $5::integer
15656
+ AND position($4 in coalesce(job.last_error, '')) > 0
15657
+ AND (job.block_reason IS NULL OR position($4 in job.block_reason) > 0)
15658
+ WHEN 'org' THEN run.org_id = $6
15659
+ ELSE false
15660
+ END
15661
+ RETURNING job.run_id
15662
+ `,
15663
+ [
15664
+ input.runId,
15665
+ input.reason,
15666
+ proof.kind,
15667
+ proof.kind === 'refused_again' ? proof.signature : null,
15668
+ proof.kind === 'refused_again' ? proof.afterFailureCount : null,
15669
+ proof.kind === 'org' ? proof.orgId : null,
15670
+ proof.kind === 'refused_again' ? proof.minAgeHours : null,
15671
+ ],
15672
+ );
15673
+ return retired.rows.length > 0;
15674
+ }
15675
+
15506
15676
  /**
15507
15677
  * A leased bootstrap-aware worker records this before it is allowed to expose
15508
15678
  * the settlement retry to retained workers. The update is fenced by the same
@@ -17764,6 +17934,11 @@ export type PostgresSchedulerExecutorAttemptStanding = {
17764
17934
  attemptStatus: string | null;
17765
17935
  /** A newer attempt exists. Assigning one retires every older attempt. */
17766
17936
  superseded: boolean;
17937
+ /**
17938
+ * A stop is queued (`runtime_cancel:<runId>`) and no worker has drained it
17939
+ * yet. Present only when the caller asks for it.
17940
+ */
17941
+ cancellationRequested?: boolean;
17767
17942
  };
17768
17943
 
17769
17944
  /**
@@ -17771,16 +17946,26 @@ export type PostgresSchedulerExecutorAttemptStanding = {
17771
17946
  * fence. It reads the same facts as `runnerProgressAttemptCurrentCondition`
17772
17947
  * but keeps them apart, because only some of them are permanent. Returns null
17773
17948
  * when the run is missing.
17949
+ *
17950
+ * `includeCancellationRequest` also reads whether a stop is queued for the
17951
+ * run. A stop on a claimed run only records that request; the run row turns
17952
+ * `cancelled` after the worker has deleted the sandbox.
17774
17953
  */
17775
17954
  export async function readPostgresSchedulerExecutorAttemptStanding(
17776
17955
  client: PostgresSchedulerQueryClient,
17777
- input: { runId: string; attempt: number | null },
17956
+ input: {
17957
+ runId: string;
17958
+ attempt: number | null;
17959
+ includeCancellationRequest?: boolean;
17960
+ },
17778
17961
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
17779
17962
  ): Promise<PostgresSchedulerExecutorAttemptStanding | null> {
17963
+ const includeCancellationRequest = input.includeCancellationRequest === true;
17780
17964
  const result = await client.query<{
17781
17965
  run_status: string;
17782
17966
  attempt_status: string | null;
17783
17967
  superseded: boolean;
17968
+ cancellation_requested?: boolean;
17784
17969
  }>(
17785
17970
  `
17786
17971
  SELECT run.status AS run_status,
@@ -17790,7 +17975,16 @@ export async function readPostgresSchedulerExecutorAttemptStanding(
17790
17975
  FROM ${tableName('attempts', options)} AS newer_attempt
17791
17976
  WHERE newer_attempt.run_id = run.run_id
17792
17977
  AND newer_attempt.attempt > $2::integer
17793
- ) AS superseded
17978
+ ) AS superseded${
17979
+ includeCancellationRequest
17980
+ ? `,
17981
+ EXISTS (
17982
+ SELECT 1
17983
+ FROM ${tableName('control', options)} AS cancel
17984
+ WHERE cancel.key = 'runtime_cancel:' || run.run_id
17985
+ ) AS cancellation_requested`
17986
+ : ''
17987
+ }
17794
17988
  FROM ${tableName('runs', options)} AS run
17795
17989
  LEFT JOIN ${tableName('attempts', options)} AS attempt
17796
17990
  ON attempt.run_id = run.run_id
@@ -17805,6 +17999,9 @@ export async function readPostgresSchedulerExecutorAttemptStanding(
17805
17999
  runStatus: row.run_status,
17806
18000
  attemptStatus: row.attempt_status ?? null,
17807
18001
  superseded: row.superseded === true,
18002
+ ...(includeCancellationRequest
18003
+ ? { cancellationRequested: row.cancellation_requested === true }
18004
+ : {}),
17808
18005
  };
17809
18006
  }
17810
18007
 
@@ -22580,9 +22777,21 @@ export async function loadPostgresSchedulerStoredArtifact(
22580
22777
  claim: PostgresSchedulerAttemptClaim,
22581
22778
  ): Promise<StoredPlayArtifactPayload> {
22582
22779
  const cacheKey = `${runtimeApiBaseUrlFromLaunch(claim.launch).replace(/\/+$/, '')}\n${claim.launch.artifactStorageKey}`;
22780
+ const claimKey = `${claim.runId}\u0000${claim.attempt}`;
22583
22781
  const cached = postgresSchedulerArtifactCache.get(cacheKey);
22584
22782
  if (cached) {
22585
- return await cached;
22783
+ if (cached.claim === claimKey) return await cached.load;
22784
+ try {
22785
+ return await cached.load;
22786
+ } catch {
22787
+ // Another attempt's token authorized that fetch, so its failure may be
22788
+ // that attempt's alone: the app refuses a run that was cancelled and an
22789
+ // attempt that was replaced. Fetch once more with this claim's token.
22790
+ return await loadArtifactFromAppRuntime(
22791
+ runtimeApiContextFromLaunch(claim.launch),
22792
+ claim.launch.artifactStorageKey,
22793
+ );
22794
+ }
22586
22795
  }
22587
22796
  const load = loadArtifactFromAppRuntime(
22588
22797
  runtimeApiContextFromLaunch(claim.launch),
@@ -22591,7 +22800,7 @@ export async function loadPostgresSchedulerStoredArtifact(
22591
22800
  postgresSchedulerArtifactCache.delete(cacheKey);
22592
22801
  throw error;
22593
22802
  });
22594
- postgresSchedulerArtifactCache.set(cacheKey, load);
22803
+ postgresSchedulerArtifactCache.set(cacheKey, { claim: claimKey, load });
22595
22804
  while (
22596
22805
  postgresSchedulerArtifactCache.size >
22597
22806
  POSTGRES_SCHEDULER_ARTIFACT_CACHE_LIMIT
@@ -22772,12 +22981,22 @@ export async function readPostgresSchedulerRunStatus(
22772
22981
  options?: Pick<PostgresSchedulerOptions, 'schema'> & {
22773
22982
  includeDetails?: boolean;
22774
22983
  includeAdmissionScope?: boolean;
22984
+ /** Read the run's team from its signed launch authority. */
22985
+ includeTeam?: boolean;
22775
22986
  includeCreatedProjectionPending?: boolean;
22776
22987
  },
22777
22988
  ): Promise<PostgresSchedulerRunStatusSnapshot | null> {
22778
- const admissionScopeSelection = options?.includeAdmissionScope
22779
- ? ", scheduler_run.launch_json ->> 'definitionScope' AS definition_scope"
22780
- : '';
22989
+ const admissionScopeSelection = `${
22990
+ options?.includeAdmissionScope
22991
+ ? ", scheduler_run.launch_json ->> 'definitionScope' AS definition_scope"
22992
+ : ''
22993
+ }${
22994
+ options?.includeTeam
22995
+ ? ", scheduler_run.launch_json -> 'runtimeAuthority' ->> 'teamId' AS team_id"
22996
+ : ''
22997
+ }`;
22998
+ const teamFields = (row: { team_id?: string | null }) =>
22999
+ options?.includeTeam ? { teamId: row.team_id?.trim() || null } : {};
22781
23000
  const createdProjectionJoin = options?.includeCreatedProjectionPending
22782
23001
  ? `LEFT JOIN ${tableName('outbox', options)} AS created_event
22783
23002
  ON created_event.run_id = scheduler_run.run_id
@@ -22808,6 +23027,7 @@ export async function readPostgresSchedulerRunStatus(
22808
23027
  | 'started_at'
22809
23028
  | 'finished_at'
22810
23029
  | 'definition_scope'
23030
+ | 'team_id'
22811
23031
  | 'created_projection_pending'
22812
23032
  >
22813
23033
  >(
@@ -22833,6 +23053,7 @@ export async function readPostgresSchedulerRunStatus(
22833
23053
  (row.definition_scope === 'org' || row.definition_scope === 'system')
22834
23054
  ? { definitionScope: row.definition_scope }
22835
23055
  : {}),
23056
+ ...teamFields(row),
22836
23057
  status: row.status,
22837
23058
  ...(row.run_log_store === 'planet_scale'
22838
23059
  ? { runLogStore: 'planet_scale' as const }
@@ -22892,6 +23113,7 @@ export async function readPostgresSchedulerRunStatus(
22892
23113
  (row.definition_scope === 'org' || row.definition_scope === 'system')
22893
23114
  ? { definitionScope: row.definition_scope }
22894
23115
  : {}),
23116
+ ...teamFields(row),
22895
23117
  status: row.status,
22896
23118
  ...(row.run_log_store === 'planet_scale'
22897
23119
  ? { runLogStore: 'planet_scale' as const }
@@ -23136,6 +23358,16 @@ async function appendRunLedgerLiveProgressFact(
23136
23358
  await client.query('BEGIN');
23137
23359
  let accepted: boolean;
23138
23360
  try {
23361
+ // A client read timeout leaves a lock-waiting backend alive through the
23362
+ // pooler. End ingress contention on the server before its caller retries.
23363
+ await client.query(
23364
+ `SELECT set_config('lock_timeout', $1, true),
23365
+ set_config('statement_timeout', $2, true)`,
23366
+ [
23367
+ `${RUNTIME_SCHEDULER_CANCEL_LOCK_TIMEOUT_MS}ms`,
23368
+ `${RUNTIME_SCHEDULER_CANCEL_STATEMENT_TIMEOUT_MS}ms`,
23369
+ ],
23370
+ );
23139
23371
  const run = await client.query<{ run_id: string }>(
23140
23372
  `
23141
23373
  SELECT run_id FROM ${tableName('runs', options)}
@@ -23294,7 +23526,37 @@ function outboxNotFailedSql(alias: string): string {
23294
23526
 
23295
23527
  // A projection receipt has always admitted at most eight ordered outbox facts.
23296
23528
  // Share that existing boundary between its SQL snapshot and prefix validation.
23297
- const RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS = 8;
23529
+ const RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS =
23530
+ RUN_LEDGER_PROJECTION_PREFIX_DEFAULT_FACTS;
23531
+
23532
+ /**
23533
+ * The terminal backlog receipt size a receiver advertised, within this
23534
+ * projector's own bound. Anything else, a newer receiver's larger number
23535
+ * included, keeps the eight-fact receipt every receiver proves.
23536
+ */
23537
+ function runLedgerTerminalBacklogFactsAdvertised(
23538
+ value: unknown,
23539
+ ): number | undefined {
23540
+ if (!isRunLedgerDeliveryPrefixFacts(value)) return undefined;
23541
+ return value;
23542
+ }
23543
+
23544
+ /** Receipts whose size and time a targeted drain's diagnostic line lists. */
23545
+ const RUN_LEDGER_TARGETED_DRAIN_LOGGED_RECEIPTS = 16;
23546
+
23547
+ /** Rows a receiver reads to prove a receipt that names `deliveryPrefixFacts`. */
23548
+ export function runLedgerProjectionProofLimit(
23549
+ deliveryPrefixFacts: number | undefined,
23550
+ ): number {
23551
+ if (deliveryPrefixFacts === undefined)
23552
+ return RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS;
23553
+ if (!isRunLedgerDeliveryPrefixFacts(deliveryPrefixFacts)) {
23554
+ throw new Error(
23555
+ `deliveryPrefixFacts must be an integer from ${RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS + 1} through ${RUN_LEDGER_TERMINAL_BACKLOG_PREFIX_MAX_FACTS}.`,
23556
+ );
23557
+ }
23558
+ return deliveryPrefixFacts;
23559
+ }
23298
23560
 
23299
23561
  /** Read only after the caller proved its terminal outbox delivery lease. */
23300
23562
  export async function readPostgresSchedulerTerminalArrayInputIntent(
@@ -23382,6 +23644,8 @@ export async function assertPostgresRunLedgerDelivery(
23382
23644
  leaseOwner?: string;
23383
23645
  projectedEvents?: readonly AcceptedPlayRunLedgerEvent[];
23384
23646
  projectionChunk?: RunLedgerProjectionChunk;
23647
+ /** Facts in the receipt, named only above the eight every receiver proves. */
23648
+ deliveryPrefixFacts?: number;
23385
23649
  sanitizeExpectedProjectionEvents?: (
23386
23650
  events: readonly PlayRunLedgerIngressEvent[],
23387
23651
  ) => readonly AcceptedPlayRunLedgerEvent[];
@@ -23397,6 +23661,7 @@ async function provePostgresRunLedgerDelivery(
23397
23661
  options?: Pick<PostgresSchedulerOptions, 'schema'>,
23398
23662
  readArrayInputMarker = false,
23399
23663
  ): Promise<boolean> {
23664
+ const proofLimit = runLedgerProjectionProofLimit(input.deliveryPrefixFacts);
23400
23665
  const result = await client.query<{
23401
23666
  event_id: string;
23402
23667
  delivery_key: string;
@@ -23441,7 +23706,7 @@ async function provePostgresRunLedgerDelivery(
23441
23706
  -- Later producer facts cannot belong to this receipt. Do not hydrate their
23442
23707
  -- payloads while proving the current causal prefix; the next lease proves
23443
23708
  -- their own delivery without changing the drain's convergence behavior.
23444
- LIMIT ${RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS}
23709
+ LIMIT ${proofLimit}
23445
23710
  `,
23446
23711
  readArrayInputMarker
23447
23712
  ? [input.runId, input.orgId, tableName('runs', options)]
@@ -23602,7 +23867,7 @@ async function provePostgresRunLedgerDelivery(
23602
23867
  if (
23603
23868
  (terminal && !ingressReceiptStarted) ||
23604
23869
  (ingressReceiptStarted && atStartedPrefixEnd) ||
23605
- prefix.length >= RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS
23870
+ prefix.length >= proofLimit
23606
23871
  ) {
23607
23872
  break;
23608
23873
  }
@@ -23916,6 +24181,8 @@ type RunLedgerOutboxPrefixClaimRow = {
23916
24181
  lag_ms: number | string | null;
23917
24182
  lease_owner?: string | null;
23918
24183
  delivery_frozen?: boolean;
24184
+ /** The claimed receipt's head was a frozen ingress fact before this claim. */
24185
+ frozen_before_claim?: boolean;
23919
24186
  lease_remaining_ms?: number | string | null;
23920
24187
  };
23921
24188
 
@@ -23995,15 +24262,33 @@ function runLedgerOutboxPrefixClaimSql(
23995
24262
  // each row whose delivery batch is being frozen.
23996
24263
  runId !== null ? '$2::text' : undefined,
23997
24264
  );
24265
+ // An attempted ingress receipt is immutable: its receiver re-proves exactly
24266
+ // the frozen rows and refuses any split as a retryable lease loss. Reclaim it
24267
+ // whole, at the size it froze with, whatever this claim's receiver
24268
+ // advertises and whatever limit it asked for. Without this, a projector that
24269
+ // lost the advertisement after the freeze retries the split forever.
24270
+ const reclaimsFrozenIngressReceipt =
24271
+ supportsTerminalBatchMarker && input.searchOnly !== true;
24272
+ const frozenIngressHeadSql = `(head.event_type = ${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents} AND head.delivery_batch_started_at IS NOT NULL)`;
24273
+ // A frozen membership never exceeds the largest receipt any claim takes, so
24274
+ // its head raises the limit to that size; an acknowledgement without a
24275
+ // successor (limit 0) still claims nothing. The limit stays the leading
24276
+ // operand: planner fixtures read the rendered `LIMIT ('n'::integer)`.
24277
+ const claimLimitSql = reclaimsFrozenIngressReceipt
24278
+ ? `$1 + coalesce((SELECT greatest(${RUN_LEDGER_TERMINAL_BACKLOG_PREFIX_MAX_FACTS} - $1, 0) FROM head WHERE $1 > 0 AND ${frozenIngressHeadSql}), 0)`
24279
+ : '$1';
23998
24280
  // Search is locally indexed and acknowledged; it has no remote ingress
23999
24281
  // receipt to freeze. Preserve causal ordering/due/lease checks, but admit
24000
- // its full prefix. Lifecycle ingress prefixes require receiver support.
24282
+ // its full prefix. Lifecycle ingress prefixes require receiver support,
24283
+ // except an already frozen one, which is retained whole.
24001
24284
  const ingressPrefixSql =
24002
24285
  input.searchOnly === true
24003
24286
  ? 'true'
24004
24287
  : supportsTerminalBatchMarker && input.allowIngressPrefix === true
24005
24288
  ? `(head.event_type = ${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents})`
24006
- : 'false';
24289
+ : reclaimsFrozenIngressReceipt
24290
+ ? frozenIngressHeadSql
24291
+ : 'false';
24007
24292
  const findSearchBlockersOnce = seekRunHead && input.searchOnly === true;
24008
24293
  // Only ordinary scoped lifecycle enumeration changes. Its existing limit
24009
24294
  // bounds candidate keys before the original eligibility/fence predicates;
@@ -24012,6 +24297,31 @@ function runLedgerOutboxPrefixClaimSql(
24012
24297
  // Recheck pending/run identity without inviting stale partial-index scans.
24013
24298
  // Predecessor checks share snapshot metadata; bounded keys own live row access.
24014
24299
  const inspectLifecycleCandidates = seekRunHead && input.searchOnly !== true;
24300
+ // A frozen ingress receipt is claimed whole or not at all. A failed or
24301
+ // delayed member would cut the claim short, and a receiver that proves only
24302
+ // that many rows cannot see the frozen row after the cut. Members are the
24303
+ // frozen rows after the head with no unfrozen row before them; the head is
24304
+ // the run's oldest pending lifecycle fact, and lifecycle_facts covers them.
24305
+ const frozenIngressMemberSource = inspectLifecycleCandidates
24306
+ ? 'lifecycle_facts'
24307
+ : tableName('outbox', options);
24308
+ const frozenIngressRunFactSql = (alias: string) =>
24309
+ `${alias}.run_id = head.run_id AND ${pending(alias)}${
24310
+ inspectLifecycleCandidates ? '' : ` AND ${searchLaneSql(alias)} = false`
24311
+ }`;
24312
+ const frozenIngressReceiptBlockedSql = `EXISTS (
24313
+ SELECT 1 FROM ${frozenIngressMemberSource} AS member
24314
+ WHERE ${frozenIngressRunFactSql('member')}
24315
+ AND member.delivery_batch_started_at IS NOT NULL
24316
+ AND (NOT ${outboxNotFailedSql('member')}
24317
+ OR coalesce(member.next_attempt_at, member.created_at) > now())
24318
+ AND NOT EXISTS (
24319
+ SELECT 1 FROM ${frozenIngressMemberSource} AS gap
24320
+ WHERE ${frozenIngressRunFactSql('gap')}
24321
+ AND gap.delivery_batch_started_at IS NULL
24322
+ AND ${runLedgerPositionSql('gap')} < ${runLedgerPositionSql('member')}
24323
+ )
24324
+ )`;
24015
24325
  const claimFactColumnsSql = (alias: string) =>
24016
24326
  `${alias}.event_id, ${alias}.run_id, ${alias}.event_type,
24017
24327
  ${alias}.created_at, ${alias}.failed_at, ${alias}.next_attempt_at,
@@ -24022,7 +24332,13 @@ function runLedgerOutboxPrefixClaimSql(
24022
24332
  const blockingPredecessorSql = (alias: string) => `(
24023
24333
  (${alias}.event_type = ${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents}
24024
24334
  AND NOT (${ingressPrefixSql}))
24025
- OR (${supportsTerminalBatchMarker && input.allowIngressPrefix === true ? `head.delivery_batch_started_at IS NOT NULL AND ${alias}.delivery_batch_started_at IS NULL` : 'false'})
24335
+ OR (${
24336
+ supportsTerminalBatchMarker && input.allowIngressPrefix === true
24337
+ ? `head.delivery_batch_started_at IS NOT NULL AND ${alias}.delivery_batch_started_at IS NULL`
24338
+ : reclaimsFrozenIngressReceipt
24339
+ ? `${frozenIngressHeadSql} AND ${alias}.delivery_batch_started_at IS NULL`
24340
+ : 'false'
24341
+ })
24026
24342
  OR ${alias}.failed_at IS NOT NULL
24027
24343
  OR coalesce(${alias}.next_attempt_at, ${alias}.created_at) > now()
24028
24344
  OR (
@@ -24246,7 +24562,7 @@ function runLedgerOutboxPrefixClaimSql(
24246
24562
  AND ${pending('pending')}
24247
24563
  AND ${searchLaneSql('pending')} = false
24248
24564
  ORDER BY ${runLedgerOrderSql('pending')}
24249
- LIMIT $1
24565
+ LIMIT ${claimLimitSql}
24250
24566
  ) AS prefix
24251
24567
  ), lifecycle_facts AS MATERIALIZED (
24252
24568
  SELECT prefix.* FROM lifecycle_window AS prefix
@@ -24296,7 +24612,18 @@ function runLedgerOutboxPrefixClaimSql(
24296
24612
  OR ${ingressPrefixSql})
24297
24613
  -- Once any ingress prefix was attempted, its receipt is immutable,
24298
24614
  -- including singleton appends whose HTTP/ACK outcome was ambiguous.
24299
- AND (${supportsTerminalBatchMarker && input.allowIngressPrefix === true ? 'head.delivery_batch_started_at IS NULL OR outbox.delivery_batch_started_at IS NOT NULL' : 'true'})
24615
+ AND (${
24616
+ supportsTerminalBatchMarker && input.allowIngressPrefix === true
24617
+ ? 'head.delivery_batch_started_at IS NULL OR outbox.delivery_batch_started_at IS NOT NULL'
24618
+ : reclaimsFrozenIngressReceipt
24619
+ ? `NOT ${frozenIngressHeadSql} OR outbox.delivery_batch_started_at IS NOT NULL`
24620
+ : 'true'
24621
+ })${
24622
+ reclaimsFrozenIngressReceipt
24623
+ ? `
24624
+ AND (CASE WHEN ${frozenIngressHeadSql} THEN NOT ${frozenIngressReceiptBlockedSql} ELSE true END)`
24625
+ : ''
24626
+ }
24300
24627
  AND coalesce(outbox.next_attempt_at, outbox.created_at) <= now()
24301
24628
  AND (
24302
24629
  $3::text IS NULL
@@ -24357,7 +24684,7 @@ function runLedgerOutboxPrefixClaimSql(
24357
24684
  }
24358
24685
  ORDER BY ${runLedgerOrderSql('outbox')}
24359
24686
  FOR UPDATE OF outbox
24360
- LIMIT $1
24687
+ LIMIT ${claimLimitSql}
24361
24688
  ${runId !== null ? ' ) AS candidate\n ' : ''}), ${
24362
24689
  inspectLifecycleCandidates
24363
24690
  ? ''
@@ -24392,6 +24719,8 @@ function runLedgerOutboxPrefixClaimSql(
24392
24719
  outbox.payload_json, outbox.created_at, outbox.lease_owner,
24393
24720
  outbox.delivery_key,
24394
24721
  ${supportsTerminalBatchMarker ? 'outbox.delivery_batch_started_at IS NOT NULL' : 'false'} AS delivery_frozen,
24722
+ -- head is the statement's snapshot, read before this UPDATE froze anything.
24723
+ ${reclaimsFrozenIngressReceipt ? `EXISTS (SELECT 1 FROM head WHERE ${frozenIngressHeadSql})` : 'false'} AS frozen_before_claim,
24395
24724
  (extract(epoch FROM (outbox.lease_expires_at - statement_timestamp())) * 1000)::float8 AS lease_remaining_ms
24396
24725
  )
24397
24726
  ${
@@ -24404,7 +24733,8 @@ function runLedgerOutboxPrefixClaimSql(
24404
24733
  SELECT * FROM (
24405
24734
  SELECT 'claimed'::text AS row_kind,
24406
24735
  event_id, run_id, event_type, payload_json, created_at, lease_owner,
24407
- delivery_key, NULL::float8 AS lag_ms, delivery_frozen, lease_remaining_ms
24736
+ delivery_key, NULL::float8 AS lag_ms, delivery_frozen, frozen_before_claim,
24737
+ lease_remaining_ms
24408
24738
  FROM claimed
24409
24739
  ${
24410
24740
  acknowledgement
@@ -24412,7 +24742,8 @@ function runLedgerOutboxPrefixClaimSql(
24412
24742
  SELECT 'delivered'::text AS row_kind,
24413
24743
  event_id, NULL::text AS run_id, event_type, NULL::jsonb AS payload_json,
24414
24744
  NULL::timestamptz AS created_at, NULL::text AS lease_owner,
24415
- NULL::text AS delivery_key, lag_ms, false AS delivery_frozen, NULL::float8 AS lease_remaining_ms
24745
+ NULL::text AS delivery_key, lag_ms, false AS delivery_frozen,
24746
+ false AS frozen_before_claim, NULL::float8 AS lease_remaining_ms
24416
24747
  FROM notified`
24417
24748
  : ''
24418
24749
  }
@@ -24548,6 +24879,7 @@ async function claimRunLedgerOutboxPrefixInBatch(
24548
24879
  events: PostgresSchedulerOutboxEvent[];
24549
24880
  deliveredRows: RunLedgerOutboxDeliveredRow[];
24550
24881
  freshClaimLease?: RunLedgerFreshClaimLeaseFacts;
24882
+ frozenIngressReceipt?: true;
24551
24883
  transportDelivered?: RunLedgerTransportDelivery;
24552
24884
  transportOwnershipUnconfirmed?: boolean;
24553
24885
  arrayInputStarted?: boolean;
@@ -24823,6 +25155,7 @@ async function claimPostgresSchedulerOutboxPrefix(
24823
25155
  events: PostgresSchedulerOutboxEvent[];
24824
25156
  deliveredRows: RunLedgerOutboxDeliveredRow[];
24825
25157
  freshClaimLease?: RunLedgerFreshClaimLeaseFacts;
25158
+ frozenIngressReceipt?: true;
24826
25159
  }> {
24827
25160
  const requestedLimit = Math.floor(input.limit ?? 1);
24828
25161
  const limit = Number.isFinite(requestedLimit)
@@ -24895,6 +25228,7 @@ function projectRunLedgerOutboxPrefixRows(
24895
25228
  events: PostgresSchedulerOutboxEvent[];
24896
25229
  deliveredRows: RunLedgerOutboxDeliveredRow[];
24897
25230
  freshClaimLease?: RunLedgerFreshClaimLeaseFacts;
25231
+ frozenIngressReceipt?: true;
24898
25232
  transportDelivered?: RunLedgerTransportDelivery;
24899
25233
  transportOwnershipUnconfirmed?: boolean;
24900
25234
  } {
@@ -24956,6 +25290,15 @@ function projectRunLedgerOutboxPrefixRows(
24956
25290
  ),
24957
25291
  }
24958
25292
  : undefined;
25293
+ // An ingress receipt frozen by an earlier claim keeps the size it froze
25294
+ // with. Its sender may name that size to a receiver that did not advertise
25295
+ // it (see the claim). A receipt this claim froze is not marked: its size
25296
+ // stays within what this claim's receiver advertised.
25297
+ const frozenIngressReceipt =
25298
+ claimedRows[0]?.event_type === RUN_SCHEDULER_OUTBOX_EVENT_TYPE.runEvents &&
25299
+ claimedRows.every(
25300
+ (row) => row.delivery_frozen === true && row.frozen_before_claim === true,
25301
+ );
24959
25302
  const transportRows = rows.filter(
24960
25303
  (row) => row.row_kind === 'transport_delivered',
24961
25304
  );
@@ -24963,6 +25306,7 @@ function projectRunLedgerOutboxPrefixRows(
24963
25306
  events,
24964
25307
  deliveredRows,
24965
25308
  ...(freshClaimLease ? { freshClaimLease } : {}),
25309
+ ...(frozenIngressReceipt ? { frozenIngressReceipt: true as const } : {}),
24966
25310
  ...(rows.some((row) => row.row_kind === 'transport_unconfirmed')
24967
25311
  ? { transportOwnershipUnconfirmed: true }
24968
25312
  : {}),
@@ -25068,6 +25412,122 @@ export async function readPostgresSchedulerOutboxNextDueAt(
25068
25412
  return Number.isFinite(parsed.getTime()) ? parsed : null;
25069
25413
  }
25070
25414
 
25415
+ export type PostgresSchedulerOutboxDueRun = {
25416
+ runId: string;
25417
+ searchOnly: boolean;
25418
+ dueAt: Date;
25419
+ /** The lane's causal head is `run.created`. */
25420
+ admission: boolean;
25421
+ };
25422
+
25423
+ /**
25424
+ * One bounded page of pending runs for Bounded Discovery: per run and lane, the
25425
+ * head's next claimable moment, with the same clock as
25426
+ * `readPostgresSchedulerOutboxNextDueAt`. A failed head quarantines its lane
25427
+ * and yields no row, but its run still advances the cursor. `cursor` is null
25428
+ * once enumeration passed the last pending run, so the next page wraps.
25429
+ */
25430
+ export async function readPostgresSchedulerOutboxDueRuns(
25431
+ client: PostgresSchedulerQueryClient,
25432
+ input: { afterRunId?: string | null; limit: number },
25433
+ options?: Pick<PostgresSchedulerOptions, 'schema'>,
25434
+ ): Promise<{
25435
+ rows: PostgresSchedulerOutboxDueRun[];
25436
+ cursor: string | null;
25437
+ }> {
25438
+ if (!Number.isInteger(input.limit) || input.limit < 1) {
25439
+ throw new Error(
25440
+ `Outbox due-runs limit must be a positive integer, got ${input.limit}.`,
25441
+ );
25442
+ }
25443
+ const outbox = tableName('outbox', options);
25444
+ const result = await client.query<{
25445
+ run_id: string;
25446
+ seq: number;
25447
+ search_only: boolean | null;
25448
+ due_at: Date | string | null;
25449
+ admission: boolean | null;
25450
+ }>(
25451
+ `
25452
+ -- Seek distinct run identities after the cursor, at most $2 of them.
25453
+ WITH RECURSIVE pending_runs AS (
25454
+ (SELECT pending.run_id, 1 AS seq
25455
+ FROM ${outbox} AS pending
25456
+ WHERE pending.delivered_at IS NULL AND pending.run_id > $1::text
25457
+ ORDER BY pending.run_id LIMIT 1)
25458
+ UNION ALL
25459
+ SELECT next_run.run_id, previous_run.seq + 1
25460
+ FROM pending_runs AS previous_run
25461
+ CROSS JOIN LATERAL (
25462
+ SELECT pending.run_id
25463
+ FROM ${outbox} AS pending
25464
+ WHERE pending.delivered_at IS NULL
25465
+ AND pending.run_id > previous_run.run_id
25466
+ ORDER BY pending.run_id LIMIT 1
25467
+ ) AS next_run
25468
+ WHERE previous_run.seq < $2::int
25469
+ ), heads AS MATERIALIZED (
25470
+ ${[false, true]
25471
+ .map(
25472
+ (
25473
+ searchOnly,
25474
+ ) => `SELECT pending_run.run_id, ${searchOnly} AS search_only, head.*
25475
+ FROM pending_runs AS pending_run
25476
+ CROSS JOIN LATERAL (
25477
+ SELECT pending.event_type, pending.created_at, pending.next_attempt_at,
25478
+ pending.failed_at, pending.lease_expires_at
25479
+ FROM ${outbox} AS pending
25480
+ WHERE pending.run_id = pending_run.run_id
25481
+ AND pending.delivered_at IS NULL
25482
+ AND ${searchLaneSql('pending')} = ${searchOnly}
25483
+ ORDER BY ${runLedgerOrderSql('pending')}
25484
+ LIMIT 1
25485
+ ) AS head`,
25486
+ )
25487
+ .join('\n UNION ALL\n ')}
25488
+ )
25489
+ SELECT pending_run.run_id, pending_run.seq, candidate.search_only,
25490
+ candidate.event_type = ${RUN_EVENT_KIND_SQL_LITERAL.runCreated} AS admission,
25491
+ greatest(
25492
+ CASE
25493
+ WHEN candidate.lease_expires_at IS NOT NULL AND candidate.lease_expires_at > now()
25494
+ THEN candidate.lease_expires_at
25495
+ ELSE coalesce(candidate.next_attempt_at, candidate.created_at)
25496
+ END,
25497
+ (SELECT max(active.lease_expires_at)
25498
+ FROM ${outbox} AS active
25499
+ WHERE active.run_id = candidate.run_id
25500
+ AND ${searchLaneSql('active')} = candidate.search_only
25501
+ AND active.delivered_at IS NULL AND active.lease_owner IS NOT NULL
25502
+ AND active.lease_expires_at > now())
25503
+ ) AS due_at
25504
+ FROM pending_runs AS pending_run
25505
+ -- Keep quarantined runs as empty rows, so the cursor passes them.
25506
+ LEFT JOIN heads AS candidate
25507
+ ON candidate.run_id = pending_run.run_id AND candidate.failed_at IS NULL
25508
+ ORDER BY pending_run.seq, candidate.search_only
25509
+ `,
25510
+ // Run IDs are non-empty, so '' seeks from the first pending run.
25511
+ [input.afterRunId ?? '', input.limit],
25512
+ );
25513
+ const last = result.rows.at(-1);
25514
+ return {
25515
+ rows: result.rows.flatMap((row) =>
25516
+ row.due_at === null || row.search_only === null
25517
+ ? []
25518
+ : [
25519
+ {
25520
+ runId: row.run_id,
25521
+ searchOnly: row.search_only,
25522
+ dueAt: new Date(row.due_at),
25523
+ admission: row.admission === true,
25524
+ },
25525
+ ],
25526
+ ),
25527
+ cursor: last && Number(last.seq) >= input.limit ? last.run_id : null,
25528
+ };
25529
+ }
25530
+
25071
25531
  /**
25072
25532
  * Read one fact's durable delivery acknowledgement without claiming it. This
25073
25533
  * deliberately performs no gateway request: the dedicated projector is the
@@ -26621,10 +27081,7 @@ export type RunLedgerOutboxDispatchInput = {
26621
27081
  leaseSeconds?: number;
26622
27082
  /** Defaults to the compatible admission-first claim order. */
26623
27083
  headPriority?: RunLedgerOutboxHeadPriority;
26624
- /**
26625
- * Token authority for the outbox dispatch. Defaults to `local_mint` for the
26626
- * app-side authoritative projector. The Fly worker MUST pass `gateway`.
26627
- */
27084
+ /** Defaults to `local_mint`, the app-side projector's authority. */
26628
27085
  tokenAuthority?: RunLedgerOutboxTokenAuthority;
26629
27086
  /**
26630
27087
  * Run-scoped claims only: claim nothing unless this exact event is the
@@ -26768,6 +27225,8 @@ type RunLedgerOutboxDrainScope = {
26768
27225
  targetEventId: string;
26769
27226
  nextClaimed: PostgresSchedulerOutboxEvent[];
26770
27227
  nextArrayInputStarted?: boolean;
27228
+ /** `nextClaimed` is a frozen ingress receipt, retained whole. */
27229
+ nextFrozenIngressReceipt?: true;
26771
27230
  };
26772
27231
 
26773
27232
  type RunLedgerOutboxAuthorityScope = {
@@ -26815,7 +27274,6 @@ async function dispatchRunLedgerOutboxThroughEventWithScope(
26815
27274
  // for a fresh worker drain that did not arrive with a preclaimed prefix.
26816
27275
  scope ??= { runId, leaseOwner, targetEventId, nextClaimed: [] };
26817
27276
  const scopedInput = { ...input, leaseOwner };
26818
- const batchSize = RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS;
26819
27277
  const eventIds: string[] = [];
26820
27278
  const failedEventIds: string[] = [];
26821
27279
  const retryingEventIds: string[] = [];
@@ -26823,10 +27281,38 @@ async function dispatchRunLedgerOutboxThroughEventWithScope(
26823
27281
  let projected = 0;
26824
27282
  let failed = 0;
26825
27283
  let retrying = 0;
27284
+ // Fixed-size diagnostics for the targeted drain: receipts sent, facts and
27285
+ // wall time per receipt (first RUN_LEDGER_TARGETED_DRAIN_LOGGED_RECEIPTS).
27286
+ const drainStartedAtMs = Date.now();
27287
+ const receiptFacts: number[] = [];
27288
+ const receiptMs: number[] = [];
27289
+ let receipts = 0;
27290
+ const logTargetedDrain = (targetDelivered: boolean) => {
27291
+ console.info('[run-ledger-outbox.targeted_drain]', {
27292
+ runId,
27293
+ targetEventId,
27294
+ targetDelivered,
27295
+ receipts,
27296
+ receiptFacts,
27297
+ receiptMs,
27298
+ maxReceiptFacts:
27299
+ authorityScope.authority?.runtimeApi.runLedgerTerminalBacklogFacts ??
27300
+ RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS,
27301
+ drainStartedAtMs,
27302
+ drainDurationMs: Date.now() - drainStartedAtMs,
27303
+ });
27304
+ };
26826
27305
 
26827
27306
  try {
26828
27307
  let remaining = maxEvents;
26829
27308
  while (remaining === null || remaining > 0) {
27309
+ // The first receipt is eight facts. Once the receiver has advertised a
27310
+ // larger terminal backlog receipt, the rest of the backlog ahead of the
27311
+ // target goes in receipts of that size: one Convex commit per receipt.
27312
+ const batchSize =
27313
+ authorityScope.authority?.runtimeApi.runLedgerTerminalBacklogFacts ??
27314
+ RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS;
27315
+ const receiptStartedAtMs = Date.now();
26830
27316
  const result = await dispatchRunLedgerOutboxBatchWithScope(
26831
27317
  withClient,
26832
27318
  {
@@ -26841,6 +27327,13 @@ async function dispatchRunLedgerOutboxThroughEventWithScope(
26841
27327
  authorityScope,
26842
27328
  remaining,
26843
27329
  );
27330
+ if (result.attempted > 0) {
27331
+ receipts += 1;
27332
+ if (receiptFacts.length < RUN_LEDGER_TARGETED_DRAIN_LOGGED_RECEIPTS) {
27333
+ receiptFacts.push(result.attempted);
27334
+ receiptMs.push(Date.now() - receiptStartedAtMs);
27335
+ }
27336
+ }
26844
27337
  attempted += result.attempted;
26845
27338
  projected += result.projected;
26846
27339
  failed += result.failed;
@@ -26850,6 +27343,7 @@ async function dispatchRunLedgerOutboxThroughEventWithScope(
26850
27343
  retryingEventIds.push(...result.retryingEventIds);
26851
27344
  if (remaining !== null) remaining -= result.attempted;
26852
27345
  if (result.eventIds.includes(targetEventId)) {
27346
+ logTargetedDrain(true);
26853
27347
  return {
26854
27348
  attempted,
26855
27349
  projected,
@@ -26881,6 +27375,7 @@ async function dispatchRunLedgerOutboxThroughEventWithScope(
26881
27375
  options,
26882
27376
  ),
26883
27377
  );
27378
+ logTargetedDrain(target.delivered);
26884
27379
  return {
26885
27380
  attempted,
26886
27381
  projected,
@@ -27206,6 +27701,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27206
27701
  launchJson: undefined,
27207
27702
  ingressPrefixClaimed: false,
27208
27703
  freshClaimLease: undefined,
27704
+ frozenIngressReceipt: undefined,
27209
27705
  transportDelivered: undefined,
27210
27706
  transportOwnershipUnconfirmed: undefined,
27211
27707
  };
@@ -27238,6 +27734,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27238
27734
  launchJson: selected.rows[0]?.dispatch_launch_json,
27239
27735
  ingressPrefixClaimed,
27240
27736
  freshClaimLease: result.freshClaimLease,
27737
+ frozenIngressReceipt: result.frozenIngressReceipt,
27241
27738
  transportDelivered: result.transportDelivered,
27242
27739
  transportOwnershipUnconfirmed: result.transportOwnershipUnconfirmed,
27243
27740
  arrayInputStarted: result.arrayInputStarted,
@@ -27270,6 +27767,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27270
27767
  launchJson: unknown;
27271
27768
  ingressPrefixClaimed: boolean;
27272
27769
  freshClaimLease?: RunLedgerFreshClaimLeaseFacts;
27770
+ frozenIngressReceipt?: true;
27273
27771
  transportDelivered?: RunLedgerTransportDelivery;
27274
27772
  transportOwnershipUnconfirmed?: boolean;
27275
27773
  arrayInputStarted?: boolean;
@@ -27337,7 +27835,11 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27337
27835
  },
27338
27836
  options,
27339
27837
  )
27340
- : { events: [], freshClaimLease: undefined };
27838
+ : {
27839
+ events: [],
27840
+ freshClaimLease: undefined,
27841
+ frozenIngressReceipt: undefined,
27842
+ };
27341
27843
  await client.query('COMMIT');
27342
27844
  // The launch is immutable. Carry only its authority/routing fields from
27343
27845
  // the run we already locked, rather than queuing another scarce checkout
@@ -27348,6 +27850,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27348
27850
  launchJson: selected.rows[0]?.dispatch_launch_json,
27349
27851
  ingressPrefixClaimed,
27350
27852
  freshClaimLease: claimed.freshClaimLease,
27853
+ frozenIngressReceipt: claimed.frozenIngressReceipt,
27351
27854
  transportDelivered: undefined,
27352
27855
  transportOwnershipUnconfirmed: undefined,
27353
27856
  arrayInputStarted: undefined,
@@ -27370,6 +27873,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27370
27873
  launchJson: null,
27371
27874
  ingressPrefixClaimed: false,
27372
27875
  freshClaimLease: undefined,
27876
+ frozenIngressReceipt: scope?.nextFrozenIngressReceipt,
27373
27877
  transportDelivered: undefined,
27374
27878
  transportOwnershipUnconfirmed: undefined,
27375
27879
  arrayInputStarted: scope?.nextArrayInputStarted,
@@ -27392,6 +27896,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27392
27896
  launchJson: null,
27393
27897
  ingressPrefixClaimed: false,
27394
27898
  freshClaimLease: undefined,
27899
+ frozenIngressReceipt: undefined,
27395
27900
  transportDelivered: undefined,
27396
27901
  transportOwnershipUnconfirmed: undefined,
27397
27902
  arrayInputStarted: undefined,
@@ -27474,6 +27979,8 @@ async function dispatchRunLedgerOutboxBatchWithScope(
27474
27979
  }
27475
27980
  }
27476
27981
  let events = claimed.events;
27982
+ // Describes `events`; a widened singleton below is a fresh, bounded receipt.
27983
+ let eventsFrozenIngressReceipt = claimed.frozenIngressReceipt === true;
27477
27984
  const searchOnlyTerminalLogCarrier =
27478
27985
  input.searchOnly === true &&
27479
27986
  events.some(
@@ -28079,6 +28586,7 @@ async function dispatchRunLedgerOutboxBatchWithScope(
28079
28586
  );
28080
28587
  }
28081
28588
  events = widened;
28589
+ eventsFrozenIngressReceipt = false;
28082
28590
  prioritizeClaimedTerminal();
28083
28591
  }
28084
28592
  // Widening can add deferred facts to the lease. Project the complete
@@ -28236,6 +28744,13 @@ async function dispatchRunLedgerOutboxBatchWithScope(
28236
28744
  events: ledgerEvents,
28237
28745
  deliveryLeaseOwner: leaseOwner,
28238
28746
  beforeBatch: renewDelivery,
28747
+ // A terminal backlog receipt names its size for the verifier.
28748
+ ...(events.length > RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS
28749
+ ? { deliveryPrefixFacts: events.length }
28750
+ : {}),
28751
+ ...(eventsFrozenIngressReceipt
28752
+ ? { frozenIngressReceipt: true }
28753
+ : {}),
28239
28754
  idempotencyKey: terminal
28240
28755
  ? buildRunLedgerTerminalIdempotencyKey({
28241
28756
  runId: first.runId,
@@ -28716,6 +29231,13 @@ async function acknowledgeRunLedgerPrefixWithContinuation(
28716
29231
  const retainContinuation =
28717
29232
  !!input.scope ||
28718
29233
  (input.input.continueThroughTerminal === true && !input.input.headEventId);
29234
+ // A targeted drain (a run's lifecycle target, its terminal included) takes
29235
+ // the backlog ahead of it in the receiver's advertised receipt size; live
29236
+ // progress keeps eight-fact receipts.
29237
+ const successorReceiptFacts =
29238
+ input.scope && input.runtimeApi?.runLedgerTerminalBacklogFacts !== undefined
29239
+ ? input.runtimeApi.runLedgerTerminalBacklogFacts
29240
+ : RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS;
28719
29241
  return withClient(async (client) => {
28720
29242
  if (retainContinuation) {
28721
29243
  const eventIds = input.events.map((event) => event.eventId);
@@ -28729,12 +29251,11 @@ async function acknowledgeRunLedgerPrefixWithContinuation(
28729
29251
  leaseSeconds: input.input.leaseSeconds ?? 120,
28730
29252
  limit: claimSuccessor
28731
29253
  ? Math.min(
28732
- RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS,
29254
+ successorReceiptFacts,
28733
29255
  input.runtimeApi?.runLedgerIngressPrefixBatching === true
28734
- ? RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS
29256
+ ? successorReceiptFacts
28735
29257
  : (input.input.limit ?? 1),
28736
- input.continuationAllowance ??
28737
- RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS,
29258
+ input.continuationAllowance ?? successorReceiptFacts,
28738
29259
  )
28739
29260
  : 0,
28740
29261
  allowIngressPrefix:
@@ -28759,6 +29280,7 @@ async function acknowledgeRunLedgerPrefixWithContinuation(
28759
29280
  };
28760
29281
  continuation.nextClaimed = fast.events;
28761
29282
  continuation.nextArrayInputStarted = fast.arrayInputStarted;
29283
+ continuation.nextFrozenIngressReceipt = fast.frozenIngressReceipt;
28762
29284
  input.continuation.current = continuation;
28763
29285
  }
28764
29286
  return { deliveredRows: fast.deliveredRows, continuation };
@@ -28786,46 +29308,49 @@ async function acknowledgeRunLedgerPrefixWithContinuation(
28786
29308
  );
28787
29309
  }
28788
29310
  const eventIds = input.events.map((event) => event.eventId);
28789
- const { deliveredRows, events: nextClaimed } =
28790
- retainContinuation &&
28791
- input.continuationAllowance !== 0 &&
28792
- !eventIds.includes(targetEventId)
28793
- ? await claimPostgresSchedulerOutboxPrefix(
29311
+ const {
29312
+ deliveredRows,
29313
+ events: nextClaimed,
29314
+ frozenIngressReceipt: nextFrozenIngressReceipt,
29315
+ } = retainContinuation &&
29316
+ input.continuationAllowance !== 0 &&
29317
+ !eventIds.includes(targetEventId)
29318
+ ? await claimPostgresSchedulerOutboxPrefix(
29319
+ client,
29320
+ {
29321
+ runId,
29322
+ leaseOwner: input.leaseOwner,
29323
+ leaseSeconds: input.input.leaseSeconds ?? 120,
29324
+ limit: Math.min(
29325
+ successorReceiptFacts,
29326
+ input.runtimeApi?.runLedgerIngressPrefixBatching === true
29327
+ ? successorReceiptFacts
29328
+ : (input.input.limit ?? 1),
29329
+ input.continuationAllowance ?? successorReceiptFacts,
29330
+ ),
29331
+ allowIngressPrefix:
29332
+ input.runtimeApi?.runLedgerIngressPrefixBatching === true,
29333
+ },
29334
+ options,
29335
+ {
29336
+ eventIds,
29337
+ targetEventId,
29338
+ createdProjectionWake: input.createdProjectionWake,
29339
+ },
29340
+ )
29341
+ : {
29342
+ deliveredRows: await markPostgresSchedulerOutboxDeliveredRows(
28794
29343
  client,
29344
+ eventIds,
28795
29345
  {
28796
- runId,
29346
+ ...options,
28797
29347
  leaseOwner: input.leaseOwner,
28798
- leaseSeconds: input.input.leaseSeconds ?? 120,
28799
- limit: Math.min(
28800
- RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS,
28801
- input.runtimeApi?.runLedgerIngressPrefixBatching === true
28802
- ? RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS
28803
- : (input.input.limit ?? 1),
28804
- input.continuationAllowance ??
28805
- RUN_LEDGER_PROJECTION_PREFIX_MAX_FACTS,
28806
- ),
28807
- allowIngressPrefix:
28808
- input.runtimeApi?.runLedgerIngressPrefixBatching === true,
28809
- },
28810
- options,
28811
- {
28812
- eventIds,
28813
- targetEventId,
28814
29348
  createdProjectionWake: input.createdProjectionWake,
28815
29349
  },
28816
- )
28817
- : {
28818
- deliveredRows: await markPostgresSchedulerOutboxDeliveredRows(
28819
- client,
28820
- eventIds,
28821
- {
28822
- ...options,
28823
- leaseOwner: input.leaseOwner,
28824
- createdProjectionWake: input.createdProjectionWake,
28825
- },
28826
- ),
28827
- events: [],
28828
- };
29350
+ ),
29351
+ events: [],
29352
+ frozenIngressReceipt: undefined,
29353
+ };
28829
29354
  let continuation: RunLedgerOutboxDrainScope | null = null;
28830
29355
  if (nextClaimed.length > 0) {
28831
29356
  continuation = input.scope ?? {
@@ -28836,6 +29361,7 @@ async function acknowledgeRunLedgerPrefixWithContinuation(
28836
29361
  };
28837
29362
  continuation.nextClaimed = nextClaimed;
28838
29363
  continuation.nextArrayInputStarted = undefined;
29364
+ continuation.nextFrozenIngressReceipt = nextFrozenIngressReceipt;
28839
29365
  input.continuation.current = continuation;
28840
29366
  }
28841
29367
  if (retainContinuation) await client.query('COMMIT');
@@ -29194,6 +29720,7 @@ async function resolvePostgresSchedulerRuntimeApiForRun(
29194
29720
  }
29195
29721
  let executorToken: string;
29196
29722
  let runLedgerIngressPrefixBatching: true | undefined;
29723
+ let runLedgerTerminalBacklogFacts: number | undefined;
29197
29724
  // Only the receiver's own dispatch response proves graph storage. A token
29198
29725
  // minted locally or at admission says nothing about the receiving build.
29199
29726
  let retainedPipelineGraphs: true | undefined;
@@ -29241,6 +29768,8 @@ async function resolvePostgresSchedulerRuntimeApiForRun(
29241
29768
  // Merely targeting an immutable URL never proves receipt support.
29242
29769
  runLedgerIngressPrefixBatching =
29243
29770
  preMintedToken.runLedgerIngressPrefixBatching;
29771
+ runLedgerTerminalBacklogFacts =
29772
+ preMintedToken.runLedgerTerminalBacklogFacts;
29244
29773
  refreshExecutorToken = async () =>
29245
29774
  (await requestRunLedgerDispatchToken(dispatchRequest, true))
29246
29775
  .executorToken;
@@ -29270,6 +29799,8 @@ async function resolvePostgresSchedulerRuntimeApiForRun(
29270
29799
  executorToken = dispatchAuthority.executorToken;
29271
29800
  runLedgerIngressPrefixBatching =
29272
29801
  dispatchAuthority.runLedgerIngressPrefixBatching;
29802
+ runLedgerTerminalBacklogFacts =
29803
+ dispatchAuthority.runLedgerTerminalBacklogFacts;
29273
29804
  retainedPipelineGraphs = dispatchAuthority.retainedPipelineGraphs;
29274
29805
  }
29275
29806
  }
@@ -29282,6 +29813,7 @@ async function resolvePostgresSchedulerRuntimeApiForRun(
29282
29813
  launch.arrayInputTerminalProjectionOrigin !== receiverBaseUrl
29283
29814
  ) {
29284
29815
  runLedgerIngressPrefixBatching = undefined;
29816
+ runLedgerTerminalBacklogFacts = undefined;
29285
29817
  }
29286
29818
  return {
29287
29819
  baseUrl: receiverBaseUrl,
@@ -29289,6 +29821,9 @@ async function resolvePostgresSchedulerRuntimeApiForRun(
29289
29821
  ...(runLedgerIngressPrefixBatching
29290
29822
  ? { runLedgerIngressPrefixBatching }
29291
29823
  : {}),
29824
+ ...(runLedgerTerminalBacklogFacts !== undefined
29825
+ ? { runLedgerTerminalBacklogFacts }
29826
+ : {}),
29292
29827
  ...(retainedPipelineGraphs ? { retainedPipelineGraphs } : {}),
29293
29828
  ...(resolveRetainedPipelineGraphs ? { resolveRetainedPipelineGraphs } : {}),
29294
29829
  vercelProtectionBypassToken: launch.vercelProtectionBypassToken ?? null,
@@ -29438,6 +29973,7 @@ function usableRunLedgerExecutorToken(
29438
29973
  ): {
29439
29974
  executorToken: string;
29440
29975
  runLedgerIngressPrefixBatching?: true;
29976
+ runLedgerTerminalBacklogFacts?: number;
29441
29977
  } | null {
29442
29978
  const token = launch.runLedgerExecutorToken;
29443
29979
  if (!token || typeof token !== 'string') return null;
@@ -29484,12 +30020,20 @@ function usableRunLedgerExecutorToken(
29484
30020
  return null;
29485
30021
  }
29486
30022
  const receiverOrigin = new URL(runtimeApiBaseUrlFromLaunch(launch)).origin;
30023
+ const sameImmutableReceiver =
30024
+ claims.run_ledger_ingress_prefix_origin === receiverOrigin &&
30025
+ isImmutableRuntimeExecutionRecoveryOrigin(receiverOrigin);
30026
+ const terminalBacklogFacts = runLedgerTerminalBacklogFactsAdvertised(
30027
+ claims.run_ledger_terminal_backlog_prefix_facts,
30028
+ );
29487
30029
  return {
29488
30030
  executorToken: token,
29489
- ...(claims.run_ledger_ingress_prefix_origin === receiverOrigin &&
29490
- isImmutableRuntimeExecutionRecoveryOrigin(receiverOrigin)
30031
+ ...(sameImmutableReceiver
29491
30032
  ? { runLedgerIngressPrefixBatching: true as const }
29492
30033
  : {}),
30034
+ ...(sameImmutableReceiver && terminalBacklogFacts !== undefined
30035
+ ? { runLedgerTerminalBacklogFacts: terminalBacklogFacts }
30036
+ : {}),
29493
30037
  };
29494
30038
  } catch {
29495
30039
  return null;
@@ -29510,6 +30054,7 @@ const runLedgerDispatchTokens = new Map<
29510
30054
  token: string;
29511
30055
  expiresAt: number;
29512
30056
  runLedgerIngressPrefixBatching?: true;
30057
+ runLedgerTerminalBacklogFacts?: number;
29513
30058
  retainedPipelineGraphs?: true;
29514
30059
  }
29515
30060
  >();
@@ -29529,6 +30074,7 @@ async function requestRunLedgerDispatchToken(
29529
30074
  reused: boolean;
29530
30075
  cacheKey: string;
29531
30076
  runLedgerIngressPrefixBatching?: true;
30077
+ runLedgerTerminalBacklogFacts?: number;
29532
30078
  retainedPipelineGraphs?: true;
29533
30079
  /** Present only when this call made the request (never for a reused token). */
29534
30080
  responseTrace?: RunLedgerDispatchResponseTrace;
@@ -29564,6 +30110,11 @@ async function requestRunLedgerDispatchToken(
29564
30110
  ...(cached.runLedgerIngressPrefixBatching
29565
30111
  ? { runLedgerIngressPrefixBatching: true as const }
29566
30112
  : {}),
30113
+ ...(cached.runLedgerTerminalBacklogFacts !== undefined
30114
+ ? {
30115
+ runLedgerTerminalBacklogFacts: cached.runLedgerTerminalBacklogFacts,
30116
+ }
30117
+ : {}),
29567
30118
  ...(cached.retainedPipelineGraphs
29568
30119
  ? { retainedPipelineGraphs: true as const }
29569
30120
  : {}),
@@ -29606,6 +30157,7 @@ async function requestRunLedgerDispatchToken(
29606
30157
  return JSON.parse(responseText) as {
29607
30158
  executorToken?: unknown;
29608
30159
  runLedgerIngressPrefixBatching?: unknown;
30160
+ runLedgerTerminalBacklogPrefixFacts?: unknown;
29609
30161
  retainedPipelineGraphs?: unknown;
29610
30162
  error?: unknown;
29611
30163
  code?: unknown;
@@ -29642,6 +30194,14 @@ async function requestRunLedgerDispatchToken(
29642
30194
  const reusablePrefix =
29643
30195
  body.runLedgerIngressPrefixBatching === true &&
29644
30196
  isImmutableRuntimeExecutionRecoveryOrigin(input.receiverBaseUrl);
30197
+ // The receiver answers for its own verifier. Take its terminal backlog
30198
+ // receipt size only with the ingress-prefix advertisement it rides beside.
30199
+ const terminalBacklogFacts =
30200
+ body.runLedgerIngressPrefixBatching === true
30201
+ ? runLedgerTerminalBacklogFactsAdvertised(
30202
+ body.runLedgerTerminalBacklogPrefixFacts,
30203
+ )
30204
+ : undefined;
29645
30205
  // Decode only the lifetime, never an authentication decision: the app
29646
30206
  // validates the signature, run scope, and live delivery lease on append.
29647
30207
  // Opaque/older token formats continue to work without this optimization.
@@ -29668,6 +30228,9 @@ async function requestRunLedgerDispatchToken(
29668
30228
  ...(reusablePrefix
29669
30229
  ? { runLedgerIngressPrefixBatching: true as const }
29670
30230
  : {}),
30231
+ ...(reusablePrefix && terminalBacklogFacts !== undefined
30232
+ ? { runLedgerTerminalBacklogFacts: terminalBacklogFacts }
30233
+ : {}),
29671
30234
  ...(body.retainedPipelineGraphs === true
29672
30235
  ? { retainedPipelineGraphs: true as const }
29673
30236
  : {}),
@@ -29694,6 +30257,9 @@ async function requestRunLedgerDispatchToken(
29694
30257
  ...(body.runLedgerIngressPrefixBatching === true
29695
30258
  ? { runLedgerIngressPrefixBatching: true as const }
29696
30259
  : {}),
30260
+ ...(terminalBacklogFacts !== undefined
30261
+ ? { runLedgerTerminalBacklogFacts: terminalBacklogFacts }
30262
+ : {}),
29697
30263
  ...(body.retainedPipelineGraphs === true
29698
30264
  ? { retainedPipelineGraphs: true as const }
29699
30265
  : {}),