@zlink-systems/framework 0.31.0 → 0.32.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 (181) 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/payload-slab.d.ts +4 -0
  8. package/dist/contracts/Common/payload-slab.js +30 -0
  9. package/dist/contracts/Handlers/Contexts.d.ts +1 -0
  10. package/dist/internal.d.ts +9 -0
  11. package/dist/internal.js +23 -1
  12. package/dist/runtime/actors/actor-client.d.ts +1 -1
  13. package/dist/runtime/actors/actor-client.js +32 -23
  14. package/dist/runtime/actors/actor-context.js +1 -1
  15. package/dist/runtime/actors/actor-creation.js +1 -1
  16. package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
  17. package/dist/runtime/actors/actor-runtime-state.d.ts +3 -2
  18. package/dist/runtime/actors/actor-runtime-state.js +24 -8
  19. package/dist/runtime/actors/index.d.ts +3 -3
  20. package/dist/runtime/actors/index.js +19 -32
  21. package/dist/runtime/actors/spot-actor-dispatch.d.ts +4 -2
  22. package/dist/runtime/actors/spot-actor-dispatch.js +2 -1
  23. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
  24. package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
  25. package/dist/runtime/backend/contracts/index.d.ts +2 -0
  26. package/dist/runtime/backend/mesh-completion-table.d.ts +1 -0
  27. package/dist/runtime/backend/mesh-completion-table.js +1 -0
  28. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
  29. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
  30. package/dist/runtime/backend/node/node-raw-binding-port.js +17 -11
  31. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +2 -2
  32. package/dist/runtime/backend/node/node-raw-mesh-backend.js +15 -8
  33. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +7 -6
  34. package/dist/runtime/channels/channel-dispatch-pipeline.js +1 -0
  35. package/dist/runtime/channels/channel-dispatchers.d.ts +7 -3
  36. package/dist/runtime/channels/channel-dispatchers.js +27 -19
  37. package/dist/runtime/channels/channel-envelope.js +543 -23
  38. package/dist/runtime/channels/channel-receive-loops.d.ts +9 -6
  39. package/dist/runtime/channels/channel-receive-loops.js +59 -18
  40. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +22 -3
  41. package/dist/runtime/channels/channel-socket-registry.d.ts +22 -4
  42. package/dist/runtime/diagnostics/runtime-metrics.d.ts +1 -1
  43. package/dist/runtime/diagnostics/runtime-metrics.js +2 -1
  44. package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
  45. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +27 -11
  46. package/dist/runtime/foundation/raw-service-mesh-runtime.js +29 -25
  47. package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
  48. package/dist/runtime/foundation/service-mailbox.d.ts +3 -1
  49. package/dist/runtime/foundation/service-mailbox.js +4 -1
  50. package/dist/runtime/foundation/service-runtime-contracts.d.ts +3 -1
  51. package/dist/runtime/foundation/service-stateful-registry.d.ts +2 -0
  52. package/dist/runtime/foundation/service-stateful-registry.js +28 -12
  53. package/dist/runtime/foundation/service-stateful-runtime.d.ts +51 -19
  54. package/dist/runtime/foundation/service-stateful-runtime.js +54 -5
  55. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
  56. package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
  57. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  58. package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
  59. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +2 -0
  60. package/dist/runtime/foundation/service-wire-m6a-codec.js +17 -7
  61. package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
  62. package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
  63. package/dist/runtime/host/application-job-queue.d.ts +1 -1
  64. package/dist/runtime/host/index.d.ts +89 -36
  65. package/dist/runtime/host/index.js +101 -7
  66. package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
  67. package/dist/runtime/host/service-relocation-host-runtime.d.ts +181 -44
  68. package/dist/runtime/host/service-relocation-host-runtime.js +47 -13
  69. package/dist/runtime/host/spot-address-transport.js +50 -42
  70. package/dist/runtime/locations/actor-location-claims.js +9 -10
  71. package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
  72. package/dist/runtime/locations/auto-connect-loop.js +25 -19
  73. package/dist/runtime/locations/auto-connect-planner.js +2 -5
  74. package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
  75. package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
  76. package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
  77. package/dist/runtime/locations/in-memory-location-store.js +1 -38
  78. package/dist/runtime/locations/location-store-repository.d.ts +0 -1
  79. package/dist/runtime/locations/location-store-repository.js +13 -115
  80. package/dist/runtime/locations/runtime.d.ts +3 -3
  81. package/dist/runtime/locations/runtime.js +12 -16
  82. package/dist/runtime/messaging/creation-payload-codec.js +2 -2
  83. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
  84. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
  85. package/dist/runtime/spots/index.d.ts +20 -5
  86. package/dist/runtime/spots/index.js +14 -0
  87. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +3 -3
  88. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +1 -0
  89. package/dist/runtime/spots/spot-actor-packet-dispatch.js +13 -7
  90. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
  91. package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
  92. package/dist/runtime/spots/spot-entry-activation.d.ts +2 -1
  93. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +8 -6
  94. package/dist/runtime/spots/spot-node-runtime-manager.js +2 -0
  95. package/dist/runtime/spots/spot-route-packet-dispatch.js +7 -4
  96. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +3 -1
  97. package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
  98. package/dist/runtime/spots/spot-subscription-dispatch.js +3 -1
  99. package/dist/runtime/spots/spot-timer.d.ts +1 -1
  100. package/dist/runtime/streams/actor-session-binding-registry.d.ts +9 -3
  101. package/dist/runtime/streams/actor-session-binding-registry.js +17 -0
  102. package/dist/runtime/streams/index.d.ts +3 -3
  103. package/dist/runtime/streams/index.js +22 -2
  104. package/dist/runtime/streams/managed-stream.js +2 -1
  105. package/dist/runtime/streams/session-calls.d.ts +1 -1
  106. package/dist/runtime/streams/session-calls.js +3 -9
  107. package/dist/runtime/streams/session-context.d.ts +2 -2
  108. package/dist/runtime/streams/session-context.js +2 -2
  109. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
  110. package/dist/runtime/streams/stream-session-runtime.js +37 -12
  111. package/package.json +3 -3
  112. package/src/contracts/Actors/ZLinkActor.ts +6 -0
  113. package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
  114. package/src/contracts/Actors/index.ts +1 -0
  115. package/src/contracts/Common/payload-slab.ts +29 -0
  116. package/src/contracts/Handlers/Contexts.ts +1 -0
  117. package/src/internal.ts +17 -0
  118. package/src/runtime/actors/actor-client.ts +48 -23
  119. package/src/runtime/actors/actor-context.ts +1 -1
  120. package/src/runtime/actors/actor-creation.ts +1 -1
  121. package/src/runtime/actors/actor-mailbox.ts +1 -1
  122. package/src/runtime/actors/actor-runtime-state.ts +28 -10
  123. package/src/runtime/actors/index.ts +30 -35
  124. package/src/runtime/actors/spot-actor-dispatch.ts +4 -3
  125. package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
  126. package/src/runtime/backend/contracts/index.ts +2 -0
  127. package/src/runtime/backend/mesh-completion-table.ts +2 -0
  128. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
  129. package/src/runtime/backend/node/node-raw-binding-port.ts +20 -7
  130. package/src/runtime/backend/node/node-raw-mesh-backend.ts +18 -10
  131. package/src/runtime/channels/channel-dispatch-pipeline.ts +6 -5
  132. package/src/runtime/channels/channel-dispatchers.ts +39 -19
  133. package/src/runtime/channels/channel-envelope.ts +547 -20
  134. package/src/runtime/channels/channel-receive-loops.ts +93 -36
  135. package/src/runtime/channels/channel-runtime-lifecycle.ts +2 -2
  136. package/src/runtime/channels/channel-socket-registry.ts +3 -3
  137. package/src/runtime/diagnostics/runtime-metrics.ts +3 -1
  138. package/src/runtime/execution/serial-execution-queue.ts +13 -13
  139. package/src/runtime/foundation/raw-service-mesh-runtime.ts +40 -39
  140. package/src/runtime/foundation/service-liveness-registry.ts +1 -1
  141. package/src/runtime/foundation/service-mailbox.ts +6 -1
  142. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  143. package/src/runtime/foundation/service-stateful-registry.ts +39 -14
  144. package/src/runtime/foundation/service-stateful-runtime.ts +87 -21
  145. package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
  146. package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
  147. package/src/runtime/foundation/service-wire-m6a-codec.ts +29 -7
  148. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  149. package/src/runtime/host/actor-transfer-runtime.ts +3 -3
  150. package/src/runtime/host/application-job-queue.ts +1 -1
  151. package/src/runtime/host/index.ts +183 -44
  152. package/src/runtime/host/location-runtime-owner.ts +2 -2
  153. package/src/runtime/host/service-relocation-host-runtime.ts +101 -65
  154. package/src/runtime/host/spot-address-transport.ts +67 -61
  155. package/src/runtime/locations/actor-location-claims.ts +14 -14
  156. package/src/runtime/locations/auto-connect-loop.ts +24 -16
  157. package/src/runtime/locations/auto-connect-planner.ts +2 -5
  158. package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
  159. package/src/runtime/locations/in-memory-location-store.ts +1 -74
  160. package/src/runtime/locations/location-store-repository.ts +32 -153
  161. package/src/runtime/locations/runtime.ts +16 -28
  162. package/src/runtime/messaging/creation-payload-codec.ts +3 -3
  163. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  164. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  165. package/src/runtime/spots/index.ts +28 -4
  166. package/src/runtime/spots/spot-actor-admission-coordinator.ts +1 -1
  167. package/src/runtime/spots/spot-actor-packet-dispatch.ts +16 -6
  168. package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
  169. package/src/runtime/spots/spot-entry-activation.ts +1 -1
  170. package/src/runtime/spots/spot-node-runtime-manager.ts +8 -6
  171. package/src/runtime/spots/spot-route-packet-dispatch.ts +8 -4
  172. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +3 -1
  173. package/src/runtime/spots/spot-serial-executor.ts +1 -1
  174. package/src/runtime/spots/spot-subscription-dispatch.ts +3 -1
  175. package/src/runtime/spots/spot-timer.ts +1 -1
  176. package/src/runtime/streams/actor-session-binding-registry.ts +30 -3
  177. package/src/runtime/streams/index.ts +30 -4
  178. package/src/runtime/streams/managed-stream.ts +2 -1
  179. package/src/runtime/streams/session-calls.ts +9 -14
  180. package/src/runtime/streams/session-context.ts +6 -11
  181. package/src/runtime/streams/stream-session-runtime.ts +49 -20
