@zlink-systems/framework 0.30.1 → 0.30.2
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +6 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.js +18 -3
- package/dist/contracts/Common/encoded-payload-storage.d.ts +1 -1
- package/dist/contracts/Common/encoded-payload-storage.js +5 -2
- package/dist/contracts/Configuration/Builders.d.ts +1 -1
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +2 -1
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +5 -1
- package/dist/contracts/Configuration/RegistrationBuilders.js +2 -2
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
- package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +2 -2
- package/dist/contracts/Locations/Rows.d.ts +2 -0
- package/dist/contracts/Spots/Contracts.d.ts +4 -0
- package/dist/contracts/Spots/ZLinkSpot.d.ts +3 -3
- package/dist/runtime/abort.d.ts +5 -0
- package/dist/runtime/abort.js +10 -0
- package/dist/runtime/actors/actor-authority-publication.js +3 -2
- package/dist/runtime/actors/actor-client.d.ts +0 -1
- package/dist/runtime/actors/actor-client.js +38 -45
- package/dist/runtime/actors/actor-context.d.ts +2 -0
- package/dist/runtime/actors/actor-context.js +46 -9
- package/dist/runtime/actors/actor-handoff.d.ts +7 -3
- package/dist/runtime/actors/actor-handoff.js +212 -88
- package/dist/runtime/actors/actor-join-relocation.d.ts +2 -0
- package/dist/runtime/actors/actor-local-native-join.js +4 -0
- package/dist/runtime/actors/actor-mailbox.js +27 -1
- package/dist/runtime/actors/actor-remote-joiner.js +3 -1
- package/dist/runtime/actors/actor-reply.d.ts +4 -0
- package/dist/runtime/actors/actor-reply.js +29 -0
- package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -0
- package/dist/runtime/actors/actor-runtime-state.js +2 -20
- package/dist/runtime/actors/actor-source-transfer.d.ts +1 -17
- package/dist/runtime/actors/index.d.ts +6 -2
- package/dist/runtime/actors/index.js +37 -21
- package/dist/runtime/actors/session-disconnected-wire.d.ts +8 -0
- package/dist/runtime/actors/session-disconnected-wire.js +48 -0
- package/dist/runtime/admission.d.ts +9 -1
- package/dist/runtime/admission.js +55 -32
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +13 -0
- package/dist/runtime/application-jobs/application-job-queue-scope.js +27 -1
- package/dist/runtime/application-jobs/contracts.d.ts +2 -0
- package/dist/runtime/backend/contracts/index.d.ts +19 -3
- package/dist/runtime/backend/mesh-actor-session-node-adapter.js +2 -2
- package/dist/runtime/backend/mesh-completion-table.js +5 -0
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +26 -2
- package/dist/runtime/backend/mesh-dispatch-pump.js +193 -107
- package/dist/runtime/backend/node/node-raw-binding-port.js +90 -58
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +33 -8
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +142 -143
- package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +1 -1
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +5 -5
- package/dist/runtime/channels/channel-clients.d.ts +1 -0
- package/dist/runtime/channels/channel-clients.js +20 -5
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +22 -3
- package/dist/runtime/channels/channel-dispatch-pipeline.js +103 -57
- package/dist/runtime/channels/channel-dispatchers.d.ts +3 -2
- package/dist/runtime/channels/channel-dispatchers.js +44 -37
- package/dist/runtime/channels/channel-envelope.d.ts +1 -0
- package/dist/runtime/channels/channel-envelope.js +74 -31
- package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +4 -3
- package/dist/runtime/channels/channel-runtime-lifecycle.js +19 -24
- package/dist/runtime/channels/channel-runtime-manager.d.ts +3 -2
- package/dist/runtime/channels/channel-runtime-manager.js +4 -4
- package/dist/runtime/channels/channel-transports.d.ts +0 -1
- package/dist/runtime/channels/channel-transports.js +35 -33
- package/dist/runtime/channels/client-server-location-runtime.js +5 -4
- package/dist/runtime/channels/dispatch-error-reporter.d.ts +2 -1
- package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
- package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
- package/dist/runtime/channels/fanout-location-runtime.js +3 -3
- package/dist/runtime/diagnostics/flow-context.js +19 -7
- package/dist/runtime/diagnostics/index.js +4 -9
- package/dist/runtime/diagnostics/message-flow.d.ts +8 -0
- package/dist/runtime/diagnostics/message-flow.js +35 -5
- package/dist/runtime/diagnostics/runtime-metrics.d.ts +2 -2
- package/dist/runtime/diagnostics/runtime-metrics.js +10 -8
- package/dist/runtime/execution/index.d.ts +4 -2
- package/dist/runtime/execution/index.js +33 -10
- package/dist/runtime/execution/serial-execution-queue.d.ts +4 -0
- package/dist/runtime/execution/serial-execution-queue.js +21 -2
- package/dist/runtime/execution/state-lane.d.ts +2 -0
- package/dist/runtime/execution/state-lane.js +5 -0
- package/dist/runtime/foundation/operation-registry.d.ts +25 -1
- package/dist/runtime/foundation/operation-registry.js +86 -18
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +39 -3
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +151 -55
- package/dist/runtime/foundation/service-liveness-registry.d.ts +12 -1
- package/dist/runtime/foundation/service-liveness-registry.js +38 -0
- package/dist/runtime/foundation/service-mailbox.d.ts +7 -0
- package/dist/runtime/foundation/service-maintenance-runtime.js +1 -6
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -3
- package/dist/runtime/foundation/service-relocation-object-owner.js +48 -35
- package/dist/runtime/foundation/service-relocation-runtime.js +7 -3
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +8 -1
- package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +2 -1
- package/dist/runtime/foundation/service-stateful-registry.d.ts +5 -4
- package/dist/runtime/foundation/service-stateful-registry.js +24 -26
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +72 -6
- package/dist/runtime/foundation/service-stateful-runtime.js +444 -117
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +14 -1
- package/dist/runtime/foundation/service-stateful-wire-codec.js +48 -27
- package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +6 -1
- package/dist/runtime/foundation/service-wire-binary-primitives.js +27 -11
- package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
- package/dist/runtime/foundation/service-wire-constants.generated.js +1 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +10 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.js +166 -53
- package/dist/runtime/host/actor-packet-relay.d.ts +6 -4
- package/dist/runtime/host/actor-packet-relay.js +59 -72
- package/dist/runtime/host/actor-placement-coordinator.js +25 -8
- package/dist/runtime/host/actor-transfer-runtime.d.ts +7 -31
- package/dist/runtime/host/actor-transfer-runtime.js +85 -331
- package/dist/runtime/host/application-job-queue.d.ts +24 -3
- package/dist/runtime/host/application-job-queue.js +28 -41
- package/dist/runtime/host/index.d.ts +5 -1
- package/dist/runtime/host/index.js +171 -97
- package/dist/runtime/host/location-runtime-owner.js +2 -6
- package/dist/runtime/host/mesh-router-resolver.d.ts +4 -0
- package/dist/runtime/host/mesh-router-resolver.js +14 -6
- package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -4
- package/dist/runtime/host/remote-bound-session-relay.js +71 -190
- package/dist/runtime/host/route-mesh-runtime.d.ts +2 -2
- package/dist/runtime/host/route-mesh-runtime.js +5 -3
- package/dist/runtime/host/runtime-shutdown.d.ts +1 -0
- package/dist/runtime/host/runtime-shutdown.js +3 -2
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +17 -7
- package/dist/runtime/host/service-relocation-host-runtime.js +550 -367
- package/dist/runtime/host/spot-runtime-options-factory.js +15 -7
- package/dist/runtime/host/user-spot-creation-coordinator.js +33 -84
- package/dist/runtime/locations/auto-connect-loop.d.ts +2 -0
- package/dist/runtime/locations/auto-connect-loop.js +22 -14
- package/dist/runtime/locations/auto-connect-reconciler.js +0 -6
- package/dist/runtime/locations/auto-connect-types.d.ts +0 -1
- package/dist/runtime/locations/descriptor-publication.d.ts +4 -0
- package/dist/runtime/locations/descriptor-publication.js +11 -0
- package/dist/runtime/locations/domain-store-contract.d.ts +1 -0
- package/dist/runtime/locations/in-memory-authority-store.d.ts +7 -1
- package/dist/runtime/locations/in-memory-authority-store.js +56 -19
- package/dist/runtime/locations/in-memory-location-store.js +1 -10
- package/dist/runtime/locations/index.d.ts +1 -0
- package/dist/runtime/locations/index.js +1 -0
- package/dist/runtime/locations/lease-tracker.js +1 -6
- package/dist/runtime/locations/location-store-repository.d.ts +51 -1
- package/dist/runtime/locations/location-store-repository.js +363 -139
- package/dist/runtime/locations/relocation-blob.d.ts +18 -1
- package/dist/runtime/locations/relocation-blob.js +52 -1
- package/dist/runtime/locations/request-source-resolver.d.ts +37 -0
- package/dist/runtime/locations/request-source-resolver.js +80 -0
- package/dist/runtime/locations/resolvers.js +1 -1
- package/dist/runtime/locations/runtime.d.ts +6 -2
- package/dist/runtime/locations/runtime.js +37 -30
- package/dist/runtime/messaging/payload-codec.d.ts +7 -1
- package/dist/runtime/messaging/payload-codec.js +7 -6
- package/dist/runtime/messaging/request-result.js +29 -26
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +19 -1
- package/dist/runtime/protocol/service_wire_codec.generated.js +85 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +7 -1
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +23 -7
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +3 -2
- package/dist/runtime/spots/index.d.ts +18 -11
- package/dist/runtime/spots/index.js +234 -176
- package/dist/runtime/spots/spot-activation-registry.d.ts +4 -2
- package/dist/runtime/spots/spot-activation-registry.js +21 -11
- package/dist/runtime/spots/spot-activation-state.d.ts +1 -1
- package/dist/runtime/spots/spot-activation-state.js +7 -7
- package/dist/runtime/spots/spot-activation.d.ts +6 -3
- package/dist/runtime/spots/spot-activation.js +123 -44
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +13 -22
- package/dist/runtime/spots/spot-actor-membership.d.ts +0 -1
- package/dist/runtime/spots/spot-actor-membership.js +0 -8
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +33 -8
- package/dist/runtime/spots/spot-actor-packet-drain.js +5 -33
- package/dist/runtime/spots/spot-entry-activation.d.ts +2 -0
- package/dist/runtime/spots/spot-entry-activation.js +14 -9
- package/dist/runtime/spots/spot-handler-registry.d.ts +4 -3
- package/dist/runtime/spots/spot-handler-registry.js +6 -2
- package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +2 -2
- package/dist/runtime/spots/spot-manager-public.js +2 -2
- package/dist/runtime/spots/spot-node-autoconnect.d.ts +2 -1
- package/dist/runtime/spots/spot-node-autoconnect.js +18 -39
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +19 -2
- package/dist/runtime/spots/spot-node-runtime-manager.js +115 -50
- package/dist/runtime/spots/spot-outbound.js +3 -3
- package/dist/runtime/spots/spot-remote-codec.js +5 -1
- package/dist/runtime/spots/spot-runtime-ports.d.ts +0 -1
- package/dist/runtime/spots/spot-serial-executor.d.ts +10 -0
- package/dist/runtime/spots/spot-serial-executor.js +61 -8
- package/dist/runtime/spots/spot-serial-turn-executor.js +19 -2
- package/dist/runtime/spots/spot-subscription-dispatch.js +1 -1
- package/dist/runtime/spots/spot-timer.d.ts +57 -5
- package/dist/runtime/spots/spot-timer.js +287 -103
- package/dist/runtime/streams/actor-session-binding-registry.d.ts +42 -11
- package/dist/runtime/streams/actor-session-binding-registry.js +165 -48
- package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +8 -4
- package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -1
- package/dist/runtime/streams/bound-actor-relay-sender.js +15 -8
- package/dist/runtime/streams/bound-session-service.d.ts +1 -1
- package/dist/runtime/streams/bound-session-service.js +6 -11
- package/dist/runtime/streams/index.d.ts +3 -2
- package/dist/runtime/streams/index.js +6 -4
- package/dist/runtime/streams/managed-stream.js +3 -2
- package/dist/runtime/streams/native-fallback-bound-session.js +8 -73
- package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -8
- package/dist/runtime/streams/session-actor-coordinator.js +15 -32
- package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +3 -10
- package/dist/runtime/streams/stream-session-runtime.js +1 -4
- package/dist/runtime/workers/index.js +1 -1
- package/package.json +3 -3
- package/src/contracts/Common/ZLinkEncodedPayload.ts +24 -4
- package/src/contracts/Common/encoded-payload-storage.ts +6 -3
- package/src/contracts/Configuration/Builders.ts +4 -1
- package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +7 -2
- package/src/contracts/Configuration/RegistrationBuilders.ts +6 -2
- package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
- package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +2 -1
- package/src/contracts/Locations/Rows.ts +2 -0
- package/src/contracts/Spots/Contracts.ts +8 -0
- package/src/contracts/Spots/ZLinkSpot.ts +3 -3
- package/src/runtime/abort.ts +12 -0
- package/src/runtime/actors/actor-authority-publication.ts +3 -2
- package/src/runtime/actors/actor-client.ts +61 -70
- package/src/runtime/actors/actor-context.ts +49 -9
- package/src/runtime/actors/actor-handoff.ts +282 -106
- package/src/runtime/actors/actor-join-relocation.ts +2 -0
- package/src/runtime/actors/actor-local-native-join.ts +4 -0
- package/src/runtime/actors/actor-mailbox.ts +40 -2
- package/src/runtime/actors/actor-remote-joiner.ts +6 -1
- package/src/runtime/actors/actor-reply.ts +42 -0
- package/src/runtime/actors/actor-runtime-contracts.ts +2 -0
- package/src/runtime/actors/actor-runtime-state.ts +2 -20
- package/src/runtime/actors/actor-source-transfer.ts +1 -34
- package/src/runtime/actors/index.ts +41 -27
- package/src/runtime/actors/session-disconnected-wire.ts +66 -0
- package/src/runtime/admission.ts +69 -34
- package/src/runtime/application-jobs/application-job-queue-scope.ts +33 -1
- package/src/runtime/application-jobs/contracts.ts +2 -0
- package/src/runtime/backend/contracts/index.ts +39 -4
- package/src/runtime/backend/mesh-actor-session-node-adapter.ts +5 -3
- package/src/runtime/backend/mesh-completion-table.ts +4 -0
- package/src/runtime/backend/mesh-dispatch-pump.ts +223 -124
- package/src/runtime/backend/node/node-raw-binding-port.ts +106 -70
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +221 -170
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +5 -5
- package/src/runtime/channels/channel-clients.ts +49 -24
- package/src/runtime/channels/channel-dispatch-pipeline.ts +173 -124
- package/src/runtime/channels/channel-dispatchers.ts +116 -72
- package/src/runtime/channels/channel-envelope.ts +105 -36
- package/src/runtime/channels/channel-runtime-lifecycle.ts +13 -13
- package/src/runtime/channels/channel-runtime-manager.ts +12 -5
- package/src/runtime/channels/channel-transports.ts +49 -58
- package/src/runtime/channels/client-server-location-runtime.ts +11 -10
- package/src/runtime/channels/dispatch-error-reporter.ts +4 -2
- package/src/runtime/channels/fanout-location-runtime.ts +17 -9
- package/src/runtime/diagnostics/flow-context.ts +20 -7
- package/src/runtime/diagnostics/index.ts +1 -7
- package/src/runtime/diagnostics/message-flow.ts +47 -9
- package/src/runtime/diagnostics/runtime-metrics.ts +12 -10
- package/src/runtime/execution/index.ts +40 -14
- package/src/runtime/execution/serial-execution-queue.ts +31 -4
- package/src/runtime/execution/state-lane.ts +7 -0
- package/src/runtime/foundation/operation-registry.ts +98 -20
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +244 -67
- package/src/runtime/foundation/service-liveness-registry.ts +39 -0
- package/src/runtime/foundation/service-mailbox.ts +8 -0
- package/src/runtime/foundation/service-maintenance-runtime.ts +1 -8
- package/src/runtime/foundation/service-relocation-object-owner.ts +54 -37
- package/src/runtime/foundation/service-relocation-runtime.ts +7 -3
- package/src/runtime/foundation/service-runtime-contracts.ts +12 -1
- package/src/runtime/foundation/service-session-binding-ingress-port.ts +2 -1
- package/src/runtime/foundation/service-stateful-registry.ts +38 -35
- package/src/runtime/foundation/service-stateful-runtime.ts +667 -152
- package/src/runtime/foundation/service-stateful-wire-codec.ts +49 -11
- package/src/runtime/foundation/service-wire-binary-primitives.ts +35 -12
- package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
- package/src/runtime/foundation/service-wire-m6a-codec.ts +187 -51
- package/src/runtime/host/actor-packet-relay.ts +113 -94
- package/src/runtime/host/actor-placement-coordinator.ts +31 -8
- package/src/runtime/host/actor-transfer-runtime.ts +104 -430
- package/src/runtime/host/application-job-queue.ts +29 -44
- package/src/runtime/host/index.ts +286 -129
- package/src/runtime/host/location-runtime-owner.ts +2 -6
- package/src/runtime/host/mesh-router-resolver.ts +13 -5
- package/src/runtime/host/remote-bound-session-relay.ts +86 -248
- package/src/runtime/host/route-mesh-runtime.ts +11 -5
- package/src/runtime/host/runtime-shutdown.ts +15 -4
- package/src/runtime/host/service-relocation-host-runtime.ts +784 -475
- package/src/runtime/host/spot-runtime-options-factory.ts +18 -7
- package/src/runtime/host/user-spot-creation-coordinator.ts +41 -100
- package/src/runtime/locations/auto-connect-loop.ts +22 -14
- package/src/runtime/locations/auto-connect-reconciler.ts +0 -6
- package/src/runtime/locations/auto-connect-types.ts +0 -1
- package/src/runtime/locations/descriptor-publication.ts +7 -0
- package/src/runtime/locations/domain-store-contract.ts +5 -0
- package/src/runtime/locations/in-memory-authority-store.ts +85 -23
- package/src/runtime/locations/in-memory-location-store.ts +1 -12
- package/src/runtime/locations/index.ts +1 -0
- package/src/runtime/locations/lease-tracker.ts +2 -9
- package/src/runtime/locations/location-store-repository.ts +628 -152
- package/src/runtime/locations/relocation-blob.ts +75 -1
- package/src/runtime/locations/request-source-resolver.ts +138 -0
- package/src/runtime/locations/resolvers.ts +2 -2
- package/src/runtime/locations/runtime.ts +70 -40
- package/src/runtime/messaging/payload-codec.ts +8 -11
- package/src/runtime/messaging/request-result.ts +33 -29
- package/src/runtime/protocol/service_wire_codec.generated.ts +87 -4
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +13 -10
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +3 -2
- package/src/runtime/spots/index.ts +375 -281
- package/src/runtime/spots/spot-activation-registry.ts +25 -13
- package/src/runtime/spots/spot-activation-state.ts +12 -19
- package/src/runtime/spots/spot-activation.ts +170 -86
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +25 -55
- package/src/runtime/spots/spot-actor-membership.ts +0 -15
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +56 -11
- package/src/runtime/spots/spot-actor-packet-drain.ts +9 -52
- package/src/runtime/spots/spot-entry-activation.ts +24 -19
- package/src/runtime/spots/spot-handler-registry.ts +15 -4
- package/src/runtime/spots/spot-manager-internal-contracts.ts +2 -2
- package/src/runtime/spots/spot-manager-public.ts +2 -2
- package/src/runtime/spots/spot-node-autoconnect.ts +22 -45
- package/src/runtime/spots/spot-node-runtime-manager.ts +197 -67
- package/src/runtime/spots/spot-outbound.ts +3 -3
- package/src/runtime/spots/spot-remote-codec.ts +9 -2
- package/src/runtime/spots/spot-runtime-ports.ts +0 -1
- package/src/runtime/spots/spot-serial-executor.ts +97 -25
- package/src/runtime/spots/spot-serial-turn-executor.ts +22 -3
- package/src/runtime/spots/spot-subscription-dispatch.ts +1 -1
- package/src/runtime/spots/spot-timer.ts +413 -157
- package/src/runtime/streams/actor-session-binding-registry.ts +236 -64
- package/src/runtime/streams/actor-session-binding-runtime-owner.ts +16 -8
- package/src/runtime/streams/bound-actor-relay-sender.ts +23 -9
- package/src/runtime/streams/bound-session-service.ts +7 -10
- package/src/runtime/streams/index.ts +12 -6
- package/src/runtime/streams/managed-stream.ts +4 -2
- package/src/runtime/streams/native-fallback-bound-session.ts +14 -103
- package/src/runtime/streams/session-actor-coordinator.ts +39 -88
- package/src/runtime/streams/stream-binding-runtime-ports.ts +3 -9
- package/src/runtime/streams/stream-session-runtime.ts +1 -5
- package/src/runtime/workers/index.ts +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { routingIdsEqual } from '../../routing-id';
|
|
1
2
|
import { requestDurableService } from '../../foundation/durable-service-request';
|
|
3
|
+
import { encodeRoutingIdStorageHex, toBackendRoutingId } from '../../routing-id';
|
|
2
4
|
import {
|
|
3
5
|
decodeStreamWireFrame,
|
|
4
6
|
decodeStreamWireHeader,
|
|
@@ -48,6 +50,8 @@ import {
|
|
|
48
50
|
import {
|
|
49
51
|
RawServiceMeshRuntime,
|
|
50
52
|
RAW_MESH_RECEIVE_TIME_BUDGET_MS,
|
|
53
|
+
type RawServiceObservedRequest,
|
|
54
|
+
type RawServiceRequestObserver,
|
|
51
55
|
type RawServiceRequestResult
|
|
52
56
|
} from '../../foundation/raw-service-mesh-runtime';
|
|
53
57
|
import type { ServiceInstanceActivationRecoveryEnvelope } from '../../foundation/service-instance-activation-recovery-codec';
|
|
@@ -85,6 +89,7 @@ import {
|
|
|
85
89
|
type ServiceAsyncInstanceActivationAuthority,
|
|
86
90
|
type ServiceInstanceApplicationLifecycle,
|
|
87
91
|
type ServicePendingInstanceActivation,
|
|
92
|
+
type ServiceSessionOwnerDescriptors,
|
|
88
93
|
type ServiceSpotMessageFollowSeal,
|
|
89
94
|
type ServiceStatefulMailboxData,
|
|
90
95
|
type ServiceStatefulPendingOperation,
|
|
@@ -116,9 +121,10 @@ import {
|
|
|
116
121
|
ServiceWireFrameworkErrorCode
|
|
117
122
|
} from '../../foundation/service-wire-constants.generated';
|
|
118
123
|
import {
|
|
119
|
-
APPLICATION_PAYLOAD_MINIMUM_FIELD_BYTES,
|
|
120
|
-
APPLICATION_PAYLOAD_VERSION,
|
|
121
124
|
decodeApplicationPayloadView,
|
|
125
|
+
decodeMultipartApplicationPayloadView,
|
|
126
|
+
decodeMultipartApplicationParts,
|
|
127
|
+
decodeMultipartParts,
|
|
122
128
|
encodeMultipartApplicationPayload,
|
|
123
129
|
ServiceWireProtocolError,
|
|
124
130
|
type ServiceApplicationPayload
|
|
@@ -137,18 +143,20 @@ import {
|
|
|
137
143
|
ZLinkBackendResultError,
|
|
138
144
|
type ZLinkBackendMessageLike as MessageLike
|
|
139
145
|
} from '../runtime-values';
|
|
140
|
-
import { translateBindingResultError } from './node-backend-adapter-support';
|
|
141
|
-
import {
|
|
146
|
+
import { translateBindingResultError, toNativeRoutingId } from './node-backend-adapter-support';
|
|
147
|
+
import { disconnectSocketPeer } from './node-socket-backend-adapter';
|
|
142
148
|
const DEFAULT_NATIVE_ACTIVE_CAPACITY = 10_000;
|
|
143
149
|
const UNSTARTED_DIAGNOSTIC_ENDPOINT = 'inproc://not-started';
|
|
144
150
|
|
|
145
151
|
const MULTIPART_PACKET_NAME = SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME;
|
|
146
152
|
const MULTIPART_CONTENT_TYPE = SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE;
|
|
147
|
-
const FATAL_UTF8 = new TextDecoder('utf-8', { fatal: true });
|
|
148
153
|
const MAX_DRAIN_RECORDS = 64;
|
|
149
|
-
//
|
|
150
|
-
// readable handler admits receive work;
|
|
154
|
+
// The maintenance timer runs at the nearest management deadline and never
|
|
155
|
+
// sooner than this. Only the binding readable handler admits receive work;
|
|
156
|
+
// this timer never probes the socket.
|
|
151
157
|
const MESH_BACKEND_MAINTENANCE_INTERVAL_MS = 1;
|
|
158
|
+
/** The longest single timer delay Node accepts. */
|
|
159
|
+
const MESH_BACKEND_MAINTENANCE_MAX_DELAY_MS = 2 ** 31 - 1;
|
|
152
160
|
// Spec 08 §4.2 bounds the combined turn. Raw gets one equal share; stateful
|
|
153
161
|
// can use the remaining turn, including time the raw registry did not consume.
|
|
154
162
|
const MESH_BACKEND_RAW_MAINTENANCE_SHARE = 1 / 2;
|
|
@@ -185,15 +193,17 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
185
193
|
private stateful?: ServiceStatefulRuntime;
|
|
186
194
|
private readyHandler?: (domains: number) => number;
|
|
187
195
|
private maintenanceTimer?: NodeJS.Timeout;
|
|
188
|
-
private
|
|
196
|
+
private maintenanceDueMs = Number.POSITIVE_INFINITY;
|
|
197
|
+
private pumpTask?: Promise<void>;
|
|
189
198
|
private readable = 0;
|
|
190
199
|
private readonly onReadable = (receiveReady: boolean, routeReady: boolean): void => {
|
|
191
200
|
if (receiveReady) this.readable |= 1;
|
|
192
201
|
if (routeReady) this.readable |= 2;
|
|
193
|
-
|
|
202
|
+
this.pump();
|
|
194
203
|
};
|
|
195
204
|
private readonly onMaintenance = (): void => {
|
|
196
205
|
this.maintenanceTimer = undefined;
|
|
206
|
+
this.maintenanceDueMs = Number.POSITIVE_INFINITY;
|
|
197
207
|
if (this.closed) return;
|
|
198
208
|
const nowMs = performance.now();
|
|
199
209
|
const turnDeadlineMs = nowMs + RAW_MESH_RECEIVE_TIME_BUDGET_MS;
|
|
@@ -203,7 +213,7 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
203
213
|
);
|
|
204
214
|
this.stateful?.expireOperations(nowMs, turnDeadlineMs);
|
|
205
215
|
this.scheduleMaintenance();
|
|
206
|
-
|
|
216
|
+
this.pump();
|
|
207
217
|
};
|
|
208
218
|
private readonly onPendingOperationsChanged = (): void => this.scheduleMaintenance();
|
|
209
219
|
private nextPeerIntent = 1n;
|
|
@@ -228,6 +238,8 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
228
238
|
record: import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord
|
|
229
239
|
) => void;
|
|
230
240
|
private dispatchErrors?: ZLinkDispatchErrorReporter;
|
|
241
|
+
private sessionOwnerDescriptors?: ServiceSessionOwnerDescriptors;
|
|
242
|
+
private requestSourceAcceptance?: import('../contracts').ZLinkBackendRequestSourceAcceptance;
|
|
231
243
|
private readonly peerDisconnectedHandlers = new Set<(endpoint: string) => void>();
|
|
232
244
|
constructor(
|
|
233
245
|
private readonly meshName: string,
|
|
@@ -284,6 +296,11 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
284
296
|
this.stateful?.setDispatchErrorReporter(reporter, this.meshName);
|
|
285
297
|
}
|
|
286
298
|
|
|
299
|
+
setSessionOwnerDescriptors(source: ServiceSessionOwnerDescriptors): void {
|
|
300
|
+
this.sessionOwnerDescriptors = source;
|
|
301
|
+
this.stateful?.setSessionOwnerDescriptors(source);
|
|
302
|
+
}
|
|
303
|
+
|
|
287
304
|
setProtocolErrorHandler(
|
|
288
305
|
handler: (record: {
|
|
289
306
|
readonly sourceNodeRid: string;
|
|
@@ -364,7 +381,7 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
364
381
|
}
|
|
365
382
|
|
|
366
383
|
setRoutingId(routingId: unknown): void {
|
|
367
|
-
if (
|
|
384
|
+
if (!routingIdsEqual(toBackendRoutingId(routingId), this.routingId)) {
|
|
368
385
|
throw new Error('MeshNode routing id is immutable after construction.');
|
|
369
386
|
}
|
|
370
387
|
}
|
|
@@ -432,15 +449,21 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
432
449
|
if (this.dispatchErrors !== undefined) {
|
|
433
450
|
this.stateful.setDispatchErrorReporter(this.dispatchErrors, this.meshName);
|
|
434
451
|
}
|
|
452
|
+
if (this.sessionOwnerDescriptors !== undefined) {
|
|
453
|
+
this.stateful.setSessionOwnerDescriptors(this.sessionOwnerDescriptors);
|
|
454
|
+
}
|
|
435
455
|
if (this.mailboxRecordDropped !== undefined) {
|
|
436
456
|
this.stateful.setMailboxDropHandler(this.mailboxRecordDropped);
|
|
437
457
|
}
|
|
438
458
|
this.stateful.setMessageFollowHandler((record) => this.messageFollowHandler?.(record));
|
|
459
|
+
if (this.requestSourceAcceptance !== undefined) {
|
|
460
|
+
this.stateful.setRequestSourceAcceptance(this.requestSourceAcceptance);
|
|
461
|
+
}
|
|
439
462
|
this.runtime = runtime;
|
|
440
463
|
try {
|
|
441
464
|
runtime.setReadableHandler(this.onReadable);
|
|
442
465
|
} catch (error) {
|
|
443
|
-
this.close();
|
|
466
|
+
void this.close().catch((failure) => runtime.reportInfrastructureFailure(failure));
|
|
444
467
|
throw error;
|
|
445
468
|
}
|
|
446
469
|
this.scheduleMaintenance();
|
|
@@ -464,25 +487,30 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
464
487
|
return await this.requireStateful().sendMessageFollowNotification(targetNodeRid, record);
|
|
465
488
|
}
|
|
466
489
|
|
|
467
|
-
shutdown(_timeoutMs: number): RequestResultValue {
|
|
468
|
-
this.close();
|
|
490
|
+
async shutdown(_timeoutMs: number): Promise<RequestResultValue> {
|
|
491
|
+
await this.close();
|
|
469
492
|
return RequestResult.Ok;
|
|
470
493
|
}
|
|
471
494
|
|
|
495
|
+
cancelPendingOperations(reason: unknown): void {
|
|
496
|
+
this.stateful?.cancelPendingOperations(reason);
|
|
497
|
+
this.runtime?.cancelPendingOperations(reason);
|
|
498
|
+
}
|
|
499
|
+
|
|
472
500
|
async publishDraining(): Promise<void> {
|
|
473
501
|
for (const name of this.channels.keys()) this.channels.set(name, 0);
|
|
474
502
|
await this.requireRuntime().updateLocalDescriptor({ state: 'draining' });
|
|
475
503
|
}
|
|
476
504
|
|
|
477
|
-
close(): void {
|
|
478
|
-
|
|
505
|
+
async close(): Promise<void> {
|
|
506
|
+
this.closed = true;
|
|
479
507
|
if (this.maintenanceTimer !== undefined) clearTimeout(this.maintenanceTimer);
|
|
480
508
|
this.maintenanceTimer = undefined;
|
|
509
|
+
if (this.pumpTask !== undefined) await this.pumpTask;
|
|
481
510
|
this.stateful?.close();
|
|
482
511
|
this.stateful = undefined;
|
|
483
512
|
this.runtime?.close();
|
|
484
513
|
this.runtime = undefined;
|
|
485
|
-
this.closed = true;
|
|
486
514
|
}
|
|
487
515
|
|
|
488
516
|
addChannelName(name: string): void {
|
|
@@ -545,6 +573,13 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
545
573
|
return intent;
|
|
546
574
|
}
|
|
547
575
|
|
|
576
|
+
setRequestSourceAcceptance(
|
|
577
|
+
acceptance: import('../contracts').ZLinkBackendRequestSourceAcceptance
|
|
578
|
+
): void {
|
|
579
|
+
this.requestSourceAcceptance = acceptance;
|
|
580
|
+
this.stateful?.setRequestSourceAcceptance(acceptance);
|
|
581
|
+
}
|
|
582
|
+
|
|
548
583
|
expectPeer(peer: {
|
|
549
584
|
readonly nodeRoutingId: string;
|
|
550
585
|
readonly endpoint: string;
|
|
@@ -629,6 +664,20 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
629
664
|
return this.requireRuntime().isObjectClientNodeDirectTarget(String(targetRid));
|
|
630
665
|
}
|
|
631
666
|
|
|
667
|
+
waitForPeerRoute(
|
|
668
|
+
targetRid: unknown,
|
|
669
|
+
lifecycleGeneration: bigint,
|
|
670
|
+
deadlineUnixMs: bigint,
|
|
671
|
+
signal?: AbortSignal
|
|
672
|
+
): Promise<void> {
|
|
673
|
+
return this.requireRuntime().waitForPeerRoute(
|
|
674
|
+
String(targetRid),
|
|
675
|
+
lifecycleGeneration,
|
|
676
|
+
deadlineUnixMs,
|
|
677
|
+
signal
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
632
681
|
observePeerRoute(targetRid: unknown) {
|
|
633
682
|
return this.requireRuntime().observePeerRoute(String(targetRid));
|
|
634
683
|
}
|
|
@@ -716,9 +765,11 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
716
765
|
String(targetRid),
|
|
717
766
|
encodeMultipartApplicationFrame(parts),
|
|
718
767
|
options?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
719
|
-
options?.onAdmitted
|
|
768
|
+
options?.onAdmitted,
|
|
769
|
+
this.requestObserver,
|
|
770
|
+
OperationKind.NodeRequest
|
|
720
771
|
);
|
|
721
|
-
return this.
|
|
772
|
+
return this.observedOperation(pending, OperationKind.NodeRequest);
|
|
722
773
|
}
|
|
723
774
|
|
|
724
775
|
async sendToChannel(
|
|
@@ -737,9 +788,11 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
737
788
|
channelName,
|
|
738
789
|
encodeMultipartApplicationFrame(parts),
|
|
739
790
|
options?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
740
|
-
options?.onAdmitted
|
|
791
|
+
options?.onAdmitted,
|
|
792
|
+
this.requestObserver,
|
|
793
|
+
OperationKind.ChannelRequest
|
|
741
794
|
);
|
|
742
|
-
return this.
|
|
795
|
+
return this.observedOperation(pending, OperationKind.ChannelRequest);
|
|
743
796
|
}
|
|
744
797
|
|
|
745
798
|
status() {
|
|
@@ -945,7 +998,8 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
945
998
|
}
|
|
946
999
|
|
|
947
1000
|
waitForInstanceApplicationQuiescence(spotId: string, signal?: AbortSignal): Promise<void> {
|
|
948
|
-
|
|
1001
|
+
// Closing the stateful owner terminalizes its operations and clears these waiters.
|
|
1002
|
+
return this.stateful?.waitForInstanceApplicationQuiescence(spotId, signal) ?? Promise.resolve();
|
|
949
1003
|
}
|
|
950
1004
|
|
|
951
1005
|
restoreUserSpotAuthority(
|
|
@@ -1031,7 +1085,7 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1031
1085
|
generation: actor.generation
|
|
1032
1086
|
},
|
|
1033
1087
|
String(sessionNodeRid),
|
|
1034
|
-
|
|
1088
|
+
toBackendRoutingId(sessionRid),
|
|
1035
1089
|
bindingGeneration
|
|
1036
1090
|
);
|
|
1037
1091
|
}
|
|
@@ -1163,7 +1217,7 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1163
1217
|
|
|
1164
1218
|
commitSpotMessageFollowIngress(
|
|
1165
1219
|
seal: ServiceSpotMessageFollowSeal,
|
|
1166
|
-
target: ServiceDirectSpotRouteFence,
|
|
1220
|
+
target: ServiceDirectSpotRouteFence | null,
|
|
1167
1221
|
durationMs: number
|
|
1168
1222
|
): Promise<boolean> {
|
|
1169
1223
|
return this.requireStateful().commitSpotMessageFollowIngress(seal, target, durationMs);
|
|
@@ -1344,36 +1398,52 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1344
1398
|
|
|
1345
1399
|
async sendToActor(
|
|
1346
1400
|
actor: ZLinkBackendActorRef,
|
|
1347
|
-
parts: MessageLike | readonly MessageLike[]
|
|
1401
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1402
|
+
options?: {
|
|
1403
|
+
readonly flags?: number;
|
|
1404
|
+
readonly routeFence?: import('../../foundation/service-stateful-wire-codec').ServiceActorRouteFence;
|
|
1405
|
+
}
|
|
1348
1406
|
): Promise<SubmitResultValue> {
|
|
1349
1407
|
return this.requireStateful().sendToActor(
|
|
1350
1408
|
actor,
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1409
|
+
encodeMultipart(parts),
|
|
1410
|
+
undefined,
|
|
1411
|
+
undefined,
|
|
1412
|
+
options?.routeFence
|
|
1354
1413
|
) as Promise<SubmitResultValue>;
|
|
1355
1414
|
}
|
|
1356
1415
|
|
|
1357
1416
|
requestToActor(
|
|
1358
1417
|
actor: ZLinkBackendActorRef,
|
|
1359
1418
|
parts: MessageLike | readonly MessageLike[],
|
|
1360
|
-
options?: {
|
|
1419
|
+
options?: {
|
|
1420
|
+
readonly timeoutMs?: number;
|
|
1421
|
+
readonly onAdmitted?: () => void;
|
|
1422
|
+
readonly routeFence?: import('../../foundation/service-stateful-wire-codec').ServiceActorRouteFence;
|
|
1423
|
+
}
|
|
1361
1424
|
): MeshOperationId {
|
|
1362
1425
|
return this.observeStateful(
|
|
1363
1426
|
OperationKind.ActorRequest,
|
|
1364
1427
|
this.requireStateful().requestToActor(
|
|
1365
1428
|
actor,
|
|
1366
|
-
this.peerGeneration(String(actor.nodeRid)),
|
|
1367
|
-
actor.generation,
|
|
1368
1429
|
encodeMultipart(parts),
|
|
1369
1430
|
options?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
1370
1431
|
undefined,
|
|
1371
1432
|
undefined,
|
|
1372
|
-
options?.onAdmitted
|
|
1433
|
+
options?.onAdmitted,
|
|
1434
|
+
options?.routeFence
|
|
1373
1435
|
)
|
|
1374
1436
|
);
|
|
1375
1437
|
}
|
|
1376
1438
|
|
|
1439
|
+
acceptRelocatedActorTerminal(
|
|
1440
|
+
operation: { readonly high: bigint; readonly low: bigint },
|
|
1441
|
+
replyRouteId: bigint,
|
|
1442
|
+
result: import('../../foundation/service-stateful-runtime').ServiceStatefulResult
|
|
1443
|
+
): 'terminalReceived' | 'alreadyTerminal' | undefined {
|
|
1444
|
+
return this.requireStateful().acceptRelocatedActorTerminal(operation, replyRouteId, result);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1377
1447
|
async actorSendToActor(
|
|
1378
1448
|
source: ZLinkBackendActorRef,
|
|
1379
1449
|
target: ZLinkBackendActorRef,
|
|
@@ -1381,8 +1451,6 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1381
1451
|
): Promise<SubmitResultValue> {
|
|
1382
1452
|
return (await this.requireStateful().sendToActor(
|
|
1383
1453
|
target,
|
|
1384
|
-
this.peerGeneration(String(target.nodeRid)),
|
|
1385
|
-
target.generation,
|
|
1386
1454
|
encodeMultipart(parts),
|
|
1387
1455
|
source
|
|
1388
1456
|
)) as SubmitResultValue;
|
|
@@ -1398,8 +1466,6 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1398
1466
|
OperationKind.ActorRequest,
|
|
1399
1467
|
this.requireStateful().requestToActor(
|
|
1400
1468
|
target,
|
|
1401
|
-
this.peerGeneration(String(target.nodeRid)),
|
|
1402
|
-
target.generation,
|
|
1403
1469
|
encodeMultipart(parts),
|
|
1404
1470
|
options?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
1405
1471
|
source,
|
|
@@ -1427,18 +1493,9 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1427
1493
|
expectedBindingGeneration: bigint,
|
|
1428
1494
|
timeoutMs: number = DEFAULT_REQUEST_TIMEOUT_MS
|
|
1429
1495
|
): MeshOperationId {
|
|
1430
|
-
const binding = this.requireStateful().registry.binding(actor);
|
|
1431
|
-
if (binding === undefined) {
|
|
1432
|
-
return this.observeImmediateFailure(OperationKind.StreamUnbind, RequestResult.NotFound);
|
|
1433
|
-
}
|
|
1434
1496
|
return this.observeStateful(
|
|
1435
1497
|
OperationKind.StreamUnbind,
|
|
1436
|
-
this.requireStateful().
|
|
1437
|
-
binding.sessionRid,
|
|
1438
|
-
actor,
|
|
1439
|
-
expectedBindingGeneration,
|
|
1440
|
-
timeoutMs
|
|
1441
|
-
)
|
|
1498
|
+
this.requireStateful().closeBoundSession(actor, expectedBindingGeneration, timeoutMs)
|
|
1442
1499
|
);
|
|
1443
1500
|
}
|
|
1444
1501
|
|
|
@@ -1563,9 +1620,35 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1563
1620
|
return result;
|
|
1564
1621
|
}
|
|
1565
1622
|
|
|
1623
|
+
/**
|
|
1624
|
+
* Arms the one maintenance timer for the nearest management deadline
|
|
1625
|
+
* (spec 08 §4.2): request expiry, liveness, or a pending peer handshake.
|
|
1626
|
+
* An earlier deadline re-arms it; a later one keeps the armed time.
|
|
1627
|
+
*/
|
|
1566
1628
|
private scheduleMaintenance(): void {
|
|
1567
1629
|
if (this.closed) return;
|
|
1568
|
-
|
|
1630
|
+
const nowMs = performance.now();
|
|
1631
|
+
const dueMs = Math.max(
|
|
1632
|
+
nowMs + MESH_BACKEND_MAINTENANCE_INTERVAL_MS,
|
|
1633
|
+
Math.min(
|
|
1634
|
+
this.runtime?.nextMaintenanceDeadlineMs(nowMs) ?? Number.POSITIVE_INFINITY,
|
|
1635
|
+
this.stateful?.nextMaintenanceDeadlineMs() ?? Number.POSITIVE_INFINITY
|
|
1636
|
+
)
|
|
1637
|
+
);
|
|
1638
|
+
if (dueMs === Number.POSITIVE_INFINITY) {
|
|
1639
|
+
if (this.maintenanceTimer !== undefined) clearTimeout(this.maintenanceTimer);
|
|
1640
|
+
this.maintenanceTimer = undefined;
|
|
1641
|
+
this.maintenanceDueMs = dueMs;
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
if (this.maintenanceTimer === undefined || dueMs < this.maintenanceDueMs) {
|
|
1645
|
+
if (this.maintenanceTimer !== undefined) clearTimeout(this.maintenanceTimer);
|
|
1646
|
+
this.maintenanceTimer = setTimeout(
|
|
1647
|
+
this.onMaintenance,
|
|
1648
|
+
Math.min(MESH_BACKEND_MAINTENANCE_MAX_DELAY_MS, Math.ceil(dueMs - nowMs))
|
|
1649
|
+
);
|
|
1650
|
+
this.maintenanceDueMs = dueMs;
|
|
1651
|
+
}
|
|
1569
1652
|
const pending =
|
|
1570
1653
|
(this.runtime?.pendingOperationCount ?? 0) + (this.stateful?.pendingOperationCount ?? 0) > 0;
|
|
1571
1654
|
if (pending === this.maintenanceTimer.hasRef()) return;
|
|
@@ -1576,14 +1659,19 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1576
1659
|
}
|
|
1577
1660
|
}
|
|
1578
1661
|
|
|
1579
|
-
private
|
|
1580
|
-
if (this.
|
|
1581
|
-
this.
|
|
1662
|
+
private pump(): void {
|
|
1663
|
+
if (this.closed || this.pumpTask !== undefined) return;
|
|
1664
|
+
this.pumpTask = this.runPump(this.requireRuntime());
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
private async runPump(runtime: RawServiceMeshRuntime): Promise<void> {
|
|
1668
|
+
// Publish pumpTask before any callback can signal readiness or begin close.
|
|
1669
|
+
await Promise.resolve();
|
|
1582
1670
|
try {
|
|
1583
1671
|
do {
|
|
1584
1672
|
const ready = this.readable;
|
|
1585
1673
|
this.readable = 0;
|
|
1586
|
-
const more = await
|
|
1674
|
+
const more = await runtime.pumpBatch((ready & 1) !== 0, (ready & 2) !== 0);
|
|
1587
1675
|
if (more) {
|
|
1588
1676
|
// Yield only after actual progress, retaining readiness across the
|
|
1589
1677
|
// existing batch limits until receive reports no data.
|
|
@@ -1591,16 +1679,14 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1591
1679
|
await yieldToIO();
|
|
1592
1680
|
}
|
|
1593
1681
|
} while (!this.closed && this.readable !== 0);
|
|
1682
|
+
} catch (error) {
|
|
1683
|
+
runtime.reportInfrastructureFailure(error);
|
|
1594
1684
|
} finally {
|
|
1595
|
-
this.
|
|
1685
|
+
this.pumpTask = undefined;
|
|
1596
1686
|
this.scheduleMaintenance();
|
|
1597
1687
|
}
|
|
1598
1688
|
}
|
|
1599
1689
|
|
|
1600
|
-
private isClosed(): boolean {
|
|
1601
|
-
return this.closed;
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
1690
|
private notifyReady(): void {
|
|
1605
1691
|
const runtime = this.runtime;
|
|
1606
1692
|
let domains = ReadyDomain.None;
|
|
@@ -1613,6 +1699,26 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1613
1699
|
if (domains !== ReadyDomain.None) this.readyHandler?.(domains);
|
|
1614
1700
|
}
|
|
1615
1701
|
|
|
1702
|
+
/**
|
|
1703
|
+
* The raw registry takes a remote request's terminal and hands it here,
|
|
1704
|
+
* where the Framework completion owner receives it in the same turn.
|
|
1705
|
+
*/
|
|
1706
|
+
private readonly requestObserver: RawServiceRequestObserver = {
|
|
1707
|
+
operationCompleted: (id, result, operationKind) =>
|
|
1708
|
+
this.deliverCompletion({ high: 1n, low: id }, operationKind ?? 0, result),
|
|
1709
|
+
operationFailed: (id, error, operationKind) =>
|
|
1710
|
+
this.deliverCompletion({ high: 1n, low: id }, operationKind ?? 0, requestFailureResult(error))
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
private observedOperation(
|
|
1714
|
+
pending: RawServiceObservedRequest,
|
|
1715
|
+
operationKind: number
|
|
1716
|
+
): MeshOperationId {
|
|
1717
|
+
return pending.promise === undefined
|
|
1718
|
+
? { high: 1n, low: pending.id }
|
|
1719
|
+
: this.observeCompletion(pending.id, operationKind, pending.promise);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1616
1722
|
private observeCompletion(
|
|
1617
1723
|
low: bigint,
|
|
1618
1724
|
operationKind: number,
|
|
@@ -1638,15 +1744,6 @@ export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
|
1638
1744
|
return id;
|
|
1639
1745
|
}
|
|
1640
1746
|
|
|
1641
|
-
private observeImmediateFailure(operationKind: number, terminalResult: number): MeshOperationId {
|
|
1642
|
-
const low = this.nextPeerIntent++;
|
|
1643
|
-
return this.observeCompletion(
|
|
1644
|
-
low,
|
|
1645
|
-
operationKind,
|
|
1646
|
-
Promise.resolve({ terminalResult, failureCode: 0 })
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
1747
|
private deliverCompletion(
|
|
1651
1748
|
operationId: MeshOperationId,
|
|
1652
1749
|
operationKind: number,
|
|
@@ -1935,7 +2032,9 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
1935
2032
|
return {
|
|
1936
2033
|
state: this.state,
|
|
1937
2034
|
lifecycleGeneration: 1n,
|
|
1938
|
-
sessionCount: BigInt(
|
|
2035
|
+
sessionCount: BigInt(
|
|
2036
|
+
new Set(bindings.map((value) => encodeRoutingIdStorageHex(value.sessionRid))).size
|
|
2037
|
+
),
|
|
1939
2038
|
bindingCount: BigInt(bindings.length),
|
|
1940
2039
|
pendingMessageCount: 0n,
|
|
1941
2040
|
pendingByteCount: 0n,
|
|
@@ -1964,7 +2063,8 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
1964
2063
|
retiredSession: ServiceRetiredBoundSessionRouteFence,
|
|
1965
2064
|
actor: ServiceActorRef
|
|
1966
2065
|
) => void,
|
|
1967
|
-
actorAuthority?: StreamSessionActorAuthorityFence
|
|
2066
|
+
actorAuthority?: StreamSessionActorAuthorityFence,
|
|
2067
|
+
close?: () => Promise<void>
|
|
1968
2068
|
): MeshOperationId {
|
|
1969
2069
|
this.requireStarted();
|
|
1970
2070
|
const sessionKey = String(sessionRid);
|
|
@@ -1972,13 +2072,13 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
1972
2072
|
return this.observe(
|
|
1973
2073
|
OperationKind.StreamBind,
|
|
1974
2074
|
this.stateful.bindSession(
|
|
1975
|
-
|
|
2075
|
+
sessionRid,
|
|
1976
2076
|
actor,
|
|
1977
2077
|
timeoutMs,
|
|
1978
|
-
(
|
|
1979
|
-
this.deliver(targetSessionRid, actor.actorId, payloadFrame),
|
|
2078
|
+
(_targetSessionRid, payloadFrame) => this.deliver(sessionKey, actor.actorId, payloadFrame),
|
|
1980
2079
|
onBindingReplaced,
|
|
1981
|
-
actorAuthority
|
|
2080
|
+
actorAuthority,
|
|
2081
|
+
close
|
|
1982
2082
|
)
|
|
1983
2083
|
);
|
|
1984
2084
|
}
|
|
@@ -1992,12 +2092,12 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
1992
2092
|
this.requireStarted();
|
|
1993
2093
|
return this.observe(
|
|
1994
2094
|
OperationKind.StreamUnbind,
|
|
1995
|
-
this.stateful.unbindSession(
|
|
2095
|
+
this.stateful.unbindSession(sessionRid, actor, expectedBindingGeneration, timeoutMs)
|
|
1996
2096
|
);
|
|
1997
2097
|
}
|
|
1998
2098
|
|
|
1999
2099
|
bindings(sessionRid: RoutingId) {
|
|
2000
|
-
return this.stateful.sessionBindings(
|
|
2100
|
+
return this.stateful.sessionBindings(sessionRid);
|
|
2001
2101
|
}
|
|
2002
2102
|
|
|
2003
2103
|
async sendToActor(
|
|
@@ -2007,7 +2107,7 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
2007
2107
|
): Promise<SubmitResultValue> {
|
|
2008
2108
|
this.requireStarted();
|
|
2009
2109
|
return (await this.stateful.sendSessionToActor(
|
|
2010
|
-
|
|
2110
|
+
sessionRid,
|
|
2011
2111
|
actor,
|
|
2012
2112
|
encodeMultipart(parts)
|
|
2013
2113
|
)) as SubmitResultValue;
|
|
@@ -2028,7 +2128,7 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
2028
2128
|
if (parts.length === 0) return false;
|
|
2029
2129
|
const actorSlot = await serviceSessionBindingIngressPortIfRegistered(this)?.actorSlot(
|
|
2030
2130
|
actorId,
|
|
2031
|
-
|
|
2131
|
+
target
|
|
2032
2132
|
);
|
|
2033
2133
|
if (actorSlot === undefined) return false;
|
|
2034
2134
|
parts[0] = Buffer.from(streamFrameWithActorSlot(parts[0]!, actorSlot));
|
|
@@ -2047,7 +2147,7 @@ class RawStreamSessionService implements StreamSessionService {
|
|
|
2047
2147
|
case SubmitResult.Terminated:
|
|
2048
2148
|
// Let the socket monitor drive the existing STREAM close/unbind
|
|
2049
2149
|
// lifecycle instead of maintaining a second session-close state.
|
|
2050
|
-
|
|
2150
|
+
disconnectSocketPeer(this.stream, toNativeRoutingId(target));
|
|
2051
2151
|
throw new ZLinkBackendResultError('submit', error.result, error.nativeErrno, {
|
|
2052
2152
|
cause: error
|
|
2053
2153
|
});
|
|
@@ -2296,7 +2396,11 @@ function decodeMultipartRecord(
|
|
|
2296
2396
|
const header = record.parts[0]!;
|
|
2297
2397
|
const command = header[SERVICE_WIRE_COMMAND_OFFSET]!;
|
|
2298
2398
|
const payloadFrame = record.parts[1]!;
|
|
2299
|
-
const
|
|
2399
|
+
const parts = decodeMultipartApplicationParts(
|
|
2400
|
+
payloadFrame,
|
|
2401
|
+
ZLinkBufferMessage.fromOwned,
|
|
2402
|
+
closeMultipartMessage
|
|
2403
|
+
);
|
|
2300
2404
|
const channelName = record.owner.startsWith('channel:')
|
|
2301
2405
|
? record.owner.slice('channel:'.length)
|
|
2302
2406
|
: null;
|
|
@@ -2318,7 +2422,7 @@ function decodeMultipartRecord(
|
|
|
2318
2422
|
: kind === ReceiveKind.ChannelRequest
|
|
2319
2423
|
? OperationKind.ChannelRequest
|
|
2320
2424
|
: 0;
|
|
2321
|
-
const
|
|
2425
|
+
const applicationJob = record.applicationJob;
|
|
2322
2426
|
return {
|
|
2323
2427
|
kind,
|
|
2324
2428
|
domain: readyDomain(record.domain),
|
|
@@ -2331,22 +2435,38 @@ function decodeMultipartRecord(
|
|
|
2331
2435
|
channelName,
|
|
2332
2436
|
topic: null,
|
|
2333
2437
|
applicationMetadata: null,
|
|
2334
|
-
packetName:
|
|
2335
|
-
contentType:
|
|
2438
|
+
packetName: SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME,
|
|
2439
|
+
contentType: SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE,
|
|
2336
2440
|
kindData: null,
|
|
2337
2441
|
terminalResult: 0,
|
|
2338
2442
|
failureErrno: 0,
|
|
2339
|
-
|
|
2340
|
-
|
|
2443
|
+
applicationJobPermit: applicationJob,
|
|
2444
|
+
releaseRetainedIngress: applicationJob === undefined ? undefined : releaseRecordApplicationJob,
|
|
2445
|
+
parts,
|
|
2341
2446
|
reply(parts) {
|
|
2342
2447
|
if (record.correlation === undefined) return SubmitResult.InvalidState;
|
|
2343
2448
|
runtime.reply(record, encodeMultipartApplicationFrame(parts));
|
|
2344
2449
|
return SubmitResult.Ok;
|
|
2345
2450
|
},
|
|
2346
|
-
replyActorJoin:
|
|
2451
|
+
replyActorJoin: replyActorJoinNotSupported
|
|
2347
2452
|
};
|
|
2348
2453
|
}
|
|
2349
2454
|
|
|
2455
|
+
/** Shared by every ordinary record: the record's own permit lease is its retained ingress. */
|
|
2456
|
+
function releaseRecordApplicationJob(this: {
|
|
2457
|
+
readonly applicationJobPermit?: import('../../application-jobs/contracts').ApplicationJobPermitPort;
|
|
2458
|
+
}): void {
|
|
2459
|
+
(
|
|
2460
|
+
this.applicationJobPermit as
|
|
2461
|
+
| import('../../application-jobs/application-ingress-record-owner').ApplicationJobRecordLease
|
|
2462
|
+
| undefined
|
|
2463
|
+
)?.close();
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
function replyActorJoinNotSupported(): SubmitResultValue {
|
|
2467
|
+
return SubmitResult.NotSupported;
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2350
2470
|
function decodeStatefulRecord(
|
|
2351
2471
|
record: ServiceMailboxRecord,
|
|
2352
2472
|
stateful: ServiceStatefulMailboxData
|
|
@@ -2362,7 +2482,7 @@ function decodeStatefulRecord(
|
|
|
2362
2482
|
? stateful.canonicalApplicationPayload
|
|
2363
2483
|
: payloadFrame === undefined
|
|
2364
2484
|
? undefined
|
|
2365
|
-
:
|
|
2485
|
+
: decodeMultipartApplicationPayloadView(payloadFrame);
|
|
2366
2486
|
const operationId =
|
|
2367
2487
|
record.correlation === undefined
|
|
2368
2488
|
? { high: 0n, low: 0n }
|
|
@@ -2370,6 +2490,12 @@ function decodeStatefulRecord(
|
|
|
2370
2490
|
const ingressLifecycle = receiveIngressLifecycle(record);
|
|
2371
2491
|
return {
|
|
2372
2492
|
kind: stateful.receiveKind,
|
|
2493
|
+
get requestSource() {
|
|
2494
|
+
return record.requestSource;
|
|
2495
|
+
},
|
|
2496
|
+
prepareDispatch:
|
|
2497
|
+
record.sourcePreparationOwner === undefined ? undefined : prepareStatefulMailboxDispatch,
|
|
2498
|
+
statefulMailboxRecord: record,
|
|
2373
2499
|
domain: readyDomain(record.domain),
|
|
2374
2500
|
sourceNodeRid: (record.sourceRoutingId as RoutingId | undefined) ?? null,
|
|
2375
2501
|
sourceSpotId: (stateful.sourceSpotId as RoutingId | undefined) ?? null,
|
|
@@ -2468,6 +2594,17 @@ function receiveIngressLifecycle(record: ServiceMailboxRecord): {
|
|
|
2468
2594
|
};
|
|
2469
2595
|
}
|
|
2470
2596
|
|
|
2597
|
+
function prepareStatefulMailboxDispatch(
|
|
2598
|
+
this: import('../../foundation/service-runtime-contracts').ReceiveRecord,
|
|
2599
|
+
signal: AbortSignal
|
|
2600
|
+
): boolean | Promise<boolean> {
|
|
2601
|
+
const mailboxRecord = this.statefulMailboxRecord;
|
|
2602
|
+
const owner = mailboxRecord?.sourcePreparationOwner;
|
|
2603
|
+
return mailboxRecord === undefined || owner === undefined
|
|
2604
|
+
? true
|
|
2605
|
+
: owner.prepareDispatch(mailboxRecord, signal);
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2471
2608
|
function readyOwner(
|
|
2472
2609
|
owner: string,
|
|
2473
2610
|
nodeRid: string,
|
|
@@ -2590,53 +2727,6 @@ function encodeMultipartApplicationFrame(parts: MessageLike | readonly MessageLi
|
|
|
2590
2727
|
);
|
|
2591
2728
|
}
|
|
2592
2729
|
|
|
2593
|
-
function decodeApplicationEnvelope(frame: Uint8Array) {
|
|
2594
|
-
const bytes = Buffer.from(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
2595
|
-
if (
|
|
2596
|
-
bytes.length < APPLICATION_PAYLOAD_MINIMUM_FIELD_BYTES ||
|
|
2597
|
-
bytes[0] !== APPLICATION_PAYLOAD_VERSION
|
|
2598
|
-
) {
|
|
2599
|
-
throw new ServiceWireProtocolError('Invalid application envelope.');
|
|
2600
|
-
}
|
|
2601
|
-
const bodyLength = bytes.readUInt32BE(1);
|
|
2602
|
-
if (bodyLength !== bytes.length - 5) {
|
|
2603
|
-
throw new ServiceWireProtocolError('Invalid application envelope length.');
|
|
2604
|
-
}
|
|
2605
|
-
let offset = 5;
|
|
2606
|
-
const packetLength = bytes[offset++]!;
|
|
2607
|
-
if (packetLength === 0 || bytes.length - offset < packetLength + 1) {
|
|
2608
|
-
throw new ServiceWireProtocolError('Invalid application envelope packet name.');
|
|
2609
|
-
}
|
|
2610
|
-
let packetName: string;
|
|
2611
|
-
try {
|
|
2612
|
-
packetName = FATAL_UTF8.decode(bytes.subarray(offset, offset + packetLength));
|
|
2613
|
-
} catch {
|
|
2614
|
-
throw new ServiceWireProtocolError('Invalid application envelope packet name.');
|
|
2615
|
-
}
|
|
2616
|
-
offset += packetLength;
|
|
2617
|
-
const contentLength = bytes[offset++]!;
|
|
2618
|
-
if (contentLength === 0 || bytes.length - offset < contentLength + 4) {
|
|
2619
|
-
throw new ServiceWireProtocolError('Invalid application envelope content type.');
|
|
2620
|
-
}
|
|
2621
|
-
let contentType: string;
|
|
2622
|
-
try {
|
|
2623
|
-
contentType = FATAL_UTF8.decode(bytes.subarray(offset, offset + contentLength));
|
|
2624
|
-
} catch {
|
|
2625
|
-
throw new ServiceWireProtocolError('Invalid application envelope content type.');
|
|
2626
|
-
}
|
|
2627
|
-
offset += contentLength;
|
|
2628
|
-
const payloadLength = bytes.readUInt32BE(offset);
|
|
2629
|
-
offset += 4;
|
|
2630
|
-
if (
|
|
2631
|
-
packetName !== MULTIPART_PACKET_NAME ||
|
|
2632
|
-
contentType !== MULTIPART_CONTENT_TYPE ||
|
|
2633
|
-
payloadLength !== bytes.length - offset
|
|
2634
|
-
) {
|
|
2635
|
-
throw new ServiceWireProtocolError('Unexpected M6A application payload.');
|
|
2636
|
-
}
|
|
2637
|
-
return { packetName, contentType, payload: bytes.subarray(offset) };
|
|
2638
|
-
}
|
|
2639
|
-
|
|
2640
2730
|
function decodeMultipart(payload: Uint8Array): FrameworkMessage[] {
|
|
2641
2731
|
return decodeMultipartParts(payload, ZLinkBufferMessage.fromOwned, closeMultipartMessage);
|
|
2642
2732
|
}
|
|
@@ -2649,45 +2739,6 @@ function borrowMultipartPart(part: Buffer): Buffer {
|
|
|
2649
2739
|
return part;
|
|
2650
2740
|
}
|
|
2651
2741
|
|
|
2652
|
-
function decodeMultipartParts<T>(
|
|
2653
|
-
payload: Uint8Array,
|
|
2654
|
-
materialize: (part: Buffer) => T,
|
|
2655
|
-
release?: (part: T) => void
|
|
2656
|
-
): T[] {
|
|
2657
|
-
const bytes = Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
2658
|
-
if (bytes.length < 4) throw new ServiceWireProtocolError('Truncated multipart payload.');
|
|
2659
|
-
const count = bytes.readUInt32BE(0);
|
|
2660
|
-
if (count === 0 || count > Math.floor((bytes.length - 4) / 4)) {
|
|
2661
|
-
throw new ServiceWireProtocolError('Invalid multipart part count.');
|
|
2662
|
-
}
|
|
2663
|
-
const result = new Array<T>(count);
|
|
2664
|
-
let offset = 4;
|
|
2665
|
-
let index = 0;
|
|
2666
|
-
try {
|
|
2667
|
-
for (; index < count; index++) {
|
|
2668
|
-
if (bytes.length - offset < 4) {
|
|
2669
|
-
throw new ServiceWireProtocolError('Truncated multipart part length.');
|
|
2670
|
-
}
|
|
2671
|
-
const length = bytes.readUInt32BE(offset);
|
|
2672
|
-
offset += 4;
|
|
2673
|
-
if (bytes.length - offset < length) {
|
|
2674
|
-
throw new ServiceWireProtocolError('Truncated multipart part.');
|
|
2675
|
-
}
|
|
2676
|
-
result[index] = materialize(bytes.subarray(offset, offset + length));
|
|
2677
|
-
offset += length;
|
|
2678
|
-
}
|
|
2679
|
-
if (offset !== bytes.length) {
|
|
2680
|
-
throw new ServiceWireProtocolError('Multipart payload has trailing bytes.');
|
|
2681
|
-
}
|
|
2682
|
-
return result;
|
|
2683
|
-
} catch (error) {
|
|
2684
|
-
if (release !== undefined) {
|
|
2685
|
-
for (let retained = 0; retained < index; retained++) release(result[retained]!);
|
|
2686
|
-
}
|
|
2687
|
-
throw error;
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
2742
|
function messageBytesView(value: MessageLike): Uint8Array {
|
|
2692
2743
|
if (typeof value === 'object' && 'data' in value) {
|
|
2693
2744
|
return value.data();
|