@zlink-systems/framework 0.29.1 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/LICENSE +150 -68
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
  4. package/dist/contracts/Channels/Calls.d.ts +2 -1
  5. package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -2
  7. package/dist/contracts/Configuration/Configs.d.ts +0 -5
  8. package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
  9. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
  10. package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
  11. package/dist/contracts/Configuration/index.d.ts +1 -1
  12. package/dist/contracts/Handlers/Attributes.d.ts +5 -13
  13. package/dist/contracts/Handlers/Attributes.js +7 -11
  14. package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
  15. package/dist/contracts/Handlers/JsonContract.js +4 -153
  16. package/dist/contracts/Spots/Contracts.d.ts +2 -1
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/internal.js +3 -1
  19. package/dist/nest-integration.d.ts +1 -1
  20. package/dist/nest-integration.js +2 -1
  21. package/dist/runtime/actors/actor-client.d.ts +1 -1
  22. package/dist/runtime/actors/actor-client.js +14 -12
  23. package/dist/runtime/actors/actor-handoff.d.ts +3 -2
  24. package/dist/runtime/actors/actor-handoff.js +15 -7
  25. package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
  26. package/dist/runtime/actors/actor-local-native-join.js +9 -12
  27. package/dist/runtime/actors/actor-remote-wire.js +15 -0
  28. package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
  29. package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
  30. package/dist/runtime/actors/index.d.ts +2 -1
  31. package/dist/runtime/actors/index.js +18 -6
  32. package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
  33. package/dist/runtime/admission.d.ts +1 -1
  34. package/dist/runtime/admission.js +15 -5
  35. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
  36. package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
  37. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
  38. package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
  39. package/dist/runtime/application-jobs/contracts.d.ts +15 -2
  40. package/dist/runtime/backend/contracts/index.d.ts +27 -27
  41. package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
  42. package/dist/runtime/backend/mesh-completion-table.js +160 -50
  43. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
  44. package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
  45. package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
  46. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
  47. package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
  48. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  49. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
  50. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
  51. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
  52. package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
  53. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
  54. package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
  55. package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
  56. package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
  57. package/dist/runtime/backend/runtime-message.d.ts +1 -0
  58. package/dist/runtime/backend/runtime-message.js +5 -0
  59. package/dist/runtime/backend/runtime-values.d.ts +1 -0
  60. package/dist/runtime/backend/runtime-values.js +2 -1
  61. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  62. package/dist/runtime/channels/channel-clients.js +58 -21
  63. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
  64. package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
  65. package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
  66. package/dist/runtime/channels/channel-dispatch-services.js +45 -0
  67. package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
  68. package/dist/runtime/channels/channel-dispatchers.js +27 -26
  69. package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
  70. package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
  71. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  72. package/dist/runtime/channels/channel-envelope.js +83 -8
  73. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  74. package/dist/runtime/channels/channel-outbound-operations.js +8 -8
  75. package/dist/runtime/channels/channel-receive-loops.js +3 -3
  76. package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
  77. package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
  78. package/dist/runtime/channels/channel-runtime-manager.js +12 -12
  79. package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
  80. package/dist/runtime/channels/channel-socket-registry.js +59 -82
  81. package/dist/runtime/channels/channel-transports.d.ts +18 -15
  82. package/dist/runtime/channels/channel-transports.js +48 -31
  83. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  84. package/dist/runtime/channels/local-spot-route-transport.js +2 -1
  85. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
  86. package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
  87. package/dist/runtime/channels/source-spot-router.d.ts +2 -2
  88. package/dist/runtime/channels/source-spot-router.js +4 -4
  89. package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
  90. package/dist/runtime/channels/spot-node-route-transport.js +4 -4
  91. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
  92. package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
  93. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
  94. package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
  95. package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
  96. package/dist/runtime/diagnostics/message-flow.js +3 -3
  97. package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
  98. package/dist/runtime/execution/serial-execution-queue.js +1 -0
  99. package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
  100. package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
  101. package/dist/runtime/foundation/durable-service-request.js +98 -0
  102. package/dist/runtime/foundation/operation-identity.d.ts +1 -0
  103. package/dist/runtime/foundation/operation-identity.js +5 -1
  104. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
  105. package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
  106. package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
  107. package/dist/runtime/foundation/service-liveness-registry.js +57 -44
  108. package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
  109. package/dist/runtime/foundation/service-mailbox.js +2 -1
  110. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
  111. package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
  112. package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
  113. package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
  114. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
  115. package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
  116. package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
  117. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
  118. package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
  119. package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
  120. package/dist/runtime/foundation/service-topology-registry.js +69 -30
  121. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
  122. package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
  123. package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
  124. package/dist/runtime/handlers/handler-instance-scope.js +54 -11
  125. package/dist/runtime/host/actor-packet-relay.js +7 -7
  126. package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
  127. package/dist/runtime/host/application-job-queue.d.ts +28 -9
  128. package/dist/runtime/host/application-job-queue.js +214 -50
  129. package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
  130. package/dist/runtime/host/entry-actor-runtime.js +4 -1
  131. package/dist/runtime/host/index.d.ts +7 -1
  132. package/dist/runtime/host/index.js +154 -126
  133. package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
  134. package/dist/runtime/host/instance-activation-authority.js +89 -25
  135. package/dist/runtime/host/remote-bound-session-relay.js +2 -18
  136. package/dist/runtime/host/route-mesh-runtime.js +1 -1
  137. package/dist/runtime/host/service-relocation-control.d.ts +1 -0
  138. package/dist/runtime/host/service-relocation-control.js +10 -4
  139. package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
  140. package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
  141. package/dist/runtime/host/spot-address-transport.d.ts +1 -0
  142. package/dist/runtime/host/spot-address-transport.js +28 -14
  143. package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
  144. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
  145. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
  146. package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
  147. package/dist/runtime/locations/actor-location-claims.js +34 -19
  148. package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
  149. package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
  150. package/dist/runtime/locations/in-memory-authority-store.js +80 -8
  151. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  152. package/dist/runtime/locations/in-memory-location-store.js +19 -3
  153. package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
  154. package/dist/runtime/locations/lifecycle.d.ts +1 -2
  155. package/dist/runtime/locations/lifecycle.js +2 -5
  156. package/dist/runtime/locations/location-store-repository.d.ts +3 -2
  157. package/dist/runtime/locations/location-store-repository.js +165 -22
  158. package/dist/runtime/locations/resolvers.d.ts +2 -1
  159. package/dist/runtime/locations/resolvers.js +10 -1
  160. package/dist/runtime/locations/runtime.d.ts +1 -1
  161. package/dist/runtime/locations/runtime.js +24 -23
  162. package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
  163. package/dist/runtime/messaging/framework-json-v1.js +38 -294
  164. package/dist/runtime/messaging/packet-name.d.ts +1 -1
  165. package/dist/runtime/messaging/packet-name.js +8 -24
  166. package/dist/runtime/messaging/request-result.d.ts +2 -0
  167. package/dist/runtime/messaging/request-result.js +54 -0
  168. package/dist/runtime/messaging/submission-result.d.ts +2 -1
  169. package/dist/runtime/messaging/submission-result.js +7 -4
  170. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
  171. package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
  172. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
  173. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
  174. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
  175. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
  176. package/dist/runtime/spots/index.d.ts +7 -3
  177. package/dist/runtime/spots/index.js +23 -16
  178. package/dist/runtime/spots/spot-activation.d.ts +3 -1
  179. package/dist/runtime/spots/spot-activation.js +21 -12
  180. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
  181. package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
  182. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
  183. package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
  184. package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
  185. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
  186. package/dist/runtime/spots/spot-entry-activation.js +9 -3
  187. package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
  188. package/dist/runtime/spots/spot-handler-registry.js +18 -8
  189. package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
  190. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
  191. package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
  192. package/dist/runtime/spots/spot-outbound.d.ts +3 -0
  193. package/dist/runtime/spots/spot-outbound.js +24 -15
  194. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
  195. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
  196. package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
  197. package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
  198. package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
  199. package/dist/runtime/spots/spot-timer.js +1 -0
  200. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
  201. package/dist/runtime/streams/stream-session-runtime.js +14 -28
  202. package/package.json +3 -3
  203. package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
  204. package/src/contracts/Channels/Calls.ts +2 -1
  205. package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
  206. package/src/contracts/Configuration/Builders.ts +1 -2
  207. package/src/contracts/Configuration/Configs.ts +0 -6
  208. package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
  209. package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
  210. package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
  211. package/src/contracts/Configuration/index.ts +1 -6
  212. package/src/contracts/Handlers/Attributes.ts +14 -21
  213. package/src/contracts/Handlers/JsonContract.ts +8 -216
  214. package/src/contracts/Spots/Contracts.ts +2 -1
  215. package/src/internal.ts +1 -0
  216. package/src/nest-integration.ts +1 -0
  217. package/src/runtime/actors/actor-client.ts +40 -16
  218. package/src/runtime/actors/actor-handoff.ts +22 -8
  219. package/src/runtime/actors/actor-join-relocation.ts +1 -0
  220. package/src/runtime/actors/actor-local-native-join.ts +17 -26
  221. package/src/runtime/actors/actor-remote-wire.ts +17 -0
  222. package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
  223. package/src/runtime/actors/actor-routed-json-request.ts +10 -2
  224. package/src/runtime/actors/index.ts +19 -5
  225. package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
  226. package/src/runtime/admission.ts +18 -5
  227. package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
  228. package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
  229. package/src/runtime/application-jobs/contracts.ts +28 -2
  230. package/src/runtime/backend/contracts/index.ts +63 -32
  231. package/src/runtime/backend/mesh-completion-table.ts +175 -59
  232. package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
  233. package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
  234. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
  235. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
  236. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
  237. package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
  238. package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
  239. package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
  240. package/src/runtime/backend/raw-binding-port.ts +18 -3
  241. package/src/runtime/backend/runtime-message.ts +6 -0
  242. package/src/runtime/backend/runtime-values.ts +1 -0
  243. package/src/runtime/channels/channel-clients.ts +90 -41
  244. package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
  245. package/src/runtime/channels/channel-dispatch-services.ts +69 -1
  246. package/src/runtime/channels/channel-dispatchers.ts +29 -27
  247. package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
  248. package/src/runtime/channels/channel-envelope.ts +133 -8
  249. package/src/runtime/channels/channel-outbound-operations.ts +22 -8
  250. package/src/runtime/channels/channel-receive-loops.ts +3 -3
  251. package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
  252. package/src/runtime/channels/channel-runtime-manager.ts +29 -12
  253. package/src/runtime/channels/channel-socket-registry.ts +84 -130
  254. package/src/runtime/channels/channel-transports.ts +128 -60
  255. package/src/runtime/channels/local-spot-route-transport.ts +3 -1
  256. package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
  257. package/src/runtime/channels/source-spot-router.ts +8 -4
  258. package/src/runtime/channels/spot-node-route-transport.ts +8 -4
  259. package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
  260. package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
  261. package/src/runtime/diagnostics/message-flow.ts +1 -1
  262. package/src/runtime/execution/serial-execution-queue.ts +2 -0
  263. package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
  264. package/src/runtime/foundation/durable-service-request.ts +137 -0
  265. package/src/runtime/foundation/operation-identity.ts +5 -1
  266. package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
  267. package/src/runtime/foundation/service-liveness-registry.ts +68 -59
  268. package/src/runtime/foundation/service-mailbox.ts +7 -1
  269. package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
  270. package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
  271. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  272. package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
  274. package/src/runtime/foundation/service-topology-registry.ts +103 -42
  275. package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
  276. package/src/runtime/handlers/handler-instance-scope.ts +67 -16
  277. package/src/runtime/host/actor-packet-relay.ts +7 -0
  278. package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
  279. package/src/runtime/host/application-job-queue.ts +249 -48
  280. package/src/runtime/host/entry-actor-runtime.ts +5 -0
  281. package/src/runtime/host/index.ts +224 -160
  282. package/src/runtime/host/instance-activation-authority.ts +132 -27
  283. package/src/runtime/host/remote-bound-session-relay.ts +2 -23
  284. package/src/runtime/host/route-mesh-runtime.ts +1 -1
  285. package/src/runtime/host/service-relocation-control.ts +11 -5
  286. package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
  287. package/src/runtime/host/spot-address-transport.ts +49 -24
  288. package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
  290. package/src/runtime/locations/actor-location-claims.ts +52 -30
  291. package/src/runtime/locations/domain-store-contract.ts +6 -2
  292. package/src/runtime/locations/in-memory-authority-store.ts +113 -9
  293. package/src/runtime/locations/in-memory-location-store.ts +25 -3
  294. package/src/runtime/locations/internal-location-contracts.ts +4 -0
  295. package/src/runtime/locations/lifecycle.ts +8 -26
  296. package/src/runtime/locations/location-store-repository.ts +220 -15
  297. package/src/runtime/locations/resolvers.ts +25 -2
  298. package/src/runtime/locations/runtime.ts +28 -24
  299. package/src/runtime/messaging/framework-json-v1.ts +5 -325
  300. package/src/runtime/messaging/packet-name.ts +5 -25
  301. package/src/runtime/messaging/request-result.ts +58 -0
  302. package/src/runtime/messaging/submission-result.ts +7 -3
  303. package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
  304. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  305. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
  306. package/src/runtime/spots/index.ts +30 -2
  307. package/src/runtime/spots/spot-activation.ts +33 -10
  308. package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
  309. package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
  310. package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
  311. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
  312. package/src/runtime/spots/spot-entry-activation.ts +12 -2
  313. package/src/runtime/spots/spot-handler-registry.ts +41 -8
  314. package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
  315. package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
  316. package/src/runtime/spots/spot-outbound.ts +36 -16
  317. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
  318. package/src/runtime/spots/spot-routing-internal.ts +14 -0
  319. package/src/runtime/spots/spot-runtime-ports.ts +3 -0
  320. package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
  321. package/src/runtime/spots/spot-timer.ts +5 -1
  322. package/src/runtime/streams/stream-session-runtime.ts +13 -30
