@zlink-systems/framework 0.30.3 → 0.32.0

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 (398) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Actors/ZLinkActor.d.ts +2 -0
  3. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.d.ts +6 -0
  4. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.js +2 -0
  5. package/dist/contracts/Actors/index.d.ts +1 -0
  6. package/dist/contracts/Actors/index.js +1 -0
  7. package/dist/contracts/Common/CoreTypes.d.ts +1 -0
  8. package/dist/contracts/Common/HandlerMessageType.d.ts +8 -0
  9. package/dist/contracts/Common/HandlerMessageType.js +41 -0
  10. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +1 -1
  11. package/dist/contracts/Common/ZLinkEncodedPayload.js +12 -20
  12. package/dist/contracts/Common/ZLinkMessage.js +11 -7
  13. package/dist/contracts/Common/encoded-payload-storage.d.ts +0 -2
  14. package/dist/contracts/Common/encoded-payload-storage.js +4 -16
  15. package/dist/contracts/Common/index.d.ts +1 -1
  16. package/dist/contracts/Common/payload-slab.d.ts +4 -0
  17. package/dist/contracts/Common/payload-slab.js +30 -0
  18. package/dist/contracts/Configuration/RegistrationBuilders.js +15 -9
  19. package/dist/contracts/Configuration/RegistrationTypes.d.ts +19 -0
  20. package/dist/contracts/Handlers/Contexts.d.ts +1 -0
  21. package/dist/contracts/Locations/Authority.d.ts +2 -0
  22. package/dist/internal.d.ts +9 -0
  23. package/dist/internal.js +23 -1
  24. package/dist/nest-integration.d.ts +1 -0
  25. package/dist/nest-integration.js +3 -1
  26. package/dist/runtime/actors/actor-client.d.ts +6 -2
  27. package/dist/runtime/actors/actor-client.js +120 -82
  28. package/dist/runtime/actors/actor-context.js +16 -5
  29. package/dist/runtime/actors/actor-execution-context.js +2 -2
  30. package/dist/runtime/actors/actor-handoff.d.ts +12 -1
  31. package/dist/runtime/actors/actor-handoff.js +79 -34
  32. package/dist/runtime/actors/actor-join-deferred-scope.js +6 -6
  33. package/dist/runtime/actors/actor-local-native-join.d.ts +2 -2
  34. package/dist/runtime/actors/actor-local-native-join.js +19 -17
  35. package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
  36. package/dist/runtime/actors/actor-remote-joiner.d.ts +2 -2
  37. package/dist/runtime/actors/actor-remote-joiner.js +4 -4
  38. package/dist/runtime/actors/actor-routed-join-transport.d.ts +9 -3
  39. package/dist/runtime/actors/actor-routed-json-request.d.ts +3 -0
  40. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -2
  41. package/dist/runtime/actors/actor-runtime-state.d.ts +1 -1
  42. package/dist/runtime/actors/spot-actor-dispatch.d.ts +9 -5
  43. package/dist/runtime/actors/spot-actor-dispatch.js +60 -38
  44. package/dist/runtime/admission.d.ts +6 -4
  45. package/dist/runtime/admission.js +21 -10
  46. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
  47. package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
  48. package/dist/runtime/backend/contracts/index.d.ts +26 -10
  49. package/dist/runtime/backend/mesh-completion-table.d.ts +7 -1
  50. package/dist/runtime/backend/mesh-completion-table.js +84 -20
  51. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +19 -6
  52. package/dist/runtime/backend/mesh-dispatch-pump.js +246 -147
  53. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -2
  54. package/dist/runtime/backend/node/node-backend-adapter-support.js +27 -19
  55. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +5 -2
  56. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +70 -13
  57. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  58. package/dist/runtime/backend/node/node-event-loop-poller.js +4 -3
  59. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
  60. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
  61. package/dist/runtime/backend/node/node-raw-binding-port.js +99 -63
  62. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +34 -16
  63. package/dist/runtime/backend/node/node-raw-mesh-backend.js +210 -106
  64. package/dist/runtime/backend/node/node-socket-backend-adapter.js +20 -6
  65. package/dist/runtime/backend/raw-binding-port.d.ts +6 -3
  66. package/dist/runtime/channels/channel-clients.js +3 -3
  67. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +11 -7
  68. package/dist/runtime/channels/channel-dispatch-pipeline.js +40 -22
  69. package/dist/runtime/channels/channel-dispatch-services.d.ts +3 -1
  70. package/dist/runtime/channels/channel-dispatch-services.js +7 -6
  71. package/dist/runtime/channels/channel-dispatchers.d.ts +13 -6
  72. package/dist/runtime/channels/channel-dispatchers.js +57 -36
  73. package/dist/runtime/channels/channel-envelope.d.ts +2 -2
  74. package/dist/runtime/channels/channel-envelope.js +609 -83
  75. package/dist/runtime/channels/channel-multipart.d.ts +1 -0
  76. package/dist/runtime/channels/channel-multipart.js +10 -6
  77. package/dist/runtime/channels/channel-outbound-operations.d.ts +6 -9
  78. package/dist/runtime/channels/channel-outbound-operations.js +107 -105
  79. package/dist/runtime/channels/channel-receive-loops.d.ts +9 -7
  80. package/dist/runtime/channels/channel-receive-loops.js +126 -90
  81. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +23 -6
  82. package/dist/runtime/channels/channel-runtime-lifecycle.js +47 -38
  83. package/dist/runtime/channels/channel-runtime-manager.d.ts +13 -6
  84. package/dist/runtime/channels/channel-runtime-manager.js +32 -14
  85. package/dist/runtime/channels/channel-socket-registry.d.ts +28 -4
  86. package/dist/runtime/channels/channel-socket-registry.js +9 -1
  87. package/dist/runtime/channels/channel-transports.d.ts +23 -16
  88. package/dist/runtime/channels/channel-transports.js +139 -119
  89. package/dist/runtime/channels/dispatch-error-reporter.d.ts +4 -4
  90. package/dist/runtime/channels/dispatch-error-reporter.js +5 -5
  91. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  92. package/dist/runtime/channels/local-spot-route-transport.d.ts +5 -2
  93. package/dist/runtime/channels/local-spot-route-transport.js +15 -18
  94. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +6 -3
  95. package/dist/runtime/channels/router-socket-spot-route-transport.js +33 -19
  96. package/dist/runtime/channels/source-spot-router.d.ts +6 -3
  97. package/dist/runtime/channels/source-spot-router.js +34 -23
  98. package/dist/runtime/channels/spot-node-route-transport.d.ts +6 -3
  99. package/dist/runtime/channels/spot-node-route-transport.js +23 -17
  100. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +6 -3
  101. package/dist/runtime/channels/spot-route-bridge-transport.js +38 -24
  102. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +8 -4
  103. package/dist/runtime/channels/spot-route-dispatch-strategy.js +36 -23
  104. package/dist/runtime/diagnostics/dispatch-error-details.js +9 -3
  105. package/dist/runtime/diagnostics/message-flow-bootstrap.d.ts +1 -0
  106. package/dist/runtime/diagnostics/message-flow-bootstrap.js +8 -0
  107. package/dist/runtime/diagnostics/message-flow-delivery.d.ts +47 -0
  108. package/dist/runtime/diagnostics/message-flow-delivery.js +149 -0
  109. package/dist/runtime/diagnostics/message-flow-record.d.ts +50 -0
  110. package/dist/runtime/diagnostics/message-flow-record.js +228 -0
  111. package/dist/runtime/diagnostics/message-flow-worker.d.ts +1 -0
  112. package/dist/runtime/diagnostics/message-flow-worker.js +118 -0
  113. package/dist/runtime/diagnostics/message-flow.d.ts +7 -19
  114. package/dist/runtime/diagnostics/message-flow.js +42 -290
  115. package/dist/runtime/diagnostics/runtime-metrics.d.ts +4 -3
  116. package/dist/runtime/diagnostics/runtime-metrics.js +8 -4
  117. package/dist/runtime/execution/index.d.ts +1 -0
  118. package/dist/runtime/execution/index.js +6 -3
  119. package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
  120. package/dist/runtime/execution/serial-execution-queue.js +75 -71
  121. package/dist/runtime/foundation/durable-service-request.d.ts +12 -3
  122. package/dist/runtime/foundation/durable-service-request.js +158 -73
  123. package/dist/runtime/foundation/operation-registry.d.ts +33 -3
  124. package/dist/runtime/foundation/operation-registry.js +272 -33
  125. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +62 -23
  126. package/dist/runtime/foundation/raw-service-mesh-runtime.js +373 -194
  127. package/dist/runtime/foundation/request-runtime.d.ts +17 -0
  128. package/dist/runtime/foundation/request-runtime.js +163 -0
  129. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  130. package/dist/runtime/foundation/service-discovery-registry.js +6 -0
  131. package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
  132. package/dist/runtime/foundation/service-mailbox.d.ts +4 -2
  133. package/dist/runtime/foundation/service-mailbox.js +4 -1
  134. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -2
  135. package/dist/runtime/foundation/service-relocation-object-owner.js +12 -5
  136. package/dist/runtime/foundation/service-runtime-contracts.d.ts +7 -2
  137. package/dist/runtime/foundation/service-stateful-registry.d.ts +6 -2
  138. package/dist/runtime/foundation/service-stateful-registry.js +38 -17
  139. package/dist/runtime/foundation/service-stateful-runtime.d.ts +91 -26
  140. package/dist/runtime/foundation/service-stateful-runtime.js +245 -120
  141. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
  142. package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
  143. package/dist/runtime/foundation/service-topology-registry.d.ts +2 -0
  144. package/dist/runtime/foundation/service-topology-registry.js +13 -3
  145. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  146. package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
  147. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +5 -1
  148. package/dist/runtime/foundation/service-wire-m6a-codec.js +50 -15
  149. package/dist/runtime/host/actor-packet-relay.d.ts +5 -6
  150. package/dist/runtime/host/actor-packet-relay.js +58 -57
  151. package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
  152. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  153. package/dist/runtime/host/actor-runtime-options-factory.js +3 -2
  154. package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
  155. package/dist/runtime/host/application-job-queue.d.ts +7 -5
  156. package/dist/runtime/host/application-job-queue.js +33 -21
  157. package/dist/runtime/host/bound-session-relay.js +0 -1
  158. package/dist/runtime/host/channel-runtime-options-factory.d.ts +2 -0
  159. package/dist/runtime/host/channel-runtime-options-factory.js +1 -0
  160. package/dist/runtime/host/entry-actor-runtime.d.ts +5 -2
  161. package/dist/runtime/host/entry-actor-runtime.js +2 -2
  162. package/dist/runtime/host/index.d.ts +106 -37
  163. package/dist/runtime/host/index.js +303 -151
  164. package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
  165. package/dist/runtime/host/location-runtime-owner.js +1 -1
  166. package/dist/runtime/host/service-relocation-host-runtime.d.ts +195 -45
  167. package/dist/runtime/host/service-relocation-host-runtime.js +257 -144
  168. package/dist/runtime/host/spot-address-transport.d.ts +3 -0
  169. package/dist/runtime/host/spot-address-transport.js +73 -76
  170. package/dist/runtime/host/spot-runtime-options-factory.js +2 -0
  171. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -1
  172. package/dist/runtime/host/user-spot-creation-coordinator.js +49 -21
  173. package/dist/runtime/internal-observation.d.ts +1 -0
  174. package/dist/runtime/internal-observation.js +5 -0
  175. package/dist/runtime/locations/actor-location-claims.d.ts +1 -1
  176. package/dist/runtime/locations/actor-location-claims.js +15 -6
  177. package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
  178. package/dist/runtime/locations/auto-connect-loop.js +25 -19
  179. package/dist/runtime/locations/auto-connect-planner.js +2 -5
  180. package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
  181. package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
  182. package/dist/runtime/locations/in-memory-authority-store.d.ts +1 -0
  183. package/dist/runtime/locations/in-memory-authority-store.js +15 -5
  184. package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
  185. package/dist/runtime/locations/in-memory-location-store.js +1 -38
  186. package/dist/runtime/locations/lifecycle.d.ts +1 -1
  187. package/dist/runtime/locations/lifecycle.js +2 -2
  188. package/dist/runtime/locations/location-store-repository.d.ts +0 -1
  189. package/dist/runtime/locations/location-store-repository.js +163 -246
  190. package/dist/runtime/locations/resolvers.d.ts +8 -1
  191. package/dist/runtime/locations/resolvers.js +16 -2
  192. package/dist/runtime/locations/runtime.d.ts +3 -3
  193. package/dist/runtime/locations/runtime.js +12 -16
  194. package/dist/runtime/messaging/creation-payload-codec.js +8 -7
  195. package/dist/runtime/messaging/framework-json-v1.d.ts +1 -1
  196. package/dist/runtime/messaging/framework-json-v1.js +6 -2
  197. package/dist/runtime/messaging/payload-codec.js +21 -35
  198. package/dist/runtime/messaging/request-deadline.d.ts +4 -2
  199. package/dist/runtime/messaging/request-deadline.js +40 -25
  200. package/dist/runtime/messaging/request-result.d.ts +14 -1
  201. package/dist/runtime/messaging/request-result.js +74 -13
  202. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
  203. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
  204. package/dist/runtime/spots/index.d.ts +28 -7
  205. package/dist/runtime/spots/index.js +31 -6
  206. package/dist/runtime/spots/spot-activation-registry.d.ts +3 -2
  207. package/dist/runtime/spots/spot-activation-registry.js +13 -8
  208. package/dist/runtime/spots/spot-activation-state.d.ts +2 -0
  209. package/dist/runtime/spots/spot-activation-state.js +1 -0
  210. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +9 -4
  211. package/dist/runtime/spots/spot-actor-admission-coordinator.js +33 -12
  212. package/dist/runtime/spots/spot-actor-ingress-admission.d.ts +40 -0
  213. package/dist/runtime/spots/spot-actor-ingress-admission.js +78 -0
  214. package/dist/runtime/spots/spot-actor-membership.js +3 -3
  215. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +16 -43
  216. package/dist/runtime/spots/spot-actor-packet-dispatch.js +56 -113
  217. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
  218. package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
  219. package/dist/runtime/spots/spot-entry-activation.d.ts +4 -3
  220. package/dist/runtime/spots/spot-entry-activation.js +7 -12
  221. package/dist/runtime/spots/spot-handler-registry.d.ts +5 -1
  222. package/dist/runtime/spots/spot-handler-registry.js +31 -15
  223. package/dist/runtime/spots/spot-manager-public.js +3 -2
  224. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +11 -6
  225. package/dist/runtime/spots/spot-node-runtime-manager.js +6 -1
  226. package/dist/runtime/spots/spot-outbound.d.ts +8 -2
  227. package/dist/runtime/spots/spot-outbound.js +5 -5
  228. package/dist/runtime/spots/spot-route-packet-dispatch.js +13 -8
  229. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +3 -3
  230. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +9 -5
  231. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -2
  232. package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
  233. package/dist/runtime/spots/spot-serial-turn-executor.js +20 -26
  234. package/dist/runtime/spots/spot-subscription-dispatch.js +5 -2
  235. package/dist/runtime/spots/spot-timer.d.ts +1 -1
  236. package/dist/runtime/streams/actor-session-binding-registry.d.ts +11 -3
  237. package/dist/runtime/streams/actor-session-binding-registry.js +28 -0
  238. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
  239. package/dist/runtime/streams/bound-actor-relay-sender.js +3 -4
  240. package/dist/runtime/streams/bound-session-service.js +6 -7
  241. package/dist/runtime/streams/index.d.ts +3 -3
  242. package/dist/runtime/streams/index.js +22 -2
  243. package/dist/runtime/streams/managed-stream.js +2 -1
  244. package/dist/runtime/streams/session-calls.d.ts +1 -1
  245. package/dist/runtime/streams/session-calls.js +3 -9
  246. package/dist/runtime/streams/session-context.d.ts +2 -2
  247. package/dist/runtime/streams/session-context.js +2 -2
  248. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
  249. package/dist/runtime/streams/stream-session-runtime.js +64 -33
  250. package/package.json +3 -3
  251. package/src/contracts/Actors/ZLinkActor.ts +6 -0
  252. package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
  253. package/src/contracts/Actors/index.ts +1 -0
  254. package/src/contracts/Common/CoreTypes.ts +1 -0
  255. package/src/contracts/Common/HandlerMessageType.ts +50 -0
  256. package/src/contracts/Common/ZLinkEncodedPayload.ts +13 -25
  257. package/src/contracts/Common/ZLinkMessage.ts +11 -7
  258. package/src/contracts/Common/encoded-payload-storage.ts +4 -16
  259. package/src/contracts/Common/index.ts +1 -1
  260. package/src/contracts/Common/payload-slab.ts +29 -0
  261. package/src/contracts/Configuration/RegistrationBuilders.ts +29 -15
  262. package/src/contracts/Configuration/RegistrationTypes.ts +19 -0
  263. package/src/contracts/Handlers/Contexts.ts +1 -0
  264. package/src/contracts/Locations/Authority.ts +7 -1
  265. package/src/internal.ts +17 -0
  266. package/src/nest-integration.ts +1 -0
  267. package/src/runtime/actors/actor-client.ts +257 -163
  268. package/src/runtime/actors/actor-context.ts +26 -14
  269. package/src/runtime/actors/actor-execution-context.ts +2 -2
  270. package/src/runtime/actors/actor-handoff.ts +86 -51
  271. package/src/runtime/actors/actor-join-deferred-scope.ts +6 -6
  272. package/src/runtime/actors/actor-local-native-join.ts +38 -17
  273. package/src/runtime/actors/actor-mailbox.ts +1 -1
  274. package/src/runtime/actors/actor-remote-joiner.ts +8 -4
  275. package/src/runtime/actors/actor-routed-join-transport.ts +13 -5
  276. package/src/runtime/actors/actor-routed-json-request.ts +3 -0
  277. package/src/runtime/actors/actor-runtime-contracts.ts +4 -2
  278. package/src/runtime/actors/actor-runtime-state.ts +1 -1
  279. package/src/runtime/actors/spot-actor-dispatch.ts +70 -68
  280. package/src/runtime/admission.ts +42 -15
  281. package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
  282. package/src/runtime/backend/contracts/index.ts +77 -10
  283. package/src/runtime/backend/mesh-completion-table.ts +106 -15
  284. package/src/runtime/backend/mesh-dispatch-pump.ts +294 -146
  285. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -32
  286. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +91 -34
  287. package/src/runtime/backend/node/node-event-loop-poller.ts +14 -5
  288. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
  289. package/src/runtime/backend/node/node-raw-binding-port.ts +180 -69
  290. package/src/runtime/backend/node/node-raw-mesh-backend.ts +386 -157
  291. package/src/runtime/backend/node/node-socket-backend-adapter.ts +56 -11
  292. package/src/runtime/backend/raw-binding-port.ts +13 -5
  293. package/src/runtime/channels/channel-clients.ts +26 -11
  294. package/src/runtime/channels/channel-dispatch-pipeline.ts +77 -65
  295. package/src/runtime/channels/channel-dispatch-services.ts +7 -12
  296. package/src/runtime/channels/channel-dispatchers.ts +93 -39
  297. package/src/runtime/channels/channel-envelope.ts +680 -144
  298. package/src/runtime/channels/channel-multipart.ts +17 -13
  299. package/src/runtime/channels/channel-outbound-operations.ts +204 -178
  300. package/src/runtime/channels/channel-receive-loops.ts +160 -107
  301. package/src/runtime/channels/channel-runtime-lifecycle.ts +64 -59
  302. package/src/runtime/channels/channel-runtime-manager.ts +74 -27
  303. package/src/runtime/channels/channel-socket-registry.ts +20 -5
  304. package/src/runtime/channels/channel-transports.ts +414 -287
  305. package/src/runtime/channels/dispatch-error-reporter.ts +4 -9
  306. package/src/runtime/channels/local-spot-route-transport.ts +27 -29
  307. package/src/runtime/channels/router-socket-spot-route-transport.ts +63 -32
  308. package/src/runtime/channels/source-spot-router.ts +75 -38
  309. package/src/runtime/channels/spot-node-route-transport.ts +67 -37
  310. package/src/runtime/channels/spot-route-bridge-transport.ts +62 -30
  311. package/src/runtime/channels/spot-route-dispatch-strategy.ts +105 -34
  312. package/src/runtime/diagnostics/dispatch-error-details.ts +10 -2
  313. package/src/runtime/diagnostics/message-flow-bootstrap.ts +6 -0
  314. package/src/runtime/diagnostics/message-flow-delivery.ts +171 -0
  315. package/src/runtime/diagnostics/message-flow-record.ts +295 -0
  316. package/src/runtime/diagnostics/message-flow-worker.ts +146 -0
  317. package/src/runtime/diagnostics/message-flow.ts +49 -362
  318. package/src/runtime/diagnostics/runtime-metrics.ts +10 -4
  319. package/src/runtime/execution/index.ts +6 -0
  320. package/src/runtime/execution/serial-execution-queue.ts +94 -96
  321. package/src/runtime/foundation/durable-service-request.ts +212 -89
  322. package/src/runtime/foundation/operation-registry.ts +287 -38
  323. package/src/runtime/foundation/raw-service-mesh-runtime.ts +617 -292
  324. package/src/runtime/foundation/request-runtime.ts +227 -0
  325. package/src/runtime/foundation/service-discovery-registry.ts +7 -0
  326. package/src/runtime/foundation/service-liveness-registry.ts +1 -1
  327. package/src/runtime/foundation/service-mailbox.ts +7 -2
  328. package/src/runtime/foundation/service-relocation-object-owner.ts +21 -6
  329. package/src/runtime/foundation/service-runtime-contracts.ts +12 -2
  330. package/src/runtime/foundation/service-stateful-registry.ts +52 -19
  331. package/src/runtime/foundation/service-stateful-runtime.ts +365 -198
  332. package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
  333. package/src/runtime/foundation/service-topology-registry.ts +21 -3
  334. package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
  335. package/src/runtime/foundation/service-wire-m6a-codec.ts +69 -17
  336. package/src/runtime/host/actor-packet-relay.ts +160 -156
  337. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  338. package/src/runtime/host/actor-runtime-options-factory.ts +7 -2
  339. package/src/runtime/host/actor-transfer-runtime.ts +3 -3
  340. package/src/runtime/host/application-job-queue.ts +56 -27
  341. package/src/runtime/host/bound-session-relay.ts +0 -1
  342. package/src/runtime/host/channel-runtime-options-factory.ts +3 -0
  343. package/src/runtime/host/entry-actor-runtime.ts +14 -6
  344. package/src/runtime/host/index.ts +388 -113
  345. package/src/runtime/host/location-runtime-owner.ts +3 -3
  346. package/src/runtime/host/service-relocation-host-runtime.ts +380 -252
  347. package/src/runtime/host/spot-address-transport.ts +110 -95
  348. package/src/runtime/host/spot-runtime-options-factory.ts +3 -0
  349. package/src/runtime/host/user-spot-creation-coordinator.ts +69 -22
  350. package/src/runtime/internal-observation.ts +2 -0
  351. package/src/runtime/locations/actor-location-claims.ts +42 -16
  352. package/src/runtime/locations/auto-connect-loop.ts +24 -16
  353. package/src/runtime/locations/auto-connect-planner.ts +2 -5
  354. package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
  355. package/src/runtime/locations/in-memory-authority-store.ts +27 -7
  356. package/src/runtime/locations/in-memory-location-store.ts +1 -74
  357. package/src/runtime/locations/lifecycle.ts +4 -2
  358. package/src/runtime/locations/location-store-repository.ts +228 -308
  359. package/src/runtime/locations/resolvers.ts +20 -8
  360. package/src/runtime/locations/runtime.ts +16 -28
  361. package/src/runtime/messaging/creation-payload-codec.ts +12 -10
  362. package/src/runtime/messaging/framework-json-v1.ts +10 -1
  363. package/src/runtime/messaging/payload-codec.ts +50 -75
  364. package/src/runtime/messaging/request-deadline.ts +47 -39
  365. package/src/runtime/messaging/request-result.ts +88 -17
  366. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  367. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  368. package/src/runtime/spots/index.ts +57 -10
  369. package/src/runtime/spots/spot-activation-registry.ts +12 -8
  370. package/src/runtime/spots/spot-activation-state.ts +2 -0
  371. package/src/runtime/spots/spot-actor-admission-coordinator.ts +62 -37
  372. package/src/runtime/spots/spot-actor-ingress-admission.ts +157 -0
  373. package/src/runtime/spots/spot-actor-membership.ts +8 -5
  374. package/src/runtime/spots/spot-actor-packet-dispatch.ts +122 -206
  375. package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
  376. package/src/runtime/spots/spot-entry-activation.ts +25 -35
  377. package/src/runtime/spots/spot-handler-registry.ts +72 -15
  378. package/src/runtime/spots/spot-manager-public.ts +4 -2
  379. package/src/runtime/spots/spot-node-runtime-manager.ts +16 -7
  380. package/src/runtime/spots/spot-outbound.ts +26 -10
  381. package/src/runtime/spots/spot-route-packet-dispatch.ts +18 -8
  382. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +14 -8
  383. package/src/runtime/spots/spot-runtime-ports.ts +5 -2
  384. package/src/runtime/spots/spot-serial-executor.ts +1 -1
  385. package/src/runtime/spots/spot-serial-turn-executor.ts +25 -40
  386. package/src/runtime/spots/spot-subscription-dispatch.ts +9 -2
  387. package/src/runtime/spots/spot-timer.ts +1 -1
  388. package/src/runtime/streams/actor-session-binding-registry.ts +46 -3
  389. package/src/runtime/streams/bound-actor-relay-sender.ts +16 -5
  390. package/src/runtime/streams/bound-session-service.ts +10 -7
  391. package/src/runtime/streams/index.ts +30 -4
  392. package/src/runtime/streams/managed-stream.ts +2 -1
  393. package/src/runtime/streams/session-calls.ts +9 -14
  394. package/src/runtime/streams/session-context.ts +6 -11
  395. package/src/runtime/streams/stream-session-runtime.ts +79 -40
  396. package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +0 -8
  397. package/dist/runtime/spots/spot-lifecycle-metrics.js +0 -17
  398. package/src/runtime/spots/spot-lifecycle-metrics.ts +0 -16
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceStatefulRuntime = void 0;
4
4
  exports.sessionOwnerFenceMatches = sessionOwnerFenceMatches;
