@zlink-systems/framework 0.11.0 → 0.12.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 (119) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Configuration/EndpointNotation.d.ts +5 -4
  3. package/dist/contracts/Configuration/EndpointNotation.js +5 -4
  4. package/dist/contracts/Configuration/InternalDefaults.d.ts +0 -1
  5. package/dist/contracts/Configuration/InternalDefaults.js +1 -2
  6. package/dist/contracts/Configuration/RegistrationNormalizers.js +1 -2
  7. package/dist/contracts/Configuration/RegistrationTypes.d.ts +2 -5
  8. package/dist/contracts/Configuration/RegistrationValidators.js +0 -1
  9. package/dist/contracts/Errors/ZLinkFrameworkException.d.ts +6 -7
  10. package/dist/contracts/Errors/ZLinkFrameworkException.js +6 -7
  11. package/dist/runtime/actors/actor-client.js +1 -1
  12. package/dist/runtime/actors/actor-mailbox.js +1 -5
  13. package/dist/runtime/backend/contracts/index.d.ts +2 -0
  14. package/dist/runtime/backend/mesh-completion-table.d.ts +1 -3
  15. package/dist/runtime/backend/mesh-completion-table.js +11 -15
  16. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +11 -4
  17. package/dist/runtime/backend/mesh-dispatch-pump.js +201 -134
  18. package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +3 -4
  19. package/dist/runtime/backend/node/node-backend-adapter-factory.js +51 -37
  20. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +2 -2
  21. package/dist/runtime/backend/node/node-backend-adapter-support.js +2 -2
  22. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +2 -2
  23. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +16 -0
  24. package/dist/runtime/backend/node/node-event-loop-poller.js +49 -0
  25. package/dist/runtime/backend/node/node-raw-binding-port.js +24 -41
  26. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +8 -8
  27. package/dist/runtime/backend/node/node-raw-mesh-backend.js +100 -107
  28. package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +3 -2
  29. package/dist/runtime/backend/node/node-socket-backend-adapter.js +18 -67
  30. package/dist/runtime/backend/raw-binding-port.d.ts +1 -0
  31. package/dist/runtime/backend/runtime-values.d.ts +5 -1
  32. package/dist/runtime/channels/channel-dispatchers.js +2 -2
  33. package/dist/runtime/channels/channel-envelope.js +324 -121
  34. package/dist/runtime/channels/channel-multipart.d.ts +8 -1
  35. package/dist/runtime/channels/channel-outbound-operations.js +0 -2
  36. package/dist/runtime/channels/channel-receive-loops.d.ts +1 -3
  37. package/dist/runtime/channels/channel-receive-loops.js +25 -65
  38. package/dist/runtime/channels/channel-socket-registry.js +3 -1
  39. package/dist/runtime/channels/channel-transports.d.ts +2 -1
  40. package/dist/runtime/channels/channel-transports.js +12 -10
  41. package/dist/runtime/execution/serial-execution-queue.d.ts +5 -18
  42. package/dist/runtime/execution/serial-execution-queue.js +16 -80
  43. package/dist/runtime/foundation/event-loop-resources.d.ts +0 -3
  44. package/dist/runtime/foundation/event-loop-resources.js +2 -11
  45. package/dist/runtime/foundation/operation-registry.d.ts +2 -8
  46. package/dist/runtime/foundation/operation-registry.js +3 -21
  47. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +19 -7
  48. package/dist/runtime/foundation/raw-service-mesh-runtime.js +56 -10
  49. package/dist/runtime/foundation/service-mailbox.d.ts +1 -7
  50. package/dist/runtime/foundation/service-mailbox.js +3 -2
  51. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -1
  52. package/dist/runtime/foundation/service-stateful-registry.d.ts +1 -1
  53. package/dist/runtime/foundation/service-stateful-registry.js +2 -2
  54. package/dist/runtime/foundation/service-stateful-runtime.js +14 -14
  55. package/dist/runtime/framework-errors-internal.d.ts +4 -4
  56. package/dist/runtime/framework-errors-internal.js +8 -10
  57. package/dist/runtime/host/actor-placement-coordinator.js +1 -1
  58. package/dist/runtime/host/index.js +1 -1
  59. package/dist/runtime/host/service-relocation-host-runtime.js +0 -4
  60. package/dist/runtime/host/spot-address-transport.js +1 -1
  61. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -1
  62. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +0 -12
  63. package/dist/runtime/spots/spot-node-runtime-manager.js +6 -166
  64. package/dist/runtime/spots/spot-serial-turn-executor.js +1 -4
  65. package/dist/runtime/spots/spot-timer.d.ts +3 -0
  66. package/dist/runtime/spots/spot-timer.js +87 -18
  67. package/dist/runtime/streams/session-serial-executor.js +1 -3
  68. package/dist/runtime/streams/stream-session-runtime.d.ts +2 -2
  69. package/dist/runtime/streams/stream-session-runtime.js +13 -19
  70. package/dist/runtime/workers/index.d.ts +0 -1
  71. package/dist/runtime/workers/index.js +1 -9
  72. package/package.json +3 -3
  73. package/src/contracts/Configuration/EndpointNotation.ts +5 -4
  74. package/src/contracts/Configuration/InternalDefaults.ts +0 -1
  75. package/src/contracts/Configuration/RegistrationNormalizers.ts +2 -4
  76. package/src/contracts/Configuration/RegistrationTypes.ts +2 -5
  77. package/src/contracts/Configuration/RegistrationValidators.ts +0 -1
  78. package/src/contracts/Errors/ZLinkFrameworkException.ts +6 -7
  79. package/src/runtime/actors/actor-client.ts +1 -1
  80. package/src/runtime/actors/actor-mailbox.ts +1 -12
  81. package/src/runtime/backend/contracts/index.ts +2 -0
  82. package/src/runtime/backend/mesh-completion-table.ts +12 -23
  83. package/src/runtime/backend/mesh-dispatch-pump.ts +206 -138
  84. package/src/runtime/backend/node/node-backend-adapter-factory.ts +66 -35
  85. package/src/runtime/backend/node/node-backend-adapter-support.ts +4 -4
  86. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +2 -2
  87. package/src/runtime/backend/node/node-event-loop-poller.ts +55 -0
  88. package/src/runtime/backend/node/node-raw-binding-port.ts +30 -45
  89. package/src/runtime/backend/node/node-raw-mesh-backend.ts +97 -110
  90. package/src/runtime/backend/node/node-socket-backend-adapter.ts +23 -69
  91. package/src/runtime/backend/raw-binding-port.ts +1 -0
  92. package/src/runtime/backend/runtime-values.ts +7 -1
  93. package/src/runtime/channels/channel-dispatchers.ts +2 -2
  94. package/src/runtime/channels/channel-envelope.ts +379 -109
  95. package/src/runtime/channels/channel-multipart.ts +9 -1
  96. package/src/runtime/channels/channel-outbound-operations.ts +0 -1
  97. package/src/runtime/channels/channel-receive-loops.ts +24 -75
  98. package/src/runtime/channels/channel-socket-registry.ts +4 -1
  99. package/src/runtime/channels/channel-transports.ts +20 -10
  100. package/src/runtime/execution/serial-execution-queue.ts +16 -108
  101. package/src/runtime/foundation/event-loop-resources.ts +2 -11
  102. package/src/runtime/foundation/operation-registry.ts +2 -22
  103. package/src/runtime/foundation/raw-service-mesh-runtime.ts +74 -19
  104. package/src/runtime/foundation/service-mailbox.ts +3 -13
  105. package/src/runtime/foundation/service-runtime-contracts.ts +2 -1
  106. package/src/runtime/foundation/service-stateful-registry.ts +2 -2
  107. package/src/runtime/foundation/service-stateful-runtime.ts +14 -14
  108. package/src/runtime/framework-errors-internal.ts +8 -10
  109. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  110. package/src/runtime/host/index.ts +2 -1
  111. package/src/runtime/host/service-relocation-host-runtime.ts +0 -4
  112. package/src/runtime/host/spot-address-transport.ts +1 -1
  113. package/src/runtime/host/user-spot-creation-coordinator.ts +1 -1
  114. package/src/runtime/spots/spot-node-runtime-manager.ts +13 -233
  115. package/src/runtime/spots/spot-serial-turn-executor.ts +1 -8
  116. package/src/runtime/spots/spot-timer.ts +109 -18
  117. package/src/runtime/streams/session-serial-executor.ts +1 -7
  118. package/src/runtime/streams/stream-session-runtime.ts +13 -17
  119. package/src/runtime/workers/index.ts +2 -17
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Deterministic endpoint-notation normalization (endpoint 표기 정책,
3
- * doc/plan/endpoint-notation-policy.ko.md).
2
+ * Deterministic endpoint-notation normalization (endpoint 표기 정책),
3
+ * applied identically across all four language bindings so endpoint
4
+ * strings compare equal.
4
5
  *
