@fuzdev/fuz_app 0.181.0 → 0.183.0

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 (267) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +28 -10
  3. package/dist/actions/action_rpc.d.ts +11 -1
  4. package/dist/actions/action_rpc.d.ts.map +1 -1
  5. package/dist/actions/action_rpc.js +3 -2
  6. package/dist/actions/action_types.d.ts +16 -1
  7. package/dist/actions/action_types.d.ts.map +1 -1
  8. package/dist/actions/action_types.js +1 -1
  9. package/dist/actions/notification_sender.d.ts +83 -0
  10. package/dist/actions/notification_sender.d.ts.map +1 -0
  11. package/dist/actions/notification_sender.js +85 -0
  12. package/dist/actions/perform_action.d.ts +9 -0
  13. package/dist/actions/perform_action.d.ts.map +1 -1
  14. package/dist/actions/perform_action.js +22 -13
  15. package/dist/actions/register_action_ws.d.ts +14 -0
  16. package/dist/actions/register_action_ws.d.ts.map +1 -1
  17. package/dist/actions/register_action_ws.js +3 -2
  18. package/dist/actions/ws_socket_session.d.ts +3 -0
  19. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  20. package/dist/actions/ws_socket_session.js +2 -1
  21. package/dist/auth/CLAUDE.md +113 -70
  22. package/dist/auth/account_actions.d.ts.map +1 -1
  23. package/dist/auth/account_actions.js +13 -3
  24. package/dist/auth/account_queries.d.ts +158 -16
  25. package/dist/auth/account_queries.d.ts.map +1 -1
  26. package/dist/auth/account_queries.js +189 -18
  27. package/dist/auth/account_routes.d.ts +6 -4
  28. package/dist/auth/account_routes.d.ts.map +1 -1
  29. package/dist/auth/account_routes.js +98 -92
  30. package/dist/auth/admin_actions.d.ts.map +1 -1
  31. package/dist/auth/admin_actions.js +93 -45
  32. package/dist/auth/api_token_queries.d.ts +13 -5
  33. package/dist/auth/api_token_queries.d.ts.map +1 -1
  34. package/dist/auth/api_token_queries.js +24 -9
  35. package/dist/auth/audit_emitter.d.ts +75 -84
  36. package/dist/auth/audit_emitter.d.ts.map +1 -1
  37. package/dist/auth/audit_emitter.js +83 -71
  38. package/dist/auth/audit_log_schema.d.ts +10 -5
  39. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  40. package/dist/auth/audit_log_schema.js +22 -6
  41. package/dist/auth/bearer_auth.d.ts.map +1 -1
  42. package/dist/auth/bearer_auth.js +3 -2
  43. package/dist/auth/bootstrap_account.d.ts +31 -13
  44. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  45. package/dist/auth/bootstrap_account.js +34 -15
  46. package/dist/auth/bootstrap_routes.d.ts +1 -1
  47. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  48. package/dist/auth/bootstrap_routes.js +7 -14
  49. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  50. package/dist/auth/daemon_token_middleware.js +12 -1
  51. package/dist/auth/deps.d.ts +18 -5
  52. package/dist/auth/deps.d.ts.map +1 -1
  53. package/dist/auth/deps.js +3 -2
  54. package/dist/auth/request_context.d.ts +73 -73
  55. package/dist/auth/request_context.d.ts.map +1 -1
  56. package/dist/auth/request_context.js +78 -96
  57. package/dist/auth/resolved_auth.d.ts +16 -11
  58. package/dist/auth/resolved_auth.d.ts.map +1 -1
  59. package/dist/auth/resolved_auth.js +6 -6
  60. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  61. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  62. package/dist/auth/role_grant_offer_action_specs.js +2 -1
  63. package/dist/auth/role_grant_offer_actions.d.ts +32 -12
  64. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  65. package/dist/auth/role_grant_offer_actions.js +91 -116
  66. package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
  67. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  68. package/dist/auth/role_grant_offer_notifications.js +75 -22
  69. package/dist/auth/role_grant_offer_queries.d.ts +155 -18
  70. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  71. package/dist/auth/role_grant_offer_queries.js +262 -73
  72. package/dist/auth/role_grant_offer_schema.js +1 -1
  73. package/dist/auth/role_grant_queries.d.ts +43 -52
  74. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  75. package/dist/auth/role_grant_queries.js +50 -74
  76. package/dist/auth/role_grant_sql.d.ts +21 -0
  77. package/dist/auth/role_grant_sql.d.ts.map +1 -1
  78. package/dist/auth/role_grant_sql.js +21 -0
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +17 -21
  81. package/dist/auth/session_queries.d.ts +40 -16
  82. package/dist/auth/session_queries.d.ts.map +1 -1
  83. package/dist/auth/session_queries.js +68 -29
  84. package/dist/auth/signup_routes.d.ts.map +1 -1
  85. package/dist/auth/signup_routes.js +90 -38
  86. package/dist/auth/standard_rpc_actions.d.ts +6 -19
  87. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  88. package/dist/auth/standard_rpc_actions.js +5 -6
  89. package/dist/auth/token_scope.d.ts +1 -1
  90. package/dist/auth/token_scope.js +1 -1
  91. package/dist/db/sql_columns.d.ts +1 -1
  92. package/dist/db/sql_columns.js +1 -1
  93. package/dist/http/CLAUDE.md +22 -16
  94. package/dist/http/auth_shape.d.ts +1 -1
  95. package/dist/http/db_routes.d.ts +7 -22
  96. package/dist/http/db_routes.d.ts.map +1 -1
  97. package/dist/http/db_routes.js +72 -72
  98. package/dist/http/error_schemas.d.ts +9 -21
  99. package/dist/http/error_schemas.d.ts.map +1 -1
  100. package/dist/http/error_schemas.js +14 -24
  101. package/dist/http/pending_effects.d.ts +42 -4
  102. package/dist/http/pending_effects.d.ts.map +1 -1
  103. package/dist/http/pending_effects.js +34 -4
  104. package/dist/http/route_spec.d.ts +2 -2
  105. package/dist/server/app_backend.d.ts.map +1 -1
  106. package/dist/server/app_backend.js +3 -1
  107. package/dist/server/app_server.d.ts +69 -18
  108. package/dist/server/app_server.d.ts.map +1 -1
  109. package/dist/server/app_server.js +74 -10
  110. package/dist/server/serve_fact_route.d.ts +3 -3
  111. package/dist/server/serve_fact_route.js +12 -12
  112. package/dist/testing/CLAUDE.md +259 -790
  113. package/dist/testing/adversarial_404.d.ts +6 -1
  114. package/dist/testing/adversarial_404.d.ts.map +1 -1
  115. package/dist/testing/adversarial_404.js +38 -17
  116. package/dist/testing/app_server.d.ts +20 -140
  117. package/dist/testing/app_server.d.ts.map +1 -1
  118. package/dist/testing/app_server.js +48 -125
  119. package/dist/testing/audit_drift_guard.d.ts +11 -6
  120. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  121. package/dist/testing/audit_drift_guard.js +15 -8
  122. package/dist/testing/auth_apps.js +1 -1
  123. package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
  124. package/dist/testing/cross_backend/account_lifecycle.js +43 -0
  125. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  126. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  127. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  128. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  129. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  130. package/dist/testing/cross_backend/capabilities.js +11 -7
  131. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  132. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  133. package/dist/testing/cross_backend/capability_mounts.js +423 -0
  134. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  135. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/cell_relations.js +12 -11
  137. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  138. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  139. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  140. package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
  141. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/conformance_table.js +2 -270
  143. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  144. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  145. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  146. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  147. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  148. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  149. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  150. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  151. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  152. package/dist/testing/cross_backend/declared_skips.js +132 -0
  153. package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
  154. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  155. package/dist/testing/cross_backend/default_spine_surface.js +2 -6
  156. package/dist/testing/cross_backend/differential.d.ts +11 -2
  157. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  158. package/dist/testing/cross_backend/differential.js +35 -11
  159. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  160. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  161. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  162. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -10
  163. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  164. package/dist/testing/cross_backend/full_spine_mount.js +4 -4
  165. package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
  166. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  167. package/dist/testing/cross_backend/in_process_setup.js +151 -134
  168. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  169. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  170. package/dist/testing/cross_backend/login_security.js +21 -4
  171. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  172. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  173. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  174. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  175. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  176. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  177. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  178. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  179. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  180. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  181. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
  182. package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
  183. package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +183 -30
  184. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  185. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  186. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  187. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  188. package/dist/testing/cross_backend/session_cap.js +48 -16
  189. package/dist/testing/cross_backend/setup.d.ts +31 -1
  190. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  191. package/dist/testing/cross_backend/setup.js +32 -1
  192. package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
  193. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  194. package/dist/testing/cross_backend/spine_suites.js +454 -57
  195. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  196. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  198. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  199. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  200. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  201. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  202. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  203. package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
  204. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  205. package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
  206. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  207. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  208. package/dist/testing/cross_backend/transport_composition.js +7 -3
  209. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  210. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  211. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  212. package/dist/testing/data_exposure.d.ts.map +1 -1
  213. package/dist/testing/data_exposure.js +3 -0
  214. package/dist/testing/db.d.ts +0 -32
  215. package/dist/testing/db.d.ts.map +1 -1
  216. package/dist/testing/db.js +0 -86
  217. package/dist/testing/db_entities.d.ts +14 -0
  218. package/dist/testing/db_entities.d.ts.map +1 -1
  219. package/dist/testing/db_entities.js +17 -0
  220. package/dist/testing/db_invariant_queries.d.ts +259 -0
  221. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  222. package/dist/testing/db_invariant_queries.js +400 -0
  223. package/dist/testing/db_invariants.d.ts +106 -0
  224. package/dist/testing/db_invariants.d.ts.map +1 -0
  225. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  226. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  227. package/dist/testing/db_invariants.gen.sql.js +13 -0
  228. package/dist/testing/db_invariants.js +141 -0
  229. package/dist/testing/db_invariants.sql +152 -0
  230. package/dist/testing/describe_db.d.ts +36 -0
  231. package/dist/testing/describe_db.d.ts.map +1 -0
  232. package/dist/testing/describe_db.js +71 -0
  233. package/dist/testing/integration.d.ts +6 -9
  234. package/dist/testing/integration.d.ts.map +1 -1
  235. package/dist/testing/integration.js +9 -13
  236. package/dist/testing/integration_helpers.d.ts +1 -1
  237. package/dist/testing/integration_helpers.d.ts.map +1 -1
  238. package/dist/testing/middleware.d.ts +1 -1
  239. package/dist/testing/middleware.js +5 -5
  240. package/dist/testing/rate_limiting.d.ts +1 -1
  241. package/dist/testing/rate_limiting.d.ts.map +1 -1
  242. package/dist/testing/rate_limiting.js +3 -2
  243. package/dist/testing/resolved_auth.d.ts +3 -1
  244. package/dist/testing/resolved_auth.d.ts.map +1 -1
  245. package/dist/testing/resolved_auth.js +4 -4
  246. package/dist/testing/role_grant_helpers.d.ts +1 -1
  247. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  248. package/dist/testing/round_trip.d.ts.map +1 -1
  249. package/dist/testing/round_trip.js +3 -0
  250. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  251. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  252. package/dist/testing/rpc_attack_surface.js +69 -6
  253. package/dist/testing/rpc_round_trip.d.ts +1 -1
  254. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  255. package/dist/testing/rpc_round_trip.js +3 -0
  256. package/dist/testing/sse_round_trip.d.ts +1 -1
  257. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  258. package/dist/testing/sse_round_trip.js +13 -4
  259. package/dist/testing/stubs.d.ts +4 -2
  260. package/dist/testing/stubs.d.ts.map +1 -1
  261. package/dist/testing/stubs.js +15 -7
  262. package/dist/testing/test_app.d.ts +166 -0
  263. package/dist/testing/test_app.d.ts.map +1 -0
  264. package/dist/testing/test_app.js +124 -0
  265. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  266. package/dist/testing/ws_round_trip.js +8 -4
  267. package/package.json +1 -1
