@zlink-systems/framework 0.30.1 → 0.30.2

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 (340) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +6 -0
  3. package/dist/contracts/Common/ZLinkEncodedPayload.js +18 -3
  4. package/dist/contracts/Common/encoded-payload-storage.d.ts +1 -1
  5. package/dist/contracts/Common/encoded-payload-storage.js +5 -2
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -1
  7. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +2 -1
  8. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +5 -1
  9. package/dist/contracts/Configuration/RegistrationBuilders.js +2 -2
  10. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
  11. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +2 -2
  12. package/dist/contracts/Locations/Rows.d.ts +2 -0
  13. package/dist/contracts/Spots/Contracts.d.ts +4 -0
  14. package/dist/contracts/Spots/ZLinkSpot.d.ts +3 -3
  15. package/dist/runtime/abort.d.ts +5 -0
  16. package/dist/runtime/abort.js +10 -0
  17. package/dist/runtime/actors/actor-authority-publication.js +3 -2
  18. package/dist/runtime/actors/actor-client.d.ts +0 -1
  19. package/dist/runtime/actors/actor-client.js +38 -45
  20. package/dist/runtime/actors/actor-context.d.ts +2 -0
  21. package/dist/runtime/actors/actor-context.js +46 -9
  22. package/dist/runtime/actors/actor-handoff.d.ts +7 -3
  23. package/dist/runtime/actors/actor-handoff.js +212 -88
  24. package/dist/runtime/actors/actor-join-relocation.d.ts +2 -0
  25. package/dist/runtime/actors/actor-local-native-join.js +4 -0
  26. package/dist/runtime/actors/actor-mailbox.js +27 -1
  27. package/dist/runtime/actors/actor-remote-joiner.js +3 -1
  28. package/dist/runtime/actors/actor-reply.d.ts +4 -0
  29. package/dist/runtime/actors/actor-reply.js +29 -0
  30. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -0
  31. package/dist/runtime/actors/actor-runtime-state.js +2 -20
  32. package/dist/runtime/actors/actor-source-transfer.d.ts +1 -17
  33. package/dist/runtime/actors/index.d.ts +6 -2
  34. package/dist/runtime/actors/index.js +37 -21
  35. package/dist/runtime/actors/session-disconnected-wire.d.ts +8 -0
  36. package/dist/runtime/actors/session-disconnected-wire.js +48 -0
  37. package/dist/runtime/admission.d.ts +9 -1
  38. package/dist/runtime/admission.js +55 -32
  39. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +13 -0
  40. package/dist/runtime/application-jobs/application-job-queue-scope.js +27 -1
  41. package/dist/runtime/application-jobs/contracts.d.ts +2 -0
  42. package/dist/runtime/backend/contracts/index.d.ts +19 -3
  43. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +2 -2
  44. package/dist/runtime/backend/mesh-completion-table.js +5 -0
  45. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +26 -2
  46. package/dist/runtime/backend/mesh-dispatch-pump.js +193 -107
  47. package/dist/runtime/backend/node/node-raw-binding-port.js +90 -58
  48. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +33 -8
  49. package/dist/runtime/backend/node/node-raw-mesh-backend.js +142 -143
  50. package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +1 -1
  51. package/dist/runtime/backend/node/node-socket-backend-adapter.js +5 -5
  52. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  53. package/dist/runtime/channels/channel-clients.js +20 -5
  54. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +22 -3
  55. package/dist/runtime/channels/channel-dispatch-pipeline.js +103 -57
  56. package/dist/runtime/channels/channel-dispatchers.d.ts +3 -2
  57. package/dist/runtime/channels/channel-dispatchers.js +44 -37
  58. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  59. package/dist/runtime/channels/channel-envelope.js +74 -31
  60. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +4 -3
  61. package/dist/runtime/channels/channel-runtime-lifecycle.js +19 -24
  62. package/dist/runtime/channels/channel-runtime-manager.d.ts +3 -2
  63. package/dist/runtime/channels/channel-runtime-manager.js +4 -4
  64. package/dist/runtime/channels/channel-transports.d.ts +0 -1
  65. package/dist/runtime/channels/channel-transports.js +35 -33
  66. package/dist/runtime/channels/client-server-location-runtime.js +5 -4
  67. package/dist/runtime/channels/dispatch-error-reporter.d.ts +2 -1
  68. package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
  69. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  70. package/dist/runtime/channels/fanout-location-runtime.js +3 -3
  71. package/dist/runtime/diagnostics/flow-context.js +19 -7
  72. package/dist/runtime/diagnostics/index.js +4 -9
  73. package/dist/runtime/diagnostics/message-flow.d.ts +8 -0
  74. package/dist/runtime/diagnostics/message-flow.js +35 -5
  75. package/dist/runtime/diagnostics/runtime-metrics.d.ts +2 -2
  76. package/dist/runtime/diagnostics/runtime-metrics.js +10 -8
  77. package/dist/runtime/execution/index.d.ts +4 -2
  78. package/dist/runtime/execution/index.js +33 -10
  79. package/dist/runtime/execution/serial-execution-queue.d.ts +4 -0
  80. package/dist/runtime/execution/serial-execution-queue.js +21 -2
  81. package/dist/runtime/execution/state-lane.d.ts +2 -0
  82. package/dist/runtime/execution/state-lane.js +5 -0
  83. package/dist/runtime/foundation/operation-registry.d.ts +25 -1
  84. package/dist/runtime/foundation/operation-registry.js +86 -18
  85. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +39 -3
  86. package/dist/runtime/foundation/raw-service-mesh-runtime.js +151 -55
  87. package/dist/runtime/foundation/service-liveness-registry.d.ts +12 -1
  88. package/dist/runtime/foundation/service-liveness-registry.js +38 -0
  89. package/dist/runtime/foundation/service-mailbox.d.ts +7 -0
  90. package/dist/runtime/foundation/service-maintenance-runtime.js +1 -6
  91. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -3
  92. package/dist/runtime/foundation/service-relocation-object-owner.js +48 -35
  93. package/dist/runtime/foundation/service-relocation-runtime.js +7 -3
  94. package/dist/runtime/foundation/service-runtime-contracts.d.ts +8 -1
  95. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +2 -1
  96. package/dist/runtime/foundation/service-stateful-registry.d.ts +5 -4
  97. package/dist/runtime/foundation/service-stateful-registry.js +24 -26
  98. package/dist/runtime/foundation/service-stateful-runtime.d.ts +72 -6
  99. package/dist/runtime/foundation/service-stateful-runtime.js +444 -117
  100. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +14 -1
  101. package/dist/runtime/foundation/service-stateful-wire-codec.js +48 -27
  102. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +6 -1
  103. package/dist/runtime/foundation/service-wire-binary-primitives.js +27 -11
  104. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  105. package/dist/runtime/foundation/service-wire-constants.generated.js +1 -0
  106. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +10 -0
  107. package/dist/runtime/foundation/service-wire-m6a-codec.js +166 -53
  108. package/dist/runtime/host/actor-packet-relay.d.ts +6 -4
  109. package/dist/runtime/host/actor-packet-relay.js +59 -72
  110. package/dist/runtime/host/actor-placement-coordinator.js +25 -8
  111. package/dist/runtime/host/actor-transfer-runtime.d.ts +7 -31
  112. package/dist/runtime/host/actor-transfer-runtime.js +85 -331
  113. package/dist/runtime/host/application-job-queue.d.ts +24 -3
  114. package/dist/runtime/host/application-job-queue.js +28 -41
  115. package/dist/runtime/host/index.d.ts +5 -1
  116. package/dist/runtime/host/index.js +171 -97
  117. package/dist/runtime/host/location-runtime-owner.js +2 -6
  118. package/dist/runtime/host/mesh-router-resolver.d.ts +4 -0
  119. package/dist/runtime/host/mesh-router-resolver.js +14 -6
  120. package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -4
  121. package/dist/runtime/host/remote-bound-session-relay.js +71 -190
  122. package/dist/runtime/host/route-mesh-runtime.d.ts +2 -2
  123. package/dist/runtime/host/route-mesh-runtime.js +5 -3
  124. package/dist/runtime/host/runtime-shutdown.d.ts +1 -0
  125. package/dist/runtime/host/runtime-shutdown.js +3 -2
  126. package/dist/runtime/host/service-relocation-host-runtime.d.ts +17 -7
  127. package/dist/runtime/host/service-relocation-host-runtime.js +550 -367
  128. package/dist/runtime/host/spot-runtime-options-factory.js +15 -7
  129. package/dist/runtime/host/user-spot-creation-coordinator.js +33 -84
  130. package/dist/runtime/locations/auto-connect-loop.d.ts +2 -0
  131. package/dist/runtime/locations/auto-connect-loop.js +22 -14
  132. package/dist/runtime/locations/auto-connect-reconciler.js +0 -6
  133. package/dist/runtime/locations/auto-connect-types.d.ts +0 -1
  134. package/dist/runtime/locations/descriptor-publication.d.ts +4 -0
  135. package/dist/runtime/locations/descriptor-publication.js +11 -0
  136. package/dist/runtime/locations/domain-store-contract.d.ts +1 -0
  137. package/dist/runtime/locations/in-memory-authority-store.d.ts +7 -1
  138. package/dist/runtime/locations/in-memory-authority-store.js +56 -19
  139. package/dist/runtime/locations/in-memory-location-store.js +1 -10
  140. package/dist/runtime/locations/index.d.ts +1 -0
  141. package/dist/runtime/locations/index.js +1 -0
  142. package/dist/runtime/locations/lease-tracker.js +1 -6
  143. package/dist/runtime/locations/location-store-repository.d.ts +51 -1
  144. package/dist/runtime/locations/location-store-repository.js +363 -139
  145. package/dist/runtime/locations/relocation-blob.d.ts +18 -1
  146. package/dist/runtime/locations/relocation-blob.js +52 -1
  147. package/dist/runtime/locations/request-source-resolver.d.ts +37 -0
  148. package/dist/runtime/locations/request-source-resolver.js +80 -0
  149. package/dist/runtime/locations/resolvers.js +1 -1
  150. package/dist/runtime/locations/runtime.d.ts +6 -2
  151. package/dist/runtime/locations/runtime.js +37 -30
  152. package/dist/runtime/messaging/payload-codec.d.ts +7 -1
  153. package/dist/runtime/messaging/payload-codec.js +7 -6
  154. package/dist/runtime/messaging/request-result.js +29 -26
  155. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +19 -1
  156. package/dist/runtime/protocol/service_wire_codec.generated.js +85 -0
  157. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +7 -1
  158. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +23 -7
  159. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +3 -2
  160. package/dist/runtime/spots/index.d.ts +18 -11
  161. package/dist/runtime/spots/index.js +234 -176
  162. package/dist/runtime/spots/spot-activation-registry.d.ts +4 -2
  163. package/dist/runtime/spots/spot-activation-registry.js +21 -11
  164. package/dist/runtime/spots/spot-activation-state.d.ts +1 -1
  165. package/dist/runtime/spots/spot-activation-state.js +7 -7
  166. package/dist/runtime/spots/spot-activation.d.ts +6 -3
  167. package/dist/runtime/spots/spot-activation.js +123 -44
  168. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -0
  169. package/dist/runtime/spots/spot-actor-admission-coordinator.js +13 -22
  170. package/dist/runtime/spots/spot-actor-membership.d.ts +0 -1
  171. package/dist/runtime/spots/spot-actor-membership.js +0 -8
  172. package/dist/runtime/spots/spot-actor-packet-dispatch.js +33 -8
  173. package/dist/runtime/spots/spot-actor-packet-drain.js +5 -33
  174. package/dist/runtime/spots/spot-entry-activation.d.ts +2 -0
  175. package/dist/runtime/spots/spot-entry-activation.js +14 -9
  176. package/dist/runtime/spots/spot-handler-registry.d.ts +4 -3
  177. package/dist/runtime/spots/spot-handler-registry.js +6 -2
  178. package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +2 -2
  179. package/dist/runtime/spots/spot-manager-public.js +2 -2
  180. package/dist/runtime/spots/spot-node-autoconnect.d.ts +2 -1
  181. package/dist/runtime/spots/spot-node-autoconnect.js +18 -39
  182. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +19 -2
  183. package/dist/runtime/spots/spot-node-runtime-manager.js +115 -50
  184. package/dist/runtime/spots/spot-outbound.js +3 -3
  185. package/dist/runtime/spots/spot-remote-codec.js +5 -1
  186. package/dist/runtime/spots/spot-runtime-ports.d.ts +0 -1
  187. package/dist/runtime/spots/spot-serial-executor.d.ts +10 -0
  188. package/dist/runtime/spots/spot-serial-executor.js +61 -8
  189. package/dist/runtime/spots/spot-serial-turn-executor.js +19 -2
  190. package/dist/runtime/spots/spot-subscription-dispatch.js +1 -1
  191. package/dist/runtime/spots/spot-timer.d.ts +57 -5
  192. package/dist/runtime/spots/spot-timer.js +287 -103
  193. package/dist/runtime/streams/actor-session-binding-registry.d.ts +42 -11
  194. package/dist/runtime/streams/actor-session-binding-registry.js +165 -48
  195. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +8 -4
  196. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -1
  197. package/dist/runtime/streams/bound-actor-relay-sender.js +15 -8
  198. package/dist/runtime/streams/bound-session-service.d.ts +1 -1
  199. package/dist/runtime/streams/bound-session-service.js +6 -11
  200. package/dist/runtime/streams/index.d.ts +3 -2
  201. package/dist/runtime/streams/index.js +6 -4
  202. package/dist/runtime/streams/managed-stream.js +3 -2
  203. package/dist/runtime/streams/native-fallback-bound-session.js +8 -73
  204. package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -8
  205. package/dist/runtime/streams/session-actor-coordinator.js +15 -32
  206. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +3 -10
  207. package/dist/runtime/streams/stream-session-runtime.js +1 -4
  208. package/dist/runtime/workers/index.js +1 -1
  209. package/package.json +3 -3
  210. package/src/contracts/Common/ZLinkEncodedPayload.ts +24 -4
  211. package/src/contracts/Common/encoded-payload-storage.ts +6 -3
  212. package/src/contracts/Configuration/Builders.ts +4 -1
  213. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +7 -2
  214. package/src/contracts/Configuration/RegistrationBuilders.ts +6 -2
  215. package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
  216. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +2 -1
  217. package/src/contracts/Locations/Rows.ts +2 -0
  218. package/src/contracts/Spots/Contracts.ts +8 -0
  219. package/src/contracts/Spots/ZLinkSpot.ts +3 -3
  220. package/src/runtime/abort.ts +12 -0
  221. package/src/runtime/actors/actor-authority-publication.ts +3 -2
  222. package/src/runtime/actors/actor-client.ts +61 -70
  223. package/src/runtime/actors/actor-context.ts +49 -9
  224. package/src/runtime/actors/actor-handoff.ts +282 -106
  225. package/src/runtime/actors/actor-join-relocation.ts +2 -0
  226. package/src/runtime/actors/actor-local-native-join.ts +4 -0
  227. package/src/runtime/actors/actor-mailbox.ts +40 -2
  228. package/src/runtime/actors/actor-remote-joiner.ts +6 -1
  229. package/src/runtime/actors/actor-reply.ts +42 -0
  230. package/src/runtime/actors/actor-runtime-contracts.ts +2 -0
  231. package/src/runtime/actors/actor-runtime-state.ts +2 -20
  232. package/src/runtime/actors/actor-source-transfer.ts +1 -34
  233. package/src/runtime/actors/index.ts +41 -27
  234. package/src/runtime/actors/session-disconnected-wire.ts +66 -0
  235. package/src/runtime/admission.ts +69 -34
  236. package/src/runtime/application-jobs/application-job-queue-scope.ts +33 -1
  237. package/src/runtime/application-jobs/contracts.ts +2 -0
  238. package/src/runtime/backend/contracts/index.ts +39 -4
  239. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +5 -3
  240. package/src/runtime/backend/mesh-completion-table.ts +4 -0
  241. package/src/runtime/backend/mesh-dispatch-pump.ts +223 -124
  242. package/src/runtime/backend/node/node-raw-binding-port.ts +106 -70
  243. package/src/runtime/backend/node/node-raw-mesh-backend.ts +221 -170
  244. package/src/runtime/backend/node/node-socket-backend-adapter.ts +5 -5
  245. package/src/runtime/channels/channel-clients.ts +49 -24
  246. package/src/runtime/channels/channel-dispatch-pipeline.ts +173 -124
  247. package/src/runtime/channels/channel-dispatchers.ts +116 -72
  248. package/src/runtime/channels/channel-envelope.ts +105 -36
  249. package/src/runtime/channels/channel-runtime-lifecycle.ts +13 -13
  250. package/src/runtime/channels/channel-runtime-manager.ts +12 -5
  251. package/src/runtime/channels/channel-transports.ts +49 -58
  252. package/src/runtime/channels/client-server-location-runtime.ts +11 -10
  253. package/src/runtime/channels/dispatch-error-reporter.ts +4 -2
  254. package/src/runtime/channels/fanout-location-runtime.ts +17 -9
  255. package/src/runtime/diagnostics/flow-context.ts +20 -7
  256. package/src/runtime/diagnostics/index.ts +1 -7
  257. package/src/runtime/diagnostics/message-flow.ts +47 -9
  258. package/src/runtime/diagnostics/runtime-metrics.ts +12 -10
  259. package/src/runtime/execution/index.ts +40 -14
  260. package/src/runtime/execution/serial-execution-queue.ts +31 -4
  261. package/src/runtime/execution/state-lane.ts +7 -0
  262. package/src/runtime/foundation/operation-registry.ts +98 -20
  263. package/src/runtime/foundation/raw-service-mesh-runtime.ts +244 -67
  264. package/src/runtime/foundation/service-liveness-registry.ts +39 -0
  265. package/src/runtime/foundation/service-mailbox.ts +8 -0
  266. package/src/runtime/foundation/service-maintenance-runtime.ts +1 -8
  267. package/src/runtime/foundation/service-relocation-object-owner.ts +54 -37
  268. package/src/runtime/foundation/service-relocation-runtime.ts +7 -3
  269. package/src/runtime/foundation/service-runtime-contracts.ts +12 -1
  270. package/src/runtime/foundation/service-session-binding-ingress-port.ts +2 -1
  271. package/src/runtime/foundation/service-stateful-registry.ts +38 -35
  272. package/src/runtime/foundation/service-stateful-runtime.ts +667 -152
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +49 -11
  274. package/src/runtime/foundation/service-wire-binary-primitives.ts +35 -12
  275. package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
  276. package/src/runtime/foundation/service-wire-m6a-codec.ts +187 -51
  277. package/src/runtime/host/actor-packet-relay.ts +113 -94
  278. package/src/runtime/host/actor-placement-coordinator.ts +31 -8
  279. package/src/runtime/host/actor-transfer-runtime.ts +104 -430
  280. package/src/runtime/host/application-job-queue.ts +29 -44
  281. package/src/runtime/host/index.ts +286 -129
  282. package/src/runtime/host/location-runtime-owner.ts +2 -6
  283. package/src/runtime/host/mesh-router-resolver.ts +13 -5
  284. package/src/runtime/host/remote-bound-session-relay.ts +86 -248
  285. package/src/runtime/host/route-mesh-runtime.ts +11 -5
  286. package/src/runtime/host/runtime-shutdown.ts +15 -4
  287. package/src/runtime/host/service-relocation-host-runtime.ts +784 -475
  288. package/src/runtime/host/spot-runtime-options-factory.ts +18 -7
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +41 -100
  290. package/src/runtime/locations/auto-connect-loop.ts +22 -14
  291. package/src/runtime/locations/auto-connect-reconciler.ts +0 -6
  292. package/src/runtime/locations/auto-connect-types.ts +0 -1
  293. package/src/runtime/locations/descriptor-publication.ts +7 -0
  294. package/src/runtime/locations/domain-store-contract.ts +5 -0
  295. package/src/runtime/locations/in-memory-authority-store.ts +85 -23
  296. package/src/runtime/locations/in-memory-location-store.ts +1 -12
  297. package/src/runtime/locations/index.ts +1 -0
  298. package/src/runtime/locations/lease-tracker.ts +2 -9
  299. package/src/runtime/locations/location-store-repository.ts +628 -152
  300. package/src/runtime/locations/relocation-blob.ts +75 -1
  301. package/src/runtime/locations/request-source-resolver.ts +138 -0
  302. package/src/runtime/locations/resolvers.ts +2 -2
  303. package/src/runtime/locations/runtime.ts +70 -40
  304. package/src/runtime/messaging/payload-codec.ts +8 -11
  305. package/src/runtime/messaging/request-result.ts +33 -29
  306. package/src/runtime/protocol/service_wire_codec.generated.ts +87 -4
  307. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +13 -10
  308. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +3 -2
  309. package/src/runtime/spots/index.ts +375 -281
  310. package/src/runtime/spots/spot-activation-registry.ts +25 -13
  311. package/src/runtime/spots/spot-activation-state.ts +12 -19
  312. package/src/runtime/spots/spot-activation.ts +170 -86
  313. package/src/runtime/spots/spot-actor-admission-coordinator.ts +25 -55
  314. package/src/runtime/spots/spot-actor-membership.ts +0 -15
  315. package/src/runtime/spots/spot-actor-packet-dispatch.ts +56 -11
  316. package/src/runtime/spots/spot-actor-packet-drain.ts +9 -52
  317. package/src/runtime/spots/spot-entry-activation.ts +24 -19
  318. package/src/runtime/spots/spot-handler-registry.ts +15 -4
  319. package/src/runtime/spots/spot-manager-internal-contracts.ts +2 -2
  320. package/src/runtime/spots/spot-manager-public.ts +2 -2
  321. package/src/runtime/spots/spot-node-autoconnect.ts +22 -45
  322. package/src/runtime/spots/spot-node-runtime-manager.ts +197 -67
  323. package/src/runtime/spots/spot-outbound.ts +3 -3
  324. package/src/runtime/spots/spot-remote-codec.ts +9 -2
  325. package/src/runtime/spots/spot-runtime-ports.ts +0 -1
  326. package/src/runtime/spots/spot-serial-executor.ts +97 -25
  327. package/src/runtime/spots/spot-serial-turn-executor.ts +22 -3
  328. package/src/runtime/spots/spot-subscription-dispatch.ts +1 -1
  329. package/src/runtime/spots/spot-timer.ts +413 -157
  330. package/src/runtime/streams/actor-session-binding-registry.ts +236 -64
  331. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +16 -8
  332. package/src/runtime/streams/bound-actor-relay-sender.ts +23 -9
  333. package/src/runtime/streams/bound-session-service.ts +7 -10
  334. package/src/runtime/streams/index.ts +12 -6
  335. package/src/runtime/streams/managed-stream.ts +4 -2
  336. package/src/runtime/streams/native-fallback-bound-session.ts +14 -103
  337. package/src/runtime/streams/session-actor-coordinator.ts +39 -88
  338. package/src/runtime/streams/stream-binding-runtime-ports.ts +3 -9
  339. package/src/runtime/streams/stream-session-runtime.ts +1 -5
  340. package/src/runtime/workers/index.ts +1 -1
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkNodeRawMeshBackend = void 0;
4
4
  exports.requestFailureResult = requestFailureResult;