5
6
  * `new URL()` cannot represent this domain: it throws on bracketed IPv6
6
7
  * literals that carry a zone id (`tcp://[fe80::1%eth0]:80`, even with the
@@ -16,7 +17,7 @@
16
17
  * public connect/disconnect APIs). Everything downstream compares the
17
18
  * resulting strings with plain `===`.
18
19
  *
19
- * Rules (policy 2.2), applied only to authority-bearing schemes
20
+ * Rules, applied only to authority-bearing schemes
20
21
  * (`tcp`, `tls`, `ws`, `wss` -- schemes whose grammar after `scheme://` is
21
22
  * `host:port`):
22
23
  * - scheme: lowercased
@@ -39,7 +40,7 @@
39
40
  * `normalizeEndpoint(normalizeEndpoint(x)) === normalizeEndpoint(x)`.
40
41
  *
41
42
  * DNS names are never resolved. `localhost` and `127.0.0.1` remain distinct
42
- * endpoints (policy 2.1).
43
+ * endpoints.
43
44
  */
44
45
  export declare function normalizeEndpoint(endpoint: string): string;
45
46
  /**
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  /**
3
- * Deterministic endpoint-notation normalization (endpoint 표기 정책,
4
- * doc/plan/endpoint-notation-policy.ko.md).
3
+ * Deterministic endpoint-notation normalization (endpoint 표기 정책),
4
+ * applied identically across all four language bindings so endpoint
5
+ * strings compare equal.
5
6
  *
6
7
  * `new URL()` cannot represent this domain: it throws on bracketed IPv6
7
8
  * literals that carry a zone id (`tcp://[fe80::1%eth0]:80`, even with the
@@ -17,7 +18,7 @@
17
18
  * public connect/disconnect APIs). Everything downstream compares the
18
19
  * resulting strings with plain `===`.
19
20
  *
20
- * Rules (policy 2.2), applied only to authority-bearing schemes
21
+ * Rules, applied only to authority-bearing schemes
21
22
  * (`tcp`, `tls`, `ws`, `wss` -- schemes whose grammar after `scheme://` is
22
23
  * `host:port`):
23
24
  * - scheme: lowercased
@@ -40,7 +41,7 @@
40
41
  * `normalizeEndpoint(normalizeEndpoint(x)) === normalizeEndpoint(x)`.
41
42
  *
42
43
  * DNS names are never resolved. `localhost` and `127.0.0.1` remain distinct
43
- * endpoints (policy 2.1).
44
+ * endpoints.
44
45
  */