@@ -5,8 +5,8 @@
5
5
  * by their timing contract:
6
6
  *
7
7
  * - `pending_effects: Array<Promise<void>>` — eager. Producers push pool
8
- * writes that are already in flight (audit emits, session-touch UPDATE,
9
- * api-token usage tracking). The pool write is rollback-resilient by
8
+ * writes that are already in flight (failure audit rows, session-touch
9
+ * UPDATE, api-token usage tracking). The pool write is rollback-resilient by
10
10
  * virtue of running outside the request transaction; pushing the
11
11
  * in-flight handle lets test mode (`await_pending_effects: true`) await
12
12
  * it.
@@ -33,6 +33,11 @@
33
33
  * ambiguous at the call site. With separate queues, the field name is
34
34
  * the contract.
35
35
  *
36
+ * A handler that opens its own transaction (a `transaction: false` route)
37
+ * runs it through `transaction_with_post_commit_rollback`, which discards
38
+ * what that transaction queued when it rolls back, even when the handler
39
+ * catches the failure and answers normally.
40
+ *
36
41
  * Both `RouteContext` (HTTP routes) and `ActionContext` (RPC + WS
37
42
  * actions) carry both queues by convention, so this module stays in
38
43
  * `http/` (every transport depends on it).
@@ -40,6 +45,7 @@
40
45
  * @module
