@workflow/world-testing 5.0.0-beta.29 → 5.0.0-beta.30

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.
@@ -14926,6 +14926,36 @@ var init_serialization3 = __esm({
14926
14926
  });
14927
14927
 
14928
14928
  // ../world/dist/events.js
14929
+ function isRunEventType(eventType) {
14930
+ return RUN_EVENT_TYPES2.includes(eventType);
14931
+ }
14932
+ function isTerminalRunEventType(eventType) {
14933
+ return TERMINAL_RUN_EVENT_TYPES2.includes(eventType);
14934
+ }
14935
+ function isStepEventType(eventType) {
14936
+ return STEP_EVENT_TYPES2.includes(eventType);
14937
+ }
14938
+ function isTerminalStepEventType(eventType) {
14939
+ return TERMINAL_STEP_EVENT_TYPES2.includes(eventType);
14940
+ }
14941
+ function isHookLifecycleEventType(eventType) {
14942
+ return HOOK_LIFECYCLE_EVENT_TYPES2.includes(eventType);
14943
+ }
14944
+ function isHookEventRequiringExistence(eventType) {
14945
+ return HOOK_EVENTS_REQUIRING_EXISTENCE2.includes(eventType);
14946
+ }
14947
+ function isWaitEventType(eventType) {
14948
+ return WAIT_EVENT_TYPES2.includes(eventType);
14949
+ }
14950
+ function isChildEntityCreationEventType(eventType) {
14951
+ return CHILD_ENTITY_CREATION_EVENT_TYPES2.includes(eventType);
14952
+ }
14953
+ function getEventDataRefFields(eventType) {
14954
+ return EVENT_DATA_REF_FIELDS2[eventType] ?? [];
14955
+ }
14956
+ function getEventDataPayloadField(eventType) {
14957
+ return EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE2[eventType];
14958
+ }
14929
14959
  function stripEventDataRefs(event, resolveData) {
14930
14960
  if (resolveData !== "none")
14931
14961
  return event;
@@ -14936,8 +14966,8 @@ function stripEventDataRefs(event, resolveData) {
14936
14966
  const { eventData: _2, ...rest2 } = event;
14937
14967
  return rest2;
14938
14968
  }
14939
- const refFields = EVENT_DATA_REF_FIELDS[event.eventType];
14940
- if (!refFields || refFields.length === 0)
14969
+ const refFields = getEventDataRefFields(event.eventType);
14970
+ if (refFields.length === 0)
14941
14971
  return event;
14942
14972
  const stripped = { ...eventData };
14943
14973
  for (const field of refFields) {
@@ -14949,28 +14979,18 @@ function stripEventDataRefs(event, resolveData) {
14949
14979
  ...Object.keys(stripped).length > 0 ? { eventData: stripped } : {}
14950
14980
  };
14951
14981
  }
14952
- function isTerminalRunEventType(eventType) {
14953
- return TERMINAL_RUN_EVENT_TYPES2.includes(eventType);
14982
+ function isChildEntityCreationEvent(event) {
14983
+ if (isChildEntityCreationEventType(event.eventType))
14984
+ return true;
14985
+ return event.eventType === "step_started" && typeof event.eventData?.stepName === "string" && event.eventData.input !== void 0;
14954
14986
  }
14955
- var EVENT_DATA_REF_FIELDS, EventTypeSchema2, TerminalRunEventTypeSchema2, TERMINAL_RUN_EVENT_TYPES2, BaseEventSchema2, stepLatencyTelemetryFields2, StepCompletedEventSchema2, StepFailedEventSchema2, StepRetryingEventSchema2, StepStartedEventSchema2, StepCreatedEventSchema2, HookCreatedEventSchema2, HookReceivedEventSchema2, HookDisposedEventSchema2, HookConflictEventSchema2, WaitCreatedEventSchema2, WaitCompletedEventSchema2, AttributeWriterSchema2, AttrSetEventSchema2, RunCreatedEventSchema2, RunStartedEventSchema2, RunCompletedEventSchema2, RunFailedEventSchema2, RunCancelledEventSchema2, CreateEventSchema2, AllEventsSchema2, EventSchema2;
14987
+ var EventTypeSchema2, RunEventTypeSchema2, RUN_EVENT_TYPES2, TerminalRunEventTypeSchema2, TERMINAL_RUN_EVENT_TYPES2, StepEventTypeSchema2, STEP_EVENT_TYPES2, TerminalStepEventTypeSchema2, TERMINAL_STEP_EVENT_TYPES2, HookLifecycleEventTypeSchema2, HOOK_LIFECYCLE_EVENT_TYPES2, HookEventRequiringExistenceTypeSchema2, HOOK_EVENTS_REQUIRING_EXISTENCE2, WaitEventTypeSchema2, WAIT_EVENT_TYPES2, ChildEntityCreationEventTypeSchema2, CHILD_ENTITY_CREATION_EVENT_TYPES2, EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE2, EVENT_DATA_REF_FIELDS2, BaseEventSchema2, stepLatencyTelemetryFields2, StepCompletedEventSchema2, StepFailedEventSchema2, StepRetryingEventSchema2, StepStartedEventSchema2, StepCreatedEventSchema2, HookCreatedEventSchema2, HookReceivedEventSchema2, HookDisposedEventSchema2, HookConflictEventSchema2, WaitCreatedEventSchema2, WaitCompletedEventSchema2, AttributeWriterSchema2, AttrSetEventSchema2, RunCreatedEventSchema2, RunStartedEventSchema2, RunCompletedEventSchema2, RunFailedEventSchema2, RunCancelledEventSchema2, CreateEventSchema2, AllEventsSchema2, EventSchema2;
14956
14988
  var init_events2 = __esm({
14957
14989
  "../world/dist/events.js"() {
14958
14990
  "use strict";
14959
14991
  init_zod2();
14960
14992
  init_attributes2();
14961
14993
  init_serialization3();
14962
- EVENT_DATA_REF_FIELDS = {
14963
- run_created: ["input"],
14964
- run_completed: ["output"],
14965
- run_failed: ["error"],
14966
- step_created: ["input"],
14967
- step_completed: ["result"],
14968
- step_failed: ["error"],
14969
- step_retrying: ["error"],
14970
- hook_created: ["metadata"],
14971
- hook_received: ["payload"]
14972
- };
14973
- __name(stripEventDataRefs, "stripEventDataRefs");
14974
14994
  EventTypeSchema2 = external_exports2.enum([
14975
14995
  // Run lifecycle events
14976
14996
  "run_created",
@@ -14996,6 +15016,15 @@ var init_events2 = __esm({
14996
15016
  "wait_created",
14997
15017
  "wait_completed"
14998
15018
  ]);
15019
+ RunEventTypeSchema2 = EventTypeSchema2.extract([
15020
+ "run_created",
15021
+ "run_started",
15022
+ "run_completed",
15023
+ "run_failed",
15024
+ "run_cancelled"
15025
+ ]);
15026
+ RUN_EVENT_TYPES2 = RunEventTypeSchema2.options;
15027
+ __name(isRunEventType, "isRunEventType");
14999
15028
  TerminalRunEventTypeSchema2 = EventTypeSchema2.extract([
15000
15029
  "run_completed",
15001
15030
  "run_failed",
@@ -15003,6 +15032,64 @@ var init_events2 = __esm({
15003
15032
  ]);
15004
15033
  TERMINAL_RUN_EVENT_TYPES2 = TerminalRunEventTypeSchema2.options;
15005
15034
  __name(isTerminalRunEventType, "isTerminalRunEventType");
15035
+ StepEventTypeSchema2 = EventTypeSchema2.extract([
15036
+ "step_created",
15037
+ "step_completed",
15038
+ "step_failed",
15039
+ "step_retrying",
15040
+ "step_started"
15041
+ ]);
15042
+ STEP_EVENT_TYPES2 = StepEventTypeSchema2.options;
15043
+ __name(isStepEventType, "isStepEventType");
15044
+ TerminalStepEventTypeSchema2 = EventTypeSchema2.extract([
15045
+ "step_completed",
15046
+ "step_failed"
15047
+ ]);
15048
+ TERMINAL_STEP_EVENT_TYPES2 = TerminalStepEventTypeSchema2.options;
15049
+ __name(isTerminalStepEventType, "isTerminalStepEventType");
15050
+ HookLifecycleEventTypeSchema2 = EventTypeSchema2.extract([
15051
+ "hook_created",
15052
+ "hook_received",
15053
+ "hook_disposed"
15054
+ ]);
15055
+ HOOK_LIFECYCLE_EVENT_TYPES2 = HookLifecycleEventTypeSchema2.options;
15056
+ __name(isHookLifecycleEventType, "isHookLifecycleEventType");
15057
+ HookEventRequiringExistenceTypeSchema2 = EventTypeSchema2.extract([
15058
+ "hook_disposed",
15059
+ "hook_received"
15060
+ ]);
15061
+ HOOK_EVENTS_REQUIRING_EXISTENCE2 = HookEventRequiringExistenceTypeSchema2.options;
15062
+ __name(isHookEventRequiringExistence, "isHookEventRequiringExistence");
15063
+ WaitEventTypeSchema2 = EventTypeSchema2.extract([
15064
+ "wait_created",
15065
+ "wait_completed"
15066
+ ]);
15067
+ WAIT_EVENT_TYPES2 = WaitEventTypeSchema2.options;
15068
+ __name(isWaitEventType, "isWaitEventType");
15069
+ ChildEntityCreationEventTypeSchema2 = EventTypeSchema2.extract([
15070
+ "step_created",
15071
+ "hook_created",
15072
+ "wait_created"
15073
+ ]);
15074
+ CHILD_ENTITY_CREATION_EVENT_TYPES2 = ChildEntityCreationEventTypeSchema2.options;
15075
+ __name(isChildEntityCreationEventType, "isChildEntityCreationEventType");
15076
+ EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE2 = {
15077
+ run_created: "input",
15078
+ run_started: "input",
15079
+ run_completed: "output",
15080
+ run_failed: "error",
15081
+ step_created: "input",
15082
+ step_started: "input",
15083
+ step_completed: "result",
15084
+ step_failed: "error",
15085
+ step_retrying: "error",
15086
+ hook_created: "metadata",
15087
+ hook_received: "payload"
15088
+ };
15089
+ EVENT_DATA_REF_FIELDS2 = Object.fromEntries(Object.entries(EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE2).map(([eventType, field]) => [eventType, [field]]));
15090
+ __name(getEventDataRefFields, "getEventDataRefFields");
15091
+ __name(getEventDataPayloadField, "getEventDataPayloadField");
15092
+ __name(stripEventDataRefs, "stripEventDataRefs");
15006
15093
  BaseEventSchema2 = external_exports2.object({
15007
15094
  eventType: EventTypeSchema2,
15008
15095
  correlationId: external_exports2.string().optional(),
@@ -15019,6 +15106,10 @@ var init_events2 = __esm({
15019
15106
  // two steps ran back-to-back (the previous event-log entry is a
15020
15107
  // step_completed/step_failed).
15021
15108
  stso: external_exports2.number().optional(),
15109
+ // Progress counters taken when the STSO gap began. Only present alongside
15110
+ // stso.
15111
+ stepCount: external_exports2.number().int().positive().optional(),
15112
+ eventCount: external_exports2.number().int().positive().optional(),
15022
15113
  // Names of the runtime's optional startup-latency optimizations that were
15023
15114
  // active for this measurement (e.g. 'turbo', 'lazyStepStart',
15024
15115
  // 'optimisticStart'), so latency metrics can be segmented by them.
@@ -15070,7 +15161,20 @@ var init_events2 = __esm({
15070
15161
  workflowName: external_exports2.string().optional(),
15071
15162
  // Lazy-start: the dehydrated step input, present only when this
15072
15163
  // step_started is also responsible for creating the step.
15073
- input: SerializedDataSchema2.optional()
15164
+ input: SerializedDataSchema2.optional(),
15165
+ // Inline step ownership: the queue message ID of the invocation whose
15166
+ // handler is executing this step's body inline. Stamped on the lazy
15167
+ // step_started (and re-stamped on an owner-recovery bare start) so
15168
+ // that a wake replay can tell "this attempt is in flight in a live
15169
+ // invocation" apart from "this attempt died with its process" — the
15170
+ // owner's queue message doubles as the liveness lease (a crash means
15171
+ // the queue redelivers that same messageId, which is allowed to
15172
+ // re-execute). Ownership derives from the step's LATEST step_started:
15173
+ // an unstamped bare start (a retry attempt driven by a queued step
15174
+ // message) clears it. Absent on eager steps and from older runtimes.
15175
+ // Requires the queue's messageId to be stable across redeliveries of
15176
+ // one message (see the Queue.createQueueHandler meta contract).
15177
+ ownerMessageId: external_exports2.string().optional()
15074
15178
  }).optional()
15075
15179
  });
15076
15180
  StepCreatedEventSchema2 = BaseEventSchema2.extend({
@@ -15253,6 +15357,7 @@ var init_events2 = __esm({
15253
15357
  occurredAt: external_exports2.coerce.date().optional(),
15254
15358
  specVersion: external_exports2.number().optional()
15255
15359
  }));
15360
+ __name(isChildEntityCreationEvent, "isChildEntityCreationEvent");
15256
15361
  }
15257
15362
  });
15258
15363
 
@@ -16040,13 +16145,14 @@ function validateUlidTimestamp(prefixedUlid, prefix, pastThresholdMs = DEFAULT_T
16040
16145
  const thresholdSeconds = Math.round(thresholdMs / 1e3);
16041
16146
  return `Invalid runId timestamp: embedded timestamp is ${driftSeconds}s in the ${direction} (threshold: ${thresholdSeconds}s)`;
16042
16147
  }
16043
- var UlidSchema2, DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS2, DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS2, DEFAULT_TIMESTAMP_THRESHOLD_MS;
16148
+ var UlidSchema2, workflowRunIdSchema2, DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS2, DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS2, DEFAULT_TIMESTAMP_THRESHOLD_MS;
16044
16149
  var init_ulid2 = __esm({
16045
16150
  "../world/dist/ulid.js"() {
16046
16151
  "use strict";
16047
16152
  init_node2();
16048
16153
  init_zod2();
16049
16154
  UlidSchema2 = external_exports2.string().ulid();
16155
+ workflowRunIdSchema2 = external_exports2.templateLiteral(["wrun_", external_exports2.ulid()]);
16050
16156
  DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS2 = 24 * 60 * 60 * 1e3;
16051
16157
  DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS2 = 5 * 60 * 1e3;
16052
16158
  DEFAULT_TIMESTAMP_THRESHOLD_MS = DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS2;
@@ -16070,13 +16176,17 @@ __export(dist_exports, {
16070
16176
  AttributeChangesSchema: () => AttributeChangesSchema2,
16071
16177
  AttributeValidationError: () => AttributeValidationError2,
16072
16178
  BaseEventSchema: () => BaseEventSchema2,
16179
+ CHILD_ENTITY_CREATION_EVENT_TYPES: () => CHILD_ENTITY_CREATION_EVENT_TYPES2,
16073
16180
  CreateEventSchema: () => CreateEventSchema2,
16074
16181
  DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS: () => DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS2,
16075
16182
  DEFAULT_TIMESTAMP_THRESHOLD_MS: () => DEFAULT_TIMESTAMP_THRESHOLD_MS,
16076
16183
  DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS: () => DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS2,
16077
- EVENT_DATA_REF_FIELDS: () => EVENT_DATA_REF_FIELDS,
16184
+ EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE: () => EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE2,
16185
+ EVENT_DATA_REF_FIELDS: () => EVENT_DATA_REF_FIELDS2,
16078
16186
  EventSchema: () => EventSchema2,
16079
16187
  EventTypeSchema: () => EventTypeSchema2,
16188
+ HOOK_EVENTS_REQUIRING_EXISTENCE: () => HOOK_EVENTS_REQUIRING_EXISTENCE2,
16189
+ HOOK_LIFECYCLE_EVENT_TYPES: () => HOOK_LIFECYCLE_EVENT_TYPES2,
16080
16190
  HealthCheckPayloadSchema: () => HealthCheckPayloadSchema2,
16081
16191
  HookCreatedEventSchema: () => HookCreatedEventSchema2,
16082
16192
  HookSchema: () => HookSchema2,
@@ -16086,6 +16196,7 @@ __export(dist_exports, {
16086
16196
  QueuePayloadSchema: () => QueuePayloadSchema2,
16087
16197
  QueuePrefix: () => QueuePrefix2,
16088
16198
  RESERVED_ATTRIBUTE_KEY_PREFIX: () => RESERVED_ATTRIBUTE_KEY_PREFIX2,
16199
+ RUN_EVENT_TYPES: () => RUN_EVENT_TYPES2,
16089
16200
  RunInputSchema: () => RunInputSchema2,
16090
16201
  SPEC_VERSION_CURRENT: () => SPEC_VERSION_CURRENT2,
16091
16202
  SPEC_VERSION_LEGACY: () => SPEC_VERSION_LEGACY2,
@@ -16093,18 +16204,21 @@ __export(dist_exports, {
16093
16204
  SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT: () => SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT2,
16094
16205
  SPEC_VERSION_SUPPORTS_COMPRESSION: () => SPEC_VERSION_SUPPORTS_COMPRESSION2,
16095
16206
  SPEC_VERSION_SUPPORTS_EVENT_SOURCING: () => SPEC_VERSION_SUPPORTS_EVENT_SOURCING,
16207
+ STEP_EVENT_TYPES: () => STEP_EVENT_TYPES2,
16096
16208
  SerializedDataSchema: () => SerializedDataSchema2,
16097
16209
  StepInvokePayloadSchema: () => StepInvokePayloadSchema2,
16098
16210
  StepSchema: () => StepSchema2,
16099
16211
  StepStatusSchema: () => StepStatusSchema2,
16100
16212
  StructuredErrorSchema: () => StructuredErrorSchema2,
16101
16213
  TERMINAL_RUN_EVENT_TYPES: () => TERMINAL_RUN_EVENT_TYPES2,
16214
+ TERMINAL_STEP_EVENT_TYPES: () => TERMINAL_STEP_EVENT_TYPES2,
16102
16215
  TERMINAL_STEP_STATUSES: () => TERMINAL_STEP_STATUSES2,
16103
16216
  TERMINAL_WORKFLOW_RUN_STATUSES: () => TERMINAL_WORKFLOW_RUN_STATUSES2,
16104
16217
  TerminalRunEventTypeSchema: () => TerminalRunEventTypeSchema2,
16105
16218
  TerminalStepStatusSchema: () => TerminalStepStatusSchema2,
16106
16219
  TerminalWorkflowRunStatusSchema: () => TerminalWorkflowRunStatusSchema2,
16107
16220
  ValidQueueName: () => ValidQueueName2,
16221
+ WAIT_EVENT_TYPES: () => WAIT_EVENT_TYPES2,
16108
16222
  WaitSchema: () => WaitSchema2,
16109
16223
  WaitStatusSchema: () => WaitStatusSchema2,
16110
16224
  WorkflowInvokePayloadSchema: () => WorkflowInvokePayloadSchema2,
@@ -16114,12 +16228,22 @@ __export(dist_exports, {
16114
16228
  _resetEnvWarnCacheForTests: () => _resetEnvWarnCacheForTests,
16115
16229
  applyAttributeChanges: () => applyAttributeChanges,
16116
16230
  envNumber: () => envNumber2,
16231
+ getEventDataPayloadField: () => getEventDataPayloadField,
16232
+ getEventDataRefFields: () => getEventDataRefFields,
16117
16233
  getQueuePrefixKind: () => getQueuePrefixKind,
16118
16234
  getQueueTopicPrefix: () => getQueueTopicPrefix2,
16235
+ isChildEntityCreationEvent: () => isChildEntityCreationEvent,
16236
+ isChildEntityCreationEventType: () => isChildEntityCreationEventType,
16237
+ isHookEventRequiringExistence: () => isHookEventRequiringExistence,
16238
+ isHookLifecycleEventType: () => isHookLifecycleEventType,
16119
16239
  isLegacySpecVersion: () => isLegacySpecVersion2,
16240
+ isRunEventType: () => isRunEventType,
16241
+ isStepEventType: () => isStepEventType,
16120
16242
  isTerminalRunEventType: () => isTerminalRunEventType,
16243
+ isTerminalStepEventType: () => isTerminalStepEventType,
16121
16244
  isTerminalStepStatus: () => isTerminalStepStatus,
16122
16245
  isTerminalWorkflowRunStatus: () => isTerminalWorkflowRunStatus,
16246
+ isWaitEventType: () => isWaitEventType,
16123
16247
  parseQueueName: () => parseQueueName,
16124
16248
  reenqueueActiveRuns: () => reenqueueActiveRuns,
16125
16249
  requiresNewerWorld: () => requiresNewerWorld,
@@ -16129,7 +16253,8 @@ __export(dist_exports, {
16129
16253
  validateAttributeChanges: () => validateAttributeChanges2,
16130
16254
  validateAttributeKey: () => validateAttributeKey2,
16131
16255
  validateAttributeValue: () => validateAttributeValue2,
16132
- validateUlidTimestamp: () => validateUlidTimestamp
16256
+ validateUlidTimestamp: () => validateUlidTimestamp,
16257
+ workflowRunIdSchema: () => workflowRunIdSchema2
16133
16258
  });
16134
16259
  var init_dist5 = __esm({
16135
16260
  "../world/dist/index.js"() {
@@ -45012,7 +45137,7 @@ var init_log_format2 = __esm({
45012
45137
  function SemanticConvention3(...names) {
45013
45138
  return (value) => Object.fromEntries(names.map((name) => [name, value]));
45014
45139
  }
45015
- var WorkflowName2, WorkflowOperation2, WorkflowRunId3, WorkflowRunStatus2, WorkflowStartedAt2, WorkflowEventsCount2, WorkflowArgumentsCount2, WorkflowResultType2, WorkflowTracePropagated2, WorkflowTraceMode2, WorkflowTurbo2, WorkflowErrorName2, WorkflowErrorMessage2, WorkflowErrorCode2, WorkflowStepsCreated2, WorkflowHooksCreated2, WorkflowWaitsCreated2, WorkflowRouteType2, WorkflowRouteHandlerCached2, WorkflowRouteInvocationCount2, WorkflowRouteEntrypointAgeMs2, WorkflowRouteModuleBodyInitMs2, StepName2, StepId3, StepAttempt2, StepStatus2, StepMaxRetries2, StepTracePropagated2, StepTtfsMs2, StepStsoMs2, StepLatencyOptimizations2, StepSkipped2, StepSkipReason2, StepArgumentsCount2, StepResultType2, StepErrorName2, StepErrorMessage2, StepFatalError2, StepRetryExhausted2, StepRetryTimeoutSeconds2, StepRetryWillRetry2, MessagingSystem2, MessagingDestinationName2, MessagingMessageId2, MessagingOperationType2, QueueOverheadMs2, DeploymentId2, HookToken2, HookId2, HookFound2, WebhookHandlersTriggered2, WorkflowSuspensionState2, WorkflowSuspensionHookCount2, WorkflowSuspensionStepCount2, WorkflowSuspensionWaitCount2, HttpRequestMethod2, HttpRoute2, UrlFull2, ServerAddress2, ServerPort2, HttpResponseStatusCode2, ErrorType2, WorldParseFormat2, WorkflowEventsPagesLoaded2, QueueDeserializeTimeMs2, QueueExecutionTimeMs2, QueueSerializeTimeMs2, SerializationOperation2, SerializationCompressed2, SerializationCodec2, SerializationUncompressedBytes2, SerializationStoredBytes2, SerializationCompressionRatio2, PeerService3, RpcSystem3, RpcService3, RpcMethod3, ErrorRetryable2, ErrorCategory2;
45140
+ var WorkflowName2, WorkflowOperation2, WorkflowRunId3, WorkflowRunStatus2, WorkflowStartedAt2, WorkflowEventsCount2, WorkflowArgumentsCount2, WorkflowResultType2, WorkflowTracePropagated2, WorkflowTraceMode2, WorkflowTurbo2, WorkflowErrorName2, WorkflowErrorMessage2, WorkflowErrorCode2, WorkflowStepsCreated2, WorkflowHooksCreated2, WorkflowWaitsCreated2, WorkflowOwnedRecoverySteps2, WorkflowBackstopWakesArmed2, WorkflowRouteType2, WorkflowRouteHandlerCached2, WorkflowRouteInvocationCount2, WorkflowRouteEntrypointAgeMs2, WorkflowRouteModuleBodyInitMs2, StepName2, StepId3, StepAttempt2, StepStatus2, StepMaxRetries2, StepTracePropagated2, StepTtfsMs2, StepStsoMs2, StepLatencyOptimizations2, StepSkipped2, StepSkipReason2, StepArgumentsCount2, StepResultType2, StepErrorName2, StepErrorMessage2, StepFatalError2, StepRetryExhausted2, StepRetryTimeoutSeconds2, StepRetryWillRetry2, MessagingSystem2, MessagingDestinationName2, MessagingMessageId2, MessagingOperationType2, QueueOverheadMs2, DeploymentId2, HookToken2, HookId2, HookFound2, WebhookHandlersTriggered2, WorkflowSuspensionState2, WorkflowSuspensionHookCount2, WorkflowSuspensionStepCount2, WorkflowSuspensionWaitCount2, HttpRequestMethod2, HttpRoute2, UrlFull2, ServerAddress2, ServerPort2, HttpResponseStatusCode2, ErrorType2, WorldParseFormat2, WorkflowEventsPagesLoaded2, QueueDeserializeTimeMs2, QueueExecutionTimeMs2, QueueSerializeTimeMs2, SerializationOperation2, SerializationCompressed2, SerializationCodec2, SerializationUncompressedBytes2, SerializationStoredBytes2, SerializationCompressionRatio2, PeerService3, RpcSystem3, RpcService3, RpcMethod3, ErrorRetryable2, ErrorCategory2;
45016
45141
  var init_semantic_conventions2 = __esm({
45017
45142
  "../core/dist/telemetry/semantic-conventions.js"() {
45018
45143
  "use strict";
@@ -45034,6 +45159,8 @@ var init_semantic_conventions2 = __esm({
45034
45159
  WorkflowStepsCreated2 = SemanticConvention3("workflow.steps.created");
45035
45160
  WorkflowHooksCreated2 = SemanticConvention3("workflow.hooks.created");
45036
45161
  WorkflowWaitsCreated2 = SemanticConvention3("workflow.waits.created");
45162
+ WorkflowOwnedRecoverySteps2 = SemanticConvention3("workflow.inline_ownership.owned_recovery_steps");
45163
+ WorkflowBackstopWakesArmed2 = SemanticConvention3("workflow.inline_ownership.backstop_wakes_armed");
45037
45164
  WorkflowRouteType2 = SemanticConvention3("workflow.route.type");
45038
45165
  WorkflowRouteHandlerCached2 = SemanticConvention3("workflow.route.handler_cached");
45039
45166
  WorkflowRouteInvocationCount2 = SemanticConvention3("workflow.route.invocation_count");
@@ -45174,6 +45301,12 @@ async function trace4(spanName, ...args) {
45174
45301
  }
45175
45302
  });
45176
45303
  }
45304
+ async function recordElapsedSpan2(spanName, startEpochMs, opts) {
45305
+ const tracer = await Tracer2.value;
45306
+ if (!tracer)
45307
+ return;
45308
+ tracer.startSpan(spanName, { ...opts, startTime: startEpochMs }).end();
45309
+ }
45177
45310
  function applyWorkflowSuspensionToSpan2(error95, otel, span) {
45178
45311
  if (!error95 || !WorkflowSuspension2.is(error95)) {
45179
45312
  return;
@@ -45198,7 +45331,7 @@ async function getSpanContextForTraceCarrier2(carrier) {
45198
45331
  async function getActiveSpan3() {
45199
45332
  return await withOtel2((otel) => otel.trace.getActiveSpan());
45200
45333
  }
45201
- async function getSpanKind2(field) {
45334
+ async function getSpanKind3(field) {
45202
45335
  return withOtel2((x) => x.SpanKind[field]);
45203
45336
  }
45204
45337
  async function withOtel2(fn) {
@@ -45270,10 +45403,11 @@ var init_telemetry2 = __esm({
45270
45403
  return api.trace.getTracer("workflow");
45271
45404
  });
45272
45405
  __name(trace4, "trace");
45406
+ __name(recordElapsedSpan2, "recordElapsedSpan");
45273
45407
  __name(applyWorkflowSuspensionToSpan2, "applyWorkflowSuspensionToSpan");
45274
45408
  __name(getSpanContextForTraceCarrier2, "getSpanContextForTraceCarrier");
45275
45409
  __name(getActiveSpan3, "getActiveSpan");
45276
- __name(getSpanKind2, "getSpanKind");
45410
+ __name(getSpanKind3, "getSpanKind");
45277
45411
  __name(withOtel2, "withOtel");
45278
45412
  __name(linkToCurrentContext, "linkToCurrentContext");
45279
45413
  __name(linkToTraceCarrier2, "linkToTraceCarrier");
@@ -45440,7 +45574,7 @@ var version4;
45440
45574
  var init_version3 = __esm({
45441
45575
  "../core/dist/version.js"() {
45442
45576
  "use strict";
45443
- version4 = "5.0.0-beta.29";
45577
+ version4 = "5.0.0-beta.30";
45444
45578
  }
45445
45579
  });
45446
45580
 
@@ -45656,7 +45790,7 @@ async function queueMessage(world, ...args) {
45656
45790
  ...RpcService3("vqs"),
45657
45791
  ...RpcMethod3("publish")
45658
45792
  },
45659
- kind: await getSpanKind2("PRODUCER")
45793
+ kind: await getSpanKind3("PRODUCER")
45660
45794
  }, async (span) => {
45661
45795
  const { messageId } = await world.queue(...args);
45662
45796
  if (messageId) {
@@ -51585,6 +51719,20 @@ function getByteUnframingStream2() {
51585
51719
  }
51586
51720
  });
51587
51721
  }
51722
+ function recordReadTimeToFirstChunk2(startEpochMs, runId, name, startIndex) {
51723
+ void (async () => {
51724
+ await recordElapsedSpan2("workflow.stream.read", startEpochMs, {
51725
+ kind: await getSpanKind3("CLIENT"),
51726
+ attributes: {
51727
+ "workflow.run.id": runId,
51728
+ "workflow.stream.name": name,
51729
+ "workflow.stream.operation": "read",
51730
+ "workflow.stream.read.ttfc_ms": Date.now() - startEpochMs,
51731
+ ...typeof startIndex === "number" ? { "workflow.stream.start_index": startIndex } : {}
51732
+ }
51733
+ });
51734
+ })();
51735
+ }
51588
51736
  function createReconnectingFramedStream2(runId, name, startIndex) {
51589
51737
  const reconnectSupported = startIndex === void 0 || startIndex >= 0;
51590
51738
  let currentStartIndex = startIndex ?? 0;
@@ -52775,6 +52923,7 @@ var init_serialization4 = __esm({
52775
52923
  MAX_FRAME_SIZE2 = 1e8;
52776
52924
  __name(getByteFramingStream2, "getByteFramingStream");
52777
52925
  __name(getByteUnframingStream2, "getByteUnframingStream");
52926
+ __name(recordReadTimeToFirstChunk2, "recordReadTimeToFirstChunk");
52778
52927
  WorkflowServerReadableStream2 = class extends ReadableStream {
52779
52928
  static {
52780
52929
  __name(this, "WorkflowServerReadableStream");
@@ -52784,12 +52933,16 @@ var init_serialization4 = __esm({
52784
52933
  if (typeof name !== "string" || name.length === 0) {
52785
52934
  throw new WorkflowRuntimeError2(`"name" is required, got "${name}"`);
52786
52935
  }
52936
+ let readStart;
52937
+ let firstChunkReported = false;
52787
52938
  super({
52788
52939
  // @ts-expect-error Not sure why TypeScript is complaining about this
52789
52940
  type: "bytes",
52790
52941
  pull: /* @__PURE__ */ __name(async (controller) => {
52791
52942
  let reader = this.#reader;
52792
52943
  if (!reader) {
52944
+ if (readStart === void 0)
52945
+ readStart = Date.now();
52793
52946
  const world = await getWorldLazy2();
52794
52947
  const stream = await world.streams.get(runId, name, startIndex);
52795
52948
  reader = this.#reader = stream.getReader();
@@ -52803,6 +52956,10 @@ var init_serialization4 = __esm({
52803
52956
  this.#reader = void 0;
52804
52957
  controller.close();
52805
52958
  } else {
52959
+ if (!firstChunkReported && result.value.byteLength > 0 && readStart !== void 0) {
52960
+ firstChunkReported = true;
52961
+ recordReadTimeToFirstChunk2(readStart, runId, name, startIndex);
52962
+ }
52806
52963
  controller.enqueue(result.value);
52807
52964
  }
52808
52965
  }, "pull"),
@@ -70902,8 +71059,24 @@ var init_serialization = __esm2({
70902
71059
  }
70903
71060
  });
70904
71061
  var EventTypeSchema;
71062
+ var RunEventTypeSchema;
71063
+ var RUN_EVENT_TYPES;
70905
71064
  var TerminalRunEventTypeSchema;
70906
71065
  var TERMINAL_RUN_EVENT_TYPES;
71066
+ var StepEventTypeSchema;
71067
+ var STEP_EVENT_TYPES;
71068
+ var TerminalStepEventTypeSchema;
71069
+ var TERMINAL_STEP_EVENT_TYPES;
71070
+ var HookLifecycleEventTypeSchema;
71071
+ var HOOK_LIFECYCLE_EVENT_TYPES;
71072
+ var HookEventRequiringExistenceTypeSchema;
71073
+ var HOOK_EVENTS_REQUIRING_EXISTENCE;
71074
+ var WaitEventTypeSchema;
71075
+ var WAIT_EVENT_TYPES;
71076
+ var ChildEntityCreationEventTypeSchema;
71077
+ var CHILD_ENTITY_CREATION_EVENT_TYPES;
71078
+ var EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE;
71079
+ var EVENT_DATA_REF_FIELDS;
70907
71080
  var BaseEventSchema;
70908
71081
  var stepLatencyTelemetryFields;
70909
71082
  var StepCompletedEventSchema;
@@ -70957,12 +71130,74 @@ var init_events = __esm2({
70957
71130
  "wait_created",
70958
71131
  "wait_completed"
70959
71132
  ]);
71133
+ RunEventTypeSchema = EventTypeSchema.extract([
71134
+ "run_created",
71135
+ "run_started",
71136
+ "run_completed",
71137
+ "run_failed",
71138
+ "run_cancelled"
71139
+ ]);
71140
+ RUN_EVENT_TYPES = RunEventTypeSchema.options;
70960
71141
  TerminalRunEventTypeSchema = EventTypeSchema.extract([
70961
71142
  "run_completed",
70962
71143
  "run_failed",
70963
71144
  "run_cancelled"
70964
71145
  ]);
70965
71146
  TERMINAL_RUN_EVENT_TYPES = TerminalRunEventTypeSchema.options;
71147
+ StepEventTypeSchema = EventTypeSchema.extract([
71148
+ "step_created",
71149
+ "step_completed",
71150
+ "step_failed",
71151
+ "step_retrying",
71152
+ "step_started"
71153
+ ]);
71154
+ STEP_EVENT_TYPES = StepEventTypeSchema.options;
71155
+ TerminalStepEventTypeSchema = EventTypeSchema.extract([
71156
+ "step_completed",
71157
+ "step_failed"
71158
+ ]);
71159
+ TERMINAL_STEP_EVENT_TYPES = TerminalStepEventTypeSchema.options;
71160
+ HookLifecycleEventTypeSchema = EventTypeSchema.extract([
71161
+ "hook_created",
71162
+ "hook_received",
71163
+ "hook_disposed"
71164
+ ]);
71165
+ HOOK_LIFECYCLE_EVENT_TYPES = HookLifecycleEventTypeSchema.options;
71166
+ HookEventRequiringExistenceTypeSchema = EventTypeSchema.extract([
71167
+ "hook_disposed",
71168
+ "hook_received"
71169
+ ]);
71170
+ HOOK_EVENTS_REQUIRING_EXISTENCE = HookEventRequiringExistenceTypeSchema.options;
71171
+ WaitEventTypeSchema = EventTypeSchema.extract([
71172
+ "wait_created",
71173
+ "wait_completed"
71174
+ ]);
71175
+ WAIT_EVENT_TYPES = WaitEventTypeSchema.options;
71176
+ ChildEntityCreationEventTypeSchema = EventTypeSchema.extract([
71177
+ "step_created",
71178
+ "hook_created",
71179
+ "wait_created"
71180
+ ]);
71181
+ CHILD_ENTITY_CREATION_EVENT_TYPES = ChildEntityCreationEventTypeSchema.options;
71182
+ EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE = {
71183
+ run_created: "input",
71184
+ run_started: "input",
71185
+ run_completed: "output",
71186
+ run_failed: "error",
71187
+ step_created: "input",
71188
+ step_started: "input",
71189
+ step_completed: "result",
71190
+ step_failed: "error",
71191
+ step_retrying: "error",
71192
+ hook_created: "metadata",
71193
+ hook_received: "payload"
71194
+ };
71195
+ EVENT_DATA_REF_FIELDS = Object.fromEntries(Object.entries(EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE).map(([eventType, field]) => [
71196
+ eventType,
71197
+ [
71198
+ field
71199
+ ]
71200
+ ]));
70966
71201
  BaseEventSchema = external_exports.object({
70967
71202
  eventType: EventTypeSchema,
70968
71203
  correlationId: external_exports.string().optional(),
@@ -70979,6 +71214,10 @@ var init_events = __esm2({
70979
71214
  // two steps ran back-to-back (the previous event-log entry is a
70980
71215
  // step_completed/step_failed).
70981
71216
  stso: external_exports.number().optional(),
71217
+ // Progress counters taken when the STSO gap began. Only present alongside
71218
+ // stso.
71219
+ stepCount: external_exports.number().int().positive().optional(),
71220
+ eventCount: external_exports.number().int().positive().optional(),
70982
71221
  // Names of the runtime's optional startup-latency optimizations that were
70983
71222
  // active for this measurement (e.g. 'turbo', 'lazyStepStart',
70984
71223
  // 'optimisticStart'), so latency metrics can be segmented by them.
@@ -71030,7 +71269,20 @@ var init_events = __esm2({
71030
71269
  workflowName: external_exports.string().optional(),
71031
71270
  // Lazy-start: the dehydrated step input, present only when this
71032
71271
  // step_started is also responsible for creating the step.
71033
- input: SerializedDataSchema.optional()
71272
+ input: SerializedDataSchema.optional(),
71273
+ // Inline step ownership: the queue message ID of the invocation whose
71274
+ // handler is executing this step's body inline. Stamped on the lazy
71275
+ // step_started (and re-stamped on an owner-recovery bare start) so
71276
+ // that a wake replay can tell "this attempt is in flight in a live
71277
+ // invocation" apart from "this attempt died with its process" — the
71278
+ // owner's queue message doubles as the liveness lease (a crash means
71279
+ // the queue redelivers that same messageId, which is allowed to
71280
+ // re-execute). Ownership derives from the step's LATEST step_started:
71281
+ // an unstamped bare start (a retry attempt driven by a queued step
71282
+ // message) clears it. Absent on eager steps and from older runtimes.
71283
+ // Requires the queue's messageId to be stable across redeliveries of
71284
+ // one message (see the Queue.createQueueHandler meta contract).
71285
+ ownerMessageId: external_exports.string().optional()
71034
71286
  }).optional()
71035
71287
  });
71036
71288
  StepCreatedEventSchema = BaseEventSchema.extend({
@@ -71915,6 +72167,7 @@ var init_node = __esm2({
71915
72167
  }
71916
72168
  });
71917
72169
  var UlidSchema;
72170
+ var workflowRunIdSchema;
71918
72171
  var DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS;
71919
72172
  var DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS;
71920
72173
  var init_ulid = __esm2({
@@ -71922,6 +72175,10 @@ var init_ulid = __esm2({
71922
72175
  "use strict";
71923
72176
  init_zod();
71924
72177
  UlidSchema = external_exports.string().ulid();
72178
+ workflowRunIdSchema = external_exports.templateLiteral([
72179
+ "wrun_",
72180
+ external_exports.ulid()
72181
+ ]);
71925
72182
  DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS = 24 * 60 * 60 * 1e3;
71926
72183
  DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS = 5 * 60 * 1e3;
71927
72184
  }
@@ -74267,6 +74524,8 @@ var WorkflowErrorCode;
74267
74524
  var WorkflowStepsCreated;
74268
74525
  var WorkflowHooksCreated;
74269
74526
  var WorkflowWaitsCreated;
74527
+ var WorkflowOwnedRecoverySteps;
74528
+ var WorkflowBackstopWakesArmed;
74270
74529
  var WorkflowRouteType;
74271
74530
  var WorkflowRouteHandlerCached;
74272
74531
  var WorkflowRouteInvocationCount;
@@ -74350,6 +74609,8 @@ var init_semantic_conventions = __esm2({
74350
74609
  WorkflowStepsCreated = SemanticConvention("workflow.steps.created");
74351
74610
  WorkflowHooksCreated = SemanticConvention("workflow.hooks.created");
74352
74611
  WorkflowWaitsCreated = SemanticConvention("workflow.waits.created");
74612
+ WorkflowOwnedRecoverySteps = SemanticConvention("workflow.inline_ownership.owned_recovery_steps");
74613
+ WorkflowBackstopWakesArmed = SemanticConvention("workflow.inline_ownership.backstop_wakes_armed");
74353
74614
  WorkflowRouteType = SemanticConvention("workflow.route.type");
74354
74615
  WorkflowRouteHandlerCached = SemanticConvention("workflow.route.handler_cached");
74355
74616
  WorkflowRouteInvocationCount = SemanticConvention("workflow.route.invocation_count");
@@ -76462,6 +76723,15 @@ async function trace(spanName, ...args) {
76462
76723
  });
76463
76724
  }
76464
76725
  __name(trace, "trace");
76726
+ async function recordElapsedSpan(spanName, startEpochMs, opts) {
76727
+ const tracer = await Tracer.value;
76728
+ if (!tracer) return;
76729
+ tracer.startSpan(spanName, {
76730
+ ...opts,
76731
+ startTime: startEpochMs
76732
+ }).end();
76733
+ }
76734
+ __name(recordElapsedSpan, "recordElapsedSpan");
76465
76735
  function applyWorkflowSuspensionToSpan(error482, otel, span) {
76466
76736
  if (!error482 || !WorkflowSuspension.is(error482)) {
76467
76737
  return;
@@ -76490,6 +76760,10 @@ async function getActiveSpan() {
76490
76760
  return await withOtel((otel) => otel.trace.getActiveSpan());
76491
76761
  }
76492
76762
  __name(getActiveSpan, "getActiveSpan");
76763
+ async function getSpanKind(field) {
76764
+ return withOtel((x) => x.SpanKind[field]);
76765
+ }
76766
+ __name(getSpanKind, "getSpanKind");
76493
76767
  async function withOtel(fn) {
76494
76768
  const otel = await OtelApi.value;
76495
76769
  if (!otel) return void 0;
@@ -76534,9 +76808,11 @@ var init_telemetry = __esm2({
76534
76808
  return api.trace.getTracer("workflow");
76535
76809
  });
76536
76810
  __name2(trace, "trace");
76811
+ __name2(recordElapsedSpan, "recordElapsedSpan");
76537
76812
  __name2(applyWorkflowSuspensionToSpan, "applyWorkflowSuspensionToSpan");
76538
76813
  __name2(getSpanContextForTraceCarrier, "getSpanContextForTraceCarrier");
76539
76814
  __name2(getActiveSpan, "getActiveSpan");
76815
+ __name2(getSpanKind, "getSpanKind");
76540
76816
  __name2(withOtel, "withOtel");
76541
76817
  __name2(linkToTraceCarrier, "linkToTraceCarrier");
76542
76818
  }
@@ -78844,7 +79120,7 @@ var version2;
78844
79120
  var init_version = __esm2({
78845
79121
  "../core/dist/version.js"() {
78846
79122
  "use strict";
78847
- version2 = "5.0.0-beta.29";
79123
+ version2 = "5.0.0-beta.30";
78848
79124
  }
78849
79125
  });
78850
79126
  function getWorkflowQueueName(workflowName, namespace) {
@@ -78863,6 +79139,16 @@ function generateHealthCheckRunId(correlationId) {
78863
79139
  return `wrun_hc_${correlationId}`;
78864
79140
  }
78865
79141
  __name(generateHealthCheckRunId, "generateHealthCheckRunId");
79142
+ function withDeadline(promise22, ms2) {
79143
+ let timer;
79144
+ return Promise.race([
79145
+ promise22,
79146
+ new Promise((_, reject) => {
79147
+ timer = setTimeout(() => reject(new Error(`Operation timed out after ${ms2}ms`)), ms2);
79148
+ })
79149
+ ]).finally(() => clearTimeout(timer));
79150
+ }
79151
+ __name(withDeadline, "withDeadline");
78866
79152
  async function readStreamWithTimeout(reader, readTimeout) {
78867
79153
  const chunks = [];
78868
79154
  let done = false;
@@ -78944,7 +79230,8 @@ async function healthCheck(world, endpoint, options) {
78944
79230
  });
78945
79231
  while (Date.now() - startTime < timeout) {
78946
79232
  try {
78947
- const stream = await world.streams.get(generateHealthCheckRunId(correlationId), streamName);
79233
+ const remainingMs = timeout - (Date.now() - startTime);
79234
+ const stream = await withDeadline(world.streams.get(generateHealthCheckRunId(correlationId), streamName), remainingMs);
78948
79235
  const reader = stream.getReader();
78949
79236
  const { chunks, timedOut } = await readStreamWithTimeout(reader, HEALTH_CHECK_READ_TIMEOUT);
78950
79237
  if (timedOut) {
@@ -79004,6 +79291,7 @@ var init_helpers = __esm2({
79004
79291
  __name2(generateHealthCheckRunId, "generateHealthCheckRunId");
79005
79292
  HEALTH_CHECK_POLL_INTERVAL = 100;
79006
79293
  HEALTH_CHECK_READ_TIMEOUT = 500;
79294
+ __name2(withDeadline, "withDeadline");
79007
79295
  __name2(readStreamWithTimeout, "readStreamWithTimeout");
79008
79296
  __name2(parseHealthCheckResponse, "parseHealthCheckResponse");
79009
79297
  __name2(healthCheck, "healthCheck");
@@ -80572,6 +80860,23 @@ function getByteUnframingStream() {
80572
80860
  });
80573
80861
  }
80574
80862
  __name(getByteUnframingStream, "getByteUnframingStream");
80863
+ function recordReadTimeToFirstChunk(startEpochMs, runId, name, startIndex) {
80864
+ void (async () => {
80865
+ await recordElapsedSpan("workflow.stream.read", startEpochMs, {
80866
+ kind: await getSpanKind("CLIENT"),
80867
+ attributes: {
80868
+ "workflow.run.id": runId,
80869
+ "workflow.stream.name": name,
80870
+ "workflow.stream.operation": "read",
80871
+ "workflow.stream.read.ttfc_ms": Date.now() - startEpochMs,
80872
+ ...typeof startIndex === "number" ? {
80873
+ "workflow.stream.start_index": startIndex
80874
+ } : {}
80875
+ }
80876
+ });
80877
+ })();
80878
+ }
80879
+ __name(recordReadTimeToFirstChunk, "recordReadTimeToFirstChunk");
80575
80880
  function createReconnectingFramedStream(runId, name, startIndex) {
80576
80881
  const reconnectSupported = startIndex === void 0 || startIndex >= 0;
80577
80882
  let currentStartIndex = startIndex ?? 0;
@@ -81582,6 +81887,7 @@ var init_serialization2 = __esm2({
81582
81887
  MAX_FRAME_SIZE = 1e8;
81583
81888
  __name2(getByteFramingStream, "getByteFramingStream");
81584
81889
  __name2(getByteUnframingStream, "getByteUnframingStream");
81890
+ __name2(recordReadTimeToFirstChunk, "recordReadTimeToFirstChunk");
81585
81891
  WorkflowServerReadableStream = class extends ReadableStream {
81586
81892
  static {
81587
81893
  __name(this, "WorkflowServerReadableStream");
@@ -81594,12 +81900,15 @@ var init_serialization2 = __esm2({
81594
81900
  if (typeof name !== "string" || name.length === 0) {
81595
81901
  throw new WorkflowRuntimeError(`"name" is required, got "${name}"`);
81596
81902
  }
81903
+ let readStart;
81904
+ let firstChunkReported = false;
81597
81905
  super({
81598
81906
  // @ts-expect-error Not sure why TypeScript is complaining about this
81599
81907
  type: "bytes",
81600
81908
  pull: /* @__PURE__ */ __name2(async (controller) => {
81601
81909
  let reader = this.#reader;
81602
81910
  if (!reader) {
81911
+ if (readStart === void 0) readStart = Date.now();
81603
81912
  const world = await getWorldLazy();
81604
81913
  const stream = await world.streams.get(runId, name, startIndex);
81605
81914
  reader = this.#reader = stream.getReader();
@@ -81613,6 +81922,10 @@ var init_serialization2 = __esm2({
81613
81922
  this.#reader = void 0;
81614
81923
  controller.close();
81615
81924
  } else {
81925
+ if (!firstChunkReported && result.value.byteLength > 0 && readStart !== void 0) {
81926
+ firstChunkReported = true;
81927
+ recordReadTimeToFirstChunk(readStart, runId, name, startIndex);
81928
+ }
81616
81929
  controller.enqueue(result.value);
81617
81930
  }
81618
81931
  }, "pull"),
@@ -82027,7 +82340,8 @@ async function start(workflow, argsOrOptions, options) {
82027
82340
  } else {
82028
82341
  const probe = await healthCheck(world, "workflow", {
82029
82342
  deploymentId,
82030
- timeout: CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS
82343
+ timeout: CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS,
82344
+ namespace: opts.namespace
82031
82345
  }).catch(() => void 0);
82032
82346
  const capabilities = getRunCapabilities(probe?.workflowCoreVersion);
82033
82347
  framedByteStreams = capabilities.framedByteStreams;
@@ -82063,6 +82377,9 @@ async function start(workflow, argsOrOptions, options) {
82063
82377
  allowReservedAttributes: true
82064
82378
  } : {}
82065
82379
  } : {};
82380
+ if (opts.replayedFromRunId !== void 0 && !workflowRunIdSchema.safeParse(opts.replayedFromRunId).success) {
82381
+ throw new WorkflowRuntimeError(`replayedFromRunId must be a run ID (wrun_<ulid>); received ${JSON.stringify(String(opts.replayedFromRunId).slice(0, 64))}.`);
82382
+ }
82066
82383
  const rawKey = await world.getEncryptionKeyForRun?.(runId, {
82067
82384
  ...opts,
82068
82385
  deploymentId
@@ -82075,7 +82392,10 @@ async function start(workflow, argsOrOptions, options) {
82075
82392
  workflowCoreVersion: version2,
82076
82393
  features: {
82077
82394
  encryption: !!encryptionKey
82078
- }
82395
+ },
82396
+ ...opts.replayedFromRunId ? {
82397
+ replayedFromRunId: opts.replayedFromRunId
82398
+ } : {}
82079
82399
  };
82080
82400
  const [runCreatedResult, queueResult] = await Promise.allSettled([
82081
82401
  world.events.create(runId, {
@@ -82091,7 +82411,7 @@ async function start(workflow, argsOrOptions, options) {
82091
82411
  }, {
82092
82412
  v1Compat
82093
82413
  }),
82094
- world.queue(getWorkflowQueueName(workflowName), {
82414
+ world.queue(getWorkflowQueueName(workflowName, opts.namespace), {
82095
82415
  runId,
82096
82416
  traceCarrier,
82097
82417
  ...specVersion >= SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT ? {
@@ -82161,7 +82481,7 @@ __name2(start, "start");
82161
82481
  value: "start",
82162
82482
  configurable: true
82163
82483
  });
82164
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.29//start");
82484
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.30//start");
82165
82485
  async function wakeUpRun(world, runId, options) {
82166
82486
  try {
82167
82487
  const run22 = await world.runs.get(runId, {
@@ -82220,7 +82540,7 @@ async function wakeUpRun(world, runId, options) {
82220
82540
  }
82221
82541
  }
82222
82542
  if (stoppedCount > 0) {
82223
- await world.queue(getWorkflowQueueName(run22.workflowName), {
82543
+ await world.queue(getWorkflowQueueName(run22.workflowName, options?.namespace), {
82224
82544
  runId
82225
82545
  }, {
82226
82546
  deploymentId: run22.deploymentId,
@@ -82497,7 +82817,7 @@ var Run = class _Run {
82497
82817
  value: "wakeUp",
82498
82818
  configurable: true
82499
82819
  });
82500
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#wakeUp");
82820
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#wakeUp");
82501
82821
  (function(__wf_fn, __wf_id) {
82502
82822
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82503
82823
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82506,7 +82826,7 @@ var Run = class _Run {
82506
82826
  value: "cancel",
82507
82827
  configurable: true
82508
82828
  });
82509
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#cancel");
82829
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#cancel");
82510
82830
  (function(__wf_fn, __wf_id) {
82511
82831
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82512
82832
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82515,7 +82835,7 @@ var Run = class _Run {
82515
82835
  value: "getReadable",
82516
82836
  configurable: true
82517
82837
  });
82518
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#getReadable");
82838
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#getReadable");
82519
82839
  (function(__wf_fn, __wf_id) {
82520
82840
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82521
82841
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82524,7 +82844,7 @@ var Run = class _Run {
82524
82844
  value: "exists",
82525
82845
  configurable: true
82526
82846
  });
82527
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#exists");
82847
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#exists");
82528
82848
  (function(__wf_fn, __wf_id) {
82529
82849
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82530
82850
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82533,7 +82853,7 @@ var Run = class _Run {
82533
82853
  value: "status",
82534
82854
  configurable: true
82535
82855
  });
82536
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#status");
82856
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#status");
82537
82857
  (function(__wf_fn, __wf_id) {
82538
82858
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82539
82859
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82542,7 +82862,7 @@ var Run = class _Run {
82542
82862
  value: "returnValue",
82543
82863
  configurable: true
82544
82864
  });
82545
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#returnValue");
82865
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#returnValue");
82546
82866
  (function(__wf_fn, __wf_id) {
82547
82867
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82548
82868
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82551,7 +82871,7 @@ var Run = class _Run {
82551
82871
  value: "workflowName",
82552
82872
  configurable: true
82553
82873
  });
82554
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#workflowName");
82874
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#workflowName");
82555
82875
  (function(__wf_fn, __wf_id) {
82556
82876
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82557
82877
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82560,7 +82880,7 @@ var Run = class _Run {
82560
82880
  value: "createdAt",
82561
82881
  configurable: true
82562
82882
  });
82563
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#createdAt");
82883
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#createdAt");
82564
82884
  (function(__wf_fn, __wf_id) {
82565
82885
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82566
82886
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82569,7 +82889,7 @@ var Run = class _Run {
82569
82889
  value: "startedAt",
82570
82890
  configurable: true
82571
82891
  });
82572
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#startedAt");
82892
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#startedAt");
82573
82893
  (function(__wf_fn, __wf_id) {
82574
82894
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82575
82895
  __wf_reg.set(__wf_id, __wf_fn);
@@ -82578,7 +82898,7 @@ var Run = class _Run {
82578
82898
  value: "completedAt",
82579
82899
  configurable: true
82580
82900
  });
82581
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.29//Run#completedAt");
82901
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.30//Run#completedAt");
82582
82902
  (function(__wf_cls, __wf_id) {
82583
82903
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
82584
82904
  __wf_reg.set(__wf_id, __wf_cls);
@@ -82588,7 +82908,7 @@ var Run = class _Run {
82588
82908
  enumerable: false,
82589
82909
  configurable: false
82590
82910
  });
82591
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.29//Run");
82911
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.30//Run");
82592
82912
  async function fetch2(...args) {
82593
82913
  return globalThis.fetch(...args);
82594
82914
  }
@@ -83983,13 +84303,13 @@ async function trace3(spanName, ...args) {
83983
84303
  });
83984
84304
  }
83985
84305
  __name(trace3, "trace");
83986
- async function getSpanKind(field) {
84306
+ async function getSpanKind2(field) {
83987
84307
  const otel = await getOtelApi();
83988
84308
  if (!otel)
83989
84309
  return void 0;
83990
84310
  return otel.SpanKind[field];
83991
84311
  }
83992
- __name(getSpanKind, "getSpanKind");
84312
+ __name(getSpanKind2, "getSpanKind");
83993
84313
  function SemanticConvention2(...names) {
83994
84314
  return (value) => Object.fromEntries(names.map((name) => [name, value]));
83995
84315
  }
@@ -84093,7 +84413,7 @@ function instrumentObject(prefix, o) {
84093
84413
  spanName = `${prefix}.${methodName} ${eventType}`;
84094
84414
  }
84095
84415
  }
84096
- return trace3(spanName, { kind: await getSpanKind("INTERNAL") }, async (span) => {
84416
+ return trace3(spanName, { kind: await getSpanKind2("INTERNAL") }, async (span) => {
84097
84417
  span?.setAttributes({
84098
84418
  ...PeerService2(WORLD_LOCAL_SERVICE.peerService),
84099
84419
  ...RpcSystem2(WORLD_LOCAL_SERVICE.rpcSystem),
@@ -85292,13 +85612,11 @@ function createEventsStorage(basedir, tag) {
85292
85612
  if ("correlationId" in data && typeof data.correlationId === "string") {
85293
85613
  assertSafeEntityId("correlationId", data.correlationId);
85294
85614
  }
85295
- const isStepEvent = data.eventType === "step_created" || data.eventType === "step_started" || data.eventType === "step_completed" || data.eventType === "step_failed" || data.eventType === "step_retrying";
85296
- if (isStepEvent && runId && data.correlationId) {
85615
+ if (isStepEventType(data.eventType) && runId && data.correlationId) {
85297
85616
  const lockKey = tag ? `${runId}-${data.correlationId}.${tag}` : `${runId}-${data.correlationId}`;
85298
85617
  return withInProcessLock(stepLocks, lockKey, () => createImpl());
85299
85618
  }
85300
- const isHookLifecycleEvent = data.eventType === "hook_created" || data.eventType === "hook_received" || data.eventType === "hook_disposed";
85301
- if (isHookLifecycleEvent && runId && data.correlationId) {
85619
+ if (isHookLifecycleEventType(data.eventType) && runId && data.correlationId) {
85302
85620
  const lockKey = tag ? `${runId}-${data.correlationId}.hook.${tag}` : `${runId}-${data.correlationId}.hook`;
85303
85621
  return withInProcessLock(hookLocks, lockKey, () => createImpl());
85304
85622
  }
@@ -85388,13 +85706,9 @@ function createEventsStorage(basedir, tag) {
85388
85706
  return handleLegacyEvent(basedir, effectiveRunId, data, currentRun, params);
85389
85707
  }
85390
85708
  }
85391
- const lazyStepStart = data.eventType === "step_started" && "eventData" in data && !!data.eventData && typeof data.eventData.stepName === "string" && data.eventData.input !== void 0;
85709
+ const createsChildEntity = isChildEntityCreationEvent(data);
85710
+ const lazyStepStart = createsChildEntity && data.eventType === "step_started";
85392
85711
  if (currentRun && isTerminalWorkflowRunStatus(currentRun.status)) {
85393
- const runTerminalEvents = [
85394
- "run_started",
85395
- "run_completed",
85396
- "run_failed"
85397
- ];
85398
85712
  if (data.eventType === "run_cancelled" && currentRun.status === "cancelled") {
85399
85713
  const event2 = {
85400
85714
  ...data,
@@ -85413,10 +85727,10 @@ function createEventsStorage(basedir, tag) {
85413
85727
  if (data.eventType === "run_started") {
85414
85728
  throw new RunExpiredError(`Workflow run "${effectiveRunId}" is already in terminal state "${currentRun.status}"`);
85415
85729
  }
85416
- if (runTerminalEvents.includes(data.eventType) || data.eventType === "run_cancelled") {
85730
+ if (isTerminalRunEventType(data.eventType)) {
85417
85731
  throw new EntityConflictError2(`Cannot transition run from terminal state "${currentRun.status}"`);
85418
85732
  }
85419
- if (data.eventType === "step_created" || data.eventType === "hook_created" || data.eventType === "wait_created" || lazyStepStart) {
85733
+ if (createsChildEntity) {
85420
85734
  throw new EntityConflictError2(`Cannot create new entities on run in terminal state "${currentRun.status}"`);
85421
85735
  }
85422
85736
  if (data.eventType === "attr_set") {
@@ -85424,13 +85738,8 @@ function createEventsStorage(basedir, tag) {
85424
85738
  }
85425
85739
  }
85426
85740
  let validatedStep = null;
85427
- const stepEvents = [
85428
- "step_started",
85429
- "step_completed",
85430
- "step_failed",
85431
- "step_retrying"
85432
- ];
85433
- if (stepEvents.includes(data.eventType) && data.correlationId) {
85741
+ const stepEventRequiresExistingStep = isStepEventType(data.eventType) && data.eventType !== "step_created";
85742
+ if (stepEventRequiresExistingStep && data.correlationId) {
85434
85743
  const stepCompositeKey = `${effectiveRunId}-${data.correlationId}`;
85435
85744
  validatedStep = await readJSONWithFallback(basedir, "steps", stepCompositeKey, StepSchema2, tag);
85436
85745
  if (!validatedStep && !lazyStepStart) {
@@ -85450,8 +85759,7 @@ function createEventsStorage(basedir, tag) {
85450
85759
  }
85451
85760
  }
85452
85761
  }
85453
- const hookEventsRequiringExistence = ["hook_disposed", "hook_received"];
85454
- if (hookEventsRequiringExistence.includes(data.eventType) && data.correlationId) {
85762
+ if (isHookEventRequiringExistence(data.eventType) && data.correlationId) {
85455
85763
  if (data.eventType === "hook_received" && await isHookDisposalCommitted(basedir, data.correlationId, tag)) {
85456
85764
  throw new HookNotFoundError2(data.correlationId);
85457
85765
  }
@@ -85470,9 +85778,9 @@ function createEventsStorage(basedir, tag) {
85470
85778
  if (data.eventType === "run_started" && "eventData" in event) {
85471
85779
  delete event.eventData;
85472
85780
  }
85473
- if (lazyStepStart && "eventData" in event && event.eventData) {
85474
- const { input: _strippedInput, ...rest } = event.eventData;
85475
- event.eventData = rest;
85781
+ if (lazyStepStart && event.eventType === "step_started" && event.eventData) {
85782
+ const { input: _strippedInput, ...eventData } = event.eventData;
85783
+ event = { ...event, eventData };
85476
85784
  }
85477
85785
  let run3;
85478
85786
  let step;
@@ -85995,7 +86303,7 @@ function createEventsStorage(basedir, tag) {
85995
86303
  cursor = allEvents.cursor;
85996
86304
  hasMore = allEvents.hasMore;
85997
86305
  }
85998
- if ((data.eventType === "step_completed" || data.eventType === "step_failed") && typeof params?.sinceCursor === "string") {
86306
+ if (isTerminalStepEventType(data.eventType) && typeof params?.sinceCursor === "string") {
85999
86307
  const delta = await paginatedFileSystemQuery({
86000
86308
  directory: path7.join(basedir, "events"),
86001
86309
  schema: EventSchema2,
@@ -87160,6 +87468,19 @@ function isTurboEnabled() {
87160
87468
  return !(raw === "0" || raw.toLowerCase() === "false");
87161
87469
  }
87162
87470
  __name(isTurboEnabled, "isTurboEnabled");
87471
+ function isInlineOwnershipEnabled() {
87472
+ const raw = process.env.WORKFLOW_INLINE_OWNERSHIP;
87473
+ if (raw === void 0 || raw === "")
87474
+ return true;
87475
+ return !(raw === "0" || raw.toLowerCase() === "false");
87476
+ }
87477
+ __name(isInlineOwnershipEnabled, "isInlineOwnershipEnabled");
87478
+ var INLINE_OWNERSHIP_LEASE_SECONDS = 860;
87479
+ var MAX_INLINE_OWNERSHIP_LEASE_SECONDS = 900;
87480
+ function getInlineOwnershipLeaseSeconds() {
87481
+ return envNumber2("WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS", INLINE_OWNERSHIP_LEASE_SECONDS, { integer: true, min: 1, max: MAX_INLINE_OWNERSHIP_LEASE_SECONDS });
87482
+ }
87483
+ __name(getInlineOwnershipLeaseSeconds, "getInlineOwnershipLeaseSeconds");
87163
87484
  var REPLAY_DIVERGENCE_MAX_RETRIES = 3;
87164
87485
  function getReplayDivergenceMaxRetries() {
87165
87486
  return envNumber2("WORKFLOW_REPLAY_DIVERGENCE_MAX_RETRIES", REPLAY_DIVERGENCE_MAX_RETRIES, { integer: true });
@@ -87475,9 +87796,19 @@ function computeStepLatencyTracking(params) {
87475
87796
  }
87476
87797
  }
87477
87798
  let prevStepEndMs;
87799
+ let stepCount;
87800
+ let eventCount;
87478
87801
  const lastEvent = events[events.length - 1];
87479
87802
  if (!params.suspensionHasWaits && !params.suspensionCreatedHooks && lastEvent && (lastEvent.eventType === "step_completed" || lastEvent.eventType === "step_failed")) {
87480
87803
  prevStepEndMs = +(lastEvent.occurredAt ?? lastEvent.createdAt);
87804
+ const terminalStepIds = /* @__PURE__ */ new Set();
87805
+ for (const event of events) {
87806
+ if ((event.eventType === "step_completed" || event.eventType === "step_failed") && event.correlationId !== void 0) {
87807
+ terminalStepIds.add(event.correlationId);
87808
+ }
87809
+ }
87810
+ stepCount = terminalStepIds.size;
87811
+ eventCount = events.length;
87481
87812
  }
87482
87813
  if (!ttfsEligible && prevStepEndMs === void 0) {
87483
87814
  return void 0;
@@ -87490,7 +87821,7 @@ function computeStepLatencyTracking(params) {
87490
87821
  preStepBlockingMs: preStepAttrStartMs !== void 0 ? params.preStepBlockingBeforeAttrMs ?? 0 : params.preStepBlockingMs,
87491
87822
  ...preStepAttrStartMs !== void 0 ? { preStepAttrStartMs } : {}
87492
87823
  } : {},
87493
- ...prevStepEndMs !== void 0 ? { prevStepEndMs } : {},
87824
+ ...prevStepEndMs !== void 0 ? { prevStepEndMs, stepCount, eventCount } : {},
87494
87825
  turbo: params.turbo
87495
87826
  };
87496
87827
  }
@@ -87516,6 +87847,8 @@ function computeStepLatencyEventData(params) {
87516
87847
  return {
87517
87848
  ...ttfs !== void 0 ? { ttfs } : {},
87518
87849
  ...stso !== void 0 ? { stso } : {},
87850
+ ...stso !== void 0 && tracking.stepCount !== void 0 ? { stepCount: tracking.stepCount } : {},
87851
+ ...stso !== void 0 && tracking.eventCount !== void 0 ? { eventCount: tracking.eventCount } : {},
87519
87852
  optimizations
87520
87853
  };
87521
87854
  }
@@ -87567,7 +87900,15 @@ async function executeStep(params) {
87567
87900
  eventType: "step_started",
87568
87901
  specVersion: SPEC_VERSION_CURRENT2,
87569
87902
  correlationId: stepId,
87570
- eventData: { stepName, workflowName, input: params.lazyStepInput }
87903
+ eventData: {
87904
+ stepName,
87905
+ workflowName,
87906
+ input: params.lazyStepInput,
87907
+ // Stamped for consistency even though this step terminal-fails
87908
+ // immediately below — the log should never show an unowned
87909
+ // lazy start.
87910
+ ...params.ownerMessageId !== void 0 ? { ownerMessageId: params.ownerMessageId } : {}
87911
+ }
87571
87912
  });
87572
87913
  } catch (startErr) {
87573
87914
  if (EntityConflictError2.is(startErr)) {
@@ -87660,7 +88001,13 @@ async function executeStep(params) {
87660
88001
  eventType: "step_started",
87661
88002
  specVersion: SPEC_VERSION_CURRENT2,
87662
88003
  correlationId: stepId,
87663
- eventData: { stepName, workflowName, input: params.lazyStepInput }
88004
+ eventData: {
88005
+ stepName,
88006
+ workflowName,
88007
+ input: params.lazyStepInput,
88008
+ // Inline-ownership stamp — see StepExecutorParams.ownerMessageId.
88009
+ ...params.ownerMessageId !== void 0 ? { ownerMessageId: params.ownerMessageId } : {}
88010
+ }
87664
88011
  }));
87665
88012
  optimisticStartSettled = startedPromise.then(() => ({ ok: true }), (err) => ({ ok: false, err }));
87666
88013
  const now = /* @__PURE__ */ new Date();
@@ -87677,11 +88024,17 @@ async function executeStep(params) {
87677
88024
  };
87678
88025
  } else {
87679
88026
  try {
88027
+ const ownershipStamp = params.ownerMessageId !== void 0 ? { ownerMessageId: params.ownerMessageId } : {};
87680
88028
  const startResult = await world.events.create(workflowRunId, {
87681
88029
  eventType: "step_started",
87682
88030
  specVersion: SPEC_VERSION_CURRENT2,
87683
88031
  correlationId: stepId,
87684
- eventData: params.lazyStepInput !== void 0 ? { stepName, workflowName, input: params.lazyStepInput } : { stepName }
88032
+ eventData: params.lazyStepInput !== void 0 ? {
88033
+ stepName,
88034
+ workflowName,
88035
+ input: params.lazyStepInput,
88036
+ ...ownershipStamp
88037
+ } : { stepName, ...ownershipStamp }
87685
88038
  });
87686
88039
  if (!startResult.step) {
87687
88040
  throw new WorkflowRuntimeError2(`step_started event for "${stepId}" did not return step entity`);
@@ -88091,6 +88444,69 @@ async function executeStep(params) {
88091
88444
  }
88092
88445
  __name(executeStep, "executeStep");
88093
88446
 
88447
+ // ../core/dist/runtime/step-ownership.js
88448
+ function isStepOwnershipActive(step) {
88449
+ return step.hasCreatedEvent === true && step.ownerMessageId !== void 0 && step.sawRetrying !== true;
88450
+ }
88451
+ __name(isStepOwnershipActive, "isStepOwnershipActive");
88452
+ function stepLeaseRemainingSeconds(step, nowMs) {
88453
+ if (step.lastStartedAt === void 0)
88454
+ return 0;
88455
+ const leaseSeconds = getInlineOwnershipLeaseSeconds();
88456
+ const remainingMs = step.lastStartedAt + leaseSeconds * 1e3 - nowMs;
88457
+ return Math.min(leaseSeconds, Math.max(0, Math.ceil(remainingMs / 1e3)));
88458
+ }
88459
+ __name(stepLeaseRemainingSeconds, "stepLeaseRemainingSeconds");
88460
+ function backstopIdempotencyKey(step) {
88461
+ return `${step.correlationId}:backstop:${step.lastStartedAt}`;
88462
+ }
88463
+ __name(backstopIdempotencyKey, "backstopIdempotencyKey");
88464
+ function hasPendingStepOwnedByMessage(events, pendingCorrelationIds, messageId) {
88465
+ const latestOwner = /* @__PURE__ */ new Map();
88466
+ const sawRetrying = /* @__PURE__ */ new Set();
88467
+ for (const e of events) {
88468
+ if (e.correlationId === void 0)
88469
+ continue;
88470
+ if (e.eventType === "step_started") {
88471
+ const owner = "eventData" in e && e.eventData && "ownerMessageId" in e.eventData && typeof e.eventData.ownerMessageId === "string" ? e.eventData.ownerMessageId : void 0;
88472
+ latestOwner.set(e.correlationId, owner);
88473
+ } else if (e.eventType === "step_retrying") {
88474
+ sawRetrying.add(e.correlationId);
88475
+ }
88476
+ }
88477
+ for (const id of pendingCorrelationIds) {
88478
+ if (id !== void 0 && !sawRetrying.has(id) && latestOwner.get(id) === messageId) {
88479
+ return true;
88480
+ }
88481
+ }
88482
+ return false;
88483
+ }
88484
+ __name(hasPendingStepOwnedByMessage, "hasPendingStepOwnedByMessage");
88485
+
88486
+ // ../core/dist/runtime/step-single-flight.js
88487
+ init_logger2();
88488
+ var inFlightSteps = /* @__PURE__ */ new Map();
88489
+ async function runStepSingleFlight(runId, correlationId, execute) {
88490
+ const key = `${runId}:${correlationId}`;
88491
+ const existing = inFlightSteps.get(key);
88492
+ if (existing) {
88493
+ runtimeLogger2.warn("Step execution already in flight in this process; awaiting its settlement instead of executing again", { workflowRunId: runId, stepId: correlationId });
88494
+ try {
88495
+ await existing;
88496
+ } catch {
88497
+ }
88498
+ return { type: "skipped" };
88499
+ }
88500
+ const promise3 = execute();
88501
+ inFlightSteps.set(key, promise3);
88502
+ try {
88503
+ return await promise3;
88504
+ } finally {
88505
+ inFlightSteps.delete(key);
88506
+ }
88507
+ }
88508
+ __name(runStepSingleFlight, "runStepSingleFlight");
88509
+
88094
88510
  // ../core/dist/runtime/suspension-handler.js
88095
88511
  init_dist7();
88096
88512
  init_dist5();
@@ -89216,9 +89632,20 @@ function createUseStep(ctx) {
89216
89632
  return EventConsumerResult2.Consumed;
89217
89633
  }
89218
89634
  if (event.eventType === "step_started") {
89635
+ const queueItem2 = ctx.invocationsQueue.get(correlationId);
89636
+ if (queueItem2 && queueItem2.type === "step") {
89637
+ const ownerMessageId = "eventData" in event && event.eventData && "ownerMessageId" in event.eventData && typeof event.eventData.ownerMessageId === "string" ? event.eventData.ownerMessageId : void 0;
89638
+ queueItem2.ownerMessageId = ownerMessageId;
89639
+ queueItem2.lastStartedAt = +event.createdAt;
89640
+ }
89219
89641
  return EventConsumerResult2.Consumed;
89220
89642
  }
89221
89643
  if (event.eventType === "step_retrying") {
89644
+ const queueItem2 = ctx.invocationsQueue.get(correlationId);
89645
+ if (queueItem2 && queueItem2.type === "step") {
89646
+ queueItem2.sawRetrying = true;
89647
+ queueItem2.ownerMessageId = void 0;
89648
+ }
89222
89649
  return EventConsumerResult2.Consumed;
89223
89650
  }
89224
89651
  if (event.eventType === "step_failed") {
@@ -90880,7 +91307,7 @@ async function wakeUpRun2(world, runId, options) {
90880
91307
  }
90881
91308
  }
90882
91309
  if (stoppedCount > 0) {
90883
- await world.queue(getWorkflowQueueName2(run3.workflowName), {
91310
+ await world.queue(getWorkflowQueueName2(run3.workflowName, options?.namespace), {
90884
91311
  runId
90885
91312
  }, {
90886
91313
  deploymentId: run3.deploymentId,
@@ -91271,7 +91698,7 @@ function workflowEntrypoint(workflowCode2, options) {
91271
91698
  const spanLinks = await buildInvocationSpanLinks(traceMode, traceContext);
91272
91699
  const replayBudget = new ReplayBudget();
91273
91700
  const parentTraceCarrier = traceMode === "continuous" ? traceContext : void 0;
91274
- const spanKind = await getSpanKind2("CONSUMER");
91701
+ const spanKind = await getSpanKind3("CONSUMER");
91275
91702
  return await withTraceContext(parentTraceCarrier, async () => {
91276
91703
  return await withWorkflowBaggage({ workflowRunId: runId, workflowName }, async () => {
91277
91704
  const world = await trace4("workflow.route.get_world", async () => getWorld());
@@ -91312,7 +91739,18 @@ function workflowEntrypoint(workflowCode2, options) {
91312
91739
  }
91313
91740
  }
91314
91741
  }, "awaitRunReady");
91742
+ const inFlightOwnedSteps = /* @__PURE__ */ new Set();
91743
+ const assertNoInFlightOwnedSteps = /* @__PURE__ */ __name((ackPath) => {
91744
+ if (inFlightOwnedSteps.size > 0) {
91745
+ runtimeLogger2.error("Invariant violation: acking the workflow message while owned inline steps are still executing \u2014 crash recovery for these steps is broken", {
91746
+ workflowRunId: runId,
91747
+ ackPath,
91748
+ stepIds: [...inFlightOwnedSteps]
91749
+ });
91750
+ }
91751
+ }, "assertNoInFlightOwnedSteps");
91315
91752
  const reinvoke = /* @__PURE__ */ __name(async (delaySeconds) => {
91753
+ assertNoInFlightOwnedSteps("reinvoke");
91316
91754
  if (!turbo)
91317
91755
  return { timeoutSeconds: delaySeconds };
91318
91756
  await queueMessage(world, getWorkflowQueueName2(workflowName, namespace), {
@@ -91333,7 +91771,7 @@ function workflowEntrypoint(workflowCode2, options) {
91333
91771
  replayBudget.pause();
91334
91772
  let stepResult;
91335
91773
  try {
91336
- stepResult = await executeStep({
91774
+ stepResult = await runStepSingleFlight(runId, incomingStepId, () => executeStep({
91337
91775
  world,
91338
91776
  workflowRunId: runId,
91339
91777
  workflowDeploymentId: bgRun.deploymentId,
@@ -91342,7 +91780,7 @@ function workflowEntrypoint(workflowCode2, options) {
91342
91780
  stepId: incomingStepId,
91343
91781
  stepName: incomingStepName,
91344
91782
  runSpecVersion: bgRun.specVersion
91345
- });
91783
+ }));
91346
91784
  } finally {
91347
91785
  replayBudget.resume();
91348
91786
  }
@@ -91373,16 +91811,19 @@ function workflowEntrypoint(workflowCode2, options) {
91373
91811
  stepTerminalIds.add(e.correlationId);
91374
91812
  }
91375
91813
  }
91376
- let hasPendingSteps = false;
91814
+ const pendingStepIds = /* @__PURE__ */ new Set();
91377
91815
  for (const id of stepCreatedIds) {
91378
91816
  if (!stepTerminalIds.has(id)) {
91379
- hasPendingSteps = true;
91380
- break;
91817
+ pendingStepIds.add(id);
91381
91818
  }
91382
91819
  }
91383
- if (hasPendingSteps) {
91384
- runtimeLogger2.debug("Background step done but other steps pending, returning", { workflowRunId: runId });
91385
- return;
91820
+ if (pendingStepIds.size > 0) {
91821
+ if (isInlineOwnershipEnabled() && hasPendingStepOwnedByMessage(cachedEvents, pendingStepIds, metadata.messageId)) {
91822
+ runtimeLogger2.debug("Background step done; falling through to recover an inline step owned by this message", { workflowRunId: runId });
91823
+ } else {
91824
+ runtimeLogger2.debug("Background step done but other steps pending, returning", { workflowRunId: runId });
91825
+ return;
91826
+ }
91386
91827
  }
91387
91828
  runtimeLogger2.debug("All parallel steps done, replaying inline after background step", { workflowRunId: runId });
91388
91829
  workflowRun = bgRun;
@@ -91803,10 +92244,38 @@ function workflowEntrypoint(workflowCode2, options) {
91803
92244
  const inlineCorrelationIds = new Set(lazyInlineSteps.map((s) => s.correlationId));
91804
92245
  const traceCarrier = await nextTraceCarrier();
91805
92246
  const dispatches = [];
92247
+ const inlineOwnership = isInlineOwnershipEnabled();
92248
+ const dispatchNowMs = Date.now();
92249
+ const ownedRecoverySteps = [];
92250
+ let backstopWakesArmed = 0;
91806
92251
  for (const step of pendingSteps) {
91807
92252
  if (inlineCorrelationIds.has(step.correlationId)) {
91808
92253
  continue;
91809
92254
  }
92255
+ const ownershipActive = inlineOwnership && isStepOwnershipActive(step);
92256
+ if (ownershipActive && step.ownerMessageId === metadata.messageId) {
92257
+ ownedRecoverySteps.push(step);
92258
+ continue;
92259
+ }
92260
+ const backstopDelaySeconds = ownershipActive ? stepLeaseRemainingSeconds(step, dispatchNowMs) : 0;
92261
+ if (backstopDelaySeconds > 0) {
92262
+ backstopWakesArmed++;
92263
+ runtimeLogger2.debug("Pending step is inline-owned by a live invocation; ensuring delayed backstop wake instead of immediate requeue", {
92264
+ workflowRunId: runId,
92265
+ stepId: step.correlationId,
92266
+ ownerMessageId: step.ownerMessageId,
92267
+ backstopDelaySeconds
92268
+ });
92269
+ dispatches.push(queueMessage(world, getWorkflowQueueName2(workflowName, namespace), {
92270
+ runId,
92271
+ traceCarrier,
92272
+ requestedAt: /* @__PURE__ */ new Date()
92273
+ }, {
92274
+ delaySeconds: backstopDelaySeconds,
92275
+ idempotencyKey: backstopIdempotencyKey(step)
92276
+ }));
92277
+ continue;
92278
+ }
91810
92279
  dispatches.push(queueMessage(world, getWorkflowQueueName2(workflowName, namespace), {
91811
92280
  runId,
91812
92281
  stepId: step.correlationId,
@@ -91825,13 +92294,36 @@ function workflowEntrypoint(workflowCode2, options) {
91825
92294
  }, getWaitContinuationDispatch(suspensionResult.waitTimeout.seconds, suspensionResult.waitTimeout.correlationId)));
91826
92295
  }
91827
92296
  await Promise.all(dispatches);
91828
- if (lazyInlineSteps.length === 0) {
92297
+ const inlineExecutions = [
92298
+ ...lazyInlineSteps.map((s) => ({
92299
+ correlationId: s.correlationId,
92300
+ stepName: s.stepName,
92301
+ lazyStepInput: s.dehydratedInput
92302
+ })),
92303
+ ...ownedRecoverySteps.map((s) => ({
92304
+ correlationId: s.correlationId,
92305
+ stepName: s.stepName
92306
+ }))
92307
+ ];
92308
+ if (backstopWakesArmed > 0 || ownedRecoverySteps.length > 0) {
92309
+ span?.setAttributes({
92310
+ ...ownedRecoverySteps.length > 0 ? WorkflowOwnedRecoverySteps2(ownedRecoverySteps.length) : {},
92311
+ ...backstopWakesArmed > 0 ? WorkflowBackstopWakesArmed2(backstopWakesArmed) : {}
92312
+ });
92313
+ }
92314
+ if (ownedRecoverySteps.length > 0) {
92315
+ runtimeLogger2.warn("Re-executing inline steps owned by this queue message \u2014 a previous delivery crashed mid-body and this redelivery is recovering them", {
92316
+ workflowRunId: runId,
92317
+ stepIds: ownedRecoverySteps.map((s) => s.correlationId)
92318
+ });
92319
+ }
92320
+ if (inlineExecutions.length === 0) {
91829
92321
  if (suspensionResult.hasAwaitedHookCreation) {
91830
92322
  return await reinvoke(0);
91831
92323
  }
91832
92324
  return;
91833
92325
  }
91834
- const requestInlineDelta = typeof preInlineWriteCursor === "string" && err.stepCount === 1 && err.hookCount === 0 && err.waitCount === 0 && pendingSteps.length === 1 && lazyInlineSteps.length === 1 && !suspensionResult.waitTimeout && !hasOpenHookOrWait(cachedEvents ?? []);
92326
+ const requestInlineDelta = typeof preInlineWriteCursor === "string" && err.stepCount === 1 && err.hookCount === 0 && err.waitCount === 0 && pendingSteps.length === 1 && lazyInlineSteps.length === 1 && ownedRecoverySteps.length === 0 && !suspensionResult.waitTimeout && !hasOpenHookOrWait(cachedEvents ?? []);
91835
92327
  const forceOptimisticStart = turbo && !suspensionResult.waitTimeout && !suspensionResult.hasHookEvents && !suspensionResult.hasAttributeEvents && !suspensionResult.hasAwaitedHookCreation && !hasOpenHookOrWait(cachedEvents ?? []);
91836
92328
  const latencyTracking = computeStepLatencyTracking({
91837
92329
  events: cachedEvents ?? [],
@@ -91848,39 +92340,53 @@ function workflowEntrypoint(workflowCode2, options) {
91848
92340
  replayBudget.pause();
91849
92341
  let stepResults;
91850
92342
  try {
91851
- stepResults = await Promise.all(lazyInlineSteps.map((s, stepIndex) => executeStep({
91852
- world,
91853
- workflowRunId: runId,
91854
- workflowDeploymentId: workflowRun.deploymentId,
91855
- workflowName,
91856
- workflowStartedAt,
91857
- stepId: s.correlationId,
91858
- stepName: s.stepName,
91859
- runSpecVersion: workflowRun.specVersion,
91860
- // Lazy inline start: send the deferred step's
91861
- // input on step_started so the world creates the
91862
- // step on the fly.
91863
- lazyStepInput: s.dehydratedInput,
91864
- // Turbo: force optimistic start and hold the lazy
91865
- // step_started until the backgrounded run_started
91866
- // lands (the body still runs immediately). Both
91867
- // are undefined/false outside turbo.
91868
- forceOptimisticStart,
91869
- runReadyBarrier,
91870
- ...stepIndex === 0 && latencyTracking ? { latencyTracking } : {},
91871
- ...requestInlineDelta && preInlineWriteCursor ? {
91872
- inlineDeltaSinceCursor: preInlineWriteCursor
91873
- } : {}
91874
- })));
92343
+ stepResults = await Promise.all(inlineExecutions.map((s, stepIndex) => {
92344
+ const run3 = /* @__PURE__ */ __name(() => executeStep({
92345
+ world,
92346
+ workflowRunId: runId,
92347
+ workflowDeploymentId: workflowRun.deploymentId,
92348
+ workflowName,
92349
+ workflowStartedAt,
92350
+ stepId: s.correlationId,
92351
+ stepName: s.stepName,
92352
+ runSpecVersion: workflowRun.specVersion,
92353
+ // Lazy inline start: send the deferred step's
92354
+ // input on step_started so the world creates
92355
+ // the step on the fly. Absent for
92356
+ // owned-recovery steps, whose input hydrates
92357
+ // from the existing step entity.
92358
+ lazyStepInput: s.lazyStepInput,
92359
+ // Inline ownership: stamp (or re-stamp) this
92360
+ // invocation's queue message ID on the
92361
+ // step_started, so wake replays see the body
92362
+ // as in flight here and suppress the
92363
+ // immediate requeue (workflow#2780).
92364
+ ownerMessageId: metadata.messageId,
92365
+ // Turbo: force optimistic start and hold the
92366
+ // lazy step_started until the backgrounded
92367
+ // run_started lands (the body still runs
92368
+ // immediately). Both are undefined/false
92369
+ // outside turbo.
92370
+ forceOptimisticStart,
92371
+ runReadyBarrier,
92372
+ ...stepIndex === 0 && s.lazyStepInput !== void 0 && latencyTracking ? { latencyTracking } : {},
92373
+ ...requestInlineDelta && preInlineWriteCursor ? {
92374
+ inlineDeltaSinceCursor: preInlineWriteCursor
92375
+ } : {}
92376
+ }), "run");
92377
+ inFlightOwnedSteps.add(s.correlationId);
92378
+ const executed = s.lazyStepInput === void 0 ? runStepSingleFlight(runId, s.correlationId, run3) : run3();
92379
+ return executed.finally(() => inFlightOwnedSteps.delete(s.correlationId));
92380
+ }));
91875
92381
  } finally {
91876
92382
  replayBudget.resume();
91877
92383
  }
91878
92384
  const toRetry = [];
91879
92385
  let anyPendingOps = false;
91880
92386
  let throttleTimeout;
91881
- for (let i = 0; i < lazyInlineSteps.length; i++) {
92387
+ for (let i = 0; i < inlineExecutions.length; i++) {
91882
92388
  const r = stepResults[i];
91883
- const s = lazyInlineSteps[i];
92389
+ const s = inlineExecutions[i];
91884
92390
  if (r.type === "retry") {
91885
92391
  toRetry.push({
91886
92392
  step: s,
@@ -91943,7 +92449,7 @@ function workflowEntrypoint(workflowCode2, options) {
91943
92449
  if (toRetry.length > 0) {
91944
92450
  return;
91945
92451
  }
91946
- if (lazyInlineSteps.length === 1) {
92452
+ if (inlineExecutions.length === 1) {
91947
92453
  const only = stepResults[0];
91948
92454
  if (only.type === "completed" && only.inlineDelta && !only.inlineDelta.hasMore) {
91949
92455
  pendingInlineDelta = {
@@ -92060,7 +92566,7 @@ function workflowEntrypoint(workflowCode2, options) {
92060
92566
  return withHealthCheck(async (req) => {
92061
92567
  invocationCount += 1;
92062
92568
  const handlerCached = cachedHandler !== void 0;
92063
- const spanKind = await getSpanKind2("SERVER");
92569
+ const spanKind = await getSpanKind3("SERVER");
92064
92570
  return trace4("workflow.route.flow", {
92065
92571
  kind: spanKind,
92066
92572
  attributes: {
@@ -107782,12 +108288,74 @@ var EventTypeSchema = external_exports.enum([
107782
108288
  "wait_created",
107783
108289
  "wait_completed"
107784
108290
  ]);
108291
+ var RunEventTypeSchema = EventTypeSchema.extract([
108292
+ "run_created",
108293
+ "run_started",
108294
+ "run_completed",
108295
+ "run_failed",
108296
+ "run_cancelled"
108297
+ ]);
108298
+ var RUN_EVENT_TYPES = RunEventTypeSchema.options;
107785
108299
  var TerminalRunEventTypeSchema = EventTypeSchema.extract([
107786
108300
  "run_completed",
107787
108301
  "run_failed",
107788
108302
  "run_cancelled"
107789
108303
  ]);
107790
108304
  var TERMINAL_RUN_EVENT_TYPES = TerminalRunEventTypeSchema.options;
108305
+ var StepEventTypeSchema = EventTypeSchema.extract([
108306
+ "step_created",
108307
+ "step_completed",
108308
+ "step_failed",
108309
+ "step_retrying",
108310
+ "step_started"
108311
+ ]);
108312
+ var STEP_EVENT_TYPES = StepEventTypeSchema.options;
108313
+ var TerminalStepEventTypeSchema = EventTypeSchema.extract([
108314
+ "step_completed",
108315
+ "step_failed"
108316
+ ]);
108317
+ var TERMINAL_STEP_EVENT_TYPES = TerminalStepEventTypeSchema.options;
108318
+ var HookLifecycleEventTypeSchema = EventTypeSchema.extract([
108319
+ "hook_created",
108320
+ "hook_received",
108321
+ "hook_disposed"
108322
+ ]);
108323
+ var HOOK_LIFECYCLE_EVENT_TYPES = HookLifecycleEventTypeSchema.options;
108324
+ var HookEventRequiringExistenceTypeSchema = EventTypeSchema.extract([
108325
+ "hook_disposed",
108326
+ "hook_received"
108327
+ ]);
108328
+ var HOOK_EVENTS_REQUIRING_EXISTENCE = HookEventRequiringExistenceTypeSchema.options;
108329
+ var WaitEventTypeSchema = EventTypeSchema.extract([
108330
+ "wait_created",
108331
+ "wait_completed"
108332
+ ]);
108333
+ var WAIT_EVENT_TYPES = WaitEventTypeSchema.options;
108334
+ var ChildEntityCreationEventTypeSchema = EventTypeSchema.extract([
108335
+ "step_created",
108336
+ "hook_created",
108337
+ "wait_created"
108338
+ ]);
108339
+ var CHILD_ENTITY_CREATION_EVENT_TYPES = ChildEntityCreationEventTypeSchema.options;
108340
+ var EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE = {
108341
+ run_created: "input",
108342
+ run_started: "input",
108343
+ run_completed: "output",
108344
+ run_failed: "error",
108345
+ step_created: "input",
108346
+ step_started: "input",
108347
+ step_completed: "result",
108348
+ step_failed: "error",
108349
+ step_retrying: "error",
108350
+ hook_created: "metadata",
108351
+ hook_received: "payload"
108352
+ };
108353
+ var EVENT_DATA_REF_FIELDS = Object.fromEntries(Object.entries(EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE).map(([eventType, field]) => [
108354
+ eventType,
108355
+ [
108356
+ field
108357
+ ]
108358
+ ]));
107791
108359
  var BaseEventSchema = external_exports.object({
107792
108360
  eventType: EventTypeSchema,
107793
108361
  correlationId: external_exports.string().optional(),
@@ -107804,6 +108372,10 @@ var stepLatencyTelemetryFields = {
107804
108372
  // two steps ran back-to-back (the previous event-log entry is a
107805
108373
  // step_completed/step_failed).
107806
108374
  stso: external_exports.number().optional(),
108375
+ // Progress counters taken when the STSO gap began. Only present alongside
108376
+ // stso.
108377
+ stepCount: external_exports.number().int().positive().optional(),
108378
+ eventCount: external_exports.number().int().positive().optional(),
107807
108379
  // Names of the runtime's optional startup-latency optimizations that were
107808
108380
  // active for this measurement (e.g. 'turbo', 'lazyStepStart',
107809
108381
  // 'optimisticStart'), so latency metrics can be segmented by them.
@@ -107855,7 +108427,20 @@ var StepStartedEventSchema = BaseEventSchema.extend({
107855
108427
  workflowName: external_exports.string().optional(),
107856
108428
  // Lazy-start: the dehydrated step input, present only when this
107857
108429
  // step_started is also responsible for creating the step.
107858
- input: SerializedDataSchema.optional()
108430
+ input: SerializedDataSchema.optional(),
108431
+ // Inline step ownership: the queue message ID of the invocation whose
108432
+ // handler is executing this step's body inline. Stamped on the lazy
108433
+ // step_started (and re-stamped on an owner-recovery bare start) so
108434
+ // that a wake replay can tell "this attempt is in flight in a live
108435
+ // invocation" apart from "this attempt died with its process" \u2014 the
108436
+ // owner's queue message doubles as the liveness lease (a crash means
108437
+ // the queue redelivers that same messageId, which is allowed to
108438
+ // re-execute). Ownership derives from the step's LATEST step_started:
108439
+ // an unstamped bare start (a retry attempt driven by a queued step
108440
+ // message) clears it. Absent on eager steps and from older runtimes.
108441
+ // Requires the queue's messageId to be stable across redeliveries of
108442
+ // one message (see the Queue.createQueueHandler meta contract).
108443
+ ownerMessageId: external_exports.string().optional()
107859
108444
  }).optional()
107860
108445
  });
107861
108446
  var StepCreatedEventSchema = BaseEventSchema.extend({
@@ -108423,6 +109008,10 @@ var StructuredErrorSchema = external_exports.object({
108423
109008
 
108424
109009
  // ../world/dist/ulid.js
108425
109010
  var UlidSchema = external_exports.string().ulid();
109011
+ var workflowRunIdSchema = external_exports.templateLiteral([
109012
+ "wrun_",
109013
+ external_exports.ulid()
109014
+ ]);
108426
109015
  var DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS = 24 * 60 * 60 * 1e3;
108427
109016
  var DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS = 5 * 60 * 1e3;
108428
109017
 
@@ -108503,10 +109092,10 @@ var Run = class _Run {
108503
109092
  return this.getReadable();
108504
109093
  }
108505
109094
  };
108506
- Run.prototype["wakeUp"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#wakeUp");
108507
- Run.prototype["cancel"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#cancel");
108508
- Run.prototype["getReadable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#getReadable");
108509
- var __step_Run$exists = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#exists");
109095
+ Run.prototype["wakeUp"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#wakeUp");
109096
+ Run.prototype["cancel"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#cancel");
109097
+ Run.prototype["getReadable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#getReadable");
109098
+ var __step_Run$exists = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#exists");
108510
109099
  Object.defineProperty(Run.prototype, "exists", {
108511
109100
  get() {
108512
109101
  return __step_Run$exists.call(this);
@@ -108514,7 +109103,7 @@ Object.defineProperty(Run.prototype, "exists", {
108514
109103
  configurable: true,
108515
109104
  enumerable: false
108516
109105
  });
108517
- var __step_Run$status = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#status");
109106
+ var __step_Run$status = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#status");
108518
109107
  Object.defineProperty(Run.prototype, "status", {
108519
109108
  get() {
108520
109109
  return __step_Run$status.call(this);
@@ -108522,7 +109111,7 @@ Object.defineProperty(Run.prototype, "status", {
108522
109111
  configurable: true,
108523
109112
  enumerable: false
108524
109113
  });
108525
- var __step_Run$returnValue = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#returnValue");
109114
+ var __step_Run$returnValue = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#returnValue");
108526
109115
  Object.defineProperty(Run.prototype, "returnValue", {
108527
109116
  get() {
108528
109117
  return __step_Run$returnValue.call(this);
@@ -108530,7 +109119,7 @@ Object.defineProperty(Run.prototype, "returnValue", {
108530
109119
  configurable: true,
108531
109120
  enumerable: false
108532
109121
  });
108533
- var __step_Run$workflowName = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#workflowName");
109122
+ var __step_Run$workflowName = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#workflowName");
108534
109123
  Object.defineProperty(Run.prototype, "workflowName", {
108535
109124
  get() {
108536
109125
  return __step_Run$workflowName.call(this);
@@ -108538,7 +109127,7 @@ Object.defineProperty(Run.prototype, "workflowName", {
108538
109127
  configurable: true,
108539
109128
  enumerable: false
108540
109129
  });
108541
- var __step_Run$createdAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#createdAt");
109130
+ var __step_Run$createdAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#createdAt");
108542
109131
  Object.defineProperty(Run.prototype, "createdAt", {
108543
109132
  get() {
108544
109133
  return __step_Run$createdAt.call(this);
@@ -108546,7 +109135,7 @@ Object.defineProperty(Run.prototype, "createdAt", {
108546
109135
  configurable: true,
108547
109136
  enumerable: false
108548
109137
  });
108549
- var __step_Run$startedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#startedAt");
109138
+ var __step_Run$startedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#startedAt");
108550
109139
  Object.defineProperty(Run.prototype, "startedAt", {
108551
109140
  get() {
108552
109141
  return __step_Run$startedAt.call(this);
@@ -108554,7 +109143,7 @@ Object.defineProperty(Run.prototype, "startedAt", {
108554
109143
  configurable: true,
108555
109144
  enumerable: false
108556
109145
  });
108557
- var __step_Run$completedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.29//Run#completedAt");
109146
+ var __step_Run$completedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.0.0-beta.30//Run#completedAt");
108558
109147
  Object.defineProperty(Run.prototype, "completedAt", {
108559
109148
  get() {
108560
109149
  return __step_Run$completedAt.call(this);
@@ -108571,7 +109160,7 @@ Object.defineProperty(Run.prototype, "completedAt", {
108571
109160
  enumerable: false,
108572
109161
  configurable: false
108573
109162
  });
108574
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.29//Run");
109163
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.30//Run");
108575
109164
 
108576
109165
  // ../core/dist/workflow/create-hook.js
108577
109166
  aliasSerializationClass(RUN_CLASS_ID, Run);