@zlink-systems/framework 0.29.1 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/LICENSE +150 -68
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
  4. package/dist/contracts/Channels/Calls.d.ts +2 -1
  5. package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -2
  7. package/dist/contracts/Configuration/Configs.d.ts +0 -5
  8. package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
  9. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
  10. package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
  11. package/dist/contracts/Configuration/index.d.ts +1 -1
  12. package/dist/contracts/Handlers/Attributes.d.ts +5 -13
  13. package/dist/contracts/Handlers/Attributes.js +7 -11
  14. package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
  15. package/dist/contracts/Handlers/JsonContract.js +4 -153
  16. package/dist/contracts/Spots/Contracts.d.ts +2 -1
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/internal.js +3 -1
  19. package/dist/nest-integration.d.ts +1 -1
  20. package/dist/nest-integration.js +2 -1
  21. package/dist/runtime/actors/actor-client.d.ts +1 -1
  22. package/dist/runtime/actors/actor-client.js +14 -12
  23. package/dist/runtime/actors/actor-handoff.d.ts +3 -2
  24. package/dist/runtime/actors/actor-handoff.js +15 -7
  25. package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
  26. package/dist/runtime/actors/actor-local-native-join.js +9 -12
  27. package/dist/runtime/actors/actor-remote-wire.js +15 -0
  28. package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
  29. package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
  30. package/dist/runtime/actors/index.d.ts +2 -1
  31. package/dist/runtime/actors/index.js +18 -6
  32. package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
  33. package/dist/runtime/admission.d.ts +1 -1
  34. package/dist/runtime/admission.js +15 -5
  35. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
  36. package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
  37. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
  38. package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
  39. package/dist/runtime/application-jobs/contracts.d.ts +15 -2
  40. package/dist/runtime/backend/contracts/index.d.ts +27 -27
  41. package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
  42. package/dist/runtime/backend/mesh-completion-table.js +160 -50
  43. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
  44. package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
  45. package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
  46. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
  47. package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
  48. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  49. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
  50. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
  51. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
  52. package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
  53. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
  54. package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
  55. package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
  56. package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
  57. package/dist/runtime/backend/runtime-message.d.ts +1 -0
  58. package/dist/runtime/backend/runtime-message.js +5 -0
  59. package/dist/runtime/backend/runtime-values.d.ts +1 -0
  60. package/dist/runtime/backend/runtime-values.js +2 -1
  61. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  62. package/dist/runtime/channels/channel-clients.js +58 -21
  63. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
  64. package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
  65. package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
  66. package/dist/runtime/channels/channel-dispatch-services.js +45 -0
  67. package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
  68. package/dist/runtime/channels/channel-dispatchers.js +27 -26
  69. package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
  70. package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
  71. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  72. package/dist/runtime/channels/channel-envelope.js +83 -8
  73. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  74. package/dist/runtime/channels/channel-outbound-operations.js +8 -8
  75. package/dist/runtime/channels/channel-receive-loops.js +3 -3
  76. package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
  77. package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
  78. package/dist/runtime/channels/channel-runtime-manager.js +12 -12
  79. package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
  80. package/dist/runtime/channels/channel-socket-registry.js +59 -82
  81. package/dist/runtime/channels/channel-transports.d.ts +18 -15
  82. package/dist/runtime/channels/channel-transports.js +48 -31
  83. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  84. package/dist/runtime/channels/local-spot-route-transport.js +2 -1
  85. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
  86. package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
  87. package/dist/runtime/channels/source-spot-router.d.ts +2 -2
  88. package/dist/runtime/channels/source-spot-router.js +4 -4
  89. package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
  90. package/dist/runtime/channels/spot-node-route-transport.js +4 -4
  91. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
  92. package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
  93. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
  94. package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
  95. package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
  96. package/dist/runtime/diagnostics/message-flow.js +3 -3
  97. package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
  98. package/dist/runtime/execution/serial-execution-queue.js +1 -0
  99. package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
  100. package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
  101. package/dist/runtime/foundation/durable-service-request.js +98 -0
  102. package/dist/runtime/foundation/operation-identity.d.ts +1 -0
  103. package/dist/runtime/foundation/operation-identity.js +5 -1
  104. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
  105. package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
  106. package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
  107. package/dist/runtime/foundation/service-liveness-registry.js +57 -44
  108. package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
  109. package/dist/runtime/foundation/service-mailbox.js +2 -1
  110. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
  111. package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
  112. package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
  113. package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
  114. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
  115. package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
  116. package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
  117. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
  118. package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
  119. package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
  120. package/dist/runtime/foundation/service-topology-registry.js +69 -30
  121. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
  122. package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
  123. package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
  124. package/dist/runtime/handlers/handler-instance-scope.js +54 -11
  125. package/dist/runtime/host/actor-packet-relay.js +7 -7
  126. package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
  127. package/dist/runtime/host/application-job-queue.d.ts +28 -9
  128. package/dist/runtime/host/application-job-queue.js +214 -50
  129. package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
  130. package/dist/runtime/host/entry-actor-runtime.js +4 -1
  131. package/dist/runtime/host/index.d.ts +7 -1
  132. package/dist/runtime/host/index.js +154 -126
  133. package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
  134. package/dist/runtime/host/instance-activation-authority.js +89 -25
  135. package/dist/runtime/host/remote-bound-session-relay.js +2 -18
  136. package/dist/runtime/host/route-mesh-runtime.js +1 -1
  137. package/dist/runtime/host/service-relocation-control.d.ts +1 -0
  138. package/dist/runtime/host/service-relocation-control.js +10 -4
  139. package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
  140. package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
  141. package/dist/runtime/host/spot-address-transport.d.ts +1 -0
  142. package/dist/runtime/host/spot-address-transport.js +28 -14
  143. package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
  144. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
  145. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
  146. package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
  147. package/dist/runtime/locations/actor-location-claims.js +34 -19
  148. package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
  149. package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
  150. package/dist/runtime/locations/in-memory-authority-store.js +80 -8
  151. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  152. package/dist/runtime/locations/in-memory-location-store.js +19 -3
  153. package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
  154. package/dist/runtime/locations/lifecycle.d.ts +1 -2
  155. package/dist/runtime/locations/lifecycle.js +2 -5
  156. package/dist/runtime/locations/location-store-repository.d.ts +3 -2
  157. package/dist/runtime/locations/location-store-repository.js +165 -22
  158. package/dist/runtime/locations/resolvers.d.ts +2 -1
  159. package/dist/runtime/locations/resolvers.js +10 -1
  160. package/dist/runtime/locations/runtime.d.ts +1 -1
  161. package/dist/runtime/locations/runtime.js +24 -23
  162. package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
  163. package/dist/runtime/messaging/framework-json-v1.js +38 -294
  164. package/dist/runtime/messaging/packet-name.d.ts +1 -1
  165. package/dist/runtime/messaging/packet-name.js +8 -24
  166. package/dist/runtime/messaging/request-result.d.ts +2 -0
  167. package/dist/runtime/messaging/request-result.js +54 -0
  168. package/dist/runtime/messaging/submission-result.d.ts +2 -1
  169. package/dist/runtime/messaging/submission-result.js +7 -4
  170. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
  171. package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
  172. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
  173. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
  174. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
  175. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
  176. package/dist/runtime/spots/index.d.ts +7 -3
  177. package/dist/runtime/spots/index.js +23 -16
  178. package/dist/runtime/spots/spot-activation.d.ts +3 -1
  179. package/dist/runtime/spots/spot-activation.js +21 -12
  180. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
  181. package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
  182. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
  183. package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
  184. package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
  185. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
  186. package/dist/runtime/spots/spot-entry-activation.js +9 -3
  187. package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
  188. package/dist/runtime/spots/spot-handler-registry.js +18 -8
  189. package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
  190. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
  191. package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
  192. package/dist/runtime/spots/spot-outbound.d.ts +3 -0
  193. package/dist/runtime/spots/spot-outbound.js +24 -15
  194. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
  195. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
  196. package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
  197. package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
  198. package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
  199. package/dist/runtime/spots/spot-timer.js +1 -0
  200. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
  201. package/dist/runtime/streams/stream-session-runtime.js +14 -28
  202. package/package.json +3 -3
  203. package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
  204. package/src/contracts/Channels/Calls.ts +2 -1
  205. package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
  206. package/src/contracts/Configuration/Builders.ts +1 -2
  207. package/src/contracts/Configuration/Configs.ts +0 -6
  208. package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
  209. package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
  210. package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
  211. package/src/contracts/Configuration/index.ts +1 -6
  212. package/src/contracts/Handlers/Attributes.ts +14 -21
  213. package/src/contracts/Handlers/JsonContract.ts +8 -216
  214. package/src/contracts/Spots/Contracts.ts +2 -1
  215. package/src/internal.ts +1 -0
  216. package/src/nest-integration.ts +1 -0
  217. package/src/runtime/actors/actor-client.ts +40 -16
  218. package/src/runtime/actors/actor-handoff.ts +22 -8
  219. package/src/runtime/actors/actor-join-relocation.ts +1 -0
  220. package/src/runtime/actors/actor-local-native-join.ts +17 -26
  221. package/src/runtime/actors/actor-remote-wire.ts +17 -0
  222. package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
  223. package/src/runtime/actors/actor-routed-json-request.ts +10 -2
  224. package/src/runtime/actors/index.ts +19 -5
  225. package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
  226. package/src/runtime/admission.ts +18 -5
  227. package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
  228. package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
  229. package/src/runtime/application-jobs/contracts.ts +28 -2
  230. package/src/runtime/backend/contracts/index.ts +63 -32
  231. package/src/runtime/backend/mesh-completion-table.ts +175 -59
  232. package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
  233. package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
  234. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
  235. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
  236. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
  237. package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
  238. package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
  239. package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
  240. package/src/runtime/backend/raw-binding-port.ts +18 -3
  241. package/src/runtime/backend/runtime-message.ts +6 -0
  242. package/src/runtime/backend/runtime-values.ts +1 -0
  243. package/src/runtime/channels/channel-clients.ts +90 -41
  244. package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
  245. package/src/runtime/channels/channel-dispatch-services.ts +69 -1
  246. package/src/runtime/channels/channel-dispatchers.ts +29 -27
  247. package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
  248. package/src/runtime/channels/channel-envelope.ts +133 -8
  249. package/src/runtime/channels/channel-outbound-operations.ts +22 -8
  250. package/src/runtime/channels/channel-receive-loops.ts +3 -3
  251. package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
  252. package/src/runtime/channels/channel-runtime-manager.ts +29 -12
  253. package/src/runtime/channels/channel-socket-registry.ts +84 -130
  254. package/src/runtime/channels/channel-transports.ts +128 -60
  255. package/src/runtime/channels/local-spot-route-transport.ts +3 -1
  256. package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
  257. package/src/runtime/channels/source-spot-router.ts +8 -4
  258. package/src/runtime/channels/spot-node-route-transport.ts +8 -4
  259. package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
  260. package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
  261. package/src/runtime/diagnostics/message-flow.ts +1 -1
  262. package/src/runtime/execution/serial-execution-queue.ts +2 -0
  263. package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
  264. package/src/runtime/foundation/durable-service-request.ts +137 -0
  265. package/src/runtime/foundation/operation-identity.ts +5 -1
  266. package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
  267. package/src/runtime/foundation/service-liveness-registry.ts +68 -59
  268. package/src/runtime/foundation/service-mailbox.ts +7 -1
  269. package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
  270. package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
  271. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  272. package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
  274. package/src/runtime/foundation/service-topology-registry.ts +103 -42
  275. package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
  276. package/src/runtime/handlers/handler-instance-scope.ts +67 -16
  277. package/src/runtime/host/actor-packet-relay.ts +7 -0
  278. package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
  279. package/src/runtime/host/application-job-queue.ts +249 -48
  280. package/src/runtime/host/entry-actor-runtime.ts +5 -0
  281. package/src/runtime/host/index.ts +224 -160
  282. package/src/runtime/host/instance-activation-authority.ts +132 -27
  283. package/src/runtime/host/remote-bound-session-relay.ts +2 -23
  284. package/src/runtime/host/route-mesh-runtime.ts +1 -1
  285. package/src/runtime/host/service-relocation-control.ts +11 -5
  286. package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
  287. package/src/runtime/host/spot-address-transport.ts +49 -24
  288. package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
  290. package/src/runtime/locations/actor-location-claims.ts +52 -30
  291. package/src/runtime/locations/domain-store-contract.ts +6 -2
  292. package/src/runtime/locations/in-memory-authority-store.ts +113 -9
  293. package/src/runtime/locations/in-memory-location-store.ts +25 -3
  294. package/src/runtime/locations/internal-location-contracts.ts +4 -0
  295. package/src/runtime/locations/lifecycle.ts +8 -26
  296. package/src/runtime/locations/location-store-repository.ts +220 -15
  297. package/src/runtime/locations/resolvers.ts +25 -2
  298. package/src/runtime/locations/runtime.ts +28 -24
  299. package/src/runtime/messaging/framework-json-v1.ts +5 -325
  300. package/src/runtime/messaging/packet-name.ts +5 -25
  301. package/src/runtime/messaging/request-result.ts +58 -0
  302. package/src/runtime/messaging/submission-result.ts +7 -3
  303. package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
  304. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  305. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
  306. package/src/runtime/spots/index.ts +30 -2
  307. package/src/runtime/spots/spot-activation.ts +33 -10
  308. package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
  309. package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
  310. package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
  311. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
  312. package/src/runtime/spots/spot-entry-activation.ts +12 -2
  313. package/src/runtime/spots/spot-handler-registry.ts +41 -8
  314. package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
  315. package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
  316. package/src/runtime/spots/spot-outbound.ts +36 -16
  317. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
  318. package/src/runtime/spots/spot-routing-internal.ts +14 -0
  319. package/src/runtime/spots/spot-runtime-ports.ts +3 -0
  320. package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
  321. package/src/runtime/spots/spot-timer.ts +5 -1
  322. package/src/runtime/streams/stream-session-runtime.ts +13 -30
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkLocationStoreRepository = void 0;
4
4
  const service_relocation_runtime_1 = require("../foundation/service-relocation-runtime");
