@zlink-systems/framework 0.30.3 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Actors/ZLinkActor.d.ts +2 -0
  3. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.d.ts +6 -0
  4. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.js +2 -0
  5. package/dist/contracts/Actors/index.d.ts +1 -0
  6. package/dist/contracts/Actors/index.js +1 -0
  7. package/dist/contracts/Common/CoreTypes.d.ts +1 -0
  8. package/dist/contracts/Common/HandlerMessageType.d.ts +8 -0
  9. package/dist/contracts/Common/HandlerMessageType.js +41 -0
  10. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +1 -1
  11. package/dist/contracts/Common/ZLinkEncodedPayload.js +12 -20
  12. package/dist/contracts/Common/ZLinkMessage.js +11 -7
  13. package/dist/contracts/Common/encoded-payload-storage.d.ts +0 -2
  14. package/dist/contracts/Common/encoded-payload-storage.js +4 -16
  15. package/dist/contracts/Common/index.d.ts +1 -1
  16. package/dist/contracts/Common/payload-slab.d.ts +4 -0
  17. package/dist/contracts/Common/payload-slab.js +30 -0
  18. package/dist/contracts/Configuration/RegistrationBuilders.js +15 -9
  19. package/dist/contracts/Configuration/RegistrationTypes.d.ts +19 -0
  20. package/dist/contracts/Handlers/Contexts.d.ts +1 -0
  21. package/dist/contracts/Locations/Authority.d.ts +2 -0
  22. package/dist/internal.d.ts +9 -0
  23. package/dist/internal.js +23 -1
  24. package/dist/nest-integration.d.ts +1 -0
  25. package/dist/nest-integration.js +3 -1
  26. package/dist/runtime/actors/actor-client.d.ts +6 -2
  27. package/dist/runtime/actors/actor-client.js +120 -82
  28. package/dist/runtime/actors/actor-context.js +16 -5
  29. package/dist/runtime/actors/actor-execution-context.js +2 -2
  30. package/dist/runtime/actors/actor-handoff.d.ts +12 -1
  31. package/dist/runtime/actors/actor-handoff.js +79 -34
  32. package/dist/runtime/actors/actor-join-deferred-scope.js +6 -6
  33. package/dist/runtime/actors/actor-local-native-join.d.ts +2 -2
  34. package/dist/runtime/actors/actor-local-native-join.js +19 -17
  35. package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
  36. package/dist/runtime/actors/actor-remote-joiner.d.ts +2 -2
  37. package/dist/runtime/actors/actor-remote-joiner.js +4 -4
  38. package/dist/runtime/actors/actor-routed-join-transport.d.ts +9 -3
  39. package/dist/runtime/actors/actor-routed-json-request.d.ts +3 -0
  40. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -2
  41. package/dist/runtime/actors/actor-runtime-state.d.ts +1 -1
  42. package/dist/runtime/actors/spot-actor-dispatch.d.ts +9 -5
  43. package/dist/runtime/actors/spot-actor-dispatch.js +60 -38
  44. package/dist/runtime/admission.d.ts +6 -4
  45. package/dist/runtime/admission.js +21 -10
  46. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
  47. package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
  48. package/dist/runtime/backend/contracts/index.d.ts +26 -10
  49. package/dist/runtime/backend/mesh-completion-table.d.ts +7 -1
  50. package/dist/runtime/backend/mesh-completion-table.js +84 -20
  51. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +19 -6
  52. package/dist/runtime/backend/mesh-dispatch-pump.js +246 -147
  53. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -2
  54. package/dist/runtime/backend/node/node-backend-adapter-support.js +27 -19
  55. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +5 -2
  56. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +70 -13
  57. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  58. package/dist/runtime/backend/node/node-event-loop-poller.js +4 -3
  59. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
  60. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
  61. package/dist/runtime/backend/node/node-raw-binding-port.js +99 -63
  62. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +34 -16
  63. package/dist/runtime/backend/node/node-raw-mesh-backend.js +210 -106
  64. package/dist/runtime/backend/node/node-socket-backend-adapter.js +20 -6
  65. package/dist/runtime/backend/raw-binding-port.d.ts +6 -3
  66. package/dist/runtime/channels/channel-clients.js +3 -3
  67. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +11 -7
  68. package/dist/runtime/channels/channel-dispatch-pipeline.js +40 -22
  69. package/dist/runtime/channels/channel-dispatch-services.d.ts +3 -1
  70. package/dist/runtime/channels/channel-dispatch-services.js +7 -6
  71. package/dist/runtime/channels/channel-dispatchers.d.ts +13 -6
  72. package/dist/runtime/channels/channel-dispatchers.js +57 -36
  73. package/dist/runtime/channels/channel-envelope.d.ts +2 -2
  74. package/dist/runtime/channels/channel-envelope.js +609 -83
  75. package/dist/runtime/channels/channel-multipart.d.ts +1 -0
  76. package/dist/runtime/channels/channel-multipart.js +10 -6
  77. package/dist/runtime/channels/channel-outbound-operations.d.ts +6 -9
  78. package/dist/runtime/channels/channel-outbound-operations.js +107 -105
  79. package/dist/runtime/channels/channel-receive-loops.d.ts +9 -7
  80. package/dist/runtime/channels/channel-receive-loops.js +126 -90
  81. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +23 -6
  82. package/dist/runtime/channels/channel-runtime-lifecycle.js +47 -38
  83. package/dist/runtime/channels/channel-runtime-manager.d.ts +13 -6
  84. package/dist/runtime/channels/channel-runtime-manager.js +32 -14
  85. package/dist/runtime/channels/channel-socket-registry.d.ts +28 -4
  86. package/dist/runtime/channels/channel-socket-registry.js +9 -1
  87. package/dist/runtime/channels/channel-transports.d.ts +23 -16
  88. package/dist/runtime/channels/channel-transports.js +139 -119
  89. package/dist/runtime/channels/dispatch-error-reporter.d.ts +4 -4
  90. package/dist/runtime/channels/dispatch-error-reporter.js +5 -5
  91. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  92. package/dist/runtime/channels/local-spot-route-transport.d.ts +5 -2
  93. package/dist/runtime/channels/local-spot-route-transport.js +15 -18
  94. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +6 -3
  95. package/dist/runtime/channels/router-socket-spot-route-transport.js +33 -19
  96. package/dist/runtime/channels/source-spot-router.d.ts +6 -3
  97. package/dist/runtime/channels/source-spot-router.js +34 -23
  98. package/dist/runtime/channels/spot-node-route-transport.d.ts +6 -3
  99. package/dist/runtime/channels/spot-node-route-transport.js +23 -17
  100. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +6 -3
  101. package/dist/runtime/channels/spot-route-bridge-transport.js +38 -24
  102. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +8 -4
  103. package/dist/runtime/channels/spot-route-dispatch-strategy.js +36 -23
  104. package/dist/runtime/diagnostics/dispatch-error-details.js +9 -3
  105. package/dist/runtime/diagnostics/message-flow-bootstrap.d.ts +1 -0
  106. package/dist/runtime/diagnostics/message-flow-bootstrap.js +8 -0
  107. package/dist/runtime/diagnostics/message-flow-delivery.d.ts +47 -0
  108. package/dist/runtime/diagnostics/message-flow-delivery.js +149 -0
  109. package/dist/runtime/diagnostics/message-flow-record.d.ts +50 -0
  110. package/dist/runtime/diagnostics/message-flow-record.js +228 -0
  111. package/dist/runtime/diagnostics/message-flow-worker.d.ts +1 -0
  112. package/dist/runtime/diagnostics/message-flow-worker.js +118 -0
  113. package/dist/runtime/diagnostics/message-flow.d.ts +7 -19
  114. package/dist/runtime/diagnostics/message-flow.js +42 -290
  115. package/dist/runtime/diagnostics/runtime-metrics.d.ts +4 -3
  116. package/dist/runtime/diagnostics/runtime-metrics.js +8 -4
  117. package/dist/runtime/execution/index.d.ts +1 -0
  118. package/dist/runtime/execution/index.js +6 -3
  119. package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
  120. package/dist/runtime/execution/serial-execution-queue.js +75 -71
  121. package/dist/runtime/foundation/durable-service-request.d.ts +12 -3
  122. package/dist/runtime/foundation/durable-service-request.js +158 -73
  123. package/dist/runtime/foundation/operation-registry.d.ts +33 -3
  124. package/dist/runtime/foundation/operation-registry.js +272 -33
  125. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +62 -23
  126. package/dist/runtime/foundation/raw-service-mesh-runtime.js +373 -194
  127. package/dist/runtime/foundation/request-runtime.d.ts +17 -0
  128. package/dist/runtime/foundation/request-runtime.js +163 -0
  129. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  130. package/dist/runtime/foundation/service-discovery-registry.js +6 -0
  131. package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
  132. package/dist/runtime/foundation/service-mailbox.d.ts +4 -2
  133. package/dist/runtime/foundation/service-mailbox.js +4 -1
  134. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -2
  135. package/dist/runtime/foundation/service-relocation-object-owner.js +12 -5
  136. package/dist/runtime/foundation/service-runtime-contracts.d.ts +7 -2
  137. package/dist/runtime/foundation/service-stateful-registry.d.ts +6 -2
  138. package/dist/runtime/foundation/service-stateful-registry.js +38 -17
  139. package/dist/runtime/foundation/service-stateful-runtime.d.ts +91 -26
  140. package/dist/runtime/foundation/service-stateful-runtime.js +245 -120
  141. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
  142. package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
  143. package/dist/runtime/foundation/service-topology-registry.d.ts +2 -0
  144. package/dist/runtime/foundation/service-topology-registry.js +13 -3
  145. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  146. package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
  147. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +5 -1
  148. package/dist/runtime/foundation/service-wire-m6a-codec.js +50 -15
  149. package/dist/runtime/host/actor-packet-relay.d.ts +5 -6
  150. package/dist/runtime/host/actor-packet-relay.js +58 -57
  151. package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
  152. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  153. package/dist/runtime/host/actor-runtime-options-factory.js +3 -2
  154. package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
  155. package/dist/runtime/host/application-job-queue.d.ts +7 -5
  156. package/dist/runtime/host/application-job-queue.js +33 -21
  157. package/dist/runtime/host/bound-session-relay.js +0 -1
  158. package/dist/runtime/host/channel-runtime-options-factory.d.ts +2 -0
  159. package/dist/runtime/host/channel-runtime-options-factory.js +1 -0
  160. package/dist/runtime/host/entry-actor-runtime.d.ts +5 -2
  161. package/dist/runtime/host/entry-actor-runtime.js +2 -2
  162. package/dist/runtime/host/index.d.ts +106 -37
  163. package/dist/runtime/host/index.js +303 -151
  164. package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
  165. package/dist/runtime/host/location-runtime-owner.js +1 -1
  166. package/dist/runtime/host/service-relocation-host-runtime.d.ts +195 -45
  167. package/dist/runtime/host/service-relocation-host-runtime.js +257 -144
  168. package/dist/runtime/host/spot-address-transport.d.ts +3 -0
  169. package/dist/runtime/host/spot-address-transport.js +73 -76
  170. package/dist/runtime/host/spot-runtime-options-factory.js +2 -0
  171. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -1
  172. package/dist/runtime/host/user-spot-creation-coordinator.js +49 -21
  173. package/dist/runtime/internal-observation.d.ts +1 -0
  174. package/dist/runtime/internal-observation.js +5 -0
  175. package/dist/runtime/locations/actor-location-claims.d.ts +1 -1
  176. package/dist/runtime/locations/actor-location-claims.js +15 -6
  177. package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
  178. package/dist/runtime/locations/auto-connect-loop.js +25 -19
  179. package/dist/runtime/locations/auto-connect-planner.js +2 -5
  180. package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
  181. package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
  182. package/dist/runtime/locations/in-memory-authority-store.d.ts +1 -0
  183. package/dist/runtime/locations/in-memory-authority-store.js +15 -5
  184. package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
  185. package/dist/runtime/locations/in-memory-location-store.js +1 -38
  186. package/dist/runtime/locations/lifecycle.d.ts +1 -1
  187. package/dist/runtime/locations/lifecycle.js +2 -2
  188. package/dist/runtime/locations/location-store-repository.d.ts +0 -1
  189. package/dist/runtime/locations/location-store-repository.js +163 -246
  190. package/dist/runtime/locations/resolvers.d.ts +8 -1
  191. package/dist/runtime/locations/resolvers.js +16 -2
  192. package/dist/runtime/locations/runtime.d.ts +3 -3
  193. package/dist/runtime/locations/runtime.js +12 -16
  194. package/dist/runtime/messaging/creation-payload-codec.js +8 -7
  195. package/dist/runtime/messaging/framework-json-v1.d.ts +1 -1
  196. package/dist/runtime/messaging/framework-json-v1.js +6 -2
  197. package/dist/runtime/messaging/payload-codec.js +21 -35
  198. package/dist/runtime/messaging/request-deadline.d.ts +4 -2
  199. package/dist/runtime/messaging/request-deadline.js +40 -25
  200. package/dist/runtime/messaging/request-result.d.ts +14 -1
  201. package/dist/runtime/messaging/request-result.js +74 -13
  202. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
  203. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
  204. package/dist/runtime/spots/index.d.ts +28 -7
  205. package/dist/runtime/spots/index.js +31 -6
  206. package/dist/runtime/spots/spot-activation-registry.d.ts +3 -2
  207. package/dist/runtime/spots/spot-activation-registry.js +13 -8
  208. package/dist/runtime/spots/spot-activation-state.d.ts +2 -0
  209. package/dist/runtime/spots/spot-activation-state.js +1 -0
  210. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +9 -4
  211. package/dist/runtime/spots/spot-actor-admission-coordinator.js +33 -12
  212. package/dist/runtime/spots/spot-actor-ingress-admission.d.ts +40 -0
  213. package/dist/runtime/spots/spot-actor-ingress-admission.js +78 -0
  214. package/dist/runtime/spots/spot-actor-membership.js +3 -3
  215. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +16 -43
  216. package/dist/runtime/spots/spot-actor-packet-dispatch.js +56 -113
  217. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
  218. package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
  219. package/dist/runtime/spots/spot-entry-activation.d.ts +4 -3
  220. package/dist/runtime/spots/spot-entry-activation.js +7 -12
  221. package/dist/runtime/spots/spot-handler-registry.d.ts +5 -1
  222. package/dist/runtime/spots/spot-handler-registry.js +31 -15
  223. package/dist/runtime/spots/spot-manager-public.js +3 -2
  224. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +11 -6
  225. package/dist/runtime/spots/spot-node-runtime-manager.js +6 -1
  226. package/dist/runtime/spots/spot-outbound.d.ts +8 -2
  227. package/dist/runtime/spots/spot-outbound.js +5 -5
  228. package/dist/runtime/spots/spot-route-packet-dispatch.js +13 -8
  229. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +3 -3
  230. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +9 -5
  231. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -2
  232. package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
  233. package/dist/runtime/spots/spot-serial-turn-executor.js +20 -26
  234. package/dist/runtime/spots/spot-subscription-dispatch.js +5 -2
  235. package/dist/runtime/spots/spot-timer.d.ts +1 -1
  236. package/dist/runtime/streams/actor-session-binding-registry.d.ts +11 -3
  237. package/dist/runtime/streams/actor-session-binding-registry.js +28 -0
  238. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
  239. package/dist/runtime/streams/bound-actor-relay-sender.js +3 -4
  240. package/dist/runtime/streams/bound-session-service.js +6 -7
  241. package/dist/runtime/streams/index.d.ts +3 -3
  242. package/dist/runtime/streams/index.js +22 -2
  243. package/dist/runtime/streams/managed-stream.js +2 -1
  244. package/dist/runtime/streams/session-calls.d.ts +1 -1
  245. package/dist/runtime/streams/session-calls.js +3 -9
  246. package/dist/runtime/streams/session-context.d.ts +2 -2
  247. package/dist/runtime/streams/session-context.js +2 -2
  248. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
  249. package/dist/runtime/streams/stream-session-runtime.js +64 -33
  250. package/package.json +3 -3
  251. package/src/contracts/Actors/ZLinkActor.ts +6 -0
  252. package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
  253. package/src/contracts/Actors/index.ts +1 -0
  254. package/src/contracts/Common/CoreTypes.ts +1 -0
  255. package/src/contracts/Common/HandlerMessageType.ts +50 -0
  256. package/src/contracts/Common/ZLinkEncodedPayload.ts +13 -25
  257. package/src/contracts/Common/ZLinkMessage.ts +11 -7
  258. package/src/contracts/Common/encoded-payload-storage.ts +4 -16
  259. package/src/contracts/Common/index.ts +1 -1
  260. package/src/contracts/Common/payload-slab.ts +29 -0
  261. package/src/contracts/Configuration/RegistrationBuilders.ts +29 -15
  262. package/src/contracts/Configuration/RegistrationTypes.ts +19 -0
  263. package/src/contracts/Handlers/Contexts.ts +1 -0
  264. package/src/contracts/Locations/Authority.ts +7 -1
  265. package/src/internal.ts +17 -0
  266. package/src/nest-integration.ts +1 -0
  267. package/src/runtime/actors/actor-client.ts +257 -163
  268. package/src/runtime/actors/actor-context.ts +26 -14
  269. package/src/runtime/actors/actor-execution-context.ts +2 -2
  270. package/src/runtime/actors/actor-handoff.ts +86 -51
  271. package/src/runtime/actors/actor-join-deferred-scope.ts +6 -6
  272. package/src/runtime/actors/actor-local-native-join.ts +38 -17
  273. package/src/runtime/actors/actor-mailbox.ts +1 -1
  274. package/src/runtime/actors/actor-remote-joiner.ts +8 -4
  275. package/src/runtime/actors/actor-routed-join-transport.ts +13 -5
  276. package/src/runtime/actors/actor-routed-json-request.ts +3 -0
  277. package/src/runtime/actors/actor-runtime-contracts.ts +4 -2
  278. package/src/runtime/actors/actor-runtime-state.ts +1 -1
  279. package/src/runtime/actors/spot-actor-dispatch.ts +70 -68
  280. package/src/runtime/admission.ts +42 -15
  281. package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
  282. package/src/runtime/backend/contracts/index.ts +77 -10
  283. package/src/runtime/backend/mesh-completion-table.ts +106 -15
  284. package/src/runtime/backend/mesh-dispatch-pump.ts +294 -146
  285. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -32
  286. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +91 -34
  287. package/src/runtime/backend/node/node-event-loop-poller.ts +14 -5
  288. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
  289. package/src/runtime/backend/node/node-raw-binding-port.ts +180 -69
  290. package/src/runtime/backend/node/node-raw-mesh-backend.ts +386 -157
  291. package/src/runtime/backend/node/node-socket-backend-adapter.ts +56 -11
  292. package/src/runtime/backend/raw-binding-port.ts +13 -5
  293. package/src/runtime/channels/channel-clients.ts +26 -11
  294. package/src/runtime/channels/channel-dispatch-pipeline.ts +77 -65
  295. package/src/runtime/channels/channel-dispatch-services.ts +7 -12
  296. package/src/runtime/channels/channel-dispatchers.ts +93 -39
  297. package/src/runtime/channels/channel-envelope.ts +680 -144
  298. package/src/runtime/channels/channel-multipart.ts +17 -13
  299. package/src/runtime/channels/channel-outbound-operations.ts +204 -178
  300. package/src/runtime/channels/channel-receive-loops.ts +160 -107
  301. package/src/runtime/channels/channel-runtime-lifecycle.ts +64 -59
  302. package/src/runtime/channels/channel-runtime-manager.ts +74 -27
  303. package/src/runtime/channels/channel-socket-registry.ts +20 -5
  304. package/src/runtime/channels/channel-transports.ts +414 -287
  305. package/src/runtime/channels/dispatch-error-reporter.ts +4 -9
  306. package/src/runtime/channels/local-spot-route-transport.ts +27 -29
  307. package/src/runtime/channels/router-socket-spot-route-transport.ts +63 -32
  308. package/src/runtime/channels/source-spot-router.ts +75 -38
  309. package/src/runtime/channels/spot-node-route-transport.ts +67 -37
  310. package/src/runtime/channels/spot-route-bridge-transport.ts +62 -30
  311. package/src/runtime/channels/spot-route-dispatch-strategy.ts +105 -34
  312. package/src/runtime/diagnostics/dispatch-error-details.ts +10 -2
  313. package/src/runtime/diagnostics/message-flow-bootstrap.ts +6 -0
  314. package/src/runtime/diagnostics/message-flow-delivery.ts +171 -0
  315. package/src/runtime/diagnostics/message-flow-record.ts +295 -0
  316. package/src/runtime/diagnostics/message-flow-worker.ts +146 -0
  317. package/src/runtime/diagnostics/message-flow.ts +49 -362
  318. package/src/runtime/diagnostics/runtime-metrics.ts +10 -4
  319. package/src/runtime/execution/index.ts +6 -0
  320. package/src/runtime/execution/serial-execution-queue.ts +94 -96
  321. package/src/runtime/foundation/durable-service-request.ts +212 -89
  322. package/src/runtime/foundation/operation-registry.ts +287 -38
  323. package/src/runtime/foundation/raw-service-mesh-runtime.ts +617 -292
  324. package/src/runtime/foundation/request-runtime.ts +227 -0
  325. package/src/runtime/foundation/service-discovery-registry.ts +7 -0
  326. package/src/runtime/foundation/service-liveness-registry.ts +1 -1
  327. package/src/runtime/foundation/service-mailbox.ts +7 -2
  328. package/src/runtime/foundation/service-relocation-object-owner.ts +21 -6
  329. package/src/runtime/foundation/service-runtime-contracts.ts +12 -2
  330. package/src/runtime/foundation/service-stateful-registry.ts +52 -19
  331. package/src/runtime/foundation/service-stateful-runtime.ts +365 -198
  332. package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
  333. package/src/runtime/foundation/service-topology-registry.ts +21 -3
  334. package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
  335. package/src/runtime/foundation/service-wire-m6a-codec.ts +69 -17
  336. package/src/runtime/host/actor-packet-relay.ts +160 -156
  337. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  338. package/src/runtime/host/actor-runtime-options-factory.ts +7 -2
  339. package/src/runtime/host/actor-transfer-runtime.ts +3 -3
  340. package/src/runtime/host/application-job-queue.ts +56 -27
  341. package/src/runtime/host/bound-session-relay.ts +0 -1
  342. package/src/runtime/host/channel-runtime-options-factory.ts +3 -0
  343. package/src/runtime/host/entry-actor-runtime.ts +14 -6
  344. package/src/runtime/host/index.ts +388 -113
  345. package/src/runtime/host/location-runtime-owner.ts +3 -3
  346. package/src/runtime/host/service-relocation-host-runtime.ts +380 -252
  347. package/src/runtime/host/spot-address-transport.ts +110 -95
  348. package/src/runtime/host/spot-runtime-options-factory.ts +3 -0
  349. package/src/runtime/host/user-spot-creation-coordinator.ts +69 -22
  350. package/src/runtime/internal-observation.ts +2 -0
  351. package/src/runtime/locations/actor-location-claims.ts +42 -16
  352. package/src/runtime/locations/auto-connect-loop.ts +24 -16
  353. package/src/runtime/locations/auto-connect-planner.ts +2 -5
  354. package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
  355. package/src/runtime/locations/in-memory-authority-store.ts +27 -7
  356. package/src/runtime/locations/in-memory-location-store.ts +1 -74
  357. package/src/runtime/locations/lifecycle.ts +4 -2
  358. package/src/runtime/locations/location-store-repository.ts +228 -308
  359. package/src/runtime/locations/resolvers.ts +20 -8
  360. package/src/runtime/locations/runtime.ts +16 -28
  361. package/src/runtime/messaging/creation-payload-codec.ts +12 -10
  362. package/src/runtime/messaging/framework-json-v1.ts +10 -1
  363. package/src/runtime/messaging/payload-codec.ts +50 -75
  364. package/src/runtime/messaging/request-deadline.ts +47 -39
  365. package/src/runtime/messaging/request-result.ts +88 -17
  366. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  367. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  368. package/src/runtime/spots/index.ts +57 -10
  369. package/src/runtime/spots/spot-activation-registry.ts +12 -8
  370. package/src/runtime/spots/spot-activation-state.ts +2 -0
  371. package/src/runtime/spots/spot-actor-admission-coordinator.ts +62 -37
  372. package/src/runtime/spots/spot-actor-ingress-admission.ts +157 -0
  373. package/src/runtime/spots/spot-actor-membership.ts +8 -5
  374. package/src/runtime/spots/spot-actor-packet-dispatch.ts +122 -206
  375. package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
  376. package/src/runtime/spots/spot-entry-activation.ts +25 -35
  377. package/src/runtime/spots/spot-handler-registry.ts +72 -15
  378. package/src/runtime/spots/spot-manager-public.ts +4 -2
  379. package/src/runtime/spots/spot-node-runtime-manager.ts +16 -7
  380. package/src/runtime/spots/spot-outbound.ts +26 -10
  381. package/src/runtime/spots/spot-route-packet-dispatch.ts +18 -8
  382. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +14 -8
  383. package/src/runtime/spots/spot-runtime-ports.ts +5 -2
  384. package/src/runtime/spots/spot-serial-executor.ts +1 -1
  385. package/src/runtime/spots/spot-serial-turn-executor.ts +25 -40
  386. package/src/runtime/spots/spot-subscription-dispatch.ts +9 -2
  387. package/src/runtime/spots/spot-timer.ts +1 -1
  388. package/src/runtime/streams/actor-session-binding-registry.ts +46 -3
  389. package/src/runtime/streams/bound-actor-relay-sender.ts +16 -5
  390. package/src/runtime/streams/bound-session-service.ts +10 -7
  391. package/src/runtime/streams/index.ts +30 -4
  392. package/src/runtime/streams/managed-stream.ts +2 -1
  393. package/src/runtime/streams/session-calls.ts +9 -14
  394. package/src/runtime/streams/session-context.ts +6 -11
  395. package/src/runtime/streams/stream-session-runtime.ts +79 -40
  396. package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +0 -8
  397. package/dist/runtime/spots/spot-lifecycle-metrics.js +0 -17
  398. package/src/runtime/spots/spot-lifecycle-metrics.ts +0 -16
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkUserSpotCreationCoordinator = exports.ZLinkHostSpotAddressTransport = exports.ZLinkRelocationStateIncompatibleError = exports.ZLinkRouteMeshRuntimeCoordinator = exports.ZLinkRetiringRollbackError = exports.ZLinkDrainingStatePublishError = exports.transferIdString = exports.ZLinkActorTransferAuthorityRuntime = exports.ZLinkFrameworkRuntimeHost = void 0;
4
4
  exports.hasUnsupportedManualTopology = hasUnsupportedManualTopology;
