@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
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkDealerChannelClientTransport = void 0;
4
+ const request_runtime_1 = require("../../foundation/request-runtime");
5
+ const request_result_1 = require("../../messaging/request-result");
4
6
  const node_backend_adapter_support_1 = require("./node-backend-adapter-support");
5
7
  const configuration_1 = require("../../configuration");
6
8
  const submission_result_1 = require("../../messaging/submission-result");
@@ -13,9 +15,11 @@ const EMPTY_METADATA = new Map();
13
15
  class ZLinkDealerChannelClientTransport {
14
16
  dealer;
15
17
  publisher;
16
- constructor(dealer, publisher) {
18
+ requests;
19
+ constructor(dealer, publisher, requests = new request_runtime_1.RequestRuntime()) {
17
20
  this.dealer = dealer;
18
21
  this.publisher = publisher;
22
+ this.requests = requests;
19
23
  }
20
24
  async send(channelName, packetName, message, metadata = EMPTY_METADATA) {
21
25
  // Call-scoped flow (spec 27 §4): the envelope flow pair does not outlive
@@ -23,20 +27,69 @@ class ZLinkDealerChannelClientTransport {
23
27
  await (0, flow_context_1.runWithOutboundFlow)(true, () => (0, channel_multipart_1.appendParts)(this.dealer.send(), (0, channel_envelope_1.encodeChannelEnvelopeParts)(3 /* ZLinkChannelMessageKind.Command */, channelName, packetName, message, undefined, undefined, undefined, undefined, true, metadata)).submit().admitted);
24
28
  return { status: submission_result_1.ZLinkSubmitStatus.Submitted };
25
29
  }
26
- async request(channelName, packetName, request, timeoutMs, signal, metadata = EMPTY_METADATA, onAdmitted) {
27
- (0, abort_1.throwIfAborted)(signal);
28
- const operation = (0, flow_context_1.runWithOutboundFlow)(true, () => (0, channel_multipart_1.appendParts)(this.dealer.request(), (0, channel_envelope_1.encodeChannelEnvelopeParts)(1 /* ZLinkChannelMessageKind.Request */, channelName, packetName, request, timeoutMs, undefined, undefined, undefined, true, metadata)));
29
- if (timeoutMs !== undefined)
30
- operation.timeout(timeoutMs);
31
- const reply = await (0, channel_multipart_1.submitRequestOperation)({
32
- submit: () => (0, node_backend_adapter_support_1.bindingRequestReply)(operation.submit(), timeoutMs === undefined ? undefined : performance.now() + timeoutMs, undefined, onAdmitted)
33
- }, 'channel request');
30
+ request(channelName, packetName, request, timeoutMs, signal, metadata = EMPTY_METADATA, onAdmitted) {
34
31
  try {
35
- return (0, channel_envelope_1.decodeChannelReply)(reply);
32
+ (0, abort_1.throwIfAborted)(signal);
33
+ }
34
+ catch (error) {
35
+ return (0, request_result_1.rejectZLinkRequestReply)(error);
36
36
  }
37
- finally {
38
- for (const part of reply)
39
- part.close();
37
+ const requestOperation = this.requests.begin(timeoutMs, signal);
38
+ try {
39
+ (0, abort_1.throwIfAborted)(signal);
40
+ const operation = (0, flow_context_1.runWithOutboundFlow)(true, () => (0, channel_multipart_1.appendParts)(this.dealer.request(), (0, channel_envelope_1.encodeChannelEnvelopeParts)(1 /* ZLinkChannelMessageKind.Request */, channelName, packetName, request, timeoutMs, undefined, undefined, undefined, true, metadata)));
41
+ if (timeoutMs !== undefined)
42
+ operation.timeout(timeoutMs);
43
+ const decode = (raw) => {
44
+ const reply = raw;
45
+ try {
46
+ return (0, channel_envelope_1.decodeChannelReply)(reply);
47
+ }
48
+ finally {
49
+ closeReply(reply);
50
+ }
51
+ };
52
+ requestOperation.mapCaller(decode, request_result_1.identityRequestReply);
53
+ if (requestOperation.isPending()) {
54
+ const receiver = {
55
+ operationCompleted: (_id, raw) => {
56
+ if (requestOperation.complete(raw))
57
+ return;
58
+ try {
59
+ requestOperation.resolveCaller(decode(raw));
60
+ }
61
+ catch (error) {
62
+ requestOperation.rejectCaller(error);
63
+ }
64
+ },
65
+ operationFailed: (_id, error) => {
66
+ let failure = error;
67
+ try {
68
+ failure = (0, channel_multipart_1.mapRequestFailure)(error, 'channel request');
69
+ }
70
+ catch (mapped) {
71
+ failure = mapped;
72
+ }
73
+ requestOperation.fail(failure);
74
+ }
75
+ };
76
+ try {
77
+ (0, node_backend_adapter_support_1.bindingRequestReply)(operation.submit(), receiver, requestOperation, undefined, onAdmitted);
78
+ }
79
+ catch (error) {
80
+ receiver.operationFailed(requestOperation.id, error);
81
+ }
82
+ }
83
+ return {
84
+ pending: requestOperation.promise,
85
+ decode: (request_result_1.identityRequestReply),
86
+ mapFailure: request_result_1.identityRequestReply,
87
+ operation: requestOperation
88
+ };
89
+ }
90
+ catch (error) {
91
+ requestOperation.fail(error);
92
+ return (0, request_result_1.prepareZLinkRequestReply)(requestOperation.promise, request_result_1.identityRequestReply);
40
93
  }
41
94
  }
42
95
  tryPublish(channelName, topic, packetName, event, metadata = EMPTY_METADATA) {
@@ -52,3 +105,7 @@ class ZLinkDealerChannelClientTransport {
52
105
  }
53
106
  }
54
107
  exports.ZLinkDealerChannelClientTransport = ZLinkDealerChannelClientTransport;
108
+ function closeReply(parts) {
109
+ for (const part of parts)
110
+ part.close();
111
+ }
@@ -9,8 +9,8 @@ export declare class ZLinkNodeEventLoopPoller {
9
9
  private readonly events;
10
10
  private readableHandler;
11
11
  private disposed;
12
- constructor(socket: Socket, pollCompletion: boolean, readableHandler: (receiveReady: boolean, routeReady: boolean) => void, pollRoute?: boolean);
13
- setReadableHandler(handler: (receiveReady: boolean, routeReady: boolean) => void): void;
12
+ constructor(socket: Socket, pollCompletion: boolean, readableHandler: (receiveReady: boolean, routeReady: boolean, connectReady: boolean) => void, pollRoute?: boolean);
13
+ setReadableHandler(handler: (receiveReady: boolean, routeReady: boolean, connectReady: boolean) => void): void;
14
14
  dispose(): void;
15
15
  private readonly onReady;
16
16
  }
@@ -21,7 +21,7 @@ class ZLinkNodeEventLoopPoller {
21
21
  // A ROUTER selected-route change (Core ROUTER §10.1) wakes the same
22
22
  // handler, whose owner is the socket's one route observer.
23
23
  if (pollRoute)
24
- pollEvents.push(node_backend_adapter_support_1.zlink.PollEventFlag.PollRoute);
24
+ pollEvents.push(node_backend_adapter_support_1.zlink.PollEventFlag.PollRoute, node_backend_adapter_support_1.zlink.PollEventFlag.PollConnect);
25
25
  this.poller.add(socket, pollEvents, 0);
26
26
  socket.setReadableHandler(this.onReady);
27
27
  }
@@ -47,8 +47,9 @@ class ZLinkNodeEventLoopPoller {
47
47
  const ready = this.poller.wait(this.events, 0);
48
48
  const receiveReady = ready === 0 || this.events.hasEvent(0, node_backend_adapter_support_1.zlink.PollEventFlag.PollIn);
49
49
  const routeReady = ready > 0 && this.events.hasEvent(0, node_backend_adapter_support_1.zlink.PollEventFlag.PollRoute);
50
- if (receiveReady || routeReady)
51
- this.readableHandler(receiveReady, routeReady);
50
+ const connectReady = ready > 0 && this.events.hasEvent(0, node_backend_adapter_support_1.zlink.PollEventFlag.PollConnect);
51
+ if (receiveReady || routeReady || connectReady)
52
+ this.readableHandler(receiveReady, routeReady, connectReady);
52
53
  };
53
54
  }
54
55
  exports.ZLinkNodeEventLoopPoller = ZLinkNodeEventLoopPoller;
@@ -12,7 +12,11 @@ class ZLinkNodeMeshBackendAdapter {
12
12
  if (!isBindingContext(bindingContext)) {
13
13
  throw new TypeError('Node MeshNode creation requires the Node binding Context owned by the host.');
14
14
  }
15
- return new node_raw_mesh_backend_1.ZLinkNodeRawMeshBackend(options.meshName, options.routingId, new node_raw_binding_port_1.ZLinkNodeRawBindingPort(bindingContext, options.receiveTimeoutMs), options.applicationJobQueue, options.applicationJobReceiveFlowFailureSink, options.peerAdmissionSealed, options.infrastructureTaskRunner);
15
+ return new node_raw_mesh_backend_1.ZLinkNodeRawMeshBackend(options.meshName, options.routingId, new node_raw_binding_port_1.ZLinkNodeRawBindingPort(bindingContext, {
16
+ sendHighWaterMark: options.sendHighWaterMark,
17
+ receiveHighWaterMark: options.receiveHighWaterMark,
18
+ receiveTimeoutMs: options.receiveTimeoutMs
19
+ }), options.applicationJobQueue, options.applicationJobReceiveFlowFailureSink, options.peerAdmissionSealed, options.infrastructureTaskRunner);
16
20
  }
17
21
  }
18
22
  exports.ZLinkNodeMeshBackendAdapter = ZLinkNodeMeshBackendAdapter;
@@ -1,9 +1,14 @@
1
1
  import { type Context } from '@zlink-systems/zlink';
2
2
  import type { ZLinkRawBindingPort, ZLinkRawHostPort } from '../raw-binding-port';
3
+ interface ZLinkNodeRawRouterSocketOptions {
4
+ readonly sendHighWaterMark?: number;
5
+ readonly receiveHighWaterMark?: number;
6
+ readonly receiveTimeoutMs?: number;
7
+ }
3
8
  export type { ZLinkRawBindingPort, ZLinkRawDealerPort, ZLinkRawHostPort, ZLinkRawMonitorPort, ZLinkRawMonitorRecord, ZLinkRawReceivedRecord, ZLinkRawRouterPort, ZLinkRawRouterRoute, ZLinkRawSocketPort } from '../raw-binding-port';
4
9
  export declare class ZLinkNodeRawBindingPort implements ZLinkRawBindingPort {
5
10
  private readonly sharedContext?;
6
- private readonly routerReceiveTimeoutMs?;
7
- constructor(sharedContext?: Context | undefined, routerReceiveTimeoutMs?: number | undefined);
11
+ private readonly routerSocketOptions?;
12
+ constructor(sharedContext?: Context | undefined, routerSocketOptions?: ZLinkNodeRawRouterSocketOptions | undefined);
8
13
  createHost(): ZLinkRawHostPort;
9
14
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkNodeRawBindingPort = void 0;
4
+ const request_runtime_1 = require("../../foundation/request-runtime");
5
+ const request_deadline_1 = require("../../messaging/request-deadline");
4
6
  const zlink_1 = require("@zlink-systems/zlink");
5
7
  const node_backend_adapter_support_1 = require("./node-backend-adapter-support");
6
8
  const node_socket_backend_adapter_1 = require("./node-socket-backend-adapter");
@@ -9,30 +11,30 @@ const node_event_loop_poller_1 = require("./node-event-loop-poller");
9
11
  const runtime_message_1 = require("../runtime-message");
10
12
  class ZLinkNodeRawBindingPort {
11
13
  sharedContext;
12
- routerReceiveTimeoutMs;
13
- constructor(sharedContext, routerReceiveTimeoutMs) {
14
+ routerSocketOptions;
15
+ constructor(sharedContext, routerSocketOptions) {
14
16
  this.sharedContext = sharedContext;
15
- this.routerReceiveTimeoutMs = routerReceiveTimeoutMs;
17
+ this.routerSocketOptions = routerSocketOptions;
16
18
  }
17
19
  createHost() {
18
- return new NodeRawHostPort(this.sharedContext ?? (0, zlink_1.createContext)(), this.sharedContext === undefined, this.routerReceiveTimeoutMs);
20
+ return new NodeRawHostPort(this.sharedContext ?? (0, zlink_1.createContext)(), this.sharedContext === undefined, this.routerSocketOptions);
19
21
  }
20
22
  }
21
23
  exports.ZLinkNodeRawBindingPort = ZLinkNodeRawBindingPort;
22
24
  class NodeRawHostPort {
23
25
  context;
24
26
  ownsContext;
25
- routerReceiveTimeoutMs;
27
+ routerSocketOptions;
26
28
  resources = [];
27
29
  state = 'open';
28
- constructor(context, ownsContext, routerReceiveTimeoutMs) {
30
+ constructor(context, ownsContext, routerSocketOptions) {
29
31
  this.context = context;
30
32
  this.ownsContext = ownsContext;
31
- this.routerReceiveTimeoutMs = routerReceiveTimeoutMs;
33
+ this.routerSocketOptions = routerSocketOptions;
32
34
  }
33
35
  createRouter() {
34
36
  this.requireOpen();
35
- return this.own(new NodeRawRouterPort((0, zlink_1.createRouterSocket)(this.context), this.routerReceiveTimeoutMs));
37
+ return this.own(new NodeRawRouterPort((0, zlink_1.createRouterSocket)(this.context), this.routerSocketOptions));
36
38
  }
37
39
  createDealer() {
38
40
  this.requireOpen();
@@ -84,6 +86,8 @@ class NodeRawHostPort {
84
86
  }
85
87
  class NodeRawSocketPort {
86
88
  socket;
89
+ requests = new request_runtime_1.RequestRuntime();
90
+ received = new zlink_1.Received();
87
91
  endpoints = new Set();
88
92
  monitors = new Set();
89
93
  eventLoopPoller;
@@ -124,6 +128,7 @@ class NodeRawSocketPort {
124
128
  return port;
125
129
  }
126
130
  close() {
131
+ this.requests.close();
127
132
  if (this.closed)
128
133
  return;
129
134
  const failures = [];
@@ -162,6 +167,7 @@ class NodeRawSocketPort {
162
167
  }
163
168
  this.endpoints.clear();
164
169
  try {
170
+ this.received.close();
165
171
  this.socket.close();
166
172
  }
167
173
  catch (error) {
@@ -212,13 +218,19 @@ class NodeRawRouterPort extends NodeRawSocketPort {
212
218
  this.requireOpen();
213
219
  (0, node_socket_backend_adapter_1.disconnectSocketPeer)(this.socket, this.preparedRoutingId(routingId));
214
220
  }
215
- constructor(socket, receiveTimeoutMs) {
221
+ constructor(socket, options) {
216
222
  super(socket, true);
217
223
  socket.options.handover = true;
218
224
  socket.options.mandatory = true;
219
225
  socket.options.probe = true;
220
- if (receiveTimeoutMs !== undefined) {
221
- socket.options.recvTimeout = receiveTimeoutMs;
226
+ if (options?.sendHighWaterMark !== undefined) {
227
+ socket.options.sendHwm = BigInt(options.sendHighWaterMark);
228
+ }
229
+ if (options?.receiveHighWaterMark !== undefined) {
230
+ socket.options.recvHwm = BigInt(options.receiveHighWaterMark);
231
+ }
232
+ if (options?.receiveTimeoutMs !== undefined) {
233
+ socket.options.recvTimeout = options.receiveTimeoutMs;
222
234
  }
223
235
  }
224
236
  localEndpoint() {
@@ -244,19 +256,25 @@ class NodeRawRouterPort extends NodeRawSocketPort {
244
256
  requireParts(parts);
245
257
  return (0, node_backend_adapter_support_1.submitBindingSend)(this.socket.send(this.preparedRoutingId(targetRid)), parts);
246
258
  }
247
- request(targetRid, parts, timeoutMs, recordReceived, onAdmitted) {
248
- let submission;
249
- const deadlineMs = performance.now() + timeoutMs;
250
- try {
259
+ request(targetRid, parts, timeoutMs, onReply, onFailed, recordReceived, onAdmitted, existing) {
260
+ if (existing !== undefined) {
251
261
  this.requireOpen();
252
- submission = appendRequestParts(this.socket.request(this.preparedRoutingId(targetRid)), parts)
253
- .timeout(timeoutMs)
254
- .submit();
255
- }
256
- catch (error) {
257
- return Promise.reject((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'submit'));
262
+ const submission = submitRawRequest(appendRequestParts(this.socket.request(this.preparedRoutingId(targetRid)), parts).timeout((0, request_deadline_1.remainingRequestTimeout)('Request', existing.deadlineMs) ?? timeoutMs));
263
+ return requestReply(submission, 0, onReply, onFailed, recordReceived, onAdmitted);
258
264
  }
259
- return requestReply(submission, deadlineMs, recordReceived, onAdmitted);
265
+ return this.requests.observe(timeoutMs, (entry, receiver) => {
266
+ this.requireOpen();
267
+ const submission = submitRawRequest(appendRequestParts(this.socket.request(this.preparedRoutingId(targetRid)), parts).timeout((0, request_deadline_1.remainingRequestTimeout)('Request', entry.deadlineMs) ?? timeoutMs));
268
+ void requestReply(submission, 0, (value) => {
269
+ receiver.operationCompleted(entry.id, value, undefined);
270
+ }, (error) => {
271
+ receiver.operationFailed(entry.id, error, undefined);
272
+ }, recordReceived, onAdmitted);
273
+ }, onReply, onFailed);
274
+ }
275
+ connectionAttemptsSnapshot() {
276
+ this.requireOpen();
277
+ return this.socket.connectionAttemptsSnapshot();
260
278
  }
261
279
  routesSnapshot() {
262
280
  this.requireOpen();
@@ -267,7 +285,7 @@ class NodeRawRouterPort extends NodeRawSocketPort {
267
285
  }
268
286
  receive(dontWait = false) {
269
287
  this.requireOpen();
270
- return receiveRecord(this.socket, dontWait, this.nextRequestSequence, this.replyParts);
288
+ return receiveRecord(this.socket, this.received, dontWait, this.nextRequestSequence, this.replyParts);
271
289
  }
272
290
  }
273
291
  class NodeRawDealerPort extends NodeRawSocketPort {
@@ -284,20 +302,19 @@ class NodeRawDealerPort extends NodeRawSocketPort {
284
302
  return (0, node_backend_adapter_support_1.submitBindingAsyncSend)(this.socket.send(), parts);
285
303
  }
286
304
  request(parts, timeoutMs, onAdmitted) {
287
- let submission;
288
- const deadlineMs = performance.now() + timeoutMs;
289
- try {
305
+ return this.requests.observe(timeoutMs, (entry, receiver) => {
290
306
  this.requireOpen();
291
- submission = appendRequestParts(this.socket.request(), parts).timeout(timeoutMs).submit();
292
- }
293
- catch (error) {
294
- return Promise.reject((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'submit'));
295
- }
296
- return requestReply(submission, deadlineMs, undefined, onAdmitted);
307
+ const submission = submitRawRequest(appendRequestParts(this.socket.request(), parts).timeout((0, request_deadline_1.remainingRequestTimeout)('Request', entry.deadlineMs) ?? timeoutMs));
308
+ void requestReply(submission, 0, (value) => {
309
+ receiver.operationCompleted(entry.id, value, undefined);
310
+ }, (error) => {
311
+ receiver.operationFailed(entry.id, error, undefined);
312
+ }, undefined, onAdmitted);
313
+ }, (value) => value, rethrowCompletion);
297
314
  }
298
315
  receive(dontWait = false) {
299
316
  this.requireOpen();
300
- return receiveRecord(this.socket, dontWait);
317
+ return receiveRecord(this.socket, this.received, dontWait);
301
318
  }
302
319
  }
303
320
  class NodeRawMonitorPort {
@@ -357,20 +374,17 @@ function requireParts(parts) {
357
374
  const EMPTY_SOURCE_ROUTE = Buffer.alloc(0);
358
375
  /**
359
376
  * One received binding record. The payload Buffers are the binding's own
360
- * `data()` storage, retained under the runtime payload policy instead of a
361
- * second Framework copy; closing the record releases the binding handles.
377
+ * `data()` storage, retained under the runtime payload policy. The socket owns
378
+ * the reusable binding envelope; snapshots survive its next receive or close.
362
379
  */
363
380
  class NodeRawReceivedRecord {
364
- received;
365
381
  sourceRid;
366
382
  sourceRoute;
367
383
  routeGeneration;
368
384
  requestSeq;
369
385
  reply;
370
386
  parts;
371
- closed = false;
372
387
  constructor(received, nextRequestSequence, reply) {
373
- this.received = received;
374
388
  const routingId = received.routingId;
375
389
  this.sourceRid = routingId?.toString() ?? '';
376
390
  this.sourceRoute = routingId?.toBytes() ?? EMPTY_SOURCE_ROUTE;
@@ -394,16 +408,13 @@ class NodeRawReceivedRecord {
394
408
  this.parts = retained;
395
409
  }
396
410
  close() {
397
- if (this.closed)
398
- return;
399
- this.closed = true;
400
- this.received.close();
411
+ // Reading each binding payload above retained JS-owned storage and released
412
+ // its native frame. The socket clears its reusable envelope; these record
413
+ // snapshots need no native cleanup.
401
414
  }
402
415
  }
403
- function receiveRecord(socket, dontWait, nextRequestSequence, reply) {
404
- const received = new zlink_1.Received();
416
+ function receiveRecord(socket, received, dontWait, nextRequestSequence, reply) {
405
417
  if (!socket.recv(received, dontWait ? zlink_1.RecvFlags.DontWait : zlink_1.RecvFlags.None)) {
406
- received.close();
407
418
  return undefined;
408
419
  }
409
420
  try {
@@ -419,36 +430,53 @@ function receiveRecord(socket, dontWait, nextRequestSequence, reply) {
419
430
  * confirmed in this turn; a backpressured submission keeps the admission
420
431
  * wait that bounds it by the request deadline.
421
432
  */
422
- function requestReply(submission, deadlineMs, recordReceived, onAdmitted) {
433
+ function requestReply(submission, _deadlineMs, onReply, onFailed, recordReceived, onAdmitted) {
434
+ const result = observeRequestReply(submission.reply, onReply, onFailed, recordReceived);
423
435
  if (submission.result === runtime_values_1.SubmitResult.Backpressured) {
424
- return (0, node_backend_adapter_support_1.bindingRequestReply)(submission, deadlineMs, recordReceived, onAdmitted).then(retainAndClose, rejectCompletion);
425
- }
426
- try {
427
- onAdmitted?.();
436
+ void submission.admitted.then(() => {
437
+ try {
438
+ onAdmitted?.();
439
+ }
440
+ catch (error) {
441
+ onFailed((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion'));
442
+ }
443
+ }, (error) => onFailed((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion')));
428
444
  }
429
- catch (error) {
430
- return Promise.reject((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion'));
445
+ else {
446
+ try {
447
+ onAdmitted?.();
448
+ }
449
+ catch (error) {
450
+ onFailed((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion'));
451
+ }
431
452
  }
432
- return submission.reply.then((replies) => {
453
+ return result;
454
+ }
455
+ /** Consumes the binding reply and notifies its terminal in this continuation. */
456
+ function observeRequestReply(reply, onReply, onFailed, recordReceived) {
457
+ return reply.then((replies) => {
433
458
  try {
434
- recordReceived?.();
435
- return retainAndClose(replies);
459
+ return onReply(retainAndClose(replies, recordReceived));
436
460
  }
437
461
  catch (error) {
438
- throw (0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion');
462
+ return onFailed((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion'));
439
463
  }
440
- }, rejectCompletion);
464
+ }, (error) => onFailed((0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion')));
441
465
  }
442
- function rejectCompletion(error) {
443
- throw (0, node_backend_adapter_support_1.translateBindingResultError)(error, 'completion');
466
+ function rethrowCompletion(error) {
467
+ throw error;
444
468
  }
445
- function retainAndClose(messages) {
469
+ function retainAndClose(messages, recordReceived) {
446
470
  try {
447
- return messages.map((message) => runtime_message_1.ZLinkBufferMessage.retainPayload(message));
471
+ recordReceived?.();
472
+ const retained = new Array(messages.length);
473
+ for (let index = 0; index < messages.length; index++)
474
+ retained[index] = runtime_message_1.ZLinkBufferMessage.retainPayload(messages[index]);
475
+ return retained;
448
476
  }
449
477
  finally {
450
- for (const message of messages)
451
- message.close();
478
+ for (let index = 0; index < messages.length; index++)
479
+ messages[index].close();
452
480
  }
453
481
  }
454
482
  function bindingRoutingId(routingId) {
@@ -472,3 +500,11 @@ function copyMonitorEvent(event) {
472
500
  flags: event.flags
473
501
  };
474
502
  }
503
+ function submitRawRequest(operation) {
504
+ try {
505
+ return operation.submit();
506
+ }
507
+ catch (error) {
508
+ throw (0, node_backend_adapter_support_1.translateBindingResultError)(error, 'submit');
509
+ }
510
+ }
@@ -1,13 +1,15 @@
1
+ import type { RequestRuntime } from '../../foundation/request-runtime';
2
+ import type { PendingOperation } from '../../foundation/operation-registry';
1
3
  import { SubmitResult, type RequestResult as RequestResultValue, type SubmitResult as SubmitResultValue } from '@zlink-systems/zlink';
2
4
  import type { ZLinkMeshCompletionHandler } from '../mesh-completion-table';
3
5
  import { type RoutingId } from '../../../contracts';
4
6
  import type { ApplicationJobQueuePort } from '../../application-jobs/contracts';
5
7
  import type { ZLinkDispatchErrorReporter } from '../../channels/dispatch-error-reporter';
6
- import { type RawServiceRequestResult } from '../../foundation/raw-service-mesh-runtime';
8
+ import { RawServiceMeshRuntime, type RawServiceRequestResult } from '../../foundation/raw-service-mesh-runtime';
7
9
  import type { ServiceInstanceActivationRecoveryEnvelope } from '../../foundation/service-instance-activation-recovery-codec';
8
10
  import { type MeshOperationId, type MeshPeerEntry, type MeshPublisher, type ReadyBatch, type ReadyRecord, type ReceiveBatch, type ServiceSpot, type StreamSessionService, MeshNodeRuntimeState } from '../../foundation/service-runtime-contracts';
9
11
  import type { ServiceActorRef, ServiceSpotState } from '../../foundation/service-stateful-registry';
10
- import { type ServiceAsyncInstanceActivationAuthority, type ServiceInstanceApplicationLifecycle, type ServicePendingInstanceActivation, type ServiceSessionOwnerDescriptors, type ServiceSpotMessageFollowSeal, type ServiceUserSpotOperationHandler, type ServiceUserSpotOperationResult } from '../../foundation/service-stateful-runtime';
12
+ import { ServiceStatefulRuntime, type ServiceAsyncInstanceActivationAuthority, type ServiceInstanceApplicationLifecycle, type ServicePendingInstanceActivation, type ServiceSessionOwnerDescriptors, type ServiceSpotMessageFollowSeal, type ServiceUserSpotOperationHandler, type ServiceUserSpotOperationResult } from '../../foundation/service-stateful-runtime';
11
13
  import type { ServiceActorCreateRecord, ServiceDirectSpotRouteFence, ServiceInstanceActivationTarget, ServiceInstanceColdActivationTarget, ServiceInstanceRouteFence, ServiceSpotRouteFence, ServiceUserSpotCloseRecord, ServiceUserSpotCreateRecord } from '../../foundation/service-stateful-wire-codec';
12
14
  import type { ServiceNodeDescriptor } from '../../foundation/service-topology-registry';
13
15
  import { type ServiceApplicationPayload } from '../../foundation/service-wire-m6a-codec';
@@ -34,7 +36,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
34
36
  private readonly lifecycleGeneration;
35
37
  private bindEndpoint?;
36
38
  private advertiseHost?;
37
- private runtime?;
39
+ runtime?: RawServiceMeshRuntime;
38
40
  private stateful?;
39
41
  private readyHandler?;
40
42
  private maintenanceTimer?;
@@ -56,10 +58,13 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
56
58
  private protocolError?;
57
59
  private messageFollowHandler?;
58
60
  private dispatchErrors?;
59
- private sessionOwnerDescriptors?;
60
61
  private requestSourceAcceptance?;
62
+ private sessionOwnerDescriptors?;
61
63
  private readonly peerDisconnectedHandlers;
62
- constructor(meshName: string, routingId: string | undefined, bindingPort: ZLinkRawBindingPort, applicationJobQueue?: ApplicationJobQueuePort | undefined, applicationJobReceiveFlowFailureSink?: ((error: unknown) => void) | undefined, peerAdmissionSealed?: (() => boolean) | undefined, infrastructureTaskRunner?: import("../../spots/spot-actor-join-dispatch").ZLinkDetachedTaskRunner | undefined);
64
+ constructor(meshName: string, routingId: string | undefined, bindingPort: ZLinkRawBindingPort, applicationJobQueue?: ApplicationJobQueuePort | undefined, applicationJobReceiveFlowFailureSink?: ((error: unknown) => void) | undefined, peerAdmissionSealed?: (() => boolean) | undefined, infrastructureTaskRunner?: import("../../spots/spot-actor-join-dispatch").ZLinkDetachedTaskRunner | undefined, runtimeDependencies?: {
65
+ readonly raw?: RawServiceMeshRuntime;
66
+ readonly stateful?: ServiceStatefulRuntime;
67
+ });
63
68
  configureObjectPlacement(options: {
64
69
  readonly role: ServiceNodeDescriptor['objectRole'];
65
70
  readonly placementWeight: number;
@@ -84,10 +89,12 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
84
89
  selectObjectPlacement(stableType: string): ZLinkBackendObjectPlacement;
85
90
  instanceSpotPlacementTypes(): readonly string[];
86
91
  sendToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>): Promise<SubmitResult>;
87
- requestToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, onAdmitted?: () => void): MeshOperationId;
92
+ requestToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, onAdmitted?: () => void, requestOperation?: PendingOperation<unknown>): MeshOperationId;
88
93
  setRoutingId(routingId: unknown): void;
89
94
  setBind(endpoint: string): void;
90
95
  setAdvertiseHost(host: string): void;
96
+ private requests?;
97
+ setRequestRuntime(requests: RequestRuntime): void;
91
98
  start(): void;
92
99
  setMessageFollowHandler(handler: (record: import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord) => void): void;
93
100
  sendMessageFollowNotification(targetNodeRid: string, record: Omit<import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord, 'kind'>): Promise<boolean>;
@@ -129,18 +136,21 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
129
136
  sendInfrastructureControlFrames(targetRid: unknown, frames: readonly Uint8Array[]): Promise<SubmitResultValue>;
130
137
  requestInfrastructureControlFrames(targetRid: unknown, frames: readonly Uint8Array[], options?: {
131
138
  readonly timeoutMs?: number;
139
+ readonly requestOperation?: PendingOperation<unknown>;
132
140
  readonly signal?: AbortSignal;
133
141
  readonly onSubmitted?: (signal: AbortSignal) => Promise<void>;
134
142
  }): Promise<readonly Uint8Array[]>;
135
143
  requestToNode(targetRid: unknown, parts: MessageLike | readonly MessageLike[], options?: {
136
144
  readonly timeoutMs?: number;
145
+ readonly requestOperation?: PendingOperation<unknown>;
137
146
  readonly onAdmitted?: () => void;
138
- }): MeshOperationId;
147
+ }, completion?: import('../mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
139
148
  sendToChannel(channelName: string, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
140
149
  requestToChannel(channelName: string, parts: MessageLike | readonly MessageLike[], options?: {
141
150
  readonly timeoutMs?: number;
151
+ readonly requestOperation?: PendingOperation<unknown>;
142
152
  readonly onAdmitted?: () => void;
143
- }): MeshOperationId;
153
+ }, completion?: import('../mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
144
154
  status(): {
145
155
  state: MeshNodeRuntimeState;
146
156
  routingId: RoutingId;
@@ -209,7 +219,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
209
219
  commitSpotMessageFollowIngress(seal: ServiceSpotMessageFollowSeal, target: ServiceDirectSpotRouteFence | null, durationMs: number): Promise<boolean>;
210
220
  forgetSpotRoute(spot: ServiceSpotRouteFence['spot'], authorityOwnerGeneration: bigint, storeVersion?: string): void;
211
221
  sendToInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean): Promise<SubmitResult>;
212
- requestInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs?: number, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean, onAdmitted?: () => void): MeshOperationId;
222
+ requestInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs?: number, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean, onAdmitted?: () => void, requestOperation?: PendingOperation<unknown>, completion?: import('../mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
213
223
  actorLookup(actorId: string): {
214
224
  actor: ServiceActorRef;
215
225
  spotId: string;
@@ -242,9 +252,10 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
242
252
  }): Promise<SubmitResultValue>;
243
253
  requestToActor(actor: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
244
254
  readonly timeoutMs?: number;
255
+ readonly requestOperation?: PendingOperation<unknown>;
245
256
  readonly onAdmitted?: () => void;
246
257
  readonly routeFence?: import('../../foundation/service-stateful-wire-codec').ServiceActorRouteFence;
247
- }): MeshOperationId;
258
+ }, completion?: import('../mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
248
259
  acceptRelocatedActorTerminal(operation: {
249
260
  readonly high: bigint;
250
261
  readonly low: bigint;
@@ -252,6 +263,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
252
263
  actorSendToActor(source: ZLinkBackendActorRef, target: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
253
264
  actorRequestToActor(source: ZLinkBackendActorRef, target: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
254
265
  readonly timeoutMs?: number;
266
+ readonly requestOperation?: PendingOperation<unknown>;
255
267
  readonly onAdmitted?: () => void;
256
268
  }): MeshOperationId;
257
269
  sendActorBoundSession(actor: ZLinkBackendActorRef, expectedBindingGeneration: bigint, parts: MessageLike | readonly MessageLike[], _flags?: number): Promise<SubmitResultValue>;
@@ -259,31 +271,37 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
259
271
  leaveActor(actor: ZLinkBackendActorRef, expectedMembershipEpoch: bigint, timeoutMs?: number): MeshOperationId;
260
272
  createStreamSessionService(stream: unknown): StreamSessionService;
261
273
  sendFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
262
- requestFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs: number, onAdmitted?: () => void): MeshOperationId;
274
+ requestFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs: number, onAdmitted?: () => void, requestOperation?: PendingOperation<unknown>, completion?: import('../mesh-completion-table').ZLinkMeshCompletionHandler): MeshOperationId;
263
275
  closeSpot(state: ServiceSpotState): boolean;
264
276
  publishFromSpot(state: ServiceSpotState, channelName: string, topic: string, parts: MessageLike | readonly MessageLike[]): Promise<void>;
265
277
  setSpotSubscription(state: ServiceSpotState, channelName: string, topicFilter: string): void;
266
278
  unsetSpotSubscription(state: ServiceSpotState, channelName: string, topicFilter: string): void;
267
279
  clearSpotSubscriptions(state: ServiceSpotState): void;
268
- private createDescriptor;
280
+ createDescriptor(): ServiceNodeDescriptor;
269
281
  private resolveAdvertisedEndpoint;
270
282
  /**
271
283
  * Arms the one maintenance timer for the nearest management deadline
272
284
  * (spec 08 §4.2): request expiry, liveness, or a pending peer handshake.
273
- * An earlier deadline re-arms it; a later one keeps the armed time.
285
+ * The timer follows changes to the index visit or the other management deadlines.
274
286
  */
275
287
  private scheduleMaintenance;
276
288
  private pump;
277
289
  private runPump;
290
+ private resumePump;
291
+ private pumpReceiveBatch;
292
+ private hasPumpReadiness;
293
+ private finishPump;
278
294
  private notifyReady;
279
295
  /**
280
- * The raw registry takes a remote request's terminal and hands it here,
281
- * where the Framework completion owner receives it in the same turn.
296
+ * Publishes native results after submission returns and the completion slot has its id.
297
+ * A caller-owned entry is completed after the result is mapped.
282
298
  */
283
299
  private readonly requestObserver;
300
+ private requestObserverFor;
284
301
  private observedOperation;
285
- private observeCompletion;
302
+ private observeStatefulRequest;
286
303
  private observeStateful;
304
+ private requestSubmission;
287
305
  private deliverCompletion;
288
306
  private drainMailbox;
289
307
  private requireRuntime;