deepline 0.3.88 → 0.3.90

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 (280) hide show
  1. package/contracts/install-commands.json +29 -0
  2. package/dist/bundling-sources/sdk/src/client.ts +652 -39
  3. package/dist/bundling-sources/sdk/src/config.ts +77 -0
  4. package/dist/bundling-sources/sdk/src/http.ts +76 -30
  5. package/dist/bundling-sources/sdk/src/index.ts +10 -0
  6. package/dist/bundling-sources/sdk/src/monitor-fleet-contract.ts +1 -1
  7. package/dist/bundling-sources/sdk/src/pagination.ts +25 -0
  8. package/dist/bundling-sources/sdk/src/play.ts +15 -1
  9. package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +3 -3
  10. package/dist/bundling-sources/sdk/src/release.ts +16 -9
  11. package/dist/bundling-sources/sdk/src/types.ts +106 -4
  12. package/dist/bundling-sources/shared_libs/integration-contracts/AGENTS.md +9 -0
  13. package/dist/bundling-sources/shared_libs/integration-contracts/README.md +3 -0
  14. package/dist/bundling-sources/shared_libs/integration-contracts/index.ts +2 -0
  15. package/dist/bundling-sources/shared_libs/monitors/analytics-install-guides.ts +77 -0
  16. package/dist/bundling-sources/shared_libs/monitors/analytics-public.ts +10 -0
  17. package/dist/bundling-sources/shared_libs/monitors/billing/charges.ts +125 -0
  18. package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +686 -0
  19. package/dist/bundling-sources/shared_libs/monitors/billing/pricing.ts +54 -0
  20. package/dist/bundling-sources/shared_libs/monitors/billing/public-pricing.ts +72 -0
  21. package/dist/bundling-sources/shared_libs/monitors/billing/session.ts +45 -0
  22. package/dist/bundling-sources/shared_libs/monitors/billing/state.ts +454 -0
  23. package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +260 -0
  24. package/dist/bundling-sources/shared_libs/monitors/billing/types.ts +215 -0
  25. package/dist/bundling-sources/shared_libs/monitors/callback-security.ts +333 -0
  26. package/dist/bundling-sources/shared_libs/monitors/cursor-page.ts +42 -0
  27. package/dist/bundling-sources/shared_libs/monitors/deactivation-reasons.ts +16 -0
  28. package/dist/bundling-sources/shared_libs/monitors/framework-managed-payload-fields.ts +71 -0
  29. package/dist/bundling-sources/shared_libs/monitors/generated/provider-monitor-callback-admission-targets.ts +16 -0
  30. package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +270 -0
  31. package/dist/bundling-sources/shared_libs/monitors/inbound-publish-key.ts +39 -0
  32. package/dist/bundling-sources/shared_libs/monitors/inbound-queue.ts +82 -0
  33. package/dist/bundling-sources/shared_libs/monitors/inventory-reconciliation.ts +59 -0
  34. package/dist/bundling-sources/shared_libs/monitors/lifecycle-notifications.ts +471 -0
  35. package/dist/bundling-sources/shared_libs/monitors/org-monitor-limits.ts +1 -1
  36. package/dist/bundling-sources/shared_libs/monitors/package.json +36 -0
  37. package/dist/bundling-sources/shared_libs/monitors/provider-callback-verification.ts +1125 -0
  38. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +305 -0
  39. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-capability.ts +964 -0
  40. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-consumer-health.ts +56 -0
  41. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-errors.ts +131 -0
  42. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-identity-claims.ts +535 -0
  43. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-legacy-aliases.ts +16 -0
  44. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-priority-execution.ts +56 -0
  45. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-public-aliases.ts +28 -0
  46. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-runtime-read-eligibility.ts +38 -0
  47. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-state.ts +122 -0
  48. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-status.ts +10 -0
  49. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +112 -0
  50. package/dist/bundling-sources/shared_libs/monitors/provider-webhook-monitor-runtime.ts +300 -0
  51. package/dist/bundling-sources/shared_libs/monitors/quickstart-prompts.ts +22 -0
  52. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +245 -0
  53. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-message.ts +38 -0
  54. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-ack-probe.ts +94 -0
  55. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +60 -0
  56. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue.ts +60 -0
  57. package/dist/bundling-sources/shared_libs/monitors/snitcher-install-validation.ts +93 -0
  58. package/dist/bundling-sources/shared_libs/monitors/snitcher-ip2company.ts +332 -0
  59. package/dist/bundling-sources/shared_libs/monitors/snitcher-radar.ts +221 -0
  60. package/dist/bundling-sources/shared_libs/monitors/starter-templates.ts +105 -0
  61. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +73 -0
  62. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-integrations.ts +81 -0
  63. package/dist/bundling-sources/shared_libs/monitors/tsconfig.json +10 -0
  64. package/dist/bundling-sources/shared_libs/observability/build-context.ts +13 -0
  65. package/dist/bundling-sources/shared_libs/observability/log-metadata.ts +160 -0
  66. package/dist/bundling-sources/shared_libs/observability/request-context.ts +68 -0
  67. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +654 -0
  68. package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +35 -0
  69. package/dist/bundling-sources/shared_libs/observability/scheduled-work.ts +5 -0
  70. package/dist/bundling-sources/shared_libs/play-data-plane/neon-constants.ts +9 -0
  71. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +272 -0
  72. package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +6 -11
  73. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +135 -12
  74. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +66 -1
  75. package/dist/bundling-sources/shared_libs/play-runtime/async-play-invocation.ts +77 -0
  76. package/dist/bundling-sources/shared_libs/play-runtime/bounceban-batching.ts +137 -0
  77. package/dist/bundling-sources/shared_libs/play-runtime/checkpoint-boundaries.ts +70 -0
  78. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +1159 -166
  79. package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +1 -32
  80. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +103 -0
  81. package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +68 -0
  82. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +103 -0
  83. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +725 -0
  84. package/dist/bundling-sources/shared_libs/play-runtime/default-batch-strategies.ts +20 -1
  85. package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +29 -0
  86. package/dist/bundling-sources/shared_libs/play-runtime/execution-capabilities.ts +29 -0
  87. package/dist/bundling-sources/shared_libs/play-runtime/execution-gateway-invocation-fence.ts +442 -0
  88. package/dist/bundling-sources/shared_libs/play-runtime/execution-protocol.ts +7 -1
  89. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +18 -0
  90. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +9 -0
  91. package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +1 -1
  92. package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +1 -1
  93. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/contracts.ts +66 -0
  94. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/job.ts +145 -0
  95. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/ports.ts +21 -0
  96. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/postgres-store.ts +170 -0
  97. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1322 -0
  98. package/dist/bundling-sources/shared_libs/play-runtime/internal-step-ids.ts +2 -2
  99. package/dist/bundling-sources/shared_libs/play-runtime/lane-retirement-gate.ts +189 -0
  100. package/dist/bundling-sources/shared_libs/play-runtime/launch-source-policy.ts +112 -0
  101. package/dist/bundling-sources/shared_libs/play-runtime/map-execution-frame.ts +8 -0
  102. package/dist/bundling-sources/shared_libs/play-runtime/perf-trace.ts +127 -0
  103. package/dist/bundling-sources/shared_libs/play-runtime/play-artifact-runtime-contract.ts +5 -0
  104. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +24 -1
  105. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/contracts.ts +56 -0
  106. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/index.ts +13 -0
  107. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/job.ts +41 -0
  108. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/ports.ts +17 -0
  109. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/postgres-adapter.ts +54 -0
  110. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/contracts.ts +114 -0
  111. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/engine-suspension.ts +108 -0
  112. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/index.ts +36 -0
  113. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/job.ts +97 -0
  114. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/ports.ts +104 -0
  115. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/postgres-fence-adapter.ts +263 -0
  116. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/worker-terminal-projection.ts +64 -0
  117. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/contracts.ts +29 -0
  118. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/gateway-adapter.ts +56 -0
  119. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/index.ts +15 -0
  120. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/job.ts +65 -0
  121. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/ports.ts +17 -0
  122. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +42 -0
  123. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/index.ts +17 -0
  124. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +142 -0
  125. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +42 -0
  126. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +102 -0
  127. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/contracts.ts +60 -0
  128. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/index.ts +16 -0
  129. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/job.ts +78 -0
  130. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/ports.ts +54 -0
  131. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +71 -0
  132. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-batching-registry.ts +4 -0
  133. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-semantics.ts +28 -0
  134. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +4 -0
  135. package/dist/bundling-sources/shared_libs/play-runtime/receipt-status.ts +5 -8
  136. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +23 -2
  137. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +168 -0
  138. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +1 -1
  139. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +90 -13
  140. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +6 -12
  141. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +68 -0
  142. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +21 -0
  143. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/bundle.ts +0 -1
  144. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +14 -43
  145. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -213
  146. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +201 -0
  147. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +20 -0
  148. package/dist/bundling-sources/shared_libs/play-runtime/runtime-contract.ts +6 -0
  149. package/dist/bundling-sources/shared_libs/play-runtime/runtime-env.ts +12 -0
  150. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +67 -0
  151. package/dist/bundling-sources/shared_libs/play-runtime/runtime-release-environment.ts +2 -0
  152. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-contract.ts +68 -0
  153. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +38 -2
  154. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +108 -0
  155. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +4 -0
  156. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +3 -0
  157. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +37 -1
  158. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +88 -0
  159. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-deploy-task.ts +124 -0
  160. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +68 -0
  161. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +193 -0
  162. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-lifecycle.ts +269 -0
  163. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-suffix.ts +73 -0
  164. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +6642 -0
  165. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +897 -0
  166. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-metrics.ts +120 -0
  167. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +76 -0
  168. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +476 -0
  169. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-heavy-request-admission.ts +47 -0
  170. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +147 -0
  171. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/index.ts +27 -0
  172. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/lazy.ts +50 -0
  173. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +98 -0
  174. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-budget-state.ts +260 -0
  175. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +1416 -0
  176. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +1255 -0
  177. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +942 -0
  178. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +14636 -0
  179. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +888 -0
  180. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +355 -0
  181. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-terminal-transition.ts +46 -0
  182. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +60 -0
  183. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-api-origin.ts +33 -0
  184. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-gateway-health.ts +64 -0
  185. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +835 -0
  186. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +1218 -0
  187. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +207 -0
  188. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-scheduler-schema.ts +10 -0
  189. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-capacity.ts +123 -0
  190. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-launch-read-observability.ts +78 -0
  191. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/submit-admission.ts +169 -0
  192. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/terminal-contract.ts +20 -0
  193. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-queue-metrics.ts +34 -0
  194. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-resource-metrics.ts +249 -0
  195. package/dist/bundling-sources/shared_libs/play-runtime/sheet-attempt-sql.ts +7 -0
  196. package/dist/bundling-sources/shared_libs/play-runtime/step-progress.ts +296 -0
  197. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/native-batch.ts +3 -3
  198. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +20 -1
  199. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +60 -15
  200. package/dist/bundling-sources/shared_libs/play-runtime/tool-execution-outcome.ts +20 -0
  201. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +1 -1
  202. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +1 -1
  203. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +12 -0
  204. package/dist/bundling-sources/shared_libs/play-runtime/vercel-protection.ts +14 -1
  205. package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-storage-contract.ts +165 -0
  206. package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +15 -23
  207. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +169 -0
  208. package/dist/bundling-sources/shared_libs/play-runtime/zerobounce-batching.ts +122 -0
  209. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +8 -3
  210. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +454 -17
  211. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +19 -4
  212. package/dist/bundling-sources/shared_libs/plays/contracts.ts +8 -14
  213. package/dist/bundling-sources/shared_libs/plays/core.ts +11 -6
  214. package/dist/bundling-sources/shared_libs/plays/deployment-status.ts +1 -1
  215. package/dist/bundling-sources/shared_libs/plays/docflow-binding-owner.ts +16 -11
  216. package/dist/bundling-sources/shared_libs/plays/docflow.ts +1 -1
  217. package/dist/bundling-sources/shared_libs/plays/email-status.ts +1 -1
  218. package/dist/bundling-sources/shared_libs/plays/play-grep-search.ts +39 -0
  219. package/dist/bundling-sources/shared_libs/plays/resolve-static-pipeline.ts +1 -1
  220. package/dist/bundling-sources/shared_libs/plays/share/copy.ts +271 -0
  221. package/dist/bundling-sources/shared_libs/plays/share/metrics.ts +140 -0
  222. package/dist/bundling-sources/shared_libs/plays/share/public-read-model.ts +86 -0
  223. package/dist/bundling-sources/shared_libs/plays/share/seo-quality.ts +181 -0
  224. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +658 -0
  225. package/dist/bundling-sources/shared_libs/plays/share/types.ts +197 -0
  226. package/dist/bundling-sources/shared_libs/plays/slack-hitl-timeout-error.ts +37 -0
  227. package/dist/bundling-sources/shared_libs/plays/slug.ts +115 -0
  228. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +50 -15
  229. package/dist/bundling-sources/shared_libs/plays/tool-category-descriptions.ts +2 -2
  230. package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +1 -1
  231. package/dist/bundling-sources/shared_libs/product-notifications/catalog.ts +877 -0
  232. package/dist/bundling-sources/shared_libs/product-notifications/configuration-draft.ts +456 -0
  233. package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +566 -0
  234. package/dist/bundling-sources/shared_libs/product-notifications/content.ts +28 -0
  235. package/dist/bundling-sources/shared_libs/product-notifications/default-policy.ts +60 -0
  236. package/dist/bundling-sources/shared_libs/product-notifications/email.ts +246 -0
  237. package/dist/bundling-sources/shared_libs/product-notifications/evaluation.ts +280 -0
  238. package/dist/bundling-sources/shared_libs/product-notifications/events.ts +433 -0
  239. package/dist/bundling-sources/shared_libs/product-notifications/legacy-slack.ts +80 -0
  240. package/dist/bundling-sources/shared_libs/product-notifications/overflow.ts +18 -0
  241. package/dist/bundling-sources/shared_libs/product-notifications/rolling-limit.ts +24 -0
  242. package/dist/bundling-sources/shared_libs/product-notifications/slack-delivery.ts +624 -0
  243. package/dist/bundling-sources/shared_libs/product-notifications/slack-payload.ts +140 -0
  244. package/dist/bundling-sources/shared_libs/product-notifications/slack-transport.ts +75 -0
  245. package/dist/bundling-sources/shared_libs/product-notifications/workspace.ts +38 -0
  246. package/dist/bundling-sources/shared_libs/runtime-env.ts +12 -0
  247. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +42 -0
  248. package/dist/bundling-sources/shared_libs/security/header-safe-env.ts +35 -0
  249. package/dist/bundling-sources/shared_libs/security/internal-actor.ts +50 -0
  250. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +267 -0
  251. package/dist/bundling-sources/shared_libs/security/slack-sanitize.ts +133 -0
  252. package/dist/cli/getting-started.d.mts +52 -0
  253. package/dist/cli/getting-started.d.ts +52 -0
  254. package/dist/cli/getting-started.js +65 -0
  255. package/dist/cli/getting-started.mjs +36 -0
  256. package/dist/cli/index.d.mts +9 -0
  257. package/dist/cli/index.d.ts +9 -0
  258. package/dist/cli/index.js +1611 -453
  259. package/dist/cli/index.mjs +1596 -447
  260. package/dist/{compiler-manifest-Dbov16F7.d.mts → compiler-manifest-BaJfE-5H.d.mts} +136 -10
  261. package/dist/{compiler-manifest-Dbov16F7.d.ts → compiler-manifest-BaJfE-5H.d.ts} +136 -10
  262. package/dist/index.d.mts +910 -155
  263. package/dist/index.d.ts +910 -155
  264. package/dist/index.js +550 -64
  265. package/dist/index.mjs +550 -64
  266. package/dist/install-integrity.json +193 -4
  267. package/dist/monitor-fleet-contract.d.mts +138 -0
  268. package/dist/monitor-fleet-contract.d.ts +138 -0
  269. package/dist/monitor-fleet-contract.js +404 -0
  270. package/dist/monitor-fleet-contract.mjs +367 -0
  271. package/dist/plays/bundle-play-file.d.mts +8 -3
  272. package/dist/plays/bundle-play-file.d.ts +8 -3
  273. package/dist/plays/bundle-play-file.mjs +100 -20
  274. package/dist/release.d.mts +255 -0
  275. package/dist/release.d.ts +255 -0
  276. package/dist/release.js +215 -0
  277. package/dist/release.mjs +188 -0
  278. package/package.json +23 -4
  279. /package/dist/bundling-sources/shared_libs/{integrations/bettercontact-execution-policy.ts → integration-contracts/bettercontact/execution-policy.ts} +0 -0
  280. /package/dist/bundling-sources/shared_libs/{integrations/theirstack-execution-policy.ts → integration-contracts/theirstack/execution-policy.ts} +0 -0