@@ -7,7 +7,7 @@ const node_async_hooks_1 = require("node:async_hooks");
7
7
  const contracts_1 = require("../../contracts");
8
8
  const service_authority_payload_codec_1 = require("./service-authority-payload-codec");
9
9
  const ZLinkDispatchOptions_1 = require("../../contracts/Dispatch/ZLinkDispatchOptions");
10
- const abort_1 = require("../abort");
10
+ const durable_service_request_1 = require("./durable-service-request");
11
11
  const admission_1 = require("../admission");
12
12
  const runtime_values_1 = require("../backend/runtime-values");
13
13
  const message_flow_1 = require("../diagnostics/message-flow");
@@ -25,7 +25,6 @@ const service_stateful_wire_codec_1 = require("./service-stateful-wire-codec");
25
25
  const service_wire_binary_primitives_1 = require("./service-wire-binary-primitives");
26
26
  const service_wire_constants_generated_1 = require("./service-wire-constants.generated");
27
27
  const service_wire_m6a_codec_1 = require("./service-wire-m6a-codec");
28
- const STATEFUL_OPERATION_RETRY_TICK_MS = 20;
29
28
  const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647;
30
29
  const SPOT_MOVING = 34;
31
30
  const USER_SPOT_OPERATION_CAPACITY = 65_536;
