@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
@@ -488,17 +488,15 @@ export class ZLinkRuntimeRouteTransport implements ZLinkRouteClientTransport {
488
488
  metadata,
489
489
  correlationId
490
490
  );
491
- const completion = await this.submitRequestOperation(
492
- meshName,
493
- timeoutMs,
494
- signal,
495
- `MeshNode '${meshName}' request to node '${targetNodeRid}'`,
496
- (remainingTimeoutMs) => {
497
- const operationId = node.requestToNode(toBackendRoutingId(targetNodeRid), parts, {
498
- flags: 1,
499
- onAdmitted,
500
- timeoutMs: remainingTimeoutMs
501
- });
491
+ const requestOptions = { flags: 1, onAdmitted, timeoutMs: requestTimeoutBudget(timeoutMs) };
492
+ let completion: ZLinkMeshCompletion;
493
+ try {
494
+ completion = await this.completionTable(meshName).submit(() => {
495
+ const operationId = node.requestToNode(
496
+ toBackendRoutingId(targetNodeRid),
497
+ parts,
498
+ requestOptions
499
+ );
502
500
  this.traceNodeRequest(
503
501
  ZLinkMessageFlowOutcome.Sent,
504
502
  undefined,
@@ -508,8 +506,13 @@ export class ZLinkRuntimeRouteTransport implements ZLinkRouteClientTransport {
508
506
  correlationId
509
507
  );
510
508
  return operationId;
511
- }
512
- );
509
+ }, signal);
510
+ } catch (error) {
511
+ throw mapMeshSubmissionError(
512
+ error,
513
+ `MeshNode '${meshName}' request to node '${targetNodeRid}'`
514
+ );
515
+ }
513
516
  const reply = this.decodeMeshReply<TReply>(meshName, completion);
514
517
  this.traceNodeRequest(
515
518
  ZLinkMessageFlowOutcome.ReplyReceived,
@@ -658,58 +661,34 @@ export class ZLinkRuntimeRouteTransport implements ZLinkRouteClientTransport {
658
661
  );
659
662
  const metric = this.metrics?.startRequest(meshName, 'channel');
660
663
  try {
661
- const completion = await this.submitRequestOperation(
662
- meshName,
663
- timeoutMs,
664
- signal,
665
- `MeshNode '${meshName}' request to channel '${channelName}'`,
666
- (remainingTimeoutMs) =>
667
- node.requestToChannel(channelName, parts, {
668
- flags: 1,
669
- timeoutMs: remainingTimeoutMs,
670
- onAdmitted
671
- })
672
- );
664
+ const requestOptions = { flags: 1, timeoutMs: requestTimeoutBudget(timeoutMs), onAdmitted };
665
+ let completion: ZLinkMeshCompletion;
666
+ try {
667
+ completion = await this.completionTable(meshName).submit(
668
+ () => node.requestToChannel(channelName, parts, requestOptions),
669
+ signal
670
+ );
671
+ } catch (error) {
672
+ throw mapMeshSubmissionError(
673
+ error,
674
+ `MeshNode '${meshName}' request to channel '${channelName}'`
675
+ );
676
+ }
673
677
  const reply = this.decodeMeshReply<TReply>(meshName, completion);
674
678
  metric?.complete('completed');
675
679
  return reply;
676
680
  } catch (error) {
677
- metric?.complete(requestMetricOutcome(error));
678
- if (requestMetricOutcome(error) === 'target_not_found') {
681
+ metric?.complete(requestMetricOutcome(error, signal));
682
+ if (
683
+ error instanceof ZLinkFrameworkException &&
684
+ internalFrameworkErrorKind(error) === ZLinkFrameworkInternalErrorKind.RequestTargetNotFound
685
+ ) {
679
686
  this.metrics?.recordChannelSelectionFailure(meshName, channelName, 'no_ready_target');
680
687
  }
681
688
  throw error;
682
689
  }
683
690
  }
684
691
 
685
- private async submitRequestOperation(
686
- meshName: string,
687
- timeoutMs: number | undefined,
688
- signal: AbortSignal | undefined,
689
- operation: string,
690
- attempt: (
691
- remainingTimeoutMs: number
692
- ) => ReturnType<Parameters<ZLinkMeshCompletionTable['submit']>[0]>
693
- ): Promise<ZLinkMeshCompletion> {
694
- const effectiveTimeoutMs = Math.max(1, timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);
695
- const deadlineMs = performance.now() + effectiveTimeoutMs;
696
- const remainingTimeoutMs = deadlineMs - performance.now();
697
- if (remainingTimeoutMs <= 0) {
698
- throw createInternalFrameworkException(
699
- ZLinkFrameworkInternalErrorKind.DeadlineExceeded,
700
- `${operation} timed out before submission.`
701
- );
702
- }
703
- try {
704
- return await this.completionTable(meshName).submit(
705
- () => attempt(Math.max(1, Math.ceil(remainingTimeoutMs))),
706
- signal
707
- );
708
- } catch (error) {
709
- throw mapMeshSubmissionError(error, operation);
710
- }
711
- }
712
-
713
692
  sendToSpot(
714
693
  spotRouteTarget: ZLinkSpotRouteTarget,
715
694
  message: unknown,
@@ -1169,6 +1148,14 @@ function instanceSpotRouteFence(target: ZLinkSpotRouteTarget): ServiceInstanceRo
1169
1148
  };
1170
1149
  }
1171
1150
 
1151
+ /**
1152
+ * The binding request timeout for one submission. The binding owns the
1153
+ * deadline after submit; the completion table slot only waits for it.
1154
+ */
1155
+ function requestTimeoutBudget(timeoutMs: number | undefined): number {
1156
+ return Math.max(1, Math.ceil(timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS));
1157
+ }
1158
+
1172
1159
  function mapMeshSubmitResult(result: number): ZLinkSubmitResult {
1173
1160
  return classifySubmitResult(result, 'Mesh submission');
1174
1161
  }
@@ -1260,14 +1247,18 @@ export function meshRequestFailure(
1260
1247
  return error;
1261
1248
  }
1262
1249
 
1263
- function requestMetricOutcome(error: unknown): string {
1250
+ function requestMetricOutcome(error: unknown, signal?: AbortSignal): string {
1264
1251
  if (error instanceof ZLinkFrameworkException) {
1265
- if (internalFrameworkErrorKind(error) === ZLinkFrameworkInternalErrorKind.RequestTargetNotFound)
1266
- return 'target_not_found';
1267
1252
  if (internalFrameworkErrorKind(error) === ZLinkFrameworkInternalErrorKind.DeadlineExceeded)
1268
1253
  return 'timed_out';
1269
1254
  if (internalFrameworkErrorKind(error) === ZLinkFrameworkInternalErrorKind.RuntimeShutdown)
1270
1255
  return 'shutdown';
1271
1256
  }
1257
+ if (
1258
+ signal?.aborted === true &&
1259
+ (error === signal.reason ||
1260
+ (error instanceof Error && (error.cause === signal.reason || error.name === 'AbortError')))
1261
+ )
1262
+ return 'cancelled';
1272
1263
  return 'failed';
1273
1264
  }
@@ -1,3 +1,4 @@
1
+ import { routingIdsEqual } from '../routing-id';
1
2
  import type { Message } from '../../contracts/Common/Message';
2
3
  import { ZLINK_DEFAULT_PUBLIC_WEIGHT } from '../../contracts/Configuration/RegistrationBuilderPolicy';
3
4
  import {
@@ -121,9 +122,9 @@ export class ZLinkClientServerLocationRuntime {
121
122
  ownerId: owner.ownerId,
122
123
  leaseGeneration: owner.leaseGeneration
123
124
  };
124
- const result = await this.store.updateClientServer(
125
- candidate,
126
- ZLinkLocationWriteIntent.Takeover,
125
+ const result = await this.locationRuntime.writeDescriptor(
126
+ (writeSignal) =>
127
+ this.store.updateClientServer(candidate, ZLinkLocationWriteIntent.Takeover, writeSignal),
127
128
  signal
128
129
  );
129
130
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -152,9 +153,9 @@ export class ZLinkClientServerLocationRuntime {
152
153
  descriptorRevision: current.descriptorRevision + 1n,
153
154
  weight: runtimeWeight
154
155
  };
155
- const result = await this.store.updateClientServer(
156
- candidate,
157
- ZLinkLocationWriteIntent.Renew,
156
+ const result = await this.locationRuntime.writeDescriptor(
157
+ (writeSignal) =>
158
+ this.store.updateClientServer(candidate, ZLinkLocationWriteIntent.Renew, writeSignal),
158
159
  signal
159
160
  );
160
161
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -181,9 +182,9 @@ export class ZLinkClientServerLocationRuntime {
181
182
  leaseGeneration: owner.leaseGeneration,
182
183
  updatedAt: new Date(0)
183
184
  };
184
- const result = await this.store.updateClientServer(
185
- descriptor,
186
- ZLinkLocationWriteIntent.NewClaim,
185
+ const result = await this.locationRuntime.writeDescriptor(
186
+ (writeSignal) =>
187
+ this.store.updateClientServer(descriptor, ZLinkLocationWriteIntent.NewClaim, writeSignal),
187
188
  signal
188
189
  );
189
190
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -587,7 +588,7 @@ function requireMatchingAdmission(
587
588
  ): void {
588
589
  if (
589
590
  actual.channelName !== expected.channelName ||
590
- actual.serverRid !== String(expected.serverRid) ||
591
+ !routingIdsEqual(actual.serverRid, expected.serverRid) ||
591
592
  actual.lifecycleGeneration !== expected.lifecycleGeneration ||
592
593
  actual.descriptorRevision !== expected.descriptorRevision ||
593
594
  actual.weight !== expected.weight ||
@@ -21,6 +21,7 @@ export type { ZLinkDispatchErrorSink } from '../diagnostics/dispatch-error-port'
21
21
 
22
22
  type ZLinkRuntimeDispatchFailure = ZLinkDispatchFailure & {
23
23
  readonly error?: unknown;
24
+ readonly severity?: 'warning';
24
25
  };
25
26
 
26
27
  export class ZLinkDispatchErrorReporter {
@@ -37,7 +38,7 @@ export class ZLinkDispatchErrorReporter {
37
38
  _providerResolver: unknown,
38
39
  errorSink: ZLinkDispatchErrorSink,
39
40
  ctx?: ZLinkDiagnosticsContext,
40
- private readonly metrics?: ZLinkRuntimeMetrics
41
+ readonly metrics?: ZLinkRuntimeMetrics
41
42
  ) {
42
43
  const flowCtx: ZLinkDiagnosticsContext = ctx ?? {
43
44
  diagnostics: DEFAULT_ZLINK_DIAGNOSTICS,
@@ -86,7 +87,8 @@ export class ZLinkDispatchErrorReporter {
86
87
  errorType: errorInfo.errorType,
87
88
  errorMessage: errorInfo.errorMessage,
88
89
  errorCauseType: errorInfo.errorCauseType,
89
- errorCauseMessage: errorInfo.errorCauseMessage
90
+ errorCauseMessage: errorInfo.errorCauseMessage,
91
+ severity: normalized.severity
90
92
  });
91
93
  }
92
94
 
@@ -155,9 +155,13 @@ export class ZLinkFanoutLocationRuntime {
155
155
  ownerId: owner.ownerId,
156
156
  leaseGeneration: owner.leaseGeneration
157
157
  };
158
- const result = await this.store.updateFanoutPublisher(
159
- candidate,
160
- ZLinkLocationWriteIntent.Takeover,
158
+ const result = await this.locationRuntime.writeDescriptor(
159
+ (writeSignal) =>
160
+ this.store.updateFanoutPublisher(
161
+ candidate,
162
+ ZLinkLocationWriteIntent.Takeover,
163
+ writeSignal
164
+ ),
161
165
  signal
162
166
  );
163
167
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -188,9 +192,9 @@ export class ZLinkFanoutLocationRuntime {
188
192
  }
189
193
  const current = await this.lane.run(() => this.localDescriptors.get(channelName));
190
194
  if (current !== undefined) {
191
- const result = await this.store.updateFanoutPublisher(
192
- current,
193
- ZLinkLocationWriteIntent.Renew,
195
+ const result = await this.locationRuntime.writeDescriptor(
196
+ (writeSignal) =>
197
+ this.store.updateFanoutPublisher(current, ZLinkLocationWriteIntent.Renew, writeSignal),
194
198
  signal
195
199
  );
196
200
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -231,9 +235,13 @@ export class ZLinkFanoutLocationRuntime {
231
235
  leaseGeneration: owner.leaseGeneration,
232
236
  updatedAt: new Date(0)
233
237
  };
234
- const result = await this.store.updateFanoutPublisher(
235
- descriptor,
236
- ZLinkLocationWriteIntent.NewClaim,
238
+ const result = await this.locationRuntime.writeDescriptor(
239
+ (writeSignal) =>
240
+ this.store.updateFanoutPublisher(
241
+ descriptor,
242
+ ZLinkLocationWriteIntent.NewClaim,
243
+ writeSignal
244
+ ),
237
245
  signal
238
246
  );
239
247
  if (result.status !== ZLinkLocationWriteStatus.Stored) {
@@ -2,7 +2,6 @@ import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import { randomBytes } from 'node:crypto';
3
3
  import type { ZLinkFlowOrigin } from '../../contracts';
4
4
  const FLOW_UUID_BYTES = 16;
5
- const FLOW_UUID_VARIANT_BYTE = 8;
6
5
 
7
6
  /**
8
7
  * Spec 27 §3 defines the flow_origin value set as lowercase
@@ -97,13 +96,27 @@ export function createInboundFlow(
97
96
  return { flowId: flowId ?? createFlowId(), flowOrigin: flowOrigin ?? 'Inbound', streamSessionId };
98
97
  }
99
98
 
99
+ /**
100
+ * UUIDv7 with a dedicated counter (RFC 9562 §6.2 method 1): the 48-bit
101
+ * millisecond timestamp, then a 42-bit counter that starts at a random value
102
+ * and spans `rand_a` and the top of `rand_b`, then 32 random bits drawn once
103
+ * per process. Flow ids stay unique within the process without drawing
104
+ * random bytes for every message.
105
+ */
106
+ const flowRandom = randomBytes(FLOW_UUID_BYTES);
107
+ const FLOW_COUNTER_SPAN = 2 ** 42;
108
+ let flowCounter = flowRandom.readUIntBE(0, 6) % FLOW_COUNTER_SPAN;
109
+ const FLOW_ID_TAIL = flowRandom.toString('hex', FLOW_UUID_BYTES - 4);
110
+
100
111
  function createFlowId(): string {
101
- const bytes = randomBytes(FLOW_UUID_BYTES);
112
+ const counter = flowCounter;
113
+ flowCounter = (flowCounter + 1) % FLOW_COUNTER_SPAN;
102
114
  // Date.now() is always within 48 bits, which is exactly the UUIDv7
103
115
  // timestamp field.
104
- bytes.writeUIntBE(Date.now(), 0, 6);
105
- bytes[6] = 0x70 | (bytes[6] & 0x0f);
106
- bytes[FLOW_UUID_VARIANT_BYTE] = 0x80 | (bytes[FLOW_UUID_VARIANT_BYTE] & 0x3f);
107
- const hex = bytes.toString('hex');
108
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
116
+ const timestamp = Date.now().toString(16).padStart(12, '0');
117
+ const randA = Math.floor(counter / 2 ** 30); // 12 bits
118
+ const randB = counter % 2 ** 30; // 30 bits after the 2 variant bits
119
+ const variantHigh = (0x8000 | Math.floor(randB / 2 ** 16)).toString(16);
120
+ const randBLow = (randB % 2 ** 16).toString(16).padStart(4, '0');
121
+ return `${timestamp.slice(0, 8)}-${timestamp.slice(8)}-7${randA.toString(16).padStart(3, '0')}-${variantHigh}-${randBLow}${FLOW_ID_TAIL}`;
109
122
  }
@@ -1,4 +1,3 @@
1
- import { AsyncResource } from 'node:async_hooks';
2
1
  import type {
3
2
  ZLinkLocationRuntimeQuery,
4
3
  ZLinkLocationRuntimeStatus,
@@ -18,7 +17,7 @@ import type {
18
17
  ZLinkSpotLocation
19
18
  } from '../../contracts/Locations/Rows';
20
19
  import type { ZLinkBackendSocketMonitor, ZLinkBackendSocketMonitorEvent } from '../backend';
21
- import { ZLinkStateLane } from '../execution/state-lane';
20
+ import { startOutsideStateLane, ZLinkStateLane } from '../execution/state-lane';
22
21
  import { normalizeOpaqueRoutingId } from '../routing-id';
23
22
  import {
24
23
  ZLinkLocationActorEventKind as ActorLocationEventKind,
@@ -54,7 +53,6 @@ export {
54
53
  } from './internal-event-contracts';
55
54
 
56
55
  const ZLINK_DISCONNECT_REASON_HANDSHAKE_FAILED = 3;
57
- const detachedStateLaneResource = new AsyncResource('zlink:location-runtime-monitoring-source');
58
56
 
59
57
  export interface ZLinkActorOwnerLeaseObservation {
60
58
  readonly actorId: string;
@@ -461,10 +459,6 @@ async function publishLocationRuntimeChange<T>(
461
459
  await publisher.publish(runtimeEvent);
462
460
  }
463
461
 
464
- function startOutsideStateLane<T>(work: () => T): T {
465
- return detachedStateLaneResource.runInAsyncScope(work);
466
- }
467
-
468
462
  function stableSnapshot(value: unknown): string {
469
463
  return JSON.stringify(value, (_key, item) => (typeof item === 'bigint' ? item.toString() : item));
470
464
  }
@@ -13,7 +13,7 @@ import {
13
13
  type ZLinkRuntimeMessageFlowEvent,
14
14
  type ZLinkRuntimeMessageFlowResult
15
15
  } from '../../contracts/Dispatch/ZLinkDispatchOptions';
16
- import { ERROR_MESSAGE_MAX_LENGTH } from './dispatch-error-details';
16
+ import { ERROR_MESSAGE_MAX_LENGTH, dispatchErrorDetails } from './dispatch-error-details';
17
17
  import type { ZLinkDispatchErrorSink } from './dispatch-error-port';
18
18
  import { currentFlowContext, FLOW_ORIGIN_VALUES } from './flow-context';
19
19
  const MESSAGE_FLOW_EVENT_ID = 'zlink.message_flow';
@@ -41,6 +41,7 @@ const telemetryTracer = openTelemetryTrace.getTracer('@zlink-systems/framework')
41
41
  let diagnosticsGeneration = 0n;
42
42
 
43
43
  interface ZLinkTelemetryRecord {
44
+ readonly severity?: 'warning';
44
45
  readonly eventId: typeof MESSAGE_FLOW_EVENT_ID | typeof DISPATCH_ERROR_EVENT_ID;
45
46
  readonly timestamp: Date;
46
47
  readonly phase?: string;
@@ -86,6 +87,15 @@ export function effectiveMessageFlow(ctx: ZLinkDiagnosticsContext): ZLinkMessage
86
87
  return ctx.liveMode.mode;
87
88
  }
88
89
 
90
+ /**
91
+ * Message-flow tracing is on at Normal and Detailed only (04-flow-correlation
92
+ * §4). Below it no flow ID is created, validated, captured or propagated. This
93
+ * is the one decision every flow processing point reads.
94
+ */
95
+ export function messageFlowTracingEnabled(mode: ZLinkMessageFlowLogMode): boolean {
96
+ return MESSAGE_FLOW_MODE_RANK[mode] >= MESSAGE_FLOW_MODE_RANK.normal;
97
+ }
98
+
89
99
  export function createMessageFlowModeCell(
90
100
  dispatch: { diagnostics?: ZLinkDiagnosticsOptions } | undefined
91
101
  ): ZLinkMessageFlowModeCell {
@@ -137,10 +147,33 @@ export interface ZLinkMessageFlowTracePoint {
137
147
  trace(flowInput: MessageFlowInput): void;
138
148
  }
139
149
 
150
+ export function traceSessionBindingControlDrop(
151
+ flow: ZLinkMessageFlowTracer | undefined,
152
+ sourceRid: string,
153
+ actorId: string,
154
+ packetName: string,
155
+ errorReason: 'location_unavailable' | 'stale_target',
156
+ error?: unknown
157
+ ): void {
158
+ const point = flowIfEnabled(flow, ZLinkMessageFlowOutcome.Dropped);
159
+ if (point === undefined) return;
160
+ point.trace({
161
+ outcome: ZLinkMessageFlowOutcome.Dropped,
162
+ surface: ZLinkDispatchErrorSurface.StreamSession,
163
+ messageKind: ZLinkDispatchMessageKind.Control,
164
+ sourceRid,
165
+ actorId,
166
+ packetName,
167
+ errorReason,
168
+ ...dispatchErrorDetails(error)
169
+ });
170
+ }
171
+
140
172
  type MessageFlowInput = Omit<
141
173
  ZLinkRuntimeMessageFlowEvent,
142
174
  'effectiveMode' | 'flowId' | 'flowOrigin'
143
175
  > & {
176
+ readonly severity?: 'warning';
144
177
  readonly effectiveMode?: ZLinkMessageFlowLogMode;
145
178
  readonly flowId?: string;
146
179
  readonly flowOrigin?: import('../../contracts').ZLinkFlowOrigin;
@@ -201,7 +234,7 @@ export class ZLinkMessageFlowTracer {
201
234
  }
202
235
 
203
236
  flowCreationEnabled(): boolean {
204
- return effectiveMessageFlow(this.ctx) !== 'off';
237
+ return messageFlowTracingEnabled(effectiveMessageFlow(this.ctx));
205
238
  }
206
239
 
207
240
  trace(flowInput: MessageFlowInput): void {
@@ -234,7 +267,7 @@ export class ZLinkMessageFlowTracer {
234
267
  const ambient = currentFlowContext();
235
268
  const flowId = flowInput.flowId ?? acceptedFlowId ?? ambient?.flowId;
236
269
  const flowOrigin = flowInput.flowOrigin ?? acceptedFlowOrigin ?? ambient?.flowOrigin;
237
- const flow: ZLinkRuntimeMessageFlowEvent = {
270
+ const flow: MessageFlowInput = {
238
271
  ...flowInput,
239
272
  ...(flowId === undefined ? {} : { flowId, flowOrigin }),
240
273
  streamSessionId: flowInput.streamSessionId ?? ambient?.streamSessionId,
@@ -302,13 +335,17 @@ export class ZLinkMessageFlowTracer {
302
335
 
303
336
  private publishToLogger(record: ZLinkTelemetryRecord): void {
304
337
  try {
305
- const severityNumber =
306
- record.eventId === DISPATCH_ERROR_EVENT_ID ? SeverityNumber.ERROR : SeverityNumber.INFO;
338
+ const severity =
339
+ record.severity === 'warning'
340
+ ? 'WARN'
341
+ : record.eventId === DISPATCH_ERROR_EVENT_ID
342
+ ? 'ERROR'
343
+ : 'INFO';
307
344
  telemetryLogger.emit({
308
345
  eventName: record.eventId,
309
346
  timestamp: record.timestamp,
310
- severityNumber,
311
- severityText: record.eventId === DISPATCH_ERROR_EVENT_ID ? 'ERROR' : 'INFO',
347
+ severityNumber: SeverityNumber[severity],
348
+ severityText: severity,
312
349
  body: structuredLogBody(record),
313
350
  attributes: structuredLogAttributes(record)
314
351
  });
@@ -342,11 +379,12 @@ export class ZLinkMessageFlowTracer {
342
379
  }
343
380
 
344
381
  function toTelemetryRecord(
345
- flow: ZLinkRuntimeMessageFlowEvent,
382
+ flow: MessageFlowInput,
346
383
  messageSizeBytes: number | undefined,
347
384
  durationSeconds: number | undefined
348
385
  ): ZLinkTelemetryRecord {
349
386
  return {
387
+ severity: flow.severity,
350
388
  eventId:
351
389
  flow.outcome === ZLinkMessageFlowOutcome.Error
352
390
  ? DISPATCH_ERROR_EVENT_ID
@@ -387,7 +425,7 @@ function toTelemetryRecord(
387
425
  function traceAttributes(record: ZLinkTelemetryRecord): Attributes {
388
426
  const attributes: Attributes = {};
389
427
  for (const [name, value] of Object.entries(record)) {
390
- if (value === undefined || name === 'timestamp') continue;
428
+ if (value === undefined || name === 'timestamp' || name === 'severity') continue;
391
429
  attributes[toSnakeCase(name)] = value instanceof Date ? value.toISOString() : value;
392
430
  }
393
431
  return attributes;
@@ -51,8 +51,8 @@ export interface ZLinkRuntimeMetricMeshSnapshot {
51
51
  readonly channelName: string;
52
52
  readonly readyMembers: number;
53
53
  }>;
54
- readonly actorCapacity: ZLinkRuntimeMetricCapacity;
55
- readonly spotCapacity: ZLinkRuntimeMetricCapacity;
54
+ readonly actorCapacity?: ZLinkRuntimeMetricCapacity;
55
+ readonly spotCapacity?: ZLinkRuntimeMetricCapacity;
56
56
  readonly spotTypeCapacities: ReadonlyArray<ZLinkRuntimeMetricSpotTypeCapacity>;
57
57
  readonly activation: { readonly active: number; readonly limit: number };
58
58
  readonly instanceSpots: ReadonlyArray<{
@@ -383,14 +383,16 @@ class MetricRegistry {
383
383
  }
384
384
  } else if (name.startsWith('zlink.object.capacity.')) {
385
385
  const field = metricSuffix(name);
386
- result.observe(capacityValue(snapshot.actorCapacity, field), {
387
- ...mesh,
388
- capacity_scope: 'actor'
389
- });
390
- result.observe(capacityValue(snapshot.spotCapacity, field), {
391
- ...mesh,
392
- capacity_scope: 'spot'
393
- });
386
+ if (snapshot.actorCapacity !== undefined)
387
+ result.observe(capacityValue(snapshot.actorCapacity, field), {
388
+ ...mesh,
389
+ capacity_scope: 'actor'
390
+ });
391
+ if (snapshot.spotCapacity !== undefined)
392
+ result.observe(capacityValue(snapshot.spotCapacity, field), {
393
+ ...mesh,
394
+ capacity_scope: 'spot'
395
+ });
394
396
  } else if (name.startsWith('zlink.spot.type.capacity.')) {
395
397
  const field = metricSuffix(name);
396
398
  for (const capacity of snapshot.spotTypeCapacities) {
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { ZLinkConfigurationException } from '../configuration';
3
2
  import { isAbortError } from '../abort';
4
3
  import {
5
4
  ZLinkFrameworkInternalErrorKind,
@@ -53,6 +52,7 @@ export class ZLinkSpotSerialTurn {
53
52
  private suspendedResolve: (() => void) | undefined;
54
53
  private suspendedPromise: Promise<void> | undefined;
55
54
  private suspendSignaled = false;
55
+ private yieldUsed = false;
56
56
  private owner: Promise<unknown> | undefined;
57
57
  private frameworkOperationsBlocked = false;
58
58
 
@@ -115,26 +115,41 @@ export class ZLinkSpotSerialTurn {
115
115
  }
116
116
 
117
117
  resetSuspension(): void {
118
+ this.yieldUsed = false;
118
119
  this.suspendSignaled = false;
119
120
  this.suspendedResolve = undefined;
120
121
  this.suspendedPromise = undefined;
121
122
  }
122
123
 
123
- async yieldPromise<T>(pending: Promise<T>): Promise<T> {
124
- if (!this.yieldAllowed) {
125
- throw new ZLinkConfigurationException(
126
- 'yield requires a SpotWide User Spot or Instance Spot application handler.'
124
+ admitYield(): void {
125
+ const current = spotSerialTurnStorage.getStore();
126
+ if (
127
+ current?.turn !== this ||
128
+ !this.yieldAllowed ||
129
+ !current.executor.isActiveTurn(this, current.turnId) ||
130
+ this.yieldUsed
131
+ ) {
132
+ throw createInternalFrameworkException(
133
+ ZLinkFrameworkInternalErrorKind.InvalidOperation,
134
+ 'Yield requires the current SpotWide application turn and may be used only once per turn.'
127
135
  );
128
136
  }
137
+ this.yieldUsed = true;
138
+ }
139
+
140
+ async yieldPromise<T>(pending: Promise<T>): Promise<T> {
141
+ this.admitYield();
129
142
  return await this.yieldFrameworkPromise(pending);
130
143
  }
131
144
 
132
145
  /** Suspends a turn only for a Framework-owned lifecycle boundary. */
133
146
  async yieldFrameworkPromise<T>(pending: Promise<T>): Promise<T> {
134
147
  this.signalSuspended();
135
- const result = await pending;
136
- await this.awaitResumePermit();
137
- return result;
148
+ try {
149
+ return await pending;
150
+ } finally {
151
+ await this.awaitResumePermit();
152
+ }
138
153
  }
139
154
 
140
155
  async resumeOwnerUntilNextYield(): Promise<void> {
@@ -204,16 +219,18 @@ export function currentZLinkSpotSerialSourceId(): unknown {
204
219
 
205
220
  export function requireZLinkYieldTurn(capturedTurn?: ZLinkSpotSerialTurn): ZLinkSpotSerialTurn {
206
221
  const turn = capturedTurn ?? captureZLinkSpotSerialTurn();
207
- if (turn === undefined || !turn.yieldAllowed) {
208
- throw new ZLinkConfigurationException(
209
- 'yield requires a SpotWide User Spot or Instance Spot application handler.'
222
+ if (turn === undefined) {
223
+ throw createInternalFrameworkException(
224
+ ZLinkFrameworkInternalErrorKind.InvalidOperation,
225
+ 'Yield requires a current SpotWide application turn.'
210
226
  );
211
227
  }
228
+ turn.admitYield();
212
229
  return turn;
213
230
  }
214
231
 
215
232
  export interface ZLinkCapturedExecutionTurn {
216
- yieldPromise<T>(pending: Promise<T>): Promise<T>;
233
+ yieldPromise<T>(operation: () => Promise<T>): Promise<T>;
217
234
  post(callback: () => void): void;
218
235
  }
219
236
 
@@ -223,7 +240,16 @@ export function captureZLinkExecutionTurn(): ZLinkCapturedExecutionTurn | undefi
223
240
  return undefined;
224
241
  }
225
242
  return {
226
- yieldPromise: <T>(pending: Promise<T>) => current.turn.yieldPromise(pending),
243
+ yieldPromise: <T>(operation: () => Promise<T>) => {
244
+ const turn = requireZLinkYieldTurn(current.turn);
245
+ let pending: Promise<T>;
246
+ try {
247
+ pending = operation();
248
+ } catch (error) {
249
+ pending = Promise.reject(error);
250
+ }
251
+ return turn.yieldFrameworkPromise(pending);
252
+ },
227
253
  post: (callback: () => void) => {
228
254
  void current.executor.post(callback);
229
255
  }
@@ -241,7 +267,7 @@ export function isCurrentZLinkSpotSerialTurn(executor: ZLinkSpotSerialTurnExecut
241
267
 
242
268
  export interface ZLinkExecutionBarrierSeal {
243
269
  readonly generation: bigint;
244
- readonly kind: 'close' | 'relocation';
270
+ readonly kind: 'close' | 'relocation' | 'activation';
245
271
  }
246
272
 
247
273
  export interface ZLinkExecutionBarrierClaim {