@zlink-systems/framework 0.27.0 → 0.29.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 (191) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Actors/ZLinkActorClient.d.ts +1 -1
  3. package/dist/contracts/Channels/Calls.d.ts +1 -1
  4. package/dist/contracts/Configuration/Builders.d.ts +2 -1
  5. package/dist/contracts/Configuration/Configs.d.ts +0 -1
  6. package/dist/contracts/Configuration/InternalDefaults.d.ts +3 -0
  7. package/dist/contracts/Configuration/InternalDefaults.js +4 -1
  8. package/dist/contracts/Configuration/RegistrationBuilders.js +9 -0
  9. package/dist/contracts/Configuration/RegistrationNormalizers.d.ts +1 -0
  10. package/dist/contracts/Configuration/RegistrationNormalizers.js +16 -0
  11. package/dist/contracts/Configuration/RegistrationTypes.d.ts +3 -5
  12. package/dist/contracts/Configuration/RegistrationValidators.js +0 -2
  13. package/dist/contracts/Spots/Contracts.d.ts +1 -1
  14. package/dist/contracts/Streams/BoundSessionContracts.d.ts +1 -1
  15. package/dist/contracts/Streams/IZLinkSession.d.ts +2 -3
  16. package/dist/contracts/Streams/IZLinkSessionActor.d.ts +2 -2
  17. package/dist/runtime/actors/actor-client.js +7 -10
  18. package/dist/runtime/actors/actor-mailbox.d.ts +2 -2
  19. package/dist/runtime/actors/actor-mailbox.js +2 -2
  20. package/dist/runtime/actors/actor-request-deadline.d.ts +1 -3
  21. package/dist/runtime/actors/actor-request-deadline.js +4 -29
  22. package/dist/runtime/actors/actor-routed-join-transport.d.ts +2 -3
  23. package/dist/runtime/backend/contracts/index.d.ts +1 -4
  24. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +2 -0
  25. package/dist/runtime/backend/node/node-backend-adapter-support.js +35 -4
  26. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  27. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +1 -2
  28. package/dist/runtime/backend/node/node-raw-binding-port.js +10 -27
  29. package/dist/runtime/backend/node/node-raw-mesh-backend.js +1 -3
  30. package/dist/runtime/backend/node/node-socket-backend-adapter.js +1 -1
  31. package/dist/runtime/channels/channel-clients.js +8 -10
  32. package/dist/runtime/channels/channel-envelope.d.ts +1 -1
  33. package/dist/runtime/channels/channel-envelope.js +4 -10
  34. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  35. package/dist/runtime/channels/channel-outbound-operations.js +20 -36
  36. package/dist/runtime/channels/channel-runtime-manager.d.ts +4 -4
  37. package/dist/runtime/channels/channel-runtime-manager.js +8 -8
  38. package/dist/runtime/channels/channel-socket-options.js +0 -10
  39. package/dist/runtime/channels/channel-socket-registry.d.ts +1 -1
  40. package/dist/runtime/channels/channel-socket-registry.js +3 -14
  41. package/dist/runtime/channels/channel-transports.d.ts +10 -14
  42. package/dist/runtime/channels/channel-transports.js +11 -14
  43. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  44. package/dist/runtime/channels/local-spot-route-transport.js +1 -3
  45. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +1 -1
  46. package/dist/runtime/channels/router-socket-spot-route-transport.js +2 -2
  47. package/dist/runtime/channels/source-spot-router.d.ts +1 -1
  48. package/dist/runtime/channels/source-spot-router.js +2 -4
  49. package/dist/runtime/channels/spot-node-route-transport.d.ts +1 -1
  50. package/dist/runtime/channels/spot-node-route-transport.js +2 -3
  51. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +1 -1
  52. package/dist/runtime/channels/spot-route-bridge-transport.js +2 -2
  53. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +2 -4
  54. package/dist/runtime/channels/spot-route-dispatch-strategy.js +11 -12
  55. package/dist/runtime/execution/serial-execution-queue.d.ts +12 -3
  56. package/dist/runtime/execution/serial-execution-queue.js +116 -28
  57. package/dist/runtime/foundation/operation-registry.d.ts +3 -2
  58. package/dist/runtime/foundation/operation-registry.js +5 -1
  59. package/dist/runtime/foundation/raw-service-mesh-runtime.js +17 -11
  60. package/dist/runtime/foundation/service-authority-payload-codec.d.ts +0 -2
  61. package/dist/runtime/foundation/service-authority-payload-codec.js +0 -43
  62. package/dist/runtime/foundation/service-stateful-registry.d.ts +4 -3
  63. package/dist/runtime/foundation/service-stateful-registry.js +5 -2
  64. package/dist/runtime/foundation/service-stateful-runtime.d.ts +1 -8
  65. package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
  66. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +0 -11
  67. package/dist/runtime/foundation/service-stateful-wire-codec.js +1 -23
  68. package/dist/runtime/foundation/service-topology-registry.d.ts +5 -0
  69. package/dist/runtime/foundation/service-topology-registry.js +16 -17
  70. package/dist/runtime/host/actor-packet-relay.d.ts +2 -2
  71. package/dist/runtime/host/actor-packet-relay.js +8 -10
  72. package/dist/runtime/host/index.js +1 -15
  73. package/dist/runtime/host/instance-activation-authority.d.ts +0 -1
  74. package/dist/runtime/host/instance-activation-authority.js +46 -97
  75. package/dist/runtime/host/remote-bound-session-relay.js +8 -8
  76. package/dist/runtime/host/spot-address-transport.d.ts +1 -9
  77. package/dist/runtime/host/spot-address-transport.js +47 -87
  78. package/dist/runtime/host/stateful-authority-route-runtime.d.ts +1 -0
  79. package/dist/runtime/host/stateful-authority-route-runtime.js +17 -9
  80. package/dist/runtime/locations/domain-store-contract.d.ts +1 -0
  81. package/dist/runtime/locations/in-memory-authority-store.d.ts +2 -0
  82. package/dist/runtime/locations/in-memory-authority-store.js +22 -8
  83. package/dist/runtime/locations/in-memory-location-store.d.ts +1 -0
  84. package/dist/runtime/locations/in-memory-location-store.js +3 -0
  85. package/dist/runtime/locations/internal-store-contracts.d.ts +1 -1
  86. package/dist/runtime/locations/location-store-repository.d.ts +1 -0
  87. package/dist/runtime/locations/location-store-repository.js +98 -53
  88. package/dist/runtime/messaging/request-deadline.d.ts +3 -0
  89. package/dist/runtime/messaging/request-deadline.js +39 -0
  90. package/dist/runtime/messaging/submission-result.d.ts +2 -1
  91. package/dist/runtime/messaging/submission-result.js +11 -4
  92. package/dist/runtime/spots/spot-outbound.d.ts +3 -5
  93. package/dist/runtime/spots/spot-outbound.js +12 -15
  94. package/dist/runtime/spots/spot-serial-executor.js +4 -1
  95. package/dist/runtime/spots/spot-serial-turn-executor.d.ts +3 -0
  96. package/dist/runtime/spots/spot-serial-turn-executor.js +5 -0
  97. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
  98. package/dist/runtime/streams/bound-actor-relay-sender.js +14 -14
  99. package/dist/runtime/streams/bound-session-service.js +1 -1
  100. package/dist/runtime/streams/index.d.ts +2 -3
  101. package/dist/runtime/streams/index.js +6 -5
  102. package/dist/runtime/streams/managed-stream.d.ts +2 -2
  103. package/dist/runtime/streams/managed-stream.js +3 -5
  104. package/dist/runtime/streams/native-fallback-bound-session.js +13 -16
  105. package/dist/runtime/streams/protocol.js +0 -9
  106. package/dist/runtime/streams/session-calls.d.ts +5 -7
  107. package/dist/runtime/streams/session-calls.js +6 -23
  108. package/dist/runtime/streams/session-context.d.ts +4 -8
  109. package/dist/runtime/streams/session-context.js +3 -32
  110. package/dist/runtime/streams/session-serial-executor.d.ts +0 -1
  111. package/dist/runtime/streams/session-serial-executor.js +0 -3
  112. package/dist/runtime/streams/stream-message-utils.d.ts +0 -1
  113. package/dist/runtime/streams/stream-message-utils.js +0 -20
  114. package/dist/runtime/streams/stream-session-runtime.d.ts +6 -3
  115. package/dist/runtime/streams/stream-session-runtime.js +40 -85
  116. package/package.json +3 -3
  117. package/src/contracts/Actors/ZLinkActorClient.ts +1 -1
  118. package/src/contracts/Channels/Calls.ts +1 -1
  119. package/src/contracts/Configuration/Builders.ts +2 -1
  120. package/src/contracts/Configuration/Configs.ts +0 -1
  121. package/src/contracts/Configuration/InternalDefaults.ts +4 -0
  122. package/src/contracts/Configuration/RegistrationBuilders.ts +13 -3
  123. package/src/contracts/Configuration/RegistrationNormalizers.ts +25 -0
  124. package/src/contracts/Configuration/RegistrationTypes.ts +3 -5
  125. package/src/contracts/Configuration/RegistrationValidators.ts +0 -4
  126. package/src/contracts/Spots/Contracts.ts +1 -1
  127. package/src/contracts/Streams/BoundSessionContracts.ts +1 -1
  128. package/src/contracts/Streams/IZLinkSession.ts +2 -3
  129. package/src/contracts/Streams/IZLinkSessionActor.ts +2 -6
  130. package/src/runtime/actors/actor-client.ts +9 -15
  131. package/src/runtime/actors/actor-mailbox.ts +7 -2
  132. package/src/runtime/actors/actor-request-deadline.ts +4 -49
  133. package/src/runtime/actors/actor-routed-join-transport.ts +3 -5
  134. package/src/runtime/backend/contracts/index.ts +1 -8
  135. package/src/runtime/backend/node/node-backend-adapter-support.ts +45 -5
  136. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +0 -2
  137. package/src/runtime/backend/node/node-raw-binding-port.ts +15 -41
  138. package/src/runtime/backend/node/node-raw-mesh-backend.ts +1 -7
  139. package/src/runtime/backend/node/node-socket-backend-adapter.ts +1 -1
  140. package/src/runtime/channels/channel-clients.ts +9 -19
  141. package/src/runtime/channels/channel-envelope.ts +16 -28
  142. package/src/runtime/channels/channel-outbound-operations.ts +36 -38
  143. package/src/runtime/channels/channel-runtime-manager.ts +6 -28
  144. package/src/runtime/channels/channel-socket-options.ts +0 -13
  145. package/src/runtime/channels/channel-socket-registry.ts +3 -17
  146. package/src/runtime/channels/channel-transports.ts +7 -33
  147. package/src/runtime/channels/local-spot-route-transport.ts +1 -5
  148. package/src/runtime/channels/router-socket-spot-route-transport.ts +2 -6
  149. package/src/runtime/channels/source-spot-router.ts +2 -9
  150. package/src/runtime/channels/spot-node-route-transport.ts +2 -7
  151. package/src/runtime/channels/spot-route-bridge-transport.ts +5 -12
  152. package/src/runtime/channels/spot-route-dispatch-strategy.ts +11 -30
  153. package/src/runtime/execution/serial-execution-queue.ts +117 -29
  154. package/src/runtime/foundation/operation-registry.ts +16 -9
  155. package/src/runtime/foundation/raw-service-mesh-runtime.ts +17 -14
  156. package/src/runtime/foundation/service-authority-payload-codec.ts +0 -46
  157. package/src/runtime/foundation/service-stateful-registry.ts +10 -5
  158. package/src/runtime/foundation/service-stateful-runtime.ts +103 -181
  159. package/src/runtime/foundation/service-stateful-wire-codec.ts +0 -25
  160. package/src/runtime/foundation/service-topology-registry.ts +30 -20
  161. package/src/runtime/host/actor-packet-relay.ts +8 -15
  162. package/src/runtime/host/index.ts +2 -26
  163. package/src/runtime/host/instance-activation-authority.ts +58 -125
  164. package/src/runtime/host/remote-bound-session-relay.ts +8 -16
  165. package/src/runtime/host/spot-address-transport.ts +107 -166
  166. package/src/runtime/host/stateful-authority-route-runtime.ts +22 -9
  167. package/src/runtime/locations/domain-store-contract.ts +5 -0
  168. package/src/runtime/locations/in-memory-authority-store.ts +42 -8
  169. package/src/runtime/locations/in-memory-location-store.ts +8 -0
  170. package/src/runtime/locations/internal-store-contracts.ts +1 -0
  171. package/src/runtime/locations/location-store-repository.ts +130 -68
  172. package/src/runtime/messaging/request-deadline.ts +58 -0
  173. package/src/runtime/messaging/submission-result.ts +18 -4
  174. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  175. package/src/runtime/spots/spot-outbound.ts +14 -24
  176. package/src/runtime/spots/spot-serial-executor.ts +4 -1
  177. package/src/runtime/spots/spot-serial-turn-executor.ts +10 -0
  178. package/src/runtime/streams/bound-actor-relay-sender.ts +12 -26
  179. package/src/runtime/streams/bound-session-service.ts +1 -1
  180. package/src/runtime/streams/index.ts +5 -5
  181. package/src/runtime/streams/managed-stream.ts +3 -13
  182. package/src/runtime/streams/native-fallback-bound-session.ts +13 -25
  183. package/src/runtime/streams/protocol.ts +0 -13
  184. package/src/runtime/streams/session-calls.ts +8 -34
  185. package/src/runtime/streams/session-context.ts +6 -47
  186. package/src/runtime/streams/session-serial-executor.ts +0 -8
  187. package/src/runtime/streams/stream-message-utils.ts +1 -27
  188. package/src/runtime/streams/stream-session-runtime.ts +54 -97
  189. package/dist/runtime/streams/session-requests.d.ts +0 -25
  190. package/dist/runtime/streams/session-requests.js +0 -101
  191. package/src/runtime/streams/session-requests.ts +0 -110
