@zlink-systems/framework 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (557) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Channels/IZLinkFanoutClient.d.ts +0 -6
  3. package/dist/contracts/Common/CoreTypes.d.ts +6 -0
  4. package/dist/contracts/Common/CoreTypes.js +7 -0
  5. package/dist/contracts/Common/index.d.ts +1 -1
  6. package/dist/contracts/Common/index.js +0 -1
  7. package/dist/contracts/Configuration/InternalDefaults.d.ts +8 -0
  8. package/dist/contracts/Configuration/InternalDefaults.js +9 -1
  9. package/dist/contracts/Configuration/Registration.d.ts +13 -2
  10. package/dist/contracts/Configuration/Registration.js +58 -36
  11. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +13 -1
  12. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +38 -1
  13. package/dist/contracts/Configuration/RegistrationBuilders.d.ts +2 -3
  14. package/dist/contracts/Configuration/RegistrationBuilders.js +27 -32
  15. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
  16. package/dist/contracts/Configuration/RegistrationValidators.js +15 -12
  17. package/dist/contracts/Configuration/TimerRegistrationValidator.js +3 -2
  18. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +1 -1
  19. package/dist/contracts/Handlers/JsonContract.js +10 -4
  20. package/dist/contracts/Locations/Authority.d.ts +1 -1
  21. package/dist/contracts/Locations/Authority.js +3 -2
  22. package/dist/contracts/Locations/Options.js +1 -1
  23. package/dist/contracts/Locations/Stores.d.ts +12 -0
  24. package/dist/contracts/Locations/Stores.js +9 -0
  25. package/dist/contracts/RouteMesh/RuntimeTopology.d.ts +8 -0
  26. package/dist/contracts/Spots/Contracts.d.ts +1 -1
  27. package/dist/internal.d.ts +5 -0
  28. package/dist/internal.js +16 -1
  29. package/dist/nest-integration.d.ts +4 -2
  30. package/dist/nest-integration.js +14 -4
  31. package/dist/runtime/abort.d.ts +1 -0
  32. package/dist/runtime/abort.js +8 -5
  33. package/dist/runtime/activation-admission.d.ts +28 -0
  34. package/dist/runtime/activation-admission.js +57 -0
  35. package/dist/runtime/actors/actor-authority-payload-codec.d.ts +1 -2
  36. package/dist/runtime/actors/actor-authority-payload-codec.js +34 -18
  37. package/dist/runtime/actors/actor-client.d.ts +2 -2
  38. package/dist/runtime/actors/actor-client.js +42 -143
  39. package/dist/runtime/actors/actor-context.d.ts +3 -5
  40. package/dist/runtime/actors/actor-context.js +19 -17
  41. package/dist/runtime/actors/actor-handoff.d.ts +13 -7
  42. package/dist/runtime/actors/actor-handoff.js +36 -25
  43. package/dist/runtime/actors/actor-lifecycle-snapshot.js +2 -1
  44. package/dist/runtime/actors/actor-local-native-join.d.ts +11 -6
  45. package/dist/runtime/actors/actor-local-native-join.js +85 -123
  46. package/dist/runtime/actors/actor-native-lookup.js +2 -8
  47. package/dist/runtime/actors/actor-packet-relay-wire.d.ts +3 -3
  48. package/dist/runtime/actors/actor-packet-relay-wire.js +5 -3
  49. package/dist/runtime/actors/actor-remote-joiner.d.ts +3 -3
  50. package/dist/runtime/actors/actor-remote-joiner.js +11 -17
  51. package/dist/runtime/actors/actor-remote-wire.js +5 -3
  52. package/dist/runtime/actors/actor-request-deadline.d.ts +3 -0
  53. package/dist/runtime/actors/actor-request-deadline.js +31 -0
  54. package/dist/runtime/actors/actor-retry-delay.js +2 -1
  55. package/dist/runtime/actors/actor-runtime-contracts.d.ts +4 -2
  56. package/dist/runtime/actors/actor-runtime-state.d.ts +9 -21
  57. package/dist/runtime/actors/actor-runtime-state.js +70 -187
  58. package/dist/runtime/actors/actor-source-transfer.d.ts +5 -5
  59. package/dist/runtime/actors/bound-session-wire.js +2 -7
  60. package/dist/runtime/actors/deferred-join-completion.d.ts +19 -0
  61. package/dist/runtime/actors/deferred-join-completion.js +21 -0
  62. package/dist/runtime/actors/index.d.ts +10 -8
  63. package/dist/runtime/actors/index.js +101 -73
  64. package/dist/runtime/actors/spot-actor-dispatch.d.ts +3 -3
  65. package/dist/runtime/actors/spot-actor-dispatch.js +25 -10
  66. package/dist/runtime/actors/transferred-actor-rollback.d.ts +3 -5
  67. package/dist/runtime/actors/transferred-actor-rollback.js +9 -42
  68. package/dist/runtime/admission.d.ts +7 -1
  69. package/dist/runtime/admission.js +11 -1
  70. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +1 -1
  71. package/dist/runtime/application-jobs/application-job-queue-scope.js +1 -1
  72. package/dist/runtime/backend/contracts/index.d.ts +8 -33
  73. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +3 -26
  74. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +1 -2
  75. package/dist/runtime/backend/mesh-dispatch-pump.js +95 -107
  76. package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +1 -2
  77. package/dist/runtime/backend/node/node-backend-adapter-factory.js +4 -18
  78. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +7 -4
  79. package/dist/runtime/backend/node/node-backend-adapter-support.js +28 -34
  80. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  81. package/dist/runtime/backend/node/node-event-loop-poller.js +11 -6
  82. package/dist/runtime/backend/node/node-monitor-backend-adapter.js +1 -0
  83. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +1 -1
  84. package/dist/runtime/backend/node/node-raw-binding-port.js +51 -19
  85. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +21 -19
  86. package/dist/runtime/backend/node/node-raw-mesh-backend.js +171 -111
  87. package/dist/runtime/backend/node/node-socket-backend-adapter.js +4 -3
  88. package/dist/runtime/backend/raw-binding-port.d.ts +13 -1
  89. package/dist/runtime/backend/runtime-values.d.ts +4 -1
  90. package/dist/runtime/backend/runtime-values.js +2 -0
  91. package/dist/runtime/channels/channel-clients.d.ts +20 -9
  92. package/dist/runtime/channels/channel-clients.js +68 -60
  93. package/dist/runtime/channels/channel-envelope-inspection.js +2 -1
  94. package/dist/runtime/channels/channel-envelope.js +47 -29
  95. package/dist/runtime/channels/channel-outbound-operations.d.ts +3 -0
  96. package/dist/runtime/channels/channel-outbound-operations.js +9 -18
  97. package/dist/runtime/channels/channel-receive-loops.d.ts +8 -3
  98. package/dist/runtime/channels/channel-receive-loops.js +27 -6
  99. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +12 -1
  100. package/dist/runtime/channels/channel-runtime-lifecycle.js +48 -28
  101. package/dist/runtime/channels/channel-runtime-manager.d.ts +2 -5
  102. package/dist/runtime/channels/channel-runtime-manager.js +4 -12
  103. package/dist/runtime/channels/channel-socket-options.js +3 -2
  104. package/dist/runtime/channels/channel-socket-registry.d.ts +30 -32
  105. package/dist/runtime/channels/channel-socket-registry.js +296 -235
  106. package/dist/runtime/channels/channel-transports.d.ts +11 -20
  107. package/dist/runtime/channels/channel-transports.js +68 -47
  108. package/dist/runtime/channels/client-server-location-runtime.d.ts +1 -1
  109. package/dist/runtime/channels/client-server-location-runtime.js +10 -11
  110. package/dist/runtime/channels/client-server-service-wire.d.ts +7 -2
  111. package/dist/runtime/channels/client-server-service-wire.js +32 -11
  112. package/dist/runtime/channels/dispatch-error-reporter.d.ts +1 -2
  113. package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
  114. package/dist/runtime/channels/fanout-location-runtime.d.ts +16 -3
  115. package/dist/runtime/channels/fanout-location-runtime.js +133 -81
  116. package/dist/runtime/channels/spot-direct-envelope.d.ts +1 -0
  117. package/dist/runtime/channels/spot-direct-envelope.js +4 -3
  118. package/dist/runtime/channels/spot-node-route-transport.js +3 -2
  119. package/dist/runtime/diagnostics/diagnostic-text.d.ts +2 -0
  120. package/dist/runtime/diagnostics/diagnostic-text.js +7 -0
  121. package/dist/runtime/diagnostics/dispatch-error-details.d.ts +3 -0
  122. package/dist/runtime/diagnostics/dispatch-error-details.js +30 -2
  123. package/dist/runtime/diagnostics/flow-context.d.ts +6 -0
  124. package/dist/runtime/diagnostics/flow-context.js +16 -2
  125. package/dist/runtime/diagnostics/index.d.ts +4 -2
  126. package/dist/runtime/diagnostics/index.js +14 -4
  127. package/dist/runtime/diagnostics/message-flow.d.ts +1 -1
  128. package/dist/runtime/diagnostics/message-flow.js +10 -19
  129. package/dist/runtime/diagnostics/runtime-metrics.d.ts +94 -31
  130. package/dist/runtime/diagnostics/runtime-metrics.js +168 -105
  131. package/dist/runtime/diagnostics/runtime-observation-queue.js +3 -2
  132. package/dist/runtime/diagnostics/topology-runtime-projections.d.ts +2 -4
  133. package/dist/runtime/diagnostics/topology-runtime-projections.js +135 -154
  134. package/dist/runtime/disposal.d.ts +5 -0
  135. package/dist/runtime/disposal.js +22 -0
  136. package/dist/runtime/execution/index.d.ts +22 -9
  137. package/dist/runtime/execution/index.js +107 -37
  138. package/dist/runtime/execution/serial-execution-queue.d.ts +12 -7
  139. package/dist/runtime/execution/serial-execution-queue.js +99 -26
  140. package/dist/runtime/execution/state-lane.d.ts +8 -1
  141. package/dist/runtime/execution/state-lane.js +118 -3
  142. package/dist/runtime/foundation/actor-join-recovery-codec.d.ts +3 -0
  143. package/dist/runtime/foundation/actor-join-recovery-codec.js +15 -11
  144. package/dist/runtime/foundation/event-loop-resources.d.ts +2 -24
  145. package/dist/runtime/foundation/event-loop-resources.js +6 -119
  146. package/dist/runtime/foundation/listener-records.d.ts +11 -0
  147. package/dist/runtime/foundation/listener-records.js +20 -0
  148. package/dist/runtime/foundation/operation-identity.d.ts +2 -0
  149. package/dist/runtime/foundation/operation-identity.js +9 -5
  150. package/dist/runtime/foundation/operation-registry.d.ts +5 -7
  151. package/dist/runtime/foundation/operation-registry.js +34 -44
  152. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +18 -26
  153. package/dist/runtime/foundation/raw-service-mesh-runtime.js +122 -469
  154. package/dist/runtime/foundation/runtime-state-projections.d.ts +3 -1
  155. package/dist/runtime/foundation/runtime-state-projections.js +8 -0
  156. package/dist/runtime/foundation/service-authority-payload-codec.d.ts +1 -0
  157. package/dist/runtime/foundation/service-authority-payload-codec.js +30 -12
  158. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  159. package/dist/runtime/foundation/service-discovery-registry.js +22 -3
  160. package/dist/runtime/foundation/service-instance-activation-recovery-codec.js +8 -4
  161. package/dist/runtime/foundation/service-liveness-registry.js +2 -1
  162. package/dist/runtime/foundation/service-maintenance-runtime.d.ts +0 -1
  163. package/dist/runtime/foundation/service-maintenance-runtime.js +23 -8
  164. package/dist/runtime/foundation/service-metadata-codec.js +3 -3
  165. package/dist/runtime/foundation/service-relocation-aggregate-committer.d.ts +2 -5
  166. package/dist/runtime/foundation/service-relocation-aggregate-committer.js +1 -48
  167. package/dist/runtime/foundation/service-relocation-coordinator.d.ts +9 -0
  168. package/dist/runtime/foundation/service-relocation-coordinator.js +14 -1
  169. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +8 -0
  170. package/dist/runtime/foundation/service-relocation-object-owner.js +19 -6
  171. package/dist/runtime/foundation/service-relocation-runtime.js +43 -32
  172. package/dist/runtime/foundation/service-runtime-contracts.d.ts +40 -8
  173. package/dist/runtime/foundation/service-runtime-contracts.js +25 -1
  174. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +0 -19
  175. package/dist/runtime/foundation/service-stateful-registry.d.ts +2 -0
  176. package/dist/runtime/foundation/service-stateful-registry.js +10 -2
  177. package/dist/runtime/foundation/service-stateful-runtime.d.ts +28 -24
  178. package/dist/runtime/foundation/service-stateful-runtime.js +297 -244
  179. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +12 -7
  180. package/dist/runtime/foundation/service-stateful-wire-codec.js +240 -143
  181. package/dist/runtime/foundation/service-topology-registry.d.ts +1 -3
  182. package/dist/runtime/foundation/service-topology-registry.js +22 -61
  183. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +5 -0
  184. package/dist/runtime/foundation/service-wire-binary-primitives.js +6 -0
  185. package/dist/runtime/foundation/service-wire-codec.js +10 -8
  186. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  187. package/dist/runtime/foundation/service-wire-constants.generated.js +2 -1
  188. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +2 -0
  189. package/dist/runtime/foundation/service-wire-m6a-codec.js +23 -13
  190. package/dist/runtime/framework-errors-internal.d.ts +2 -1
  191. package/dist/runtime/framework-errors-internal.js +343 -122
  192. package/dist/runtime/handlers/handler-instance-scope.d.ts +3 -1
  193. package/dist/runtime/handlers/handler-instance-scope.js +61 -74
  194. package/dist/runtime/host/actor-packet-relay.d.ts +9 -6
  195. package/dist/runtime/host/actor-packet-relay.js +48 -91
  196. package/dist/runtime/host/actor-placement-coordinator.js +7 -5
  197. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  198. package/dist/runtime/host/actor-runtime-options-factory.js +17 -4
  199. package/dist/runtime/host/actor-transfer-runtime.d.ts +28 -28
  200. package/dist/runtime/host/actor-transfer-runtime.js +210 -256
  201. package/dist/runtime/host/application-job-queue.js +16 -33
  202. package/dist/runtime/host/bound-session-relay.js +1 -1
  203. package/dist/runtime/host/channel-runtime-options-factory.js +1 -1
  204. package/dist/runtime/host/index.d.ts +19 -14
  205. package/dist/runtime/host/index.js +234 -175
  206. package/dist/runtime/host/instance-activation-authority.d.ts +2 -3
  207. package/dist/runtime/host/instance-activation-authority.js +17 -45
  208. package/dist/runtime/host/location-runtime-owner.d.ts +1 -1
  209. package/dist/runtime/host/location-runtime-owner.js +2 -2
  210. package/dist/runtime/host/remote-actor-join-receiver.d.ts +2 -2
  211. package/dist/runtime/host/remote-actor-join-receiver.js +1 -14
  212. package/dist/runtime/host/remote-actor-packet-target-store.d.ts +3 -2
  213. package/dist/runtime/host/remote-actor-packet-target-store.js +8 -47
  214. package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -3
  215. package/dist/runtime/host/remote-bound-session-relay.js +11 -23
  216. package/dist/runtime/host/route-mesh-runtime.d.ts +14 -10
  217. package/dist/runtime/host/route-mesh-runtime.js +178 -257
  218. package/dist/runtime/host/runtime-shutdown.d.ts +2 -0
  219. package/dist/runtime/host/runtime-shutdown.js +18 -21
  220. package/dist/runtime/host/service-relocation-control.js +6 -1
  221. package/dist/runtime/host/service-relocation-host-runtime.d.ts +71 -38
  222. package/dist/runtime/host/service-relocation-host-runtime.js +816 -651
  223. package/dist/runtime/host/spot-address-transport.d.ts +2 -3
  224. package/dist/runtime/host/spot-address-transport.js +34 -136
  225. package/dist/runtime/host/spot-node-runtime-options-factory.d.ts +1 -1
  226. package/dist/runtime/host/spot-node-runtime-options-factory.js +3 -2
  227. package/dist/runtime/host/spot-runtime-options-factory.d.ts +4 -7
  228. package/dist/runtime/host/spot-runtime-options-factory.js +53 -21
  229. package/dist/runtime/host/stateful-authority-route-runtime.js +6 -2
  230. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +14 -6
  231. package/dist/runtime/host/user-spot-creation-coordinator.js +96 -95
  232. package/dist/runtime/locations/aggregate-inventory-store.js +13 -10
  233. package/dist/runtime/locations/authority-key-codec.js +4 -3
  234. package/dist/runtime/locations/auto-connect-reconciler.d.ts +4 -0
  235. package/dist/runtime/locations/auto-connect-reconciler.js +37 -25
  236. package/dist/runtime/locations/creation-operation-id.js +6 -4
  237. package/dist/runtime/locations/domain-store-contract.d.ts +3 -3
  238. package/dist/runtime/locations/in-memory-authority-store.js +31 -15
  239. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  240. package/dist/runtime/locations/in-memory-location-store.js +17 -14
  241. package/dist/runtime/locations/in-memory-provider-location-store.d.ts +1 -0
  242. package/dist/runtime/locations/in-memory-provider-location-store.js +79 -27
  243. package/dist/runtime/locations/key-codec.js +3 -2
  244. package/dist/runtime/locations/lease-tracker.d.ts +3 -5
  245. package/dist/runtime/locations/lease-tracker.js +7 -11
  246. package/dist/runtime/locations/lifecycle.d.ts +5 -10
  247. package/dist/runtime/locations/lifecycle.js +4 -33
  248. package/dist/runtime/locations/location-store-failure.d.ts +2 -0
  249. package/dist/runtime/locations/location-store-failure.js +7 -0
  250. package/dist/runtime/locations/location-store-pages.d.ts +3 -0
  251. package/dist/runtime/locations/location-store-pages.js +13 -0
  252. package/dist/runtime/locations/location-store-repository.d.ts +5 -7
  253. package/dist/runtime/locations/location-store-repository.js +303 -332
  254. package/dist/runtime/locations/relocation-blob.js +18 -5
  255. package/dist/runtime/locations/resolvers.d.ts +5 -5
  256. package/dist/runtime/locations/resolvers.js +44 -30
  257. package/dist/runtime/locations/runtime.d.ts +5 -4
  258. package/dist/runtime/locations/runtime.js +123 -92
  259. package/dist/runtime/locations/spot-location-claims.d.ts +8 -2
  260. package/dist/runtime/locations/spot-location-claims.js +40 -23
  261. package/dist/runtime/messaging/payload-codec.js +26 -20
  262. package/dist/runtime/messaging/submission-result.d.ts +3 -0
  263. package/dist/runtime/messaging/submission-result.js +48 -0
  264. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +2 -0
  265. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -8
  266. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +1 -0
  267. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +3 -2
  268. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +3 -3
  269. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +4 -4
  270. package/dist/runtime/spots/formal-remote-actor-transfer-registry.d.ts +6 -3
  271. package/dist/runtime/spots/index.d.ts +29 -29
  272. package/dist/runtime/spots/index.js +441 -313
  273. package/dist/runtime/spots/spot-activation-registry.d.ts +4 -4
  274. package/dist/runtime/spots/spot-activation-registry.js +27 -60
  275. package/dist/runtime/spots/spot-activation-state.d.ts +2 -11
  276. package/dist/runtime/spots/spot-activation-state.js +4 -17
  277. package/dist/runtime/spots/spot-activation.d.ts +10 -9
  278. package/dist/runtime/spots/spot-activation.js +103 -81
  279. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -2
  280. package/dist/runtime/spots/spot-actor-admission-coordinator.js +3 -40
  281. package/dist/runtime/spots/spot-actor-join-dispatch.d.ts +10 -18
  282. package/dist/runtime/spots/spot-actor-join-dispatch.js +5 -55
  283. package/dist/runtime/spots/spot-actor-lifecycle-drain.js +2 -2
  284. package/dist/runtime/spots/spot-actor-membership.d.ts +7 -5
  285. package/dist/runtime/spots/spot-actor-membership.js +44 -53
  286. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +0 -1
  287. package/dist/runtime/spots/spot-actor-packet-dispatch.js +0 -9
  288. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.d.ts +2 -2
  289. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -7
  290. package/dist/runtime/spots/spot-context.d.ts +2 -2
  291. package/dist/runtime/spots/spot-entry-activation.d.ts +3 -4
  292. package/dist/runtime/spots/spot-entry-activation.js +9 -21
  293. package/dist/runtime/spots/spot-lifecycle-metrics.js +3 -2
  294. package/dist/runtime/spots/spot-manager-public.d.ts +5 -6
  295. package/dist/runtime/spots/spot-manager-public.js +6 -5
  296. package/dist/runtime/spots/spot-node-autoconnect.js +22 -31
  297. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +22 -21
  298. package/dist/runtime/spots/spot-node-runtime-manager.js +73 -82
  299. package/dist/runtime/spots/spot-outbound.d.ts +4 -3
  300. package/dist/runtime/spots/spot-outbound.js +10 -37
  301. package/dist/runtime/spots/spot-remote-codec.js +5 -3
  302. package/dist/runtime/spots/spot-route-packet-dispatch.d.ts +2 -2
  303. package/dist/runtime/spots/spot-route-packet-dispatch.js +8 -8
  304. package/dist/runtime/spots/spot-route-replies.d.ts +2 -2
  305. package/dist/runtime/spots/spot-route-replies.js +3 -1
  306. package/dist/runtime/spots/spot-routed-actor-admission.d.ts +3 -2
  307. package/dist/runtime/spots/spot-routed-actor-admission.js +3 -2
  308. package/dist/runtime/spots/spot-routed-frame-dispatch.d.ts +2 -7
  309. package/dist/runtime/spots/spot-routed-frame-dispatch.js +1 -70
  310. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +4 -0
  311. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +65 -15
  312. package/dist/runtime/spots/spot-runtime-ports.d.ts +4 -20
  313. package/dist/runtime/spots/spot-serial-executor.d.ts +5 -0
  314. package/dist/runtime/spots/spot-serial-executor.js +9 -2
  315. package/dist/runtime/spots/spot-serial-turn-executor.d.ts +29 -6
  316. package/dist/runtime/spots/spot-serial-turn-executor.js +89 -13
  317. package/dist/runtime/spots/spot-timer.d.ts +3 -2
  318. package/dist/runtime/streams/actor-session-binding-registry.d.ts +17 -32
  319. package/dist/runtime/streams/actor-session-binding-registry.js +145 -367
  320. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +2 -6
  321. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +6 -2
  322. package/dist/runtime/streams/bound-actor-relay-sender.js +57 -33
  323. package/dist/runtime/streams/bound-session-service.d.ts +7 -0
  324. package/dist/runtime/streams/bound-session-service.js +12 -19
  325. package/dist/runtime/streams/index.d.ts +15 -14
  326. package/dist/runtime/streams/index.js +38 -39
  327. package/dist/runtime/streams/managed-stream.d.ts +3 -0
  328. package/dist/runtime/streams/managed-stream.js +17 -8
  329. package/dist/runtime/streams/native-fallback-bound-session.js +1 -3
  330. package/dist/runtime/streams/protocol.d.ts +6 -33
  331. package/dist/runtime/streams/protocol.js +38 -110
  332. package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -3
  333. package/dist/runtime/streams/session-actor-coordinator.js +12 -4
  334. package/dist/runtime/streams/session-calls.d.ts +1 -1
  335. package/dist/runtime/streams/session-calls.js +5 -4
  336. package/dist/runtime/streams/session-context.d.ts +6 -6
  337. package/dist/runtime/streams/session-context.js +22 -4
  338. package/dist/runtime/streams/session-requests.js +2 -1
  339. package/dist/runtime/streams/session-serial-executor.js +2 -2
  340. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +16 -1
  341. package/dist/runtime/streams/stream-frame-factory.js +2 -2
  342. package/dist/runtime/streams/stream-session-runtime.d.ts +10 -11
  343. package/dist/runtime/streams/stream-session-runtime.js +25 -33
  344. package/dist/runtime/workers/index.d.ts +2 -2
  345. package/dist/runtime/workers/index.js +5 -4
  346. package/package.json +3 -3
  347. package/src/contracts/Channels/IZLinkFanoutClient.ts +0 -7
  348. package/src/contracts/Common/CoreTypes.ts +7 -0
  349. package/src/contracts/Common/index.ts +1 -1
  350. package/src/contracts/Configuration/InternalDefaults.ts +12 -0
  351. package/src/contracts/Configuration/Registration.ts +92 -48
  352. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +44 -2
  353. package/src/contracts/Configuration/RegistrationBuilders.ts +77 -68
  354. package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
  355. package/src/contracts/Configuration/RegistrationValidators.ts +19 -13
  356. package/src/contracts/Configuration/TimerRegistrationValidator.ts +4 -2
  357. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +1 -0
  358. package/src/contracts/Handlers/JsonContract.ts +14 -4
  359. package/src/contracts/Locations/Authority.ts +7 -3
  360. package/src/contracts/Locations/Options.ts +1 -1
  361. package/src/contracts/Locations/Stores.ts +14 -0
  362. package/src/contracts/RouteMesh/RuntimeTopology.ts +10 -0
  363. package/src/contracts/Spots/Contracts.ts +1 -1
  364. package/src/internal.ts +15 -0
  365. package/src/nest-integration.ts +28 -10
  366. package/src/runtime/abort.ts +6 -5
  367. package/src/runtime/activation-admission.ts +72 -0
  368. package/src/runtime/actors/actor-authority-payload-codec.ts +58 -20
  369. package/src/runtime/actors/actor-client.ts +77 -204
  370. package/src/runtime/actors/actor-context.ts +45 -39
  371. package/src/runtime/actors/actor-handoff.ts +55 -45
  372. package/src/runtime/actors/actor-lifecycle-snapshot.ts +2 -1
  373. package/src/runtime/actors/actor-local-native-join.ts +174 -215
  374. package/src/runtime/actors/actor-native-lookup.ts +2 -9
  375. package/src/runtime/actors/actor-packet-relay-wire.ts +18 -12
  376. package/src/runtime/actors/actor-remote-joiner.ts +15 -36
  377. package/src/runtime/actors/actor-remote-wire.ts +5 -3
  378. package/src/runtime/actors/actor-request-deadline.ts +49 -0
  379. package/src/runtime/actors/actor-retry-delay.ts +2 -1
  380. package/src/runtime/actors/actor-runtime-contracts.ts +4 -10
  381. package/src/runtime/actors/actor-runtime-state.ts +85 -247
  382. package/src/runtime/actors/actor-source-transfer.ts +5 -18
  383. package/src/runtime/actors/bound-session-wire.ts +2 -8
  384. package/src/runtime/actors/deferred-join-completion.ts +44 -0
  385. package/src/runtime/actors/index.ts +122 -88
  386. package/src/runtime/actors/spot-actor-dispatch.ts +60 -29
  387. package/src/runtime/actors/transferred-actor-rollback.ts +11 -62
  388. package/src/runtime/admission.ts +13 -2
  389. package/src/runtime/application-jobs/application-job-queue-scope.ts +4 -4
  390. package/src/runtime/backend/contracts/index.ts +15 -42
  391. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +4 -28
  392. package/src/runtime/backend/mesh-dispatch-pump.ts +111 -117
  393. package/src/runtime/backend/node/node-backend-adapter-factory.ts +5 -25
  394. package/src/runtime/backend/node/node-backend-adapter-support.ts +32 -35
  395. package/src/runtime/backend/node/node-event-loop-poller.ts +16 -8
  396. package/src/runtime/backend/node/node-monitor-backend-adapter.ts +1 -0
  397. package/src/runtime/backend/node/node-raw-binding-port.ts +58 -23
  398. package/src/runtime/backend/node/node-raw-mesh-backend.ts +252 -162
  399. package/src/runtime/backend/node/node-socket-backend-adapter.ts +5 -4
  400. package/src/runtime/backend/raw-binding-port.ts +14 -1
  401. package/src/runtime/backend/runtime-values.ts +4 -1
  402. package/src/runtime/channels/channel-clients.ts +132 -96
  403. package/src/runtime/channels/channel-envelope-inspection.ts +2 -1
  404. package/src/runtime/channels/channel-envelope.ts +58 -29
  405. package/src/runtime/channels/channel-outbound-operations.ts +10 -31
  406. package/src/runtime/channels/channel-receive-loops.ts +39 -7
  407. package/src/runtime/channels/channel-runtime-lifecycle.ts +60 -27
  408. package/src/runtime/channels/channel-runtime-manager.ts +8 -15
  409. package/src/runtime/channels/channel-socket-options.ts +8 -2
  410. package/src/runtime/channels/channel-socket-registry.ts +369 -262
  411. package/src/runtime/channels/channel-transports.ts +161 -115
  412. package/src/runtime/channels/client-server-location-runtime.ts +17 -17
  413. package/src/runtime/channels/client-server-service-wire.ts +40 -12
  414. package/src/runtime/channels/dispatch-error-reporter.ts +7 -5
  415. package/src/runtime/channels/fanout-location-runtime.ts +175 -106
  416. package/src/runtime/channels/spot-direct-envelope.ts +1 -1
  417. package/src/runtime/channels/spot-node-route-transport.ts +5 -2
  418. package/src/runtime/diagnostics/diagnostic-text.ts +4 -0
  419. package/src/runtime/diagnostics/dispatch-error-details.ts +36 -1
  420. package/src/runtime/diagnostics/flow-context.ts +16 -2
  421. package/src/runtime/diagnostics/index.ts +27 -17
  422. package/src/runtime/diagnostics/message-flow.ts +15 -25
  423. package/src/runtime/diagnostics/runtime-metrics.ts +181 -113
  424. package/src/runtime/diagnostics/runtime-observation-queue.ts +3 -2
  425. package/src/runtime/diagnostics/topology-runtime-projections.ts +194 -162
  426. package/src/runtime/disposal.ts +19 -0
  427. package/src/runtime/execution/index.ts +116 -38
  428. package/src/runtime/execution/serial-execution-queue.ts +179 -34
  429. package/src/runtime/execution/state-lane.ts +142 -4
  430. package/src/runtime/foundation/actor-join-recovery-codec.ts +13 -8
  431. package/src/runtime/foundation/event-loop-resources.ts +5 -122
  432. package/src/runtime/foundation/listener-records.ts +21 -0
  433. package/src/runtime/foundation/operation-identity.ts +11 -5
  434. package/src/runtime/foundation/operation-registry.ts +33 -50
  435. package/src/runtime/foundation/raw-service-mesh-runtime.ts +170 -571
  436. package/src/runtime/foundation/runtime-state-projections.ts +9 -1
  437. package/src/runtime/foundation/service-authority-payload-codec.ts +41 -13
  438. package/src/runtime/foundation/service-discovery-registry.ts +32 -3
  439. package/src/runtime/foundation/service-instance-activation-recovery-codec.ts +12 -4
  440. package/src/runtime/foundation/service-liveness-registry.ts +2 -1
  441. package/src/runtime/foundation/service-maintenance-runtime.ts +30 -19
  442. package/src/runtime/foundation/service-metadata-codec.ts +2 -2
  443. package/src/runtime/foundation/service-relocation-aggregate-committer.ts +3 -66
  444. package/src/runtime/foundation/service-relocation-coordinator.ts +13 -0
  445. package/src/runtime/foundation/service-relocation-object-owner.ts +23 -7
  446. package/src/runtime/foundation/service-relocation-runtime.ts +57 -35
  447. package/src/runtime/foundation/service-runtime-contracts.ts +46 -10
  448. package/src/runtime/foundation/service-session-binding-ingress-port.ts +0 -25
  449. package/src/runtime/foundation/service-stateful-registry.ts +14 -2
  450. package/src/runtime/foundation/service-stateful-runtime.ts +435 -327
  451. package/src/runtime/foundation/service-stateful-wire-codec.ts +329 -199
  452. package/src/runtime/foundation/service-topology-registry.ts +30 -79
  453. package/src/runtime/foundation/service-wire-binary-primitives.ts +6 -0
  454. package/src/runtime/foundation/service-wire-codec.ts +15 -8
  455. package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
  456. package/src/runtime/foundation/service-wire-m6a-codec.ts +29 -15
  457. package/src/runtime/framework-errors-internal.ts +380 -134
  458. package/src/runtime/handlers/handler-instance-scope.ts +68 -95
  459. package/src/runtime/host/actor-packet-relay.ts +57 -147
  460. package/src/runtime/host/actor-placement-coordinator.ts +8 -5
  461. package/src/runtime/host/actor-runtime-options-factory.ts +27 -8
  462. package/src/runtime/host/actor-transfer-runtime.ts +266 -418
  463. package/src/runtime/host/application-job-queue.ts +28 -34
  464. package/src/runtime/host/bound-session-relay.ts +1 -2
  465. package/src/runtime/host/channel-runtime-options-factory.ts +1 -2
  466. package/src/runtime/host/index.ts +408 -312
  467. package/src/runtime/host/instance-activation-authority.ts +89 -109
  468. package/src/runtime/host/location-runtime-owner.ts +4 -2
  469. package/src/runtime/host/remote-actor-join-receiver.ts +3 -31
  470. package/src/runtime/host/remote-actor-packet-target-store.ts +17 -58
  471. package/src/runtime/host/remote-bound-session-relay.ts +12 -44
  472. package/src/runtime/host/route-mesh-runtime.ts +236 -275
  473. package/src/runtime/host/runtime-shutdown.ts +17 -21
  474. package/src/runtime/host/service-relocation-control.ts +14 -1
  475. package/src/runtime/host/service-relocation-host-runtime.ts +1161 -904
  476. package/src/runtime/host/spot-address-transport.ts +73 -195
  477. package/src/runtime/host/spot-node-runtime-options-factory.ts +6 -3
  478. package/src/runtime/host/spot-runtime-options-factory.ts +92 -30
  479. package/src/runtime/host/stateful-authority-route-runtime.ts +8 -4
  480. package/src/runtime/host/user-spot-creation-coordinator.ts +182 -163
  481. package/src/runtime/locations/aggregate-inventory-store.ts +16 -13
  482. package/src/runtime/locations/authority-key-codec.ts +7 -3
  483. package/src/runtime/locations/auto-connect-reconciler.ts +39 -26
  484. package/src/runtime/locations/creation-operation-id.ts +6 -3
  485. package/src/runtime/locations/domain-store-contract.ts +12 -3
  486. package/src/runtime/locations/in-memory-authority-store.ts +44 -15
  487. package/src/runtime/locations/in-memory-location-store.ts +50 -39
  488. package/src/runtime/locations/in-memory-provider-location-store.ts +110 -31
  489. package/src/runtime/locations/key-codec.ts +3 -2
  490. package/src/runtime/locations/lease-tracker.ts +8 -14
  491. package/src/runtime/locations/lifecycle.ts +16 -45
  492. package/src/runtime/locations/location-store-failure.ts +4 -0
  493. package/src/runtime/locations/location-store-pages.ts +18 -0
  494. package/src/runtime/locations/location-store-repository.ts +450 -478
  495. package/src/runtime/locations/relocation-blob.ts +17 -6
  496. package/src/runtime/locations/resolvers.ts +90 -58
  497. package/src/runtime/locations/runtime.ts +220 -110
  498. package/src/runtime/locations/spot-location-claims.ts +54 -26
  499. package/src/runtime/messaging/payload-codec.ts +35 -24
  500. package/src/runtime/messaging/submission-result.ts +57 -1
  501. package/src/runtime/protocol/service_wire_codec.generated.ts +27 -10
  502. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  503. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +6 -6
  504. package/src/runtime/spots/formal-remote-actor-transfer-registry.ts +6 -3
  505. package/src/runtime/spots/index.ts +687 -437
  506. package/src/runtime/spots/spot-activation-registry.ts +42 -71
  507. package/src/runtime/spots/spot-activation-state.ts +4 -16
  508. package/src/runtime/spots/spot-activation.ts +167 -115
  509. package/src/runtime/spots/spot-actor-admission-coordinator.ts +5 -57
  510. package/src/runtime/spots/spot-actor-join-dispatch.ts +25 -79
  511. package/src/runtime/spots/spot-actor-lifecycle-drain.ts +20 -18
  512. package/src/runtime/spots/spot-actor-membership.ts +107 -75
  513. package/src/runtime/spots/spot-actor-packet-dispatch.ts +0 -16
  514. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +3 -15
  515. package/src/runtime/spots/spot-context.ts +3 -3
  516. package/src/runtime/spots/spot-entry-activation.ts +13 -33
  517. package/src/runtime/spots/spot-lifecycle-metrics.ts +3 -2
  518. package/src/runtime/spots/spot-manager-public.ts +29 -21
  519. package/src/runtime/spots/spot-node-autoconnect.ts +20 -26
  520. package/src/runtime/spots/spot-node-runtime-manager.ts +145 -140
  521. package/src/runtime/spots/spot-outbound.ts +47 -68
  522. package/src/runtime/spots/spot-remote-codec.ts +7 -3
  523. package/src/runtime/spots/spot-route-packet-dispatch.ts +25 -24
  524. package/src/runtime/spots/spot-route-replies.ts +6 -4
  525. package/src/runtime/spots/spot-routed-actor-admission.ts +13 -6
  526. package/src/runtime/spots/spot-routed-frame-dispatch.ts +6 -77
  527. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +95 -22
  528. package/src/runtime/spots/spot-runtime-ports.ts +10 -43
  529. package/src/runtime/spots/spot-serial-executor.ts +10 -2
  530. package/src/runtime/spots/spot-serial-turn-executor.ts +120 -13
  531. package/src/runtime/spots/spot-timer.ts +3 -2
  532. package/src/runtime/streams/actor-session-binding-registry.ts +182 -560
  533. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +1 -19
  534. package/src/runtime/streams/bound-actor-relay-sender.ts +89 -43
  535. package/src/runtime/streams/bound-session-service.ts +23 -37
  536. package/src/runtime/streams/index.ts +102 -88
  537. package/src/runtime/streams/managed-stream.ts +29 -10
  538. package/src/runtime/streams/native-fallback-bound-session.ts +1 -3
  539. package/src/runtime/streams/protocol.ts +34 -88
  540. package/src/runtime/streams/session-actor-coordinator.ts +17 -5
  541. package/src/runtime/streams/session-calls.ts +6 -5
  542. package/src/runtime/streams/session-context.ts +54 -10
  543. package/src/runtime/streams/session-requests.ts +2 -1
  544. package/src/runtime/streams/session-serial-executor.ts +2 -2
  545. package/src/runtime/streams/stream-binding-runtime-ports.ts +22 -1
  546. package/src/runtime/streams/stream-frame-factory.ts +2 -3
  547. package/src/runtime/streams/stream-session-runtime.ts +57 -59
  548. package/src/runtime/workers/index.ts +13 -12
  549. package/dist/runtime/actors/deferred-join-accepted-journal.d.ts +0 -47
  550. package/dist/runtime/actors/deferred-join-accepted-journal.js +0 -992
  551. package/dist/runtime/actors/post-commit-actor-location.d.ts +0 -19
  552. package/dist/runtime/actors/post-commit-actor-location.js +0 -72
  553. package/dist/runtime/spots/spot-native-actor-join-admission.d.ts +0 -26
  554. package/dist/runtime/spots/spot-native-actor-join-admission.js +0 -106
  555. package/src/runtime/actors/deferred-join-accepted-journal.ts +0 -1346
  556. package/src/runtime/actors/post-commit-actor-location.ts +0 -121
  557. package/src/runtime/spots/spot-native-actor-join-admission.ts +0 -155
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultZLinkSpotManager = exports.ZLinkPublicSpotManager = exports.ZLinkSpotNodeRuntimeManager = exports.createFrameworkEntrySpotId = exports.ZLinkEntrySpotActivation = exports.ZLinkRuntimeSpotPublisherTransport = exports.DefaultZLinkSpotHandlerRegistry = exports.DefaultZLinkSpotOutbound = exports.ZLinkSpotTimerRegistry = exports.ZLinkManagedTimer = exports.ZLinkSpotSerialExecutor = exports.ZLinkSpotSerialTurnExecutor = exports.ZLinkSpotActorAdmissionCoordinator = exports.ZLinkSpotRoutedBoundSessionDispatch = exports.sendToSpotHandle = exports.requestToSpotHandle = exports.resolveSpotHandle = exports.createSpotHandle = void 0;
4
+ const dispatch_error_details_1 = require("../diagnostics/dispatch-error-details");
4
5
  var spot_handle_1 = require("./spot-handle");
