@workflow/world-testing 5.0.0-beta.41 → 5.0.0-beta.43

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.
@@ -406,7 +406,7 @@ function buildFramedDetails(hint2, slug) {
406
406
  });
407
407
  return out;
408
408
  }
409
- var BASE_URL, ERROR_SLUGS, WorkflowError, WorkflowWorldError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRuntimeError, RuntimeDecryptionError, SerializationError, StepNotRegisteredError, WorkflowNotRegisteredError, WorkflowRunNotFoundError, HookConflictError, HookNotFoundError, EntityConflictError, RunExpiredError, ThrottleError, WorkflowRunCancelledError, FatalError, RetryableError, FATAL_ERROR_KEY, RETRYABLE_ERROR_KEY, HOOK_CONFLICT_ERROR_KEY, RUNTIME_DECRYPTION_ERROR_KEY;
409
+ var BASE_URL, ERROR_SLUGS, WorkflowError, WorkflowWorldError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRuntimeError, RuntimeDecryptionError, SerializationError, StepNotRegisteredError, WorkflowNotRegisteredError, WorkflowRunNotFoundError, HookConflictError, HookNotFoundError, EntityConflictError, RunExpiredError, StreamExpiredError, ThrottleError, WorkflowRunCancelledError, FatalError, RetryableError, FATAL_ERROR_KEY, RETRYABLE_ERROR_KEY, HOOK_CONFLICT_ERROR_KEY, RUNTIME_DECRYPTION_ERROR_KEY;
410
410
  var init_dist2 = __esm({
411
411
  "../errors/dist/index.js"() {
412
412
  "use strict";
@@ -682,6 +682,27 @@ Caused by: ${options.cause.stack}`;
682
682
  return isError(value) && value.name === "RunExpiredError";
683
683
  }
684
684
  };
685
+ StreamExpiredError = class extends WorkflowWorldError {
686
+ static {
687
+ __name(this, "StreamExpiredError");
688
+ }
689
+ runId;
690
+ streamId;
691
+ expiredAt;
692
+ constructor(message, runId, streamId, expiredAt) {
693
+ super(message, {
694
+ status: 410,
695
+ code: "stream-expired"
696
+ });
697
+ this.runId = runId;
698
+ this.streamId = streamId;
699
+ this.expiredAt = expiredAt;
700
+ this.name = "StreamExpiredError";
701
+ }
702
+ static is(value) {
703
+ return isError(value) && value.name === "StreamExpiredError";
704
+ }
705
+ };
685
706
  ThrottleError = class extends WorkflowWorldError {
686
707
  static {
687
708
  __name(this, "ThrottleError");
@@ -17399,7 +17420,7 @@ function getQueueTopicPrefix(kind, namespace) {
17399
17420
  }
17400
17421
  return "__wkf_workflow_";
17401
17422
  }
17402
- var QueuePrefix, ValidQueueName, QueueNamespace, MessageId, TraceCarrierSchema, RunInputSchema, HookResumeInputSchema, WorkflowInvokePayloadSchema, HealthCheckPayloadSchema, QueuePayloadSchema;
17423
+ var QueuePrefix, ValidQueueName, QueueNamespace, MessageId, TraceCarrierSchema, RunInputSchema, StepDispatchInputSchema, HookResumeInputSchema, HookResumeTimingSchema, WorkflowInvokePayloadSchema, HealthCheckPayloadSchema, QueuePayloadSchema;
17403
17424
  var init_queue = __esm({
17404
17425
  "../world/dist/queue.js"() {
17405
17426
  "use strict";
@@ -17446,6 +17467,19 @@ var init_queue = __esm({
17446
17467
  */
17447
17468
  environment: external_exports.string().optional()
17448
17469
  });
17470
+ StepDispatchInputSchema = external_exports.object({
17471
+ /**
17472
+ * The serialized step input, reused verbatim from the direct write. Always
17473
+ * binary: producers only attach `stepInput` when the dehydrated input is a
17474
+ * `Uint8Array` and the run's queue transport preserves bytes (CBOR).
17475
+ * Validated here so a malformed or transport-mangled payload fails the
17476
+ * message parse instead of being silently written into a `step_created` as
17477
+ * non-binary data. `Buffer` is a `Uint8Array` subclass and passes.
17478
+ */
17479
+ input: external_exports.custom((value) => value instanceof Uint8Array, {
17480
+ message: "stepInput.input must be a Uint8Array"
17481
+ })
17482
+ });
17449
17483
  HookResumeInputSchema = external_exports.object({
17450
17484
  /** Stable idempotency key minted once per `resumeHook()` call. */
17451
17485
  resumeId: external_exports.string(),
@@ -17479,6 +17513,22 @@ var init_queue = __esm({
17479
17513
  */
17480
17514
  deploymentId: external_exports.string().optional()
17481
17515
  });
17516
+ HookResumeTimingSchema = external_exports.object({
17517
+ /** Epoch ms at entry into `resumeHook()` — the start of the TTR window. */
17518
+ resumeRequestedAtMs: external_exports.number(),
17519
+ /** Epoch ms immediately before the queue publish was requested. */
17520
+ queuePublishRequestedAtMs: external_exports.number(),
17521
+ /** Which `resumeHook()` dispatch path ran: `parallel` or `sequential`. */
17522
+ strategy: external_exports.string().optional(),
17523
+ /** Epoch ms the final consumer's queue handler was entered. */
17524
+ consumerStartedAtMs: external_exports.number().optional(),
17525
+ /** Epoch ms this invocation's first replay pass began. */
17526
+ replayStartedAtMs: external_exports.number().optional(),
17527
+ /** Epoch ms replay first encountered a durable step after the resume. */
17528
+ nextStepEncounteredAtMs: external_exports.number().optional(),
17529
+ /** How the consumer initialized replay state: see `ResumeSetupSource`. */
17530
+ setupSource: external_exports.string().optional()
17531
+ });
17482
17532
  WorkflowInvokePayloadSchema = external_exports.object({
17483
17533
  runId: external_exports.string(),
17484
17534
  traceCarrier: TraceCarrierSchema.optional(),
@@ -17512,7 +17562,28 @@ var init_queue = __esm({
17512
17562
  * fast path. A consumer that understands this field idempotently ensures the
17513
17563
  * `hook_received` event exists (keyed by `resumeId`) before replaying.
17514
17564
  */
17515
- hookInput: HookResumeInputSchema.optional()
17565
+ hookInput: HookResumeInputSchema.optional(),
17566
+ /**
17567
+ * Resilient step dispatch data, only present alongside `stepId` when the
17568
+ * producer parallelized the `step_created` write with this queue publish. A
17569
+ * consumer that understands this field idempotently ensures the
17570
+ * `step_created` event exists (keyed by `stepId`) before executing the step.
17571
+ */
17572
+ stepInput: StepDispatchInputSchema.optional(),
17573
+ /**
17574
+ * Hook-resume TTR timing. Present on both `resumeHook()` dispatch paths
17575
+ * (unlike `hookInput`, which only rides the parallel fast path), and
17576
+ * forwarded onto a dispatched step message when the resuming invocation
17577
+ * hands the next durable step to another invocation. Purely observational —
17578
+ * see {@link HookResumeTimingSchema}.
17579
+ *
17580
+ * `.catch(undefined)` because this field must never be able to fail the
17581
+ * parse of the invocation payload: a malformed value (a NaN boundary, a
17582
+ * shape change from a future producer) would otherwise throw on every
17583
+ * delivery of that message and burn the run's delivery budget over a
17584
+ * telemetry field. Anything unparseable degrades to "no measurement".
17585
+ */
17586
+ hookResumeTiming: HookResumeTimingSchema.optional().catch(void 0)
17516
17587
  });
17517
17588
  HealthCheckPayloadSchema = external_exports.object({
17518
17589
  __healthCheck: external_exports.literal(true),
@@ -17608,6 +17679,14 @@ var init_hooks = __esm({
17608
17679
  }
17609
17680
  });
17610
17681
 
17682
+ // ../world/dist/node-http-flag.js
17683
+ var init_node_http_flag = __esm({
17684
+ "../world/dist/node-http-flag.js"() {
17685
+ "use strict";
17686
+ init_env_config();
17687
+ }
17688
+ });
17689
+
17611
17690
  // ../world/dist/recovery.js
17612
17691
  var init_recovery = __esm({
17613
17692
  "../world/dist/recovery.js"() {
@@ -17669,7 +17748,7 @@ var init_spec_version = __esm({
17669
17748
  SPEC_VERSION_SUPPORTS_ATTRIBUTES = 4;
17670
17749
  SPEC_VERSION_SUPPORTS_COMPRESSION = 5;
17671
17750
  SPEC_VERSION_SUPPORTS_SLOT_IDENTITY = 6;
17672
- SPEC_VERSION_CURRENT = SPEC_VERSION_SUPPORTS_COMPRESSION;
17751
+ SPEC_VERSION_CURRENT = SPEC_VERSION_SUPPORTS_SLOT_IDENTITY;
17673
17752
  SPEC_VERSION_MAX_SUPPORTED = SPEC_VERSION_SUPPORTS_SLOT_IDENTITY;
17674
17753
  __name(isLegacySpecVersion, "isLegacySpecVersion");
17675
17754
  }
@@ -17847,6 +17926,7 @@ var init_dist4 = __esm({
17847
17926
  init_env_config();
17848
17927
  init_events();
17849
17928
  init_hooks();
17929
+ init_node_http_flag();
17850
17930
  init_queue();
17851
17931
  init_recovery();
17852
17932
  init_runs();
@@ -20508,7 +20588,7 @@ function getReviversForMode(mode, global2 = globalThis, extraRevivers) {
20508
20588
  }
20509
20589
  return base;
20510
20590
  }
20511
- var encoder, decoder, devalueCodec;
20591
+ var encoder, decoder, MAX_SPARSE_ARRAY_LENGTH, parseOptions, devalueCodec;
20512
20592
  var init_codec_devalue = __esm({
20513
20593
  "../core/dist/serialization/codec-devalue.js"() {
20514
20594
  "use strict";
@@ -20520,6 +20600,17 @@ var init_codec_devalue = __esm({
20520
20600
  init_types();
20521
20601
  encoder = new TextEncoder();
20522
20602
  decoder = new TextDecoder();
20603
+ MAX_SPARSE_ARRAY_LENGTH = 1e5;
20604
+ parseOptions = {
20605
+ operations: {
20606
+ createSparseArray(length) {
20607
+ if (length > MAX_SPARSE_ARRAY_LENGTH) {
20608
+ throw new RangeError(`Sparse array length ${length} exceeds the maximum of ${MAX_SPARSE_ARRAY_LENGTH}`);
20609
+ }
20610
+ return default_parse_operations.createSparseArray(length);
20611
+ }
20612
+ }
20613
+ };
20523
20614
  __name(getReducersForMode, "getReducersForMode");
20524
20615
  __name(getReviversForMode, "getReviversForMode");
20525
20616
  devalueCodec = {
@@ -20534,11 +20625,11 @@ var init_codec_devalue = __esm({
20534
20625
  deserialize(data, mode, options) {
20535
20626
  const revivers = getReviversForMode(mode, options?.global, options?.extraRevivers);
20536
20627
  const str = decoder.decode(data);
20537
- return parse3(str, revivers);
20628
+ return parse3(str, revivers, parseOptions);
20538
20629
  },
20539
20630
  deserializeLegacy(data, mode, options) {
20540
20631
  const revivers = getReviversForMode(mode, options?.global, options?.extraRevivers);
20541
- return unflatten(data, revivers);
20632
+ return unflatten(data, revivers, parseOptions);
20542
20633
  }
20543
20634
  };
20544
20635
  }
@@ -21059,7 +21150,7 @@ function SemanticConvention(...names) {
21059
21150
  value
21060
21151
  ]));
21061
21152
  }
21062
- var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowExecutionMode, WorkflowParkedEventsCount, WorkflowParkedEventId, WorkflowParkedEventType, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowVm, QuickJSOutcome, QuickJSEventsPreloaded, QuickJSEventsFetchedCount, QuickJSEventsFetchedPages, QuickJSPendingOpsCount, QuickJSInlineSteps, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, FaasInstance, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, WorkflowRunPinnedDeploymentId, WorkflowDeploymentMismatchRetryCount, WorkflowDeploymentMismatchRecovered, HookToken, HookId, HookFound, HookResilientResume, HookResilientResumeMaterialized, HookResumeSetupSource, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, SerializationGuestCodeExecutions, SerializationGuestCodeDetails, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
21153
+ var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowExecutionMode, WorkflowParkedEventsCount, WorkflowParkedEventId, WorkflowParkedEventType, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowVm, QuickJSOutcome, QuickJSEventsPreloaded, QuickJSEventsFetchedCount, QuickJSEventsFetchedPages, QuickJSPendingOpsCount, QuickJSInlineSteps, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, FaasInstance, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, WorkflowRunPinnedDeploymentId, WorkflowDeploymentMismatchRetryCount, WorkflowDeploymentMismatchRecovered, HookToken, HookId, HookFound, HookResilientResume, HookResilientResumeMaterialized, HookResumeSetupSource, StepResilientDispatchRecovered, StepResilientDispatchMaterialized, ResumeTotalMs, ResumeProducerPrepMs, ResumeQueueDeliveryMs, ResumeSetupMs, ResumeReplayMs, ResumeStepDispatchMs, ResumeStepClaimMs, ResumeStepPrepareMs, ResumeTrigger, ResumeStrategy, ResumeSetupSource, ResumeStepExecution, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, SerializationGuestCodeExecutions, SerializationGuestCodeDetails, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
21063
21154
  var init_semantic_conventions = __esm({
21064
21155
  "../core/dist/telemetry/semantic-conventions.js"() {
21065
21156
  "use strict";
@@ -21136,6 +21227,20 @@ var init_semantic_conventions = __esm({
21136
21227
  HookResilientResume = SemanticConvention("workflow.hook.resilient_resume");
21137
21228
  HookResilientResumeMaterialized = SemanticConvention("workflow.hook.resilient_resume_materialized");
21138
21229
  HookResumeSetupSource = SemanticConvention("workflow.resume_setup_source");
21230
+ StepResilientDispatchRecovered = SemanticConvention("workflow.step.resilient_dispatch_recovered");
21231
+ StepResilientDispatchMaterialized = SemanticConvention("workflow.step.resilient_dispatch_materialized");
21232
+ ResumeTotalMs = SemanticConvention("workflow.resume.total_ms");
21233
+ ResumeProducerPrepMs = SemanticConvention("workflow.resume.phase.producer_prep_ms");
21234
+ ResumeQueueDeliveryMs = SemanticConvention("workflow.resume.phase.queue_delivery_ms");
21235
+ ResumeSetupMs = SemanticConvention("workflow.resume.phase.resume_setup_ms");
21236
+ ResumeReplayMs = SemanticConvention("workflow.resume.phase.replay_ms");
21237
+ ResumeStepDispatchMs = SemanticConvention("workflow.resume.phase.step_dispatch_ms");
21238
+ ResumeStepClaimMs = SemanticConvention("workflow.resume.phase.step_claim_ms");
21239
+ ResumeStepPrepareMs = SemanticConvention("workflow.resume.phase.step_prepare_ms");
21240
+ ResumeTrigger = SemanticConvention("workflow.resume.trigger");
21241
+ ResumeStrategy = SemanticConvention("workflow.resume.strategy");
21242
+ ResumeSetupSource = SemanticConvention("workflow.resume.setup_source");
21243
+ ResumeStepExecution = SemanticConvention("workflow.resume.step_execution");
21139
21244
  WebhookHandlersTriggered = SemanticConvention("webhook.handlers.triggered");
21140
21245
  WorkflowSuspensionState = SemanticConvention("workflow.suspension.state");
21141
21246
  WorkflowSuspensionHookCount = SemanticConvention("workflow.suspension.hook_count");
@@ -23332,7 +23437,7 @@ async function linkToTraceCarrier(carrier) {
23332
23437
  context
23333
23438
  };
23334
23439
  }
23335
- var OtelApi, Tracer, otelDiagLogged;
23440
+ var OtelApi, Tracer, StepExecutionDurationHistogram, otelDiagLogged;
23336
23441
  var init_telemetry = __esm({
23337
23442
  "../core/dist/telemetry.js"() {
23338
23443
  "use strict";
@@ -23357,6 +23462,14 @@ var init_telemetry = __esm({
23357
23462
  logOtelDiagnosticOnce(api, tracer);
23358
23463
  return tracer;
23359
23464
  });
23465
+ StepExecutionDurationHistogram = once(async () => {
23466
+ const otel = await OtelApi.value;
23467
+ if (!otel) return null;
23468
+ return otel.metrics.getMeter("workflow").createHistogram("workflow.step.execute.duration", {
23469
+ description: "Duration of user step execution",
23470
+ unit: "ms"
23471
+ });
23472
+ });
23360
23473
  otelDiagLogged = false;
23361
23474
  __name(logOtelDiagnosticOnce, "logOtelDiagnosticOnce");
23362
23475
  __name(trace, "trace");
@@ -23862,7 +23975,7 @@ var require_parse_options = __commonJS({
23862
23975
  loose: true
23863
23976
  });
23864
23977
  var emptyOpts = Object.freeze({});
23865
- var parseOptions = /* @__PURE__ */ __name((options) => {
23978
+ var parseOptions2 = /* @__PURE__ */ __name((options) => {
23866
23979
  if (!options) {
23867
23980
  return emptyOpts;
23868
23981
  }
@@ -23871,7 +23984,7 @@ var require_parse_options = __commonJS({
23871
23984
  }
23872
23985
  return options;
23873
23986
  }, "parseOptions");
23874
- module.exports = parseOptions;
23987
+ module.exports = parseOptions2;
23875
23988
  }
23876
23989
  });
23877
23990
 
@@ -23907,14 +24020,14 @@ var require_semver2 = __commonJS({
23907
24020
  var debug = require_debug();
23908
24021
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
23909
24022
  var { safeRe: re, t } = require_re();
23910
- var parseOptions = require_parse_options();
24023
+ var parseOptions2 = require_parse_options();
23911
24024
  var { compareIdentifiers } = require_identifiers();
23912
24025
  var SemVer = class _SemVer {
23913
24026
  static {
23914
24027
  __name(this, "SemVer");
23915
24028
  }
23916
24029
  constructor(version3, options) {
23917
- options = parseOptions(options);
24030
+ options = parseOptions2(options);
23918
24031
  if (version3 instanceof _SemVer) {
23919
24032
  if (version3.loose === !!options.loose && version3.includePrerelease === !!options.includePrerelease) {
23920
24033
  return version3;
@@ -24614,7 +24727,7 @@ var require_range = __commonJS({
24614
24727
  __name(this, "Range");
24615
24728
  }
24616
24729
  constructor(range, options) {
24617
- options = parseOptions(options);
24730
+ options = parseOptions2(options);
24618
24731
  if (range instanceof _Range) {
24619
24732
  if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
24620
24733
  return range;
@@ -24765,7 +24878,7 @@ var require_range = __commonJS({
24765
24878
  module.exports = Range;
24766
24879
  var LRU = require_lrucache();
24767
24880
  var cache = new LRU();
24768
- var parseOptions = require_parse_options();
24881
+ var parseOptions2 = require_parse_options();
24769
24882
  var Comparator = require_comparator();
24770
24883
  var debug = require_debug();
24771
24884
  var SemVer = require_semver2();
@@ -25003,7 +25116,7 @@ var require_comparator = __commonJS({
25003
25116
  return ANY;
25004
25117
  }
25005
25118
  constructor(comp, options) {
25006
- options = parseOptions(options);
25119
+ options = parseOptions2(options);
25007
25120
  if (comp instanceof _Comparator) {
25008
25121
  if (comp.loose === !!options.loose) {
25009
25122
  return comp;
@@ -25071,7 +25184,7 @@ var require_comparator = __commonJS({
25071
25184
  }
25072
25185
  return new Range(this.value, options).test(comp.semver);
25073
25186
  }
25074
- options = parseOptions(options);
25187
+ options = parseOptions2(options);
25075
25188
  if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) {
25076
25189
  return false;
25077
25190
  }
@@ -25097,7 +25210,7 @@ var require_comparator = __commonJS({
25097
25210
  }
25098
25211
  };
25099
25212
  module.exports = Comparator;
25100
- var parseOptions = require_parse_options();
25213
+ var parseOptions2 = require_parse_options();
25101
25214
  var { safeRe: re, t } = require_re();
25102
25215
  var cmp = require_cmp();
25103
25216
  var debug = require_debug();
@@ -25810,7 +25923,7 @@ var version2;
25810
25923
  var init_version = __esm({
25811
25924
  "../core/dist/version.js"() {
25812
25925
  "use strict";
25813
- version2 = "5.0.0-beta.41";
25926
+ version2 = "5.0.0-beta.43";
25814
25927
  }
25815
25928
  });
25816
25929
 
@@ -31009,9 +31122,9 @@ async function getHookByToken(token) {
31009
31122
  return hook;
31010
31123
  }
31011
31124
  async function resumeHook(tokenOrHook, payload, encryptionKeyOverride) {
31012
- return resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, false);
31125
+ return resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, false, Date.now());
31013
31126
  }
31014
- async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookFreshlyLookedUp) {
31127
+ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookFreshlyLookedUp, resumeRequestedAtMs) {
31015
31128
  return await waitedUntil(() => {
31016
31129
  return trace("hook.resume", async (span) => {
31017
31130
  const world = await getWorldLazy();
@@ -31103,9 +31216,15 @@ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookF
31103
31216
  }
31104
31217
  throw err;
31105
31218
  }
31219
+ const queuePublishRequestedAtMs = Date.now();
31106
31220
  await world.queue(queueName, {
31107
31221
  runId: hook.runId,
31108
- traceCarrier: resumeContext.traceCarrier ?? void 0
31222
+ traceCarrier: resumeContext.traceCarrier ?? void 0,
31223
+ hookResumeTiming: {
31224
+ resumeRequestedAtMs,
31225
+ queuePublishRequestedAtMs,
31226
+ strategy: "sequential"
31227
+ }
31109
31228
  }, queueOptions);
31110
31229
  return hook;
31111
31230
  }
@@ -31114,18 +31233,9 @@ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookF
31114
31233
  span?.setAttributes({
31115
31234
  "workflow.hook.resume_id": resumeId
31116
31235
  });
31117
- const [eventResult, queueResult] = await Promise.allSettled([
31118
- world.events.create(hook.runId, {
31119
- eventType: "hook_received",
31120
- specVersion: SPEC_VERSION_CURRENT,
31121
- correlationId: hook.hookId,
31122
- eventData
31123
- }, {
31124
- v1Compat,
31125
- resumeId,
31126
- resumePayloadDigest: payloadDigest
31127
- }),
31128
- world.queue(queueName, {
31236
+ const publishInvocation = /* @__PURE__ */ __name(() => {
31237
+ const queuePublishRequestedAtMs = Date.now();
31238
+ return world.queue(queueName, {
31129
31239
  runId: hook.runId,
31130
31240
  traceCarrier: resumeContext.traceCarrier ?? void 0,
31131
31241
  hookInput: {
@@ -31138,8 +31248,26 @@ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookF
31138
31248
  // check: lets a misrouted delivery re-route before its
31139
31249
  // hoisted hook_received write instead of after.
31140
31250
  deploymentId: resumeContext.deploymentId
31251
+ },
31252
+ hookResumeTiming: {
31253
+ resumeRequestedAtMs,
31254
+ queuePublishRequestedAtMs,
31255
+ strategy: "parallel"
31141
31256
  }
31142
- }, queueOptions)
31257
+ }, queueOptions);
31258
+ }, "publishInvocation");
31259
+ const [eventResult, queueResult] = await Promise.allSettled([
31260
+ world.events.create(hook.runId, {
31261
+ eventType: "hook_received",
31262
+ specVersion: SPEC_VERSION_CURRENT,
31263
+ correlationId: hook.hookId,
31264
+ eventData
31265
+ }, {
31266
+ v1Compat,
31267
+ resumeId,
31268
+ resumePayloadDigest: payloadDigest
31269
+ }),
31270
+ publishInvocation()
31143
31271
  ]);
31144
31272
  if (queueResult.status === "rejected") {
31145
31273
  throw queueResult.reason;
@@ -31182,6 +31310,7 @@ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookF
31182
31310
  });
31183
31311
  }
31184
31312
  async function resumeWebhook(token, request) {
31313
+ const resumeRequestedAtMs = Date.now();
31185
31314
  const { hook, encryptionKey } = await getHookByTokenWithKey(token);
31186
31315
  if (hook.isWebhook === false) {
31187
31316
  throw new HookNotFoundError(token);
@@ -31205,7 +31334,7 @@ async function resumeWebhook(token, request) {
31205
31334
  status: 202
31206
31335
  });
31207
31336
  }
31208
- await resumeHookImpl(hook, request, encryptionKey, true);
31337
+ await resumeHookImpl(hook, request, encryptionKey, true, resumeRequestedAtMs);
31209
31338
  if (responseReadable) {
31210
31339
  const reader = responseReadable.getReader();
31211
31340
  const chunk = await reader.read();
@@ -31556,6 +31685,16 @@ function createReconnectingFramedStream(runId, name, startIndex) {
31556
31685
  reader = stream.getReader();
31557
31686
  }
31558
31687
  __name(connect, "connect");
31688
+ async function isVerifiedComplete() {
31689
+ try {
31690
+ const world = await getWorldLazy();
31691
+ const info = await world.streams.getInfo(runId, name);
31692
+ return info.done && currentStartIndex + consumedFrames > info.tailIndex;
31693
+ } catch {
31694
+ return true;
31695
+ }
31696
+ }
31697
+ __name(isVerifiedComplete, "isVerifiedComplete");
31559
31698
  async function reconnect() {
31560
31699
  if (reader) {
31561
31700
  await reader.cancel().catch(() => {
@@ -31579,7 +31718,8 @@ function createReconnectingFramedStream(runId, name, startIndex) {
31579
31718
  try {
31580
31719
  await connect();
31581
31720
  return;
31582
- } catch {
31721
+ } catch (error48) {
31722
+ if (StreamExpiredError.is(error48)) throw error48;
31583
31723
  }
31584
31724
  }
31585
31725
  }
@@ -31614,6 +31754,15 @@ function createReconnectingFramedStream(runId, name, startIndex) {
31614
31754
  }
31615
31755
  if (result.done || !result.value) {
31616
31756
  reader = void 0;
31757
+ if (reconnectSupported && !await isVerifiedComplete()) {
31758
+ try {
31759
+ await reconnect();
31760
+ } catch (reconnectErr) {
31761
+ controller.error(reconnectErr);
31762
+ return;
31763
+ }
31764
+ continue;
31765
+ }
31617
31766
  if (readStart !== void 0) {
31618
31767
  recordStreamReadComplete(readStart, runId, name, chunksDelivered, bytesDelivered, totalReconnectCount);
31619
31768
  }
@@ -33379,7 +33528,7 @@ __name(start, "start");
33379
33528
  value: "start",
33380
33529
  configurable: true
33381
33530
  });
33382
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.41//start");
33531
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.43//start");
33383
33532
 
33384
33533
  // ../core/dist/runtime/runs.js
33385
33534
  async function wakeUpRun(world, runId, options) {
@@ -33466,6 +33615,10 @@ __name(wakeUpRun, "wakeUpRun");
33466
33615
 
33467
33616
  // ../core/dist/runtime/run.js
33468
33617
  var RETURN_VALUE_POLL_INTERVAL_MS = 1e3;
33618
+ var PAYLOAD_TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set([
33619
+ "completed",
33620
+ "failed"
33621
+ ]);
33469
33622
  function getReturnValuePollIntervalMs() {
33470
33623
  return envNumber("WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS", RETURN_VALUE_POLL_INTERVAL_MS, {
33471
33624
  integer: true,
@@ -33525,12 +33678,12 @@ var Run = class _Run {
33525
33678
  * to be resolved once.
33526
33679
  * @internal
33527
33680
  */
33528
- #getEncryptionKey() {
33681
+ #getEncryptionKey(run2) {
33529
33682
  if (!this.#encryptionKeyPromise) {
33530
33683
  this.#encryptionKeyPromise = (async () => {
33531
33684
  const world = await this.#lazyWorldPromise;
33532
- const run2 = await world.runs.get(this.runId);
33533
- const rawKey = await world.getEncryptionKeyForRun?.(run2);
33685
+ const runData = run2 ?? await world.runs.get(this.runId);
33686
+ const rawKey = await world.getEncryptionKeyForRun?.(runData);
33534
33687
  return rawKey ? await deriveRunPayloadKeys(rawKey) : void 0;
33535
33688
  })();
33536
33689
  }
@@ -33591,7 +33744,9 @@ var Run = class _Run {
33591
33744
  * The status of the workflow run.
33592
33745
  */
33593
33746
  get status() {
33594
- return this.#lazyWorldPromise.then((world) => world.runs.get(this.runId).then((run2) => run2.status));
33747
+ return this.#lazyWorldPromise.then((world) => world.runs.get(this.runId, {
33748
+ resolveData: "none"
33749
+ }).then((run2) => run2.status));
33595
33750
  }
33596
33751
  /**
33597
33752
  * The return value of the workflow run.
@@ -33662,6 +33817,29 @@ var Run = class _Run {
33662
33817
  }, "getTailIndex")
33663
33818
  });
33664
33819
  }
33820
+ /** @internal */
33821
+ async #resolveTerminalReturnValue(run2) {
33822
+ if (run2.status === "completed") {
33823
+ const encryptionKey = await this.#getEncryptionKey(run2);
33824
+ return await hydrateWorkflowReturnValue(run2.output, this.runId, encryptionKey);
33825
+ }
33826
+ if (run2.status === "cancelled") {
33827
+ throw new WorkflowRunCancelledError(this.runId);
33828
+ }
33829
+ if (run2.status === "failed") {
33830
+ const encryptionKey = await this.#getEncryptionKey(run2);
33831
+ let hydratedError;
33832
+ try {
33833
+ hydratedError = await hydrateRunError(run2.error, this.runId, encryptionKey);
33834
+ } catch {
33835
+ hydratedError = new Error("Failed to hydrate workflow run error");
33836
+ }
33837
+ throw new WorkflowRunFailedError(this.runId, hydratedError, {
33838
+ errorCode: run2.errorCode
33839
+ });
33840
+ }
33841
+ throw new WorkflowRunNotCompletedError(this.runId, run2.status);
33842
+ }
33665
33843
  /**
33666
33844
  * Polls the workflow return value until it is completed.
33667
33845
  * @internal
@@ -33678,27 +33856,19 @@ var Run = class _Run {
33678
33856
  ];
33679
33857
  while (true) {
33680
33858
  try {
33681
- const run2 = await world.runs.get(this.runId);
33682
- if (run2.status === "completed") {
33683
- const encryptionKey = await this.#getEncryptionKey();
33684
- return await hydrateWorkflowReturnValue(run2.output, this.runId, encryptionKey);
33685
- }
33686
- if (run2.status === "cancelled") {
33859
+ const runMetadata = await world.runs.get(this.runId, {
33860
+ resolveData: "none"
33861
+ });
33862
+ if (runMetadata.status === "cancelled") {
33687
33863
  throw new WorkflowRunCancelledError(this.runId);
33688
33864
  }
33689
- if (run2.status === "failed") {
33690
- const encryptionKey = await this.#getEncryptionKey();
33691
- let hydratedError;
33692
- try {
33693
- hydratedError = await hydrateRunError(run2.error, this.runId, encryptionKey);
33694
- } catch {
33695
- hydratedError = new Error("Failed to hydrate workflow run error");
33696
- }
33697
- throw new WorkflowRunFailedError(this.runId, hydratedError, {
33698
- errorCode: run2.errorCode
33865
+ if (PAYLOAD_TERMINAL_RUN_STATUSES.has(runMetadata.status)) {
33866
+ const run2 = await world.runs.get(this.runId, {
33867
+ resolveData: "all"
33699
33868
  });
33869
+ return await this.#resolveTerminalReturnValue(run2);
33700
33870
  }
33701
- throw new WorkflowRunNotCompletedError(this.runId, run2.status);
33871
+ throw new WorkflowRunNotCompletedError(this.runId, runMetadata.status);
33702
33872
  } catch (error48) {
33703
33873
  if (WorkflowRunNotCompletedError.is(error48)) {
33704
33874
  await new Promise((resolve) => setTimeout(resolve, getReturnValuePollIntervalMs()));
@@ -33723,7 +33893,7 @@ var Run = class _Run {
33723
33893
  value: "wakeUp",
33724
33894
  configurable: true
33725
33895
  });
33726
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#wakeUp");
33896
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#wakeUp");
33727
33897
  (function(__wf_fn, __wf_id) {
33728
33898
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33729
33899
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33732,7 +33902,7 @@ var Run = class _Run {
33732
33902
  value: "cancel",
33733
33903
  configurable: true
33734
33904
  });
33735
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#cancel");
33905
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#cancel");
33736
33906
  (function(__wf_fn, __wf_id) {
33737
33907
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33738
33908
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33741,7 +33911,7 @@ var Run = class _Run {
33741
33911
  value: "getReadable",
33742
33912
  configurable: true
33743
33913
  });
33744
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#getReadable");
33914
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#getReadable");
33745
33915
  (function(__wf_fn, __wf_id) {
33746
33916
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33747
33917
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33750,7 +33920,7 @@ var Run = class _Run {
33750
33920
  value: "exists",
33751
33921
  configurable: true
33752
33922
  });
33753
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#exists");
33923
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#exists");
33754
33924
  (function(__wf_fn, __wf_id) {
33755
33925
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33756
33926
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33759,7 +33929,7 @@ var Run = class _Run {
33759
33929
  value: "status",
33760
33930
  configurable: true
33761
33931
  });
33762
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#status");
33932
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#status");
33763
33933
  (function(__wf_fn, __wf_id) {
33764
33934
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33765
33935
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33768,7 +33938,7 @@ var Run = class _Run {
33768
33938
  value: "returnValue",
33769
33939
  configurable: true
33770
33940
  });
33771
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#returnValue");
33941
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#returnValue");
33772
33942
  (function(__wf_fn, __wf_id) {
33773
33943
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33774
33944
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33777,7 +33947,7 @@ var Run = class _Run {
33777
33947
  value: "workflowName",
33778
33948
  configurable: true
33779
33949
  });
33780
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#workflowName");
33950
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#workflowName");
33781
33951
  (function(__wf_fn, __wf_id) {
33782
33952
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33783
33953
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33786,7 +33956,7 @@ var Run = class _Run {
33786
33956
  value: "createdAt",
33787
33957
  configurable: true
33788
33958
  });
33789
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#createdAt");
33959
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#createdAt");
33790
33960
  (function(__wf_fn, __wf_id) {
33791
33961
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33792
33962
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33795,7 +33965,7 @@ var Run = class _Run {
33795
33965
  value: "startedAt",
33796
33966
  configurable: true
33797
33967
  });
33798
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#startedAt");
33968
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#startedAt");
33799
33969
  (function(__wf_fn, __wf_id) {
33800
33970
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33801
33971
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33804,7 +33974,7 @@ var Run = class _Run {
33804
33974
  value: "completedAt",
33805
33975
  configurable: true
33806
33976
  });
33807
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.41//Run#completedAt");
33977
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#completedAt");
33808
33978
  (function(__wf_cls, __wf_id) {
33809
33979
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33810
33980
  __wf_reg.set(__wf_id, __wf_cls);
@@ -33814,7 +33984,7 @@ var Run = class _Run {
33814
33984
  enumerable: false,
33815
33985
  configurable: false
33816
33986
  });
33817
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.41//Run");
33987
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.43//Run");
33818
33988
 
33819
33989
  // ../workflow/dist/stdlib.js
33820
33990
  async function fetch2(...args) {