@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
@@ -1,7 +1,24 @@
1
- import type { ZLinkBlobReference, ZLinkRelocationStore } from '../../contracts/Locations/RelocationStore';
1
+ import type { ZLinkRuntimeMetrics } from '../diagnostics/runtime-metrics';
2
+ import type { ZLinkBlobReference, ZLinkBlobPutResult, ZLinkRelocationStore } from '../../contracts/Locations/RelocationStore';
2
3
  export declare function relocationBlobReference(value: string): ZLinkBlobReference;
3
4
  export declare function putNewRelocationBlob(store: ZLinkRelocationStore, payload: Uint8Array, retentionMs: number, signal?: AbortSignal): Promise<{
4
5
  readonly reference: ZLinkBlobReference;
5
6
  readonly expiresAt: Date;
6
7
  readonly storeNow: Date;
7
8
  }>;
9
+ /** Observes provider requests before callers interpret or decode blob contents. */
10
+ export declare class ZLinkProviderRelocationRepository implements ZLinkRelocationStore {
11
+ private readonly provider;
12
+ private readonly metrics;
13
+ constructor(provider: ZLinkRelocationStore, metrics: ZLinkRuntimeMetrics);
14
+ putNew(payload: Uint8Array, retentionMs: number, signal?: AbortSignal): Promise<{
15
+ readonly reference: ZLinkBlobReference;
16
+ readonly expiresAt: Date;
17
+ readonly storeNow: Date;
18
+ }>;
19
+ put(...args: Parameters<ZLinkRelocationStore['put']>): Promise<ZLinkBlobPutResult>;
20
+ read(...args: Parameters<ZLinkRelocationStore['read']>): Promise<import("../../contracts/Locations/RelocationStore").ZLinkBlobReadResult>;
21
+ renew(...args: Parameters<ZLinkRelocationStore['renew']>): Promise<import("../../contracts/Locations/RelocationStore").ZLinkBlobRenewResult>;
22
+ delete(...args: Parameters<ZLinkRelocationStore['delete']>): Promise<void>;
23
+ private observe;
24
+ }
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZLinkProviderRelocationRepository = void 0;
3
4
  exports.relocationBlobReference = relocationBlobReference;
4
5
  exports.putNewRelocationBlob = putNewRelocationBlob;
6
+ const ZLinkFrameworkException_1 = require("../../contracts/Errors/ZLinkFrameworkException");
7
+ const location_store_failure_1 = require("./location-store-failure");
5
8
  const node_crypto_1 = require("node:crypto");
6
9
  const abort_1 = require("../abort");
7
10
  function relocationBlobReference(value) {
8
11
  return { value };
9
12
  }