@@ -92,7 +91,7 @@ class ServiceStatefulRuntime {
92
91
  this.operations = new service_stateful_registry_1.ServiceTerminalOperationRegistry(new operation_registry_1.OperationRegistry(undefined, onPendingOperationsChanged));
93
92
  this.registry = new service_stateful_registry_1.ServiceStatefulRegistry(nodeRid, nodeGeneration);
94
93
  this.registry.createEntrySpot(nodeRid);
95
- raw.setServiceIngress((record) => this.ingress(record));
94
+ raw.setServiceIngress((record) => this.ingress(record), acceptsStatefulIngress);
96
95
  }
97
96
  setMailboxDropHandler(handler) {
98
97
  this.mailboxDropHandler = handler;
@@ -345,7 +344,7 @@ class ServiceStatefulRuntime {
345
344
  const record = {
346
345
  kind: 'instanceSpot',
347
346
  activation: 'missing',
348
- target,
347
+ target: { ...target, targetMeshName: envelope.targetMeshName },
349
348
  sourceNodeGeneration: envelope.sourceNodeGeneration,
350
349
  sourceNodeRid: envelope.sourceNodeRid,
351
350
  ...(envelope.sourceSpotId === undefined ? {} : { sourceSpotId: envelope.sourceSpotId }),
@@ -362,7 +361,7 @@ class ServiceStatefulRuntime {
362
361
  flags: envelope.metadataFrame === undefined ? 0 : service_stateful_wire_codec_1.M6bServiceWireFlag.metadata,
363
362
  sourceRoutingId: envelope.sourceNodeRid,
364
363
  parts: [
365
- (0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(target, envelope.sourceNodeGeneration, envelope.sourceNodeRid, envelope.sourceSpotId, envelope.operationKind, envelope.operation, envelope.deadlineUnixMs, envelope.replyRouteId, envelope.metadataFrame !== undefined)
364
+ (0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(record.target, envelope.sourceNodeGeneration, envelope.sourceNodeRid, envelope.sourceSpotId, envelope.operationKind, envelope.operation, envelope.deadlineUnixMs, envelope.replyRouteId, envelope.metadataFrame !== undefined)
366
365
  ],
367
366
  applicationJobOwner
368
367
  }, record, Buffer.from(envelope.applicationPayloadFrame), spot, undefined, terminal.onTerminalCompletion, envelope.metadataFrame === undefined
@@ -679,7 +678,7 @@ class ServiceStatefulRuntime {
679
678
  });
680
679
  return this.submitOneWay(target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
681
680
  }
682
- requestToSpot(sourceSpotId, requested, payload, timeoutMs) {
681
+ requestToSpot(sourceSpotId, requested, payload, timeoutMs, onAdmitted) {
683
682
  const pending = this.operations.register(timeoutMs);
684
683
  const target = this.acceptSpotAuthority(requested);
685
684
  if (target === undefined) {
@@ -690,7 +689,7 @@ class ServiceStatefulRuntime {
690
689
  high: this.nodeGeneration,
691
690
  low: this.nextMessageFollowOperation++
692
691
  });
693
- this.submitRequest(pending, target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'spotRequest');
692
+ this.submitRequest(pending, target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'spotRequest', undefined, onAdmitted);
694
693
  return pending;
695
694
  }
696
695
  async sendToActor(target, _targetNodeGeneration, _authorityOwnerGeneration, payload, sourceActor, boundSession) {
@@ -705,7 +704,7 @@ class ServiceStatefulRuntime {
705
704
  }, { high: this.nodeGeneration, low: this.nextMessageFollowOperation++ });
706
705
  return this.submitOneWay(target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
707
706
  }
708
- requestToActor(target, _targetNodeGeneration, _authorityOwnerGeneration, payload, timeoutMs, sourceActor, boundSession) {
707
+ requestToActor(target, _targetNodeGeneration, _authorityOwnerGeneration, payload, timeoutMs, sourceActor, boundSession, onAdmitted) {
709
708
  const pending = this.operations.register(timeoutMs);
710
709
  const route = this.tryActorFence(target);
711
710
  if (route === undefined) {
@@ -718,7 +717,7 @@ class ServiceStatefulRuntime {
718
717
  ...boundSession,
719
718
  sequence: this.nextSessionSequence++
720
719
  }, { high: this.nodeGeneration, low: this.nextMessageFollowOperation++ });
721
- this.submitRequest(pending, target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'actorRequest');
720
+ this.submitRequest(pending, target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'actorRequest', undefined, onAdmitted);
722
721
  return pending;
723
722
  }
724
723
  async sendToInstanceSpot(route, payload, sourceSpotId, metadataFrame, instanceIntent = false) {
@@ -737,12 +736,12 @@ class ServiceStatefulRuntime {
737
736
  payloadFrame
738
737
  ], metadataFrame));
739
738
  }
740
- requestToInstanceSpot(route, payload, timeoutMs, sourceSpotId, metadataFrame, instanceIntent = false) {
739
+ requestToInstanceSpot(route, payload, timeoutMs, sourceSpotId, metadataFrame, instanceIntent = false, onAdmitted) {
741
740
  const pending = this.operations.register(timeoutMs);
742
741
  this.submitRequest(pending, route.targetNodeRid, instanceOperationParts([
743
742
  (0, service_stateful_wire_codec_1.encodeInstanceSpotHeader)(route, this.nodeGeneration, this.nodeRid, sourceSpotId, 'request', { high: operation_identity_1.ZLINK_NATIVE_CORRELATION_OPERATION_NAMESPACE, low: pending.id }, pending.id, metadataFrame !== undefined, instanceIntent),
744
743
  (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)
745
- ], metadataFrame), timeoutMs, 'instanceSpotRequest');
744
+ ], metadataFrame), timeoutMs, 'instanceSpotRequest', undefined, onAdmitted);
746
745
  return pending;
747
746
  }
748
747
  requestToMissingInstanceSpot(target, payload, timeoutMs, sourceSpotId, metadataFrame) {
@@ -750,13 +749,13 @@ class ServiceStatefulRuntime {
750
749
  const payloadFrame = (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload);
751
750
  return this.requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame);
752
751
  }
753
- requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame) {
752
+ requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame, onAdmitted) {
754
753
  const timeoutMs = remainingDeadlineMs(deadlineUnixMs);
755
754
  const pending = this.operations.register(timeoutMs);
756
755
  this.submitRequest(pending, target.targetNodeRid, instanceOperationParts([
757
756
  (0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(target, this.nodeGeneration, this.nodeRid, sourceSpotId, 'request', { high: operation_identity_1.ZLINK_NATIVE_CORRELATION_OPERATION_NAMESPACE, low: pending.id }, deadlineUnixMs, pending.id, metadataFrame !== undefined),
758
757
  payloadFrame
759
- ], metadataFrame), timeoutMs, 'instanceSpotRequest');
758
+ ], metadataFrame), timeoutMs, 'instanceSpotRequest', undefined, onAdmitted);
760
759
  return pending;
