@rivetkit/engine 1.0.0 → 2.2.1-pr.4600.b74ff3b

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 (1038) hide show
  1. package/CLAUDE.md +38 -0
  2. package/artifacts/config-schema.json +1140 -0
  3. package/artifacts/errors/actor.kv_storage_quota_exceeded.json +5 -0
  4. package/artifacts/errors/actor.no_runner_config_configured.json +5 -0
  5. package/artifacts/errors/guard.actor_runner_failed.json +5 -0
  6. package/artifacts/errors/guard.invalid_request.json +5 -0
  7. package/artifacts/errors/guard.invalid_request_body.json +5 -0
  8. package/artifacts/errors/guard.invalid_response_body.json +5 -0
  9. package/artifacts/errors/guard.missing_query_parameter.json +5 -0
  10. package/artifacts/errors/guard.query_ambiguous_runner_configs.json +5 -0
  11. package/artifacts/errors/guard.query_duplicate_param.json +5 -0
  12. package/artifacts/errors/guard.query_empty_actor_name.json +5 -0
  13. package/artifacts/errors/guard.query_get_disallowed_params.json +5 -0
  14. package/artifacts/errors/guard.query_invalid_base64_input.json +5 -0
  15. package/artifacts/errors/guard.query_invalid_cbor_input.json +5 -0
  16. package/artifacts/errors/guard.query_invalid_params.json +5 -0
  17. package/artifacts/errors/guard.query_invalid_percent_encoding.json +5 -0
  18. package/artifacts/errors/guard.query_missing_runner_name.json +5 -0
  19. package/artifacts/errors/guard.query_no_runner_configs.json +5 -0
  20. package/artifacts/errors/guard.query_param_missing_equals.json +5 -0
  21. package/artifacts/errors/guard.query_path_token_syntax.json +5 -0
  22. package/artifacts/errors/guard.query_unknown_param.json +5 -0
  23. package/artifacts/errors/guard.request_body_too_large.json +5 -0
  24. package/artifacts/errors/guard.response_body_too_large.json +5 -0
  25. package/artifacts/errors/serverless_runner_pool.failed_to_fetch_metadata.json +5 -0
  26. package/artifacts/errors/serverless_runner_pool.not_found.json +5 -0
  27. package/artifacts/errors/{api.rate_limited.json → test.api_rate_limited.json} +2 -2
  28. package/artifacts/errors/{namespace.invalid_name.json → test.namespace_invalid_name.json} +2 -2
  29. package/artifacts/errors/ws.going_away.json +5 -0
  30. package/artifacts/openapi.json +458 -6
  31. package/docker/builder-base/linux-gnu.Dockerfile +21 -0
  32. package/docker/builder-base/linux-musl.Dockerfile +53 -0
  33. package/docker/builder-base/osxcross.Dockerfile +42 -0
  34. package/docker/builder-base/windows-mingw.Dockerfile +41 -0
  35. package/docker/builder-base/windows-msvc.Dockerfile +25 -0
  36. package/docker/dev/docker-compose.yml +43 -18
  37. package/docker/dev/grafana/dashboards/api.json +1077 -1239
  38. package/docker/dev/grafana/dashboards/cache.json +911 -1074
  39. package/docker/dev/grafana/dashboards/epoxy.json +1606 -0
  40. package/docker/dev/grafana/dashboards/futures.json +242 -229
  41. package/docker/dev/grafana/dashboards/gasoline.json +2663 -2476
  42. package/docker/dev/grafana/dashboards/guard.json +1433 -1273
  43. package/docker/dev/grafana/dashboards/operation.json +871 -0
  44. package/docker/dev/grafana/dashboards/pegboard.json +1274 -0
  45. package/docker/dev/grafana/dashboards/tokio.json +930 -1004
  46. package/docker/dev/grafana/dashboards/traces.json +35 -13
  47. package/docker/dev/grafana/provisioning/datasources/datasources.yaml +8 -0
  48. package/docker/{dev-multinode/otel-collector-server → dev/otel-collector}/config.yaml +18 -13
  49. package/docker/dev/prometheus/prometheus.yml +4 -0
  50. package/docker/dev/rivet-engine/config.jsonc +9 -16
  51. package/docker/dev-host/docker-compose.yml +38 -16
  52. package/docker/dev-host/grafana/dashboards/api.json +1077 -1239
  53. package/docker/dev-host/grafana/dashboards/cache.json +911 -1074
  54. package/docker/dev-host/grafana/dashboards/epoxy.json +1606 -0
  55. package/docker/dev-host/grafana/dashboards/futures.json +242 -229
  56. package/docker/dev-host/grafana/dashboards/gasoline.json +2663 -2476
  57. package/docker/dev-host/grafana/dashboards/guard.json +1433 -1273
  58. package/docker/dev-host/grafana/dashboards/operation.json +871 -0
  59. package/docker/dev-host/grafana/dashboards/pegboard.json +1274 -0
  60. package/docker/dev-host/grafana/dashboards/tokio.json +930 -1004
  61. package/docker/dev-host/grafana/dashboards/traces.json +35 -13
  62. package/docker/dev-host/grafana/provisioning/datasources/datasources.yaml +8 -0
  63. package/docker/dev-host/{otel-collector-server → otel-collector}/config.yaml +18 -13
  64. package/docker/dev-host/prometheus/prometheus.yml +4 -0
  65. package/docker/dev-host/rivet-engine/config.jsonc +9 -16
  66. package/docker/dev-multidc/core/grafana/dashboards/api.json +1077 -1239
  67. package/docker/dev-multidc/core/grafana/dashboards/cache.json +911 -1074
  68. package/docker/dev-multidc/core/grafana/dashboards/epoxy.json +1606 -0
  69. package/docker/dev-multidc/core/grafana/dashboards/futures.json +242 -229
  70. package/docker/dev-multidc/core/grafana/dashboards/gasoline.json +2663 -2476
  71. package/docker/dev-multidc/core/grafana/dashboards/guard.json +1433 -1273
  72. package/docker/dev-multidc/core/grafana/dashboards/operation.json +871 -0
  73. package/docker/dev-multidc/core/grafana/dashboards/pegboard.json +1274 -0
  74. package/docker/dev-multidc/core/grafana/dashboards/tokio.json +930 -1004
  75. package/docker/dev-multidc/core/grafana/dashboards/traces.json +35 -13
  76. package/docker/dev-multidc/core/grafana/provisioning/datasources/datasources.yaml +8 -0
  77. package/docker/dev-multidc/core/prometheus/prometheus.yml +4 -0
  78. package/docker/dev-multidc/datacenters/dc-a/{otel-collector-server → otel-collector}/config.yaml +18 -13
  79. package/docker/dev-multidc/datacenters/dc-a/rivet-engine/config.jsonc +23 -22
  80. package/docker/{dev-multidc-multinode/datacenters/dc-b/otel-collector-server → dev-multidc/datacenters/dc-b/otel-collector}/config.yaml +18 -13
  81. package/docker/dev-multidc/datacenters/dc-b/rivet-engine/config.jsonc +23 -22
  82. package/docker/dev-multidc/datacenters/dc-c/{otel-collector-server → otel-collector}/config.yaml +18 -13
  83. package/docker/dev-multidc/datacenters/dc-c/rivet-engine/config.jsonc +23 -22
  84. package/docker/dev-multidc/docker-compose.yml +71 -64
  85. package/docker/dev-multidc-multinode/core/grafana/dashboards/api.json +1077 -1239
  86. package/docker/dev-multidc-multinode/core/grafana/dashboards/cache.json +911 -1074
  87. package/docker/dev-multidc-multinode/core/grafana/dashboards/epoxy.json +1606 -0
  88. package/docker/dev-multidc-multinode/core/grafana/dashboards/futures.json +242 -229
  89. package/docker/dev-multidc-multinode/core/grafana/dashboards/gasoline.json +2663 -2476
  90. package/docker/dev-multidc-multinode/core/grafana/dashboards/guard.json +1433 -1273
  91. package/docker/dev-multidc-multinode/core/grafana/dashboards/operation.json +871 -0
  92. package/docker/dev-multidc-multinode/core/grafana/dashboards/pegboard.json +1274 -0
  93. package/docker/dev-multidc-multinode/core/grafana/dashboards/tokio.json +930 -1004
  94. package/docker/dev-multidc-multinode/core/grafana/dashboards/traces.json +35 -13
  95. package/docker/dev-multidc-multinode/core/grafana/provisioning/datasources/datasources.yaml +8 -0
  96. package/docker/dev-multidc-multinode/core/prometheus/prometheus.yml +4 -0
  97. package/docker/dev-multidc-multinode/datacenters/dc-a/{otel-collector-server → otel-collector}/config.yaml +28 -13
  98. package/docker/dev-multidc-multinode/datacenters/dc-a/rivet-engine/0/config.jsonc +23 -22
  99. package/docker/dev-multidc-multinode/datacenters/dc-a/rivet-engine/1/config.jsonc +23 -22
  100. package/docker/dev-multidc-multinode/datacenters/dc-a/rivet-engine/2/config.jsonc +23 -22
  101. package/docker/{dev-multidc/datacenters/dc-b/otel-collector-server → dev-multidc-multinode/datacenters/dc-b/otel-collector}/config.yaml +28 -13
  102. package/docker/dev-multidc-multinode/datacenters/dc-b/rivet-engine/0/config.jsonc +23 -22
  103. package/docker/dev-multidc-multinode/datacenters/dc-b/rivet-engine/1/config.jsonc +23 -22
  104. package/docker/dev-multidc-multinode/datacenters/dc-b/rivet-engine/2/config.jsonc +23 -22
  105. package/docker/dev-multidc-multinode/datacenters/dc-c/{otel-collector-server → otel-collector}/config.yaml +28 -13
  106. package/docker/dev-multidc-multinode/datacenters/dc-c/rivet-engine/0/config.jsonc +23 -22
  107. package/docker/dev-multidc-multinode/datacenters/dc-c/rivet-engine/1/config.jsonc +23 -22
  108. package/docker/dev-multidc-multinode/datacenters/dc-c/rivet-engine/2/config.jsonc +23 -22
  109. package/docker/dev-multidc-multinode/docker-compose.yml +113 -88
  110. package/docker/dev-multinode/docker-compose.yml +57 -26
  111. package/docker/dev-multinode/grafana/dashboards/api.json +1077 -1239
  112. package/docker/dev-multinode/grafana/dashboards/cache.json +911 -1074
  113. package/docker/dev-multinode/grafana/dashboards/epoxy.json +1606 -0
  114. package/docker/dev-multinode/grafana/dashboards/futures.json +242 -229
  115. package/docker/dev-multinode/grafana/dashboards/gasoline.json +2663 -2476
  116. package/docker/dev-multinode/grafana/dashboards/guard.json +1433 -1273
  117. package/docker/dev-multinode/grafana/dashboards/operation.json +871 -0
  118. package/docker/dev-multinode/grafana/dashboards/pegboard.json +1274 -0
  119. package/docker/dev-multinode/grafana/dashboards/tokio.json +930 -1004
  120. package/docker/dev-multinode/grafana/dashboards/traces.json +35 -13
  121. package/docker/dev-multinode/grafana/provisioning/datasources/datasources.yaml +8 -0
  122. package/docker/{dev/otel-collector-server → dev-multinode/otel-collector}/config.yaml +28 -13
  123. package/docker/dev-multinode/prometheus/prometheus.yml +4 -0
  124. package/docker/dev-multinode/rivet-engine/0/config.jsonc +9 -16
  125. package/docker/dev-multinode/rivet-engine/1/config.jsonc +9 -16
  126. package/docker/dev-multinode/rivet-engine/2/config.jsonc +9 -16
  127. package/docker/engine/linux-aarch64.Dockerfile +9 -49
  128. package/docker/engine/linux-x86_64.Dockerfile +7 -57
  129. package/docker/engine/macos-aarch64.Dockerfile +8 -54
  130. package/docker/engine/macos-x86_64.Dockerfile +9 -55
  131. package/docker/engine/windows.Dockerfile +5 -53
  132. package/docker/template/grafana-dashboards/api.json +1077 -1239
  133. package/docker/template/grafana-dashboards/cache.json +911 -1074
  134. package/docker/template/grafana-dashboards/epoxy.json +1606 -0
  135. package/docker/template/grafana-dashboards/futures.json +242 -229
  136. package/docker/template/grafana-dashboards/gasoline.json +2663 -2476
  137. package/docker/template/grafana-dashboards/guard.json +1433 -1273
  138. package/docker/template/grafana-dashboards/operation.json +871 -0
  139. package/docker/template/grafana-dashboards/pegboard.json +1274 -0
  140. package/docker/template/grafana-dashboards/tokio.json +930 -1004
  141. package/docker/template/grafana-dashboards/traces.json +35 -13
  142. package/docker/template/node_modules/.bin/js-yaml +4 -4
  143. package/docker/template/node_modules/.bin/tsc +4 -4
  144. package/docker/template/node_modules/.bin/tsserver +4 -4
  145. package/docker/template/node_modules/.bin/tsx +4 -4
  146. package/docker/template/src/docker-compose.ts +42 -29
  147. package/docker/template/src/main.ts +4 -4
  148. package/docker/template/src/services/core/grafana.ts +14 -1
  149. package/docker/template/src/services/core/prometheus.ts +20 -0
  150. package/docker/template/src/services/edge/{otel-collector-server.ts → otel-collector.ts} +55 -24
  151. package/docker/template/src/services/edge/rivet-engine.ts +4 -16
  152. package/docker/template/src/services/edge/runner.ts +2 -3
  153. package/docker/universal/Dockerfile +5 -3
  154. package/package.json +2 -5
  155. package/packages/api-builder/src/global_context.rs +1 -1
  156. package/packages/api-builder/src/metrics.rs +28 -24
  157. package/packages/api-builder/src/middleware.rs +30 -48
  158. package/packages/api-builder/src/router.rs +13 -1
  159. package/packages/api-peer/Cargo.toml +7 -9
  160. package/packages/api-peer/src/actors/delete.rs +56 -57
  161. package/packages/api-peer/src/actors/get_or_create.rs +139 -0
  162. package/packages/api-peer/src/actors/kv_get.rs +40 -28
  163. package/packages/api-peer/src/actors/list.rs +31 -14
  164. package/packages/api-peer/src/actors/list_names.rs +6 -6
  165. package/packages/api-peer/src/actors/mod.rs +3 -0
  166. package/packages/api-peer/src/actors/reschedule.rs +55 -0
  167. package/packages/api-peer/src/actors/sleep.rs +55 -0
  168. package/packages/api-peer/src/envoys.rs +57 -0
  169. package/packages/api-peer/src/internal.rs +441 -24
  170. package/packages/api-peer/src/lib.rs +2 -1
  171. package/packages/api-peer/src/namespaces.rs +24 -9
  172. package/packages/api-peer/src/router.rs +31 -7
  173. package/packages/api-peer/src/runner_configs.rs +66 -19
  174. package/packages/api-peer/src/runners.rs +30 -32
  175. package/packages/api-public/Cargo.toml +2 -0
  176. package/packages/api-public/src/actors/create.rs +8 -17
  177. package/packages/api-public/src/actors/delete.rs +11 -35
  178. package/packages/api-public/src/actors/get_or_create.rs +23 -95
  179. package/packages/api-public/src/actors/kv_get.rs +12 -29
  180. package/packages/api-public/src/actors/list.rs +56 -78
  181. package/packages/api-public/src/actors/list_names.rs +15 -14
  182. package/packages/api-public/src/actors/mod.rs +2 -0
  183. package/packages/api-public/src/actors/reschedule.rs +65 -0
  184. package/packages/api-public/src/actors/sleep.rs +64 -0
  185. package/packages/api-public/src/actors/utils.rs +12 -60
  186. package/packages/api-public/src/ctx.rs +14 -6
  187. package/packages/api-public/src/datacenters.rs +5 -5
  188. package/packages/api-public/src/envoys.rs +57 -0
  189. package/packages/api-public/src/errors.rs +0 -7
  190. package/packages/api-public/src/health.rs +51 -44
  191. package/packages/api-public/src/lib.rs +2 -1
  192. package/packages/api-public/src/metadata.rs +44 -14
  193. package/packages/api-public/src/namespaces.rs +11 -11
  194. package/packages/api-public/src/router.rs +22 -5
  195. package/packages/api-public/src/runner_configs/delete.rs +13 -10
  196. package/packages/api-public/src/runner_configs/list.rs +5 -2
  197. package/packages/api-public/src/runner_configs/refresh_metadata.rs +1 -1
  198. package/packages/api-public/src/runner_configs/serverless_health_check.rs +2 -2
  199. package/packages/api-public/src/runner_configs/upsert.rs +12 -9
  200. package/packages/api-public/src/runner_configs/utils.rs +35 -175
  201. package/packages/api-public/src/runners.rs +17 -45
  202. package/packages/{dump-openapi → api-public-openapi-gen}/Cargo.toml +1 -1
  203. package/packages/api-types/src/actors/create.rs +1 -0
  204. package/packages/api-types/src/actors/delete.rs +20 -0
  205. package/packages/api-types/src/actors/get_or_create.rs +30 -0
  206. package/packages/api-types/src/actors/kv_get.rs +25 -0
  207. package/packages/api-types/src/actors/list.rs +8 -1
  208. package/packages/api-types/src/actors/mod.rs +5 -0
  209. package/packages/api-types/src/actors/reschedule.rs +26 -0
  210. package/packages/api-types/src/actors/sleep.rs +26 -0
  211. package/packages/api-types/src/datacenters/list.rs +2 -2
  212. package/packages/api-types/src/envoys/list.rs +24 -0
  213. package/packages/api-types/src/envoys/mod.rs +1 -0
  214. package/packages/api-types/src/lib.rs +1 -0
  215. package/packages/api-types/src/namespaces/list.rs +4 -0
  216. package/packages/api-types/src/namespaces/runner_configs.rs +23 -2
  217. package/packages/api-types/src/runner_configs/list.rs +6 -1
  218. package/packages/api-types/src/runner_configs/mod.rs +12 -0
  219. package/packages/api-types/src/runners/list.rs +4 -0
  220. package/packages/api-types/src/runners/list_names.rs +21 -0
  221. package/packages/api-types/src/runners/mod.rs +1 -0
  222. package/packages/api-util/src/lib.rs +44 -21
  223. package/packages/bootstrap/Cargo.toml +7 -4
  224. package/packages/bootstrap/src/backfill.rs +53 -0
  225. package/packages/bootstrap/src/lib.rs +43 -7
  226. package/packages/cache/Cargo.toml +3 -1
  227. package/packages/cache/src/driver.rs +43 -151
  228. package/packages/cache/src/getter_ctx.rs +48 -70
  229. package/packages/cache/src/inner.rs +28 -18
  230. package/packages/cache/src/key.rs +17 -3
  231. package/packages/cache/src/lib.rs +0 -2
  232. package/packages/cache/src/metrics.rs +43 -31
  233. package/packages/cache/src/req_config.rs +219 -156
  234. package/packages/cache/tests/fetch.rs +91 -0
  235. package/packages/cache/tests/in_flight.rs +361 -0
  236. package/packages/cache/tests/ttl.rs +314 -0
  237. package/packages/cache-purge/src/lib.rs +1 -1
  238. package/packages/config/Cargo.toml +1 -0
  239. package/packages/config/src/config/cache.rs +10 -3
  240. package/packages/config/src/config/clickhouse.rs +0 -30
  241. package/packages/config/src/config/{db.rs → db/mod.rs} +3 -18
  242. package/packages/config/src/config/db/postgres.rs +59 -0
  243. package/packages/config/src/config/guard.rs +19 -0
  244. package/packages/config/src/config/metrics.rs +22 -0
  245. package/packages/config/src/config/mod.rs +44 -10
  246. package/packages/config/src/config/pegboard.rs +242 -16
  247. package/packages/config/src/config/pubsub.rs +11 -0
  248. package/packages/config/src/config/runtime.rs +58 -0
  249. package/packages/config/src/config/telemetry.rs +1 -0
  250. package/packages/config/src/config/topology.rs +78 -19
  251. package/packages/config/src/defaults.rs +3 -0
  252. package/packages/config/src/lib.rs +10 -1
  253. package/packages/config-schema-gen/Cargo.toml +11 -0
  254. package/packages/config-schema-gen/build.rs +26 -0
  255. package/packages/config-schema-gen/src/lib.rs +2 -0
  256. package/packages/engine/Cargo.toml +11 -2
  257. package/packages/engine/src/commands/db/mod.rs +0 -10
  258. package/packages/engine/src/commands/epoxy.rs +395 -0
  259. package/packages/engine/src/commands/mod.rs +1 -1
  260. package/packages/engine/src/commands/start.rs +43 -63
  261. package/packages/engine/src/commands/udb/cli.rs +148 -4
  262. package/packages/engine/src/commands/wf/mod.rs +83 -12
  263. package/packages/engine/src/commands/wf/signal.rs +38 -0
  264. package/packages/engine/src/lib.rs +6 -3
  265. package/packages/engine/src/main.rs +1 -1
  266. package/packages/engine/src/run_config.rs +6 -7
  267. package/packages/engine/src/util/db.rs +1 -25
  268. package/packages/engine/src/util/wf/mod.rs +39 -5
  269. package/packages/engine/tests/common/actors.rs +50 -332
  270. package/packages/engine/tests/common/api/mod.rs +7 -0
  271. package/packages/engine/tests/common/api/peer.rs +364 -0
  272. package/packages/engine/tests/common/api/public.rs +473 -0
  273. package/packages/engine/tests/common/ctx.rs +15 -3
  274. package/packages/engine/tests/common/mod.rs +8 -5
  275. package/packages/engine/tests/common/test_envoy.rs +87 -0
  276. package/packages/engine/tests/common/test_helpers.rs +218 -130
  277. package/packages/engine/tests/common/test_runner.rs +273 -0
  278. package/packages/engine/tests/envoy/actors_lifecycle.rs +1277 -0
  279. package/packages/engine/tests/envoy/mod.rs +1 -0
  280. package/packages/engine/tests/mod.rs +3 -0
  281. package/packages/engine/tests/runner/actors_alarm.rs +1453 -0
  282. package/packages/engine/tests/runner/actors_kv_crud.rs +996 -0
  283. package/packages/engine/tests/runner/actors_kv_delete_range.rs +126 -0
  284. package/packages/engine/tests/runner/actors_kv_drop.rs +255 -0
  285. package/packages/engine/tests/runner/actors_kv_list.rs +1061 -0
  286. package/packages/engine/tests/runner/actors_kv_misc.rs +882 -0
  287. package/packages/engine/tests/runner/actors_lifecycle.rs +1284 -0
  288. package/packages/engine/tests/runner/actors_scheduling_errors.rs +1005 -0
  289. package/packages/engine/tests/runner/api_actors_create.rs +422 -0
  290. package/packages/engine/tests/runner/api_actors_delete.rs +487 -0
  291. package/packages/engine/tests/runner/api_actors_get_or_create.rs +634 -0
  292. package/packages/engine/tests/runner/api_actors_list.rs +1771 -0
  293. package/packages/engine/tests/runner/api_actors_list_names.rs +691 -0
  294. package/packages/engine/tests/runner/api_namespaces_create.rs +428 -0
  295. package/packages/engine/tests/runner/api_namespaces_list.rs +760 -0
  296. package/packages/engine/tests/runner/api_runner_configs_list.rs +646 -0
  297. package/packages/engine/tests/runner/api_runner_configs_upsert.rs +651 -0
  298. package/packages/engine/tests/runner/api_runners_list.rs +166 -0
  299. package/packages/engine/tests/runner/api_runners_list_names.rs +386 -0
  300. package/packages/engine/tests/runner/mod.rs +20 -0
  301. package/packages/engine/tests/runner/runner_drain_on_version.rs +620 -0
  302. package/packages/env/Cargo.toml +0 -4
  303. package/packages/env/src/lib.rs +0 -18
  304. package/packages/epoxy/Cargo.toml +3 -2
  305. package/packages/epoxy/README.md +554 -93
  306. package/packages/epoxy/src/consts.rs +4 -36
  307. package/packages/epoxy/src/http_client.rs +59 -26
  308. package/packages/epoxy/src/http_routes.rs +73 -10
  309. package/packages/epoxy/src/keys/keys.rs +260 -11
  310. package/packages/epoxy/src/keys/mod.rs +11 -1
  311. package/packages/epoxy/src/keys/replica.rs +5 -260
  312. package/packages/epoxy/src/lib.rs +2 -1
  313. package/packages/epoxy/src/metrics.rs +118 -0
  314. package/packages/epoxy/src/ops/kv/get_local.rs +15 -24
  315. package/packages/epoxy/src/ops/kv/get_optimistic.rs +102 -64
  316. package/packages/epoxy/src/ops/kv/mod.rs +1 -0
  317. package/packages/epoxy/src/ops/kv/purge_local.rs +18 -9
  318. package/packages/epoxy/src/ops/kv/read_value.rs +92 -0
  319. package/packages/epoxy/src/ops/mod.rs +0 -1
  320. package/packages/epoxy/src/ops/propose.rs +1079 -194
  321. package/packages/epoxy/src/replica/ballot.rs +162 -102
  322. package/packages/epoxy/src/replica/changelog.rs +147 -0
  323. package/packages/epoxy/src/replica/commit_kv.rs +69 -66
  324. package/packages/epoxy/src/replica/message_request.rs +33 -48
  325. package/packages/epoxy/src/replica/messages/accept.rs +82 -41
  326. package/packages/epoxy/src/replica/messages/commit.rs +21 -33
  327. package/packages/epoxy/src/replica/messages/mod.rs +0 -8
  328. package/packages/epoxy/src/replica/messages/prepare.rs +68 -69
  329. package/packages/epoxy/src/replica/mod.rs +1 -6
  330. package/packages/epoxy/src/replica/update_config.rs +3 -1
  331. package/packages/epoxy/src/types.rs +30 -54
  332. package/packages/epoxy/src/utils.rs +149 -16
  333. package/packages/epoxy/src/workflows/backfill.rs +233 -0
  334. package/packages/epoxy/src/workflows/coordinator/mod.rs +33 -7
  335. package/packages/epoxy/src/workflows/coordinator/reconfigure.rs +44 -0
  336. package/packages/epoxy/src/workflows/coordinator/replica_status_change.rs +4 -3
  337. package/packages/epoxy/src/workflows/mod.rs +1 -1
  338. package/packages/epoxy/src/workflows/replica/mod.rs +4 -6
  339. package/packages/epoxy/src/workflows/replica/setup.rs +130 -771
  340. package/packages/epoxy/tests/backfill.rs +65 -0
  341. package/packages/epoxy/tests/backfill_snapshot.rs +233 -0
  342. package/packages/epoxy/tests/common/mod.rs +77 -21
  343. package/packages/epoxy/tests/common/utils.rs +366 -10
  344. package/packages/epoxy/tests/consensus_regressions.rs +285 -0
  345. package/packages/epoxy/tests/kv.rs +128 -167
  346. package/packages/epoxy/tests/kv_get_optimistic.rs +257 -157
  347. package/packages/epoxy/tests/migration.rs +75 -0
  348. package/packages/epoxy/tests/proposal.rs +133 -28
  349. package/packages/epoxy/tests/reconfigure.rs +92 -474
  350. package/packages/error/tests/basic.rs +8 -8
  351. package/packages/gasoline/Cargo.toml +1 -0
  352. package/packages/gasoline/src/builder/common/message.rs +19 -47
  353. package/packages/gasoline/src/builder/common/signal.rs +37 -21
  354. package/packages/gasoline/src/builder/common/workflow.rs +19 -15
  355. package/packages/gasoline/src/builder/workflow/lupe.rs +295 -0
  356. package/packages/gasoline/src/builder/workflow/message.rs +24 -47
  357. package/packages/gasoline/src/builder/workflow/mod.rs +1 -0
  358. package/packages/gasoline/src/builder/workflow/signal.rs +68 -22
  359. package/packages/gasoline/src/builder/workflow/sub_workflow.rs +6 -15
  360. package/packages/gasoline/src/ctx/activity.rs +46 -6
  361. package/packages/gasoline/src/ctx/common.rs +26 -23
  362. package/packages/gasoline/src/ctx/listen.rs +33 -50
  363. package/packages/gasoline/src/ctx/message.rs +76 -64
  364. package/packages/gasoline/src/ctx/operation.rs +15 -5
  365. package/packages/gasoline/src/ctx/standalone.rs +32 -4
  366. package/packages/gasoline/src/ctx/test.rs +31 -6
  367. package/packages/gasoline/src/ctx/versioned_workflow.rs +33 -7
  368. package/packages/gasoline/src/ctx/workflow.rs +194 -384
  369. package/packages/gasoline/src/db/debug.rs +49 -9
  370. package/packages/gasoline/src/db/kv/debug.rs +905 -15
  371. package/packages/gasoline/src/db/kv/keys/history.rs +434 -9
  372. package/packages/gasoline/src/db/kv/keys/metric.rs +70 -47
  373. package/packages/gasoline/src/db/kv/keys/signal.rs +19 -3
  374. package/packages/gasoline/src/db/kv/keys/workflow.rs +349 -3
  375. package/packages/gasoline/src/db/kv/mod.rs +975 -514
  376. package/packages/gasoline/src/db/kv/system.rs +155 -18
  377. package/packages/gasoline/src/db/mod.rs +29 -7
  378. package/packages/gasoline/src/error.rs +26 -21
  379. package/packages/gasoline/src/executable.rs +3 -1
  380. package/packages/gasoline/src/history/cursor.rs +436 -336
  381. package/packages/gasoline/src/history/event.rs +24 -15
  382. package/packages/gasoline/src/listen.rs +2 -14
  383. package/packages/gasoline/src/message.rs +1 -1
  384. package/packages/gasoline/src/metrics.rs +260 -143
  385. package/packages/gasoline/src/prelude.rs +1 -1
  386. package/packages/gasoline/src/registry.rs +6 -2
  387. package/packages/gasoline/src/signal.rs +34 -31
  388. package/packages/gasoline/src/utils/mod.rs +1 -18
  389. package/packages/gasoline/src/utils/topic.rs +35 -0
  390. package/packages/gasoline/src/worker.rs +71 -14
  391. package/packages/gasoline/src/workflow.rs +13 -0
  392. package/packages/gasoline/tests/workflows/eviction_test.rs +2 -2
  393. package/packages/gasoline-macros/src/lib.rs +74 -12
  394. package/packages/gasoline-runtime/Cargo.toml +18 -0
  395. package/packages/gasoline-runtime/src/lib.rs +12 -0
  396. package/packages/gasoline-runtime/src/workflows/mod.rs +1 -0
  397. package/packages/gasoline-runtime/src/workflows/pruner.rs +55 -0
  398. package/packages/guard/Cargo.toml +16 -8
  399. package/packages/guard/src/cache/mod.rs +63 -43
  400. package/packages/guard/src/cache/pegboard_gateway.rs +144 -0
  401. package/packages/guard/src/errors.rs +105 -0
  402. package/packages/guard/src/lib.rs +5 -15
  403. package/packages/guard/src/metrics.rs +12 -0
  404. package/packages/guard/src/routing/actor_path.rs +409 -0
  405. package/packages/guard/src/routing/api_public.rs +6 -14
  406. package/packages/guard/src/routing/envoy.rs +98 -0
  407. package/packages/guard/src/routing/mod.rs +152 -206
  408. package/packages/guard/src/routing/pegboard_gateway/mod.rs +572 -0
  409. package/packages/guard/src/routing/pegboard_gateway/resolve_actor_query.rs +236 -0
  410. package/packages/guard/src/routing/runner.rs +24 -54
  411. package/packages/guard/src/routing/ws_health.rs +61 -0
  412. package/packages/guard/src/shared_state.rs +11 -2
  413. package/packages/guard/tests/parse_actor_path.rs +418 -165
  414. package/packages/guard-core/Cargo.toml +3 -10
  415. package/packages/guard-core/src/custom_serve.rs +4 -10
  416. package/packages/guard-core/src/errors.rs +20 -4
  417. package/packages/guard-core/src/lib.rs +6 -4
  418. package/packages/guard-core/src/metrics.rs +66 -53
  419. package/packages/guard-core/src/proxy_service.rs +618 -1520
  420. package/packages/guard-core/src/request_context.rs +149 -169
  421. package/packages/guard-core/src/response_body.rs +65 -0
  422. package/packages/guard-core/src/route.rs +76 -0
  423. package/packages/guard-core/src/server.rs +60 -26
  424. package/packages/guard-core/src/task_group.rs +4 -0
  425. package/packages/guard-core/src/utils.rs +296 -0
  426. package/packages/guard-core/src/websocket_handle.rs +3 -3
  427. package/packages/guard-core/tests/common/mod.rs +0 -1
  428. package/packages/guard-core/tests/custom_serve.rs +4 -6
  429. package/packages/guard-core/tests/simple_websocket.rs +19 -19
  430. package/packages/guard-core/tests/streaming_response.rs +4 -9
  431. package/packages/metrics/Cargo.toml +3 -2
  432. package/packages/metrics/src/buckets.rs +5 -11
  433. package/packages/metrics/src/lib.rs +6 -3
  434. package/packages/metrics/src/providers.rs +2 -42
  435. package/packages/metrics/src/registry.rs +7 -0
  436. package/packages/metrics/src/server.rs +57 -0
  437. package/packages/namespace/Cargo.toml +0 -3
  438. package/packages/namespace/src/keys/metric.rs +301 -0
  439. package/packages/namespace/src/keys/mod.rs +1 -1
  440. package/packages/namespace/src/ops/get_global.rs +7 -4
  441. package/packages/namespace/src/ops/get_local.rs +32 -16
  442. package/packages/namespace/src/ops/mod.rs +0 -1
  443. package/packages/namespace/src/ops/resolve_for_name_global.rs +7 -4
  444. package/packages/namespace/src/ops/resolve_for_name_local.rs +39 -19
  445. package/packages/namespace/src/workflows/namespace.rs +3 -3
  446. package/packages/pegboard/Cargo.toml +22 -0
  447. package/packages/pegboard/src/actor_kv/entry.rs +47 -0
  448. package/packages/pegboard/src/actor_kv/metrics.rs +19 -0
  449. package/packages/pegboard/src/actor_kv/mod.rs +530 -0
  450. package/packages/pegboard/src/actor_kv/preload.rs +363 -0
  451. package/packages/{actor-kv/src → pegboard/src/actor_kv}/utils.rs +36 -35
  452. package/packages/pegboard/src/errors.rs +39 -5
  453. package/packages/pegboard/src/keys/actor.rs +285 -2
  454. package/packages/{actor-kv/src/entry.rs → pegboard/src/keys/actor_kv.rs} +73 -39
  455. package/packages/pegboard/src/keys/backfill.rs +49 -0
  456. package/packages/pegboard/src/keys/envoy.rs +1070 -0
  457. package/packages/pegboard/src/keys/epoxy/ns.rs +1 -1
  458. package/packages/pegboard/src/keys/mod.rs +4 -6
  459. package/packages/pegboard/src/keys/ns.rs +493 -14
  460. package/packages/pegboard/src/keys/runner.rs +281 -0
  461. package/packages/{namespace → pegboard}/src/keys/runner_config.rs +53 -0
  462. package/packages/pegboard/src/lib.rs +15 -2
  463. package/packages/pegboard/src/metrics.rs +57 -16
  464. package/packages/pegboard/src/ops/actor/create.rs +123 -53
  465. package/packages/pegboard/src/ops/actor/get.rs +14 -45
  466. package/packages/pegboard/src/ops/actor/get_for_gateway.rs +16 -0
  467. package/packages/pegboard/src/ops/actor/get_for_key.rs +3 -0
  468. package/packages/pegboard/src/ops/actor/get_for_kv.rs +43 -0
  469. package/packages/pegboard/src/ops/actor/get_for_runner.rs +99 -0
  470. package/packages/pegboard/src/ops/actor/get_reservation_for_key.rs +1 -0
  471. package/packages/pegboard/src/ops/actor/list_for_ns.rs +10 -38
  472. package/packages/pegboard/src/ops/actor/list_names.rs +3 -3
  473. package/packages/pegboard/src/ops/actor/mod.rs +3 -1
  474. package/packages/pegboard/src/ops/actor/util.rs +263 -0
  475. package/packages/pegboard/src/ops/envoy/drain.rs +101 -0
  476. package/packages/pegboard/src/ops/envoy/evict_actors.rs +54 -0
  477. package/packages/pegboard/src/ops/envoy/expire.rs +92 -0
  478. package/packages/pegboard/src/ops/envoy/get.rs +135 -0
  479. package/packages/pegboard/src/ops/envoy/list.rs +131 -0
  480. package/packages/pegboard/src/ops/envoy/mod.rs +6 -0
  481. package/packages/pegboard/src/ops/envoy/update_ping.rs +92 -0
  482. package/packages/pegboard/src/ops/mod.rs +3 -0
  483. package/packages/pegboard/src/ops/runner/drain.rs +110 -0
  484. package/packages/pegboard/src/ops/runner/list_names.rs +3 -3
  485. package/packages/pegboard/src/ops/runner/list_runner_config_enabled_dcs.rs +199 -0
  486. package/packages/pegboard/src/ops/runner/list_runner_config_epoxy_replica_ids.rs +51 -0
  487. package/packages/pegboard/src/ops/runner/mod.rs +3 -1
  488. package/packages/pegboard/src/ops/runner/update_alloc_idx.rs +17 -5
  489. package/packages/{namespace → pegboard}/src/ops/runner_config/delete.rs +18 -9
  490. package/packages/pegboard/src/ops/runner_config/ensure_normal_if_missing.rs +62 -0
  491. package/packages/{namespace → pegboard}/src/ops/runner_config/get.rs +15 -5
  492. package/packages/pegboard/src/ops/runner_config/get_error.rs +146 -0
  493. package/packages/{namespace → pegboard}/src/ops/runner_config/list.rs +13 -12
  494. package/packages/pegboard/src/ops/runner_config/mod.rs +7 -0
  495. package/packages/pegboard/src/ops/runner_config/refresh_metadata.rs +124 -0
  496. package/packages/pegboard/src/ops/runner_config/upsert.rs +206 -0
  497. package/packages/pegboard/src/ops/serverless_metadata/fetch.rs +223 -0
  498. package/packages/pegboard/src/ops/serverless_metadata/mod.rs +1 -0
  499. package/packages/pegboard/src/pubsub_subjects.rs +52 -0
  500. package/packages/pegboard/src/utils.rs +36 -2
  501. package/packages/pegboard/src/workflows/actor/destroy.rs +135 -99
  502. package/packages/pegboard/src/workflows/actor/keys.rs +59 -5
  503. package/packages/pegboard/src/workflows/actor/metrics.rs +345 -0
  504. package/packages/pegboard/src/workflows/actor/mod.rs +848 -204
  505. package/packages/pegboard/src/workflows/actor/runtime.rs +785 -212
  506. package/packages/pegboard/src/workflows/actor/setup.rs +61 -0
  507. package/packages/pegboard/src/workflows/actor2/keys.rs +337 -0
  508. package/packages/pegboard/src/workflows/actor2/metrics.rs +334 -0
  509. package/packages/pegboard/src/workflows/actor2/mod.rs +1251 -0
  510. package/packages/pegboard/src/workflows/actor2/runtime.rs +1005 -0
  511. package/packages/pegboard/src/workflows/actor_runner_name_selector_backfill.rs +266 -0
  512. package/packages/pegboard/src/workflows/metrics_aggregator.rs +282 -0
  513. package/packages/pegboard/src/workflows/mod.rs +8 -0
  514. package/packages/pegboard/src/workflows/runner.rs +62 -56
  515. package/packages/pegboard/src/workflows/runner2.rs +978 -0
  516. package/packages/pegboard/src/workflows/runner_pool.rs +298 -0
  517. package/packages/pegboard/src/workflows/runner_pool_error_tracker.rs +173 -0
  518. package/packages/pegboard/src/workflows/runner_pool_metadata_poller.rs +237 -0
  519. package/packages/pegboard/src/workflows/serverless/backfill.rs +120 -0
  520. package/packages/pegboard/src/workflows/serverless/conn.rs +702 -0
  521. package/packages/pegboard/src/workflows/serverless/mod.rs +3 -0
  522. package/packages/pegboard/src/workflows/serverless/receiver.rs +87 -0
  523. package/packages/pegboard/tests/actor_v1_pre_migration.rs +77 -0
  524. package/packages/{actor-kv/tests/list_edge_cases.rs → pegboard/tests/kv_list_edge_cases.rs} +74 -59
  525. package/packages/{actor-kv → pegboard}/tests/kv_operations.rs +77 -48
  526. package/packages/pegboard-envoy/Cargo.toml +43 -0
  527. package/packages/pegboard-envoy/src/actor_event_demuxer.rs +165 -0
  528. package/packages/pegboard-envoy/src/conn.rs +417 -0
  529. package/packages/pegboard-envoy/src/errors.rs +38 -0
  530. package/packages/pegboard-envoy/src/lib.rs +250 -0
  531. package/packages/pegboard-envoy/src/metrics.rs +44 -0
  532. package/packages/pegboard-envoy/src/ping_task.rs +61 -0
  533. package/packages/pegboard-envoy/src/tunnel_to_ws_task.rs +183 -0
  534. package/packages/pegboard-envoy/src/utils.rs +68 -0
  535. package/packages/pegboard-envoy/src/ws_to_tunnel_task.rs +536 -0
  536. package/packages/pegboard-envoy/tests/support/ws_to_tunnel_task.rs +82 -0
  537. package/packages/pegboard-gateway/Cargo.toml +2 -0
  538. package/packages/pegboard-gateway/src/keepalive_task.rs +1 -1
  539. package/packages/pegboard-gateway/src/lib.rs +506 -128
  540. package/packages/pegboard-gateway/src/metrics.rs +7 -11
  541. package/packages/pegboard-gateway/src/metrics_task.rs +80 -0
  542. package/packages/pegboard-gateway/src/ping_task.rs +9 -2
  543. package/packages/pegboard-gateway/src/shared_state.rs +110 -74
  544. package/packages/pegboard-gateway/src/tunnel_to_ws_task.rs +21 -7
  545. package/packages/pegboard-gateway/src/ws_to_tunnel_task.rs +12 -6
  546. package/packages/pegboard-gateway2/Cargo.toml +37 -0
  547. package/packages/pegboard-gateway2/src/keepalive_task.rs +61 -0
  548. package/packages/pegboard-gateway2/src/lib.rs +1044 -0
  549. package/packages/pegboard-gateway2/src/metrics.rs +10 -0
  550. package/packages/pegboard-gateway2/src/metrics_task.rs +80 -0
  551. package/packages/pegboard-gateway2/src/ping_task.rs +30 -0
  552. package/packages/pegboard-gateway2/src/shared_state.rs +601 -0
  553. package/packages/pegboard-gateway2/src/tunnel_to_ws_task.rs +99 -0
  554. package/packages/pegboard-gateway2/src/ws_to_tunnel_task.rs +71 -0
  555. package/packages/{pegboard-serverless → pegboard-outbound}/Cargo.toml +9 -9
  556. package/packages/pegboard-outbound/src/lib.rs +487 -0
  557. package/packages/pegboard-outbound/src/metrics.rs +17 -0
  558. package/packages/pegboard-runner/Cargo.toml +11 -5
  559. package/packages/pegboard-runner/src/actor_event_demuxer.rs +163 -0
  560. package/packages/pegboard-runner/src/conn.rs +358 -122
  561. package/packages/pegboard-runner/src/errors.rs +5 -0
  562. package/packages/pegboard-runner/src/lib.rs +62 -36
  563. package/packages/pegboard-runner/src/metrics.rs +44 -0
  564. package/packages/pegboard-runner/src/ping_task.rs +60 -13
  565. package/packages/pegboard-runner/src/tunnel_to_ws_task.rs +249 -110
  566. package/packages/pegboard-runner/src/ws_to_tunnel_task.rs +738 -113
  567. package/packages/pegboard-runner/tests/support/ws_to_tunnel_task.rs +150 -0
  568. package/packages/pools/Cargo.toml +1 -2
  569. package/packages/pools/src/db/clickhouse.rs +7 -6
  570. package/packages/pools/src/db/udb.rs +16 -3
  571. package/packages/pools/src/db/ups.rs +27 -5
  572. package/packages/pools/src/error.rs +0 -3
  573. package/packages/pools/src/lib.rs +0 -2
  574. package/packages/pools/src/metrics.rs +33 -28
  575. package/packages/pools/src/pools.rs +15 -39
  576. package/packages/pools/src/prelude.rs +1 -1
  577. package/packages/postgres-util/Cargo.toml +13 -0
  578. package/packages/postgres-util/src/lib.rs +84 -0
  579. package/packages/runner-protocol/build.rs +157 -0
  580. package/packages/runner-protocol/src/lib.rs +16 -0
  581. package/packages/runner-protocol/src/util.rs +14 -0
  582. package/packages/runner-protocol/src/versioned.rs +4345 -0
  583. package/packages/runtime/src/lib.rs +46 -46
  584. package/packages/runtime/src/metrics.rs +39 -30
  585. package/packages/runtime/src/term_signal.rs +25 -12
  586. package/packages/runtime/src/traces.rs +5 -8
  587. package/packages/service-manager/src/lib.rs +66 -15
  588. package/packages/test-deps/src/datacenter.rs +22 -8
  589. package/packages/test-deps/src/lib.rs +47 -25
  590. package/packages/test-deps-docker/src/database.rs +45 -36
  591. package/packages/test-snapshot-gen/Cargo.toml +39 -0
  592. package/packages/test-snapshot-gen/snapshots/.gitkeep +0 -0
  593. package/packages/test-snapshot-gen/snapshots/epoxy-v1/metadata.json +3 -0
  594. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-1/000008.log +0 -0
  595. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-1/000009.sst +3 -0
  596. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-1/CURRENT +3 -0
  597. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-1/MANIFEST-000005 +3 -0
  598. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-1/OPTIONS-000007 +3 -0
  599. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-2/000008.log +0 -0
  600. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-2/000009.sst +3 -0
  601. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-2/CURRENT +3 -0
  602. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-2/MANIFEST-000005 +3 -0
  603. package/packages/test-snapshot-gen/snapshots/epoxy-v1/replica-2/OPTIONS-000007 +3 -0
  604. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/metadata.json +3 -0
  605. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-1/000008.log +0 -0
  606. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-1/000009.sst +3 -0
  607. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-1/CURRENT +3 -0
  608. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-1/MANIFEST-000005 +3 -0
  609. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-1/OPTIONS-000007 +3 -0
  610. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-2/000008.log +0 -0
  611. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-2/000009.sst +3 -0
  612. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-2/CURRENT +3 -0
  613. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-2/MANIFEST-000005 +3 -0
  614. package/packages/test-snapshot-gen/snapshots/pb-actor-v1-pre-migration/replica-2/OPTIONS-000007 +3 -0
  615. package/packages/test-snapshot-gen/src/lib.rs +328 -0
  616. package/packages/test-snapshot-gen/src/main.rs +145 -0
  617. package/packages/test-snapshot-gen/src/scenarios/epoxy_keys.rs +60 -0
  618. package/packages/test-snapshot-gen/src/scenarios/mod.rs +27 -0
  619. package/packages/test-snapshot-gen/src/scenarios/pb_actor_v1_pre_migration.rs +56 -0
  620. package/packages/test-snapshot-gen/src/test_cluster.rs +234 -0
  621. package/packages/tracing-reconfigure/src/lib.rs +1 -1
  622. package/packages/tracing-utils/src/lib.rs +12 -20
  623. package/packages/types/src/actor/error.rs +59 -0
  624. package/packages/types/src/actor/mod.rs +2 -0
  625. package/packages/types/src/actors.rs +5 -0
  626. package/packages/types/src/envoys.rs +21 -0
  627. package/packages/types/src/keys/backfill.rs +5 -0
  628. package/packages/types/src/keys/mod.rs +1 -0
  629. package/packages/types/src/lib.rs +2 -1
  630. package/packages/types/src/runner_configs.rs +43 -14
  631. package/packages/universaldb/Cargo.toml +4 -0
  632. package/packages/universaldb/src/database.rs +50 -5
  633. package/packages/universaldb/src/driver/mod.rs +12 -2
  634. package/packages/universaldb/src/driver/postgres/database.rs +88 -27
  635. package/packages/universaldb/src/driver/postgres/mod.rs +1 -1
  636. package/packages/universaldb/src/driver/postgres/transaction.rs +4 -7
  637. package/packages/universaldb/src/driver/postgres/transaction_task.rs +30 -52
  638. package/packages/universaldb/src/driver/rocksdb/database.rs +13 -7
  639. package/packages/universaldb/src/driver/rocksdb/transaction_conflict_tracker.rs +5 -5
  640. package/packages/universaldb/src/driver/rocksdb/transaction_task.rs +2 -1
  641. package/packages/universaldb/src/metrics.rs +39 -23
  642. package/packages/universaldb/src/prelude.rs +1 -1
  643. package/packages/universaldb/src/transaction.rs +9 -2
  644. package/packages/universaldb/src/utils/cherry_pick.rs +46 -46
  645. package/packages/universaldb/src/utils/keys.rs +21 -2
  646. package/packages/universaldb/src/utils/mod.rs +8 -0
  647. package/packages/universaldb/src/utils/subspace.rs +9 -4
  648. package/packages/universaldb/tests/integration.rs +5 -3
  649. package/packages/universaldb/tests/integration_gas.rs +5 -3
  650. package/packages/universaldb/tests/rocksdb.rs +152 -19
  651. package/packages/universalpubsub/Cargo.toml +8 -2
  652. package/packages/universalpubsub/benches/simple.rs +28 -8
  653. package/packages/universalpubsub/src/chunking.rs +27 -5
  654. package/packages/universalpubsub/src/driver/memory/mod.rs +131 -20
  655. package/packages/universalpubsub/src/driver/mod.rs +5 -0
  656. package/packages/universalpubsub/src/driver/nats/mod.rs +8 -0
  657. package/packages/universalpubsub/src/driver/postgres/mod.rs +505 -96
  658. package/packages/universalpubsub/src/lib.rs +3 -0
  659. package/packages/universalpubsub/src/metrics.rs +60 -0
  660. package/packages/universalpubsub/src/pubsub.rs +227 -87
  661. package/packages/universalpubsub/src/subject.rs +32 -0
  662. package/packages/universalpubsub/tests/chunking.rs +298 -0
  663. package/packages/universalpubsub/tests/integration.rs +148 -7
  664. package/packages/universalpubsub/tests/reconnect.rs +8 -6
  665. package/packages/util/Cargo.toml +1 -3
  666. package/packages/util/build.rs +6 -0
  667. package/packages/util/src/lib.rs +7 -2
  668. package/packages/util/src/metric.rs +1 -0
  669. package/packages/util/src/serde.rs +1 -516
  670. package/packages/{internal → util-serde}/Cargo.toml +4 -5
  671. package/packages/util-serde/src/lib.rs +517 -0
  672. package/packages/workflow-worker/Cargo.toml +4 -4
  673. package/packages/workflow-worker/src/lib.rs +3 -2
  674. package/sdks/go/api-full/client/client.go +17 -4
  675. package/sdks/go/api-full/metadata/client.go +50 -0
  676. package/sdks/go/api-full/namespaces/client.go +3 -0
  677. package/sdks/go/api-full/namespaces.go +6 -4
  678. package/sdks/go/api-full/runners/client.go +3 -0
  679. package/sdks/go/api-full/runners.go +8 -6
  680. package/sdks/go/api-full/types.go +107 -23
  681. package/sdks/rust/api-full/rust/.openapi-generator/FILES +6 -0
  682. package/sdks/rust/api-full/rust/Cargo.toml +1 -1
  683. package/sdks/rust/api-full/rust/README.md +5 -2
  684. package/sdks/rust/api-full/rust/docs/Actor.md +1 -0
  685. package/sdks/rust/api-full/rust/docs/ActorsDeleteApi.md +1 -1
  686. package/sdks/rust/api-full/rust/docs/ActorsKvGetApi.md +2 -1
  687. package/sdks/rust/api-full/rust/docs/ActorsListApi.md +3 -2
  688. package/sdks/rust/api-full/rust/docs/MetadataApi.md +34 -0
  689. package/sdks/rust/api-full/rust/docs/MetadataGetResponse.md +18 -0
  690. package/sdks/rust/api-full/rust/docs/NamespacesApi.md +3 -2
  691. package/sdks/rust/api-full/rust/docs/RunnerConfig.md +1 -0
  692. package/sdks/rust/api-full/rust/docs/RunnerConfigKindOneOf1Serverless.md +1 -0
  693. package/sdks/rust/api-full/rust/docs/RunnerConfigResponse.md +15 -0
  694. package/sdks/rust/api-full/rust/docs/RunnerConfigsListApi.md +3 -2
  695. package/sdks/rust/api-full/rust/docs/RunnerConfigsListResponseRunnerConfigsValue.md +1 -1
  696. package/sdks/rust/api-full/rust/docs/RunnersApi.md +3 -2
  697. package/sdks/rust/api-full/rust/src/apis/actors_create_api.rs +1 -1
  698. package/sdks/rust/api-full/rust/src/apis/actors_delete_api.rs +3 -5
  699. package/sdks/rust/api-full/rust/src/apis/actors_get_or_create_api.rs +1 -1
  700. package/sdks/rust/api-full/rust/src/apis/actors_kv_get_api.rs +4 -2
  701. package/sdks/rust/api-full/rust/src/apis/actors_list_api.rs +9 -2
  702. package/sdks/rust/api-full/rust/src/apis/actors_list_names_api.rs +1 -1
  703. package/sdks/rust/api-full/rust/src/apis/configuration.rs +2 -2
  704. package/sdks/rust/api-full/rust/src/apis/datacenters_api.rs +1 -1
  705. package/sdks/rust/api-full/rust/src/apis/health_api.rs +1 -1
  706. package/sdks/rust/api-full/rust/src/apis/metadata_api.rs +62 -0
  707. package/sdks/rust/api-full/rust/src/apis/mod.rs +1 -0
  708. package/sdks/rust/api-full/rust/src/apis/namespaces_api.rs +9 -2
  709. package/sdks/rust/api-full/rust/src/apis/runner_configs_delete_api.rs +1 -1
  710. package/sdks/rust/api-full/rust/src/apis/runner_configs_list_api.rs +9 -2
  711. package/sdks/rust/api-full/rust/src/apis/runner_configs_refresh_metadata_api.rs +1 -1
  712. package/sdks/rust/api-full/rust/src/apis/runner_configs_serverless_health_check_api.rs +1 -1
  713. package/sdks/rust/api-full/rust/src/apis/runner_configs_upsert_api.rs +1 -1
  714. package/sdks/rust/api-full/rust/src/apis/runners_api.rs +9 -2
  715. package/sdks/rust/api-full/rust/src/models/actor.rs +5 -1
  716. package/sdks/rust/api-full/rust/src/models/actor_name.rs +1 -1
  717. package/sdks/rust/api-full/rust/src/models/actors_create_request.rs +1 -1
  718. package/sdks/rust/api-full/rust/src/models/actors_create_response.rs +1 -1
  719. package/sdks/rust/api-full/rust/src/models/actors_get_or_create_request.rs +1 -1
  720. package/sdks/rust/api-full/rust/src/models/actors_get_or_create_response.rs +1 -1
  721. package/sdks/rust/api-full/rust/src/models/actors_kv_get_response.rs +1 -1
  722. package/sdks/rust/api-full/rust/src/models/actors_list_names_response.rs +1 -1
  723. package/sdks/rust/api-full/rust/src/models/actors_list_response.rs +1 -1
  724. package/sdks/rust/api-full/rust/src/models/crash_policy.rs +1 -1
  725. package/sdks/rust/api-full/rust/src/models/datacenter.rs +1 -1
  726. package/sdks/rust/api-full/rust/src/models/datacenter_health.rs +1 -1
  727. package/sdks/rust/api-full/rust/src/models/datacenters_list_response.rs +1 -1
  728. package/sdks/rust/api-full/rust/src/models/health_fanout_response.rs +1 -1
  729. package/sdks/rust/api-full/rust/src/models/health_response.rs +1 -1
  730. package/sdks/rust/api-full/rust/src/models/health_status.rs +1 -1
  731. package/sdks/rust/api-full/rust/src/models/metadata_get_response.rs +48 -0
  732. package/sdks/rust/api-full/rust/src/models/mod.rs +4 -0
  733. package/sdks/rust/api-full/rust/src/models/namespace.rs +1 -1
  734. package/sdks/rust/api-full/rust/src/models/namespace_list_response.rs +1 -1
  735. package/sdks/rust/api-full/rust/src/models/namespaces_create_request.rs +1 -1
  736. package/sdks/rust/api-full/rust/src/models/namespaces_create_response.rs +1 -1
  737. package/sdks/rust/api-full/rust/src/models/pagination.rs +1 -1
  738. package/sdks/rust/api-full/rust/src/models/runner.rs +1 -1
  739. package/sdks/rust/api-full/rust/src/models/runner_config.rs +4 -1
  740. package/sdks/rust/api-full/rust/src/models/runner_config_kind.rs +1 -1
  741. package/sdks/rust/api-full/rust/src/models/runner_config_kind_one_of.rs +1 -1
  742. package/sdks/rust/api-full/rust/src/models/runner_config_kind_one_of_1.rs +1 -1
  743. package/sdks/rust/api-full/rust/src/models/runner_config_kind_one_of_1_serverless.rs +5 -1
  744. package/sdks/rust/api-full/rust/src/models/runner_config_response.rs +39 -0
  745. package/sdks/rust/api-full/rust/src/models/runner_config_variant.rs +1 -1
  746. package/sdks/rust/api-full/rust/src/models/runner_configs_list_response.rs +1 -1
  747. package/sdks/rust/api-full/rust/src/models/runner_configs_list_response_runner_configs_value.rs +3 -3
  748. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_request.rs +1 -1
  749. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_response.rs +1 -1
  750. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_response_one_of.rs +1 -1
  751. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_response_one_of_1.rs +1 -1
  752. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_response_one_of_1_failure.rs +1 -1
  753. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_health_check_response_one_of_success.rs +1 -1
  754. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error.rs +1 -1
  755. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of.rs +1 -1
  756. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_1.rs +1 -1
  757. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_2.rs +1 -1
  758. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_3.rs +1 -1
  759. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_3_non_success_status.rs +1 -1
  760. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_4.rs +1 -1
  761. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_4_invalid_response_json.rs +1 -1
  762. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_5.rs +1 -1
  763. package/sdks/rust/api-full/rust/src/models/runner_configs_serverless_metadata_error_one_of_5_invalid_response_schema.rs +1 -1
  764. package/sdks/rust/api-full/rust/src/models/runner_configs_upsert_request_body.rs +1 -1
  765. package/sdks/rust/api-full/rust/src/models/runner_configs_upsert_response.rs +1 -1
  766. package/sdks/rust/api-full/rust/src/models/runners_list_names_response.rs +1 -1
  767. package/sdks/rust/api-full/rust/src/models/runners_list_response.rs +1 -1
  768. package/sdks/rust/api-full/src/apis/actors_api.rs +8 -4
  769. package/sdks/rust/api-full/src/apis/ns_api.rs +8 -4
  770. package/sdks/rust/data/src/converted.rs +7 -4
  771. package/sdks/rust/data/src/lib.rs +2 -2
  772. package/sdks/rust/data/src/versioned/mod.rs +47 -4
  773. package/sdks/rust/data/src/versioned/namespace_runner_config.rs +256 -6
  774. package/sdks/rust/envoy-client/Cargo.toml +25 -0
  775. package/sdks/rust/envoy-client/src/actor.rs +992 -0
  776. package/sdks/rust/envoy-client/src/commands.rs +88 -0
  777. package/sdks/rust/envoy-client/src/config.rs +159 -0
  778. package/sdks/rust/envoy-client/src/connection.rs +288 -0
  779. package/sdks/rust/envoy-client/src/context.rs +24 -0
  780. package/sdks/rust/envoy-client/src/envoy.rs +432 -0
  781. package/sdks/rust/envoy-client/src/events.rs +62 -0
  782. package/sdks/rust/envoy-client/src/handle.rs +355 -0
  783. package/sdks/rust/envoy-client/src/kv.rs +132 -0
  784. package/sdks/rust/envoy-client/src/latency_channel.rs +27 -0
  785. package/sdks/rust/envoy-client/src/lib.rs +15 -0
  786. package/sdks/rust/envoy-client/src/stringify.rs +322 -0
  787. package/sdks/rust/envoy-client/src/tunnel.rs +265 -0
  788. package/sdks/rust/envoy-client/src/utils.rs +172 -0
  789. package/sdks/rust/envoy-protocol/Cargo.toml +22 -0
  790. package/sdks/rust/envoy-protocol/build.rs +200 -0
  791. package/sdks/rust/envoy-protocol/src/generated.rs +1 -0
  792. package/sdks/rust/envoy-protocol/src/lib.rs +8 -0
  793. package/sdks/rust/envoy-protocol/src/versioned.rs +208 -0
  794. package/sdks/rust/epoxy-protocol/Cargo.toml +0 -2
  795. package/sdks/rust/epoxy-protocol/build.rs +7 -0
  796. package/sdks/rust/epoxy-protocol/src/lib.rs +2 -5
  797. package/sdks/rust/epoxy-protocol/src/protocol.rs +128 -0
  798. package/sdks/rust/test-envoy/Cargo.toml +23 -0
  799. package/sdks/rust/test-envoy/Dockerfile +22 -0
  800. package/sdks/rust/test-envoy/src/behaviors.rs +141 -0
  801. package/sdks/rust/test-envoy/src/lib.rs +11 -0
  802. package/sdks/rust/test-envoy/src/main.rs +4 -0
  803. package/sdks/rust/test-envoy/src/server.rs +269 -0
  804. package/sdks/schemas/README.md +1 -2
  805. package/sdks/schemas/data/namespace.runner_config.v3.bare +24 -0
  806. package/sdks/schemas/data/namespace.runner_config.v4.bare +25 -0
  807. package/sdks/schemas/data/namespace.runner_config.v5.bare +26 -0
  808. package/sdks/schemas/data/pegboard.namespace.runner_alloc_idx.v2.bare +8 -0
  809. package/sdks/schemas/envoy-protocol/v1.bare +459 -0
  810. package/sdks/schemas/epoxy-protocol/v2.bare +220 -0
  811. package/sdks/schemas/runner-protocol/v4.bare +438 -0
  812. package/sdks/schemas/runner-protocol/v5.bare +430 -0
  813. package/sdks/schemas/runner-protocol/v6.bare +432 -0
  814. package/sdks/schemas/runner-protocol/v7.bare +438 -0
  815. package/sdks/typescript/api-full/.turbo/turbo-build.log +28 -27
  816. package/sdks/typescript/api-full/build.js +7 -1
  817. package/sdks/typescript/api-full/package.json +66 -57
  818. package/sdks/typescript/api-full/rivetkit-engine-api-full-25.5.3.tgz +0 -0
  819. package/sdks/typescript/api-full/src/Client.ts +41 -10
  820. package/sdks/typescript/api-full/src/api/client/requests/ActorsDeleteRequest.ts +4 -2
  821. package/sdks/typescript/api-full/src/api/client/requests/ActorsKvGetRequest.ts +13 -0
  822. package/sdks/typescript/api-full/src/api/client/requests/ActorsListRequest.ts +6 -0
  823. package/sdks/typescript/api-full/src/api/client/requests/RunnerConfigsListRequest.ts +4 -0
  824. package/sdks/typescript/api-full/src/api/client/requests/index.ts +1 -0
  825. package/sdks/typescript/api-full/src/api/resources/index.ts +1 -0
  826. package/sdks/typescript/api-full/src/api/resources/metadata/client/Client.ts +97 -0
  827. package/sdks/typescript/api-full/src/api/resources/metadata/client/index.ts +1 -0
  828. package/sdks/typescript/api-full/src/api/resources/metadata/index.ts +1 -0
  829. package/sdks/typescript/api-full/src/api/resources/namespaces/client/Client.ts +12 -2
  830. package/sdks/typescript/api-full/src/api/resources/namespaces/client/requests/NamespacesListRequest.ts +6 -0
  831. package/sdks/typescript/api-full/src/api/resources/runners/client/Client.ts +12 -2
  832. package/sdks/typescript/api-full/src/api/resources/runners/client/requests/RunnersListRequest.ts +6 -0
  833. package/sdks/typescript/api-full/src/api/types/Actor.ts +2 -0
  834. package/sdks/typescript/api-full/src/api/types/MetadataGetResponse.ts +14 -0
  835. package/sdks/typescript/api-full/src/api/types/RunnerConfig.ts +1 -0
  836. package/sdks/typescript/api-full/src/api/types/RunnerConfigKindServerlessServerless.ts +2 -0
  837. package/sdks/typescript/api-full/src/api/types/RunnerConfigResponse.ts +9 -0
  838. package/sdks/typescript/api-full/src/api/types/RunnerConfigServerless.ts +2 -0
  839. package/sdks/typescript/api-full/src/api/types/RunnerConfigsListResponseRunnerConfigsValue.ts +1 -1
  840. package/sdks/typescript/api-full/src/api/types/index.ts +2 -0
  841. package/sdks/typescript/api-full/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +6 -4
  842. package/sdks/typescript/api-full/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +4 -3
  843. package/sdks/typescript/api-full/src/serialization/types/Actor.ts +2 -0
  844. package/sdks/typescript/api-full/src/serialization/types/MetadataGetResponse.ts +34 -0
  845. package/sdks/typescript/api-full/src/serialization/types/RunnerConfig.ts +5 -0
  846. package/sdks/typescript/api-full/src/serialization/types/RunnerConfigKindServerlessServerless.ts +2 -0
  847. package/sdks/typescript/api-full/src/serialization/types/RunnerConfigResponse.ts +26 -0
  848. package/sdks/typescript/api-full/src/serialization/types/RunnerConfigServerless.ts +2 -0
  849. package/sdks/typescript/api-full/src/serialization/types/RunnerConfigsListResponseRunnerConfigsValue.ts +3 -3
  850. package/sdks/typescript/api-full/src/serialization/types/index.ts +2 -0
  851. package/sdks/typescript/api-full/turbo.json +9 -0
  852. package/sdks/typescript/envoy-protocol/.turbo/turbo-build.log +23 -0
  853. package/sdks/typescript/{runner-protocol → envoy-protocol}/dist/index.cjs +466 -281
  854. package/sdks/typescript/envoy-protocol/dist/index.cjs.map +1 -0
  855. package/sdks/typescript/envoy-protocol/dist/index.d.cts +699 -0
  856. package/sdks/typescript/envoy-protocol/dist/index.d.ts +699 -0
  857. package/sdks/typescript/{runner-protocol → envoy-protocol}/dist/index.js +530 -345
  858. package/sdks/typescript/envoy-protocol/dist/index.js.map +1 -0
  859. package/sdks/typescript/{runner-protocol → envoy-protocol}/node_modules/.bin/tsc +4 -4
  860. package/{tests/load → sdks/typescript/envoy-protocol}/node_modules/.bin/tsserver +4 -4
  861. package/sdks/typescript/envoy-protocol/node_modules/.bin/tsup +21 -0
  862. package/sdks/typescript/envoy-protocol/node_modules/.bin/tsup-node +21 -0
  863. package/sdks/typescript/envoy-protocol/package.json +36 -0
  864. package/sdks/typescript/envoy-protocol/src/index.ts +2331 -0
  865. package/sdks/typescript/envoy-protocol/tsconfig.json +9 -0
  866. package/sdks/typescript/envoy-protocol/tsup.config.ts +4 -0
  867. package/sdks/typescript/runner/package.json +8 -2
  868. package/sdks/typescript/runner/src/actor.ts +38 -0
  869. package/sdks/typescript/runner/src/mod.ts +435 -229
  870. package/sdks/typescript/runner/src/stringify.ts +36 -33
  871. package/sdks/typescript/runner/src/tunnel.ts +52 -56
  872. package/sdks/typescript/runner/src/utils.ts +19 -0
  873. package/sdks/typescript/runner/src/websocket-tunnel-adapter.ts +98 -435
  874. package/sdks/typescript/runner-protocol/package.json +11 -9
  875. package/sdks/typescript/runner-protocol/src/index.ts +224 -156
  876. package/sdks/typescript/runner-protocol/tsconfig.json +1 -9
  877. package/sdks/typescript/test-runner/.turbo/turbo-build.log +5 -5
  878. package/sdks/typescript/test-runner/dist/index.js +53 -44
  879. package/sdks/typescript/test-runner/dist/index.js.map +1 -1
  880. package/sdks/typescript/test-runner/node_modules/.bin/pino +2 -2
  881. package/sdks/typescript/test-runner/node_modules/.bin/tsc +4 -4
  882. package/sdks/typescript/test-runner/node_modules/.bin/tsserver +4 -4
  883. package/sdks/typescript/test-runner/node_modules/.bin/tsup +4 -4
  884. package/sdks/typescript/test-runner/node_modules/.bin/tsup-node +4 -4
  885. package/sdks/typescript/test-runner/node_modules/.bin/tsx +4 -4
  886. package/sdks/typescript/test-runner/node_modules/.bin/vitest +4 -4
  887. package/sdks/typescript/test-runner/package.json +3 -3
  888. package/sdks/typescript/test-runner/src/index.ts +65 -42
  889. package/sdks/typescript/test-runner/src/log.ts +4 -18
  890. package/artifacts/errors/actor.no_runners_available.json +0 -5
  891. package/artifacts/errors/guard.actor_destroyed.json +0 -5
  892. package/artifacts/errors/guard.actor_not_found.json +0 -5
  893. package/contrib-docs/ACTOR_KEY_RESERVATION.md +0 -101
  894. package/contrib-docs/API.md +0 -11
  895. package/contrib-docs/DOCKER.md +0 -5
  896. package/contrib-docs/ERRORS.md +0 -13
  897. package/contrib-docs/GUARD.md +0 -76
  898. package/contrib-docs/PEGBOARD_TUNNEL_RETRIES.md +0 -83
  899. package/contrib-docs/RUNNER_LIFECYCLE.md +0 -172
  900. package/contrib-docs/SDKS.md +0 -9
  901. package/contrib-docs/TEST_DEPENDENCIES.md +0 -43
  902. package/contrib-docs/design-choicse/EMBEDDED_KV.md +0 -80
  903. package/contrib-docs/operate/TRACING_RECONFIGURE.md +0 -78
  904. package/docker/dev/otel-collector-client/config.yaml +0 -39
  905. package/docker/dev-host/otel-collector-client/config.yaml +0 -39
  906. package/docker/dev-multidc/datacenters/dc-a/otel-collector-client/config.yaml +0 -39
  907. package/docker/dev-multidc/datacenters/dc-b/otel-collector-client/config.yaml +0 -39
  908. package/docker/dev-multidc/datacenters/dc-c/otel-collector-client/config.yaml +0 -39
  909. package/docker/dev-multidc-multinode/datacenters/dc-a/otel-collector-client/config.yaml +0 -39
  910. package/docker/dev-multidc-multinode/datacenters/dc-b/otel-collector-client/config.yaml +0 -39
  911. package/docker/dev-multidc-multinode/datacenters/dc-c/otel-collector-client/config.yaml +0 -39
  912. package/docker/dev-multinode/otel-collector-client/config.yaml +0 -39
  913. package/docker/template/src/services/edge/otel-collector-client.ts +0 -64
  914. package/packages/actor-kv/Cargo.toml +0 -31
  915. package/packages/actor-kv/src/key.rs +0 -81
  916. package/packages/actor-kv/src/lib.rs +0 -357
  917. package/packages/cache/src/rate_limit.rs +0 -109
  918. package/packages/cache/tests/integration.rs +0 -582
  919. package/packages/clickhouse-inserter/Cargo.toml +0 -17
  920. package/packages/clickhouse-inserter/src/error.rs +0 -16
  921. package/packages/clickhouse-inserter/src/lib.rs +0 -179
  922. package/packages/clickhouse-user-query/Cargo.toml +0 -16
  923. package/packages/clickhouse-user-query/examples/case_sensitivity_demo.rs +0 -100
  924. package/packages/clickhouse-user-query/examples/group_by_example.rs +0 -53
  925. package/packages/clickhouse-user-query/examples/string_contains_demo.rs +0 -96
  926. package/packages/clickhouse-user-query/src/builder.rs +0 -445
  927. package/packages/clickhouse-user-query/src/error.rs +0 -37
  928. package/packages/clickhouse-user-query/src/lib.rs +0 -61
  929. package/packages/clickhouse-user-query/src/query.rs +0 -143
  930. package/packages/clickhouse-user-query/src/schema.rs +0 -78
  931. package/packages/clickhouse-user-query/tests/builder_tests.rs +0 -619
  932. package/packages/clickhouse-user-query/tests/case_sensitivity_tests.rs +0 -307
  933. package/packages/clickhouse-user-query/tests/integration_tests.rs +0 -540
  934. package/packages/clickhouse-user-query/tests/query_tests.rs +0 -263
  935. package/packages/clickhouse-user-query/tests/schema_tests.rs +0 -44
  936. package/packages/config/src/config/vector.rs +0 -18
  937. package/packages/engine/src/commands/udb_keys.rs +0 -200
  938. package/packages/engine/tests/actors_create.rs +0 -524
  939. package/packages/engine/tests/actors_delete.rs +0 -243
  940. package/packages/engine/tests/actors_general.rs +0 -191
  941. package/packages/engine/tests/actors_get.rs +0 -230
  942. package/packages/engine/tests/actors_get_by_id.rs +0 -170
  943. package/packages/engine/tests/actors_get_or_create.rs +0 -294
  944. package/packages/engine/tests/actors_get_or_create_by_id.rs +0 -147
  945. package/packages/engine/tests/actors_lifecycle.rs +0 -165
  946. package/packages/engine/tests/actors_list.rs +0 -798
  947. package/packages/engine/tests/actors_list_names.rs +0 -353
  948. package/packages/engine/tests/common/ns.rs +0 -36
  949. package/packages/engine/tests/common/runner.rs +0 -134
  950. package/packages/engine/tests/runners_dupe_key.rs +0 -27
  951. package/packages/engine/tests/runners_version.rs +0 -50
  952. package/packages/env/build.rs +0 -8
  953. package/packages/epoxy/spec/KEYS.md +0 -33
  954. package/packages/epoxy/spec/PROPOSAL.md +0 -125
  955. package/packages/epoxy/spec/RECONFIGURE.md +0 -40
  956. package/packages/epoxy/src/ops/explicit_prepare.rs +0 -342
  957. package/packages/epoxy/src/replica/decide_path.rs +0 -51
  958. package/packages/epoxy/src/replica/lead_consensus.rs +0 -65
  959. package/packages/epoxy/src/replica/log.rs +0 -84
  960. package/packages/epoxy/src/replica/messages/accepted.rs +0 -35
  961. package/packages/epoxy/src/replica/messages/committed.rs +0 -41
  962. package/packages/epoxy/src/replica/messages/download_instances.rs +0 -69
  963. package/packages/epoxy/src/replica/messages/pre_accept.rs +0 -69
  964. package/packages/epoxy/src/replica/utils.rs +0 -111
  965. package/packages/epoxy/src/workflows/purger.rs +0 -81
  966. package/packages/guard/src/cache/actor.rs +0 -43
  967. package/packages/guard/src/middleware.rs +0 -42
  968. package/packages/guard/src/routing/pegboard_gateway.rs +0 -260
  969. package/packages/guard-core/src/analytics.rs +0 -46
  970. package/packages/internal/README.md +0 -1
  971. package/packages/internal/src/lib.rs +0 -1
  972. package/packages/internal/src/ops/bump_serverless_autoscaler_global.rs +0 -64
  973. package/packages/internal/src/ops/cache/mod.rs +0 -1
  974. package/packages/internal/src/ops/cache/purge_global.rs +0 -81
  975. package/packages/internal/src/ops/mod.rs +0 -2
  976. package/packages/namespace/src/ops/runner_config/mod.rs +0 -4
  977. package/packages/namespace/src/ops/runner_config/upsert.rs +0 -148
  978. package/packages/pegboard/src/ops/actor/get_runner.rs +0 -64
  979. package/packages/pegboard/src/ops/runner/find_dc_with_runner.rs +0 -222
  980. package/packages/pegboard-serverless/src/lib.rs +0 -523
  981. package/packages/types/src/msgs/mod.rs +0 -1
  982. package/packages/types/src/msgs/pegboard.rs +0 -5
  983. package/sdks/rust/epoxy-protocol/src/versioned.rs +0 -206
  984. package/sdks/rust/runner-protocol/build.rs +0 -115
  985. package/sdks/rust/runner-protocol/src/lib.rs +0 -10
  986. package/sdks/rust/runner-protocol/src/versioned.rs +0 -1734
  987. package/sdks/schemas/epoxy-protocol/v1.bare +0 -260
  988. package/sdks/typescript/runner/.turbo/turbo-build.log +0 -22
  989. package/sdks/typescript/runner/dist/mod.cjs +0 -2951
  990. package/sdks/typescript/runner/dist/mod.cjs.map +0 -1
  991. package/sdks/typescript/runner/dist/mod.d.cts +0 -326
  992. package/sdks/typescript/runner/dist/mod.d.ts +0 -326
  993. package/sdks/typescript/runner/dist/mod.js +0 -2951
  994. package/sdks/typescript/runner/dist/mod.js.map +0 -1
  995. package/sdks/typescript/runner/node_modules/.bin/pino +0 -21
  996. package/sdks/typescript/runner/node_modules/.bin/tsc +0 -21
  997. package/sdks/typescript/runner/node_modules/.bin/tsserver +0 -21
  998. package/sdks/typescript/runner/node_modules/.bin/tsup +0 -21
  999. package/sdks/typescript/runner/node_modules/.bin/tsup-node +0 -21
  1000. package/sdks/typescript/runner/node_modules/.bin/tsx +0 -21
  1001. package/sdks/typescript/runner/node_modules/.bin/uuid +0 -21
  1002. package/sdks/typescript/runner/node_modules/.bin/vitest +0 -21
  1003. package/sdks/typescript/runner-protocol/.turbo/turbo-build.log +0 -22
  1004. package/sdks/typescript/runner-protocol/dist/index.cjs.map +0 -1
  1005. package/sdks/typescript/runner-protocol/dist/index.d.cts +0 -666
  1006. package/sdks/typescript/runner-protocol/dist/index.d.ts +0 -666
  1007. package/sdks/typescript/runner-protocol/dist/index.js.map +0 -1
  1008. package/sdks/typescript/runner-protocol/node_modules/.bin/tsserver +0 -21
  1009. package/sdks/typescript/runner-protocol/node_modules/.bin/tsup +0 -21
  1010. package/sdks/typescript/runner-protocol/node_modules/.bin/tsup-node +0 -21
  1011. package/sdks/typescript/test-runner/Dockerfile +0 -26
  1012. package/tests/load/README.md +0 -28
  1013. package/tests/load/actor-lifecycle/README.md +0 -26
  1014. package/tests/load/actor-lifecycle/actor.ts +0 -41
  1015. package/tests/load/actor-lifecycle/config.ts +0 -14
  1016. package/tests/load/actor-lifecycle/index.ts +0 -62
  1017. package/tests/load/actor-lifecycle/rivet_api.ts +0 -140
  1018. package/tests/load/actor-lifecycle/types.ts +0 -17
  1019. package/tests/load/node_modules/.bin/biome +0 -21
  1020. package/tests/load/node_modules/.bin/tsc +0 -21
  1021. package/tests/load/package.json +0 -15
  1022. package/tests/load/tsconfig.json +0 -20
  1023. package/tests/smoke/README.md +0 -32
  1024. package/tests/smoke/package.json +0 -19
  1025. package/tests/smoke/scripts/connect.ts +0 -41
  1026. package/tests/smoke/src/server/registry.ts +0 -32
  1027. package/tests/smoke/src/server/server.ts +0 -7
  1028. package/tests/smoke/src/smoke-test/index.ts +0 -161
  1029. package/tests/smoke/src/smoke-test/spawn-actor.ts +0 -109
  1030. package/tests/smoke/tsconfig.json +0 -43
  1031. /package/packages/{dump-openapi → api-public-openapi-gen}/build.rs +0 -0
  1032. /package/packages/{dump-openapi → api-public-openapi-gen}/src/lib.rs +0 -0
  1033. /package/{sdks/rust → packages}/runner-protocol/Cargo.toml +0 -0
  1034. /package/{sdks/rust → packages}/runner-protocol/src/compat.rs +0 -0
  1035. /package/{sdks/rust → packages}/runner-protocol/src/generated.rs +0 -0
  1036. /package/{sdks/rust → packages}/runner-protocol/src/uuid_compat.rs +0 -0
  1037. /package/sdks/rust/{runner-protocol → envoy-protocol}/src/util.rs +0 -0
  1038. /package/{tests/smoke → sdks/typescript/envoy-protocol}/turbo.json +0 -0