5
5
  exports.hasExactPeerReadiness = hasExactPeerReadiness;
6
+ const contracts_1 = require("../../contracts");
7
+ const request_runtime_1 = require("../foundation/request-runtime");
8
+ const internal_observation_1 = require("../internal-observation");
6
9
  const relocation_blob_1 = require("../locations/relocation-blob");
7
10
  const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
8
11
  const location_store_pages_1 = require("../locations/location-store-pages");
@@ -10,7 +13,7 @@ const descriptor_publication_1 = require("../locations/descriptor-publication");
10
13
  const stream_wire_1 = require("@zlink-systems/stream-wire");
11
14
  const node_crypto_1 = require("node:crypto");
12
15
  const node_util_1 = require("node:util");
13
- const contracts_1 = require("../../contracts");
16
+ const contracts_2 = require("../../contracts");
14
17
  const ConfigurationException_1 = require("../../contracts/Configuration/ConfigurationException");
15
18
  const DiagnosticsValidation_1 = require("../../contracts/Configuration/DiagnosticsValidation");
16
19
  const InternalDefaults_1 = require("../../contracts/Configuration/InternalDefaults");
@@ -35,6 +38,7 @@ const channel_envelope_1 = require("../channels/channel-envelope");
35
38
  const diagnostics_1 = require("../diagnostics");