45
46
  Object.defineProperty(exports, "__esModule", { value: true });
46
47
  exports.normalizeEndpoint = normalizeEndpoint;
@@ -3,5 +3,4 @@ export declare const DEFAULT_STREAM_NODE_MAX_MESSAGE_SIZE: number;
3
3
  /** Defaults shared by registration normalization and the runtime worker pool. */
4
4
  export declare const DEFAULT_WORKER_MIN_THREADS = 0;
5
5
  export declare const DEFAULT_WORKER_IDLE_TIMEOUT_MS = 30000;
6
- export declare const DEFAULT_WORKER_QUEUE_LENGTH = 1024;
7
6
  export declare function defaultWorkerMaxThreads(): number;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.DEFAULT_WORKER_QUEUE_LENGTH = exports.DEFAULT_WORKER_IDLE_TIMEOUT_MS = exports.DEFAULT_WORKER_MIN_THREADS = exports.DEFAULT_STREAM_NODE_MAX_MESSAGE_SIZE = void 0;
36
+ exports.DEFAULT_WORKER_IDLE_TIMEOUT_MS = exports.DEFAULT_WORKER_MIN_THREADS = exports.DEFAULT_STREAM_NODE_MAX_MESSAGE_SIZE = void 0;
37
37
  exports.defaultWorkerMaxThreads = defaultWorkerMaxThreads;
