@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
@@ -351,6 +351,10 @@ exports.decodeRelocationPendingTimerTick = decodeRelocationPendingTimerTick;
351
351
  exports.encodeRelocationPendingTimerTick = encodeRelocationPendingTimerTick;
352
352
  exports.decodeRelocationPendingTimerTickVector = decodeRelocationPendingTimerTickVector;
353
353
  exports.encodeRelocationPendingTimerTickVector = encodeRelocationPendingTimerTickVector;
354
+ exports.decodeRelocationSessionBinding = decodeRelocationSessionBinding;
355
+ exports.encodeRelocationSessionBinding = encodeRelocationSessionBinding;
356
+ exports.decodeRelocationSessionBindingVector = decodeRelocationSessionBindingVector;
357
+ exports.encodeRelocationSessionBindingVector = encodeRelocationSessionBindingVector;
354
358
  exports.decodeRelocationEnvelopeV1 = decodeRelocationEnvelopeV1;
355
359
  exports.encodeRelocationEnvelopeV1 = encodeRelocationEnvelopeV1;
356
360
  exports.decodeHelloCommand = decodeHelloCommand;
@@ -8487,6 +8491,141 @@ function writeRelocationPendingTimerTickVector(input, writer, context, enclosing
8487
8491
  }
8488
8492
  function decodeRelocationPendingTimerTickVector(bytes, context) { const reader = new Reader(bytes); const value = readRelocationPendingTimerTickVector(reader, context, {}, 0); reader.done("relocation-pending-timer-tick-vector"); return value; }
8489
8493
  function encodeRelocationPendingTimerTickVector(value, context) { const writer = new Writer(); writeRelocationPendingTimerTickVector(value, writer, context, {}, 0); return writer.result(); }