@@ -1,32 +1,35 @@
1
- use anyhow::*;
1
+ use anyhow::{Context, Result, anyhow};
2
2
  use async_trait::async_trait;
3
3
  use base64::Engine;
4
4
  use base64::engine::general_purpose::STANDARD_NO_PAD as BASE64;
5
5
  use deadpool_postgres::{Config, ManagerConfig, Pool, PoolConfig, RecyclingMethod, Runtime};
6
6
  use futures_util::future::poll_fn;
7
+ use rivet_postgres_util::build_tls_config;
7
8
  use rivet_util::backoff::Backoff;
8
- use std::collections::HashMap;
9
+ use scc::HashMap;
9
10
  use std::hash::{DefaultHasher, Hash, Hasher};
11
+ use std::path::PathBuf;
10
12
  use std::sync::Arc;
13
+ use std::time::Duration;
11
14
  use tokio::sync::{Mutex, broadcast};
12
- use tokio_postgres::{AsyncMessage, NoTls};
15
+ use tokio_postgres::AsyncMessage;
16
+ use tokio_postgres_rustls::MakeRustlsConnect;
13
17
  use tracing::Instrument;
18
+ use uuid::Uuid;
14
19
 
15
20
  use crate::driver::{PubSubDriver, SubscriberDriver, SubscriberDriverHandle};
