@zlink-systems/framework 0.29.1 → 0.30.1

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 (322) hide show
  1. package/LICENSE +150 -68
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
  4. package/dist/contracts/Channels/Calls.d.ts +2 -1
  5. package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -2
  7. package/dist/contracts/Configuration/Configs.d.ts +0 -5
  8. package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
  9. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
  10. package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
  11. package/dist/contracts/Configuration/index.d.ts +1 -1
  12. package/dist/contracts/Handlers/Attributes.d.ts +5 -13
  13. package/dist/contracts/Handlers/Attributes.js +7 -11
  14. package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
  15. package/dist/contracts/Handlers/JsonContract.js +4 -153
  16. package/dist/contracts/Spots/Contracts.d.ts +2 -1
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/internal.js +3 -1
  19. package/dist/nest-integration.d.ts +1 -1
  20. package/dist/nest-integration.js +2 -1
  21. package/dist/runtime/actors/actor-client.d.ts +1 -1
  22. package/dist/runtime/actors/actor-client.js +14 -12
  23. package/dist/runtime/actors/actor-handoff.d.ts +3 -2
  24. package/dist/runtime/actors/actor-handoff.js +15 -7
  25. package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
  26. package/dist/runtime/actors/actor-local-native-join.js +9 -12
  27. package/dist/runtime/actors/actor-remote-wire.js +15 -0
  28. package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
  29. package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
  30. package/dist/runtime/actors/index.d.ts +2 -1
  31. package/dist/runtime/actors/index.js +18 -6
  32. package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
  33. package/dist/runtime/admission.d.ts +1 -1
  34. package/dist/runtime/admission.js +15 -5
  35. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
  36. package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
  37. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
  38. package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
  39. package/dist/runtime/application-jobs/contracts.d.ts +15 -2
  40. package/dist/runtime/backend/contracts/index.d.ts +27 -27
  41. package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
  42. package/dist/runtime/backend/mesh-completion-table.js +160 -50
  43. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
  44. package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
  45. package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
  46. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
  47. package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
  48. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  49. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
  50. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
  51. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
  52. package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
  53. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
  54. package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
  55. package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
  56. package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
  57. package/dist/runtime/backend/runtime-message.d.ts +1 -0
  58. package/dist/runtime/backend/runtime-message.js +5 -0
  59. package/dist/runtime/backend/runtime-values.d.ts +1 -0
  60. package/dist/runtime/backend/runtime-values.js +2 -1
  61. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  62. package/dist/runtime/channels/channel-clients.js +58 -21
  63. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
  64. package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
  65. package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
  66. package/dist/runtime/channels/channel-dispatch-services.js +45 -0
  67. package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
  68. package/dist/runtime/channels/channel-dispatchers.js +27 -26
  69. package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
  70. package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
  71. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  72. package/dist/runtime/channels/channel-envelope.js +83 -8
  73. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  74. package/dist/runtime/channels/channel-outbound-operations.js +8 -8
  75. package/dist/runtime/channels/channel-receive-loops.js +3 -3
  76. package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
  77. package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
  78. package/dist/runtime/channels/channel-runtime-manager.js +12 -12
  79. package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
  80. package/dist/runtime/channels/channel-socket-registry.js +59 -82
  81. package/dist/runtime/channels/channel-transports.d.ts +18 -15
  82. package/dist/runtime/channels/channel-transports.js +48 -31
  83. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  84. package/dist/runtime/channels/local-spot-route-transport.js +2 -1
  85. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
  86. package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
  87. package/dist/runtime/channels/source-spot-router.d.ts +2 -2
  88. package/dist/runtime/channels/source-spot-router.js +4 -4
  89. package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
  90. package/dist/runtime/channels/spot-node-route-transport.js +4 -4
  91. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
  92. package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
  93. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
  94. package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
  95. package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
  96. package/dist/runtime/diagnostics/message-flow.js +3 -3
  97. package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
  98. package/dist/runtime/execution/serial-execution-queue.js +1 -0
  99. package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
  100. package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
  101. package/dist/runtime/foundation/durable-service-request.js +98 -0
  102. package/dist/runtime/foundation/operation-identity.d.ts +1 -0
  103. package/dist/runtime/foundation/operation-identity.js +5 -1
  104. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
  105. package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
  106. package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
  107. package/dist/runtime/foundation/service-liveness-registry.js +57 -44
  108. package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
  109. package/dist/runtime/foundation/service-mailbox.js +2 -1
  110. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
  111. package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
  112. package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
  113. package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
  114. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
  115. package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
  116. package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
  117. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
  118. package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
  119. package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
  120. package/dist/runtime/foundation/service-topology-registry.js +69 -30
  121. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
  122. package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
  123. package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
  124. package/dist/runtime/handlers/handler-instance-scope.js +54 -11
  125. package/dist/runtime/host/actor-packet-relay.js +7 -7
  126. package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
  127. package/dist/runtime/host/application-job-queue.d.ts +28 -9
  128. package/dist/runtime/host/application-job-queue.js +214 -50
  129. package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
  130. package/dist/runtime/host/entry-actor-runtime.js +4 -1
  131. package/dist/runtime/host/index.d.ts +7 -1
  132. package/dist/runtime/host/index.js +154 -126
  133. package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
  134. package/dist/runtime/host/instance-activation-authority.js +89 -25
  135. package/dist/runtime/host/remote-bound-session-relay.js +2 -18
  136. package/dist/runtime/host/route-mesh-runtime.js +1 -1
  137. package/dist/runtime/host/service-relocation-control.d.ts +1 -0
  138. package/dist/runtime/host/service-relocation-control.js +10 -4
  139. package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
  140. package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
  141. package/dist/runtime/host/spot-address-transport.d.ts +1 -0
  142. package/dist/runtime/host/spot-address-transport.js +28 -14
  143. package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
  144. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
  145. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
  146. package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
  147. package/dist/runtime/locations/actor-location-claims.js +34 -19
  148. package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
  149. package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
  150. package/dist/runtime/locations/in-memory-authority-store.js +80 -8
  151. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  152. package/dist/runtime/locations/in-memory-location-store.js +19 -3
  153. package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
  154. package/dist/runtime/locations/lifecycle.d.ts +1 -2
  155. package/dist/runtime/locations/lifecycle.js +2 -5
  156. package/dist/runtime/locations/location-store-repository.d.ts +3 -2
  157. package/dist/runtime/locations/location-store-repository.js +165 -22
  158. package/dist/runtime/locations/resolvers.d.ts +2 -1
  159. package/dist/runtime/locations/resolvers.js +10 -1
  160. package/dist/runtime/locations/runtime.d.ts +1 -1
  161. package/dist/runtime/locations/runtime.js +24 -23
  162. package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
  163. package/dist/runtime/messaging/framework-json-v1.js +38 -294
  164. package/dist/runtime/messaging/packet-name.d.ts +1 -1
  165. package/dist/runtime/messaging/packet-name.js +8 -24
  166. package/dist/runtime/messaging/request-result.d.ts +2 -0
  167. package/dist/runtime/messaging/request-result.js +54 -0
  168. package/dist/runtime/messaging/submission-result.d.ts +2 -1
  169. package/dist/runtime/messaging/submission-result.js +7 -4
  170. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
  171. package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
  172. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
  173. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
  174. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
  175. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
  176. package/dist/runtime/spots/index.d.ts +7 -3
  177. package/dist/runtime/spots/index.js +23 -16
  178. package/dist/runtime/spots/spot-activation.d.ts +3 -1
  179. package/dist/runtime/spots/spot-activation.js +21 -12
  180. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
  181. package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
  182. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
  183. package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
  184. package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
  185. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
  186. package/dist/runtime/spots/spot-entry-activation.js +9 -3
  187. package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
  188. package/dist/runtime/spots/spot-handler-registry.js +18 -8
  189. package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
  190. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
  191. package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
  192. package/dist/runtime/spots/spot-outbound.d.ts +3 -0
  193. package/dist/runtime/spots/spot-outbound.js +24 -15
  194. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
  195. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
  196. package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
  197. package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
  198. package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
  199. package/dist/runtime/spots/spot-timer.js +1 -0
  200. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
  201. package/dist/runtime/streams/stream-session-runtime.js +14 -28
  202. package/package.json +3 -3
  203. package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
  204. package/src/contracts/Channels/Calls.ts +2 -1
  205. package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
  206. package/src/contracts/Configuration/Builders.ts +1 -2
  207. package/src/contracts/Configuration/Configs.ts +0 -6
  208. package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
  209. package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
  210. package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
  211. package/src/contracts/Configuration/index.ts +1 -6
  212. package/src/contracts/Handlers/Attributes.ts +14 -21
  213. package/src/contracts/Handlers/JsonContract.ts +8 -216
  214. package/src/contracts/Spots/Contracts.ts +2 -1
  215. package/src/internal.ts +1 -0
  216. package/src/nest-integration.ts +1 -0
  217. package/src/runtime/actors/actor-client.ts +40 -16
  218. package/src/runtime/actors/actor-handoff.ts +22 -8
  219. package/src/runtime/actors/actor-join-relocation.ts +1 -0
  220. package/src/runtime/actors/actor-local-native-join.ts +17 -26
  221. package/src/runtime/actors/actor-remote-wire.ts +17 -0
  222. package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
  223. package/src/runtime/actors/actor-routed-json-request.ts +10 -2
  224. package/src/runtime/actors/index.ts +19 -5
  225. package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
  226. package/src/runtime/admission.ts +18 -5
  227. package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
  228. package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
  229. package/src/runtime/application-jobs/contracts.ts +28 -2
  230. package/src/runtime/backend/contracts/index.ts +63 -32
  231. package/src/runtime/backend/mesh-completion-table.ts +175 -59
  232. package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
  233. package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
  234. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
  235. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
  236. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
  237. package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
  238. package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
  239. package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
  240. package/src/runtime/backend/raw-binding-port.ts +18 -3
  241. package/src/runtime/backend/runtime-message.ts +6 -0
  242. package/src/runtime/backend/runtime-values.ts +1 -0
  243. package/src/runtime/channels/channel-clients.ts +90 -41
  244. package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
  245. package/src/runtime/channels/channel-dispatch-services.ts +69 -1
  246. package/src/runtime/channels/channel-dispatchers.ts +29 -27
  247. package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
  248. package/src/runtime/channels/channel-envelope.ts +133 -8
  249. package/src/runtime/channels/channel-outbound-operations.ts +22 -8
  250. package/src/runtime/channels/channel-receive-loops.ts +3 -3
  251. package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
  252. package/src/runtime/channels/channel-runtime-manager.ts +29 -12
  253. package/src/runtime/channels/channel-socket-registry.ts +84 -130
  254. package/src/runtime/channels/channel-transports.ts +128 -60
  255. package/src/runtime/channels/local-spot-route-transport.ts +3 -1
  256. package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
  257. package/src/runtime/channels/source-spot-router.ts +8 -4
  258. package/src/runtime/channels/spot-node-route-transport.ts +8 -4
  259. package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
  260. package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
  261. package/src/runtime/diagnostics/message-flow.ts +1 -1
  262. package/src/runtime/execution/serial-execution-queue.ts +2 -0
  263. package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
  264. package/src/runtime/foundation/durable-service-request.ts +137 -0
  265. package/src/runtime/foundation/operation-identity.ts +5 -1
  266. package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
  267. package/src/runtime/foundation/service-liveness-registry.ts +68 -59
  268. package/src/runtime/foundation/service-mailbox.ts +7 -1
  269. package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
  270. package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
  271. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  272. package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
  274. package/src/runtime/foundation/service-topology-registry.ts +103 -42
  275. package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
  276. package/src/runtime/handlers/handler-instance-scope.ts +67 -16
  277. package/src/runtime/host/actor-packet-relay.ts +7 -0
  278. package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
  279. package/src/runtime/host/application-job-queue.ts +249 -48
  280. package/src/runtime/host/entry-actor-runtime.ts +5 -0
  281. package/src/runtime/host/index.ts +224 -160
  282. package/src/runtime/host/instance-activation-authority.ts +132 -27
  283. package/src/runtime/host/remote-bound-session-relay.ts +2 -23
  284. package/src/runtime/host/route-mesh-runtime.ts +1 -1
  285. package/src/runtime/host/service-relocation-control.ts +11 -5
  286. package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
  287. package/src/runtime/host/spot-address-transport.ts +49 -24
  288. package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
  290. package/src/runtime/locations/actor-location-claims.ts +52 -30
  291. package/src/runtime/locations/domain-store-contract.ts +6 -2
  292. package/src/runtime/locations/in-memory-authority-store.ts +113 -9
  293. package/src/runtime/locations/in-memory-location-store.ts +25 -3
  294. package/src/runtime/locations/internal-location-contracts.ts +4 -0
  295. package/src/runtime/locations/lifecycle.ts +8 -26
  296. package/src/runtime/locations/location-store-repository.ts +220 -15
  297. package/src/runtime/locations/resolvers.ts +25 -2
  298. package/src/runtime/locations/runtime.ts +28 -24
  299. package/src/runtime/messaging/framework-json-v1.ts +5 -325
  300. package/src/runtime/messaging/packet-name.ts +5 -25
  301. package/src/runtime/messaging/request-result.ts +58 -0
  302. package/src/runtime/messaging/submission-result.ts +7 -3
  303. package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
  304. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  305. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
  306. package/src/runtime/spots/index.ts +30 -2
  307. package/src/runtime/spots/spot-activation.ts +33 -10
  308. package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
  309. package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
  310. package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
  311. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
  312. package/src/runtime/spots/spot-entry-activation.ts +12 -2
  313. package/src/runtime/spots/spot-handler-registry.ts +41 -8
  314. package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
  315. package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
  316. package/src/runtime/spots/spot-outbound.ts +36 -16
  317. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
  318. package/src/runtime/spots/spot-routing-internal.ts +14 -0
  319. package/src/runtime/spots/spot-runtime-ports.ts +3 -0
  320. package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
  321. package/src/runtime/spots/spot-timer.ts +5 -1
  322. package/src/runtime/streams/stream-session-runtime.ts +13 -30
