@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
@@ -36,7 +36,7 @@ class ZLinkSpotActivationLifecycle {
36
36
  const serial = new spot_serial_turn_executor_1.ZLinkSpotSerialTurnExecutor(executionMode === contracts_1.ZLinkUserSpotExecutionMode.SpotWide, spotId);
37
37
  const serialExecutor = new spot_serial_executor_1.ZLinkSpotSerialExecutor(serial, executionMode, spotId);
38
38
  const actorHandlers = new actors_1.ZLinkSpotActorHandlerRegistryRuntime();
39
- const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers);
39
+ const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers, this.options.providerResolver);
40
40
  (0, spot_handler_registry_1.applySpotHandlerRegistrations)(handlers, implementation, objectKind === 'user_spot'
41
41
  ? {
42
42
  actorSendHandlers: this.options.spotActorSendHandlers,
@@ -154,7 +154,7 @@ class ZLinkSpotActivationLifecycle {
154
154
  const serial = serialOwner?.serial ?? new spot_serial_turn_executor_1.ZLinkSpotSerialTurnExecutor(true, spotId);
155
155
  const serialExecutor = new spot_serial_executor_1.ZLinkSpotSerialExecutor(serial, contracts_1.ZLinkUserSpotExecutionMode.SpotWide, spotId);
156
156
  const actorHandlers = new actors_1.ZLinkSpotActorHandlerRegistryRuntime();
157
- const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers);
157
+ const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers, this.options.providerResolver);
158
158
  const instanceHandlers = new spot_handler_registry_1.DefaultZLinkInstanceSpotHandlerRegistry(handlers);
159
159
  (0, spot_handler_registry_1.applySpotHandlerRegistrations)(handlers, implementation, {
160
160
  packetHandlers: this.options.spotPacketHandlers
@@ -268,7 +268,7 @@ class ZLinkSpotActivationLifecycle {
268
268
  const serial = new spot_serial_turn_executor_1.ZLinkSpotSerialTurnExecutor(executionMode === contracts_1.ZLinkUserSpotExecutionMode.SpotWide, spotId);
269
269
  const serialExecutor = new spot_serial_executor_1.ZLinkSpotSerialExecutor(serial, executionMode, spotId);
270
270
  const actorHandlers = new actors_1.ZLinkSpotActorHandlerRegistryRuntime();
271
- const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers);
271
+ const handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(actorHandlers, this.options.providerResolver);
272
272
  (0, spot_handler_registry_1.applySpotHandlerRegistrations)(handlers, spotType, {
273
273
  actorSendHandlers: this.options.spotActorSendHandlers,
274
274
  actorRequestHandlers: this.options.spotActorRequestHandlers,
@@ -477,12 +477,12 @@ class ZLinkSpotActivationLifecycle {
477
477
  async cleanupFailedIncarnation(activation) {
478
478
  await this.cleanupActivation(activation, activation.meshName, false, undefined, contracts_1.ZLinkSpotCloseReason.ExplicitClose, undefined, true);
479
479
  }
480
- async dispatchActorPacket(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
481
- return await this.actorAdmission.dispatchActorPacket(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin);
480
+ async dispatchActorPacket(origin, activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
481
+ return await this.actorAdmission.dispatchActorPacket(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin);
482
482
  }
483
483
  /** @internal Dispatches a held Actor record after its handoff owner releases it. */
484
- dispatchActorPacketDirect(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
485
- return this.actorAdmission.dispatchActorPacketDirect(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
484
+ dispatchActorPacketDirect(origin, activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
485
+ return this.actorAdmission.dispatchActorPacketDirect(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
486
486
  }
487
487
  /** @internal Atomically restores one durable Actor packet prefix. */
488
488
  admitActorPacketPrefix(activation, actorId, records) {
@@ -571,7 +571,9 @@ class ZLinkSpotActivationLifecycle {
571
571
  catch (error) {
572
572
  // An OnClosing failure is diagnostic and cleanup continues. It is
573
573
  // returned so host shutdown can classify its teardown outcome.
574
- this.options.closeErrorSink?.reportRuntimeTaskException(`spot ${String(activation.spotId)} onClosing`, error);
574
+ if (reason !== contracts_1.ZLinkSpotCloseReason.HostShutdown) {
575
+ this.options.closeErrorSink?.reportRuntimeTaskException(`spot ${String(activation.spotId)} onClosing`, error);
576
+ }
575
577
  closingFailure = error;
576
578
  }
577
579
  }
@@ -598,7 +600,12 @@ class ZLinkSpotActivationLifecycle {
598
600
  });
599
601
  }
600
602
  if (!state.nativeDisposed) {
601
- await cleanup(() => activation.nativeSpot?.dispose(), () => {
603
+ await cleanup(async () => {
604
+ if (reason === contracts_1.ZLinkSpotCloseReason.HostShutdown) {
605
+ await this.options.releaseActorMembers?.(locationMeshName, activation.spotId);
606
+ }
607
+ await activation.nativeSpot?.dispose();
608
+ }, () => {
602
609
  state.nativeDisposed = true;
603
610
  });
604
611
  }
@@ -617,9 +624,11 @@ class ZLinkSpotActivationLifecycle {
617
624
  state.locationReleased = true;
618
625
  });
619
626
  }
620
- if (errors.length === 1)
621
- throw errors[0];
622
- if (errors.length > 1) {
627
+ if (errors.length > 0) {
628
+ if (closingFailure !== undefined)
629
+ errors.unshift(closingFailure);
630
+ if (errors.length === 1)
631
+ throw errors[0];
623
632
  throw new AggregateError(errors, `Spot '${activation.spotId}' cleanup failed.`);
624
633
  }
625
634
  return closingFailure;
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type { ActorRef } from '../../contracts';
2
3
  import type { Message } from '../../contracts/Common/Message';
3
4
  import type { ZLinkMessageFollowOrigin } from '../foundation/service-runtime-contracts';
@@ -10,7 +11,7 @@ type AdmissionOptions = Pick<ZLinkSpotActivationLifecycleOptions, 'actorHandoffR
10
11
  export declare class ZLinkSpotActorAdmissionCoordinator {
11
12
  private readonly options;
12
13
  constructor(options: AdmissionOptions);
13
- dispatchActorPacket(activation: ZLinkSpotActivation, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin): Promise<unknown>;
14
+ dispatchActorPacket(origin: ApplicationJobOrigin, activation: ZLinkSpotActivation, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin): Promise<unknown>;
14
15
  attachNativeActorJoinDispatch(activation: ZLinkSpotActivation, nativeSpot: ZLinkBackendSpot | undefined): ZLinkSpotActorJoinDispatch | undefined;
15
16
  private dispatchActorPacketInActorTurn;
16
17
  private commitTransferredActorTransaction;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkSpotActorAdmissionCoordinator = void 0;
4
+ const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
4
5
  const actor_handoff_1 = require("../actors/actor-handoff");
5
6
  const routing_id_1 = require("../routing-id");
6
7
  const spot_actor_join_dispatch_1 = require("./spot-actor-join-dispatch");
@@ -10,11 +11,11 @@ class ZLinkSpotActorAdmissionCoordinator {
10
11
  constructor(options) {
11
12
  this.options = options;
12
13
  }
13
- async dispatchActorPacket(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
14
- const handoff = this.options.actorHandoffRuntime?.capture(actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, undefined, messageFollowOrigin, (replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef) => this.dispatchActorPacketDirect(activation, actorId, replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef));
14
+ async dispatchActorPacket(origin, activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
15
+ const handoff = this.options.actorHandoffRuntime?.capture(origin, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, undefined, messageFollowOrigin, (replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef) => this.dispatchActorPacketDirect(origin, activation, actorId, replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef));
15
16
  if (handoff !== undefined)
16
17
  return await handoff;
17
- return await this.dispatchActorPacketDirect(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
18
+ return await this.dispatchActorPacketDirect(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
18
19
  }
19
20
  attachNativeActorJoinDispatch(activation, nativeSpot) {
20
21
  if (nativeSpot === undefined)
@@ -39,7 +40,7 @@ class ZLinkSpotActorAdmissionCoordinator {
39
40
  commitTransferredActor: (actor, backlog, sealedSession) => this.commitTransferredActorTransaction(activation, actor, backlog, sealedSession)
40
41
  },
41
42
  packets: {
42
- handle: (delivery) => this.dispatchActorPacket(activation, delivery.actorId, delivery.parts, delivery.returnResponse, delivery.remoteBoundSessionTarget, delivery.fallbackActorRef),
43
+ handle: (delivery) => this.dispatchActorPacket('remote', activation, delivery.actorId, delivery.parts, delivery.returnResponse, delivery.remoteBoundSessionTarget, delivery.fallbackActorRef),
43
44
  bindRemoteSession: (actor, sourceNodeRid, sourceSessionRid) => {
44
45
  const node = this.options.nativeSpotNodeProvider?.(activation.meshName);
45
46
  if (node === undefined || (0, routing_id_1.routingIdsEqual)(sourceNodeRid, node.routingId))
@@ -63,8 +64,8 @@ class ZLinkSpotActorAdmissionCoordinator {
63
64
  return nativeDispatch;
64
65
  }
65
66
  /** @internal Dispatches a coordinator-owned replay without recapturing it. */
66
- dispatchActorPacketDirect(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
67
- return activation.executeActor(actorId, (actorSerial) => this.dispatchActorPacketInActorTurn(activation, actorSerial, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal));
67
+ dispatchActorPacketDirect(origin, activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
68
+ return activation.executeActor(actorId, (actorSerial) => this.dispatchActorPacketInActorTurn(origin, activation, actorSerial, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal));
68
69
  }
69
70
  /**
70
71
  * Atomically restores one durable packet prefix at the Actor FIFO tail.
@@ -75,7 +76,7 @@ class ZLinkSpotActorAdmissionCoordinator {
75
76
  */
76
77
  admitActorPacketPrefix(activation, actorId, records) {
77
78
  const terminals = activation.admitActorDurablePrefix(actorId, records.map((record) => ({
78
- operation: (executeChild) => record.drain((parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => executeChild((actorSerial) => this.dispatchActorPacketInActorTurn(activation, actorSerial, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef))),
79
+ operation: (executeChild) => record.drain((parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => executeChild((actorSerial) => this.dispatchActorPacketInActorTurn((0, application_job_queue_scope_1.currentApplicationJobOrigin)(), activation, actorSerial, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef))),
79
80
  preparation: record.preparation,
80
81
  workOptions: { payloadBytes: record.payloadBytes }
81
82
  })));
@@ -89,7 +90,7 @@ class ZLinkSpotActorAdmissionCoordinator {
89
90
  });
90
91
  return { terminal };
91
92
  }
92
- dispatchActorPacketInActorTurn(activation, actorSerial, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
93
+ dispatchActorPacketInActorTurn(origin, activation, actorSerial, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
93
94
  return new spot_actor_packet_dispatch_1.ZLinkSpotActorPacketDispatch({
94
95
  spot: activation.spot,
95
96
  spotId: () => String(activation.spotId),
@@ -107,7 +108,7 @@ class ZLinkSpotActorAdmissionCoordinator {
107
108
  messageSerializers: this.options.messageSerializers,
108
109
  dispatchErrors: this.options.dispatchErrors,
109
110
  routeToActorJoinPrewarm: this.options.routeToActorJoinPrewarm
110
- }).dispatch(actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
111
+ }).dispatch(origin, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
111
112
  }
112
113
  async commitTransferredActorTransaction(activation, actor, backlog, sealedSession) {
113
114
  const transfer = this.options.actorTransferRuntime;
@@ -140,7 +141,7 @@ class ZLinkSpotActorAdmissionCoordinator {
140
141
  }
141
142
  }
142
143
  async replayActorBacklog(activation, actor, backlog) {
143
- return await (0, actor_handoff_1.replayActorHandoffBacklog)(backlog, (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => this.dispatchActorPacketDirect(activation, actor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef), (index) => this.options.runtimeEventPublisher?.publish({
144
+ return await (0, actor_handoff_1.replayActorHandoffBacklog)(backlog, (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => this.dispatchActorPacketDirect('remote', activation, actor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef), (index) => this.options.runtimeEventPublisher?.publish({
144
145
  sourceName: 'zlink.framework.actor-handoff',
145
146
  timestamp: new Date(),
146
147
  marker: 'backlog_enqueued',
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type { ActorRef, RoutingId, ZLinkActor, ZLinkMessageSerializer, ZLinkSpot } from '../../contracts';
2
3
  import type { Message } from '../../contracts/Common/Message';
3
4
  import type { ZLinkRemoteBoundSessionTarget } from '../actors';
@@ -17,6 +18,7 @@ export interface ZLinkActorRequestTerminal {
17
18
  }
18
19
  /** One admitted Actor packet and the routing context that must move with it. */
19
20
  export interface ZLinkActorPacketDelivery {
21
+ readonly origin: ApplicationJobOrigin;
20
22
  readonly actorId: string;
21
23
  readonly parts: readonly Message[];
22
24
  readonly returnResponse: boolean;
@@ -35,6 +37,7 @@ export interface ZLinkActorPacketDelivery {
35
37
  * unchanged.
36
38
  */
37
39
  export type ZLinkRouteToActorJoinPrewarm = (actorId: string, objectGeneration: bigint, arrival: {
40
+ readonly origin: ApplicationJobOrigin;
38
41
  readonly header: Buffer;
39
42
  readonly payload: Buffer;
40
43
  readonly returnResponse: boolean;
@@ -69,7 +72,7 @@ interface ZLinkSpotActorPacketDispatchOptions {
69
72
  export declare class ZLinkSpotActorPacketDispatch {
70
73
  private readonly options;
71
74
  constructor(options: ZLinkSpotActorPacketDispatchOptions);
72
- dispatch(actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: ZLinkActorRequestTerminal): Promise<unknown>;
75
+ dispatch(origin: ApplicationJobOrigin, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: ZLinkActorRequestTerminal): Promise<unknown>;
73
76
  dispatchDelivery(delivery: ZLinkActorPacketDelivery): Promise<unknown>;
74
77
  private handleMissingActor;
75
78
  /**
@@ -17,8 +17,9 @@ class ZLinkSpotActorPacketDispatch {
17
17
  constructor(options) {
18
18
  this.options = options;
19
19
  }
20
- dispatch(actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
20
+ dispatch(origin, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
21
21
  return this.dispatchDelivery({
22
+ origin,
22
23
  actorId,
23
24
  parts,
24
25
  returnResponse,
@@ -71,7 +72,7 @@ class ZLinkSpotActorPacketDispatch {
71
72
  }
72
73
  const actor = this.options.resolveActor(actorId);
73
74
  if (actor === undefined) {
74
- return this.handleMissingActor(actorId, parts, header, messageKind, action, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
75
+ return this.handleMissingActor(delivery.origin, actorId, parts, header, messageKind, action, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal);
75
76
  }
76
77
  if (header.name === actors_1.ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET) {
77
78
  await this.options.onDisconnectActor(actor);
@@ -81,7 +82,7 @@ class ZLinkSpotActorPacketDispatch {
81
82
  return this.dispatchActorPacket(actor, actorId, decodePayload, header, messageKind, action, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, requestDeadlineUnixMs, (0, serial_work_size_1.zlinkSerialWorkOptions)(parts[1].data().byteLength, (0, serial_work_size_1.zlinkMetadataByteLength)(header.metadata)));
82
83
  });
83
84
  }
84
- async handleMissingActor(actorId, parts, header, messageKind, action, returnResponse, fallbackBoundSessionTarget, fallbackActorRef, requestTerminal) {
85
+ async handleMissingActor(origin, actorId, parts, header, messageKind, action, returnResponse, fallbackBoundSessionTarget, fallbackActorRef, requestTerminal) {
85
86
  if (this.options.routeToActorJoinPrewarm !== undefined &&
86
87
  fallbackActorRef !== undefined &&
87
88
  parts.length >= 2 &&
@@ -90,7 +91,7 @@ class ZLinkSpotActorPacketDispatch {
90
91
  // forever with no reply route. Fall through to the existing
91
92
  // missing-actor handling for that shape instead.
92
93
  (messageKind !== ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.ActorRequest || requestTerminal !== undefined)) {
93
- const parked = this.parkForActorJoinPrewarm(actorId, parts, messageKind, returnResponse, fallbackBoundSessionTarget, fallbackActorRef, requestTerminal);
94
+ const parked = this.parkForActorJoinPrewarm(origin, actorId, parts, messageKind, returnResponse, fallbackBoundSessionTarget, fallbackActorRef, requestTerminal);
94
95
  if (parked !== undefined)
95
96
  return parked;
96
97
  }
@@ -126,7 +127,7 @@ class ZLinkSpotActorPacketDispatch {
126
127
  * arrival survives independently of the original {@link Message}
127
128
  * lifetime.
128
129
  */
129
- parkForActorJoinPrewarm(actorId, parts, messageKind, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
130
+ parkForActorJoinPrewarm(origin, actorId, parts, messageKind, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal) {
130
131
  const isRequest = messageKind === ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.ActorRequest;
131
132
  let resolve = () => undefined;
132
133
  let reject = () => undefined;
@@ -154,6 +155,7 @@ class ZLinkSpotActorPacketDispatch {
154
155
  }
155
156
  }, { prepare: requestTerminal.prepare });
156
157
  const route = this.options.routeToActorJoinPrewarm(actorId, fallbackActorRef.objectGeneration, {
158
+ origin,
157
159
  header: Buffer.from(parts[0].data()),
158
160
  payload: Buffer.from(parts[1].data()),
159
161
  returnResponse,
@@ -83,6 +83,7 @@ class ZLinkSpotActorPacketDrain {
83
83
  }
84
84
  else {
85
85
  await this.options.actorPacketHandler({
86
+ origin: 'remote',
86
87
  actorId,
87
88
  parts,
88
89
  returnResponse: false,
@@ -131,6 +132,7 @@ class ZLinkSpotActorPacketDrain {
131
132
  async dispatchNoBindActorRequest(info, actorId, parts, actorRef) {
132
133
  try {
133
134
  const response = await this.options.actorPacketHandler?.({
135
+ origin: 'remote',
134
136
  actorId,
135
137
  parts,
136
138
  returnResponse: true,
@@ -69,6 +69,7 @@ class ZLinkSpotActorPacketRelayDispatch {
69
69
  actorPacketRelay.messageFollowContext !== undefined &&
70
70
  remoteBoundSessionTarget !== undefined;
71
71
  const response = await this.options.actorPacketHandler({
72
+ origin: 'remote',
72
73
  actorId: actorPacketRelay.actorId,
73
74
  parts: [header, payload],
74
75
  returnResponse: !followedBoundSessionReply,
@@ -27,7 +27,7 @@ class ZLinkEntrySpotActivation {
27
27
  spotSerialExecutor;
28
28
  timers;
29
29
  actorHandlers = new actors_1.ZLinkSpotActorHandlerRegistryRuntime();
30
- handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(this.actorHandlers);
30
+ handlers;
31
31
  outbound;
32
32
  workerRuntime;
33
33
  lifecycleMetrics;
@@ -43,6 +43,7 @@ class ZLinkEntrySpotActivation {
43
43
  if (options.detachedTaskRunner === undefined) {
44
44
  throw new configuration_1.ZLinkConfigurationException('Entry Spot activation requires a detached task runner.');
45
45
  }
46
+ this.handlers = new spot_handler_registry_1.DefaultZLinkSpotHandlerRegistry(this.actorHandlers, options.providerResolver);
46
47
  this.serial = new spot_serial_turn_executor_1.ZLinkSpotSerialTurnExecutor(false, options.nativeSpot.routingId);
47
48
  this.spotSerialExecutor = new spot_serial_executor_1.ZLinkSpotSerialExecutor(this.serial, contracts_1.ZLinkUserSpotExecutionMode.PerActor, options.nativeSpot.routingId);
48
49
  // Entry Spot lifecycle, timers and detached continuations use this serial
@@ -182,7 +183,10 @@ class ZLinkEntrySpotActivation {
182
183
  await cleanup(() => this.timers.dispose());
183
184
  await cleanup(() => this.spotSerialExecutor.close());
184
185
  await cleanup(() => (0, handler_instance_scope_1.disposeLifecycleHandlers)(this.entrySpot, this.options.detachedTaskRunner));
185
- await cleanup(() => this.options.nativeSpot.dispose());
186
+ await cleanup(async () => {
187
+ await this.options.entryActorRuntime?.releaseMembers?.(this.options.spotNodeName);
188
+ await this.options.nativeSpot.dispose();
189
+ });
186
190
  if (this.initialized) {
187
191
  this.lifecycleMetrics.closed('entry');
188
192
  }
@@ -287,7 +291,8 @@ class ZLinkEntrySpotActivation {
287
291
  }
288
292
  async dispatchActorPacket(delivery) {
289
293
  const { actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, messageFollowOrigin } = delivery;
290
- const handoff = this.options.actorHandoffRuntime?.capture(actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, undefined, messageFollowOrigin, (replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef) => this.spotSerialExecutor.executeActor(actorId, () => this.dispatchActorPacketInsideMailbox({
294
+ const handoff = this.options.actorHandoffRuntime?.capture(delivery.origin, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, undefined, messageFollowOrigin, (replayedParts, replayReturnResponse, replayRemoteBoundSessionTarget, replayFallbackActorRef) => this.spotSerialExecutor.executeActor(actorId, () => this.dispatchActorPacketInsideMailbox({
295
+ origin: delivery.origin,
291
296
  actorId,
292
297
  parts: replayedParts,
293
298
  returnResponse: replayReturnResponse,
@@ -300,6 +305,7 @@ class ZLinkEntrySpotActivation {
300
305
  }
301
306
  async replayActorBacklog(actor, backlog) {
302
307
  return await (0, actor_handoff_1.replayActorHandoffBacklog)(backlog, (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => this.spotSerialExecutor.executeActor(actor.context.actorId, () => this.dispatchActorPacketInsideMailbox({
308
+ origin: 'remote',
303
309
  actorId: actor.context.actorId,
304
310
  parts,
305
311
  returnResponse,
@@ -1,5 +1,6 @@
1
1
  import type { Type, ZLinkActor, ZLinkEntrySpot, ZLinkInstanceSpotHandlerRegistry, ZLinkSpot, ZLinkSpotHandlerRegistry } from '../../contracts';
2
2
  import type { ZLinkEntrySpotActorRequestHandlerRegistration, ZLinkEntrySpotActorSendHandlerRegistration, ZLinkEntrySpotPacketHandlerRegistration, ZLinkEntrySpotSubscriptionHandlerRegistration, ZLinkSpotActorRequestHandlerRegistration, ZLinkSpotActorSendHandlerRegistration, ZLinkSpotPacketHandlerRegistration, ZLinkSpotSubscriptionHandlerRegistration } from '../../contracts/Configuration/RegistrationTypes';
3
+ import type { ZLinkProviderResolver } from '../../contracts/Common/ZLinkProviderResolver';
3
4
  import { ZLinkActorPacketKind, ZLinkSpotActorHandlerRegistryRuntime } from '../actors';
4
5
  export interface ZLinkSpotHandlerRegistration {
5
6
  readonly kind: 'packet' | 'subscribe' | 'actorSend' | 'actorRequest' | 'spotHandler';
@@ -11,8 +12,9 @@ export interface ZLinkSpotHandlerRegistration {
11
12
  }
12
13
  export declare class DefaultZLinkSpotHandlerRegistry<TActor extends ZLinkActor = ZLinkActor> implements ZLinkSpotHandlerRegistry {
13
14
  private readonly actorHandlers?;
15
+ private readonly providerResolver?;
14
16
  private readonly entries;
15
- constructor(actorHandlers?: ZLinkSpotActorHandlerRegistryRuntime | undefined);
17
+ constructor(actorHandlers?: ZLinkSpotActorHandlerRegistryRuntime | undefined, providerResolver?: ZLinkProviderResolver | undefined);
16
18
  addHandler<THandler>(handlerType: Type<THandler>, packetName?: string): this;
17
19
  addActorPacket<THandler, TRegisteredActor extends ZLinkActor>(handlerType: Type<THandler>, actorType: Type<TRegisteredActor>): this;
18
20
  addPacket(handlerType: Type, packetName?: string): this;
@@ -3,36 +3,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultZLinkInstanceSpotHandlerRegistry = exports.DefaultZLinkSpotHandlerRegistry = void 0;
4
4
  exports.applyEntrySpotHandlerRegistrations = applyEntrySpotHandlerRegistrations;
5
5
  exports.applySpotHandlerRegistrations = applySpotHandlerRegistrations;
6
- const configuration_1 = require("../configuration");
6
+ const handler_instance_scope_1 = require("../handlers/handler-instance-scope");
7
+ const framework_errors_internal_1 = require("../framework-errors-internal");
7
8
  const actors_1 = require("../actors");
8
9
  const Attributes_1 = require("../../contracts/Handlers/Attributes");
9
10
  class DefaultZLinkSpotHandlerRegistry {
10
11
  actorHandlers;
12
+ providerResolver;
11
13
  entries = [];
12
- constructor(actorHandlers) {
14
+ constructor(actorHandlers, providerResolver) {
13
15
  this.actorHandlers = actorHandlers;
16
+ this.providerResolver = providerResolver;
14
17
  }
15
18
  addHandler(handlerType, packetName) {
16
19
  const metadata = (0, Attributes_1.readZLinkDecoratorMetadata)(handlerType).find((entry) => entry.kind === 'spotActorSend' || entry.kind === 'spotActorRequest');
17
20
  const resolvedPacketName = packetName ?? metadata?.packetName;
18
21
  if (metadata === undefined || resolvedPacketName === undefined) {
19
- throw new configuration_1.ZLinkConfigurationException(`Actor packet handler '${handlerType.name}' must declare a packet name.`);
22
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `Actor packet handler '${handlerType.name}' must declare a packet name.`);
20
23
  }
21
24
  return this.addActorPacketRegistration(metadata.kind === 'spotActorSend' ? actors_1.ZLinkActorPacketKind.Send : actors_1.ZLinkActorPacketKind.Request, handlerType, Object, resolvedPacketName);
22
25
  }
23
26
  addActorPacket(handlerType, actorType) {
24
27
  const metadata = (0, Attributes_1.readZLinkDecoratorMetadata)(handlerType).find((entry) => entry.kind === 'spotActorSend' || entry.kind === 'spotActorRequest');
25
28
  if (metadata?.packetName === undefined) {
26
- throw new configuration_1.ZLinkConfigurationException(`Actor packet handler '${handlerType.name}' must declare a packet name.`);
29
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `Actor packet handler '${handlerType.name}' must declare a packet name.`);
27
30
  }
28
31
  return this.addActorPacketRegistration(metadata.kind === 'spotActorSend' ? actors_1.ZLinkActorPacketKind.Send : actors_1.ZLinkActorPacketKind.Request, handlerType, actorType, metadata.packetName);
29
32
  }
30
33
  addPacket(handlerType, packetName) {
31
34
  const declared = (0, Attributes_1.readZLinkDecoratorMetadata)(handlerType).find((entry) => entry.kind === 'packet')?.packetName;
35
+ (0, handler_instance_scope_1.prepareHandlerInstance)(this.providerResolver, handlerType);
36
+ const resolvedPacketName = packetName ?? declared ?? handlerType.name;
37
+ if (this.entries.some((entry) => entry.kind === 'packet' && entry.packetName === resolvedPacketName))
38
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `SPOT packet '${resolvedPacketName}' is already registered.`);
32
39
  this.entries.push({
33
40
  kind: 'packet',
34
41
  handlerType,
35
- packetName: packetName ?? declared ?? handlerType.name
42
+ packetName: resolvedPacketName
36
43
  });
37
44
  return this;
38
45
  }
@@ -40,6 +47,7 @@ class DefaultZLinkSpotHandlerRegistry {
40
47
  return this.addPacket(handlerType, packetName);
41
48
  }
42
49
  addActorPacketRegistration(kind, handlerType, actorType, packetName) {
50
+ (0, handler_instance_scope_1.prepareHandlerInstance)(this.providerResolver, handlerType);
43
51
  this.entries.push({
44
52
  kind: kind === actors_1.ZLinkActorPacketKind.Send ? 'actorSend' : 'actorRequest',
45
53
  handlerType,
@@ -62,17 +70,18 @@ class DefaultZLinkSpotHandlerRegistry {
62
70
  }
63
71
  addSubscribe(handlerType, channelName, topic) {
64
72
  if (channelName.trim().length === 0) {
65
- throw new configuration_1.ZLinkConfigurationException('SPOT subscribe channel name must not be empty.');
73
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, 'SPOT subscribe channel name must not be empty.');
66
74
  }
67
75
  if (topic.trim().length === 0) {
68
- throw new configuration_1.ZLinkConfigurationException('SPOT subscribe topic must not be empty.');
76
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, 'SPOT subscribe topic must not be empty.');
69
77
  }
70
78
  if (this.entries.some((entry) => entry.kind === 'subscribe' &&
71
79
  entry.handlerType === handlerType &&
72
80
  entry.channelName === channelName &&
73
81
  entry.topic === topic)) {
74
- return this;
82
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `SPOT subscription '${channelName}/${topic}' is already registered.`);
75
83
  }
84
+ (0, handler_instance_scope_1.prepareHandlerInstance)(this.providerResolver, handlerType);
76
85
  this.entries.push({ kind: 'subscribe', handlerType, channelName, topic });
77
86
  return this;
78
87
  }
@@ -80,6 +89,7 @@ class DefaultZLinkSpotHandlerRegistry {
80
89
  return this.addSubscribe(handlerType, channelName, topic);
81
90
  }
82
91
  addSpotHandler(handlerType) {
92
+ (0, handler_instance_scope_1.prepareHandlerInstance)(this.providerResolver, handlerType);
83
93
  this.entries.push({ kind: 'spotHandler', handlerType });
84
94
  return this;
85
95
  }
@@ -105,16 +105,17 @@ class ZLinkSpotNodeAutoConnectExecutor {
105
105
  this.node.onPeerDisconnected?.(handler);
106
106
  }
107
107
  async connect(target) {
108
- if (this.manualConnections)
109
- return false;
110
108
  const key = connectionKey(target);
109
+ if (!this.connectionIntents.has(key) &&
110
+ this.node.hasPeerRouteOrConnectionIntent?.(target.nodeRid, target.endpoint) === true)
111
+ return false;
111
112
  const intent = await this.lane.run(() => this.prepareConnectCore(key));
112
113
  if (intent === undefined)
113
114
  return true;
114
115
  return await runDetachedSpotNodeAutoConnect(() => this.connectPeer(target, key, intent));
115
116
  }
116
117
  disconnect(target) {
117
- if (this.manualConnections)
118
+ if (!this.connectionIntents.has(connectionKey(target)))
118
119
  return;
119
120
  this.disconnectPeer(target);
120
121
  }
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import { type ActorRef, type RoutingId, type ZLinkActor, type ZLinkChannelClient, type ZLinkFanoutClient, type ZLinkMeshNodeDescriptor, type ZLinkMessage, type ZLinkMessageSerializer, type ZLinkSpotPublisherClient, ZLinkFrameworkRuntimeState } from '../../contracts';
2
3
  import type { Message } from '../../contracts/Common/Message';
3
4
  import type { ZLinkProviderResolver } from '../../contracts/Common/ZLinkProviderResolver';
@@ -116,7 +117,7 @@ export declare class ZLinkSpotNodeRuntimeManager {
116
117
  private ensureEntryActivation;
117
118
  private initializeEntrySpot;
118
119
  private primaryEntryActivation;
119
- dispatchEntryActorPacket(actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin): Promise<unknown>;
120
+ dispatchEntryActorPacket(origin: ApplicationJobOrigin, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin): Promise<unknown>;
120
121
  dispatchEntryActorJoin(meshName: string, actor: ZLinkActor, handoffBacklog?: readonly ZLinkActorHandoffPacket[]): Promise<void>;
121
122
  executeEntryActor<T>(meshName: string, actorId: string, operation: () => Promise<T>): Promise<T>;
122
123
  publish(meshName: string, channelName: string, topic: string, packetName: string | undefined, event: Message, signal?: AbortSignal, metadata?: ReadonlyMap<string, string>): Promise<ZLinkSubmitResult>;
@@ -17,7 +17,6 @@ const channel_clients_1 = require("../channels/channel-clients");
17
17
  const channel_envelope_1 = require("../channels/channel-envelope");
18
18
  const configuration_1 = require("../configuration");
19
19
  const flow_context_1 = require("../diagnostics/flow-context");
20
- const execution_1 = require("../execution");
21
20
  const service_runtime_contracts_1 = require("../foundation/service-runtime-contracts");
22
21
  const framework_errors_internal_1 = require("../framework-errors-internal");
23
22
  const application_job_queue_1 = require("../host/application-job-queue");
@@ -146,6 +145,7 @@ class ZLinkSpotNodeRuntimeManager {
146
145
  routingId,
147
146
  receiveTimeoutMs: spotNode.router?.receiveTimeoutMs,
148
147
  applicationJobQueue: this.applicationJobQueue,
148
+ infrastructureTaskRunner: this.options.detachedTaskRunner,
149
149
  applicationJobReceiveFlowFailureSink: this.options.applicationJobReceiveFlowFailureSink,
150
150
  peerAdmissionSealed: () => this.options.peerAdmissionSealed?.(spotNodeName) ?? false
151
151
  });
@@ -177,6 +177,7 @@ class ZLinkSpotNodeRuntimeManager {
177
177
  let pump;
178
178
  const completions = new mesh_completion_table_1.ZLinkMeshCompletionTable();
179
179
  try {
180
+ node.setCompletionHandler((terminal, materialize) => completions.complete(terminal, materialize));
180
181
  node.setBind(bind);
181
182
  if (spotNode.router?.advertiseHost !== undefined) {
182
183
  node.setAdvertiseHost(spotNode.router.advertiseHost);
@@ -604,15 +605,6 @@ class ZLinkSpotNodeRuntimeManager {
604
605
  this.meshCompletions.clear();
605
606
  }
606
607
  async dispatchMeshRecord(meshName, owner, record) {
607
- if (record.kind === service_runtime_contracts_1.ReceiveKind.Completion) {
608
- (0, execution_1.requireZLinkInfrastructureExecutionArea)();
609
- const completions = this.meshCompletions.get(meshName);
610
- if (completions === undefined) {
611
- throw new configuration_1.ZLinkConfigurationException(`MeshNode '${meshName}' received a completion before its completion table was registered.`);
612
- }
613
- completions.complete(record);
614
- return;
615
- }
616
608
  const node = this.meshNodes.get(meshName);
617
609
  const targetsEntrySpot = owner.spotId === null ||
618
610
  (node !== undefined &&
@@ -745,7 +737,7 @@ class ZLinkSpotNodeRuntimeManager {
745
737
  primaryEntryActivation() {
746
738
  return this.entryActivations.values().next().value;
747
739
  }
748
- async dispatchEntryActorPacket(actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
740
+ async dispatchEntryActorPacket(origin, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
749
741
  let activation = this.primaryEntryActivation();
750
742
  if (activation === undefined) {
751
743
  const candidates = this.options.primaryMeshName === undefined
@@ -774,6 +766,7 @@ class ZLinkSpotNodeRuntimeManager {
774
766
  throw new configuration_1.ZLinkConfigurationException('Entry Spot actor packet dispatch requires an Entry Spot.');
775
767
  }
776
768
  return await activation.dispatchActorPacket({
769
+ origin,
777
770
  actorId,
778
771
  parts,
779
772
  returnResponse,
@@ -35,6 +35,7 @@ export declare class DefaultZLinkSpotOutbound implements ZLinkSpotOutbound {
35
35
  private requireAddressTransport;
36
36
  }
37
37
  export interface ZLinkSpotAddressCallOptions {
38
+ readonly onAdmitted?: () => void;
38
39
  readonly metadata?: ReadonlyMap<string, string>;
39
40
  readonly instanceSpot: boolean;
40
41
  readonly instanceSpotType?: string;
@@ -63,10 +64,12 @@ export interface ZLinkSpotRoutedSendOptions {
63
64
  readonly metadata?: ReadonlyMap<string, string>;
64
65
  }
65
66
  export interface ZLinkSpotRoutedRequestOptions extends ZLinkSpotRoutedSendOptions {
67
+ readonly onAdmitted?: () => void;
66
68
  readonly timeoutMs?: number;
67
69
  readonly signal?: AbortSignal;
68
70
  }
69
71
  export interface ZLinkSpotHandleCallOptions {
72
+ readonly onAdmitted?: () => void;
70
73
  readonly metadata?: ReadonlyMap<string, string>;
71
74
  readonly timeoutMs?: number;
72
75
  readonly signal?: AbortSignal;