41
46
  */
42
47
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
48
+ import type { Db } from '../db/db.js';
43
49
  /**
44
50
  * Context passed to `on_effect_error` when an eager pending effect rejects.
45
51
  */
@@ -102,8 +108,10 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
102
108
  *
103
109
  * Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
104
110
  * action dispatcher (`actions/perform_action.ts`, the RPC + WS path) — wrap
105
- * their handler call in this so the discard contract lives in one place. The
106
- * Rust `fuz_actions` spine pins the same contract.
111
+ * their handler call in this so the discard contract lives in one place, and a
112
+ * handler that opens its own transaction runs it through
113
+ * `transaction_with_post_commit_rollback`, the same truncation around just
114
+ * that transaction. The Rust `fuz_actions` spine pins the same contract.
107
115
  *
108
116
  * `post_commit_effects` is `undefined` when a handler runs without the
109
117
  * app-server pending-effects middleware (bare route / dispatch harnesses):
@@ -114,6 +122,36 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
114
122
  * @mutates `post_commit_effects` - truncated to its pre-dispatch depth on throw
115
123
  */
116
124
  export declare const dispatch_with_post_commit_rollback: <T>(post_commit_effects: Array<() => void | Promise<void>> | undefined, dispatch: () => T | Promise<T>) => Promise<Awaited<T>>;