5
5
  exports.statefulMailboxData = statefulMailboxData;
6
+ const request_deadline_1 = require("../messaging/request-deadline");
7
+ const internal_observation_1 = require("../internal-observation");
6
8
  const abort_1 = require("../abort");
7
9
  const channel_envelope_1 = require("../channels/channel-envelope");
8
10
  const runtime_message_1 = require("../backend/runtime-message");
@@ -31,6 +33,7 @@ const service_stateful_registry_1 = require("./service-stateful-registry");
31
33
  const service_stateful_wire_codec_1 = require("./service-stateful-wire-codec");
32
34
  const service_wire_binary_primitives_1 = require("./service-wire-binary-primitives");
33
35
  const service_wire_constants_generated_1 = require("./service-wire-constants.generated");
36
+ const payload_slab_1 = require("../../contracts/Common/payload-slab");
34
37
  const service_wire_m6a_codec_1 = require("./service-wire-m6a-codec");
35
38
  const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647;
36
39
  const SPOT_MOVING = 34;
@@ -55,6 +58,24 @@ class ServiceStatefulRuntime {
55
58
  raw;
56
59
  nodeRid;
57
60
  nodeGeneration;
61
+ requests;
62
+ [internal_observation_1.inspectRuntime]() {
63
+ return Object.freeze({
64
+ canonicalActorJoinHandoffs: this.canonicalActorJoinHandoffs.size,
65
+ spotRoutes: this.spotRoutes.size,
66
+ instanceRoute: (spotId) => {
67
+ const route = this.instanceIntents.get(spotId)?.route;
68
+ return route === undefined ? undefined : Object.freeze({ ...route });
69
+ },
70
+ directSpotRoute: (spotId) => {
71
+ const route = this.directSpotRoutes.get(directSpotKey(spotId));
72
+ return route === undefined
73
+ ? undefined
74
+ : Object.freeze({ ...route, spot: Object.freeze({ ...route.spot }) });
75
+ },
76
+ spotMessageFollow: Object.freeze([...this.spotMessageFollow.values()].map((state) => Object.freeze({ queuedCount: state.queuedCount, queuedBytes: state.queuedBytes })))
77
+ });
78
+ }
58
79
  // Captured at module load, before any application turn exists: running a
59
80
  // callback through this snapshot detaches every AsyncLocalStorage context
60
81
  // (Spot serial turn, execution area, flow) so local loopback ingress
@@ -103,11 +124,13 @@ class ServiceStatefulRuntime {
103
124
  admittedUserSpotOperations = new Map();
104
125
  pendingInstanceActivations = new Map();
105
126
  closed = false;
106
- constructor(raw, nodeRid, nodeGeneration, onPendingOperationsChanged) {
127
+ constructor(raw, nodeRid, nodeGeneration, onPendingOperationsChanged, requests) {
107
128
  this.raw = raw;
108
129
  this.nodeRid = nodeRid;
109
130
  this.nodeGeneration = nodeGeneration;
110
- this.operations = new service_stateful_registry_1.ServiceTerminalOperationRegistry(new operation_registry_1.OperationRegistry(undefined, onPendingOperationsChanged));
131
+ this.requests = requests;
132
+ this.operations = new service_stateful_registry_1.ServiceTerminalOperationRegistry(requests?.operations() ??
133
+ new operation_registry_1.OperationRegistry(undefined, onPendingOperationsChanged, (reason) => (0, request_deadline_1.requestTerminalError)('Request', reason)), requests === undefined ? undefined : () => { });
111
134
  this.registry = new service_stateful_registry_1.ServiceStatefulRegistry(nodeRid, nodeGeneration);
112
135
  this.registry.createEntrySpot(nodeRid);
113
136
  raw.setServiceIngress((record) => this.ingress(record), acceptsStatefulIngress);
@@ -788,18 +811,23 @@ class ServiceStatefulRuntime {
788
811
  });
789
812
  return this.submitOneWay(target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
790
813
  }
791
- requestToSpot(sourceSpotId, requested, payload, timeoutMs, onAdmitted) {
792
- const pending = this.operations.register(timeoutMs);
814
+ requestToSpot(sourceSpotId, requested, payload, timeoutMs, onAdmitted, requestOperation, receiver) {
815
+ const pending = requestOperation ??
816
+ this.operations.register(timeoutMs);
793
817
  const target = this.acceptSpotAuthority(requested);
794
818
  if (target === undefined) {
795
- this.operations.reply(pending.id, (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
819
+ const result = (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
820
+ if (receiver === undefined)
821
+ pending.reply(result);
822
+ else
823
+ receiver.operationCompleted(pending.id, result, undefined);
796
824
  return pending;
797
825
  }
798
826
  const header = (0, service_stateful_wire_codec_1.encodeSpotHeader)('spotRequest', sourceSpotId, target, pending.id, {
799
827
  high: this.nodeGeneration,
800
828
  low: this.nextMessageFollowOperation++
801
829
  });
802
- this.submitRequest(pending, target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'spotRequest', undefined, onAdmitted);
830
+ this.submitRequest(pending, target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'spotRequest', undefined, onAdmitted, receiver);
803
831
  return pending;
804
832
  }
805
833
  async sendToActor(target, payload, sourceActor, boundSession, routeFence) {
@@ -814,12 +842,18 @@ class ServiceStatefulRuntime {
814
842
  }, { high: this.nodeGeneration, low: this.nextMessageFollowOperation++ });
815
843
  return this.submitOneWay(target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
816
844
  }
817
- requestToActor(target, payload, timeoutMs, sourceActor, boundSession, onAdmitted, routeFence) {
845
+ requestToActor(target, payload, timeoutMs, sourceActor, boundSession, onAdmitted, routeFence, requestOperation, receiver) {
818
846
  const operationLow = this.nextMessageFollowOperation++;
819
- const pending = this.operations.register(timeoutMs, 'registry', operationLow);
847
+ const pending = requestOperation ??
848
+ this.operations.register(timeoutMs, 'registry', operationLow);
849
+ this.operations.setContext(pending.id, operationLow);
820
850
  const route = routeFence ?? this.tryActorFence(target);
821
851
  if (route === undefined) {
822
- this.operations.reply(pending.id, (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
852
+ const result = (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale);
853
+ if (receiver !== undefined)
854
+ receiver.operationCompleted(pending.id, result, undefined);
855
+ else
856
+ pending.reply(result);
823
857
  return pending;
824
858
  }
825
859
  const header = (0, service_stateful_wire_codec_1.encodeActorHeader)('actorRequest', route, pending.id, sourceActor, boundSession === undefined
@@ -828,7 +862,7 @@ class ServiceStatefulRuntime {
828
862
  ...boundSession,
829
863
  sequence: this.nextSessionSequence++
830
864
  }, { high: this.nodeGeneration, low: operationLow });
831
- this.submitRequest(pending, target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'actorRequest', undefined, onAdmitted);
865
+ this.submitRequest(pending, target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'actorRequest', undefined, onAdmitted, receiver);
832
866
  return pending;
833
867
  }
834
868
  acceptRelocatedActorTerminal(operation, replyRouteId, result) {
@@ -855,22 +889,24 @@ class ServiceStatefulRuntime {
855
889
  payloadFrame
856
890
  ], metadataFrame));
857
891
  }
858
- requestToInstanceSpot(route, payload, timeoutMs, sourceSpotId, metadataFrame, instanceIntent = false, onAdmitted) {
859
- const pending = this.operations.register(timeoutMs);
892
+ requestToInstanceSpot(route, payload, timeoutMs, sourceSpotId, metadataFrame, instanceIntent = false, onAdmitted, requestOperation, receiver) {
893
+ const pending = requestOperation ??
894
+ this.operations.register(timeoutMs);
860
895
  this.submitRequest(pending, route.targetNodeRid, instanceOperationParts([
861
896
  (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),
862
897
  (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)
863
- ], metadataFrame), timeoutMs, 'instanceSpotRequest', undefined, onAdmitted);
898
+ ], metadataFrame), timeoutMs, 'instanceSpotRequest', undefined, onAdmitted, receiver);
864
899
  return pending;
865
900
  }
866
- requestToMissingInstanceSpot(target, payload, timeoutMs, sourceSpotId, metadataFrame) {
901
+ requestToMissingInstanceSpot(target, payload, timeoutMs, sourceSpotId, metadataFrame, requestOperation) {
867
902
  const deadlineUnixMs = BigInt(Date.now() + timeoutMs);
868
903
  const payloadFrame = (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload);
869
- return this.requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame);
904
+ return this.requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame, undefined, requestOperation);
870
905
  }
871
- requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame, onAdmitted) {
906
+ requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame, onAdmitted, requestOperation) {
872
907
  const timeoutMs = remainingDeadlineMs(deadlineUnixMs);
873
- const pending = this.operations.register(timeoutMs);
908
+ const pending = requestOperation ??
909
+ this.operations.register(timeoutMs);
874
910
  this.submitRequest(pending, target.targetNodeRid, instanceOperationParts([
875
911
  (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),
876
912
  payloadFrame
@@ -889,10 +925,10 @@ class ServiceStatefulRuntime {
889
925
  queueMicrotask(() => {
890
926
  try {
891
927
  this.registry.destroyActor(actor);
892
- this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
928
+ pending.reply({ terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
893
929
  }
894
930
  catch (error) {
895
- this.operations.reply(pending.id, failure(error));
931
+ pending.reply(failure(error));
896
932
  }
897
933
  });
898
934
  return pending;
@@ -903,7 +939,7 @@ class ServiceStatefulRuntime {
903
939
  }
904
940
  joinActor(actor, targetNodeRid, targetSpot, targetSpotGeneration, payload, timeoutMs) {
905
941
  const deadlineMs = performance.now() + timeoutMs;
906
- const pending = this.operations.register(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
942
+ const pending = this.operations.register(timeoutMs, 'registry', undefined, deadlineMs);
907
943
  const target = this.trySpotFence(targetNodeRid, {
908
944
  ...targetSpot,
909
945
  generation: targetSpotGeneration
@@ -913,7 +949,7 @@ class ServiceStatefulRuntime {
913
949
  }
914
950
  joinActorCanonical(actor, targetNodeRid, targetSpot, targetSpotGeneration, request, actorFence, local, timeoutMs) {
915
951
  const deadlineMs = performance.now() + timeoutMs;
916
- const pending = this.operations.register(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
952
+ const pending = this.operations.register(timeoutMs, 'registry', undefined, deadlineMs);
917
953
  const target = this.trySpotFence(targetNodeRid, {
918
954
  ...targetSpot,
919
955
  generation: targetSpotGeneration
@@ -927,13 +963,13 @@ class ServiceStatefulRuntime {
927
963
  }
928
964
  joinActorEntrySpot(actor, targetNodeRid, payload, timeoutMs) {
929
965
  const deadlineMs = performance.now() + timeoutMs;
930
- const pending = this.operations.register(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
966
+ const pending = this.operations.register(timeoutMs, 'registry', undefined, deadlineMs);
931
967
  this.submitActorJoin(pending, actor, targetNodeRid, this.tryEntrySpotFence(targetNodeRid), payload, deadlineMs);
932
968
  return pending;
933
969
  }
934
970
  joinActorEntrySpotCanonical(actor, targetNodeRid, request, actorFence, local, timeoutMs) {
935
971
  const deadlineMs = performance.now() + timeoutMs;
936
- const pending = this.operations.register(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
972
+ const pending = this.operations.register(timeoutMs, 'registry', undefined, deadlineMs);
937
973
  this.submitActorJoin(pending, actor, targetNodeRid, this.tryEntrySpotFence(targetNodeRid), request, deadlineMs, { request, actorFence, local });
938
974
  return pending;
939
975
  }
@@ -955,20 +991,20 @@ class ServiceStatefulRuntime {
955
991
  currentMembershipEpoch: transition.currentMembershipEpoch,
956
992
  resultCode: 0
957
993
  });
958
- this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
994
+ pending.reply({ terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
959
995
  }
960
996
  catch (error) {
961
- this.operations.reply(pending.id, failure(error));
997
+ pending.reply(failure(error));
962
998
  }
963
999
  });
964
1000
  return pending;
965
1001
  }
966
1002
  bindSession(sessionRid, actor, timeoutMs, deliver, onBindingReplaced, actorAuthority, close) {
967
1003
  const deadlineMs = performance.now() + timeoutMs;
968
- const pending = this.operations.register(timeoutMs, 'sender');
1004
+ const pending = this.operations.register(timeoutMs, 'registry', undefined, deadlineMs);
969
1005
  const sessionOwner = this.localSessionOwner();
970
1006
  if (sessionOwner === undefined) {
971
- this.operations.reply(pending.id, failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `Session owner '${this.nodeRid}' has no live MeshNode descriptor.`)));
1007
+ pending.reply(failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `Session owner '${this.nodeRid}' has no live MeshNode descriptor.`)));
972
1008
  return pending;
973
1009
  }
974
1010
  const deliveryKey = actorKey(actor);
@@ -1013,7 +1049,7 @@ class ServiceStatefulRuntime {
1013
1049
  else {
1014
1050
  this.sessionDeliveries.set(deliveryKey, { ...delivery, binding: previous });
1015
1051
  }
1016
- this.operations.reply(pending.id, {
1052
+ pending.reply({
1017
1053
  terminalResult: runtime_values_1.RequestResult.Ok,
1018
1054
  failureCode: 0
1019
1055
  });
@@ -1022,7 +1058,7 @@ class ServiceStatefulRuntime {
1022
1058
  const binding = this.registry.installSessionBinding(localBinding);
1023
1059
  installedDelivery = { ...delivery, binding };
1024
1060
  this.sessionDeliveries.set(deliveryKey, installedDelivery);
1025
- this.operations.reply(pending.id, {
1061
+ pending.reply({
1026
1062
  terminalResult: runtime_values_1.RequestResult.Ok,
1027
1063
  failureCode: 0,
1028
1064
  kindData: undefined
@@ -1044,7 +1080,7 @@ class ServiceStatefulRuntime {
1044
1080
  this.sessionDeliveries.get(deliveryKey) === installedDelivery) {
1045
1081
  this.sessionDeliveries.delete(deliveryKey);
1046
1082
  }
1047
- this.operations.reply(pending.id, failure(error));
1083
+ pending.reply(failure(error));
1048
1084
  }
1049
1085
  return pending;
1050
1086
  }
@@ -1059,12 +1095,11 @@ class ServiceStatefulRuntime {
1059
1095
  });
1060
1096
  }
1061
1097
  catch (error) {
1062
- this.operations.fail(pending.id, error);
1098
+ pending.replyFailure(error);
1063
1099
  return pending;
1064
1100
  }
1065
- void this.requestDurableOperation(actor.nodeRid, [header], pending.id, 'streamBind', deadlineMs).then((reply) => this.completeRemoteReply(pending, actor.nodeRid, 'streamBind', undefined, reply), (error) => this.operations.fail(pending.id, error));
1066
- return {
1067
- id: pending.id,
1101
+ void this.requestDurableOperation(actor.nodeRid, [header], pending.id, 'streamBind', pending).then((reply) => this.completeRemoteReply(pending, actor.nodeRid, 'streamBind', undefined, reply), (error) => pending.replyFailure(error));
1102
+ return Object.assign(Object.create(pending), {
1068
1103
  promise: pending.promise.then((result) => {
1069
1104
  if (result.terminalResult === runtime_values_1.RequestResult.Ok && result.streamBinding !== undefined) {
1070
1105
  const committed = {
@@ -1094,13 +1129,13 @@ class ServiceStatefulRuntime {
1094
1129
  }
1095
1130
  return result;
1096
1131
  })
1097
- };
1132
+ });
1098
1133
  }
1099
1134
  closeBoundSession(actor, expectedBindingGeneration, timeoutMs) {
1100
1135
  const pending = this.operations.register(timeoutMs);
1101
1136
  const binding = this.registry.binding(actor);
1102
1137
  if (binding === undefined) {
1103
- this.operations.reply(pending.id, (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorSessionNotBound));
1138
+ pending.reply((0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorSessionNotBound));
1104
1139
  return pending;
1105
1140
  }
1106
1141
  const header = Buffer.from((0, service_wire_codec_generated_1.encodeBoundSessionCloseCommand)({
@@ -1118,9 +1153,9 @@ class ServiceStatefulRuntime {
1118
1153
  }
1119
1154
  }, {})[0]);
1120
1155
  const reply = (0, routing_id_1.routingIdsEqual)(binding.sessionOwnerNodeRid, this.nodeRid)
1121
- ? this.requestLocalInfrastructure(header, pending.id, timeoutMs)
1122
- : this.raw.requestService(binding.sessionOwnerNodeRid, [header], timeoutMs);
1123
- void reply.then((parts) => this.completeRemoteReply(pending, binding.sessionOwnerNodeRid, 'boundSessionClose', undefined, parts), (error) => this.operations.fail(pending.id, error));
1156
+ ? this.requestLocalInfrastructure(header, pending.id, pending)
1157
+ : (0, durable_service_request_1.requestDurableService)(this.raw, binding.sessionOwnerNodeRid, [header], pending, 'boundSessionClose');
1158
+ void reply.then((parts) => this.completeRemoteReply(pending, binding.sessionOwnerNodeRid, 'boundSessionClose', undefined, parts), (error) => pending.replyFailure(error));
1124
1159
  return pending;
1125
1160
  }
1126
1161
  unbindSession(sessionRid, actor, expectedBindingGeneration, timeoutMs) {
@@ -1129,17 +1164,17 @@ class ServiceStatefulRuntime {
1129
1164
  if (delivery === undefined ||
1130
1165
  !(0, routing_id_1.routingIdsEqual)(delivery.binding.sessionRid, sessionRid) ||
1131
1166
  delivery.binding.bindingGeneration !== expectedBindingGeneration) {
1132
- this.operations.reply(pending.id, (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
1167
+ pending.reply((0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
1133
1168
  return pending;
1134
1169
  }
1135
1170
  this.sessionDeliveries.delete(actorKey(actor));
1136
1171
  if (actor.nodeRid === this.nodeRid) {
1137
1172
  try {
1138
1173
  this.registry.unbindSession(actor, expectedBindingGeneration);
1139
- this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
1174
+ pending.reply({ terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
1140
1175
  }
1141
1176
  catch (error) {
1142
- this.operations.reply(pending.id, failure(error));
1177
+ pending.reply(failure(error));
1143
1178
  }
1144
1179
  return pending;
1145
1180
  }
@@ -1201,14 +1236,16 @@ class ServiceStatefulRuntime {
1201
1236
  ]);
1202
1237
  }
1203
1238
  expireOperations(nowMs, turnDeadlineMs) {
1204
- return this.operations.expire(nowMs, turnDeadlineMs);
1239
+ return this.requests === undefined && nowMs >= this.operations.nextDeadlineMs()
1240
+ ? this.operations.expire(nowMs, turnDeadlineMs)
1241
+ : 0;
1205
1242
  }
1206
1243
  get pendingOperationCount() {
1207
1244
  return this.operations.size;
1208
1245
  }
1209
1246
  /** The next stateful request expiry, as a lower bound. */
1210
1247
  nextMaintenanceDeadlineMs() {
1211
- return this.operations.nextDeadlineMs();
1248
+ return this.requests === undefined ? this.operations.nextDeadlineMs() : Infinity;
1212
1249
  }
1213
1250
  close() {
1214
1251
  if (this.closed)
@@ -1303,7 +1340,7 @@ class ServiceStatefulRuntime {
1303
1340
  ? record.parts.length >= 2
1304
1341
  ? record.parts[record.parts.length - 1]
1305
1342
  : undefined
1306
- : (0, service_wire_m6a_codec_1.encodeApplicationPayload)(canonicalPayload);
1343
+ : (0, service_wire_m6a_codec_1.encodeOwnedApplicationPayload)(canonicalPayload);
1307
1344
  try {
1308
1345
  return await this.handleIngress(record, decoded, payloadFrame, metadataFrame, canonicalActorJoin, canonicalPayload);
1309
1346
  }
@@ -1419,6 +1456,48 @@ class ServiceStatefulRuntime {
1419
1456
  binding.sessionOwnerNodeRid !== ingress.sourceRoutingId) {
1420
1457
  throw new service_stateful_registry_1.ServiceStaleGenerationError('binding', record.target.actor.actorId);
1421
1458
  }
1459
+ if (!this.registry.acceptBoundSessionSequence(record.target.actor, record.boundSession.bindingGeneration, record.boundSession.sequence)) {
1460
+ const error = new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.InvalidOperation, 'Bound Session relay sequence does not increase.');
1461
+ const reporter = this.dispatchErrors;
1462
+ if (record.kind === 'actorRequest') {
1463
+ if (reporter?.captureEnabled() === true) {
1464
+ reporter.report({
1465
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.StreamSession,
1466
+ messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Request,
1467
+ reason: ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.StaleTarget,
1468
+ action: ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError,
1469
+ meshName: this.dispatchErrorMeshName,
1470
+ sourceRid: ingress.sourceRoutingId,
1471
+ actorId: record.target.actor.actorId,
1472
+ correlationId: record.correlation?.toString(),
1473
+ error
1474
+ });
1475
+ }
1476
+ const result = failure(error);
1477
+ this.replyWire(ingress, record.correlation, result.terminalResult, result.failureCode);
1478
+ return 'infrastructure';
1479
+ }
1480
+ const tracePoint = (0, message_flow_1.flowIfEnabled)(reporter?.flow, ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dropped);
1481
+ if (tracePoint !== undefined) {
1482
+ tracePoint.trace({
1483
+ outcome: ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Dropped,
1484
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.StreamSession,
1485
+ messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Send,
1486
+ packetName: (0, service_wire_m6a_codec_1.decodeApplicationPayloadView)(payloadFrame).packetName,
1487
+ ...(this.dispatchErrorMeshName === undefined
1488
+ ? {}
1489
+ : { meshName: this.dispatchErrorMeshName }),
1490
+ ...(record.correlation === undefined
1491
+ ? {}
1492
+ : { correlationId: record.correlation.toString() }),
1493
+ sourceRid: ingress.sourceRoutingId,
1494
+ actorId: record.target.actor.actorId,
1495
+ streamSessionId: record.boundSession.sessionRid,
1496
+ errorReason: ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.StaleTarget
1497
+ });
1498
+ }
1499
+ return 'application';
1500
+ }
1422
1501
  }
1423
1502
  return this.enqueueApplicationFrame(ingress, `actor:${actor.ref.actorId}\0${actor.ref.generation}`, payloadFrame, {
1424
1503
  receiveKind: record.kind === 'actorSend' ? service_runtime_contracts_1.ReceiveKind.ActorSend : service_runtime_contracts_1.ReceiveKind.ActorRequest,
@@ -2237,7 +2316,7 @@ class ServiceStatefulRuntime {
2237
2316
  }
2238
2317
  })
2239
2318
  };
2240
- const applicationFrame = payloadFrame ?? (0, service_wire_m6a_codec_1.encodeApplicationPayload)(emptyPayload());
2319
+ const applicationFrame = payloadFrame ?? (0, service_wire_m6a_codec_1.encodeOwnedApplicationPayload)(emptyPayload());
2241
2320
  return this.enqueueLifecycleFrame(ingress, `spot:${record.target.spot.spotId}`, applicationFrame, {
2242
2321
  receiveKind: service_runtime_contracts_1.ReceiveKind.SpotControl,
2243
2322
  operationKind: service_runtime_contracts_1.OperationKind.ActorJoin,
@@ -2658,7 +2737,7 @@ class ServiceStatefulRuntime {
2658
2737
  async enqueueLogicalMulticast(channelName, topic, sourceSpotId, payload, sourceNodeRid = this.nodeRid) {
2659
2738
  const applicationJobOwner = await this.raw.reserveLocalIngress();
2660
2739
  try {
2661
- await this.enqueueLogicalMulticastFrame(channelName, topic, sourceSpotId, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload), sourceNodeRid, applicationJobOwner);
2740
+ await this.enqueueLogicalMulticastFrame(channelName, topic, sourceSpotId, (0, service_wire_m6a_codec_1.encodeOwnedApplicationPayload)(payload), sourceNodeRid, applicationJobOwner);
2662
2741
  }
2663
2742
  finally {
2664
2743
  applicationJobOwner.close();
@@ -2937,60 +3016,57 @@ class ServiceStatefulRuntime {
2937
3016
  }
2938
3017
  }
2939
3018
  async requestUserSpotOperation(targetNodeRid, header, correlation, operationKind, timeoutMs) {
2940
- const parts = await this.requestDurableOperation(targetNodeRid, [header], correlation, operationKind, performance.now() + Math.max(1, timeoutMs));
2941
- // A received envelope, including a decode failure, ends sender replay.
2942
- try {
2943
- if (parts.length < 1 || parts.length > 2) {
2944
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid creation operation reply parts.');
2945
- }
2946
- const decoded = (0, service_stateful_wire_codec_1.decodeStatefulReply)(parts[0], correlation, operationKind, parts.length >= 2);
2947
- if (decoded.terminalResult !== runtime_values_1.RequestResult.Ok && parts.length !== 1) {
2948
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Failed creation operation reply carries a payload.');
3019
+ const deadlineMs = performance.now() + Math.max(1, timeoutMs);
3020
+ const pending = this.operations.register(Math.max(1, timeoutMs), 'registry', undefined, deadlineMs);
3021
+ const completed = (parts) => {
3022
+ try {
3023
+ if (parts.length < 1 || parts.length > 2) {
3024
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid creation operation reply parts.');
3025
+ }
3026
+ const decoded = (0, service_stateful_wire_codec_1.decodeStatefulReply)(parts[0], correlation, operationKind, parts.length >= 2);
3027
+ if (decoded.terminalResult !== runtime_values_1.RequestResult.Ok && parts.length !== 1) {
3028
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Failed creation operation reply carries a payload.');
3029
+ }
3030
+ if (operationKind === 'userSpotClose' && parts.length !== 1) {
3031
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('User Spot close reply carries a payload.');
3032
+ }
3033
+ const value = {
3034
+ terminalResult: decoded.terminalResult,
3035
+ failureCode: decoded.failureCode,
3036
+ ...(decoded.tail === undefined ? {} : { tail: decoded.tail }),
3037
+ ...(parts.length === 2 ? { payload: (0, service_wire_m6a_codec_1.decodeApplicationPayload)(parts[1]) } : {})
3038
+ };
3039
+ pending.complete(value);
2949
3040
  }
2950
- if (operationKind === 'userSpotClose' && parts.length !== 1) {
2951
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('User Spot close reply carries a payload.');
3041
+ catch (error) {
3042
+ pending.fail((0, framework_errors_internal_1.translateWireReplyDecodeError)(error));
2952
3043
  }
2953
- return {
2954
- terminalResult: decoded.terminalResult,
2955
- failureCode: decoded.failureCode,
2956
- ...(decoded.tail === undefined ? {} : { tail: decoded.tail }),
2957
- ...(parts.length === 2 ? { payload: (0, service_wire_m6a_codec_1.decodeApplicationPayload)(parts[1]) } : {})
2958
- };
2959
- }
2960
- catch (error) {
2961
- throw (0, framework_errors_internal_1.translateWireReplyDecodeError)(error);
2962
- }
3044
+ };
3045
+ const failed = (error) => {
3046
+ pending.fail(error);
3047
+ };
3048
+ void this.requestDurableOperation(targetNodeRid, [header], correlation, operationKind, pending).then(completed, failed);
3049
+ return pending.promise;
2963
3050
  }
2964
- async requestDurableOperation(targetNodeRid, parts, correlation, operationKind, deadlineMs) {
3051
+ async requestDurableOperation(targetNodeRid, parts, correlation, operationKind, pending) {
2965
3052
  this.requireOpen();
2966
3053
  if (targetNodeRid === this.nodeRid) {
2967
- return this.requestLocalInfrastructure(parts[0], correlation, Math.ceil(deadlineMs - performance.now()));
3054
+ return this.requestLocalInfrastructure(parts[0], correlation, pending);
2968
3055
  }
2969
- return (0, durable_service_request_1.requestDurableService)(this.raw, targetNodeRid, parts, deadlineMs, operationKind);
3056
+ return (0, durable_service_request_1.requestDurableService)(this.raw, targetNodeRid, parts, pending, operationKind);
2970
3057
  }
2971
- requestLocalInfrastructure(header, requestSequence, timeoutMs) {
3058
+ requestLocalInfrastructure(header, requestSequence, pending) {
2972
3059
  return new Promise((resolve, reject) => {
2973
- let settled = false;
2974
- const fail = (error) => {
2975
- if (settled)
2976
- return;
2977
- settled = true;
2978
- clearTimeout(timer);
2979
- reject(error);
2980
- };
2981
- const timer = setTimeout(() => {
2982
- fail(new Error('Local infrastructure request timed out.'));
2983
- }, timeoutMs);
2984
3060
  const finish = (parts) => {
2985
- if (settled)
2986
- return;
2987
- settled = true;
2988
- clearTimeout(timer);
2989
3061
  resolve(parts.map((part) => Buffer.from(part)));
2990
3062
  };
2991
3063
  void (async () => {
2992
3064
  const applicationJobOwner = await this.raw.reserveLocalIngress();
2993
3065
  try {
3066
+ if (!pending.isPending()) {
3067
+ await pending.promise;
3068
+ throw new operation_registry_1.OperationCancelledError(pending.id, 'Request is already terminal.');
3069
+ }
2994
3070
  const result = await this.ingress({
2995
3071
  command: header[service_wire_binary_primitives_1.SERVICE_WIRE_COMMAND_OFFSET],
2996
3072
  flags: header[service_wire_binary_primitives_1.SERVICE_WIRE_FLAGS_OFFSET],
@@ -3001,18 +3077,19 @@ class ServiceStatefulRuntime {
3001
3077
  applicationJobOwner
3002
3078
  });
3003
3079
  if (result !== 'infrastructure') {
3004
- fail(new service_wire_m6a_codec_1.ServiceWireProtocolError(`Local infrastructure request was rejected as '${result ?? 'unsupported'}'.`));
3080
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError(`Local infrastructure request was rejected as '${result ?? 'unsupported'}'.`);
3005
3081
  }
3006
3082
  }
3007
3083
  finally {
3008
3084
  applicationJobOwner.close();
3009
3085
  }
3010
- })().catch(fail);
3086
+ })().catch(reject);
3011
3087
  });
3012
3088
  }
3013
3089
  async submitOneWay(targetNodeRid, parts) {
3014
3090
  this.requireOpen();
3015
3091
  if (targetNodeRid === this.nodeRid) {
3092
+ parts = copyRetainedServiceFrames(parts);
3016
3093
  const applicationJobOwner = await this.raw.reserveLocalIngress();
3017
3094
  if ((0, execution_1.captureZLinkExecutionTurn)() !== undefined) {
3018
3095
  // The sender is inside a Spot serial turn. Running ingress inline
@@ -3072,15 +3149,16 @@ class ServiceStatefulRuntime {
3072
3149
  ? runtime_values_1.SubmitResult.Ok
3073
3150
  : runtime_values_1.SubmitResult.NotConnected;
3074
3151
  }
3075
- submitRequest(pending, targetNodeRid, parts, timeoutMs, operationKind, actor, onAdmitted) {
3152
+ submitRequest(pending, targetNodeRid, parts, timeoutMs, operationKind, actor, onAdmitted, receiver) {
3076
3153
  if (targetNodeRid === this.nodeRid) {
3154
+ parts = copyRetainedServiceFrames(parts);
3077
3155
  const deadlineUnixMs = BigInt(Date.now() + Math.max(0, timeoutMs));
3078
3156
  const capacityStop = new AbortController();
3079
3157
  void pending.promise.then(() => capacityStop.abort(), () => capacityStop.abort());
3080
3158
  void (async () => {
3081
3159
  const applicationJobOwner = await this.raw.reserveLocalIngress(capacityStop.signal);
3082
3160
  try {
3083
- if (!this.operations.isPending(pending.id))
3161
+ if (!pending.isPending())
3084
3162
  return;
3085
3163
  const localIngress = {
3086
3164
  command: parts[0][service_wire_binary_primitives_1.SERVICE_WIRE_COMMAND_OFFSET],
@@ -3091,25 +3169,55 @@ class ServiceStatefulRuntime {
3091
3169
  parts,
3092
3170
  applicationJobOwner
3093
3171
  };
3094
- await this.submitLocalRequest(localIngress, pending, operationKind, actor, deadlineUnixMs);
3172
+ await this.submitLocalRequest(localIngress, pending, operationKind, actor, deadlineUnixMs, receiver);
3095
3173
  }
3096
3174
  catch (error) {
3097
- this.operations.reply(pending.id, failure(error));
3175
+ receiver === undefined
3176
+ ? pending.reply(failure(error))
3177
+ : receiver.operationFailed(pending.id, error, undefined);
3098
3178
  }
3099
3179
  finally {
3100
3180
  applicationJobOwner.close();
3101
3181
  }
3102
- })().catch((error) => this.operations.reply(pending.id, failure(error)));
3182
+ })().catch((error) => receiver === undefined
3183
+ ? pending.reply(failure(error))
3184
+ : receiver.operationFailed(pending.id, error, undefined));
3185
+ return;
3186
+ }
3187
+ if (receiver !== undefined) {
3188
+ const completion = {
3189
+ operationCompleted: (_id, reply) => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply, receiver),
3190
+ operationFailed: (_id, error) => receiver.operationFailed(pending.id, error, undefined)
3191
+ };
3192
+ if (this.raw.isPeerRouteReady(targetNodeRid) === true) {
3193
+ this.raw.requestService(targetNodeRid, parts, timeoutMs, onAdmitted, pending, completion);
3194
+ return;
3195
+ }
3196
+ (0, durable_service_request_1.admitServiceRequest)(this.raw, targetNodeRid, pending, (remaining, finished) => {
3197
+ this.raw.requestService(targetNodeRid, parts, remaining, onAdmitted, pending, {
3198
+ operationCompleted: (id, reply) => {
3199
+ finished();
3200
+ completion.operationCompleted(id, reply);
3201
+ },
3202
+ operationFailed: (id, error) => {
3203
+ finished();
3204
+ completion.operationFailed(id, error);
3205
+ }
3206
+ });
3207
+ }, (error) => completion.operationFailed(pending.id, error), operationKind);
3103
3208
  return;
3104
3209
  }
3105
- void this.raw.requestService(targetNodeRid, parts, timeoutMs, onAdmitted).then((reply) => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply), (error) => this.operations.fail(pending.id, error));
3210
+ const reply = this.raw.isPeerRouteReady(targetNodeRid) === true
3211
+ ? this.raw.requestService(targetNodeRid, parts, timeoutMs, onAdmitted, pending)
3212
+ : (0, durable_service_request_1.requestDurableService)(this.raw, targetNodeRid, parts, pending, operationKind, undefined, undefined, onAdmitted);
3213
+ void reply.then((reply) => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply), (error) => pending.replyFailure(error));
3106
3214
  }
3107
3215
  submitActorJoin(pending, actor, targetNodeRid, target, payload, deadlineMs, canonical) {
3108
3216
  const actorRoute = canonical === undefined
3109
3217
  ? this.tryActorFence(actor)
3110
3218
  : this.acceptCanonicalActorFence(actor, canonical.actorFence);
3111
3219
  if (target === undefined || actorRoute === undefined) {
3112
- this.operations.reply(pending.id, (0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
3220
+ pending.reply((0, framework_errors_internal_1.internalFrameworkWireReply)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale));
3113
3221
  return;
3114
3222
  }
3115
3223
  if (canonical !== undefined) {
@@ -3147,19 +3255,19 @@ class ServiceStatefulRuntime {
3147
3255
  }
3148
3256
  catch (error) {
3149
3257
  this.canonicalActorJoinHandoffs.delete(pending.id);
3150
- this.operations.fail(pending.id, error);
3258
+ pending.replyFailure(error);
3151
3259
  return;
3152
3260
  }
3153
3261
  if (targetNodeRid === this.nodeRid) {
3154
3262
  this.submitRequest(pending, targetNodeRid, parts, Math.max(0, Math.ceil(deadlineMs - performance.now())), 'actorJoin', actor);
3155
3263
  return;
3156
3264
  }
3157
- void this.requestDurableOperation(targetNodeRid, parts, pending.id, 'actorJoin', deadlineMs).then((reply) => this.completeRemoteReply(pending, targetNodeRid, 'actorJoin', actor, reply), (error) => {
3265
+ void this.requestDurableOperation(targetNodeRid, parts, pending.id, 'actorJoin', pending).then((reply) => this.completeRemoteReply(pending, targetNodeRid, 'actorJoin', actor, reply), (error) => {
3158
3266
  this.canonicalActorJoinHandoffs.delete(pending.id);
3159
- this.operations.fail(pending.id, error);
3267
+ pending.replyFailure(error);
3160
3268
  });
3161
3269
  }
3162
- async submitLocalRequest(ingress, pending, operationKind, actor, deadlineUnixMs) {
3270
+ async submitLocalRequest(ingress, pending, operationKind, actor, deadlineUnixMs, receiver) {
3163
3271
  const canonicalActorJoin = operationKind === 'actorJoin' ? (0, service_wire_pilot_codec_generated_1.decodeActorJoin28)(ingress.parts) : undefined;
3164
3272
  const decoded = canonicalActorJoin === undefined
3165
3273
  ? (0, service_stateful_wire_codec_1.decodeStatefulHeader)(ingress.parts[0])
@@ -3168,14 +3276,14 @@ class ServiceStatefulRuntime {
3168
3276
  ? ingress.parts.length < 2
3169
3277
  ? undefined
3170
3278
  : ingress.parts[1]
3171
- : (0, service_wire_m6a_codec_1.encodeApplicationPayload)({
3279
+ : (0, service_wire_m6a_codec_1.encodeOwnedApplicationPayload)({
3172
3280
  packetName: canonicalActorJoin.payload.packetName,
3173
3281
  contentType: canonicalActorJoin.payload.contentType,
3174
3282
  payload: Buffer.from(canonicalActorJoin.payload.payload)
3175
3283
  });
3176
3284
  if (decoded.kind === 'actorLookup') {
3177
3285
  const found = this.registry.actor(decoded.actorId);
3178
- this.operations.reply(pending.id, found === undefined
3286
+ pending.reply(found === undefined
3179
3287
  ? { terminalResult: runtime_values_1.RequestResult.NotFound, failureCode: ACTOR_ROUTE_NOT_FOUND }
3180
3288
  : {
3181
3289
  terminalResult: runtime_values_1.RequestResult.Ok,
@@ -3187,14 +3295,20 @@ class ServiceStatefulRuntime {
3187
3295
  if (decoded.kind === 'actorDestroy') {
3188
3296
  try {
3189
3297
  this.registry.destroyActor(decoded.actor.actor);
3190
- this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
3298
+ pending.reply({ terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
3191
3299
  }
3192
3300
  catch (error) {
3193
- this.operations.reply(pending.id, failure(error));
3301
+ pending.reply(failure(error));
3194
3302
  }
3195
3303
  return;
3196
3304
  }
3197
- const localReply = (terminalResult, failureCode, replyPayload, tail) => this.operations.reply(pending.id, this.resultFromReply(terminalResult, failureCode, replyPayload, tail, this.nodeRid, actor));
3305
+ const localReply = (terminalResult, failureCode, replyPayload, tail) => {
3306
+ const result = this.resultFromReply(terminalResult, failureCode, replyPayload, tail, this.nodeRid, actor);
3307
+ if (receiver === undefined)
3308
+ return pending.reply(result);
3309
+ receiver.operationCompleted(pending.id, result, undefined);
3310
+ return true;
3311
+ };
3198
3312
  if (decoded.kind === 'spotRequest') {
3199
3313
  this.validateDirectSpotFence(decoded.target);
3200
3314
  this.enqueueApplicationFrame(ingress, `spot:${decoded.target.spot.spotId}`, payloadFrame, {
@@ -3254,7 +3368,7 @@ class ServiceStatefulRuntime {
3254
3368
  currentMembershipEpoch: (previous?.membershipEpoch ?? 0n) + 1n,
3255
3369
  resultCode: 0
3256
3370
  };
3257
- this.enqueueLifecycleFrame(ingress, `spot:${decoded.target.spot.spotId}`, payloadFrame ?? (0, service_wire_m6a_codec_1.encodeApplicationPayload)(emptyPayload()), {
3371
+ this.enqueueLifecycleFrame(ingress, `spot:${decoded.target.spot.spotId}`, payloadFrame ?? (0, service_wire_m6a_codec_1.encodeOwnedApplicationPayload)(emptyPayload()), {
3258
3372
  receiveKind: service_runtime_contracts_1.ReceiveKind.SpotControl,
3259
3373
  operationKind: service_runtime_contracts_1.OperationKind.ActorJoin,
3260
3374
  correlation: decoded.correlation,
@@ -3270,7 +3384,7 @@ class ServiceStatefulRuntime {
3270
3384
  payload: Buffer.from(canonicalActorJoin.payload.payload)
3271
3385
  }
3272
3386
  }),
3273
- isPending: () => this.operations.isPending(pending.id),
3387
+ isPending: () => pending.isPending(),
3274
3388
  ...(deadlineUnixMs === undefined ? {} : { deadlineUnixMs }),
3275
3389
  onTerminalCompletion: () => completeOnJoinDispatchTerminal?.(),
3276
3390
  reply: (terminalResult, failureCode, replyPayload, tail) => {
@@ -3279,7 +3393,7 @@ class ServiceStatefulRuntime {
3279
3393
  const acceptedJoin = terminalResult === runtime_values_1.RequestResult.Ok &&
3280
3394
  tail?.kind === 'actorJoin' &&
3281
3395
  tail.joinResult === 0;
3282
- if (acceptedJoin && this.operations.isPending(pending.id)) {
3396
+ if (acceptedJoin && pending.isPending()) {
3283
3397
  // Commit membership now, but keep the source operation behind
3284
3398
  // target OnJoinedActor. Entry finishes on this record; User
3285
3399
  // Spot lifecycle finishes on the Joined control below.
@@ -3318,10 +3432,10 @@ class ServiceStatefulRuntime {
3318
3432
  else {
3319
3433
  this.registry.unbindSession(current.ref, decoded.binding.retiredGeneration, decoded.sessionRid, this.nodeRid);
3320
3434
  }
3321
- this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
3435
+ pending.reply({ terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
3322
3436
  }
3323
3437
  catch (error) {
3324
- this.operations.reply(pending.id, failure(error));
3438
+ pending.reply(failure(error));
3325
3439
  }
3326
3440
  return;
3327
3441
  }
@@ -3333,26 +3447,33 @@ class ServiceStatefulRuntime {
3333
3447
  this.enqueueInstanceSpot(ingress, decoded, ingress.parts[hasMetadata ? 2 : 1], metadataFrame, localReply);
3334
3448
  return;
3335
3449
  }
3336
- this.operations.reply(pending.id, {
3450
+ pending.reply({
3337
3451
  terminalResult: runtime_values_1.RequestResult.ProtocolError,
3338
3452
  failureCode: 0
3339
3453
  });
3340
3454
  void operationKind;
3341
3455
  }
3342
- completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply) {
3456
+ completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply, receiver) {
3343
3457
  const canonicalActorJoinHandoffId = operationKind === 'actorJoin' ? this.canonicalActorJoinHandoffs.get(pending.id) : undefined;
3344
3458
  try {
3345
3459
  if (reply.length < 1 || reply.length > 2)
3346
3460
  throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid M6B reply parts.');
3347
3461
  const decoded = (0, service_stateful_wire_codec_1.decodeStatefulReply)(reply[0], pending.id, operationKind, reply.length >= 2);
3348
3462
  const payload = reply.length < 2 ? undefined : (0, service_wire_m6a_codec_1.decodeApplicationPayload)(reply[1]);
3349
- this.operations.reply(pending.id, this.resultFromReply(decoded.terminalResult, decoded.failureCode, payload, decoded.tail, targetNodeRid, actor, canonicalActorJoinHandoffId));
3463
+ const result = this.resultFromReply(decoded.terminalResult, decoded.failureCode, payload, decoded.tail, targetNodeRid, actor, canonicalActorJoinHandoffId);
3464
+ if (receiver === undefined)
3465
+ pending.reply(result);
3466
+ else
3467
+ receiver.operationCompleted(pending.id, result, undefined);
3350
3468
  }
3351
3469
  catch (error) {
3352
3470
  // Spec 32-framework-error-model:58-60, 91-92 — an unprocessable remote
3353
3471
  // reply (decode/shape failure) fails the awaiting operation with a
3354
3472
  // Framework ProtocolError instead of leaking the codec's plain Error.
3355
- this.operations.fail(pending.id, (0, framework_errors_internal_1.translateWireReplyDecodeError)(error));
3473
+ if (receiver === undefined)
3474
+ pending.replyFailure((0, framework_errors_internal_1.translateWireReplyDecodeError)(error));
3475
+ else
3476
+ receiver.operationFailed(pending.id, (0, framework_errors_internal_1.translateWireReplyDecodeError)(error), undefined);
3356
3477
  }
3357
3478
  finally {
3358
3479
  if (operationKind === 'actorJoin') {
@@ -3405,6 +3526,7 @@ class ServiceStatefulRuntime {
3405
3526
  return {
3406
3527
  terminalResult,
3407
3528
  failureCode,
3529
+ ...(tail?.kind === 'streamBindRejected' ? { failureMessage: tail.rejectionMessage } : {}),
3408
3530
  ...(payload === undefined ? {} : { payload }),
3409
3531
  ...(tail?.kind === 'streamBind'
3410
3532
  ? {
@@ -3541,7 +3663,9 @@ class ServiceStatefulRuntime {
3541
3663
  else {
3542
3664
  try {
3543
3665
  const remainingMs = Math.max(1, Math.min(30_000, Math.ceil(state.expiresAtMs - performance.now())));
3544
- const reply = await this.raw.requestService(state.target.targetNodeRid, parts, remainingMs);
3666
+ const pending = this.raw.beginInfrastructureRequest(remainingMs);
3667
+ const reply = await (0, durable_service_request_1.requestDurableService)(this.raw, state.target.targetNodeRid, parts, pending, 'spot message follow');
3668
+ pending.complete(reply);
3545
3669
  this.raw.replyService(current.ingress, reply);
3546
3670
  }
3547
3671
  catch (error) {
@@ -3700,9 +3824,7 @@ class ServiceStatefulRuntime {
3700
3824
  : undefined;
3701
3825
  }
3702
3826
  tryEntrySpotFence(targetNodeRid) {
3703
- const targetNodeGeneration = targetNodeRid === this.nodeRid
3704
- ? this.nodeGeneration
3705
- : this.raw.topology.peer(targetNodeRid)?.descriptor.lifecycleGeneration;
3827
+ const targetNodeGeneration = this.raw.peerLifecycleGeneration(targetNodeRid) ?? this.tryPeerGeneration(targetNodeRid);
3706
3828
  if (targetNodeGeneration === undefined)
3707
3829
  return undefined;
3708
3830
  return {
@@ -3741,8 +3863,8 @@ class ServiceStatefulRuntime {
3741
3863
  ? current
3742
3864
  : undefined;
3743
3865
  }
3744
- const peer = this.raw.topology.peer(targetNodeRid);
3745
- if (peer?.descriptor.lifecycleGeneration !== targetNodeGeneration) {
3866
+ if ((this.raw.peerLifecycleGeneration(targetNodeRid) ?? this.tryPeerGeneration(targetNodeRid)) !==
3867
+ targetNodeGeneration) {
3746
3868
  return undefined;
3747
3869
  }
3748
3870
  this.rememberSpotRoute(requested);
@@ -4143,6 +4265,9 @@ function emptyPayload() {
4143
4265
  payload: Buffer.alloc(0)
4144
4266
  };
4145
4267
  }
4268
+ function copyRetainedServiceFrames(parts) {
4269
+ return parts.map((part) => (0, payload_slab_1.copyPayloadBytes)(part));
4270
+ }
4146
4271
  /**
4147
4272
  * The generated command-28 decoder is the canonical wire authority. Keep
4148
4273
  * the stateful mailbox's internal record shape as an adapter only; it must