@workflow/world-testing 5.0.3 → 5.0.4

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.
@@ -387,6 +387,16 @@ function createWorkflowUrl(baseUrl, route) {
387
387
  url3.hash = "";
388
388
  return url3.toString();
389
389
  }
390
+ function createAppRouteUrl(baseUrl, path16) {
391
+ if (!path16.startsWith("/")) {
392
+ throw new TypeError(`App route "${path16}" must start with "/"`);
393
+ }
394
+ const url3 = new URL(baseUrl);
395
+ url3.pathname = `${url3.pathname.replace(/\/+$/, "")}${path16}`;
396
+ url3.search = "";
397
+ url3.hash = "";
398
+ return url3.toString();
399
+ }
390
400
  function getWorkflowRouteEndpoint(route) {
391
401
  switch (route.type) {
392
402
  case "flow":
@@ -413,6 +423,7 @@ var init_workflow_routes = __esm({
413
423
  __name(getWorkflowBasePath, "getWorkflowBasePath");
414
424
  __name(createWorkflowBaseUrl, "createWorkflowBaseUrl");
415
425
  __name(createWorkflowUrl, "createWorkflowUrl");
426
+ __name(createAppRouteUrl, "createAppRouteUrl");
416
427
  __name(getWorkflowRouteEndpoint, "getWorkflowRouteEndpoint");
417
428
  __name(createWorkflowHealthEndpoint, "createWorkflowHealthEndpoint");
418
429
  }
@@ -20916,7 +20927,7 @@ function isChildEntityCreationEvent(event) {
20916
20927
  return true;
20917
20928
  return event.eventType === "step_started" && typeof event.eventData?.stepName === "string" && event.eventData.input !== void 0;
20918
20929
  }
20919
- 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, BaseEventSchema2, stepLatencyTelemetryFields2, StepCompletedEventSchema2, StepFailedEventSchema2, StepRetryingEventSchema2, StepStartedEventSchema2, StepCreatedEventSchema2, HookCreatedEventSchema2, HookReceivedEventSchema2, HookDisposedEventSchema2, HookConflictEventSchema2, NoopEventSchema2, WaitCreatedEventSchema2, WaitCompletedEventSchema2, AttributeWriterSchema2, AttrSetEventSchema2, RunCreatedEventSchema2, RunStartedEventSchema2, RunCompletedEventSchema2, RunFailedEventSchema2, RunCancelledEventSchema2, CreateEventSchema2, AllEventsSchema2, EventSchema2;
20930
+ 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, BaseEventSchema2, stepLatencyTelemetryFields2, StepCompletedEventSchema2, StepFailedEventSchema2, StepRetryingEventSchema2, StepStartedEventSchema2, StepCreatedEventSchema2, HookCreatedEventSchema2, HookReceivedEventSchema2, HookDisposedEventSchema2, HookConflictEventSchema2, NoopEventSchema2, WaitCreatedEventSchema2, WaitCompletedEventSchema2, AttributeWriterSchema2, AttrSetEventSchema2, RunCreatedEventSchema2, RunStartedEventSchema2, RunCompletedEventSchema2, RunFailedEventSchema2, RunCancelledEventSchema2, CreateEventSchema2, AllEventsSchema2, EventSchema2, IN_BAND_SEQ_AT_RUN_CREATION;
20920
20931
  var init_events2 = __esm({
20921
20932
  "../world/dist/events.js"() {
20922
20933
  "use strict";
@@ -21383,6 +21394,7 @@ var init_events2 = __esm({
21383
21394
  resumeId: external_exports2.string().optional()
21384
21395
  })));
21385
21396
  __name(isChildEntityCreationEvent, "isChildEntityCreationEvent");
21397
+ IN_BAND_SEQ_AT_RUN_CREATION = 1;
21386
21398
  }
21387
21399
  });
21388
21400
 
@@ -21855,6 +21867,19 @@ function getQueueTopicPrefix2(kind, namespace) {
21855
21867
  }
21856
21868
  return "__wkf_workflow_";
21857
21869
  }
