@zlink-systems/framework 0.30.3 → 0.32.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 (398) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Actors/ZLinkActor.d.ts +2 -0
  3. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.d.ts +6 -0
  4. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.js +2 -0
  5. package/dist/contracts/Actors/index.d.ts +1 -0
  6. package/dist/contracts/Actors/index.js +1 -0
  7. package/dist/contracts/Common/CoreTypes.d.ts +1 -0
  8. package/dist/contracts/Common/HandlerMessageType.d.ts +8 -0
  9. package/dist/contracts/Common/HandlerMessageType.js +41 -0
  10. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +1 -1
  11. package/dist/contracts/Common/ZLinkEncodedPayload.js +12 -20
  12. package/dist/contracts/Common/ZLinkMessage.js +11 -7
  13. package/dist/contracts/Common/encoded-payload-storage.d.ts +0 -2
  14. package/dist/contracts/Common/encoded-payload-storage.js +4 -16
  15. package/dist/contracts/Common/index.d.ts +1 -1
  16. package/dist/contracts/Common/payload-slab.d.ts +4 -0
  17. package/dist/contracts/Common/payload-slab.js +30 -0
  18. package/dist/contracts/Configuration/RegistrationBuilders.js +15 -9
  19. package/dist/contracts/Configuration/RegistrationTypes.d.ts +19 -0
  20. package/dist/contracts/Handlers/Contexts.d.ts +1 -0
  21. package/dist/contracts/Locations/Authority.d.ts +2 -0
  22. package/dist/internal.d.ts +9 -0
  23. package/dist/internal.js +23 -1
  24. package/dist/nest-integration.d.ts +1 -0
  25. package/dist/nest-integration.js +3 -1
  26. package/dist/runtime/actors/actor-client.d.ts +6 -2
  27. package/dist/runtime/actors/actor-client.js +120 -82
  28. package/dist/runtime/actors/actor-context.js +16 -5
  29. package/dist/runtime/actors/actor-execution-context.js +2 -2
  30. package/dist/runtime/actors/actor-handoff.d.ts +12 -1
  31. package/dist/runtime/actors/actor-handoff.js +79 -34
  32. package/dist/runtime/actors/actor-join-deferred-scope.js +6 -6
  33. package/dist/runtime/actors/actor-local-native-join.d.ts +2 -2
  34. package/dist/runtime/actors/actor-local-native-join.js +19 -17
  35. package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
  36. package/dist/runtime/actors/actor-remote-joiner.d.ts +2 -2
  37. package/dist/runtime/actors/actor-remote-joiner.js +4 -4
  38. package/dist/runtime/actors/actor-routed-join-transport.d.ts +9 -3
  39. package/dist/runtime/actors/actor-routed-json-request.d.ts +3 -0
  40. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -2
  41. package/dist/runtime/actors/actor-runtime-state.d.ts +1 -1
  42. package/dist/runtime/actors/spot-actor-dispatch.d.ts +9 -5
  43. package/dist/runtime/actors/spot-actor-dispatch.js +60 -38
  44. package/dist/runtime/admission.d.ts +6 -4
  45. package/dist/runtime/admission.js +21 -10
  46. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
  47. package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
  48. package/dist/runtime/backend/contracts/index.d.ts +26 -10
  49. package/dist/runtime/backend/mesh-completion-table.d.ts +7 -1
  50. package/dist/runtime/backend/mesh-completion-table.js +84 -20
  51. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +19 -6
  52. package/dist/runtime/backend/mesh-dispatch-pump.js +246 -147
  53. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -2
  54. package/dist/runtime/backend/node/node-backend-adapter-support.js +27 -19
  55. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +5 -2
  56. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +70 -13
  57. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  58. package/dist/runtime/backend/node/node-event-loop-poller.js +4 -3
  59. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
  60. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
  61. package/dist/runtime/backend/node/node-raw-binding-port.js +99 -63
  62. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +34 -16
  63. package/dist/runtime/backend/node/node-raw-mesh-backend.js +210 -106
  64. package/dist/runtime/backend/node/node-socket-backend-adapter.js +20 -6
  65. package/dist/runtime/backend/raw-binding-port.d.ts +6 -3
  66. package/dist/runtime/channels/channel-clients.js +3 -3
  67. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +11 -7
  68. package/dist/runtime/channels/channel-dispatch-pipeline.js +40 -22
  69. package/dist/runtime/channels/channel-dispatch-services.d.ts +3 -1
  70. package/dist/runtime/channels/channel-dispatch-services.js +7 -6
  71. package/dist/runtime/channels/channel-dispatchers.d.ts +13 -6
  72. package/dist/runtime/channels/channel-dispatchers.js +57 -36
  73. package/dist/runtime/channels/channel-envelope.d.ts +2 -2
  74. package/dist/runtime/channels/channel-envelope.js +609 -83
  75. package/dist/runtime/channels/channel-multipart.d.ts +1 -0
  76. package/dist/runtime/channels/channel-multipart.js +10 -6
  77. package/dist/runtime/channels/channel-outbound-operations.d.ts +6 -9
  78. package/dist/runtime/channels/channel-outbound-operations.js +107 -105
  79. package/dist/runtime/channels/channel-receive-loops.d.ts +9 -7
  80. package/dist/runtime/channels/channel-receive-loops.js +126 -90
  81. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +23 -6
  82. package/dist/runtime/channels/channel-runtime-lifecycle.js +47 -38
  83. package/dist/runtime/channels/channel-runtime-manager.d.ts +13 -6
  84. package/dist/runtime/channels/channel-runtime-manager.js +32 -14
  85. package/dist/runtime/channels/channel-socket-registry.d.ts +28 -4
  86. package/dist/runtime/channels/channel-socket-registry.js +9 -1
  87. package/dist/runtime/channels/channel-transports.d.ts +23 -16
  88. package/dist/runtime/channels/channel-transports.js +139 -119
  89. package/dist/runtime/channels/dispatch-error-reporter.d.ts +4 -4
  90. package/dist/runtime/channels/dispatch-error-reporter.js +5 -5
  91. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  92. package/dist/runtime/channels/local-spot-route-transport.d.ts +5 -2
  93. package/dist/runtime/channels/local-spot-route-transport.js +15 -18
  94. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +6 -3
  95. package/dist/runtime/channels/router-socket-spot-route-transport.js +33 -19
  96. package/dist/runtime/channels/source-spot-router.d.ts +6 -3
  97. package/dist/runtime/channels/source-spot-router.js +34 -23
  98. package/dist/runtime/channels/spot-node-route-transport.d.ts +6 -3
  99. package/dist/runtime/channels/spot-node-route-transport.js +23 -17
  100. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +6 -3
  101. package/dist/runtime/channels/spot-route-bridge-transport.js +38 -24
  102. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +8 -4
  103. package/dist/runtime/channels/spot-route-dispatch-strategy.js +36 -23
  104. package/dist/runtime/diagnostics/dispatch-error-details.js +9 -3
  105. package/dist/runtime/diagnostics/message-flow-bootstrap.d.ts +1 -0
  106. package/dist/runtime/diagnostics/message-flow-bootstrap.js +8 -0
  107. package/dist/runtime/diagnostics/message-flow-delivery.d.ts +47 -0
  108. package/dist/runtime/diagnostics/message-flow-delivery.js +149 -0
  109. package/dist/runtime/diagnostics/message-flow-record.d.ts +50 -0
  110. package/dist/runtime/diagnostics/message-flow-record.js +228 -0
  111. package/dist/runtime/diagnostics/message-flow-worker.d.ts +1 -0
  112. package/dist/runtime/diagnostics/message-flow-worker.js +118 -0
  113. package/dist/runtime/diagnostics/message-flow.d.ts +7 -19
  114. package/dist/runtime/diagnostics/message-flow.js +42 -290
  115. package/dist/runtime/diagnostics/runtime-metrics.d.ts +4 -3
  116. package/dist/runtime/diagnostics/runtime-metrics.js +8 -4
  117. package/dist/runtime/execution/index.d.ts +1 -0
  118. package/dist/runtime/execution/index.js +6 -3
  119. package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
  120. package/dist/runtime/execution/serial-execution-queue.js +75 -71
  121. package/dist/runtime/foundation/durable-service-request.d.ts +12 -3
  122. package/dist/runtime/foundation/durable-service-request.js +158 -73
  123. package/dist/runtime/foundation/operation-registry.d.ts +33 -3
  124. package/dist/runtime/foundation/operation-registry.js +272 -33
  125. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +62 -23
  126. package/dist/runtime/foundation/raw-service-mesh-runtime.js +373 -194
  127. package/dist/runtime/foundation/request-runtime.d.ts +17 -0
  128. package/dist/runtime/foundation/request-runtime.js +163 -0
  129. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  130. package/dist/runtime/foundation/service-discovery-registry.js +6 -0
  131. package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
  132. package/dist/runtime/foundation/service-mailbox.d.ts +4 -2
  133. package/dist/runtime/foundation/service-mailbox.js +4 -1
  134. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -2
  135. package/dist/runtime/foundation/service-relocation-object-owner.js +12 -5
  136. package/dist/runtime/foundation/service-runtime-contracts.d.ts +7 -2
  137. package/dist/runtime/foundation/service-stateful-registry.d.ts +6 -2
  138. package/dist/runtime/foundation/service-stateful-registry.js +38 -17
  139. package/dist/runtime/foundation/service-stateful-runtime.d.ts +91 -26
  140. package/dist/runtime/foundation/service-stateful-runtime.js +245 -120
  141. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
  142. package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
  143. package/dist/runtime/foundation/service-topology-registry.d.ts +2 -0
  144. package/dist/runtime/foundation/service-topology-registry.js +13 -3
  145. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  146. package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
  147. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +5 -1
  148. package/dist/runtime/foundation/service-wire-m6a-codec.js +50 -15
  149. package/dist/runtime/host/actor-packet-relay.d.ts +5 -6
  150. package/dist/runtime/host/actor-packet-relay.js +58 -57
  151. package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
  152. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  153. package/dist/runtime/host/actor-runtime-options-factory.js +3 -2
  154. package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
  155. package/dist/runtime/host/application-job-queue.d.ts +7 -5
  156. package/dist/runtime/host/application-job-queue.js +33 -21
  157. package/dist/runtime/host/bound-session-relay.js +0 -1
  158. package/dist/runtime/host/channel-runtime-options-factory.d.ts +2 -0
  159. package/dist/runtime/host/channel-runtime-options-factory.js +1 -0
  160. package/dist/runtime/host/entry-actor-runtime.d.ts +5 -2
  161. package/dist/runtime/host/entry-actor-runtime.js +2 -2
  162. package/dist/runtime/host/index.d.ts +106 -37
  163. package/dist/runtime/host/index.js +303 -151
  164. package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
  165. package/dist/runtime/host/location-runtime-owner.js +1 -1
  166. package/dist/runtime/host/service-relocation-host-runtime.d.ts +195 -45
  167. package/dist/runtime/host/service-relocation-host-runtime.js +257 -144
  168. package/dist/runtime/host/spot-address-transport.d.ts +3 -0
  169. package/dist/runtime/host/spot-address-transport.js +73 -76
  170. package/dist/runtime/host/spot-runtime-options-factory.js +2 -0
  171. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -1
  172. package/dist/runtime/host/user-spot-creation-coordinator.js +49 -21
  173. package/dist/runtime/internal-observation.d.ts +1 -0
  174. package/dist/runtime/internal-observation.js +5 -0
  175. package/dist/runtime/locations/actor-location-claims.d.ts +1 -1
  176. package/dist/runtime/locations/actor-location-claims.js +15 -6
  177. package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
  178. package/dist/runtime/locations/auto-connect-loop.js +25 -19
  179. package/dist/runtime/locations/auto-connect-planner.js +2 -5
  180. package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
  181. package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
  182. package/dist/runtime/locations/in-memory-authority-store.d.ts +1 -0
  183. package/dist/runtime/locations/in-memory-authority-store.js +15 -5
  184. package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
  185. package/dist/runtime/locations/in-memory-location-store.js +1 -38
  186. package/dist/runtime/locations/lifecycle.d.ts +1 -1
  187. package/dist/runtime/locations/lifecycle.js +2 -2
  188. package/dist/runtime/locations/location-store-repository.d.ts +0 -1
  189. package/dist/runtime/locations/location-store-repository.js +163 -246
  190. package/dist/runtime/locations/resolvers.d.ts +8 -1
  191. package/dist/runtime/locations/resolvers.js +16 -2
  192. package/dist/runtime/locations/runtime.d.ts +3 -3
  193. package/dist/runtime/locations/runtime.js +12 -16
  194. package/dist/runtime/messaging/creation-payload-codec.js +8 -7
  195. package/dist/runtime/messaging/framework-json-v1.d.ts +1 -1
  196. package/dist/runtime/messaging/framework-json-v1.js +6 -2
  197. package/dist/runtime/messaging/payload-codec.js +21 -35
  198. package/dist/runtime/messaging/request-deadline.d.ts +4 -2
  199. package/dist/runtime/messaging/request-deadline.js +40 -25
  200. package/dist/runtime/messaging/request-result.d.ts +14 -1
  201. package/dist/runtime/messaging/request-result.js +74 -13
  202. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
  203. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
  204. package/dist/runtime/spots/index.d.ts +28 -7
  205. package/dist/runtime/spots/index.js +31 -6
  206. package/dist/runtime/spots/spot-activation-registry.d.ts +3 -2
  207. package/dist/runtime/spots/spot-activation-registry.js +13 -8
  208. package/dist/runtime/spots/spot-activation-state.d.ts +2 -0
  209. package/dist/runtime/spots/spot-activation-state.js +1 -0
  210. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +9 -4
  211. package/dist/runtime/spots/spot-actor-admission-coordinator.js +33 -12
  212. package/dist/runtime/spots/spot-actor-ingress-admission.d.ts +40 -0
  213. package/dist/runtime/spots/spot-actor-ingress-admission.js +78 -0
  214. package/dist/runtime/spots/spot-actor-membership.js +3 -3
  215. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +16 -43
  216. package/dist/runtime/spots/spot-actor-packet-dispatch.js +56 -113
  217. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
  218. package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
  219. package/dist/runtime/spots/spot-entry-activation.d.ts +4 -3
  220. package/dist/runtime/spots/spot-entry-activation.js +7 -12
  221. package/dist/runtime/spots/spot-handler-registry.d.ts +5 -1
  222. package/dist/runtime/spots/spot-handler-registry.js +31 -15
  223. package/dist/runtime/spots/spot-manager-public.js +3 -2
  224. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +11 -6
  225. package/dist/runtime/spots/spot-node-runtime-manager.js +6 -1
  226. package/dist/runtime/spots/spot-outbound.d.ts +8 -2
  227. package/dist/runtime/spots/spot-outbound.js +5 -5
  228. package/dist/runtime/spots/spot-route-packet-dispatch.js +13 -8
  229. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +3 -3
  230. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +9 -5
  231. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -2
  232. package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
  233. package/dist/runtime/spots/spot-serial-turn-executor.js +20 -26
  234. package/dist/runtime/spots/spot-subscription-dispatch.js +5 -2
  235. package/dist/runtime/spots/spot-timer.d.ts +1 -1
  236. package/dist/runtime/streams/actor-session-binding-registry.d.ts +11 -3
  237. package/dist/runtime/streams/actor-session-binding-registry.js +28 -0
  238. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
  239. package/dist/runtime/streams/bound-actor-relay-sender.js +3 -4
  240. package/dist/runtime/streams/bound-session-service.js +6 -7
  241. package/dist/runtime/streams/index.d.ts +3 -3
  242. package/dist/runtime/streams/index.js +22 -2
  243. package/dist/runtime/streams/managed-stream.js +2 -1
  244. package/dist/runtime/streams/session-calls.d.ts +1 -1
  245. package/dist/runtime/streams/session-calls.js +3 -9
  246. package/dist/runtime/streams/session-context.d.ts +2 -2
  247. package/dist/runtime/streams/session-context.js +2 -2
  248. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
  249. package/dist/runtime/streams/stream-session-runtime.js +64 -33
  250. package/package.json +3 -3
  251. package/src/contracts/Actors/ZLinkActor.ts +6 -0
  252. package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
  253. package/src/contracts/Actors/index.ts +1 -0
  254. package/src/contracts/Common/CoreTypes.ts +1 -0
  255. package/src/contracts/Common/HandlerMessageType.ts +50 -0
  256. package/src/contracts/Common/ZLinkEncodedPayload.ts +13 -25
  257. package/src/contracts/Common/ZLinkMessage.ts +11 -7
  258. package/src/contracts/Common/encoded-payload-storage.ts +4 -16
  259. package/src/contracts/Common/index.ts +1 -1
  260. package/src/contracts/Common/payload-slab.ts +29 -0
  261. package/src/contracts/Configuration/RegistrationBuilders.ts +29 -15
  262. package/src/contracts/Configuration/RegistrationTypes.ts +19 -0
  263. package/src/contracts/Handlers/Contexts.ts +1 -0
  264. package/src/contracts/Locations/Authority.ts +7 -1
  265. package/src/internal.ts +17 -0
  266. package/src/nest-integration.ts +1 -0
  267. package/src/runtime/actors/actor-client.ts +257 -163
  268. package/src/runtime/actors/actor-context.ts +26 -14
  269. package/src/runtime/actors/actor-execution-context.ts +2 -2
  270. package/src/runtime/actors/actor-handoff.ts +86 -51
  271. package/src/runtime/actors/actor-join-deferred-scope.ts +6 -6
  272. package/src/runtime/actors/actor-local-native-join.ts +38 -17
  273. package/src/runtime/actors/actor-mailbox.ts +1 -1
  274. package/src/runtime/actors/actor-remote-joiner.ts +8 -4
  275. package/src/runtime/actors/actor-routed-join-transport.ts +13 -5
  276. package/src/runtime/actors/actor-routed-json-request.ts +3 -0
  277. package/src/runtime/actors/actor-runtime-contracts.ts +4 -2
  278. package/src/runtime/actors/actor-runtime-state.ts +1 -1
  279. package/src/runtime/actors/spot-actor-dispatch.ts +70 -68
  280. package/src/runtime/admission.ts +42 -15
  281. package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
  282. package/src/runtime/backend/contracts/index.ts +77 -10
  283. package/src/runtime/backend/mesh-completion-table.ts +106 -15
  284. package/src/runtime/backend/mesh-dispatch-pump.ts +294 -146
  285. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -32
  286. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +91 -34
  287. package/src/runtime/backend/node/node-event-loop-poller.ts +14 -5
  288. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
  289. package/src/runtime/backend/node/node-raw-binding-port.ts +180 -69
  290. package/src/runtime/backend/node/node-raw-mesh-backend.ts +386 -157
  291. package/src/runtime/backend/node/node-socket-backend-adapter.ts +56 -11
  292. package/src/runtime/backend/raw-binding-port.ts +13 -5
  293. package/src/runtime/channels/channel-clients.ts +26 -11
  294. package/src/runtime/channels/channel-dispatch-pipeline.ts +77 -65
  295. package/src/runtime/channels/channel-dispatch-services.ts +7 -12
  296. package/src/runtime/channels/channel-dispatchers.ts +93 -39
  297. package/src/runtime/channels/channel-envelope.ts +680 -144
  298. package/src/runtime/channels/channel-multipart.ts +17 -13
  299. package/src/runtime/channels/channel-outbound-operations.ts +204 -178
  300. package/src/runtime/channels/channel-receive-loops.ts +160 -107
  301. package/src/runtime/channels/channel-runtime-lifecycle.ts +64 -59
  302. package/src/runtime/channels/channel-runtime-manager.ts +74 -27
  303. package/src/runtime/channels/channel-socket-registry.ts +20 -5
  304. package/src/runtime/channels/channel-transports.ts +414 -287
  305. package/src/runtime/channels/dispatch-error-reporter.ts +4 -9
  306. package/src/runtime/channels/local-spot-route-transport.ts +27 -29
  307. package/src/runtime/channels/router-socket-spot-route-transport.ts +63 -32
  308. package/src/runtime/channels/source-spot-router.ts +75 -38
  309. package/src/runtime/channels/spot-node-route-transport.ts +67 -37
  310. package/src/runtime/channels/spot-route-bridge-transport.ts +62 -30
  311. package/src/runtime/channels/spot-route-dispatch-strategy.ts +105 -34
  312. package/src/runtime/diagnostics/dispatch-error-details.ts +10 -2
  313. package/src/runtime/diagnostics/message-flow-bootstrap.ts +6 -0
  314. package/src/runtime/diagnostics/message-flow-delivery.ts +171 -0
  315. package/src/runtime/diagnostics/message-flow-record.ts +295 -0
  316. package/src/runtime/diagnostics/message-flow-worker.ts +146 -0
  317. package/src/runtime/diagnostics/message-flow.ts +49 -362
  318. package/src/runtime/diagnostics/runtime-metrics.ts +10 -4
  319. package/src/runtime/execution/index.ts +6 -0
  320. package/src/runtime/execution/serial-execution-queue.ts +94 -96
  321. package/src/runtime/foundation/durable-service-request.ts +212 -89
  322. package/src/runtime/foundation/operation-registry.ts +287 -38
  323. package/src/runtime/foundation/raw-service-mesh-runtime.ts +617 -292
  324. package/src/runtime/foundation/request-runtime.ts +227 -0
  325. package/src/runtime/foundation/service-discovery-registry.ts +7 -0
  326. package/src/runtime/foundation/service-liveness-registry.ts +1 -1
  327. package/src/runtime/foundation/service-mailbox.ts +7 -2
  328. package/src/runtime/foundation/service-relocation-object-owner.ts +21 -6
  329. package/src/runtime/foundation/service-runtime-contracts.ts +12 -2
  330. package/src/runtime/foundation/service-stateful-registry.ts +52 -19
  331. package/src/runtime/foundation/service-stateful-runtime.ts +365 -198
  332. package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
  333. package/src/runtime/foundation/service-topology-registry.ts +21 -3
  334. package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
  335. package/src/runtime/foundation/service-wire-m6a-codec.ts +69 -17
  336. package/src/runtime/host/actor-packet-relay.ts +160 -156
  337. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  338. package/src/runtime/host/actor-runtime-options-factory.ts +7 -2
  339. package/src/runtime/host/actor-transfer-runtime.ts +3 -3
  340. package/src/runtime/host/application-job-queue.ts +56 -27
  341. package/src/runtime/host/bound-session-relay.ts +0 -1
  342. package/src/runtime/host/channel-runtime-options-factory.ts +3 -0
  343. package/src/runtime/host/entry-actor-runtime.ts +14 -6
  344. package/src/runtime/host/index.ts +388 -113
  345. package/src/runtime/host/location-runtime-owner.ts +3 -3
  346. package/src/runtime/host/service-relocation-host-runtime.ts +380 -252
  347. package/src/runtime/host/spot-address-transport.ts +110 -95
  348. package/src/runtime/host/spot-runtime-options-factory.ts +3 -0
  349. package/src/runtime/host/user-spot-creation-coordinator.ts +69 -22
  350. package/src/runtime/internal-observation.ts +2 -0
  351. package/src/runtime/locations/actor-location-claims.ts +42 -16
  352. package/src/runtime/locations/auto-connect-loop.ts +24 -16
  353. package/src/runtime/locations/auto-connect-planner.ts +2 -5
  354. package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
  355. package/src/runtime/locations/in-memory-authority-store.ts +27 -7
  356. package/src/runtime/locations/in-memory-location-store.ts +1 -74
  357. package/src/runtime/locations/lifecycle.ts +4 -2
  358. package/src/runtime/locations/location-store-repository.ts +228 -308
  359. package/src/runtime/locations/resolvers.ts +20 -8
  360. package/src/runtime/locations/runtime.ts +16 -28
  361. package/src/runtime/messaging/creation-payload-codec.ts +12 -10
  362. package/src/runtime/messaging/framework-json-v1.ts +10 -1
  363. package/src/runtime/messaging/payload-codec.ts +50 -75
  364. package/src/runtime/messaging/request-deadline.ts +47 -39
  365. package/src/runtime/messaging/request-result.ts +88 -17
  366. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  367. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  368. package/src/runtime/spots/index.ts +57 -10
  369. package/src/runtime/spots/spot-activation-registry.ts +12 -8
  370. package/src/runtime/spots/spot-activation-state.ts +2 -0
  371. package/src/runtime/spots/spot-actor-admission-coordinator.ts +62 -37
  372. package/src/runtime/spots/spot-actor-ingress-admission.ts +157 -0
  373. package/src/runtime/spots/spot-actor-membership.ts +8 -5
  374. package/src/runtime/spots/spot-actor-packet-dispatch.ts +122 -206
  375. package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
  376. package/src/runtime/spots/spot-entry-activation.ts +25 -35
  377. package/src/runtime/spots/spot-handler-registry.ts +72 -15
  378. package/src/runtime/spots/spot-manager-public.ts +4 -2
  379. package/src/runtime/spots/spot-node-runtime-manager.ts +16 -7
  380. package/src/runtime/spots/spot-outbound.ts +26 -10
  381. package/src/runtime/spots/spot-route-packet-dispatch.ts +18 -8
  382. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +14 -8
  383. package/src/runtime/spots/spot-runtime-ports.ts +5 -2
  384. package/src/runtime/spots/spot-serial-executor.ts +1 -1
  385. package/src/runtime/spots/spot-serial-turn-executor.ts +25 -40
  386. package/src/runtime/spots/spot-subscription-dispatch.ts +9 -2
  387. package/src/runtime/spots/spot-timer.ts +1 -1
  388. package/src/runtime/streams/actor-session-binding-registry.ts +46 -3
  389. package/src/runtime/streams/bound-actor-relay-sender.ts +16 -5
  390. package/src/runtime/streams/bound-session-service.ts +10 -7
  391. package/src/runtime/streams/index.ts +30 -4
  392. package/src/runtime/streams/managed-stream.ts +2 -1
  393. package/src/runtime/streams/session-calls.ts +9 -14
  394. package/src/runtime/streams/session-context.ts +6 -11
  395. package/src/runtime/streams/stream-session-runtime.ts +79 -40
  396. package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +0 -8
  397. package/dist/runtime/spots/spot-lifecycle-metrics.js +0 -17
  398. package/src/runtime/spots/spot-lifecycle-metrics.ts +0 -16