@@ -464,13 +464,12 @@ export class ZLinkActorPacketRelay {
464
464
  async relayActorPacket(
465
465
  actor: ZLinkSessionActor,
466
466
  frameHeader: ZLinkStreamFrameHeader,
467
- payload: Message,
468
- signal?: AbortSignal
467
+ payload: Message
469
468
  ): Promise<boolean> {
470
- if (await this.relayRemoteActorPacket(actor, frameHeader, payload, signal)) {
469
+ if (await this.relayRemoteActorPacket(actor, frameHeader, payload)) {
471
470
  return true;
472
471
  }
473
- return this.relayLocalActorPacket(actor, frameHeader, payload, signal);
472
+ return this.relayLocalActorPacket(actor, frameHeader, payload);
474
473
  }
475
474
 
476
475
  async confirmRemoteSessionBinding(
@@ -581,8 +580,7 @@ export class ZLinkActorPacketRelay {
581
580
  async relayRemoteActorPacket(
582
581
  actor: ZLinkSessionActor,
583
582
  frameHeader: ZLinkStreamFrameHeader,
584
- payload: Message,
585
- signal?: AbortSignal
583
+ payload: Message
586
584
  ): Promise<boolean> {
587
585
  const streamRuntime = this.options.streamBindingRuntime();
588
586
  const responseTarget = await streamRuntime.captureBoundSessionResponseTarget(actor);
@@ -671,8 +669,7 @@ export class ZLinkActorPacketRelay {
671
669
  remoteAddress.routerChannelId,
672
670
  String(remoteAddress.targetNodeRid),
673
671
  ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET,
674
- request,
675
- signal
672
+ request
676
673
  );
677
674
  if (result.status !== ZLinkSubmitStatus.Submitted) {
678
675
  throw new Error(`Actor '${actor.actorId}' remote node relay was not admitted.`);
@@ -681,8 +678,7 @@ export class ZLinkActorPacketRelay {
681
678
  }
682
679
  if (frameHeader.kind === ZLinkStreamMessageKind.Send || frameHeader.requestSeq === undefined) {
683
680
  await this.options.routeTransport.sendToSpot(remoteAddress, request, {
684
- packetName: ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET,
685
- signal
681
+ packetName: ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET
686
682
  });
687
683
  return true;
688
684
  }
@@ -702,8 +698,7 @@ export class ZLinkActorPacketRelay {
702
698
  throw new Error(`Remote actor packet relay reply was empty for '${actor.actorId}'.`);
703
699
  }
704
700
  return JSON.parse(parts[0].getString('utf8')) as typeof reply;
705
- },
706
- signal
701
+ }
707
702
  );
708
703
  const actorPacketTarget = this.targets.decodeFromWire(reply.actorPacketTarget);
709
704
  const currentStoredRoute = await streamRuntime.sessionRouteFence(actor.actorId);
@@ -863,10 +858,8 @@ export class ZLinkActorPacketRelay {
863
858
  private async relayLocalActorPacket(
864
859
  actor: ZLinkSessionActor,
865
860
  frameHeader: ZLinkStreamFrameHeader,
866
- payload: Message,
867
- signal?: AbortSignal
861
+ payload: Message
868
862
  ): Promise<boolean> {
869
- void signal;
870
863
  const state = this.options.actorManager()?.getState(actor.actorId);
871
864
  const spotId = state?.spotId as RoutingId | undefined;
872
865
  const hasActiveSpot =
@@ -221,8 +221,6 @@ const HOST_SHUTDOWN_POLL_INTERVAL_MS = 100;
221
221
  const HANDOFF_ACCEPTANCE_POLL_INTERVAL_MS = 10;
222
222
  const DEFAULT_HOST_CONTROL_TIMEOUT_MS = 30_000;
223
223
 
224
- const LEGACY_MESH_SEND_TIMEOUT_MS = 1000;
225
-
226
224
  export interface ZLinkFrameworkRuntimeLifecycle {
227
225
  readonly isStarted: boolean;
228
226
  readonly locationRuntimeQuery?: ZLinkLocationRuntimeQuery;
@@ -367,25 +365,6 @@ export class ZLinkFrameworkRuntimeHost
367
365
  );
368
366
  this.meshRouters = new MeshRouterResolver(options.registration);
369
367
  this.spotRouterChannelIdForMesh = this.meshRouters.spotRouterChannelIdByMesh();
370
- const sendTimeoutMsForSpotMesh = (meshName: string): number =>
371
- options.registration.spotNodes.get(meshName)?.router?.sendTimeoutMs ??
372
- LEGACY_MESH_SEND_TIMEOUT_MS;
373
- const sendTimeoutMsForSpotRouteChannel = (routeChannelId: string): number => {
374
- const routeChannel = options.registration.routeChannelOptions.get(routeChannelId);
375
- if (routeChannel !== undefined) {
376
- return routeChannel.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS;
377
- }
378
- return sendTimeoutMsForSpotMesh(routeChannelId);
379
- };
380
- const defaultSpotSendTimeoutMs = Math.max(
381
- LEGACY_MESH_SEND_TIMEOUT_MS,
382
- ...[...options.registration.spotNodes.values()].map(
383
- (node) => node.router?.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS
384
- ),
385
- ...[...options.registration.routeChannelOptions.values()].map(
386
- (route) => route.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS
387
- )
388
- );
389
368
  this.routeTransport = new ZLinkRuntimeRouteTransport(
390
369
  () => this.channelRuntime,
391
370
  (routerChannelId) => this.meshRouters.canUseRouterChannel(routerChannelId),
@@ -410,9 +389,6 @@ export class ZLinkFrameworkRuntimeHost
410
389
  completions: (meshName) => this.spotNodeRuntime?.meshCompletionTable(meshName),
411
390
  codecs: { serializers: options.registration.messageSerializers },
412
391
  defaultRequestTimeoutMs: options.registration.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
413
- defaultSendTimeoutMs: defaultSpotSendTimeoutMs,
414
- sendTimeoutMsForMesh: sendTimeoutMsForSpotMesh,
415
- sendTimeoutMsForRouteChannel: sendTimeoutMsForSpotRouteChannel,
416
392
  dispatchErrors: this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink)
417
393
  });
418
394
  this.locationOwner = new ZLinkLocationRuntimeOwner({
@@ -463,8 +439,8 @@ export class ZLinkFrameworkRuntimeHost
463
439
  options
464
440
  );
465
441
  },
466
- relay: (actor, header, payload, signal) =>
467
- this.boundSessionRelay.actorPackets.relayActorPacket(actor, header, payload, signal),
442
+ relay: (actor, header, payload) =>
443
+ this.boundSessionRelay.actorPackets.relayActorPacket(actor, header, payload),
468
444
  notifyDisconnected: (actor, signal) =>
469
445
  this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal)
470
446
  });
