@workflow/world-testing 5.0.0-beta.34 → 5.0.0-beta.36

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.
@@ -356,6 +356,8 @@ var init_error_codes = __esm({
356
356
  REPLAY_DIVERGENCE: "REPLAY_DIVERGENCE",
357
357
  /** Run exceeded the maximum number of queue deliveries */
358
358
  MAX_DELIVERIES_EXCEEDED: "MAX_DELIVERIES_EXCEEDED",
359
+ /** Run exceeded the maximum number of events per run */
360
+ MAX_EVENTS_EXCEEDED: "MAX_EVENTS_EXCEEDED",
359
361
  /** Workflow replay exceeded the maximum allowed duration */
360
362
  REPLAY_TIMEOUT: "REPLAY_TIMEOUT",
361
363
  /** World response violated the SDK contract and cannot be retried safely */
@@ -16451,12 +16453,14 @@ function validateAttributeChanges(changes, context = {}) {
16451
16453
  throw new AttributeValidationError(`Run attribute count would exceed limit ${ATTRIBUTE_MAX_PER_RUN} (post-merge ${postMerge})`);
16452
16454
  }
16453
16455
  }
16454
- var RESERVED_ATTRIBUTE_KEY_PREFIX, ATTRIBUTE_KEY_MAX_LENGTH, ATTRIBUTE_VALUE_MAX_BYTES, ATTRIBUTE_MAX_PER_RUN, AttributeChangeSchema, AttributeChangesSchema, AttributeValidationError, valueByteLength;
16456
+ var RESERVED_ATTRIBUTE_KEY_PREFIX, ROOT_RUN_ID_ATTRIBUTE, PARENT_RUN_ID_ATTRIBUTE, ATTRIBUTE_KEY_MAX_LENGTH, ATTRIBUTE_VALUE_MAX_BYTES, ATTRIBUTE_MAX_PER_RUN, AttributeChangeSchema, AttributeChangesSchema, AttributeValidationError, valueByteLength;
16455
16457
  var init_attributes = __esm({
16456
16458
  "../world/dist/attributes.js"() {
16457
16459
  "use strict";
16458
16460
  init_zod();
16459
16461
  RESERVED_ATTRIBUTE_KEY_PREFIX = "$";
16462
+ ROOT_RUN_ID_ATTRIBUTE = `${RESERVED_ATTRIBUTE_KEY_PREFIX}rootRunId`;
16463
+ PARENT_RUN_ID_ATTRIBUTE = `${RESERVED_ATTRIBUTE_KEY_PREFIX}parentRunId`;
16460
16464
  ATTRIBUTE_KEY_MAX_LENGTH = 256;
16461
16465
  ATTRIBUTE_VALUE_MAX_BYTES = 256;
16462
16466
  ATTRIBUTE_MAX_PER_RUN = 64;
@@ -16619,6 +16623,17 @@ var init_events = __esm({
16619
16623
  // stso.
16620
16624
  stepCount: external_exports.number().int().positive().optional(),
16621
16625
  eventCount: external_exports.number().int().positive().optional(),
16626
+ // Run-started-to-first-step: milliseconds from the `run_started` response
16627
+ // landing (or, under turbo, the local run synthesis instant) until this
16628
+ // step's start POST was issued. A sub-window of ttfs. Only reported
16629
+ // alongside the same eligibility as ttfs.
16630
+ rsfs: external_exports.number().optional(),
16631
+ // Synchronous workflow-function replay duration of only the FINAL replay
16632
+ // pass within the rsfs window (the pass that scheduled the first step),
16633
+ // excluding awaited network I/O — not accumulated across earlier
16634
+ // pre-first-step passes, so it is not "the replay portion of rsfs". Only
16635
+ // present alongside rsfs, and only for the run's first step.
16636
+ finalSchedulingReplay: external_exports.number().optional(),
16622
16637
  // Names of the runtime's optional startup-latency optimizations that were
16623
16638
  // active for this measurement (e.g. 'turbo', 'lazyStepStart',
16624
16639
  // 'optimisticStart'), so latency metrics can be segmented by them.
@@ -16700,6 +16715,7 @@ var init_events = __esm({
16700
16715
  correlationId: external_exports.string(),
16701
16716
  eventData: external_exports.object({
16702
16717
  token: external_exports.string(),
16718
+ tokenRetentionUntil: external_exports.coerce.date().optional(),
16703
16719
  metadata: SerializedDataSchema.optional(),
16704
16720
  isWebhook: external_exports.boolean().optional(),
16705
16721
  isSystem: external_exports.boolean().optional()
@@ -16869,6 +16885,9 @@ var init_events = __esm({
16869
16885
  });
16870
16886
 
16871
16887
  // ../world/dist/runs.js
16888
+ function isTerminalWorkflowRunStatus(status) {
16889
+ return TERMINAL_WORKFLOW_RUN_STATUSES.includes(status);
16890
+ }
16872
16891
  var WorkflowRunStatusSchema, TerminalWorkflowRunStatusSchema, TERMINAL_WORKFLOW_RUN_STATUSES, WorkflowRunBaseSchema, WorkflowRunSchema;
16873
16892
  var init_runs = __esm({
16874
16893
  "../world/dist/runs.js"() {
@@ -16888,6 +16907,7 @@ var init_runs = __esm({
16888
16907
  "cancelled"
16889
16908
  ]);
16890
16909
  TERMINAL_WORKFLOW_RUN_STATUSES = TerminalWorkflowRunStatusSchema.options;
16910
+ __name(isTerminalWorkflowRunStatus, "isTerminalWorkflowRunStatus");
16891
16911
  WorkflowRunBaseSchema = external_exports.object({
16892
16912
  runId: external_exports.string(),
16893
16913
  status: WorkflowRunStatusSchema,
@@ -18310,6 +18330,28 @@ var init_devalue = __esm({
18310
18330
  }
18311
18331
  });
18312
18332
 
18333
+ // ../core/dist/symbols.js
18334
+ var STABLE_ULID, STREAM_NAME_SYMBOL, STREAM_TYPE_SYMBOL, STREAM_FRAMING_SYMBOL, STREAM_SERVER_RUN_ID_SYMBOL, STREAM_SERVER_DEPLOYMENT_ID_SYMBOL, STREAM_WRITE_BATCH_SYMBOL, BODY_INIT_SYMBOL, WEBHOOK_RESPONSE_WRITABLE, WORKFLOW_CLASS_REGISTRY, ABORT_STREAM_NAME, ABORT_HOOK_TOKEN, ABORT_LISTENER_ATTACHED, ABORT_READER_CANCEL;
18335
+ var init_symbols = __esm({
18336
+ "../core/dist/symbols.js"() {
18337
+ "use strict";
18338
+ STABLE_ULID = /* @__PURE__ */ Symbol.for("WORKFLOW_STABLE_ULID");
18339
+ STREAM_NAME_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_NAME");
18340
+ STREAM_TYPE_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_TYPE");
18341
+ STREAM_FRAMING_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_FRAMING");
18342
+ STREAM_SERVER_RUN_ID_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_SERVER_RUN_ID");
18343
+ STREAM_SERVER_DEPLOYMENT_ID_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_SERVER_DEPLOYMENT_ID");
18344
+ STREAM_WRITE_BATCH_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_WRITE_BATCH");
18345
+ BODY_INIT_SYMBOL = /* @__PURE__ */ Symbol.for("BODY_INIT");
18346
+ WEBHOOK_RESPONSE_WRITABLE = /* @__PURE__ */ Symbol.for("WEBHOOK_RESPONSE_WRITABLE");
18347
+ WORKFLOW_CLASS_REGISTRY = /* @__PURE__ */ Symbol.for("workflow-class-registry");
18348
+ ABORT_STREAM_NAME = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_STREAM_NAME");
18349
+ ABORT_HOOK_TOKEN = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_HOOK_TOKEN");
18350
+ ABORT_LISTENER_ATTACHED = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_LISTENER_ATTACHED");
18351
+ ABORT_READER_CANCEL = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_READER_CANCEL");
18352
+ }
18353
+ });
18354
+
18313
18355
  // ../core/dist/flushable-stream.js
18314
18356
  function createFlushableState() {
18315
18357
  const state = {
@@ -18390,7 +18432,11 @@ function pollReadableLock(readable, state) {
18390
18432
  }, getLockPollIntervalMs());
18391
18433
  state.readablePollingInterval = intervalId;
18392
18434
  }
18393
- async function flushablePipe(source, sink, state) {
18435
+ function flushablePipe(source, sink, state) {
18436
+ const batchWrite = sink[STREAM_WRITE_BATCH_SYMBOL];
18437
+ return typeof batchWrite === "function" ? flushablePipeCoalescing(source, sink, state, batchWrite) : flushablePipePerChunk(source, sink, state);
18438
+ }
18439
+ async function flushablePipePerChunk(source, sink, state) {
18394
18440
  const reader = source.getReader();
18395
18441
  const writer = sink.getWriter();
18396
18442
  let cancelReason;
@@ -18439,13 +18485,142 @@ async function flushablePipe(source, sink, state) {
18439
18485
  writer.releaseLock();
18440
18486
  }
18441
18487
  }
18442
- var LOCK_POLL_INTERVAL_MS, getLockPollIntervalMs;
18488
+ function wake(ctx, which) {
18489
+ const resolve = ctx[which];
18490
+ if (resolve) {
18491
+ ctx[which] = null;
18492
+ resolve();
18493
+ }
18494
+ }
18495
+ function nextBatchSize(ctx) {
18496
+ let count2 = 0;
18497
+ let bytes = 0;
18498
+ for (const chunk of ctx.queue) {
18499
+ if (count2 >= ctx.maxChunksPerBatch) break;
18500
+ if (count2 > 0 && bytes + chunk.byteLength > ctx.maxBytesPerBatch) break;
18501
+ count2++;
18502
+ bytes += chunk.byteLength;
18503
+ }
18504
+ return count2;
18505
+ }
18506
+ async function drainBatches(ctx) {
18507
+ while (true) {
18508
+ if (ctx.queue.length === 0) {
18509
+ if (ctx.sourceDone) return;
18510
+ await new Promise((resolve) => {
18511
+ ctx.wakeConsumer = resolve;
18512
+ });
18513
+ continue;
18514
+ }
18515
+ const count2 = nextBatchSize(ctx);
18516
+ const batch = ctx.queue.slice(0, count2);
18517
+ ctx.queue = ctx.queue.slice(count2);
18518
+ await ctx.batchWrite(batch);
18519
+ ctx.state.pendingOps -= batch.length;
18520
+ wake(ctx, "wakeProducer");
18521
+ }
18522
+ }
18523
+ function readNextChunk(reader, writer, consumer) {
18524
+ return Promise.race([
18525
+ reader.read(),
18526
+ writer.closed.then(() => {
18527
+ throw new WorkflowRuntimeError("Writable stream closed prematurely");
18528
+ }),
18529
+ consumer.then(() => {
18530
+ throw new WorkflowRuntimeError("Stream consumer ended prematurely");
18531
+ }, (err) => {
18532
+ throw err;
18533
+ })
18534
+ ]);
18535
+ }
18536
+ async function awaitBackpressureRelief(ctx, consumer, maxInflight) {
18537
+ if (ctx.state.pendingOps < maxInflight) return;
18538
+ await Promise.race([
18539
+ new Promise((resolve) => {
18540
+ ctx.wakeProducer = resolve;
18541
+ }),
18542
+ consumer.then(() => void 0, () => void 0)
18543
+ ]);
18544
+ }
18545
+ async function flushablePipeCoalescing(source, sink, state, batchWrite) {
18546
+ const reader = source.getReader();
18547
+ const writer = sink.getWriter();
18548
+ const maxInflight = getMaxInflightChunks();
18549
+ let cancelReason;
18550
+ const ctx = {
18551
+ state,
18552
+ batchWrite,
18553
+ queue: [],
18554
+ sourceDone: false,
18555
+ wakeConsumer: null,
18556
+ wakeProducer: null,
18557
+ maxChunksPerBatch: getMaxChunksPerBatch(),
18558
+ maxBytesPerBatch: getMaxBytesPerBatch()
18559
+ };
18560
+ const consumer = drainBatches(ctx);
18561
+ try {
18562
+ while (!state.streamEnded) {
18563
+ const readResult = await readNextChunk(reader, writer, consumer);
18564
+ if (state.streamEnded) return;
18565
+ if (readResult.done) {
18566
+ ctx.sourceDone = true;
18567
+ wake(ctx, "wakeConsumer");
18568
+ await consumer;
18569
+ state.streamEnded = true;
18570
+ await writer.close();
18571
+ if (!state.doneResolved) {
18572
+ state.doneResolved = true;
18573
+ state.resolve();
18574
+ }
18575
+ return;
18576
+ }
18577
+ ctx.queue.push(readResult.value);
18578
+ state.pendingOps++;
18579
+ wake(ctx, "wakeConsumer");
18580
+ await awaitBackpressureRelief(ctx, consumer, maxInflight);
18581
+ }
18582
+ } catch (err) {
18583
+ state.streamEnded = true;
18584
+ cancelReason = err;
18585
+ ctx.sourceDone = true;
18586
+ wake(ctx, "wakeConsumer");
18587
+ await consumer.catch(() => {
18588
+ });
18589
+ if (!state.doneResolved) {
18590
+ state.doneResolved = true;
18591
+ state.reject(err);
18592
+ }
18593
+ throw err;
18594
+ } finally {
18595
+ reader.cancel(cancelReason).catch(() => {
18596
+ });
18597
+ reader.releaseLock();
18598
+ writer.releaseLock();
18599
+ }
18600
+ }
18601
+ var MAX_INFLIGHT_CHUNKS, getMaxInflightChunks, MAX_CHUNKS_PER_BATCH, getMaxChunksPerBatch, MAX_BYTES_PER_BATCH, getMaxBytesPerBatch, LOCK_POLL_INTERVAL_MS, getLockPollIntervalMs;
18443
18602
  var init_flushable_stream = __esm({
18444
18603
  "../core/dist/flushable-stream.js"() {
18445
18604
  "use strict";
18446
18605
  init_dist2();
18447
18606
  init_dist();
18448
18607
  init_dist4();
18608
+ init_symbols();
18609
+ MAX_INFLIGHT_CHUNKS = 1e3;
18610
+ getMaxInflightChunks = /* @__PURE__ */ __name(() => envNumber("WORKFLOW_STREAM_MAX_INFLIGHT_CHUNKS", MAX_INFLIGHT_CHUNKS, {
18611
+ integer: true,
18612
+ min: 1
18613
+ }), "getMaxInflightChunks");
18614
+ MAX_CHUNKS_PER_BATCH = 1e3;
18615
+ getMaxChunksPerBatch = /* @__PURE__ */ __name(() => envNumber("WORKFLOW_STREAM_MAX_CHUNKS_PER_BATCH", MAX_CHUNKS_PER_BATCH, {
18616
+ integer: true,
18617
+ min: 1
18618
+ }), "getMaxChunksPerBatch");
18619
+ MAX_BYTES_PER_BATCH = 1024 * 1024;
18620
+ getMaxBytesPerBatch = /* @__PURE__ */ __name(() => envNumber("WORKFLOW_STREAM_MAX_BYTES_PER_BATCH", MAX_BYTES_PER_BATCH, {
18621
+ integer: true,
18622
+ min: 1
18623
+ }), "getMaxBytesPerBatch");
18449
18624
  LOCK_POLL_INTERVAL_MS = 10;
18450
18625
  getLockPollIntervalMs = /* @__PURE__ */ __name(() => envNumber("WORKFLOW_LOCK_POLL_INTERVAL_MS", LOCK_POLL_INTERVAL_MS, {
18451
18626
  integer: true,
@@ -18457,6 +18632,13 @@ var init_flushable_stream = __esm({
18457
18632
  __name(pollWritableLock, "pollWritableLock");
18458
18633
  __name(pollReadableLock, "pollReadableLock");
18459
18634
  __name(flushablePipe, "flushablePipe");
18635
+ __name(flushablePipePerChunk, "flushablePipePerChunk");
18636
+ __name(wake, "wake");
18637
+ __name(nextBatchSize, "nextBatchSize");
18638
+ __name(drainBatches, "drainBatches");
18639
+ __name(readNextChunk, "readNextChunk");
18640
+ __name(awaitBackpressureRelief, "awaitBackpressureRelief");
18641
+ __name(flushablePipeCoalescing, "flushablePipeCoalescing");
18460
18642
  }
18461
18643
  });
18462
18644
 
@@ -18585,27 +18767,6 @@ var init_get_world_lazy = __esm({
18585
18767
  }
18586
18768
  });
18587
18769
 
18588
- // ../core/dist/symbols.js
18589
- var STABLE_ULID, STREAM_NAME_SYMBOL, STREAM_TYPE_SYMBOL, STREAM_FRAMING_SYMBOL, STREAM_SERVER_RUN_ID_SYMBOL, STREAM_SERVER_DEPLOYMENT_ID_SYMBOL, BODY_INIT_SYMBOL, WEBHOOK_RESPONSE_WRITABLE, WORKFLOW_CLASS_REGISTRY, ABORT_STREAM_NAME, ABORT_HOOK_TOKEN, ABORT_LISTENER_ATTACHED, ABORT_READER_CANCEL;
18590
- var init_symbols = __esm({
18591
- "../core/dist/symbols.js"() {
18592
- "use strict";
18593
- STABLE_ULID = /* @__PURE__ */ Symbol.for("WORKFLOW_STABLE_ULID");
18594
- STREAM_NAME_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_NAME");
18595
- STREAM_TYPE_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_TYPE");
18596
- STREAM_FRAMING_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_FRAMING");
18597
- STREAM_SERVER_RUN_ID_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_SERVER_RUN_ID");
18598
- STREAM_SERVER_DEPLOYMENT_ID_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STREAM_SERVER_DEPLOYMENT_ID");
18599
- BODY_INIT_SYMBOL = /* @__PURE__ */ Symbol.for("BODY_INIT");
18600
- WEBHOOK_RESPONSE_WRITABLE = /* @__PURE__ */ Symbol.for("WEBHOOK_RESPONSE_WRITABLE");
18601
- WORKFLOW_CLASS_REGISTRY = /* @__PURE__ */ Symbol.for("workflow-class-registry");
18602
- ABORT_STREAM_NAME = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_STREAM_NAME");
18603
- ABORT_HOOK_TOKEN = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_HOOK_TOKEN");
18604
- ABORT_LISTENER_ATTACHED = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_LISTENER_ATTACHED");
18605
- ABORT_READER_CANCEL = /* @__PURE__ */ Symbol.for("WORKFLOW_ABORT_READER_CANCEL");
18606
- }
18607
- });
18608
-
18609
18770
  // ../core/dist/class-serialization.js
18610
18771
  function getRegistry(global2 = globalThis) {
18611
18772
  const g = global2;
@@ -19808,7 +19969,7 @@ function SemanticConvention(...names) {
19808
19969
  value
19809
19970
  ]));
19810
19971
  }
19811
- var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, HookToken, HookId, HookFound, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
19972
+ var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, HookToken, HookId, HookFound, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
19812
19973
  var init_semantic_conventions = __esm({
19813
19974
  "../core/dist/telemetry/semantic-conventions.js"() {
19814
19975
  "use strict";
@@ -19845,6 +20006,8 @@ var init_semantic_conventions = __esm({
19845
20006
  StepTracePropagated = SemanticConvention("step.trace.propagated");
19846
20007
  StepTtfsMs = SemanticConvention("step.ttfs_ms");
19847
20008
  StepStsoMs = SemanticConvention("step.stso_ms");
20009
+ StepRsfsMs = SemanticConvention("step.rsfs_ms");
20010
+ StepFinalSchedulingReplayMs = SemanticConvention("step.final_scheduling_replay_ms");
19848
20011
  StepLatencyOptimizations = SemanticConvention("step.latency_optimizations");
19849
20012
  StepSkipped = SemanticConvention("step.skipped");
19850
20013
  StepSkipReason = SemanticConvention("step.skip_reason");
@@ -24477,7 +24640,7 @@ var version2;
24477
24640
  var init_version = __esm({
24478
24641
  "../core/dist/version.js"() {
24479
24642
  "use strict";
24480
- version2 = "5.0.0-beta.34";
24643
+ version2 = "5.0.0-beta.36";
24481
24644
  }
24482
24645
  });
24483
24646
 
@@ -25818,18 +25981,24 @@ __export(resume_hook_exports, {
25818
25981
  resumeHook: () => resumeHook,
25819
25982
  resumeWebhook: () => resumeWebhook
25820
25983
  });
25821
- async function getHookByTokenWithKey(token) {
25984
+ async function getHookAndRun(token) {
25822
25985
  const world = await getWorldLazy();
25823
25986
  const hook = await world.hooks.getByToken(token);
25824
25987
  const run2 = await world.runs.get(hook.runId);
25825
- const rawKey = await world.getEncryptionKeyForRun?.(run2);
25988
+ return {
25989
+ hook,
25990
+ run: run2
25991
+ };
25992
+ }
25993
+ async function getHookByTokenWithKey(token) {
25994
+ const { hook, run: run2 } = await getHookAndRun(token);
25995
+ const rawKey = await (await getWorldLazy()).getEncryptionKeyForRun?.(run2);
25826
25996
  const encryptionKey = rawKey ? await importKey(rawKey) : void 0;
25827
25997
  if (typeof hook.metadata !== "undefined") {
25828
25998
  hook.metadata = await hydrateStepArguments(hook.metadata, hook.runId, encryptionKey);
25829
25999
  }
25830
26000
  return {
25831
26001
  hook,
25832
- run: run2,
25833
26002
  encryptionKey
25834
26003
  };
25835
26004
  }
@@ -25844,27 +26013,27 @@ async function resumeHook(tokenOrHook, payload, encryptionKeyOverride) {
25844
26013
  try {
25845
26014
  let hook;
25846
26015
  let workflowRun;
25847
- let encryptionKey;
25848
26016
  if (typeof tokenOrHook === "string") {
25849
- const result = await getHookByTokenWithKey(tokenOrHook);
26017
+ const result = await getHookAndRun(tokenOrHook);
25850
26018
  hook = result.hook;
25851
26019
  workflowRun = result.run;
25852
- encryptionKey = encryptionKeyOverride ?? result.encryptionKey;
25853
26020
  } else {
25854
26021
  hook = tokenOrHook;
25855
26022
  workflowRun = await world.runs.get(hook.runId);
25856
- if (encryptionKeyOverride) {
25857
- encryptionKey = encryptionKeyOverride;
25858
- } else {
25859
- const rawKey = await world.getEncryptionKeyForRun?.(workflowRun);
25860
- encryptionKey = rawKey ? await importKey(rawKey) : void 0;
25861
- }
25862
26023
  }
25863
26024
  span?.setAttributes({
25864
26025
  ...HookToken(hook.token),
25865
26026
  ...HookId(hook.hookId),
25866
26027
  ...WorkflowRunId(hook.runId)
25867
26028
  });
26029
+ if (isTerminalWorkflowRunStatus(workflowRun.status)) {
26030
+ throw new HookNotFoundError(hook.token);
26031
+ }
26032
+ let encryptionKey = encryptionKeyOverride;
26033
+ if (!encryptionKey) {
26034
+ const rawKey = await world.getEncryptionKeyForRun?.(workflowRun);
26035
+ encryptionKey = rawKey ? await importKey(rawKey) : void 0;
26036
+ }
25868
26037
  const rawVersion = workflowRun.executionContext?.workflowCoreVersion;
25869
26038
  const capabilities = getRunCapabilities(typeof rawVersion === "string" ? rawVersion : void 0);
25870
26039
  if (!capabilities.supportedFormats.has(SerializationFormat.ENCRYPTED)) {
@@ -25976,6 +26145,7 @@ var init_resume_hook = __esm({
25976
26145
  init_get_world_lazy();
25977
26146
  init_helpers();
25978
26147
  init_wait_until();
26148
+ __name(getHookAndRun, "getHookAndRun");
25979
26149
  __name(getHookByTokenWithKey, "getHookByTokenWithKey");
25980
26150
  __name(getHookByToken, "getHookByToken");
25981
26151
  __name(resumeHook, "resumeHook");
@@ -27078,9 +27248,6 @@ function getStepRevivers(global2 = globalThis, ops, runId, cryptoKey, deployment
27078
27248
  AbortSignal: /* @__PURE__ */ __name((value) => reviveAbortSignal(value, ops, runId), "AbortSignal")
27079
27249
  };
27080
27250
  }
27081
- async function maybeDecrypt(data, key) {
27082
- return decrypt2(data, key);
27083
- }
27084
27251
  async function dehydrateWorkflowArguments(value, runId, key, ops = [], global2 = globalThis, v1Compat = false, framedByteStreams = false, compression = false) {
27085
27252
  if (v1Compat) {
27086
27253
  const str = stringify(value, getExternalReducers(global2, ops, runId, key, framedByteStreams));
@@ -27181,7 +27348,7 @@ async function dehydrateStepReturnValue(value, runId, key, ops = [], global2 = g
27181
27348
  }
27182
27349
  async function hydrateRunError(value, runId, key, ops = [], global2 = globalThis, extraRevivers = {}) {
27183
27350
  const compressionStats = {};
27184
- const decrypted = await decompress(await maybeDecrypt(value, key), compressionStats);
27351
+ const decrypted = await decompress(await decrypt2(value, key), compressionStats);
27185
27352
  await recordCompression(compressionStats, "deserialize");
27186
27353
  if (!(decrypted instanceof Uint8Array)) {
27187
27354
  return unflatten(decrypted, {
@@ -27458,6 +27625,16 @@ var init_serialization2 = __esm({
27458
27625
  for (const w of waiters) w.reject(abortError);
27459
27626
  }
27460
27627
  });
27628
+ Object.defineProperty(this, STREAM_WRITE_BATCH_SYMBOL, {
27629
+ value: /* @__PURE__ */ __name(async (chunks) => {
27630
+ if (chunks.length === 0) return;
27631
+ if (batchStartAt === void 0) batchStartAt = Date.now();
27632
+ for (const chunk of chunks) buffer2.push(chunk);
27633
+ await flush();
27634
+ }, "value"),
27635
+ enumerable: false,
27636
+ writable: false
27637
+ });
27461
27638
  }
27462
27639
  };
27463
27640
  __name(getAllBaseReducers, "getAllBaseReducers");
@@ -27476,7 +27653,6 @@ var init_serialization2 = __esm({
27476
27653
  __name(getForwardedWritableEncryptionKey, "getForwardedWritableEncryptionKey");
27477
27654
  __name(getExternalRevivers, "getExternalRevivers");
27478
27655
  __name(getStepRevivers, "getStepRevivers");
27479
- __name(maybeDecrypt, "maybeDecrypt");
27480
27656
  __name(dehydrateWorkflowArguments, "dehydrateWorkflowArguments");
27481
27657
  __name(hydrateWorkflowReturnValue, "hydrateWorkflowReturnValue");
27482
27658
  __name(dehydrateStepArguments, "dehydrateStepArguments");
@@ -27681,6 +27857,7 @@ __name(isRetryableWorldError, "isRetryableWorldError");
27681
27857
  init_encryption();
27682
27858
  init_logger();
27683
27859
  init_serialization2();
27860
+ init_context_storage();
27684
27861
  init_semantic_conventions();
27685
27862
  init_telemetry();
27686
27863
  init_version();
@@ -27690,6 +27867,16 @@ init_wait_until();
27690
27867
  init_world_compatibility();
27691
27868
  var CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS = 2e3;
27692
27869
  var ulid3 = monotonicFactory();
27870
+ function resolveLineageAttributes() {
27871
+ const store = contextStorage.getStore();
27872
+ const parentRunId = store?.workflowMetadata?.workflowRunId;
27873
+ if (!parentRunId) return void 0;
27874
+ return {
27875
+ [ROOT_RUN_ID_ATTRIBUTE]: store.rootRunId ?? parentRunId,
27876
+ [PARENT_RUN_ID_ATTRIBUTE]: parentRunId
27877
+ };
27878
+ }
27879
+ __name(resolveLineageAttributes, "resolveLineageAttributes");
27693
27880
  var hasWarnedLatestNoOp = false;
27694
27881
  async function start(workflow, argsOrOptions, options) {
27695
27882
  return await waitedUntil(() => {
@@ -27774,9 +27961,14 @@ async function start(workflow, argsOrOptions, options) {
27774
27961
  value
27775
27962
  ]));
27776
27963
  }
27777
- const attributeSeed = attributes ? {
27778
- attributes,
27779
- ...allowReservedAttributes ? {
27964
+ const lineage = specVersion >= SPEC_VERSION_SUPPORTS_ATTRIBUTES ? resolveLineageAttributes() : void 0;
27965
+ const runAttributes = lineage ? {
27966
+ ...lineage,
27967
+ ...attributes
27968
+ } : attributes;
27969
+ const attributeSeed = runAttributes ? {
27970
+ attributes: runAttributes,
27971
+ ...allowReservedAttributes || lineage != null ? {
27780
27972
  allowReservedAttributes: true
27781
27973
  } : {}
27782
27974
  } : {};
@@ -27890,7 +28082,7 @@ __name(start, "start");
27890
28082
  value: "start",
27891
28083
  configurable: true
27892
28084
  });
27893
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.34//start");
28085
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.36//start");
27894
28086
 
27895
28087
  // ../core/dist/runtime/runs.js
27896
28088
  async function wakeUpRun(world, runId, options) {
@@ -28226,7 +28418,7 @@ var Run = class _Run {
28226
28418
  value: "wakeUp",
28227
28419
  configurable: true
28228
28420
  });
28229
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#wakeUp");
28421
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#wakeUp");
28230
28422
  (function(__wf_fn, __wf_id) {
28231
28423
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28232
28424
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28235,7 +28427,7 @@ var Run = class _Run {
28235
28427
  value: "cancel",
28236
28428
  configurable: true
28237
28429
  });
28238
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#cancel");
28430
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#cancel");
28239
28431
  (function(__wf_fn, __wf_id) {
28240
28432
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28241
28433
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28244,7 +28436,7 @@ var Run = class _Run {
28244
28436
  value: "getReadable",
28245
28437
  configurable: true
28246
28438
  });
28247
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#getReadable");
28439
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#getReadable");
28248
28440
  (function(__wf_fn, __wf_id) {
28249
28441
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28250
28442
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28253,7 +28445,7 @@ var Run = class _Run {
28253
28445
  value: "exists",
28254
28446
  configurable: true
28255
28447
  });
28256
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#exists");
28448
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#exists");
28257
28449
  (function(__wf_fn, __wf_id) {
28258
28450
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28259
28451
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28262,7 +28454,7 @@ var Run = class _Run {
28262
28454
  value: "status",
28263
28455
  configurable: true
28264
28456
  });
28265
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#status");
28457
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#status");
28266
28458
  (function(__wf_fn, __wf_id) {
28267
28459
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28268
28460
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28271,7 +28463,7 @@ var Run = class _Run {
28271
28463
  value: "returnValue",
28272
28464
  configurable: true
28273
28465
  });
28274
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#returnValue");
28466
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#returnValue");
28275
28467
  (function(__wf_fn, __wf_id) {
28276
28468
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28277
28469
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28280,7 +28472,7 @@ var Run = class _Run {
28280
28472
  value: "workflowName",
28281
28473
  configurable: true
28282
28474
  });
28283
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#workflowName");
28475
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#workflowName");
28284
28476
  (function(__wf_fn, __wf_id) {
28285
28477
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28286
28478
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28289,7 +28481,7 @@ var Run = class _Run {
28289
28481
  value: "createdAt",
28290
28482
  configurable: true
28291
28483
  });
28292
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#createdAt");
28484
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#createdAt");
28293
28485
  (function(__wf_fn, __wf_id) {
28294
28486
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28295
28487
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28298,7 +28490,7 @@ var Run = class _Run {
28298
28490
  value: "startedAt",
28299
28491
  configurable: true
28300
28492
  });
28301
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#startedAt");
28493
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#startedAt");
28302
28494
  (function(__wf_fn, __wf_id) {
28303
28495
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28304
28496
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28307,7 +28499,7 @@ var Run = class _Run {
28307
28499
  value: "completedAt",
28308
28500
  configurable: true
28309
28501
  });
28310
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.34//Run#completedAt");
28502
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.36//Run#completedAt");
28311
28503
  (function(__wf_cls, __wf_id) {
28312
28504
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28313
28505
  __wf_reg.set(__wf_id, __wf_cls);
@@ -28317,7 +28509,7 @@ var Run = class _Run {
28317
28509
  enumerable: false,
28318
28510
  configurable: false
28319
28511
  });
28320
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.34//Run");
28512
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.36//Run");
28321
28513
 
28322
28514
  // ../workflow/dist/stdlib.js
28323
28515
  async function fetch2(...args) {
@@ -28359,6 +28551,26 @@ async function addTenWorkflow(input) {
28359
28551
  __name(addTenWorkflow, "addTenWorkflow");
28360
28552
  addTenWorkflow.workflowId = "workflow//./workflows/addition//addTenWorkflow";
28361
28553
 
28554
+ // workflows/event-limit.ts
28555
+ async function tick(i) {
28556
+ return i;
28557
+ }
28558
+ __name(tick, "tick");
28559
+ (function(__wf_fn, __wf_id) {
28560
+ var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28561
+ __wf_reg.set(__wf_id, __wf_fn);
28562
+ __wf_fn.stepId = __wf_id;
28563
+ Object.defineProperty(__wf_fn, "name", {
28564
+ value: "tick",
28565
+ configurable: true
28566
+ });
28567
+ })(tick, "step//./workflows/event-limit//tick");
28568
+ async function runawayWorkflow() {
28569
+ throw new Error("You attempted to execute workflow runawayWorkflow function directly. To start a workflow, use start(runawayWorkflow) from workflow/api");
28570
+ }
28571
+ __name(runawayWorkflow, "runawayWorkflow");
28572
+ runawayWorkflow.workflowId = "workflow//./workflows/event-limit//runawayWorkflow";
28573
+
28362
28574
  // ../core/dist/index.js
28363
28575
  init_dist2();
28364
28576
 
@@ -28676,13 +28888,52 @@ async function hookWorkflow(token) {
28676
28888
  __name(hookWorkflow, "hookWorkflow");
28677
28889
  hookWorkflow.workflowId = "workflow//./workflows/inline-execution//hookWorkflow";
28678
28890
 
28891
+ // workflows/lineage.ts
28892
+ async function noop() {
28893
+ }
28894
+ __name(noop, "noop");
28895
+ (function(__wf_fn, __wf_id) {
28896
+ var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28897
+ __wf_reg.set(__wf_id, __wf_fn);
28898
+ __wf_fn.stepId = __wf_id;
28899
+ Object.defineProperty(__wf_fn, "name", {
28900
+ value: "noop",
28901
+ configurable: true
28902
+ });
28903
+ })(noop, "step//./workflows/lineage//noop");
28904
+ async function bodyStartsChild() {
28905
+ throw new Error("You attempted to execute workflow bodyStartsChild function directly. To start a workflow, use start(bodyStartsChild) from workflow/api");
28906
+ }
28907
+ __name(bodyStartsChild, "bodyStartsChild");
28908
+ bodyStartsChild.workflowId = "workflow//./workflows/lineage//bodyStartsChild";
28909
+ async function spawnedChild() {
28910
+ throw new Error("You attempted to execute workflow spawnedChild function directly. To start a workflow, use start(spawnedChild) from workflow/api");
28911
+ }
28912
+ __name(spawnedChild, "spawnedChild");
28913
+ spawnedChild.workflowId = "workflow//./workflows/lineage//spawnedChild";
28914
+ async function chainRoot() {
28915
+ throw new Error("You attempted to execute workflow chainRoot function directly. To start a workflow, use start(chainRoot) from workflow/api");
28916
+ }
28917
+ __name(chainRoot, "chainRoot");
28918
+ chainRoot.workflowId = "workflow//./workflows/lineage//chainRoot";
28919
+ async function chainMiddle() {
28920
+ throw new Error("You attempted to execute workflow chainMiddle function directly. To start a workflow, use start(chainMiddle) from workflow/api");
28921
+ }
28922
+ __name(chainMiddle, "chainMiddle");
28923
+ chainMiddle.workflowId = "workflow//./workflows/lineage//chainMiddle";
28924
+ async function chainLeaf() {
28925
+ throw new Error("You attempted to execute workflow chainLeaf function directly. To start a workflow, use start(chainLeaf) from workflow/api");
28926
+ }
28927
+ __name(chainLeaf, "chainLeaf");
28928
+ chainLeaf.workflowId = "workflow//./workflows/lineage//chainLeaf";
28929
+
28679
28930
  // workflows/noop.ts
28680
28931
  var count = 0;
28681
- async function noop(_i) {
28932
+ async function noop2(_i) {
28682
28933
  count++;
28683
28934
  return count;
28684
28935
  }
28685
- __name(noop, "noop");
28936
+ __name(noop2, "noop");
28686
28937
  (function(__wf_fn, __wf_id) {
28687
28938
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
28688
28939
  __wf_reg.set(__wf_id, __wf_fn);
@@ -28691,7 +28942,7 @@ __name(noop, "noop");
28691
28942
  value: "noop",
28692
28943
  configurable: true
28693
28944
  });
28694
- })(noop, "step//./workflows/noop//noop");
28945
+ })(noop2, "step//./workflows/noop//noop");
28695
28946
  async function brokenWf() {
28696
28947
  throw new Error("You attempted to execute workflow brokenWf function directly. To start a workflow, use start(brokenWf) from workflow/api");
28697
28948
  }