@@ -6,16 +6,17 @@ import {
6
6
  deleteModalSandboxById,
7
7
  readDetachedModalRuntimeCompletion,
8
8
  } from './backends/modal';
9
+ import {
10
+ readPersistedRuntimeSandboxRef,
11
+ type RuntimeSandboxProviderId,
12
+ type RuntimeSandboxRef,
13
+ } from '../runtime-sandbox-contract';
9
14
  import type { DetachedRunnerSuspension } from '../suspension';
10
15
 
11
- export type RuntimeSandboxProviderId = 'daytona' | 'modal';
12
-
13
- export type RuntimeSandboxRef = {
14
- schemaVersion: 1;
15
- provider: RuntimeSandboxProviderId;
16
- resourceId: string;
17
- routingDomain: string | null;
18
- };
16
+ export type {
17
+ RuntimeSandboxProviderId,
18
+ RuntimeSandboxRef,
19
+ } from '../runtime-sandbox-contract';
19
20
 
20
21
  export type RuntimeSandboxReconciliationAdapter = {
21
22
  provider: RuntimeSandboxProviderId;
@@ -138,41 +139,11 @@ export function runtimeSandboxRefFromSuspension(
138
139
  const storedRef = (suspension as { runtimeSandboxRef?: unknown })
139
140
  .runtimeSandboxRef;
140
141
  if (storedRef !== undefined) {
141
- if (
142
- !storedRef ||
143
- typeof storedRef !== 'object' ||
144
- Array.isArray(storedRef)
145
- ) {
146
- throw new Error('Persisted Runtime Sandbox Ref is not an object.');
147
- }
148
- const candidate = storedRef as Record<string, unknown>;
149
- const resourceId =
150
- typeof candidate.resourceId === 'string'
151
- ? candidate.resourceId.trim()
152
- : '';
153
- const provider = candidate.provider;
154
- const routingDomain = candidate.routingDomain;
155
- if (
156
- candidate.schemaVersion !== 1 ||
157
- (provider !== 'daytona' && provider !== 'modal') ||
158
- !resourceId ||
159
- resourceId !== suspension.sandboxId.trim() ||
160
- (routingDomain !== null && typeof routingDomain !== 'string') ||
161
- (typeof routingDomain === 'string' && !routingDomain.trim()) ||
162
- (suspension.sandboxProvider !== undefined &&
163
- suspension.sandboxProvider !== provider)
164
- ) {
165
- throw new Error(
166
- `Persisted Runtime Sandbox Ref is invalid or inconsistent for sandbox ${suspension.sandboxId}.`,
167
- );
168
- }
169
- return {
170
- schemaVersion: 1,
171
- provider,
172
- resourceId,
173
- routingDomain:
174
- typeof routingDomain === 'string' ? routingDomain.trim() : null,
175
- };
142
+ return readPersistedRuntimeSandboxRef({
143
+ raw: storedRef,
144
+ expectedSandboxId: suspension.sandboxId,
145
+ expectedProvider: suspension.sandboxProvider,
146
+ });
176
147
  }
177
148
  if (
178
149
  suspension.sandboxProvider !== undefined &&
@@ -68,6 +68,7 @@ import {
68
68
  stringifyPostgresJson,
69
69
  } from './postgres-json';
70
70
  import { RECEIPT_STATUS_CODE, receiptStatusFromCode } from './receipt-status';
71
+ import { WORK_RECEIPT_EXECUTION_LOCK_TABLE } from './work-receipt-storage-contract';
71
72
  import {
72
73
  workReceiptClaimableStatusCodes,
73
74
  workReceiptActiveOwnerPredicateSql,
@@ -298,7 +299,6 @@ const dbSessionCache = new Map<string, DbSessionCacheEntry>();
298
299
  const dbSessionInFlight = new Map<string, Promise<CreateDbSessionResponse>>();
299
300
  const postgresPools = new Map<string, CachedRuntimePostgresPool>();
300
301
  const runtimePostgresAdmissions = new Map<string, RuntimePostgresAdmission>();
301
- const runtimeWorkReceiptEnsureCache = new Map<string, Promise<void>>();
302
302
  const runtimeSheetEnsureCache = new Map<
303
303
  string,
304
304
  { expiresAt: number; promise: Promise<void> }
@@ -313,19 +313,6 @@ const APPEND_KEY_SUFFIX_LENGTH = 12;
313
313
  // 60-min alignment fixed. A shorter TTL only causes periodic re-mints (cheap;
314
314
  // the tenant runtime role is long-lived), not run failures.
315
315
  const RUNTIME_DB_SESSION_TTL_SECONDS = 10 * 60;
316
- const RUNTIME_WORK_RECEIPT_LEASE_COLUMNS = [
317
- 'lease_id',
318
- 'lease_owner_run_id',
319
- 'lease_owner_attempt',
320
- 'lease_expires_at',
321
- ] as const;
322
- const RUNTIME_WORK_RECEIPT_FAILURE_KIND_COLUMN = 'failure_kind';
323
- const RUNTIME_WORK_RECEIPT_ERROR_PAYLOAD_COLUMN = 'error_payload';
324
- const RUNTIME_WORK_RECEIPT_SELF_HEAL_COLUMNS = [
325
- ...RUNTIME_WORK_RECEIPT_LEASE_COLUMNS,
326
- RUNTIME_WORK_RECEIPT_FAILURE_KIND_COLUMN,
327
- RUNTIME_WORK_RECEIPT_ERROR_PAYLOAD_COLUMN,
328
- ] as const;
329
316
  const RUNTIME_SHEET_ATTEMPT_COLUMNS = [
330
317
  '_attempt_id',
331
318
  '_attempt_owner_run_id',
@@ -2483,11 +2470,7 @@ function workReceiptTable(session: RuntimePostgresSession): string {
2483
2470
  }
2484
2471
 
2485
2472
  function receiptExecutionLockTable(session: RuntimePostgresSession): string {
2486
- return fqRuntimeTable(session, '_deepline_receipt_execution_locks');
2487
- }
2488
-
2489
- function postgresUrlCacheKey(value: string): string {
2490
- return createHash('sha256').update(value).digest('hex').slice(0, 24);
2473
+ return fqRuntimeTable(session, WORK_RECEIPT_EXECUTION_LOCK_TABLE);
2491
2474
  }
2492
2475
 
2493
2476
  function workReceiptKeyHex(key: string): string {
@@ -2548,134 +2531,6 @@ function mapRuntimeWorkReceiptRow(raw: Record<string, unknown>): WorkReceipt {
2548
2531
  };
2549
2532
  }
2550
2533
 
2551
- function isMissingRuntimeWorkReceiptSelfHealColumnError(
2552
- error: unknown,
2553
- ): boolean {
2554
- if (!error || typeof error !== 'object') {
2555
- return false;
2556
- }
2557
- const code = 'code' in error ? String(error.code) : '';
2558
- const message = 'message' in error ? String(error.message) : '';
2559
- if (code !== '42703' && !/column .* does not exist/i.test(message)) {
2560
- return false;
2561
- }
2562
- return RUNTIME_WORK_RECEIPT_SELF_HEAL_COLUMNS.some((column) =>
2563
- message.includes(column),
2564
- );
2565
- }
2566
-
2567
- function runtimeWorkReceiptEnsureCacheKey(
2568
- session: RuntimePostgresSession,
2569
- ): string {
2570
- return `${postgresUrlCacheKey(session.postgresUrl)}::${session.postgres.schema}::${session.postgres.receiptTable ?? RUNTIME_WORK_RECEIPT_POSTGRES_TABLE}`;
2571
- }
2572
-
2573
- async function missingRuntimeWorkReceiptSelfHealColumns(
2574
- session: RuntimePostgresSession,
2575
- client: RuntimeQueryClient,
2576
- ): Promise<string[]> {
2577
- const result = await client.query(
2578
- `
2579
- SELECT column_name
2580
- FROM information_schema.columns
2581
- WHERE table_schema = $1
2582
- AND table_name = $2
2583
- AND column_name = ANY($3::text[])
2584
- `,
2585
- [
2586
- session.postgres.schema,
2587
- session.postgres.receiptTable ?? RUNTIME_WORK_RECEIPT_POSTGRES_TABLE,
2588
- [...RUNTIME_WORK_RECEIPT_SELF_HEAL_COLUMNS],
2589
- ],
2590
- );
2591
- const present = new Set(
2592
- result.rows.map((row) => String(row.column_name ?? '')),
2593
- );
2594
- return RUNTIME_WORK_RECEIPT_SELF_HEAL_COLUMNS.filter(
2595
- (column) => !present.has(column),
2596
- );
2597
- }
2598
-
2599
- // COMPAT / SELF-HEAL — owner: runtime. Removal milestone: runtime-ledger
2600
- // cutover. The customer-Neon
2601
- // work-receipt table (lease columns + failure_kind) is the dying surface. The
2602
- // F2 rolling migration (scripts/migrate-play-runtime-storage.ts) backfills these
2603
- // columns; this lazy CREATE/ALTER self-heal is a compat-window safety net and is
2604
- // deleted together with the Neon receipt path at M1.
2605
- async function ensureRuntimeWorkReceiptTable(
2606
- session: RuntimePostgresSession,
2607
- client: RuntimeQueryClient,
2608
- ): Promise<void> {
2609
- const cacheKey = runtimeWorkReceiptEnsureCacheKey(session);
2610
- const cached = runtimeWorkReceiptEnsureCache.get(cacheKey);
2611
- if (cached) {
2612
- await cached;
2613
- return;
2614
- }
2615
- const promise = client
2616
- .query(
2617
- `
2618
- CREATE TABLE IF NOT EXISTS ${workReceiptTable(session)} (
2619
- k bytea PRIMARY KEY,
2620
- status smallint NOT NULL DEFAULT 0,
2621
- output jsonb,
2622
- error text,
2623
- error_payload jsonb,
2624
- failure_kind smallint NOT NULL DEFAULT 0,
2625
- run_id text,
2626
- lease_id text,
2627
- lease_owner_run_id text,
2628
- lease_owner_attempt integer,
2629
- lease_expires_at timestamptz,
2630
- updated_at timestamptz NOT NULL DEFAULT now()
2631
- )
2632
- `,
2633
- )
2634
- .then(async () => {
2635
- await client.query(`
2636
- CREATE TABLE IF NOT EXISTS ${receiptExecutionLockTable(session)} (
2637
- k bytea PRIMARY KEY,
2638
- owner_execution_id text NOT NULL,
2639
- expires_at timestamptz NOT NULL,
2640
- updated_at timestamptz NOT NULL DEFAULT now()
2641
- )
2642
- `);
2643
- const missingColumns = await missingRuntimeWorkReceiptSelfHealColumns(
2644
- session,
2645
- client,
2646
- );
2647
- if (missingColumns.length === 0) return;
2648
- await client.query(`
2649
- ALTER TABLE ${workReceiptTable(session)}
2650
- ${missingColumns
2651
- .map((column) => {
2652
- const type =
2653
- column === 'lease_expires_at'
2654
- ? 'timestamptz'
2655
- : column === 'lease_owner_attempt'
2656
- ? 'integer'
2657
- : column === RUNTIME_WORK_RECEIPT_FAILURE_KIND_COLUMN
2658
- ? 'smallint NOT NULL DEFAULT 0'
2659
- : column === RUNTIME_WORK_RECEIPT_ERROR_PAYLOAD_COLUMN
2660
- ? 'jsonb'
2661
- : 'text';
2662
- return `ADD COLUMN IF NOT EXISTS ${column} ${type}`;
2663
- })
2664
- .join(',\n ')}
2665
- `);
2666
- })
2667
- .then(() => undefined);
2668
- runtimeWorkReceiptEnsureCache.set(cacheKey, promise);
2669
- try {
2670
- await promise;
2671
- } catch (error) {
2672
- if (runtimeWorkReceiptEnsureCache.get(cacheKey) === promise) {
2673
- runtimeWorkReceiptEnsureCache.delete(cacheKey);
2674
- }
2675
- throw error;
2676
- }
2677
- }
2678
-
2679
2534
  export async function acquireRuntimeReceiptExecutionLock(
2680
2535
  context: RuntimeApiContext,
2681
2536
  input: {
@@ -2752,13 +2607,10 @@ async function withRuntimeWorkReceiptClient<T>(
2752
2607
  session: RuntimePostgresSession,
2753
2608
  operation: (client: RuntimeQueryClient) => Promise<T>,
2754
2609
  ): Promise<T> {
2755
- // Receipt tables are part of customer Postgres bootstrap, so the hot path
2756
- // should not pay DDL on every fresh runtime isolate. Try the receipt query
2757
- // first, then self-heal once on a missing relation/column. Permission loss
2758
- // during an operational receipt query must fail loud: silently repairing it
2759
- // can let provider work continue after durable receipt persistence is gone.
2760
- // Only the schema-migration branch below may repair ownership before its
2761
- // retry. A genuinely missing schema or second failure also rethrows loudly.
2610
+ // Receipt tables are customer-Postgres bootstrap state. The operation path
2611
+ // never performs DDL or schema repair: a missing table/column is the real
2612
+ // operation failure and must remain visible to the caller. We retry only
2613
+ // transient connection/transport failures, never a semantic SQL error.
2762
2614
  const withClient = async <R>(
2763
2615
  run: (client: RuntimeQueryClient) => Promise<R>,
2764
2616
  ): Promise<R> =>
@@ -2768,8 +2620,6 @@ async function withRuntimeWorkReceiptClient<T>(
2768
2620
  cachePool: !context.disablePostgresPoolCache,
2769
2621
  signal: context.abortSignal,
2770
2622
  });
2771
- let selfHealAttempted = false;
2772
-
2773
2623
  for (
2774
2624
  let attempt = 1;
2775
2625
  attempt <= RUNTIME_WORK_RECEIPT_QUERY_MAX_ATTEMPTS;
@@ -2778,34 +2628,6 @@ async function withRuntimeWorkReceiptClient<T>(
2778
2628
  try {
2779
2629
  return await withClient(operation);
2780
2630
  } catch (error) {
2781
- const missingStorage =
2782
- isMissingRelationError(error) ||
2783
- isMissingRuntimeWorkReceiptSelfHealColumnError(error);
2784
- if (missingStorage && !selfHealAttempted) {
2785
- selfHealAttempted = true;
2786
- runtimeWorkReceiptEnsureCache.delete(
2787
- runtimeWorkReceiptEnsureCacheKey(session),
2788
- );
2789
- try {
2790
- await withClient((client) =>
2791
- ensureRuntimeWorkReceiptTable(session, client),
2792
- );
2793
- } catch (ensureError) {
2794
- if (!isPostgresPermissionDeniedError(ensureError)) {
2795
- throw ensureError;
2796
- }
2797
- runtimeWorkReceiptEnsureCache.delete(
2798
- runtimeWorkReceiptEnsureCacheKey(session),
2799
- );
2800
- await repairRuntimeStorageGrants(context, {
2801
- playName: context.playName?.trim() || session.playName,
2802
- });
2803
- await withClient((client) =>
2804
- ensureRuntimeWorkReceiptTable(session, client),
2805
- );
2806
- }
2807
- continue;
2808
- }
2809
2631
  if (
2810
2632
  attempt >= RUNTIME_WORK_RECEIPT_QUERY_MAX_ATTEMPTS ||
2811
2633
  !isTransientRuntimePostgresOperationError(error)
@@ -3361,8 +3183,8 @@ async function writeRuntimeRows(
3361
3183
  const insertedRowsCte =
3362
3184
  input.mode === 'upsert'
3363
3185
  ? `inserted_rows AS (
3364
- INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index${physicalInsertColumnsSql})
3365
- SELECT _key, 'pending', $4::text, _input_index${physicalInsertValuesSql}
3186
+ INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index, _created_at${physicalInsertColumnsSql})
3187
+ SELECT _key, 'pending', $4::text, _input_index, now()${physicalInsertValuesSql}
3366
3188
  FROM input_rows
3367
3189
  ON CONFLICT (_key) DO UPDATE SET
3368
3190
  _status = 'pending',
@@ -3374,8 +3196,8 @@ async function writeRuntimeRows(
3374
3196
  RETURNING _key
3375
3197
  ),`
3376
3198
  : `inserted_rows AS (
3377
- INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index${physicalInsertColumnsSql})
3378
- SELECT _key, 'pending', $4::text, _input_index${physicalInsertValuesSql}
3199
+ INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index, _created_at${physicalInsertColumnsSql})
3200
+ SELECT _key, 'pending', $4::text, _input_index, now()${physicalInsertValuesSql}
3379
3201
  FROM input_rows
3380
3202
  RETURNING _key
3381
3203
  ),`;
@@ -3660,8 +3482,8 @@ async function prepareRuntimeSheetDatasetRows(
3660
3482
  RETURNING target._key
3661
3483
  ),
3662
3484
  inserted_rows AS (
3663
- INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index, _attempt_id, _attempt_owner_run_id, _attempt_expires_at, _attempt_seq, _write_version, _writer_run_id${input.physicalInsertColumnsSql})
3664
- SELECT _key, 'pending', $4::text, _input_index, $7::text, $8::text, $9::timestamptz, $10::integer, $12::bigint, $4::text${input.physicalInsertValuesSql}
3485
+ INSERT INTO ${sheetTable(session)} (_key, _status, _run_id, _input_index, _attempt_id, _attempt_owner_run_id, _attempt_expires_at, _attempt_seq, _write_version, _writer_run_id, _created_at${input.physicalInsertColumnsSql})
3486
+ SELECT _key, 'pending', $4::text, _input_index, $7::text, $8::text, $9::timestamptz, $10::integer, $12::bigint, $4::text, now()${input.physicalInsertValuesSql}
3665
3487
  FROM input_rows
3666
3488
  ON CONFLICT (_key) DO UPDATE SET
3667
3489
  _status = 'pending',
@@ -3991,9 +3813,9 @@ async function prepareNetNewRuntimeSheetDatasetRows(
3991
3813
  inserted_rows AS (
3992
3814
  INSERT INTO ${sheetTable(session)}
3993
3815
  (_key, _status, _run_id, _input_index, _attempt_id, _attempt_owner_run_id,
3994
- _attempt_expires_at, _attempt_seq, _write_version, _writer_run_id${input.physicalInsertColumnsSql})
3816
+ _attempt_expires_at, _attempt_seq, _write_version, _writer_run_id, _created_at${input.physicalInsertColumnsSql})
3995
3817
  SELECT _key, 'pending', $4::text, _input_index, $5::text, $6::text,
3996
- $7::timestamptz, $8::integer, $9::bigint, $4::text${input.physicalInsertValuesSql}
3818
+ $7::timestamptz, $8::integer, $9::bigint, $4::text, now()${input.physicalInsertValuesSql}
3997
3819
  FROM input_rows
3998
3820
  ON CONFLICT (_key) DO NOTHING
3999
3821
  RETURNING _key
@@ -7047,11 +6869,6 @@ async function completeRuntimeMapRowChunks(
7047
6869
  OR coalesce(target._attempt_owner_run_id, target._run_id) IS DISTINCT FROM $10::text
7048
6870
  )
7049
6871
  )`;
7050
- const sameOwnerTerminalEpochSql = sameOwnerTerminalAttemptEpochSql(
7051
- 'target',
7052
- '$10::text',
7053
- '$12',
7054
- );
7055
6872
  const { rows } = await client.query<{
7056
6873
  updated: number;
7057
6874
  matched_keys: string[];
@@ -7106,6 +6923,15 @@ async function completeRuntimeMapRowChunks(
7106
6923
  target._status <> 'enriched'
7107
6924
  OR (${targetChangedPatchedCellSql})
7108
6925
  )
6926
+ -- First terminal wins: suppress conflict for same owner+epoch already-terminal row.
6927
+ -- Durable replay (omitted_terminal_replay) from same attempt epoch is idempotent.
6928
+ AND NOT (
6929
+ $10::text IS NOT NULL
6930
+ AND $12::integer IS NOT NULL
6931
+ AND target._status = 'enriched'
6932
+ AND coalesce(target._attempt_owner_run_id, target._run_id) = $10::text
6933
+ AND COALESCE(target._attempt_seq, 0) = $12::integer
6934
+ )
7109
6935
  ),
7110
6936
  applied_rows AS (
7111
6937
  UPDATE ${sheetTable(session)} AS target
@@ -7127,13 +6953,21 @@ async function completeRuntimeMapRowChunks(
7127
6953
  AND ($13::bigint IS NULL OR target._write_version = $13::bigint)
7128
6954
  AND ($13::bigint IS NOT NULL OR target._status <> 'enriched')
7129
6955
  AND NOT (${newerTerminalRuntimeSheetRowSql('target', '$11::timestamptz', '$12::integer', '$9::text', '$10::text')})
7130
- AND NOT (${sameOwnerTerminalEpochSql})
7131
6956
  AND (
7132
6957
  ($9::text IS NULL AND target._run_id = $5::text)
7133
6958
  OR ($9::text IS NOT NULL AND ${writableNonTerminalAttemptSql})
7134
6959
  OR ($9::text IS NOT NULL AND ${activeRuntimeSheetAttemptFenceSql('target', '$9::text', '$10::text', '$11::timestamptz', '$12::integer')})
7135
6960
  OR ($9::text IS NOT NULL AND ${writableEnrichedAttemptSql})
7136
6961
  )
6962
+ -- First terminal wins: skip UPDATE for already-terminal same-owner+epoch row.
6963
+ -- Even though we excluded from conflicts, we still no-op here for idempotency.
6964
+ AND NOT (
6965
+ $10::text IS NOT NULL
6966
+ AND $12::integer IS NOT NULL
6967
+ AND target._status = 'enriched'
6968
+ AND coalesce(target._attempt_owner_run_id, target._run_id) = $10::text
6969
+ AND COALESCE(target._attempt_seq, 0) = $12::integer
6970
+ )
7137
6971
  AND (
7138
6972
  target._status <> 'enriched'
7139
6973
  OR target._run_id IS DISTINCT FROM $5::text
@@ -7339,11 +7173,6 @@ async function completeRuntimeMapRowChunksWithInputIndexRepair(
7339
7173
  '$11::timestamptz',
7340
7174
  '$12',
7341
7175
  );
7342
- const sameOwnerTerminalEpochSql = sameOwnerTerminalAttemptEpochSql(
7343
- 'target',
7344
- '$10::text',
7345
- '$12',
7346
- );
7347
7176
  const { rows } = await client.query<{
7348
7177
  _key?: string;
7349
7178
  fenced_keys?: string[];
@@ -7403,6 +7232,15 @@ async function completeRuntimeMapRowChunksWithInputIndexRepair(
7403
7232
  target._status <> 'enriched'
7404
7233
  OR (${targetChangedPatchedCellSql})
7405
7234
  )
7235
+ -- First terminal wins: suppress conflict for same owner+epoch already-terminal row.
7236
+ -- Durable replay (omitted_terminal_replay) from same attempt epoch is idempotent.
7237
+ AND NOT (
7238
+ $10::text IS NOT NULL
7239
+ AND $12::integer IS NOT NULL
7240
+ AND target._status = 'enriched'
7241
+ AND coalesce(target._attempt_owner_run_id, target._run_id) = $10::text
7242
+ AND COALESCE(target._attempt_seq, 0) = $12::integer
7243
+ )
7406
7244
  ),
7407
7245
  applied_rows AS (
7408
7246
  UPDATE ${sheetTable(session)} AS target
@@ -7425,7 +7263,6 @@ async function completeRuntimeMapRowChunksWithInputIndexRepair(
7425
7263
  AND ($13::bigint IS NULL OR target._write_version = $13::bigint)
7426
7264
  AND ($13::bigint IS NOT NULL OR target._status <> 'enriched')
7427
7265
  AND NOT (${newerTerminalRuntimeSheetRowSql('target', '$11::timestamptz', '$12::integer', '$9::text', '$10::text')})
7428
- AND NOT (${sameOwnerTerminalEpochSql})
7429
7266
  AND (
7430
7267
  ($9::text IS NULL AND target._run_id = $5::text)
7431
7268
  OR ($9::text IS NOT NULL AND ${activeRuntimeSheetAttemptFenceSql('target', '$9::text', '$10::text', '$11::timestamptz', '$12::integer')})
@@ -7642,6 +7479,7 @@ async function insertMissingCompletedMapRowChunks(
7642
7479
  _attempt_owner_run_id,
7643
7480
  _attempt_expires_at,
7644
7481
  _attempt_seq,
7482
+ _created_at,
7645
7483
  _cell_meta${physicalInsertColumnsSql}
7646
7484
  )
7647
7485
  SELECT _key,
@@ -7652,6 +7490,7 @@ async function insertMissingCompletedMapRowChunks(
7652
7490
  $9::text,
7653
7491
  $10::timestamptz,
7654
7492
  $11::integer,
7493
+ now(),
7655
7494
  cell_meta_patch${physicalInsertValuesSql}
7656
7495
  FROM missing_rows
7657
7496
  ON CONFLICT (_key) DO NOTHING
@@ -7860,6 +7699,16 @@ async function failRuntimeMapRowChunks(
7860
7699
  OR target._error IS DISTINCT FROM updates.error
7861
7700
  OR (${targetChangedPatchedCellSql})
7862
7701
  )
7702
+ -- Same-owner terminal replay is not a conflict. Normal replay
7703
+ -- preserves the first value below; explicit force-failure may update it.
7704
+ -- Different owners and attempt epochs still conflict.
7705
+ AND NOT (
7706
+ $12::text IS NOT NULL
7707
+ AND $14::integer IS NOT NULL
7708
+ AND target._status IN ('failed', 'enriched')
7709
+ AND coalesce(target._attempt_owner_run_id, target._run_id) = $12::text
7710
+ AND COALESCE(target._attempt_seq, 0) = $14::integer
7711
+ )
7863
7712
  ),
7864
7713
  applied_rows AS (
7865
7714
  UPDATE ${sheetTable(session)} AS target
@@ -7886,13 +7735,15 @@ async function failRuntimeMapRowChunks(
7886
7735
  ($11::text IS NULL AND target._run_id = $6::text)
7887
7736
  OR ($11::text IS NOT NULL AND ${activeRuntimeSheetAttemptFenceSql('target', '$11::text', '$12::text', '$13::timestamptz', '$14::integer')})
7888
7737
  )
7738
+ -- First terminal wins for failed rows too, BUT only when NOT force-failing.
7739
+ -- Normal replay: no-op when already-failed OR already-enriched from same owner+epoch.
7889
7740
  AND NOT (
7890
- $16::bigint IS NOT NULL
7891
- AND target._write_version = $16::bigint
7892
- AND target._run_id = $6::text
7893
- AND target._status = 'failed'
7894
- AND target._error IS NOT DISTINCT FROM updates.error
7895
- AND NOT (${targetChangedPatchedCellSql})
7741
+ $15::boolean = FALSE
7742
+ AND $12::text IS NOT NULL
7743
+ AND $14::integer IS NOT NULL
7744
+ AND target._status IN ('failed', 'enriched')
7745
+ AND coalesce(target._attempt_owner_run_id, target._run_id) = $12::text
7746
+ AND COALESCE(target._attempt_seq, 0) = $14::integer
7896
7747
  )
7897
7748
  RETURNING target._key, prev._status AS prev_status
7898
7749
  ),
@@ -8004,9 +7855,12 @@ async function failRuntimeMapRowChunks(
8004
7855
  input.writeVersion,
8005
7856
  ],
8006
7857
  );
8007
- updated += Number(rows[0]?.updated ?? 0);
8008
- fencedKeys.push(...(rows[0]?.fenced_keys ?? []));
8009
- conflictKeys.push(...(rows[0]?.conflict_keys ?? []));
7858
+ const appliedCount = Number(rows[0]?.updated ?? 0);
7859
+ const chunkFencedKeys = rows[0]?.fenced_keys ?? [];
7860
+ const chunkConflictKeys = rows[0]?.conflict_keys ?? [];
7861
+ updated += appliedCount;
7862
+ fencedKeys.push(...chunkFencedKeys);
7863
+ conflictKeys.push(...chunkConflictKeys);
8010
7864
  }
8011
7865
  return { updated, fencedKeys, conflictKeys };
8012
7866
  }