@@ -16,7 +16,7 @@ import type {
16
16
  ZLinkAuthorityStore,
17
17
  ZLinkObjectCreationStore
18
18
  } from '../locations/internal-store-contracts';
19
- import { ZLinkFrameworkException } from '../../contracts';
19
+ import { ZLinkFrameworkErrorKind, ZLinkFrameworkException } from '../../contracts';
20
20
  import {
21
21
  decodeServiceInstanceAuthorityPayload,
22
22
  decodeServiceReadySpotAuthority,
@@ -46,7 +46,6 @@ import {
46
46
 
47
47
  const CREATION_REQUEST_RETENTION_MS = 24 * 60 * 60 * 1_000;
48
48
  const MAX_CREATION_REQUEST_BYTES = 1024 * 1024;
49
- const ACTIVATION_JOIN_POLL_INTERVAL_MS = 10;
50
49
 
51
50
  interface PendingReservation {
52
51
  readonly reservationId: string;
@@ -115,87 +114,81 @@ export class ZLinkInstanceActivationAuthority implements ServiceAsyncInstanceAct
115
114
  }
116
115
  let reserved: Awaited<ReturnType<ZLinkObjectCreationStore['reserve']>>;
117
116
  try {
118
- for (;;) {
119
- reserved = await this.options.store.reserve(
120
- {
121
- key: { kind: 'instance_spot', globalId: target.targetSpotId },
122
- intent: {
123
- stableType: target.stableType,
124
- requestContentReference: stored.reference.value,
125
- requestSha256: requestHash,
126
- requestEncodedSize: BigInt(requestBytes.byteLength)
127
- },
128
- target: {
129
- meshName: this.options.meshName,
130
- nodeRid: target.targetNodeRid,
131
- nodeLifecycleGeneration: target.targetNodeGeneration,
132
- owner
133
- },
134
- creatingPayload: encodeServiceInstanceAuthorityPayload({
135
- state: 'coldActivating',
117
+ reserved = await this.options.store.reserve(
118
+ {
119
+ key: { kind: 'instance_spot', globalId: target.targetSpotId },
120
+ intent: {
121
+ stableType: target.stableType,
122
+ requestContentReference: stored.reference.value,
123
+ requestSha256: requestHash,
124
+ requestEncodedSize: BigInt(requestBytes.byteLength)
125
+ },
126
+ target: {
127
+ meshName: this.options.meshName,
128
+ nodeRid: target.targetNodeRid,
129
+ nodeLifecycleGeneration: target.targetNodeGeneration,
130
+ owner
131
+ },
132
+ creatingPayload: encodeServiceInstanceAuthorityPayload({
133
+ state: 'coldActivating',
134
+ stableType: target.stableType,
135
+ spotId: target.targetSpotId,
136
+ ownerId: owner.ownerId,
137
+ ownerLeaseGeneration: owner.leaseGeneration,
138
+ ownerMeshName: this.options.meshName,
139
+ ownerNodeRid: target.targetNodeRid,
140
+ ownerNodeGeneration: target.targetNodeGeneration
141
+ }),
142
+ capacity: {
143
+ actors: 0,
144
+ spots: 1,
145
+ spotType: {
146
+ objectKind: 'instance_spot',
136
147
  stableType: target.stableType,
137
- spotId: target.targetSpotId,
138
- ownerId: owner.ownerId,
139
- ownerLeaseGeneration: owner.leaseGeneration,
140
- ownerMeshName: this.options.meshName,
141
- ownerNodeRid: target.targetNodeRid,
142
- ownerNodeGeneration: target.targetNodeGeneration
143
- }),
144
- capacity: {
145
- actors: 0,
146
- spots: 1,
147
- spotType: {
148
- objectKind: 'instance_spot',
149
- stableType: target.stableType,
150
- count: 1
151
- }
148
+ count: 1
152
149
  }
153
- },
154
- undefined,
155
- activation.deadlineUnixMs
156
- );
157
- if (reserved.kind !== 'alreadyExists') break;
158
- this.options.metrics?.recordInstanceSpotClaimConflict(
159
- this.options.meshName,
160
- target.stableType,
161
- 'already_exists'
162
- );
163
- await this.deleteOrphan(stored.reference);
164
- return readyExisting(reserved.current, target);
165
- }
150
+ }
151
+ },
152
+ undefined,
153
+ activation.deadlineUnixMs
154
+ );
166
155
  } catch (error) {
167
156
  await this.deleteOrphan(stored.reference);
168
157
  throw error;
169
158
  }
170
- if (
171
- reserved.kind === 'conflict' &&
172
- reserved.current.kind === 'snapshot' &&
173
- reserved.current.allocation.objectKind === 'instance_spot' &&
174
- reserved.current.allocation.stableType === target.stableType &&
175
- reserved.current.allocation.state === 'reserved'
176
- ) {
177
- this.options.metrics?.recordInstanceSpotClaimConflict(
178
- this.options.meshName,
179
- target.stableType,
180
- 'activation_in_progress'
181
- );
182
- await this.deleteOrphan(stored.reference);
183
- return await this.awaitConcurrentActivation(target, activation.deadlineUnixMs);
184
- }
185
159
  if (reserved.kind !== 'reserved') {
160
+ const conflictReason =
161
+ reserved.kind === 'alreadyExists'
162
+ ? 'already_exists'
163
+ : reserved.kind === 'conflict' &&
164
+ reserved.current.kind === 'snapshot' &&
165
+ reserved.current.allocation.objectKind === 'instance_spot' &&
166
+ reserved.current.allocation.stableType === target.stableType &&
167
+ reserved.current.allocation.state === 'reserved'
168
+ ? 'activation_in_progress'
169
+ : reserved.kind;
186
170
  this.options.metrics?.recordInstanceSpotClaimConflict(
187
171
  this.options.meshName,
188
172
  target.stableType,
189
- reserved.kind
173
+ conflictReason
190
174
  );
191
175
  await this.deleteOrphan(stored.reference);
176
+ if (reserved.kind === 'typeMismatch') {
177
+ throw createInternalFrameworkException(
178
+ ZLinkFrameworkInternalErrorKind.SpotTypeMismatch,
179
+ `Instance activation reservation failed: ${reserved.kind}.`
180
+ );
181
+ }
192
182
  if (reserved.kind === 'placementCapacityExhausted') {
193
183
  throw createInternalFrameworkException(
194
184
  ZLinkFrameworkInternalErrorKind.PlacementCapacityExhausted,
195
185
  `Instance Spot placement capacity is exhausted for '${String(target.targetSpotId)}'.`
196
186
  );
197
187
  }
198
- throw new Error(`Instance activation reservation failed: ${reserved.kind}.`);
188
+ throw new ZLinkFrameworkException(
189
+ ZLinkFrameworkErrorKind.Unavailable,
190
+ `Instance activation reservation failed: ${reserved.kind}.`
191
+ );
199
192
  }
200
193
  const reservation: ServiceInstanceActivationReservation = {
201
194
  attempt: reserved.creating.objectGeneration,
@@ -455,34 +448,6 @@ export class ZLinkInstanceActivationAuthority implements ServiceAsyncInstanceAct
455
448
  }
456
449
  }
457
450
 
458
- private async awaitConcurrentActivation(
459
- target: ServiceInstanceActivationTarget,
460
- deadlineUnixMs: bigint
461
- ): Promise<Extract<ServiceInstanceAuthorityRead, { readonly kind: 'ready' }>> {
462
- const key = authorityKey(target.targetSpotId);
463
- const deadlineMs = performance.now() + Number(deadlineUnixMs - BigInt(Date.now()));
464
- while (performance.now() <= deadlineMs) {
465
- const current = await this.options.store.readAuthority(key);
466
- if (current.kind === 'snapshot') {
467
- if (
468
- current.allocation.objectKind !== 'instance_spot' ||
469
- current.allocation.stableType !== target.stableType
470
- ) {
471
- throw new Error('Concurrent Instance activation resolved to a different Spot type.');
472
- }
473
- if (current.allocation.state === 'active') {
474
- return readyExisting(current, target);
475
- }
476
- } else {
477
- throw new Error('Concurrent Instance activation ended before the Ready barrier.');
478
- }
479
- await waitForActivationJoin(deadlineMs);
480
- }
481
- throw new Error(
482
- `Concurrent Instance activation for '${target.targetSpotId}' did not reach Ready before deadline.`
483
- );
484
- }
485
-
486
451
  private requirePending(reservation: ServiceInstanceActivationReservation): PendingReservation {
487
452
  const pending = this.pending.get(reservation.token);
488
453
  if (pending === undefined || pending.creating.objectGeneration !== reservation.attempt) {
@@ -539,38 +504,6 @@ function readyRead(
539
504
  return { kind: 'ready', route: routeFromSnapshot(snapshot), authority: snapshot };
540
505
  }
541
506
 
542
- function readyExisting(
543
- snapshot: ZLinkAuthoritySnapshot,
544
- target: ServiceInstanceActivationTarget
545
- ): Extract<ServiceInstanceAuthorityRead, { readonly kind: 'ready' }> {
546
- const decoded =
547
- decodeServiceReadySpotAuthority(snapshot.payload) ??
548
- decodeServiceClosingSpotAuthority(snapshot.payload);
549
- if (
550
- decoded?.kind !== 'instance_spot' ||
551
- decoded.stableType !== target.stableType ||
552
- decoded.spotId !== target.targetSpotId ||
553
- snapshot.allocation.objectKind !== 'instance_spot' ||
554
- snapshot.allocation.state !== 'active' ||
555
- decoded.ownerId !== snapshot.ownerId ||
556
- decoded.ownerLeaseGeneration !== snapshot.ownerLeaseGeneration ||
557
- decoded.ownerMeshName !== snapshot.allocation.descriptor.meshName ||
558
- decoded.ownerNodeGeneration !== snapshot.allocation.descriptorLifecycleGeneration ||
559
- !routingIdsEqual(decoded.ownerNodeRid, snapshot.allocation.descriptor.rid)
560
- ) {
561
- throw new Error('Existing Instance authority is not a matching Ready allocation.');
562
- }
563
- return { kind: 'ready', route: routeFromSnapshot(snapshot), authority: snapshot };
564
- }
565
-
566
- async function waitForActivationJoin(deadlineMs: number): Promise<void> {
567
- const remaining = deadlineMs - performance.now();
568
- if (remaining <= 0) return;
569
- await new Promise<void>((resolve) => {
570
- setTimeout(resolve, Math.min(ACTIVATION_JOIN_POLL_INTERVAL_MS, remaining));
571
- });
572
- }
573
-
574
507
  function requireCommitIdentity(
575
508
  target: ServiceInstanceActivationTarget,
576
509
  reservation: ServiceInstanceActivationReservation,
@@ -642,8 +642,7 @@ export class ZLinkRemoteBoundSessionRelay {
642
642
  packetName,
643
643
  requestSeq,
644
644
  response,
645
- replyOptions,
646
- signal
645
+ replyOptions
647
646
  );
648
647
  return;
649
648
  }
@@ -698,8 +697,7 @@ export class ZLinkRemoteBoundSessionRelay {
698
697
  packetName,
699
698
  requestSeq,
700
699
  error,
701
- metadata,
702
- signal
700
+ metadata
703
701
  );
704
702
  return;
705
703
  }
@@ -731,8 +729,7 @@ export class ZLinkRemoteBoundSessionRelay {
731
729
  packetName: string,
732
730
  requestSeq: bigint,
733
731
  message: unknown,
734
- replyOptions: ZLinkActorResponseOptions,
735
- signal?: AbortSignal
732
+ replyOptions: ZLinkActorResponseOptions
736
733
  ): Promise<void> {
737
734
  const actorPacketTarget = encodeRemoteActorPacketTarget(
738
735
  this.options.actorPacketTargetForState(actorId)
@@ -747,8 +744,7 @@ export class ZLinkRemoteBoundSessionRelay {
747
744
  metadata: replyOptions.metadata,
748
745
  compressPayload: replyOptions.compressPayload,
749
746
  actorPacketTarget
750
- }),
751
- signal
747
+ })
752
748
  );
753
749
  }