125
+ /**
126
+ * A request's `db` and its two side-effect queues — what a handler that opens
127
+ * its own transaction hands `transaction_with_post_commit_rollback`, and what
128
+ * that transaction's callback gets back with `db` swapped for the transaction.
129
+ * `RouteContext` and `ActionContext` satisfy it, and so does the callback's
130
+ * context, so either can be passed to `AuditEmitter.emit`.
131
+ */
132
+ export interface RequestEffectsContext extends EmitAfterCommitContext {
133
+ db: Db;
134
+ pending_effects: Array<Promise<void>>;
135
+ }
136
+ /**
137
+ * Run `fn` in a transaction a handler opens on its own `db` (a route with
138
+ * `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
139
+ * connection), discarding the `post_commit_effects` `fn` queued when that
140
+ * transaction rolls back.
141
+ *
142
+ * `dispatch_with_post_commit_rollback` discards them only when the handler
143
+ * throws; a handler that catches its own transaction's failure and answers a
144
+ * refusal (signup's classified conflicts, bootstrap's undeletable token file)
145
+ * would otherwise leave a queued fan-out — a success row's announcement — to
146
+ * fire for writes that rolled back. The truncation is the same: back to the
147
+ * depth before the transaction, the error rethrown unchanged.
148
+ *
149
+ * @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
150
+ * @param fn - the transaction's work, given `ctx` with `db` the transaction
151
+ * @returns what `fn` returns, once the transaction has committed
152
+ * @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
153
+ */
154
+ export declare const transaction_with_post_commit_rollback: <T>(ctx: RequestEffectsContext, fn: (tx_ctx: RequestEffectsContext) => Promise<T>) => Promise<Awaited<T>>;
117
155
  /**
118
156
  * Drain an eager `pending_effects` queue: `Promise.allSettled` the
119
157
  * in-flight handles, route every rejection through `log.error`, and
@@ -1 +1 @@
1
- {"version":3,"file":"pending_effects.d.ts","sourceRoot":"","sources":["../../src/lib/http/pending_effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0E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CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qCAAqC,GAAI,CAAC,EACtD,KAAK,qBAAqB,EAC1B,IAAI,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC,CAAC,KAC/C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CASnB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,GACjC,SAAS,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EACrC,KAAK,MAAM,EACX,eAAe,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KACtC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,aAAa,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAClD,KAAK,MAAM,KACT,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,GACjC,iBAAiB,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAC7C,qBAAqB,aAAa,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAC9D,KAAK,MAAM,EACX,eAAe,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KACtC,OAAO,CAAC,IAAI,CAKd,CAAC"}
@@ -5,8 +5,8 @@
5
5
  * by their timing contract:
6
6
  *
7
7
  * - `pending_effects: Array<Promise<void>>` — eager. Producers push pool
8
- * writes that are already in flight (audit emits, session-touch UPDATE,
9
- * api-token usage tracking). The pool write is rollback-resilient by
8
+ * writes that are already in flight (failure audit rows, session-touch
9
+ * UPDATE, api-token usage tracking). The pool write is rollback-resilient by
10
10
  * virtue of running outside the request transaction; pushing the
11
11
  * in-flight handle lets test mode (`await_pending_effects: true`) await
12
12
  * it.
@@ -33,6 +33,11 @@
33
33
  * ambiguous at the call site. With separate queues, the field name is
34
34
  * the contract.
35
35
  *
36
+ * A handler that opens its own transaction (a `transaction: false` route)
37
+ * runs it through `transaction_with_post_commit_rollback`, which discards
38
+ * what that transaction queued when it rolls back, even when the handler
39
+ * catches the failure and answers normally.
40
+ *
36
41
  * Both `RouteContext` (HTTP routes) and `ActionContext` (RPC + WS
37
42
  * actions) carry both queues by convention, so this module stays in
38
43
  * `http/` (every transport depends on it).
@@ -83,8 +88,10 @@ export const emit_after_commit = (ctx, fn) => {
83
88
  *
84
89
  * Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
85
90
  * action dispatcher (`actions/perform_action.ts`, the RPC + WS path) — wrap
86
- * their handler call in this so the discard contract lives in one place. The
87
- * Rust `fuz_actions` spine pins the same contract.
91
+ * their handler call in this so the discard contract lives in one place, and a
92
+ * handler that opens its own transaction runs it through
93
+ * `transaction_with_post_commit_rollback`, the same truncation around just
94
+ * that transaction. The Rust `fuz_actions` spine pins the same contract.
88
95
  *
89
96
  * `post_commit_effects` is `undefined` when a handler runs without the
90
97
  * app-server pending-effects middleware (bare route / dispatch harnesses):
@@ -105,6 +112,29 @@ export const dispatch_with_post_commit_rollback = async (post_commit_effects, di
105
112
  throw err;
106
113
  }
107
114
  };
115
+ /**
116
+ * Run `fn` in a transaction a handler opens on its own `db` (a route with
117
+ * `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
118
+ * connection), discarding the `post_commit_effects` `fn` queued when that
119
+ * transaction rolls back.
120
+ *
121
+ * `dispatch_with_post_commit_rollback` discards them only when the handler
122
+ * throws; a handler that catches its own transaction's failure and answers a
123
+ * refusal (signup's classified conflicts, bootstrap's undeletable token file)
124
+ * would otherwise leave a queued fan-out — a success row's announcement — to
125
+ * fire for writes that rolled back. The truncation is the same: back to the
126
+ * depth before the transaction, the error rethrown unchanged.
127
+ *
128
+ * @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
129
+ * @param fn - the transaction's work, given `ctx` with `db` the transaction
130
+ * @returns what `fn` returns, once the transaction has committed
131
+ * @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
132
+ */
133
+ export const transaction_with_post_commit_rollback = (ctx, fn) => dispatch_with_post_commit_rollback(ctx.post_commit_effects, () => ctx.db.transaction((tx) => fn({
134
+ db: tx,
135
+ pending_effects: ctx.pending_effects,
136
+ post_commit_effects: ctx.post_commit_effects
137
+ })));
108
138
  /**
109
139
  * Drain an eager `pending_effects` queue: `Promise.allSettled` the
110
140
  * in-flight handles, route every rejection through `log.error`, and
@@ -115,7 +115,7 @@ export interface RouteContext<TAuth extends RequestContext | null = RequestConte
115
115
  * The credential the auth middleware resolved, `null` for an anonymous
116
116
  * caller. A `reads_credential` route — one that answers anonymous callers
117
117
  * itself — reads the account it may act on through
118
- * `get_public_account_id(route)` (`auth/request_context.ts`), never from
118
+ * `get_public_account(route)` (`auth/request_context.ts`), never from
119
119
  * here: a scope-narrowed API token is the anonymous caller there, and only
120
120
  * that function applies the rule.
121
121
  */