5
6
  Object.defineProperty(exports, "createSpotHandle", { enumerable: true, get: function () { return spot_handle_1.createSpotHandle; } });
6
7
  Object.defineProperty(exports, "resolveSpotHandle", { enumerable: true, get: function () { return spot_handle_1.resolveSpotHandle; } });
@@ -15,11 +16,13 @@ const abort_1 = require("../abort");
15
16
  const contracts_1 = require("../../contracts");
16
17
  const ZLinkDispatchOptions_1 = require("../../contracts/Dispatch/ZLinkDispatchOptions");
17
18
  const diagnostics_1 = require("../diagnostics");
19
+ const diagnostic_text_1 = require("../diagnostics/diagnostic-text");
18
20
  const runtime_message_1 = require("../backend/runtime-message");
19
21
  const runtime_values_1 = require("../backend/runtime-values");
20
22
  const service_runtime_contracts_1 = require("../foundation/service-runtime-contracts");
21
23
  const serial_work_size_1 = require("../execution/serial-work-size");
22
24
  const configuration_1 = require("../configuration");
25
+ const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
23
26
  const framework_errors_internal_1 = require("../framework-errors-internal");
24
27
  const workers_1 = require("../workers");
25
28
  const payload_codec_1 = require("../messaging/payload-codec");