5
+ const routing_id_1 = require("../../routing-id");
5
6
  const durable_service_request_1 = require("../../foundation/durable-service-request");
7
+ const routing_id_2 = require("../../routing-id");
6
8
  const stream_wire_1 = require("@zlink-systems/stream-wire");
7
9
  const zlink_1 = require("@zlink-systems/zlink");
8
10
  const node_crypto_1 = require("node:crypto");
@@ -33,11 +35,13 @@ const DEFAULT_NATIVE_ACTIVE_CAPACITY = 10_000;
33
35
  const UNSTARTED_DIAGNOSTIC_ENDPOINT = 'inproc://not-started';
34
36
  const MULTIPART_PACKET_NAME = service_wire_constants_generated_1.SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME;
35
37
  const MULTIPART_CONTENT_TYPE = service_wire_constants_generated_1.SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE;
36
- const FATAL_UTF8 = new TextDecoder('utf-8', { fatal: true });
37
38
  const MAX_DRAIN_RECORDS = 64;
38
- // Preserve the existing route observation/admission/liveness cadence. Only the binding
39
- // readable handler admits receive work; this timer never probes the socket.
39
+ // The maintenance timer runs at the nearest management deadline and never
40
+ // sooner than this. Only the binding readable handler admits receive work;
41
+ // this timer never probes the socket.
40
42
  const MESH_BACKEND_MAINTENANCE_INTERVAL_MS = 1;