21870
+ function parseQueueRoute(path16) {
21871
+ if (typeof path16 !== "string" || !path16.startsWith("/") || path16.startsWith("//") || /[?#\s]/.test(path16)) {
21872
+ throw new TypeError(`Invalid queue route "${String(path16)}": must be an absolute path such as "/api/agent/queue", without a query or fragment`);
21873
+ }
21874
+ return path16;
21875
+ }
21876
+ function getRunQueueNamespace(executionContext) {
21877
+ if (typeof executionContext !== "object" || executionContext === null || executionContext instanceof Uint8Array) {
21878
+ return void 0;
21879
+ }
21880
+ const namespace = executionContext.queueNamespace;
21881
+ return typeof namespace === "string" && QueueNamespace2.safeParse(namespace).success ? namespace : void 0;
21882
+ }
21858
21883
  function parseQueueName(name) {
21859
21884
  const match2 = name.match(/^(__(?:[a-z][a-z0-9]*_)?wkf_workflow_)(.+)$/);
21860
21885
  if (!match2) {
@@ -21865,7 +21890,7 @@ function parseQueueName(name) {
21865
21890
  id: match2[2]
21866
21891
  };
21867
21892
  }
21868
- var QueuePrefix2, ValidQueueName2, QueueNamespace2, MessageId2, TraceCarrierSchema2, RunInputSchema2, StepDispatchInputSchema2, RunDispatchContextSchema2, HookResumeInputSchema2, HookResumeTimingSchema2, WorkflowInvokePayloadSchema2, HealthCheckPayloadSchema2, QueuePayloadSchema2;
21893
+ var QueuePrefix2, ValidQueueName2, QueueNamespace2, WORKFLOW_FLOW_ROUTE, MessageId2, TraceCarrierSchema2, RunInputSchema2, StepDispatchInputSchema2, RunDispatchContextSchema2, HookResumeInputSchema2, HookResumeTimingSchema2, WorkflowInvokePayloadSchema2, HealthCheckPayloadSchema2, QueuePayloadSchema2;
21869
21894
  var init_queue2 = __esm({
21870
21895
  "../world/dist/queue.js"() {
21871
21896
  "use strict";
@@ -21876,6 +21901,9 @@ var init_queue2 = __esm({
21876
21901
  QueueNamespace2 = external_exports2.compile(external_exports2.string().regex(/^[a-z][a-z0-9]*$/, "Must be lowercase alphanumeric, starting with a letter"));
21877
21902
  __name(resolveQueueNamespace2, "resolveQueueNamespace");
21878
21903
  __name(getQueueTopicPrefix2, "getQueueTopicPrefix");
21904
+ WORKFLOW_FLOW_ROUTE = "/.well-known/workflow/v1/flow";
21905
+ __name(parseQueueRoute, "parseQueueRoute");
21906
+ __name(getRunQueueNamespace, "getRunQueueNamespace");
21879
21907
  __name(parseQueueName, "parseQueueName");
21880
21908
  MessageId2 = external_exports2.compile(external_exports2.string().brand().describe("A stored queue message ID"));
21881
21909
  TraceCarrierSchema2 = external_exports2.compile(external_exports2.record(external_exports2.string(), external_exports2.string()));
@@ -22235,7 +22263,8 @@ var init_node_http_flag2 = __esm({
22235
22263
 
22236
22264
  // ../world/dist/recovery.js
22237
22265
  async function reenqueueActiveRuns(runs, enqueue, label, namespace) {
22238
- const workflowQueuePrefix = getQueueTopicPrefix2("workflow", resolveQueueNamespace2(namespace));
22266
+ const defaultNamespace = resolveQueueNamespace2(namespace);
22267
+ getQueueTopicPrefix2("workflow", defaultNamespace);
22239
22268
  let reenqueued = 0;
22240
22269
  let cursor;
22241
22270
  let hasMore = true;
@@ -22247,7 +22276,8 @@ async function reenqueueActiveRuns(runs, enqueue, label, namespace) {
22247
22276
  });
22248
22277
  for (const run3 of page.data) {
22249
22278
  try {
22250
- const queueName = `${workflowQueuePrefix}${run3.workflowName}`;
22279
+ const prefix = getQueueTopicPrefix2("workflow", getRunQueueNamespace(run3.executionContext) ?? defaultNamespace);
22280
+ const queueName = `${prefix}${run3.workflowName}`;
22251
22281
  await enqueue(queueName, { runId: run3.runId });
22252
22282
  reenqueued++;
22253
22283
  } catch (err) {
@@ -22829,6 +22859,7 @@ __export(dist_exports, {
22829
22859
  HookCreatedEventSchema: () => HookCreatedEventSchema2,
22830
22860
  HookResumeCapabilitiesSchema: () => HookResumeCapabilitiesSchema2,
22831
22861
  HookSchema: () => HookSchema2,
22862
+ IN_BAND_SEQ_AT_RUN_CREATION: () => IN_BAND_SEQ_AT_RUN_CREATION,
22832
22863
  LegacySerializedDataSchemaV1: () => LegacySerializedDataSchemaV12,
22833
22864
  MAX_EVENT_SLOT: () => MAX_EVENT_SLOT2,
22834
22865
  MessageId: () => MessageId2,
@@ -22875,6 +22906,7 @@ __export(dist_exports, {
22875
22906
  TerminalWorkflowRunStatusSchema: () => TerminalWorkflowRunStatusSchema2,
22876
22907
  ValidQueueName: () => ValidQueueName2,
22877
22908
  WAIT_EVENT_TYPES: () => WAIT_EVENT_TYPES2,
22909
+ WORKFLOW_FLOW_ROUTE: () => WORKFLOW_FLOW_ROUTE,
22878
22910
  WaitSchema: () => WaitSchema2,
22879
22911
  WaitStatusSchema: () => WaitStatusSchema2,
22880
22912
  WorkflowInvokePayloadSchema: () => WorkflowInvokePayloadSchema2,
@@ -22896,6 +22928,7 @@ __export(dist_exports, {
22896
22928
  getEventDataRefFields: () => getEventDataRefFields,
22897
22929
  getMaxEventsPerRun: () => getMaxEventsPerRun,
22898
22930
  getQueueTopicPrefix: () => getQueueTopicPrefix2,
22931
+ getRunQueueNamespace: () => getRunQueueNamespace,
22899
22932
  isChildEntityCreationEvent: () => isChildEntityCreationEvent,
22900
22933
  isChildEntityCreationEventType: () => isChildEntityCreationEventType,
22901
22934
  isHookEventRequiringExistence: () => isHookEventRequiringExistence,
@@ -22914,6 +22947,7 @@ __export(dist_exports, {
22914
22947
  isWaitEventType: () => isWaitEventType,
22915
22948
  mintedSpecVersion: () => mintedSpecVersion,
22916
22949
  parseQueueName: () => parseQueueName,
22950
+ parseQueueRoute: () => parseQueueRoute,
22917
22951
  purgesUserDataOnFinish: () => purgesUserDataOnFinish,
22918
22952
  readRunRetention: () => readRunRetention,
22919
22953
  reenqueueActiveRuns: () => reenqueueActiveRuns,
@@ -23008,7 +23042,7 @@ function buildFramedDetails2(hint3, slug) {
23008
23042
  out.push({ label: "docs", value: `${BASE_URL2}/${slug}` });
23009
23043
  return out;
23010
23044
  }
23011
- var BASE_URL2, ERROR_SLUGS2, WorkflowError2, WorkflowWorldError2, WorkflowRunFailedError2, WorkflowRunNotCompletedError2, WorkflowRuntimeError2, CorruptedEventLogError, ReplayDivergenceError, MaxEventsExceededError, RuntimeDecryptionError2, SerializationError2, StepNotRegisteredError2, WorkflowNotRegisteredError2, WorkflowDeploymentMismatchError, WorkflowRunNotFoundError2, HookConflictError2, HookForceClaimedError2, HookNotFoundError2, EntityConflictError2, RunExpiredError2, StreamError2, StreamExpiredError2, TooEarlyError, ThrottleError2, PreconditionFailedError, WorkflowRunCancelledError2, RunNotSupportedError, FatalError2, RetryableError2, FATAL_ERROR_KEY2, RETRYABLE_ERROR_KEY2, HOOK_CONFLICT_ERROR_KEY2, HOOK_FORCE_CLAIMED_ERROR_KEY2, RUNTIME_DECRYPTION_ERROR_KEY2, STREAM_ERROR_KEY2;
23045
+ var BASE_URL2, ERROR_SLUGS2, WorkflowError2, WorkflowWorldError2, WorkflowRunFailedError2, WorkflowRunNotCompletedError2, WorkflowRuntimeError2, CorruptedEventLogError, ReplayDivergenceError, MaxEventsExceededError, RuntimeDecryptionError2, SerializationError2, StepNotRegisteredError2, WorkflowNotRegisteredError2, WorkflowDeploymentMismatchError, WorkflowRunNotFoundError2, HookConflictError2, HookForceClaimedError2, HookNotFoundError2, EntityConflictError2, RunExpiredError2, StreamError2, StreamExpiredError2, TooEarlyError, ThrottleError2, PreconditionFailedError, IN_BAND_SUPERSEDED_CODE, InBandSupersededError, WorkflowRunCancelledError2, RunNotSupportedError, FatalError2, RetryableError2, FATAL_ERROR_KEY2, RETRYABLE_ERROR_KEY2, HOOK_CONFLICT_ERROR_KEY2, HOOK_FORCE_CLAIMED_ERROR_KEY2, RUNTIME_DECRYPTION_ERROR_KEY2, STREAM_ERROR_KEY2;
23012
23046
  var init_dist7 = __esm({
23013
23047
  "../errors/dist/index.js"() {
23014
23048
  "use strict";
@@ -23474,6 +23508,23 @@ Caused by: ${options.cause.stack}`;
23474
23508
  return isError2(value) && value.name === "PreconditionFailedError";
23475
23509
  }
23476
23510
  };
23511
+ IN_BAND_SUPERSEDED_CODE = "in-band-superseded";
23512
+ InBandSupersededError = class extends WorkflowWorldError2 {
23513
+ static {
23514
+ __name(this, "InBandSupersededError");
23515
+ }
23516
+ seq;
23517
+ seqInBand;
23518
+ constructor(message, options) {
23519
+ super(message, { status: 412, code: IN_BAND_SUPERSEDED_CODE });
23520
+ this.name = "InBandSupersededError";
23521
+ this.seq = options?.seq;
23522
+ this.seqInBand = options?.seqInBand;
23523
+ }
23524
+ static is(value) {
23525
+ return isError2(value) && value.name === "InBandSupersededError";
23526
+ }
23527
+ };
23477
23528
  WorkflowRunCancelledError2 = class extends WorkflowError2 {
23478
23529
  static {
23479
23530
  __name(this, "WorkflowRunCancelledError");
@@ -23899,10 +23950,30 @@ function once3(fn) {
23899
23950
  };
23900
23951
  return result2;
23901
23952
  }
23953
+ function withInProcessLock(locks, key, fn) {
23954
+ const prev = locks.get(key);
23955
+ const taskBox = {};
23956
+ const task = (async () => {
23957
+ if (prev) {
23958
+ await prev.catch(() => void 0);
23959
+ }
23960
+ try {
23961
+ return await fn();
23962
+ } finally {
23963
+ if (locks.get(key) === taskBox.task) {
23964
+ locks.delete(key);
23965
+ }
23966
+ }
23967
+ })();
23968
+ taskBox.task = task;
23969
+ locks.set(key, task);
23970
+ return task;
23971
+ }
23902
23972
  var init_util4 = __esm({
23903
23973
  "../world-local/dist/util.js"() {
23904
23974
  "use strict";
23905
23975
  __name(once3, "once");
23976
+ __name(withInProcessLock, "withInProcessLock");
23906
23977
  }
23907
23978
  });
23908
23979
 
@@ -25865,70 +25936,70 @@ var require_lockfile = __commonJS({
25865
25936
  }
25866
25937
  __name(removeLock, "removeLock");
25867
25938
  function updateLock(file3, options) {
25868
- const lock3 = locks[file3];
25869
- if (lock3.updateTimeout) {
25939
+ const lock4 = locks[file3];
25940
+ if (lock4.updateTimeout) {
25870
25941
  return;
25871
25942
  }
25872
- lock3.updateDelay = lock3.updateDelay || options.update;
25873
- lock3.updateTimeout = setTimeout(() => {
25874
- lock3.updateTimeout = null;
25875
- options.fs.stat(lock3.lockfilePath, (err, stat) => {
25876
- const isOverThreshold = lock3.lastUpdate + options.stale < Date.now();
25943
+ lock4.updateDelay = lock4.updateDelay || options.update;
25944
+ lock4.updateTimeout = setTimeout(() => {
25945
+ lock4.updateTimeout = null;
25946
+ options.fs.stat(lock4.lockfilePath, (err, stat) => {
25947
+ const isOverThreshold = lock4.lastUpdate + options.stale < Date.now();
25877
25948
  if (err) {
25878
25949
  if (err.code === "ENOENT" || isOverThreshold) {
25879
- return setLockAsCompromised(file3, lock3, Object.assign(err, { code: "ECOMPROMISED" }));
25950
+ return setLockAsCompromised(file3, lock4, Object.assign(err, { code: "ECOMPROMISED" }));
25880
25951
  }
25881
- lock3.updateDelay = 1e3;
25952
+ lock4.updateDelay = 1e3;
25882
25953
  return updateLock(file3, options);
25883
25954
  }
25884
- const isMtimeOurs = lock3.mtime.getTime() === stat.mtime.getTime();
25955
+ const isMtimeOurs = lock4.mtime.getTime() === stat.mtime.getTime();
25885
25956
  if (!isMtimeOurs) {
25886
25957
  return setLockAsCompromised(
25887
25958
  file3,
25888
- lock3,
25959
+ lock4,
25889
25960
  Object.assign(
25890
25961
  new Error("Unable to update lock within the stale threshold"),
25891
25962
  { code: "ECOMPROMISED" }
25892
25963
  )
25893
25964
  );
25894
25965
  }
25895
- const mtime = mtimePrecision.getMtime(lock3.mtimePrecision);
25896
- options.fs.utimes(lock3.lockfilePath, mtime, mtime, (err2) => {
25897
- const isOverThreshold2 = lock3.lastUpdate + options.stale < Date.now();
25898
- if (lock3.released) {
25966
+ const mtime = mtimePrecision.getMtime(lock4.mtimePrecision);
25967
+ options.fs.utimes(lock4.lockfilePath, mtime, mtime, (err2) => {
25968
+ const isOverThreshold2 = lock4.lastUpdate + options.stale < Date.now();
25969
+ if (lock4.released) {
25899
25970
  return;
25900
25971
  }
25901
25972
  if (err2) {
25902
25973
  if (err2.code === "ENOENT" || isOverThreshold2) {
25903
- return setLockAsCompromised(file3, lock3, Object.assign(err2, { code: "ECOMPROMISED" }));
25974
+ return setLockAsCompromised(file3, lock4, Object.assign(err2, { code: "ECOMPROMISED" }));
25904
25975
  }
25905
- lock3.updateDelay = 1e3;
25976
+ lock4.updateDelay = 1e3;
25906
25977
  return updateLock(file3, options);
25907
25978
  }
25908
- lock3.mtime = mtime;
25909
- lock3.lastUpdate = Date.now();
25910
- lock3.updateDelay = null;
25979
+ lock4.mtime = mtime;
25980
+ lock4.lastUpdate = Date.now();
25981
+ lock4.updateDelay = null;
25911
25982
  updateLock(file3, options);
25912
25983
  });
25913
25984
  });
25914
- }, lock3.updateDelay);
25915
- if (lock3.updateTimeout.unref) {
25916
- lock3.updateTimeout.unref();
25985
+ }, lock4.updateDelay);
25986
+ if (lock4.updateTimeout.unref) {
25987
+ lock4.updateTimeout.unref();
25917
25988
  }
25918
25989
  }
25919
25990
  __name(updateLock, "updateLock");
25920
- function setLockAsCompromised(file3, lock3, err) {
25921
- lock3.released = true;
25922
- if (lock3.updateTimeout) {
25923
- clearTimeout(lock3.updateTimeout);
25991
+ function setLockAsCompromised(file3, lock4, err) {
25992
+ lock4.released = true;
25993
+ if (lock4.updateTimeout) {
25994
+ clearTimeout(lock4.updateTimeout);
25924
25995
  }
25925
- if (locks[file3] === lock3) {
25996
+ if (locks[file3] === lock4) {
25926
25997
  delete locks[file3];
25927
25998
  }
25928
- lock3.options.onCompromised(err);
25999
+ lock4.options.onCompromised(err);
25929
26000
  }
25930
26001
  __name(setLockAsCompromised, "setLockAsCompromised");
25931
- function lock2(file3, options, callback) {
26002
+ function lock3(file3, options, callback) {
25932
26003
  options = {
25933
26004
  stale: 1e4,
25934
26005
  update: null,
@@ -25958,7 +26029,7 @@ var require_lockfile = __commonJS({
25958
26029
  if (err2) {
25959
26030
  return callback(operation.mainError());
25960
26031
  }
25961
- const lock3 = locks[file4] = {
26032
+ const lock4 = locks[file4] = {
25962
26033
  lockfilePath: getLockFile(file4, options),
25963
26034
  mtime,
25964
26035
  mtimePrecision: mtimePrecision2,
@@ -25967,7 +26038,7 @@ var require_lockfile = __commonJS({
25967
26038
  };
25968
26039
  updateLock(file4, options);
25969
26040
  callback(null, (releasedCallback) => {
25970
- if (lock3.released) {
26041
+ if (lock4.released) {
25971
26042
  return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
25972
26043
  }
25973
26044
  unlock(file4, { ...options, realpath: false }, releasedCallback);
@@ -25976,7 +26047,7 @@ var require_lockfile = __commonJS({
25976
26047
  });
25977
26048
  });
25978
26049
  }
25979
- __name(lock2, "lock");
26050
+ __name(lock3, "lock");
25980
26051
  function unlock(file3, options, callback) {
25981
26052
  options = {
25982
26053
  fs: fs10,
@@ -25987,12 +26058,12 @@ var require_lockfile = __commonJS({
25987
26058
  if (err) {
25988
26059
  return callback(err);
25989
26060
  }
25990
- const lock3 = locks[file4];
25991
- if (!lock3) {
26061
+ const lock4 = locks[file4];
26062
+ if (!lock4) {
25992
26063
  return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
25993
26064
  }
25994
- lock3.updateTimeout && clearTimeout(lock3.updateTimeout);
25995
- lock3.released = true;
26065
+ lock4.updateTimeout && clearTimeout(lock4.updateTimeout);
26066
+ lock4.released = true;
25996
26067
  delete locks[file4];
25997
26068
  removeLock(file4, options, callback);
25998
26069
  });
@@ -26032,7 +26103,7 @@ var require_lockfile = __commonJS({
26032
26103
  }
26033
26104
  }
26034
26105
  });
26035
- module.exports.lock = lock2;
26106
+ module.exports.lock = lock3;
26036
26107
  module.exports.unlock = unlock;
26037
26108
  module.exports.check = check3;
26038
26109
  module.exports.getLocks = getLocks;
@@ -26114,11 +26185,11 @@ var require_proper_lockfile = __commonJS({
26114
26185
  "use strict";
26115
26186
  var lockfile = require_lockfile();
26116
26187
  var { toPromise, toSync, toSyncOptions } = require_adapter();
26117
- async function lock2(file3, options) {
26188
+ async function lock3(file3, options) {
26118
26189
  const release = await toPromise(lockfile.lock)(file3, options);
26119
26190
  return toPromise(release);
26120
26191
  }
26121
- __name(lock2, "lock");
26192
+ __name(lock3, "lock");
26122
26193
  function lockSync(file3, options) {
26123
26194
  const release = toSync(lockfile.lock)(file3, toSyncOptions(options));
26124
26195
  return toSync(release);
@@ -26140,8 +26211,8 @@ var require_proper_lockfile = __commonJS({
26140
26211
  return toSync(lockfile.check)(file3, toSyncOptions(options));
26141
26212
  }
26142
26213
  __name(checkSync, "checkSync");
26143
- module.exports = lock2;
26144
- module.exports.lock = lock2;
26214
+ module.exports = lock3;
26215
+ module.exports.lock = lock3;
26145
26216
  module.exports.unlock = unlock;
26146
26217
  module.exports.lockSync = lockSync;
26147
26218
  module.exports.unlockSync = unlockSync;
@@ -26822,17 +26893,15 @@ async function inspectEntityDirs(dataDir) {
26822
26893
  runScoped: false
26823
26894
  };
26824
26895
  for (const entityDir of RUN_SCOPED_ENTITY_DIRS) {
26825
- let dir;
26826
26896
  try {
26827
- dir = await opendir(path5.join(dataDir, entityDir));
26897
+ for await (const entry of await opendir(path5.join(dataDir, entityDir))) {
26898
+ classifyEntityDirEntry(layout, entityDir, entry);
26899
+ }
26828
26900
  } catch (error121) {
26829
26901
  if (error121.code === "ENOENT")
26830
26902
  continue;
26831
26903
  throw error121;
26832
26904
  }
26833
- for await (const entry of dir) {
26834
- classifyEntityDirEntry(layout, entityDir, entry);
26835
- }
26836
26905
  }
26837
26906
  return layout;
26838
26907
  }
@@ -56185,6 +56254,11 @@ function createQueue(config4) {
56185
56254
  const closeSignal = closeController.signal;
56186
56255
  const inflightMessages = /* @__PURE__ */ new Map();
56187
56256
  const directHandlers = /* @__PURE__ */ new Map();
56257
+ const routes = /* @__PURE__ */ new Map();
56258
+ const deliveryUrl = /* @__PURE__ */ __name((baseUrl, prefix) => {
56259
+ const route = routes.get(prefix);
56260
+ return route ? createAppRouteUrl(baseUrl, route) : createWorkflowUrl(baseUrl, { type: "flow" });
56261
+ }, "deliveryUrl");
56188
56262
  const queue = /* @__PURE__ */ __name(async (queueName, message, opts) => {
56189
56263
  const cleanup = [];
56190
56264
  if (opts?.idempotencyKey) {
@@ -56196,6 +56270,7 @@ function createQueue(config4) {
56196
56270
  const body = transport.serialize(message);
56197
56271
  const { prefix } = parseQueueName(queueName);
56198
56272
  const messageId = MessageId2.parse(`msg_${generateId3()}`);
56273
+ const createdAt = (/* @__PURE__ */ new Date()).toISOString();
56199
56274
  const msg = message;
56200
56275
  const runId = msg.runId ?? void 0;
56201
56276
  const stepId = msg.stepId ?? void 0;
@@ -56225,20 +56300,19 @@ function createQueue(config4) {
56225
56300
  "content-type": "application/json",
56226
56301
  "x-vqs-queue-name": queueName,
56227
56302
  "x-vqs-message-id": messageId,
56228
- "x-vqs-message-attempt": String(delivery + 1)
56303
+ "x-vqs-message-attempt": String(delivery + 1),
56304
+ "x-vqs-message-created-at": createdAt
56229
56305
  };
56230
56306
  const directHandler = directHandlers.get(prefix);
56231
56307
  let response;
56232
56308
  let text;
56233
56309
  try {
56234
56310
  if (directHandler) {
56235
- const req = new Request(createWorkflowUrl(resolveDirectBaseUrl(config4), {
56236
- type: "flow"
56237
- }), { method: "POST", headers, body });
56311
+ const req = new Request(deliveryUrl(resolveDirectBaseUrl(config4), prefix), { method: "POST", headers, body });
56238
56312
  response = await directHandler(req);
56239
56313
  } else {
56240
56314
  const baseUrl = await resolveBaseUrl(config4);
56241
- const url3 = createWorkflowUrl(baseUrl, { type: "flow" });
56315
+ const url3 = deliveryUrl(baseUrl, prefix);
56242
56316
  response = nodeHttpAgents ? await nodeHttpFetch(url3, {
56243
56317
  method: "POST",
56244
56318
  headers: new Headers(headers),
@@ -56299,7 +56373,10 @@ function createQueue(config4) {
56299
56373
  messageId,
56300
56374
  ...runId && { runId },
56301
56375
  ...stepId && { stepId },
56302
- handlerError: text
56376
+ handlerError: text,
56377
+ ...!directHandler && !routes.has(prefix) && (response.status === 400 || response.status === 404) && {
56378
+ hint: `No route or handler is registered for queue prefix "${prefix}", so its messages go to the Workflow SDK's flow route (${WORKFLOW_FLOW_ROUTE}). A queue consumer of its own registers one with world.registerRoute(prefix, path) or world.registerHandler(prefix, handler).`
56379
+ }
56303
56380
  });
56304
56381
  await setTimeout2(5e3, void 0, { signal: closeSignal });
56305
56382
  }
@@ -56337,7 +56414,11 @@ function createQueue(config4) {
56337
56414
  const HeaderParser = external_exports2.compile(external_exports2.object({
56338
56415
  "x-vqs-queue-name": ValidQueueName2,
56339
56416
  "x-vqs-message-id": MessageId2,
56340
- "x-vqs-message-attempt": external_exports2.coerce.number()
56417
+ "x-vqs-message-attempt": external_exports2.coerce.number(),
56418
+ // Sent by world-postgres, whose `attempt` restarts on a reschedule.
56419
+ "x-vqs-message-delivery-count": external_exports2.coerce.number().int().positive().optional(),
56420
+ // Absent on a delivery from a sender that predates it.
56421
+ "x-vqs-message-created-at": external_exports2.iso.datetime().optional()
56341
56422
  }));
56342
56423
  const createQueueHandler = /* @__PURE__ */ __name((prefix, handler) => {
56343
56424
  return async (req) => {
@@ -56350,12 +56431,25 @@ function createQueue(config4) {
56350
56431
  const queueName = headers.data["x-vqs-queue-name"];
56351
56432
  const messageId = headers.data["x-vqs-message-id"];
56352
56433
  const attempt = headers.data["x-vqs-message-attempt"];
56434
+ const deliveryCountHeader = headers.data["x-vqs-message-delivery-count"];
56435
+ const createdAtHeader = headers.data["x-vqs-message-created-at"];
56353
56436
  if (!queueName.startsWith(prefix)) {
56354
- return Response.json({ error: "Unhandled queue" }, { status: 400 });
56437
+ return Response.json({
56438
+ error: "Unhandled queue",
56439
+ detail: `This route handles queue prefix "${prefix}", not "${queueName}".`
56440
+ }, { status: 400 });
56355
56441
  }
56356
56442
  const body = await new TypedJsonTransport().deserialize(req.body);
56357
56443
  try {
56358
- const result2 = await handler(body, { attempt, queueName, messageId });
56444
+ const result2 = await handler(body, {
56445
+ attempt,
56446
+ // Counts every delivery of this message that reached a handler,
56447
+ // starting at 1, including `{ timeoutSeconds }` redeliveries.
56448
+ deliveryCount: deliveryCountHeader ?? attempt,
56449
+ ...createdAtHeader ? { createdAt: new Date(createdAtHeader) } : {},
56450
+ queueName,
56451
+ messageId
56452
+ });
56359
56453
  if (typeof body === "object" && body !== null && "invoke" in body && body.invoke === true) {
56360
56454
  return Response.json({ result: result2 });
56361
56455
  }
@@ -56383,6 +56477,9 @@ function createQueue(config4) {
56383
56477
  registerHandler(prefix, handler) {
56384
56478
  directHandlers.set(prefix, handler);
56385
56479
  },
56480
+ registerRoute(prefix, path16) {
56481
+ routes.set(QueuePrefix2.parse(prefix), parseQueueRoute(path16));
56482
+ },
56386
56483
  async close() {
56387
56484
  if (closeSignal.aborted)
56388
56485
  return;
@@ -56566,8 +56663,8 @@ function createHooksStorage(basedir, tag) {
56566
56663
  }
56567
56664
  __name(isHookAvailable, "isHookAvailable");
56568
56665
  async function isForceDisposed(hook) {
56569
- const lock2 = await readHookDisposeLock(basedir, hook.hookId, tag);
56570
- return lock2.committed && lock2.forceClaimedBy !== void 0;
56666
+ const lock3 = await readHookDisposeLock(basedir, hook.hookId, tag);
56667
+ return lock3.committed && lock3.forceClaimedBy !== void 0;
56571
56668
  }
56572
56669
  __name(isForceDisposed, "isForceDisposed");
56573
56670
  async function findHookByToken(token) {
@@ -56809,23 +56906,69 @@ function createStreamer(basedir, tag) {
56809
56906
  const tagSuffix = tag ? `.${tag}` : "";
56810
56907
  const streamEmitter = new EventEmitter();
56811
56908
  const registeredStreams = /* @__PURE__ */ new Set();
56812
- async function registerStreamForRun(runId, streamName) {
56909
+ const runStreamsLocks = /* @__PURE__ */ new Map();
56910
+ let warnedRunStreamsLockFailure = false;
56911
+ async function readRunStreams(runId) {
56912
+ const data3 = await readJSONWithFallback(basedir, "streams/runs", runId, RunStreamsSchema, tag);
56913
+ return data3?.streams ?? [];
56914
+ }
56915
+ __name(readRunStreams, "readRunStreams");
56916
+ async function registerStreamForRun(runId, streamName, { verify = false } = {}) {
56813
56917
  assertSafeEntityId("runId", runId);
56814
56918
  assertSafeEntityId("streamName", streamName);
56815
56919
  const cacheKey = `${runId}:${streamName}`;
56816
56920
  if (registeredStreams.has(cacheKey)) {
56817
- return;
56921
+ if (!verify)
56922
+ return;
56923
+ const listed = await readRunStreams(runId).catch(() => null);
56924
+ if (listed === null || listed.includes(streamName))
56925
+ return;
56926
+ registeredStreams.delete(cacheKey);
56818
56927
  }
56819
56928
  const runStreamsPath = taggedPath(basedir, "streams/runs", runId, tag);
56820
- const existing = await readJSONWithFallback(basedir, "streams/runs", runId, RunStreamsSchema, tag);
56821
- const streams = existing?.streams ?? [];
56822
- if (!streams.includes(streamName)) {
56823
- streams.push(streamName);
56824
- await writeJSON(runStreamsPath, { streams }, { overwrite: true });
56825
- }
56826
- registeredStreams.add(cacheKey);
56929
+ await withInProcessLock(runStreamsLocks, runStreamsPath, async () => {
56930
+ if (registeredStreams.has(cacheKey))
56931
+ return;
56932
+ if (await addToRunStreams(runStreamsPath, runId, streamName)) {
56933
+ registeredStreams.add(cacheKey);
56934
+ }
56935
+ });
56827
56936
  }
56828
56937
  __name(registerStreamForRun, "registerStreamForRun");
56938
+ async function addToRunStreams(runStreamsPath, runId, streamName) {
56939
+ await fs4.mkdir(path7.dirname(runStreamsPath), { recursive: true });
56940
+ let compromised = false;
56941
+ let release;
56942
+ try {
56943
+ release = await (0, import_proper_lockfile2.lock)(runStreamsPath, {
56944
+ ...RUN_STREAMS_LOCK_OPTIONS,
56945
+ // The default handler throws from a timer, which would crash the
56946
+ // process.
56947
+ onCompromised: /* @__PURE__ */ __name(() => {
56948
+ compromised = true;
56949
+ }, "onCompromised")
56950
+ });
56951
+ } catch (error121) {
56952
+ if (!warnedRunStreamsLockFailure) {
56953
+ warnedRunStreamsLockFailure = true;
56954
+ console.warn(`[world-local] Could not lock the stream index of run ${runId}; updating it without the lock:`, error121 instanceof Error ? error121.message : error121);
56955
+ }
56956
+ }
56957
+ try {
56958
+ const streams = await readRunStreams(runId);
56959
+ if (!streams.includes(streamName)) {
56960
+ streams.push(streamName);
56961
+ await writeJSON(runStreamsPath, { streams }, { overwrite: true });
56962
+ }
56963
+ } finally {
56964
+ if (release && !compromised) {
56965
+ await release().catch(() => {
56966
+ });
56967
+ }
56968
+ }
56969
+ return !compromised;
56970
+ }
56971
+ __name(addToRunStreams, "addToRunStreams");
56829
56972
  function toBuffer(chunk) {
56830
56973
  if (typeof chunk === "string") {
56831
56974
  return Buffer.from(new TextEncoder().encode(chunk));
@@ -56837,6 +56980,9 @@ function createStreamer(basedir, tag) {
56837
56980
  }
56838
56981
  __name(toBuffer, "toBuffer");
56839
56982
  return {
56983
+ clearCache() {
56984
+ registeredStreams.clear();
56985
+ },
56840
56986
  streams: {
56841
56987
  async write(_runId, name, chunk) {
56842
56988
  const chunkId = `chnk_${monotonicUlid2()}`;
@@ -56888,15 +57034,14 @@ function createStreamer(basedir, tag) {
56888
57034
  async close(_runId, name) {
56889
57035
  const chunkId = `chnk_${monotonicUlid2()}`;
56890
57036
  const runId = await _runId;
56891
- await registerStreamForRun(runId, name);
57037
+ await registerStreamForRun(runId, name, { verify: true });
56892
57038
  const chunkPath = path7.join(chunkDirForStream(path7.join(basedir, "streams", "chunks"), name), `${chunkId}${tagSuffix}.bin`);
56893
57039
  await write(chunkPath, serializeChunk({ chunk: Buffer.from([]), eof: true }));
56894
57040
  streamEmitter.emit(`close:${name}`, { streamName: name });
56895
57041
  },
56896
57042
  async list(runId) {
56897
57043
  assertSafeEntityId("runId", runId);
56898
- const data3 = await readJSONWithFallback(basedir, "streams/runs", runId, RunStreamsSchema, tag);
56899
- return data3?.streams ?? [];
57044
+ return readRunStreams(runId);
56900
57045
  },
56901
57046
  async getChunks(_runId, name, options) {
56902
57047
  const limit = options?.limit ?? 100;
@@ -57124,19 +57269,26 @@ function createStreamer(basedir, tag) {
57124
57269
  }
57125
57270
  };
57126
57271
  }
57127
- var chunkIds, monotonicUlid2, RunStreamsSchema, EOF_MARKER, PURGED_STREAM_TOMBSTONE_ID;
57272
+ var import_proper_lockfile2, chunkIds, monotonicUlid2, RunStreamsSchema, RUN_STREAMS_LOCK_OPTIONS, EOF_MARKER, PURGED_STREAM_TOMBSTONE_ID;
57128
57273
  var init_streamer = __esm({
57129
57274
  "../world-local/dist/streamer.js"() {
57130
57275
  "use strict";
57131
57276
  init_dist5();
57277
+ import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
57132
57278
  init_node2();
57133
57279
  init_zod2();
57134
57280
  init_fs();
57281
+ init_util4();
57135
57282
  chunkIds = globalSingleton2("@workflow/world-local//streamerMonotonicUlid", 1, () => ({ next: monotonicFactory2(() => Math.random()) }));
57136
57283
  monotonicUlid2 = /* @__PURE__ */ __name((seedTime) => chunkIds.next(seedTime), "monotonicUlid");
57137
57284
  RunStreamsSchema = external_exports2.compile(external_exports2.object({
57138
57285
  streams: external_exports2.array(external_exports2.string())
57139
57286
  }));
57287
+ RUN_STREAMS_LOCK_OPTIONS = {
57288
+ realpath: false,
57289
+ stale: 1e4,
57290
+ retries: { retries: 150, factor: 1, minTimeout: 100, maxTimeout: 100 }
57291
+ };
57140
57292
  EOF_MARKER = 1;
57141
57293
  __name(isEofByte, "isEofByte");
57142
57294
  __name(serializeChunk, "serializeChunk");
@@ -57671,24 +57823,12 @@ async function pinCanonicalEventIdForLegacyClaim(basedir, token, runId, hookId,
57671
57823
  const existing = await readHookRecoveryMarker(markerPath);
57672
57824
  return existing?.eventId ?? null;
57673
57825
  }
57674
- function withInProcessLock(locks, key, fn) {
57675
- const prev = locks.get(key);
57676
- const taskBox = {};
57677
- const task = (async () => {
57678
- if (prev) {
57679
- await prev.catch(() => void 0);
57680
- }
57681
- try {
57682
- return await fn();
57683
- } finally {
57684
- if (locks.get(key) === taskBox.task) {
57685
- locks.delete(key);
57686
- }
57687
- }
57688
- })();
57689
- taskBox.task = task;
57690
- locks.set(key, task);
57691
- return task;
57826
+ function isDefinitiveRefusal(error121) {
57827
+ if (EntityConflictError2.is(error121) || RunExpiredError2.is(error121) || TooEarlyError.is(error121) || HookNotFoundError2.is(error121) || HookForceClaimedError2.is(error121) || WorkflowRunNotFoundError2.is(error121) || RunNotSupportedError.is(error121)) {
57828
+ return true;
57829
+ }
57830
+ const status = error121?.status;
57831
+ return typeof status === "number" && status >= 400 && status < 500;
57692
57832
  }
57693
57833
  async function deleteAllWaitsForRun(basedir, runId) {
57694
57834
  const waitsDir = path10.join(basedir, "waits");
@@ -57718,6 +57858,15 @@ async function writeRunUnderLifecycleLock(basedir, runId, tag, proposed) {
57718
57858
  return { run: next2, purged };
57719
57859
  });
57720
57860
  }
57861
+ function inBandFenceState() {
57862
+ return globalSingleton2("@workflow/world-local//inBandFence", 2, () => ({
57863
+ locks: /* @__PURE__ */ new Map()
57864
+ }));
57865
+ }
57866
+ function inBandCountPath(basedir, runId, tag) {
57867
+ const name = tag ? `${runId}.in-band.${tag}` : `${runId}.in-band`;
57868
+ return resolveWithinBase(basedir, ".locks", "runs", name);
57869
+ }
57721
57870
  function createEventsStorage(basedir, tag) {
57722
57871
  const hookRetentionLimitMs = getHookRetentionLimitMs();
57723
57872
  const maxCachedEventBytes = 4 * 1024 * 1024;
@@ -57882,11 +58031,11 @@ function createEventsStorage(basedir, tag) {
57882
58031
  }
57883
58032
  __name(storeEvent, "storeEvent");
57884
58033
  async function refuseDisposedHookDelivery(hookId, token) {
57885
- const lock2 = await readHookDisposeLock(basedir, hookId, tag);
57886
- if (!lock2.committed)
58034
+ const lock3 = await readHookDisposeLock(basedir, hookId, tag);
58035
+ if (!lock3.committed)
57887
58036
  return;
57888
- if (lock2.forceClaimedBy) {
57889
- throw new HookForceClaimedError2(typeof token === "string" ? token : "", lock2.forceClaimedBy.runId, lock2.forceClaimedBy.hookId);
58037
+ if (lock3.forceClaimedBy) {
58038
+ throw new HookForceClaimedError2(typeof token === "string" ? token : "", lock3.forceClaimedBy.runId, lock3.forceClaimedBy.hookId);
57890
58039
  }
57891
58040
  throw new HookNotFoundError2(hookId);
57892
58041
  }
@@ -59092,17 +59241,140 @@ function createEventsStorage(basedir, tag) {
59092
59241
  }
59093
59242
  return reportSkippedSlots(result2, params.eventCount, resolveData);
59094
59243
  }), "create");
59095
- return { ...storage, create };
59096
- }
59097
- var DAY_MS, MAX_CACHED_EVENT_ENTRIES, HookRecoveryMarkerSchema, HookResumeClaimSchema;
59244
+ const fenceState = inBandFenceState();
59245
+ const fenceKey = /* @__PURE__ */ __name((runId) => `${path10.resolve(basedir)}\0${slotStateKey(runId)}`, "fenceKey");
59246
+ const readInBandCount = /* @__PURE__ */ __name(async (runId) => await readJSON(inBandCountPath(basedir, runId, tag), InBandCountSchema) ?? {
59247
+ seqInBand: IN_BAND_SEQ_AT_RUN_CREATION
59248
+ }, "readInBandCount");
59249
+ const writeInBandCount = /* @__PURE__ */ __name((runId, count2) => writeJSON(inBandCountPath(basedir, runId, tag), count2, {
59250
+ overwrite: true
59251
+ }), "writeInBandCount");
59252
+ async function readTopSlot(runId) {
59253
+ const state = runSlotState.get(slotStateKey(runId));
59254
+ if (state === null)
59255
+ return void 0;
59256
+ const scan = await scanRunEventIds(basedir, runId, tag);
59257
+ if (state === void 0 && scan.count > 0 && !scan.usesSlots) {
59258
+ return void 0;
59259
+ }
59260
+ return Math.max(state?.published ?? 0, scan.maxSlot);
59261
+ }
59262
+ __name(readTopSlot, "readTopSlot");
59263
+ async function settledInBandCount(runId) {
59264
+ const count2 = await readInBandCount(runId);
59265
+ if (count2.pending === void 0)
59266
+ return count2.seqInBand;
59267
+ const settled = Math.max(count2.seqInBand, count2.pending + 1);
59268
+ await writeInBandCount(runId, { seqInBand: settled });
59269
+ return settled;
59270
+ }
59271
+ __name(settledInBandCount, "settledInBandCount");
59272
+ async function supersededAt(runId, expected, current3) {
59273
+ const seq = await readTopSlot(runId).catch(() => void 0);
59274
+ return new InBandSupersededError(`In-band write on run ${runId} expected seqInBand ${expected}, but the run is at ${current3}. Another orchestrator wrote in-band events this one has not seen; stop writing and redeliver.`, { seqInBand: current3, ...seq !== void 0 ? { seq } : {} });
59275
+ }
59276
+ __name(supersededAt, "supersededAt");
59277
+ function withFenceLock(runId, fn) {
59278
+ return withInProcessLock(fenceState.locks, fenceKey(runId), async () => {
59279
+ const countPath = inBandCountPath(basedir, runId, tag);
59280
+ await fs6.mkdir(path10.dirname(countPath), { recursive: true });
59281
+ let compromised;
59282
+ let release;
59283
+ try {
59284
+ release = await (0, import_proper_lockfile3.lock)(countPath, {
59285
+ realpath: false,
59286
+ stale: 3e4,
59287
+ update: 1e3,
59288
+ retries: {
59289
+ retries: 350,
59290
+ factor: 1,
59291
+ minTimeout: 100,
59292
+ maxTimeout: 100
59293
+ },
59294
+ onCompromised(error121) {
59295
+ compromised = error121;
59296
+ }
59297
+ });
59298
+ } catch (error121) {
59299
+ throw new WorkflowWorldError2(`Could not acquire the in-band fence lock of run ${runId}`, { cause: error121 });
59300
+ }
59301
+ let result2;
59302
+ try {
59303
+ result2 = await fn();
59304
+ } finally {
59305
+ if (!compromised)
59306
+ await release().catch(() => {
59307
+ });
59308
+ }
59309
+ if (compromised) {
59310
+ throw new WorkflowWorldError2(`The in-band fence lock of run ${runId} was lost while a write held it`, { cause: compromised });
59311
+ }
59312
+ return result2;
59313
+ });
59314
+ }
59315
+ __name(withFenceLock, "withFenceLock");
59316
+ const fencedCreate = /* @__PURE__ */ __name((async (runId, request, params) => {
59317
+ const data3 = request;
59318
+ if (!params?.inBand || !runId || request.eventType === "run_created") {
59319
+ return create(runId, data3, params);
59320
+ }
59321
+ const expected = params.expectedSeqInBand;
59322
+ if (expected === void 0 || !Number.isSafeInteger(expected) || expected < 0) {
59323
+ throw new WorkflowWorldError2(`An in-band write to run ${runId} must carry a nonnegative integer expectedSeqInBand`, { status: 400 });
59324
+ }
59325
+ assertSafeEntityId("runId", runId);
59326
+ return withFenceLock(runId, async () => {
59327
+ const current3 = await settledInBandCount(runId);
59328
+ if (current3 !== expected)
59329
+ throw await supersededAt(runId, expected, current3);
59330
+ await writeInBandCount(runId, { seqInBand: current3, pending: current3 });
59331
+ let result2;
59332
+ try {
59333
+ result2 = await create(runId, data3, params);
59334
+ } catch (error121) {
59335
+ await writeInBandCount(runId, {
59336
+ seqInBand: isDefinitiveRefusal(error121) ? current3 : current3 + 1
59337
+ });
59338
+ throw error121;
59339
+ }
59340
+ const allocated = result2.event ? 1 : 0;
59341
+ await writeInBandCount(runId, { seqInBand: current3 + allocated });
59342
+ return { ...result2, allocated };
59343
+ });
59344
+ }), "fencedCreate");
59345
+ async function readEventLogSnapshot(runId) {
59346
+ const { seqInBand } = await readInBandCount(runId);
59347
+ const state = runSlotState.get(slotStateKey(runId));
59348
+ if (state === null)
59349
+ return void 0;
59350
+ if (state !== void 0)
59351
+ return { seq: state.published, seqInBand };
59352
+ const scan = await scanRunEventIds(basedir, runId, tag);
59353
+ if (scan.count > 0 && !scan.usesSlots)
59354
+ return void 0;
59355
+ return { seq: scan.maxSlot, seqInBand };
59356
+ }
59357
+ __name(readEventLogSnapshot, "readEventLogSnapshot");
59358
+ const list3 = /* @__PURE__ */ __name((async (params) => {
59359
+ assertSafeEntityId("runId", params.runId);
59360
+ const snapshot = await readEventLogSnapshot(params.runId);
59361
+ const result2 = await storage.list(params);
59362
+ return snapshot ? { ...result2, snapshot } : result2;
59363
+ }), "list");
59364
+ return { ...storage, create: fencedCreate, list: list3 };
59365
+ }
59366
+ var import_proper_lockfile3, DAY_MS, MAX_CACHED_EVENT_ENTRIES, HookRecoveryMarkerSchema, HookResumeClaimSchema, InBandCountSchema;
59098
59367
  var init_events_storage = __esm({
59099
59368
  "../world-local/dist/storage/events-storage.js"() {
59100
59369
  "use strict";
59101
59370
  init_dist7();
59371
+ init_dist5();
59102
59372
  init_dist6();
59373
+ import_proper_lockfile3 = __toESM(require_proper_lockfile(), 1);
59103
59374
  init_zod2();
59104
59375
  init_config();
59105
59376
  init_fs();
59377
+ init_util4();
59106
59378
  init_filters();
59107
59379
  init_helpers2();
59108
59380
  init_hook_index();
@@ -59133,9 +59405,15 @@ var init_events_storage = __esm({
59133
59405
  __name(findExistingHookCreatedEventId, "findExistingHookCreatedEventId");
59134
59406
  __name(repairHookEntityFromPersistedEvent, "repairHookEntityFromPersistedEvent");
59135
59407
  __name(pinCanonicalEventIdForLegacyClaim, "pinCanonicalEventIdForLegacyClaim");
59136
- __name(withInProcessLock, "withInProcessLock");
59408
+ __name(isDefinitiveRefusal, "isDefinitiveRefusal");
59137
59409
  __name(deleteAllWaitsForRun, "deleteAllWaitsForRun");
59138
59410
  __name(writeRunUnderLifecycleLock, "writeRunUnderLifecycleLock");
59411
+ __name(inBandFenceState, "inBandFenceState");
59412
+ InBandCountSchema = external_exports2.object({
59413
+ seqInBand: external_exports2.number().int().nonnegative(),
59414
+ pending: external_exports2.number().int().nonnegative().optional()
59415
+ });
59416
+ __name(inBandCountPath, "inBandCountPath");
59139
59417
  __name(createEventsStorage, "createEventsStorage");
59140
59418
  }
59141
59419
  });
@@ -59303,6 +59581,7 @@ function createWorld(args) {
59303
59581
  const tag = mergedConfig.tag;
59304
59582
  const queue = createQueue(mergedConfig);
59305
59583
  const { clearCache: clearStorageCache, ...storage } = createStorage(mergedConfig.dataDir, tag);
59584
+ const { clearCache: clearStreamerCache, ...streamer } = createStreamer(mergedConfig.dataDir, tag);
59306
59585
  const recoverActiveRuns = resolveRecoverActiveRuns(mergedConfig);
59307
59586
  return {
59308
59587
  specVersion: mintedSpecVersion(),
@@ -59319,12 +59598,16 @@ function createWorld(args) {
59319
59598
  // The token claim lock serializes the takeover behind
59320
59599
  // `createHook({ experimental_force: true })`; see the hook_created
59321
59600
  // branch of storage/events-storage.ts.
59322
- hookForceClaim: true
59601
+ hookForceClaim: true,
59602
+ // A per-run in-band count on disk, under a lock file, so every process
59603
+ // on the data directory shares it; see the in-band writer fence in
59604
+ // storage/events-storage.ts.
59605
+ inBandFence: true
59323
59606
  },
59324
59607
  ...queue,
59325
59608
  ...storage,
59326
59609
  ...instrumentObject("world.streams", {
59327
- ...createStreamer(mergedConfig.dataDir, tag),
59610
+ ...streamer,
59328
59611
  ...mergedConfig.streamFlushIntervalMs !== void 0 && {
59329
59612
  streamFlushIntervalMs: mergedConfig.streamFlushIntervalMs
59330
59613
  }
@@ -59420,6 +59703,7 @@ function createWorld(args) {
59420
59703
  await rm2(mergedConfig.dataDir, { recursive: true, force: true });
59421
59704
  await initDataDir(mergedConfig.dataDir);
59422
59705
  }
59706
+ clearStreamerCache();
59423
59707
  }
59424
59708
  };
59425
59709
  }
@@ -63156,7 +63440,7 @@ var version5;
63156
63440
  var init_version3 = __esm({
63157
63441
  "../world-vercel/dist/version.js"() {
63158
63442
  "use strict";
63159
- version5 = "5.2.0";
63443
+ version5 = "5.2.1";
63160
63444
  }
63161
63445
  });
63162
63446
 
@@ -63645,7 +63929,7 @@ async function getTraceContextHeaders() {
63645
63929
  function SemanticConvention3(...names) {
63646
63930
  return (value) => Object.fromEntries(names.map((name) => [name, value]));
63647
63931
  }
63648
- var otel2, otelDiagLogged2, HttpRequestMethod2, UrlFull2, ServerAddress2, ServerPort2, HttpResponseStatusCode2, ErrorType2, NetworkProtocolName, WorldParseFormat2, PeerService3, RpcSystem3, RpcService3, RpcMethod3, WorkflowRunId3, StepId3, WorkflowStreamName, WorkflowStreamOperation, WorkflowStreamStartIndex, WorkflowEventsTransport, WorkflowHttpTransport, WorkflowEventType, WorkflowStepStartMode, WorkflowStepStartOwnerStamped, WorkflowClientVersion, StepStsoMs2, StepLatencyOptimizations2, WorkflowWsUrl, WorkflowWsRequestId, WorkflowWsRequestParts, WorkflowWsReplyParts, WorkflowWsReconnectAttempt;
63932
+ var otel2, otelDiagLogged2, HttpRequestMethod2, UrlFull2, ServerAddress2, ServerPort2, HttpResponseStatusCode2, ErrorType2, NetworkProtocolName, WorldParseFormat2, PeerService3, RpcSystem3, RpcService3, RpcMethod3, WorkflowRunId3, StepId3, WorkflowStreamName, WorkflowStreamOperation, WorkflowStreamStartIndex, WorkflowEventsTransport, WorkflowHttpTransport, WorkflowEventType, WorkflowEventInBand, WorkflowEventExpectedSeqInBand, WorkflowEventSeqInBand, WorkflowStepStartMode, WorkflowStepStartOwnerStamped, WorkflowClientVersion, StepStsoMs2, StepLatencyOptimizations2, WorkflowWsUrl, WorkflowWsRequestId, WorkflowWsRequestParts, WorkflowWsReplyParts, WorkflowWsReconnectAttempt;
63649
63933
  var init_telemetry3 = __esm({
63650
63934
  "../world-vercel/dist/telemetry.js"() {
63651
63935
  "use strict";
@@ -63685,6 +63969,9 @@ var init_telemetry3 = __esm({
63685
63969
  WorkflowEventsTransport = SemanticConvention3("workflow.events.transport");
63686
63970
  WorkflowHttpTransport = SemanticConvention3("workflow.http.transport");
63687
63971
  WorkflowEventType = SemanticConvention3("workflow.event.type");
63972
+ WorkflowEventInBand = SemanticConvention3("workflow.event.in_band");
63973
+ WorkflowEventExpectedSeqInBand = SemanticConvention3("workflow.event.expected_seq_in_band");
63974
+ WorkflowEventSeqInBand = SemanticConvention3("workflow.event.seq_in_band");
63688
63975
  WorkflowStepStartMode = SemanticConvention3("workflow.step_start.mode");
63689
63976
  WorkflowStepStartOwnerStamped = SemanticConvention3("workflow.step_start.owner_stamped");
63690
63977
  WorkflowClientVersion = SemanticConvention3("workflow.client.version");
@@ -63779,6 +64066,14 @@ function headersToRecord(headers) {
63779
64066
  });
63780
64067
  return out;
63781
64068
  }
64069
+ function recordInBandRefusal(span, error121) {
64070
+ if (InBandSupersededError.is(error121) && error121.seqInBand !== void 0) {
64071
+ span?.setAttributes(WorkflowEventSeqInBand(error121.seqInBand));
64072
+ }
64073
+ }
64074
+ function inBandCounter(value) {
64075
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
64076
+ }
63782
64077
  function errorForResponse(status, message, opts = {}) {
63783
64078
  const { retryAfter, code: code3, url: url3, mitigated, details } = opts;
63784
64079
  if (status === 409 && code3 === "hook-force-claimed") {
@@ -63795,6 +64090,13 @@ function errorForResponse(status, message, opts = {}) {
63795
64090
  }
63796
64091
  return new RunExpiredError2(message);
63797
64092
  }
64093
+ if (status === 412 && code3 === IN_BAND_SUPERSEDED_CODE) {
64094
+ const counters = details && typeof details === "object" ? details : void 0;
64095
+ return new InBandSupersededError(message, {
64096
+ seq: inBandCounter(counters?.seq),
64097
+ seqInBand: inBandCounter(counters?.seqInBand)
64098
+ });
64099
+ }
63798
64100
  if (status === 412)
63799
64101
  return new PreconditionFailedError(message, { retryAfter, details });
63800
64102
  if (status === 425)
@@ -63969,6 +64271,7 @@ async function instrumentedFetch(opts) {
63969
64271
  throw cause;
63970
64272
  }
63971
64273
  onTransportOutcome?.(void 0, response);
64274
+ recordInBandRefusal(span, error122);
63972
64275
  span?.recordException?.(error122);
63973
64276
  throw error122;
63974
64277
  }
@@ -64049,6 +64352,8 @@ var init_http_core = __esm({
64049
64352
  __name(logCurlRepro, "logCurlRepro");
64050
64353
  __name(parseRetryAfter, "parseRetryAfter");
64051
64354
  __name(headersToRecord, "headersToRecord");
64355
+ __name(recordInBandRefusal, "recordInBandRefusal");
64356
+ __name(inBandCounter, "inBandCounter");
64052
64357
  __name(errorForResponse, "errorForResponse");
64053
64358
  __name(isFirewallChallenge429, "isFirewallChallenge429");
64054
64359
  __name(resolveVercelApiToken, "resolveVercelApiToken");
@@ -77055,6 +77360,8 @@ function throttleBudgetFor(eventType, options) {
77055
77360
  return options?.afterStepBody === true || recordsStepOutcome(eventType) ? "invocation" : "bounded";
77056
77361
  }
77057
77362
  function isEligibleForTransientRetry(eventType, options) {
77363
+ if (options?.inBand === true)
77364
+ return false;
77058
77365
  if (options?.batchIdempotent !== void 0) {
77059
77366
  return options.batchIdempotent;
77060
77367
  }
@@ -77525,6 +77832,24 @@ async function fetchV4(url3, init, config4, opName, attributes) {
77525
77832
  function eventsV4Url(baseUrl, runId, eventType) {
77526
77833
  return `${baseUrl}/v4/runs/${encodeURIComponent(runId)}/events/${encodeURIComponent(eventType)}`;
77527
77834
  }
77835
+ function snapshotFromHeaders(headers) {
77836
+ const seq = headers.get(SNAPSHOT_SEQ_HEADER);
77837
+ const seqInBand = headers.get(SNAPSHOT_SEQ_IN_BAND_HEADER);
77838
+ if (seq === null || seqInBand === null || !DECIMAL_COUNTER.test(seq) || !DECIMAL_COUNTER.test(seqInBand)) {
77839
+ return void 0;
77840
+ }
77841
+ const parsed = EventLogSnapshotWireSchema.safeParse({
77842
+ seq: Number(seq),
77843
+ seqInBand: Number(seqInBand)
77844
+ });
77845
+ return parsed.success ? parsed.data : void 0;
77846
+ }
77847
+ function snapshotFromEnd(snapshot) {
77848
+ if (snapshot === void 0)
77849
+ return void 0;
77850
+ const parsed = EventLogSnapshotWireSchema.safeParse(snapshot);
77851
+ return parsed.success ? parsed.data : void 0;
77852
+ }
77528
77853
  function decodeLegacyStructuredError(payload) {
77529
77854
  if (hasSerializedDataFormatPrefix(payload))
77530
77855
  return payload;
@@ -77656,8 +77981,19 @@ function buildPostFrameMeta(input3) {
77656
77981
  if (input3.viaStepDispatch !== void 0) {
77657
77982
  meta5.viaStepDispatch = input3.viaStepDispatch;
77658
77983
  }
77984
+ if (input3.inBand !== void 0)
77985
+ meta5.inBand = input3.inBand;
77986
+ if (input3.expectedSeqInBand !== void 0) {
77987
+ meta5.expectedSeqInBand = input3.expectedSeqInBand;
77988
+ }
77659
77989
  return meta5;
77660
77990
  }
77991
+ function inBandFenceAttributes(input3) {
77992
+ return {
77993
+ ...input3.inBand !== void 0 ? WorkflowEventInBand(input3.inBand) : {},
77994
+ ...input3.expectedSeqInBand !== void 0 ? WorkflowEventExpectedSeqInBand(input3.expectedSeqInBand) : {}
77995
+ };
77996
+ }
77661
77997
  function errorFromV4Response(statusCode, responseHeaders, errorBody, opName, url3) {
77662
77998
  let message = `v4 ${opName} failed: HTTP ${statusCode}`;
77663
77999
  let code3;
@@ -77670,8 +78006,9 @@ function errorFromV4Response(statusCode, responseHeaders, errorBody, opName, url
77670
78006
  code3 = record3.code;
77671
78007
  else if (typeof record3.error === "string")
77672
78008
  code3 = record3.error;
77673
- if (statusCode === 412)
77674
- details = decodePreconditionDetails(record3);
78009
+ if (statusCode === 412) {
78010
+ details = code3 === IN_BAND_SUPERSEDED_CODE ? decodeInBandSupersededDetails(record3) : decodePreconditionDetails(record3);
78011
+ }
77675
78012
  if (statusCode === 409 && code3 === "hook-force-claimed") {
77676
78013
  details = { claimedBy: record3.claimedBy };
77677
78014
  }
@@ -77687,6 +78024,14 @@ function errorFromV4Response(statusCode, responseHeaders, errorBody, opName, url
77687
78024
  ...details !== void 0 ? { details } : {}
77688
78025
  });
77689
78026
  }
78027
+ function decodeInBandSupersededDetails(json3) {
78028
+ const seq = inBandCounter(json3.seq);
78029
+ const seqInBand = inBandCounter(json3.seqInBand);
78030
+ return {
78031
+ ...seq !== void 0 ? { seq } : {},
78032
+ ...seqInBand !== void 0 ? { seqInBand } : {}
78033
+ };
78034
+ }
77690
78035
  function parseV4ErrorBody(body, contentType) {
77691
78036
  if (typeof body !== "string" && contentType?.includes("application/cbor")) {
77692
78037
  try {
@@ -77758,6 +78103,7 @@ async function postWorkflowRunEventV4(input3, responseType, config4) {
77758
78103
  ...WorkflowEventsTransport("http"),
77759
78104
  ...WorkflowEventType(input3.eventType),
77760
78105
  ...WorkflowClientVersion(`@workflow/world-vercel/${version5}`),
78106
+ ...inBandFenceAttributes(input3),
77761
78107
  ...input3.eventType === "step_started" ? {
77762
78108
  ...WorkflowStepStartMode(input3.payload === void 0 ? input3.ownerMessageId !== void 0 ? "single_owned_recovery" : "single_bare" : "single_lazy_create_claim"),
77763
78109
  ...WorkflowStepStartOwnerStamped(input3.ownerMessageId !== void 0)
@@ -77867,6 +78213,8 @@ async function createWorkflowRunEventsBatchV4(input3, config4) {
77867
78213
  const response = await fetchV4(url3, { method: "POST", headers, body }, config4, "createEventBatch", {
77868
78214
  ...WorkflowEventsTransport("http"),
77869
78215
  "workflow.batch.bytes": body.byteLength,
78216
+ // Every frame of a batch carries the same fence.
78217
+ ...inBandFenceAttributes(input3.events[0]),
77870
78218
  ...input3.events.some((event) => event.eventType === "step_started") ? {
77871
78219
  ...WorkflowStepStartMode(input3.events.some((event) => event.eventType === "step_created") ? "batch_create_claim" : "batch_bare"),
77872
78220
  ...WorkflowStepStartOwnerStamped(input3.events.some((event) => event.ownerMessageId !== void 0))
@@ -77935,6 +78283,7 @@ async function postEventFrameOverWs(input3, config4) {
77935
78283
  ...WorkflowEventsTransport("ws"),
77936
78284
  ...WorkflowEventType(input3.eventType),
77937
78285
  ...WorkflowClientVersion(`@workflow/world-vercel/${version5}`),
78286
+ ...inBandFenceAttributes(input3),
77938
78287
  ...input3.stso !== void 0 ? StepStsoMs2(input3.stso) : {},
77939
78288
  ...input3.optimizations !== void 0 ? StepLatencyOptimizations2(input3.optimizations) : {},
77940
78289
  ...input3.eventType === "step_started" ? {
@@ -77977,6 +78326,7 @@ async function postEventFrameOverWs(input3, config4) {
77977
78326
  recordClientSpanStatus(span, status);
77978
78327
  if (status < 200 || status >= 300) {
77979
78328
  const error121 = errorFromV4Response(status, headerRecord, new TextDecoder().decode(reply.body), "createEvent", endpoint);
78329
+ recordInBandRefusal(span, error121);
77980
78330
  span?.recordException?.(error121);
77981
78331
  throw error121;
77982
78332
  }
@@ -78078,11 +78428,13 @@ async function consumeEventFrameStream(response, opName, replayEventObserver) {
78078
78428
  for await (const frame3 of decodeFrames(response.body)) {
78079
78429
  if (frame3.meta._end === 1) {
78080
78430
  const end = EventStreamEndSchema.parse(frame3.meta);
78431
+ const snapshot = snapshotFromEnd(end.snapshot) ?? snapshotFromHeaders(response.headers);
78081
78432
  return {
78082
78433
  kind: "complete",
78083
78434
  events,
78084
78435
  cursor: end.next ?? null,
78085
- hasMore: end.hasMore
78436
+ hasMore: end.hasMore,
78437
+ ...snapshot ? { snapshot } : {}
78086
78438
  };
78087
78439
  }
78088
78440
  if (frame3.meta._error === 1) {
@@ -78238,7 +78590,10 @@ async function getWorkflowRunEventsV4(runId, params = {}, config4, replayEventOb
78238
78590
  return {
78239
78591
  events,
78240
78592
  cursor: consumed.cursor || (partialStreamRetries > 0 ? cursor : null),
78241
- hasMore: consumed.hasMore
78593
+ hasMore: consumed.hasMore,
78594
+ // Only a complete response reaches its sentinel, and the loop ends on
78595
+ // the first one, so this is the first snapshot the read saw.
78596
+ ...consumed.kind === "complete" && consumed.snapshot ? { snapshot: consumed.snapshot } : {}
78242
78597
  };
78243
78598
  }
78244
78599
  async function getEventsByCorrelationIdV4(correlationId, runId, params = {}, config4) {
@@ -78258,7 +78613,7 @@ async function getEventsByCorrelationIdV4(correlationId, runId, params = {}, con
78258
78613
  hasMore: consumed.hasMore
78259
78614
  };
78260
78615
  }
78261
- var EVENT_ID_HEADER, MAX_EVENTS_HEADER, OMITTED_EVENT_PAYLOAD, VercelEventWireSchema, CreateEventV4BodyBaseSchema, CreateEventV4PageSchema, CreateEventV4BodySchema, CreateEventV4BodySchemas, MaxEventsHeaderSchema, EventStreamEndSchema, EventStreamErrorSchema, PAYLOAD_MISSING_ERROR_CODE, legacyStructuredErrorEventTypes, STRICT_WS_EVENT_TYPES, createEventResponseSchemas, BatchItemFailureSchema, MAX_PARTIAL_STREAM_RETRIES, skipStepInputsSupport, SKIP_STEP_INPUTS_REPROBE_MS;
78616
+ var EVENT_ID_HEADER, MAX_EVENTS_HEADER, OMITTED_EVENT_PAYLOAD, VercelEventWireSchema, CreateEventV4BodyBaseSchema, CreateEventV4PageSchema, CreateEventV4BodySchema, CreateEventV4BodySchemas, MaxEventsHeaderSchema, EventLogSnapshotWireSchema, SNAPSHOT_SEQ_HEADER, SNAPSHOT_SEQ_IN_BAND_HEADER, DECIMAL_COUNTER, EventStreamEndSchema, EventStreamErrorSchema, PAYLOAD_MISSING_ERROR_CODE, legacyStructuredErrorEventTypes, STRICT_WS_EVENT_TYPES, createEventResponseSchemas, BatchItemFailureSchema, MAX_PARTIAL_STREAM_RETRIES, skipStepInputsSupport, SKIP_STEP_INPUTS_REPROBE_MS;
78262
78617
  var init_events_v4 = __esm({
78263
78618
  "../world-vercel/dist/events-v4.js"() {
78264
78619
  "use strict";
@@ -78318,7 +78673,14 @@ var init_events_v4 = __esm({
78318
78673
  hook: HookSchema2.optional(),
78319
78674
  wait: WaitSchema2.optional(),
78320
78675
  stepCreated: external_exports2.literal(true).optional(),
78321
- maxEvents: external_exports2.number().int().positive().optional()
78676
+ maxEvents: external_exports2.number().int().positive().optional(),
78677
+ // Positions the backend allocated for this write, when it reports them
78678
+ // (`EventResult.allocated`): what an in-band writer advances its count by.
78679
+ // Passed on for a single create answered with this body. A batch's item
78680
+ // results reuse this schema, but a batch is one allocation for the whole
78681
+ // block and its count is not passed on, nor is one on the streamed
78682
+ // `run_started` and `hook_received` preload responses.
78683
+ allocated: external_exports2.number().int().nonnegative().optional()
78322
78684
  });
78323
78685
  CreateEventV4PageSchema = external_exports2.union([
78324
78686
  external_exports2.object({
@@ -78369,10 +78731,22 @@ var init_events_v4 = __esm({
78369
78731
  noop: CreateEventV4BodySchema
78370
78732
  };
78371
78733
  MaxEventsHeaderSchema = external_exports2.compile(external_exports2.coerce.number().int().positive());
78734
+ EventLogSnapshotWireSchema = external_exports2.compile(external_exports2.object({
78735
+ seq: external_exports2.number().int().nonnegative(),
78736
+ seqInBand: external_exports2.number().int().nonnegative()
78737
+ }).refine(({ seq, seqInBand }) => seqInBand <= seq));
78738
+ SNAPSHOT_SEQ_HEADER = "x-wf-snapshot-seq";
78739
+ SNAPSHOT_SEQ_IN_BAND_HEADER = "x-wf-snapshot-seq-in-band";
78740
+ DECIMAL_COUNTER = /^\d+$/;
78741
+ __name(snapshotFromHeaders, "snapshotFromHeaders");
78742
+ __name(snapshotFromEnd, "snapshotFromEnd");
78372
78743
  EventStreamEndSchema = external_exports2.compile(external_exports2.object({
78373
78744
  _end: external_exports2.literal(1),
78374
78745
  next: external_exports2.string().optional(),
78375
- hasMore: external_exports2.boolean()
78746
+ hasMore: external_exports2.boolean(),
78747
+ // Read on its own (`snapshotFromEnd`): a malformed snapshot lists none
78748
+ // rather than failing the page.
78749
+ snapshot: external_exports2.unknown().optional()
78376
78750
  }));
78377
78751
  EventStreamErrorSchema = external_exports2.compile(external_exports2.object({
78378
78752
  _error: external_exports2.literal(1),
@@ -78388,7 +78762,9 @@ var init_events_v4 = __esm({
78388
78762
  __name(decodeLegacyStructuredError, "decodeLegacyStructuredError");
78389
78763
  __name(decodeEventFrame, "decodeEventFrame");
78390
78764
  __name(buildPostFrameMeta, "buildPostFrameMeta");
78765
+ __name(inBandFenceAttributes, "inBandFenceAttributes");
78391
78766
  __name(errorFromV4Response, "errorFromV4Response");
78767
+ __name(decodeInBandSupersededDetails, "decodeInBandSupersededDetails");
78392
78768
  __name(parseV4ErrorBody, "parseV4ErrorBody");
78393
78769
  __name(decodePreconditionDetails, "decodePreconditionDetails");
78394
78770
  __name(hasUnusablePayload, "hasUnusablePayload");
@@ -78823,7 +79199,10 @@ async function getWorkflowRunEvents(params, config4) {
78823
79199
  // The cursor is present even on the final page because it is also the
78824
79200
  // incremental-load resume point. `hasMore` is the pagination signal.
78825
79201
  cursor: result2.cursor,
78826
- hasMore: result2.hasMore
79202
+ hasMore: result2.hasMore,
79203
+ // The in-band fence's counters, read before the listing, when the
79204
+ // backend reports them (see `capabilities.inBandFence` in index.ts).
79205
+ ...result2.snapshot ? { snapshot: result2.snapshot } : {}
78827
79206
  };
78828
79207
  }
78829
79208
  async function createWorkflowRunEventBatch(runId, events, params, config4) {
@@ -78855,11 +79234,16 @@ async function createWorkflowRunEventBatch(runId, events, params, config4) {
78855
79234
  // batched usage facts carry the same attribution.
78856
79235
  ...params?.requestId ? { vercelId: params.requestId } : {},
78857
79236
  payload,
78858
- ...meta5
79237
+ ...meta5,
79238
+ // The batch is one fenced allocation: the backend requires every frame
79239
+ // to carry the same fence. Spread after `meta` so nothing derived from
79240
+ // the event data can override it.
79241
+ ...params?.inBand !== void 0 ? { inBand: params.inBand } : {},
79242
+ ...params?.expectedSeqInBand !== void 0 ? { expectedSeqInBand: params.expectedSeqInBand } : {}
78859
79243
  };
78860
79244
  });
78861
79245
  const retryConvergent = events.every(({ event }) => event.eventType !== "step_started" && event.eventType !== "step_retrying");
78862
- const wire = await withEventPostRetry(() => createWorkflowRunEventsBatchV4({ runId, events: inputs }, config4), events[0].event.eventType, { batchIdempotent: retryConvergent });
79246
+ const wire = await withEventPostRetry(() => createWorkflowRunEventsBatchV4({ runId, events: inputs }, config4), events[0].event.eventType, { batchIdempotent: retryConvergent, inBand: params?.inBand === true });
78863
79247
  return {
78864
79248
  results: wire.results.map((item) => {
78865
79249
  if (item.error !== void 0) {
@@ -78886,7 +79270,8 @@ async function createWorkflowRunEvent(id, data3, params, config4) {
78886
79270
  // (runId, resumeId) claim, so its POST is idempotent-on-retry even
78887
79271
  // though plain hook_received is not; see EVENT_RETRY_ELIGIBILITY.
78888
79272
  idempotentHookResume: data3.eventType === "hook_received" && params?.resumeId !== void 0 && params?.resumePayloadDigest !== void 0,
78889
- afterStepBody: params?.afterStepBody === true
79273
+ afterStepBody: params?.afterStepBody === true,
79274
+ inBand: params?.inBand === true
78890
79275
  });
78891
79276
  if (data3.eventType === "run_created" && !result2.run) {
78892
79277
  throw new WorkflowWorldError2(`${data3.eventType} response is missing the run entity`, { code: "SCHEMA_VALIDATION" });
@@ -78965,6 +79350,10 @@ async function createWorkflowRunEventInner(id, data3, params, config4) {
78965
79350
  // `eventCount`.
78966
79351
  ...params?.eventCount !== void 0 ? { maxSlot: params.eventCount } : {},
78967
79352
  replayDivergenceCount: params?.replayDivergenceCount,
79353
+ // In-band writer fence. The backend refuses a stale in-band write with
79354
+ // 412 `in-band-superseded` (InBandSupersededError).
79355
+ ...params?.inBand !== void 0 ? { inBand: params.inBand } : {},
79356
+ ...params?.expectedSeqInBand !== void 0 ? { expectedSeqInBand: params.expectedSeqInBand } : {},
78968
79357
  occurredAt: params?.occurredAt ?? /* @__PURE__ */ new Date(),
78969
79358
  // Opt-in inline-delta: forward the cursor the runtime held before
78970
79359
  // this write so the server can return the authoritative event-log
@@ -80669,6 +81058,17 @@ function createWorld2(config4) {
80669
81058
  // Vercel deployments are atomic and immutable, so a deployment id names
80670
81059
  // one fixed build for its whole lifetime.
80671
81060
  deploymentAffinity: true,
81061
+ // The backend fences in-band writes on every sealed-log run (spec >= 7,
81062
+ // the backend's event sequencer): a stale one is refused with 412
81063
+ // `in-band-superseded`, carrying the run's `seq` and `seqInBand`
81064
+ // (`InBandSupersededError`), and nothing is allocated for it. On an
81065
+ // older run an in-band write is a 400 `in-band-fence-unsupported`,
81066
+ // never an unfenced write, so a client fences by the run's spec
81067
+ // version. A list response carries `snapshot` and a single create
81068
+ // carries `allocated` where the backend reports them (events-v4.ts); a
81069
+ // run whose list carries no snapshot is still fenced, and its refusals
81070
+ // carry the counters.
81071
+ inBandFence: true,
80672
81072
  // The server implements the takeover protocol behind
80673
81073
  // `createHook({ experimental_force: true })` (workflow-server
80674
81074
  // docs/hook-force-claim.md). Static rather than attested per lookup,
@@ -85422,7 +85822,7 @@ async function compress2(data3, mode, stats, opts) {
85422
85822
  recordStats2(stats, "none", data3.length, data3.length);
85423
85823
  return data3;
85424
85824
  }
85425
- const compressed = codec3 === "zstd" ? opts?.preferAsync ? await zstdBytesAsync2(data3) : zstdBytes2(data3) : await gzipBytes2(data3);
85825
+ const compressed = codec3 === "zstd" ? opts?.preferAsync && data3.length >= COMPRESSION_ASYNC_MIN_BYTES2 ? await zstdBytesAsync2(data3) : zstdBytes2(data3) : await gzipBytes2(data3);
85426
85826
  const format = codec3 === "zstd" ? SerializationFormat2.ZSTD : SerializationFormat2.GZIP;
85427
85827
  const wrappedLength = 4 + compressed.length;
85428
85828
  if (wrappedLength >= data3.length * (1 - COMPRESSION_MIN_SAVINGS_RATIO2)) {
@@ -85454,7 +85854,7 @@ async function decompress3(data3, stats, opts) {
85454
85854
  recordStats2(stats, "none", data3.length, data3.length);
85455
85855
  return data3;
85456
85856
  }
85457
- var COMPRESSION_MIN_BYTES2, COMPRESSION_MIN_SAVINGS_RATIO2, ZSTD_LEVEL2, DecompressedSizeLimitError2;
85857
+ var COMPRESSION_MIN_BYTES2, COMPRESSION_MIN_SAVINGS_RATIO2, COMPRESSION_ASYNC_MIN_BYTES2, ZSTD_LEVEL2, DecompressedSizeLimitError2;
85458
85858
  var init_compression2 = __esm({
85459
85859
  "../core/dist/serialization/compression.js"() {
85460
85860
  "use strict";
@@ -85462,6 +85862,7 @@ var init_compression2 = __esm({
85462
85862
  init_types3();
85463
85863
  COMPRESSION_MIN_BYTES2 = 1024;
85464
85864
  COMPRESSION_MIN_SAVINGS_RATIO2 = 0.05;
85865
+ COMPRESSION_ASYNC_MIN_BYTES2 = 256 * 1024;
85465
85866
  ZSTD_LEVEL2 = 3;
85466
85867
  __name(isCompressionDisabledByEnv2, "isCompressionDisabledByEnv");
85467
85868
  __name(codecOverrideFromEnv2, "codecOverrideFromEnv");
@@ -88656,7 +89057,7 @@ var version6;
88656
89057
  var init_version4 = __esm({
88657
89058
  "../core/dist/version.js"() {
88658
89059
  "use strict";
88659
- version6 = "5.2.0";
89060
+ version6 = "5.2.1";
88660
89061
  }
88661
89062
  });
88662
89063
 
@@ -139019,7 +139420,7 @@ async function compress(data22, mode, stats, opts) {
139019
139420
  recordStats(stats, "none", data22.length, data22.length);
139020
139421
  return data22;
139021
139422
  }
139022
- const compressed = codec22 === "zstd" ? opts?.preferAsync ? await zstdBytesAsync(data22) : zstdBytes(data22) : await gzipBytes(data22);
139423
+ const compressed = codec22 === "zstd" ? opts?.preferAsync && data22.length >= COMPRESSION_ASYNC_MIN_BYTES ? await zstdBytesAsync(data22) : zstdBytes(data22) : await gzipBytes(data22);
139023
139424
  const format = codec22 === "zstd" ? SerializationFormat.ZSTD : SerializationFormat.GZIP;
139024
139425
  const wrappedLength = 4 + compressed.length;
139025
139426
  if (wrappedLength >= data22.length * (1 - COMPRESSION_MIN_SAVINGS_RATIO)) {
@@ -139054,6 +139455,7 @@ async function decompress(data22, stats, opts) {
139054
139455
  __name(decompress, "decompress");
139055
139456
  var COMPRESSION_MIN_BYTES;
139056
139457
  var COMPRESSION_MIN_SAVINGS_RATIO;
139458
+ var COMPRESSION_ASYNC_MIN_BYTES;
139057
139459
  var ZSTD_LEVEL;
139058
139460
  var DecompressedSizeLimitError;
139059
139461
  var init_compression = __esm2({
@@ -139063,6 +139465,7 @@ var init_compression = __esm2({
139063
139465
  init_types();
139064
139466
  COMPRESSION_MIN_BYTES = 1024;
139065
139467
  COMPRESSION_MIN_SAVINGS_RATIO = 0.05;
139468
+ COMPRESSION_ASYNC_MIN_BYTES = 256 * 1024;
139066
139469
  ZSTD_LEVEL = 3;
139067
139470
  __name2(isCompressionDisabledByEnv, "isCompressionDisabledByEnv");
139068
139471
  __name2(codecOverrideFromEnv, "codecOverrideFromEnv");
@@ -142079,7 +142482,9 @@ async function serialize(value, encryptionKey, options) {
142079
142482
  try {
142080
142483
  const payload = devalueCodec.serialize(value, "client", options);
142081
142484
  const prefixed = encodeWithFormatPrefix(SerializationFormat.DEVALUE_V1, payload);
142082
- const compressed = await compress(prefixed, options?.compression ?? false, options?.compressionStats);
142485
+ const compressed = await compress(prefixed, options?.compression ?? false, options?.compressionStats, {
142486
+ preferAsync: true
142487
+ });
142083
142488
  return encrypt2(compressed, encryptionKey);
142084
142489
  } catch (error612) {
142085
142490
  rethrowIfRuntimeError(error612);
@@ -144301,7 +144706,7 @@ var version2;
144301
144706
  var init_version = __esm2({
144302
144707
  "../core/dist/version.js"() {
144303
144708
  "use strict";
144304
- version2 = "5.2.0";
144709
+ version2 = "5.2.1";
144305
144710
  }
144306
144711
  });
144307
144712
  function isDynamicWorkflowsEnabled() {
@@ -159513,9 +159918,13 @@ async function start(workflow, argsOrOptions, options) {
159513
159918
  }
159514
159919
  const workflowVm = getWorkflowVmFromEnv();
159515
159920
  const snapshotThreshold = getSnapshotThresholdFromEnv();
159921
+ const queueNamespace = resolveQueueNamespace(opts.namespace);
159516
159922
  const executionContext = {
159517
159923
  traceCarrier,
159518
159924
  workflowCoreVersion: version2,
159925
+ ...queueNamespace ? {
159926
+ queueNamespace
159927
+ } : {},
159519
159928
  ...targetNodeVersion ? {
159520
159929
  nodeVersion: targetNodeVersion
159521
159930
  } : {},
@@ -159546,7 +159955,8 @@ async function start(workflow, argsOrOptions, options) {
159546
159955
  }
159547
159956
  }
159548
159957
  const compression = specVersion >= SPEC_VERSION_SUPPORTS_COMPRESSION ? targetCompression : false;
159549
- const workflowArguments = await dehydrateWorkflowArguments(args, runId, encryptionKey, ops, globalThis, v1Compat, framedByteStreams, compression);
159958
+ const argumentCompression = opts.compressArguments === false ? false : compression;
159959
+ const workflowArguments = await dehydrateWorkflowArguments(args, runId, encryptionKey, ops, globalThis, v1Compat, framedByteStreams, argumentCompression);
159550
159960
  let dynamicWorkflowCode;
159551
159961
  let dynamicWorkflowCodeRef;
159552
159962
  if (dynamicWorkflow) {
@@ -159681,7 +160091,7 @@ __name2(start, "start");
159681
160091
  value: "start",
159682
160092
  configurable: true
159683
160093
  });
159684
- })(start, "step//@workflow/core/runtime/start@5.2.0//start");
160094
+ })(start, "step//@workflow/core/runtime/start@5.2.1//start");
159685
160095
  async function wakeUpRun(world, runId, options) {
159686
160096
  try {
159687
160097
  const run22 = await world.runs.get(runId, {
@@ -160159,7 +160569,7 @@ var Run = class _Run {
160159
160569
  value: "wakeUp",
160160
160570
  configurable: true
160161
160571
  });
160162
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.2.0//Run#wakeUp");
160572
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.2.1//Run#wakeUp");
160163
160573
  (function(__wf_fn, __wf_id) {
160164
160574
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160165
160575
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160168,7 +160578,7 @@ var Run = class _Run {
160168
160578
  value: "cancel",
160169
160579
  configurable: true
160170
160580
  });
160171
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.2.0//Run#cancel");
160581
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.2.1//Run#cancel");
160172
160582
  (function(__wf_fn, __wf_id) {
160173
160583
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160174
160584
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160177,7 +160587,7 @@ var Run = class _Run {
160177
160587
  value: "getReadable",
160178
160588
  configurable: true
160179
160589
  });
160180
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.2.0//Run#getReadable");
160590
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.2.1//Run#getReadable");
160181
160591
  (function(__wf_fn, __wf_id) {
160182
160592
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160183
160593
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160186,7 +160596,7 @@ var Run = class _Run {
160186
160596
  value: "getWritable",
160187
160597
  configurable: true
160188
160598
  });
160189
- })(Run.prototype["getWritable"], "step//@workflow/core/runtime/run@5.2.0//Run#getWritable");
160599
+ })(Run.prototype["getWritable"], "step//@workflow/core/runtime/run@5.2.1//Run#getWritable");
160190
160600
  (function(__wf_fn, __wf_id) {
160191
160601
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160192
160602
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160195,7 +160605,7 @@ var Run = class _Run {
160195
160605
  value: "exists",
160196
160606
  configurable: true
160197
160607
  });
160198
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.2.0//Run#exists");
160608
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.2.1//Run#exists");
160199
160609
  (function(__wf_fn, __wf_id) {
160200
160610
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160201
160611
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160204,7 +160614,7 @@ var Run = class _Run {
160204
160614
  value: "status",
160205
160615
  configurable: true
160206
160616
  });
160207
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.2.0//Run#status");
160617
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.2.1//Run#status");
160208
160618
  (function(__wf_fn, __wf_id) {
160209
160619
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160210
160620
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160213,7 +160623,7 @@ var Run = class _Run {
160213
160623
  value: "returnValue",
160214
160624
  configurable: true
160215
160625
  });
160216
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.2.0//Run#returnValue");
160626
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.2.1//Run#returnValue");
160217
160627
  (function(__wf_fn, __wf_id) {
160218
160628
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160219
160629
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160222,7 +160632,7 @@ var Run = class _Run {
160222
160632
  value: "workflowName",
160223
160633
  configurable: true
160224
160634
  });
160225
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.2.0//Run#workflowName");
160635
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.2.1//Run#workflowName");
160226
160636
  (function(__wf_fn, __wf_id) {
160227
160637
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160228
160638
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160231,7 +160641,7 @@ var Run = class _Run {
160231
160641
  value: "createdAt",
160232
160642
  configurable: true
160233
160643
  });
160234
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.2.0//Run#createdAt");
160644
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.2.1//Run#createdAt");
160235
160645
  (function(__wf_fn, __wf_id) {
160236
160646
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160237
160647
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160240,7 +160650,7 @@ var Run = class _Run {
160240
160650
  value: "startedAt",
160241
160651
  configurable: true
160242
160652
  });
160243
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.2.0//Run#startedAt");
160653
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.2.1//Run#startedAt");
160244
160654
  (function(__wf_fn, __wf_id) {
160245
160655
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160246
160656
  __wf_reg.set(__wf_id, __wf_fn);
@@ -160249,7 +160659,7 @@ var Run = class _Run {
160249
160659
  value: "completedAt",
160250
160660
  configurable: true
160251
160661
  });
160252
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.2.0//Run#completedAt");
160662
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.2.1//Run#completedAt");
160253
160663
  (function(__wf_cls, __wf_id) {
160254
160664
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
160255
160665
  __wf_reg.set(__wf_id, __wf_cls);
@@ -160259,7 +160669,7 @@ var Run = class _Run {
160259
160669
  enumerable: false,
160260
160670
  configurable: false
160261
160671
  });
160262
- })(Run, "class//@workflow/core/runtime/run@5.2.0//Run");
160672
+ })(Run, "class//@workflow/core/runtime/run@5.2.1//Run");
160263
160673
  async function fetch2(...args) {
160264
160674
  return globalThis.fetch(...args);
160265
160675
  }
@@ -167425,11 +167835,11 @@ var Run = class _Run {
167425
167835
  return this.getWritable();
167426
167836
  }
167427
167837
  };
167428
- Run.prototype["wakeUp"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#wakeUp");
167429
- Run.prototype["cancel"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#cancel");
167430
- Run.prototype["getReadable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#getReadable");
167431
- Run.prototype["getWritable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#getWritable");
167432
- var __step_Run$exists = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#exists");
167838
+ Run.prototype["wakeUp"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#wakeUp");
167839
+ Run.prototype["cancel"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#cancel");
167840
+ Run.prototype["getReadable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#getReadable");
167841
+ Run.prototype["getWritable"] = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#getWritable");
167842
+ var __step_Run$exists = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#exists");
167433
167843
  Object.defineProperty(Run.prototype, "exists", {
167434
167844
  get() {
167435
167845
  return __step_Run$exists.call(this);
@@ -167437,7 +167847,7 @@ Object.defineProperty(Run.prototype, "exists", {
167437
167847
  configurable: true,
167438
167848
  enumerable: false
167439
167849
  });
167440
- var __step_Run$status = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#status");
167850
+ var __step_Run$status = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#status");
167441
167851
  Object.defineProperty(Run.prototype, "status", {
167442
167852
  get() {
167443
167853
  return __step_Run$status.call(this);
@@ -167445,7 +167855,7 @@ Object.defineProperty(Run.prototype, "status", {
167445
167855
  configurable: true,
167446
167856
  enumerable: false
167447
167857
  });
167448
- var __step_Run$returnValue = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#returnValue");
167858
+ var __step_Run$returnValue = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#returnValue");
167449
167859
  Object.defineProperty(Run.prototype, "returnValue", {
167450
167860
  get() {
167451
167861
  return __step_Run$returnValue.call(this);
@@ -167453,7 +167863,7 @@ Object.defineProperty(Run.prototype, "returnValue", {
167453
167863
  configurable: true,
167454
167864
  enumerable: false
167455
167865
  });
167456
- var __step_Run$workflowName = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#workflowName");
167866
+ var __step_Run$workflowName = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#workflowName");
167457
167867
  Object.defineProperty(Run.prototype, "workflowName", {
167458
167868
  get() {
167459
167869
  return __step_Run$workflowName.call(this);
@@ -167461,7 +167871,7 @@ Object.defineProperty(Run.prototype, "workflowName", {
167461
167871
  configurable: true,
167462
167872
  enumerable: false
167463
167873
  });
167464
- var __step_Run$createdAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#createdAt");
167874
+ var __step_Run$createdAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#createdAt");
167465
167875
  Object.defineProperty(Run.prototype, "createdAt", {
167466
167876
  get() {
167467
167877
  return __step_Run$createdAt.call(this);
@@ -167469,7 +167879,7 @@ Object.defineProperty(Run.prototype, "createdAt", {
167469
167879
  configurable: true,
167470
167880
  enumerable: false
167471
167881
  });
167472
- var __step_Run$startedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#startedAt");
167882
+ var __step_Run$startedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#startedAt");
167473
167883
  Object.defineProperty(Run.prototype, "startedAt", {
167474
167884
  get() {
167475
167885
  return __step_Run$startedAt.call(this);
@@ -167477,7 +167887,7 @@ Object.defineProperty(Run.prototype, "startedAt", {
167477
167887
  configurable: true,
167478
167888
  enumerable: false
167479
167889
  });
167480
- var __step_Run$completedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.0//Run#completedAt");
167890
+ var __step_Run$completedAt = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/run@5.2.1//Run#completedAt");
167481
167891
  Object.defineProperty(Run.prototype, "completedAt", {
167482
167892
  get() {
167483
167893
  return __step_Run$completedAt.call(this);
@@ -167494,7 +167904,7 @@ Object.defineProperty(Run.prototype, "completedAt", {
167494
167904
  enumerable: false,
167495
167905
  configurable: false
167496
167906
  });
167497
- })(Run, "class//@workflow/core/runtime/run@5.2.0//Run");
167907
+ })(Run, "class//@workflow/core/runtime/run@5.2.1//Run");
167498
167908
 
167499
167909
  // ../core/dist/workflow/create-hook.js
167500
167910
  aliasSerializationClass(RUN_CLASS_ID, Run);
@@ -189792,7 +190202,7 @@ var latestNoOpWarning = globalSingleton("@workflow/core//latestNoOpWarning", 1,
189792
190202
  var probeMissWarning = globalSingleton("@workflow/core//crossDeploymentProbeMissWarning", 1, () => ({
189793
190203
  warned: false
189794
190204
  }));
189795
- var start = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/start@5.2.0//start");
190205
+ var start = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//@workflow/core/runtime/start@5.2.1//start");
189796
190206
 
189797
190207
  // workflows/lineage.ts
189798
190208
  var noop = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//./workflows/lineage//noop");