@zlink-systems/framework 0.30.1 → 0.30.2

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 (340) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +6 -0
  3. package/dist/contracts/Common/ZLinkEncodedPayload.js +18 -3
  4. package/dist/contracts/Common/encoded-payload-storage.d.ts +1 -1
  5. package/dist/contracts/Common/encoded-payload-storage.js +5 -2
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -1
  7. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +2 -1
  8. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +5 -1
  9. package/dist/contracts/Configuration/RegistrationBuilders.js +2 -2
  10. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
  11. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +2 -2
  12. package/dist/contracts/Locations/Rows.d.ts +2 -0
  13. package/dist/contracts/Spots/Contracts.d.ts +4 -0
  14. package/dist/contracts/Spots/ZLinkSpot.d.ts +3 -3
  15. package/dist/runtime/abort.d.ts +5 -0
  16. package/dist/runtime/abort.js +10 -0
  17. package/dist/runtime/actors/actor-authority-publication.js +3 -2
  18. package/dist/runtime/actors/actor-client.d.ts +0 -1
  19. package/dist/runtime/actors/actor-client.js +38 -45
  20. package/dist/runtime/actors/actor-context.d.ts +2 -0
  21. package/dist/runtime/actors/actor-context.js +46 -9
  22. package/dist/runtime/actors/actor-handoff.d.ts +7 -3
  23. package/dist/runtime/actors/actor-handoff.js +212 -88
  24. package/dist/runtime/actors/actor-join-relocation.d.ts +2 -0
  25. package/dist/runtime/actors/actor-local-native-join.js +4 -0
  26. package/dist/runtime/actors/actor-mailbox.js +27 -1
  27. package/dist/runtime/actors/actor-remote-joiner.js +3 -1
  28. package/dist/runtime/actors/actor-reply.d.ts +4 -0
  29. package/dist/runtime/actors/actor-reply.js +29 -0
  30. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -0
  31. package/dist/runtime/actors/actor-runtime-state.js +2 -20
  32. package/dist/runtime/actors/actor-source-transfer.d.ts +1 -17
  33. package/dist/runtime/actors/index.d.ts +6 -2
  34. package/dist/runtime/actors/index.js +37 -21
  35. package/dist/runtime/actors/session-disconnected-wire.d.ts +8 -0
  36. package/dist/runtime/actors/session-disconnected-wire.js +48 -0
  37. package/dist/runtime/admission.d.ts +9 -1
  38. package/dist/runtime/admission.js +55 -32
  39. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +13 -0
  40. package/dist/runtime/application-jobs/application-job-queue-scope.js +27 -1
  41. package/dist/runtime/application-jobs/contracts.d.ts +2 -0
  42. package/dist/runtime/backend/contracts/index.d.ts +19 -3
  43. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +2 -2
  44. package/dist/runtime/backend/mesh-completion-table.js +5 -0
  45. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +26 -2
  46. package/dist/runtime/backend/mesh-dispatch-pump.js +193 -107
  47. package/dist/runtime/backend/node/node-raw-binding-port.js +90 -58
  48. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +33 -8
  49. package/dist/runtime/backend/node/node-raw-mesh-backend.js +142 -143
  50. package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +1 -1
  51. package/dist/runtime/backend/node/node-socket-backend-adapter.js +5 -5
  52. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  53. package/dist/runtime/channels/channel-clients.js +20 -5
  54. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +22 -3
  55. package/dist/runtime/channels/channel-dispatch-pipeline.js +103 -57
  56. package/dist/runtime/channels/channel-dispatchers.d.ts +3 -2
  57. package/dist/runtime/channels/channel-dispatchers.js +44 -37
  58. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  59. package/dist/runtime/channels/channel-envelope.js +74 -31
  60. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +4 -3
  61. package/dist/runtime/channels/channel-runtime-lifecycle.js +19 -24
  62. package/dist/runtime/channels/channel-runtime-manager.d.ts +3 -2
  63. package/dist/runtime/channels/channel-runtime-manager.js +4 -4
  64. package/dist/runtime/channels/channel-transports.d.ts +0 -1
  65. package/dist/runtime/channels/channel-transports.js +35 -33
  66. package/dist/runtime/channels/client-server-location-runtime.js +5 -4
  67. package/dist/runtime/channels/dispatch-error-reporter.d.ts +2 -1
  68. package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
  69. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  70. package/dist/runtime/channels/fanout-location-runtime.js +3 -3
  71. package/dist/runtime/diagnostics/flow-context.js +19 -7
  72. package/dist/runtime/diagnostics/index.js +4 -9
  73. package/dist/runtime/diagnostics/message-flow.d.ts +8 -0
  74. package/dist/runtime/diagnostics/message-flow.js +35 -5
  75. package/dist/runtime/diagnostics/runtime-metrics.d.ts +2 -2
  76. package/dist/runtime/diagnostics/runtime-metrics.js +10 -8
  77. package/dist/runtime/execution/index.d.ts +4 -2
  78. package/dist/runtime/execution/index.js +33 -10
  79. package/dist/runtime/execution/serial-execution-queue.d.ts +4 -0
  80. package/dist/runtime/execution/serial-execution-queue.js +21 -2
  81. package/dist/runtime/execution/state-lane.d.ts +2 -0
  82. package/dist/runtime/execution/state-lane.js +5 -0
  83. package/dist/runtime/foundation/operation-registry.d.ts +25 -1
  84. package/dist/runtime/foundation/operation-registry.js +86 -18
  85. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +39 -3
  86. package/dist/runtime/foundation/raw-service-mesh-runtime.js +151 -55
  87. package/dist/runtime/foundation/service-liveness-registry.d.ts +12 -1
  88. package/dist/runtime/foundation/service-liveness-registry.js +38 -0
  89. package/dist/runtime/foundation/service-mailbox.d.ts +7 -0
  90. package/dist/runtime/foundation/service-maintenance-runtime.js +1 -6
  91. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -3
  92. package/dist/runtime/foundation/service-relocation-object-owner.js +48 -35
  93. package/dist/runtime/foundation/service-relocation-runtime.js +7 -3
  94. package/dist/runtime/foundation/service-runtime-contracts.d.ts +8 -1
  95. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +2 -1
  96. package/dist/runtime/foundation/service-stateful-registry.d.ts +5 -4
  97. package/dist/runtime/foundation/service-stateful-registry.js +24 -26
  98. package/dist/runtime/foundation/service-stateful-runtime.d.ts +72 -6
  99. package/dist/runtime/foundation/service-stateful-runtime.js +444 -117
  100. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +14 -1
  101. package/dist/runtime/foundation/service-stateful-wire-codec.js +48 -27
  102. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +6 -1
  103. package/dist/runtime/foundation/service-wire-binary-primitives.js +27 -11
  104. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  105. package/dist/runtime/foundation/service-wire-constants.generated.js +1 -0
  106. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +10 -0
  107. package/dist/runtime/foundation/service-wire-m6a-codec.js +166 -53
  108. package/dist/runtime/host/actor-packet-relay.d.ts +6 -4
  109. package/dist/runtime/host/actor-packet-relay.js +59 -72
  110. package/dist/runtime/host/actor-placement-coordinator.js +25 -8
  111. package/dist/runtime/host/actor-transfer-runtime.d.ts +7 -31
  112. package/dist/runtime/host/actor-transfer-runtime.js +85 -331
  113. package/dist/runtime/host/application-job-queue.d.ts +24 -3
  114. package/dist/runtime/host/application-job-queue.js +28 -41
  115. package/dist/runtime/host/index.d.ts +5 -1
  116. package/dist/runtime/host/index.js +171 -97
  117. package/dist/runtime/host/location-runtime-owner.js +2 -6
  118. package/dist/runtime/host/mesh-router-resolver.d.ts +4 -0
  119. package/dist/runtime/host/mesh-router-resolver.js +14 -6
  120. package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -4
  121. package/dist/runtime/host/remote-bound-session-relay.js +71 -190
  122. package/dist/runtime/host/route-mesh-runtime.d.ts +2 -2
  123. package/dist/runtime/host/route-mesh-runtime.js +5 -3
  124. package/dist/runtime/host/runtime-shutdown.d.ts +1 -0
  125. package/dist/runtime/host/runtime-shutdown.js +3 -2
  126. package/dist/runtime/host/service-relocation-host-runtime.d.ts +17 -7
  127. package/dist/runtime/host/service-relocation-host-runtime.js +550 -367
  128. package/dist/runtime/host/spot-runtime-options-factory.js +15 -7
  129. package/dist/runtime/host/user-spot-creation-coordinator.js +33 -84
  130. package/dist/runtime/locations/auto-connect-loop.d.ts +2 -0
  131. package/dist/runtime/locations/auto-connect-loop.js +22 -14
  132. package/dist/runtime/locations/auto-connect-reconciler.js +0 -6
  133. package/dist/runtime/locations/auto-connect-types.d.ts +0 -1
  134. package/dist/runtime/locations/descriptor-publication.d.ts +4 -0
  135. package/dist/runtime/locations/descriptor-publication.js +11 -0
  136. package/dist/runtime/locations/domain-store-contract.d.ts +1 -0
  137. package/dist/runtime/locations/in-memory-authority-store.d.ts +7 -1
  138. package/dist/runtime/locations/in-memory-authority-store.js +56 -19
  139. package/dist/runtime/locations/in-memory-location-store.js +1 -10
  140. package/dist/runtime/locations/index.d.ts +1 -0
  141. package/dist/runtime/locations/index.js +1 -0
  142. package/dist/runtime/locations/lease-tracker.js +1 -6
  143. package/dist/runtime/locations/location-store-repository.d.ts +51 -1
  144. package/dist/runtime/locations/location-store-repository.js +363 -139
  145. package/dist/runtime/locations/relocation-blob.d.ts +18 -1
  146. package/dist/runtime/locations/relocation-blob.js +52 -1
  147. package/dist/runtime/locations/request-source-resolver.d.ts +37 -0
  148. package/dist/runtime/locations/request-source-resolver.js +80 -0
  149. package/dist/runtime/locations/resolvers.js +1 -1
  150. package/dist/runtime/locations/runtime.d.ts +6 -2
  151. package/dist/runtime/locations/runtime.js +37 -30
  152. package/dist/runtime/messaging/payload-codec.d.ts +7 -1
  153. package/dist/runtime/messaging/payload-codec.js +7 -6
  154. package/dist/runtime/messaging/request-result.js +29 -26
  155. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +19 -1
  156. package/dist/runtime/protocol/service_wire_codec.generated.js +85 -0
  157. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +7 -1
  158. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +23 -7
  159. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +3 -2
  160. package/dist/runtime/spots/index.d.ts +18 -11
  161. package/dist/runtime/spots/index.js +234 -176
  162. package/dist/runtime/spots/spot-activation-registry.d.ts +4 -2
  163. package/dist/runtime/spots/spot-activation-registry.js +21 -11
  164. package/dist/runtime/spots/spot-activation-state.d.ts +1 -1
  165. package/dist/runtime/spots/spot-activation-state.js +7 -7
  166. package/dist/runtime/spots/spot-activation.d.ts +6 -3
  167. package/dist/runtime/spots/spot-activation.js +123 -44
  168. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -0
  169. package/dist/runtime/spots/spot-actor-admission-coordinator.js +13 -22
  170. package/dist/runtime/spots/spot-actor-membership.d.ts +0 -1
  171. package/dist/runtime/spots/spot-actor-membership.js +0 -8
  172. package/dist/runtime/spots/spot-actor-packet-dispatch.js +33 -8
  173. package/dist/runtime/spots/spot-actor-packet-drain.js +5 -33
  174. package/dist/runtime/spots/spot-entry-activation.d.ts +2 -0
  175. package/dist/runtime/spots/spot-entry-activation.js +14 -9
  176. package/dist/runtime/spots/spot-handler-registry.d.ts +4 -3
  177. package/dist/runtime/spots/spot-handler-registry.js +6 -2
  178. package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +2 -2
  179. package/dist/runtime/spots/spot-manager-public.js +2 -2
  180. package/dist/runtime/spots/spot-node-autoconnect.d.ts +2 -1
  181. package/dist/runtime/spots/spot-node-autoconnect.js +18 -39
  182. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +19 -2
  183. package/dist/runtime/spots/spot-node-runtime-manager.js +115 -50
  184. package/dist/runtime/spots/spot-outbound.js +3 -3
  185. package/dist/runtime/spots/spot-remote-codec.js +5 -1
  186. package/dist/runtime/spots/spot-runtime-ports.d.ts +0 -1
  187. package/dist/runtime/spots/spot-serial-executor.d.ts +10 -0
  188. package/dist/runtime/spots/spot-serial-executor.js +61 -8
  189. package/dist/runtime/spots/spot-serial-turn-executor.js +19 -2
  190. package/dist/runtime/spots/spot-subscription-dispatch.js +1 -1
  191. package/dist/runtime/spots/spot-timer.d.ts +57 -5
  192. package/dist/runtime/spots/spot-timer.js +287 -103
  193. package/dist/runtime/streams/actor-session-binding-registry.d.ts +42 -11
  194. package/dist/runtime/streams/actor-session-binding-registry.js +165 -48
  195. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +8 -4
  196. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -1
  197. package/dist/runtime/streams/bound-actor-relay-sender.js +15 -8
  198. package/dist/runtime/streams/bound-session-service.d.ts +1 -1
  199. package/dist/runtime/streams/bound-session-service.js +6 -11
  200. package/dist/runtime/streams/index.d.ts +3 -2
  201. package/dist/runtime/streams/index.js +6 -4
  202. package/dist/runtime/streams/managed-stream.js +3 -2
  203. package/dist/runtime/streams/native-fallback-bound-session.js +8 -73
  204. package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -8
  205. package/dist/runtime/streams/session-actor-coordinator.js +15 -32
  206. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +3 -10
  207. package/dist/runtime/streams/stream-session-runtime.js +1 -4
  208. package/dist/runtime/workers/index.js +1 -1
  209. package/package.json +3 -3
  210. package/src/contracts/Common/ZLinkEncodedPayload.ts +24 -4
  211. package/src/contracts/Common/encoded-payload-storage.ts +6 -3
  212. package/src/contracts/Configuration/Builders.ts +4 -1
  213. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +7 -2
  214. package/src/contracts/Configuration/RegistrationBuilders.ts +6 -2
  215. package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
  216. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +2 -1
  217. package/src/contracts/Locations/Rows.ts +2 -0
  218. package/src/contracts/Spots/Contracts.ts +8 -0
  219. package/src/contracts/Spots/ZLinkSpot.ts +3 -3
  220. package/src/runtime/abort.ts +12 -0
  221. package/src/runtime/actors/actor-authority-publication.ts +3 -2
  222. package/src/runtime/actors/actor-client.ts +61 -70
  223. package/src/runtime/actors/actor-context.ts +49 -9
  224. package/src/runtime/actors/actor-handoff.ts +282 -106
  225. package/src/runtime/actors/actor-join-relocation.ts +2 -0
  226. package/src/runtime/actors/actor-local-native-join.ts +4 -0
  227. package/src/runtime/actors/actor-mailbox.ts +40 -2
  228. package/src/runtime/actors/actor-remote-joiner.ts +6 -1
  229. package/src/runtime/actors/actor-reply.ts +42 -0
  230. package/src/runtime/actors/actor-runtime-contracts.ts +2 -0
  231. package/src/runtime/actors/actor-runtime-state.ts +2 -20
  232. package/src/runtime/actors/actor-source-transfer.ts +1 -34
  233. package/src/runtime/actors/index.ts +41 -27
  234. package/src/runtime/actors/session-disconnected-wire.ts +66 -0
  235. package/src/runtime/admission.ts +69 -34
  236. package/src/runtime/application-jobs/application-job-queue-scope.ts +33 -1
  237. package/src/runtime/application-jobs/contracts.ts +2 -0
  238. package/src/runtime/backend/contracts/index.ts +39 -4
  239. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +5 -3
  240. package/src/runtime/backend/mesh-completion-table.ts +4 -0
  241. package/src/runtime/backend/mesh-dispatch-pump.ts +223 -124
  242. package/src/runtime/backend/node/node-raw-binding-port.ts +106 -70
  243. package/src/runtime/backend/node/node-raw-mesh-backend.ts +221 -170
  244. package/src/runtime/backend/node/node-socket-backend-adapter.ts +5 -5
  245. package/src/runtime/channels/channel-clients.ts +49 -24
  246. package/src/runtime/channels/channel-dispatch-pipeline.ts +173 -124
  247. package/src/runtime/channels/channel-dispatchers.ts +116 -72
  248. package/src/runtime/channels/channel-envelope.ts +105 -36
  249. package/src/runtime/channels/channel-runtime-lifecycle.ts +13 -13
  250. package/src/runtime/channels/channel-runtime-manager.ts +12 -5
  251. package/src/runtime/channels/channel-transports.ts +49 -58
  252. package/src/runtime/channels/client-server-location-runtime.ts +11 -10
  253. package/src/runtime/channels/dispatch-error-reporter.ts +4 -2
  254. package/src/runtime/channels/fanout-location-runtime.ts +17 -9
  255. package/src/runtime/diagnostics/flow-context.ts +20 -7
  256. package/src/runtime/diagnostics/index.ts +1 -7
  257. package/src/runtime/diagnostics/message-flow.ts +47 -9
  258. package/src/runtime/diagnostics/runtime-metrics.ts +12 -10
  259. package/src/runtime/execution/index.ts +40 -14
  260. package/src/runtime/execution/serial-execution-queue.ts +31 -4
  261. package/src/runtime/execution/state-lane.ts +7 -0
  262. package/src/runtime/foundation/operation-registry.ts +98 -20
  263. package/src/runtime/foundation/raw-service-mesh-runtime.ts +244 -67
  264. package/src/runtime/foundation/service-liveness-registry.ts +39 -0
  265. package/src/runtime/foundation/service-mailbox.ts +8 -0
  266. package/src/runtime/foundation/service-maintenance-runtime.ts +1 -8
  267. package/src/runtime/foundation/service-relocation-object-owner.ts +54 -37
  268. package/src/runtime/foundation/service-relocation-runtime.ts +7 -3
  269. package/src/runtime/foundation/service-runtime-contracts.ts +12 -1
  270. package/src/runtime/foundation/service-session-binding-ingress-port.ts +2 -1
  271. package/src/runtime/foundation/service-stateful-registry.ts +38 -35
  272. package/src/runtime/foundation/service-stateful-runtime.ts +667 -152
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +49 -11
  274. package/src/runtime/foundation/service-wire-binary-primitives.ts +35 -12
  275. package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
  276. package/src/runtime/foundation/service-wire-m6a-codec.ts +187 -51
  277. package/src/runtime/host/actor-packet-relay.ts +113 -94
  278. package/src/runtime/host/actor-placement-coordinator.ts +31 -8
  279. package/src/runtime/host/actor-transfer-runtime.ts +104 -430
  280. package/src/runtime/host/application-job-queue.ts +29 -44
  281. package/src/runtime/host/index.ts +286 -129
  282. package/src/runtime/host/location-runtime-owner.ts +2 -6
  283. package/src/runtime/host/mesh-router-resolver.ts +13 -5
  284. package/src/runtime/host/remote-bound-session-relay.ts +86 -248
  285. package/src/runtime/host/route-mesh-runtime.ts +11 -5
  286. package/src/runtime/host/runtime-shutdown.ts +15 -4
  287. package/src/runtime/host/service-relocation-host-runtime.ts +784 -475
  288. package/src/runtime/host/spot-runtime-options-factory.ts +18 -7
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +41 -100
  290. package/src/runtime/locations/auto-connect-loop.ts +22 -14
  291. package/src/runtime/locations/auto-connect-reconciler.ts +0 -6
  292. package/src/runtime/locations/auto-connect-types.ts +0 -1
  293. package/src/runtime/locations/descriptor-publication.ts +7 -0
  294. package/src/runtime/locations/domain-store-contract.ts +5 -0
  295. package/src/runtime/locations/in-memory-authority-store.ts +85 -23
  296. package/src/runtime/locations/in-memory-location-store.ts +1 -12
  297. package/src/runtime/locations/index.ts +1 -0
  298. package/src/runtime/locations/lease-tracker.ts +2 -9
  299. package/src/runtime/locations/location-store-repository.ts +628 -152
  300. package/src/runtime/locations/relocation-blob.ts +75 -1
  301. package/src/runtime/locations/request-source-resolver.ts +138 -0
  302. package/src/runtime/locations/resolvers.ts +2 -2
  303. package/src/runtime/locations/runtime.ts +70 -40
  304. package/src/runtime/messaging/payload-codec.ts +8 -11
  305. package/src/runtime/messaging/request-result.ts +33 -29
  306. package/src/runtime/protocol/service_wire_codec.generated.ts +87 -4
  307. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +13 -10
  308. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +3 -2
  309. package/src/runtime/spots/index.ts +375 -281
  310. package/src/runtime/spots/spot-activation-registry.ts +25 -13
  311. package/src/runtime/spots/spot-activation-state.ts +12 -19
  312. package/src/runtime/spots/spot-activation.ts +170 -86
  313. package/src/runtime/spots/spot-actor-admission-coordinator.ts +25 -55
  314. package/src/runtime/spots/spot-actor-membership.ts +0 -15
  315. package/src/runtime/spots/spot-actor-packet-dispatch.ts +56 -11
  316. package/src/runtime/spots/spot-actor-packet-drain.ts +9 -52
  317. package/src/runtime/spots/spot-entry-activation.ts +24 -19
  318. package/src/runtime/spots/spot-handler-registry.ts +15 -4
  319. package/src/runtime/spots/spot-manager-internal-contracts.ts +2 -2
  320. package/src/runtime/spots/spot-manager-public.ts +2 -2
  321. package/src/runtime/spots/spot-node-autoconnect.ts +22 -45
  322. package/src/runtime/spots/spot-node-runtime-manager.ts +197 -67
  323. package/src/runtime/spots/spot-outbound.ts +3 -3
  324. package/src/runtime/spots/spot-remote-codec.ts +9 -2
  325. package/src/runtime/spots/spot-runtime-ports.ts +0 -1
  326. package/src/runtime/spots/spot-serial-executor.ts +97 -25
  327. package/src/runtime/spots/spot-serial-turn-executor.ts +22 -3
  328. package/src/runtime/spots/spot-subscription-dispatch.ts +1 -1
  329. package/src/runtime/spots/spot-timer.ts +413 -157
  330. package/src/runtime/streams/actor-session-binding-registry.ts +236 -64
  331. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +16 -8
  332. package/src/runtime/streams/bound-actor-relay-sender.ts +23 -9
  333. package/src/runtime/streams/bound-session-service.ts +7 -10
  334. package/src/runtime/streams/index.ts +12 -6
  335. package/src/runtime/streams/managed-stream.ts +4 -2
  336. package/src/runtime/streams/native-fallback-bound-session.ts +14 -103
  337. package/src/runtime/streams/session-actor-coordinator.ts +39 -88
  338. package/src/runtime/streams/stream-binding-runtime-ports.ts +3 -9
  339. package/src/runtime/streams/stream-session-runtime.ts +1 -5
  340. package/src/runtime/workers/index.ts +1 -1