@@ -3,9 +3,11 @@ 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 application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
6
7
  const location_store_pages_1 = require("../locations/location-store-pages");
7
8
  const stream_wire_1 = require("@zlink-systems/stream-wire");
8
9
  const node_crypto_1 = require("node:crypto");
10
+ const node_util_1 = require("node:util");
9
11
  const contracts_1 = require("../../contracts");
10
12
  const ConfigurationException_1 = require("../../contracts/Configuration/ConfigurationException");
11
13
  const DiagnosticsValidation_1 = require("../../contracts/Configuration/DiagnosticsValidation");
@@ -21,7 +23,7 @@ const actor_message_follow_context_1 = require("../actors/actor-message-follow-c
21
23
  const actor_transport_delivery_gate_1 = require("../actors/actor-transport-delivery-gate");
22
24
  const admission_1 = require("../admission");
23
25
  const application_job_queue_handler_start_gate_1 = require("../application-jobs/application-job-queue-handler-start-gate");
24
- const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
26
+ const application_job_queue_scope_2 = require("../application-jobs/application-job-queue-scope");
25
27
  const backend_1 = require("../backend");
26
28
  const runtime_message_1 = require("../backend/runtime-message");
27
29
  const runtime_values_1 = require("../backend/runtime-values");
@@ -76,7 +78,7 @@ class ZLinkFrameworkRuntimeHost {
76
78
  lifecycleSink;
77
79
  executionState;
78
80
  runtimeState = contracts_1.ZLinkFrameworkRuntimeState.Preparing;
79
- runtimeSequence = 0n;
81
+ runtimeStatus;
80
82
  runtimeObservationSource = Symbol('zlink.framework-runtime');
81
83
  runtimeDeadline;
82
84
  shutdownDeadline;
@@ -152,16 +154,8 @@ class ZLinkFrameworkRuntimeHost {
152
154
  this.runtimeEventPublisher =
153
155
  options.runtimeEventPublisher ?? new diagnostics_1.DefaultZLinkRuntimeEventPublisher();
154
156
  this.metrics = new diagnostics_1.ZLinkRuntimeMetrics(options.registration.metrics?.meterProvider);
155
- this.applicationJobQueue = new application_job_queue_1.ApplicationJobQueue((0, application_job_queue_1.resolveApplicationJobQueueConfiguration)(options.registration.applicationJobQueue, () => (0, application_job_queue_1.nodeEffectiveProcessorCount)(options.registration.worker?.maxThreads)), undefined, () => {
156
- try {
157
- return (this.options.providerResolver
158
- ?.get?.(application_job_queue_handler_start_gate_1.ZLINK_INTERNAL_APPLICATION_JOB_QUEUE_HANDLER_START_GATE)
159
- ?.shouldHoldPermitBeforeHandler() === true);
160
- }
161
- catch {
162
- return false;
163
- }
164
- });
157
+ const handlerStartGate = options.providerResolver?.get?.(application_job_queue_handler_start_gate_1.ZLINK_INTERNAL_APPLICATION_JOB_QUEUE_HANDLER_START_GATE);
158
+ this.applicationJobQueue = new application_job_queue_1.ApplicationJobQueue((0, application_job_queue_1.resolveApplicationJobQueueConfiguration)(options.registration.applicationJobQueue, () => (0, application_job_queue_1.nodeEffectiveProcessorCount)(options.registration.worker?.maxThreads)), undefined, handlerStartGate?.shouldHoldPermitBeforeHandler.bind(handlerStartGate), (error) => (this.errorSink ?? this.preStartErrorSink).reportRuntimeTaskException('logger-provider', error));
165
159
  this.capacityStatus = new host_capacity_status_1.HostCapacityStatusProjection(options.registration.coreHwm, this.applicationJobQueue);
166
160
  this.clientServerRuntime = new topology_runtime_projections_1.ZLinkClientServerRuntimeProjection(() => this.channelRuntime, () => this.runtimeState);
167
161
  this.fanoutRuntime = new topology_runtime_projections_1.ZLinkFanoutRuntimeProjection(() => this.channelRuntime, () => this.runtimeState);
@@ -452,12 +446,12 @@ class ZLinkFrameworkRuntimeHost {
452
446
  },
453
447
  sessionRelocationWire: () => this.serviceRelocation,
454
448
  clearRemoteActorPacketTarget: (actorId) => this.boundSessionRelay.clearRemoteActorPacketTarget(actorId),
455
- prepareApplicationJob: async (preparationSignal) => {
449
+ prepareApplicationJob: async (preparationSignal, origin) => {
456
450
  const runtimeSignal = this.executionState?.abortController.signal;
457
451
  const signal = runtimeSignal === undefined
458
452
  ? preparationSignal
459
453
  : AbortSignal.any([runtimeSignal, preparationSignal]);
460
- const permit = await this.applicationJobQueue.acquire(signal);
454
+ const permit = await this.applicationJobQueue.acquire(signal, origin);
461
455
  let state = 'ready';
462
456
  let closedReason;
463
457
  let abort;
@@ -491,7 +485,7 @@ class ZLinkFrameworkRuntimeHost {
491
485
  state = 'running';
492
486
  signal.removeEventListener('abort', abort);
493
487
  try {
494
- return await (0, application_job_queue_scope_1.runWithApplicationJobPermit)(permit, operation);
488
+ return await (0, application_job_queue_scope_2.runWithApplicationJobPermit)(permit, operation);
495
489
  }
496
490
  finally {
497
491
  state = 'closed';
@@ -508,6 +502,7 @@ class ZLinkFrameworkRuntimeHost {
508
502
  this.serviceRelocation = new service_relocation_host_runtime_1.ZLinkHostServiceRelocationRuntime({
509
503
  registration: options.registration,
510
504
  targetAdmissionSealed: () => this.shutdownOperationStartedAt !== undefined,
505
+ sourceQuiescenceChanged: () => this.publishCurrentRuntimeStatus(),
511
506
  providerResolver: options.providerResolver,
512
507
  locationStore: () => this.locationOwner.currentStores?.locationStore,
513
508
  currentOwner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
@@ -581,6 +576,9 @@ class ZLinkFrameworkRuntimeHost {
581
576
  return this.executionState !== undefined && !this.executionState.abortController.signal.aborted;
582
577
  }
583
578
  get status() {
579
+ return this.publishCurrentRuntimeStatus();
580
+ }
581
+ buildRuntimeStatus() {
584
582
  return {
585
583
  state: this.runtimeState,
586
584
  isReady: (0, runtime_state_projections_1.runtimeStateIsReady)(this.runtimeState),
@@ -590,8 +588,8 @@ class ZLinkFrameworkRuntimeHost {
590
588
  deadline: this.runtimeDeadline,
591
589
  relocationResult: this.runtimeRelocationResult,
592
590
  terminationResult: this.runtimeTerminationResult,
593
- sequence: this.runtimeSequence,
594
- observedAt: new Date()
591
+ sequence: this.runtimeStatus?.sequence ?? 0n,
592
+ observedAt: this.runtimeStatus?.observedAt ?? new Date()
595
593
  };
596
594
  }
597
595
  // Bound listener records of the current runtime generation.
@@ -604,10 +602,11 @@ class ZLinkFrameworkRuntimeHost {
604
602
  return { kind, name, endpoint, observedAt: new Date() };
605
603
  }
606
604
  observe(signal) {
605
+ const status = this.status;
607
606
  const queue = new runtime_observation_queue_1.RuntimeEventQueue(undefined, signal);
608
607
  this.runtimeObservers.add(queue);
609
608
  queue.onClose(() => this.runtimeObservers.delete(queue));
610
- this.publishRuntimeStatus(queue, this.status);
609
+ this.publishRuntimeStatus(queue, status);
611
610
  return queue;
612
611
  }
613
612
  resetCapacityMetrics() {
@@ -770,6 +769,9 @@ class ZLinkFrameworkRuntimeHost {
770
769
  const shutdown = this.routeMeshCoordinator.shutdownHost(this.runtimeDeadline, this.shutdownDeadline.signal);
771
770
  const drain = await shutdown;
772
771
  await unscopedStreamDrain;
772
+ if (drain.kind === 'forceStopped' && drain.error !== undefined) {
773
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('host shutdown', drain.error);
774
+ }
773
775
  await this.stop();
774
776
  if (drain.kind === 'forceStopped') {
775
777
  return this.completeTermination({
@@ -891,12 +893,24 @@ class ZLinkFrameworkRuntimeHost {
891
893
  if (this.runtimeState === state)
892
894
  return;
893
895
  this.runtimeState = state;
894
- this.runtimeSequence += 1n;
895
896
  this.notifyTopologyHostStateChanged();
896
- const status = this.status;
897
+ this.publishCurrentRuntimeStatus();
898
+ }
899
+ publishCurrentRuntimeStatus() {
900
+ const current = this.buildRuntimeStatus();
901
+ if (this.runtimeStatus !== undefined && (0, node_util_1.isDeepStrictEqual)(this.runtimeStatus, current)) {
902
+ return this.runtimeStatus;
903
+ }
904
+ const status = {
905
+ ...current,
906
+ sequence: (this.runtimeStatus?.sequence ?? 0n) + 1n,
907
+ observedAt: new Date()
908
+ };
909
+ this.runtimeStatus = status;
897
910
  for (const observer of this.runtimeObservers) {
898
911
  this.publishRuntimeStatus(observer, status);
899
912
  }
913
+ return status;
900
914
  }
901
915
  publishRuntimeStatus(observer, status) {
902
916
  if ((0, runtime_state_projections_1.runtimeObservationIsTerminal)(status.state)) {
@@ -1245,6 +1259,7 @@ class ZLinkFrameworkRuntimeHost {
1245
1259
  }
1246
1260
  activationNode.registerAsyncInstanceActivationAuthority?.(new instance_activation_authority_1.ZLinkInstanceActivationAuthority({
1247
1261
  store: locationStore,
1262
+ relocationPolicy: (stableType) => this.options.registration.spotNodes.get(meshName)?.instanceSpotFactoryRegistrations?.[stableType]?.relocation.kind,
1248
1263
  relocationStore: this.options.registration.locations.relocationStoreInstance,
1249
1264
  meshName,
1250
1265
  owner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
@@ -1579,6 +1594,8 @@ class ZLinkFrameworkRuntimeHost {
1579
1594
  });
1580
1595
  const coordinator = (this.userSpotCoordinator = new user_spot_creation_coordinator_1.ZLinkUserSpotCreationCoordinator({
1581
1596
  store: locationStore,
1597
+ relocationPolicy: (meshName, stableType) => this.options.registration.spotNodes.get(meshName)?.spotFactoryRegistrations?.[stableType]
1598
+ ?.relocation.kind,
1582
1599
  publishReadyRoute: (meshName, route) => {
1583
1600
  this.cachedLocationSpotRouteResolver?.invalidate?.(route.spot.spotId);
1584
1601
  this.spotNodeRuntime?.meshNode(meshName)?.rememberSpotRoute?.(route);
@@ -1961,96 +1978,49 @@ class ZLinkFrameworkRuntimeHost {
1961
1978
  ownerLeaseGeneration: record.source.ownerLeaseGeneration
1962
1979
  });
1963
1980
  },
1964
- meshRecordDispatcher: (meshName, owner, record) => this.dispatchMeshRecord(meshName, owner, record, this.executionState?.abortController.signal),
1981
+ meshRecordDispatcher: (meshName, owner, record) => this.dispatchMeshRecord(application_job_queue_scope_1.currentApplicationJobOrigin, meshName, owner, record, this.executionState?.abortController.signal),
1965
1982
  activationConcurrency: (meshName) => this.activationAdmission.current(meshName)
1966
1983
  };
1967
1984
  }
1968
- async dispatchMeshRecord(meshName, owner, record, signal) {
1985
+ dispatchMeshNodeRecord(meshName, record, signal) {
1986
+ const control = this.serviceRelocation.tryHandleControl(meshName, record, signal);
1987
+ if (control instanceof Promise)
1988
+ return control.then((handled) => handled ? undefined : this.dispatchMeshNodePayload(meshName, record, signal));
1989
+ if (!control)
1990
+ return this.dispatchMeshNodePayload(meshName, record, signal);
1991
+ }
1992
+ dispatchMeshNodePayload(meshName, record, signal) {
1993
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.NodeRequest && record.parts.length === 1) {
1994
+ const terminal = (0, actors_1.decodeRemoteActorSourceLeaveTerminal)(record.parts[0].data());
1995
+ if (terminal !== undefined) {
1996
+ return this.completeFormalSourceLeave(record, terminal);
1997
+ }
1998
+ }
1999
+ const channelRuntime = this.channelRuntime;
2000
+ if (channelRuntime === undefined) {
2001
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode node-direct dispatch requires the channel runtime.');
2002
+ }
2003
+ return channelRuntime.dispatchMeshRoute(meshName, record, signal);
2004
+ }
2005
+ async completeFormalSourceLeave(record, terminal) {
2006
+ const completed = await this.spotManager?.completeFormalSourceLeaveTerminal(terminal.actorId, terminal.transferId, terminal.succeeded);
2007
+ if (completed !== true) {
2008
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' has no matching formal transfer terminal gate.`);
2009
+ }
2010
+ if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
2011
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' formal transfer terminal acknowledgement failed.`);
2012
+ }
2013
+ return;
2014
+ }
2015
+ dispatchMeshRecord(applicationJobOrigin, meshName, owner, record, signal) {
1969
2016
  if (record.operationKind === service_runtime_contracts_1.OperationKind.ActorJoin) {
1970
2017
  if (this.spotManager === undefined) {
1971
2018
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor join dispatch requires the Spot manager.');
1972
2019
  }
1973
2020
  return this.spotManager.dispatchMeshActorJoin(meshName, owner, record);
1974
2021
  }
1975
- if (record.kind === service_runtime_contracts_1.ReceiveKind.ActorBinding) {
1976
- if (record.kindData?.kind !== 'actorBinding') {
1977
- throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor binding record has no binding generation.');
1978
- }
1979
- const binding = record.kindData;
1980
- const replyBindingFailure = (kind) => {
1981
- const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(kind);
1982
- if (record.replyFailure?.(terminal.terminalResult, terminal.failureCode) !== runtime_values_1.SubmitResult.Ok) {
1983
- throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' failure acknowledgement failed.`);
1984
- }
1985
- };
1986
- const replyBindingSuccess = () => {
1987
- if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
1988
- throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' acknowledgement failed.`);
1989
- }
1990
- };
1991
- const state = this.actorManager?.getState(binding.actor.actorId);
1992
- const nativeActorRef = state?.nativeActorRef;
1993
- if (state === undefined ||
1994
- nativeActorRef === undefined ||
1995
- nativeActorRef.actorId !== binding.actor.actorId ||
1996
- !(0, routing_id_1.routingIdsEqual)(nativeActorRef.nodeRid, binding.actor.nodeRid)) {
1997
- replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
1998
- return;
1999
- }
2000
- if (nativeActorRef.generation !== binding.actor.generation) {
2001
- replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorGenerationStale);
2002
- return;
2003
- }
2004
- const node = state.meshName === meshName ? this.spotNodeRuntime?.meshNode(meshName) : undefined;
2005
- const localStatus = node?.status();
2006
- // ownsLocation tracks local cleanup responsibility, not Actor authority.
2007
- // A relocation target can exact-read committed authority without owning that cleanup.
2008
- if (localStatus === undefined ||
2009
- !(0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.actor.nodeRid) ||
2010
- localStatus.lifecycleGeneration !== binding.actorNodeGeneration ||
2011
- state.locationGeneration !== binding.authorityOwnerGeneration ||
2012
- state.isMoving) {
2013
- replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2014
- return;
2015
- }
2016
- const sessionOwnerIsLocal = (0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.sessionNodeRid) &&
2017
- localStatus.lifecycleGeneration === binding.sessionOwnerNodeGeneration;
2018
- if (binding.transition === 'tombstone') {
2019
- const actorRef = {
2020
- actorId: binding.actor.actorId,
2021
- objectGeneration: binding.actor.generation,
2022
- meshName,
2023
- nodeRid: binding.actor.nodeRid
2024
- };
2025
- if (sessionOwnerIsLocal) {
2026
- (0, application_job_queue_scope_1.releaseApplicationJobPermitBeforeHandler)();
2027
- await this.streamBindingRuntime.retireRemoteBinding(actorRef, binding.sessionRid, binding.bindingGeneration, signal);
2028
- }
2029
- state.retireBoundSessionBinding(binding);
2030
- replyBindingSuccess();
2031
- return;
2032
- }
2033
- const target = this.boundSessionRelay.boundSessions.resolveRemoteBoundSessionTarget(binding.sessionNodeRid, binding.sessionRid);
2034
- if (target === undefined) {
2035
- replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2036
- return;
2037
- }
2038
- const installed = state.installBoundSessionBinding({
2039
- ...target,
2040
- sessionNodeRid: binding.sessionNodeRid,
2041
- sessionRid: binding.sessionRid,
2042
- sessionOwnerNodeGeneration: binding.sessionOwnerNodeGeneration,
2043
- sessionOwnerId: binding.sessionOwnerId,
2044
- sessionOwnerLeaseGeneration: binding.sessionOwnerLeaseGeneration,
2045
- bindingGeneration: binding.bindingGeneration
2046
- });
2047
- if (!installed) {
2048
- replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2049
- return;
2050
- }
2051
- replyBindingSuccess();
2052
- return Promise.resolve();
2053
- }
2022
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.ActorBinding)
2023
+ return this.dispatchMeshActorBinding(meshName, record, signal);
2054
2024
  switch (record.kind) {
2055
2025
  case service_runtime_contracts_1.ReceiveKind.TransferControl:
2056
2026
  if (record.kindData?.kind !== 'transferControl') {
@@ -2067,28 +2037,7 @@ class ZLinkFrameworkRuntimeHost {
2067
2037
  }
2068
2038
  case service_runtime_contracts_1.ReceiveKind.NodeSend:
2069
2039
  case service_runtime_contracts_1.ReceiveKind.NodeRequest: {
2070
- return this.admission.run(meshName, 'RouteMesh node dispatch', async () => {
2071
- if (await this.serviceRelocation.tryHandleControl(meshName, record, signal)) {
2072
- return;
2073
- }
2074
- if (record.kind === service_runtime_contracts_1.ReceiveKind.NodeRequest && record.parts.length === 1) {
2075
- const terminal = (0, actors_1.decodeRemoteActorSourceLeaveTerminal)(record.parts[0].data());
2076
- if (terminal !== undefined) {
2077
- if ((await this.spotManager?.completeFormalSourceLeaveTerminal(terminal.actorId, terminal.transferId, terminal.succeeded)) !== true) {
2078
- throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' has no matching formal transfer terminal gate.`);
2079
- }
2080
- if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
2081
- throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' formal transfer terminal acknowledgement failed.`);
2082
- }
2083
- return;
2084
- }
2085
- }
2086
- const channelRuntime = this.channelRuntime;
2087
- if (channelRuntime === undefined) {
2088
- throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode node-direct dispatch requires the channel runtime.');
2089
- }
2090
- return await channelRuntime.dispatchMeshRoute(meshName, record, signal);
2091
- });
2040
+ return this.admission.run(meshName, 'RouteMesh node dispatch', () => this.dispatchMeshNodeRecord(meshName, record, signal));
2092
2041
  }
2093
2042
  case service_runtime_contracts_1.ReceiveKind.SpotSend:
2094
2043
  case service_runtime_contracts_1.ReceiveKind.SpotRequest:
@@ -2109,13 +2058,92 @@ class ZLinkFrameworkRuntimeHost {
2109
2058
  if (this.spotManager === undefined) {
2110
2059
  throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor dispatch requires the Spot manager.');
2111
2060
  }
2112
- return this.admission.run(meshName, 'RouteMesh Actor dispatch', () => this.spotManager.dispatchMeshActor(meshName, owner, record));
2061
+ return this.admission.run(meshName, 'RouteMesh Actor dispatch', () => this.spotManager.dispatchMeshActor(applicationJobOrigin(), meshName, owner, record));
2113
2062
  case service_runtime_contracts_1.ReceiveKind.SendReady:
2114
2063
  return Promise.resolve();
2115
2064
  default:
2116
2065
  throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode record kind '${record.kind}' does not yet have a registered framework consumer.`);
2117
2066
  }
2118
2067
  }
2068
+ async dispatchMeshActorBinding(meshName, record, signal) {
2069
+ if (record.kindData?.kind !== 'actorBinding') {
2070
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor binding record has no binding generation.');
2071
+ }
2072
+ const binding = record.kindData;
2073
+ const replyBindingFailure = (kind) => {
2074
+ const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(kind);
2075
+ if (record.replyFailure?.(terminal.terminalResult, terminal.failureCode) !== runtime_values_1.SubmitResult.Ok) {
2076
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' failure acknowledgement failed.`);
2077
+ }
2078
+ };
2079
+ const replyBindingSuccess = () => {
2080
+ if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
2081
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' acknowledgement failed.`);
2082
+ }
2083
+ };
2084
+ const state = this.actorManager?.getState(binding.actor.actorId);
2085
+ const nativeActorRef = state?.nativeActorRef;
2086
+ if (state === undefined ||
2087
+ nativeActorRef === undefined ||
2088
+ nativeActorRef.actorId !== binding.actor.actorId ||
2089
+ !(0, routing_id_1.routingIdsEqual)(nativeActorRef.nodeRid, binding.actor.nodeRid)) {
2090
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2091
+ return;
2092
+ }
2093
+ if (nativeActorRef.generation !== binding.actor.generation) {
2094
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorGenerationStale);
2095
+ return;
2096
+ }
2097
+ const node = state.meshName === meshName ? this.spotNodeRuntime?.meshNode(meshName) : undefined;
2098
+ const localStatus = node?.status();
2099
+ // ownsLocation tracks local cleanup responsibility, not Actor authority.
2100
+ // A relocation target can exact-read committed authority without owning that cleanup.
2101
+ if (localStatus === undefined ||
2102
+ !(0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.actor.nodeRid) ||
2103
+ localStatus.lifecycleGeneration !== binding.actorNodeGeneration ||
2104
+ state.locationGeneration !== binding.authorityOwnerGeneration ||
2105
+ state.isMoving) {
2106
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2107
+ return;
2108
+ }
2109
+ const sessionOwnerIsLocal = (0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.sessionNodeRid) &&
2110
+ localStatus.lifecycleGeneration === binding.sessionOwnerNodeGeneration;
2111
+ if (binding.transition === 'tombstone') {
2112
+ const actorRef = {
2113
+ actorId: binding.actor.actorId,
2114
+ objectGeneration: binding.actor.generation,
2115
+ meshName,
2116
+ nodeRid: binding.actor.nodeRid
2117
+ };
2118
+ if (sessionOwnerIsLocal) {
2119
+ (0, application_job_queue_scope_2.releaseApplicationJobPermitBeforeHandler)();
2120
+ await this.streamBindingRuntime.retireRemoteBinding(actorRef, binding.sessionRid, binding.bindingGeneration, signal);
2121
+ }
2122
+ state.retireBoundSessionBinding(binding);
2123
+ replyBindingSuccess();
2124
+ return;
2125
+ }
2126
+ const target = this.boundSessionRelay.boundSessions.resolveRemoteBoundSessionTarget(binding.sessionNodeRid, binding.sessionRid);
2127
+ if (target === undefined) {
2128
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2129
+ return;
2130
+ }
2131
+ const installed = state.installBoundSessionBinding({
2132
+ ...target,
2133
+ sessionNodeRid: binding.sessionNodeRid,
2134
+ sessionRid: binding.sessionRid,
2135
+ sessionOwnerNodeGeneration: binding.sessionOwnerNodeGeneration,
2136
+ sessionOwnerId: binding.sessionOwnerId,
2137
+ sessionOwnerLeaseGeneration: binding.sessionOwnerLeaseGeneration,
2138
+ bindingGeneration: binding.bindingGeneration
2139
+ });
2140
+ if (!installed) {
2141
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
2142
+ return;
2143
+ }
2144
+ replyBindingSuccess();
2145
+ return Promise.resolve();
2146
+ }
2119
2147
  submitLocalMeshRoute(meshName, sourceNodeRid, parts) {
2120
2148
  const state = this.executionState;
2121
2149
  const channelRuntime = this.channelRuntime;
@@ -2143,9 +2171,9 @@ class ZLinkFrameworkRuntimeHost {
2143
2171
  try {
2144
2172
  state.taskRunner.runDetached('mesh-node-local-route-dispatch', async () => {
2145
2173
  try {
2146
- const permit = await this.applicationJobQueue.acquire(state.abortController.signal);
2174
+ const permit = await this.applicationJobQueue.acquire(state.abortController.signal, 'local');
2147
2175
  permit.markApplicationQueued();
2148
- await (0, application_job_queue_scope_1.runWithApplicationJobPermit)(permit, () => channelRuntime.dispatchLocalMeshRoute(meshName, sourceNodeRid, ownedParts));
2176
+ await (0, application_job_queue_scope_2.runWithApplicationJobPermit)(permit, () => channelRuntime.dispatchLocalMeshRoute(meshName, sourceNodeRid, ownedParts));
2149
2177
  }
2150
2178
  finally {
2151
2179
  for (const part of ownedParts)
@@ -5,6 +5,7 @@ import type { ServiceSpotState } from '../foundation/service-stateful-registry';
5
5
  import type { ServiceInstanceActivationTarget, ServiceInstanceRouteFence } from '../foundation/service-stateful-wire-codec';
6
6
  import { type ServiceInstanceActivationRecoveryEnvelope } from '../foundation/service-instance-activation-recovery-codec';
7
7
  export interface ZLinkInstanceActivationAuthorityOptions {
8
+ readonly relocationPolicy?: (stableType: string) => import('../locations/internal-location-contracts').ZLinkObjectReserveRequest['actorRelocationPolicy'];
8
9
  readonly store: ZLinkObjectCreationStore & ZLinkAuthorityStore;
9
10
  readonly relocationStore?: ZLinkRelocationStore;
10
11
  readonly meshName: string;
@@ -16,7 +17,7 @@ export declare class ZLinkInstanceActivationAuthority implements ServiceAsyncIns
16
17
  private readonly options;
17
18
  private readonly pending;
18
19
  constructor(options: ZLinkInstanceActivationAuthorityOptions);
19
- read(target: ServiceInstanceActivationTarget): Promise<ServiceInstanceAuthorityRead>;
20
+ read(target: ServiceInstanceActivationTarget, instanceIntent?: true, activation?: ServiceInstanceActivationRecoveryEnvelope, acceptsLocal?: (route: ServiceInstanceRouteFence) => boolean): Promise<ServiceInstanceAuthorityRead>;
20
21
  reserve(activation: Omit<ServiceInstanceActivationRecoveryEnvelope, 'targetMeshName'>, signal?: AbortSignal): Promise<ServiceInstanceAuthorityReserve>;
21
22
  resume(target: ServiceInstanceActivationTarget, pending: ServicePendingInstanceActivation): Promise<ServiceInstanceActivationReservation>;
22
23
  commit(target: ServiceInstanceActivationTarget, reservation: ServiceInstanceActivationReservation, spot: ServiceSpotState, deadlineUnixMs?: bigint): Promise<{
@@ -17,9 +17,71 @@ class ZLinkInstanceActivationAuthority {
17
17
  constructor(options) {
18
18
  this.options = options;
19
19
  }
20
- async read(target) {
21
- const current = await this.options.store.readAuthority(authorityKey(target.targetSpotId));
22
- return current.kind === 'snapshot' ? readyRead(current, target) : { kind: 'missing' };
20
+ async read(target, instanceIntent, activation, acceptsLocal) {
21
+ const key = authorityKey(target.targetSpotId);
22
+ const current = await this.options.store.readAuthority(key);
23
+ if (current.kind !== 'snapshot')
24
+ return { kind: 'missing' };
25
+ const ready = (0, service_authority_payload_codec_1.decodeServiceInstanceAuthorityPayload)(current.payload);
26
+ const resolved = readyRead(current, target, ready);
27
+ if (ready?.state === 'ready' &&
28
+ resolved.kind === 'ready' &&
29
+ acceptsLocal?.(resolved.route) === true) {
30
+ return resolved;
31
+ }
32
+ if (activation !== undefined &&
33
+ current.allocation.objectKind === 'instance_spot' &&
34
+ (0, routing_id_1.routingIdsEqual)(current.allocation.descriptor.rid, target.targetNodeRid) &&
35
+ current.allocation.descriptorLifecycleGeneration === target.targetNodeGeneration) {
36
+ const reference = current.pendingCreation?.requestContentReference ?? ready?.activationRecovery?.reference;
37
+ if (reference !== undefined) {
38
+ const root = await this.options.relocationStore?.read((0, relocation_blob_1.relocationBlobReference)(reference));
39
+ if (root?.kind !== 'found') {
40
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.DataLost, 'Stored Instance activation is missing.');
41
+ }
42
+ let stored;
43
+ try {
44
+ stored = (0, service_instance_activation_recovery_codec_1.decodeInstanceActivationRecoveryEnvelope)(root.bytes);
45
+ }
46
+ catch (error) {
47
+ if (!(error instanceof TypeError || error instanceof RangeError))
48
+ throw error;
49
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Stored Instance activation is invalid.');
50
+ }
51
+ if (stored.operation.high === activation.operation.high &&
52
+ stored.operation.low === activation.operation.low &&
53
+ (stored.targetMeshName !== activation.targetMeshName ||
54
+ stored.target.stableType !== target.stableType ||
55
+ stored.target.descriptorVersion !== target.descriptorVersion ||
56
+ stored.deadlineUnixMs !== activation.deadlineUnixMs ||
57
+ (stored.metadataFrame === undefined) !== (activation.metadataFrame === undefined) ||
58
+ (stored.metadataFrame !== undefined &&
59
+ activation.metadataFrame !== undefined &&
60
+ Buffer.compare(stored.metadataFrame, activation.metadataFrame) !== 0))) {
61
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Instance route does not match the stored activation.');
62
+ }
63
+ }
64
+ }
65
+ if (instanceIntent === true &&
66
+ current.allocation.state === 'active' &&
67
+ ready?.state === 'ready') {
68
+ if (current.allocation.objectKind !== 'instance_spot' ||
69
+ current.allocation.stableType !== target.stableType) {
70
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotTypeMismatch, 'Instance activation type does not match the current authority.');
71
+ }
72
+ const released = await this.options.store.releaseEndedReservation?.(key, current.storeVersion.value, undefined, {
73
+ key: { kind: 'instance_spot', globalId: target.targetSpotId },
74
+ intent: { stableType: target.stableType },
75
+ actorRelocationPolicy: this.options.relocationPolicy?.(target.stableType)
76
+ });
77
+ if (released === true)
78
+ return { kind: 'missing' };
79
+ const refreshed = await this.options.store.readAuthority(key);
80
+ return refreshed.kind === 'snapshot'
81
+ ? readyRead(refreshed, target, (0, service_authority_payload_codec_1.decodeServiceInstanceAuthorityPayload)(refreshed.payload))
82
+ : { kind: 'missing' };
83
+ }
84
+ return resolved;
23
85
  }
24
86
  async reserve(activation, signal) {
25
87
  const target = activation.target;
@@ -49,6 +111,7 @@ class ZLinkInstanceActivationAuthority {
49
111
  try {
50
112
  reserved = await this.options.store.reserve({
51
113
  key: { kind: 'instance_spot', globalId: target.targetSpotId },
114
+ actorRelocationPolicy: this.options.relocationPolicy?.(target.stableType),
52
115
  intent: {
53
116
  stableType: target.stableType,
54
117
  requestContentReference: stored.reference.value,
@@ -207,7 +270,7 @@ class ZLinkInstanceActivationAuthority {
207
270
  }
208
271
  const current = await this.options.store.readAuthority(authorityKey(target.targetSpotId));
209
272
  if (current.kind === 'snapshot') {
210
- const ready = readyRead(current, target);
273
+ const ready = readyRead(current, target, (0, service_authority_payload_codec_1.decodeServiceInstanceAuthorityPayload)(current.payload));
211
274
  if (ready.kind === 'ready') {
212
275
  this.pending.delete(reservation.token);
213
276
  return { kind: 'lost', route: ready.route };
@@ -236,7 +299,7 @@ class ZLinkInstanceActivationAuthority {
236
299
  }
237
300
  const recovery = decoded.activationRecovery;
238
301
  if (recovery === undefined)
239
- return routeFromSnapshot(current);
302
+ return routeFromSnapshot(current, decoded.spotId);
240
303
  let completed = current;
241
304
  if (recovery.replayCursor < recovery.inboxSequence) {
242
305
  const cursorStored = await this.options.store.compareExchangeAuthority(key, current.storeVersion, {
@@ -338,19 +401,16 @@ class ZLinkInstanceActivationAuthority {
338
401
  }
339
402
  }
340
403
  exports.ZLinkInstanceActivationAuthority = ZLinkInstanceActivationAuthority;
341
- function readyRead(snapshot, target) {
342
- const decoded = (0, service_authority_payload_codec_1.decodeServiceReadySpotAuthority)(snapshot.payload) ??
343
- (0, service_authority_payload_codec_1.decodeServiceClosingSpotAuthority)(snapshot.payload);
344
- const creating = (0, service_authority_payload_codec_1.decodeServiceInstanceAuthorityPayload)(snapshot.payload);
345
- if (creating?.state === 'coldActivating' &&
404
+ function readyRead(snapshot, target, decoded) {
405
+ if (decoded?.state === 'coldActivating' &&
346
406
  snapshot.allocation.objectKind === 'instance_spot' &&
347
- creating.stableType === target.stableType &&
348
- creating.spotId === target.targetSpotId &&
349
- creating.ownerId === snapshot.ownerId &&
350
- creating.ownerLeaseGeneration === snapshot.ownerLeaseGeneration &&
351
- creating.ownerMeshName === snapshot.allocation.descriptor.meshName &&
352
- creating.ownerNodeGeneration === snapshot.allocation.descriptorLifecycleGeneration &&
353
- (0, routing_id_1.routingIdsEqual)(creating.ownerNodeRid, snapshot.allocation.descriptor.rid) &&
407
+ decoded.stableType === target.stableType &&
408
+ decoded.spotId === target.targetSpotId &&
409
+ decoded.ownerId === snapshot.ownerId &&
410
+ decoded.ownerLeaseGeneration === snapshot.ownerLeaseGeneration &&
411
+ decoded.ownerMeshName === snapshot.allocation.descriptor.meshName &&
412
+ decoded.ownerNodeGeneration === snapshot.allocation.descriptorLifecycleGeneration &&
413
+ (0, routing_id_1.routingIdsEqual)(decoded.ownerNodeRid, snapshot.allocation.descriptor.rid) &&
354
414
  (0, routing_id_1.routingIdsEqual)(target.targetNodeRid, snapshot.allocation.descriptor.rid) &&
355
415
  target.targetNodeGeneration === snapshot.allocation.descriptorLifecycleGeneration) {
356
416
  return {
@@ -360,7 +420,8 @@ function readyRead(snapshot, target) {
360
420
  authority: snapshot
361
421
  };
362
422
  }
363
- if (decoded?.kind !== 'instance_spot' ||
423
+ if (decoded === undefined ||
424
+ decoded.state === 'coldActivating' ||
364
425
  decoded.stableType !== target.stableType ||
365
426
  decoded.spotId !== target.targetSpotId ||
366
427
  snapshot.allocation.objectKind !== 'instance_spot' ||
@@ -374,7 +435,7 @@ function readyRead(snapshot, target) {
374
435
  target.targetNodeGeneration !== snapshot.allocation.descriptorLifecycleGeneration) {
375
436
  return { kind: 'missing' };
376
437
  }
377
- return { kind: 'ready', route: routeFromSnapshot(snapshot), authority: snapshot };
438
+ return { kind: 'ready', route: routeFromSnapshot(snapshot, decoded.spotId), authority: snapshot };
378
439
  }
379
440
  function requireCommitIdentity(target, reservation, creating, spot, meshName) {
380
441
  if (creating.allocation.state !== 'reserved' ||
@@ -392,16 +453,19 @@ function requireCommitIdentity(target, reservation, creating, spot, meshName) {
392
453
  throw new Error('Instance activation Ready identity does not match its exact reservation.');
393
454
  }
394
455
  }
395
- function routeFromSnapshot(snapshot) {
396
- const decoded = (0, service_authority_payload_codec_1.decodeServiceReadySpotAuthority)(snapshot.payload) ??
397
- (0, service_authority_payload_codec_1.decodeServiceClosingSpotAuthority)(snapshot.payload);
398
- if (decoded?.kind !== 'instance_spot') {
399
- throw new Error('Instance authority is not Ready.');
456
+ function routeFromSnapshot(snapshot, spotId) {
457
+ if (spotId === undefined) {
458
+ const decoded = (0, service_authority_payload_codec_1.decodeServiceReadySpotAuthority)(snapshot.payload) ??
459
+ (0, service_authority_payload_codec_1.decodeServiceClosingSpotAuthority)(snapshot.payload);
460
+ if (decoded?.kind !== 'instance_spot') {
461
+ throw new Error('Instance authority is not Ready.');
462
+ }
463
+ spotId = decoded.spotId;
400
464
  }
401
465
  return {
402
466
  targetNodeRid: String(snapshot.allocation.descriptor.rid),
403
467
  targetNodeGeneration: snapshot.allocation.descriptorLifecycleGeneration,
404
- targetSpotId: decoded.spotId,
468
+ targetSpotId: spotId,
405
469
  objectGeneration: snapshot.objectGeneration,
406
470
  ownerId: snapshot.ownerId,
407
471
  authorityOwnerGeneration: snapshot.authorityOwnerGeneration,