@zlink-systems/framework 0.29.1 → 0.30.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 (152) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Configuration/Builders.d.ts +1 -2
  3. package/dist/contracts/Configuration/Configs.d.ts +0 -5
  4. package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
  5. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
  6. package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
  7. package/dist/contracts/Configuration/index.d.ts +1 -1
  8. package/dist/internal.d.ts +1 -0
  9. package/dist/internal.js +3 -1
  10. package/dist/runtime/actors/actor-handoff.d.ts +3 -2
  11. package/dist/runtime/actors/actor-handoff.js +9 -4
  12. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +3 -1
  13. package/dist/runtime/application-jobs/application-ingress-record-owner.js +6 -1
  14. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +3 -1
  15. package/dist/runtime/application-jobs/application-job-queue-scope.js +5 -0
  16. package/dist/runtime/application-jobs/contracts.d.ts +5 -1
  17. package/dist/runtime/backend/contracts/index.d.ts +10 -19
  18. package/dist/runtime/backend/mesh-completion-table.d.ts +6 -4
  19. package/dist/runtime/backend/mesh-completion-table.js +28 -18
  20. package/dist/runtime/backend/mesh-dispatch-pump.js +21 -25
  21. package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
  22. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
  23. package/dist/runtime/backend/node/node-backend-adapter-support.js +24 -29
  24. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
  25. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
  26. package/dist/runtime/backend/node/node-raw-binding-port.js +11 -6
  27. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +10 -12
  28. package/dist/runtime/backend/node/node-raw-mesh-backend.js +64 -98
  29. package/dist/runtime/backend/node/node-socket-backend-adapter.js +10 -5
  30. package/dist/runtime/backend/raw-binding-port.d.ts +9 -2
  31. package/dist/runtime/channels/channel-receive-loops.js +3 -3
  32. package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
  33. package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
  34. package/dist/runtime/channels/channel-socket-registry.js +59 -82
  35. package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
  36. package/dist/runtime/diagnostics/message-flow.js +3 -3
  37. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +15 -1
  38. package/dist/runtime/foundation/raw-service-mesh-runtime.js +193 -64
  39. package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
  40. package/dist/runtime/foundation/service-liveness-registry.js +57 -44
  41. package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
  42. package/dist/runtime/foundation/service-mailbox.js +2 -1
  43. package/dist/runtime/foundation/service-stateful-runtime.d.ts +7 -6
  44. package/dist/runtime/foundation/service-stateful-runtime.js +34 -23
  45. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -2
  46. package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
  47. package/dist/runtime/foundation/service-topology-registry.d.ts +5 -3
  48. package/dist/runtime/foundation/service-topology-registry.js +9 -4
  49. package/dist/runtime/host/actor-packet-relay.js +7 -7
  50. package/dist/runtime/host/actor-runtime-options-factory.js +1 -1
  51. package/dist/runtime/host/application-job-queue.d.ts +11 -4
  52. package/dist/runtime/host/application-job-queue.js +66 -10
  53. package/dist/runtime/host/entry-actor-runtime.js +1 -1
  54. package/dist/runtime/host/index.js +15 -11
  55. package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
  56. package/dist/runtime/host/instance-activation-authority.js +89 -25
  57. package/dist/runtime/host/service-relocation-host-runtime.js +2 -2
  58. package/dist/runtime/host/spot-address-transport.d.ts +1 -0
  59. package/dist/runtime/host/spot-address-transport.js +25 -12
  60. package/dist/runtime/host/spot-runtime-options-factory.js +2 -2
  61. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
  62. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
  63. package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
  64. package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
  65. package/dist/runtime/locations/in-memory-authority-store.js +80 -8
  66. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  67. package/dist/runtime/locations/in-memory-location-store.js +19 -3
  68. package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
  69. package/dist/runtime/locations/location-store-repository.d.ts +3 -2
  70. package/dist/runtime/locations/location-store-repository.js +165 -22
  71. package/dist/runtime/locations/resolvers.d.ts +2 -1
  72. package/dist/runtime/locations/resolvers.js +10 -1
  73. package/dist/runtime/messaging/submission-result.d.ts +1 -1
  74. package/dist/runtime/messaging/submission-result.js +2 -2
  75. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +2 -0
  76. package/dist/runtime/spots/index.d.ts +4 -3
  77. package/dist/runtime/spots/index.js +14 -14
  78. package/dist/runtime/spots/spot-activation.d.ts +2 -1
  79. package/dist/runtime/spots/spot-activation.js +4 -4
  80. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
  81. package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
  82. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
  83. package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
  84. package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
  85. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
  86. package/dist/runtime/spots/spot-entry-activation.js +3 -1
  87. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
  88. package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
  89. package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
  90. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -1
  91. package/dist/runtime/streams/stream-session-runtime.js +1 -1
  92. package/package.json +3 -3
  93. package/src/contracts/Configuration/Builders.ts +1 -2
  94. package/src/contracts/Configuration/Configs.ts +0 -6
  95. package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
  96. package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
  97. package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
  98. package/src/contracts/Configuration/index.ts +1 -6
  99. package/src/internal.ts +1 -0
  100. package/src/runtime/actors/actor-handoff.ts +13 -4
  101. package/src/runtime/application-jobs/application-ingress-record-owner.ts +12 -2
  102. package/src/runtime/application-jobs/application-job-queue-scope.ts +6 -1
  103. package/src/runtime/application-jobs/contracts.ts +14 -1
  104. package/src/runtime/backend/contracts/index.ts +10 -18
  105. package/src/runtime/backend/mesh-completion-table.ts +36 -19
  106. package/src/runtime/backend/mesh-dispatch-pump.ts +19 -22
  107. package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
  108. package/src/runtime/backend/node/node-backend-adapter-support.ts +31 -29
  109. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
  110. package/src/runtime/backend/node/node-raw-binding-port.ts +19 -10
  111. package/src/runtime/backend/node/node-raw-mesh-backend.ts +81 -111
  112. package/src/runtime/backend/node/node-socket-backend-adapter.ts +12 -8
  113. package/src/runtime/backend/raw-binding-port.ts +12 -2
  114. package/src/runtime/channels/channel-receive-loops.ts +3 -3
  115. package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
  116. package/src/runtime/channels/channel-socket-registry.ts +84 -130
  117. package/src/runtime/diagnostics/message-flow.ts +1 -1
  118. package/src/runtime/foundation/raw-service-mesh-runtime.ts +268 -70
  119. package/src/runtime/foundation/service-liveness-registry.ts +68 -59
  120. package/src/runtime/foundation/service-mailbox.ts +7 -1
  121. package/src/runtime/foundation/service-stateful-runtime.ts +61 -35
  122. package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -79
  123. package/src/runtime/foundation/service-topology-registry.ts +13 -7
  124. package/src/runtime/host/actor-packet-relay.ts +7 -0
  125. package/src/runtime/host/actor-runtime-options-factory.ts +1 -0
  126. package/src/runtime/host/application-job-queue.ts +77 -10
  127. package/src/runtime/host/entry-actor-runtime.ts +1 -0
  128. package/src/runtime/host/index.ts +24 -5
  129. package/src/runtime/host/instance-activation-authority.ts +132 -27
  130. package/src/runtime/host/service-relocation-host-runtime.ts +2 -0
  131. package/src/runtime/host/spot-address-transport.ts +45 -22
  132. package/src/runtime/host/spot-runtime-options-factory.ts +2 -0
  133. package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
  134. package/src/runtime/locations/domain-store-contract.ts +6 -2
  135. package/src/runtime/locations/in-memory-authority-store.ts +113 -9
  136. package/src/runtime/locations/in-memory-location-store.ts +25 -3
  137. package/src/runtime/locations/internal-location-contracts.ts +4 -0
  138. package/src/runtime/locations/location-store-repository.ts +220 -15
  139. package/src/runtime/locations/resolvers.ts +25 -2
  140. package/src/runtime/messaging/submission-result.ts +2 -2
  141. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +2 -0
  142. package/src/runtime/spots/index.ts +16 -0
  143. package/src/runtime/spots/spot-activation.ts +5 -0
  144. package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
  145. package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
  146. package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
  147. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
  148. package/src/runtime/spots/spot-entry-activation.ts +3 -0
  149. package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
  150. package/src/runtime/spots/spot-routing-internal.ts +14 -0
  151. package/src/runtime/spots/spot-runtime-ports.ts +2 -0
  152. package/src/runtime/streams/stream-session-runtime.ts +1 -1
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import {
2
3
  ZLinkFrameworkInternalErrorKind,
3
4
  createInternalFrameworkException,
@@ -57,6 +58,7 @@ export interface ZLinkActorRequestTerminal {
57
58
 
58
59
  /** One admitted Actor packet and the routing context that must move with it. */
59
60
  export interface ZLinkActorPacketDelivery {
61
+ readonly origin: ApplicationJobOrigin;
60
62
  readonly actorId: string;
61
63
  readonly parts: readonly Message[];
62
64
  readonly returnResponse: boolean;
@@ -79,6 +81,7 @@ export type ZLinkRouteToActorJoinPrewarm = (
79
81
  actorId: string,
80
82
  objectGeneration: bigint,
81
83
  arrival: {
84
+ readonly origin: ApplicationJobOrigin;
82
85
  readonly header: Buffer;
83
86
  readonly payload: Buffer;
84
87
  readonly returnResponse: boolean;
@@ -133,6 +136,7 @@ export class ZLinkSpotActorPacketDispatch {
133
136
  constructor(private readonly options: ZLinkSpotActorPacketDispatchOptions) {}
134
137
 
135
138
  dispatch(
139
+ origin: ApplicationJobOrigin,
136
140
  actorId: string,
137
141
  parts: readonly Message[],
138
142
  returnResponse = false,
@@ -141,6 +145,7 @@ export class ZLinkSpotActorPacketDispatch {
141
145
  requestTerminal?: ZLinkActorRequestTerminal
142
146
  ): Promise<unknown> {
143
147
  return this.dispatchDelivery({
148
+ origin,
144
149
  actorId,
145
150
  parts,
146
151
  returnResponse,
@@ -212,6 +217,7 @@ export class ZLinkSpotActorPacketDispatch {
212
217
  const actor = this.options.resolveActor(actorId);
213
218
  if (actor === undefined) {
214
219
  return this.handleMissingActor(
220
+ delivery.origin,
215
221
  actorId,
216
222
  parts,
217
223
  header,
@@ -250,6 +256,7 @@ export class ZLinkSpotActorPacketDispatch {
250
256
  }
251
257
 
252
258
  private async handleMissingActor(
259
+ origin: ApplicationJobOrigin,
253
260
  actorId: string,
254
261
  parts: readonly Message[],
255
262
  header: ReturnType<typeof decodeStreamHeader>,
@@ -271,6 +278,7 @@ export class ZLinkSpotActorPacketDispatch {
271
278
  (messageKind !== ZLinkDispatchMessageKind.ActorRequest || requestTerminal !== undefined)
272
279
  ) {
273
280
  const parked = this.parkForActorJoinPrewarm(
281
+ origin,
274
282
  actorId,
275
283
  parts,
276
284
  messageKind,
@@ -328,6 +336,7 @@ export class ZLinkSpotActorPacketDispatch {
328
336
  * lifetime.
329
337
  */
330
338
  private parkForActorJoinPrewarm(
339
+ origin: ApplicationJobOrigin,
331
340
  actorId: string,
332
341
  parts: readonly Message[],
333
342
  messageKind: ZLinkDispatchMessageKind,
@@ -369,6 +378,7 @@ export class ZLinkSpotActorPacketDispatch {
369
378
  actorId,
370
379
  fallbackActorRef.objectGeneration,
371
380
  {
381
+ origin,
372
382
  header: Buffer.from(parts[0].data()),
373
383
  payload: Buffer.from(parts[1].data()),
374
384
  returnResponse,
@@ -135,6 +135,7 @@ export class ZLinkSpotActorPacketDrain {
135
135
  await this.dispatchNoBindActorRequest(noBindInfo, actorId, parts, actorRef);
136
136
  } else {
137
137
  await this.options.actorPacketHandler({
138
+ origin: 'remote',
138
139
  actorId,
139
140
  parts,
140
141
  returnResponse: false,
@@ -198,6 +199,7 @@ export class ZLinkSpotActorPacketDrain {
198
199
  ): Promise<void> {
199
200
  try {
200
201
  const response = await this.options.actorPacketHandler?.({
202
+ origin: 'remote',
201
203
  actorId,
202
204
  parts,
203
205
  returnResponse: true,
@@ -111,6 +111,7 @@ export class ZLinkSpotActorPacketRelayDispatch {
111
111
  actorPacketRelay.messageFollowContext !== undefined &&
112
112
  remoteBoundSessionTarget !== undefined;
113
113
  const response = await this.options.actorPacketHandler({
114
+ origin: 'remote',
114
115
  actorId: actorPacketRelay.actorId,
115
116
  parts: [header, payload],
116
117
  returnResponse: !followedBoundSessionReply,
@@ -465,6 +465,7 @@ export class ZLinkEntrySpotActivation {
465
465
  messageFollowOrigin
466
466
  } = delivery;
467
467
  const handoff = this.options.actorHandoffRuntime?.capture(
468
+ delivery.origin,
468
469
  actorId,
469
470
  parts,
470
471
  returnResponse,
@@ -480,6 +481,7 @@ export class ZLinkEntrySpotActivation {
480
481
  ) =>
481
482
  this.spotSerialExecutor.executeActor(actorId, () =>
482
483
  this.dispatchActorPacketInsideMailbox({
484
+ origin: delivery.origin,
483
485
  actorId,
484
486
  parts: replayedParts,
485
487
  returnResponse: replayReturnResponse,
@@ -503,6 +505,7 @@ export class ZLinkEntrySpotActivation {
503
505
  (parts, returnResponse, remoteBoundSessionTarget, fallbackActorRef) =>
504
506
  this.spotSerialExecutor.executeActor(actor.context.actorId, () =>
505
507
  this.dispatchActorPacketInsideMailbox({
508
+ origin: 'remote',
506
509
  actorId: actor.context.actorId,
507
510
  parts,
508
511
  returnResponse,
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import { RuntimeDisposal } from '../disposal';
2
3
  import { randomUUID } from 'node:crypto';
3
4
  import {
@@ -62,7 +63,6 @@ import {
62
63
  } from '../configuration';
63
64
  import type { ZLinkRuntimeEventPublisher } from '../diagnostics';
64
65
  import { runWithOutboundFlow } from '../diagnostics/flow-context';
65
- import { requireZLinkInfrastructureExecutionArea } from '../execution';
66
66
  import type { ZLinkListenerRecords } from '../foundation/listener-records';
67
67
  import {
68
68
  type ZLinkMessageFollowOrigin,
@@ -285,6 +285,7 @@ export class ZLinkSpotNodeRuntimeManager {
285
285
  routingId,
286
286
  receiveTimeoutMs: spotNode.router?.receiveTimeoutMs,
287
287
  applicationJobQueue: this.applicationJobQueue,
288
+ infrastructureTaskRunner: this.options.detachedTaskRunner,
288
289
  applicationJobReceiveFlowFailureSink: this.options.applicationJobReceiveFlowFailureSink,
289
290
  peerAdmissionSealed: () => this.options.peerAdmissionSealed?.(spotNodeName) ?? false
290
291
  });
@@ -324,6 +325,9 @@ export class ZLinkSpotNodeRuntimeManager {
324
325
  let pump: ZLinkMeshDispatchPump | undefined;
325
326
  const completions = new ZLinkMeshCompletionTable();
326
327
  try {
328
+ node.setCompletionHandler((terminal, materialize) =>
329
+ completions.complete(terminal, materialize)
330
+ );
327
331
  node.setBind(bind);
328
332
  if (spotNode.router?.advertiseHost !== undefined) {
329
333
  node.setAdvertiseHost(spotNode.router.advertiseHost);
@@ -871,17 +875,6 @@ export class ZLinkSpotNodeRuntimeManager {
871
875
  owner: ReadyRecord,
872
876
  record: ReceiveRecord
873
877
  ): Promise<void> {
874
- if (record.kind === ReceiveKind.Completion) {
875
- requireZLinkInfrastructureExecutionArea();
876
- const completions = this.meshCompletions.get(meshName);
877
- if (completions === undefined) {
878
- throw new ZLinkConfigurationException(
879
- `MeshNode '${meshName}' received a completion before its completion table was registered.`
880
- );
881
- }
882
- completions.complete(record);
883
- return;
884
- }
885
878
  const node = this.meshNodes.get(meshName);
886
879
  const targetsEntrySpot =
887
880
  owner.spotId === null ||
@@ -1051,6 +1044,7 @@ export class ZLinkSpotNodeRuntimeManager {
1051
1044
  }
1052
1045
 
1053
1046
  async dispatchEntryActorPacket(
1047
+ origin: ApplicationJobOrigin,
1054
1048
  actorId: string,
1055
1049
  parts: readonly Message[],
1056
1050
  returnResponse = false,
@@ -1090,6 +1084,7 @@ export class ZLinkSpotNodeRuntimeManager {
1090
1084
  );
1091
1085
  }
1092
1086
  return await activation.dispatchActorPacket({
1087
+ origin,
1093
1088
  actorId,
1094
1089
  parts,
1095
1090
  returnResponse,
@@ -2,6 +2,11 @@ import type { RoutingId } from '../../contracts/Common';
2
2
  import type { ZLinkFrameworkRuntimeState, ZLinkSpotKind } from '../../contracts';
3
3
 
4
4
  export interface ZLinkSpotRouteResolver {
5
+ resolve(
6
+ spotId: RoutingId,
7
+ signal: AbortSignal | undefined,
8
+ instanceIntent: true
9
+ ): Promise<ZLinkSpotRouteTarget | ZLinkInstanceReactivationRoute>;
5
10
  resolve(spotId: RoutingId, signal?: AbortSignal): Promise<ZLinkSpotRouteTarget>;
6
11
  invalidate?(spotId: RoutingId): void;
7
12
  }
@@ -28,3 +33,12 @@ export interface ZLinkSpotRouteTarget {
28
33
  /** Current state of the owning MeshNode, when the route was resolved from Location Store. */
29
34
  readonly targetNodeState?: ZLinkFrameworkRuntimeState;
30
35
  }
36
+
37
+ export interface ZLinkInstanceReactivationRoute extends Pick<
38
+ ZLinkSpotRouteTarget,
39
+ 'spotId' | 'spotKind' | 'stableType'
40
+ > {
41
+ readonly kind: 'coldActivation';
42
+ readonly meshName: string;
43
+ readonly stableType: string;
44
+ }
@@ -1,3 +1,4 @@
1
+ import type { ApplicationJobOrigin } from '../application-jobs/contracts';
1
2
  import type {
2
3
  ActorRef,
3
4
  RoutingId,
@@ -151,6 +152,7 @@ export interface ZLinkSpotBoundSessionRuntime {
151
152
 
152
153
  export interface ZLinkSpotActorHandoffRuntime {
153
154
  capture(
155
+ origin: ApplicationJobOrigin,
154
156
  actorId: string,
155
157
  parts: readonly Message[],
156
158
  returnResponse?: boolean,
@@ -1048,7 +1048,7 @@ export class ZLinkStreamSessionNodeRuntime {
1048
1048
  let packet: ZLinkBackendStreamPacket | undefined;
1049
1049
  let packetTransferred = false;
1050
1050
  try {
1051
- permit = await this.options.applicationJobQueue.acquire(signal);
1051
+ permit = await this.options.applicationJobQueue.acquire(signal, 'remote');
1052
1052
  if (this.isReceiveStopped(signal)) {
1053
1053
  permit.releaseAfterInternalProcessing();
1054
1054
  break;