36
39
  const runtime_metrics_1 = require("../diagnostics/runtime-metrics");
37
40
  const runtime_observation_queue_1 = require("../diagnostics/runtime-observation-queue");
41
+ const message_flow_delivery_1 = require("../diagnostics/message-flow-delivery");
38
42
  const topology_runtime_projections_1 = require("../diagnostics/topology-runtime-projections");
39
43
  const execution_1 = require("../execution");
40
44
  const listener_records_1 = require("../foundation/listener-records");
@@ -79,10 +83,26 @@ const HANDOFF_ACCEPTANCE_POLL_INTERVAL_MS = 10;
79
83
  const DEFAULT_HOST_CONTROL_TIMEOUT_MS = 30_000;
80
84
  class ZLinkFrameworkRuntimeHost {
81
85
  options;
86
+ [internal_observation_1.inspectRuntime]() {
87
+ return Object.freeze({
88
+ ownerLeaseUsable: this.locationOwner.currentRuntime?.ownerLeaseUsable,
89
+ ownerId: this.locationOwner.currentRuntime?.ownerId,
90
+ hasOwnerToken: this.locationOwner.currentRuntime?.currentOwnerToken !== undefined,
91
+ ownerAdmissionOpen: this.admission.ownerAdmissionOpen(),
92
+ channelRuntimeStarted: this.channelRuntime !== undefined,
93
+ fanoutStoreIsLocationStore: this.locationOwner.currentStores?.fanoutStore ===
94
+ this.locationOwner.currentStores?.locationStore,
95
+ fanoutStoreMethods: Object.freeze({
96
+ update: typeof this.locationOwner.currentStores?.fanoutStore?.updateFanoutPublisher,
97
+ remove: typeof this.locationOwner.currentStores?.fanoutStore?.removeFanoutPublisher,
98
+ list: typeof this.locationOwner.currentStores?.fanoutStore?.listFanoutPublishers
99
+ })
100
+ });
101
+ }
82
102
  backendAdapterFactory;
83
103
  lifecycleSink;
84
104
  executionState;
85
- runtimeState = contracts_1.ZLinkFrameworkRuntimeState.Preparing;
105
+ runtimeState = contracts_2.ZLinkFrameworkRuntimeState.Preparing;
86
106
  runtimeStatus;
87
107
  runtimeObservationSource = Symbol('zlink.framework-runtime');
88
108
  runtimeDeadline;
@@ -123,7 +143,7 @@ class ZLinkFrameworkRuntimeHost {
123
143
  applicationJobQueue;
124
144
  capacityStatus;
125
145
  metricRegistrations = [];
126
- admission = new admission_1.ZLinkRuntimeAdmissionGate(() => this.ownerAdmissionOpen());
146
+ admission;
127
147
  activationAdmission = new activation_admission_1.ZLinkActivationAdmission((meshName) => this.options.registration.spotNodes.get(meshName)?.activationConcurrencyLimit ??
128
148
  InternalDefaults_1.DEFAULT_ACTIVATION_CONCURRENCY_LIMIT);
129
149
  cachedLocationSpotRouteResolver;
@@ -133,6 +153,7 @@ class ZLinkFrameworkRuntimeHost {
133
153
  messageFlowModeCell = {
134
154
  mode: 'errors'
135
155
  };
156
+ telemetryLease = (0, message_flow_delivery_1.openTelemetryLease)();
136
157
  dispatchErrorReporters = new WeakMap();
137
158
  runtimeOrPreStartErrorSink = {
138
159
  reportRuntimeTaskException: (taskName, error) => (this.errorSink ?? this.preStartErrorSink).reportRuntimeTaskException(taskName, error)
@@ -142,6 +163,7 @@ class ZLinkFrameworkRuntimeHost {
142
163
  channelTransport = () => this.channelRuntime;
143
164
  channelRuntimeOptions = new channels_1.DefaultZLinkChannelRuntimeOptions(() => this.channelRuntime);
144
165
  routeMeshRuntimeOptions = new route_mesh_runtime_options_1.DefaultZLinkRouteMeshRuntimeOptions(() => this.spotNodeRuntime);
166
+ requests = new request_runtime_1.RequestRuntime();
145
167
  routeTransport;
146
168
  spotAddressTransport;
147
169
  spotPublisherTransport = new spots_1.ZLinkRuntimeSpotPublisherTransport(() => this.spotNodeRuntime);
@@ -155,6 +177,9 @@ class ZLinkFrameworkRuntimeHost {
155
177
  routeMeshCoordinator;
156
178
  constructor(options, internalOptions) {
157
179
  this.options = options;
180
+ const factories = internalOptions;
181
+ this.spotNodeRuntime = factories?.spotNodeRuntime;
182
+ this.admission = (factories?.createAdmissionGate ?? ((ownerOpen) => new admission_1.ZLinkRuntimeAdmissionGate(ownerOpen)))(() => this.ownerAdmissionOpen());
158
183
  this.backendAdapterFactory = resolveBackendAdapterFactory(internalOptions);
159
184
  this.lifecycleSink = options.lifecycleSink;
160
185
  this.runtimeEventPublisher =
@@ -172,8 +197,15 @@ class ZLinkFrameworkRuntimeHost {
172
197
  this.fanoutRuntime = new topology_runtime_projections_1.ZLinkFanoutRuntimeProjection(() => this.channelRuntime, () => this.runtimeState);
173
198
  this.meshRouters = new mesh_router_resolver_1.MeshRouterResolver(options.registration);
174
199
  this.spotRouterChannelIdForMesh = this.meshRouters.spotRouterChannelIdByMesh();
175
- this.routeTransport = new channels_1.ZLinkRuntimeRouteTransport(() => this.channelRuntime, (routerChannelId) => this.meshRouters.canUseRouterChannel(routerChannelId), () => this.spotNodeRuntime, { serializers: options.registration.messageSerializers }, (meshName, targetNodeRid) => this.meshRouters.classifyManualNodeTarget(meshName, targetNodeRid), (meshName, sourceNodeRid, parts) => this.submitLocalMeshRoute(meshName, sourceNodeRid, parts), this.metrics, () => this.flowCreationEnabled(), () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow);
200
+ this.routeTransport = new channels_1.ZLinkRuntimeRouteTransport(() => {
201
+ if (this.channelRuntime === undefined &&
202
+ this.runtimeState === contracts_2.ZLinkFrameworkRuntimeState.Stopped) {
203
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RuntimeShutdown, 'Route channel runtime is stopped.');
204
+ }
205
+ return this.channelRuntime;
206
+ }, (routerChannelId) => this.meshRouters.canUseRouterChannel(routerChannelId), () => this.spotNodeRuntime, { serializers: options.registration.messageSerializers }, (meshName, targetNodeRid) => this.meshRouters.classifyManualNodeTarget(meshName, targetNodeRid), (meshName, sourceNodeRid, parts) => this.submitLocalMeshRoute(meshName, sourceNodeRid, parts), this.metrics, () => this.flowCreationEnabled(), () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow, this.requests);
176
207
  this.spotAddressTransport = new spot_address_transport_1.ZLinkHostSpotAddressTransport({
208
+ requests: this.requests,
177
209
  resolver: () => this.createLocationSpotRouteResolver(),
178
210
  routed: this.routeTransport,
179
211
  meshNames: () => [...this.options.registration.spotNodes]
@@ -225,9 +257,10 @@ class ZLinkFrameworkRuntimeHost {
225
257
  : this.boundSessionRelay.actorPackets.confirmRemoteSessionBinding(actor, sessionNode.status().routingId, sessionRid, signal, options);
226
258
  },
227
259
  relay: (actor, header, payload) => this.boundSessionRelay.actorPackets.relayActorPacket(actor, header, payload),
228
- notifyDisconnected: (actor, signal, binding) => this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal, binding)
260
+ notifyDisconnected: (actor, signal, binding, authorityFence) => this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal, binding, authorityFence)
229
261
  });
230
262
  this.actorHandoff = new actors_1.ZLinkActorHandoffCoordinator({
263
+ requests: this.requests,
231
264
  routedTransport: this.routeTransport,
232
265
  messageFollowDurationMs: options.registration.locations.options.messageFollowDurationMs,
233
266
  requestTimeoutMs: options.registration.requestTimeoutMs,
@@ -385,7 +418,9 @@ class ZLinkFrameworkRuntimeHost {
385
418
  });
386
419
  this.actorTransferRegistry = new actors_1.ZLinkActorTransferRegistry(options.registration.spotNodes, options.providerResolver, options.registration.messageSerializers);
387
420
  this.boundSessionFactory = new streams_1.DefaultZLinkBoundSessionFactory(this.streamBindingRuntime);
388
- this.boundSessionRelay = new bound_session_relay_1.ZLinkBoundSessionRelay({
421
+ const createBoundSessionRelay = factories?.createBoundSessionRelay ??
422
+ ((relayOptions) => new bound_session_relay_1.ZLinkBoundSessionRelay(relayOptions));
423
+ this.boundSessionRelay = createBoundSessionRelay({
389
424
  requestTimeoutMs: options.registration.requestTimeoutMs,
390
425
  sessionRelocationSealTimeoutMs: options.registration.locations.options.sessionRelocationSealTimeoutMs ??
391
426
  Locations_1.zlinkDefaultLocationOptions.sessionRelocationSealTimeoutMs,
@@ -500,6 +535,7 @@ class ZLinkFrameworkRuntimeHost {
500
535
  shutdownSignal: () => this.executionState?.abortController.signal
501
536
  });
502
537
  this.serviceRelocation = new service_relocation_host_runtime_1.ZLinkHostServiceRelocationRuntime({
538
+ requests: this.requests,
503
539
  flowCreationEnabled: () => this.flowCreationEnabled(),
504
540
  messageFlow: () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow,
505
541
  registration: options.registration,
@@ -523,7 +559,7 @@ class ZLinkFrameworkRuntimeHost {
523
559
  clear: () => this.boundSessionRelay.boundSessions.clearServiceWireSessionRelocations()
524
560
  },
525
561
  trackInstanceSpot: (input) => this.locationOwner.currentLifecycle?.trackInstanceSpot(input),
526
- invalidateActorRoute: (actorId) => this.actorClientLocationResolver?.invalidateActorRoute(actorId),
562
+ observeActorAuthorityVersion: (actorId, storeVersion) => this.actorClientLocationResolver?.observeActorAuthorityVersion(actorId, storeVersion),
527
563
  reconcileStatefulAuthorityRoutes: (signal) => this.statefulAuthorityRoutes?.reconcile(signal) ?? Promise.resolve(),
528
564
  runtimeEventPublisher: this.runtimeEventPublisher,
529
565
  metrics: this.metrics,
@@ -537,7 +573,8 @@ class ZLinkFrameworkRuntimeHost {
537
573
  ...options.registration.locations.options
538
574
  }.ownerLeaseTtlMs
539
575
  });
540
- this.routeMeshCoordinator = new route_mesh_runtime_1.ZLinkRouteMeshRuntimeCoordinator({
576
+ this.routeMeshCoordinator = (factories?.createRouteMeshCoordinator ??
577
+ ((meshOptions) => new route_mesh_runtime_1.ZLinkRouteMeshRuntimeCoordinator(meshOptions)))({
541
578
  meshNames: [...options.registration.spotNodes.keys()],
542
579
  meshOptions: options.registration.spotNodes,
543
580
  meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
@@ -624,15 +661,15 @@ class ZLinkFrameworkRuntimeHost {
624
661
  if (!Number.isFinite(deadlineMs) || deadlineMs <= 0) {
625
662
  return Promise.reject(new RangeError('Relocation deadlineMs must be greater than zero.'));
626
663
  }
627
- if (this.runtimeRelocationResult?.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated) {
664
+ if (this.runtimeRelocationResult?.outcome === contracts_2.ZLinkFrameworkRelocationOutcome.Relocated) {
628
665
  return Promise.resolve(this.runtimeRelocationResult);
629
666
  }
630
667
  if (this.shutdownOperation !== undefined) {
631
668
  return Promise.resolve({
632
669
  mode: options.mode,
633
670
  effectiveTargetApplicationVersion,
634
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
635
- reason: contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
671
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
672
+ reason: contracts_2.ZLinkFrameworkRelocationReason.ShutdownRequested
636
673
  });
637
674
  }
638
675
  const operationKey = `${options.mode}:${effectiveTargetApplicationVersion}`;
@@ -643,34 +680,34 @@ class ZLinkFrameworkRuntimeHost {
643
680
  return Promise.resolve({
644
681
  mode: options.mode,
645
682
  effectiveTargetApplicationVersion,
646
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
647
- reason: contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress
683
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
684
+ reason: contracts_2.ZLinkFrameworkRelocationReason.OperationInProgress
648
685
  });
649
686
  }
650
- if (this.runtimeState !== contracts_1.ZLinkFrameworkRuntimeState.Serving) {
687
+ if (this.runtimeState !== contracts_2.ZLinkFrameworkRuntimeState.Serving) {
651
688
  return Promise.resolve({
652
689
  mode: options.mode,
653
690
  effectiveTargetApplicationVersion,
654
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
655
- reason: this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Relocating
656
- ? contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress
657
- : contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady
691
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
692
+ reason: this.runtimeState === contracts_2.ZLinkFrameworkRuntimeState.Relocating
693
+ ? contracts_2.ZLinkFrameworkRelocationReason.OperationInProgress
694
+ : contracts_2.ZLinkFrameworkRelocationReason.RuntimeNotReady
658
695
  });
659
696
  }
660
697
  if (!this.admission.acceptsNewWork) {
661
698
  return Promise.resolve({
662
699
  mode: options.mode,
663
700
  effectiveTargetApplicationVersion,
664
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
665
- reason: contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable
701
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
702
+ reason: contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable
666
703
  });
667
704
  }
668
705
  if (hasUnsupportedManualTopology(this.options.registration)) {
669
706
  return Promise.resolve({
670
707
  mode: options.mode,
671
708
  effectiveTargetApplicationVersion,
672
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
673
- reason: contracts_1.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported
709
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
710
+ reason: contracts_2.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported
674
711
  });
675
712
  }
676
713
  this.runtimeDeadline = new Date(Date.now() + deadlineMs);
@@ -696,7 +733,7 @@ class ZLinkFrameworkRuntimeHost {
696
733
  }
697
734
  async runRelocation(mode, effectiveTargetApplicationVersion, deadlineMs, stopStartingSignal) {
698
735
  if (!this.isStarted) {
699
- return this.completeRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady));
736
+ return this.completeRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, contracts_2.ZLinkFrameworkRelocationReason.RuntimeNotReady));
700
737
  }
701
738
  const deadlineAtMs = performance.now() + deadlineMs;
702
739
  const remainingDeadlineMs = () => Math.max(1, deadlineAtMs - performance.now());
@@ -713,39 +750,39 @@ class ZLinkFrameworkRuntimeHost {
713
750
  const descriptorPreparation = await this.routeMeshCoordinator.prepareHostRetire(remainingDeadlineMs());
714
751
  if (descriptorPreparation !== 'prepared') {
715
752
  return this.resetBlockedRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, descriptorPreparation === 'deadline_exceeded'
716
- ? contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded
717
- : contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable));
753
+ ? contracts_2.ZLinkFrameworkRelocationReason.DeadlineExceeded
754
+ : contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable));
718
755
  }
719
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Relocating);
756
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Relocating);
720
757
  const drained = await this.routeMeshCoordinator.relocateHost(remainingDeadlineMs(), stopStartingSignal);
721
758
  if (drained.kind === 'forceStopped') {
722
759
  // Settled authority on both sides or an expired source owner lease
723
760
  // ends the host in Error (spec 30 §13).
724
761
  if (drained.error instanceof service_relocation_coordinator_1.ServiceRelocationAuthorityError) {
725
- return this.completeRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed));
762
+ return this.completeRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, contracts_2.ZLinkFrameworkRelocationReason.RelocationFailed));
726
763
  }
727
764
  return this.resetBlockedRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, stopStartingSignal.aborted
728
- ? contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
765
+ ? contracts_2.ZLinkFrameworkRelocationReason.ShutdownRequested
729
766
  : drained.error instanceof service_relocation_host_runtime_1.ZLinkRelocationStateIncompatibleError
730
- ? contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible
767
+ ? contracts_2.ZLinkFrameworkRelocationReason.StateIncompatible
731
768
  : relocationReason(drained.reason)));
732
769
  }
733
770
  await this.publishHostRelocated();
734
771
  return this.completeRelocation({
735
772
  mode,
736
773
  effectiveTargetApplicationVersion,
737
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Relocated,
738
- reason: contracts_1.ZLinkFrameworkRelocationReason.None
774
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Relocated,
775
+ reason: contracts_2.ZLinkFrameworkRelocationReason.None
739
776
  });
740
777
  }
741
778
  catch (error) {
742
779
  const result = blockedRelocation(mode, effectiveTargetApplicationVersion, stopStartingSignal.aborted
743
- ? contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
780
+ ? contracts_2.ZLinkFrameworkRelocationReason.ShutdownRequested
744
781
  : (0, abort_1.isDeadlineExceededError)(error)
745
- ? contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded
782
+ ? contracts_2.ZLinkFrameworkRelocationReason.DeadlineExceeded
746
783
  : error instanceof service_relocation_host_runtime_1.ZLinkRelocationStateIncompatibleError
747
- ? contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible
748
- : contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed);
784
+ ? contracts_2.ZLinkFrameworkRelocationReason.StateIncompatible
785
+ : contracts_2.ZLinkFrameworkRelocationReason.RelocationFailed);
749
786
  return error instanceof route_mesh_runtime_1.ZLinkRetiringRollbackError
750
787
  ? this.completeRelocation(result)
751
788
  : this.resetBlockedRelocation(result);
@@ -756,10 +793,10 @@ class ZLinkFrameworkRuntimeHost {
756
793
  const deadlineAtMs = performance.now() + deadlineMs;
757
794
  try {
758
795
  this.admission.close();
759
- if (this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Preparing) {
796
+ if (this.runtimeState === contracts_2.ZLinkFrameworkRuntimeState.Preparing) {
760
797
  this.executionState?.abortController.abort();
761
798
  }
762
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Draining);
799
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Draining);
763
800
  if (this.relocationOperation !== undefined &&
764
801
  this.relocationStopStarting?.signal.aborted === true) {
765
802
  await this.relocationOperation;
@@ -777,27 +814,27 @@ class ZLinkFrameworkRuntimeHost {
777
814
  await this.stop();
778
815
  if (drain.kind === 'forceStopped') {
779
816
  return this.completeTermination({
780
- outcome: contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped,
817
+ outcome: contracts_2.ZLinkFrameworkTerminationOutcome.ForceStopped,
781
818
  reason: drain.reason === 'deadline_exceeded'
782
- ? contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded
783
- : contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed
819
+ ? contracts_2.ZLinkFrameworkTerminationReason.DeadlineExceeded
820
+ : contracts_2.ZLinkFrameworkTerminationReason.TeardownFailed
784
821
  });
785
822
  }
786
823
  if (performance.now() >= deadlineAtMs) {
787
824
  throw (0, abort_1.createDeadlineExceededError)('Shutdown resource cleanup exceeded its deadline.');
788
825
  }
789
826
  return this.completeTermination({
790
- outcome: contracts_1.ZLinkFrameworkTerminationOutcome.Stopped,
791
- reason: contracts_1.ZLinkFrameworkTerminationReason.None
827
+ outcome: contracts_2.ZLinkFrameworkTerminationOutcome.Stopped,
828
+ reason: contracts_2.ZLinkFrameworkTerminationReason.None
792
829
  });
793
830
  }
794
831
  catch (error) {
795
832
  await this.stop().catch(() => undefined);
796
833
  return this.completeTermination({
797
- outcome: contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped,
834
+ outcome: contracts_2.ZLinkFrameworkTerminationOutcome.ForceStopped,
798
835
  reason: (0, abort_1.isDeadlineExceededError)(error)
799
- ? contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded
800
- : contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed
836
+ ? contracts_2.ZLinkFrameworkTerminationReason.DeadlineExceeded
837
+ : contracts_2.ZLinkFrameworkTerminationReason.TeardownFailed
801
838
  });
802
839
  }
803
840
  });
@@ -822,8 +859,8 @@ class ZLinkFrameworkRuntimeHost {
822
859
  }
823
860
  resetBlockedRelocation(result) {
824
861
  this.recordRelocationResult(result);
825
- if (this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Relocating) {
826
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Serving);
862
+ if (this.runtimeState === contracts_2.ZLinkFrameworkRuntimeState.Relocating) {
863
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Serving);
827
864
  }
828
865
  this.runtimeDeadline = undefined;
829
866
  this.relocationTargetApplicationVersion = undefined;
@@ -837,9 +874,9 @@ class ZLinkFrameworkRuntimeHost {
837
874
  this.runtimeRelocationResult = result;
838
875
  this.runtimeDeadline = undefined;
839
876
  this.recordRelocationResult(result);
840
- this.setRuntimeState(result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated
841
- ? contracts_1.ZLinkFrameworkRuntimeState.Relocated
842
- : contracts_1.ZLinkFrameworkRuntimeState.Error);
877
+ this.setRuntimeState(result.outcome === contracts_2.ZLinkFrameworkRelocationOutcome.Relocated
878
+ ? contracts_2.ZLinkFrameworkRuntimeState.Relocated
879
+ : contracts_2.ZLinkFrameworkRuntimeState.Error);
843
880
  return result;
844
881
  }
845
882
  recordRelocationResult(result) {
@@ -847,10 +884,10 @@ class ZLinkFrameworkRuntimeHost {
847
884
  this.metrics.duration(runtime_metrics_1.METRIC_NAMES.HostRelocationDuration, Math.max(0, performance.now() - this.relocationOperationStartedAt) /
848
885
  runtime_metrics_1.MILLISECONDS_PER_SECOND, {
849
886
  mode: relocationModeMetricName(result.mode),
850
- outcome: result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated ? 'relocated' : 'blocked'
887
+ outcome: result.outcome === contracts_2.ZLinkFrameworkRelocationOutcome.Relocated ? 'relocated' : 'blocked'
851
888
  });
852
889
  }
853
- if (result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Blocked) {
890
+ if (result.outcome === contracts_2.ZLinkFrameworkRelocationOutcome.Blocked) {
854
891
  this.metrics.count(runtime_metrics_1.METRIC_NAMES.HostRelocationBlocked, 1, {
855
892
  mode: relocationModeMetricName(result.mode),
856
893
  reason: relocationReasonMetricName(result.reason)
@@ -871,12 +908,12 @@ class ZLinkFrameworkRuntimeHost {
871
908
  this.runtimeDeadline = undefined;
872
909
  if (this.shutdownOperationStartedAt !== undefined) {
873
910
  this.metrics.duration(runtime_metrics_1.METRIC_NAMES.HostShutdownDuration, Math.max(0, performance.now() - this.shutdownOperationStartedAt) / runtime_metrics_1.MILLISECONDS_PER_SECOND, {
874
- outcome: result.outcome === contracts_1.ZLinkFrameworkTerminationOutcome.Stopped
911
+ outcome: result.outcome === contracts_2.ZLinkFrameworkTerminationOutcome.Stopped
875
912
  ? 'stopped'
876
913
  : 'force_stopped'
877
914
  });
878
915
  }
879
- if (result.outcome === contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped) {
916
+ if (result.outcome === contracts_2.ZLinkFrameworkTerminationOutcome.ForceStopped) {
880
917
  this.metrics.count(runtime_metrics_1.METRIC_NAMES.HostShutdownForced, 1, {
881
918
  reason: terminationReasonMetricName(result.reason)
882
919
  });
@@ -888,7 +925,7 @@ class ZLinkFrameworkRuntimeHost {
888
925
  outcome: result.outcome,
889
926
  reason: result.reason
890
927
  });
891
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Stopped);
928
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Stopped);
892
929
  return result;
893
930
  }
894
931
  setRuntimeState(state) {
@@ -1004,7 +1041,13 @@ class ZLinkFrameworkRuntimeHost {
1004
1041
  if (this.executionState !== undefined) {
1005
1042
  return;
1006
1043
  }
1007
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing);
1044
+ const previousLease = this.telemetryLease;
1045
+ this.telemetryLease = (0, message_flow_delivery_1.renewTelemetryLease)(previousLease);
1046
+ if (this.telemetryLease !== previousLease) {
1047
+ this.dispatchErrorReporters = new WeakMap();
1048
+ this.cachedDiagnosticsContext = undefined;
1049
+ }
1050
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Preparing);
1008
1051
  this.lifecycleSink?.push('framework:start');
1009
1052
  const listenerRecords = new listener_records_1.ZLinkListenerRecords();
1010
1053
  this.listenerRecords = listenerRecords;
@@ -1024,10 +1067,11 @@ class ZLinkFrameworkRuntimeHost {
1024
1067
  this.messageFlowModeCell.mode =
1025
1068
  this.options.registration.dispatch?.diagnostics.messageFlow ?? 'errors';
1026
1069
  const dispatchErrors = this.createDispatchErrorReporter(this.executionState.errorSink);
1027
- channelRuntime = new channels_1.ZLinkChannelRuntimeManager(this.options.registration, channelAdapter, context, this.options.providerResolver, { ...this.createChannelRuntimeOptions(), listenerRecords });
1070
+ channelRuntime = new channels_1.ZLinkChannelRuntimeManager(this.options.registration, channelAdapter, context, this.options.providerResolver, { ...this.createChannelRuntimeOptions(), listenerRecords, requests: this.requests });
1028
1071
  this.channelRuntime = channelRuntime;
1029
1072
  channelRuntime.prepareMeshDispatch(this.executionState.taskRunner);
1030
1073
  spotNodeRuntime = new spots_1.ZLinkSpotNodeRuntimeManager({
1074
+ requests: this.requests,
1031
1075
  ...this.createSpotNodeRuntimeOptions(context, dispatchErrors),
1032
1076
  listenerRecords
1033
1077
  });
@@ -1045,7 +1089,7 @@ class ZLinkFrameworkRuntimeHost {
1045
1089
  await this.publishOrStayPreparing(locationRuntime, async (publishSignal) => {
1046
1090
  await spotNodeRuntime.startLocationAutoConnect(publishSignal);
1047
1091
  await channelRuntime.startLocationAutoConnect(publishSignal);
1048
- await spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing, publishSignal);
1092
+ await spotNodeRuntime.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Preparing, publishSignal);
1049
1093
  });
1050
1094
  }
1051
1095
  streamRuntime = new streams_1.ZLinkStreamRuntimeManager({
@@ -1108,6 +1152,8 @@ class ZLinkFrameworkRuntimeHost {
1108
1152
  }
1109
1153
  }
1110
1154
  async stop() {
1155
+ (0, message_flow_delivery_1.retireTelemetryLease)(this.telemetryLease);
1156
+ this.requests.close(new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ShuttingDown, 'Host stopped.'));
1111
1157
  await this.runWithShutdownDeadline(DEFAULT_HOST_CONTROL_TIMEOUT_MS, async () => this.runLifecycle(() => this.stopCore()));
1112
1158
  }
1113
1159
  runtimeMetricMeshSnapshots() {
@@ -1133,7 +1179,7 @@ class ZLinkFrameworkRuntimeHost {
1133
1179
  meshName,
1134
1180
  source,
1135
1181
  configuredPeers: status.peers.length,
1136
- connectedPeers: status.peers.filter((peer) => peer.state !== contracts_1.ZLinkPeerState.NotConnected)
1182
+ connectedPeers: status.peers.filter((peer) => peer.state !== contracts_2.ZLinkPeerState.NotConnected)
1137
1183
  .length,
1138
1184
  readyPeers: status.readyPeerCount,
1139
1185
  channels: status.channels.map((channel) => ({
@@ -1190,7 +1236,7 @@ class ZLinkFrameworkRuntimeHost {
1190
1236
  this.listenerRecords.clear();
1191
1237
  this.lifecycleSink?.push('framework:stopped');
1192
1238
  if (this.shutdownOperation === undefined) {
1193
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Stopped);
1239
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Stopped);
1194
1240
  }
1195
1241
  }
1196
1242
  installOwnerLeaseRecoveryPublication(runtime, spotNodeRuntime, channelRuntime) {
@@ -1198,7 +1244,7 @@ class ZLinkFrameworkRuntimeHost {
1198
1244
  const handler = (_renewal, wasOwnerLeaseUsable) => {
1199
1245
  if (!this.ownerAdmissionOpen())
1200
1246
  return;
1201
- if (wasOwnerLeaseUsable && this.runtimeState !== contracts_1.ZLinkFrameworkRuntimeState.Preparing)
1247
+ if (wasOwnerLeaseUsable && this.runtimeState !== contracts_2.ZLinkFrameworkRuntimeState.Preparing)
1202
1248
  return;
1203
1249
  if (recoveryOperation !== undefined)
1204
1250
  return;
@@ -1219,17 +1265,17 @@ class ZLinkFrameworkRuntimeHost {
1219
1265
  if (!this.ownerAdmissionOpen())
1220
1266
  return;
1221
1267
  await this.publishOrStayPreparing(runtime, async (signal) => {
1222
- await spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing, signal);
1268
+ await spotNodeRuntime.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Preparing, signal);
1223
1269
  if (runtime.ownerLeaseUsable === false)
1224
1270
  return;
1225
- if (this.runtimeState !== contracts_1.ZLinkFrameworkRuntimeState.Preparing) {
1271
+ if (this.runtimeState !== contracts_2.ZLinkFrameworkRuntimeState.Preparing) {
1226
1272
  await spotNodeRuntime.publishMeshNodeState(this.runtimeState, signal);
1227
1273
  }
1228
1274
  await spotNodeRuntime.startLocationAutoConnect(signal);
1229
1275
  await channelRuntime.startLocationAutoConnect(signal);
1230
1276
  await channelRuntime.reclaimLocationOwnerRows(signal);
1231
1277
  await this.locationOwner.currentLifecycle?.reclaimOwnerRows();
1232
- if (this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Preparing) {
1278
+ if (this.runtimeState === contracts_2.ZLinkFrameworkRuntimeState.Preparing) {
1233
1279
  await this.enterServing(spotNodeRuntime, signal);
1234
1280
  }
1235
1281
  });
@@ -1241,9 +1287,9 @@ class ZLinkFrameworkRuntimeHost {
1241
1287
  if (store !== undefined) {
1242
1288
  await this.startStatefulAuthority(store, spotNodeRuntime, signal);
1243
1289
  }
1244
- await spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Serving, signal);
1290
+ await spotNodeRuntime.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Serving, signal);
1245
1291
  this.routeMeshCoordinator.markServing();
1246
- this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Serving);
1292
+ this.setRuntimeState(contracts_2.ZLinkFrameworkRuntimeState.Serving);
1247
1293
  }
1248
1294
  // Location runtime §5: a startup publication the Store does not confirm (a
1249
1295
  // provider error, or no answer within the renew timeout) leaves the host in
@@ -1366,10 +1412,10 @@ class ZLinkFrameworkRuntimeHost {
1366
1412
  await awaitWithDrainSignal(this.streamRuntime?.notifyServerDrain(meshName), signal);
1367
1413
  }
1368
1414
  async publishMeshRetiring(meshName, signal) {
1369
- await this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Relocating, signal, meshName);
1415
+ await this.spotNodeRuntime?.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Relocating, signal, meshName);
1370
1416
  }
1371
1417
  async publishMeshServing(meshName, signal) {
1372
- await this.spotNodeRuntime?.reconcileAndPublishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Serving, meshName, signal);
1418
+ await this.spotNodeRuntime?.reconcileAndPublishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Serving, meshName, signal);
1373
1419
  // A failed relocation rolls the local object barriers back before the
1374
1420
  // descriptor is published as Serving. Reconcile the durable authority
1375
1421
  // routes before returning so the next local request cannot observe the
@@ -1382,7 +1428,7 @@ class ZLinkFrameworkRuntimeHost {
1382
1428
  if (node !== undefined) {
1383
1429
  await node.publishDraining?.();
1384
1430
  }
1385
- await this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Draining, signal, meshName);
1431
+ await this.spotNodeRuntime?.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Draining, signal, meshName);
1386
1432
  }
1387
1433
  async preflightAutomaticPeerReadiness(deadlineAt, targetApplicationVersion) {
1388
1434
  // A host with no local stateful workload has nothing to move. The public
@@ -1394,7 +1440,7 @@ class ZLinkFrameworkRuntimeHost {
1394
1440
  return undefined;
1395
1441
  const location = this.locationOwner.currentRuntime;
1396
1442
  if (location === undefined)
1397
- return contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable;
1443
+ return contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable;
1398
1444
  let storeUnavailable = false;
1399
1445
  while (performance.now() < deadlineAt) {
1400
1446
  try {
@@ -1409,8 +1455,8 @@ class ZLinkFrameworkRuntimeHost {
1409
1455
  Locations_1.zlinkDefaultLocationOptions.pollingIntervalMs, Math.max(1, deadlineAt - performance.now()))));
1410
1456
  }
1411
1457
  return storeUnavailable
1412
- ? contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable
1413
- : contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable;
1458
+ ? contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable
1459
+ : contracts_2.ZLinkFrameworkRelocationReason.TargetUnavailable;
1414
1460
  }
1415
1461
  hasLocalStatefulRelocationWork() {
1416
1462
  const spotManager = this.spotManager;
@@ -1447,7 +1493,7 @@ class ZLinkFrameworkRuntimeHost {
1447
1493
  return true;
1448
1494
  }
1449
1495
  async publishHostRelocated() {
1450
- await Promise.all([...this.options.registration.spotNodes.keys()].map((meshName) => this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Relocated, undefined, meshName)));
1496
+ await Promise.all([...this.options.registration.spotNodes.keys()].map((meshName) => this.spotNodeRuntime?.publishMeshNodeState(contracts_2.ZLinkFrameworkRuntimeState.Relocated, undefined, meshName)));
1451
1497
  }
1452
1498
  async publishHostDraining(signal) {
1453
1499
  try {
@@ -1613,7 +1659,7 @@ class ZLinkFrameworkRuntimeHost {
1613
1659
  const descriptors = await (0, location_store_pages_1.listAllMeshNodeDescriptors)(locationStore, meshName, signal);
1614
1660
  const selected = await selectReadyLocationPlacementDescriptor(descriptors, meshNode, signal, (descriptor) => {
1615
1661
  const capability = descriptor.objectCapabilities.find((candidate) => candidate.objectKind === 'actor' && candidate.stableType === stableType);
1616
- return (descriptor.state === contracts_1.ZLinkFrameworkRuntimeState.Serving &&
1662
+ return (descriptor.state === contracts_2.ZLinkFrameworkRuntimeState.Serving &&
1617
1663
  descriptor.objectRole === 'server' &&
1618
1664
  descriptor.placementWeight > 0 &&
1619
1665
  descriptor.entrySpotId !== undefined &&
@@ -1642,10 +1688,33 @@ class ZLinkFrameworkRuntimeHost {
1642
1688
  };
1643
1689
  }
1644
1690
  });
1691
+ const selectUserSpotMesh = (requestedMeshName) => {
1692
+ const clientMeshes = [...this.options.registration.spotNodes]
1693
+ .filter(([, node]) => (0, spot_address_transport_1.hasObjectClientCapability)(node.objectRole))
1694
+ .map(([meshName]) => meshName);
1695
+ const meshes = requestedMeshName === undefined ? clientMeshes : [requestedMeshName];
1696
+ if (meshes.length === 0) {
1697
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, 'No object-client RouteMesh is configured.');
1698
+ }
1699
+ if (requestedMeshName === undefined && meshes.length > 1) {
1700
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshSelectionRequired, 'Multiple object-client RouteMeshes are configured; call inMesh(...).');
1701
+ }
1702
+ const meshName = meshes[0];
1703
+ if (!this.options.registration.spotNodes.has(meshName)) {
1704
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshNotFound, `RouteMesh '${meshName}' is not configured.`);
1705
+ }
1706
+ if (!clientMeshes.includes(meshName)) {
1707
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no object-client role.`);
1708
+ }
1709
+ return meshName;
1710
+ };
1645
1711
  const coordinator = (this.userSpotCoordinator = new user_spot_creation_coordinator_1.ZLinkUserSpotCreationCoordinator({
1646
1712
  store: locationStore,
1647
- relocationPolicy: (meshName, stableType) => this.options.registration.spotNodes.get(meshName)?.spotFactoryRegistrations?.[stableType]
1648
- ?.relocation.kind,
1713
+ leaseTracker: this.locationOwner.currentLeaseTracker,
1714
+ relocationPolicy: (meshName, stableType) => {
1715
+ const node = this.options.registration.spotNodes.get(selectUserSpotMesh(meshName));
1716
+ return node?.spotFactoryRegistrations?.[stableType]?.relocation.kind;
1717
+ },
1649
1718
  publishReadyRoute: (meshName, route) => {
1650
1719
  this.cachedLocationSpotRouteResolver?.invalidate?.(route.spot.spotId);
1651
1720
  this.spotNodeRuntime?.meshNode(meshName)?.rememberSpotRoute?.(route);
@@ -1673,23 +1742,7 @@ class ZLinkFrameworkRuntimeHost {
1673
1742
  }
1674
1743
  },
1675
1744
  target: async (request, signal, excludedNodeRids) => {
1676
- const clientMeshes = [...this.options.registration.spotNodes]
1677
- .filter(([, node]) => (0, spot_address_transport_1.hasObjectClientCapability)(node.objectRole))
1678
- .map(([meshName]) => meshName);
1679
- const meshes = request.meshName === undefined ? clientMeshes : [request.meshName];
1680
- if (meshes.length === 0) {
1681
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, 'No object-client RouteMesh is configured.');
1682
- }
1683
- if (request.meshName === undefined && meshes.length > 1) {
1684
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshSelectionRequired, 'Multiple object-client RouteMeshes are configured; call inMesh(...).');
1685
- }
1686
- const meshName = meshes[0];
1687
- if (!this.options.registration.spotNodes.has(meshName)) {
1688
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshNotFound, `RouteMesh '${meshName}' is not configured.`);
1689
- }
1690
- if (!clientMeshes.includes(meshName)) {
1691
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no object-client role.`);
1692
- }
1745
+ const meshName = selectUserSpotMesh(request.meshName);
1693
1746
  const meshNode = this.spotNodeRuntime?.meshNode(meshName);
1694
1747
  const descriptors = await (0, location_store_pages_1.listAllMeshNodeDescriptors)(locationStore, meshName, signal);
1695
1748
  const selected = await selectReadyLocationPlacementDescriptor(descriptors, meshNode, signal, (descriptor) => {
@@ -1764,7 +1817,7 @@ class ZLinkFrameworkRuntimeHost {
1764
1817
  }, signal);
1765
1818
  const reply = coordinated.result.reply;
1766
1819
  let payload;
1767
- if (reply !== undefined && coordinated.result.state !== contracts_1.ZLinkSpotCreateState.Existing) {
1820
+ if (reply !== undefined && coordinated.result.state !== contracts_2.ZLinkSpotCreateState.Existing) {
1768
1821
  const message = (0, payload_codec_1.encodeFrameworkPayloadMessage)(reply, this.options.registration.messageSerializers);
1769
1822
  try {
1770
1823
  payload = {
@@ -1782,9 +1835,9 @@ class ZLinkFrameworkRuntimeHost {
1782
1835
  failureCode: 0,
1783
1836
  tail: {
1784
1837
  kind: 'userSpotCreate',
1785
- createResult: coordinated.result.state === contracts_1.ZLinkSpotCreateState.Existing
1838
+ createResult: coordinated.result.state === contracts_2.ZLinkSpotCreateState.Existing
1786
1839
  ? 'existing'
1787
- : coordinated.result.state === contracts_1.ZLinkSpotCreateState.Created
1840
+ : coordinated.result.state === contracts_2.ZLinkSpotCreateState.Created
1788
1841
  ? 'created'
1789
1842
  : 'rejected',
1790
1843
  spotId: String(coordinated.spot.spotId),
@@ -1870,7 +1923,7 @@ class ZLinkFrameworkRuntimeHost {
1870
1923
  failureCode: 0,
1871
1924
  tail: {
1872
1925
  kind: 'userSpotClose',
1873
- closed: await coordinator.handleRemoteClose(record, (spot, beginAuthority, closeSignal) => local.closeUserWithAuthority(spot.meshName, spot.spotId, beginAuthority, closeSignal), signal, (spot) => local.isSpotClosing(spot.meshName, spot.spotId))
1926
+ closed: await coordinator.handleRemoteClose(record, (spot, beginAuthority, closeSignal) => local.closeUserWithAuthority(spot.meshName, spot.spotId, beginAuthority, closeSignal, new Date(Number(record.deadlineUnixMs))), signal, (spot) => local.isSpotClosing(spot.meshName, spot.spotId))
1874
1927
  }
1875
1928
  };
1876
1929
  }
@@ -1906,6 +1959,7 @@ class ZLinkFrameworkRuntimeHost {
1906
1959
  }
1907
1960
  actorRuntimeOptionsFactory() {
1908
1961
  return new actor_runtime_options_factory_1.ZLinkActorRuntimeOptionsFactory({
1962
+ requests: this.requests,
1909
1963
  terminateActorActivation: (actor, terminal) => this.spotNodeRuntime?.terminateActorActivation(actor, terminal) ?? terminal(),
1910
1964
  registration: this.options.registration,
1911
1965
  messageFlow: () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow,
@@ -1944,7 +1998,7 @@ class ZLinkFrameworkRuntimeHost {
1944
1998
  if (entrySpotId === undefined) {
1945
1999
  throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${actorRef.actorId}' authority requires its RouteMesh Entry Spot.`);
1946
2000
  }
1947
- await (0, actors_1.publishInitialActorAuthority)(store, {
2001
+ const authority = await (0, actors_1.publishInitialActorAuthority)(store, {
1948
2002
  actorType,
1949
2003
  actor: actorRef,
1950
2004
  meshName,
@@ -1952,9 +2006,9 @@ class ZLinkFrameworkRuntimeHost {
1952
2006
  owner,
1953
2007
  spotId: entrySpotId,
1954
2008
  spotGeneration: ownerNodeGeneration,
1955
- spotKind: contracts_1.ZLinkSpotKind.Entry
2009
+ spotKind: contracts_2.ZLinkSpotKind.Entry
1956
2010
  }, signal);
1957
- this.actorClientLocationResolver?.invalidateActorRoute(actorRef.actorId);
2011
+ this.actorClientLocationResolver?.observeActorAuthorityVersion(actorRef.actorId, authority.storeVersion.value);
1958
2012
  },
1959
2013
  reportPostCommitError: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('post-commit actor binding', error),
1960
2014
  reportBoundSessionSendError: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('bound session one-way submit', error),
@@ -1983,6 +2037,7 @@ class ZLinkFrameworkRuntimeHost {
1983
2037
  return new channel_runtime_options_factory_1.ZLinkChannelRuntimeOptionsFactory({
1984
2038
  monitoringAdapter: this.backendAdapterFactory.createMonitoringAdapter(),
1985
2039
  messageFlowModeCell: this.messageFlowModeCell,
2040
+ telemetryLease: this.telemetryLease,
1986
2041
  boundSessionRelay: this.boundSessionRelay,
1987
2042
  applicationJobQueue: this.applicationJobQueue,
1988
2043
  spotManager: () => this.spotManager,
@@ -2012,6 +2067,7 @@ class ZLinkFrameworkRuntimeHost {
2012
2067
  }).create();
2013
2068
  return {
2014
2069
  ...options,
2070
+ admission: this.admission,
2015
2071
  errorSink: this.runtimeOrPreStartErrorSink,
2016
2072
  peerAdmissionSealed: (meshName) => !this.admission.accepts(meshName),
2017
2073
  messageFollowReceiver: (record) => {
@@ -2090,21 +2146,21 @@ class ZLinkFrameworkRuntimeHost {
2090
2146
  if (channelRuntime === undefined) {
2091
2147
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode channel dispatch requires the channel runtime.');
2092
2148
  }
2093
- return channelRuntime.dispatchMeshChannel(meshName, record, signal, (dispatch, onRejected) => this.admitMeshDispatch(meshName, record, 'RouteMesh channel dispatch', dispatch, onRejected));
2149
+ return channelRuntime.dispatchMeshChannel(meshName, record, signal, (dispatch, onRejected, receiver, context) => this.admitMeshDispatch(meshName, record, 'RouteMesh channel dispatch', dispatch, onRejected, receiver, context));
2094
2150
  }
2095
2151
  case service_runtime_contracts_1.ReceiveKind.NodeSend:
2096
2152
  case service_runtime_contracts_1.ReceiveKind.NodeRequest: {
2097
- return this.dispatchMeshNodeRecord(meshName, record, signal, (dispatch, onRejected) => this.admitMeshDispatch(meshName, record, 'RouteMesh node dispatch', dispatch, onRejected));
2153
+ return this.dispatchMeshNodeRecord(meshName, record, signal, (dispatch, onRejected, receiver, context) => this.admitMeshDispatch(meshName, record, 'RouteMesh node dispatch', dispatch, onRejected, receiver, context));
2098
2154
  }
2099
2155
  case service_runtime_contracts_1.ReceiveKind.SpotSend:
2100
2156
  case service_runtime_contracts_1.ReceiveKind.SpotRequest:
2101
2157
  case service_runtime_contracts_1.ReceiveKind.SpotMulticast:
2102
- return this.dispatchMeshSpotRecord(meshName, owner, record, (dispatch, onRejected) => this.admitMeshDispatch(meshName, record, 'RouteMesh Spot dispatch', dispatch, onRejected));
2158
+ return this.dispatchMeshSpotRecord(meshName, owner, record, (dispatch, onRejected, receiver, context) => this.admitMeshDispatch(meshName, record, 'RouteMesh Spot dispatch', dispatch, onRejected, receiver, context));
2103
2159
  case service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation:
2104
2160
  if (this.spotManager === undefined) {
2105
2161
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Instance Spot dispatch requires the Spot manager.');
2106
2162
  }
2107
- return this.spotManager.dispatchMeshInstance(meshName, owner, record, (dispatch, onRejected) => this.admitMeshDispatch(meshName, record, 'RouteMesh Instance Spot dispatch', dispatch, onRejected));
2163
+ return this.spotManager.dispatchMeshInstance(meshName, owner, record, (dispatch, onRejected, receiver, context) => this.admitMeshDispatch(meshName, record, 'RouteMesh Instance Spot dispatch', dispatch, onRejected, receiver, context));
2108
2164
  case service_runtime_contracts_1.ReceiveKind.SpotControl:
2109
2165
  if (this.spotManager === undefined) {
2110
2166
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Spot control dispatch requires the Spot manager.');
@@ -2115,19 +2171,19 @@ class ZLinkFrameworkRuntimeHost {
2115
2171
  if (this.spotManager === undefined) {
2116
2172
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor dispatch requires the Spot manager.');
2117
2173
  }
2118
- return this.spotManager.dispatchMeshActor(applicationJobOrigin(), meshName, owner, record, (dispatch, onRejected) => this.admitMeshDispatch(meshName, record, 'RouteMesh Actor dispatch', dispatch, onRejected));
2174
+ return this.spotManager.dispatchMeshActor(applicationJobOrigin(), meshName, owner, record, (dispatch, onRejected, receiver, context) => this.admitMeshDispatch(meshName, record, 'RouteMesh Actor dispatch', dispatch, onRejected, receiver, context));
2119
2175
  case service_runtime_contracts_1.ReceiveKind.SendReady:
2120
2176
  return Promise.resolve();
2121
2177
  default:
2122
2178
  throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode record kind '${record.kind}' does not yet have a registered framework consumer.`);
2123
2179
  }
2124
2180
  }
2125
- admitMeshDispatch(meshName, record, operation, dispatch, onRejected) {
2181
+ admitMeshDispatch(meshName, record, operation, dispatch, onRejected, receiver, context) {
2126
2182
  // Execution gate §13 and host relocation §14 keep control progress independent
2127
2183
  // of new application admission. Disconnect callbacks still use their owner gate.
2128
2184
  if (record.domain === service_runtime_contracts_1.ReadyDomain.Infrastructure)
2129
- return dispatch();
2130
- if (!this.admission.accepts(meshName) &&
2185
+ return dispatch.call(receiver, context);
2186
+ if (!this.admission.accepts(meshName, record.kind) &&
2131
2187
  (record.kind === service_runtime_contracts_1.ReceiveKind.NodeSend ||
2132
2188
  record.kind === service_runtime_contracts_1.ReceiveKind.NodeRequest ||
2133
2189
  record.kind === service_runtime_contracts_1.ReceiveKind.SpotSend ||
@@ -2136,10 +2192,10 @@ class ZLinkFrameworkRuntimeHost {
2136
2192
  if (relay !== undefined &&
2137
2193
  (0, protocol_1.decodeStreamHeader)(Buffer.from(relay.header, 'base64'), this.flowCreationEnabled()).name ===
2138
2194
  actor_packet_relay_wire_1.ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET) {
2139
- return dispatch();
2195
+ return dispatch.call(receiver, context);
2140
2196
  }
2141
2197
  }
2142
- return this.admission.run(meshName, operation, dispatch, onRejected);
2198
+ return this.admission.run(meshName, operation, dispatch, record.kind, onRejected, receiver, context);
2143
2199
  }
2144
2200
  async dispatchMeshActorBinding(meshName, record, signal) {
2145
2201
  if (record.kindData?.kind !== 'actorBinding') {
@@ -2204,8 +2260,7 @@ class ZLinkFrameworkRuntimeHost {
2204
2260
  replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2205
2261
  return;
2206
2262
  }
2207
- replyBindingSuccess();
2208
- state.installBoundSessionBinding({
2263
+ const incomingTarget = {
2209
2264
  ...target,
2210
2265
  sessionNodeRid: binding.sessionNodeRid,
2211
2266
  sessionRid: binding.sessionRid,
@@ -2213,19 +2268,92 @@ class ZLinkFrameworkRuntimeHost {
2213
2268
  sessionOwnerId: binding.sessionOwnerId,
2214
2269
  sessionOwnerLeaseGeneration: binding.sessionOwnerLeaseGeneration,
2215
2270
  bindingGeneration: binding.bindingGeneration
2271
+ };
2272
+ const currentBinding = state.boundSession;
2273
+ const currentActor = state.actor;
2274
+ if (currentBinding === undefined ||
2275
+ currentActor?.onDuplicateBind === undefined ||
2276
+ samePhysicalSession(currentBinding, incomingTarget)) {
2277
+ state.installBoundSessionBinding(incomingTarget);
2278
+ replyBindingSuccess();
2279
+ return;
2280
+ }
2281
+ const spotManager = this.spotManager;
2282
+ if (spotManager === undefined || state.meshName === undefined) {
2283
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2284
+ return;
2285
+ }
2286
+ let callbackStarted;
2287
+ const started = new Promise((resolve) => {
2288
+ callbackStarted = resolve;
2216
2289
  });
2217
- return Promise.resolve();
2290
+ let callbackTimedOut = false;
2291
+ let timeoutHandle;
2292
+ const cancellation = new AbortController();
2293
+ const callbackSignal = signal === undefined ? cancellation.signal : AbortSignal.any([signal, cancellation.signal]);
2294
+ const turn = spotManager.executeActorTurn(state.meshName, state.actor?.context.spotId, state.actorId, async () => {
2295
+ const current = state.boundSession;
2296
+ const actor = state.actor;
2297
+ const duplicateCallback = current !== undefined && !samePhysicalSession(current, incomingTarget)
2298
+ ? actor?.onDuplicateBind
2299
+ : undefined;
2300
+ if (duplicateCallback === undefined || actor === undefined || current === undefined) {
2301
+ state.installBoundSessionBinding(incomingTarget);
2302
+ replyBindingSuccess();
2303
+ return;
2304
+ }
2305
+ callbackStarted();
2306
+ const decision = await duplicateCallback.call(actor, sessionBindingIdentity(current), sessionBindingIdentity(incomingTarget), callbackSignal);
2307
+ if (callbackTimedOut)
2308
+ return;
2309
+ if (decision !== undefined && decision.length > 0) {
2310
+ if (Buffer.byteLength(decision, 'utf8') > 0xffff) {
2311
+ throw new RangeError('Duplicate bind rejection message exceeds Text16 capacity.');
2312
+ }
2313
+ if (record.replyFailure?.(runtime_values_1.RequestResult.Rejected, 0, {
2314
+ kind: 'streamBindRejected',
2315
+ rejectionMessage: decision
2316
+ }) !== runtime_values_1.SubmitResult.Ok) {
2317
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' rejection acknowledgement failed.`);
2318
+ }
2319
+ return;
2320
+ }
2321
+ state.installBoundSessionBinding(incomingTarget);
2322
+ replyBindingSuccess();
2323
+ });
2324
+ const timeout = started.then(() => new Promise((resolve) => {
2325
+ timeoutHandle = setTimeout(() => {
2326
+ callbackTimedOut = true;
2327
+ resolve('timedOut');
2328
+ }, this.options.registration.sessionReplacementCallbackTimeoutMs);
2329
+ }));
2330
+ try {
2331
+ const outcome = await Promise.race([turn.then(() => 'completed'), timeout]);
2332
+ if (outcome === 'timedOut') {
2333
+ cancellation.abort((0, abort_1.createDeadlineExceededError)('Duplicate bind callback timed out.'));
2334
+ if (record.replyFailure?.(runtime_values_1.RequestResult.TimedOut, 0) !== runtime_values_1.SubmitResult.Ok) {
2335
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' timeout acknowledgement failed.`);
2336
+ }
2337
+ void turn.catch((error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException(`duplicate bind callback '${binding.actor.actorId}'`, error));
2338
+ }
2339
+ }
2340
+ finally {
2341
+ if (timeoutHandle !== undefined)
2342
+ clearTimeout(timeoutHandle);
2343
+ }
2218
2344
  }
2219
2345
  submitLocalMeshRoute(meshName, sourceNodeRid, parts) {
2220
2346
  const state = this.executionState;
2221
2347
  const channelRuntime = this.channelRuntime;
2222
- if (state === undefined || channelRuntime === undefined || !this.admission.accepts(meshName)) {
2348
+ if (state === undefined ||
2349
+ channelRuntime === undefined ||
2350
+ !this.admission.accepts(meshName, service_runtime_contracts_1.ReceiveKind.NodeSend)) {
2223
2351
  return { status: submission_result_1.ZLinkSubmitStatus.Shutdown };
2224
2352
  }
2225
2353
  if (!channelRuntime.canDispatchLocalMeshRoute(meshName)) {
2226
2354
  return { status: submission_result_1.ZLinkSubmitStatus.TargetNotFound };
2227
2355
  }
2228
- const claim = this.admission.claim(meshName, 'RouteMesh local node dispatch');
2356
+ const claim = this.admission.claim(meshName, 'RouteMesh local node dispatch', service_runtime_contracts_1.ReceiveKind.NodeSend);
2229
2357
  const ownedParts = [];
2230
2358
  try {
2231
2359
  for (const part of parts) {
@@ -2273,8 +2401,9 @@ class ZLinkFrameworkRuntimeHost {
2273
2401
  packetName: envelope.packetName,
2274
2402
  contentType: envelope.header.contentType,
2275
2403
  sourceNodeRid: String(record.sourceNodeRid ?? ''),
2276
- metadata: (0, contracts_1.zlinkMessageMetadata)(envelope.header.metadata),
2277
- correlationId: envelope.header.correlationId ?? undefined
2404
+ metadata: (0, contracts_2.zlinkMessageMetadata)(envelope.header.metadata),
2405
+ correlationId: envelope.header.correlationId ?? undefined,
2406
+ receivedAt: record.receivedAt ?? new Date()
2278
2407
  };
2279
2408
  try {
2280
2409
  const dispatch = async () => {
@@ -2305,7 +2434,7 @@ class ZLinkFrameworkRuntimeHost {
2305
2434
  if (existing !== undefined) {
2306
2435
  return existing;
2307
2436
  }
2308
- const reporter = new channels_1.ZLinkDispatchErrorReporter(undefined, undefined, errorSink, this.diagnosticsContext(), this.metrics);
2437
+ const reporter = new channels_1.ZLinkDispatchErrorReporter(this.diagnosticsContext(), this.metrics);
2309
2438
  this.dispatchErrorReporters.set(errorSink, reporter);
2310
2439
  return reporter;
2311
2440
  }
@@ -2322,7 +2451,7 @@ class ZLinkFrameworkRuntimeHost {
2322
2451
  };
2323
2452
  }
2324
2453
  diagnosticsContext() {
2325
- this.cachedDiagnosticsContext ??= (0, diagnostics_1.createDiagnosticsContext)(this.options.registration.dispatch, this.options.providerResolver, this.messageFlowModeCell);
2454
+ this.cachedDiagnosticsContext ??= (0, diagnostics_1.createDiagnosticsContext)(this.options.registration.dispatch, this.options.providerResolver, this.messageFlowModeCell, this.telemetryLease);
2326
2455
  return this.cachedDiagnosticsContext;
2327
2456
  }
2328
2457
  flowCreationEnabled() {
@@ -2394,16 +2523,39 @@ function hasUnsupportedManualTopology(registration) {
2394
2523
  }
2395
2524
  return false;
2396
2525
  }
2526
+ function samePhysicalSession(left, right) {
2527
+ return (left.sessionNodeRid !== undefined &&
2528
+ left.sessionRid !== undefined &&
2529
+ left.sessionOwnerNodeGeneration !== undefined &&
2530
+ right.sessionNodeRid !== undefined &&
2531
+ right.sessionRid !== undefined &&
2532
+ right.sessionOwnerNodeGeneration !== undefined &&
2533
+ (0, routing_id_1.routingIdsEqual)(left.sessionNodeRid, right.sessionNodeRid) &&
2534
+ left.sessionRid === right.sessionRid &&
2535
+ left.sessionOwnerNodeGeneration === right.sessionOwnerNodeGeneration);
2536
+ }
2537
+ function sessionBindingIdentity(value) {
2538
+ if (value.sessionNodeRid === undefined ||
2539
+ value.sessionOwnerNodeGeneration === undefined ||
2540
+ value.bindingGeneration === undefined) {
2541
+ throw new ConfigurationException_1.ZLinkConfigurationException('Duplicate bind callback requires a complete identity.');
2542
+ }
2543
+ return {
2544
+ sessionOwnerNodeRid: value.sessionNodeRid,
2545
+ sessionOwnerNodeGeneration: value.sessionOwnerNodeGeneration,
2546
+ bindingGeneration: value.bindingGeneration
2547
+ };
2548
+ }
2397
2549
  function hasConfiguredLocationStore(registration) {
2398
2550
  return (registration.locations.useInMemoryStores || registration.locations.storeInstance !== undefined);
2399
2551
  }
2400
2552
  function hasExactPeerReadiness(descriptors, local, peers) {
2401
2553
  const replacementDescriptors = descriptors.filter((descriptor) => !((0, routing_id_1.routingIdsEqual)(descriptor.rid, (0, routing_id_1.toBackendRoutingId)(local.routingId)) &&
2402
2554
  descriptor.lifecycleGeneration === local.lifecycleGeneration) &&
2403
- descriptor.state === contracts_1.ZLinkFrameworkRuntimeState.Serving &&
2555
+ descriptor.state === contracts_2.ZLinkFrameworkRuntimeState.Serving &&
2404
2556
  local.applicationVersion !== undefined &&
2405
2557
  descriptor.applicationVersion === local.applicationVersion &&
2406
- descriptor.objectRole === contracts_1.ZLinkObjectRole.Server &&
2558
+ descriptor.objectRole === contracts_2.ZLinkObjectRole.Server &&
2407
2559
  (local.maintenanceWave === undefined || descriptor.maintenanceWave !== local.maintenanceWave));
2408
2560
  return (replacementDescriptors.length > 0 &&
2409
2561
  replacementDescriptors.some((descriptor) => peers.some((peer) => peer.routingId !== null &&
@@ -2478,60 +2630,60 @@ function resolveStreamPayloadCodec(registration) {
2478
2630
  }
2479
2631
  function runtimeStateMetricName(state) {
2480
2632
  switch (state) {
2481
- case contracts_1.ZLinkFrameworkRuntimeState.Preparing:
2633
+ case contracts_2.ZLinkFrameworkRuntimeState.Preparing:
2482
2634
  return 'preparing';
2483
- case contracts_1.ZLinkFrameworkRuntimeState.Serving:
2635
+ case contracts_2.ZLinkFrameworkRuntimeState.Serving:
2484
2636
  return 'serving';
2485
- case contracts_1.ZLinkFrameworkRuntimeState.Relocating:
2637
+ case contracts_2.ZLinkFrameworkRuntimeState.Relocating:
2486
2638
  return 'relocating';
2487
- case contracts_1.ZLinkFrameworkRuntimeState.Relocated:
2639
+ case contracts_2.ZLinkFrameworkRuntimeState.Relocated:
2488
2640
  return 'relocated';
2489
- case contracts_1.ZLinkFrameworkRuntimeState.Draining:
2641
+ case contracts_2.ZLinkFrameworkRuntimeState.Draining:
2490
2642
  return 'draining';
2491
- case contracts_1.ZLinkFrameworkRuntimeState.Stopped:
2643
+ case contracts_2.ZLinkFrameworkRuntimeState.Stopped:
2492
2644
  return 'stopped';
2493
- case contracts_1.ZLinkFrameworkRuntimeState.Error:
2645
+ case contracts_2.ZLinkFrameworkRuntimeState.Error:
2494
2646
  return 'error';
2495
2647
  }
2496
2648
  }
2497
2649
  function relocationModeMetricName(mode) {
2498
- return mode === contracts_1.ZLinkFrameworkRelocationMode.RollingUpdate
2650
+ return mode === contracts_2.ZLinkFrameworkRelocationMode.RollingUpdate
2499
2651
  ? 'rolling_update'
2500
2652
  : 'planned_maintenance';
2501
2653
  }
2502
2654
  function relocationReasonMetricName(reason) {
2503
2655
  switch (reason) {
2504
- case contracts_1.ZLinkFrameworkRelocationReason.None:
2656
+ case contracts_2.ZLinkFrameworkRelocationReason.None:
2505
2657
  return 'none';
2506
- case contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable:
2658
+ case contracts_2.ZLinkFrameworkRelocationReason.TargetUnavailable:
2507
2659
  return 'target_unavailable';
2508
- case contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable:
2660
+ case contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable:
2509
2661
  return 'store_unavailable';
2510
- case contracts_1.ZLinkFrameworkRelocationReason.RelocationDisabled:
2662
+ case contracts_2.ZLinkFrameworkRelocationReason.RelocationDisabled:
2511
2663
  return 'relocation_disabled';
2512
- case contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible:
2664
+ case contracts_2.ZLinkFrameworkRelocationReason.StateIncompatible:
2513
2665
  return 'state_incompatible';
2514
- case contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded:
2666
+ case contracts_2.ZLinkFrameworkRelocationReason.DeadlineExceeded:
2515
2667
  return 'deadline_exceeded';
2516
- case contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed:
2668
+ case contracts_2.ZLinkFrameworkRelocationReason.RelocationFailed:
2517
2669
  return 'relocation_failed';
2518
- case contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady:
2670
+ case contracts_2.ZLinkFrameworkRelocationReason.RuntimeNotReady:
2519
2671
  return 'runtime_not_ready';
2520
- case contracts_1.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported:
2672
+ case contracts_2.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported:
2521
2673
  return 'manual_topology_unsupported';
2522
- case contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested:
2674
+ case contracts_2.ZLinkFrameworkRelocationReason.ShutdownRequested:
2523
2675
  return 'shutdown_requested';
2524
- case contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress:
2676
+ case contracts_2.ZLinkFrameworkRelocationReason.OperationInProgress:
2525
2677
  return 'operation_in_progress';
2526
2678
  }
2527
2679
  }
2528
2680
  function terminationReasonMetricName(reason) {
2529
2681
  switch (reason) {
2530
- case contracts_1.ZLinkFrameworkTerminationReason.None:
2682
+ case contracts_2.ZLinkFrameworkTerminationReason.None:
2531
2683
  return 'none';
2532
- case contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded:
2684
+ case contracts_2.ZLinkFrameworkTerminationReason.DeadlineExceeded:
2533
2685
  return 'deadline_exceeded';
2534
- case contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed:
2686
+ case contracts_2.ZLinkFrameworkTerminationReason.TeardownFailed:
2535
2687
  return 'teardown_failed';
2536
2688
  }
2537
2689
  }
@@ -2614,13 +2766,13 @@ function randomBigIntBelow(exclusiveUpperBound) {
2614
2766
  function relocationReason(reason) {
2615
2767
  switch (reason) {
2616
2768
  case 'deadline_exceeded':
2617
- return contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded;
2769
+ return contracts_2.ZLinkFrameworkRelocationReason.DeadlineExceeded;
2618
2770
  case 'store_unavailable':
2619
- return contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable;
2771
+ return contracts_2.ZLinkFrameworkRelocationReason.StoreUnavailable;
2620
2772
  case 'target_unavailable':
2621
- return contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable;
2773
+ return contracts_2.ZLinkFrameworkRelocationReason.TargetUnavailable;
2622
2774
  default:
2623
- return contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed;
2775
+ return contracts_2.ZLinkFrameworkRelocationReason.RelocationFailed;
2624
2776
  }
2625
2777
  }
2626
2778
  function rewriteAuthorityPayloadForOwner(payload, owner) {
@@ -2635,11 +2787,11 @@ function validateRelocationOptions(options, sourceApplicationVersion) {
2635
2787
  throw new TypeError('Relocation mode is required.');
2636
2788
  }
2637
2789
  const mode = options.mode;
2638
- if (mode !== contracts_1.ZLinkFrameworkRelocationMode.PlannedMaintenance &&
2639
- mode !== contracts_1.ZLinkFrameworkRelocationMode.RollingUpdate) {
2790
+ if (mode !== contracts_2.ZLinkFrameworkRelocationMode.PlannedMaintenance &&
2791
+ mode !== contracts_2.ZLinkFrameworkRelocationMode.RollingUpdate) {
2640
2792
  throw new TypeError('Relocation mode is required.');
2641
2793
  }
2642
- if (options.mode === contracts_1.ZLinkFrameworkRelocationMode.PlannedMaintenance) {
2794
+ if (options.mode === contracts_2.ZLinkFrameworkRelocationMode.PlannedMaintenance) {
2643
2795
  if (options.targetApplicationVersion !== undefined) {
2644
2796
  throw new TypeError('PlannedMaintenance relocation cannot define targetApplicationVersion.');
2645
2797
  }
@@ -2655,7 +2807,7 @@ function blockedRelocation(mode, effectiveTargetApplicationVersion, reason) {
2655
2807
  return {
2656
2808
  mode,
2657
2809
  effectiveTargetApplicationVersion,
2658
- outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
2810
+ outcome: contracts_2.ZLinkFrameworkRelocationOutcome.Blocked,
2659
2811
  reason
2660
2812
  };
2661
2813
  }