21
+ use crate::metrics;
16
22
  use crate::pubsub::DriverOutput;
17
23
 
18
24
  #[derive(Clone)]
19
25
  struct Subscription {
20
26
  // Channel to send messages to this subscription
21
27
  tx: broadcast::Sender<Vec<u8>>,
22
- // Cancellation token shared by all subscribers of this subject
23
- token: tokio_util::sync::CancellationToken,
24
28
  }
25
29
 
26
30
  impl Subscription {
27
31
  fn new(tx: broadcast::Sender<Vec<u8>>) -> Self {
28
- let token = tokio_util::sync::CancellationToken::new();
29
- Self { tx, token }
32
+ Self { tx }
30
33
  }
31
34
  }
32
35
 
@@ -46,17 +49,33 @@ const CHARS_PER_BLOCK: usize = 4;
46
49
  pub const POSTGRES_MAX_MESSAGE_SIZE: usize =
47
50
  (MAX_NOTIFY_LENGTH * BYTES_PER_BLOCK) / CHARS_PER_BLOCK - BYTES_PER_BLOCK;
48
51
 
52
+ const QUEUE_SUB_HEARTBEAT_INTERVAL: Duration = Duration::from_secs(10);
53
+ /// How long a queue subscriber's heartbeat must be within to be considered active.
54
+ const QUEUE_SUB_TTL_SECS: i64 = 30;
55
+ /// How often to GC orphaned queue messages.
56
+ const QUEUE_MESSAGE_GC_INTERVAL: Duration = Duration::from_secs(300);
57
+ /// Max age before an unconsumed queue message is garbage collected.
58
+ const QUEUE_MESSAGE_MAX_AGE_SECS: i64 = 3600;
59
+
49
60
  #[derive(Clone)]