@@ -328,7 +328,7 @@ export interface RouteSpec {
328
328
  * The handler owns the token-scope rule a gate would otherwise apply: a
329
329
  * scope-narrowed API token reaches no non-RPC surface that reads account
330
330
  * data, and `auth.required_scope` is refused on a route that admits
331
- * anonymous callers. Read the credential through `get_public_account_id`
331
+ * anonymous callers. Read the credential through `get_public_account`
332
332
  * (`auth/request_context.ts`), not `get_resolved_auth`, so a narrowed token is
333
333
  * answered as the anonymous caller. The RPC endpoint is the exception — its
334
334
  * dispatcher gates each method against the scope.
@@ -1 +1 @@
1
- {"version":3,"file":"app_backend.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE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;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,YAAY,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,YACF,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACvC,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,iFAAiF;IACjF,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;;;;;;;;;;;;OAkBG;IACH,aAAa,EAAE,YAAY,CAAC;IAC5B;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,cAAc,CAAC;IACnC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IACzD;;;;;;;;;OASG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;;;OAOG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAU,SAAS,uBAAuB,KAAG,OAAO,CAAC,UAAU,CAwD7F,CAAC"}
@@ -13,6 +13,7 @@
13
13
  import { Logger } from '@fuzdev/fuz_util/log.ts';
14
14
  import { create_audit_emitter } from '../auth/audit_emitter.js';
15
15
  import { create_realtime_closer } from '../actions/connection_closer.js';
16
+ import { create_realtime_notification_sender } from '../actions/notification_sender.js';
16
17
  import { run_migrations } from '../db/migrate.js';
17
18
  import { AUTH_MIGRATION_NS } from '../auth/migrations.js';
18
19
  import { create_db, is_pg_database_url } from '../db/create_db.js';
@@ -80,7 +81,8 @@ export const create_app_backend = async (options) => {
80
81
  db,
81
82
  log,
82
83
  audit,
83
- connection_closer: options.connection_closer ?? create_realtime_closer()
84
+ connection_closer: options.connection_closer ?? create_realtime_closer(),
85
+ notification_sender: create_realtime_notification_sender()
84
86
  }
85
87
  };
86
88
  }
@@ -10,6 +10,7 @@
10
10
  import { Hono, type Context } from 'hono';
11
11
  import type { UpgradeWebSocket } from 'hono/ws';
12
12
  import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
13
+ import type { Logger } from '@fuzdev/fuz_util/log.ts';
13
14
  import { type SessionOptions } from '../auth/session_cookie.js';
14
15
  import type { BootstrapTokenStore } from '../auth/bootstrap_token_store.js';
15
16
  import { type EventSpec } from '../realtime/sse.js';
@@ -29,6 +30,7 @@ import { type EffectErrorContext } from '../http/pending_effects.js';
29
30
  import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
30
31
  import type { ConnectionRegistry } from '../actions/connection_registry.js';
31
32
  import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
33
+ import type { AuditEmitter } from '../auth/audit_emitter.js';
32
34
  /**
33
35
  * Bootstrap configuration for `AppServerOptions.bootstrap`.
34
36
  *
@@ -363,7 +365,7 @@ export interface AppServerOptions {
363
365
  * `(ctx: AppServerContext) => ReadonlyArray<WsEndpointSpec>`
364
366
  * (evaluated after the server context is assembled). Use the factory
365
367
  * form when action lists depend on `ctx.deps` — e.g. when spreading
366
- * `create_standard_rpc_actions({...ctx.deps, notification_sender})` over WS.
368
+ * `create_standard_rpc_actions(ctx.deps)` over WS.
367
369
  *
368
370
  * When non-empty, `upgrade_websocket` must be supplied (throws
369
371
  * otherwise). A factory returning `[]` does NOT trip the check —
@@ -387,7 +389,11 @@ export interface AppServerOptions {
387
389
  * the revocation handlers' post-commit closes reach its sockets, and so
388
390
  * does the one revocation guard `create_app_server` registers on that
389
391
  * closer (`create_revocation_guard`) when it mounts a WS endpoint or the
390
- * audit stream. `AppServer.close` removes it again.
392
+ * audit stream. Each is added to `deps.notification_sender` too, so a
393
+ * notification any action handler sends — over HTTP RPC or a socket —
394
+ * reaches the account's sockets on every mounted registry, once per
395
+ * registry however many endpoints share it. `AppServer.close` removes
396
+ * both memberships again.
391
397
  */
392
398
  ws_endpoints?: ReadonlyArray<WsEndpointSpec> | ((context: AppServerContext) => ReadonlyArray<WsEndpointSpec>);
393
399
  /**
@@ -419,6 +425,15 @@ export interface AppServerOptions {
419
425
  * Default `false` (production: true fire-and-forget).
420
426
  */
421
427
  await_pending_effects?: boolean;