@@ -25,13 +25,13 @@ interface ZLinkChannelRequestDispatchLoop {
25
25
  readonly send?: () => ZLinkMultipartOperation<ZLinkMultipartAsyncSubmitOperation>;
26
26
  }, router: ZLinkBackendRouterSocket & {
27
27
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
28
- }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader): Promise<boolean | void>;
28
+ }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader, receivedAt?: Date): Promise<boolean | void>;
29
29
  }
30
30
  interface ZLinkChannelPublishDispatchLoop {
31
31
  dispatch(topicMessage: {
32
32
  readonly topic: string;
33
33
  readonly parts: readonly Message[];
34
- }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader): Promise<void>;
34
+ }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader, receivedAt?: Date): Promise<void>;
35
35
  }
36
36
  interface ZLinkSubscriberInfrastructureResult {
37
37
  readonly consumed: boolean;
@@ -54,7 +54,7 @@ interface ZLinkRoutePacketDispatchLoop {
54
54
  readonly replyToken: unknown | null;
55
55
  }, router: {
56
56
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
57
- }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader, infrastructureChecked?: boolean): Promise<boolean | void>;
57
+ }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader, infrastructureChecked?: boolean, receivedAt?: Date): Promise<boolean | void>;
58
58
  }
59
59
  interface ZLinkChannelInfrastructureHandler {
60
60
  (received: {
@@ -87,6 +87,7 @@ export declare class ZLinkChannelReceiveLoop {
87
87
  private readonly applicationJobQueue;
88
88
  private readonly roundRobin?;
89
89
  private readonly applicationDispatchQueue;
90
+ private readonly receivedAtClock;
90
91
  private stoppedFlag;
91
92
  private isStopped;
92
93
  private running?;
@@ -96,7 +97,7 @@ export declare class ZLinkChannelReceiveLoop {
96
97
  private readonly capacityStop;
97
98
  constructor(channelName: string, router: ZLinkBackendRouterSocket & {
98
99
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
99
- }, dispatcher: ZLinkChannelRequestDispatchLoop, spotRouteBridge: ZLinkBackendSpotRouteBridge | undefined, infrastructureHandler: ZLinkChannelInfrastructureHandler | undefined, poller: ZLinkBackendReadablePoller, applicationJobQueue: ApplicationJobQueue, reportError?: ZLinkReceiveTaskErrorReporter, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, applicationDispatchQueue?: ZLinkSerialExecutionQueue);
100
+ }, dispatcher: ZLinkChannelRequestDispatchLoop, spotRouteBridge: ZLinkBackendSpotRouteBridge | undefined, infrastructureHandler: ZLinkChannelInfrastructureHandler | undefined, poller: ZLinkBackendReadablePoller, applicationJobQueue: ApplicationJobQueue, reportError?: ZLinkReceiveTaskErrorReporter, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, applicationDispatchQueue?: ZLinkSerialExecutionQueue, receivedAtClock?: () => Date);
100
101
  run(signal?: AbortSignal): Promise<void>;
101
102
  private runLoop;
102
103
  stop(): Promise<void>;
@@ -111,6 +112,7 @@ export declare class ZLinkSubscriberReceiveLoop {
111
112
  private readonly infrastructureHandler?;
112
113
  private readonly roundRobin?;
113
114
  private readonly applicationDispatchQueue;
115
+ private readonly receivedAtClock;
114
116
  private stoppedFlag;
115
117
  private isStopped;
116
118
  private running?;
@@ -118,7 +120,7 @@ export declare class ZLinkSubscriberReceiveLoop {
118
120
  private readonly receiveOwner;
119
121
  private readonly rawReceiveReservations;
120
122
  private readonly capacityStop;
121
- constructor(adapter: ZLinkChannelBackendAdapter, subscriber: ZLinkBackendSubscriberSocket, dispatcher: ZLinkChannelPublishDispatchLoop, applicationJobQueue: ApplicationJobQueue, infrastructureHandler?: ((topicMessage: ReturnType<ZLinkChannelBackendAdapter["createTopicMessage"]>) => boolean | ZLinkSubscriberInfrastructureResult) | undefined, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, reportError?: ZLinkReceiveTaskErrorReporter, applicationDispatchQueue?: ZLinkSerialExecutionQueue);
123
+ constructor(adapter: ZLinkChannelBackendAdapter, subscriber: ZLinkBackendSubscriberSocket, dispatcher: ZLinkChannelPublishDispatchLoop, applicationJobQueue: ApplicationJobQueue, infrastructureHandler?: ((topicMessage: ReturnType<ZLinkChannelBackendAdapter["createTopicMessage"]>) => boolean | ZLinkSubscriberInfrastructureResult) | undefined, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, reportError?: ZLinkReceiveTaskErrorReporter, applicationDispatchQueue?: ZLinkSerialExecutionQueue, receivedAtClock?: () => Date);
122
124
  private readonly poller;
123
125
  run(signal?: AbortSignal): Promise<void>;
124
126
  private runLoop;
@@ -134,6 +136,7 @@ export declare class ZLinkRouteReceiveLoop {
134
136
  private readonly applicationJobQueue;
135
137
  private readonly roundRobin?;
136
138
  private readonly applicationDispatchQueue;
139
+ private readonly receivedAtClock;
137
140
  private stoppedFlag;
138
141
  private isStopped;
139
142
  private running?;
@@ -143,7 +146,7 @@ export declare class ZLinkRouteReceiveLoop {
143
146
  private readonly capacityStop;
144
147
  constructor(router: ZLinkBackendRouterSocket & {
145
148
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
146
- }, dispatcher: ZLinkRoutePacketDispatchLoop, poller: ZLinkBackendReadablePoller, applicationJobQueue: ApplicationJobQueue, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, reportError?: ZLinkReceiveTaskErrorReporter, applicationDispatchQueue?: ZLinkSerialExecutionQueue);
149
+ }, dispatcher: ZLinkRoutePacketDispatchLoop, poller: ZLinkBackendReadablePoller, applicationJobQueue: ApplicationJobQueue, roundRobin?: ZLinkReceiveRoundRobinCoordinator | undefined, reportError?: ZLinkReceiveTaskErrorReporter, applicationDispatchQueue?: ZLinkSerialExecutionQueue, receivedAtClock?: () => Date);
147
150
  run(signal?: AbortSignal): Promise<void>;
148
151
  private runLoop;
149
152
  stop(): Promise<void>;
@@ -9,18 +9,50 @@ const application_job_queue_scope_1 = require("../application-jobs/application-j
9
9
  const serial_execution_queue_1 = require("../execution/serial-execution-queue");
10
10
  function createChannelApplicationDispatchQueue() {
11
11
  return new serial_execution_queue_1.ZLinkSerialExecutionQueue(async (record) => {
12
+ const permit = record.context;
13
+ const previousPermit = (0, application_job_queue_scope_1.enterApplicationJobPermitScope)(permit);
12
14
  try {
13
15
  void Promise.resolve(record.operation()).then((value) => {
14
- record.resolve(value);
15
- record.release();
16
+ try {
17
+ record.resolve(value);
18
+ }
19
+ finally {
20
+ try {
21
+ record.release();
22
+ }
23
+ finally {
24
+ (0, application_job_queue_scope_1.releaseApplicationJobPermitTurn)(permit);
25
+ }
26
+ }
16
27
  }, (error) => {
17
- record.reject(error);
18
- record.release();
28
+ try {
29
+ record.reject(error);
30
+ }
31
+ finally {
32
+ try {
33
+ record.release();
34
+ }
35
+ finally {
36
+ (0, application_job_queue_scope_1.releaseApplicationJobPermitTurn)(permit);
37
+ }
38
+ }
19
39
  });
20
40
  }
21
41
  catch (error) {
22
- record.reject(error);
23
- record.release();
42
+ try {
43
+ record.reject(error);
44
+ }
45
+ finally {
46
+ try {
47
+ record.release();
48
+ }
49
+ finally {
50
+ (0, application_job_queue_scope_1.releaseApplicationJobPermitTurn)(permit);
51
+ }
52
+ }
53
+ }
54
+ finally {
55
+ (0, application_job_queue_scope_1.leaveApplicationJobPermitScope)(previousPermit);
24
56
  }
25
57
  });
26
58
  }
@@ -122,6 +154,7 @@ class ZLinkChannelReceiveLoop {
122
154
  applicationJobQueue;
123
155
  roundRobin;
124
156
  applicationDispatchQueue;
157
+ receivedAtClock;
125
158
  // The loop awaits between the two reads and stop() can land in that gap.
126
159
  // Reading through a method keeps the second check honest; a field read stays
127
160
  // narrowed to false across the await and is treated as dead code.
@@ -134,7 +167,7 @@ class ZLinkChannelReceiveLoop {
134
167
  receiveOwner;
135
168
  rawReceiveReservations;
136
169
  capacityStop = new AbortController();
137
- constructor(channelName, router, dispatcher, spotRouteBridge, infrastructureHandler, poller, applicationJobQueue, reportError, roundRobin, applicationDispatchQueue = createChannelApplicationDispatchQueue()) {
170
+ constructor(channelName, router, dispatcher, spotRouteBridge, infrastructureHandler, poller, applicationJobQueue, reportError, roundRobin, applicationDispatchQueue = createChannelApplicationDispatchQueue(), receivedAtClock = () => new Date()) {
138
171
  this.channelName = channelName;
139
172
  this.router = router;
140
173
  this.dispatcher = dispatcher;
@@ -144,6 +177,7 @@ class ZLinkChannelReceiveLoop {
144
177
  this.applicationJobQueue = applicationJobQueue;
145
178
  this.roundRobin = roundRobin;
146
179
  this.applicationDispatchQueue = applicationDispatchQueue;
180
+ this.receivedAtClock = receivedAtClock;
147
181
  this.inFlight = new channel_receive_task_tracker_1.ZLinkReceiveTaskTracker(reportError);
148
182
  this.receiveOwner = roundRobin?.register() ?? Symbol('channel-receive-owner');
149
183
  this.rawReceiveReservations = new ZLinkRawReceiveReservationPool(exports.ZLINK_CHANNEL_RAW_RECEIVE_RESERVATION_LIMIT);
@@ -200,6 +234,7 @@ class ZLinkChannelReceiveLoop {
200
234
  this.roundRobin?.setReady(this.receiveOwner, false);
201
235
  break;
202
236
  }
237
+ const receivedAt = this.receivedAtClock();
203
238
  const receivedBytes = messageBytes(received.parts);
204
239
  let classification;
205
240
  try {
@@ -223,7 +258,7 @@ class ZLinkChannelReceiveLoop {
223
258
  }
224
259
  else {
225
260
  applicationJobPermit.markApplicationQueued();
226
- const task = (0, application_job_queue_scope_1.runWithApplicationJobPermit)(applicationJobPermit, () => this.applicationDispatchQueue.submitPreAdmitted((0, application_job_queue_scope_1.bindApplicationJobPermit)(() => this.dispatchAndClose(received, signal, classification.decodedHeader, true))));
261
+ const task = this.applicationDispatchQueue.submitPreAdmitted(() => this.dispatchAndClose(received, signal, classification.decodedHeader, true, undefined, receivedAt), undefined, applicationJobPermit);
227
262
  this.inFlight.track(task);
228
263
  }
229
264
  if (batch.record(receivedBytes))
@@ -261,7 +296,7 @@ class ZLinkChannelReceiveLoop {
261
296
  this.poller.dispose();
262
297
  }
263
298
  }
264
- async dispatchAndClose(received, signal, decodedHeader, infrastructureChecked = false, releaseRawReceive) {
299
+ async dispatchAndClose(received, signal, decodedHeader, infrastructureChecked = false, releaseRawReceive, receivedAt = this.receivedAtClock()) {
265
300
  let closeReceived = true;
266
301
  try {
267
302
  if (!infrastructureChecked) {
@@ -272,7 +307,7 @@ class ZLinkChannelReceiveLoop {
272
307
  }
273
308
  decodedHeader = classification.decodedHeader;
274
309
  }
275
- const consumed = await this.dispatcher.dispatch(received, this.router, signal, decodedHeader);
310
+ const consumed = await this.dispatcher.dispatch(received, this.router, signal, decodedHeader, receivedAt);
276
311
  if (consumed === true) {
277
312
  closeReceived = false;
278
313
  }
@@ -305,6 +340,7 @@ class ZLinkSubscriberReceiveLoop {
305
340
  infrastructureHandler;
306
341
  roundRobin;
307
342
  applicationDispatchQueue;
343
+ receivedAtClock;
308
344
  // The loop awaits between the two reads and stop() can land in that gap.
309
345
  // Reading through a method keeps the second check honest; a field read stays
310
346
  // narrowed to false across the await and is treated as dead code.
@@ -317,7 +353,7 @@ class ZLinkSubscriberReceiveLoop {
317
353
  receiveOwner;
318
354
  rawReceiveReservations;
319
355
  capacityStop = new AbortController();
320
- constructor(adapter, subscriber, dispatcher, applicationJobQueue, infrastructureHandler, roundRobin, reportError, applicationDispatchQueue = createChannelApplicationDispatchQueue()) {
356
+ constructor(adapter, subscriber, dispatcher, applicationJobQueue, infrastructureHandler, roundRobin, reportError, applicationDispatchQueue = createChannelApplicationDispatchQueue(), receivedAtClock = () => new Date()) {
321
357
  this.adapter = adapter;
322
358
  this.subscriber = subscriber;
323
359
  this.dispatcher = dispatcher;
@@ -325,6 +361,7 @@ class ZLinkSubscriberReceiveLoop {
325
361
  this.infrastructureHandler = infrastructureHandler;
326
362
  this.roundRobin = roundRobin;
327
363
  this.applicationDispatchQueue = applicationDispatchQueue;
364
+ this.receivedAtClock = receivedAtClock;
328
365
  this.inFlight = new channel_receive_task_tracker_1.ZLinkReceiveTaskTracker(reportError);
329
366
  this.poller = adapter.createReadablePoller(subscriber);
330
367
  this.receiveOwner = roundRobin?.register() ?? Symbol('subscriber-receive-owner');
@@ -391,6 +428,7 @@ class ZLinkSubscriberReceiveLoop {
391
428
  break;
392
429
  continue;
393
430
  }
431
+ const receivedAt = this.receivedAtClock();
394
432
  const receivedBytes = messageBytes(topicMessage.parts);
395
433
  let classification;
396
434
  try {
@@ -420,7 +458,7 @@ class ZLinkSubscriberReceiveLoop {
420
458
  break;
421
459
  }
422
460
  applicationJobPermit.markApplicationQueued();
423
- const task = (0, application_job_queue_scope_1.runWithApplicationJobPermit)(applicationJobPermit, () => this.applicationDispatchQueue.submitPreAdmitted((0, application_job_queue_scope_1.bindApplicationJobPermit)(() => this.dispatchAndClose(topicMessage, signal, classification.decodedHeader, true))));
461
+ const task = this.applicationDispatchQueue.submitPreAdmitted(() => this.dispatchAndClose(topicMessage, signal, classification.decodedHeader, true, undefined, receivedAt), undefined, applicationJobPermit);
424
462
  releaseRawReceive();
425
463
  this.inFlight.track(task);
426
464
  if (batch.record(receivedBytes)) {
@@ -451,7 +489,7 @@ class ZLinkSubscriberReceiveLoop {
451
489
  throw error;
452
490
  }
453
491
  }
454
- async dispatchAndClose(topicMessage, signal, decodedHeader, infrastructureChecked = false, releaseRawReceive) {
492
+ async dispatchAndClose(topicMessage, signal, decodedHeader, infrastructureChecked = false, releaseRawReceive, receivedAt = this.receivedAtClock()) {
455
493
  try {
456
494
  if (!infrastructureChecked) {
457
495
  const classification = this.classify(topicMessage);
@@ -459,7 +497,7 @@ class ZLinkSubscriberReceiveLoop {
459
497
  return;
460
498
  decodedHeader = classification.decodedHeader;
461
499
  }
462
- await this.dispatcher.dispatch(topicMessage, signal, decodedHeader);
500
+ await this.dispatcher.dispatch(topicMessage, signal, decodedHeader, receivedAt);
463
501
  }
464
502
  finally {
465
503
  releaseRawReceive?.();
@@ -484,6 +522,7 @@ class ZLinkRouteReceiveLoop {
484
522
  applicationJobQueue;
485
523
  roundRobin;
486
524
  applicationDispatchQueue;
525
+ receivedAtClock;
487
526
  // The loop awaits between the two reads and stop() can land in that gap.
488
527
  // Reading through a method keeps the second check honest; a field read stays
489
528
  // narrowed to false across the await and is treated as dead code.
@@ -496,13 +535,14 @@ class ZLinkRouteReceiveLoop {
496
535
  receiveOwner;
497
536
  rawReceiveReservations;
498
537
  capacityStop = new AbortController();
499
- constructor(router, dispatcher, poller, applicationJobQueue, roundRobin, reportError, applicationDispatchQueue = createChannelApplicationDispatchQueue()) {
538
+ constructor(router, dispatcher, poller, applicationJobQueue, roundRobin, reportError, applicationDispatchQueue = createChannelApplicationDispatchQueue(), receivedAtClock = () => new Date()) {
500
539
  this.router = router;
501
540
  this.dispatcher = dispatcher;
502
541
  this.poller = poller;
503
542
  this.applicationJobQueue = applicationJobQueue;
504
543
  this.roundRobin = roundRobin;
505
544
  this.applicationDispatchQueue = applicationDispatchQueue;
545
+ this.receivedAtClock = receivedAtClock;
506
546
  this.inFlight = new channel_receive_task_tracker_1.ZLinkReceiveTaskTracker(reportError);
507
547
  this.receiveOwner = roundRobin?.register() ?? Symbol('route-receive-owner');
508
548
  this.rawReceiveReservations = new ZLinkRawReceiveReservationPool(exports.ZLINK_CHANNEL_RAW_RECEIVE_RESERVATION_LIMIT);
@@ -560,6 +600,7 @@ class ZLinkRouteReceiveLoop {
560
600
  break;
561
601
  continue;
562
602
  }
603
+ const receivedAt = this.receivedAtClock();
563
604
  const receivedBytes = messageBytes(received.parts);
564
605
  let infrastructure;
565
606
  try {
@@ -612,7 +653,7 @@ class ZLinkRouteReceiveLoop {
612
653
  break;
613
654
  }
614
655
  applicationJobPermit.markApplicationQueued();
615
- const task = (0, application_job_queue_scope_1.runWithApplicationJobPermit)(applicationJobPermit, () => this.applicationDispatchQueue.submitPreAdmitted((0, application_job_queue_scope_1.bindApplicationJobPermit)(() => this.dispatchAndClose(received, signal, true))));
656
+ const task = this.applicationDispatchQueue.submitPreAdmitted(() => this.dispatchAndClose(received, signal, true, undefined, receivedAt), undefined, applicationJobPermit);
616
657
  releaseRawReceive();
617
658
  this.inFlight.track(task);
618
659
  if (batch.record(receivedBytes)) {
@@ -643,10 +684,10 @@ class ZLinkRouteReceiveLoop {
643
684
  throw error;
644
685
  }
645
686
  }
646
- async dispatchAndClose(received, signal, infrastructureChecked = false, releaseRawReceive) {
687
+ async dispatchAndClose(received, signal, infrastructureChecked = false, releaseRawReceive, receivedAt = this.receivedAtClock()) {
647
688
  let closeReceived = true;
648
689
  try {
649
- const consumed = await this.dispatcher.dispatch(received, this.router, signal, (0, channel_envelope_inspection_1.tryDecodeChannelHeader)(received.parts, this.dispatcher.flowEnabled?.() ?? true), infrastructureChecked);
690
+ const consumed = await this.dispatcher.dispatch(received, this.router, signal, (0, channel_envelope_inspection_1.tryDecodeChannelHeader)(received.parts, this.dispatcher.flowEnabled?.() ?? true), infrastructureChecked, receivedAt);
650
691
  if (consumed === true) {
651
692
  closeReceived = false;
652
693
  }
@@ -7,12 +7,30 @@ import { ZLinkLocationRuntime, type ZLinkLocationEventSink, type ZLinkLocationRu
7
7
  import type { Message } from '../../contracts/Common/Message';
8
8
  import type { ReceiveRecord } from '../foundation/service-runtime-contracts';
9
9
  import type { RoutingId } from '../../contracts';
10
- import { type ZLinkRouteRuntimeRequestHandler, type ZLinkRouteRuntimeSendHandler } from './channel-dispatchers';
10
+ import { ZLinkChannelPublishDispatcher, type ZLinkRouteRuntimeRequestHandler, type ZLinkRouteRuntimeSendHandler } from './channel-dispatchers';
11
+ import { ZLinkSubscriberReceiveLoop } from './channel-receive-loops';
11
12
  import { ZLinkChannelDispatchServices } from './channel-dispatch-services';
12
13
  import type { ZLinkChannelEnvelopeCodecRegistry } from './channel-envelope';
13
14
  import { ZLinkChannelSocketRegistry } from './channel-socket-registry';
14
15
  import { ZLinkSpotRouteDispatchStrategy } from './spot-route-dispatch-strategy';
15
16
  import type { ApplicationJobQueue } from '../host/application-job-queue';
17
+ interface ManualFanoutSubscriberState {
18
+ readonly channelName: string;
19
+ readonly endpoint: string;
20
+ readonly index: number;
21
+ readonly connectionId: string;
22
+ readonly taskRunner: ZLinkRuntimeTaskRunner;
23
+ readonly dispatcher: ZLinkChannelPublishDispatcher;
24
+ desired: boolean;
25
+ transition: Promise<void>;
26
+ openingToken?: symbol;
27
+ active?: ManualFanoutSubscriberActive;
28
+ stopping?: ManualFanoutSubscriberActive;
29
+ }
30
+ interface ManualFanoutSubscriberActive {
31
+ readonly token: symbol;
32
+ readonly loop: ZLinkSubscriberReceiveLoop;
33
+ }
16
34
  export interface ZLinkChannelRuntimeLifecycleOptions {
17
35
  readonly registration: ZLinkFrameworkRegistration;
18
36
  readonly adapter: ZLinkChannelBackendAdapter;
@@ -31,7 +49,7 @@ export declare class ZLinkChannelRuntimeLifecycle {
31
49
  private readonly receiveRoundRobin;
32
50
  private readonly channelReceiveLoops;
33
51
  private readonly subscriberReceiveLoops;
34
- private readonly manualFanoutSubscribers;
52
+ readonly manualFanoutSubscribers: Map<string, ManualFanoutSubscriberState>;
35
53
  private readonly manualFanoutSubscriberOwners;
36
54
  private readonly routeReceiveLoops;
37
55
  private readonly meshChannelDispatchers;
@@ -71,7 +89,7 @@ export declare class ZLinkChannelRuntimeLifecycle {
71
89
  private startChannelReceivers;
72
90
  private startSubscriberReceivers;
73
91
  private getOrCreateManualFanoutSubscriber;
74
- private requestManualFanoutConnect;
92
+ requestManualFanoutConnect(channelName: string, endpoint: string, taskRunner: ZLinkRuntimeTaskRunner, dispatcher: ZLinkChannelPublishDispatcher): void;
75
93
  private requestManualFanoutDisconnect;
76
94
  private enqueueManualFanoutTransition;
77
95
  private openManualFanoutSubscriber;
@@ -85,3 +103,4 @@ export declare class ZLinkChannelRuntimeLifecycle {
85
103
  private startRouteReceivers;
86
104
  private createSpotRouteBridgeForRouter;
87
105
  }
106
+ export {};
@@ -1,13 +1,14 @@
1
1
  import { inspectRuntime } from '../internal-observation';
2
2
  import { type RoutingId, type ZLinkClientServerServerDescriptor, type ZLinkFanoutPublisherDescriptor } from '../../contracts';
3
3
  import type { Message } from '../../contracts/Common/Message';
4
- import type { ZLinkBackendContext, ZLinkBackendDealerSocket, ZLinkBackendPublisherSocket, ZLinkBackendRouterSocket, ZLinkBackendSocketMonitor, ZLinkBackendSubscriberSocket, ZLinkChannelBackendAdapter, ZLinkMonitoringBackendAdapter } from '../backend/contracts';
4
+ import type { ZLinkBackendContext, ZLinkBackendDealerSocket, ZLinkBackendPublisherSocket, ZLinkBackendReadablePoller, ZLinkBackendRouterSocket, ZLinkBackendSocketMonitor, ZLinkBackendSubscriberSocket, ZLinkChannelBackendAdapter, ZLinkMonitoringBackendAdapter } from '../backend/contracts';
5
5
  import { type ZLinkFrameworkRegistration } from '../configuration';
6
6
  import { ZLinkListenerRecords } from '../foundation/listener-records';
7
7
  import { ServiceDiscoveryRegistry } from '../foundation/service-discovery-registry';
8
8
  import { ServiceLivenessConnection } from '../foundation/service-liveness-registry';
9
9
  import type { ApplicationJobQueue } from '../host/application-job-queue';
10
10
  import type { ZLinkChannelEnvelopeHeader } from './channel-envelope';
11
+ import { type ZLinkClientServerAdmission } from './client-server-service-wire';
11
12
  export interface ZLinkClientServerServerSocketIdentity {
12
13
  readonly serverRid: string;
13
14
  readonly lifecycleGeneration: bigint;
@@ -18,6 +19,20 @@ export interface ZLinkClientServerConnectionCallbacks {
18
19
  readonly onTerminated: (routingId: string | undefined, endpoint: string) => void;
19
20
  }
20
21
  type ClientServerDiscoveryDescriptor = Parameters<ServiceDiscoveryRegistry['admitClientServer']>[0];
22
+ interface ClientServerPhysicalConnection {
23
+ readonly channelName: string;
24
+ readonly endpoint: string;
25
+ readonly dealer: ZLinkBackendDealerSocket;
26
+ readablePoller?: ZLinkBackendReadablePoller;
27
+ monitor?: ZLinkBackendSocketMonitor;
28
+ readonly aliases: Set<string>;
29
+ readonly callbacksByAlias: Map<string, ZLinkClientServerConnectionCallbacks>;
30
+ physicalConnectionId: symbol;
31
+ readyConnectionId?: string;
32
+ admittedDescriptor?: ClientServerDiscoveryDescriptor;
33
+ liveness?: ServiceLivenessConnection;
34
+ admissionAttempt?: symbol;
35
+ }
21
36
  export interface ZLinkFanoutConnectionCallbacks {
22
37
  readonly onReady: () => void;
23
38
  readonly onTerminated: (reason: 'disconnect' | 'deadline' | 'protocol') => void;
@@ -46,7 +61,7 @@ export declare class ZLinkChannelSocketRegistry {
46
61
  private readonly routeRouters;
47
62
  private readonly routeMembers;
48
63
  private readonly clientServerIdentities;
49
- private readonly clientServerConnections;
64
+ readonly clientServerConnections: Map<string, ClientServerPhysicalConnection>;
50
65
  private readonly clientServerDiscovery;
51
66
  private readonly clientServerReadyIdentities;
52
67
  private readonly clientServerServerDescriptors;
@@ -143,9 +158,12 @@ export declare class ZLinkChannelSocketRegistry {
143
158
  * the existing admission path.
144
159
  */
145
160
  private restartClientServerAdmission;
146
- private applyClientServerDescriptorUpdate;
161
+ applyClientServerDescriptorUpdate(connectionId: string, connection: {
162
+ readonly channelName: string;
163
+ readonly physicalConnectionId: symbol;
164
+ }, admission: ZLinkClientServerAdmission): void;
147
165
  private ensureClientServerLivenessTimer;
148
- private drainSocketMonitors;
166
+ drainSocketMonitors(): void;
149
167
  private removeReadyConnection;
150
168
  private requestClientServerLiveness;
151
169
  private admitClientServerServerPeer;
@@ -169,7 +169,7 @@ export declare class ZLinkRuntimeMetrics {
169
169
  recordChannelSelectionFailure(meshName: string, channelName: string, reason: string): void;
170
170
  recordMessageDropped(meshName: string, surface: string, messageKind: string, reason: string): void;
171
171
  startInstanceSpotActivation(meshName: string, instanceSpotType: string): ZLinkRuntimeMetricOperation;
172
- startRelocation(meshName: string, objectKind: 'actor' | 'user_spot' | 'instance_spot', policy: 'recreate' | 'snapshot'): ZLinkRelocationMetricOperation;
172
+ startRelocation(meshName: string, objectKind: 'actor' | 'user_spot' | 'instance_spot', policy: 'recreate' | 'snapshot', onComplete?: (outcome: string) => void): ZLinkRelocationMetricOperation;
173
173
  recordInstanceSpotClaimConflict(meshName: string, instanceSpotType: string, reason: string): void;
174
174
  recordInstanceSpotTakeover(meshName: string, instanceSpotType: string, outcome: string): void;
175
175
  enabled(): boolean;
@@ -426,7 +426,7 @@ class ZLinkRuntimeMetrics {
426
426
  }
427
427
  };
428
428
  }
429
- startRelocation(meshName, objectKind, policy) {
429
+ startRelocation(meshName, objectKind, policy, onComplete) {
430
430
  const started = process.hrtime.bigint();
431
431
  const startAttributes = { mesh_name: meshName, object_kind: objectKind, policy };
432
432
  let completed = false;
@@ -444,6 +444,7 @@ class ZLinkRuntimeMetrics {
444
444
  const terminal = { ...startAttributes, outcome };
445
445
  this.count(exports.METRIC_NAMES.RelocationCompleted, 1, terminal);
446
446
  this.duration(exports.METRIC_NAMES.RelocationDuration, Number(process.hrtime.bigint() - started) / exports.NANOSECONDS_PER_SECOND, terminal);
447
+ onComplete?.(outcome);
447
448
  }
448
449
  };
449
450
  }
@@ -33,16 +33,28 @@ export interface ZLinkSerialWorkPreparation {
33
33
  prepare(signal: AbortSignal): Promise<void>;
34
34
  cancel(): void;
35
35
  }
36
+ type SerialWorkRecord<T> = Omit<ZLinkSerialWorkRecord<T>, 'acceptedSequence'> & {
37
+ acceptedSequence: bigint;
38
+ readonly operationEnvelope: boolean;
39
+ readonly mailbox?: ZLinkSerialExecutionQueue;
40
+ readonly preparation?: ZLinkSerialWorkPreparation;
41
+ preparationState: 'idle' | 'pending' | 'canceling' | 'ready' | 'failed';
42
+ preparationController?: AbortController;
43
+ preparationError?: unknown;
44
+ };
45
+ interface ZLinkSerialAdmissionLane {
46
+ readonly records: Array<SerialWorkRecord<unknown>>;
47
+ }
36
48
  /**
37
49
  * One event-loop serial execution queue per Spot, Actor mailbox, or Stream session.
38
50
  * Application work carries the host permit through the queue until the handler starts.
39
51
  */
40
52
  export declare class ZLinkSerialExecutionQueue {
41
- private readonly executeRecord;
53
+ readonly executeRecord: (record: ZLinkSerialWorkRecord<unknown>) => Promise<void>;
42
54
  private readonly sharedOwner?;
43
- private readonly application;
44
- private readonly lifecycle;
45
- private activeLifecycle?;
55
+ readonly application: ZLinkSerialAdmissionLane;
56
+ readonly lifecycle: ZLinkSerialAdmissionLane;
57
+ activeLifecycle?: ZLinkSerialWorkRecord<unknown>;
46
58
  private activeRecord?;
47
59
  /** The admitted node itself owns ready membership; no second readiness flag. */
48
60
  private ownerMembership?;
@@ -54,7 +66,7 @@ export declare class ZLinkSerialExecutionQueue {
54
66
  private lifecycleDebt;
55
67
  private claimStartedAt?;
56
68
  private closed;
57
- private readonly idleWaiters;
69
+ readonly idleWaiters: Array<() => void>;
58
70
  constructor(executeRecord: (record: ZLinkSerialWorkRecord<unknown>) => Promise<void>, options?: ZLinkSerialSchedulerOptions, sharedOwner?: ZLinkSerialExecutionQueue | undefined);
59
71
  submit<T>(operation: () => Promise<T> | T, options?: ZLinkSerialWorkOptions, context?: unknown): Promise<T>;
60
72
  submitDetached<T>(operation: () => Promise<T> | T, onError: (error: unknown) => void, options?: ZLinkSerialWorkOptions, context?: unknown): void;
@@ -79,22 +91,23 @@ export declare class ZLinkSerialExecutionQueue {
79
91
  /** Stops admission within the lifecycle operation that owns this queue's close. */
80
92
  closeAdmission(): void;
81
93
  get admissionClosed(): boolean;
82
- private admit;
83
- private scheduleDrain;
94
+ admit<T>(operation: () => Promise<T> | T, options: ZLinkSerialWorkOptions | undefined, context?: unknown, preparation?: ZLinkSerialWorkPreparation, operationEnvelope?: boolean): Promise<T>;
95
+ scheduleDrain(): void;
84
96
  /** Notifications carry no payload, admission sequence, result Promise, or host permit. */
85
- private enqueueMailboxTurn;
97
+ enqueueMailboxTurn(operation: () => void): void;
86
98
  /** Called only by the shared scheduler's consumer, never by a producer. */
87
99
  private consumeMailbox;
88
100
  private finishMailbox;
89
- private drain;
101
+ drain(): Promise<void>;
90
102
  private prepareSelected;
91
- private selectNext;
92
- private takeSelected;
103
+ selectNext(): SerialWorkRecord<unknown> | undefined;
104
+ takeSelected(selected: SerialWorkRecord<unknown>): ZLinkSerialWorkRecord<unknown>;
93
105
  private takeLifecycle;
94
- private takeApplication;
106
+ takeApplication(selected: SerialWorkRecord<unknown>): ZLinkSerialWorkRecord<unknown>;
95
107
  private startPreparation;
96
108
  /** Returns false while an outstanding readiness attempt is being canceled. */
97
109
  private cancelPreparationForRearbitration;
98
110
  private shouldYield;
99
- private resolveIdleWaiters;
111
+ resolveIdleWaiters(): void;
100
112
  }
113
+ export {};
@@ -3,12 +3,12 @@ import type { RequestRuntime } from './request-runtime';
3
3
  import { inspectRuntime } from '../internal-observation';
4
4
  import { ApplicationIngressRecordOwner } from '../application-jobs/application-ingress-record-owner';
5
5
  import type { ApplicationJobQueuePort } from '../application-jobs/contracts';
6
- import type { ZLinkRawBindingPort } from '../backend/raw-binding-port';
6
+ import type { ZLinkRawBindingPort, ZLinkRawReceivedRecord, ZLinkRawRouterPort } from '../backend/raw-binding-port';
7
7
  import { SubmitResult } from '../backend/runtime-values';
8
8
  import { type OperationObserver, type PendingOperation } from './operation-registry';
9
9
  import { ServiceLivenessRegistry, type ServiceLivenessTick } from './service-liveness-registry';
10
10
  import { ServiceMailbox, type ServiceMailboxRecord } from './service-mailbox';
11
- import { ServiceTopologyRegistry, type ServiceNodeDescriptor } from './service-topology-registry';
11
+ import { ServiceTopologyRegistry, type PeerAdmissionResult, type ServiceNodeDescriptor } from './service-topology-registry';
12
12
  import { type ServiceApplicationPayload } from './service-wire-m6a-codec';
13
13
  export type RawServicePumpResult = 'noData' | 'infrastructure' | 'application' | 'dropped' | 'protocolError';
14
14
  export type RawServicePumpObserver = (sourceRoutingId: string, byteCount: number) => void;
@@ -67,6 +67,12 @@ export interface RawServiceMeshRuntimeOptions {
67
67
  }) => void;
68
68
  }
69
69
  export declare const RAW_MESH_RECEIVE_TIME_BUDGET_MS = 2;
70
+ interface ControlSendState {
71
+ task?: Promise<boolean>;
72
+ next?: () => boolean | Promise<boolean>;
73
+ current?: () => boolean;
74
+ hello?: Uint8Array;
75
+ }
70
76
  /**
71
77
  * RouteMesh M6A runtime built only on the public raw binding package.
72
78
  * It owns protocol, admission, mailbox, request and liveness state.
@@ -85,7 +91,13 @@ export declare class RawServiceMeshRuntime {
85
91
  private readonly requestOwner;
86
92
  private readonly releaseOperations;
87
93
  private readonly operations;
88
- private readonly expectedPeers;
94
+ readonly expectedPeers: Map<string, {
95
+ readonly meshName: string;
96
+ readonly nodeRoutingId: string;
97
+ readonly endpoint?: string;
98
+ readonly securityIdentity?: string;
99
+ readonly lifecycleGeneration?: bigint;
100
+ }>;
89
101
  private readonly endpointOnlyPeers;
90
102
  private readonly peerConnectionIntentRemoved;
91
103
  private readonly peerRouteChanged;
@@ -93,7 +105,7 @@ export declare class RawServiceMeshRuntime {
93
105
  * The last observed Core selected route of each RID (Core ROUTER §10.1):
94
106
  * RID -> route generation. Only `observeSelectedRoutes` replaces it.
95
107
  */
96
- private selectedRoutes;
108
+ selectedRoutes: Map<string, bigint>;
97
109
  private connectionAttempts;
98
110
  private readonly bindingPort;
99
111
  private readonly applicationJobQueue;
@@ -103,7 +115,7 @@ export declare class RawServiceMeshRuntime {
103
115
  private receiveAcquisition?;
104
116
  private receivePermit?;
105
117
  private receiveRotation?;
106
- private readonly controlSends;
118
+ readonly controlSends: Map<string, ControlSendState>;
107
119
  private infrastructureFailure?;
108
120
  private readonly onReceiveReady?;
109
121
  private readonly infrastructureTaskRunner?;
@@ -114,7 +126,7 @@ export declare class RawServiceMeshRuntime {
114
126
  private readonly resolveAdvertisedEndpoint?;
115
127
  private descriptor;
116
128
  private host?;
117
- private router?;
129
+ router?: ZLinkRawRouterPort;
118
130
  private nextCorrelation;
119
131
  private serviceIngress?;
120
132
  private serviceIngressAccepts?;
@@ -186,9 +198,9 @@ export declare class RawServiceMeshRuntime {
186
198
  private acquireReceivePermit;
187
199
  private finishPendingReceive;
188
200
  private finishReceive;
189
- private reportProtocolError;
201
+ reportProtocolError(received: import('../backend/node/node-raw-binding-port').ZLinkRawReceivedRecord): void;
190
202
  private replyGenericProtocolError;
191
- private processReceived;
203
+ processReceived(received: ZLinkRawReceivedRecord, nowMs: number, applicationJobOwner: ApplicationIngressRecordOwner): RawServicePumpResult | Promise<RawServicePumpResult>;
192
204
  private finishPendingProtocolReceive;
193
205
  private finishPendingStatefulReceive;
194
206
  private receiveProtocolFailure;
@@ -223,14 +235,18 @@ export declare class RawServiceMeshRuntime {
223
235
  */
224
236
  private applicationFrame;
225
237
  private applicationPayload;
226
- private admitPeer;
238
+ admitPeer(descriptor: ServiceNodeDescriptor, connectionId: string | bigint, nowMs: number, expected?: {
239
+ readonly endpoint?: string;
240
+ readonly securityIdentity?: string;
241
+ readonly lifecycleGeneration?: bigint;
242
+ }, command?: number, descriptorBytes?: Uint8Array): PeerAdmissionResult;
227
243
  private retireNotRequiredExpectedPeer;
228
244
  private selectBilateralConnection;
229
245
  private removePeer;
230
246
  private requireStarted;
231
- private sendControl;
247
+ sendControl(targetNodeRoutingId: string, parts: readonly Uint8Array[]): Promise<boolean>;
232
248
  private submitControl;
233
- private startControlSend;
249
+ startControlSend(target: string, command: number, attempt: () => boolean | Promise<boolean>, current?: () => boolean, hello?: Uint8Array): boolean;
234
250
  reportInfrastructureFailure(error: unknown): void;
235
251
  private observeInfrastructureFailure;
236
252
  private send;