50
61
  pub struct PostgresDriver {
51
62
  pool: Arc<Pool>,
52
- client: Arc<Mutex<Option<Arc<tokio_postgres::Client>>>>,
53
- subscriptions: Arc<Mutex<HashMap<String, Subscription>>>,
63
+ client: Arc<Mutex<Option<tokio_postgres::Client>>>,
64
+ subscriptions: Arc<HashMap<String, Subscription>>,
65
+ /// Wakeup channels for queue subscriptions, keyed by queue channel name.
66
+ queue_subscriptions: Arc<HashMap<String, Subscription>>,
54
67
  client_ready: tokio::sync::watch::Receiver<bool>,
55
68
  }
56
69
 
57
70
  impl PostgresDriver {
58
71
  #[tracing::instrument(skip(conn_str), fields(memory_optimization))]
59
- pub async fn connect(conn_str: String, memory_optimization: bool) -> Result<Self> {
72
+ pub async fn connect(
73
+ conn_str: String,
74
+ memory_optimization: bool,
75
+ ssl_root_cert_path: Option<PathBuf>,
76
+ ssl_client_cert_path: Option<PathBuf>,
77
+ ssl_client_key_path: Option<PathBuf>,
78
+ ) -> Result<Self> {
60
79
  tracing::debug!(?memory_optimization, "connecting to postgres");
61
80
  // Create deadpool config from connection string
62
81
  let mut config = Config::new();
@@ -71,14 +90,24 @@ impl PostgresDriver {
71
90
 
72
91
  // Create the pool
73
92
  tracing::debug!("creating postgres pool");
93
+
94
+ // Build TLS configuration with optional custom certificates
95
+ let tls_config = build_tls_config(
96
+ ssl_root_cert_path.as_ref(),
97
+ ssl_client_cert_path.as_ref(),
98
+ ssl_client_key_path.as_ref(),
99
+ )?;
100
+
101
+ let tls = MakeRustlsConnect::new(tls_config);
102
+
74
103
  let pool = config
75
- .create_pool(Some(Runtime::Tokio1), NoTls)
104
+ .create_pool(Some(Runtime::Tokio1), tls)
76
105
  .context("failed to create postgres pool")?;
77
106
  tracing::debug!("postgres pool created successfully");
78
107
 
79
- let subscriptions: Arc<Mutex<HashMap<String, Subscription>>> =
80
- Arc::new(Mutex::new(HashMap::new()));
81
- let client: Arc<Mutex<Option<Arc<tokio_postgres::Client>>>> = Arc::new(Mutex::new(None));
108
+ let subscriptions: Arc<HashMap<String, Subscription>> = Arc::new(HashMap::new());
109
+ let queue_subscriptions: Arc<HashMap<String, Subscription>> = Arc::new(HashMap::new());
110
+ let client: Arc<Mutex<Option<tokio_postgres::Client>>> = Arc::new(Mutex::new(None));
82
111
 
83
112
  // Create channel for client ready notifications
84
113
  let (ready_tx, client_ready) = tokio::sync::watch::channel(false);
@@ -87,82 +116,168 @@ impl PostgresDriver {
87
116
  tokio::spawn(Self::spawn_connection_lifecycle(
88
117
  conn_str.clone(),
89
118
  subscriptions.clone(),
119
+ queue_subscriptions.clone(),
90
120
  client.clone(),
91
121
  ready_tx,
122
+ ssl_root_cert_path.clone(),
123
+ ssl_client_cert_path.clone(),
124
+ ssl_client_key_path.clone(),
92
125
  ));
93
126
 
94
127
  let driver = Self {
95
128
  pool: Arc::new(pool),
96
129
  client,
97
130
  subscriptions,
131
+ queue_subscriptions,
98
132
  client_ready,
99
133
  };
100
134
 
101
135
  // Wait for initial connection to be established
102
136
  driver.wait_for_client().await?;
103
137
 
138
+ // Create queue tables eagerly so they exist before any publish or subscribe
139
+ {
140
+ let conn = driver
141
+ .pool
142
+ .get()
143
+ .await
144
+ .context("failed to get connection for queue table creation")?;
145
+ conn.batch_execute(
146
+ "CREATE TABLE IF NOT EXISTS ups_queue_subs ( \
147
+ id TEXT PRIMARY KEY, \
148
+ subject_hash TEXT NOT NULL, \
149
+ queue_hash TEXT NOT NULL, \
150
+ heartbeat_at TIMESTAMPTZ NOT NULL DEFAULT NOW() \
151
+ ); \
152
+ CREATE INDEX IF NOT EXISTS ups_queue_subs_subject_queue \
153
+ ON ups_queue_subs (subject_hash, queue_hash); \
154
+ CREATE TABLE IF NOT EXISTS ups_queue_messages ( \
155
+ id BIGSERIAL PRIMARY KEY, \
156
+ subject_hash TEXT NOT NULL, \
157
+ queue_hash TEXT NOT NULL, \
158
+ payload BYTEA NOT NULL, \
159
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() \
160
+ ); \
161
+ CREATE INDEX IF NOT EXISTS ups_queue_messages_idx \
162
+ ON ups_queue_messages (subject_hash, queue_hash, id);",
163
+ )
164
+ .await
165
+ .context("failed to create queue tables")?;
166
+ tracing::debug!("queue tables ready");
167
+ }
168
+
169
+ // Spawn GC task for orphaned queue messages
170
+ let gc_driver = driver.clone();
171
+ tokio::spawn(async move {
172
+ let mut interval = tokio::time::interval(QUEUE_MESSAGE_GC_INTERVAL);
173
+ interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
174
+
175
+ loop {
176
+ interval.tick().await;
177
+ if let Ok(conn) = gc_driver.pool.get().await {
178
+ let result = conn
179
+ .execute(
180
+ "DELETE FROM ups_queue_messages \
181
+ WHERE created_at < NOW() - ($1::bigint * INTERVAL '1 second')",
182
+ &[&QUEUE_MESSAGE_MAX_AGE_SECS],
183
+ )
184
+ .await;
185
+ if let Err(e) = result {
186
+ tracing::warn!(?e, "failed to gc queue messages");
187
+ }
188
+ }
189
+ }
190
+ });
191
+
104
192
  Ok(driver)
105
193
  }
106
194
 
107
195
  /// Manages the connection lifecycle with automatic reconnection
108
196
  async fn spawn_connection_lifecycle(
109
197
  conn_str: String,
110
- subscriptions: Arc<Mutex<HashMap<String, Subscription>>>,
111
- client: Arc<Mutex<Option<Arc<tokio_postgres::Client>>>>,
198
+ subscriptions: Arc<HashMap<String, Subscription>>,
199
+ queue_subscriptions: Arc<HashMap<String, Subscription>>,
200
+ client: Arc<Mutex<Option<tokio_postgres::Client>>>,
112
201
  ready_tx: tokio::sync::watch::Sender<bool>,
202
+ ssl_root_cert_path: Option<PathBuf>,
203
+ ssl_client_cert_path: Option<PathBuf>,
204
+ ssl_client_key_path: Option<PathBuf>,
113
205
  ) {
114
206
  let mut backoff = Backoff::default();
115
207
 
208
+ // Build TLS configuration with optional custom certificates
209
+ let tls_config = match build_tls_config(
210
+ ssl_root_cert_path.as_ref(),
211
+ ssl_client_cert_path.as_ref(),
212
+ ssl_client_key_path.as_ref(),
213
+ ) {
214
+ std::result::Result::Ok(config) => config,
215
+ std::result::Result::Err(e) => {
216
+ tracing::error!(?e, "failed to build TLS config");
217
+ return;
218
+ }
219
+ };
220
+
221
+ let tls = MakeRustlsConnect::new(tls_config);
222
+
116
223
  loop {
117
- match tokio_postgres::connect(&conn_str, tokio_postgres::NoTls).await {
224
+ match tokio_postgres::connect(&conn_str, tls.clone()).await {
118
225
  Result::Ok((new_client, conn)) => {
119
226
  tracing::debug!("postgres listen connection established");
120
227
  // Reset backoff on successful connection
121
228
  backoff = Backoff::default();
122
229
 
123
- let new_client = Arc::new(new_client);
124
-
125
230
  // Spawn the polling task immediately
126
231
  // This must be done before any operations on the client
127
232
  let subscriptions_clone = subscriptions.clone();
233
+ let queue_subscriptions_clone = queue_subscriptions.clone();
128
234
  let poll_handle = tokio::spawn(async move {
129
- Self::poll_connection(conn, subscriptions_clone).await;
235
+ Self::poll_connection(conn, subscriptions_clone, queue_subscriptions_clone)
236
+ .await;
130
237
  });
131
238
 
132
- // Get channels to re-subscribe to
133
- let channels: Vec<String> =
134
- subscriptions.lock().await.keys().cloned().collect();
135
- let needs_resubscribe = !channels.is_empty();
136
-
239
+ // Get regular channels to re-subscribe to
240
+ let mut channels = Vec::new();
241
+ subscriptions
242
+ .iter_async(|k, _| {
243
+ channels.push(k.clone());
244
+ true
245
+ })
246
+ .await;
247
+
248
+ // Get queue wakeup channels to re-subscribe to
249
+ let mut queue_channels = Vec::new();
250
+ queue_subscriptions
251
+ .iter_async(|k, _| {
252
+ queue_channels.push(k.clone());
253
+ true
254
+ })
255
+ .await;
256
+
257
+ let needs_resubscribe = !channels.is_empty() || !queue_channels.is_empty();
137
258
  if needs_resubscribe {
138
259
  tracing::debug!(
139
- channels=?channels.len(),
140
- "will re-subscribe to channels after connection starts"
260
+ regular_channels = channels.len(),
261
+ queue_channels = queue_channels.len(),
262
+ "re-subscribing to channels after reconnection"
141
263
  );
142
264
  }
143
265
 
144
- // Re-subscribe to channels
145
- if needs_resubscribe {
146
- tracing::debug!(
147
- channels=?channels.len(),
148
- "re-subscribing to channels after reconnection"
149
- );
150
- for channel in &channels {
151
- tracing::debug!(?channel, "re-subscribing to channel");
152
- if let Result::Err(e) = new_client
153
- .execute(&format!("LISTEN \"{}\"", channel), &[])
154
- .await
155
- {
156
- tracing::error!(?e, %channel, "failed to re-subscribe to channel");
157
- } else {
158
- tracing::debug!(%channel, "successfully re-subscribed to channel");
159
- }
266
+ for channel in channels.iter().chain(queue_channels.iter()) {
267
+ tracing::debug!(?channel, "re-subscribing to channel");
268
+ if let Result::Err(e) = new_client
269
+ .execute(&format!("LISTEN \"{}\"", channel), &[])
270
+ .await
271
+ {
272
+ tracing::error!(?e, %channel, "failed to re-subscribe to channel");
273
+ } else {
274
+ tracing::debug!(%channel, "successfully re-subscribed to channel");
160
275
  }
161
276
  }
162
277
 
163
278
  // Update the client reference and signal ready
164
279
  // Do this AFTER re-subscribing to ensure LISTEN is complete
165
- *client.lock().await = Some(new_client.clone());
280
+ *client.lock().await = Some(new_client);
166
281
  let _ = ready_tx.send(true);
167
282
 
168
283
  // Wait for the polling task to complete (when the connection closes)
@@ -183,18 +298,18 @@ impl PostgresDriver {
183
298
  }
184
299
 
185
300
  /// Polls the connection for notifications until it closes or errors
186
- async fn poll_connection(
187
- mut conn: tokio_postgres::Connection<
188
- tokio_postgres::Socket,
189
- tokio_postgres::tls::NoTlsStream,
190
- >,
191
- subscriptions: Arc<Mutex<HashMap<String, Subscription>>>,
192
- ) {
301
+ async fn poll_connection<T>(
302
+ mut conn: tokio_postgres::Connection<tokio_postgres::Socket, T>,
303
+ subscriptions: Arc<HashMap<String, Subscription>>,
304
+ queue_subscriptions: Arc<HashMap<String, Subscription>>,
305
+ ) where
306
+ T: tokio_postgres::tls::TlsStream + Unpin,
307
+ {
193
308
  loop {
194
309
  match poll_fn(|cx| conn.poll_message(cx)).await {
195
310
  Some(std::result::Result::Ok(AsyncMessage::Notification(note))) => {
196
311
  tracing::trace!(channel = %note.channel(), "received notification");
197
- if let Some(sub) = subscriptions.lock().await.get(note.channel()).cloned() {
312
+ if let Some(sub) = subscriptions.get_async(note.channel()).await {
198
313
  let bytes = match BASE64.decode(note.payload()) {
199
314
  std::result::Result::Ok(b) => b,
200
315
  std::result::Result::Err(err) => {
@@ -204,6 +319,9 @@ impl PostgresDriver {
204
319
  };
205
320
  tracing::trace!(channel = %note.channel(), bytes_len = bytes.len(), "sending to broadcast channel");
206
321
  let _ = sub.tx.send(bytes);
322
+ } else if let Some(sub) = queue_subscriptions.get_async(note.channel()).await {
323
+ // Queue notifications are wakeup signals only; payload lives in the table
324
+ let _ = sub.tx.send(Vec::new());
207
325
  } else {
208
326
  tracing::warn!(channel = %note.channel(), "received notification for unknown channel");
209
327
  }
@@ -224,24 +342,24 @@ impl PostgresDriver {
224
342
  }
225
343
 
226
344
  /// Wait for the client to be connected
227
- async fn wait_for_client(&self) -> Result<Arc<tokio_postgres::Client>> {
345
+ async fn wait_for_client(&self) -> Result<()> {
228
346
  let mut ready_rx = self.client_ready.clone();
229
347
  tokio::time::timeout(tokio::time::Duration::from_secs(5), async {
230
348
  loop {
231
349
  // Check if client is already available
232
- if let Some(client) = self.client.lock().await.clone() {
233
- return Ok(client);
350
+ if self.client.lock().await.is_some() {
351
+ return Ok(());
234
352
  }
235
353
 
236
354
  // Wait for the ready signal to change
237
355
  ready_rx
238
356
  .changed()
239
357
  .await
240
- .map_err(|_| anyhow!("connection lifecycle task ended"))?;
358
+ .context("connection lifecycle task ended")?;
241
359
  }
242
360
  })
243
361
  .await
244
- .map_err(|_| anyhow!("timeout waiting for postgres client connection"))?
362
+ .context("timeout waiting for postgres client connection")?
245
363
  }
246
364
 
247
365
  fn hash_subject(&self, subject: &str) -> String {
@@ -251,6 +369,115 @@ impl PostgresDriver {
251
369
  subject.hash(&mut hasher);
252
370
  format!("ups_{:x}", hasher.finish())
253
371
  }
372
+
373
+ fn hash_queue(&self, queue: &str) -> String {
374
+ let mut hasher = DefaultHasher::new();
375
+ queue.hash(&mut hasher);
376
+ format!("{:x}", hasher.finish())
377
+ }
378
+
379
+ /// Returns the NOTIFY channel name for a (subject, queue) pair.
380
+ fn queue_channel(&self, subject_hash: &str, queue_hash: &str) -> String {
381
+ // Max length: "ups_q_" (6) + 16 + "_" (1) + 16 = 39 chars, well within 64
382
+ format!("ups_q_{}_{}", subject_hash, queue_hash)
383
+ }
384
+
385
+ /// Inserts messages into the queue table and notifies active queue subscribers.
386
+ async fn publish_to_queues(&self, subject: &str, payload: &[u8]) -> Result<()> {
387
+ let subject_hash = self.hash_subject(subject);
388
+
389
+ let conn = self
390
+ .pool
391
+ .get()
392
+ .await
393
+ .context("failed to get connection for queue publish")?;
394
+
395
+ // Find active queue groups for this subject
396
+ let rows = conn
397
+ .query(
398
+ "SELECT DISTINCT queue_hash FROM ups_queue_subs \
399
+ WHERE subject_hash = $1 \
400
+ AND heartbeat_at > NOW() - ($2::bigint * INTERVAL '1 second')",
401
+ &[&subject_hash, &QUEUE_SUB_TTL_SECS],
402
+ )
403
+ .await
404
+ .context("failed to query active queue subs")?;
405
+
406
+ for row in rows {
407
+ let queue_hash: String = row.get(0);
408
+ let channel = self.queue_channel(&subject_hash, &queue_hash);
409
+
410
+ conn.execute(
411
+ "INSERT INTO ups_queue_messages (subject_hash, queue_hash, payload) \
412
+ VALUES ($1, $2, $3)",
413
+ &[&subject_hash, &queue_hash, &payload],
414
+ )
415
+ .await
416
+ .context("failed to insert queue message")?;
417
+
418
+ conn.execute(&format!("NOTIFY \"{}\"", channel), &[])
419
+ .await
420
+ .context("failed to notify queue channel")?;
421
+ }
422
+
423
+ Ok(())
424
+ }
425
+
426
+ fn spawn_subscription_cleanup_task(
427
+ &self,
428
+ subject_hash: String,
429
+ tx: broadcast::Sender<Vec<u8>>,
430
+ ) -> tokio_util::sync::DropGuard {
431
+ let driver = self.clone();
432
+ let token = tokio_util::sync::CancellationToken::new();
433
+ let drop_guard = token.clone().drop_guard();
434
+
435
+ tokio::spawn(async move {
436
+ token.cancelled().await;
437
+ if tx.receiver_count() == 0 {
438
+ if let Some(client) = &*driver.client.lock().await {
439
+ let sql = format!("UNLISTEN \"{}\"", subject_hash);
440
+ if let Err(err) = client.execute(sql.as_str(), &[]).await {
441
+ tracing::warn!(?err, %subject_hash, "failed to UNLISTEN channel");
442
+ } else {
443
+ tracing::trace!(%subject_hash, "unlistened channel");
444
+ }
445
+ }
446
+ driver.subscriptions.remove_async(&subject_hash).await;
447
+ metrics::POSTGRES_SUBSCRIPTION_COUNT.set(driver.subscriptions.len() as i64);
448
+ }
449
+ });
450
+
451
+ drop_guard
452
+ }
453
+
454
+ fn spawn_queue_subscription_cleanup_task(
455
+ &self,
456
+ channel: String,
457
+ tx: broadcast::Sender<Vec<u8>>,
458
+ ) -> tokio_util::sync::DropGuard {
459
+ let driver = self.clone();
460
+ let token = tokio_util::sync::CancellationToken::new();
461
+ let drop_guard = token.clone().drop_guard();
462
+
463
+ tokio::spawn(async move {
464
+ token.cancelled().await;
465
+ if tx.receiver_count() == 0 {
466
+ if let Some(client) = &*driver.client.lock().await {
467
+ let sql = format!("UNLISTEN \"{}\"", channel);
468
+
469
+ if let Err(err) = client.execute(sql.as_str(), &[]).await {
470
+ tracing::warn!(?err, %channel, "failed to UNLISTEN queue channel");
471
+ } else {
472
+ tracing::trace!(%channel, "unlistened queue channel");
473
+ }
474
+ }
475
+ driver.queue_subscriptions.remove_async(&channel).await;
476
+ }
477
+ });
478
+
479
+ drop_guard
480
+ }
254
481
  }
255
482
 
256
483
  #[async_trait]
@@ -270,28 +497,28 @@ impl PubSubDriver for PostgresDriver {
270
497
  let hashed = self.hash_subject(subject);
271
498
 
272
499
  // Check if we already have a subscription for this channel
273
- let (rx, drop_guard) =
274
- if let Some(existing_sub) = self.subscriptions.lock().await.get(&hashed).cloned() {
500
+ let (rx, drop_guard) = match self.subscriptions.entry_async(hashed.clone()).await {
501
+ scc::hash_map::Entry::Occupied(existing_sub) => {
275
502
  // Reuse the existing broadcast channel
276
503
  let rx = existing_sub.tx.subscribe();
277
- let drop_guard = existing_sub.token.clone().drop_guard();
504
+ let drop_guard =
505
+ self.spawn_subscription_cleanup_task(hashed.clone(), existing_sub.tx.clone());
278
506
  (rx, drop_guard)
279
- } else {
507
+ }
508
+ scc::hash_map::Entry::Vacant(e) => {
280
509
  // Create a new broadcast channel for this subject
281
510
  let (tx, rx) = tokio::sync::broadcast::channel(1024);
282
511
  let subscription = Subscription::new(tx.clone());
283
512
 
284
513
  // Register subscription
285
- self.subscriptions
286
- .lock()
287
- .await
288
- .insert(hashed.clone(), subscription.clone());
514
+ e.insert_entry(subscription.clone());
515
+ metrics::POSTGRES_SUBSCRIPTION_COUNT.set(self.subscriptions.len() as i64);
289
516
 
290
517
  // Execute LISTEN command on the async client (for receiving notifications)
291
518
  // This only needs to be done once per channel
292
519
  // Try to LISTEN if client is available, but don't fail if disconnected
293
520
  // The reconnection logic will handle re-subscribing
294
- if let Some(client) = self.client.lock().await.clone() {
521
+ if let Some(client) = &*self.client.lock().await {
295
522
  match client
296
523
  .execute(&format!("LISTEN \"{hashed}\""), &[])
297
524
  .instrument(tracing::trace_span!("pg_listen"))
@@ -308,35 +535,116 @@ impl PubSubDriver for PostgresDriver {
308
535
  tracing::debug!(%hashed, "client not connected, will LISTEN on reconnection");
309
536
  }
310
537
 
311
- // Spawn a single cleanup task for this subscription waiting on its token
312
- let driver = self.clone();
313
- let hashed_clone = hashed.clone();
314
- let tx_clone = tx.clone();
315
- let token_clone = subscription.token.clone();
316
- tokio::spawn(async move {
317
- token_clone.cancelled().await;
318
- if tx_clone.receiver_count() == 0 {
319
- let client = driver.client.lock().await.clone();
320
- if let Some(client) = client {
321
- let sql = format!("UNLISTEN \"{}\"", hashed_clone);
322
- if let Err(err) = client.execute(sql.as_str(), &[]).await {
323
- tracing::warn!(?err, %hashed_clone, "failed to UNLISTEN channel");
324
- } else {
325
- tracing::trace!(%hashed_clone, "unlistened channel");
326
- }
538
+ let drop_guard = self.spawn_subscription_cleanup_task(hashed.clone(), tx.clone());
539
+ (rx, drop_guard)
540
+ }
541
+ };
542
+
543
+ Ok(Box::new(PostgresSubscriber {
544
+ subject: subject.to_string(),
545
+ rx: Some(rx),
546
+ _drop_guard: drop_guard,
547
+ }))
548
+ }
549
+
550
+ async fn queue_subscribe(&self, subject: &str, queue: &str) -> Result<SubscriberDriverHandle> {
551
+ let subject_hash = self.hash_subject(subject);
552
+ let queue_hash = self.hash_queue(queue);
553
+ let channel = self.queue_channel(&subject_hash, &queue_hash);
554
+
555
+ // Register this subscriber in the database so publishers know the queue exists
556
+ let sub_id = Uuid::new_v4().to_string();
557
+ {
558
+ let conn = self
559
+ .pool
560
+ .get()
561
+ .await
562
+ .context("failed to get connection for queue subscribe")?;
563
+ conn.execute(
564
+ "INSERT INTO ups_queue_subs (id, subject_hash, queue_hash) VALUES ($1, $2, $3)",
565
+ &[&sub_id, &subject_hash, &queue_hash],
566
+ )
567
+ .await
568
+ .context("failed to register queue subscriber")?;
569
+ }
570
+
571
+ // Set up a shared LISTEN/broadcast channel for the wakeup signal
572
+ let (rx, drop_guard) = match self.queue_subscriptions.entry_async(channel.clone()).await {
573
+ scc::hash_map::Entry::Occupied(existing_sub) => {
574
+ let rx = existing_sub.tx.subscribe();
575
+ let drop_guard = self.spawn_queue_subscription_cleanup_task(
576
+ channel.clone(),
577
+ existing_sub.tx.clone(),
578
+ );
579
+ (rx, drop_guard)
580
+ }
581
+ scc::hash_map::Entry::Vacant(e) => {
582
+ let (tx, rx) = tokio::sync::broadcast::channel(1024);
583
+ let subscription = Subscription::new(tx.clone());
584
+
585
+ e.insert_entry(subscription.clone());
586
+
587
+ if let Some(client) = &*self.client.lock().await {
588
+ match client
589
+ .execute(&format!("LISTEN \"{}\"", channel), &[])
590
+ .instrument(tracing::trace_span!("pg_listen_queue"))
591
+ .await
592
+ {
593
+ Result::Ok(_) => {
594
+ tracing::debug!(%channel, "successfully subscribed to queue channel");
595
+ }
596
+ Result::Err(e) => {
597
+ tracing::warn!(?e, %channel, "failed to LISTEN queue channel, will retry on reconnection");
327
598
  }
328
- driver.subscriptions.lock().await.remove(&hashed_clone);
329
599
  }
330
- });
600
+ } else {
601
+ tracing::debug!(%channel, "client not connected, will LISTEN queue channel on reconnection");
602
+ }
331
603
 
332
- let drop_guard = subscription.token.clone().drop_guard();
604
+ let drop_guard =
605
+ self.spawn_queue_subscription_cleanup_task(channel.clone(), tx.clone());
333
606
  (rx, drop_guard)
334
- };
607
+ }
608
+ };
335
609
 
336
- Ok(Box::new(PostgresSubscriber {
610
+ // Spawn heartbeat task to keep the registration alive
611
+ let pool = self.pool.clone();
612
+ let sub_id_for_heartbeat = sub_id.clone();
613
+ let heartbeat_token = tokio_util::sync::CancellationToken::new();
614
+ let heartbeat_token_child = heartbeat_token.clone();
615
+ tokio::spawn(async move {
616
+ let mut interval = tokio::time::interval(QUEUE_SUB_HEARTBEAT_INTERVAL);
617
+ interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
618
+
619
+ loop {
620
+ tokio::select! {
621
+ _ = heartbeat_token_child.cancelled() => break,
622
+ _ = interval.tick() => {
623
+ if let Ok(conn) = pool.get().await {
624
+ if let Err(e) = conn
625
+ .execute(
626
+ "UPDATE ups_queue_subs SET heartbeat_at = NOW() WHERE id = $1",
627
+ &[&sub_id_for_heartbeat],
628
+ )
629
+ .await
630
+ {
631
+ tracing::warn!(?e, id = %sub_id_for_heartbeat, "failed to heartbeat queue sub");
632
+ }
633
+ }
634
+ }
635
+ }
636
+ }
637
+ });
638
+
639
+ Ok(Box::new(PostgresQueueSubscriber {
337
640
  subject: subject.to_string(),
641
+ subject_hash,
642
+ queue_hash,
643
+ sub_id,
644
+ pool: self.pool.clone(),
338
645
  rx: Some(rx),
339
646
  _drop_guard: drop_guard,
647
+ _heartbeat_token: heartbeat_token,
340
648
  }))
341
649
  }
342
650
 
@@ -347,11 +655,11 @@ impl PubSubDriver for PostgresDriver {
347
655
  let encoded = BASE64.encode(payload);
348
656
  let hashed = self.hash_subject(subject);
349
657
 
350
- tracing::debug!("attempting to get connection for publish");
658
+ tracing::trace!("attempting to get connection for publish");
351
659
 
352
660
  // Wait for listen connection to be ready first if this channel has subscribers
353
661
  // This ensures that if we're reconnecting, the LISTEN is re-registered before NOTIFY
354
- if self.subscriptions.lock().await.contains_key(&hashed) {
662
+ if self.subscriptions.contains_async(&hashed).await {
355
663
  self.wait_for_client().await?;
356
664
  }
357
665
 
@@ -366,13 +674,22 @@ impl PubSubDriver for PostgresDriver {
366
674
  // Test the connection with a simple query before using it
367
675
  match conn.execute("SELECT 1", &[]).await {
368
676
  Result::Ok(_) => {
369
- // Connection is good, use it for NOTIFY
370
- match conn
371
- .execute(&format!("NOTIFY \"{hashed}\", '{encoded}'"), &[])
372
- .instrument(tracing::trace_span!("pg_notify"))
373
- .await
374
- {
375
- Result::Ok(_) => return Ok(()),
677
+ // Connection is good; run NOTIFY and queue publish in parallel.
678
+ // publish_to_queues acquires its own pool connection so both
679
+ // can proceed concurrently.
680
+ let notify_sql = format!("NOTIFY \"{hashed}\", '{encoded}'");
681
+ let (notify_result, queue_result) = tokio::join!(
682
+ conn.execute(notify_sql.as_str(), &[])
683
+ .instrument(tracing::trace_span!("pg_notify")),
684
+ self.publish_to_queues(subject, payload),
685
+ );
686
+ match notify_result {
687
+ Result::Ok(_) => {
688
+ if let Err(e) = queue_result {
689
+ tracing::warn!(?e, %subject, "failed to publish to queue subscribers");
690
+ }
691
+ return Ok(());
692
+ }
376
693
  Result::Err(e) => {
377
694
  tracing::debug!(
378
695
  ?e,
@@ -441,3 +758,95 @@ impl SubscriberDriver for PostgresSubscriber {
441
758
  }
442
759
  }
443
760
  }
761
+
762
+ pub struct PostgresQueueSubscriber {
763
+ subject: String,
764
+ subject_hash: String,
765
+ queue_hash: String,
766
+ sub_id: String,
767
+ pool: Arc<Pool>,
768
+ rx: Option<tokio::sync::broadcast::Receiver<Vec<u8>>>,
769
+ _drop_guard: tokio_util::sync::DropGuard,
770
+ _heartbeat_token: tokio_util::sync::CancellationToken,
771
+ }
772
+
773
+ impl PostgresQueueSubscriber {
774
+ /// Attempts to atomically claim and delete one pending message for this (subject, queue).
775
+ async fn claim_message(&self) -> Result<Option<Vec<u8>>> {
776
+ let conn = self
777
+ .pool
778
+ .get()
779
+ .await
780
+ .context("failed to get connection for queue claim")?;
781
+
782
+ let rows = conn
783
+ .query(
784
+ "WITH claimed AS ( \
785
+ SELECT id, payload FROM ups_queue_messages \
786
+ WHERE subject_hash = $1 AND queue_hash = $2 \
787
+ ORDER BY id \
788
+ LIMIT 1 \
789
+ FOR UPDATE SKIP LOCKED \
790
+ ) \
791
+ DELETE FROM ups_queue_messages \
792
+ WHERE id IN (SELECT id FROM claimed) \
793
+ RETURNING payload",
794
+ &[&self.subject_hash, &self.queue_hash],
795
+ )
796
+ .await
797
+ .context("failed to claim queue message")?;
798
+
799
+ Ok(rows.into_iter().next().map(|row| row.get::<_, Vec<u8>>(0)))
800
+ }
801
+ }
802
+
803
+ #[async_trait]
804
+ impl SubscriberDriver for PostgresQueueSubscriber {
805
+ async fn next(&mut self) -> Result<DriverOutput> {
806
+ loop {
807
+ // Drain any messages that arrived before or between notifications.
808
+ // Do this before borrowing rx so claim_message can borrow self freely.
809
+ if let Some(payload) = self.claim_message().await? {
810
+ return Ok(DriverOutput::Message {
811
+ subject: self.subject.clone(),
812
+ payload,
813
+ });
814
+ }
815
+
816
+ // Wait for a wakeup notification, then loop back to claim.
817
+ let rx = match self.rx.as_mut() {
818
+ Some(rx) => rx,
819
+ None => return Ok(DriverOutput::Unsubscribed),
820
+ };
821
+ match rx.recv().await {
822
+ std::result::Result::Ok(_) => {
823
+ // Wakeup received; loop back to claim
824
+ }
825
+ Err(tokio::sync::broadcast::error::RecvError::Closed) => {
826
+ return Ok(DriverOutput::Unsubscribed);
827
+ }
828
+ Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => {
829
+ // Notifications were dropped while lagged; loop back to claim in case
830
+ // messages are waiting
831
+ }
832
+ }
833
+ }
834
+ }
835
+ }
836
+
837
+ impl Drop for PostgresQueueSubscriber {
838
+ fn drop(&mut self) {
839
+ let pool = self.pool.clone();
840
+ let sub_id = self.sub_id.clone();
841
+ tokio::spawn(async move {
842
+ if let Ok(conn) = pool.get().await {
843
+ if let Err(e) = conn
844
+ .execute("DELETE FROM ups_queue_subs WHERE id = $1", &[&sub_id])
845
+ .await
846
+ {
847
+ tracing::warn!(?e, %sub_id, "failed to deregister queue subscriber");
848
+ }
849
+ }
850
+ });
851
+ }
852
+ }