@@ -0,0 +1,17 @@
1
+ import { OperationRegistry, type OperationHandle, type OperationObserver, type PendingOperation } from './operation-registry';
2
+ import { type ZLinkRequestResult } from '../messaging/request-result';
3
+ /** Owns the request entries and deadline visits of one runtime instance. */
4
+ export declare class RequestRuntime {
5
+ readonly registry: OperationRegistry<unknown, unknown>;
6
+ private timer?;
7
+ private dueMs;
8
+ begin<T>(timeoutMs: number | undefined, signal?: AbortSignal, existing?: PendingOperation<unknown>, absoluteDeadlineMs?: number): PendingOperation<T>;
9
+ run<T>(pending: PendingOperation<unknown>, start: (receiver: OperationObserver<unknown, unknown>) => void, decode: (raw: unknown) => T, mapFailure: (error: unknown) => unknown, destination?: OperationObserver<unknown, unknown>): Promise<T>;
10
+ request<T>(timeoutMs: number | undefined, signal: AbortSignal | undefined, work: (pending: PendingOperation<unknown>) => Promise<T>, existing?: PendingOperation<unknown>, discardLateResult?: (value: T) => void): Promise<T>;
11
+ prepare<T>(timeoutMs: number | undefined, signal: AbortSignal | undefined, start: (pending: PendingOperation<unknown>, receiver: OperationObserver<unknown, unknown>) => void, decode: (raw: unknown) => T, mapFailure: (error: unknown) => unknown, existing?: PendingOperation<unknown>, destination?: OperationObserver<unknown, unknown>): ZLinkRequestResult<T>;
12
+ observe<T, R = T>(timeoutMs: number, submit: (entry: OperationHandle<T>, receiver: OperationObserver<T, unknown>) => void, onReply: (value: T) => R, onFailed: (error: unknown) => R): Promise<R>;
13
+ operations<T, Context = unknown>(): OperationRegistry<T, Context>;
14
+ close(reason?: unknown): void;
15
+ private schedule;
16
+ private readonly visit;
17
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestRuntime = void 0;
4
+ const request_deadline_1 = require("../messaging/request-deadline");
5
+ const contracts_1 = require("../../contracts");
6
+ const operation_registry_1 = require("./operation-registry");
7
+ const abort_1 = require("../abort");
8
+ const request_result_1 = require("../messaging/request-result");
9
+ /** Owns the request entries and deadline visits of one runtime instance. */
10
+ class RequestRuntime {
11
+ registry = new operation_registry_1.OperationRegistry(undefined, () => this.schedule(), (reason) => (0, request_deadline_1.requestTerminalError)('Request', reason));
12
+ timer;
13
+ dueMs = Number.POSITIVE_INFINITY;
14
+ begin(timeoutMs, signal, existing, absoluteDeadlineMs) {
15
+ if (existing !== undefined)
16
+ return existing;
17
+ const operation = this.registry.register(timeoutMs ?? 0, timeoutMs === undefined ? 'sender' : 'registry', undefined, absoluteDeadlineMs);
18
+ operation.setSignal(signal);
19
+ return operation;
20
+ }
21
+ run(pending, start, decode, mapFailure, destination) {
22
+ if (!pending.isPending())
23
+ return pending.promise;
24
+ pending.deferCompletion();
25
+ const receiver = {
26
+ operationCompleted: (_id, raw) => {
27
+ try {
28
+ const value = decode(raw);
29
+ if (destination !== undefined)
30
+ destination.operationCompleted(pending.id, value, undefined);
31
+ else
32
+ pending.complete(value);
33
+ }
34
+ catch (error) {
35
+ if (destination !== undefined)
36
+ destination.operationFailed(pending.id, error, undefined);
37
+ else
38
+ pending.fail(error);
39
+ }
40
+ },
41
+ operationFailed: (_id, error) => {
42
+ let failure = error;
43
+ try {
44
+ failure = mapFailure(error);
45
+ }
46
+ catch (mapped) {
47
+ failure = mapped;
48
+ }
49
+ if (destination !== undefined)
50
+ destination.operationFailed(pending.id, failure, undefined);
51
+ else
52
+ pending.fail(failure);
53
+ }
54
+ };
55
+ try {
56
+ start(receiver);
57
+ }
58
+ catch (error) {
59
+ receiver.operationFailed(pending.id, error, undefined);
60
+ }
61
+ return pending.promise;
62
+ }
63
+ request(timeoutMs, signal, work, existing, discardLateResult) {
64
+ if (existing !== undefined) {
65
+ if (!existing.isPending())
66
+ return existing.promise.then(() => {
67
+ throw new operation_registry_1.OperationCancelledError(existing.id, 'Request is already terminal.');
68
+ });
69
+ return work(existing);
70
+ }
71
+ const pending = this.begin(timeoutMs, signal, existing);
72
+ return this.run(pending, (receiver) => {
73
+ void work(pending).then((value) => receiver.operationCompleted(pending.id, value, undefined), (error) => receiver.operationFailed(pending.id, error, undefined));
74
+ }, (value) => {
75
+ if (!pending.isPending())
76
+ discardLateResult?.(value);
77
+ return value;
78
+ }, request_result_1.identityRequestReply);
79
+ }
80
+ prepare(timeoutMs, signal, start, decode, mapFailure, existing, destination) {
81
+ if (signal?.aborted === true && destination === undefined)
82
+ return (0, request_result_1.rejectZLinkRequestReply)(signal.reason ?? (0, abort_1.createAbortError)());
83
+ const operation = this.begin(timeoutMs, signal, existing);
84
+ if (signal?.aborted === true && destination !== undefined)
85
+ destination.operationFailed(operation.id, signal.reason ?? (0, abort_1.createAbortError)(), undefined);
86
+ const pending = signal?.aborted === true
87
+ ? operation.promise
88
+ : this.run(operation, (receiver) => start(operation, receiver), decode, mapFailure, destination);
89
+ return {
90
+ pending,
91
+ decode: (request_result_1.identityRequestReply),
92
+ mapFailure: request_result_1.identityRequestReply,
93
+ operation: operation
94
+ };
95
+ }
96
+ observe(timeoutMs, submit, onReply, onFailed) {
97
+ return new Promise((resolve, reject) => {
98
+ const observer = {
99
+ operationCompleted: (_id, value) => {
100
+ try {
101
+ resolve(onReply(value));
102
+ }
103
+ catch (error) {
104
+ reject(error);
105
+ }
106
+ },
107
+ operationFailed: (_id, reason) => {
108
+ try {
109
+ resolve(onFailed((0, request_deadline_1.requestTerminalError)('Request', reason)));
110
+ }
111
+ catch (error) {
112
+ reject(error);
113
+ }
114
+ }
115
+ };
116
+ const id = this.registry.registerObserved(timeoutMs, observer);
117
+ const entry = this.registry.handle(id);
118
+ try {
119
+ submit(entry, {
120
+ operationCompleted: (_id, value) => {
121
+ if (!entry.complete(value))
122
+ observer.operationCompleted(id, value, undefined);
123
+ },
124
+ operationFailed: (_id, error) => entry.fail(error)
125
+ });
126
+ }
127
+ catch (error) {
128
+ entry.fail(error);
129
+ }
130
+ });
131
+ }
132
+ operations() {
133
+ return this.registry;
134
+ }
135
+ close(reason = new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ShuttingDown, 'Request runtime closed.')) {
136
+ this.registry.clear(reason);
137
+ this.schedule();
138
+ }
139
+ schedule() {
140
+ const next = this.registry.nextDeadlineMs();
141
+ if (next < this.dueMs) {
142
+ clearTimeout(this.timer);
143
+ this.timer = undefined;
144
+ this.dueMs = next;
145
+ if (Number.isFinite(next))
146
+ this.timer = setTimeout(this.visit, Math.min(0x7fff_ffff, Math.ceil(next - performance.now())));
147
+ }
148
+ if (this.timer !== undefined) {
149
+ if (this.registry.size === 0)
150
+ this.timer.unref();
151
+ else
152
+ this.timer.ref();
153
+ }
154
+ }
155
+ visit = () => {
156
+ this.timer = undefined;
157
+ this.dueMs = Number.POSITIVE_INFINITY;
158
+ const now = performance.now();
159
+ this.registry.expire(now, now + 1);
160
+ this.schedule();
161
+ };
162
+ }
163
+ exports.RequestRuntime = RequestRuntime;
@@ -1,3 +1,4 @@
1
+ import { inspectRuntime } from '../internal-observation';
1
2
  export interface ClientServerDescriptor {
2
3
  readonly channelName: string;
3
4
  readonly serverRoutingId: string;
@@ -23,6 +24,9 @@ export interface SelectedClientServer {
23
24
  }
24
25
  /** Dedicated discovery state; fanout publishers never reuse RouteMesh peer rows. */
25
26
  export declare class ServiceDiscoveryRegistry {
27
+ [inspectRuntime](): Readonly<{
28
+ clientServerObservers: number;
29
+ }>;
26
30
  private readonly clientServerChanged;
27
31
  onClientServerChanged(listener: (error?: Error) => void): () => void;
28
32
  dispose(error: Error): void;
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceDiscoveryRegistry = void 0;
4
+ const internal_observation_1 = require("../internal-observation");
4
5
  const RegistrationBuilderPolicy_1 = require("../../contracts/Configuration/RegistrationBuilderPolicy");
5
6
  const service_weighted_selection_1 = require("./service-weighted-selection");
6
7
  /** Dedicated discovery state; fanout publishers never reuse RouteMesh peer rows. */
7
8
  class ServiceDiscoveryRegistry {
9
+ [internal_observation_1.inspectRuntime]() {
10
+ return Object.freeze({
11
+ clientServerObservers: this.clientServerChanged.size
12
+ });
13
+ }
8
14
  clientServerChanged = new Set();
9
15
  onClientServerChanged(listener) {
10
16
  this.clientServerChanged.add(listener);
@@ -25,7 +25,7 @@ export declare class ServiceLivenessConnection {
25
25
  export declare class ServiceLivenessRegistry {
26
26
  private readonly probeIntervalMs;
27
27
  private readonly peerTimeoutMs;
28
- private readonly peers;
28
+ readonly peers: Map<string, ServiceLivenessConnection>;
29
29
  private nextProbeId;
30
30
  /**
31
31
  * The earliest probe or timeout among admitted peers. Received traffic only
@@ -6,6 +6,7 @@ export interface ServiceMailboxDispatchOwner {
6
6
  prepareDispatch(record: ServiceMailboxRecord, signal: AbortSignal): boolean | Promise<boolean>;
7
7
  }
8
8
  export interface ServiceMailboxRecord {
9
+ receivedAt?: Date;
9
10
  readonly sourcePreparationOwner?: ServiceMailboxDispatchOwner;
10
11
  readonly ingress?: RawServiceIngressRecord;
11
12
  readonly owner: string;
@@ -15,7 +16,7 @@ export interface ServiceMailboxRecord {
15
16
  readonly requestSource?: import('../locations/request-source-resolver').ZLinkRequestSourceFence;
16
17
  readonly sourceRoute?: Uint8Array;
17
18
  readonly requestSequence?: bigint;
18
- readonly reply?: (parts: readonly Uint8Array[]) => void;
19
+ readonly reply?: (parts: readonly (Uint8Array | string)[]) => void;
19
20
  readonly correlation?: bigint;
20
21
  readonly localReply?: (terminalResult: number, failureCode: number, payload?: {
21
22
  readonly packetName: string;
@@ -42,6 +43,7 @@ export interface ServiceMailboxRelocationSeal {
42
43
  /** Level-triggered queues with one active application claim per owner. */
43
44
  export declare class ServiceMailbox {
44
45
  private readonly onReady?;
46
+ private readonly receivedAtClock;
45
47
  private readonly application;
46
48
  private readonly infrastructure;
47
49
  private readonly relocationSeals;
@@ -49,7 +51,7 @@ export declare class ServiceMailbox {
49
51
  private nextClaimSerial;
50
52
  private nextRelocationSerial;
51
53
  private closed;
52
- constructor(onReady?: ((domain: ServiceMailboxDomain) => void) | undefined);
54
+ constructor(onReady?: ((domain: ServiceMailboxDomain) => void) | undefined, receivedAtClock?: () => Date);
53
55
  releaseClaimedPayload(record: ServiceMailboxRecord): void;
54
56
  tryEnqueue(record: ServiceMailboxRecord): boolean;
55
57
  tryClaim(domain: ServiceMailboxDomain, messageBudget: number, byteBudget: number): ServiceMailboxClaim | undefined;
@@ -4,6 +4,7 @@ exports.ServiceMailbox = void 0;
4
4
  /** Level-triggered queues with one active application claim per owner. */
5
5
  class ServiceMailbox {
6
6
  onReady;
7
+ receivedAtClock;
7
8
  application;
8
9
  infrastructure;
9
10
  relocationSeals = new Map();
@@ -11,8 +12,9 @@ class ServiceMailbox {
11
12
  nextClaimSerial = 1n;
12
13
  nextRelocationSerial = 1n;
13
14
  closed = false;
14
- constructor(onReady) {
15
+ constructor(onReady, receivedAtClock = () => new Date()) {
15
16
  this.onReady = onReady;
17
+ this.receivedAtClock = receivedAtClock;
16
18
  // Host ApplicationJobQueue permits own ordinary-record admission. The
17
19
  // Framework-owned payload lifetime does not retain Core HWM credit. A
18
20
  // second mailbox cap would reject already-admitted work before the shared
@@ -32,6 +34,7 @@ class ServiceMailbox {
32
34
  const bytes = retainedBytes(record);
33
35
  if (this.closed)
34
36
  return false;
37
+ record.receivedAt ??= this.receivedAtClock();
35
38
  if (record.domain === 'application') {
36
39
  if (this.relocatedOwners.has(record.owner))
37
40
  return false;
@@ -16,7 +16,7 @@ export interface ServiceRelocationCaptureUnit {
16
16
  seal(signal?: AbortSignal): Promise<ServiceRelocationSealedWork>;
17
17
  captureApplicationState(signal?: AbortSignal): Promise<Uint8Array>;
18
18
  commitSeal(followAuthorities: ReadonlyMap<string, ZLinkAuthoritySnapshot>): Promise<void> | void;
19
- abortSeal(): Promise<void> | void;
19
+ abortSeal(onCleanupError?: (error: unknown) => void): Promise<void> | void;
20
20
  /** Expired-owner terminal: pending requests fail once and dispatch stays closed. */
21
21
  discardSeal?(reason: unknown): Promise<void> | void;
22
22
  }
@@ -26,7 +26,7 @@ export declare class ServiceCapturedObjectRelocation {
26
26
  private terminal;
27
27
  constructor(envelope: ServiceRelocationEnvelope, units: readonly ServiceRelocationCaptureUnit[]);
28
28
  commitSource(followAuthorities: ReadonlyMap<string, ZLinkAuthoritySnapshot>): Promise<void>;
29
- abortSource(): Promise<void>;
29
+ abortSource(onCleanupError?: (error: unknown) => void): Promise<void>;
30
30
  /**
31
31
  * The source owner lease ended before the authority settled (spec 28 §4.4):
32
32
  * the source neither resumes nor commits. Retained work is dropped and
@@ -20,14 +20,14 @@ class ServiceCapturedObjectRelocation {
20
20
  await unit.commitSeal(followAuthorities);
21
21
  this.terminal = 'committed';
22
22
  }
23
- async abortSource() {
23
+ async abortSource(onCleanupError) {
24
24
  if (this.terminal === 'aborted')
25
25
  return;
26
26
  if (this.terminal !== 'open') {
27
27
  throw new Error(`A ${this.terminal} relocation source capture cannot be aborted.`);
28
28
  }
29
29
  try {
30
- await abortSourceSeals(this.units);
30
+ await abortSourceSeals(this.units, onCleanupError);
31
31
  }
32
32
  finally {
33
33
  this.terminal = 'aborted';
@@ -126,18 +126,25 @@ class ServiceRelocationObjectCaptureOwner {
126
126
  }
127
127
  }
128
128
  exports.ServiceRelocationObjectCaptureOwner = ServiceRelocationObjectCaptureOwner;
129
- async function abortSourceSeals(units) {
129
+ async function abortSourceSeals(units, onCleanupError) {
130
130
  const failures = [];
131
+ const cleanupFailures = [];
131
132
  for (const unit of [...units].reverse()) {
132
133
  try {
133
- await unit.abortSeal();
134
+ await unit.abortSeal((error) => cleanupFailures.push(error));
134
135
  }
135
136
  catch (error) {
136
137
  failures.push(error);
137
138
  }
138
139
  }
139
140
  if (failures.length !== 0) {
140
- throw new AggregateError(failures, 'Relocation source rollback was incomplete.');
141
+ throw new AggregateError([...failures, ...cleanupFailures], 'Relocation source rollback was incomplete.');
142
+ }
143
+ if (cleanupFailures.length !== 0) {
144
+ const cleanup = new AggregateError(cleanupFailures, 'Relocation source rollback was incomplete.');
145
+ if (onCleanupError === undefined)
146
+ throw cleanup;
147
+ onCleanupError(cleanup);
141
148
  }
142
149
  }
143
150
  /** Restores an exact User Spot aggregate or standalone Actor into hidden objects. */
@@ -1,3 +1,4 @@
1
+ import type { PendingOperation } from './operation-registry';
1
2
  import type { RoutingId } from '../../contracts';
2
3
  import type { Message } from '../../contracts/Common/Message';
3
4
  import type { ApplicationJobPermitPort } from '../application-jobs/contracts';
@@ -213,6 +214,7 @@ export interface ZLinkMessageFollowOrigin {
213
214
  readonly target?: import('./service-stateful-wire-codec').ServiceActorRouteFence;
214
215
  }
215
216
  export interface ReceiveRecord {
217
+ readonly receivedAt?: Date;
216
218
  /** Resolve record prerequisites in owner order, outside an application handler turn. */
217
219
  readonly prepareDispatch?: (this: ReceiveRecord, signal: AbortSignal) => boolean | Promise<boolean>;
218
220
  readonly statefulMailboxRecord?: import('./service-mailbox').ServiceMailboxRecord;
@@ -233,6 +235,7 @@ export interface ReceiveRecord {
233
235
  readonly kindData: ReceiveKindData | null;
234
236
  readonly terminalResult: number;
235
237
  readonly failureErrno: number;
238
+ readonly failureMessage?: string;
236
239
  readonly parts: Message[];
237
240
  /** Returns whether the local operation can still accept a lifecycle reply. */
238
241
  readonly isPending?: () => boolean;
@@ -250,7 +253,7 @@ export interface ReceiveRecord {
250
253
  reply(parts: MessageLike | readonly MessageLike[], flags?: number): SubmitResult;
251
254
  replyActorJoin(joinResult: number, parts: MessageLike | readonly MessageLike[], flags?: number, replyContentType?: string): SubmitResult;
252
255
  /** Emits a typed command-20 terminal for a lifecycle request before admission. */
253
- replyFailure?(terminalResult: number, failureCode: number): SubmitResult;
256
+ replyFailure?(terminalResult: number, failureCode: number, tail?: import('./service-stateful-wire-codec').ServiceStatefulReplyTail): SubmitResult;
254
257
  }
255
258
  export interface ClaimReceiveResult {
256
259
  readonly ok: boolean;
@@ -349,6 +352,7 @@ export interface ServiceSpot {
349
352
  requestToChannel(channelName: string, parts: MessageLike | readonly MessageLike[], options?: {
350
353
  flags?: number;
351
354
  timeoutMs?: number;
355
+ readonly requestOperation?: PendingOperation<unknown>;
352
356
  applicationMetadata?: Buffer;
353
357
  onAdmitted?: () => void;
354
358
  }): MeshOperationId;
@@ -360,11 +364,12 @@ export interface ServiceSpot {
360
364
  requestToSpot(targetNodeRid: unknown, targetSpotId: unknown, targetSpotGeneration: bigint, parts: MessageLike | readonly MessageLike[], options?: {
361
365
  flags?: number;
362
366
  timeoutMs?: number;
367
+ readonly requestOperation?: PendingOperation<unknown>;
363
368
  applicationMetadata?: Buffer;
364
369
  routeFence?: ServiceDirectSpotRouteFence;
365
370
  onAdmitted?: () => void;
366
371
  entrySpot?: boolean;
367
- }): MeshOperationId;
372
+ }, completion?: import('../backend/mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
368
373
  publish(channelName: string, topic: string, parts: MessageLike | readonly MessageLike[], options?: {
369
374
  flags?: number;
370
375
  }): Promise<void>;
@@ -119,6 +119,8 @@ export declare class ServiceStatefulRegistry {
119
119
  installSessionBinding(binding: ServiceSessionBinding): ServiceSessionBinding;
120
120
  binding(actor: ServiceActorRef): ServiceSessionBinding | undefined;
121
121
  private bindingCore;
122
+ /** The Actor owner admits each relayed Session sequence once per binding. */
123
+ acceptBoundSessionSequence(actor: ServiceActorRef, expectedBindingGeneration: bigint, sequence: bigint): boolean;
122
124
  unbindSession(actor: ServiceActorRef, expectedBindingGeneration: bigint, expectedSessionRid?: string, expectedSessionOwnerNodeRid?: string): boolean;
123
125
  validateBoundSession(actor: ServiceActorRef, expectedBindingGeneration: bigint): ServiceSessionBinding;
124
126
  reserve(objectKind: ServiceObjectReservation['objectKind'], key: string, stableType: string, attempt: bigint): ServiceReservationResult;
@@ -129,9 +131,11 @@ export declare class ServiceStatefulRegistry {
129
131
  }
130
132
  export declare const RELOCATION_REPLY_RETENTION_MS: number;
131
133
  export declare class ServiceTerminalOperationRegistry<T, Context = unknown> {
134
+ private readonly release;
132
135
  private readonly operations;
133
- constructor(operations?: OperationRegistry<T, Context>);
134
- register(timeoutMs: number, timeoutOwner?: 'registry' | 'sender', context?: Context): PendingOperation<T>;
136
+ constructor(operations?: OperationRegistry<T, Context>, release?: () => void);
137
+ register(timeoutMs: number, timeoutOwner?: 'registry' | 'sender', context?: Context, absoluteDeadlineMs?: number): PendingOperation<T>;
138
+ setContext(id: bigint, context: Context): void;
135
139
  reply(id: bigint, value: T, terminalContextRetentionMs?: number): boolean;
136
140
  fail(id: bigint, error: unknown): boolean;
137
141
  cancel(id: bigint): boolean;
@@ -246,7 +246,7 @@ class ServiceStatefulRegistry {
246
246
  });
247
247
  requireText(binding.sessionOwnerNodeRid, 'sessionOwnerNodeRid');
248
248
  requirePositive(binding.bindingGeneration, 'bindingGeneration');
249
- const current = this.bindings.get(actorKey(binding.actor));
249
+ const current = this.bindings.get(actorKey(binding.actor))?.binding;
250
250
  if (current !== undefined &&
251
251
  current.sessionOwnerNodeRid === binding.sessionOwnerNodeRid &&
252
252
  current.sessionOwnerNodeGeneration === binding.sessionOwnerNodeGeneration &&
@@ -257,21 +257,34 @@ class ServiceStatefulRegistry {
257
257
  throw new ServiceStaleGenerationError('binding', binding.actor.actorId);
258
258
  }
259
259
  const accepted = Object.freeze({ ...binding });
260
- this.bindings.set(actorKey(binding.actor), accepted);
260
+ this.bindings.set(actorKey(binding.actor), { binding: accepted, lastAcceptedSequence: 0n });
261
261
  return accepted;
262
262
  }
263
263
  binding(actor) {
264
264
  return this.bindingCore(actor);
265
265
  }
266
266
  bindingCore(actor) {
267
- const binding = this.bindings.get(actorKey(actor));
267
+ const binding = this.bindings.get(actorKey(actor))?.binding;
268
268
  return binding?.actor.generation === actor.generation ? binding : undefined;
269
269
  }
270
+ /** The Actor owner admits each relayed Session sequence once per binding. */
271
+ acceptBoundSessionSequence(actor, expectedBindingGeneration, sequence) {
272
+ const entry = this.bindings.get(actorKey(actor));
273
+ if (entry === undefined ||
274
+ entry.binding.actor.generation !== actor.generation ||
275
+ entry.binding.bindingGeneration !== expectedBindingGeneration ||
276
+ sequence <= entry.lastAcceptedSequence) {
277
+ return false;
278
+ }
279
+ entry.lastAcceptedSequence = sequence;
280
+ return true;
281
+ }
270
282
  unbindSession(actor, expectedBindingGeneration, expectedSessionRid, expectedSessionOwnerNodeRid) {
271
283
  const key = actorKey(actor);
272
- const binding = this.bindings.get(key);
273
- if (binding === undefined)
284
+ const entry = this.bindings.get(key);
285
+ if (entry === undefined)
274
286
  return false;
287
+ const binding = entry.binding;
275
288
  if (binding.bindingGeneration !== expectedBindingGeneration ||
276
289
  (expectedSessionRid !== undefined &&
277
290
  !(0, routing_id_1.routingIdsEqual)(binding.sessionRid, expectedSessionRid)) ||
@@ -387,14 +400,17 @@ class ServiceStatefulRegistry {
387
400
  }
388
401
  updateBindingMembership(actor) {
389
402
  const key = actorKey(actor.ref);
390
- const binding = this.bindings.get(key);
391
- if (binding === undefined)
403
+ const entry = this.bindings.get(key);
404
+ if (entry === undefined)
392
405
  return;
393
- this.bindings.set(key, Object.freeze({
394
- ...binding,
395
- actor: actor.ref,
396
- membershipEpoch: actor.membershipEpoch
397
- }));
406
+ this.bindings.set(key, {
407
+ binding: Object.freeze({
408
+ ...entry.binding,
409
+ actor: actor.ref,
410
+ membershipEpoch: actor.membershipEpoch
411
+ }),
412
+ lastAcceptedSequence: entry.lastAcceptedSequence
413
+ });
398
414
  }
399
415
  }
400
416
  exports.ServiceStatefulRegistry = ServiceStatefulRegistry;
@@ -418,15 +434,20 @@ function createSpotState(ref, kind, stableType, authorityOwnerGeneration) {
418
434
  }
419
435
  exports.RELOCATION_REPLY_RETENTION_MS = 24 * 60 * 60 * 1_000;
420
436
  class ServiceTerminalOperationRegistry {
437
+ release;
421
438
  operations;
422
- constructor(operations = new operation_registry_1.OperationRegistry()) {
439
+ constructor(operations = new operation_registry_1.OperationRegistry(), release = () => operations.close('Stateful runtime closed.')) {
440
+ this.release = release;
423
441
  this.operations = operations;
424
442
  }
425
- register(timeoutMs, timeoutOwner = 'registry', context) {
426
- return this.operations.register(timeoutMs, timeoutOwner, context);
443
+ register(timeoutMs, timeoutOwner = 'registry', context, absoluteDeadlineMs) {
444
+ return this.operations.register(timeoutMs, timeoutOwner, context, absoluteDeadlineMs);
445
+ }
446
+ setContext(id, context) {
447
+ this.operations.setContext(id, context);
427
448
  }
428
449
  reply(id, value, terminalContextRetentionMs = 0) {
429
- return this.operations.complete(id, value, terminalContextRetentionMs);
450
+ return this.operations.reply(id, value, terminalContextRetentionMs);
430
451
  }
431
452
  fail(id, error) {
432
453
  return this.operations.fail(id, error);
@@ -450,7 +471,7 @@ class ServiceTerminalOperationRegistry {
450
471
  return this.operations.expire(nowMs, turnDeadlineMs);
451
472
  }
452
473
  close() {
453
- this.operations.close('Stateful runtime closed.');
474
+ this.release();
454
475
  }
455
476
  failAll(reason) {
456
477
  this.operations.failAll(reason);