@@ -30,14 +30,8 @@ function sameRemoteSessionOwnerLifecycle(left, right) {
30
30
  right.sessionNodeRid !== undefined &&
31
31
  left.sessionOwnerNodeGeneration !== undefined &&
32
32
  right.sessionOwnerNodeGeneration !== undefined &&
33
- left.sessionOwnerId !== undefined &&
34
- right.sessionOwnerId !== undefined &&
35
- left.sessionOwnerLeaseGeneration !== undefined &&
36
- right.sessionOwnerLeaseGeneration !== undefined &&
37
33
  (0, routing_id_1.routingIdsEqual)(left.sessionNodeRid, right.sessionNodeRid) &&
38
- left.sessionOwnerNodeGeneration === right.sessionOwnerNodeGeneration &&
39
- left.sessionOwnerId === right.sessionOwnerId &&
40
- left.sessionOwnerLeaseGeneration === right.sessionOwnerLeaseGeneration);
34
+ left.sessionOwnerNodeGeneration === right.sessionOwnerNodeGeneration);
41
35
  }
42
36
  function sameRemoteSessionOwner(left, right) {
43
37
  return (left.sessionRid !== undefined &&
@@ -296,19 +290,7 @@ class ZLinkActorRuntimeState {
296
290
  target.bindingGeneration === undefined) {
297
291
  throw new TypeError('An installed bound Session target requires its binding identity.');
298
292
  }
299
- const current = this.boundSessionValue;
300
- if (current !== undefined && sameRemoteSessionOwnerLifecycle(current, target)) {
301
- // A duplicate or late older command for the exact physical Session
302
- // leaves the current binding; a newer generation of the same Session
303
- // replaces it. A different Session in the same owner lifecycle must
304
- // advance that lifecycle's generation; a late equal/lower one is stale.
305
- const advances = current.bindingGeneration === undefined ||
306
- target.bindingGeneration > current.bindingGeneration;
307
- if (!advances)
308
- return sameRemoteSessionOwner(current, target);
309
- }
310
- // Binding generations are scoped to a Session-owner lifecycle. A restarted
311
- // owner can legitimately reset its counter below the predecessor value.
293
+ // The service registry accepted this identity in the Actor owner turn.
312
294
  this.boundSessionValue = boundSessionIdentity(target);
313
295
  return true;
314
296
  }
@@ -1,27 +1,11 @@
1
- import type { ActorRef, ZLinkActor, ZLinkMessage } from '../../contracts';
1
+ import type { ActorRef, ZLinkActor } from '../../contracts';
2
2
  import type { ZLinkSpotRouteTarget } from '../spots/spot-routing-internal';
3
3
  import type { ZLinkActorRuntimeState } from './actor-runtime-state';
4
- import type { ZLinkActorHandoffPacket, ZLinkActorHandoffResult } from './actor-handoff';
5
- import type { ServiceWireOperationId } from '../foundation/service-stateful-wire-codec';
6
- export interface ZLinkPreparedActorSource {
7
- readonly adapterKey?: string;
8
- readonly state: ZLinkMessage;
9
- readonly handoffBacklog: readonly ZLinkActorHandoffPacket[];
10
- readonly sourceLeaveCompletion?: Promise<void>;
11
- readonly sourceLeaveSubmitted?: Promise<void>;
12
- onSourceLeaveSubmitted(notify: () => Promise<void>): void;
13
- observeTargetAuthority(target: ZLinkSpotRouteTarget, targetActorRef: ActorRef, signal?: AbortSignal): Promise<void>;
14
- commit(target: ZLinkSpotRouteTarget, targetActorRef: ActorRef, results: readonly ZLinkActorHandoffResult[], releaseLocation?: boolean): void;
15
- rollback(): Promise<void>;
16
- }
17
4
  export interface ZLinkActorSourceTransfer {
18
5
  /** Starts the ingress handoff before target route lookup. */
19
6
  beginDeferredActorHandoff?(actor: ZLinkActor, state: ZLinkActorRuntimeState): void;
20
- /** Changes a provisional ingress fence into a relocation handoff. */
21
- promoteDeferredActorHandoff?(actor: ZLinkActor, state: ZLinkActorRuntimeState): void;
22
7
  /** Finishes a same-node deferred Join handoff after completion callback. */
23
8
  completeDeferredActorHandoff?(actor: ZLinkActor, target: ZLinkSpotRouteTarget, targetActorRef: ActorRef): Promise<void>;
24
9
  /** Releases an early handoff when Join cannot commit. */
25
10
  cancelDeferredActorHandoff?(actor: ZLinkActor, state: ZLinkActorRuntimeState): Promise<void>;
26
- prepareSource(actor: ZLinkActor, state: ZLinkActorRuntimeState, signal?: AbortSignal, lifecycleAuthority?: 'framework' | 'core', deferredJoin?: boolean, relocation?: ServiceWireOperationId): Promise<ZLinkPreparedActorSource>;
27
11
  }
@@ -2,7 +2,7 @@ import { type ActorRef, type RoutingId, type SpotRef, type ZLinkActor, type ZLin
2
2
  import type { ZLinkBackendActorRef, ZLinkBackendSpotNode } from '../backend/contracts';
3
3
  import type { ZLinkActorManagerOptions } from './actor-runtime-contracts';
4
4
  import { ZLinkActorRuntimeState } from './actor-runtime-state';
5
- export { DefaultZLinkActorClient, forwardEncodedActorPacket, type ZLinkActorClientOptions } from './actor-client';
5
+ export { DefaultZLinkActorClient, type ZLinkActorClientOptions } from './actor-client';
6
6
  export { DefaultZLinkActorContext, ZLINK_ACTOR_JOIN_ENTRY_SPOT_RUNTIME } from './actor-context';
7
7
  export { ZLinkActorSerialExecutor } from './actor-mailbox';
8
8
  export { DEFAULT_MESSAGE_FOLLOW_DURATION_MS, ZLinkActorHandoffCoordinator, decodeHandoffPacket, type ZLinkActorHandoffPacket, type ZLinkActorHandoffDispatch, type ZLinkActorHandoffPrefixAdmission, type ZLinkActorHandoffPrefixQueue, type ZLinkActorHandoffPrefixRecord, type ZLinkActorHandoffPreparedReplayAdmission, type ZLinkActorHandoffReplayAdmission, type ZLinkActorHandoffReplayPreparation, type ZLinkActorHandoffResult } from './actor-handoff';
@@ -51,10 +51,14 @@ export declare class DefaultZLinkActorManager implements ZLinkActorManager {
51
51
  publishRelocationActor(actorId: string): void;
52
52
  abortRelocationActor(actorId: string): Promise<void>;
53
53
  completeRelocationSource(actorId: string, sourceActorRef?: ZLinkBackendActorRef): Promise<void>;
54
+ /** Commit removes current ownership; a Join profile may still own its leave callback. */
55
+ detachRelocationSource(state: ZLinkActorRuntimeState): void;
54
56
  releaseSpotActorMembers(meshName: string, spotId?: RoutingId): Promise<void>;
55
57
  private releaseLocalActor;
56
- completeCoreRelocationSource(actorId: string): Promise<void>;
58
+ completeCoreRelocationSource(actorId: string, state?: ZLinkActorRuntimeState | undefined): Promise<void>;
59
+ private discardNativeRelocationSource;
57
60
  private finalizeActorState;
61
+ private detachActorStateRegistration;
58
62
  private finalizeDestroyedActor;
59
63
  private terminateActor;
60
64
  private awaitActorDestroy;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultZLinkActorManager = exports.ZLINK_ACTOR_LIFECYCLE_SNAPSHOT = exports.createActorMembership = exports.createActorJoinRequest = exports.actorJoinIdentity = exports.ZLinkRemoteBoundSessionFenceError = exports.isRemoteBoundSessionFenceError = exports.encodeRemoteBoundSessionNack = exports.ZLINK_REMOTE_BOUND_SESSION_SEND_PACKET = exports.ZLINK_REMOTE_BOUND_SESSION_RESPONSE_PACKET = exports.ZLINK_REMOTE_BOUND_SESSION_FENCE_NACK_CODE = exports.ZLINK_REMOTE_BOUND_SESSION_ERROR_PACKET = exports.ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET = exports.ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET = exports.decodeRemoteActorSourceLeaveTerminal = exports.ZLINK_REMOTE_ACTOR_SOURCE_LEAVE_TERMINAL = exports.ZLINK_REMOTE_ACTOR_JOIN_PACKET = exports.ZLinkActorTransferRegistry = exports.ZLinkActorNativeJoinCoordinator = exports.ZLinkSpotActorHandlerRegistryRuntime = exports.ZLinkSpotActorDispatcher = exports.ZLinkActorPacketKind = exports.publishInitialActorAuthority = exports.rewriteActorAuthorityOwner = exports.rewriteActorAuthorityRoute = exports.isActorAuthorityPayload = exports.encodeActorAuthorityIdentity = exports.decodeRelocatingActorAuthorityIdentity = exports.decodeActorAuthorityIdentity = exports.createDeferredJoinCompletion = exports.toFrameworkRoutingId = exports.toFrameworkActorRef = exports.ZLinkActorRuntimeState = exports.decodeActorMessageFollowContext = exports.attachActorMessageFollowContext = exports.actorMessageFollowContext = exports.decodeHandoffPacket = exports.ZLinkActorHandoffCoordinator = exports.DEFAULT_MESSAGE_FOLLOW_DURATION_MS = exports.ZLinkActorSerialExecutor = exports.ZLINK_ACTOR_JOIN_ENTRY_SPOT_RUNTIME = exports.DefaultZLinkActorContext = exports.forwardEncodedActorPacket = exports.DefaultZLinkActorClient = void 0;
3
+ exports.DefaultZLinkActorManager = exports.ZLINK_ACTOR_LIFECYCLE_SNAPSHOT = exports.createActorMembership = exports.createActorJoinRequest = exports.actorJoinIdentity = exports.ZLinkRemoteBoundSessionFenceError = exports.isRemoteBoundSessionFenceError = exports.encodeRemoteBoundSessionNack = exports.ZLINK_REMOTE_BOUND_SESSION_SEND_PACKET = exports.ZLINK_REMOTE_BOUND_SESSION_RESPONSE_PACKET = exports.ZLINK_REMOTE_BOUND_SESSION_FENCE_NACK_CODE = exports.ZLINK_REMOTE_BOUND_SESSION_ERROR_PACKET = exports.ZLINK_REMOTE_ACTOR_SESSION_DISCONNECTED_PACKET = exports.ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET = exports.decodeRemoteActorSourceLeaveTerminal = exports.ZLINK_REMOTE_ACTOR_SOURCE_LEAVE_TERMINAL = exports.ZLINK_REMOTE_ACTOR_JOIN_PACKET = exports.ZLinkActorTransferRegistry = exports.ZLinkActorNativeJoinCoordinator = exports.ZLinkSpotActorHandlerRegistryRuntime = exports.ZLinkSpotActorDispatcher = exports.ZLinkActorPacketKind = exports.publishInitialActorAuthority = exports.rewriteActorAuthorityOwner = exports.rewriteActorAuthorityRoute = exports.isActorAuthorityPayload = exports.encodeActorAuthorityIdentity = exports.decodeRelocatingActorAuthorityIdentity = exports.decodeActorAuthorityIdentity = exports.createDeferredJoinCompletion = exports.toFrameworkRoutingId = exports.toFrameworkActorRef = exports.ZLinkActorRuntimeState = exports.decodeActorMessageFollowContext = exports.attachActorMessageFollowContext = exports.actorMessageFollowContext = exports.decodeHandoffPacket = exports.ZLinkActorHandoffCoordinator = exports.DEFAULT_MESSAGE_FOLLOW_DURATION_MS = exports.ZLinkActorSerialExecutor = exports.ZLINK_ACTOR_JOIN_ENTRY_SPOT_RUNTIME = exports.DefaultZLinkActorContext = exports.DefaultZLinkActorClient = void 0;
4
4
  const contracts_1 = require("../../contracts");
5
5
  const Registration_1 = require("../../contracts/Configuration/Registration");
6
6
  const abort_1 = require("../abort");
@@ -20,7 +20,6 @@ const ACTOR_CREATION_RETRY_INTERVAL_MS = 5;
20
20
  const LOCAL_DIAGNOSTIC_NODE_RID = 'local';
21
21
  var actor_client_1 = require("./actor-client");
22
22
  Object.defineProperty(exports, "DefaultZLinkActorClient", { enumerable: true, get: function () { return actor_client_1.DefaultZLinkActorClient; } });
23
- Object.defineProperty(exports, "forwardEncodedActorPacket", { enumerable: true, get: function () { return actor_client_1.forwardEncodedActorPacket; } });
24
23
  var actor_context_1 = require("./actor-context");
25
24
  Object.defineProperty(exports, "DefaultZLinkActorContext", { enumerable: true, get: function () { return actor_context_1.DefaultZLinkActorContext; } });
26
25
  Object.defineProperty(exports, "ZLINK_ACTOR_JOIN_ENTRY_SPOT_RUNTIME", { enumerable: true, get: function () { return actor_context_1.ZLINK_ACTOR_JOIN_ENTRY_SPOT_RUNTIME; } });
@@ -262,6 +261,10 @@ class DefaultZLinkActorManager {
262
261
  }
263
262
  async findActor(actorId, signal) {
264
263
  (0, abort_1.throwIfAborted)(signal);
264
+ return this.resolveLocalActor(actorId);
265
+ }
266
+ /** @internal Uses the relocation owner's publication boundary for local dispatch. */
267
+ resolveLocalActor(actorId) {
265
268
  if (this.relocationStaged.has(actorId))
266
269
  return undefined;
267
270
  return this.states.get(actorId)?.actor;
@@ -310,7 +313,7 @@ class DefaultZLinkActorManager {
310
313
  node.discardRelocatedActor?.(nativeRef);
311
314
  this.relocationStaged.delete(actorId);
312
315
  const failedState = this.states.get(actorId);
313
- await this.finalizeActorState(actorId, failedState);
316
+ await this.finalizeActorState(failedState);
314
317
  throw error;
315
318
  }
316
319
  }
@@ -326,6 +329,12 @@ class DefaultZLinkActorManager {
326
329
  async completeRelocationSource(actorId, sourceActorRef) {
327
330
  await this.releaseLocalActor(actorId, sourceActorRef);
328
331
  }
332
+ /** Commit removes current ownership; a Join profile may still own its leave callback. */
333
+ detachRelocationSource(state) {
334
+ if (this.detachActorStateRegistration(state)) {
335
+ this.discardNativeRelocationSource(state.nativeActorRef);
336
+ }
337
+ }
329
338
  async releaseSpotActorMembers(meshName, spotId) {
330
339
  const results = await Promise.allSettled([...this.states.values()]
331
340
  .filter((state) => state.meshName === meshName && state.spotId === spotId)
@@ -340,19 +349,17 @@ class DefaultZLinkActorManager {
340
349
  }
341
350
  async releaseLocalActor(actorId, exactNativeActorRef) {
342
351
  const state = this.states.get(actorId);
343
- const node = this.options.nativeActorNodeProvider?.() ?? this.options.nativeActorNode;
344
- const nativeActorRef = exactNativeActorRef ?? state?.nativeActorRef;
352
+ if (state === undefined)
353
+ return;
345
354
  const failures = [];
346
355
  try {
347
- if (nativeActorRef !== undefined) {
348
- node?.discardRelocatedActor?.(nativeActorRef);
349
- }
356
+ this.discardNativeRelocationSource(exactNativeActorRef ?? state.nativeActorRef);
350
357
  }
351
358
  catch (error) {
352
359
  failures.push(error);
353
360
  }
354
361
  try {
355
- await this.completeCoreRelocationSource(actorId);
362
+ await this.completeCoreRelocationSource(actorId, state);
356
363
  }
357
364
  catch (error) {
358
365
  failures.push(error);
@@ -363,12 +370,17 @@ class DefaultZLinkActorManager {
363
370
  : new AggregateError(failures, 'Actor relocation cleanup failed.');
364
371
  }
365
372
  }
366
- async completeCoreRelocationSource(actorId) {
367
- const state = this.states.get(actorId);
368
- await this.finalizeActorState(actorId, state);
373
+ async completeCoreRelocationSource(actorId, state = this.states.get(actorId)) {
374
+ await this.finalizeActorState(state);
369
375
  }
370
- async finalizeActorState(actorId, state) {
371
- if (state === undefined || this.states.get(actorId) !== state)
376
+ discardNativeRelocationSource(nativeActorRef) {
377
+ if (nativeActorRef === undefined)
378
+ return;
379
+ const node = this.options.nativeActorNodeProvider?.() ?? this.options.nativeActorNode;
380
+ node?.discardRelocatedActor?.(nativeActorRef);
381
+ }
382
+ async finalizeActorState(state) {
383
+ if (state === undefined)
372
384
  return;
373
385
  try {
374
386
  if (state.actor !== undefined)
@@ -376,13 +388,17 @@ class DefaultZLinkActorManager {
376
388
  }
377
389
  finally {
378
390
  state.clearAfterDestroy();
379
- if (this.states.get(actorId) === state) {
380
- this.states.delete(actorId);
381
- this.actorMeshNames.delete(actorId);
382
- this.relocationStaged.delete(actorId);
383
- }
391
+ this.detachActorStateRegistration(state);
384
392
  }
385
393
  }
394
+ detachActorStateRegistration(state) {
395
+ if (this.states.get(state.actorId) !== state)
396
+ return false;
397
+ this.states.delete(state.actorId);
398
+ this.actorMeshNames.delete(state.actorId);
399
+ this.relocationStaged.delete(state.actorId);
400
+ return true;
401
+ }
386
402
  async finalizeDestroyedActor(actorId, state) {
387
403
  if (this.states.get(actorId) !== state)
388
404
  return;
@@ -390,7 +406,7 @@ class DefaultZLinkActorManager {
390
406
  this.options.actorDestroyedCleanup?.(actorId);
391
407
  }
392
408
  finally {
393
- await this.finalizeActorState(actorId, state);
409
+ await this.finalizeActorState(state);
394
410
  this.options.metrics?.change(runtime_metrics_1.METRIC_NAMES.ActorCount, -1);
395
411
  }
396
412
  }
@@ -644,7 +660,7 @@ class ZLinkActorCreateCallRuntime {
644
660
  yield(signal) {
645
661
  const turn = (0, execution_1.requireZLinkYieldTurn)(this.turn);
646
662
  const pending = this.executeOnce(signal);
647
- return turn.yieldPromise(pending);
663
+ return turn.yieldFrameworkPromise(pending);
648
664
  }
649
665
  executeOnce(signal) {
650
666
  this.requireMutable();
@@ -0,0 +1,8 @@
1
+ import type { RoutingId } from '../../contracts';
2
+ export interface SessionDisconnectedIdentity {
3
+ readonly sessionOwnerNodeRid: RoutingId;
4
+ readonly sessionOwnerNodeGeneration: bigint;
5
+ readonly bindingGeneration: bigint;
6
+ }
7
+ export declare function encodeSessionDisconnected(sessionOwnerNodeRid: RoutingId | undefined, sessionOwnerNodeGeneration: bigint | undefined, bindingGeneration: bigint | undefined): Buffer;
8
+ export declare function decodeSessionDisconnected(bytes: Uint8Array): SessionDisconnectedIdentity | undefined;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeSessionDisconnected = encodeSessionDisconnected;
4
+ exports.decodeSessionDisconnected = decodeSessionDisconnected;
5
+ const CoreTypes_1 = require("../../contracts/Common/CoreTypes");
6
+ const contracts_1 = require("../../contracts");
7
+ const routing_id_1 = require("../routing-id");
8
+ const RID_LENGTH_BYTES = 1;
9
+ const GENERATION_BYTES = 8;
10
+ const GENERATIONS_BYTES = GENERATION_BYTES * 2;
11
+ function encodeSessionDisconnected(sessionOwnerNodeRid, sessionOwnerNodeGeneration, bindingGeneration) {
12
+ if (sessionOwnerNodeRid === undefined ||
13
+ sessionOwnerNodeGeneration === undefined ||
14
+ sessionOwnerNodeGeneration === 0n ||
15
+ bindingGeneration === undefined ||
16
+ bindingGeneration === 0n) {
17
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Session disconnect requires an exact binding identity.');
18
+ }
19
+ const rid = Buffer.from((0, routing_id_1.encodeRoutingIdStorageHex)(sessionOwnerNodeRid), 'hex');
20
+ if (rid.length === 0 || rid.length > CoreTypes_1.ZLINK_MAX_ROUTING_ID_BYTES) {
21
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Invalid Session owner Node RID length.');
22
+ }
23
+ const payload = Buffer.allocUnsafe(RID_LENGTH_BYTES + rid.length + GENERATIONS_BYTES);
24
+ payload[0] = rid.length;
25
+ rid.copy(payload, RID_LENGTH_BYTES);
26
+ payload.writeBigUInt64BE(sessionOwnerNodeGeneration, RID_LENGTH_BYTES + rid.length);
27
+ payload.writeBigUInt64BE(bindingGeneration, RID_LENGTH_BYTES + rid.length + GENERATION_BYTES);
28
+ return payload;
29
+ }
30
+ function decodeSessionDisconnected(bytes) {
31
+ const payload = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
32
+ if (payload.length < RID_LENGTH_BYTES + 1 + GENERATIONS_BYTES)
33
+ return undefined;
34
+ const ridLength = payload[0];
35
+ if (ridLength === 0 || payload.length !== RID_LENGTH_BYTES + ridLength + GENERATIONS_BYTES)
36
+ return undefined;
37
+ const offset = RID_LENGTH_BYTES + ridLength;
38
+ const sessionOwnerNodeGeneration = payload.readBigUInt64BE(offset);
39
+ const bindingGeneration = payload.readBigUInt64BE(offset + GENERATION_BYTES);
40
+ if (sessionOwnerNodeGeneration === 0n || bindingGeneration === 0n)
41
+ return undefined;
42
+ const hex = payload.subarray(RID_LENGTH_BYTES, offset).toString('hex');
43
+ return {
44
+ sessionOwnerNodeRid: (0, routing_id_1.decodeRoutingId)(hex, hex),
45
+ sessionOwnerNodeGeneration,
46
+ bindingGeneration
47
+ };
48
+ }
@@ -1,4 +1,6 @@
1
1
  import { ZLinkFrameworkInternalErrorKind } from './framework-errors-internal';
2
+ /** Runs host admission inside the domain's request completion boundary. */
3
+ export type ZLinkMeshDispatchAdmission = (dispatch: () => void | Promise<void>, onRejected?: (error: unknown) => void | Promise<void>) => void | Promise<void>;
2
4
  /** 소비한 배열 prefix가 정리 조건에 도달했는지 판정합니다. */
3
5
  export declare function shouldCompactBackingArray(head: number, length: number): boolean;
4
6
  export declare class ZLinkRuntimeAdmissionGate {
@@ -16,7 +18,13 @@ export declare class ZLinkRuntimeAdmissionGate {
16
18
  seal(meshName: string, reason?: ZLinkFrameworkInternalErrorKind): void;
17
19
  close(): void;
18
20
  claim(meshName: string, operation: string): ZLinkApplicationWorkClaim;
19
- run<T>(meshName: string, operation: string, work: () => T | Promise<T>): Promise<T>;
21
+ /**
22
+ * Runs one admitted unit of work. Work that completes synchronously leaves
23
+ * admission in the same turn; asynchronous work leaves it from the single
24
+ * continuation on its result.
25
+ */
26
+ run<T>(meshName: string, operation: string, work: () => T | Promise<T>, onRejected?: (error: unknown) => T | Promise<T>): T | Promise<T>;
27
+ private enter;
20
28
  awaitZero(meshName: string, signal?: AbortSignal): Promise<void>;
21
29
  requireRequest(operation: string, meshName?: string): void;
22
30
  requireActorCreate(actorId: string, meshName?: string): void;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkRuntimeAdmissionGate = void 0;
4
4
  exports.shouldCompactBackingArray = shouldCompactBackingArray;
5
5
  const framework_errors_internal_1 = require("./framework-errors-internal");
6
+ const abort_1 = require("./abort");
6
7
  const BACKING_ARRAY_COMPACTION_MIN_HEAD = 1024;
7
8
  /** 소비한 배열 prefix가 정리 조건에 도달했는지 판정합니다. */
8
9
  function shouldCompactBackingArray(head, length) {
@@ -57,44 +58,58 @@ class ZLinkRuntimeAdmissionGate {
57
58
  }
58
59
  }
59
60
  claim(meshName, operation) {
60
- const state = this.requireState(meshName);
61
- if (this.ownerAdmissionOpen() && !state.sealed) {
62
- state.active += 1;
63
- let closed = false;
64
- return {
65
- close: () => {
66
- if (closed)
67
- return;
68
- closed = true;
69
- state.active -= 1;
70
- if (state.active === 0) {
71
- let resolve;
72
- while ((resolve = takeWaiter(state)) !== undefined)
73
- resolve();
74
- }
75
- }
76
- };
77
- }
78
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(state.sealedReason, `${operation} was rejected because framework admission is closed.`);
61
+ const state = this.enter(meshName, operation);
62
+ let closed = false;
63
+ return {
64
+ close: () => {
65
+ if (closed)
66
+ return;
67
+ closed = true;
68
+ exitAdmission(state);
69
+ }
70
+ };
79
71
  }
80
- run(meshName, operation, work) {
81
- let claim;
72
+ /**
73
+ * Runs one admitted unit of work. Work that completes synchronously leaves
74
+ * admission in the same turn; asynchronous work leaves it from the single
75
+ * continuation on its result.
76
+ */
77
+ run(meshName, operation, work, onRejected) {
78
+ let state;
79
+ let result;
82
80
  try {
83
- claim = this.claim(meshName, operation);
84
- const result = work();
85
- const close = claim.close;
86
- return Promise.resolve(result).then((value) => {
87
- close();
88
- return value;
89
- }, (error) => {
90
- close();
91
- throw error;
92
- });
81
+ state = this.enter(meshName, operation);
93
82
  }
94
83
  catch (error) {
95
- claim?.close();
84
+ // The domain owns admission rejection completion, just as it owns handler failure.
85
+ return onRejected === undefined ? Promise.reject(error) : onRejected(error);
86
+ }
87
+ try {
88
+ result = work();
89
+ }
90
+ catch (error) {
91
+ exitAdmission(state);
96
92
  return Promise.reject(error);
97
93
  }
94
+ if (!(0, abort_1.isPromiseLike)(result)) {
95
+ exitAdmission(state);
96
+ return result;
97
+ }
98
+ return Promise.resolve(result).then((value) => {
99
+ exitAdmission(state);
100
+ return value;
101
+ }, (error) => {
102
+ exitAdmission(state);
103
+ throw error;
104
+ });
105
+ }
106
+ enter(meshName, operation) {
107
+ const state = this.requireState(meshName);
108
+ if (this.ownerAdmissionOpen() && !state.sealed) {
109
+ state.active += 1;
110
+ return state;
111
+ }
112
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(state.sealedReason, `${operation} was rejected because framework admission is closed.`);
98
113
  }
99
114
  awaitZero(meshName, signal) {
100
115
  const state = this.requireState(meshName);
@@ -160,6 +175,14 @@ class ZLinkRuntimeAdmissionGate {
160
175
  }
161
176
  }
162
177
  exports.ZLinkRuntimeAdmissionGate = ZLinkRuntimeAdmissionGate;
178
+ function exitAdmission(state) {
179
+ state.active -= 1;
180
+ if (state.active === 0) {
181
+ let resolve;
182
+ while ((resolve = takeWaiter(state)) !== undefined)
183
+ resolve();
184
+ }
185
+ }
163
186
  function takeWaiter(state) {
164
187
  advanceWaiterHead(state);
165
188
  const waiter = state.waiters[state.waiterHead];
@@ -1,4 +1,15 @@
1
1
  import type { ApplicationJobOrigin, ApplicationJobPermitPort } from './contracts';
2
+ /** Ends the internal processing of one record turn unless its handler detached the permit. */
3
+ export declare function releaseApplicationJobPermitTurn(permit: ApplicationJobPermitPort | undefined): void;
4
+ /**
5
+ * Makes `permit` the current record's permit for the synchronous part of a
6
+ * dispatch. The caller restores the returned previous scope with
7
+ * {@link leaveApplicationJobPermitScope} and releases the turn itself, so a
8
+ * dispatcher that already continues on the handler result needs no second
9
+ * continuation here.
10
+ */
11
+ export declare function enterApplicationJobPermitScope(permit: ApplicationJobPermitPort): ApplicationJobPermitPort | undefined;
12
+ export declare function leaveApplicationJobPermitScope(previous: ApplicationJobPermitPort | undefined): void;
2
13
  /**
3
14
  * Carries the host-owned queue permit through internal async dispatch without
4
15
  * leaking capacity ownership into public handler contracts.
@@ -9,6 +20,8 @@ export declare function runWithApplicationJobPermit<TResult, TFirst = undefined,
9
20
  export declare function releaseApplicationJobPermitBeforeHandler(): void;
10
21
  /** True while dispatch already owns the host-wide application job permit. */
11
22
  export declare function hasApplicationJobPermit(): boolean;
23
+ /** The current ingress reservation; capacity remains owned by its host queue. */
24
+ export declare function currentApplicationJobPermit(): ApplicationJobPermitPort | undefined;
12
25
  /** Keeps the ingress origin when a durable record later reacquires its permit. */
13
26
  export declare function currentApplicationJobOrigin(): ApplicationJobOrigin;
14
27
  /** Re-enters the captured permit scope when a serial executor runs later. */
@@ -1,19 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.releaseApplicationJobPermitTurn = releaseApplicationJobPermitTurn;
4
+ exports.enterApplicationJobPermitScope = enterApplicationJobPermitScope;
5
+ exports.leaveApplicationJobPermitScope = leaveApplicationJobPermitScope;
3
6
  exports.runWithApplicationJobPermit = runWithApplicationJobPermit;
4
7
  exports.releaseApplicationJobPermitBeforeHandler = releaseApplicationJobPermitBeforeHandler;
5
8
  exports.releaseApplicationJobPermitForDurableHandoff = releaseApplicationJobPermitForDurableHandoff;
6
9
  exports.hasApplicationJobPermit = hasApplicationJobPermit;
10
+ exports.currentApplicationJobPermit = currentApplicationJobPermit;
7
11
  exports.currentApplicationJobOrigin = currentApplicationJobOrigin;
8
12
  exports.bindApplicationJobPermit = bindApplicationJobPermit;
9
13
  exports.detachApplicationJobPermit = detachApplicationJobPermit;
10
14
  const node_async_hooks_1 = require("node:async_hooks");
11
15
  const applicationJobPermitScope = new node_async_hooks_1.AsyncLocalStorage();
12
16
  function releasePermitTurn() {
13
- const permit = applicationJobPermitScope.getStore();
17
+ releaseApplicationJobPermitTurn(applicationJobPermitScope.getStore());
18
+ }
19
+ /** Ends the internal processing of one record turn unless its handler detached the permit. */
20
+ function releaseApplicationJobPermitTurn(permit) {
14
21
  if (permit !== undefined && !permit.detachedForHandlerTurn)
15
22
  permit.releaseAfterInternalProcessing();
16
23
  }
24
+ /**
25
+ * Makes `permit` the current record's permit for the synchronous part of a
26
+ * dispatch. The caller restores the returned previous scope with
27
+ * {@link leaveApplicationJobPermitScope} and releases the turn itself, so a
28
+ * dispatcher that already continues on the handler result needs no second
29
+ * continuation here.
30
+ */
31
+ function enterApplicationJobPermitScope(permit) {
32
+ const previous = applicationJobPermitScope.getStore();
33
+ applicationJobPermitScope.enterWith(permit);
34
+ return previous;
35
+ }
36
+ function leaveApplicationJobPermitScope(previous) {
37
+ applicationJobPermitScope.enterWith(previous);
38
+ }
17
39
  function releasePermitSuccess(value) {
18
40
  releasePermitTurn();
19
41
  return value;
@@ -53,6 +75,10 @@ function releaseApplicationJobPermitForDurableHandoff() {
53
75
  function hasApplicationJobPermit() {
54
76
  return applicationJobPermitScope.getStore() !== undefined;
55
77
  }
78
+ /** The current ingress reservation; capacity remains owned by its host queue. */
79
+ function currentApplicationJobPermit() {
80
+ return applicationJobPermitScope.getStore();
81
+ }
56
82
  /** Keeps the ingress origin when a durable record later reacquires its permit. */
57
83
  function currentApplicationJobOrigin() {
58
84
  return applicationJobPermitScope.getStore().origin;
@@ -1,5 +1,7 @@
1
1
  export type ApplicationJobOrigin = 'local' | 'remote';
2
2
  export interface ApplicationJobPermitPort {
3
+ /** Reacquires this record's host supply after durable FIFO ownership. */
4
+ reacquire?(signal: AbortSignal): Promise<ApplicationJobPermitPort>;
3
5
  readonly origin: ApplicationJobOrigin;
4
6
  readonly detachedForHandlerTurn: boolean;
5
7
  markApplicationQueued(): void;
@@ -32,10 +32,17 @@ export type ZLinkBackendObjectPlacement = {
32
32
  } | {
33
33
  readonly kind: 'unavailable';
34
34
  };
35
+ export type ZLinkBackendRequestSourceAcceptance = (nodeRid: string, nodeGeneration: bigint, nodeRidStorageHex: string, signal?: AbortSignal) => import('../../locations/request-source-resolver').ZLinkRequestSourceFence | undefined | Promise<import('../../locations/request-source-resolver').ZLinkRequestSourceFence | undefined>;
35
36
  export interface ZLinkBackendMeshNode {
37
+ acceptRelocatedActorTerminal?(operation: {
38
+ readonly high: bigint;
39
+ readonly low: bigint;
40
+ }, replyRouteId: bigint, result: import('../../foundation/service-stateful-runtime').ServiceStatefulResult): 'terminalReceived' | 'alreadyTerminal' | undefined;
36
41
  readonly routingId?: RoutingId;
42
+ cancelPendingOperations?(reason: unknown): void;
37
43
  completeClosedInstance?(spotId: string, objectGeneration: bigint): void;
38
44
  setDispatchErrorReporter?(reporter: import('../../channels/dispatch-error-reporter').ZLinkDispatchErrorReporter, meshName: string): void;
45
+ setSessionOwnerDescriptors?(source: import('../../foundation/service-stateful-runtime').ServiceSessionOwnerDescriptors): void;
39
46
  setRoutingId(routingId: unknown): void;
40
47
  setBind(endpoint: string): void;
41
48
  setAdvertiseHost(host: string): void;
@@ -52,9 +59,9 @@ export interface ZLinkBackendMeshNode {
52
59
  }) => void): void;
53
60
  setMessageFollowHandler?(handler: (record: import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord) => void): void;
54
61
  sendMessageFollowNotification?(targetNodeRid: string, record: Omit<import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord, 'kind'>): Promise<boolean>;
55
- shutdown(timeoutMs: number): RequestResult;
62
+ shutdown(timeoutMs: number): Promise<RequestResult>;
56
63
  publishDraining?(): Promise<void>;
57
- close(): void;
64
+ close(): Promise<void>;
58
65
  addChannelName(name: string): void;
59
66
  setChannelWeight(name: string, weight: number): Promise<void>;
60
67
  setPlacementWeight(weight: number): Promise<void>;
@@ -97,10 +104,16 @@ export interface ZLinkBackendMeshNode {
97
104
  readonly securityIdentity?: string;
98
105
  readonly lifecycleGeneration: bigint;
99
106
  }): void;
107
+ /**
108
+ * Installs the source request owner check the first accepting owner runs on Actor and Spot
109
+ * ingress (Location runtime §9.3). Undefined from the check ends the request Unavailable.
110
+ */
111
+ setRequestSourceAcceptance?(acceptance: ZLinkBackendRequestSourceAcceptance): void;
100
112
  isObjectClientNodeDirectTarget?(targetRid: unknown): boolean;
101
113
  observePeerRoute?(targetRid: unknown): import('../../foundation/durable-service-request').PeerRouteObservation;
102
114
  hasPeerRouteOrConnectionIntent?(targetRid: unknown, endpoint: string): boolean;
103
115
  isPeerRouteReady?(targetRid: unknown, lifecycleGeneration?: bigint): boolean;
116
+ waitForPeerRoute?(targetRid: unknown, lifecycleGeneration: bigint, deadlineUnixMs: bigint, signal?: AbortSignal): Promise<void>;
104
117
  sendToNode(targetRid: unknown, parts: MessageLike | readonly MessageLike[], options?: {
105
118
  flags?: number;
106
119
  }): SubmitResult | Promise<SubmitResult>;
@@ -172,7 +185,8 @@ export interface ZLinkBackendMeshNode {
172
185
  forgetSpotRoute?(spot: ServiceDirectSpotRouteFence['spot'], authorityOwnerGeneration: bigint, storeVersion?: string): void;
173
186
  sealSpotMessageFollowIngress?(source: ServiceDirectSpotRouteFence): ServiceSpotMessageFollowSeal | undefined;
174
187
  abortSpotMessageFollowIngress?(seal: ServiceSpotMessageFollowSeal): boolean;
175
- commitSpotMessageFollowIngress?(seal: ServiceSpotMessageFollowSeal, target: ServiceDirectSpotRouteFence, durationMs: number): Promise<boolean>;
188
+ /** A null target consumes the committed seal without installing a Follow route. */
189
+ commitSpotMessageFollowIngress?(seal: ServiceSpotMessageFollowSeal, target: ServiceDirectSpotRouteFence | null, durationMs: number): Promise<boolean>;
176
190
  joinActorSpot(actor: ZLinkBackendActorRef, targetNodeRid: unknown, targetSpotId: unknown, targetSpotGeneration: bigint, request: ServiceApplicationPayload, timeoutMs?: number): MeshOperationId;
177
191
  joinActorSpotCanonical(actor: ZLinkBackendActorRef, targetNodeRid: unknown, targetSpotId: unknown, targetSpotGeneration: bigint, request: ServiceApplicationPayload, actorFence: {
178
192
  readonly targetNodeGeneration: bigint;
@@ -193,12 +207,14 @@ export interface ZLinkBackendMeshNode {
193
207
  }, timeoutMs?: number): MeshOperationId;
194
208
  sendToActor(actor: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
195
209
  flags?: number;
210
+ routeFence?: import('../../foundation/service-stateful-wire-codec').ServiceActorRouteFence;
196
211
  }): Promise<SubmitResult>;
197
212
  requestToActor(actor: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
198
213
  flags?: number;
199
214
  timeoutMs?: number;
200
215
  applicationMetadata?: Buffer;
201
216
  onAdmitted?: () => void;
217
+ routeFence?: import('../../foundation/service-stateful-wire-codec').ServiceActorRouteFence;
202
218
  }): MeshOperationId;
203
219
  actorSendToActor(source: ZLinkBackendActorRef, target: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
204
220
  flags?: number;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.meshActorSessionNodeAdapter = meshActorSessionNodeAdapter;
4
+ const framework_errors_internal_1 = require("../framework-errors-internal");
4
5
  const submission_result_1 = require("../messaging/submission-result");
5
6
  const mesh_completion_table_1 = require("./mesh-completion-table");
6
7
  function meshActorSessionNodeAdapter(node, completions) {
@@ -16,8 +17,7 @@ function meshActorSessionNodeAdapter(node, completions) {
16
17
  const completion = await completions.submit(() => node.closeActorBoundSession(actor, expectedBindingGeneration, timeoutMs), signal);
17
18
  try {
18
19
  if (completion.terminalResult !== 0 || completion.failureErrno !== 0) {
19
- throw new Error(`Actor '${actor.actorId}' bound-session close failed with result ` +
20
- `'${completion.terminalResult}' and errno '${completion.failureErrno}'.`);
20
+ throw (0, framework_errors_internal_1.wireReplyFailureException)(completion.terminalResult, completion.failureErrno, `Actor '${actor.actorId}' bound-session close failed.`);
21
21
  }
22
22
  }
23
23
  finally {
@@ -49,7 +49,12 @@ class ZLinkMeshCompletionTable {
49
49
  this.slots.push(slot);
50
50
  this.free = index;
51
51
  }
52
+ // New slots hold no identity yet. Only a larger bucket array needs the
53
+ // pending identities placed again; it doubles, so growth to N pending
54
+ // operations re-indexes O(N) slots in total.
52
55
  const minimumBuckets = this.slots.length * COMPLETION_HASH_BUCKETS_PER_SLOT;
56
+ if (minimumBuckets <= this.buckets.length)
57
+ return;
53
58
  this.buckets = new Int32Array(2 ** Math.ceil(Math.log2(minimumBuckets))).fill(-1);
54
59
  for (let index = 0; index < this.slots.length; index++) {
55
60
  const slot = this.slots[index];