38
38
  const os = __importStar(require("node:os"));
39
39
  /** Default complete header plus payload size accepted by a StreamNode. */
@@ -41,7 +41,6 @@ exports.DEFAULT_STREAM_NODE_MAX_MESSAGE_SIZE = 64 * 1024;
41
41
  /** Defaults shared by registration normalization and the runtime worker pool. */
42
42
  exports.DEFAULT_WORKER_MIN_THREADS = 0;
43
43
  exports.DEFAULT_WORKER_IDLE_TIMEOUT_MS = 30_000;
44
- exports.DEFAULT_WORKER_QUEUE_LENGTH = 1024;
45
44
  function defaultWorkerMaxThreads() {
46
45
  return Math.max(2, os.availableParallelism());
47
46
  }
@@ -31,8 +31,7 @@ function normalizeWorkerOptions(value) {
31
31
  return {
32
32
  minThreads: partial.minThreads ?? InternalDefaults_1.DEFAULT_WORKER_MIN_THREADS,
33
33
  maxThreads: partial.maxThreads ?? (0, InternalDefaults_1.defaultWorkerMaxThreads)(),
34
- idleTimeoutMs: partial.idleTimeoutMs ?? InternalDefaults_1.DEFAULT_WORKER_IDLE_TIMEOUT_MS,
35
- maxQueueLength: partial.maxQueueLength ?? InternalDefaults_1.DEFAULT_WORKER_QUEUE_LENGTH
34
+ idleTimeoutMs: partial.idleTimeoutMs ?? InternalDefaults_1.DEFAULT_WORKER_IDLE_TIMEOUT_MS
36
35
  };
37
36
  }
