@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
@@ -1,6 +1,8 @@
1
+ import { ZLinkProviderRelocationRepository } from '../locations/relocation-blob';
1
2
  import type { ApplicationJobOrigin } from '../application-jobs/contracts';
2
3
  import { currentApplicationJobOrigin } from '../application-jobs/application-job-queue-scope';
3
4
  import { listAllMeshNodeDescriptors } from '../locations/location-store-pages';
5
+ import { ZLinkDescriptorPublicationUnconfirmedError } from '../locations/descriptor-publication';
4
6
  import { ZlinkStreamContentType } from '@zlink-systems/stream-wire';
5
7
  import { randomBytes, randomUUID } from 'node:crypto';
6
8
  import { isDeepStrictEqual } from 'node:util';
@@ -66,11 +68,12 @@ import {
66
68
  ZLinkActorTransferRegistry
67
69
  } from '../actors';
68
70
  import { messageFollowOwnerNodeRid, ownerFence } from '../actors/actor-message-follow-context';
71
+ import { ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET } from '../actors/actor-packet-relay-wire';
69
72
  import {
70
73
  ZLINK_INTERNAL_ACTOR_TRANSPORT_DELIVERY_GATE,
71
74
  type ZLinkInternalActorTransportDeliveryGate
72
75
  } from '../actors/actor-transport-delivery-gate';
73
- import { ZLinkRuntimeAdmissionGate } from '../admission';
76
+ import { ZLinkRuntimeAdmissionGate, type ZLinkMeshDispatchAdmission } from '../admission';
74
77
  import {
75
78
  ZLINK_INTERNAL_APPLICATION_JOB_QUEUE_HANDLER_START_GATE,
76
79
  type ZLinkInternalApplicationJobQueueHandlerStartGate
@@ -113,6 +116,7 @@ import {
113
116
  currentOrCreateFlow,
114
117
  DefaultZLinkRuntimeEventPublisher,
115
118
  flowIfEnabled,
119
+ messageFlowTracingEnabled,
116
120
  runWithFlow,
117
121
  ZLinkRuntimeMetrics,
118
122
  type ZLinkDiagnosticsContext,
@@ -141,6 +145,7 @@ import {
141
145
  import {
142
146
  MeshPeerRuntimeState,
143
147
  OperationKind,
148
+ ReadyDomain,
144
149
  ReceiveKind,
145
150
  type ReadyRecord,
146
151
  type ReceiveRecord
@@ -170,12 +175,18 @@ import {
170
175
  encodeFrameworkPayloadMessage
171
176
  } from '../messaging/payload-codec';
172
177
  import { ZLinkSubmitStatus } from '../messaging/submission-result';
173
- import { decodeRoutingId, encodeRoutingIdStorageHex, routingIdsEqual } from '../routing-id';
178
+ import {
179
+ decodeRoutingId,
180
+ encodeRoutingIdStorageHex,
181
+ routingIdsEqual,
182
+ toBackendRoutingId
183
+ } from '../routing-id';
174
184
  import {
175
185
  DefaultZLinkSpotManager,
176
186
  ZLinkPublicSpotManager,
177
187
  ZLinkRuntimeSpotPublisherTransport,
178
188
  ZLinkSpotNodeRuntimeManager,
189
+ registrationAcceptsNewActor,
179
190
  type ZLinkDetachedTaskRunner,
180
191
  type ZLinkSpotManagerOptions
181
192
  } from '../spots';
@@ -204,6 +215,7 @@ import { ZLinkInstanceActivationAuthority } from './instance-activation-authorit
204
215
  import { ZLinkLocationRuntimeOwner } from './location-runtime-owner';
205
216
  import { MeshRouterResolver } from './mesh-router-resolver';
206
217
  import {
218
+ type ZLinkDrainForceReason,
207
219
  ZLinkDrainingStatePublishError,
208
220
  ZLinkRetiringRollbackError,
209
221
  ZLinkRouteMeshRuntimeCoordinator
@@ -219,6 +231,8 @@ import { ZLinkSpotNodeRuntimeOptionsFactory } from './spot-node-runtime-options-
219
231
  import { ZLinkSpotRuntimeOptionsFactory } from './spot-runtime-options-factory';
220
232
  import { ZLinkStatefulAuthorityRouteRuntime } from './stateful-authority-route-runtime';
221
233
  import { ZLinkUserSpotCreationCoordinator } from './user-spot-creation-coordinator';
234
+ import { decodeRemoteActorPacketRelay } from '../spots/spot-remote-route-codec';
235
+ import { decodeStreamHeader } from '../streams/protocol';
222
236
 
223
237
  const HOST_SHUTDOWN_POLL_INTERVAL_MS = 100;
224
238
  const HANDOFF_ACCEPTANCE_POLL_INTERVAL_MS = 10;
@@ -277,7 +291,9 @@ export class ZLinkFrameworkRuntimeHost
277
291
  private spotManager?: DefaultZLinkSpotManager;
278
292
  private userSpotCoordinator?: ZLinkUserSpotCreationCoordinator;
279
293
  private ownerLeaseRecoveryRuntime?: ZLinkLocationRuntime;
280
- private ownerLeaseRecoveryHandler?: () => void;
294
+ private ownerLeaseRecoveryHandler?: Parameters<
295
+ ZLinkLocationRuntime['addOwnerLeaseRenewedHandler']
296
+ >[0];
281
297
  private registerUserSpotHandlers?: (runtime: ZLinkSpotNodeRuntimeManager) => void;
282
298
  private readonly destroyedActorRefs = new Map<string, ActorRef>();
283
299
  private readonly runtimeEventPublisher: ZLinkRuntimeEventPublisher;
@@ -325,6 +341,7 @@ export class ZLinkFrameworkRuntimeHost
325
341
  readonly routeMeshRuntime: ZLinkRouteMeshRuntime;
326
342
  readonly clientServerRuntime: ZLinkClientServerRuntime;
327
343
  readonly fanoutRuntime: ZLinkFanoutRuntime;
344
+ private readonly relocationStore?: import('../../contracts/Locations/RelocationStore').ZLinkRelocationStore;
328
345
  private readonly routeMeshCoordinator: ZLinkRouteMeshRuntimeCoordinator;
329
346
  constructor(
330
347
  readonly options: ZLinkFrameworkRuntimeHostOptions,
@@ -335,6 +352,11 @@ export class ZLinkFrameworkRuntimeHost
335
352
  this.runtimeEventPublisher =
336
353
  options.runtimeEventPublisher ?? new DefaultZLinkRuntimeEventPublisher();
337
354
  this.metrics = new ZLinkRuntimeMetrics(options.registration.metrics?.meterProvider);
355
+ const relocationProvider = options.registration.locations.relocationStoreInstance;
356
+ this.relocationStore =
357
+ relocationProvider === undefined
358
+ ? undefined
359
+ : new ZLinkProviderRelocationRepository(relocationProvider, this.metrics);
338
360
  const handlerStartGate = options.providerResolver?.get?.(
339
361
  ZLINK_INTERNAL_APPLICATION_JOB_QUEUE_HANDLER_START_GATE as unknown as Type<ZLinkInternalApplicationJobQueueHandlerStartGate>
340
362
  );
@@ -440,8 +462,8 @@ export class ZLinkFrameworkRuntimeHost
440
462
  },
441
463
  relay: (actor, header, payload) =>
442
464
  this.boundSessionRelay.actorPackets.relayActorPacket(actor, header, payload),
443
- notifyDisconnected: (actor, signal) =>
444
- this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal)
465
+ notifyDisconnected: (actor, signal, binding) =>
466
+ this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal, binding)
445
467
  });
446
468
  this.actorHandoff = new ZLinkActorHandoffCoordinator({
447
469
  routedTransport: this.routeTransport,
@@ -702,21 +724,11 @@ export class ZLinkFrameworkRuntimeHost
702
724
  primaryMeshNode: () => this.requirePrimaryMeshNode(),
703
725
  notifyEntrySpotActorLeft: (actor, signal) =>
704
726
  this.spotNodeRuntime?.notifyPrimaryEntrySpotActorLeft(actor, signal) ?? Promise.resolve(),
705
- restoreEntrySpotActorJoined: (actor, signal) =>
706
- this.spotNodeRuntime?.notifyPrimaryEntrySpotActorJoined(actor, signal) ?? Promise.resolve(),
707
727
  locationLifecycle: () => this.locationOwner.currentLifecycle,
708
728
  spotRouteResolver: () => this.createLocationSpotRouteResolver(),
709
729
  actorHandoff: this.actorHandoff,
710
- actorTransferRegistry: this.actorTransferRegistry,
711
730
  authorityStore: () => this.locationOwner.currentStores?.locationStore,
712
731
  currentOwner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
713
- liveDescriptors: (meshName, signal) => {
714
- const runtime = this.locationOwner.currentRuntime;
715
- if (runtime === undefined) {
716
- throw new Error('Session owner liveness is unavailable without a Location runtime.');
717
- }
718
- return runtime.listLiveMeshNodes(meshName, signal);
719
- },
720
732
  sessionRelocationWire: () => this.serviceRelocation,
721
733
  clearRemoteActorPacketTarget: (actorId) =>
722
734
  this.boundSessionRelay.clearRemoteActorPacketTarget(actorId),
@@ -770,14 +782,15 @@ export class ZLinkFrameworkRuntimeHost
770
782
  'source actor departure',
771
783
  error
772
784
  ),
773
- onSourceDepartureCompleted: (actorId) =>
774
- this.publishActorHandoffEvent({ marker: 'source_cleanup', actorId }),
775
- shutdownSignal: () => this.executionState?.abortController.signal,
776
- metrics: this.metrics
785
+ shutdownSignal: () => this.executionState?.abortController.signal
777
786
  });