10
13
  async function putNewRelocationBlob(store, payload, retentionMs, signal) {
14
+ if (store instanceof ZLinkProviderRelocationRepository) {
15
+ return store.putNew(payload, retentionMs, signal);
16
+ }
17
+ return putNewRelocationBlobCore(store, payload, retentionMs, signal);
18
+ }
19
+ async function putNewRelocationBlobCore(store, payload, retentionMs, signal) {
11
20
  let reference = relocationBlobReference((0, node_crypto_1.randomUUID)());
12
21
  for (;; await (0, abort_1.macrotaskBoundary)()) {
13
22
  signal?.throwIfAborted();
@@ -15,7 +24,9 @@ async function putNewRelocationBlob(store, payload, retentionMs, signal) {
15
24
  try {
16
25
  result = await (0, abort_1.awaitWithAbort)(store.put(reference, payload, retentionMs, signal), signal);
17
26
  }
18
- catch {
27
+ catch (error) {
28
+ if (!isRelocationProviderFailure(error))
29
+ throw error;
19
30
  signal?.throwIfAborted();
20
31
  const read = await (0, abort_1.awaitWithAbort)(store.read(reference, signal), signal);
21
32
  if (read.kind === 'found' && Buffer.compare(read.bytes, payload) === 0) {
@@ -35,3 +46,43 @@ async function putNewRelocationBlob(store, payload, retentionMs, signal) {
35
46
  reference = relocationBlobReference((0, node_crypto_1.randomUUID)());
36
47
  }
37
48
  }
49
+ /** Observes provider requests before callers interpret or decode blob contents. */
50
+ class ZLinkProviderRelocationRepository {
51
+ provider;
52
+ metrics;
53
+ constructor(provider, metrics) {
54
+ this.provider = provider;
55
+ this.metrics = metrics;
56
+ }
57
+ putNew(payload, retentionMs, signal) {
58
+ return this.observe('relocation_put', () => putNewRelocationBlobCore(this.provider, payload, retentionMs, signal), signal);
59
+ }
60
+ put(...args) {
61
+ return this.observe('relocation_put', () => this.provider.put(...args), args[3]);
62
+ }
63
+ read(...args) {
64
+ return this.observe('relocation_get', () => this.provider.read(...args), args[1]);
65
+ }
66
+ renew(...args) {
67
+ return this.observe('relocation_put', () => this.provider.renew(...args), args[2]);
68
+ }
69
+ delete(...args) {
70
+ return this.observe('relocation_delete', () => this.provider.delete(...args), args[1]);
71
+ }
72
+ async observe(operation, request, signal) {
73
+ try {
74
+ return await request();
75
+ }
76
+ catch (error) {
77
+ if (isRelocationProviderFailure(error, signal)) {
78
+ this.metrics.recordLocationStoreError(operation);
79
+ }
80
+ throw error;
81
+ }
82
+ }
83
+ }
84
+ exports.ZLinkProviderRelocationRepository = ZLinkProviderRelocationRepository;
85
+ function isRelocationProviderFailure(error, signal) {
86
+ return ((0, location_store_failure_1.isIndeterminateLocationStoreFailure)(error, signal) &&
87
+ !(error instanceof ZLinkFrameworkException_1.ZLinkFrameworkException && error.kind !== ZLinkFrameworkException_1.ZLinkFrameworkErrorKind.Unavailable));
88
+ }
@@ -0,0 +1,37 @@
1
+ import type { RoutingId } from '../../contracts/Common';
2
+ import type { ZLinkMeshNodeDescriptor } from '../../contracts/Locations/Rows';
3
+ import type { ZLinkLocationOwnerToken } from './internal-location-contracts';
4
+ /** Source request owner values the first accepting owner records (Location runtime §9.3). */
5
+ export interface ZLinkRequestSourceFence {
6
+ readonly ownerId: string;
7
+ readonly leaseGeneration: bigint;
8
+ readonly nodeRid: RoutingId;
9
+ readonly nodeGeneration: bigint;
10
+ }
11
+ export interface ZLinkRequestSourceResolverOptions {
12
+ readonly listLiveMeshNodes: (meshName: string, signal?: AbortSignal) => Promise<readonly ZLinkMeshNodeDescriptor[]>;
13
+ readonly remainingOwnerTokenLeaseMs: (owner: ZLinkLocationOwnerToken, signal?: AbortSignal) => Promise<number>;
14
+ readonly monotonicNowMs?: () => number;
15
+ }
16
+ /**
17
+ * Chooses the descriptor that supplies the source request owner values (Session·Actor binding
18
+ * §4): the admitted sender's descriptor with the exact RID and node lifecycle generation whose
19
+ * owner lease passes the Location runtime §4.1 check. Auto-connect polling keeps the live
20
+ * descriptors here with the local lease deadline computed from the same lease read. A sender
21
+ * missing from them is read from the Store once and kept with them.
22
+ */
23
+ export declare class ZLinkRequestSourceResolver {
24
+ private readonly options;
25
+ private readonly polled;
26
+ private readonly monotonicNowMs;
27
+ constructor(options: ZLinkRequestSourceResolverOptions);
28
+ /** Replaces the polled descriptors of one mesh with a live descriptor listing. */
29
+ observeLiveDescriptors(meshName: string, descriptors: readonly ZLinkMeshNodeDescriptor[], signal?: AbortSignal): Promise<void>;
30
+ /**
31
+ * Returns the recorded values, undefined when the sender has no live descriptor, or a promise
32
+ * while the Store is read once for a sender the polled descriptors do not contain.
33
+ */
34
+ accept(meshName: string, nodeRid: RoutingId, nodeGeneration: bigint, nodeRidStorageHex: string, signal?: AbortSignal): ZLinkRequestSourceFence | undefined | Promise<ZLinkRequestSourceFence | undefined>;
35
+ private readOnce;
36
+ private polledSource;
37
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZLinkRequestSourceResolver = void 0;
4
+ const routing_id_1 = require("../routing-id");
5
+ const abort_1 = require("../abort");
6
+ /**
7
+ * Chooses the descriptor that supplies the source request owner values (Session·Actor binding
8
+ * §4): the admitted sender's descriptor with the exact RID and node lifecycle generation whose
9
+ * owner lease passes the Location runtime §4.1 check. Auto-connect polling keeps the live
10
+ * descriptors here with the local lease deadline computed from the same lease read. A sender
11
+ * missing from them is read from the Store once and kept with them.
12
+ */
13
+ class ZLinkRequestSourceResolver {
14
+ options;
15
+ polled = new Map();
16
+ monotonicNowMs;
17
+ constructor(options) {
18
+ this.options = options;
19
+ this.monotonicNowMs = options.monotonicNowMs ?? (() => performance.now());
20
+ }
21
+ /** Replaces the polled descriptors of one mesh with a live descriptor listing. */
22
+ async observeLiveDescriptors(meshName, descriptors, signal) {
23
+ const sources = new Map();
24
+ for (const descriptor of descriptors) {
25
+ const source = await this.polledSource(descriptor, signal);
26
+ if (source !== undefined)
27
+ sources.set((0, routing_id_1.encodeRoutingIdStorageHex)(descriptor.rid), source);
28
+ }
29
+ this.polled.set(meshName, sources);
30
+ }
31
+ /**
32
+ * Returns the recorded values, undefined when the sender has no live descriptor, or a promise
33
+ * while the Store is read once for a sender the polled descriptors do not contain.
34
+ */
35
+ accept(meshName, nodeRid, nodeGeneration, nodeRidStorageHex, signal) {
36
+ (0, abort_1.throwIfAborted)(signal);
37
+ const known = this.polled.get(meshName)?.get(nodeRidStorageHex);
38
+ if (known !== undefined && known.fence.nodeGeneration === nodeGeneration) {
39
+ return this.monotonicNowMs() < known.leaseDeadlineMs ? known.fence : undefined;
40
+ }
41
+ return this.readOnce(meshName, nodeRid, nodeGeneration, nodeRidStorageHex, signal);
42
+ }
43
+ async readOnce(meshName, nodeRid, nodeGeneration, nodeRidStorageHex, signal) {
44
+ // The Store boundary already classifies provider failures as Unavailable. Preserve their
45
+ // cause for the ingress error reporter, and let programming errors propagate unchanged.
46
+ const descriptors = await (0, abort_1.awaitWithAbort)(this.options.listLiveMeshNodes(meshName, signal), signal);
47
+ const descriptor = descriptors.find((value) => (0, routing_id_1.routingIdsEqual)(value.rid, nodeRid) && value.lifecycleGeneration === nodeGeneration);
48
+ const source = descriptor === undefined ? undefined : await this.polledSource(descriptor, signal);
49
+ (0, abort_1.throwIfAborted)(signal);
50
+ if (source === undefined)
51
+ return undefined;
52
+ let sources = this.polled.get(meshName);
53
+ if (sources === undefined) {
54
+ sources = new Map();
55
+ this.polled.set(meshName, sources);
56
+ }
57
+ sources.set(nodeRidStorageHex, source);
58
+ return source.fence;
59
+ }
60
+ async polledSource(descriptor, signal) {
61
+ if (descriptor.ownerId.length === 0 ||
62
+ descriptor.leaseGeneration <= 0n ||
63
+ descriptor.lifecycleGeneration <= 0n) {
64
+ return undefined;
65
+ }
66
+ const remainingMs = await (0, abort_1.awaitWithAbort)(this.options.remainingOwnerTokenLeaseMs({ ownerId: descriptor.ownerId, leaseGeneration: descriptor.leaseGeneration }, signal), signal);
67
+ if (remainingMs <= 0)
68
+ return undefined;
69
+ return {
70
+ fence: {
71
+ ownerId: descriptor.ownerId,
72
+ leaseGeneration: descriptor.leaseGeneration,
73
+ nodeRid: descriptor.rid,
74
+ nodeGeneration: descriptor.lifecycleGeneration
75
+ },
76
+ leaseDeadlineMs: this.monotonicNowMs() + remainingMs
77
+ };
78
+ }
79
+ }
80
+ exports.ZLinkRequestSourceResolver = ZLinkRequestSourceResolver;
@@ -104,7 +104,7 @@ class ZLinkStoreLocationResolvers {
104
104
  descriptor.objectRole === internal_location_contracts_1.ZLinkObjectRole.Server &&
105
105
  descriptor.placementWeight > 0 &&
106
106
  !(0, routing_id_1.routingIdsEqual)(descriptor.rid, excludedNodeRid) &&
107
- !excludedCandidateRids.has(String(descriptor.rid)) &&
107
+ !excludedCandidateRids.has((0, routing_id_1.encodeRoutingIdStorageHex)(descriptor.rid)) &&
108
108
  capacity.active + capacity.reserved < capacity.limit &&
109
109
  descriptor.objectCapabilities.some((candidate) => candidate.objectKind === 'actor' && candidate.stableType === actorType));
110
110
  });
@@ -95,13 +95,15 @@ export declare class ZLinkLocationRuntime implements ZLinkLocationRuntimeQuery {
95
95
  get isStarted(): boolean;
96
96
  get nodeRid(): RoutingId | undefined;
97
97
  get currentOwnerToken(): ZLinkLocationOwnerToken | undefined;
98
+ /** Location runtime §5: a startup Store request ends within the renew timeout. */
99
+ writeDescriptor<T>(action: (signal?: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<T>;
98
100
  closeOwnerLeaseAdmission(error: unknown): void;
99
101
  reclaimOwnerAuthorities(signal?: AbortSignal): Promise<void>;
100
102
  private readAllAuthorityEntries;
101
103
  addOwnershipLostHandler(handler: (event: ZLinkOwnershipLostEvent) => void): void;
102
104
  removeOwnershipLostHandler(handler: (event: ZLinkOwnershipLostEvent) => void): void;
103
- addOwnerLeaseRenewedHandler(handler: (renewal: ZLinkOwnerLeaseRenewed) => void): void;
104
- removeOwnerLeaseRenewedHandler(handler: (renewal: ZLinkOwnerLeaseRenewed) => void): void;
105
+ addOwnerLeaseRenewedHandler(handler: (renewal: ZLinkOwnerLeaseRenewed, wasOwnerLeaseUsable: boolean) => void): void;
106
+ removeOwnerLeaseRenewedHandler(handler: (renewal: ZLinkOwnerLeaseRenewed, wasOwnerLeaseUsable: boolean) => void): void;
105
107
  addOwnerLeaseRenewalFailedHandler(handler: () => void): void;
106
108
  removeOwnerLeaseRenewalFailedHandler(handler: () => void): void;
107
109
  start(nodeRid: RoutingId): Promise<void>;
@@ -128,6 +130,8 @@ export declare class ZLinkLocationRuntime implements ZLinkLocationRuntimeQuery {
128
130
  reportDiscoveryFailure(error: unknown): void;
129
131
  listPeerLocations(filter: ZLinkPeerLocationFilter, signal?: AbortSignal): Promise<readonly ZLinkPeerLocation[]>;
130
132
  listLiveMeshNodes(meshName: string, signal?: AbortSignal): Promise<readonly ZLinkMeshNodeDescriptor[]>;
133
+ /** Remaining exact owner lease from the same tracker that filters live descriptors. */
134
+ remainingOwnerTokenLeaseMs(owner: ZLinkLocationOwnerToken, signal?: AbortSignal): Promise<number>;
131
135
  listMeshNodeDescriptors(meshName: string, page?: ZLinkPageRequest, signal?: AbortSignal): Promise<ZLinkLocationPage<ZLinkMeshNodeDescriptor>>;
132
136
  listSpotLocations(filter: ZLinkSpotLocationFilter, page?: ZLinkPageRequest, signal?: AbortSignal): Promise<ZLinkLocationPage<ZLinkSpotLocation>>;
133
137
  listActorLocations(filter: ZLinkActorLocationFilter, page?: ZLinkPageRequest, signal?: AbortSignal): Promise<ZLinkLocationPage<ZLinkActorLocation>>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkLocationRuntime = exports.ZLinkOwnerLeaseClaimError = exports.ZLinkOwnerCleanupError = void 0;
4
+ const descriptor_publication_1 = require("./descriptor-publication");
5
+ const location_store_failure_1 = require("./location-store-failure");
4
6
  const location_store_pages_1 = require("./location-store-pages");
5
7
  const runtime_metrics_1 = require("../diagnostics/runtime-metrics");
6
8
  const Stores_1 = require("../../contracts/Locations/Stores");
@@ -97,9 +99,20 @@ class ZLinkLocationRuntime {
97
99
  get currentOwnerToken() {
98
100
  return this.ownerToken;
99
101
  }
102
+ /** Location runtime §5: a startup Store request ends within the renew timeout. */
103
+ async writeDescriptor(action, signal) {
104
+ try {
105
+ return await withTimeout(action, this.options.ownerLeaseRenewTimeoutMs, signal);
106
+ }
107
+ catch (error) {
108
+ if (!(0, location_store_failure_1.isIndeterminateLocationStoreFailure)(error, signal))
109
+ throw error;
110
+ throw new descriptor_publication_1.ZLinkDescriptorPublicationUnconfirmedError(error);
111
+ }
112
+ }
100
113
  closeOwnerLeaseAdmission(error) {
101
114
  this.ownerLeaseDeadlineMs = undefined;
102
- this.recordFailure(errorMessage(error), 'owner_lease_recovery');
115
+ this.recordFailure(errorMessage(error));
103
116
  }
104
117
  async reclaimOwnerAuthorities(signal) {
105
118
  const owner = this.ownerToken;
@@ -255,7 +268,6 @@ class ZLinkLocationRuntime {
255
268
  if (this.ownerToken === undefined) {
256
269
  return await this.claimFreshOwnerLease(signal, shutdownSignal);
257
270
  }
258
- const wasOwnerLeaseUsable = this.ownerLeaseUsable;
259
271
  try {
260
272
  const renewStartedAtMs = this.monotonicNowMs();
261
273
  this.leaseOperationStartedAtMs = renewStartedAtMs;
@@ -277,13 +289,13 @@ class ZLinkLocationRuntime {
277
289
  // another heartbeat interval.
278
290
  return await this.claimFreshOwnerLease(signal, shutdownSignal);
279
291
  }
292
+ const wasOwnerLeaseUsable = this.ownerLeaseUsable;
280
293
  this.ownerLeaseHealthy = true;
281
294
  this.ownerLeaseRenewedAt = result.storeNow;
282
295
  this.setOwnerLeaseDeadline(renewStartedAtMs, renewCompletedAtMs, result.leaseExpiresAt, result.storeNow);
283
296
  this.lastError = undefined;
284
- if (!wasOwnerLeaseUsable) {
285
- for (const handler of this.ownerLeaseRenewedHandlers)
286
- handler(result);
297
+ for (const handler of this.ownerLeaseRenewedHandlers) {
298
+ handler(result, wasOwnerLeaseUsable);
287
299
  }
288
300
  return true;
289
301
  }
@@ -291,7 +303,7 @@ class ZLinkLocationRuntime {
291
303
  if (signal?.aborted === true)
292
304
  throw error;
293
305
  this.recordOwnerLeaseRenewFailure();
294
- this.recordFailure(errorMessage(error), 'lease_renew');
306
+ this.recordFailure(errorMessage(error));
295
307
  for (const handler of this.ownerLeaseRenewalFailedHandlers)
296
308
  handler();
297
309
  return false;
@@ -311,13 +323,13 @@ class ZLinkLocationRuntime {
311
323
  if (error instanceof ZLinkOwnerLeaseClaimError)
312
324
  throw error;
313
325
  this.recordOwnerLeaseRenewFailure();
314
- this.recordFailure(errorMessage(error), 'owner_lease_claim');
326
+ this.recordFailure(errorMessage(error));
315
327
  return false;
316
328
  }
317
329
  const claimCompletedAtMs = this.monotonicNowMs();
318
330
  if (claim.kind !== 'claimed') {
319
331
  const error = new ZLinkOwnerLeaseClaimError(claim.kind);
320
- this.recordFailure(error.message, 'owner_lease_claim');
332
+ this.recordFailure(error.message);
321
333
  throw error;
322
334
  }
323
335
  try {
@@ -336,14 +348,14 @@ class ZLinkLocationRuntime {
336
348
  kind: 'renewed',
337
349
  leaseExpiresAt: claim.leaseExpiresAt,
338
350
  storeNow: claim.storeNow
339
- });
351
+ }, false);
340
352
  }
341
353
  return true;
342
354
  }
343
355
  catch (error) {
344
356
  if (signal?.aborted === true)
345
357
  throw error;
346
- this.recordFailure(errorMessage(error), 'owner_lease_claim');
358
+ this.recordFailure(errorMessage(error));
347
359
  return false;
348
360
  }
349
361
  }
@@ -370,7 +382,7 @@ class ZLinkLocationRuntime {
370
382
  throw new ZLinkOwnerCleanupError(completionError);
371
383
  }
372
384
  if (!(0, abort_1.isAbortError)(completionError)) {
373
- this.recordFailure(errorMessage(completionError), 'owner_lease_claim');
385
+ this.recordFailure(errorMessage(completionError));
374
386
  }
375
387
  }
376
388
  }
@@ -397,10 +409,10 @@ class ZLinkLocationRuntime {
397
409
  confirmed = await withTimeout((readSignal) => this.stores.ownerLeaseStore.readOwnerLease(this.ownerId, readSignal), confirmationTimeoutMs, cleanupSignal);
398
410
  }
399
411
  catch (confirmationError) {
400
- this.recordFailure(errorMessage(confirmationError), 'owner_lease_claim_confirmation');
412
+ this.recordFailure(errorMessage(confirmationError));
401
413
  if (cancelled)
402
414
  throw new ZLinkOwnerCleanupError(confirmationError);
403
- throw confirmationError;
415
+ throw originalError instanceof ZLinkOwnerLeaseClaimError ? originalError : confirmationError;
404
416
  }
405
417
  if (confirmed.kind !== 'found' || confirmed.token.ownerId !== this.ownerId) {
406
418
  throw originalError;
@@ -412,7 +424,7 @@ class ZLinkLocationRuntime {
412
424
  : undefined, cleanupSignal);
413
425
  }
414
426
  catch (releaseError) {
415
- this.recordFailure(errorMessage(releaseError), 'owner_lease_release');
427
+ this.recordFailure(errorMessage(releaseError));
416
428
  throw new ZLinkOwnerCleanupError(releaseError);
417
429
  }
418
430
  throw originalError;
@@ -466,7 +478,7 @@ class ZLinkLocationRuntime {
466
478
  // in-process result after the write completes.
467
479
  updatedAt: new Date()
468
480
  };
469
- let result = await this.guardWrite(() => this.stores.locationStore.updateMeshNode(stamped, intent, signal));
481
+ let result = await this.guardWrite(() => this.writeDescriptor((writeSignal) => this.stores.locationStore.updateMeshNode(stamped, intent, writeSignal), signal));
470
482
  if (intent === internal_location_contracts_1.ZLinkLocationWriteIntent.Renew &&
471
483
  (result.status === internal_location_contracts_1.ZLinkLocationWriteStatus.RejectedConflict ||
472
484
  result.status === internal_location_contracts_1.ZLinkLocationWriteStatus.IgnoredStale)) {
@@ -474,7 +486,7 @@ class ZLinkLocationRuntime {
474
486
  // in-process owner token. Renew cannot recreate an absent row, so use
475
487
  // NewClaim as a bounded fallback. If another owner has recreated the
476
488
  // row, NewClaim remains rejected and the caller keeps the conflict.
477
- result = await this.guardWrite(() => this.stores.locationStore.updateMeshNode(stamped, internal_location_contracts_1.ZLinkLocationWriteIntent.NewClaim, signal));
489
+ result = await this.guardWrite(() => this.writeDescriptor((writeSignal) => this.stores.locationStore.updateMeshNode(stamped, internal_location_contracts_1.ZLinkLocationWriteIntent.NewClaim, writeSignal), signal));
478
490
  }
479
491
  this.notifyIfStale(result, internal_location_contracts_1.ZLinkLocationKind.Peer, `${descriptor.meshName}\0${String(descriptor.rid)}`);
480
492
  return result;
@@ -592,7 +604,7 @@ class ZLinkLocationRuntime {
592
604
  };
593
605
  }
594
606
  reportDiscoveryFailure(error) {
595
- this.recordFailure(errorMessage(error), 'read');
607
+ this.recordFailure(errorMessage(error));
596
608
  }
597
609
  async listPeerLocations(filter, signal) {
598
610
  const rows = await this.stores.peerStore.listPeers(filter, signal);
@@ -608,6 +620,10 @@ class ZLinkLocationRuntime {
608
620
  const live = await this.liveRows.filter(rows, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal);
609
621
  return live.map((row) => ({ ...row, endpoint: (0, EndpointNotation_1.normalizeEndpoint)(row.endpoint) }));
610
622
  }
623
+ /** Remaining exact owner lease from the same tracker that filters live descriptors. */
624
+ remainingOwnerTokenLeaseMs(owner, signal) {
625
+ return this.leaseTracker.remainingOwnerTokenLeaseMs(owner, signal);
626
+ }
611
627
  async listMeshNodeDescriptors(meshName, page, signal) {
612
628
  const rows = await this.stores.locationStore.listMeshNodes(meshName, this.pageRequest(page), signal);
613
629
  const live = await this.liveRows.filter(rows.items, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal);
@@ -791,7 +807,7 @@ class ZLinkLocationRuntime {
791
807
  if (this.ownerLeaseDeadlineMs !== undefined &&
792
808
  this.monotonicNowMs() >= this.ownerLeaseDeadlineMs) {
793
809
  this.ownerLeaseHealthy = false;
794
- this.recordFailure('Owner lease expired before renewal completed.', 'lease_expired');
810
+ this.recordFailure('Owner lease expired before renewal completed.');
795
811
  for (const handler of this.ownerLeaseRenewalFailedHandlers)
796
812
  handler();
797
813
  }
@@ -812,7 +828,7 @@ class ZLinkLocationRuntime {
812
828
  return await write();
813
829
  }
814
830
  catch (error) {
815
- this.recordFailure(errorMessage(error), 'compare_exchange');
831
+ this.recordFailure(errorMessage(error));
816
832
  throw error;
817
833
  }
818
834
  }
@@ -821,15 +837,11 @@ class ZLinkLocationRuntime {
821
837
  return await write();
822
838
  }
823
839
  catch (error) {
824
- this.recordFailure(errorMessage(error), 'compare_exchange');
840
+ this.recordFailure(errorMessage(error));
825
841
  throw error;
826
842
  }
827
843
  }
828
844
  notifyIfStale(result, kind, key) {
829
- if (result.status === internal_location_contracts_1.ZLinkLocationWriteStatus.IgnoredStale ||
830
- result.status === internal_location_contracts_1.ZLinkLocationWriteStatus.RejectedConflict) {
831
- this.metrics?.recordLocationStoreError('compare_exchange');
832
- }
833
845
  if (result.status !== internal_location_contracts_1.ZLinkLocationWriteStatus.IgnoredStale) {
834
846
  return;
835
847
  }
@@ -838,10 +850,6 @@ class ZLinkLocationRuntime {
838
850
  }
839
851
  }
840
852
  notifyIfStaleStatus(status, kind, key) {
841
- if (status === internal_location_contracts_1.ZLinkLocationWriteStatus.IgnoredStale ||
842
- status === internal_location_contracts_1.ZLinkLocationWriteStatus.RejectedConflict) {
843
- this.metrics?.recordLocationStoreError('compare_exchange');
844
- }
845
853
  if (status !== internal_location_contracts_1.ZLinkLocationWriteStatus.IgnoredStale) {
846
854
  return;
847
855
  }
@@ -849,8 +857,7 @@ class ZLinkLocationRuntime {
849
857
  handler({ kind, key });
850
858
  }
851
859
  }
852
- recordFailure(message, operation = 'read') {
853
- this.metrics?.recordLocationStoreError(operation);
860
+ recordFailure(message) {
854
861
  this.ownerLeaseHealthy = false;
855
862
  this.lastError = message;
856
863
  }
@@ -1,4 +1,4 @@
1
- import { ZLinkMessage, type Type, type ZLinkMessageSerializer } from '../../contracts';
1
+ import { ZLinkMessage, type Type, ZLinkEncodedPayload, type ZLinkMessageSerializer } from '../../contracts';
2
2
  import type { Message } from '../../contracts/Common/Message';
3
3
  export interface ZLinkSerializerRegistryLike {
4
4
  readonly serializers: ReadonlyMap<string, ZLinkMessageSerializer>;
@@ -22,4 +22,10 @@ export declare function wrapFrameworkPayloadMessage(message: Message, registry?:
22
22
  export declare function selectDefaultSerializer(registry?: ZLinkSerializerRegistryLike | ReadonlyMap<string, ZLinkMessageSerializer>): ZLinkMessageSerializer | undefined;
23
23
  export declare function selectSerializer(value: unknown, registry?: ZLinkSerializerRegistryLike | ReadonlyMap<string, ZLinkMessageSerializer>, declaredType?: Type): ZLinkMessageSerializer | undefined;
24
24
  export declare function selectSerializerWithContentType(value: unknown, registry?: ZLinkSerializerRegistryLike | ReadonlyMap<string, ZLinkMessageSerializer>, declaredType?: Type): ZLinkSerializerSelectionEntry | undefined;
25
+ /**
26
+ * Wraps received bytes for a serializer without copying them. Binding receive
27
+ * Buffers keep their storage after the message closes and nothing writes to
28
+ * them, so the payload may adopt them; the public from() and data() still copy.
29
+ */
30
+ export declare function encodedPayloadFromOwned(bytes: Uint8Array): ZLinkEncodedPayload;
25
31
  export {};
@@ -9,6 +9,7 @@ exports.wrapFrameworkPayloadMessage = wrapFrameworkPayloadMessage;
9
9
  exports.selectDefaultSerializer = selectDefaultSerializer;
10
10
  exports.selectSerializer = selectSerializer;
11
11
  exports.selectSerializerWithContentType = selectSerializerWithContentType;
12
+ exports.encodedPayloadFromOwned = encodedPayloadFromOwned;
12
13
  const stream_wire_1 = require("@zlink-systems/stream-wire");
13
14
  const framework_errors_internal_1 = require("../framework-errors-internal");
14
15
  const runtime_message_1 = require("../backend/runtime-message");
@@ -250,13 +251,13 @@ function toRuntimeMessage(payload) {
250
251
  ? runtime_message_1.ZLinkBufferMessage.from(payload.data())
251
252
  : runtime_message_1.ZLinkBufferMessage.fromOwned(owned);
252
253
  }
254
+ /**
255
+ * Wraps received bytes for a serializer without copying them. Binding receive
256
+ * Buffers keep their storage after the message closes and nothing writes to
257
+ * them, so the payload may adopt them; the public from() and data() still copy.
258
+ */
253
259
  function encodedPayloadFromOwned(bytes) {
254
- if (!Buffer.isBuffer(bytes)) {
255
- return contracts_1.ZLinkEncodedPayload.from(bytes);
256
- }
257
- const payload = contracts_1.ZLinkEncodedPayload.from(Buffer.alloc(0));
258
- (0, encoded_payload_storage_1.adoptEncodedPayload)(payload, bytes);
259
- return payload;
260
+ return contracts_1.ZLinkEncodedPayload.fromOwned(bytes);
260
261
  }
261
262
  function rememberContentType(message, contentType) {
262
263
  encodedContentTypes.set(message, contentType);
@@ -3,52 +3,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createZLinkRequest = createZLinkRequest;
4
4
  const completedAdmission = Promise.resolve();
5
5
  const ignoreAdmissionFailure = () => { };
6
- function createZLinkRequest(start, deliverReply) {
7
- let admitted;
8
- let resolveAdmission;
9
- let rejectAdmission;
10
- const confirmAdmission = () => {
11
- admitted ??= completedAdmission;
12
- resolveAdmission?.();
13
- };
14
- const failAdmission = (error) => {
15
- if (admitted === undefined) {
16
- admitted = Promise.reject(error);
6
+ class RequestAdmission {
7
+ admitted;
8
+ resolveAdmission;
9
+ rejectAdmission;
10
+ confirm() {
11
+ this.admitted ??= completedAdmission;
12
+ this.resolveAdmission?.();
13
+ }
14
+ fail(error) {
15
+ if (this.admitted === undefined) {
16
+ this.admitted = Promise.reject(error);
17
17
  // Existing callers may observe only the reply Promise. Observing the
18
18
  // rejection here leaves the public admission Promise rejected.
19
- void admitted.catch(ignoreAdmissionFailure);
19
+ void this.admitted.catch(ignoreAdmissionFailure);
20
20
  }
21
21
  else {
22
- rejectAdmission?.(error);
22
+ this.rejectAdmission?.(error);
23
23
  }
24
- };
25
- const observeAdmission = () => {
26
- if (admitted === undefined) {
27
- admitted = new Promise((resolve, reject) => {
28
- resolveAdmission = resolve;
29
- rejectAdmission = reject;
24
+ }
25
+ observe() {
26
+ if (this.admitted === undefined) {
27
+ this.admitted = new Promise((resolve, reject) => {
28
+ this.resolveAdmission = resolve;
29
+ this.rejectAdmission = reject;
30
30
  });
31
- void admitted.catch(ignoreAdmissionFailure);
31
+ void this.admitted.catch(ignoreAdmissionFailure);
32
32
  }
33
- return admitted;
34
- };
33
+ return this.admitted;
34
+ }
35
+ }
36
+ function createZLinkRequest(start, deliverReply) {
37
+ const admission = new RequestAdmission();
35
38
  let pending;
36
39
  try {
37
- pending = start(confirmAdmission);
40
+ pending = start(() => admission.confirm());
38
41
  }
39
42
  catch (error) {
40
43
  pending = Promise.reject(error);
41
44
  }
42
45
  const observed = pending.then((value) => {
43
46
  // A successful reply proves admission even without an observation callback.
44
- confirmAdmission();
47
+ admission.confirm();
45
48
  return value;
46
49
  }, (error) => {
47
- failAdmission(error);
50
+ admission.fail(error);
48
51
  throw error;
49
52
  });
50
53
  const reply = deliverReply?.(observed) ?? observed;
51
54
  return Object.defineProperty(reply, 'admitted', {
52
- get: observeAdmission
55
+ get: () => admission.observe()
53
56
  });
54
57
  }