428
+ /**
429
+ * How long `AppServer.close` waits for the effects still in flight — each
430
+ * request's unflushed `pending_effects` (failure audit rows, the session
431
+ * touch, token usage) and every pool write of `deps.audit` — before it
432
+ * closes the database. What is still running then is given up on and
433
+ * logged. Default `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive
434
+ * number of ms.
435
+ */
436
+ shutdown_drain_timeout_ms?: number;
422
437
  /**
423
438
  * Called when an eager pending effect rejects, on HTTP requests and on the
424
439
  * frames of every WS endpoint the server mounts, in either
@@ -470,17 +485,24 @@ export interface AppServer {
470
485
  * is left closing, so an upgrade or stream that registers afterward is
471
486
  * born closed — refused at once rather than outliving the server — and
472
487
  * a closed registry hosts no other server
473
- * 3. release what assembly acquired, last acquired first: remove the
488
+ * 3. wait for the effects still in flight — the unflushed
489
+ * `pending_effects` of requests already answered (failure audit rows,
490
+ * the session touch, token usage; production does not hold a response
491
+ * for them) and every pool write of `deps.audit` — bounded by
492
+ * `shutdown_drain_timeout_ms`, logging what it gives up on
493
+ * 4. release what assembly acquired, last acquired first: remove the
474
494
  * audit listeners `create_app_server` registered on `deps.audit` (the
475
- * revocation guard, the audit-log SSE listener) and the closer members it added to
476
- * `deps.connection_closer` (each mounted connection registry, the audit stream
477
- * registry), and `dispose` the rate limiters it built for omitted
478
- * options — never one passed in, which its caller owns. A release that
479
- * throws is logged and the rest still run. The backend's emitter and
480
- * closer are left as they were before assembly, so a failed assembly
481
- * can be retried on the same backend, and a backend whose `close` you
482
- * own (a test harness) can host another server
483
- * 4. close the database connection (`AppBackend.close`)
495
+ * revocation guard, the audit-log SSE listener), the members it added
496
+ * to `deps.connection_closer` (each mounted connection registry, the
497
+ * audit stream registry) and to `deps.notification_sender` (each
498
+ * mounted connection registry), and `dispose` the rate limiters it
499
+ * built for omitted options — never one passed in, which its caller
500
+ * owns. A release that throws is logged and the rest still run. The
501
+ * backend's emitter, closer and notification sender are left as they
502
+ * were before assembly, so a failed assembly can be retried on the same
503
+ * backend, and a backend whose `close` you own (a test harness) can
504
+ * host another server
505
+ * 5. close the database connection (`AppBackend.close`)
484
506
  *
485
507
  * Idempotent: a second call settles with the first one's outcome (a failed
486
508
  * close is not retried), and concurrent calls share one shutdown.
@@ -516,6 +538,12 @@ export declare const require_audit_sse: (source: {
516
538
  * `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
517
539
  */
518
540
  export declare const DEFAULT_BODY_LIMIT_BYTES: number;
541
+ /**
542
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
543
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
544
+ * `DEFAULT_DRAIN_TIMEOUT`.
545
+ */
546
+ export declare const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10000;
519
547
  /**
520
548
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
521
549
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -639,7 +667,10 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
639
667
  * to `backend.deps.connection_closer`, so the revocation handlers built from
640
668
  * `ctx.deps` close their connections with no further wiring, and — when the
641
669
  * server mounts either — one `create_revocation_guard` listener on that closer
642
- * repeats each close on the audit row.
670
+ * repeats each close on the audit row. Each WebSocket connection registry is
671
+ * added to `backend.deps.notification_sender` as well, the sender every
672
+ * mounted RPC and WebSocket dispatcher puts on its handler contexts, so an
673
+ * action's notification reaches the account's sockets with no wiring either.
643
674
  * The
644
675
  * `audit_sse` field on the returned `AppServer` (and the
645
676
  * `AppServerContext` passed to `create_route_specs`) is non-null in that
@@ -648,11 +679,12 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
648
679
  *
649
680
  * Assembly acquires a few things that outlive it — the rate limiters it
650
681
  * builds, the listeners it registers on `deps.audit`, the members it adds to
651
- * `deps.connection_closer` — and records a release for each as it goes. When
652
- * assembly throws, every release recorded so far runs, last acquired first
653
- * (one that throws is logged and the rest still run), and the original error
654
- * is rethrown: a failed assembly leaves the backend's emitter and closer as
655
- * it found them and no limiter timer running. When `auth_cleanup` is set, the
682
+ * `deps.connection_closer` and `deps.notification_sender` — and records a
683
+ * release for each as it goes. When assembly throws, every release recorded
684
+ * so far runs, last acquired first (one that throws is logged and the rest
685
+ * still run), and the original error is rethrown: a failed assembly leaves
686
+ * the backend's emitter, closer and notification sender as it found them and
687
+ * no limiter timer running. When `auth_cleanup` is set, the
656
688
  * auth cleanup schedule starts as the last step of assembly — nothing after
657
689
  * it can throw, so an assembly that throws leaves no schedule running.
658
690
  *
@@ -665,5 +697,24 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
665
697
  * @throws Error from any assembly step, after releasing what assembly acquired
666
698
  */
667
699
  export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