5
+ const service_authority_payload_codec_1 = require("../foundation/service-authority-payload-codec");
6
+ const actor_authority_payload_codec_1 = require("../actors/actor-authority-payload-codec");
7
+ const contracts_1 = require("../../contracts");
5
8
  const stream_wire_1 = require("@zlink-systems/stream-wire");
6
9
  const node_crypto_1 = require("node:crypto");
7
10
  const Options_1 = require("../../contracts/Locations/Options");
8
- const contracts_1 = require("../../contracts");
11
+ const contracts_2 = require("../../contracts");
9
12
  const CoreTypes_1 = require("../../contracts/Common/CoreTypes");
10
13
  const InternalDefaults_1 = require("../../contracts/Configuration/InternalDefaults");
11
14
  const RegistrationBuilderPolicy_1 = require("../../contracts/Configuration/RegistrationBuilderPolicy");
@@ -215,9 +218,27 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
215
218
  payload: Buffer.from(mutation.payload)
216
219
  }
217
220
  };
221
+ const actor = mutation.kind !== 'delete' && record.snapshot.allocation.objectKind === 'actor'
222
+ ? (0, actor_authority_payload_codec_1.decodeActorAuthorityPayload)((0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(mutation.payload))
223
+ : undefined;
224
+ const previousActor = actor === undefined
225
+ ? undefined
226
+ : (0, actor_authority_payload_codec_1.decodeActorAuthorityPayload)((0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(record.snapshot.payload));
227
+ const membershipConditions = actor?.currentSpotKind === contracts_1.ZLinkSpotKind.User &&
228
+ (previousActor?.currentSpotKind !== contracts_1.ZLinkSpotKind.User ||
229
+ previousActor.currentSpotId !== actor.currentSpotId ||
230
+ previousActor.currentSpotGeneration !== actor.currentSpotGeneration)
231
+ ? await this.userSpotMembershipConditions(actor.currentSpotId, actor.currentSpotGeneration, signal, {
232
+ ownerId: record.snapshot.ownerId,
233
+ leaseGeneration: record.snapshot.ownerLeaseGeneration
234
+ })
235
+ : [];
236
+ if (membershipConditions === undefined)
237
+ return { kind: 'conflict', current: snapshot };
218
238
  const result = await this.provider.write({
219
239
  conditions: [
220
240
  { kind: 'version', key: rowKey, expected: current.value.version },
241
+ ...membershipConditions,
221
242
  ...(mutation.kind === 'restore'
222
243
  ? []
223
244
  : [
@@ -654,7 +675,7 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
654
675
  sha256Hex(membership) !== entry.membershipMutationSha256) {
655
676
  throw new Error('Aggregate participant staging checksum does not match inventory.');
656
677
  }
657
- authorityRows.push({ key: rowKeyForParticipant, current, record, entry });
678
+ authorityRows.push({ key: rowKeyForParticipant, current, record, entry, payload });
658
679
  }
659
680
  const targetDescriptorKey = meshKey(aggregate.targetDescriptor.meshName, aggregate.targetDescriptor.rid);
660
681
  const targetLeaseKey = ownerKey(aggregate.targetOwner.ownerId);
@@ -717,11 +738,34 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
717
738
  bytes: encodeJson(capacity)
718
739
  });
719
740
  }
741
+ const membershipConditions = [];
742
+ for (const row of authorityRows) {
743
+ if (row.record.snapshot.allocation.objectKind !== 'actor')
744
+ continue;
745
+ const actor = (0, actor_authority_payload_codec_1.decodeActorAuthorityPayload)((0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(row.payload));
746
+ if (actor?.currentSpotKind !== contracts_1.ZLinkSpotKind.User)
747
+ continue;
748
+ const spotKey = (0, authority_key_codec_1.encodeAuthorityKey)('user_spot', actor.currentSpotId);
749
+ const participantSpot = authorityRows.find((candidate) => candidate.entry.authorityKey === spotKey.value);
750
+ if (participantSpot !== undefined) {
751
+ if (participantSpot.record.snapshot.allocation.objectKind !== 'user_spot' ||
752
+ participantSpot.record.snapshot.objectGeneration !== actor.currentSpotGeneration)
753
+ return { kind: 'stale' };
754
+ continue;
755
+ }
756
+ if (membershipConditions.some((condition) => condition.key.value === authorityKey(spotKey.value).value))
757
+ continue;
758
+ const conditions = await this.userSpotMembershipConditions(actor.currentSpotId, actor.currentSpotGeneration, signal, aggregate.targetOwner);
759
+ if (conditions === undefined)
760
+ return { kind: 'stale' };
761
+ membershipConditions.push(...conditions.filter((condition) => !membershipConditions.some((existing) => existing.key.value === condition.key.value)));
762
+ }
720
763
  const published = await this.provider.write({
721
764
  conditions: [
722
765
  { kind: 'version', key: rowKey, expected: aggregateRead.value.version },
723
766
  versionCondition(targetDescriptorKey, descriptorRead),
724
767
  leaseValueCondition(targetLeaseKey, aggregate.targetOwner),
768
+ ...membershipConditions,
725
769
  ...[...capacityReads.entries()].map(([value, read]) => ({
726
770
  kind: 'version',
727
771
  key: capacityKeys.get(value),
@@ -814,8 +858,9 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
814
858
  return { kind: 'aborted' };
815
859
  }
816
860
  }
817
- async releaseEndedReservation(key, expectedStoreVersion, signal) {
818
- return ((await this.tryReleaseEndedReservation(key, expectedStoreVersion, signal)) === 'reclaimed');
861
+ async releaseEndedReservation(key, expectedStoreVersion, signal, request) {
862
+ return ((await this.tryReleaseEndedReservation(key, expectedStoreVersion, signal, request)) ===
863
+ 'reclaimed');
819
864
  }
820
865
  async tryReleaseEndedReservation(key, expectedStoreVersion, signal, request) {
821
866
  const rowKey = authorityKey(key.value);
@@ -824,11 +869,9 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
824
869
  return 'conflict';
825
870
  const record = decodeAuthorityRecord(current.value.bytes);
826
871
  const snapshot = record.snapshot;
827
- if ((snapshot.allocation.state === 'active'
828
- ? request?.key.kind !== 'actor'
829
- : snapshot.pendingCreation === undefined) ||
830
- record.aggregate !== undefined ||
831
- hasRelocationAuthority(snapshot.payload))
872
+ if (snapshot.allocation.state === 'active'
873
+ ? request === undefined
874
+ : snapshot.pendingCreation === undefined)
832
875
  return 'notReclaimable';
833
876
  const leaseKey = ownerKey(snapshot.ownerId);
834
877
  const descriptorKey = meshKey(snapshot.allocation.descriptor.meshName, snapshot.allocation.descriptor.rid);
@@ -844,13 +887,62 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
844
887
  if (snapshot.allocation.state === 'active') {
845
888
  if (ownerLive)
846
889
  return 'notReclaimable';
847
- if (request?.actorRelocationPolicy !== 'disabled')
848
- throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.Unavailable, 'Actor owner lease is unavailable.');
890
+ let unavailable = record.aggregate !== undefined || hasRelocationAuthority(snapshot.payload);
891
+ if (snapshot.allocation.objectKind !== 'actor') {
892
+ const spot = (0, service_authority_payload_codec_1.decodeServiceReadySpotAuthority)(snapshot.payload);
893
+ unavailable ||=
894
+ spot === undefined ||
895
+ spot.kind !== request?.key.kind ||
896
+ spot.stableType !== request.intent.stableType ||
897
+ spot.spotId !== request.key.globalId ||
898
+ spot.activationRecovery !== undefined;
899
+ if (spot?.kind === 'user_spot') {
900
+ // The snapshot starts only after the old owner's lease was found invalid.
901
+ for (const prefix of [`${PREFIX}actor:`, `${AUTHORITY_PREIMAGE_PREFIX}actor\0`]) {
902
+ membershipSnapshot: for (;;) {
903
+ let snapshotHasMember = false;
904
+ let cursor;
905
+ do {
906
+ const page = await this.provider.scan({ prefix, cursor, limit: Stores_1.ZLINK_PROVIDER_MAX_PAGE_SIZE }, signal);
907
+ if (page.kind === 'expired')
908
+ continue membershipSnapshot;
909
+ for (const item of page.value.items) {
910
+ if (prefix === `${PREFIX}actor:`) {
911
+ const actor = normalizeActor(decodeJson(item.value.bytes).descriptor);
912
+ snapshotHasMember ||=
913
+ actor.spotKind === contracts_1.ZLinkSpotKind.User &&
914
+ String(actor.spotId) === spot.spotId &&
915
+ actor.spotGeneration === snapshot.objectGeneration;
916
+ }
917
+ else {
918
+ const authority = decodeAuthorityRecord(item.value.bytes).snapshot;
919
+ if (authority.allocation.objectKind !== 'actor')
920
+ continue;
921
+ const actor = (0, actor_authority_payload_codec_1.decodeActorAuthorityPayload)((0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(authority.payload));
922
+ snapshotHasMember ||=
923
+ actor?.currentSpotKind === contracts_1.ZLinkSpotKind.User &&
924
+ actor.currentSpotId === spot.spotId &&
925
+ actor.currentSpotGeneration === snapshot.objectGeneration;
926
+ }
927
+ }
928
+ cursor = page.value.nextCursor;
929
+ } while (cursor !== undefined);
930
+ unavailable ||= snapshotHasMember;
931
+ break;
932
+ }
933
+ }
934
+ }
935
+ }
936
+ if (unavailable || request?.actorRelocationPolicy !== 'disabled')
937
+ throw new contracts_2.ZLinkFrameworkException(contracts_2.ZLinkFrameworkErrorKind.Unavailable, 'Object owner lease is unavailable.');
849
938
  }
850
939
  else if (ownerLive &&
851
940
  descriptor.kind === 'found' &&
852
941
  reviveMeshDescriptor(decodeCanonicalDescriptorRecord(descriptor.value.bytes).descriptor).lifecycleGeneration === snapshot.allocation.descriptorLifecycleGeneration)
853
942
  return 'notReclaimable';
943
+ if (snapshot.allocation.state !== 'active' &&
944
+ (record.aggregate !== undefined || hasRelocationAuthority(snapshot.payload)))
945
+ return 'notReclaimable';
854
946
  const mutations = [
855
947
  { kind: 'delete', key: rowKey }
856
948
  ];
@@ -871,8 +963,8 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
871
963
  });
872
964
  }
873
965
  catch (error) {
874
- if (!(error instanceof contracts_1.ZLinkFrameworkException) ||
875
- error.kind !== contracts_1.ZLinkFrameworkErrorKind.DataLost)
966
+ if (!(error instanceof contracts_2.ZLinkFrameworkException) ||
967
+ error.kind !== contracts_2.ZLinkFrameworkErrorKind.DataLost)
876
968
  throw error;
877
969
  const observed = await this.provider.read(rowKey, signal);
878
970
  if (observed.kind === 'missing' ||
@@ -927,7 +1019,7 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
927
1019
  this.provider.read(leaseKey, signal)
928
1020
  ]);
929
1021
  const descriptor = liveTargetDescriptor(descriptorRead, leaseRead, request.target);
930
- if (descriptor === undefined || descriptor.state !== contracts_1.ZLinkFrameworkRuntimeState.Serving) {
1022
+ if (descriptor === undefined || descriptor.state !== contracts_2.ZLinkFrameworkRuntimeState.Serving) {
931
1023
  return { kind: 'conflict', current: { kind: 'missing', storeNow: current.storeNow } };
932
1024
  }
933
1025
  const [capacityRead, objectGenerationRead, authorityOwnerGenerationRead] = await Promise.all([
@@ -1204,6 +1296,14 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
1204
1296
  if (retentionMs <= 0) {
1205
1297
  throw new RangeError('Creation terminal expiry must be the live operation deadline plus five minutes.');
1206
1298
  }
1299
+ const actor = request.completion.kind === 'created'
1300
+ ? (0, actor_authority_payload_codec_1.decodeActorAuthorityPayload)((0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(request.completion.readyPayload))
1301
+ : undefined;
1302
+ const membershipConditions = actor?.currentSpotKind === contracts_1.ZLinkSpotKind.User
1303
+ ? await this.userSpotMembershipConditions(actor.currentSpotId, actor.currentSpotGeneration, signal, request.target.owner)
1304
+ : [];
1305
+ if (membershipConditions === undefined)
1306
+ return { kind: 'stale' };
1207
1307
  const mutations = request.completion.kind === 'created'
1208
1308
  ? [
1209
1309
  {
@@ -1243,6 +1343,7 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
1243
1343
  conditions: [
1244
1344
  { kind: 'version', key: rowKey, expected: current.value.version },
1245
1345
  { kind: 'missing', key: terminalRowKey },
1346
+ ...membershipConditions,
1246
1347
  versionCondition(descriptorKey, descriptorRead),
1247
1348
  leaseValueCondition(leaseKey, request.target.owner),
1248
1349
  conditionFor(capacityRowKey, capacityRead)
@@ -1505,7 +1606,7 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
1505
1606
  return this.listOwnedLocations(`${PREFIX}spot:`, page, normalizeSpot, (value) => matchesSpot(value, filter), signal);
1506
1607
  }
1507
1608
  async updateActor(location, intent, signal) {
1508
- return this.updateOwnedLocation(actorKey(location.meshName, location.actorId), normalizeActor(location), intent, signal);
1609
+ return this.updateOwnedLocation(actorKey(location.meshName, location.actorId), normalizeActor(location), intent, signal, location);
1509
1610
  }
1510
1611
  async removeActor(key, owner, signal) {
1511
1612
  return this.removeOwnedLocation(actorKey(key.meshName, key.actorId), owner, signal);
@@ -1874,7 +1975,37 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
1874
1975
  continuationToken: result.value.nextCursor?.value
1875
1976
  };
1876
1977
  }
1877
- async updateOwnedLocation(rowKey, location, intent, signal) {
1978
+ async userSpotMembershipConditions(spotId, objectGeneration, signal, conditionedOwner) {
1979
+ const key = authorityKey((0, authority_key_codec_1.encodeAuthorityKey)('user_spot', spotId).value);
1980
+ const read = await this.provider.read(key, signal);
1981
+ if (read.kind === 'missing')
1982
+ return undefined;
1983
+ const record = decodeAuthorityRecord(read.value.bytes);
1984
+ const snapshot = record.snapshot;
1985
+ if (record.aggregate !== undefined ||
1986
+ snapshot.allocation.objectKind !== 'user_spot' ||
1987
+ snapshot.allocation.state !== 'active' ||
1988
+ snapshot.objectGeneration !== objectGeneration ||
1989
+ (0, service_authority_payload_codec_1.decodeServiceReadySpotAuthority)(snapshot.payload)?.kind !== 'user_spot')
1990
+ return undefined;
1991
+ const leaseKey = ownerKey(snapshot.ownerId);
1992
+ const lease = await this.provider.read(leaseKey, signal);
1993
+ if (!sameLiveOwner(lease, snapshot))
1994
+ return undefined;
1995
+ return [
1996
+ { kind: 'version', key, expected: read.value.version },
1997
+ ...(conditionedOwner?.ownerId === snapshot.ownerId &&
1998
+ conditionedOwner.leaseGeneration === snapshot.ownerLeaseGeneration
1999
+ ? []
2000
+ : [
2001
+ leaseValueCondition(leaseKey, {
2002
+ ownerId: snapshot.ownerId,
2003
+ leaseGeneration: snapshot.ownerLeaseGeneration
2004
+ })
2005
+ ])
2006
+ ];
2007
+ }
2008
+ async updateOwnedLocation(rowKey, location, intent, signal, membership) {
1878
2009
  const leaseKey = ownerKey(location.ownerId);
1879
2010
  const [lease, current] = await Promise.all([
1880
2011
  this.provider.read(leaseKey, signal),
@@ -1919,13 +2050,25 @@ class ZLinkLocationStoreRepository extends in_memory_location_store_1.ZLinkInMem
1919
2050
  else if (intent === 2) {
1920
2051
  return rejected(lease.value.storeNow);
1921
2052
  }
2053
+ const previousMembership = current.kind === 'found' && membership !== undefined
2054
+ ? decodeJson(current.value.bytes).descriptor
2055
+ : undefined;
2056
+ const membershipConditions = membership?.spotKind === contracts_1.ZLinkSpotKind.User &&
2057
+ (previousMembership?.spotKind !== contracts_1.ZLinkSpotKind.User ||
2058
+ String(previousMembership.spotId) !== String(membership.spotId) ||
2059
+ BigInt(previousMembership.spotGeneration) !== membership.spotGeneration)
2060
+ ? await this.userSpotMembershipConditions(String(membership.spotId), membership.spotGeneration, signal, { ownerId: location.ownerId, leaseGeneration: locationOwnerGeneration(location) })
2061
+ : [];
2062
+ if (membershipConditions === undefined)
2063
+ return rejected(lease.value.storeNow);
1922
2064
  const result = await this.provider.write({
1923
2065
  conditions: [
1924
2066
  leaseValueCondition(leaseKey, {
1925
2067
  ownerId: location.ownerId,
1926
2068
  leaseGeneration: locationOwnerGeneration(location)
1927
2069
  }),
1928
- rowCondition
2070
+ rowCondition,
2071
+ ...membershipConditions
1929
2072
  ],
1930
2073
  mutations: [
1931
2074
  {
@@ -2913,7 +3056,7 @@ function liveTargetDescriptor(descriptorRead, leaseRead, target) {
2913
3056
  descriptor.lifecycleGeneration === target.nodeLifecycleGeneration &&
2914
3057
  descriptor.ownerId === target.owner.ownerId &&
2915
3058
  descriptor.leaseGeneration === target.owner.leaseGeneration &&
2916
- descriptor.objectRole === contracts_1.ZLinkObjectRole.Server &&
3059
+ descriptor.objectRole === contracts_2.ZLinkObjectRole.Server &&
2917
3060
  lease.ownerId === target.owner.ownerId &&
2918
3061
  BigInt(lease.leaseGeneration) === target.owner.leaseGeneration &&
2919
3062
  leaseRead.value.expiresAt !== undefined &&
@@ -2974,7 +3117,7 @@ function adjustCapacity(usage, delta, direction) {
2974
3117
  const key = capacityTypeKey(delta.spotType);
2975
3118
  const next = (spotTypes[key] ?? 0) + direction * delta.spotType.count;
2976
3119
  if (next < 0)
2977
- throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.DataLost, 'Provider capacity counter underflow.');
3120
+ throw new contracts_2.ZLinkFrameworkException(contracts_2.ZLinkFrameworkErrorKind.DataLost, 'Provider capacity counter underflow.');
2978
3121
  if (next === 0)
2979
3122
  delete spotTypes[key];
2980
3123
  else
@@ -2983,7 +3126,7 @@ function adjustCapacity(usage, delta, direction) {
2983
3126
  const actors = usage.actors + direction * delta.actors;
2984
3127
  const spots = usage.spots + direction * delta.spots;
2985
3128
  if (actors < 0 || spots < 0)
2986
- throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.DataLost, 'Provider capacity counter underflow.');
3129
+ throw new contracts_2.ZLinkFrameworkException(contracts_2.ZLinkFrameworkErrorKind.DataLost, 'Provider capacity counter underflow.');
2987
3130
  return { actors, spots, spotTypes };
2988
3131
  }
2989
3132
  function capacityTypeKey(value) {
@@ -3308,10 +3451,10 @@ function throwIfOperationExpired(signal, deadlineUnixMs) {
3308
3451
  }
3309
3452
  // Store SPI §6: preserve caller failures and classify provider failures once.
3310
3453
  function locationStoreProviderFailure(error, signal) {
3311
- if (error instanceof contracts_1.ZLinkFrameworkException ||
3454
+ if (error instanceof contracts_2.ZLinkFrameworkException ||
3312
3455
  error instanceof TypeError ||
3313
3456
  error instanceof RangeError ||
3314
3457
  signal?.aborted === true)
3315
3458
  return error;
3316
- return new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.Unavailable, 'Location Store provider is unavailable.', error);
3459
+ return new contracts_2.ZLinkFrameworkException(contracts_2.ZLinkFrameworkErrorKind.Unavailable, 'Location Store provider is unavailable.', error);
3317
3460
  }
@@ -1,6 +1,6 @@
1
1
  import type { ActorRef, RoutingId, SpotId } from '../../contracts/Common';
2
2
  import { type SpotHandle, type ZLinkActorSpotHandleResolver, type ZLinkSpotHandleResolver, type ResolvedSpotHandle } from '../spots/spot-handle';
3
- import type { ZLinkSpotRouteResolver, ZLinkSpotRouteTarget } from '../spots/spot-routing-internal';
3
+ import type { ZLinkSpotRouteResolver, ZLinkSpotRouteTarget, ZLinkInstanceReactivationRoute } from '../spots/spot-routing-internal';
4
4
  import { ZLinkFrameworkRuntimeState, ZLinkLocationRole, type ZLinkActorLocation, type ZLinkActorLocationKey, type ZLinkLocationReadiness, type ZLinkLocationRuntimeQuery, type ZLinkPeerLocation, type ZLinkPeerLocationFilter, type ZLinkPeerLocationResolver, type ZLinkRouteLocation, type ZLinkRouteLocationKey, type ZLinkSpotLocation, type ZLinkSpotLocationKey } from './internal-location-contracts';
5
5
  import type { ZLinkActorLocationStore, ZLinkAuthorityStore, ZLinkMeshNodeLocationStore, ZLinkPeerLocationStore, ZLinkRouteLocationStore, ZLinkSpotLocationStore } from './internal-store-contracts';
6
6
  import { ZLinkOwnerLeaseTracker } from './lease-tracker';
@@ -135,6 +135,7 @@ export declare class ZLinkAuthoritySpotRouteResolver implements ZLinkSpotRouteRe
135
135
  private readonly routeEpochs;
136
136
  private readonly activeResolutions;
137
137
  constructor(store: ZLinkAuthorityStore, routerChannelIdForMesh: (meshName: string) => string, fallback?: ZLinkSpotRouteResolver | undefined, leaseTracker?: ZLinkOwnerLeaseTracker | undefined, routeCacheMaxAgeMs?: number, monotonicNowMs?: () => number, targetNodeStateResolver?: ((meshName: string, nodeRid: RoutingId, expectedLifecycleGeneration: bigint, signal?: AbortSignal) => Promise<ZLinkFrameworkRuntimeState | undefined>) | undefined);
138
+ resolve(spotId: RoutingId, signal: AbortSignal | undefined, instanceIntent: true): Promise<ZLinkSpotRouteTarget | ZLinkInstanceReactivationRoute>;
138
139
  resolve(spotId: RoutingId, signal?: AbortSignal): Promise<ZLinkSpotRouteTarget>;
139
140
  invalidate(spotId: RoutingId): void;
140
141
  private invalidateCore;
@@ -583,7 +583,7 @@ class ZLinkAuthoritySpotRouteResolver {
583
583
  this.monotonicNowMs = monotonicNowMs;
584
584
  this.targetNodeStateResolver = targetNodeStateResolver;
585
585
  }
586
- async resolve(spotId, signal) {
586
+ async resolve(spotId, signal, instanceIntent) {
587
587
  const key = String(spotId);
588
588
  const prepared = await this.lane.run(() => this.beginResolutionCore(key));
589
589
  try {
@@ -606,6 +606,15 @@ class ZLinkAuthoritySpotRouteResolver {
606
606
  leaseGeneration: current.ownerLeaseGeneration
607
607
  }, signal);
608
608
  if (remainingLeaseMs !== undefined && remainingLeaseMs <= 0) {
609
+ if (instanceIntent === true && ready?.kind === 'instance_spot') {
610
+ return {
611
+ kind: 'coldActivation',
612
+ spotId,
613
+ spotKind: Spots_1.ZLinkSpotKind.Instance,
614
+ meshName: ready.ownerMeshName,
615
+ stableType: ready.stableType
616
+ };
617
+ }
609
618
  throw new Errors_1.ZLinkFrameworkException(Errors_1.ZLinkFrameworkErrorKind.Unavailable, `SPOT '${spotId}' Ready authority owner lease is unavailable.`);
610
619
  }
611
620
  const target = {
@@ -83,7 +83,7 @@ export declare class ZLinkLocationRuntime implements ZLinkLocationRuntimeQuery {
83
83
  private readonly meshNames;
84
84
  private readonly leaseScopes;
85
85
  private readonly rewriteAuthorityPayloadForOwner?;
86
- private nextLeaseRenewAtMs?;
86
+ private leaseOperationStartedAtMs;
87
87
  private ownerToken?;
88
88
  private lastOwnerToken?;
89
89
  private ownerLeaseDeadlineMs?;
@@ -52,7 +52,7 @@ class ZLinkLocationRuntime {
52
52
  meshNames;
53
53
  leaseScopes;
54
54
  rewriteAuthorityPayloadForOwner;
55
- nextLeaseRenewAtMs;
55
+ leaseOperationStartedAtMs = 0;
56
56
  ownerToken;
57
57
  lastOwnerToken;
58
58
  ownerLeaseDeadlineMs;
@@ -191,12 +191,7 @@ class ZLinkLocationRuntime {
191
191
  const claim = this.renewOwnerLeaseOnce(signal, shutdownSignal);
192
192
  this.heartbeatRenewal = claim;
193
193
  try {
194
- const claimed = await claim;
195
- if (claimed) {
196
- this.scheduleHeartbeat();
197
- return;
198
- }
199
- this.nextLeaseRenewAtMs = this.monotonicNowMs() + this.options.ownerLeaseRenewIntervalMs;
194
+ await claim;
200
195
  this.scheduleHeartbeat();
201
196
  }
202
197
  catch (error) {
@@ -211,7 +206,7 @@ class ZLinkLocationRuntime {
211
206
  this.clearTimer(this.heartbeatTimer);
212
207
  this.heartbeatTimer = undefined;
213
208
  }
214
- this.nextLeaseRenewAtMs = undefined;
209
+ this.leaseOperationStartedAtMs = 0;
215
210
  this.ownerLeaseDeadlineMs = undefined;
216
211
  await this.cleanupOwner(signal);
217
212
  }
@@ -263,6 +258,7 @@ class ZLinkLocationRuntime {
263
258
  const wasOwnerLeaseUsable = this.ownerLeaseUsable;
264
259
  try {
265
260
  const renewStartedAtMs = this.monotonicNowMs();
261
+ this.leaseOperationStartedAtMs = renewStartedAtMs;
266
262
  const result = await withTimeout((renewSignal) => this.stores.ownerLeaseStore.renewOwnerLease(this.ownerToken, this.options.ownerLeaseTtlMs, renewSignal), this.options.ownerLeaseRenewTimeoutMs, signal);
267
263
  const renewCompletedAtMs = this.monotonicNowMs();
268
264
  if (result.kind !== 'renewed') {
@@ -303,10 +299,11 @@ class ZLinkLocationRuntime {
303
299
  }
304
300
  async claimFreshOwnerLease(signal, shutdownSignal) {
305
301
  const claimStartedAtMs = this.monotonicNowMs();
306
- const timeoutDeadline = performance.now() + this.options.ownerLeaseRenewTimeoutMs;
302
+ this.leaseOperationStartedAtMs = claimStartedAtMs;
303
+ const timeoutStartedAtMs = performance.now();
307
304
  let claim;
308
305
  try {
309
- claim = await this.claimOwnerLeaseWithConfirmation(timeoutDeadline, signal, shutdownSignal);
306
+ claim = await this.claimOwnerLeaseWithConfirmation(timeoutStartedAtMs, signal, shutdownSignal);
310
307
  }
311
308
  catch (error) {
312
309
  if (signal?.aborted === true)
@@ -334,7 +331,6 @@ class ZLinkLocationRuntime {
334
331
  this.ownerLeaseRenewedAt = claim.storeNow;
335
332
  this.setOwnerLeaseDeadline(claimStartedAtMs, claimCompletedAtMs, claim.leaseExpiresAt, claim.storeNow);
336
333
  this.lastError = undefined;
337
- this.nextLeaseRenewAtMs = this.monotonicNowMs() + this.options.ownerLeaseRenewIntervalMs;
338
334
  for (const handler of this.ownerLeaseRenewedHandlers) {
339
335
  handler({
340
336
  kind: 'renewed',
@@ -351,12 +347,12 @@ class ZLinkLocationRuntime {
351
347
  return false;
352
348
  }
353
349
  }
354
- async claimOwnerLeaseWithConfirmation(timeoutDeadline, signal, shutdownSignal) {
350
+ async claimOwnerLeaseWithConfirmation(timeoutStartedAtMs, signal, shutdownSignal) {
355
351
  signal?.throwIfAborted();
356
352
  let claim;
357
353
  let request;
358
354
  try {
359
- claim = await withTimeout((claimSignal) => (request = this.stores.ownerLeaseStore.claimOwnerLease(this.ownerId, this.options.ownerLeaseTtlMs, claimSignal)), remainingTimeoutMs(timeoutDeadline), signal);
355
+ claim = await withTimeout((claimSignal) => (request = this.stores.ownerLeaseStore.claimOwnerLease(this.ownerId, this.options.ownerLeaseTtlMs, claimSignal)), remainingTimeoutMs(timeoutStartedAtMs, this.options.ownerLeaseRenewTimeoutMs), signal);
360
356
  }
361
357
  catch (error) {
362
358
  if (error instanceof OwnerLeaseRenewTimeoutError)
@@ -364,7 +360,9 @@ class ZLinkLocationRuntime {
364
360
  if (signal?.aborted === true && request !== undefined) {
365
361
  const cleanupSignal = shutdownSignal?.();
366
362
  try {
367
- await withTimeout(() => request, cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined, cleanupSignal);
363
+ await withTimeout(() => request, cleanupSignal === undefined
364
+ ? remainingTimeoutMs(timeoutStartedAtMs, this.options.ownerLeaseRenewTimeoutMs)
365
+ : undefined, cleanupSignal);
368
366
  }
369
367
  catch (completionError) {
370
368
  if (cleanupSignal?.aborted === true ||
@@ -376,7 +374,7 @@ class ZLinkLocationRuntime {
376
374
  }
377
375
  }
378
376
  }
379
- const confirmed = await this.confirmOwnerLease(error, timeoutDeadline, signal, shutdownSignal);
377
+ const confirmed = await this.confirmOwnerLease(error, timeoutStartedAtMs, signal, shutdownSignal);
380
378
  if (confirmed !== undefined)
381
379
  return confirmed;
382
380
  throw error;
@@ -384,12 +382,14 @@ class ZLinkLocationRuntime {
384
382
  if (claim.kind !== 'conflict')
385
383
  return claim;
386
384
  const conflict = new ZLinkOwnerLeaseClaimError(claim.kind);
387
- return ((await this.confirmOwnerLease(conflict, timeoutDeadline, signal, shutdownSignal)) ?? claim);
385
+ return ((await this.confirmOwnerLease(conflict, timeoutStartedAtMs, signal, shutdownSignal)) ?? claim);
388
386
  }
389
- async confirmOwnerLease(originalError, timeoutDeadline, signal, shutdownSignal) {
387
+ async confirmOwnerLease(originalError, timeoutStartedAtMs, signal, shutdownSignal) {
390
388
  const cancelled = signal?.aborted === true;
391
389
  const cleanupSignal = cancelled ? shutdownSignal?.() : undefined;
392
- const confirmationTimeoutMs = cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined;
390
+ const confirmationTimeoutMs = cleanupSignal === undefined
391
+ ? remainingTimeoutMs(timeoutStartedAtMs, this.options.ownerLeaseRenewTimeoutMs)
392
+ : undefined;
393
393
  if (confirmationTimeoutMs !== undefined && confirmationTimeoutMs <= 0)
394
394
  throw originalError;
395
395
  let confirmed;
@@ -407,7 +407,9 @@ class ZLinkLocationRuntime {
407
407
  }
408
408
  if (signal?.aborted === true) {
409
409
  try {
410
- await withTimeout((releaseSignal) => this.stores.ownerLeaseStore.releaseOwnerLease(confirmed.token, releaseSignal), cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined, cleanupSignal);
410
+ await withTimeout((releaseSignal) => this.stores.ownerLeaseStore.releaseOwnerLease(confirmed.token, releaseSignal), cleanupSignal === undefined
411
+ ? remainingTimeoutMs(timeoutStartedAtMs, this.options.ownerLeaseRenewTimeoutMs)
412
+ : undefined, cleanupSignal);
411
413
  }
412
414
  catch (releaseError) {
413
415
  this.recordFailure(errorMessage(releaseError), 'owner_lease_release');
@@ -778,7 +780,7 @@ class ZLinkLocationRuntime {
778
780
  if (!this.started) {
779
781
  return;
780
782
  }
781
- const scheduledAt = this.nextLeaseRenewAtMs ?? this.monotonicNowMs() + this.options.ownerLeaseRenewIntervalMs;
783
+ const scheduledAt = this.leaseOperationStartedAtMs + this.options.ownerLeaseRenewIntervalMs;
782
784
  const delayMs = Math.max(0, scheduledAt - this.monotonicNowMs());
783
785
  this.heartbeatTimer = this.setTimer(() => {
784
786
  this.heartbeatTimer = undefined;
@@ -786,7 +788,6 @@ class ZLinkLocationRuntime {
786
788
  for (const scope of this.leaseScopes) {
787
789
  this.metrics?.recordOwnerLeaseRenewLateness(lateness, scope.kind, scope.name);
788
790
  }
789
- this.nextLeaseRenewAtMs = this.monotonicNowMs() + this.options.ownerLeaseRenewIntervalMs;
790
791
  if (this.ownerLeaseDeadlineMs !== undefined &&
791
792
  this.monotonicNowMs() >= this.ownerLeaseDeadlineMs) {
792
793
  this.ownerLeaseHealthy = false;
@@ -908,8 +909,8 @@ class OwnerLeaseRenewTimeoutError extends Error {
908
909
  this.name = 'OwnerLeaseRenewTimeoutError';
909
910
  }
910
911
  }
911
- function remainingTimeoutMs(timeoutDeadline) {
912
- return Math.max(0, timeoutDeadline - performance.now());
912
+ function remainingTimeoutMs(timeoutStartedAtMs, timeoutMs) {
913
+ return Math.max(0, timeoutMs - (performance.now() - timeoutStartedAtMs));
913
914
  }
914
915
  function errorMessage(error) {
915
916
  return error instanceof Error ? error.message : String(error);
@@ -1,7 +1,5 @@
1
- import type { ZLinkJsonSchema } from '../../contracts/Handlers/JsonContract';
1
+ import * as profile from '@zlink-systems/stream-wire/internal/json';
2
2
  export declare const FRAMEWORK_JSON_V1_PROFILE = "framework-json-v1";
3
- export interface FrameworkJsonParseOptions {
4
- readonly rejectPropertyName?: (name: string) => boolean;
5
- }
6
- export declare function stringifyFrameworkJsonV1(value: unknown, schema?: ZLinkJsonSchema): string;
7
- export declare function parseFrameworkJsonV1(text: string, options?: FrameworkJsonParseOptions, schema?: ZLinkJsonSchema): unknown;
3
+ export declare const stringifyFrameworkJsonV1: typeof profile.stringifyFrameworkJsonV1;
4
+ export declare const parseFrameworkJsonV1: typeof profile.parseFrameworkJsonV1;
5
+ export type { FrameworkJsonParseOptions } from '@zlink-systems/stream-wire/internal/json';