43
+ /** The longest single timer delay Node accepts. */
44
+ const MESH_BACKEND_MAINTENANCE_MAX_DELAY_MS = 2 ** 31 - 1;
41
45
  // Spec 08 §4.2 bounds the combined turn. Raw gets one equal share; stateful
42
46
  // can use the remaining turn, including time the raw registry did not consume.
43
47
  const MESH_BACKEND_RAW_MAINTENANCE_SHARE = 1 / 2;
@@ -71,18 +75,19 @@ class ZLinkNodeRawMeshBackend {
71
75
  stateful;
72
76
  readyHandler;
73
77
  maintenanceTimer;
74
- pumping = false;
78
+ maintenanceDueMs = Number.POSITIVE_INFINITY;
79
+ pumpTask;
75
80
  readable = 0;
76
81
  onReadable = (receiveReady, routeReady) => {
77
82
  if (receiveReady)
78
83
  this.readable |= 1;
79
84
  if (routeReady)
80
85
  this.readable |= 2;
81
- if (!this.closed && !this.pumping)
82
- void this.pump();
86
+ this.pump();
83
87
  };
84
88
  onMaintenance = () => {
85
89
  this.maintenanceTimer = undefined;
90
+ this.maintenanceDueMs = Number.POSITIVE_INFINITY;
86
91
  if (this.closed)
87
92
  return;
88
93
  const nowMs = performance.now();
@@ -90,7 +95,7 @@ class ZLinkNodeRawMeshBackend {
90
95
  this.runtime?.expireOperations(nowMs, nowMs + raw_service_mesh_runtime_1.RAW_MESH_RECEIVE_TIME_BUDGET_MS * MESH_BACKEND_RAW_MAINTENANCE_SHARE);
91
96
  this.stateful?.expireOperations(nowMs, turnDeadlineMs);
92
97
  this.scheduleMaintenance();
93
- void this.pump();
98
+ this.pump();
94
99
  };
95
100
  onPendingOperationsChanged = () => this.scheduleMaintenance();
96
101
  nextPeerIntent = 1n;
@@ -105,6 +110,8 @@ class ZLinkNodeRawMeshBackend {
105
110
  protocolError;
106
111
  messageFollowHandler;
107
112
  dispatchErrors;
113
+ sessionOwnerDescriptors;
114
+ requestSourceAcceptance;
108
115
  peerDisconnectedHandlers = new Set();
109
116
  constructor(meshName, routingId, bindingPort, applicationJobQueue, applicationJobReceiveFlowFailureSink, peerAdmissionSealed, infrastructureTaskRunner) {
110
117
  this.meshName = meshName;
@@ -138,6 +145,10 @@ class ZLinkNodeRawMeshBackend {
138
145
  this.dispatchErrors = reporter;
139
146
  this.stateful?.setDispatchErrorReporter(reporter, this.meshName);
140
147
  }
148
+ setSessionOwnerDescriptors(source) {
149
+ this.sessionOwnerDescriptors = source;
150
+ this.stateful?.setSessionOwnerDescriptors(source);
151
+ }
141
152
  setProtocolErrorHandler(handler) {
142
153
  this.protocolError = handler;
143
154
  }
@@ -173,7 +184,7 @@ class ZLinkNodeRawMeshBackend {
173
184
  return this.observeStateful(service_runtime_contracts_1.OperationKind.InstanceSpotRequest, this.requireStateful().requestToMissingInstanceSpotFrame(target, encodeMultipartApplicationFrame(parts), deadlineUnixMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata), onAdmitted));
174
185
  }
175
186
  setRoutingId(routingId) {
176
- if (String(routingId) !== this.routingId) {
187
+ if (!(0, routing_id_1.routingIdsEqual)((0, routing_id_2.toBackendRoutingId)(routingId), this.routingId)) {
177
188
  throw new Error('MeshNode routing id is immutable after construction.');
178
189
  }
179
190
  }
@@ -232,16 +243,22 @@ class ZLinkNodeRawMeshBackend {
232
243
  if (this.dispatchErrors !== undefined) {
233
244
  this.stateful.setDispatchErrorReporter(this.dispatchErrors, this.meshName);
234
245
  }
246
+ if (this.sessionOwnerDescriptors !== undefined) {
247
+ this.stateful.setSessionOwnerDescriptors(this.sessionOwnerDescriptors);
248
+ }
235
249
  if (this.mailboxRecordDropped !== undefined) {
236
250
  this.stateful.setMailboxDropHandler(this.mailboxRecordDropped);
237
251
  }
238
252
  this.stateful.setMessageFollowHandler((record) => this.messageFollowHandler?.(record));
253
+ if (this.requestSourceAcceptance !== undefined) {
254
+ this.stateful.setRequestSourceAcceptance(this.requestSourceAcceptance);
255
+ }
239
256
  this.runtime = runtime;
240
257
  try {
241
258
  runtime.setReadableHandler(this.onReadable);
242
259
  }
243
260
  catch (error) {
244
- this.close();
261
+ void this.close().catch((failure) => runtime.reportInfrastructureFailure(failure));
245
262
  throw error;
246
263
  }
247
264
  this.scheduleMaintenance();
@@ -252,26 +269,30 @@ class ZLinkNodeRawMeshBackend {
252
269
  async sendMessageFollowNotification(targetNodeRid, record) {
253
270
  return await this.requireStateful().sendMessageFollowNotification(targetNodeRid, record);
254
271
  }
255
- shutdown(_timeoutMs) {
256
- this.close();
272
+ async shutdown(_timeoutMs) {
273
+ await this.close();
257
274
  return zlink_1.RequestResult.Ok;
258
275
  }
276
+ cancelPendingOperations(reason) {
277
+ this.stateful?.cancelPendingOperations(reason);
278
+ this.runtime?.cancelPendingOperations(reason);
279
+ }
259
280
  async publishDraining() {
260
281
  for (const name of this.channels.keys())
261
282
  this.channels.set(name, 0);
262
283
  await this.requireRuntime().updateLocalDescriptor({ state: 'draining' });
263
284
  }
264
- close() {
265
- if (this.closed)
266
- return;
285
+ async close() {
286
+ this.closed = true;
267
287
  if (this.maintenanceTimer !== undefined)
268
288
  clearTimeout(this.maintenanceTimer);
269
289
  this.maintenanceTimer = undefined;
290
+ if (this.pumpTask !== undefined)
291
+ await this.pumpTask;
270
292
  this.stateful?.close();
271
293
  this.stateful = undefined;
272
294
  this.runtime?.close();
273
295
  this.runtime = undefined;
274
- this.closed = true;
275
296
  }
276
297
  addChannelName(name) {
277
298
  this.requireNotStarted();
@@ -323,6 +344,10 @@ class ZLinkNodeRawMeshBackend {
323
344
  });
324
345
  return intent;
325
346
  }
347
+ setRequestSourceAcceptance(acceptance) {
348
+ this.requestSourceAcceptance = acceptance;
349
+ this.stateful?.setRequestSourceAcceptance(acceptance);
350
+ }
326
351
  expectPeer(peer) {
327
352
  this.requireRuntime().expectPeerByRoutingId(peer.endpoint, peer.nodeRoutingId, peer.securityIdentity, peer.lifecycleGeneration);
328
353
  }
@@ -374,6 +399,9 @@ class ZLinkNodeRawMeshBackend {
374
399
  isObjectClientNodeDirectTarget(targetRid) {
375
400
  return this.requireRuntime().isObjectClientNodeDirectTarget(String(targetRid));
376
401
  }
402
+ waitForPeerRoute(targetRid, lifecycleGeneration, deadlineUnixMs, signal) {
403
+ return this.requireRuntime().waitForPeerRoute(String(targetRid), lifecycleGeneration, deadlineUnixMs, signal);
404
+ }
377
405
  observePeerRoute(targetRid) {
378
406
  return this.requireRuntime().observePeerRoute(String(targetRid));
379
407
  }
@@ -411,15 +439,15 @@ class ZLinkNodeRawMeshBackend {
411
439
  return (0, durable_service_request_1.requestDurableService)(this.requireRuntime(), String(targetRid), frames, performance.now() + (options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS), 'relocation control', options?.signal, options?.onSubmitted);
412
440
  }
413
441
  requestToNode(targetRid, parts, options) {
414
- const pending = this.requireRuntime().requestToNode(String(targetRid), encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted);
415
- return this.observeCompletion(pending.id, service_runtime_contracts_1.OperationKind.NodeRequest, pending.promise);
442
+ const pending = this.requireRuntime().requestToNode(String(targetRid), encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted, this.requestObserver, service_runtime_contracts_1.OperationKind.NodeRequest);
443
+ return this.observedOperation(pending, service_runtime_contracts_1.OperationKind.NodeRequest);
416
444
  }
417
445
  async sendToChannel(channelName, parts) {
418
446
  return this.requireRuntime().sendToChannel(channelName, encodeMultipartApplicationFrame(parts));
419
447
  }
420
448
  requestToChannel(channelName, parts, options) {
421
- const pending = this.requireRuntime().requestToChannel(channelName, encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted);
422
- return this.observeCompletion(pending.id, service_runtime_contracts_1.OperationKind.ChannelRequest, pending.promise);
449
+ const pending = this.requireRuntime().requestToChannel(channelName, encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted, this.requestObserver, service_runtime_contracts_1.OperationKind.ChannelRequest);
450
+ return this.observedOperation(pending, service_runtime_contracts_1.OperationKind.ChannelRequest);
423
451
  }
424
452
  status() {
425
453
  const descriptor = this.runtime?.topology.localDescriptor() ?? this.createDescriptor();
@@ -580,7 +608,8 @@ class ZLinkNodeRawMeshBackend {
580
608
  return this.requireStateful().instanceSpotApplicationTarget(spotId);
581
609
  }
582
610
  waitForInstanceApplicationQuiescence(spotId, signal) {
583
- return this.requireStateful().waitForInstanceApplicationQuiescence(spotId, signal);
611
+ // Closing the stateful owner terminalizes its operations and clears these waiters.
612
+ return this.stateful?.waitForInstanceApplicationQuiescence(spotId, signal) ?? Promise.resolve();
584
613
  }
585
614
  restoreUserSpotAuthority(spotId, stableType, generation, authorityOwnerGeneration) {
586
615
  return new RawServiceSpot(this, this.requireStateful().restoreUserSpotAuthority(spotId, stableType, generation, authorityOwnerGeneration));
@@ -608,7 +637,7 @@ class ZLinkNodeRawMeshBackend {
608
637
  nodeRid: String(actor.nodeRid),
609
638
  actorId: actor.actorId,
610
639
  generation: actor.generation
611
- }, String(sessionNodeRid), String(sessionRid), bindingGeneration);
640
+ }, String(sessionNodeRid), (0, routing_id_2.toBackendRoutingId)(sessionRid), bindingGeneration);
612
641
  }
613
642
  registerInstanceIntent(instanceType, route, expectedCurrentRoute) {
614
643
  this.requireStateful().registerInstanceIntent(instanceType, route, expectedCurrentRoute);
@@ -713,27 +742,26 @@ class ZLinkNodeRawMeshBackend {
713
742
  const target = String(targetNodeRid);
714
743
  return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorJoin, this.requireStateful().joinActorEntrySpotCanonical(actor, target, request, actorFence, local, timeoutMs));
715
744
  }
716
- async sendToActor(actor, parts) {
717
- return this.requireStateful().sendToActor(actor, this.peerGeneration(String(actor.nodeRid)), actor.generation, encodeMultipart(parts));
745
+ async sendToActor(actor, parts, options) {
746
+ return this.requireStateful().sendToActor(actor, encodeMultipart(parts), undefined, undefined, options?.routeFence);
718
747
  }
719
748
  requestToActor(actor, parts, options) {
720
- return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(actor, this.peerGeneration(String(actor.nodeRid)), actor.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, undefined, undefined, options?.onAdmitted));
749
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(actor, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, undefined, undefined, options?.onAdmitted, options?.routeFence));
750
+ }
751
+ acceptRelocatedActorTerminal(operation, replyRouteId, result) {
752
+ return this.requireStateful().acceptRelocatedActorTerminal(operation, replyRouteId, result);
721
753
  }
722
754
  async actorSendToActor(source, target, parts) {
723
- return (await this.requireStateful().sendToActor(target, this.peerGeneration(String(target.nodeRid)), target.generation, encodeMultipart(parts), source));
755
+ return (await this.requireStateful().sendToActor(target, encodeMultipart(parts), source));
724
756
  }
725
757
  actorRequestToActor(source, target, parts, options) {
726
- return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(target, this.peerGeneration(String(target.nodeRid)), target.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, source, undefined, options?.onAdmitted));
758
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(target, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, source, undefined, options?.onAdmitted));
727
759
  }
728
760
  async sendActorBoundSession(actor, expectedBindingGeneration, parts, _flags) {
729
761
  return (await this.requireStateful().sendBoundSession(actor, expectedBindingGeneration, encodeMultipart(parts)));
730
762
  }
731
763
  closeActorBoundSession(actor, expectedBindingGeneration, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS) {
732
- const binding = this.requireStateful().registry.binding(actor);
733
- if (binding === undefined) {
734
- return this.observeImmediateFailure(service_runtime_contracts_1.OperationKind.StreamUnbind, zlink_1.RequestResult.NotFound);
735
- }
736
- return this.observeStateful(service_runtime_contracts_1.OperationKind.StreamUnbind, this.requireStateful().unbindSession(binding.sessionRid, actor, expectedBindingGeneration, timeoutMs));
764
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.StreamUnbind, this.requireStateful().closeBoundSession(actor, expectedBindingGeneration, timeoutMs));
737
765
  }
738
766
  leaveActor(actor, expectedMembershipEpoch, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS) {
739
767
  return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorLeave, this.requireStateful().leaveActor(actor, expectedMembershipEpoch, timeoutMs));
@@ -796,10 +824,29 @@ class ZLinkNodeRawMeshBackend {
796
824
  }
797
825
  return result;
798
826
  }
827
+ /**
828
+ * Arms the one maintenance timer for the nearest management deadline
829
+ * (spec 08 §4.2): request expiry, liveness, or a pending peer handshake.
830
+ * An earlier deadline re-arms it; a later one keeps the armed time.
831
+ */
799
832
  scheduleMaintenance() {
800
833
  if (this.closed)
801
834
  return;
802
- this.maintenanceTimer ??= setTimeout(this.onMaintenance, MESH_BACKEND_MAINTENANCE_INTERVAL_MS);
835
+ const nowMs = performance.now();
836
+ const dueMs = Math.max(nowMs + MESH_BACKEND_MAINTENANCE_INTERVAL_MS, Math.min(this.runtime?.nextMaintenanceDeadlineMs(nowMs) ?? Number.POSITIVE_INFINITY, this.stateful?.nextMaintenanceDeadlineMs() ?? Number.POSITIVE_INFINITY));
837
+ if (dueMs === Number.POSITIVE_INFINITY) {
838
+ if (this.maintenanceTimer !== undefined)
839
+ clearTimeout(this.maintenanceTimer);
840
+ this.maintenanceTimer = undefined;
841
+ this.maintenanceDueMs = dueMs;
842
+ return;
843
+ }
844
+ if (this.maintenanceTimer === undefined || dueMs < this.maintenanceDueMs) {
845
+ if (this.maintenanceTimer !== undefined)
846
+ clearTimeout(this.maintenanceTimer);
847
+ this.maintenanceTimer = setTimeout(this.onMaintenance, Math.min(MESH_BACKEND_MAINTENANCE_MAX_DELAY_MS, Math.ceil(dueMs - nowMs)));
848
+ this.maintenanceDueMs = dueMs;
849
+ }
803
850
  const pending = (this.runtime?.pendingOperationCount ?? 0) + (this.stateful?.pendingOperationCount ?? 0) > 0;
804
851
  if (pending === this.maintenanceTimer.hasRef())
805
852
  return;
@@ -810,15 +857,19 @@ class ZLinkNodeRawMeshBackend {
810
857
  this.maintenanceTimer.unref();
811
858
  }
812
859
  }
813
- async pump() {
814
- if (this.isClosed() || this.pumping)
860
+ pump() {
861
+ if (this.closed || this.pumpTask !== undefined)
815
862
  return;
816
- this.pumping = true;
863
+ this.pumpTask = this.runPump(this.requireRuntime());
864
+ }
865
+ async runPump(runtime) {
866
+ // Publish pumpTask before any callback can signal readiness or begin close.
867
+ await Promise.resolve();
817
868
  try {
818
869
  do {
819
870
  const ready = this.readable;
820
871
  this.readable = 0;
821
- const more = await this.requireRuntime().pumpBatch((ready & 1) !== 0, (ready & 2) !== 0);
872
+ const more = await runtime.pumpBatch((ready & 1) !== 0, (ready & 2) !== 0);
822
873
  if (more) {
823
874
  // Yield only after actual progress, retaining readiness across the
824
875
  // existing batch limits until receive reports no data.
@@ -827,14 +878,14 @@ class ZLinkNodeRawMeshBackend {
827
878
  }
828
879
  } while (!this.closed && this.readable !== 0);
829
880
  }
881
+ catch (error) {
882
+ runtime.reportInfrastructureFailure(error);
883
+ }
830
884
  finally {
831
- this.pumping = false;
885
+ this.pumpTask = undefined;
832
886
  this.scheduleMaintenance();
833
887
  }
834
888
  }
835
- isClosed() {
836
- return this.closed;
837
- }
838
889
  notifyReady() {
839
890
  const runtime = this.runtime;
840
891
  let domains = service_runtime_contracts_1.ReadyDomain.None;
@@ -847,6 +898,19 @@ class ZLinkNodeRawMeshBackend {
847
898
  if (domains !== service_runtime_contracts_1.ReadyDomain.None)
848
899
  this.readyHandler?.(domains);
849
900
  }
901
+ /**
902
+ * The raw registry takes a remote request's terminal and hands it here,
903
+ * where the Framework completion owner receives it in the same turn.
904
+ */
905
+ requestObserver = {
906
+ operationCompleted: (id, result, operationKind) => this.deliverCompletion({ high: 1n, low: id }, operationKind ?? 0, result),
907
+ operationFailed: (id, error, operationKind) => this.deliverCompletion({ high: 1n, low: id }, operationKind ?? 0, requestFailureResult(error))
908
+ };
909
+ observedOperation(pending, operationKind) {
910
+ return pending.promise === undefined
911
+ ? { high: 1n, low: pending.id }
912
+ : this.observeCompletion(pending.id, operationKind, pending.promise);
913
+ }
850
914
  observeCompletion(low, operationKind, promise) {
851
915
  const id = { high: 1n, low };
852
916
  void promise.then((result) => this.deliverCompletion(id, operationKind, result), (error) => this.deliverCompletion(id, operationKind, requestFailureResult(error)));
@@ -857,10 +921,6 @@ class ZLinkNodeRawMeshBackend {
857
921
  void pending.promise.then((result) => this.deliverCompletion(id, operationKind, result), (error) => this.deliverCompletion(id, operationKind, requestFailureResult(error)));
858
922
  return id;
859
923
  }
860
- observeImmediateFailure(operationKind, terminalResult) {
861
- const low = this.nextPeerIntent++;
862
- return this.observeCompletion(low, operationKind, Promise.resolve({ terminalResult, failureCode: 0 }));
863
- }
864
924
  deliverCompletion(operationId, operationKind, result) {
865
925
  if (this.completionHandler !== undefined) {
866
926
  this.completionHandler({ operationId, terminalResult: result.terminalResult }, () => completionRecord(operationId, operationKind, result));
@@ -1055,7 +1115,7 @@ class RawStreamSessionService {
1055
1115
  return {
1056
1116
  state: this.state,
1057
1117
  lifecycleGeneration: 1n,
1058
- sessionCount: BigInt(new Set(bindings.map((value) => value.sessionRid)).size),
1118
+ sessionCount: BigInt(new Set(bindings.map((value) => (0, routing_id_2.encodeRoutingIdStorageHex)(value.sessionRid))).size),
1059
1119
  bindingCount: BigInt(bindings.length),
1060
1120
  pendingMessageCount: 0n,
1061
1121
  pendingByteCount: 0n,
@@ -1066,32 +1126,32 @@ class RawStreamSessionService {
1066
1126
  this.requireStarted();
1067
1127
  return this.observe(service_runtime_contracts_1.OperationKind.ActorLookup, this.stateful.lookupRemoteActor(String(targetNodeRid), actorId, timeoutMs));
1068
1128
  }
1069
- bindActor(sessionRid, actor, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, onBindingReplaced, actorAuthority) {
1129
+ bindActor(sessionRid, actor, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, onBindingReplaced, actorAuthority, close) {
1070
1130
  this.requireStarted();
1071
1131
  const sessionKey = String(sessionRid);
1072
1132
  this.sessionTargets.set(sessionKey, sessionRid);
1073
- return this.observe(service_runtime_contracts_1.OperationKind.StreamBind, this.stateful.bindSession(sessionKey, actor, timeoutMs, (targetSessionRid, payloadFrame) => this.deliver(targetSessionRid, actor.actorId, payloadFrame), onBindingReplaced, actorAuthority));
1133
+ return this.observe(service_runtime_contracts_1.OperationKind.StreamBind, this.stateful.bindSession(sessionRid, actor, timeoutMs, (_targetSessionRid, payloadFrame) => this.deliver(sessionKey, actor.actorId, payloadFrame), onBindingReplaced, actorAuthority, close));
1074
1134
  }
1075
1135
  unbindActor(sessionRid, actor, expectedBindingGeneration, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS) {
1076
1136
  this.requireStarted();
1077
- return this.observe(service_runtime_contracts_1.OperationKind.StreamUnbind, this.stateful.unbindSession(String(sessionRid), actor, expectedBindingGeneration, timeoutMs));
1137
+ return this.observe(service_runtime_contracts_1.OperationKind.StreamUnbind, this.stateful.unbindSession(sessionRid, actor, expectedBindingGeneration, timeoutMs));
1078
1138
  }
1079
1139
  bindings(sessionRid) {
1080
- return this.stateful.sessionBindings(String(sessionRid));
1140
+ return this.stateful.sessionBindings(sessionRid);
1081
1141
  }
1082
1142
  async sendToActor(sessionRid, actor, parts) {
1083
1143
  this.requireStarted();
1084
- return (await this.stateful.sendSessionToActor(String(sessionRid), actor, encodeMultipart(parts)));
1144
+ return (await this.stateful.sendSessionToActor(sessionRid, actor, encodeMultipart(parts)));
1085
1145
  }
1086
1146
  async deliver(sessionRid, actorId, payload) {
1087
1147
  const target = this.sessionTargets.get(sessionRid);
1088
1148
  if (target === undefined)
1089
1149
  return false;
1090
1150
  const operation = this.stream.send(target);
1091
- const parts = decodeMultipartParts((0, service_wire_m6a_codec_1.decodeApplicationPayloadView)(payload).payload, borrowMultipartPart);
1151
+ const parts = (0, service_wire_m6a_codec_1.decodeMultipartParts)((0, service_wire_m6a_codec_1.decodeApplicationPayloadView)(payload).payload, borrowMultipartPart);
1092
1152
  if (parts.length === 0)
1093
1153
  return false;
1094
- const actorSlot = await (0, service_session_binding_ingress_port_1.serviceSessionBindingIngressPortIfRegistered)(this)?.actorSlot(actorId, sessionRid);
1154
+ const actorSlot = await (0, service_session_binding_ingress_port_1.serviceSessionBindingIngressPortIfRegistered)(this)?.actorSlot(actorId, target);
1095
1155
  if (actorSlot === undefined)
1096
1156
  return false;
1097
1157
  parts[0] = Buffer.from(streamFrameWithActorSlot(parts[0], actorSlot));
@@ -1112,7 +1172,7 @@ class RawStreamSessionService {
1112
1172
  case zlink_1.SubmitResult.Terminated:
1113
1173
  // Let the socket monitor drive the existing STREAM close/unbind
1114
1174
  // lifecycle instead of maintaining a second session-close state.
1115
- (0, node_socket_backend_adapter_1.disconnectStreamPeer)(this.stream, target);
1175
+ (0, node_socket_backend_adapter_1.disconnectSocketPeer)(this.stream, (0, node_backend_adapter_support_1.toNativeRoutingId)(target));
1116
1176
  throw new runtime_values_1.ZLinkBackendResultError('submit', error.result, error.nativeErrno, {
1117
1177
  cause: error
1118
1178
  });
@@ -1340,7 +1400,7 @@ function decodeMultipartRecord(runtime, record) {
1340
1400
  const header = record.parts[0];
1341
1401
  const command = header[service_wire_binary_primitives_1.SERVICE_WIRE_COMMAND_OFFSET];
1342
1402
  const payloadFrame = record.parts[1];
1343
- const application = decodeApplicationEnvelope(payloadFrame);
1403
+ const parts = (0, service_wire_m6a_codec_1.decodeMultipartApplicationParts)(payloadFrame, runtime_message_1.ZLinkBufferMessage.fromOwned, closeMultipartMessage);
1344
1404
  const channelName = record.owner.startsWith('channel:')
1345
1405
  ? record.owner.slice('channel:'.length)
1346
1406
  : null;
@@ -1359,7 +1419,7 @@ function decodeMultipartRecord(runtime, record) {
1359
1419
  : kind === service_runtime_contracts_1.ReceiveKind.ChannelRequest
1360
1420
  ? service_runtime_contracts_1.OperationKind.ChannelRequest
1361
1421
  : 0;
1362
- const ingressLifecycle = receiveIngressLifecycle(record);
1422
+ const applicationJob = record.applicationJob;
1363
1423
  return {
1364
1424
  kind,
1365
1425
  domain: readyDomain(record.domain),
@@ -1372,22 +1432,30 @@ function decodeMultipartRecord(runtime, record) {
1372
1432
  channelName,
1373
1433
  topic: null,
1374
1434
  applicationMetadata: null,
1375
- packetName: application.packetName,
1376
- contentType: application.contentType,
1435
+ packetName: service_wire_constants_generated_1.SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME,
1436
+ contentType: service_wire_constants_generated_1.SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE,
1377
1437
  kindData: null,
1378
1438
  terminalResult: 0,
1379
1439
  failureErrno: 0,
1380
- ...ingressLifecycle,
1381
- parts: decodeMultipart(application.payload),
1440
+ applicationJobPermit: applicationJob,
1441
+ releaseRetainedIngress: applicationJob === undefined ? undefined : releaseRecordApplicationJob,
1442
+ parts,
1382
1443
  reply(parts) {
1383
1444
  if (record.correlation === undefined)
1384
1445
  return zlink_1.SubmitResult.InvalidState;
1385
1446
  runtime.reply(record, encodeMultipartApplicationFrame(parts));
1386
1447
  return zlink_1.SubmitResult.Ok;
1387
1448
  },
1388
- replyActorJoin: () => zlink_1.SubmitResult.NotSupported
1449
+ replyActorJoin: replyActorJoinNotSupported
1389
1450
  };
1390
1451
  }
1452
+ /** Shared by every ordinary record: the record's own permit lease is its retained ingress. */
1453
+ function releaseRecordApplicationJob() {
1454
+ this.applicationJobPermit?.close();
1455
+ }
1456
+ function replyActorJoinNotSupported() {
1457
+ return zlink_1.SubmitResult.NotSupported;
1458
+ }
1391
1459
  function decodeStatefulRecord(record, stateful) {
1392
1460
  const payloadFrame = record.parts.length < 2 ? undefined : record.parts[1];
1393
1461
  const canonicalActorJoin = stateful.kindData?.kind === 'actorControl' &&
@@ -1398,13 +1466,18 @@ function decodeStatefulRecord(record, stateful) {
1398
1466
  ? stateful.canonicalApplicationPayload
1399
1467
  : payloadFrame === undefined
1400
1468
  ? undefined
1401
- : decodeApplicationEnvelope(payloadFrame);
1469
+ : (0, service_wire_m6a_codec_1.decodeMultipartApplicationPayloadView)(payloadFrame);
1402
1470
  const operationId = record.correlation === undefined
1403
1471
  ? { high: 0n, low: 0n }
1404
1472
  : { high: operation_identity_1.ZLINK_NATIVE_CORRELATION_OPERATION_NAMESPACE, low: record.correlation };
1405
1473
  const ingressLifecycle = receiveIngressLifecycle(record);
1406
1474
  return {
1407
1475
  kind: stateful.receiveKind,
1476
+ get requestSource() {
1477
+ return record.requestSource;
1478
+ },
1479
+ prepareDispatch: record.sourcePreparationOwner === undefined ? undefined : prepareStatefulMailboxDispatch,
1480
+ statefulMailboxRecord: record,
1408
1481
  domain: readyDomain(record.domain),
1409
1482
  sourceNodeRid: record.sourceRoutingId ?? null,
1410
1483
  sourceSpotId: stateful.sourceSpotId ?? null,
@@ -1498,6 +1571,13 @@ function receiveIngressLifecycle(record) {
1498
1571
  releaseRetainedIngress: () => applicationJob.close()
1499
1572
  };
1500
1573
  }
1574
+ function prepareStatefulMailboxDispatch(signal) {
1575
+ const mailboxRecord = this.statefulMailboxRecord;
1576
+ const owner = mailboxRecord?.sourcePreparationOwner;
1577
+ return mailboxRecord === undefined || owner === undefined
1578
+ ? true
1579
+ : owner.prepareDispatch(mailboxRecord, signal);
1580
+ }
1501
1581
  function readyOwner(owner, nodeRid, stateful, domain) {
1502
1582
  if (owner.startsWith('spot:')) {
1503
1583
  return {
@@ -1607,52 +1687,8 @@ function encodeMultipartApplicationFrame(parts) {
1607
1687
  throw new TypeError('Multipart payload must contain at least one part.');
1608
1688
  return (0, service_wire_m6a_codec_1.encodeMultipartApplicationPayload)(values.map(messageBytesView), MULTIPART_PACKET_NAME, MULTIPART_CONTENT_TYPE);
1609
1689
  }
1610
- function decodeApplicationEnvelope(frame) {
1611
- const bytes = Buffer.from(frame.buffer, frame.byteOffset, frame.byteLength);
1612
- if (bytes.length < service_wire_m6a_codec_1.APPLICATION_PAYLOAD_MINIMUM_FIELD_BYTES ||
1613
- bytes[0] !== service_wire_m6a_codec_1.APPLICATION_PAYLOAD_VERSION) {
1614
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope.');
1615
- }
1616
- const bodyLength = bytes.readUInt32BE(1);
1617
- if (bodyLength !== bytes.length - 5) {
1618
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope length.');
1619
- }
1620
- let offset = 5;
1621
- const packetLength = bytes[offset++];
1622
- if (packetLength === 0 || bytes.length - offset < packetLength + 1) {
1623
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope packet name.');
1624
- }
1625
- let packetName;
1626
- try {
1627
- packetName = FATAL_UTF8.decode(bytes.subarray(offset, offset + packetLength));
1628
- }
1629
- catch {
1630
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope packet name.');
1631
- }
1632
- offset += packetLength;
1633
- const contentLength = bytes[offset++];
1634
- if (contentLength === 0 || bytes.length - offset < contentLength + 4) {
1635
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope content type.');
1636
- }
1637
- let contentType;
1638
- try {
1639
- contentType = FATAL_UTF8.decode(bytes.subarray(offset, offset + contentLength));
1640
- }
1641
- catch {
1642
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid application envelope content type.');
1643
- }
1644
- offset += contentLength;
1645
- const payloadLength = bytes.readUInt32BE(offset);
1646
- offset += 4;
1647
- if (packetName !== MULTIPART_PACKET_NAME ||
1648
- contentType !== MULTIPART_CONTENT_TYPE ||
1649
- payloadLength !== bytes.length - offset) {
1650
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Unexpected M6A application payload.');
1651
- }
1652
- return { packetName, contentType, payload: bytes.subarray(offset) };
1653
- }
1654
1690
  function decodeMultipart(payload) {
1655
- return decodeMultipartParts(payload, runtime_message_1.ZLinkBufferMessage.fromOwned, closeMultipartMessage);
1691
+ return (0, service_wire_m6a_codec_1.decodeMultipartParts)(payload, runtime_message_1.ZLinkBufferMessage.fromOwned, closeMultipartMessage);
1656
1692
  }
1657
1693
  function closeMultipartMessage(part) {
1658
1694
  part.close();
@@ -1660,43 +1696,6 @@ function closeMultipartMessage(part) {
1660
1696
  function borrowMultipartPart(part) {
1661
1697
  return part;
1662
1698
  }
1663
- function decodeMultipartParts(payload, materialize, release) {
1664
- const bytes = Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);
1665
- if (bytes.length < 4)
1666
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart payload.');
1667
- const count = bytes.readUInt32BE(0);
1668
- if (count === 0 || count > Math.floor((bytes.length - 4) / 4)) {
1669
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid multipart part count.');
1670
- }
1671
- const result = new Array(count);
1672
- let offset = 4;
1673
- let index = 0;
1674
- try {
1675
- for (; index < count; index++) {
1676
- if (bytes.length - offset < 4) {
1677
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part length.');
1678
- }
1679
- const length = bytes.readUInt32BE(offset);
1680
- offset += 4;
1681
- if (bytes.length - offset < length) {
1682
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part.');
1683
- }
1684
- result[index] = materialize(bytes.subarray(offset, offset + length));
1685
- offset += length;
1686
- }
1687
- if (offset !== bytes.length) {
1688
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Multipart payload has trailing bytes.');
1689
- }
1690
- return result;
1691
- }
1692
- catch (error) {
1693
- if (release !== undefined) {
1694
- for (let retained = 0; retained < index; retained++)
1695
- release(result[retained]);
1696
- }
1697
- throw error;
1698
- }
1699
- }
1700
1699
  function messageBytesView(value) {
1701
1700
  if (typeof value === 'object' && 'data' in value) {
1702
1701
  return value.data();
@@ -4,7 +4,7 @@ export declare function wrapSocket<T extends {
4
4
  close(): void;
5
5
  }>(nativeInstance: T, pollCompletion?: boolean): T & ZLinkBackendObject;
6
6
  export declare function nodeEventLoopPollerOf(socket: object): ZLinkNodeEventLoopPoller;
7
- export declare function disconnectStreamPeer(socket: {
7
+ export declare function disconnectSocketPeer(socket: {
8
8
  disconnectRid(routingId: unknown): void;
9
9
  }, routingId: unknown): void;
10
10
  export declare function isEndpointCloseIgnorableError(error: unknown): boolean;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wrapSocket = wrapSocket;
4
4
  exports.nodeEventLoopPollerOf = nodeEventLoopPollerOf;
5
- exports.disconnectStreamPeer = disconnectStreamPeer;
5
+ exports.disconnectSocketPeer = disconnectSocketPeer;
6
6
  exports.isEndpointCloseIgnorableError = isEndpointCloseIgnorableError;
7
7
  const RegistrationBuilderPolicy_1 = require("../../../contracts/Configuration/RegistrationBuilderPolicy");
8
8
  const node_backend_adapter_support_1 = require("./node-backend-adapter-support");
@@ -205,7 +205,7 @@ function wrapSocket(nativeInstance, pollCompletion) {
205
205
  return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.requestToSpot((0, node_backend_adapter_support_1.toNativeRoutingId)(targetRid), (0, node_backend_adapter_support_1.toNativeRoutingId)(targetSpot)), payload, timeoutMs, undefined, onAdmitted);
206
206
  },
207
207
  disconnectPeer(routingId) {
208
- disconnectStreamPeer(nativeInstance, routingId);
208
+ disconnectSocketPeer(nativeInstance, (0, node_backend_adapter_support_1.toNativeRoutingId)(routingId));
209
209
  },
210
210
  async bindActor(_sessionRid, _actor, _timeoutMs, _signal) {
211
211
  throw new Error('Session Actor dispatch requires enableActorDispatch() and a Framework MeshNode service route.');
@@ -228,13 +228,13 @@ function nodeEventLoopPollerOf(socket) {
228
228
  }
229
229
  return poller;
230
230
  }
231
- function disconnectStreamPeer(socket, routingId) {
231
+ function disconnectSocketPeer(socket, routingId) {
232
232
  try {
233
- socket.disconnectRid((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId));
233
+ socket.disconnectRid(routingId);
234
234
  }
235
235
  catch (error) {
236
236
  // An absent RID has already completed the physical close. The existing
237
- // session lifecycle still owns local cleanup and unbind.
237
+ // logical lifecycle still owns local cleanup and unbind.
238
238
  if (!(0, node_backend_adapter_support_1.isBindingNotFound)(error))
239
239
  throw error;
240
240
  }
@@ -36,6 +36,7 @@ export declare class DefaultZLinkRouteClient implements ZLinkRouteClient {
36
36
  private readonly spotRouterChannelIdForMesh;
37
37
  private readonly channelTransport?;
38
38
  private readonly nodeSends;
39
+ private readonly nodeRequests;
39
40
  constructor(registration: ZLinkFrameworkRegistration, transport?: ZLinkRouteClientTransport | undefined, spotRouterChannelIdForMesh?: (meshName: string) => string, channelTransport?: ZLinkChannelClientTransportSource | undefined);
40
41
  sendToNode(meshName: string, targetNodeRid: string, message: unknown): ZLinkSendCall;
41
42
  requestToNode(meshName: string, targetNodeRid: string, request: unknown): ZLinkRequestCall;