700
+ /**
701
+ * What `drain_effects_on_shutdown` gave up on at its bound, each counted on
702
+ * its own: a request flush still waiting on its audit writes has those
703
+ * writes counted in `audit_writes` too, so the two are not summed.
704
+ */
705
+ export interface ShutdownDrainGivenUp {
706
+ /** Request flushes still running. */
707
+ request_flushes: number;
708
+ /** Pool writes of the audit emitter still in flight. */
709
+ audit_writes: number;
710
+ }
711
+ /**
712
+ * Wait for the request flushes in flight and then the audit emitter's pool
713
+ * writes, until none is left or `timeout_ms` passes — then log an error naming
714
+ * what was given up on. Never rejects.
715
+ *
716
+ * @returns what was given up on, both counts `0` when everything settled
717
+ */
718
+ export declare const drain_effects_on_shutdown: (inflight_flushes: ReadonlySet<Promise<void>>, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
668
719
  export {};
669
720
  //# sourceMappingURL=app_server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app_server.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EAKN,KAAK,cAAc,EACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIN,KAAK,WAAW,EAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACN,WAAW,EAMX,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAKhF,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAIN,KAAK,SAAS,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACrF,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AAS,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GACtC,OAAO,sBAAsB,KAC3B,KAAK,CAAC,oBAAoB,CAgC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,SAAS,CAQpF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACrC,kBAAkB,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAC5C,OAAO,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,EAC9D,YAAY,MAAM,EAClB,KAAK,MAAM,KACT,OAAO,CAAC,oBAAoB,CAwB9B,CAAC"}
@@ -70,6 +70,12 @@ export const require_audit_sse = (source) => {
70
70
  * `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
71
71
  */
72
72
  export const DEFAULT_BODY_LIMIT_BYTES = 1024 * 1024;
73
+ /**
74
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
75
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
76
+ * `DEFAULT_DRAIN_TIMEOUT`.
77
+ */
78
+ export const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10_000;
73
79
  /**
74
80
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
75
81
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -196,7 +202,10 @@ export const collect_config_diagnostics = (input) => {
196
202
  * to `backend.deps.connection_closer`, so the revocation handlers built from
197
203
  * `ctx.deps` close their connections with no further wiring, and — when the
198
204
  * server mounts either — one `create_revocation_guard` listener on that closer
199
- * repeats each close on the audit row.
205
+ * repeats each close on the audit row. Each WebSocket connection registry is
206
+ * added to `backend.deps.notification_sender` as well, the sender every
207
+ * mounted RPC and WebSocket dispatcher puts on its handler contexts, so an
208
+ * action's notification reaches the account's sockets with no wiring either.
200
209
  * The
201
210
  * `audit_sse` field on the returned `AppServer` (and the
202
211
  * `AppServerContext` passed to `create_route_specs`) is non-null in that
@@ -205,11 +214,12 @@ export const collect_config_diagnostics = (input) => {
205
214
  *
206
215
  * Assembly acquires a few things that outlive it — the rate limiters it
207
216
  * builds, the listeners it registers on `deps.audit`, the members it adds to
208
- * `deps.connection_closer` — and records a release for each as it goes. When
209
- * assembly throws, every release recorded so far runs, last acquired first
210
- * (one that throws is logged and the rest still run), and the original error
211
- * is rethrown: a failed assembly leaves the backend's emitter and closer as
212
- * it found them and no limiter timer running. When `auth_cleanup` is set, the
217
+ * `deps.connection_closer` and `deps.notification_sender` — and records a
218
+ * release for each as it goes. When assembly throws, every release recorded
219
+ * so far runs, last acquired first (one that throws is logged and the rest
220
+ * still run), and the original error is rethrown: a failed assembly leaves
221
+ * the backend's emitter, closer and notification sender as it found them and
222
+ * no limiter timer running. When `auth_cleanup` is set, the
213
223
  * auth cleanup schedule starts as the last step of assembly — nothing after
214
224
  * it can throw, so an assembly that throws leaves no schedule running.
215
225
  *
@@ -231,6 +241,39 @@ export const create_app_server = async (options) => {
231
241
  throw error;
232
242
  }
233
243
  };
244
+ /**
245
+ * Wait for the request flushes in flight and then the audit emitter's pool
246
+ * writes, until none is left or `timeout_ms` passes — then log an error naming
247
+ * what was given up on. Never rejects.
248
+ *
249
+ * @returns what was given up on, both counts `0` when everything settled
250
+ */
251
+ export const drain_effects_on_shutdown = async (inflight_flushes, audit, timeout_ms, log) => {
252
+ const drain = async () => {
253
+ // wait for zero: a flush's post-commit thunk can start another write
254
+ while (inflight_flushes.size > 0)
255
+ await Promise.allSettled(inflight_flushes);
256
+ await audit.drain_inflight();
257
+ };
258
+ let timer;
259
+ const timed_out = new Promise((resolve) => {
260
+ timer = setTimeout(resolve, timeout_ms);
261
+ });
262
+ try {
263
+ await Promise.race([drain(), timed_out]);
264
+ }
265
+ finally {
266
+ clearTimeout(timer);
267
+ }
268
+ const given_up = {
269
+ request_flushes: inflight_flushes.size,
270
+ audit_writes: audit.inflight_count()
271
+ };
272
+ if (given_up.request_flushes === 0 && given_up.audit_writes === 0)
273
+ return given_up;
274
+ log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on effects still running — ${given_up.request_flushes} request flush(es), ${given_up.audit_writes} audit row write(s)`);
275
+ return given_up;
276
+ };
234
277
  /**
235
278
  * Run `releases` last-first and empty it. Each runs in its own `try`, so one
236
279
  * that throws is logged and the rest still run.
@@ -289,6 +332,10 @@ const assemble_app_server = async (options, releases) => {
289
332
  const body_limit_spec = options.max_body_size === null
290
333
  ? null
291
334
  : create_body_limit_middleware_spec(options.max_body_size ?? DEFAULT_BODY_LIMIT_BYTES);
335
+ const shutdown_drain_timeout_ms = options.shutdown_drain_timeout_ms ?? DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS;
336
+ if (!(shutdown_drain_timeout_ms > 0 && Number.isFinite(shutdown_drain_timeout_ms))) {
337
+ throw new Error(`create_app_server: shutdown_drain_timeout_ms must be a positive number of ms, got ${shutdown_drain_timeout_ms}`);
338
+ }
292
339
  // Rate limiters — the ones built here are the server's to dispose, on
293
340
  // close or when assembly fails.
294
341
  const { mode: rate_limiter_mode, limiters: rate_limiters, built: built_rate_limiters } = resolve_rate_limiters(options);
@@ -403,7 +450,8 @@ const assemble_app_server = async (options, releases) => {
403
450
  actions: endpoint.actions,
404
451
  log,
405
452
  action_ip_rate_limiter,
406
- action_account_rate_limiter
453
+ action_account_rate_limiter,
454
+ notification_sender: deps.notification_sender
407
455
  }));
408
456
  }
409
457
  }
@@ -554,6 +602,10 @@ const assemble_app_server = async (options, releases) => {
554
602
  // writes to settle — a revocation's connection close must not sit behind
555
603
  // a slow audit INSERT.
556
604
  const on_effect_error = options.on_effect_error;
605
+ // The flushes production leaves running past the response — what
606
+ // shutdown waits on before the database closes. Each removes itself as it
607
+ // settles; none rejects.
608
+ const inflight_flushes = new Set();
557
609
  app.use('*', async (c, next) => {
558
610
  c.set('pending_effects', []);
559
611
  c.set('post_commit_effects', []);
@@ -570,10 +622,13 @@ const assemble_app_server = async (options, releases) => {
570
622
  path: c.req.path
571
623
  };
572
624
  const flushed = flush_request_effects(eager, deferred, log, on_effect_error ? (reason) => on_effect_error(reason, error_ctx) : undefined);
573
- if (options.await_pending_effects)
625
+ if (options.await_pending_effects) {
574
626
  await flushed;
575
- else
576
- void flushed;
627
+ }
628
+ else {
629
+ inflight_flushes.add(flushed);
630
+ void flushed.then(() => inflight_flushes.delete(flushed));
631
+ }
577
632
  }
578
633
  }
579
634
  });
@@ -620,12 +675,17 @@ const assemble_app_server = async (options, releases) => {
620
675
  required_roles: endpoint.required_roles,
621
676
  action_ip_rate_limiter,
622
677
  action_account_rate_limiter,
678
+ notification_sender: deps.notification_sender,
623
679
  on_effect_error
624
680
  });
625
681
  mounted_ws_endpoints[endpoint.path] = endpoint_registry;
626
682
  // every revocation's close — the handlers' and the guard's — reaches
627
683
  // this registry
628
684
  releases.push(deps.connection_closer.add(endpoint_registry));
685
+ // and so does every action's notification, from either transport; a
686
+ // registry two endpoints share is one member, so no socket hears a
687
+ // notification twice
688
+ releases.push(deps.notification_sender.add(endpoint_registry));
629
689
  }
630
690
  }
631
691
  // Post-route middleware (before static serving)
@@ -665,6 +725,10 @@ const assemble_app_server = async (options, releases) => {
665
725
  catch (error) {
666
726
  log.error('create_app_server: closing live connections on shutdown failed:', error);
667
727
  }
728
+ // then the effects still in flight, so a failure row or a session touch
729
+ // a request already answered started is not lost to the closing pool —
730
+ // bounded, as the Rust spine's shutdown drain is
731
+ await drain_effects_on_shutdown(inflight_flushes, deps.audit, shutdown_drain_timeout_ms, log);
668
732
  // then what assembly acquired — the audit listeners and closer members
669
733
  // this server added, and the limiters it built
670
734
  run_releases(releases, log, 'shutdown');
@@ -71,14 +71,14 @@
71
71
  * Auth shape on the cell-scoped route is `{account: 'none', actor: 'none'}`
72
72
  * — the dispatcher's authorization phase is skipped for pure-public routes,
73
73
  * so the handler builds the `RequestContext` itself from the resolved account
74
- * id (`get_public_account_id`, over what the `/api/*` auth middleware set) by
74
+ * (`get_public_account`, over what the `/api/*` auth middleware set) by
75
75
  * resolving the caller's single actor and loading their role_grants.
76
76
  * Unauthed callers pass through with `req_ctx: null` and are admitted only by
77
77
  * a `cell.visibility === 'public'` cell whose `moderation` admits an audience (unmoderated or
78
78
  * `'approved'`). Multi-actor accounts fall through with `req_ctx: null`
79
79
  * — there's no `acting?` slot on a pure-public route, so multi-actor
80
80
  * callers are treated as anonymous. A scope-narrowed API token is treated as
81
- * anonymous too, not refused (`get_public_account_id`): a narrowed token
81
+ * anonymous too, not refused (`get_public_account`): a narrowed token
82
82
  * reaches no non-RPC surface, but on a route that admits anonymous callers
83
83
  * a 403 would enforce nothing — the holder drops the `Authorization` header and
84
84
  * re-reads every public cell anyway.
@@ -160,7 +160,7 @@ export interface CreateServeFactRouteSpecOptions {
160
160
  * other referrers.
161
161
  *
162
162
  * Pure-public auth — the handler builds the per-request `RequestContext`
163
- * from the resolved account id (`get_public_account_id`) and enforces
163
+ * from the resolved account id (`get_public_account`) and enforces
164
164
  * visibility per-reference.
165
165
  */
166
166
  export declare const create_serve_cell_fact_route_spec: (options: CreateServeFactRouteSpecOptions) => RouteSpec;