754
750
 
@@ -758,8 +754,7 @@ export class ZLinkRemoteBoundSessionRelay {
758
754
  packetName: string,
759
755
  requestSeq: bigint,
760
756
  error: unknown,
761
- metadata: ReadonlyMap<string, string>,
762
- signal?: AbortSignal
757
+ metadata: ReadonlyMap<string, string>
763
758
  ): Promise<void> {
764
759
  await this.sendRemoteBoundSessionControl(
765
760
  target,
@@ -772,15 +767,13 @@ export class ZLinkRemoteBoundSessionRelay {
772
767
  actorPacketTarget: encodeRemoteActorPacketTarget(
773
768
  this.options.actorPacketTargetForState(actorId)
774
769
  )
775
- }),
776
- signal
770
+ })
777
771
  );
778
772
  }
779
773
 
780
774
  private async sendRemoteBoundSessionControl(
781
775
  target: ZLinkRemoteBoundSessionTarget,
782
- payload: Record<string, unknown>,
783
- signal?: AbortSignal
776
+ payload: Record<string, unknown>
784
777
  ): Promise<void> {
785
778
  const packetName = payload.packetName;
786
779
  if (typeof packetName !== 'string') {
@@ -796,8 +789,7 @@ export class ZLinkRemoteBoundSessionRelay {
796
789
  target.routerChannelId,
797
790
  String(target.targetNodeRid),
798
791
  packetName,
799
- payload,
800
- signal
792
+ payload
801
793
  );
802
794
  if (result.status !== ZLinkSubmitStatus.Submitted) {
803
795
  throw new Error(