@dudousxd/nestjs-durable-core 0.85.9 → 0.85.11

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/index.d.cts CHANGED
@@ -1572,6 +1572,16 @@ interface StateStore {
1572
1572
  * Optional: a store that omits it still works — the engine falls back to {@link listCheckpoints}
1573
1573
  * and counts in JS, which loads the whole run on every result of a fan.
1574
1574
  */
1575
+ /**
1576
+ * Whether any of the run's checkpoints with `fromSeq <= seq <= toSeq` has one of `statuses`: the
1577
+ * question the join barrier of a step fan actually asks on each batch of results ("is any step of
1578
+ * the fan still `pending`?"). A store reads it from the TOP of the range down and stops at the first
1579
+ * match: a fan's steps are dispatched in seq order, so its highest seqs are the last to settle, and
1580
+ * the answer comes from the first rows read instead of a count over the whole range.
1581
+ *
1582
+ * Optional: a store that omits it still works — the engine asks {@link countCheckpoints} instead.
1583
+ */
1584
+ hasCheckpoints?(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<boolean>;
1575
1585
  countCheckpoints?(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<number>;
1576
1586
  /**
1577
1587
  * The run's checkpoints aggregated into {@link CheckpointStat} buckets — one per
@@ -6260,10 +6270,17 @@ declare class WorkflowEngine {
6260
6270
  * result may have landed since. The fan's last turn so reads nothing it already read.
6261
6271
  */
6262
6272
  private fanCheckpoints;
6273
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
6274
+ private saveFanCheckpoints;
6263
6275
  /**
6264
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
6265
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
6266
- * batch, where the store and transport have them.
6276
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
6277
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
6278
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
6279
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
6280
+ *
6281
+ * No result can wake the run before every round is written: the run is `running` under this
6282
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
6283
+ * checkpoint, and the replay sends them once the written ones settle.
6267
6284
  */
6268
6285
  private sendStepFan;
6269
6286
  /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
@@ -6356,8 +6373,8 @@ declare class WorkflowEngine {
6356
6373
  * that result (see {@link completeRemoteResults}).
6357
6374
  */
6358
6375
  private stepFanStillRunning;
6359
- /** How many steps of a step fan's seq range are still `pending`. */
6360
- private stepFanPending;
6376
+ /** Whether any step of a step fan's seq range is still `pending`. */
6377
+ private stepFanHasPending;
6361
6378
  /**
6362
6379
  * Apply a remote workflow-turn {@link WorkflowDecision} durably — runs on WHATEVER instance receives
6363
6380
  * it over the broker (the dispatching one may be gone, or a point-to-point broker handed it to a
@@ -7086,6 +7103,8 @@ declare class CodecStateStore implements StateStore {
7086
7103
  readonly getCheckpointsForSettle?: (runId: string, seqs: number[]) => Promise<StepCheckpoint[]>;
7087
7104
  /** Decodes each checkpoint read. Bound only when the inner store has it. */
7088
7105
  readonly getCheckpoints?: (runId: string, seqs: number[]) => Promise<StepCheckpoint[]>;
7106
+ /** Forwarded verbatim — reads no payload. Bound only when the inner store has it. */
7107
+ readonly hasCheckpoints?: (runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]) => Promise<boolean>;
7089
7108
  /** Forwarded verbatim — a count reads no payload. Bound only when the inner store has it. */
7090
7109
  readonly countCheckpoints?: (runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]) => Promise<number>;
7091
7110
  /** Forwarded verbatim — retention selects by status/updatedAt/scope, never by payload. Bound only
@@ -7252,6 +7271,19 @@ type Subscribable = {
7252
7271
  */
7253
7272
  declare function collectMetrics(engine: Subscribable): MetricsCollector;
7254
7273
 
7274
+ /**
7275
+ * An event another instance produced and the control plane re-delivered here. Every instance hears
7276
+ * every run's lifecycle, so a consumer that RECORDS events (Telescope, a metrics counter, a trace
7277
+ * exporter) would record each one once per pod; such consumers skip the events marked remote.
7278
+ *
7279
+ * The mark is a non-enumerable property under a registered symbol, so it never reaches a serialized
7280
+ * event and a consumer can test for it without importing this module.
7281
+ */
7282
+ declare const REMOTE_EVENT: unique symbol;
7283
+ declare function markRemoteEvent<E extends object>(event: E): E;
7284
+ /** Whether `event` was produced by another instance and re-delivered here over the control plane. */
7285
+ declare function isRemoteEvent(event: object): boolean;
7286
+
7255
7287
  /**
7256
7288
  * The origin (see {@link import('./interfaces').WorkflowRun.origin}) stamped onto runs of the
7257
7289
  * workflows this package registers ITSELF — the built-in `__entity` runner behind durable entities
@@ -7711,6 +7743,7 @@ declare class InMemoryStateStore implements StateStore {
7711
7743
  }): Promise<CheckpointStat[]>;
7712
7744
  queryCheckpoints(runId: string, query: CheckpointQuery): Promise<StepCheckpoint[]>;
7713
7745
  getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
7746
+ hasCheckpoints(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<boolean>;
7714
7747
  countCheckpoints(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<number>;
7715
7748
  listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
7716
7749
  }
@@ -7810,4 +7843,4 @@ declare function singletonAdmissionDenialPatch(runs: WorkflowRun[], runId: strin
7810
7843
  updatedAt: Date;
7811
7844
  } | undefined;
7812
7845
 
7813
- export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
7846
+ export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
package/dist/index.d.ts CHANGED
@@ -1572,6 +1572,16 @@ interface StateStore {
1572
1572
  * Optional: a store that omits it still works — the engine falls back to {@link listCheckpoints}
1573
1573
  * and counts in JS, which loads the whole run on every result of a fan.
1574
1574
  */
1575
+ /**
1576
+ * Whether any of the run's checkpoints with `fromSeq <= seq <= toSeq` has one of `statuses`: the
1577
+ * question the join barrier of a step fan actually asks on each batch of results ("is any step of
1578
+ * the fan still `pending`?"). A store reads it from the TOP of the range down and stops at the first
1579
+ * match: a fan's steps are dispatched in seq order, so its highest seqs are the last to settle, and
1580
+ * the answer comes from the first rows read instead of a count over the whole range.
1581
+ *
1582
+ * Optional: a store that omits it still works — the engine asks {@link countCheckpoints} instead.
1583
+ */
1584
+ hasCheckpoints?(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<boolean>;
1575
1585
  countCheckpoints?(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<number>;
1576
1586
  /**
1577
1587
  * The run's checkpoints aggregated into {@link CheckpointStat} buckets — one per
@@ -6260,10 +6270,17 @@ declare class WorkflowEngine {
6260
6270
  * result may have landed since. The fan's last turn so reads nothing it already read.
6261
6271
  */
6262
6272
  private fanCheckpoints;
6273
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
6274
+ private saveFanCheckpoints;
6263
6275
  /**
6264
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
6265
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
6266
- * batch, where the store and transport have them.
6276
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
6277
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
6278
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
6279
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
6280
+ *
6281
+ * No result can wake the run before every round is written: the run is `running` under this
6282
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
6283
+ * checkpoint, and the replay sends them once the written ones settle.
6267
6284
  */
6268
6285
  private sendStepFan;
6269
6286
  /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
@@ -6356,8 +6373,8 @@ declare class WorkflowEngine {
6356
6373
  * that result (see {@link completeRemoteResults}).
6357
6374
  */
6358
6375
  private stepFanStillRunning;
6359
- /** How many steps of a step fan's seq range are still `pending`. */
6360
- private stepFanPending;
6376
+ /** Whether any step of a step fan's seq range is still `pending`. */
6377
+ private stepFanHasPending;
6361
6378
  /**
6362
6379
  * Apply a remote workflow-turn {@link WorkflowDecision} durably — runs on WHATEVER instance receives
6363
6380
  * it over the broker (the dispatching one may be gone, or a point-to-point broker handed it to a
@@ -7086,6 +7103,8 @@ declare class CodecStateStore implements StateStore {
7086
7103
  readonly getCheckpointsForSettle?: (runId: string, seqs: number[]) => Promise<StepCheckpoint[]>;
7087
7104
  /** Decodes each checkpoint read. Bound only when the inner store has it. */
7088
7105
  readonly getCheckpoints?: (runId: string, seqs: number[]) => Promise<StepCheckpoint[]>;
7106
+ /** Forwarded verbatim — reads no payload. Bound only when the inner store has it. */
7107
+ readonly hasCheckpoints?: (runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]) => Promise<boolean>;
7089
7108
  /** Forwarded verbatim — a count reads no payload. Bound only when the inner store has it. */
7090
7109
  readonly countCheckpoints?: (runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]) => Promise<number>;
7091
7110
  /** Forwarded verbatim — retention selects by status/updatedAt/scope, never by payload. Bound only
@@ -7252,6 +7271,19 @@ type Subscribable = {
7252
7271
  */
7253
7272
  declare function collectMetrics(engine: Subscribable): MetricsCollector;
7254
7273
 
7274
+ /**
7275
+ * An event another instance produced and the control plane re-delivered here. Every instance hears
7276
+ * every run's lifecycle, so a consumer that RECORDS events (Telescope, a metrics counter, a trace
7277
+ * exporter) would record each one once per pod; such consumers skip the events marked remote.
7278
+ *
7279
+ * The mark is a non-enumerable property under a registered symbol, so it never reaches a serialized
7280
+ * event and a consumer can test for it without importing this module.
7281
+ */
7282
+ declare const REMOTE_EVENT: unique symbol;
7283
+ declare function markRemoteEvent<E extends object>(event: E): E;
7284
+ /** Whether `event` was produced by another instance and re-delivered here over the control plane. */
7285
+ declare function isRemoteEvent(event: object): boolean;
7286
+
7255
7287
  /**
7256
7288
  * The origin (see {@link import('./interfaces').WorkflowRun.origin}) stamped onto runs of the
7257
7289
  * workflows this package registers ITSELF — the built-in `__entity` runner behind durable entities
@@ -7711,6 +7743,7 @@ declare class InMemoryStateStore implements StateStore {
7711
7743
  }): Promise<CheckpointStat[]>;
7712
7744
  queryCheckpoints(runId: string, query: CheckpointQuery): Promise<StepCheckpoint[]>;
7713
7745
  getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
7746
+ hasCheckpoints(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<boolean>;
7714
7747
  countCheckpoints(runId: string, fromSeq: number, toSeq: number, statuses: StepCheckpoint['status'][]): Promise<number>;
7715
7748
  listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
7716
7749
  }
@@ -7810,4 +7843,4 @@ declare function singletonAdmissionDenialPatch(runs: WorkflowRun[], runId: strin
7810
7843
  updatedAt: Date;
7811
7844
  } | undefined;
7812
7845
 
7813
- export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
7846
+ export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AllOptions, type AllSettledOptions, type AllStepsOptions, type AllStepsSettledOptions, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, type BufferedSignalRow, CHILD_EDGE_PREFIXES, CONTROL_FLOW_SIGNAL, CORE_ORIGIN, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type CheckpointAggregatingStore, type CheckpointNameKind, type CheckpointQuery, type CheckpointStat, type ChildCallOptions, type ChildWait, CodecStateStore, type CodecStateStoreOptions, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DEFAULT_STALLED_AFTER_MS, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, ENTITY_WORKFLOW, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, type EntityWorkflowHost, EventAccumulators, type EventBatchConfig, FAN_SUMMARY_FAILURES, type FanJoin, type FanPage, type FanPageQuery, type FanSummary, type FanWait, FatalError, type FindStalledRunsOptions, GatherError, type GatherItemFailure, type GroupHealth, HANDOFF_SEQ_BASE, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryRunQueue, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type ListStalledRunsOptions, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type OnErrorInput, type OnErrorRoute, type OwnedLeaseReclaim, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, REMOTE_EVENT, RUN_HISTORY_FIXTURE_VERSION, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunConsumerOptions, type RunDetail, type RunDetailOptions, type RunDispatch, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunQueueOptions, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, SINGLETON_ACTIVE_STATUSES, SINGLETON_ADMITTED_TAG, SINGLETON_RESERVED_TAGS, SINGLETON_TRACKED_TAG, STATE_STORE, STATE_STORE_CANONICAL, SUMMARY_CHILD_LIMIT, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, type ScheduledWorkflow, type SchemaIssue, type SchemaValidationCode, SchemaValidationError, type SearchAttributes, type SearchAttributesSchema, type Settled, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StalePendingStep, type StalledRunInfo, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepScope, type StepSettlement, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type TenantTokenSource, type TenantVerifier, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, type VerifiedTenant, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, aggregatesCheckpoints, announcementsOf, applyAttributeQuery, assertConcurrency, assertRoutes, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, checkpointNameKind, checkpointStatsOf, childIdsOf, classifyWaiterToken, clearDurableExecutionWrappers, clearTerminalSingletonAdmission, codeAndDetails, codeOf, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, detailsOf, error, etagMatches, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, fanPageBounds, fanPageEtag, findStalledRuns, foldedCount, getRunsByIds, handoffHandlerId, handoffName, hasDurableExecutionWrappers, heartbeatStatus, hmacTenantVerifier, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isFailedMember, isLegacyDescriptor, isNonEmptyRunScope, isRemoteEvent, isWorkflowControlFlowSignal, legacySingletonHolders, listSignalWaitersOfRuns, liveHandoff, log, markRemoteEvent, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, onErrorRunId, pageFan, pageFanFromStore, parentRunIdOf, parseDuration, parseWebhookToken, partitionOfToken, planDispatch, poolNamespace, prevCronFireMs, queryCheckpointsOf, readRunsByIds, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, resolveTenantToken, resolveWireTenant, retiredHandoffName, routeFor, runDetailEtag, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduleRunIdAt, scheduledRunId, signTenantToken, singletonAdmissionDenialPatch, singletonAdmissionTags, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, summarizeFan, summarizeRunFromStore, summarizeTimeline, tenantGroup, useDurableExecution, warn, withSingletonTracked, withoutSingletonMarkers, workflowName };
package/dist/index.js CHANGED
@@ -2561,6 +2561,20 @@ function codeAndDetails(err) {
2561
2561
  }
2562
2562
  __name(codeAndDetails, "codeAndDetails");
2563
2563
 
2564
+ // src/remote-event.ts
2565
+ var REMOTE_EVENT = Symbol.for("@dudousxd/nestjs-durable:remote-event");
2566
+ function markRemoteEvent(event) {
2567
+ Object.defineProperty(event, REMOTE_EVENT, {
2568
+ value: true
2569
+ });
2570
+ return event;
2571
+ }
2572
+ __name(markRemoteEvent, "markRemoteEvent");
2573
+ function isRemoteEvent(event) {
2574
+ return event[REMOTE_EVENT] === true;
2575
+ }
2576
+ __name(isRemoteEvent, "isRemoteEvent");
2577
+
2564
2578
  // src/tenant-group.ts
2565
2579
  function tenantGroup(baseGroup, tenant) {
2566
2580
  return tenant !== void 0 && tenant !== "" && tenant !== "default" ? `${baseGroup}@${tenant}` : baseGroup;
@@ -4801,6 +4815,7 @@ var VERSION_UNDECLARED_TAG = "version:undeclared";
4801
4815
  var versionKey = /* @__PURE__ */ __name((name, version) => `${name}@${version}`, "versionKey");
4802
4816
  var STEP_FAN_CHUNK = 200;
4803
4817
  var FAN_REREAD_CHUNK = 1e3;
4818
+ var STEP_FAN_SEND_ROUND = 2e3;
4804
4819
  var PARENT_NOTIFY_ATTEMPTS = 4;
4805
4820
  var PARENT_NOTIFY_BACKOFF_MS = 250;
4806
4821
  var LEASE_RECHECK_MAX_MS = 2e3;
@@ -5265,10 +5280,10 @@ var WorkflowEngine = class {
5265
5280
  this.controlPlane?.onControl((msg) => {
5266
5281
  if (msg.from === this.instanceId) return;
5267
5282
  if (msg.kind === "event") {
5268
- this.deliver({
5283
+ this.deliver(markRemoteEvent({
5269
5284
  ...msg.event,
5270
5285
  at: new Date(msg.event.at)
5271
- });
5286
+ }));
5272
5287
  } else if (msg.kind === "cancel") {
5273
5288
  this.notifyCancelled(msg.runId);
5274
5289
  } else if (msg.kind === "enqueued") {
@@ -7273,7 +7288,7 @@ var WorkflowEngine = class {
7273
7288
  async redriveSettledStepFans(runId, fans) {
7274
7289
  for (const fan of fans) {
7275
7290
  if (this.stepFansFiredHere.has(`${runId}:${fan.from}`)) continue;
7276
- if (await this.stepFanPending(runId, fan.from, fan.to) > 0) continue;
7291
+ if (await this.stepFanHasPending(runId, fan.from, fan.to)) continue;
7277
7292
  const nowMs = this.clock();
7278
7293
  if (!await this.store.tryLockRun(runId, this.instanceId, nowMs + this.leaseMs, nowMs)) {
7279
7294
  return;
@@ -10211,10 +10226,25 @@ ${run.workflowVersion}`;
10211
10226
  }
10212
10227
  return bySeq;
10213
10228
  }
10229
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
10230
+ async saveFanCheckpoints(checkpoints) {
10231
+ if (this.store.saveCheckpoints) {
10232
+ await this.store.saveCheckpoints(checkpoints);
10233
+ return;
10234
+ }
10235
+ for (let at = 0; at < checkpoints.length; at += STEP_FAN_CHUNK) {
10236
+ await Promise.all(checkpoints.slice(at, at + STEP_FAN_CHUNK).map((cp) => this.store.saveCheckpoint(cp)));
10237
+ }
10238
+ }
10214
10239
  /**
10215
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
10216
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
10217
- * batch, where the store and transport have them.
10240
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
10241
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
10242
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
10243
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
10244
+ *
10245
+ * No result can wake the run before every round is written: the run is `running` under this
10246
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
10247
+ * checkpoint, and the replay sends them once the written ones settle.
10218
10248
  */
10219
10249
  async sendStepFan(runId, positions, step, inputs, batch, group, opts, routing) {
10220
10250
  const workerGroup = stepGroup(step, routing?.namespace);
@@ -10242,27 +10272,33 @@ ${run.workflowVersion}`;
10242
10272
  } : {}
10243
10273
  };
10244
10274
  });
10245
- if (this.store.saveCheckpoints) {
10246
- await this.store.saveCheckpoints(checkpoints);
10247
- } else {
10248
- for (let at = 0; at < checkpoints.length; at += STEP_FAN_CHUNK) {
10249
- await Promise.all(checkpoints.slice(at, at + STEP_FAN_CHUNK).map((cp) => this.store.saveCheckpoint(cp)));
10250
- }
10251
- }
10252
10275
  const traceparent = this.traceparent?.();
10253
10276
  const context = this.context?.();
10254
- await this.pool.dispatchMany(checkpoints.map((cp, k) => ({
10255
- runId,
10256
- seq: cp.seq,
10257
- name: step.name,
10258
- stepId: cp.stepId,
10259
- group: workerGroup,
10260
- input: inputs[batch[k]],
10261
- traceparent,
10262
- context,
10263
- priority: opts.admission?.priority,
10264
- attempt: 1
10265
- })), opts.transport);
10277
+ const dispatches = [];
10278
+ try {
10279
+ for (let from = 0; from < checkpoints.length; from += STEP_FAN_SEND_ROUND) {
10280
+ const round = checkpoints.slice(from, from + STEP_FAN_SEND_ROUND);
10281
+ await this.saveFanCheckpoints(round);
10282
+ const dispatch = this.pool.dispatchMany(round.map((cp, k) => ({
10283
+ runId,
10284
+ seq: cp.seq,
10285
+ name: step.name,
10286
+ stepId: cp.stepId,
10287
+ group: workerGroup,
10288
+ input: inputs[batch[from + k]],
10289
+ traceparent,
10290
+ context,
10291
+ priority: opts.admission?.priority,
10292
+ attempt: 1
10293
+ })), opts.transport);
10294
+ dispatch.catch(() => {
10295
+ });
10296
+ dispatches.push(dispatch);
10297
+ }
10298
+ } finally {
10299
+ await Promise.allSettled(dispatches);
10300
+ }
10301
+ await Promise.all(dispatches);
10266
10302
  for (const cp of checkpoints) {
10267
10303
  this.emit({
10268
10304
  type: "step.started",
@@ -10621,21 +10657,26 @@ ${run.workflowVersion}`;
10621
10657
  let closed = barriers.get(fan.firstSeq);
10622
10658
  if (!closed) {
10623
10659
  const lastSeq = fan.firstSeq + fan.size - 1;
10624
- closed = queuedIn(fan.firstSeq, lastSeq) ? Promise.resolve(true) : this.stepFanPending(result.runId, fan.firstSeq, lastSeq).then((pending) => pending > 0, () => false);
10660
+ closed = queuedIn(fan.firstSeq, lastSeq) ? Promise.resolve(true) : this.stepFanHasPending(result.runId, fan.firstSeq, lastSeq).catch(() => false);
10625
10661
  barriers.set(fan.firstSeq, closed);
10626
10662
  }
10627
10663
  if (await closed) return true;
10628
10664
  this.noteRecent(this.stepFansFiredHere, `${result.runId}:${fan.firstSeq}`);
10629
10665
  return false;
10630
10666
  }
10631
- /** How many steps of a step fan's seq range are still `pending`. */
10632
- async stepFanPending(runId, from, to) {
10633
- if (this.store.countCheckpoints) {
10634
- return this.store.countCheckpoints(runId, from, to, [
10667
+ /** Whether any step of a step fan's seq range is still `pending`. */
10668
+ async stepFanHasPending(runId, from, to) {
10669
+ if (this.store.hasCheckpoints) {
10670
+ return this.store.hasCheckpoints(runId, from, to, [
10635
10671
  "pending"
10636
10672
  ]);
10637
10673
  }
10638
- return (await this.store.listCheckpoints(runId)).filter((c) => c.seq >= from && c.seq <= to && c.status === "pending").length;
10674
+ if (this.store.countCheckpoints) {
10675
+ return await this.store.countCheckpoints(runId, from, to, [
10676
+ "pending"
10677
+ ]) > 0;
10678
+ }
10679
+ return (await this.store.listCheckpoints(runId)).some((c) => c.seq >= from && c.seq <= to && c.status === "pending");
10639
10680
  }
10640
10681
  /**
10641
10682
  * Apply a remote workflow-turn {@link WorkflowDecision} durably — runs on WHATEVER instance receives
@@ -11467,6 +11508,8 @@ var CodecStateStore = class {
11467
11508
  getCheckpointsForSettle;
11468
11509
  /** Decodes each checkpoint read. Bound only when the inner store has it. */
11469
11510
  getCheckpoints;
11511
+ /** Forwarded verbatim — reads no payload. Bound only when the inner store has it. */
11512
+ hasCheckpoints;
11470
11513
  /** Forwarded verbatim — a count reads no payload. Bound only when the inner store has it. */
11471
11514
  countCheckpoints;
11472
11515
  /** Forwarded verbatim — retention selects by status/updatedAt/scope, never by payload. Bound only
@@ -11527,6 +11570,8 @@ var CodecStateStore = class {
11527
11570
  if (getForSettle) this.getCheckpointsForSettle = async (runId, seqs) => (await getForSettle.call(inner, runId, seqs)).map((cp) => this.decCp(cp));
11528
11571
  const getMany = inner.getCheckpoints;
11529
11572
  if (getMany) this.getCheckpoints = async (runId, seqs) => (await getMany.call(inner, runId, seqs)).map((cp) => this.decCp(cp));
11573
+ const hasCps = inner.hasCheckpoints;
11574
+ if (hasCps) this.hasCheckpoints = (runId, from, to, statuses) => hasCps.call(inner, runId, from, to, statuses);
11530
11575
  const countCps = inner.countCheckpoints;
11531
11576
  if (countCps) this.countCheckpoints = (runId, from, to, statuses) => countCps.call(inner, runId, from, to, statuses);
11532
11577
  const stats = inner.checkpointStats;
@@ -11820,6 +11865,7 @@ function collectMetrics(engine) {
11820
11865
  return entry;
11821
11866
  }, "wf");
11822
11867
  const stop = engine.subscribe((e) => {
11868
+ if (isRemoteEvent(e)) return;
11823
11869
  switch (e.type) {
11824
11870
  case "run.started":
11825
11871
  m.runs.started += 1;
@@ -12594,6 +12640,9 @@ var InMemoryStateStore = class {
12594
12640
  ...latest
12595
12641
  } : void 0;
12596
12642
  }
12643
+ async hasCheckpoints(runId, fromSeq, toSeq, statuses) {
12644
+ return await this.countCheckpoints(runId, fromSeq, toSeq, statuses) > 0;
12645
+ }
12597
12646
  async countCheckpoints(runId, fromSeq, toSeq, statuses) {
12598
12647
  let n = 0;
12599
12648
  for (const cp of this.checkpoints.values()) {
@@ -12786,6 +12835,7 @@ export {
12786
12835
  NestedWorkflowCallError,
12787
12836
  NonDeterminismError,
12788
12837
  QueueController,
12838
+ REMOTE_EVENT,
12789
12839
  RUN_HISTORY_FIXTURE_VERSION,
12790
12840
  RUN_VALUE_FACET_LIMIT,
12791
12841
  RUN_VALUE_FACET_SCAN,
@@ -12876,11 +12926,13 @@ export {
12876
12926
  isFailedMember,
12877
12927
  isLegacyDescriptor,
12878
12928
  isNonEmptyRunScope,
12929
+ isRemoteEvent,
12879
12930
  isWorkflowControlFlowSignal,
12880
12931
  legacySingletonHolders,
12881
12932
  listSignalWaitersOfRuns,
12882
12933
  liveHandoff,
12883
12934
  log,
12935
+ markRemoteEvent,
12884
12936
  matchesAttributes,
12885
12937
  mergeRunFacetRows,
12886
12938
  mergeRunValueFacetRows,