778
787
  this.serviceRelocation = new ZLinkHostServiceRelocationRuntime({
788
+ flowCreationEnabled: () => this.flowCreationEnabled(),
789
+ messageFlow: () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow,
779
790
  registration: options.registration,
780
791
  targetAdmissionSealed: () => this.shutdownOperationStartedAt !== undefined,
792
+ requestPeerReconcile: (meshName, peerRid) =>
793
+ this.spotNodeRuntime?.requestPeerReconcile(meshName, peerRid) ?? Promise.resolve(),
781
794
  sourceQuiescenceChanged: () => this.publishCurrentRuntimeStatus(),
782
795
  providerResolver: options.providerResolver,
783
796
  locationStore: () => this.locationOwner.currentStores?.locationStore,
@@ -789,14 +802,14 @@ export class ZLinkFrameworkRuntimeHost
789
802
  meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
790
803
  completions: (meshName) => this.spotNodeRuntime?.meshCompletionTable(meshName),
791
804
  spotManager: () => this.spotManager,
792
- spotNodeRuntime: () => this.spotNodeRuntime,
793
805
  actorManager: () => this.actorManager,
794
806
  actorTransfer: this.actorTransferRuntime,
795
807
  boundSessionRelocation: {
796
- receiveSeal: (value, signal) =>
808
+ receiveSeal: (value, signal, onInstalled) =>
797
809
  this.boundSessionRelay.boundSessions.receiveServiceWireSessionRelocationSeal(
798
810
  value,
799
- signal
811
+ signal,
812
+ onInstalled
800
813
  ),
801
814
  receiveRoute: (value) =>
802
815
  this.boundSessionRelay.boundSessions.receiveServiceWireSessionRelocationRoute(value),
@@ -851,7 +864,8 @@ export class ZLinkFrameworkRuntimeHost
851
864
  this.performMeshDrain(meshName, signal, stopStartingSignal),
852
865
  shutdownResources: (meshName, signal) => this.performMeshShutdown(meshName, signal),
853
866
  cleanupHostResources: (signal) => this.cleanupOwnerForDrain(signal),
854
- forceStopResources: (meshName) => this.forceStopMesh(meshName)
867
+ forceStopResources: (meshName, reason, signal) =>
868
+ this.performMeshShutdown(meshName, signal, reason)
855
869
  });
856
870
  this.metricRegistrations.push(
857
871
  this.metrics.registerHostState(() => runtimeStateMetricName(this.runtimeState)),
@@ -1426,7 +1440,6 @@ export class ZLinkFrameworkRuntimeHost
1426
1440
  let spotNodeRuntime: ZLinkSpotNodeRuntimeManager | undefined;
1427
1441
  let streamRuntime: ZLinkStreamRuntimeManager | undefined;
1428
1442
  let startedLocationRuntime: ZLinkLocationRuntime | undefined;
1429
- let statefulAuthorityRoutes: ZLinkStatefulAuthorityRouteRuntime | undefined;
1430
1443
  try {
1431
1444
  this.executionState = new ZLinkFrameworkExecutionState(context);
1432
1445
  // Seed the shared live-mode cell from the configured mode (default errorsOnly).
@@ -1463,24 +1476,16 @@ export class ZLinkFrameworkRuntimeHost
1463
1476
  () => this.shutdownDeadline!.signal
1464
1477
  );
1465
1478
  startedLocationRuntime = locationRuntime;
1466
- if (locationRuntime !== undefined) {
1467
- this.installOwnerLeaseRecoveryPublication(locationRuntime, spotNodeRuntime, channelRuntime);
1468
- }
1469
1479
  const locationStore = this.locationOwner.currentStores?.locationStore;
1470
1480
  if (locationStore !== undefined && locationRuntime?.ownerLeaseUsable !== false) {
1471
- await spotNodeRuntime.publishMeshNodeState(
1472
- ZLinkFrameworkRuntimeState.Preparing,
1473
- this.executionState.abortController.signal
1474
- );
1475
- if (this.requiresStatefulAuthorityRuntime()) {
1476
- this.installLocationBackedAuthorities(locationStore, spotNodeRuntime);
1477
- statefulAuthorityRoutes = this.createStatefulAuthorityRoutes(
1478
- locationStore,
1479
- spotNodeRuntime
1481
+ await this.publishOrStayPreparing(locationRuntime, async (publishSignal) => {
1482
+ await spotNodeRuntime!.startLocationAutoConnect(publishSignal);
1483
+ await channelRuntime!.startLocationAutoConnect(publishSignal);
1484
+ await spotNodeRuntime!.publishMeshNodeState(
1485
+ ZLinkFrameworkRuntimeState.Preparing,
1486
+ publishSignal
1480
1487
  );
1481
- await statefulAuthorityRoutes.start(this.executionState.abortController.signal);
1482
- this.statefulAuthorityRoutes = statefulAuthorityRoutes;
1483
- }
1488
+ });
1484
1489
  }
1485
1490
  streamRuntime = new ZLinkStreamRuntimeManager({
1486
1491
  listenerRecords,
@@ -1502,18 +1507,20 @@ export class ZLinkFrameworkRuntimeHost
1502
1507
  });
1503
1508
  streamRuntime.start();
1504
1509
  this.streamRuntime = streamRuntime;
1510
+ // Location runtime §5: a host without an owner lease stays Preparing;
1511
+ // owner lease recovery enters Serving once it publishes descriptors.
1505
1512
  if (locationRuntime === undefined || locationRuntime.ownerLeaseUsable) {
1506
- await spotNodeRuntime.publishMeshNodeState(
1507
- ZLinkFrameworkRuntimeState.Serving,
1508
- this.executionState.abortController.signal
1513
+ await this.publishOrStayPreparing(locationRuntime, (publishSignal) =>
1514
+ this.enterServing(spotNodeRuntime!, publishSignal)
1509
1515
  );
1510
1516
  }
1511
- this.routeMeshCoordinator.markServing();
1512
- this.setRuntimeState(ZLinkFrameworkRuntimeState.Serving);
1517
+ if (locationRuntime !== undefined) {
1518
+ this.installOwnerLeaseRecoveryPublication(locationRuntime, spotNodeRuntime, channelRuntime);
1519
+ }
1513
1520
  this.lifecycleSink?.push('framework:started');
1514
1521
  } catch (error) {
1515
1522
  if (this.shutdownDeadline !== undefined && isAbortError(error)) throw error;
1516
- await statefulAuthorityRoutes?.stop();
1523
+ await this.statefulAuthorityRoutes?.stop();
1517
1524
  try {
1518
1525
  await this.runWithShutdownDeadline(DEFAULT_HOST_CONTROL_TIMEOUT_MS, async () =>
1519
1526
  rollbackRuntimeStart({
@@ -1568,7 +1575,13 @@ export class ZLinkFrameworkRuntimeHost
1568
1575
  const hasDiscovery = hasConfiguredLocationStore(this.options.registration);
1569
1576
  const source =
1570
1577
  hasManual && hasDiscovery ? 'manual_and_redis' : hasManual ? 'manual' : 'redis';
1571
- const emptyCapacity = { active: 0, reserved: 0, limit: 0 };
1578
+ const capacity =
1579
+ descriptor === undefined
1580
+ ? undefined
1581
+ : this.locationOwner.currentStores?.locationStore.confirmedCapacity?.(
1582
+ { meshName, rid: descriptor.rid },
1583
+ descriptor.populationCapacity
1584
+ );
1572
1585
  snapshots.push({
1573
1586
  meshName,
1574
1587
  source,
@@ -1580,9 +1593,9 @@ export class ZLinkFrameworkRuntimeHost
1580
1593
  channelName: channel.channelName,
1581
1594
  readyMembers: channel.readyTargetCount
1582
1595
  })),
1583
- actorCapacity: descriptor?.populationCapacity.actors ?? emptyCapacity,
1584
- spotCapacity: descriptor?.populationCapacity.spots ?? emptyCapacity,
1585
- spotTypeCapacities: (descriptor?.populationCapacity.spotTypes ?? []).map((capacity) => ({
1596
+ actorCapacity: capacity?.actors,
1597
+ spotCapacity: capacity?.spots,
1598
+ spotTypeCapacities: (capacity?.spotTypes ?? []).map((capacity) => ({
1586
1599
  spotKind: capacity.objectKind === 'instance_spot' ? 'instance' : 'user',
1587
1600
  stableType: capacity.stableType,
1588
1601
  active: capacity.active,
@@ -1641,14 +1654,22 @@ export class ZLinkFrameworkRuntimeHost
1641
1654
  spotNodeRuntime: ZLinkSpotNodeRuntimeManager,
1642
1655
  channelRuntime: ZLinkChannelRuntimeManager
1643
1656
  ): void {
1644
- const handler = () => {
1657
+ let recoveryOperation: Promise<void> | undefined;
1658
+ const handler: Parameters<ZLinkLocationRuntime['addOwnerLeaseRenewedHandler']>[0] = (
1659
+ _renewal,
1660
+ wasOwnerLeaseUsable
1661
+ ) => {
1645
1662
  if (!this.ownerAdmissionOpen()) return;
1646
- void this.resumeOwnerLeaseOwnedWork(runtime, spotNodeRuntime, channelRuntime).catch(
1647
- (error) => {
1663
+ if (wasOwnerLeaseUsable && this.runtimeState !== ZLinkFrameworkRuntimeState.Preparing) return;
1664
+ if (recoveryOperation !== undefined) return;
1665
+ recoveryOperation = this.resumeOwnerLeaseOwnedWork(runtime, spotNodeRuntime, channelRuntime)
1666
+ .catch((error) => {
1648
1667
  runtime.closeOwnerLeaseAdmission(error);
1649
1668
  this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('owner lease recovery', error);
1650
- }
1651
- );
1669
+ })
1670
+ .finally(() => {
1671
+ recoveryOperation = undefined;
1672
+ });
1652
1673
  };
1653
1674
  this.ownerLeaseRecoveryRuntime = runtime;
1654
1675
  this.ownerLeaseRecoveryHandler = handler;
@@ -1661,25 +1682,72 @@ export class ZLinkFrameworkRuntimeHost
1661
1682
  channelRuntime: ZLinkChannelRuntimeManager
1662
1683
  ): Promise<void> {
1663
1684
  if (!this.ownerAdmissionOpen()) return;
1664
- const signal = this.executionState?.abortController.signal;
1665
- await spotNodeRuntime.publishMeshNodeState(ZLinkFrameworkRuntimeState.Preparing, signal);
1685
+ await this.publishOrStayPreparing(runtime, async (signal) => {
1686
+ await spotNodeRuntime.publishMeshNodeState(ZLinkFrameworkRuntimeState.Preparing, signal);
1687
+ if (runtime.ownerLeaseUsable === false) return;
1688
+ if (this.runtimeState !== ZLinkFrameworkRuntimeState.Preparing) {
1689
+ await spotNodeRuntime.publishMeshNodeState(this.runtimeState, signal);
1690
+ }
1691
+ await spotNodeRuntime.startLocationAutoConnect(signal);
1692
+ await channelRuntime.startLocationAutoConnect(signal);
1693
+ await channelRuntime.reclaimLocationOwnerRows(signal);
1694
+ await this.locationOwner.currentLifecycle?.reclaimOwnerRows();
1695
+ if (this.runtimeState === ZLinkFrameworkRuntimeState.Preparing) {
1696
+ await this.enterServing(spotNodeRuntime, signal);
1697
+ }
1698
+ });
1699
+ }
1700
+
1701
+ // The one transition from Preparing to Serving: the host publishes its
1702
+ // Serving descriptors first, then takes new application work.
1703
+ private async enterServing(
1704
+ spotNodeRuntime: ZLinkSpotNodeRuntimeManager,
1705
+ signal: AbortSignal | undefined
1706
+ ): Promise<void> {
1666
1707
  const store = this.locationOwner.currentStores?.locationStore;
1667
- if (
1668
- this.statefulAuthorityRoutes === undefined &&
1669
- store !== undefined &&
1670
- this.executionState !== undefined &&
1671
- this.requiresStatefulAuthorityRuntime()
1672
- ) {
1673
- const routes = this.createStatefulAuthorityRoutes(store, spotNodeRuntime);
1674
- await routes.start(signal);
1675
- this.statefulAuthorityRoutes = routes;
1708
+ if (store !== undefined) {
1709
+ await this.startStatefulAuthority(store, spotNodeRuntime, signal);
1676
1710
  }
1677
- if (runtime.ownerLeaseUsable === false) return;
1678
- await spotNodeRuntime.publishMeshNodeState(this.runtimeState, signal);
1679
- await spotNodeRuntime.startLocationAutoConnect(signal);
1680
- await channelRuntime.startLocationAutoConnect(signal);
1681
- await channelRuntime.reclaimLocationOwnerRows(signal);
1682
- await this.locationOwner.currentLifecycle?.reclaimOwnerRows();
1711
+ await spotNodeRuntime.publishMeshNodeState(ZLinkFrameworkRuntimeState.Serving, signal);
1712
+ this.routeMeshCoordinator.markServing();
1713
+ this.setRuntimeState(ZLinkFrameworkRuntimeState.Serving);
1714
+ }
1715
+
1716
+ // Location runtime §5: a startup publication the Store does not confirm (a
1717
+ // provider error, or no answer within the renew timeout) leaves the host in
1718
+ // Preparing. The owner lease renewal handler retries publication while the
1719
+ // host stays Preparing; only a settled rejection fails startup.
1720
+ private async publishOrStayPreparing(
1721
+ runtime: ZLinkLocationRuntime | undefined,
1722
+ publish: (signal: AbortSignal | undefined) => Promise<void>
1723
+ ): Promise<boolean> {
1724
+ const signal = this.executionState?.abortController.signal;
1725
+ try {
1726
+ await publish(signal);
1727
+ return true;
1728
+ } catch (error) {
1729
+ if (runtime === undefined || !(error instanceof ZLinkDescriptorPublicationUnconfirmedError))
1730
+ throw error;
1731
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException(
1732
+ 'startup descriptor publication',
1733
+ error
1734
+ );
1735
+ return false;
1736
+ }
1737
+ }
1738
+
1739
+ private async startStatefulAuthority(
1740
+ locationStore: import('../locations/domain-store-contract').ZLinkDomainLocationStore,
1741
+ spotNodeRuntime: ZLinkSpotNodeRuntimeManager,
1742
+ signal: AbortSignal | undefined
1743
+ ): Promise<void> {
1744
+ if (this.statefulAuthorityRoutes !== undefined || !this.requiresStatefulAuthorityRuntime()) {
1745
+ return;
1746
+ }
1747
+ this.installLocationBackedAuthorities(locationStore, spotNodeRuntime);
1748
+ const routes = this.createStatefulAuthorityRoutes(locationStore, spotNodeRuntime);
1749
+ await routes.start(signal);
1750
+ this.statefulAuthorityRoutes = routes;
1683
1751
  }
1684
1752
 
1685
1753
  private createStatefulAuthorityRoutes(
@@ -1689,7 +1757,7 @@ export class ZLinkFrameworkRuntimeHost
1689
1757
  return new ZLinkStatefulAuthorityRouteRuntime({
1690
1758
  store: locationStore,
1691
1759
  creationStore: locationStore,
1692
- relocationStore: this.options.registration.locations.relocationStoreInstance,
1760
+ relocationStore: this.relocationStore,
1693
1761
  meshNodes: spotNodeRuntime.meshNodesByName,
1694
1762
  pollingIntervalMs:
1695
1763
  this.options.registration.locations.options.pollingIntervalMs ??
@@ -1747,7 +1815,7 @@ export class ZLinkFrameworkRuntimeHost
1747
1815
  this.options.registration.spotNodes.get(meshName)?.instanceSpotFactoryRegistrations?.[
1748
1816
  stableType
1749
1817
  ]?.relocation.kind,
1750
- relocationStore: this.options.registration.locations.relocationStoreInstance,
1818
+ relocationStore: this.relocationStore,
1751
1819
  meshName,
1752
1820
  owner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
1753
1821
  metrics: this.metrics,
@@ -1812,7 +1880,24 @@ export class ZLinkFrameworkRuntimeHost
1812
1880
  );
1813
1881
  }
1814
1882
 
1815
- private async performMeshShutdown(meshName: string, signal: AbortSignal): Promise<void> {
1883
+ private async performMeshShutdown(
1884
+ meshName: string,
1885
+ signal: AbortSignal,
1886
+ forceReason?: ZLinkDrainForceReason
1887
+ ): Promise<void> {
1888
+ if (forceReason !== undefined) {
1889
+ this.spotNodeRuntime
1890
+ ?.meshNode(meshName)
1891
+ ?.cancelPendingOperations?.(
1892
+ createInternalFrameworkException(
1893
+ ZLinkFrameworkInternalErrorKind.RuntimeShutdown,
1894
+ 'The host stopped before the request completed.'
1895
+ )
1896
+ );
1897
+ await waitForForcedSessionNotification(this.streamRuntime?.notifyServerDrain(meshName));
1898
+ } else {
1899
+ await awaitWithDrainSignal(this.serviceRelocation.drainActorJoinSources(meshName), signal);
1900
+ }
1816
1901
  await this.spotManager?.drainForShutdown(meshName, signal, this.runtimeDeadline);
1817
1902
  await awaitWithDrainSignal(this.streamRuntime?.notifyServerDrain(meshName), signal);
1818
1903
  }
@@ -1966,11 +2051,6 @@ export class ZLinkFrameworkRuntimeHost
1966
2051
  }
1967
2052
  }
1968
2053
 
1969
- private async forceStopMesh(meshName: string): Promise<void> {
1970
- await waitForForcedSessionNotification(this.streamRuntime?.notifyServerDrain(meshName));
1971
- await this.spotManager?.drainForShutdown(meshName, undefined, this.runtimeDeadline);
1972
- }
1973
-
1974
2054
  private registerInstanceApplicationLifecycle(
1975
2055
  meshName: string,
1976
2056
  node: ZLinkBackendMeshNode,
@@ -2000,8 +2080,10 @@ export class ZLinkFrameworkRuntimeHost
2000
2080
  target.stableType,
2001
2081
  target.targetSpotId as never,
2002
2082
  objectGeneration,
2003
- this.executionState?.abortController.signal
2083
+ this.executionState?.abortController.signal,
2084
+ 'first-terminal'
2004
2085
  ),
2086
+ publish: (target) => spotManager.publishInstance(target, meshName),
2005
2087
  discard: (target) => spotManager.discardInstance(meshName, target.targetSpotId as never),
2006
2088
  beginTerminal: (target) =>
2007
2089
  spotManager.beginInstanceTerminal(
@@ -2228,8 +2310,8 @@ export class ZLinkFrameworkRuntimeHost
2228
2310
  descriptor.objectRole === 'server' &&
2229
2311
  descriptor.placementWeight > 0 &&
2230
2312
  descriptor.entrySpotId !== undefined &&
2231
- excludedNodeRids?.has(String(descriptor.rid)) !== true &&
2232
- capability !== undefined
2313
+ excludedNodeRids?.has(encodeRoutingIdStorageHex(descriptor.rid)) !== true &&
2314
+ capability?.entryAccepted === true
2233
2315
  );
2234
2316
  }
2235
2317
  );
@@ -2253,7 +2335,7 @@ export class ZLinkFrameworkRuntimeHost
2253
2335
  leaseGeneration: selected.leaseGeneration
2254
2336
  },
2255
2337
  isLocal:
2256
- String(localStatus.routingId) === String(selected.rid) &&
2338
+ routingIdsEqual(localStatus.routingId, selected.rid) &&
2257
2339
  localStatus.lifecycleGeneration === selected.lifecycleGeneration
2258
2340
  };
2259
2341
  }
@@ -2344,7 +2426,7 @@ export class ZLinkFrameworkRuntimeHost
2344
2426
  descriptor.state === 1 &&
2345
2427
  descriptor.objectRole === 'server' &&
2346
2428
  descriptor.placementWeight > 0 &&
2347
- excludedNodeRids?.has(String(descriptor.rid)) !== true &&
2429
+ excludedNodeRids?.has(encodeRoutingIdStorageHex(descriptor.rid)) !== true &&
2348
2430
  (spots.limit === 0 || spots.active + spots.reserved < spots.limit) &&
2349
2431
  capability !== undefined &&
2350
2432
  (spotTypeCapacity === undefined ||
@@ -2365,7 +2447,7 @@ export class ZLinkFrameworkRuntimeHost
2365
2447
  },
2366
2448
  isLocal:
2367
2449
  localStatus !== undefined &&
2368
- String(localStatus.routingId) === String(selected.rid) &&
2450
+ routingIdsEqual(localStatus.routingId, selected.rid) &&
2369
2451
  localStatus.lifecycleGeneration === selected.lifecycleGeneration
2370
2452
  };
2371
2453
  }
@@ -2471,6 +2553,18 @@ export class ZLinkFrameworkRuntimeHost
2471
2553
  return await actorPlacement.handleRemoteCreate(
2472
2554
  record,
2473
2555
  async (requestPayload, authority, createSignal) => {
2556
+ const registration = this.options.registration.spotNodes.get(meshName);
2557
+ if (
2558
+ registration === undefined ||
2559
+ !registrationAcceptsNewActor(registration, record.stableType)
2560
+ ) {
2561
+ // Framework failure before the callback (Actor model §6.3): the reservation is
2562
+ // cancelled and the requester excludes this host run.
2563
+ throw createInternalFrameworkException(
2564
+ ZLinkFrameworkInternalErrorKind.RouteNotConnected,
2565
+ `RouteMesh '${meshName}' registers no Entry Spot type that accepts Actor type '${record.stableType}'.`
2566
+ );
2567
+ }
2474
2568
  const request = decodeFrameworkCreationPayload(
2475
2569
  requestPayload,
2476
2570
  this.options.registration.messageSerializers
@@ -2526,7 +2620,7 @@ export class ZLinkFrameworkRuntimeHost
2526
2620
  }
2527
2621
  if (
2528
2622
  local.actorRef.objectGeneration !== authority.objectGeneration ||
2529
- String(local.actorRef.nodeRid) !== record.reservation.targetNodeRid
2623
+ !routingIdsEqual(local.actorRef.nodeRid, record.reservation.targetNodeRid)
2530
2624
  ) {
2531
2625
  throw createInternalFrameworkException(
2532
2626
  ZLinkFrameworkInternalErrorKind.ActorCreateFailed,
@@ -2603,7 +2697,7 @@ export class ZLinkFrameworkRuntimeHost
2603
2697
  },
2604
2698
  isLocalNode: (meshName, nodeRid) => {
2605
2699
  const status = this.spotNodeRuntime?.meshNode(meshName)?.status();
2606
- return status !== undefined && String(status.routingId) === String(nodeRid);
2700
+ return status !== undefined && routingIdsEqual(status.routingId, nodeRid);
2607
2701
  },
2608
2702
  remoteClose: (meshName, targetNodeRid, request, timeoutMs) => {
2609
2703
  const node = this.spotNodeRuntime?.meshNode(meshName);
@@ -2798,20 +2892,22 @@ export class ZLinkFrameworkRuntimeHost
2798
2892
  private dispatchMeshNodeRecord(
2799
2893
  meshName: string,
2800
2894
  record: ReceiveRecord,
2801
- signal?: AbortSignal
2895
+ signal?: AbortSignal,
2896
+ admit?: ZLinkMeshDispatchAdmission
2802
2897
  ): void | Promise<void> {
2803
2898
  const control = this.serviceRelocation.tryHandleControl(meshName, record, signal);
2804
2899
  if (control instanceof Promise)
2805
2900
  return control.then((handled) =>
2806
- handled ? undefined : this.dispatchMeshNodePayload(meshName, record, signal)
2901
+ handled ? undefined : this.dispatchMeshNodePayload(meshName, record, signal, admit)
2807
2902
  );
2808
- if (!control) return this.dispatchMeshNodePayload(meshName, record, signal);
2903
+ if (!control) return this.dispatchMeshNodePayload(meshName, record, signal, admit);
2809
2904
  }
2810
2905
 
2811
2906
  private dispatchMeshNodePayload(
2812
2907
  meshName: string,
2813
2908
  record: ReceiveRecord,
2814
- signal?: AbortSignal
2909
+ signal?: AbortSignal,
2910
+ admit?: ZLinkMeshDispatchAdmission
2815
2911
  ): void | Promise<void> {
2816
2912
  if (record.kind === ReceiveKind.NodeRequest && record.parts.length === 1) {
2817
2913
  const terminal = decodeRemoteActorSourceLeaveTerminal(record.parts[0]!.data());
@@ -2825,7 +2921,7 @@ export class ZLinkFrameworkRuntimeHost
2825
2921
  'MeshNode node-direct dispatch requires the channel runtime.'
2826
2922
  );
2827
2923
  }
2828
- return channelRuntime.dispatchMeshRoute(meshName, record, signal);
2924
+ return channelRuntime.dispatchMeshRoute(meshName, record, signal, admit);
2829
2925
  }
2830
2926
 
2831
2927
  private async completeFormalSourceLeave(
@@ -2883,22 +2979,32 @@ export class ZLinkFrameworkRuntimeHost
2883
2979
  'MeshNode channel dispatch requires the channel runtime.'
2884
2980
  );
2885
2981
  }
2886
- return this.admission.run(meshName, 'RouteMesh channel dispatch', () =>
2887
- channelRuntime.dispatchMeshChannel(meshName, record, signal)
2982
+ return channelRuntime.dispatchMeshChannel(
2983
+ meshName,
2984
+ record,
2985
+ signal,
2986
+ (dispatch, onRejected) =>
2987
+ this.admitMeshDispatch(
2988
+ meshName,
2989
+ record,
2990
+ 'RouteMesh channel dispatch',
2991
+ dispatch,
2992
+ onRejected
2993
+ )
2888
2994
  );
2889
2995
  }
2890
2996
  case ReceiveKind.NodeSend:
2891
2997
  case ReceiveKind.NodeRequest: {
2892
- return this.admission.run(meshName, 'RouteMesh node dispatch', () =>
2893
- this.dispatchMeshNodeRecord(meshName, record, signal)
2998
+ return this.dispatchMeshNodeRecord(meshName, record, signal, (dispatch, onRejected) =>
2999
+ this.admitMeshDispatch(meshName, record, 'RouteMesh node dispatch', dispatch, onRejected)
2894
3000
  );
2895
3001
  }
2896
3002
 
2897
3003
  case ReceiveKind.SpotSend:
2898
3004
  case ReceiveKind.SpotRequest:
2899
3005
  case ReceiveKind.SpotMulticast:
2900
- return this.admission.run(meshName, 'RouteMesh Spot dispatch', () =>
2901
- this.dispatchMeshSpotRecord(meshName, owner, record)
3006
+ return this.dispatchMeshSpotRecord(meshName, owner, record, (dispatch, onRejected) =>
3007
+ this.admitMeshDispatch(meshName, record, 'RouteMesh Spot dispatch', dispatch, onRejected)
2902
3008
  );
2903
3009
  case ReceiveKind.InstanceSpotActivation:
2904
3010
  if (this.spotManager === undefined) {
@@ -2906,8 +3012,18 @@ export class ZLinkFrameworkRuntimeHost
2906
3012
  'MeshNode Instance Spot dispatch requires the Spot manager.'
2907
3013
  );
2908
3014
  }
2909
- return this.admission.run(meshName, 'RouteMesh Instance Spot dispatch', () =>
2910
- this.spotManager!.dispatchMeshInstance(meshName, owner, record)
3015
+ return this.spotManager.dispatchMeshInstance(
3016
+ meshName,
3017
+ owner,
3018
+ record,
3019
+ (dispatch, onRejected) =>
3020
+ this.admitMeshDispatch(
3021
+ meshName,
3022
+ record,
3023
+ 'RouteMesh Instance Spot dispatch',
3024
+ dispatch,
3025
+ onRejected
3026
+ )
2911
3027
  );
2912
3028
  case ReceiveKind.SpotControl:
2913
3029
  if (this.spotManager === undefined) {
@@ -2923,8 +3039,19 @@ export class ZLinkFrameworkRuntimeHost
2923
3039
  'MeshNode Actor dispatch requires the Spot manager.'
2924
3040
  );
2925
3041
  }
2926
- return this.admission.run(meshName, 'RouteMesh Actor dispatch', () =>
2927
- this.spotManager!.dispatchMeshActor(applicationJobOrigin(), meshName, owner, record)
3042
+ return this.spotManager.dispatchMeshActor(
3043
+ applicationJobOrigin(),
3044
+ meshName,
3045
+ owner,
3046
+ record,
3047
+ (dispatch, onRejected) =>
3048
+ this.admitMeshDispatch(
3049
+ meshName,
3050
+ record,
3051
+ 'RouteMesh Actor dispatch',
3052
+ dispatch,
3053
+ onRejected
3054
+ )
2928
3055
  );
2929
3056
  case ReceiveKind.SendReady:
2930
3057
  return Promise.resolve();
@@ -2935,6 +3062,39 @@ export class ZLinkFrameworkRuntimeHost
2935
3062
  }
2936
3063
  }
2937
3064
 
3065
+ private admitMeshDispatch(
3066
+ meshName: string,
3067
+ record: ReceiveRecord,
3068
+ operation: string,
3069
+ dispatch: () => void | Promise<void>,
3070
+ onRejected?: (error: unknown) => void | Promise<void>
3071
+ ): void | Promise<void> {
3072
+ // Execution gate §13 and host relocation §14 keep control progress independent
3073
+ // of new application admission. Disconnect callbacks still use their owner gate.
3074
+ if (record.domain === ReadyDomain.Infrastructure) return dispatch();
3075
+ if (
3076
+ !this.admission.accepts(meshName) &&
3077
+ (record.kind === ReceiveKind.NodeSend ||
3078
+ record.kind === ReceiveKind.NodeRequest ||
3079
+ record.kind === ReceiveKind.SpotSend ||
3080
+ record.kind === ReceiveKind.SpotRequest)
3081
+ ) {
3082
+ const relay = decodeRemoteActorPacketRelay(
3083
+ record.parts,
3084
+ { serializers: this.options.registration.messageSerializers },
3085
+ this.flowCreationEnabled()
3086
+ );
3087
+ if (
3088
+ relay !== undefined &&
3089
+ decodeStreamHeader(Buffer.from(relay.header, 'base64'), this.flowCreationEnabled()).name ===
3090
+ ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET
3091
+ ) {
3092
+ return dispatch();
3093
+ }
3094
+ }
3095
+ return this.admission.run(meshName, operation, dispatch, onRejected);
3096
+ }
3097
+
2938
3098
  private async dispatchMeshActorBinding(
2939
3099
  meshName: string,
2940
3100
  record: ReceiveRecord,
@@ -2958,7 +3118,8 @@ export class ZLinkFrameworkRuntimeHost
2958
3118
  };
2959
3119
  const replyBindingSuccess = (): void => {
2960
3120
  if (record.reply(Buffer.alloc(0)) !== SubmitResult.Ok) {
2961
- throw new ZLinkConfigurationException(
3121
+ throw createInternalFrameworkException(
3122
+ ZLinkFrameworkInternalErrorKind.ActorLocationStale,
2962
3123
  `MeshNode Actor binding target '${binding.actor.actorId}' acknowledgement failed.`
2963
3124
  );
2964
3125
  }
@@ -3023,7 +3184,8 @@ export class ZLinkFrameworkRuntimeHost
3023
3184
  replyBindingFailure(ZLinkFrameworkInternalErrorKind.ActorLocationStale);
3024
3185
  return;
3025
3186
  }
3026
- const installed = state.installBoundSessionBinding({
3187
+ replyBindingSuccess();
3188
+ state.installBoundSessionBinding({
3027
3189
  ...target,
3028
3190
  sessionNodeRid: binding.sessionNodeRid,
3029
3191
  sessionRid: binding.sessionRid,
@@ -3032,11 +3194,6 @@ export class ZLinkFrameworkRuntimeHost
3032
3194
  sessionOwnerLeaseGeneration: binding.sessionOwnerLeaseGeneration,
3033
3195
  bindingGeneration: binding.bindingGeneration
3034
3196
  });
3035
- if (!installed) {
3036
- replyBindingFailure(ZLinkFrameworkInternalErrorKind.ActorLocationStale);
3037
- return;
3038
- }
3039
- replyBindingSuccess();
3040
3197
  return Promise.resolve();
3041
3198
  }
3042
3199
 
@@ -3097,7 +3254,8 @@ export class ZLinkFrameworkRuntimeHost
3097
3254
  private async dispatchMeshSpotRecord(
3098
3255
  meshName: string,
3099
3256
  owner: ReadyRecord,
3100
- record: ReceiveRecord
3257
+ record: ReceiveRecord,
3258
+ admit?: ZLinkMeshDispatchAdmission
3101
3259
  ): Promise<void> {
3102
3260
  const envelope = decodeChannelEnvelope(record.parts, undefined, this.flowCreationEnabled());
3103
3261
  if (envelope.packetName === ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET) {
@@ -3113,33 +3271,32 @@ export class ZLinkFrameworkRuntimeHost
3113
3271
  correlationId: envelope.header.correlationId ?? undefined
3114
3272
  };
3115
3273
  try {
3116
- const response = await this.boundSessionRelay.actorPackets.receiveRemoteActorPacketRelay(
3117
- payload,
3118
- context
3119
- );
3120
- if (record.kind === ReceiveKind.SpotRequest) {
3121
- record.reply(encodeChannelReplyParts(envelope.header, response));
3122
- }
3274
+ const dispatch = async () => {
3275
+ const response = await this.boundSessionRelay.actorPackets.receiveRemoteActorPacketRelay(
3276
+ payload,
3277
+ context
3278
+ );
3279
+ if (record.kind === ReceiveKind.SpotRequest)
3280
+ record.reply(encodeChannelReplyParts(envelope.header, response));
3281
+ };
3282
+ await (admit === undefined ? dispatch() : admit(dispatch));
3123
3283
  } catch (error) {
3124
3284
  if (record.kind !== ReceiveKind.SpotRequest) {
3125
3285
  throw error;
3126
3286
  }
3127
- record.reply(
3128
- encodeChannelErrorReplyParts(
3129
- envelope.header,
3130
- error instanceof Error ? error.message : String(error)
3131
- )
3132
- );
3287
+ record.reply(encodeChannelErrorReplyParts(envelope.header, error));
3133
3288
  }
3134
3289
  return;
3135
3290
  }
3136
- if ((await this.spotNodeRuntime?.dispatchEntrySpotRecord(meshName, owner, record)) === true) {
3291
+ if (
3292
+ (await this.spotNodeRuntime?.dispatchEntrySpotRecord(meshName, owner, record, admit)) === true
3293
+ ) {
3137
3294
  return;
3138
3295
  }
3139
3296
  if (this.spotManager === undefined) {
3140
3297
  throw new ZLinkConfigurationException('MeshNode Spot dispatch requires the Spot manager.');
3141
3298
  }
3142
- await this.spotManager.dispatchMeshSpot(meshName, owner, record);
3299
+ await this.spotManager.dispatchMeshSpot(meshName, owner, record, admit);
3143
3300
  }
3144
3301
 
3145
3302
  private createDispatchErrorReporter(
@@ -3189,7 +3346,7 @@ export class ZLinkFrameworkRuntimeHost
3189
3346
  this.executionState === undefined
3190
3347
  ? (this.options.registration.dispatch?.diagnostics.messageFlow ?? 'errors')
3191
3348
  : this.messageFlowModeCell.mode;
3192
- return mode !== 'off';
3349
+ return messageFlowTracingEnabled(mode);
3193
3350
  }
3194
3351
 
3195
3352
  private runLifecycle<T>(operation: () => T): T {
@@ -3317,7 +3474,7 @@ export function hasExactPeerReadiness(
3317
3474
  const replacementDescriptors = descriptors.filter(
3318
3475
  (descriptor) =>
3319
3476
  !(
3320
- String(descriptor.rid) === String(local.routingId) &&
3477
+ routingIdsEqual(descriptor.rid, toBackendRoutingId(local.routingId)) &&
3321
3478
  descriptor.lifecycleGeneration === local.lifecycleGeneration
3322
3479
  ) &&
3323
3480
  descriptor.state === ZLinkFrameworkRuntimeState.Serving &&
@@ -3332,7 +3489,7 @@ export function hasExactPeerReadiness(
3332
3489
  peers.some(
3333
3490
  (peer) =>
3334
3491
  peer.routingId !== null &&
3335
- String(peer.routingId) === String(descriptor.rid) &&
3492
+ routingIdsEqual(toBackendRoutingId(peer.routingId), descriptor.rid) &&
3336
3493
  peer.lifecycleGeneration === descriptor.lifecycleGeneration &&
3337
3494
  peer.state === MeshPeerRuntimeState.Serving
3338
3495
  )
@@ -3544,7 +3701,7 @@ function isPlacementTargetReady(
3544
3701
  if (node === undefined) return true;
3545
3702
  if (
3546
3703
  localStatus !== undefined &&
3547
- String(localStatus.routingId) === String(descriptor.rid) &&
3704
+ routingIdsEqual(localStatus.routingId, descriptor.rid) &&
3548
3705
  localStatus.lifecycleGeneration === descriptor.lifecycleGeneration
3549
3706
  ) {
3550
3707
  return true;