761
760
  }
762
761
  lookupRemoteActor(targetNodeRid, actorId, timeoutMs) {
@@ -1072,25 +1071,6 @@ class ServiceStatefulRuntime {
1072
1071
  this.spotMessageFollow.clear();
1073
1072
  }
1074
1073
  async ingress(record) {
1075
- // These frozen relocation controls overlap the legacy stateful command
1076
- // number range (30-34). They are bare infrastructure records and must
1077
- // fall through to RawServiceMeshRuntime's relocation ingress instead of
1078
- // being decoded as stateful actor/spot work.
1079
- if (record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationReady ||
1080
- record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationData ||
1081
- record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.replyRelay ||
1082
- record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationCutover) {
1083
- return undefined;
1084
- }
1085
- if (record.command < service_stateful_wire_codec_1.M6bServiceWireCommand.spotSend ||
1086
- (record.command > service_stateful_wire_codec_1.M6bServiceWireCommand.instanceSpot &&
1087
- record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotCreate &&
1088
- record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotClose &&
1089
- record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.actorCreate &&
1090
- record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.messageFollow &&
1091
- record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.boundSessionReplaced)) {
1092
- return undefined;
1093
- }
1094
1074
  let decoded;
1095
1075
  let canonicalActorJoin;
1096
1076
  try {
@@ -1329,12 +1309,14 @@ class ServiceStatefulRuntime {
1329
1309
  if (record.activation === 'missing' && this.asyncInstanceAuthority !== undefined) {
1330
1310
  const ownedIngress = shareIngressOwnership(ingress);
1331
1311
  void this.continueMissingInstanceActivation(ownedIngress, record, payloadFrame, localReply, metadataFrame).finally(() => ownedIngress.applicationJobOwner?.close());
1312
+ ingress.onAdmitted?.();
1332
1313
  return 'infrastructure';
1333
1314
  }
1334
1315
  if (record.activation === 'ready' &&
1335
1316
  this.needsInstanceApplicationMaterialization(ingress, record)) {
1336
1317
  const ownedIngress = shareIngressOwnership(ingress);
1337
1318
  void this.continueReadyInstanceMaterialization(ownedIngress, record, payloadFrame, metadataFrame).finally(() => ownedIngress.applicationJobOwner?.close());
1319
+ ingress.onAdmitted?.();
1338
1320
  return 'infrastructure';
1339
1321
  }
1340
1322
  const spot = this.requireInstanceActivation(ingress, record);
@@ -1739,6 +1721,18 @@ class ServiceStatefulRuntime {
1739
1721
  }
1740
1722
  return activation.spot;
1741
1723
  }
1724
+ localReadyInstance(target, route) {
1725
+ const local = this.registry.spot(target.targetSpotId);
1726
+ if (local !== undefined &&
1727
+ (local.kind !== 'instance' || local.stableType !== target.stableType)) {
1728
+ throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
1729
+ }
1730
+ return local !== undefined &&
1731
+ local.state === 'ready' &&
1732
+ routeMatchesLocal(route, local, this.nodeRid, this.nodeGeneration)
1733
+ ? local
1734
+ : undefined;
1735
+ }
1742
1736
  activateMissingInstanceAsync(record, payloadFrame, metadataFrame, admit) {
1743
1737
  const key = record.target.targetSpotId;
1744
1738
  const pending = this.pendingInstanceActivations.get(key);
@@ -1747,7 +1741,15 @@ class ServiceStatefulRuntime {
1747
1741
  ...activation,
1748
1742
  stableType: record.target.stableType
1749
1743
  }));
1750
- const operation = ready.then((value) => {
1744
+ const operation = ready.then(async (value) => {
1745
+ if (pending !== undefined) {
1746
+ await this.asyncInstanceAuthority?.read(record.target, undefined, {
1747
+ ...record,
1748
+ targetMeshName: record.target.targetMeshName,
1749
+ ...(metadataFrame === undefined ? {} : { metadataFrame }),
1750
+ applicationPayloadFrame: payloadFrame
1751
+ }, (route) => this.localReadyInstance(record.target, route) !== undefined);
1752
+ }
1751
1753
  if (value.stableType !== record.target.stableType) {
1752
1754
  throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.TypeMismatch, 'Instance Spot type does not match.');
1753
1755
  }
@@ -1776,8 +1778,14 @@ class ServiceStatefulRuntime {
1776
1778
  if (authority === undefined) {
1777
1779
  throw new Error('Async Instance activation authority is not registered.');
1778
1780
  }
1781
+ const activationRequest = {
1782
+ ...record,
1783
+ targetMeshName: record.target.targetMeshName,
1784
+ ...(metadataFrame === undefined ? {} : { metadataFrame }),
1785
+ applicationPayloadFrame: payloadFrame
1786
+ };
1787
+ const current = await authority.read(target, true, activationRequest, (route) => this.localReadyInstance(target, route) !== undefined);
1779
1788
  const local = this.registry.spot(target.targetSpotId);
1780
- const current = await authority.read(target);
1781
1789
  if (current.kind === 'creating' &&
1782
1790
  current.authority?.allocation.state === 'active' &&
1783
1791
  this.instanceApplicationLifecycle?.isMaterializing?.(target) === true) {
@@ -1821,13 +1829,9 @@ class ServiceStatefulRuntime {
1821
1829
  if (current.route.targetNodeGeneration !== this.nodeGeneration) {
1822
1830
  throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
1823
1831
  }
1824
- if (local !== undefined &&
1825
- (local.kind !== 'instance' || local.stableType !== target.stableType)) {
1826
- throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
1827
- }
1828
- if (local !== undefined &&
1829
- routeMatchesLocal(current.route, local, this.nodeRid, this.nodeGeneration)) {
1830
- return { spot: local, route: current.route };
1832
+ const readyLocal = this.localReadyInstance(target, current.route);
1833
+ if (readyLocal !== undefined) {
1834
+ return { spot: readyLocal, route: current.route };
1831
1835
  }
1832
1836
  return await this.reconcileReadyInstanceProjection(target, current.route, authority);
1833
1837
  }
@@ -1864,18 +1868,7 @@ class ServiceStatefulRuntime {
1864
1868
  const deadline = operationDeadline(record.deadlineUnixMs);
1865
1869
  let reserved;
1866
1870
  try {
1867
- reserved = await authority.reserve({
1868
- target,
1869
- sourceNodeRid: record.sourceNodeRid,
1870
- sourceNodeGeneration: record.sourceNodeGeneration,
1871
- ...(record.sourceSpotId === undefined ? {} : { sourceSpotId: record.sourceSpotId }),
1872
- operationKind: record.operationKind,
1873
- operation: record.operation,
1874
- ...(record.replyRouteId === undefined ? {} : { replyRouteId: record.replyRouteId }),
1875
- deadlineUnixMs: record.deadlineUnixMs,
1876
- ...(metadataFrame === undefined ? {} : { metadataFrame }),
1877
- applicationPayloadFrame: payloadFrame
1878
- }, deadline.signal);
1871
+ reserved = await authority.reserve(activationRequest, deadline.signal);
1879
1872
  }
1880
1873
  finally {
1881
1874
  deadline.close();
@@ -2369,8 +2362,10 @@ class ServiceStatefulRuntime {
2369
2362
  stateful,
2370
2363
  applicationJob
2371
2364
  });
2372
- if (accepted)
2365
+ if (accepted) {
2366
+ ingress.onAdmitted?.();
2373
2367
  return domain;
2368
+ }
2374
2369
  applicationJob.close();
2375
2370
  if (stateful.reply !== undefined) {
2376
2371
  const result = failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Mailbox owner '${owner}' no longer accepts work on this runtime.`));
@@ -2671,57 +2666,11 @@ class ServiceStatefulRuntime {
2671
2666
  }
2672
2667
  }
2673
2668
  async requestDurableOperation(targetNodeRid, parts, correlation, operationKind, deadlineMs) {
2674
- const stop = new AbortController();
2675
- const unobserve = this.raw.observePeerConnectionIntentRemoved((nodeRoutingId) => {
2676
- if (nodeRoutingId === targetNodeRid) {
2677
- stop.abort((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `${operationKind} target node lifecycle ended.`, true));
2678
- }
2679
- });
2680
- let wasAdmitted = false;
2681
- try {
2682
- // Only durable lifecycle operations replay these frozen frames. Received
2683
- // envelopes leave this loop before decoding, including failure terminals.
2684
- for (;;) {
2685
- this.requireOpen();
2686
- stop.signal.throwIfAborted();
2687
- const remainingMs = Math.ceil(deadlineMs - performance.now());
2688
- if (remainingMs <= 0)
2689
- throw durableOperationExhausted(operationKind, wasAdmitted);
2690
- try {
2691
- return await (0, abort_1.awaitWithAbort)(targetNodeRid === this.nodeRid
2692
- ? this.requestLocalInfrastructure(parts[0], correlation, remainingMs)
2693
- : this.raw.requestService(targetNodeRid, parts, remainingMs), stop.signal);
2694
- }
2695
- catch (error) {
2696
- stop.signal.throwIfAborted();
2697
- if (!durableRequestCanReplay(error))
2698
- throw error;
2699
- if (durableRequestWasAdmitted(error))
2700
- wasAdmitted = true;
2701
- const retryDelayMs = Math.min(STATEFUL_OPERATION_RETRY_TICK_MS, deadlineMs - performance.now());
2702
- if (retryDelayMs <= 0) {
2703
- throw durableOperationExhausted(operationKind, wasAdmitted, error);
2704
- }
2705
- let timer;
2706
- try {
2707
- await (0, abort_1.awaitWithAbort)(new Promise((resolve) => {
2708
- timer = setTimeout(resolve, retryDelayMs);
2709
- }), stop.signal);
2710
- }
2711
- finally {
2712
- if (timer !== undefined)
2713
- clearTimeout(timer);
2714
- }
2715
- }
2716
- }
2717
- }
2718
- catch (error) {
2719
- stop.signal.throwIfAborted();
2720
- throw error;
2721
- }
2722
- finally {
2723
- unobserve();
2669
+ this.requireOpen();
2670
+ if (targetNodeRid === this.nodeRid) {
2671
+ return this.requestLocalInfrastructure(parts[0], correlation, Math.ceil(deadlineMs - performance.now()));
2724
2672
  }
2673
+ return (0, durable_service_request_1.requestDurableService)(this.raw, targetNodeRid, parts, deadlineMs, operationKind);
2725
2674
  }
2726
2675
  requestLocalInfrastructure(header, requestSequence, timeoutMs) {
2727
2676
  return new Promise((resolve, reject) => {
@@ -2827,7 +2776,7 @@ class ServiceStatefulRuntime {
2827
2776
  ? runtime_values_1.SubmitResult.Ok
2828
2777
  : runtime_values_1.SubmitResult.NotConnected;
2829
2778
  }
2830
- submitRequest(pending, targetNodeRid, parts, timeoutMs, operationKind, actor) {
2779
+ submitRequest(pending, targetNodeRid, parts, timeoutMs, operationKind, actor, onAdmitted) {
2831
2780
  if (targetNodeRid === this.nodeRid) {
2832
2781
  const deadlineUnixMs = BigInt(Date.now() + Math.max(0, timeoutMs));
2833
2782
  const capacityStop = new AbortController();
@@ -2842,6 +2791,7 @@ class ServiceStatefulRuntime {
2842
2791
  flags: parts[0][service_wire_binary_primitives_1.SERVICE_WIRE_FLAGS_OFFSET],
2843
2792
  sourceRoutingId: this.nodeRid,
2844
2793
  requestSequence: pending.id,
2794
+ onAdmitted,
2845
2795
  parts,
2846
2796
  applicationJobOwner
2847
2797
  };
@@ -2856,7 +2806,7 @@ class ServiceStatefulRuntime {
2856
2806
  })().catch((error) => this.operations.reply(pending.id, failure(error)));
2857
2807
  return;
2858
2808
  }
2859
- void this.raw.requestService(targetNodeRid, parts, timeoutMs).then((reply) => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply), (error) => this.operations.fail(pending.id, error));
2809
+ void this.raw.requestService(targetNodeRid, parts, timeoutMs, onAdmitted).then((reply) => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply), (error) => this.operations.fail(pending.id, error));
2860
2810
  }
2861
2811
  submitActorJoin(pending, actor, targetNodeRid, target, payload, deadlineMs, canonical) {
2862
2812
  const actorRoute = canonical === undefined
@@ -3587,26 +3537,6 @@ function operationDeadline(deadlineUnixMs) {
3587
3537
  function operationReplayExpired(replayExpiresAtMs) {
3588
3538
  return performance.now() > replayExpiresAtMs;
3589
3539
  }
3590
- function durableRequestWasAdmitted(error) {
3591
- // Request NotConnected includes Core handover of an admitted request. The
3592
- // submit/request phase, rather than the result number, owns this distinction.
3593
- return (0, runtime_values_1.isZLinkBackendResultError)(error) && error.operation === 'request';
3594
- }
3595
- function durableOperationExhausted(operationKind, wasAdmitted, cause) {
3596
- return (0, framework_errors_internal_1.createInternalFrameworkException)(wasAdmitted
3597
- ? framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.DeadlineExceeded
3598
- : framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `${operationKind} exhausted its end-to-end deadline.`, true, cause);
3599
- }
3600
- function durableRequestCanReplay(error) {
3601
- if (!(0, runtime_values_1.isZLinkBackendResultError)(error))
3602
- return false;
3603
- return error.operation === 'request'
3604
- ? error.result === runtime_values_1.RequestResult.NotConnected || error.result === runtime_values_1.RequestResult.TimedOut
3605
- : error.result === runtime_values_1.SubmitResult.NotConnected ||
3606
- error.result === runtime_values_1.SubmitResult.NotFound ||
3607
- error.result === runtime_values_1.SubmitResult.NotAdmitted ||
3608
- error.result === runtime_values_1.SubmitResult.Backpressured;
3609
- }
3610
3540
  function remainingDeadlineMs(deadlineUnixMs) {
3611
3541
  const remainingMs = deadlineUnixMs - BigInt(Date.now());
3612
3542
  if (remainingMs <= 0n) {
@@ -3933,3 +3863,25 @@ function instanceOperationParts(headerAndPayload, metadataFrame) {
3933
3863
  function statefulMailboxData(record) {
3934
3864
  return record.stateful;
3935
3865
  }
3866
+ function acceptsStatefulIngress(command) {
3867
+ // These frozen relocation controls overlap the legacy stateful command
3868
+ // number range (30-34). They are bare infrastructure records and must
3869
+ // fall through to RawServiceMeshRuntime's relocation ingress instead of
3870
+ // being decoded as stateful actor/spot work.
3871
+ if (command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationReady ||
3872
+ command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationData ||
3873
+ command === service_stateful_wire_codec_1.M6bServiceWireCommand.replyRelay ||
3874
+ command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationCutover) {
3875
+ return false;
3876
+ }
3877
+ if (command < service_stateful_wire_codec_1.M6bServiceWireCommand.spotSend ||
3878
+ (command > service_stateful_wire_codec_1.M6bServiceWireCommand.instanceSpot &&
3879
+ command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotCreate &&
3880
+ command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotClose &&
3881
+ command !== service_stateful_wire_codec_1.M6bServiceWireCommand.actorCreate &&
3882
+ command !== service_stateful_wire_codec_1.M6bServiceWireCommand.messageFollow &&
3883
+ command !== service_stateful_wire_codec_1.M6bServiceWireCommand.boundSessionReplaced)) {
3884
+ return false;
3885
+ }
3886
+ return true;
3887
+ }
@@ -126,11 +126,6 @@ export interface ServiceMaintenanceRelocationPrepare extends ServiceWireRelocati
126
126
  /** CRC-32C (Castagnoli) over the fully assembled payload bytes. */
127
127
  readonly payloadChecksumCrc32c: number;
128
128
  readonly applicationVersion: bigint;
129
- /** NODE-INTERNAL; serialized as extra frames after canonical command 40. */
130
- readonly nodeInternalBoundSessions?: readonly {
131
- readonly participantKey: string;
132
- readonly payload: Uint8Array;
133
- }[];
134
129
  }
135
130
  export interface ServiceMaintenanceRelocationReady extends ServiceWireRelocationBase {
136
131
  readonly kind: 'ready';
@@ -320,6 +315,9 @@ export interface ServiceInstanceActivationTarget {
320
315
  readonly stableType: string;
321
316
  readonly descriptorVersion: string;
322
317
  }
318
+ export interface ServiceInstanceColdActivationTarget extends ServiceInstanceActivationTarget {
319
+ readonly targetMeshName: string;
320
+ }
323
321
  export interface ServiceUserSpotReservationFence {
324
322
  readonly reservationId: string;
325
323
  readonly expectedStoreVersion: string;
@@ -475,7 +473,7 @@ export type ServiceStatefulWireRecord = {
475
473
  } | {
476
474
  readonly kind: 'instanceSpot';
477
475
  readonly activation: 'missing';
478
- readonly target: ServiceInstanceActivationTarget;
476
+ readonly target: ServiceInstanceColdActivationTarget;
479
477
  readonly sourceNodeGeneration: bigint;
480
478
  readonly sourceNodeRid: string;
481
479
  readonly sourceSpotId?: string;
@@ -549,7 +547,7 @@ export declare function encodeInstanceSpotHeader(route: ServiceInstanceRouteFenc
549
547
  readonly high: bigint;
550
548
  readonly low: bigint;
551
549
  }, replyRouteId?: bigint, hasMetadata?: boolean, instanceIntent?: boolean): Buffer;
552
- export declare function encodeInstanceSpotActivationHeader(target: ServiceInstanceActivationTarget, sourceNodeGeneration: bigint, sourceNodeRid: string, sourceSpotId: string | undefined, operationKind: 'send' | 'request', operation: {
550
+ export declare function encodeInstanceSpotActivationHeader(target: ServiceInstanceColdActivationTarget, sourceNodeGeneration: bigint, sourceNodeRid: string, sourceSpotId: string | undefined, operationKind: 'send' | 'request', operation: {
553
551
  readonly high: bigint;
554
552
  readonly low: bigint;
555
553
  }, deadlineUnixMs: bigint, replyRouteId?: bigint, hasMetadata?: boolean): Buffer;
@@ -47,8 +47,6 @@ const service_wire_constants_generated_1 = require("./service-wire-constants.gen
47
47
  const service_wire_m6a_codec_1 = require("./service-wire-m6a-codec");
48
48
  const MESSAGE_FOLLOW_MAX_BODY_BYTES = 16 * 1024 * 1024;
49
49
  const MESSAGE_FOLLOW_VERSION = 1;
50
- const INSTANCE_ROUTE_VERSION = 1;
51
- const INSTANCE_ACTIVATION_VERSION = 2;
52
50
  const PREFIX_SIZE = service_wire_binary_primitives_1.SERVICE_WIRE_PREFIX_SIZE;
53
51
  const MAGIC_0 = service_wire_constants_generated_1.SERVICE_WIRE_MAGIC[0];
54
52
  const MAGIC_1 = service_wire_constants_generated_1.SERVICE_WIRE_MAGIC[1];
@@ -653,8 +651,17 @@ function encodeInstanceSpotActivationHeader(target, sourceNodeGeneration, source
653
651
  if (operationKind === 'send' && replyRouteId !== undefined) {
654
652
  throw new RangeError('Instance Spot send must not carry a reply route.');
655
653
  }
656
- const targetBody = concat(rid(target.targetNodeRid, 'targetNodeRid'), u64(target.targetNodeGeneration), rid(target.targetSpotId, 'targetSpotId'), text16(target.stableType, 'stableType'), text16(target.descriptorVersion, 'descriptorVersion'));
657
- return concat(prefix(exports.M6bServiceWireCommand.instanceSpot, hasMetadata ? exports.M6bServiceWireFlag.metadata : 0), Buffer.of(INSTANCE_ACTIVATION_VERSION), u16(targetBody.byteLength), targetBody, u64Any(sourceNodeGeneration), rid(sourceNodeRid, 'sourceNodeRid'), optionalRid(sourceSpotId), Buffer.of(operationKind === 'send' ? 1 : 2), u64Any(operation.high), u64Any(operation.low), u64(deadlineUnixMs), ...(operationKind === 'request' ? [u64(requirePositive(replyRouteId, 'replyRouteId'))] : []));
654
+ const encodedRoute = (0, service_wire_codec_generated_1.encodeInstanceRouteV1)({
655
+ routeKind: 'coldActivation',
656
+ targetNodeRid: toGeneratedRoutingId(target.targetNodeRid, 'targetNodeRid'),
657
+ targetNodeGeneration: target.targetNodeGeneration,
658
+ targetSpotId: target.targetSpotId,
659
+ targetMeshName: target.targetMeshName,
660
+ stableType: target.stableType,
661
+ targetDescriptorVersion: target.descriptorVersion,
662
+ deadlineUnixMs
663
+ }, STATEFUL_MESSAGE_CONTEXT);
664
+ return concat(prefix(exports.M6bServiceWireCommand.instanceSpot, hasMetadata ? exports.M6bServiceWireFlag.metadata : 0), encodedRoute, u64Any(sourceNodeGeneration), rid(sourceNodeRid, 'sourceNodeRid'), optionalRid(sourceSpotId), Buffer.of(operationKind === 'send' ? 1 : 2), u64Any(operation.high), u64Any(operation.low), ...(operationKind === 'request' ? [u64(requirePositive(replyRouteId, 'replyRouteId'))] : []));
658
665
  }
659
666
  function encodeUserSpotCreateHeader(record) {
660
667
  return Buffer.from((0, service_wire_pilot_codec_generated_1.encodeUserSpotCreate47)(toGeneratedUserSpotCreate(record)));
@@ -878,45 +885,27 @@ function decodeStatefulHeader(frame, payloadFrame, metadataFrame) {
878
885
  fail(`Invalid command flags '${command.flags}'.`);
879
886
  }
880
887
  const routeStart = reader.offset;
881
- const version = reader.u8('instanceRoute.version');
882
- if (version !== INSTANCE_ROUTE_VERSION && version !== INSTANCE_ACTIVATION_VERSION)
883
- fail('Unsupported Instance route version.');
888
+ reader.u8('instanceRoute.kind');
884
889
  const routeLength = reader.u16('instanceRoute.length');
885
890
  const routeEnd = reader.offset + routeLength;
886
- const generatedReadyRoute = version === INSTANCE_ROUTE_VERSION
887
- ? (0, service_wire_codec_generated_1.decodeInstanceRouteV1)(reader.bytes.subarray(routeStart, routeEnd), STATEFUL_MESSAGE_CONTEXT)
888
- : undefined;
889
- if (generatedReadyRoute !== undefined && generatedReadyRoute.routeKind !== 'ready') {
890
- fail('Invalid Ready Instance route kind.');
891
- }
892
- const commonTarget = generatedReadyRoute?.routeKind === 'ready'
893
- ? {
894
- targetNodeRid: fromGeneratedRoutingId(generatedReadyRoute.targetNodeRid, 'targetNodeRid'),
895
- targetNodeGeneration: generatedReadyRoute.targetNodeGeneration,
896
- targetSpotId: generatedReadyRoute.targetSpotId
897
- }
898
- : {
899
- targetNodeRid: reader.rid('targetNodeRid'),
900
- targetNodeGeneration: reader.nonZeroU64('targetNodeGeneration'),
901
- targetSpotId: reader.rid('targetSpotId')
902
- };
903
- const route = generatedReadyRoute?.routeKind === 'ready'
904
- ? {
905
- ...commonTarget,
906
- ...generatedReadyRoute.authority
907
- }
891
+ const generatedRoute = decodeCanonicalInstanceRoute(reader.bytes.subarray(routeStart, routeEnd));
892
+ const commonTarget = {
893
+ targetNodeRid: fromGeneratedRoutingId(generatedRoute.targetNodeRid, 'targetNodeRid'),
894
+ targetNodeGeneration: generatedRoute.targetNodeGeneration,
895
+ targetSpotId: generatedRoute.targetSpotId
896
+ };
897
+ const route = generatedRoute.routeKind === 'ready'
898
+ ? { ...commonTarget, ...generatedRoute.authority }
908
899
  : undefined;
909
- const target = version === INSTANCE_ACTIVATION_VERSION
900
+ const target = generatedRoute.routeKind === 'coldActivation'
910
901
  ? {
911
902
  ...commonTarget,
912
- stableType: reader.text16('stableType'),
913
- descriptorVersion: reader.text16('descriptorVersion')
903
+ targetMeshName: generatedRoute.targetMeshName,
904
+ stableType: generatedRoute.stableType,
905
+ descriptorVersion: generatedRoute.targetDescriptorVersion
914
906
  }
915
907
  : undefined;
916
- if (generatedReadyRoute !== undefined)
917
- reader.offset = routeEnd;
918
- if (reader.offset !== routeEnd)
919
- fail('Invalid Instance route body length.');
908
+ reader.offset = routeEnd;
920
909
  const sourceNodeGeneration = reader.nonZeroU64('sourceNodeGeneration');
921
910
  const sourceNodeRid = reader.rid('sourceNodeRid');
922
911
  const sourceSpotId = reader.optionalRid('sourceSpotId');
@@ -928,17 +917,17 @@ function decodeStatefulHeader(frame, payloadFrame, metadataFrame) {
928
917
  low: reader.u64('operation.low')
929
918
  };
930
919
  const operationKind = operationValue === 1 ? 'send' : 'request';
931
- if (version === INSTANCE_ROUTE_VERSION &&
920
+ if (generatedRoute.routeKind === 'ready' &&
932
921
  ((operationKind === 'send' && (operation.high !== 0n || operation.low !== 0n)) ||
933
922
  (operationKind === 'request' && operation.high === 0n && operation.low === 0n))) {
934
923
  fail('Invalid Instance operation identity.');
935
924
  }
936
- if (version === INSTANCE_ACTIVATION_VERSION &&
925
+ if (generatedRoute.routeKind === 'coldActivation' &&
937
926
  operation.high === 0n &&
938
927
  operation.low === 0n) {
939
928
  fail('Instance activation requires a non-zero operation identity.');
940
929
  }
941
- const deadlineUnixMs = version === INSTANCE_ACTIVATION_VERSION ? reader.nonZeroU64('deadlineUnixMs') : undefined;
930
+ const deadlineUnixMs = generatedRoute.routeKind === 'coldActivation' ? generatedRoute.deadlineUnixMs : undefined;
942
931
  const replyRouteId = operationKind === 'request' ? reader.nonZeroU64('replyRouteId') : undefined;
943
932
  reader.end();
944
933
  const common = {
@@ -950,12 +939,12 @@ function decodeStatefulHeader(frame, payloadFrame, metadataFrame) {
950
939
  operation,
951
940
  ...(replyRouteId === undefined ? {} : { replyRouteId })
952
941
  };
953
- return version === INSTANCE_ROUTE_VERSION
942
+ return generatedRoute.routeKind === 'ready'
954
943
  ? {
955
944
  ...common,
956
945
  activation: 'ready',
957
946
  route: route,
958
- instanceIntent: generatedReadyRoute.instanceIntent === 'true'
947
+ instanceIntent: generatedRoute.instanceIntent === 'true'
959
948
  }
960
949
  : {
961
950
  ...common,
@@ -1375,10 +1364,6 @@ function rid(value, name) {
1375
1364
  function text8(value, name) {
1376
1365
  return sized8(value, name);
1377
1366
  }
1378
- function text16(value, name) {
1379
- const bytes = (0, service_wire_binary_primitives_1.encodeCanonicalServiceWireText)(value, name, 0xffff, outOfRange);
1380
- return concat(u16(bytes.byteLength), bytes);
1381
- }
1382
1367
  function optionalRid(value) {
1383
1368
  return value === undefined ? Buffer.of(0) : rid(value, 'sourceSpotId');
1384
1369
  }
@@ -1428,6 +1413,16 @@ function requireFlags(actual, expected) {
1428
1413
  function concat(...parts) {
1429
1414
  return Buffer.concat(parts.map((part) => Buffer.from(part)));
1430
1415
  }
1416
+ function decodeCanonicalInstanceRoute(bytes) {
1417
+ try {
1418
+ return (0, service_wire_codec_generated_1.decodeInstanceRouteV1)(bytes, STATEFUL_MESSAGE_CONTEXT);
1419
+ }
1420
+ catch (error) {
1421
+ if (error instanceof RangeError)
1422
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError(error.message);
1423
+ throw error;
1424
+ }
1425
+ }
1431
1426
  function fail(message) {
1432
1427
  throw new service_wire_m6a_codec_1.ServiceWireProtocolError(message);
1433
1428
  }
@@ -2009,22 +2004,9 @@ class FrozenReader {
2009
2004
  }
2010
2005
  instanceRoute() {
2011
2006
  const start = this.offset;
2012
- const kind = this.u8('instanceRouteKind');
2013
- if (kind < 1 || kind > 2)
2014
- fail('Invalid Instance route kind.');
2015
- const body = this.body16('Instance route');
2016
- if (kind === INSTANCE_ROUTE_VERSION) {
2017
- (0, service_wire_codec_generated_1.decodeInstanceRouteV1)(this.bytes.subarray(start, this.offset), STATEFUL_MESSAGE_CONTEXT);
2018
- return;
2019
- }
2020
- body.rid8('targetNodeRid');
2021
- body.nonZeroU64('targetNodeGeneration');
2022
- body.text8('targetSpotId');
2023
- body.text8('targetMeshName');
2024
- body.text8('stableType');
2025
- body.text8('targetDescriptorVersion');
2026
- body.nonZeroU64('deadlineUnixMs');
2027
- body.end('Instance route');
2007
+ this.u8('instanceRouteKind');
2008
+ this.body16('Instance route');
2009
+ decodeCanonicalInstanceRoute(this.bytes.subarray(start, this.offset));
2028
2010
  }
2029
2011
  relocationObject() {
2030
2012
  const kind = this.u8('relocationObjectKind');
@@ -1,3 +1,4 @@
1
+ import type { ServiceLivenessConnection } from './service-liveness-registry';
1
2
  export type ServiceNodeState = 'preparing' | 'serving' | 'retiring' | 'draining' | 'stopped' | 'error';
2
3
  export type ServiceObjectRole = 'none' | 'client' | 'server';
3
4
  export interface ServiceChannelDescriptor {
@@ -23,9 +24,15 @@ export interface ServiceNodeDescriptor {
23
24
  readonly activeCapacityUsed: number;
24
25
  readonly pendingCapacityUsed: number;
25
26
  }
26
- export interface AdmittedServicePeer {
27
+ interface ServiceRouteAdmission {
27
28
  readonly descriptor: ServiceNodeDescriptor;
28
- readonly connectionId: string;
29
+ readonly descriptorBytes?: Uint8Array;
30
+ readonly connectionId?: string | bigint;
31
+ readonly remoteAdmitReceived?: boolean;
32
+ }
33
+ export interface AdmittedServicePeer extends ServiceRouteAdmission {
34
+ readonly connectionId: string | bigint;
35
+ readonly liveness?: ServiceLivenessConnection;
29
36
  }
30
37
  export interface ServicePeerAdmissionExpectation {
31
38
  readonly endpoint?: string;
@@ -44,15 +51,19 @@ export declare class ServiceTopologyRegistry {
44
51
  constructor(local: ServiceNodeDescriptor);
45
52
  localDescriptor(): ServiceNodeDescriptor;
46
53
  publishLocal(descriptor: ServiceNodeDescriptor): void;
47
- admit(descriptor: ServiceNodeDescriptor, connectionId: string, expected?: ServicePeerAdmissionExpectation): PeerAdmissionResult;
48
- disconnect(nodeRoutingId: string, connectionId: string): boolean;
54
+ admit(descriptor: ServiceNodeDescriptor, connectionId: string | bigint, expected?: ServicePeerAdmissionExpectation, admitLiveness?: () => ServiceLivenessConnection, command?: number, descriptorBytes?: Uint8Array): PeerAdmissionResult;
55
+ disconnect(nodeRoutingId: string, connectionId: string | bigint): boolean;
49
56
  peer(nodeRoutingId: string): AdmittedServicePeer | undefined;
57
+ routeAdmission(nodeRoutingId: string): ServiceRouteAdmission | undefined;
58
+ admittedPeer(nodeRoutingId: string): AdmittedServicePeer | undefined;
50
59
  peers(): readonly AdmittedServicePeer[];
51
60
  private peersCore;
52
61
  notRequiredPeers(): readonly ServiceNodeDescriptor[];
53
62
  replaceDiscoveredNotRequired(descriptors: readonly ServiceNodeDescriptor[]): void;
54
63
  forgetNotRequired(nodeRoutingId: string): void;
55
64
  knownDescriptor(nodeRoutingId: string): ServiceNodeDescriptor | undefined;
65
+ isObjectClientNodeDirectTarget(nodeRoutingId: string): boolean;
66
+ private knownPeerDescriptor;
56
67
  hasKnownChannelTarget(channelName: string): boolean;
57
68
  private remember;
58
69
  selectChannel(channelName: string, isReady?: (peer: AdmittedServicePeer) => boolean): AdmittedServicePeer | undefined;
@@ -70,3 +81,4 @@ export declare class ServiceTopologyRegistry {
70
81
  }
71
82
  export declare function validateDescriptor(descriptor: ServiceNodeDescriptor): void;
72
83
  export declare function sameServiceNodeDescriptor(left: ServiceNodeDescriptor, right: ServiceNodeDescriptor): boolean;
84
+ export {};