@@ -44,7 +47,6 @@ Object.defineProperty(exports, "DefaultZLinkSpotHandlerRegistry", { enumerable:
44
47
  var spot_publisher_transport_1 = require("./spot-publisher-transport");
45
48
  Object.defineProperty(exports, "ZLinkRuntimeSpotPublisherTransport", { enumerable: true, get: function () { return spot_publisher_transport_1.ZLinkRuntimeSpotPublisherTransport; } });
46
49
  const spot_activation_registry_1 = require("./spot-activation-registry");
47
- const spot_activation_state_1 = require("./spot-activation-state");
48
50
  const spot_activation_1 = require("./spot-activation");
49
51
  const spot_actor_membership_1 = require("./spot-actor-membership");
50
52
  const formal_remote_actor_transfer_registry_1 = require("./formal-remote-actor-transfer-registry");
@@ -74,8 +76,7 @@ class DefaultZLinkSpotManager {
74
76
  // callbacks (isInstanceMaterializing, sibling-generation lookups) resolve
75
77
  // in O(1) instead of scanning every pending key.
76
78
  pendingInstanceMaterializationsByPrefix = new Map();
77
- instanceActivationGates = new Map();
78
- pendingInstanceCloses = new Map();
79
+ closeOperations = new Map();
79
80
  pendingInstanceTerminals = new Map();
80
81
  pendingInstanceTerminalGenerations = new Map();
81
82
  deferredInstanceAuthorityReleases = new Map();
@@ -83,6 +84,9 @@ class DefaultZLinkSpotManager {
83
84
  idleSweepRunning = false;
84
85
  constructor(options, timerClock) {
85
86
  this.options = options;
87
+ if (options.detachedTaskRunner === undefined) {
88
+ throw new configuration_1.ZLinkConfigurationException('Spot manager requires a detached task runner.');
89
+ }
86
90
  this.activations = new spot_activation_registry_1.ZLinkSpotActivationRegistry(options.metrics);
87
91
  this.factories = new Set(options.spotFactories);
88
92
  this.workerRuntime = options.workerRuntime ?? new workers_1.ZLinkWorkerRuntime();
@@ -93,7 +97,7 @@ class DefaultZLinkSpotManager {
93
97
  nodeGenerationProvider: options.nodeGenerationProvider
94
98
  });
95
99
  this.routedSpotPackets = new spot_routed_spot_packet_dispatch_1.ZLinkRoutedSpotPacketDispatch({
96
- resolveActivation: (spotId) => this.activations.resolveUnique(spotId),
100
+ resolveActivation: (spotId) => this.resolveApplicationActivation(spotId),
97
101
  claimApplicationWork: options.admission === undefined
98
102
  ? undefined
99
103
  : (meshName) => options.admission.claim(meshName, 'Spot route dispatch'),
@@ -136,12 +140,12 @@ class DefaultZLinkSpotManager {
136
140
  spotRouterChannelIdForMesh: options.spotRouterChannelIdForMesh,
137
141
  providerResolver: options.providerResolver,
138
142
  dispatchErrors: options.dispatchErrors,
143
+ closeErrorSink: options.closeErrorSink,
139
144
  runtimeEventPublisher: options.runtimeEventPublisher,
140
145
  workerRuntime: this.workerRuntime,
141
146
  messageSerializers: options.messageSerializers,
142
147
  locationClaim: this.locationClaim,
143
148
  createNativeSpot: options.createNativeSpot,
144
- createReceived: options.createReceived,
145
149
  createTopicMessage: options.createTopicMessage,
146
150
  nativeSpotNodeProvider: options.nativeSpotNodeProvider,
147
151
  actorResolver: options.actorResolver,
@@ -150,9 +154,9 @@ class DefaultZLinkSpotManager {
150
154
  boundSessionRuntime: options.boundSessionRuntime,
151
155
  actorHandoffRuntime: options.actorHandoffRuntime,
152
156
  admission: options.admission,
153
- statefulExecutionAllowed: options.statefulExecutionAllowed,
157
+ statefulExecutionAllowed: options.statefulExecution?.admissionOpen,
154
158
  leaveActor: (spotId, actor, signal, meshName) => this.actorMembership.leaveActor(spotId, actor, signal, meshName),
155
- closeSpot: (meshName, spotId, signal, reason) => this.closeWithReason(meshName, spotId, signal, reason),
159
+ requestContextClose: (activation, objectGeneration, signal) => this.closeFromContext(activation, objectGeneration, signal),
156
160
  registerActivation: (activation) => {
157
161
  this.activations.register(activation);
158
162
  this.scheduleIdleSweep();
@@ -199,10 +203,6 @@ class DefaultZLinkSpotManager {
199
203
  activeSpotCount(meshName) {
200
204
  return this.activations.list(meshName).length;
201
205
  }
202
- instanceActivationConcurrency(meshName) {
203
- const limit = this.options.activationConcurrencyLimitProvider?.(meshName) ?? 128;
204
- return { active: this.instanceActivationGates.get(meshName)?.active ?? 0, limit };
205
- }
206
206
  resolveRelocationActivation(meshName, spotId) {
207
207
  return this.activations.resolve(meshName, spotId);
208
208
  }
@@ -237,12 +237,12 @@ class DefaultZLinkSpotManager {
237
237
  await (0, abort_1.awaitWithAbort)(existing, signal);
238
238
  return;
239
239
  }
240
- const release = await this.acquireInstanceActivation(meshName, signal);
240
+ const release = await this.options.activationAdmission?.acquire(meshName, signal);
241
241
  try {
242
242
  await this.materializeInstanceCore(meshName, instanceType, spotId, objectGeneration, readyTarget?.objectGeneration === objectGeneration, signal);
243
243
  }
244
244
  finally {
245
- release();
245
+ release?.();
246
246
  }
247
247
  }
248
248
  async materializeInstanceCore(meshName, instanceType, spotId, objectGeneration, requiresReadyTarget, signal) {
@@ -260,7 +260,8 @@ class DefaultZLinkSpotManager {
260
260
  // explicit Instance intent arriving at that boundary must wait for the
261
261
  // old resources to be released before materializing the replacement.
262
262
  // This is lifecycle convergence; it does not resubmit application work.
263
- const pendingClose = this.pendingInstanceCloses.get(key);
263
+ const closeOperation = this.closeOperations.get(key);
264
+ const pendingClose = closeOperation?.ready;
264
265
  if (pendingClose !== undefined) {
265
266
  await (0, abort_1.awaitWithAbort)(pendingClose, signal);
266
267
  continue;
@@ -340,71 +341,36 @@ class DefaultZLinkSpotManager {
340
341
  return;
341
342
  }
342
343
  }
343
- async acquireInstanceActivation(meshName, signal) {
344
- let gate = this.instanceActivationGates.get(meshName);
345
- if (gate === undefined) {
346
- gate = {
347
- meshName,
348
- limit: this.options.activationConcurrencyLimitProvider?.(meshName) ?? 128,
349
- active: 0,
350
- waiters: [],
351
- waiterHead: 0
352
- };
353
- this.instanceActivationGates.set(meshName, gate);
354
- }
355
- if (signal?.aborted === true)
356
- throw signal.reason;
357
- if (gate.active < gate.limit) {
358
- gate.active += 1;
359
- this.options.onInstanceActivationConcurrencyChanged?.(meshName);
360
- return () => this.releaseInstanceActivation(gate);
361
- }
362
- return new Promise((resolve, reject) => {
363
- const waiter = { resolve, reject, signal, abort: undefined };
364
- const slot = gate.waiters.length;
365
- waiter.abort = () => {
366
- if (gate.waiters[slot] === waiter)
367
- gate.waiters[slot] = undefined;
368
- reject(signal?.reason);
369
- };
370
- signal?.addEventListener('abort', waiter.abort, { once: true });
371
- gate.waiters.push(waiter);
372
- });
373
- }
374
- releaseInstanceActivation(gate) {
375
- while (gate.waiterHead < gate.waiters.length) {
376
- const waiter = gate.waiters[gate.waiterHead];
377
- gate.waiters[gate.waiterHead] = undefined;
378
- gate.waiterHead += 1;
379
- if (gate.waiterHead >= gate.waiters.length) {
380
- gate.waiters.length = 0;
381
- gate.waiterHead = 0;
382
- }
383
- if (waiter === undefined)
384
- continue;
385
- if (waiter.abort !== undefined)
386
- waiter.signal?.removeEventListener('abort', waiter.abort);
387
- waiter.resolve(() => this.releaseInstanceActivation(gate));
388
- return;
389
- }
390
- gate.waiters.length = 0;
391
- gate.waiterHead = 0;
392
- gate.active -= 1;
393
- this.options.onInstanceActivationConcurrencyChanged?.(gate.meshName);
394
- }
395
344
  isInstanceMaterialized(meshName, instanceType, spotId) {
396
- const activation = this.activations.resolve(meshName, spotId);
345
+ const activation = this.resolveApplicationActivation(spotId, meshName);
397
346
  return (activation !== undefined &&
398
347
  activation.spotType === this.requireInstanceFactory(meshName, instanceType));
399
348
  }
349
+ resolveApplicationActivation(spotId, meshName) {
350
+ const current = meshName === undefined
351
+ ? this.activations.resolveUnique(spotId)
352
+ : this.activations.resolve(meshName, spotId);
353
+ if (current !== undefined)
354
+ return current;
355
+ if (meshName !== undefined)
356
+ return this.closeOperations.get(`${meshName}\0${String(spotId)}`)?.activation;
357
+ for (const operation of this.closeOperations.values()) {
358
+ if (String(operation.activation.spotId) === String(spotId))
359
+ return operation.activation;
360
+ }
361
+ return undefined;
362
+ }
400
363
  isInstanceMaterializing(meshName, spotId) {
401
364
  const prefix = instanceMaterializationPrefix(meshName, spotId);
402
- return (this.pendingInstanceMaterializationsByPrefix.get(prefix)?.size ?? 0) > 0;
365
+ return ((this.pendingInstanceMaterializationsByPrefix.get(prefix)?.size ?? 0) > 0 ||
366
+ this.closeOperations.get(`${meshName}\0${String(spotId)}`)?.authority !== undefined);
403
367
  }
404
- isInstanceClosing(meshName, spotId) {
405
- const key = `${meshName}\0${String(spotId)}`;
406
- return (this.pendingInstanceCloses.has(key) ||
407
- this.activations.closingOperation(meshName, spotId) !== undefined);
368
+ isSpotClosing(meshName, spotId) {
369
+ return (this.closeOperations.get(`${meshName}\0${String(spotId)}`)?.authority !== undefined ||
370
+ this.activations.activationForClose(meshName, spotId)?.executionBarrier.isCloseSealed === true);
371
+ }
372
+ pendingSpotCloseDecision(meshName, spotId) {
373
+ return this.closeOperations.get(`${meshName}\0${String(spotId)}`)?.authorityDecision;
408
374
  }
409
375
  async discardInstance(meshName, spotId) {
410
376
  const activation = this.activations.resolve(meshName, spotId);
@@ -443,7 +409,7 @@ class DefaultZLinkSpotManager {
443
409
  }
444
410
  this.pendingInstanceTerminals.delete(key);
445
411
  this.pendingInstanceTerminalGenerations.delete(key);
446
- const pendingClose = this.pendingInstanceCloses.get(key);
412
+ const pendingClose = this.closeOperations.get(key)?.ready;
447
413
  if (pendingClose !== undefined) {
448
414
  this.deferInstanceAuthorityRelease(key, objectGeneration);
449
415
  await pendingClose;
@@ -539,39 +505,20 @@ class DefaultZLinkSpotManager {
539
505
  !activation.beginIdleEviction()) {
540
506
  continue;
541
507
  }
542
- let durableClosing;
543
- try {
544
- durableClosing = await (this.options.beginInstanceIdleClosingAuthority?.(activation.meshName, activation.spotId) ?? Promise.resolve({ restoreReady: async () => undefined }));
545
- }
546
- catch (error) {
547
- activation.abortIdleEviction();
548
- throw error;
549
- }
550
- if (durableClosing === undefined) {
551
- activation.abortIdleEviction();
552
- continue;
553
- }
554
508
  const close = this.closeWithReason(activation.meshName, activation.spotId, undefined, contracts_1.ZLinkSpotCloseReason.IdleEvicted);
555
509
  const run = async () => {
556
510
  try {
557
511
  const closed = await close;
558
- if (!closed) {
559
- await durableClosing.restoreReady();
512
+ if (!closed)
560
513
  activation.abortIdleEviction();
561
- }
562
514
  }
563
515
  catch (error) {
564
- if (error instanceof spot_activation_state_1.ZLinkSpotCloseOccupiedError) {
565
- await durableClosing.restoreReady();
566
- }
567
- activation.abortIdleEviction();
516
+ if (!this.isSpotClosing(activation.meshName, activation.spotId))
517
+ activation.abortIdleEviction();
568
518
  throw error;
569
519
  }
570
520
  };
571
- this.options.detachedTaskRunner?.runDetached(`instance idle eviction ${String(activation.spotId)}`, run);
572
- if (this.options.detachedTaskRunner === undefined) {
573
- void run().catch(() => undefined);
574
- }
521
+ this.options.detachedTaskRunner.runDetached(`instance idle eviction ${String(activation.spotId)}`, run);
575
522
  }
576
523
  }
577
524
  finally {
@@ -601,8 +548,9 @@ class DefaultZLinkSpotManager {
601
548
  requireMeshName(meshName);
602
549
  const args = normalizeSpotCreateArgs(requestOrSignal, signal);
603
550
  (0, abort_1.throwIfAborted)(args.signal);
551
+ this.options.admission?.requireRequest('SPOT create', meshName);
604
552
  const operation = this.activations.getOrBegin(meshName, spotType, spotId, async () => {
605
- this.options.admission?.requireRequest('SPOT create', meshName);
553
+ const release = await this.options.activationAdmission?.acquire(meshName, args.signal);
606
554
  const ownedRequest = args.request === undefined
607
555
  ? runtime_message_1.ZLinkBufferMessage.from(Buffer.alloc(0))
608
556
  : (0, payload_codec_1.encodeFrameworkPayloadMessage)(args.request, this.options.messageSerializers);
@@ -611,17 +559,22 @@ class DefaultZLinkSpotManager {
611
559
  }
612
560
  finally {
613
561
  ownedRequest.close();
562
+ release?.();
614
563
  }
615
564
  });
616
565
  return await (0, abort_1.awaitWithAbort)(operation.ready, args.signal);
617
566
  }
618
567
  async find(meshName, spotId) {
619
568
  requireMeshName(meshName);
620
- return this.activations.has(meshName, spotId) ? { spotId } : null;
569
+ return this.activations.has(meshName, spotId) && !this.isSpotClosing(meshName, spotId)
570
+ ? { spotId }
571
+ : null;
621
572
  }
622
573
  async list(meshName) {
623
574
  requireMeshName(meshName);
624
- return this.activations.list(meshName);
575
+ return this.activations
576
+ .list(meshName)
577
+ .filter(({ spotId }) => !this.isSpotClosing(meshName, spotId));
625
578
  }
626
579
  async drainForShutdown(meshName, signal, deadline) {
627
580
  const results = await Promise.allSettled(this.activations
@@ -639,99 +592,192 @@ class DefaultZLinkSpotManager {
639
592
  async close(meshName, spotId, signal) {
640
593
  return await this.closeWithReason(meshName, spotId, signal, contracts_1.ZLinkSpotCloseReason.ExplicitClose);
641
594
  }
642
- async closeWithReason(meshName, spotId, signal, reason = contracts_1.ZLinkSpotCloseReason.ExplicitClose, deadline) {
595
+ async closeUserWithAuthority(meshName, spotId, beginAuthority, signal) {
596
+ return await this.closeWithReason(meshName, spotId, signal, contracts_1.ZLinkSpotCloseReason.ExplicitClose, undefined, beginAuthority);
597
+ }
598
+ closeFromContext(activation, objectGeneration, signal) {
599
+ const { meshName, spotId } = activation;
600
+ const operation = this.closeOperations.get(`${meshName}\0${String(spotId)}`);
601
+ const current = operation?.activation ?? this.activations.resolve(meshName, spotId);
602
+ if (current === undefined) {
603
+ return Promise.resolve(false);
604
+ }
605
+ if (current !== activation || current.objectGeneration !== objectGeneration) {
606
+ return Promise.reject((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `Spot '${String(spotId)}' generation is stale.`));
607
+ }
608
+ const beginUserAuthority = activation.domain.kind === 'user' && this.options.beginUserClosingAuthority !== undefined
609
+ ? (onCommitted) => this.options.beginUserClosingAuthority(meshName, spotId, objectGeneration, onCommitted)
610
+ : undefined;
611
+ return this.closeWithReason(meshName, spotId, signal, contracts_1.ZLinkSpotCloseReason.ExplicitClose, undefined, beginUserAuthority);
612
+ }
613
+ async closeWithReason(meshName, spotId, signal, reason = contracts_1.ZLinkSpotCloseReason.ExplicitClose, deadline, beginUserAuthority) {
643
614
  requireMeshName(meshName);
644
615
  const key = `${meshName}\0${String(spotId)}`;
645
- const closing = this.activations.closingOperation(meshName, spotId);
646
- if (closing !== undefined) {
647
- return await closing.ready;
616
+ let operation = this.closeOperations.get(key);
617
+ if (operation === undefined) {
618
+ const activation = this.activations.resolve(meshName, spotId);
619
+ if (activation === undefined)
620
+ return false;
621
+ if (activation.domain.kind === 'user' &&
622
+ reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose &&
623
+ beginUserAuthority === undefined) {
624
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation, `User Spot '${String(spotId)}' Close requires its authority owner.`);
625
+ }
626
+ const domain = activation.domain;
627
+ const beginAuthority = beginUserAuthority ??
628
+ (domain.kind === 'instance' &&
629
+ reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose &&
630
+ this.options.beginInstanceClosingAuthority !== undefined
631
+ ? (onCommitted) => this.options.beginInstanceClosingAuthority(meshName, spotId, onCommitted, domain.objectGeneration)
632
+ : domain.kind === 'instance' &&
633
+ reason === contracts_1.ZLinkSpotCloseReason.IdleEvicted &&
634
+ this.options.beginInstanceIdleClosingAuthority !== undefined
635
+ ? (onCommitted) => this.options.beginInstanceIdleClosingAuthority(meshName, spotId, onCommitted)
636
+ : async (onCommitted) => {
637
+ onCommitted();
638
+ return { release: async () => undefined };
639
+ });
640
+ operation = {
641
+ activation,
642
+ reason,
643
+ beginAuthority
644
+ };
645
+ if (reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose) {
646
+ operation.canExecuteApplication = (record) => {
647
+ const context = record.context;
648
+ return context === undefined;
649
+ };
650
+ }
651
+ this.closeOperations.set(key, operation);
648
652
  }
649
- const pendingClose = this.pendingInstanceCloses.get(key);
650
- if (pendingClose !== undefined) {
651
- const pendingActivation = this.activations.resolve(meshName, spotId);
652
- if (pendingActivation?.serial.isCurrentTurn === true)
653
- return true;
654
- return await pendingClose;
653
+ if (operation.ready === undefined) {
654
+ const active = operation;
655
+ const run = active.activation.serial.executeControlLifecycleOperation(() => this.runCloseOperation(meshName, spotId, active, signal, deadline), active.canExecuteApplication === undefined
656
+ ? undefined
657
+ : active);
658
+ active.ready = run.finally(() => {
659
+ active.ready = undefined;
660
+ if (this.closeOperations.get(key) === active) {
661
+ this.closeOperations.delete(key);
662
+ }
663
+ });
655
664
  }
656
- const activation = this.activations.resolve(meshName, spotId);
657
- if (activation === undefined) {
665
+ return await operation.ready;
666
+ }
667
+ async runCloseOperation(meshName, spotId, operation, signal, deadline) {
668
+ const seal = await this.beginCloseAuthority(meshName, spotId, operation, signal);
669
+ if (seal === undefined)
658
670
  return false;
671
+ if (seal !== true) {
672
+ await this.activationLifecycle.sealForClose(operation.activation, seal);
659
673
  }
660
- const currentTurn = activation.serial.isCurrentTurn;
661
- const isInstance = activation.domain.kind === 'instance';
662
- const beginClose = () => {
663
- const seal = activation.sealExecution();
664
- const operation = this.activations.startClose(meshName, spotId, (target) => this.activationLifecycle.closeAfterSeal(target, seal, signal, reason, deadline), (target) => this.activationLifecycle.resourcesReleased(target), reason);
665
- if (operation === undefined) {
666
- activation.abortExecutionSeal(seal);
674
+ else {
675
+ await operation.activation.executionBarrier.waitForStartedTurns(signal);
676
+ }
677
+ const closingFailure = await this.activationLifecycle.cleanupClosedActivation(operation.activation, operation.reason, deadline);
678
+ this.activations.finishClose(meshName, spotId);
679
+ const intentRecords = [];
680
+ operation.activation.serial.visitPendingApplication((record) => {
681
+ const context = record.context;
682
+ if (context?.replay !== undefined)
683
+ intentRecords.push(record);
684
+ });
685
+ const hasIntent = intentRecords.length > 0;
686
+ // Spot messaging §7 step 3: with no Instance intent message waiting, the
687
+ // release decision also ends this Instance incarnation's admission in this turn.
688
+ if (!hasIntent && operation.activation.domain.kind === 'instance')
689
+ operation.activation.serial.closeAdmission();
690
+ const hostState = this.options.statefulExecution?.hostState();
691
+ const intentFailure = !hasIntent
692
+ ? undefined
693
+ : hostState === contracts_1.ZLinkFrameworkRuntimeState.Draining
694
+ ? (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RuntimeShutdown, 'Instance intent cannot continue while the host is draining.')
695
+ : hostState === contracts_1.ZLinkFrameworkRuntimeState.Relocating ||
696
+ hostState === contracts_1.ZLinkFrameworkRuntimeState.Relocated ||
697
+ this.options.statefulExecution?.admissionOpen() === false ||
698
+ (operation.activation.executionBarrier.isSealed &&
699
+ !operation.activation.executionBarrier.isCloseSealed)
700
+ ? (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, 'Instance intent cannot continue on an unavailable or relocating owner.')
701
+ : undefined;
702
+ if (operation.reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose &&
703
+ hasIntent &&
704
+ intentFailure === undefined &&
705
+ operation.authority?.reincarnate !== undefined) {
706
+ try {
707
+ await operation.authority.reincarnate(async (authority) => {
708
+ await this.activationLifecycle.materializeInstance(meshName, authority.stableType, operation.activation.spotType, spotId, authority.objectGeneration, signal, operation.activation);
709
+ });
710
+ // The new incarnation shares this serial owner and admits membership work again.
711
+ operation.activation.serial.setLifecycleAdmissionClosed(false);
667
712
  }
668
- return operation;
669
- };
670
- if (isInstance) {
671
- const beginAuthorityClose = reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose
672
- ? this.options.beginInstanceClosingAuthority
673
- : undefined;
674
- // Register the close gate before waiting for the current application
675
- // and activation-authority terminal completions. A close requested from
676
- // a handler cannot publish Closing until that handler's durable inbox
677
- // completion has removed the recovery fence.
678
- const trackedClosePromise = (async () => {
679
- const waitForApplication = this.options.instanceSpotApplicationQuiescenceProvider?.(meshName, spotId, signal);
680
- if (waitForApplication !== undefined) {
681
- await waitForApplication;
682
- }
683
- const closingAuthority = beginAuthorityClose === undefined
684
- ? undefined
685
- : await beginAuthorityClose(meshName, spotId);
686
- if (beginAuthorityClose !== undefined && closingAuthority === undefined) {
687
- return false;
688
- }
689
- const operation = beginClose();
690
- if (operation === undefined) {
691
- await closingAuthority?.restoreReady();
692
- return false;
693
- }
694
- const closed = await operation.ready;
695
- if (!closed)
696
- await closingAuthority?.restoreReady();
697
- return closed;
698
- })().finally(() => {
699
- if (this.pendingInstanceCloses.get(key) === trackedClosePromise) {
700
- this.pendingInstanceCloses.delete(key);
713
+ catch (error) {
714
+ const initialized = this.activations.resolve(meshName, spotId);
715
+ if (initialized !== undefined && initialized !== operation.activation) {
716
+ await this.activationLifecycle.cleanupFailedIncarnation(initialized);
701
717
  }
702
- });
703
- this.pendingInstanceCloses.set(key, trackedClosePromise);
704
- if (currentTurn) {
705
- // The current turn must return before its terminal completion can
706
- // release the activation recovery fence and allow the durable close
707
- // CAS. The registered close gate prevents a second admission while
708
- // that detached close finishes.
709
- this.options.detachedTaskRunner?.runDetached(`instance spot close ${String(spotId)}`, async () => {
710
- await trackedClosePromise;
718
+ this.activations.finishClose(meshName, spotId);
719
+ operation.activation.serial.visitPendingApplication((record) => {
720
+ const context = record.context;
721
+ if (context?.replay !== undefined)
722
+ record.operation = () => context.replay(error);
711
723
  });
712
- if (this.options.detachedTaskRunner === undefined) {
713
- void trackedClosePromise.catch(() => undefined);
714
- }
715
- return true;
724
+ operation.activation.serial.closeAdmission();
725
+ throw error;
716
726
  }
717
- return await trackedClosePromise;
718
- }
719
- const operation = beginClose();
720
- if (operation === undefined) {
721
- return false;
722
727
  }
723
- if (currentTurn) {
724
- if (operation.started) {
725
- this.options.detachedTaskRunner?.runDetached(`spot close ${String(spotId)}`, async () => {
726
- await operation.ready;
727
- });
728
- if (this.options.detachedTaskRunner === undefined) {
729
- void operation.ready.catch(() => undefined);
728
+ else {
729
+ await operation.authority?.release();
730
+ operation.activation.serial.closeAdmission();
731
+ if (!operation.activation.executionBarrier.isSealed) {
732
+ const closed = operation.activation.sealExecution('close');
733
+ operation.activation.commitExecutionSeal(closed);
734
+ }
735
+ }
736
+ if (operation.reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose) {
737
+ operation.activation.serial.visitPendingApplication((record) => {
738
+ const context = record.context;
739
+ if (context?.replay !== undefined) {
740
+ record.operation =
741
+ intentFailure === undefined ? context.replay : () => context.replay(intentFailure);
730
742
  }
743
+ });
744
+ }
745
+ this.closeOperations.delete(`${meshName}\0${String(spotId)}`);
746
+ // An OnClosing failure never changes a Close result; host shutdown alone
747
+ // reports it as its teardown outcome after cleanup has finished.
748
+ if (closingFailure !== undefined && operation.reason === contracts_1.ZLinkSpotCloseReason.HostShutdown) {
749
+ throw closingFailure;
750
+ }
751
+ return true;
752
+ }
753
+ async beginCloseAuthority(meshName, spotId, operation, signal) {
754
+ // Spot messaging §4 step 12 with §7 step 1: a Close of any reason begins its
755
+ // Closing CAS only after the first terminal record of an activated message.
756
+ await this.options.instanceSpotApplicationQuiescenceProvider?.(meshName, spotId, signal);
757
+ if (!operation.activation.canClose(operation.reason))
758
+ return undefined;
759
+ if (operation.activation.executionBarrier.isSealed) {
760
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Spot '${String(spotId)}' is sealed for relocation.`, true);
761
+ }
762
+ let seal;
763
+ const authorityPromise = Promise.resolve().then(() => operation.beginAuthority(() => {
764
+ if (operation.reason === contracts_1.ZLinkSpotCloseReason.ExplicitClose) {
765
+ operation.activation.serial.setLifecycleAdmissionClosed(true);
766
+ seal = true;
731
767
  }
732
- return true;
768
+ else {
769
+ seal = operation.activation.sealExecution('close');
770
+ }
771
+ }));
772
+ operation.authorityDecision = authorityPromise.then(() => undefined, () => undefined);
773
+ const authority = await authorityPromise;
774
+ if (authority === undefined)
775
+ return undefined;
776
+ operation.authority = authority;
777
+ if (seal === undefined) {
778
+ throw new Error(`Spot '${String(spotId)}' Closing authority did not confirm its commit.`);
733
779
  }
734
- return await operation.ready;
780
+ return seal;
735
781
  }
736
782
  async executeOnSpot(spotType, spotId, operation, signal) {
737
783
  (0, abort_1.throwIfAborted)(signal);
@@ -750,9 +796,6 @@ class DefaultZLinkSpotManager {
750
796
  hasActiveSpot(spotId) {
751
797
  return this.activations.resolveUnique(spotId) !== undefined;
752
798
  }
753
- canCloseUserSpot(meshName, spotId) {
754
- return this.activations.canClose(meshName, spotId);
755
- }
756
799
  beginUserSpotPublication(meshName, spotId) {
757
800
  this.activations.stage(meshName, spotId);
758
801
  }
@@ -783,6 +826,9 @@ class DefaultZLinkSpotManager {
783
826
  async admitActorJoin(spotId, actor, request, commit, signal, leaveSource, contentType = 'application/json') {
784
827
  const meshName = this.activations.resolveUnique(spotId)?.meshName;
785
828
  this.options.admission?.requireRequest('Actor join admission', meshName);
829
+ if (meshName !== undefined && this.isSpotClosing(meshName, spotId)) {
830
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestRejected, `Spot '${String(spotId)}' is closing.`);
831
+ }
786
832
  return await this.actorMembership.admitActorJoin(spotId, actor, request, commit, signal, leaveSource, contentType);
787
833
  }
788
834
  async leaveActor(spotId, actor, signal) {
@@ -884,7 +930,7 @@ class DefaultZLinkSpotManager {
884
930
  requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, response, codecs)));
885
931
  }
886
932
  catch (error) {
887
- requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error instanceof Error ? error.message : String(error))));
933
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)));
888
934
  }
889
935
  }
890
936
  async ensureInstanceApplicationActivation(meshName, spotId) {
@@ -892,7 +938,7 @@ class DefaultZLinkSpotManager {
892
938
  if (target === undefined)
893
939
  return;
894
940
  for (;;) {
895
- const current = this.activations.resolve(meshName, spotId);
941
+ const current = this.resolveApplicationActivation(spotId, meshName);
896
942
  if (current !== undefined &&
897
943
  current.objectGeneration === target.objectGeneration &&
898
944
  current.spotType === this.requireInstanceFactory(meshName, target.stableType))
@@ -919,7 +965,7 @@ class DefaultZLinkSpotManager {
919
965
  this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Received, meshName, spotId, record, envelope, 'activating');
920
966
  try {
921
967
  await this.ensureInstanceApplicationActivation(meshName, spotId);
922
- const activation = this.activations.resolve(meshName, spotId);
968
+ const activation = this.resolveApplicationActivation(spotId, meshName);
923
969
  if (activation === undefined || activation.domain.kind !== 'instance') {
924
970
  throw new configuration_1.ZLinkConfigurationException(`MeshNode Instance Spot target '${String(spotId)}' is not active.`);
925
971
  }
@@ -936,9 +982,26 @@ class DefaultZLinkSpotManager {
936
982
  channelName: envelope.header.channelName,
937
983
  contentType: envelope.header.contentType,
938
984
  awaitFirstHandlerTurn: record.kind === service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation,
985
+ activationRecord: record,
986
+ onOneWayError: this.options.dispatchErrors?.captureEnabled() === true
987
+ ? (error) => this.reportInstanceDispatchFailure(meshName, spotId, record, envelope, false, error)
988
+ : undefined,
939
989
  workOptions: (0, serial_work_size_1.zlinkSerialWorkOptions)(envelope.payload.byteLength, record.applicationMetadata?.byteLength ??
940
990
  (0, serial_work_size_1.zlinkMetadataByteLength)(envelope.header.metadata))
941
991
  };
992
+ // Spot messaging §7 step 3: an Instance intent request that reaches an
993
+ // incarnation whose Close ended admission is refused before admission
994
+ // with the owner fence terminal, so its caller re-reads authority.
995
+ const instanceIntent = record.activationRecord?.activation === 'missing' ||
996
+ (record.activationRecord?.activation === 'ready' &&
997
+ record.activationRecord.instanceIntent);
998
+ const refusal = activation.serial.applicationAdmissionRefusal(instanceIntent === true);
999
+ if (request && refusal !== undefined && record.replyFailure !== undefined) {
1000
+ this.reportInstanceDispatchFailure(meshName, spotId, record, envelope, request, refusal);
1001
+ const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(refusal);
1002
+ requireMeshSpotReply(record.replyFailure(terminal.terminalResult, terminal.failureCode));
1003
+ return;
1004
+ }
942
1005
  this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Admitted, meshName, spotId, record, envelope, 'ready', target?.stableType);
943
1006
  if (!request) {
944
1007
  this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dispatched, meshName, spotId, record, envelope, 'ready', target?.stableType);
@@ -952,33 +1015,39 @@ class DefaultZLinkSpotManager {
952
1015
  this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Replied, meshName, spotId, record, envelope, 'ready', target?.stableType);
953
1016
  }
954
1017
  catch (error) {
955
- const reason = instanceDispatchErrorReason(error);
1018
+ this.reportInstanceDispatchFailure(meshName, spotId, record, envelope, request, error);
1019
+ const reason = (0, dispatch_error_details_1.dispatchReasonFromError)(error);
956
1020
  if (!request) {
957
1021
  this.traceInstanceMessage(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dropped, meshName, spotId, record, envelope, 'closing', undefined, reason);
958
1022
  return;
959
1023
  }
960
- this.options.dispatchErrors?.report({
961
- surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.InstanceSpot,
962
- messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Request,
963
- packetName: envelope.packetName,
964
- channelName: envelope.header.channelName,
965
- meshName,
966
- correlationId: envelope.header.correlationId ?? undefined,
967
- sourceRid: record.sourceNodeRid === null ? undefined : String(record.sourceNodeRid),
968
- spotId: String(spotId),
969
- instanceSpotType: this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId)
970
- ?.stableType,
971
- activationState: 'closing',
972
- flowId: envelope.header.flowId,
973
- flowOrigin: envelope.header.flowOrigin,
974
- reason,
975
- action: ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError,
976
- error
977
- });
978
- requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error instanceof Error ? error.message : String(error))));
1024
+ requireMeshSpotReply(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)));
979
1025
  }
980
1026
  });
981
1027
  }
1028
+ reportInstanceDispatchFailure(meshName, spotId, record, envelope, request, error) {
1029
+ const reporter = this.options.dispatchErrors;
1030
+ if (reporter?.captureEnabled() !== true)
1031
+ return;
1032
+ reporter.report({
1033
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.InstanceSpot,
1034
+ messageKind: request ? ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Request : ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Send,
1035
+ packetName: envelope.packetName,
1036
+ channelName: envelope.header.channelName,
1037
+ meshName,
1038
+ correlationId: envelope.header.correlationId ?? undefined,
1039
+ sourceRid: record.sourceNodeRid === null ? undefined : String(record.sourceNodeRid),
1040
+ spotId: String(spotId),
1041
+ instanceSpotType: this.options.instanceSpotApplicationTargetProvider?.(meshName, spotId)
1042
+ ?.stableType,
1043
+ activationState: 'closing',
1044
+ flowId: envelope.header.flowId,
1045
+ flowOrigin: envelope.header.flowOrigin,
1046
+ reason: (0, dispatch_error_details_1.dispatchReasonFromError)(error),
1047
+ action: request ? ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError : ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop,
1048
+ error
1049
+ });
1050
+ }
982
1051
  traceInstanceMessage(outcome, meshName, spotId, record, envelope, activationState, instanceSpotType, errorReason) {
983
1052
  const flow = (0, diagnostics_1.flowIfEnabled)(this.options.dispatchErrors?.flow, outcome, undefined, envelope.header.flowId);
984
1053
  if (flow === undefined)
@@ -1011,9 +1080,6 @@ class DefaultZLinkSpotManager {
1011
1080
  throw new configuration_1.ZLinkConfigurationException('MeshNode Actor record is missing its Actor owner.');
1012
1081
  }
1013
1082
  const request = record.kind === service_runtime_contracts_1.ReceiveKind.ActorRequest;
1014
- if (record.sourceBindingGeneration > 0n) {
1015
- this.options.actorBindingGenerationObserver?.(actor.actorId, record.sourceBindingGeneration);
1016
- }
1017
1083
  const resolvedOwner = this.options.actorDispatchOwnerResolver?.(actor.actorId);
1018
1084
  const resolvedActorRef = resolvedOwner?.actorRef ?? {
1019
1085
  actorId: actor.actorId,
@@ -1067,13 +1133,41 @@ class DefaultZLinkSpotManager {
1067
1133
  }
1068
1134
  requireMeshSpotReply(record.reply(this.encodeMeshActorReply(record.parts[0], protocol_1.ZLinkStreamMessageKind.Error, {
1069
1135
  message: error instanceof Error ? error.message : String(error),
1070
- kind: error instanceof contracts_1.ZLinkFrameworkException
1071
- ? error.kind
1072
- : contracts_1.ZLinkFrameworkErrorKind.InternalFailure
1136
+ kind: spotActorFailureKind(error)
1073
1137
  })));
1074
1138
  }
1075
1139
  }
1076
1140
  async dispatchMeshActorJoin(meshName, owner, record) {
1141
+ const spotId = owner.spotId;
1142
+ const activation = spotId === null ? undefined : this.activations.resolve(meshName, spotId);
1143
+ const replyState = { targetCommitPublished: false };
1144
+ try {
1145
+ if (record.kindData?.kind === 'actorControl' &&
1146
+ record.kindData.canonicalActorJoin !== undefined) {
1147
+ const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1148
+ if (spotId !== null && entrySpotId !== undefined && String(spotId) === String(entrySpotId)
1149
+ ? this.options.dispatchEntryActorJoin === undefined
1150
+ : activation === undefined) {
1151
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `Spot '${String(spotId)}' is not active on this node.`);
1152
+ }
1153
+ }
1154
+ if (activation?.domain.kind === 'user') {
1155
+ await activation.serial.executeLifecycleOperation(() => this.dispatchMeshActorJoinCore(meshName, owner, record, replyState));
1156
+ return;
1157
+ }
1158
+ await this.dispatchMeshActorJoinCore(meshName, owner, record, replyState);
1159
+ }
1160
+ catch (error) {
1161
+ if (replyState.targetCommitPublished || record.replyFailure === undefined)
1162
+ throw error;
1163
+ const failure = error instanceof contracts_1.ZLinkFrameworkException
1164
+ ? error
1165
+ : (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestFailed, 'Actor Join target admission failed.', error);
1166
+ const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(failure);
1167
+ requireMeshSpotReply(record.replyFailure(terminal.terminalResult, terminal.failureCode));
1168
+ }
1169
+ }
1170
+ async dispatchMeshActorJoinCore(meshName, owner, record, replyState) {
1077
1171
  const spotId = owner.spotId;
1078
1172
  const control = record.kindData;
1079
1173
  if (control?.kind !== 'actorControl') {
@@ -1126,15 +1220,11 @@ class DefaultZLinkSpotManager {
1126
1220
  admissionRecord = provisional.record;
1127
1221
  canonicalAdmissionCreated = provisional.created;
1128
1222
  try {
1223
+ (0, application_job_queue_scope_1.releaseApplicationJobPermitBeforeHandler)();
1129
1224
  canonicalActorType = (await resolver({ actorId, ...control.canonicalActorJoin })).actorType;
1130
1225
  }
1131
1226
  catch (error) {
1132
1227
  this.formalRemoteActorAdmissions.fail(control.canonicalActorJoin.handoffId, error);
1133
- if (error instanceof contracts_1.ZLinkFrameworkException && record.replyFailure !== undefined) {
1134
- const terminal = (0, framework_errors_internal_1.internalFrameworkWireReply)(error);
1135
- requireMeshSpotReply(record.replyFailure(terminal.terminalResult, terminal.failureCode));
1136
- return;
1137
- }
1138
1228
  throw error;
1139
1229
  }
1140
1230
  }
@@ -1157,12 +1247,11 @@ class DefaultZLinkSpotManager {
1157
1247
  let ownedCallbackRequest;
1158
1248
  let materialized = false;
1159
1249
  let reply;
1160
- let deferredJoinRoot;
1250
+ let deferredJoinCompletion;
1161
1251
  let preparedTransferState;
1162
1252
  let admissionOutcome;
1163
1253
  let accepted = false;
1164
1254
  let committedAdmissionReplay = isRemoteCommit && admissionRecord?.state === 'committed';
1165
- let targetCommitPublished;
1166
1255
  const actorJoinIsCurrent = () => (record.deadlineUnixMs === undefined || record.deadlineUnixMs > BigInt(Date.now())) &&
1167
1256
  (record.isPending?.() ?? true);
1168
1257
  const abandonStaleAdmission = () => {
@@ -1213,13 +1302,10 @@ class DefaultZLinkSpotManager {
1213
1302
  if (canonicalAdmissionCreated) {
1214
1303
  if (targetsEntrySpot) {
1215
1304
  admissionOutcome = {
1216
- accepted: this.options.dispatchEntryActorJoin !== undefined,
1305
+ accepted: true,
1217
1306
  actorRef
1218
1307
  };
1219
1308
  }
1220
- else if (activation === undefined) {
1221
- admissionOutcome = { accepted: false, actorRef };
1222
- }
1223
1309
  else {
1224
1310
  const response = await activation.serial.execute(async () => activation.spot.onActorJoin(actorRef.actorId, (0, payload_codec_1.wrapFrameworkPayloadMessage)(callbackRequest, this.options.messageSerializers, requestContentType)));
1225
1311
  let encodedReply;
@@ -1286,13 +1372,13 @@ class DefaultZLinkSpotManager {
1286
1372
  if (this.options.dispatchEntryActorJoin !== undefined &&
1287
1373
  transferRequest.completionOperationId !== undefined &&
1288
1374
  this.options.actorTransferRuntime !== undefined) {
1289
- deferredJoinRoot =
1290
- await this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, Buffer.alloc(0));
1375
+ deferredJoinCompletion =
1376
+ this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, Buffer.alloc(0));
1291
1377
  }
1292
1378
  admissionOutcome = {
1293
1379
  accepted: this.options.dispatchEntryActorJoin !== undefined,
1294
1380
  actorRef,
1295
- ...(deferredJoinRoot === undefined ? {} : { deferredJoinRoot })
1381
+ ...(deferredJoinCompletion === undefined ? {} : { deferredJoinCompletion })
1296
1382
  };
1297
1383
  }
1298
1384
  else if (activation === undefined) {
@@ -1313,8 +1399,8 @@ class DefaultZLinkSpotManager {
1313
1399
  if (response.accepted &&
1314
1400
  transferRequest.completionOperationId !== undefined &&
1315
1401
  this.options.actorTransferRuntime !== undefined) {
1316
- deferredJoinRoot =
1317
- await this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, encodedReply?.data() ?? Buffer.alloc(0), encodedReply === undefined
1402
+ deferredJoinCompletion =
1403
+ this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, encodedReply?.data() ?? Buffer.alloc(0), encodedReply === undefined
1318
1404
  ? undefined
1319
1405
  : (0, payload_codec_1.frameworkPayloadContentType)(encodedReply));
1320
1406
  this.options.runtimeEventPublisher?.publish({
@@ -1327,7 +1413,7 @@ class DefaultZLinkSpotManager {
1327
1413
  admissionOutcome = {
1328
1414
  accepted: response.accepted,
1329
1415
  actorRef,
1330
- ...(deferredJoinRoot === undefined ? {} : { deferredJoinRoot }),
1416
+ ...(deferredJoinCompletion === undefined ? {} : { deferredJoinCompletion }),
1331
1417
  ...(encodedReply === undefined
1332
1418
  ? {}
1333
1419
  : {
@@ -1366,7 +1452,7 @@ class DefaultZLinkSpotManager {
1366
1452
  if ('error' in admissionOutcome) {
1367
1453
  throw admissionOutcome.error;
1368
1454
  }
1369
- deferredJoinRoot = admissionOutcome.deferredJoinRoot;
1455
+ deferredJoinCompletion = admissionOutcome.deferredJoinCompletion;
1370
1456
  }
1371
1457
  if (actor === undefined &&
1372
1458
  transferRequest !== undefined &&
@@ -1436,7 +1522,7 @@ class DefaultZLinkSpotManager {
1436
1522
  if (accepted &&
1437
1523
  transferRequest?.completionOperationId !== undefined &&
1438
1524
  this.options.actorTransferRuntime !== undefined) {
1439
- deferredJoinRoot = await this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, reply?.data() ?? Buffer.alloc(0), reply === undefined ? undefined : (0, payload_codec_1.frameworkPayloadContentType)(reply));
1525
+ deferredJoinCompletion = this.options.actorTransferRuntime.prepareDeferredJoinAccepted(actorId, transferRequest.completionOperationId, actorRef, reply?.data() ?? Buffer.alloc(0), reply === undefined ? undefined : (0, payload_codec_1.frameworkPayloadContentType)(reply));
1440
1526
  this.options.runtimeEventPublisher?.publish({
1441
1527
  sourceName: 'zlink.framework.actor-handoff',
1442
1528
  timestamp: new Date(),
@@ -1474,16 +1560,6 @@ class DefaultZLinkSpotManager {
1474
1560
  return;
1475
1561
  }
1476
1562
  }
1477
- if (accepted &&
1478
- transferRequest !== undefined &&
1479
- this.options.actorTransferRuntime !== undefined &&
1480
- !isRemoteAdmission) {
1481
- // A lightweight Core actor-join notification can create the Actor
1482
- // before the formal transfer request reaches this branch. Preserve
1483
- // the full relocation fence in that race so a later Session bind
1484
- // refresh cannot erase the seal or accepted journal.
1485
- this.options.actorTransferRuntime.rememberRoutedActorTransferTarget(actorId, transferRequest.remoteBoundSessionTarget);
1486
- }
1487
1563
  if (accepted &&
1488
1564
  actor !== undefined &&
1489
1565
  transferRequest !== undefined &&
@@ -1494,7 +1570,8 @@ class DefaultZLinkSpotManager {
1494
1570
  spotId,
1495
1571
  transferId: transferRequest.transferId,
1496
1572
  handoffBacklog: transferRequest.handoffBacklog,
1497
- deferredJoinRoot
1573
+ deferredJoinCompletion,
1574
+ sealedSession: transferRequest.remoteBoundSessionTarget
1498
1575
  });
1499
1576
  if (isRemoteCommit && admissionRecord !== undefined) {
1500
1577
  this.formalRemoteActorAdmissions.markCommitted(transferRequest.transferId, actor);
@@ -1510,7 +1587,7 @@ class DefaultZLinkSpotManager {
1510
1587
  // Core commits the target membership while it accepts this reply.
1511
1588
  // From this call onward a later callback/transport failure is
1512
1589
  // post-commit and must not roll the materialized Actor back.
1513
- targetCommitPublished = true;
1590
+ replyState.targetCommitPublished = true;
1514
1591
  }
1515
1592
  requireMeshSpotReply(joinReplyResult);
1516
1593
  return true;
@@ -1540,38 +1617,52 @@ class DefaultZLinkSpotManager {
1540
1617
  return;
1541
1618
  const commitEntryTransfer = async () => {
1542
1619
  try {
1543
- await this.options.dispatchEntryActorJoin?.(meshName, entryActor, []);
1544
- }
1545
- finally {
1546
- this.formalRemoteTransfers.completeTargetLifecycle(entryActor.context.actorId, pendingTransfer.transferId);
1547
- }
1548
- const sourceLeaveSubmitted = await pendingTransfer.sourceLeaveSubmitted;
1549
- if (!sourceLeaveSubmitted) {
1550
- throw new Error(`Actor '${entryActor.context.actorId}' source authority commit failed before leave submission.`);
1620
+ try {
1621
+ await this.options.dispatchEntryActorJoin?.(meshName, entryActor, []);
1622
+ }
1623
+ finally {
1624
+ this.formalRemoteTransfers.completeTargetLifecycle(entryActor.context.actorId, pendingTransfer.transferId);
1625
+ }
1626
+ const sourceLeaveSubmitted = await pendingTransfer.sourceLeaveSubmitted;
1627
+ if (!sourceLeaveSubmitted) {
1628
+ throw new Error(`Actor '${entryActor.context.actorId}' source authority commit failed before leave submission.`);
1629
+ }
1630
+ const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, async (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => {
1631
+ if (this.options.dispatchEntryActorPacket === undefined) {
1632
+ throw new Error('Entry Spot saved handoff replay requires its Actor packet runtime.');
1633
+ }
1634
+ return await this.options.dispatchEntryActorPacket(entryActor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
1635
+ }, (index) => this.options.runtimeEventPublisher?.publish({
1636
+ sourceName: 'zlink.framework.actor-handoff',
1637
+ timestamp: new Date(),
1638
+ marker: 'backlog_enqueued',
1639
+ actorId: entryActor.context.actorId,
1640
+ index
1641
+ }));
1642
+ const failedHandoff = handoffResults.find((result) => !result.ok);
1643
+ if (failedHandoff !== undefined) {
1644
+ throw new Error(`Actor '${entryActor.context.actorId}' saved Entry handoff packet ` +
1645
+ `${failedHandoff.index} failed: ${(0, diagnostic_text_1.diagnosticTextOrAbsent)(failedHandoff.error)}.`);
1646
+ }
1551
1647
  }
1552
- const handoffResults = await (0, actor_handoff_1.replayActorHandoffBacklog)(pendingTransfer.handoffBacklog, async (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) => {
1553
- if (this.options.dispatchEntryActorPacket === undefined) {
1554
- throw new Error('Entry Spot saved handoff replay requires its Actor packet runtime.');
1648
+ catch (error) {
1649
+ const completion = pendingTransfer.deferredJoinCompletion;
1650
+ if (completion !== undefined) {
1651
+ await this.options.actorTransferRuntime?.deliverDeferredJoinCompletion({
1652
+ ...completion,
1653
+ status: 'failed',
1654
+ kind: spotActorFailureKind(error)
1655
+ }, entryActor, completion.actor, (operation) => this.options.executeEntryActor(meshName, entryActor.context.actorId, operation));
1555
1656
  }
1556
- return await this.options.dispatchEntryActorPacket(entryActor.context.actorId, parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef);
1557
- }, (index) => this.options.runtimeEventPublisher?.publish({
1558
- sourceName: 'zlink.framework.actor-handoff',
1559
- timestamp: new Date(),
1560
- marker: 'backlog_enqueued',
1561
- actorId: entryActor.context.actorId,
1562
- index
1563
- }));
1564
- const failedHandoff = handoffResults.find((result) => !result.ok);
1565
- if (failedHandoff !== undefined) {
1566
- throw new Error(`Actor '${entryActor.context.actorId}' saved Entry handoff packet ` +
1567
- `${failedHandoff.index} failed: ${failedHandoff.error ?? 'unknown error'}.`);
1657
+ throw error;
1658
+ }
1659
+ const completion = pendingTransfer.deferredJoinCompletion;
1660
+ if (completion !== undefined) {
1661
+ await this.options.actorTransferRuntime?.deliverDeferredJoinCompletion(completion, entryActor, completion.actor, (operation) => this.options.executeEntryActor(meshName, entryActor.context.actorId, operation));
1568
1662
  }
1569
1663
  this.formalRemoteTransfers.delete(entryActor.context.actorId);
1570
1664
  };
1571
- this.options.detachedTaskRunner?.runDetached(`actor Entry Spot transfer ${entryActor.context.actorId}`, commitEntryTransfer);
1572
- if (this.options.detachedTaskRunner === undefined) {
1573
- void commitEntryTransfer().catch(() => undefined);
1574
- }
1665
+ this.options.detachedTaskRunner.runDetached(`actor Entry Spot transfer ${entryActor.context.actorId}`, commitEntryTransfer);
1575
1666
  }
1576
1667
  }
1577
1668
  else {
@@ -1583,13 +1674,10 @@ class DefaultZLinkSpotManager {
1583
1674
  if (control.canonicalActorJoin !== undefined) {
1584
1675
  this.formalRemoteActorAdmissions.fail(control.canonicalActorJoin.handoffId, error);
1585
1676
  }
1586
- if (deferredJoinRoot !== undefined && targetCommitPublished !== true) {
1587
- await this.options.actorTransferRuntime?.discardDeferredJoinAccepted(deferredJoinRoot);
1588
- }
1589
- if (targetCommitPublished !== true) {
1677
+ if (!replyState.targetCommitPublished) {
1590
1678
  this.formalRemoteTransfers.delete(actorId);
1591
1679
  }
1592
- if (materialized && targetCommitPublished !== true) {
1680
+ if (materialized && !replyState.targetCommitPublished) {
1593
1681
  await this.options.actorTransferRuntime?.rollbackRoutedActor(actor);
1594
1682
  }
1595
1683
  throw error;
@@ -1602,6 +1690,31 @@ class DefaultZLinkSpotManager {
1602
1690
  }
1603
1691
  }
1604
1692
  async dispatchMeshSpotControl(meshName, owner, record) {
1693
+ const spotId = owner.spotId;
1694
+ const activation = spotId === null ? undefined : this.activations.resolve(meshName, spotId);
1695
+ if (activation?.domain.kind === 'user') {
1696
+ const transfer = { terminal: undefined };
1697
+ const operation = activation.serial.executeLifecycleOperation(async () => {
1698
+ await this.dispatchMeshSpotControlCore(meshName, owner, record, (terminal) => {
1699
+ transfer.terminal = terminal;
1700
+ });
1701
+ await transfer.terminal;
1702
+ });
1703
+ const control = record.kindData;
1704
+ const actorId = control?.kind === 'actorControl' ? control.currentActor?.actorId : undefined;
1705
+ if (control?.kind === 'actorControl' &&
1706
+ control.lifecycleKind === service_runtime_contracts_1.ActorLifecycleKind.Joined &&
1707
+ actorId !== undefined &&
1708
+ this.formalRemoteTransfers.get(actorId) !== undefined) {
1709
+ this.options.detachedTaskRunner.runDetached(`actor transfer target commit ${actorId}`, async () => await operation);
1710
+ return;
1711
+ }
1712
+ await operation;
1713
+ return;
1714
+ }
1715
+ await this.dispatchMeshSpotControlCore(meshName, owner, record);
1716
+ }
1717
+ async dispatchMeshSpotControlCore(meshName, owner, record, onDetachedTerminal) {
1605
1718
  const spotId = owner.spotId;
1606
1719
  const control = record.kindData;
1607
1720
  if (control?.kind !== 'actorControl') {
@@ -1664,15 +1777,15 @@ class DefaultZLinkSpotManager {
1664
1777
  await activation.spot.onJoinedActor(actor);
1665
1778
  };
1666
1779
  const completePublicJoin = async () => {
1667
- const deferredJoinRoot = pendingTransfer?.deferredJoinRoot;
1668
- if (deferredJoinRoot !== undefined) {
1780
+ const deferredJoinCompletion = pendingTransfer?.deferredJoinCompletion;
1781
+ if (deferredJoinCompletion !== undefined) {
1669
1782
  const currentRef = this.options.actorTransferRuntime === undefined
1670
1783
  ? null
1671
1784
  : control.currentActor;
1672
1785
  if (currentRef === null) {
1673
1786
  throw new Error(`Actor '${actor.context.actorId}' has no target ref for deferred Join completion.`);
1674
1787
  }
1675
- await this.options.actorTransferRuntime?.commitAndDeliverDeferredJoinAccepted(deferredJoinRoot, actor, currentRef, (operation) => activation.executeActor(actor.context.actorId, async () => await operation()));
1788
+ await this.options.actorTransferRuntime?.deliverDeferredJoinCompletion(deferredJoinCompletion, actor, currentRef, (operation) => activation.executeActor(actor.context.actorId, async () => await operation()));
1676
1789
  }
1677
1790
  };
1678
1791
  const completeTargetReady = async () => {
@@ -1687,7 +1800,7 @@ class DefaultZLinkSpotManager {
1687
1800
  const failedHandoff = handoffResults.find((result) => !result.ok);
1688
1801
  if (failedHandoff !== undefined) {
1689
1802
  throw new Error(`Actor '${actor.context.actorId}' saved handoff packet ` +
1690
- `${failedHandoff.index} failed: ${failedHandoff.error ?? 'unknown error'}.`);
1803
+ `${failedHandoff.index} failed: ${(0, diagnostic_text_1.diagnosticTextOrAbsent)(failedHandoff.error)}.`);
1691
1804
  }
1692
1805
  // Spec 15 §4.2 relocation temporary queue: arrivals parked at
1693
1806
  // this target directly (not relayed through the source's
@@ -1700,13 +1813,14 @@ class DefaultZLinkSpotManager {
1700
1813
  // the Session binding aggregate after this boundary.
1701
1814
  this.formalRemoteTransfers.delete(actor.context.actorId);
1702
1815
  }
1816
+ const sealedSession = pendingTransfer?.sealedSession;
1703
1817
  const updateBoundSessionRoute = async () => {
1704
- await this.options.actorTransferRuntime?.publishRoutedActorOwnership(actor);
1818
+ await this.options.actorTransferRuntime?.publishRoutedActorOwnership(actor, sealedSession);
1705
1819
  await this.options.actorTransferRuntime?.openRoutedActorSession(actor);
1706
1820
  };
1707
- // Session routing is an independent post-Ready branch. Callback
1708
- // sends are retained by the Session owner seal until this converges.
1709
- if (pendingTransfer !== undefined && this.options.detachedTaskRunner !== undefined) {
1821
+ // Session routing is an independent post-Ready branch. The Session
1822
+ // owner submits current-binding pushes while the route seal remains installed.
1823
+ if (pendingTransfer !== undefined) {
1710
1824
  this.options.detachedTaskRunner.runDetached(`actor transfer Session route ${actor.context.actorId}`, updateBoundSessionRoute);
1711
1825
  }
1712
1826
  else {
@@ -1730,9 +1844,12 @@ class DefaultZLinkSpotManager {
1730
1844
  // them only after the lifecycle turn above has been released.
1731
1845
  await completeTargetReady();
1732
1846
  };
1733
- this.options.detachedTaskRunner?.runDetached(`actor transfer target commit ${actor.context.actorId}`, resume);
1734
- if (this.options.detachedTaskRunner === undefined) {
1735
- void resume().catch(() => undefined);
1847
+ const terminal = resume();
1848
+ if (onDetachedTerminal !== undefined) {
1849
+ onDetachedTerminal(terminal);
1850
+ }
1851
+ else {
1852
+ this.options.detachedTaskRunner.runDetached(`actor transfer target commit ${actor.context.actorId}`, async () => await terminal);
1736
1853
  }
1737
1854
  return;
1738
1855
  }
@@ -1782,33 +1899,52 @@ class DefaultZLinkSpotManager {
1782
1899
  }
1783
1900
  const entrySpotId = this.options.entryNodeRidProvider?.() ?? this.options.entryNodeRid;
1784
1901
  const targetsEntry = entrySpotId !== undefined && String(admission.admission.spotId) === String(entrySpotId);
1785
- if (targetsEntry) {
1786
- await this.options.dispatchEntryActorJoin?.(meshName, actor, []);
1787
- }
1788
- else {
1789
- const activation = this.activations.resolve(meshName, admission.admission.spotId);
1790
- if (activation === undefined) {
1791
- throw new Error(`Actor Join relocation '${relocationId}' target Spot is not active.`);
1902
+ const activation = targetsEntry
1903
+ ? undefined
1904
+ : this.activations.resolve(meshName, admission.admission.spotId);
1905
+ let lifecycleFailure;
1906
+ try {
1907
+ if (targetsEntry) {
1908
+ await this.options.dispatchEntryActorJoin?.(meshName, actor, []);
1792
1909
  }
1793
- await activation.serial.execute(() => activation.spot.onJoinedActor(actor));
1910
+ else {
1911
+ if (activation === undefined) {
1912
+ throw new Error(`Actor Join relocation '${relocationId}' target Spot is not active.`);
1913
+ }
1914
+ await activation.serial.execute(() => activation.spot.onJoinedActor(actor));
1915
+ }
1916
+ }
1917
+ catch (error) {
1918
+ lifecycleFailure = { error };
1794
1919
  }
1795
- await submitSourceLeave(admission.admission.actorRef.nodeRid);
1796
- if (outcome.deferredJoinRoot !== undefined && this.options.actorTransferRuntime !== undefined) {
1920
+ if (lifecycleFailure === undefined) {
1921
+ const sourceLeave = submitSourceLeave(admission.admission.actorRef.nodeRid);
1922
+ this.options.detachedTaskRunner.runDetached(`actor Join source leave ${actor.context.actorId}`, () => sourceLeave);
1923
+ }
1924
+ if (outcome.deferredJoinCompletion !== undefined &&
1925
+ this.options.actorTransferRuntime !== undefined) {
1797
1926
  const submitMailbox = targetsEntry
1798
1927
  ? (operation) => operation()
1799
1928
  : (operation) => {
1800
- const activation = this.activations.resolve(meshName, admission.admission.spotId);
1801
1929
  if (activation === undefined) {
1802
1930
  throw new Error(`Actor Join relocation '${relocationId}' target mailbox is missing.`);
1803
1931
  }
1804
1932
  return activation.executeActor(actor.context.actorId, operation);
1805
1933
  };
1806
- await this.options.actorTransferRuntime.commitAndDeliverDeferredJoinAccepted(outcome.deferredJoinRoot, actor, actorRef, submitMailbox, signal);
1807
- }
1934
+ await this.options.actorTransferRuntime.deliverDeferredJoinCompletion(lifecycleFailure === undefined
1935
+ ? outcome.deferredJoinCompletion
1936
+ : {
1937
+ ...outcome.deferredJoinCompletion,
1938
+ status: 'failed',
1939
+ kind: spotActorFailureKind(lifecycleFailure.error)
1940
+ }, actor, actorRef, submitMailbox, signal);
1941
+ }
1942
+ if (lifecycleFailure !== undefined)
1943
+ throw lifecycleFailure.error;
1808
1944
  this.formalRemoteActorAdmissions.markCommitted(relocationId, actor);
1809
1945
  return true;
1810
1946
  }
1811
- async restoreCanonicalActorJoinRecovery(recovery, signal, canonicalInventoryDigest) {
1947
+ async restoreCanonicalActorJoinRecovery(recovery, signal) {
1812
1948
  (0, abort_1.throwIfAborted)(signal);
1813
1949
  const admission = this.formalRemoteActorAdmissions.get(recovery.request.handoffId);
1814
1950
  if (admission === undefined) {
@@ -1850,15 +1986,14 @@ class DefaultZLinkSpotManager {
1850
1986
  }
1851
1987
  // Command 28 carries a present reply in one outer framework-multipart
1852
1988
  // part. The accepted target admission still owns the inner typed content
1853
- // type, which the durable completion must retain for application decode.
1989
+ // type, which the process-local completion keeps for application decode.
1854
1990
  const admittedContentType = admittedReply.byteLength === 0 ? recovery.replyContentType : outcome.replyContentType;
1855
1991
  const transfer = this.options.actorTransferRuntime;
1856
1992
  if (transfer === undefined) {
1857
1993
  throw new Error('Canonical Actor Join recovery requires the Actor transfer runtime.');
1858
1994
  }
1859
- const deferred = await transfer.prepareDeferredJoinAccepted(recovery.request.actorId, recovery.operationId, admitted.actorRef, recovery.reply, admittedContentType, signal, canonicalInventoryDigest);
1860
- this.formalRemoteActorAdmissions.attachDeferredJoinRoot(recovery.request.handoffId, deferred);
1861
- return deferred;
1995
+ const deferred = transfer.prepareDeferredJoinAccepted(recovery.request.actorId, recovery.operationId, admitted.actorRef, recovery.reply, admittedContentType);
1996
+ this.formalRemoteActorAdmissions.attachDeferredJoinCompletion(recovery.request.handoffId, deferred);
1862
1997
  }
1863
1998
  encodeMeshActorReply(requestHeaderPart, kind, payload) {
1864
1999
  // Spec 27 §4/§7: the decode gate strips the observation-only flow pair at
@@ -1932,17 +2067,10 @@ class DefaultZLinkSpotManager {
1932
2067
  }
1933
2068
  }
1934
2069
  exports.DefaultZLinkSpotManager = DefaultZLinkSpotManager;
1935
- function instanceDispatchErrorReason(error) {
1936
- if (error instanceof contracts_1.ZLinkFrameworkException) {
1937
- const kind = (0, framework_errors_internal_1.internalFrameworkErrorKind)(error);
1938
- if (kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale ||
1939
- kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving ||
1940
- kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotRouteNotFound ||
1941
- kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound) {
1942
- return ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.StaleTarget;
1943
- }
1944
- }
1945
- return ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerException;
2070
+ function spotActorFailureKind(error) {
2071
+ return error instanceof contracts_1.ZLinkFrameworkException
2072
+ ? error.kind
2073
+ : contracts_1.ZLinkFrameworkErrorKind.InternalFailure;
1946
2074
  }
1947
2075
  function decodeFormalRemoteTransferRequest(message) {
1948
2076
  return decodeFormalRemoteTransferRequestBytes(message.data());