38
37
  function normalizeNetworkOptions(value) {
@@ -79,16 +79,13 @@ export interface ZLinkLocationRegistration {
79
79
  /**
80
80
  * CPU worker-thread pool settings. I/O workers do not consume this pool.
81
81
  * `minThreads` keeps a warm baseline, `maxThreads` bounds active CPU jobs,
82
- * `idleTimeoutMs` reclaims workers above the baseline, and `maxQueueLength`
83
- * bounds queued jobs. The registration normalizer supplies defaults when a
84
- * JavaScript caller omits a field: `0`, `max(2, availableParallelism())`,
85
- * `30000`, and `1024`, respectively.
82
+ * `idleTimeoutMs` reclaims workers above the baseline. The registration
83
+ * normalizer supplies defaults when a JavaScript caller omits a field.
86
84
  */
87
85
  export interface ZLinkWorkerOptions {
88
86
  readonly minThreads: number;
89
87
  readonly maxThreads: number;
90
88
  readonly idleTimeoutMs: number;
91
- readonly maxQueueLength: number;
92
89
  }
93
90
  export interface ZLinkCodecSerializerRegistration {
94
91
  readonly contentType: string;
@@ -61,7 +61,6 @@ function validateWorkerOptions(worker) {
61
61
  requireNonNegativeInteger('Worker minThreads', worker.minThreads);
62
62
  (0, RegistrationNormalizers_1.requirePositiveInteger)('Worker maxThreads', worker.maxThreads);
63
63
  requireNonNegativeInteger('Worker idleTimeoutMs', worker.idleTimeoutMs);
64
- (0, RegistrationNormalizers_1.requirePositiveInteger)('Worker maxQueueLength', worker.maxQueueLength);
65
64
  if (worker.maxThreads < worker.minThreads) {
66
65
  throw new ConfigurationException_1.ZLinkConfigurationException('Worker maxThreads must be greater than or equal to minThreads.');
67
66
  }
@@ -6,13 +6,12 @@ export declare enum ZLinkFrameworkErrorKind {
6
6
  NotConfigured = 3,
7
7
  Rejected = 4,
8
8
  Unavailable = 5,
9
- CapacityExceeded = 6,
10
- DeadlineExceeded = 7,
11
- ShuttingDown = 8,
12
- ProtocolError = 9,
13
- InvalidOperation = 10,
14
- DataLost = 11,
15
- InternalFailure = 12
9
+ DeadlineExceeded = 6,
10
+ ShuttingDown = 7,
11
+ ProtocolError = 8,
12
+ InvalidOperation = 9,
13
+ DataLost = 10,
14
+ InternalFailure = 11
16
15
  }
17
16
  export declare class ZLinkFrameworkException extends Error {
18
17
  readonly kind: ZLinkFrameworkErrorKind;
@@ -10,13 +10,12 @@ var ZLinkFrameworkErrorKind;
10
10
  ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["NotConfigured"] = 3] = "NotConfigured";
11
11
  ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["Rejected"] = 4] = "Rejected";
12
12
  ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["Unavailable"] = 5] = "Unavailable";
13
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["CapacityExceeded"] = 6] = "CapacityExceeded";
14
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["DeadlineExceeded"] = 7] = "DeadlineExceeded";
15
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["ShuttingDown"] = 8] = "ShuttingDown";
16
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["ProtocolError"] = 9] = "ProtocolError";
17
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["InvalidOperation"] = 10] = "InvalidOperation";
18
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["DataLost"] = 11] = "DataLost";
19
- ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["InternalFailure"] = 12] = "InternalFailure";
13
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["DeadlineExceeded"] = 6] = "DeadlineExceeded";
14
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["ShuttingDown"] = 7] = "ShuttingDown";
15
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["ProtocolError"] = 8] = "ProtocolError";
16
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["InvalidOperation"] = 9] = "InvalidOperation";
17
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["DataLost"] = 10] = "DataLost";
18
+ ZLinkFrameworkErrorKind[ZLinkFrameworkErrorKind["InternalFailure"] = 11] = "InternalFailure";
20
19
  })(ZLinkFrameworkErrorKind || (exports.ZLinkFrameworkErrorKind = ZLinkFrameworkErrorKind = {}));