8494
+ function readRelocationSessionBinding(reader, context, enclosing, flags) {
8495
+ void context;
8496
+ void enclosing;
8497
+ void flags;
8498
+ const value = {};
8499
+ value["participantId"] = readNonzeroU64(reader, context, value, flags);
8500
+ value["sessionOwnerNodeRid"] = readRid(reader, context, value, flags);
8501
+ value["sessionOwnerNodeGeneration"] = readNonzeroU64(reader, context, value, flags);
8502
+ value["sessionOwnerId"] = readText8(reader, context, value, flags);
8503
+ value["sessionOwnerLeaseGeneration"] = readNonzeroU64(reader, context, value, flags);
8504
+ value["sessionRid"] = readRid(reader, context, value, flags);
8505
+ value["bindingGeneration"] = readNonzeroU64(reader, context, value, flags);
8506
+ return value;
8507
+ }
8508
+ function* readIncrementalRelocationSessionBinding(reader, context, enclosing, flags) {
8509
+ void context;
8510
+ void enclosing;
8511
+ void flags;
8512
+ const value = {};
8513
+ value["participantId"] = yield* readIncrementalNonzeroU64(reader, context, value, flags);
8514
+ value["sessionOwnerNodeRid"] = yield* readIncrementalRid(reader, context, value, flags);
8515
+ value["sessionOwnerNodeGeneration"] = yield* readIncrementalNonzeroU64(reader, context, value, flags);
8516
+ value["sessionOwnerId"] = yield* readIncrementalText8(reader, context, value, flags);
8517
+ value["sessionOwnerLeaseGeneration"] = yield* readIncrementalNonzeroU64(reader, context, value, flags);
8518
+ value["sessionRid"] = yield* readIncrementalRid(reader, context, value, flags);
8519
+ value["bindingGeneration"] = yield* readIncrementalNonzeroU64(reader, context, value, flags);
8520
+ return value;
8521
+ }
8522
+ function writeRelocationSessionBinding(input, writer, context, enclosing, flags) {
8523
+ void context;
8524
+ void enclosing;
8525
+ void flags;
8526
+ const value = input;
8527
+ if (value["participantId"] === undefined)
8528
+ fail("participantId required");
8529
+ writeNonzeroU64(numeric(value["participantId"]), writer, context, value, flags);
8530
+ if (value["sessionOwnerNodeRid"] === undefined)
8531
+ fail("sessionOwnerNodeRid required");
8532
+ writeRid(value["sessionOwnerNodeRid"], writer, context, value, flags);
8533
+ if (value["sessionOwnerNodeGeneration"] === undefined)
8534
+ fail("sessionOwnerNodeGeneration required");
8535
+ writeNonzeroU64(numeric(value["sessionOwnerNodeGeneration"]), writer, context, value, flags);
8536
+ if (value["sessionOwnerId"] === undefined)
8537
+ fail("sessionOwnerId required");
8538
+ writeText8(value["sessionOwnerId"], writer, context, value, flags);
8539
+ if (value["sessionOwnerLeaseGeneration"] === undefined)
8540
+ fail("sessionOwnerLeaseGeneration required");
8541
+ writeNonzeroU64(numeric(value["sessionOwnerLeaseGeneration"]), writer, context, value, flags);
8542
+ if (value["sessionRid"] === undefined)
8543
+ fail("sessionRid required");
8544
+ writeRid(value["sessionRid"], writer, context, value, flags);
8545
+ if (value["bindingGeneration"] === undefined)
8546
+ fail("bindingGeneration required");
8547
+ writeNonzeroU64(numeric(value["bindingGeneration"]), writer, context, value, flags);
8548
+ }
8549
+ function decodeRelocationSessionBinding(bytes, context) { const reader = new Reader(bytes); const value = readRelocationSessionBinding(reader, context, {}, 0); reader.done("relocation-session-binding"); return value; }
8550
+ function encodeRelocationSessionBinding(value, context) { const writer = new Writer(); writeRelocationSessionBinding(value, writer, context, {}, 0); return writer.result(); }
8551
+ function readRelocationSessionBindingVector(reader, context, enclosing, flags) {
8552
+ void context;
8553
+ void enclosing;
8554
+ void flags;
8555
+ const count = Number(readU32(reader, context, enclosing, flags));
8556
+ if (count > 1024)
8557
+ fail("relocation-session-binding-vector count");
8558
+ const value = Array.from({ length: count }, () => readRelocationSessionBinding(reader, context, enclosing, flags));
8559
+ try {
8560
+ for (let index = 1; index < value.length; ++index)
8561
+ if (compareResults([compareBigint(numeric(value[index - 1]["participantId"]), numeric(value[index]["participantId"]))]) >= 0)
8562
+ fail("relocation-session-binding-vector sorted");
8563
+ }
8564
+ catch (error) {
8565
+ if (error instanceof ServiceWireProtocolError || error instanceof ServiceWireCapacityError)
8566
+ throw error;
8567
+ if (error instanceof RangeError)
8568
+ capacityFail("relocation-session-binding-vector constraint capacity");
8569
+ throw error;
8570
+ }
8571
+ return value;
8572
+ }
8573
+ function* readIncrementalRelocationSessionBindingVector(reader, context, enclosing, flags) {
8574
+ void context;
8575
+ void enclosing;
8576
+ void flags;
8577
+ const count = Number(yield* readIncrementalU32(reader, context, enclosing, flags));
8578
+ if (count > 1024)
8579
+ fail("relocation-session-binding-vector count");
8580
+ const value = [];
8581
+ for (let index = 0; index < count; ++index) {
8582
+ const item = yield* readIncrementalRelocationSessionBinding(reader, context, enclosing, flags);
8583
+ try {
8584
+ value.push(item);
8585
+ }
8586
+ catch {
8587
+ capacityFail("relocation-session-binding-vector capacity");
8588
+ }
8589
+ }
8590
+ try {
8591
+ for (let index = 1; index < value.length; ++index)
8592
+ if (compareResults([compareBigint(numeric(value[index - 1]["participantId"]), numeric(value[index]["participantId"]))]) >= 0)
8593
+ fail("relocation-session-binding-vector sorted");
8594
+ }
8595
+ catch (error) {
8596
+ if (error instanceof ServiceWireProtocolError || error instanceof ServiceWireCapacityError)
8597
+ throw error;
8598
+ if (error instanceof RangeError)
8599
+ capacityFail("relocation-session-binding-vector constraint capacity");
8600
+ throw error;
8601
+ }
8602
+ return value;
8603
+ }
8604
+ function writeRelocationSessionBindingVector(input, writer, context, enclosing, flags) {
8605
+ void context;
8606
+ void enclosing;
8607
+ void flags;
8608
+ const value = input;
8609
+ if (!Array.isArray(value) || value.length > 1024)
8610
+ fail("relocation-session-binding-vector count");
8611
+ try {
8612
+ for (let index = 1; index < value.length; ++index)
8613
+ if (compareResults([compareBigint(numeric(value[index - 1]["participantId"]), numeric(value[index]["participantId"]))]) >= 0)
8614
+ fail("relocation-session-binding-vector sorted");
8615
+ }
8616
+ catch (error) {
8617
+ if (error instanceof ServiceWireProtocolError || error instanceof ServiceWireCapacityError)
8618
+ throw error;
8619
+ if (error instanceof RangeError)
8620
+ capacityFail("relocation-session-binding-vector constraint capacity");
8621
+ throw error;
8622
+ }
8623
+ writeU32(value.length, writer, context, enclosing, flags);
8624
+ for (const item of value)
8625
+ writeRelocationSessionBinding(item, writer, context, enclosing, flags);
8626
+ }
8627
+ function decodeRelocationSessionBindingVector(bytes, context) { const reader = new Reader(bytes); const value = readRelocationSessionBindingVector(reader, context, {}, 0); reader.done("relocation-session-binding-vector"); return value; }
8628
+ function encodeRelocationSessionBindingVector(value, context) { const writer = new Writer(); writeRelocationSessionBindingVector(value, writer, context, {}, 0); return writer.result(); }
8490
8629
  function readRelocationEnvelopeV1(reader, context, enclosing, flags) {
8491
8630
  void context;
8492
8631
  void enclosing;
@@ -8499,6 +8638,7 @@ function readRelocationEnvelopeV1(reader, context, enclosing, flags) {
8499
8638
  value["savedWork"] = readSavedWorkVector(reader, context, value, flags);
8500
8639
  value["timerRegistrations"] = readRelocationTimerRegistrationVector(reader, context, value, flags);
8501
8640
  value["pendingTimerTicks"] = readRelocationPendingTimerTickVector(reader, context, value, flags);
8641
+ value["sessionBindings"] = readRelocationSessionBindingVector(reader, context, value, flags);
8502
8642
  return value;
8503
8643
  }
8504
8644
  function* readIncrementalRelocationEnvelopeV1(reader, context, enclosing, flags) {
@@ -8513,6 +8653,7 @@ function* readIncrementalRelocationEnvelopeV1(reader, context, enclosing, flags)
8513
8653
  value["savedWork"] = yield* readIncrementalSavedWorkVector(reader, context, value, flags);
8514
8654
  value["timerRegistrations"] = yield* readIncrementalRelocationTimerRegistrationVector(reader, context, value, flags);
8515
8655
  value["pendingTimerTicks"] = yield* readIncrementalRelocationPendingTimerTickVector(reader, context, value, flags);
8656
+ value["sessionBindings"] = yield* readIncrementalRelocationSessionBindingVector(reader, context, value, flags);
8516
8657
  return value;
8517
8658
  }
8518
8659
  function writeRelocationEnvelopeV1(input, writer, context, enclosing, flags) {
@@ -8541,6 +8682,9 @@ function writeRelocationEnvelopeV1(input, writer, context, enclosing, flags) {
8541
8682
  if (value["pendingTimerTicks"] === undefined)
8542
8683
  fail("pendingTimerTicks required");
8543
8684
  writeRelocationPendingTimerTickVector(value["pendingTimerTicks"], writer, context, value, flags);
8685
+ if (value["sessionBindings"] === undefined)
8686
+ fail("sessionBindings required");
8687
+ writeRelocationSessionBindingVector(value["sessionBindings"], writer, context, value, flags);
8544
8688
  }
8545
8689
  function decodeRelocationEnvelopeV1(bytes, context) { const reader = new Reader(bytes); const value = readRelocationEnvelopeV1(reader, context, {}, 0); reader.done("relocation-envelope-v1"); return value; }
8546
8690
  function encodeRelocationEnvelopeV1(value, context) { const writer = new Writer(); writeRelocationEnvelopeV1(value, writer, context, {}, 0); return writer.result(); }
@@ -72,6 +72,15 @@ export interface RelocationEnvelopeV1 {
72
72
  readonly scheduledAtUnixMilliseconds: bigint;
73
73
  readonly skippedTicks: bigint;
74
74
  }[];
75
+ readonly sessionBindings: readonly {
76
+ readonly participantId: bigint;
77
+ readonly sessionOwnerNodeRid: Uint8Array;
78
+ readonly sessionOwnerNodeGeneration: bigint;
79
+ readonly sessionOwnerId: string;
80
+ readonly sessionOwnerLeaseGeneration: bigint;
81
+ readonly sessionRid: Uint8Array;
82
+ readonly bindingGeneration: bigint;
83
+ }[];
75
84
  }
76
85
  export interface RelocationDataChunkV1 {
77
86
  readonly order: number;
@@ -331,6 +331,17 @@ function encodeRelocationEnvelopeV1(value) { const out = []; if (value.relocatio
331
331
  u64(out, p.scheduledIndex);
332
332
  u64(out, p.scheduledAtUnixMilliseconds);
333
333
  u64(out, p.skippedTicks);
334
+ } sorted(value.sessionBindings, (a, b) => a.participantId < b.participantId ? -1 : a.participantId > b.participantId ? 1 : 0, "sessionBindings"); if (value.sessionBindings.length > 1024)
335
+ throw new RangeError("bindings count"); u32(out, value.sessionBindings.length); for (const b of value.sessionBindings) {
336
+ if (b.participantId === 0n || b.sessionOwnerNodeGeneration === 0n || b.sessionOwnerLeaseGeneration === 0n || b.bindingGeneration === 0n)
337
+ throw new RangeError("binding");
338
+ u64(out, b.participantId);
339
+ rid(out, b.sessionOwnerNodeRid);
340
+ u64(out, b.sessionOwnerNodeGeneration);
341
+ text8(out, b.sessionOwnerId);
342
+ u64(out, b.sessionOwnerLeaseGeneration);
343
+ rid(out, b.sessionRid);
344
+ u64(out, b.bindingGeneration);
334
345
  } if (out.length > 274877906944)
335
346
  throw new RangeError("relocation logical bytes"); return Uint8Array.from(out); }
336
347
  function decodeRelocationEnvelopeV1(chunks) { const n = chunks.reduce((s, c) => s + c.length, 0); if (n > 274877906944)
@@ -381,7 +392,9 @@ function decodeRelocationEnvelopeV1(chunks) { const n = chunks.reduce((s, c) =>
381
392
  if (registeredTimerNames.get(participantId)?.has(timerName) !== true)
382
393
  throw new RangeError("pending timer registration");
383
394
  pendingTimerTicks.push({ participantId, order, timerName, deliveryIndex: nonzero64(bytes, at, "delivery"), scheduledIndex: nonzero64(bytes, at, "scheduled"), scheduledAtUnixMilliseconds: read64(bytes, at), skippedTicks: read64(bytes, at) });
384
- } exactEnd(at, bytes.length, "relocation envelope"); sorted(applicationStates, (a, b) => a.participantId < b.participantId ? -1 : a.participantId > b.participantId ? 1 : 0, "applicationStates"); sorted(savedWork, (a, b) => a.participantId === b.participantId ? (a.order < b.order ? -1 : a.order > b.order ? 1 : 0) : (a.participantId < b.participantId ? -1 : 1), "savedWork"); sorted(timerRegistrations, (a, b) => a.participantId === b.participantId ? compareUtf8(a.name, b.name) : a.participantId < b.participantId ? -1 : 1, "timerRegistrations"); sorted(pendingTimerTicks, (a, b) => a.participantId === b.participantId ? (a.order < b.order ? -1 : a.order > b.order ? 1 : 0) : (a.participantId < b.participantId ? -1 : 1), "pendingTimerTicks"); return { relocationHigh, relocationLow, object, applicationVersion, applicationStates, savedWork, timerRegistrations, pendingTimerTicks }; }
395
+ } const sessionBindings = []; const bindingCount = read32(bytes, at); if (bindingCount > 1024)
396
+ throw new RangeError("bindings count"); for (let n = 0; n < bindingCount; n++)
397
+ sessionBindings.push({ participantId: nonzero64(bytes, at, "participant"), sessionOwnerNodeRid: readRid(bytes, at), sessionOwnerNodeGeneration: nonzero64(bytes, at, "session node"), sessionOwnerId: readText8(bytes, at), sessionOwnerLeaseGeneration: nonzero64(bytes, at, "session lease"), sessionRid: readRid(bytes, at), bindingGeneration: nonzero64(bytes, at, "binding") }); sorted(sessionBindings, (a, b) => a.participantId < b.participantId ? -1 : a.participantId > b.participantId ? 1 : 0, "sessionBindings"); exactEnd(at, bytes.length, "relocation envelope"); sorted(applicationStates, (a, b) => a.participantId < b.participantId ? -1 : a.participantId > b.participantId ? 1 : 0, "applicationStates"); sorted(savedWork, (a, b) => a.participantId === b.participantId ? (a.order < b.order ? -1 : a.order > b.order ? 1 : 0) : (a.participantId < b.participantId ? -1 : 1), "savedWork"); sorted(timerRegistrations, (a, b) => a.participantId === b.participantId ? compareUtf8(a.name, b.name) : a.participantId < b.participantId ? -1 : 1, "timerRegistrations"); sorted(pendingTimerTicks, (a, b) => a.participantId === b.participantId ? (a.order < b.order ? -1 : a.order > b.order ? 1 : 0) : (a.participantId < b.participantId ? -1 : 1), "pendingTimerTicks"); return { relocationHigh, relocationLow, object, applicationVersion, applicationStates, savedWork, timerRegistrations, pendingTimerTicks, sessionBindings }; }
385
398
  function crc32c(bytes) { let crc = 0xffffffff; for (const octet of bytes) {
386
399
  crc ^= octet;
387
400
  for (let bit = 0; bit < 8; bit++)
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type { ActorRef, RoutingId, ZLinkActor, ZLinkActorJoinOperationId } from '../../contracts';
2
3
  import type { ZLinkRemoteBoundSessionTarget } from '../actors/actor-runtime-state';
3
4
  import type { ZLinkDeferredJoinCompletion } from '../actors/deferred-join-completion';
@@ -10,6 +11,7 @@ import type { ZLinkActorRequestTerminal } from './spot-actor-packet-dispatch';
10
11
  * how long the underlying buffer stays valid.
11
12
  */
12
13
  export interface ZLinkParkedActorArrival {
14
+ readonly origin: ApplicationJobOrigin;
13
15
  readonly header: Buffer;
14
16
  readonly payload: Buffer;
15
17
  readonly returnResponse: boolean;
@@ -20,7 +22,7 @@ export interface ZLinkParkedActorArrival {
20
22
  readonly reject: (reason: unknown) => void;
21
23
  }
22
24
  export type ZLinkActorJoinIngressRoute = 'parked' | 'not-found';
23
- export type ZLinkFormalRemoteActorAdmissionState = 'provisional' | 'admitting' | 'admitted' | 'rejected' | 'committed' | 'aborted' | 'failed';
25
+ export type ZLinkFormalRemoteActorAdmissionState = 'provisional' | 'admitting' | 'admitted' | 'restoring' | 'rejected' | 'committed' | 'aborted' | 'failed';
24
26
  export interface ZLinkFormalRemoteActorAdmission {
25
27
  readonly actorId: string;
26
28
  readonly actorType: string;
@@ -54,7 +56,7 @@ export interface ZLinkFormalRemoteActorAdmissionRecord {
54
56
  readonly resultTask: Promise<ZLinkFormalRemoteActorAdmissionResult>;
55
57
  }
56
58
  interface ZLinkFormalRemoteActorAdmissionEntry extends ZLinkFormalRemoteActorAdmissionRecord {
57
- readonly timer: ReturnType<typeof setTimeout>;
59
+ timer: ReturnType<typeof setTimeout>;
58
60
  readonly resolveResult: (result: ZLinkFormalRemoteActorAdmissionResult) => void;
59
61
  admission: ZLinkFormalRemoteActorAdmission;
60
62
  state: ZLinkFormalRemoteActorAdmissionState;
@@ -68,6 +70,11 @@ export declare class ZLinkFormalRemoteActorAdmissionRegistry {
68
70
  private readonly admissions;
69
71
  private readonly byObject;
70
72
  get(transferId: string): ZLinkFormalRemoteActorAdmissionEntry | undefined;
73
+ /** PREPARE transfers prepared resources to the target attempt until its terminal. */
74
+ beginRestore(transferId: string): void;
75
+ /** Retains successful commit replay; unsuccessful attempts release their resources now. */
76
+ finishRestore(transferId: string): void;
77
+ private scheduleExpiry;
71
78
  begin(input: ZLinkFormalRemoteActorAdmission): {
72
79
  readonly record: ZLinkFormalRemoteActorAdmissionEntry;
73
80
  readonly created: boolean;
@@ -17,6 +17,34 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
17
17
  get(transferId) {
18
18
  return this.admissions.get(transferId);
19
19
  }
20
+ /** PREPARE transfers prepared resources to the target attempt until its terminal. */
21
+ beginRestore(transferId) {
22
+ const entry = this.admissions.get(transferId);
23
+ if (entry === undefined || (entry.state !== 'admitted' && entry.state !== 'restoring')) {
24
+ throw new Error(`Remote actor admission '${transferId}' is not ready to restore.`);
25
+ }
26
+ clearTimeout(entry.timer);
27
+ entry.state = 'restoring';
28
+ }
29
+ /** Retains successful commit replay; unsuccessful attempts release their resources now. */
30
+ finishRestore(transferId) {
31
+ const entry = this.admissions.get(transferId);
32
+ if (entry === undefined)
33
+ return;
34
+ if (entry.state === 'committed') {
35
+ clearTimeout(entry.timer);
36
+ entry.timer = this.scheduleExpiry(transferId);
37
+ }
38
+ else {
39
+ this.abort(transferId);
40
+ this.delete(transferId);
41
+ }
42
+ }
43
+ scheduleExpiry(transferId) {
44
+ const timer = setTimeout(() => this.delete(transferId), ADMISSION_RETENTION_MS);
45
+ timer.unref();
46
+ return timer;
47
+ }
20
48
  begin(input) {
21
49
  const existing = this.admissions.get(input.transferId);
22
50
  if (existing !== undefined) {
@@ -71,10 +99,7 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
71
99
  const resultTask = new Promise((resolve) => {
72
100
  resolveResult = resolve;
73
101
  });
74
- const timer = setTimeout(() => {
75
- this.delete(input.transferId);
76
- }, ADMISSION_RETENTION_MS);
77
- timer.unref();
102
+ const timer = this.scheduleExpiry(input.transferId);
78
103
  const entry = {
79
104
  admission: input,
80
105
  state,
@@ -186,7 +211,7 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
186
211
  const entry = this.admissions.get(transferId);
187
212
  if (entry === undefined)
188
213
  return;
189
- if (entry.state !== 'admitted' && entry.state !== 'committed') {
214
+ if (entry.state !== 'admitted' && entry.state !== 'restoring' && entry.state !== 'committed') {
190
215
  throw new Error(`Remote actor admission '${transferId}' is not ready to commit.`);
191
216
  }
192
217
  entry.state = 'committed';
@@ -195,7 +220,7 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
195
220
  attachDeferredJoinCompletion(transferId, root) {
196
221
  const entry = this.admissions.get(transferId);
197
222
  if (entry === undefined ||
198
- entry.state !== 'admitted' ||
223
+ (entry.state !== 'admitted' && entry.state !== 'restoring') ||
199
224
  entry.result === undefined ||
200
225
  'error' in entry.result ||
201
226
  !entry.result.accepted) {
@@ -227,7 +252,7 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
227
252
  */
228
253
  delete(transferId) {
229
254
  const pending = this.admissions.get(transferId);
230
- if (pending === undefined)
255
+ if (pending === undefined || pending.state === 'restoring')
231
256
  return;
232
257
  clearTimeout(pending.timer);
233
258
  this.admissions.delete(transferId);
@@ -240,18 +265,7 @@ class ZLinkFormalRemoteActorAdmissionRegistry {
240
265
  }
241
266
  exports.ZLinkFormalRemoteActorAdmissionRegistry = ZLinkFormalRemoteActorAdmissionRegistry;
242
267
  function sameAdmission(left, right) {
243
- return (left.actorId === right.actorId &&
244
- left.actorType === right.actorType &&
245
- String(left.spotId) === String(right.spotId) &&
246
- left.targetSpotGeneration === right.targetSpotGeneration &&
247
- left.expectedMembershipEpoch === right.expectedMembershipEpoch &&
248
- left.requestFingerprint === right.requestFingerprint &&
249
- sameOperationId(left.completionOperationId, right.completionOperationId) &&
250
- String(left.sourceSpotId ?? '') === String(right.sourceSpotId ?? '') &&
251
- String(left.sourceActorNodeRid ?? '') === String(right.sourceActorNodeRid ?? '') &&
252
- left.actorRef.actorId === right.actorRef.actorId &&
253
- String(left.actorRef.nodeRid) === String(right.actorRef.nodeRid) &&
254
- left.actorRef.objectGeneration === right.actorRef.objectGeneration);
268
+ return left.actorType === right.actorType && sameProvisionalAdmission(left, right);
255
269
  }
256
270
  function sameProvisionalAdmission(left, right) {
257
271
  return (left.actorId === right.actorId &&
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type { ActorRef, RoutingId, Type, ZLinkMessageSerializer, ZLinkInstanceSpot, ZLinkActor, ZLinkChannelClient, ZLinkFanoutClient, ZLinkSpot, ZLinkSpotActorJoinResult, ZLinkSpotInfo, ZLinkSpotPublisherClient } from '../../contracts';
2
3
  import type { ZLinkProviderResolver } from '../../contracts/Common/ZLinkProviderResolver';
3
4
  import type { ZLinkSpotActorRequestHandlerRegistration, ZLinkSpotActorSendHandlerRegistration, ZLinkSpotPacketHandlerRegistration, ZLinkSpotSubscriptionHandlerRegistration, ZLinkSpotTimerHandlerRegistration } from '../../contracts/Configuration/RegistrationTypes';
@@ -55,7 +56,7 @@ export interface ZLinkSpotManagerOptions {
55
56
  readonly entrySpotCallbacks?: {
56
57
  onLeaveActor(actor: ZLinkActor, signal?: AbortSignal, actorRef?: ActorRef, membershipEpoch?: bigint): Promise<void>;
57
58
  };
58
- readonly dispatchEntryActorPacket?: (actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin) => Promise<unknown>;
59
+ readonly dispatchEntryActorPacket?: (origin: ApplicationJobOrigin, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin) => Promise<unknown>;
59
60
  /**
60
61
  * Commits a stateful MeshNode Actor return to the Entry Spot after the
61
62
  * stateful reply has committed Core membership.
@@ -63,6 +64,7 @@ export interface ZLinkSpotManagerOptions {
63
64
  readonly dispatchEntryActorJoin?: (meshName: string, actor: ZLinkActor, handoffBacklog?: readonly ZLinkActorHandoffPacket[]) => Promise<void>;
64
65
  readonly executeEntryActor?: <T>(meshName: string, actorId: string, operation: () => Promise<T>) => Promise<T>;
65
66
  readonly actorCountProvider?: (spotId: RoutingId) => number;
67
+ readonly releaseActorMembers?: (meshName: string, spotId: RoutingId) => Promise<void>;
66
68
  readonly userSpotExecutionMode?: (meshName: string, spotType: Type<ZLinkSpot>) => import('../../contracts').ZLinkUserSpotExecutionMode;
67
69
  readonly userSpotRelocationCoordinationMode?: (meshName: string, spotType: Type<ZLinkSpot>) => import('../../contracts').ZLinkSpotRelocationCoordinationMode;
68
70
  readonly actorDispatchOwnerResolver?: (actorId: string) => {
@@ -200,7 +202,7 @@ export declare class DefaultZLinkSpotManager {
200
202
  beginActorTransfer(spotId: RoutingId, actorId: string): Promise<void>;
201
203
  cancelActorTransfer(spotId: RoutingId, actorId: string): Promise<void>;
202
204
  notifyJoinedSpotActorDisconnected(spotId: RoutingId, actor: ZLinkActor, signal?: AbortSignal): Promise<boolean>;
203
- dispatchRoutedActorPacket(spotId: RoutingId, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef): Promise<unknown>;
205
+ dispatchRoutedActorPacket(origin: ApplicationJobOrigin, spotId: RoutingId, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef): Promise<unknown>;
204
206
  dispatchRoutedSpotSend(spotId: RoutingId, packetName: string | undefined, message: unknown, context: {
205
207
  readonly channelName: string;
206
208
  readonly contentType?: string;
@@ -214,19 +216,21 @@ export declare class DefaultZLinkSpotManager {
214
216
  readonly workOptions?: import('../execution/serial-execution-queue').ZLinkSerialWorkOptions;
215
217
  readonly admissionTimeoutMs?: number;
216
218
  readonly signal?: AbortSignal;
219
+ readonly onAdmitted?: () => void;
217
220
  }): Promise<TReply>;
218
221
  dispatchMeshSpot(meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
219
222
  private ensureInstanceApplicationActivation;
220
223
  dispatchMeshInstance(meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
221
224
  private reportInstanceDispatchFailure;
222
225
  private traceInstanceMessage;
223
- dispatchMeshActor(meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
226
+ dispatchMeshActor(origin: ApplicationJobOrigin, meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
224
227
  dispatchMeshActorJoin(meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
225
228
  private dispatchMeshActorJoinCore;
226
229
  dispatchMeshSpotControl(meshName: string, owner: ReadyRecord, record: ReceiveRecord): Promise<void>;
227
230
  private dispatchMeshSpotControlCore;
228
231
  completeFormalSourceLeaveTerminal(actorId: string, transferId: string, succeeded: boolean): Promise<boolean>;
229
232
  finalizeActorJoinRelocation(meshName: string, relocationId: string, actor: ZLinkActor, actorRef: ActorRef, submitSourceLeave: (sourceNodeRid: RoutingId) => Promise<void>, signal?: AbortSignal): Promise<boolean>;
233
+ beginActorJoinRelocation(relocationId: string): () => void;
230
234
  restoreCanonicalActorJoinRecovery(recovery: CanonicalActorJoinRecovery, signal?: AbortSignal): Promise<void>;
231
235
  private encodeMeshActorReply;
232
236
  private createActivation;
@@ -130,6 +130,7 @@ class DefaultZLinkSpotManager {
130
130
  nodeRid: options.nodeRid,
131
131
  nodeRidProvider: options.nodeRidProvider,
132
132
  actorCountProvider: options.actorCountProvider,
133
+ releaseActorMembers: options.releaseActorMembers,
133
134
  userSpotExecutionMode: options.userSpotExecutionMode,
134
135
  userSpotRelocationCoordinationMode: options.userSpotRelocationCoordinationMode,
135
136
  channelClient: options.channelClient,
@@ -860,20 +861,20 @@ class DefaultZLinkSpotManager {
860
861
  async notifyJoinedSpotActorDisconnected(spotId, actor, signal) {
861
862
  return await this.actorMembership.notifyJoinedActorDisconnected(spotId, actor, signal);
862
863
  }
863
- dispatchRoutedActorPacket(spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
864
+ dispatchRoutedActorPacket(origin, spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
864
865
  const activation = this.activations.resolveUnique(spotId);
865
866
  if (activation === undefined) {
866
867
  throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
867
868
  }
868
- return this.dispatchActorPacket(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
869
+ return this.dispatchActorPacket(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
869
870
  }
870
871
  /** @internal Replays a record already owned by the Actor handoff queue. */
871
- dispatchRoutedActorPacketDirect(spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
872
+ dispatchRoutedActorPacketDirect(origin, spotId, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef) {
872
873
  const activation = this.activations.resolveUnique(spotId);
873
874
  if (activation === undefined) {
874
875
  throw new configuration_1.ZLinkConfigurationException(`Spot '${spotId}' is not active.`);
875
876
  }
876
- return this.activationLifecycle.dispatchActorPacketDirect(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
877
+ return this.activationLifecycle.dispatchActorPacketDirect(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
877
878
  }
878
879
  /** @internal Atomically restores one durable packet prefix to an Actor FIFO. */
879
880
  admitRoutedActorPacketPrefix(spotId, actorId, records) {
@@ -1071,7 +1072,7 @@ class DefaultZLinkSpotManager {
1071
1072
  errorReason
1072
1073
  });
1073
1074
  }
1074
- async dispatchMeshActor(meshName, owner, record) {
1075
+ async dispatchMeshActor(origin, meshName, owner, record) {
1075
1076
  const spotId = owner.spotId;
1076
1077
  const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1077
1078
  const targetsEntrySpot = spotId === null || (entrySpotId !== undefined && spotId === entrySpotId);
@@ -1115,8 +1116,8 @@ class DefaultZLinkSpotManager {
1115
1116
  throw new Error(`Actor '${actor.actorId}' target transfer reconciliation is not complete.`);
1116
1117
  }
1117
1118
  const response = targetsEntrySpot
1118
- ? await this.options.dispatchEntryActorPacket?.(actor.actorId, record.parts, request, undefined, ownerActorRef, requestTerminal, record.messageFollowOrigin)
1119
- : await this.dispatchMeshActorPacket(meshName, spotId, actor.actorId, record.parts, request, ownerActorRef, requestTerminal, record.messageFollowOrigin);
1119
+ ? await this.options.dispatchEntryActorPacket?.(origin, actor.actorId, record.parts, request, undefined, ownerActorRef, requestTerminal, record.messageFollowOrigin)
1120
+ : await this.dispatchMeshActorPacket(origin, meshName, spotId, actor.actorId, record.parts, request, ownerActorRef, requestTerminal, record.messageFollowOrigin);
1120
1121
  if (targetsEntrySpot && this.options.dispatchEntryActorPacket === undefined) {
1121
1122
  throw new configuration_1.ZLinkConfigurationException('MeshNode Entry Spot Actor dispatch is not configured.');
1122
1123
  }
@@ -1631,7 +1632,7 @@ class DefaultZLinkSpotManager {
1631
1632
  if (this.options.dispatchEntryActorPacket === undefined) {
1632
1633
  throw new Error('Entry Spot saved handoff replay requires its Actor packet runtime.');
1633
1634
  }
1634
- return await this.options.dispatchEntryActorPacket(entryActor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
1635
+ return await this.options.dispatchEntryActorPacket('remote', entryActor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
1635
1636
  }, (index) => this.options.runtimeEventPublisher?.publish({
1636
1637
  sourceName: 'zlink.framework.actor-handoff',
1637
1638
  timestamp: new Date(),
@@ -1790,7 +1791,7 @@ class DefaultZLinkSpotManager {
1790
1791
  };
1791
1792
  const completeTargetReady = async () => {
1792
1793
  if (pendingTransfer !== undefined) {
1793
- const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, (parts, returnResponse, remoteBoundSessionTarget, _fallbackActorRef) => this.dispatchActorPacket(activation, actor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, undefined), (index) => this.options.runtimeEventPublisher?.publish({
1794
+ const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, (parts, returnResponse, remoteBoundSessionTarget, _fallbackActorRef) => this.dispatchActorPacket('remote', activation, actor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, undefined), (index) => this.options.runtimeEventPublisher?.publish({
1794
1795
  sourceName: 'zlink.framework.actor-handoff',
1795
1796
  timestamp: new Date(),
1796
1797
  marker: 'backlog_enqueued',
@@ -1894,7 +1895,7 @@ class DefaultZLinkSpotManager {
1894
1895
  const outcome = admission.result ?? (await admission.resultTask);
1895
1896
  if ('error' in outcome)
1896
1897
  throw outcome.error;
1897
- if (!outcome.accepted || admission.state !== 'admitted') {
1898
+ if (!outcome.accepted || (admission.state !== 'admitted' && admission.state !== 'restoring')) {
1898
1899
  throw new Error(`Actor Join relocation '${relocationId}' has no accepted admission.`);
1899
1900
  }
1900
1901
  const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
@@ -1944,6 +1945,10 @@ class DefaultZLinkSpotManager {
1944
1945
  this.formalRemoteActorAdmissions.markCommitted(relocationId, actor);
1945
1946
  return true;
1946
1947
  }
1948
+ beginActorJoinRelocation(relocationId) {
1949
+ this.formalRemoteActorAdmissions.beginRestore(relocationId);
1950
+ return () => this.formalRemoteActorAdmissions.finishRestore(relocationId);
1951
+ }
1947
1952
  async restoreCanonicalActorJoinRecovery(recovery, signal) {
1948
1953
  (0, abort_1.throwIfAborted)(signal);
1949
1954
  const admission = this.formalRemoteActorAdmissions.get(recovery.request.handoffId);
@@ -1951,7 +1956,9 @@ class DefaultZLinkSpotManager {
1951
1956
  throw new Error(`Actor Join recovery '${recovery.request.handoffId}' has no canonical command-28 admission.`);
1952
1957
  }
1953
1958
  const outcome = admission.result ?? (await admission.resultTask);
1954
- if ('error' in outcome || !outcome.accepted || admission.state !== 'admitted') {
1959
+ if ('error' in outcome ||
1960
+ !outcome.accepted ||
1961
+ (admission.state !== 'admitted' && admission.state !== 'restoring')) {
1955
1962
  throw new Error(`Actor Join recovery '${recovery.request.handoffId}' has no accepted admission.`);
1956
1963
  }
1957
1964
  const admitted = admission.admission;
@@ -2033,8 +2040,8 @@ class DefaultZLinkSpotManager {
2033
2040
  throw new configuration_1.ZLinkConfigurationException('Spot type is not registered as a spot factory.');
2034
2041
  }
2035
2042
  }
2036
- async dispatchActorPacket(activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
2037
- return await this.activationLifecycle.dispatchActorPacket(activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin);
2043
+ async dispatchActorPacket(origin, activation, actorId, parts, returnResponse = false, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin) {
2044
+ return await this.activationLifecycle.dispatchActorPacket(origin, activation, actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef, requestTerminal, messageFollowOrigin);
2038
2045
  }
2039
2046
  /**
2040
2047
  * Spec 15 §4.2 relocation temporary queue: drains every arrival parked
@@ -2050,7 +2057,7 @@ class DefaultZLinkSpotManager {
2050
2057
  const drained = this.formalRemoteActorAdmissions.completeMigration(transferId);
2051
2058
  for (const arrival of drained) {
2052
2059
  try {
2053
- const response = await this.dispatchActorPacket(activation, actor.context.actorId, [runtime_message_1.ZLinkBufferMessage.from(arrival.header), runtime_message_1.ZLinkBufferMessage.from(arrival.payload)], arrival.returnResponse, arrival.remoteBoundSessionTarget, arrival.fallbackActorRef, arrival.requestTerminal);
2060
+ const response = await this.dispatchActorPacket(arrival.origin, activation, actor.context.actorId, [runtime_message_1.ZLinkBufferMessage.from(arrival.header), runtime_message_1.ZLinkBufferMessage.from(arrival.payload)], arrival.returnResponse, arrival.remoteBoundSessionTarget, arrival.fallbackActorRef, arrival.requestTerminal);
2054
2061
  arrival.resolve(response);
2055
2062
  }
2056
2063
  catch (error) {
@@ -2058,12 +2065,12 @@ class DefaultZLinkSpotManager {
2058
2065
  }
2059
2066
  }
2060
2067
  }
2061
- async dispatchMeshActorPacket(meshName, spotId, actorId, parts, returnResponse, fallbackActorRef, requestTerminal, messageFollowOrigin) {
2068
+ async dispatchMeshActorPacket(origin, meshName, spotId, actorId, parts, returnResponse, fallbackActorRef, requestTerminal, messageFollowOrigin) {
2062
2069
  const activation = this.activations.resolve(meshName, spotId);
2063
2070
  if (activation === undefined) {
2064
2071
  throw new configuration_1.ZLinkConfigurationException(`Spot '${String(spotId)}' is not active in mesh '${meshName}'.`);
2065
2072
  }
2066
- return await this.dispatchActorPacket(activation, actorId, parts, returnResponse, undefined, fallbackActorRef, requestTerminal, messageFollowOrigin);
2073
+ return await this.dispatchActorPacket(origin, activation, actorId, parts, returnResponse, undefined, fallbackActorRef, requestTerminal, messageFollowOrigin);
2067
2074
  }
2068
2075
  }
2069
2076
  exports.DefaultZLinkSpotManager = DefaultZLinkSpotManager;
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type { ActorRef, RoutingId, Type, ZLinkActor, ZLinkChannelClient, ZLinkFanoutClient, ZLinkMessageSerializer, ZLinkInstanceSpot, ZLinkSpot, ZLinkSpotPublisherClient } from '../../contracts';
2
3
  import type { ZLinkProviderResolver } from '../../contracts/Common/ZLinkProviderResolver';
3
4
  import type { ZLinkRuntimeAdmissionGate } from '../admission';
@@ -28,6 +29,7 @@ export interface ZLinkSpotActivationLifecycleOptions {
28
29
  readonly nodeRid?: RoutingId;
29
30
  readonly nodeRidProvider?: (meshName: string) => RoutingId | undefined;
30
31
  readonly actorCountProvider?: (spotId: RoutingId) => number;
32
+ readonly releaseActorMembers?: (meshName: string, spotId: RoutingId) => Promise<void>;
31
33
  readonly userSpotExecutionMode?: (meshName: string, spotType: Type<ZLinkSpot>) => ZLinkUserSpotExecutionMode;
32
34
  readonly userSpotRelocationCoordinationMode?: (meshName: string, spotType: Type<ZLinkSpot>) => ZLinkSpotRelocationCoordinationMode;
33
35
  readonly channelClient?: ZLinkChannelClient;
@@ -82,7 +84,7 @@ export declare class ZLinkSpotActivationLifecycle {
82
84
  /** Returns the OnClosing failure, which cleanup records and does not rethrow. */
83
85
  cleanupClosedActivation(activation: ZLinkSpotActivation, reason?: ZLinkSpotCloseReason, deadline?: Date): Promise<unknown>;
84
86
  cleanupFailedIncarnation(activation: ZLinkSpotActivation): Promise<void>;
85
- dispatchActorPacket(activation: ZLinkSpotActivation, actorId: string, parts: readonly Message[], returnResponse?: boolean, remoteBoundSessionTarget?: ZLinkRemoteBoundSessionTarget, fallbackActorRef?: ActorRef, requestTerminal?: (response: unknown) => Promise<void> | void, messageFollowOrigin?: ZLinkMessageFollowOrigin): Promise<unknown>;
87
+ 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>;
86
88
  private runCreateLifecycle;
87
89
  private cleanupActivation;
88
90
  private runCleanup;