21
20
  class ZLinkFrameworkException extends Error {
22
21
  kind;
@@ -537,7 +537,7 @@ function submitted() {
537
537
  // the reply comes from a remote target, so a fine framework failure code
538
538
  // refines the coarse terminal, and a terminal-only conflict/busy is the
539
539
  // target's owner/queue state (retryable stale/Unavailable), never a
540
- // source-owned CapacityExceeded. Backpressure never appears on this reply
540
+ // source-owned queue exhaustion. Backpressure never appears on this reply
541
541
  // path. Internal kinds are preserved so the stale-actor re-resolve retry
542
542
  // (isStaleActorError) keeps working.
543
543
  function actorFailureCodeKind(failureErrno) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkActorSerialExecutor = void 0;
4
4
  const serial_execution_queue_1 = require("../execution/serial-execution-queue");
5
- const framework_errors_internal_1 = require("../framework-errors-internal");
6
5
  const actor_execution_context_1 = require("./actor-execution-context");
7
6
  const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
8
7
  class ZLinkActorSerialExecutor {
@@ -12,10 +11,7 @@ class ZLinkActorSerialExecutor {
12
11
  constructor(actorId, sourceSpotId, options) {
13
12
  this.actorId = actorId;
14
13
  this.sourceSpotId = sourceSpotId;
15
- this.scheduler = new serial_execution_queue_1.ZLinkSerialExecutionQueue((record) => this.runRecord(record), {
16
- ...options,
17
- capacityError: options?.capacityError ?? (() => (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.WorkerQueueFull, 'Actor execution queue capacity was exceeded.'))
18
- });
14
+ this.scheduler = new serial_execution_queue_1.ZLinkSerialExecutionQueue((record) => this.runRecord(record), options);
19
15
  }
20
16
  execute(operation, workOptions) {
21
17
  const boundOperation = (0, application_job_queue_scope_1.bindApplicationJobPermit)(() => (0, actor_execution_context_1.runZLinkActorExecution)(this.actorId, this.sourceSpotId, operation));
@@ -359,6 +359,8 @@ export interface ZLinkBackendSubscriberSocket extends ZLinkBackendConnectableSoc
359
359
  }
360
360
  export interface ZLinkBackendReadablePoller {
361
361
  wait(timeoutMs: number): boolean;
362
+ waitForReadable(signal?: AbortSignal): Promise<boolean>;
363
+ markDrained(): void;
362
364
  dispose(): void;
363
365
  }
364
366
  export interface ZLinkBackendStreamPacket {
@@ -1,6 +1,5 @@
1
1
  import { ZLinkBufferMessage as Message } from './runtime-message';
2
2
  import type { MeshOperationId, ReceiveKindData, ReceiveRecord } from '../foundation/service-runtime-contracts';
3
- export declare const ZLINK_MESH_COMPLETION_CAPACITY = 4096;
4
3
  export interface ZLinkMeshCompletionDiagnostic {
5
4
  readonly kind: 'unknownOrLate';
6
5
  readonly operationId: MeshOperationId;
@@ -14,11 +13,10 @@ export interface ZLinkMeshCompletion {
14
13
  readonly parts: Message[];
15
14
  }
16
15
  export declare class ZLinkMeshCompletionTable {
17
- private readonly maxPendingOperations;
18
16
  private readonly onDiagnostic?;
19
17
  private readonly pending;
20
18
  private disposed;
21
- constructor(maxPendingOperations?: number, onDiagnostic?: ((diagnostic: ZLinkMeshCompletionDiagnostic) => void) | undefined);
19
+ constructor(onDiagnostic?: ((diagnostic: ZLinkMeshCompletionDiagnostic) => void) | undefined);
22
20
  /**
23
21
  * Submits and registers without yielding control to the event loop. Mesh
24
22
  * completion dispatch is asynchronous, so a completion cannot overtake the
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZLinkMeshCompletionTable = exports.ZLINK_MESH_COMPLETION_CAPACITY = void 0;
3
+ exports.ZLinkMeshCompletionTable = void 0;
4
4
  exports.closeMeshCompletion = closeMeshCompletion;
5
5
  const runtime_message_1 = require("./runtime-message");
6
6
  const operation_identity_1 = require("../foundation/operation-identity");
7
- const contracts_1 = require("../../contracts");
8
- exports.ZLINK_MESH_COMPLETION_CAPACITY = 4_096;
9
7
  class ZLinkMeshCompletionTable {
10
- maxPendingOperations;
11
8
  onDiagnostic;
12
9
  pending = new Map();
13
10
  disposed = false;
14
- constructor(maxPendingOperations = exports.ZLINK_MESH_COMPLETION_CAPACITY, onDiagnostic) {
15
- this.maxPendingOperations = maxPendingOperations;
11
+ constructor(onDiagnostic) {
16
12
  this.onDiagnostic = onDiagnostic;
17
- if (!Number.isSafeInteger(maxPendingOperations) || maxPendingOperations <= 0) {
18
- throw new RangeError('maxPendingOperations must be a positive safe integer.');
19
- }
20
13
  }
21
14
  /**
22
15
  * Submits and registers without yielding control to the event loop. Mesh
@@ -31,9 +24,6 @@ class ZLinkMeshCompletionTable {
31
24
  if (signal?.aborted === true) {
32
25
  return Promise.reject(signal.reason ?? new DOMException('The operation was aborted.', 'AbortError'));
33
26
  }
34
- if (this.pending.size >= this.maxPendingOperations) {
35
- return Promise.reject(new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.CapacityExceeded, `Mesh completion capacity ${this.maxPendingOperations} is exhausted.`));
36
- }
37
27
  const operationId = operation();
38
28
  // The backend submission callback can synchronously re-enter `dispose()`.
39
29
  // TypeScript's control-flow analysis cannot observe mutation through it.
@@ -80,7 +70,7 @@ class ZLinkMeshCompletionTable {
80
70
  this.pending.delete(key);
81
71
  pending.removeAbort?.();
82
72
  try {
83
- pending.resolve(copyCompletion(record));
73
+ pending.resolve(retainCompletion(record));
84
74
  }
85
75
  catch (error) {
86
76
  pending.reject(error);
@@ -105,15 +95,21 @@ class ZLinkMeshCompletionTable {
105
95
  }
106
96
  }
107
97
  exports.ZLinkMeshCompletionTable = ZLinkMeshCompletionTable;
108
- function copyCompletion(record) {
98
+ function retainCompletion(record) {
109
99
  return {
110
100
  terminalResult: record.terminalResult,
111
101
  failureErrno: record.failureErrno,
112
102
  operationKind: record.operationKind,
113
103
  kindData: record.kindData,
114
- parts: record.parts.map((part) => runtime_message_1.ZLinkBufferMessage.fromOwned(Buffer.from(part.data())))
104
+ parts: record.parts.map(retainCompletionPart)
115
105
  };
116
106
  }
107
+ function retainCompletionPart(part) {
108
+ // A runtime message already owns a managed Buffer and close() is a no-op.
109
+ // Binding-native messages can expose native storage through data(), which
110
+ // becomes invalid when their owner closes; materialize that one boundary copy.
111
+ return part instanceof runtime_message_1.ZLinkBufferMessage ? part : runtime_message_1.ZLinkBufferMessage.fromOwned(Buffer.from(part.data()));
112
+ }
117
113
  function closeMeshCompletion(completion) {
118
114
  closeParts(completion.parts);
119
115
  }
@@ -21,17 +21,24 @@ export declare class ZLinkMeshDispatchPump {
21
21
  private readonly node;
22
22
  private readonly options;
23
23
  private pendingDomains;
24
- private scheduled;
25
24
  private infrastructureScheduled;
26
25
  private disposed;
27
- private drainPromise?;
28
26
  private infrastructureDrainPromise?;
29
27
  private readonly activeDrains;
28
+ private readonly idleApplicationWorkers;
29
+ private applicationWorkerCount;
30
30
  private readonly capacityStop;
31
+ private recordsSinceYield;
32
+ private yieldStartedAtMs;
31
33
  constructor(node: ZLinkBackendMeshNode, options: ZLinkMeshDispatchPumpOptions);
32
34
  start(): void;
33
35
  dispose(): Promise<void>;
34
- private schedule;
36
+ private markReady;
37
+ private wakeApplicationWorker;
38
+ private startApplicationWorker;
39
+ private runApplicationWorker;
40
+ private waitForApplicationReady;
41
+ private reportDispatchError;
35
42
  /**
36
43
  * Infrastructure controls must not wait for an application permit. During
37
44
  * source draining an application claim can legitimately remain parked at
@@ -40,9 +47,9 @@ export declare class ZLinkMeshDispatchPump {
40
47
  * completing the drain that releases the application work.
41
48
  */
42
49
  private scheduleInfrastructure;
43
- private drain;
44
50
  private drainInfrastructure;
45
51
  private drainDomain;
52
+ private yieldIfNeeded;
46
53
  private nowMs;
47
54
  private acquirePermit;
48
55
  }