@workflow/world-testing 5.0.0-beta.56 → 5.0.0-beta.57

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.
@@ -496,6 +496,17 @@ Caused by: ${options.cause.stack}`;
496
496
  static {
497
497
  __name(this, "WorkflowRunFailedError");
498
498
  }
499
+ /**
500
+ * `failed` is terminal, and a run's terminal state is immutable. This error
501
+ * is only ever thrown after a *successful* read of such a run, so re-running
502
+ * the read returns the same record and throws the same error. Marking it
503
+ * non-retryable is what stops the step executor from spending a retry budget
504
+ * on that when the read happens inside a step — a parent awaiting a child's
505
+ * `returnValue` — and then replacing this error with its retry-exhaustion
506
+ * wrapper. A read that *fails* throws something else and stays retryable.
507
+ * See `FatalError.is()`.
508
+ */
509
+ fatal = true;
499
510
  runId;
500
511
  /**
501
512
  * The high-level error category (e.g. USER_ERROR, RUNTIME_ERROR) for the
@@ -786,6 +797,8 @@ Caused by: ${options.cause.stack}`;
786
797
  static {
787
798
  __name(this, "WorkflowRunCancelledError");
788
799
  }
800
+ /** Terminal and immutable, for the same reason as {@link WorkflowRunFailedError.fatal}. */
801
+ fatal = true;
789
802
  runId;
790
803
  constructor(runId) {
791
804
  super(`Workflow run "${runId}" cancelled`, {});
@@ -938,27 +951,6 @@ var init_env_config = __esm({
938
951
  }
939
952
  });
940
953
 
941
- // ../world/dist/spec-version.js
942
- function isLegacySpecVersion(v) {
943
- return v === void 0 || v === null || v <= SPEC_VERSION_LEGACY;
944
- }
945
- var SPEC_VERSION_LEGACY, SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT, SPEC_VERSION_SUPPORTS_ATTRIBUTES, SPEC_VERSION_SUPPORTS_COMPRESSION, SPEC_VERSION_SUPPORTS_SLOT_IDENTITY, SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM, SPEC_VERSION_CURRENT, SPEC_VERSION_MAX_SUPPORTED;
946
- var init_spec_version = __esm({
947
- "../world/dist/spec-version.js"() {
948
- "use strict";
949
- init_env_config();
950
- SPEC_VERSION_LEGACY = 1;
951
- SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT = 3;
952
- SPEC_VERSION_SUPPORTS_ATTRIBUTES = 4;
953
- SPEC_VERSION_SUPPORTS_COMPRESSION = 5;
954
- SPEC_VERSION_SUPPORTS_SLOT_IDENTITY = 6;
955
- SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM = 8;
956
- SPEC_VERSION_CURRENT = SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM;
957
- SPEC_VERSION_MAX_SUPPORTED = SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM;
958
- __name(isLegacySpecVersion, "isLegacySpecVersion");
959
- }
960
- });
961
-
962
954
  // ../core/dist/encryption.js
963
955
  async function importKey(raw, usages = [
964
956
  "encrypt",
@@ -26009,6 +26001,28 @@ var init_slot_identity = __esm({
26009
26001
  }
26010
26002
  });
26011
26003
 
26004
+ // ../world/dist/spec-version.js
26005
+ function isLegacySpecVersion(v) {
26006
+ return v === void 0 || v === null || v <= SPEC_VERSION_LEGACY;
26007
+ }
26008
+ var SPEC_VERSION_LEGACY, SPEC_VERSION_SUPPORTS_EVENT_SOURCING, SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT, SPEC_VERSION_SUPPORTS_ATTRIBUTES, SPEC_VERSION_SUPPORTS_COMPRESSION, SPEC_VERSION_SUPPORTS_SLOT_IDENTITY, SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM, SPEC_VERSION_CURRENT, SPEC_VERSION_MAX_SUPPORTED;
26009
+ var init_spec_version = __esm({
26010
+ "../world/dist/spec-version.js"() {
26011
+ "use strict";
26012
+ init_env_config();
26013
+ SPEC_VERSION_LEGACY = 1;
26014
+ SPEC_VERSION_SUPPORTS_EVENT_SOURCING = 2;
26015
+ SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT = 3;
26016
+ SPEC_VERSION_SUPPORTS_ATTRIBUTES = 4;
26017
+ SPEC_VERSION_SUPPORTS_COMPRESSION = 5;
26018
+ SPEC_VERSION_SUPPORTS_SLOT_IDENTITY = 6;
26019
+ SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM = 8;
26020
+ SPEC_VERSION_CURRENT = SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM;
26021
+ SPEC_VERSION_MAX_SUPPORTED = SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM;
26022
+ __name(isLegacySpecVersion, "isLegacySpecVersion");
26023
+ }
26024
+ });
26025
+
26012
26026
  // ../world/dist/ulid.js
26013
26027
  var UlidSchema, workflowRunIdSchema, DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS, DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS;
26014
26028
  var init_ulid = __esm({
@@ -27540,7 +27554,7 @@ function SemanticConvention(...names) {
27540
27554
  value
27541
27555
  ]));
27542
27556
  }
27543
- var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowExecutionMode, WorkflowBundleCompileCacheHit, WorkflowReplayLoadSource, WorkflowParkedEventsCount, WorkflowParkedEventId, WorkflowParkedEventType, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowVm, QuickJSOutcome, QuickJSEventsPreloaded, QuickJSEventsFetchedCount, QuickJSEventsFetchedPages, QuickJSPendingOpsCount, QuickJSInlineSteps, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowStepsFailedSerialization, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowDispatchRepublishSkipped, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, FaasInstance, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepStartStrategy, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, MessagingBatchMessageCount, QueueOverheadMs, DeploymentId, WorkflowRunPinnedDeploymentId, WorkflowDeploymentMismatchRetryCount, WorkflowDeploymentMismatchRecovered, HookToken, HookId, HookFound, HookResilientResume, HookResumeCommitted, HookWakePublished, HookResilientResumeMaterialized, HookResumeSetupSource, StepResilientDispatchRecovered, StepResilientDispatchMaterialized, StepDispatchPrologue, ResumeTotalMs, ResumeProducerPrepMs, ResumeQueueDeliveryMs, ResumeSetupMs, ResumeReplayMs, ResumeStepDispatchMs, ResumeStepClaimMs, ResumeStepPrepareMs, ResumeTrigger, ResumeStrategy, ResumeSetupSource, ResumeStepExecution, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, SerializationGuestCodeExecutions, SerializationGuestCodeDetails, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
27557
+ var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowExecutionMode, WorkflowBundleCompileCacheHit, WorkflowReplayLoadSource, WorkflowParkedEventsCount, WorkflowParkedEventId, WorkflowParkedEventType, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowVm, QuickJSOutcome, QuickJSEventsPreloaded, QuickJSEventsFetchedCount, QuickJSEventsFetchedPages, QuickJSPendingOpsCount, QuickJSInlineSteps, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowStepsFailedSerialization, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowDispatchRepublishSkipped, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, FaasInstance, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepStartStrategy, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, MessagingBatchMessageCount, QueueOverheadMs, DeploymentId, WorkflowRunPinnedDeploymentId, WorkflowDeploymentMismatchRetryCount, WorkflowDeploymentMismatchRecovered, WorkflowRunSpecVersion, WorkflowRunSpecVersionSource, WorkflowCapabilityProbeLatencyMs, WorkflowCapabilityProbeCached, WorkflowCapabilityProbeError, HookToken, HookId, HookFound, HookResilientResume, HookResumeCommitted, HookWakePublished, HookResilientResumeMaterialized, HookResumeSetupSource, StepResilientDispatchRecovered, StepResilientDispatchMaterialized, StepDispatchPrologue, ResumeTotalMs, ResumeProducerPrepMs, ResumeQueueDeliveryMs, ResumeSetupMs, ResumeReplayMs, ResumeStepDispatchMs, ResumeStepClaimMs, ResumeStepPrepareMs, ResumeTrigger, ResumeStrategy, ResumeSetupSource, ResumeStepExecution, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, SerializationGuestCodeExecutions, SerializationGuestCodeDetails, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
27544
27558
  var init_semantic_conventions = __esm({
27545
27559
  "../core/dist/telemetry/semantic-conventions.js"() {
27546
27560
  "use strict";
@@ -27617,6 +27631,11 @@ var init_semantic_conventions = __esm({
27617
27631
  WorkflowRunPinnedDeploymentId = SemanticConvention("workflow.deployment.pinned_id");
27618
27632
  WorkflowDeploymentMismatchRetryCount = SemanticConvention("workflow.deployment_mismatch.retry_count");
27619
27633
  WorkflowDeploymentMismatchRecovered = SemanticConvention("workflow.deployment_mismatch.recovered");
27634
+ WorkflowRunSpecVersion = SemanticConvention("workflow.run.spec_version");
27635
+ WorkflowRunSpecVersionSource = SemanticConvention("workflow.run.spec_version_source");
27636
+ WorkflowCapabilityProbeLatencyMs = SemanticConvention("workflow.capability_probe.latency_ms");
27637
+ WorkflowCapabilityProbeCached = SemanticConvention("workflow.capability_probe.cached");
27638
+ WorkflowCapabilityProbeError = SemanticConvention("workflow.capability_probe.error");
27620
27639
  HookToken = SemanticConvention("workflow.hook.token");
27621
27640
  HookId = SemanticConvention("workflow.hook.id");
27622
27641
  HookFound = SemanticConvention("workflow.hook.found");
@@ -32295,7 +32314,7 @@ var version2;
32295
32314
  var init_version = __esm({
32296
32315
  "../core/dist/version.js"() {
32297
32316
  "use strict";
32298
- version2 = "5.0.0-beta.56";
32317
+ version2 = "5.0.0-beta.57";
32299
32318
  }
32300
32319
  });
32301
32320
 
@@ -32363,7 +32382,8 @@ function parseHealthCheckResponse(chunks) {
32363
32382
  } catch {
32364
32383
  if (responseText.length > 0) {
32365
32384
  return {
32366
- healthy: true
32385
+ healthy: true,
32386
+ format: "text"
32367
32387
  };
32368
32388
  }
32369
32389
  return null;
@@ -32373,7 +32393,8 @@ function parseHealthCheckResponse(chunks) {
32373
32393
  }
32374
32394
  const r = response;
32375
32395
  const parsed = {
32376
- healthy: r.healthy
32396
+ healthy: r.healthy,
32397
+ format: "json"
32377
32398
  };
32378
32399
  if (typeof r.specVersion === "number") {
32379
32400
  parsed.specVersion = r.specVersion;
@@ -32507,7 +32528,7 @@ async function publishHookWakeWithRetry(publish, isDeploymentUnavailableError) {
32507
32528
  }
32508
32529
  throw lastError;
32509
32530
  }
32510
- var HOOK_WAKE_RETRY_DELAYS_MS;
32531
+ var HOOK_WAKE_RETRY_DELAYS_MS, FORCE_CLAIM_WAKE_REPUBLISH_WINDOW_MS;
32511
32532
  var init_hook_wake = __esm({
32512
32533
  "../core/dist/runtime/hook-wake.js"() {
32513
32534
  "use strict";
@@ -32521,6 +32542,7 @@ var init_hook_wake = __esm({
32521
32542
  ];
32522
32543
  __name(isRetryableWakeError, "isRetryableWakeError");
32523
32544
  __name(publishHookWakeWithRetry, "publishHookWakeWithRetry");
32545
+ FORCE_CLAIM_WAKE_REPUBLISH_WINDOW_MS = 24 * 60 * 60 * 1e3;
32524
32546
  }
32525
32547
  });
32526
32548
 
@@ -32556,6 +32578,18 @@ var init_invocations = __esm({
32556
32578
  }
32557
32579
  });
32558
32580
 
32581
+ // ../core/dist/runtime/run-spec-version.js
32582
+ function specVersionForRunWrite(runSpecVersion, whenUnknown = SPEC_VERSION_CURRENT) {
32583
+ return Math.min(SPEC_VERSION_CURRENT, runSpecVersion ?? whenUnknown);
32584
+ }
32585
+ var init_run_spec_version = __esm({
32586
+ "../core/dist/runtime/run-spec-version.js"() {
32587
+ "use strict";
32588
+ init_spec_version();
32589
+ __name(specVersionForRunWrite, "specVersionForRunWrite");
32590
+ }
32591
+ });
32592
+
32559
32593
  // ../../node_modules/.pnpm/@vercel+functions@3.8.0_@aws-sdk+credential-provider-web-identity@3.972.49_ws@8.20.0/node_modules/@vercel/functions/headers.js
32560
32594
  var require_headers = __commonJS({
32561
32595
  "../../node_modules/.pnpm/@vercel+functions@3.8.0_@aws-sdk+credential-provider-web-identity@3.972.49_ws@8.20.0/node_modules/@vercel/functions/headers.js"(exports, module) {
@@ -37807,7 +37841,8 @@ async function resumeHookAttempt(world, span, tokenOrHook, payload, encryptionKe
37807
37841
  try {
37808
37842
  await world.events.create(hook.runId, {
37809
37843
  eventType: "hook_received",
37810
- specVersion: SPEC_VERSION_CURRENT,
37844
+ // The payload is already encoded for the run (see `compression`).
37845
+ specVersion: specVersionForRunWrite(resumeContext.runSpecVersion),
37811
37846
  correlationId: hook.hookId,
37812
37847
  eventData: {
37813
37848
  ...v1Compat ? {} : {
@@ -37924,6 +37959,7 @@ var init_resume_hook = __esm({
37924
37959
  init_helpers();
37925
37960
  init_hook_wake();
37926
37961
  init_invocations();
37962
+ init_run_spec_version();
37927
37963
  init_wait_until();
37928
37964
  generateResumeId = monotonicFactory();
37929
37965
  __name(computeResumePayloadDigest, "computeResumePayloadDigest");
@@ -39378,13 +39414,13 @@ async function dehydrateStepReturnValue(value, runId, key, ops = [], global2 = g
39378
39414
  });
39379
39415
  }
39380
39416
  }
39381
- async function hydrateRunError(value, runId, key, ops = [], global2 = globalThis, extraRevivers = {}) {
39417
+ async function hydrateRunError(value, runId, key, ops = [], global2 = globalThis, extraRevivers = {}, options) {
39382
39418
  const compressionStats = {};
39383
39419
  const decrypted = await decompress(await decrypt2(value, key), compressionStats);
39384
39420
  await recordCompression(compressionStats, "deserialize");
39385
39421
  if (!(decrypted instanceof Uint8Array)) {
39386
39422
  return unflatten(decrypted, {
39387
- ...getExternalRevivers(global2, ops, runId, key),
39423
+ ...getExternalRevivers(global2, ops, runId, key, options),
39388
39424
  ...extraRevivers
39389
39425
  });
39390
39426
  }
@@ -39392,7 +39428,7 @@ async function hydrateRunError(value, runId, key, ops = [], global2 = globalThis
39392
39428
  if (format === SerializationFormat.DEVALUE_V1) {
39393
39429
  const str = new TextDecoder().decode(payload);
39394
39430
  return parse(str, {
39395
- ...getExternalRevivers(global2, ops, runId, key),
39431
+ ...getExternalRevivers(global2, ops, runId, key, options),
39396
39432
  ...extraRevivers
39397
39433
  });
39398
39434
  }
@@ -39918,11 +39954,11 @@ __builtin_set_attributes.maxRetries = INTERNAL_ATTRIBUTES_MAX_ATTEMPTS - 1;
39918
39954
  init_dist2();
39919
39955
  init_dist3();
39920
39956
  init_env_config();
39921
- init_spec_version();
39922
39957
  init_encryption2();
39923
39958
  init_serialization2();
39924
39959
  init_util2();
39925
39960
  init_get_world_lazy();
39961
+ init_run_spec_version();
39926
39962
 
39927
39963
  // ../core/dist/runtime/runs.js
39928
39964
  init_dist2();
@@ -39930,6 +39966,7 @@ init_dist4();
39930
39966
  init_encryption2();
39931
39967
  init_serialization2();
39932
39968
  init_helpers();
39969
+ init_run_spec_version();
39933
39970
 
39934
39971
  // ../core/dist/runtime/start.js
39935
39972
  init_dist2();
@@ -40047,8 +40084,34 @@ __name(getWorkflowVmFromEnv, "getWorkflowVmFromEnv");
40047
40084
  // ../core/dist/runtime/start.js
40048
40085
  init_wait_until();
40049
40086
  init_world_compatibility();
40050
- var CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS = 2e3;
40087
+ var CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS = 1e4;
40088
+ var CROSS_DEPLOYMENT_PROBE_RETRY_TIMEOUT_MS = 2e3;
40089
+ var CROSS_DEPLOYMENT_PROBE_CACHE_TTL_MS = 10 * 6e4;
40090
+ var CROSS_DEPLOYMENT_PROBE_MISS_TTL_MS = 6e4;
40091
+ var CROSS_DEPLOYMENT_PROBE_CACHE_MAX_ENTRIES = 256;
40051
40092
  var RETENTION_ZERO_ATTRIBUTE_VALUE = "0";
40093
+ function resolveCrossDeploymentSpecVersion(probe, callerSpecVersion) {
40094
+ let target;
40095
+ let source;
40096
+ if (typeof probe?.specVersion === "number" && Number.isInteger(probe.specVersion) && probe.specVersion >= 1) {
40097
+ target = probe.specVersion;
40098
+ source = "probe";
40099
+ } else if (probe?.format === "json") {
40100
+ target = SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT;
40101
+ source = "probe-malformed";
40102
+ } else if (probe?.healthy) {
40103
+ target = SPEC_VERSION_SUPPORTS_EVENT_SOURCING;
40104
+ source = "probe-unversioned";
40105
+ } else {
40106
+ target = SPEC_VERSION_SUPPORTS_SLOT_IDENTITY;
40107
+ source = probe ? "probe-miss" : "no-probe-channel";
40108
+ }
40109
+ return {
40110
+ specVersion: Math.min(target, callerSpecVersion),
40111
+ source
40112
+ };
40113
+ }
40114
+ __name(resolveCrossDeploymentSpecVersion, "resolveCrossDeploymentSpecVersion");
40052
40115
  var ulid3 = monotonicFactory();
40053
40116
  function resolveLineageAttributes() {
40054
40117
  const store = contextStorage.getStore();
@@ -40063,6 +40126,54 @@ __name(resolveLineageAttributes, "resolveLineageAttributes");
40063
40126
  var latestNoOpWarning = globalSingleton("@workflow/core//latestNoOpWarning", 1, () => ({
40064
40127
  warned: false
40065
40128
  }));
40129
+ var probeMissWarning = globalSingleton("@workflow/core//crossDeploymentProbeMissWarning", 1, () => ({
40130
+ warned: false
40131
+ }));
40132
+ var crossDeploymentProbeCache = globalSingleton("@workflow/core//crossDeploymentProbeCache", 1, () => /* @__PURE__ */ new WeakMap());
40133
+ async function probeCrossDeployment(world, options) {
40134
+ let byDeployment = crossDeploymentProbeCache.get(world);
40135
+ if (!byDeployment) {
40136
+ byDeployment = /* @__PURE__ */ new Map();
40137
+ crossDeploymentProbeCache.set(world, byDeployment);
40138
+ }
40139
+ const key = `${options.namespace ?? ""}\0${options.deploymentId}`;
40140
+ const now = Date.now();
40141
+ const entry = byDeployment.get(key);
40142
+ if (entry?.probe !== void 0 && now - entry.at < CROSS_DEPLOYMENT_PROBE_CACHE_TTL_MS) {
40143
+ return {
40144
+ probe: entry.probe,
40145
+ cached: true
40146
+ };
40147
+ }
40148
+ const recentMiss = entry !== void 0 && entry.probe === void 0 && now - entry.at < CROSS_DEPLOYMENT_PROBE_MISS_TTL_MS;
40149
+ const probe = await healthCheck(world, {
40150
+ deploymentId: options.deploymentId,
40151
+ runId: options.runId,
40152
+ timeout: recentMiss ? CROSS_DEPLOYMENT_PROBE_RETRY_TIMEOUT_MS : CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS,
40153
+ namespace: options.namespace
40154
+ }).catch(() => void 0);
40155
+ const answered = probe?.format !== void 0;
40156
+ byDeployment.delete(key);
40157
+ byDeployment.set(key, {
40158
+ // A repeated miss keeps the first miss's time, so the short budget ends
40159
+ // `CROSS_DEPLOYMENT_PROBE_MISS_TTL_MS` after it.
40160
+ at: !answered && recentMiss ? entry.at : Date.now(),
40161
+ // The run public key is per run, so it is never reused.
40162
+ probe: answered ? {
40163
+ ...probe,
40164
+ encryptionPublicKey: void 0
40165
+ } : void 0
40166
+ });
40167
+ if (byDeployment.size > CROSS_DEPLOYMENT_PROBE_CACHE_MAX_ENTRIES) {
40168
+ const oldest = byDeployment.keys().next().value;
40169
+ if (oldest !== void 0) byDeployment.delete(oldest);
40170
+ }
40171
+ return {
40172
+ probe,
40173
+ cached: false
40174
+ };
40175
+ }
40176
+ __name(probeCrossDeployment, "probeCrossDeployment");
40066
40177
  async function start(workflow, argsOrOptions, options) {
40067
40178
  return await waitedUntil(() => {
40068
40179
  const workflowName = workflow?.workflowId;
@@ -40089,19 +40200,34 @@ async function start(workflow, argsOrOptions, options) {
40089
40200
  });
40090
40201
  const world = opts.world ?? await getWorldLazy();
40091
40202
  assertWorldSupportsRuntimeProtocol(world);
40092
- const currentDeploymentId = await world.getDeploymentId();
40093
- let deploymentId = opts.deploymentId ?? currentDeploymentId;
40094
- if (deploymentId === "latest") {
40095
- if (world.resolveLatestDeploymentId) {
40096
- deploymentId = await world.resolveLatestDeploymentId();
40097
- } else {
40098
- if (!latestNoOpWarning.warned) {
40099
- latestNoOpWarning.warned = true;
40100
- runtimeLogger.warn("deploymentId: 'latest' has no effect in this world and was ignored. It is only supported by worlds with atomic deployments, such as Vercel. The run will target the current deployment.", {
40101
- currentDeploymentId
40102
- });
40203
+ let currentDeploymentId;
40204
+ let deploymentId;
40205
+ if (opts.deploymentId === void 0 || opts.deploymentId === "latest") {
40206
+ const current = await world.getDeploymentId();
40207
+ currentDeploymentId = current;
40208
+ deploymentId = opts.deploymentId ?? current;
40209
+ if (deploymentId === "latest") {
40210
+ if (world.resolveLatestDeploymentId) {
40211
+ deploymentId = await world.resolveLatestDeploymentId();
40212
+ } else {
40213
+ if (!latestNoOpWarning.warned) {
40214
+ latestNoOpWarning.warned = true;
40215
+ runtimeLogger.warn("deploymentId: 'latest' has no effect in this world and was ignored. It is only supported by worlds with atomic deployments, such as Vercel. The run will target the current deployment.", {
40216
+ currentDeploymentId
40217
+ });
40218
+ }
40219
+ deploymentId = current;
40103
40220
  }
40104
- deploymentId = currentDeploymentId;
40221
+ }
40222
+ } else {
40223
+ deploymentId = opts.deploymentId;
40224
+ try {
40225
+ currentDeploymentId = await world.getDeploymentId();
40226
+ } catch (err) {
40227
+ runtimeLogger.debug("Current deployment is unavailable; starting as a cross-deployment run", {
40228
+ deploymentId,
40229
+ error: String(err)
40230
+ });
40105
40231
  }
40106
40232
  }
40107
40233
  const runId = `wrun_${world.createRunId ? world.createRunId(opts) : ulid3()}`;
@@ -40109,36 +40235,61 @@ async function start(workflow, argsOrOptions, options) {
40109
40235
  let targetSupportsCompression;
40110
40236
  let targetHookResumeInputVersion;
40111
40237
  let probedRunPublicKey;
40112
- if (deploymentId === currentDeploymentId) {
40238
+ let targetSpecVersion;
40239
+ let specVersionSource;
40240
+ const crossDeployment = deploymentId !== currentDeploymentId;
40241
+ if (!crossDeployment) {
40113
40242
  framedByteStreams = true;
40114
40243
  targetSupportsCompression = true;
40115
40244
  targetHookResumeInputVersion = HOOK_RESUME_INPUT_VERSION;
40245
+ targetSpecVersion = world.specVersion;
40246
+ specVersionSource = "same-deployment";
40116
40247
  } else if (typeof world.streams?.get !== "function") {
40117
40248
  framedByteStreams = false;
40118
40249
  targetSupportsCompression = false;
40119
40250
  targetHookResumeInputVersion = void 0;
40251
+ ({ specVersion: targetSpecVersion, source: specVersionSource } = resolveCrossDeploymentSpecVersion(void 0, world.specVersion));
40120
40252
  } else {
40121
- const probe = await healthCheck(world, {
40253
+ const { probe, cached: cached2 } = await probeCrossDeployment(world, {
40122
40254
  deploymentId,
40123
40255
  runId,
40124
- timeout: CROSS_DEPLOYMENT_CAPABILITY_PROBE_TIMEOUT_MS,
40125
40256
  namespace: opts.namespace
40126
- }).catch(() => void 0);
40257
+ });
40127
40258
  probedRunPublicKey = probe?.encryptionPublicKey;
40128
40259
  const capabilities = getRunCapabilities(probe?.workflowCoreVersion);
40129
40260
  framedByteStreams = capabilities.framedByteStreams;
40130
40261
  targetSupportsCompression = capabilities.supportedFormats.has(SerializationFormat.GZIP);
40131
40262
  targetHookResumeInputVersion = probe?.hookResumeInputVersion;
40263
+ ({ specVersion: targetSpecVersion, source: specVersionSource } = resolveCrossDeploymentSpecVersion(probe, world.specVersion));
40264
+ span?.setAttributes({
40265
+ ...WorkflowCapabilityProbeCached(cached2),
40266
+ ...!cached2 && probe?.latencyMs !== void 0 ? WorkflowCapabilityProbeLatencyMs(probe.latencyMs) : {},
40267
+ ...!cached2 && probe?.error ? WorkflowCapabilityProbeError(probe.error) : {}
40268
+ });
40269
+ if (specVersionSource === "probe-miss" && opts.specVersion === void 0 && !probeMissWarning.warned) {
40270
+ probeMissWarning.warned = true;
40271
+ runtimeLogger.warn("The target deployment did not answer the capability probe, so the run was stamped with a fallback spec version instead of the target's own. A target on an older major version may not be able to execute it.", {
40272
+ deploymentId,
40273
+ specVersion: targetSpecVersion,
40274
+ error: probe?.error
40275
+ });
40276
+ }
40132
40277
  }
40133
40278
  const ops = [];
40134
40279
  const traceCarrier = await serializeTraceCarrier();
40135
- const specVersion = opts.specVersion ?? world.specVersion;
40280
+ const specVersion = opts.specVersion ?? targetSpecVersion;
40281
+ if (opts.specVersion !== void 0) specVersionSource = "explicit";
40282
+ span?.setAttributes({
40283
+ ...WorkflowRunSpecVersion(specVersion),
40284
+ ...WorkflowRunSpecVersionSource(specVersionSource)
40285
+ });
40286
+ const specGateError = /* @__PURE__ */ __name((featureRequires) => new WorkflowRuntimeError(crossDeployment && opts.specVersion === void 0 ? `${featureRequires} spec version ${SPEC_VERSION_SUPPORTS_ATTRIBUTES} or later, but the target deployment (${deploymentId}) runs spec version ${specVersion}.` : `${featureRequires} a World that supports spec version ${SPEC_VERSION_SUPPORTS_ATTRIBUTES} or later.`), "specGateError");
40136
40287
  const v1Compat = isLegacySpecVersion(specVersion);
40137
40288
  const allowReservedAttributes = opts.allowReservedAttributes === true;
40138
40289
  let attributes;
40139
40290
  if (opts.attributes && Object.keys(opts.attributes).length > 0) {
40140
40291
  if (specVersion < SPEC_VERSION_SUPPORTS_ATTRIBUTES) {
40141
- throw new WorkflowRuntimeError("Initial workflow attributes require a World that supports spec version 4 or later.");
40292
+ throw specGateError("Initial workflow attributes require");
40142
40293
  }
40143
40294
  for (const [key, value] of Object.entries(opts.attributes)) {
40144
40295
  if (typeof value !== "string") {
@@ -40159,7 +40310,7 @@ async function start(workflow, argsOrOptions, options) {
40159
40310
  throw new WorkflowRuntimeError(`start({ experimental_retention }) must be 0 or 'default'; received ${JSON.stringify(opts.experimental_retention)}.`);
40160
40311
  }
40161
40312
  if (specVersion < SPEC_VERSION_SUPPORTS_ATTRIBUTES) {
40162
- throw new WorkflowRuntimeError("start({ experimental_retention }) requires a World that supports spec version 4 or later.");
40313
+ throw specGateError("start({ experimental_retention }) requires");
40163
40314
  }
40164
40315
  retentionAttribute = {
40165
40316
  [RETENTION_ATTRIBUTE]: RETENTION_ZERO_ATTRIBUTE_VALUE
@@ -40319,7 +40470,7 @@ __name(start, "start");
40319
40470
  value: "start",
40320
40471
  configurable: true
40321
40472
  });
40322
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.56//start");
40473
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.57//start");
40323
40474
 
40324
40475
  // ../core/dist/runtime/runs.js
40325
40476
  async function wakeUpRun(world, runId, options) {
@@ -40361,7 +40512,7 @@ async function wakeUpRun(world, runId, options) {
40361
40512
  } : {
40362
40513
  eventType: "wait_completed",
40363
40514
  correlationId: waitEvent.correlationId,
40364
- specVersion: run2.specVersion,
40515
+ specVersion: specVersionForRunWrite(run2.specVersion),
40365
40516
  eventData: {
40366
40517
  resumeAt: waitEvent.eventData.resumeAt
40367
40518
  }
@@ -40384,7 +40535,7 @@ async function wakeUpRun(world, runId, options) {
40384
40535
  runId
40385
40536
  }, {
40386
40537
  deploymentId: run2.deploymentId,
40387
- specVersion: run2.specVersion ?? SPEC_VERSION_LEGACY
40538
+ specVersion: specVersionForRunWrite(run2.specVersion, SPEC_VERSION_LEGACY)
40388
40539
  });
40389
40540
  }
40390
40541
  if (errors.length > 0) {
@@ -40535,9 +40686,12 @@ var Run = class _Run {
40535
40686
  */
40536
40687
  async cancel(options) {
40537
40688
  const world = await this.#lazyWorldPromise;
40689
+ const run2 = await world.runs.get(this.runId, {
40690
+ resolveData: "none"
40691
+ });
40538
40692
  await world.events.create(this.runId, {
40539
40693
  eventType: "run_cancelled",
40540
- specVersion: SPEC_VERSION_CURRENT,
40694
+ specVersion: specVersionForRunWrite(run2.specVersion),
40541
40695
  ...options?.cancelReason !== void 0 ? {
40542
40696
  eventData: {
40543
40697
  cancelReason: options.cancelReason
@@ -40790,7 +40944,7 @@ var Run = class _Run {
40790
40944
  value: "wakeUp",
40791
40945
  configurable: true
40792
40946
  });
40793
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#wakeUp");
40947
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#wakeUp");
40794
40948
  (function(__wf_fn, __wf_id) {
40795
40949
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40796
40950
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40799,7 +40953,7 @@ var Run = class _Run {
40799
40953
  value: "cancel",
40800
40954
  configurable: true
40801
40955
  });
40802
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#cancel");
40956
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#cancel");
40803
40957
  (function(__wf_fn, __wf_id) {
40804
40958
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40805
40959
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40808,7 +40962,7 @@ var Run = class _Run {
40808
40962
  value: "getReadable",
40809
40963
  configurable: true
40810
40964
  });
40811
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#getReadable");
40965
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#getReadable");
40812
40966
  (function(__wf_fn, __wf_id) {
40813
40967
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40814
40968
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40817,7 +40971,7 @@ var Run = class _Run {
40817
40971
  value: "getWritable",
40818
40972
  configurable: true
40819
40973
  });
40820
- })(Run.prototype["getWritable"], "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#getWritable");
40974
+ })(Run.prototype["getWritable"], "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#getWritable");
40821
40975
  (function(__wf_fn, __wf_id) {
40822
40976
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40823
40977
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40826,7 +40980,7 @@ var Run = class _Run {
40826
40980
  value: "exists",
40827
40981
  configurable: true
40828
40982
  });
40829
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#exists");
40983
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#exists");
40830
40984
  (function(__wf_fn, __wf_id) {
40831
40985
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40832
40986
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40835,7 +40989,7 @@ var Run = class _Run {
40835
40989
  value: "status",
40836
40990
  configurable: true
40837
40991
  });
40838
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#status");
40992
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#status");
40839
40993
  (function(__wf_fn, __wf_id) {
40840
40994
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40841
40995
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40844,7 +40998,7 @@ var Run = class _Run {
40844
40998
  value: "returnValue",
40845
40999
  configurable: true
40846
41000
  });
40847
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#returnValue");
41001
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#returnValue");
40848
41002
  (function(__wf_fn, __wf_id) {
40849
41003
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40850
41004
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40853,7 +41007,7 @@ var Run = class _Run {
40853
41007
  value: "workflowName",
40854
41008
  configurable: true
40855
41009
  });
40856
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#workflowName");
41010
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#workflowName");
40857
41011
  (function(__wf_fn, __wf_id) {
40858
41012
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40859
41013
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40862,7 +41016,7 @@ var Run = class _Run {
40862
41016
  value: "createdAt",
40863
41017
  configurable: true
40864
41018
  });
40865
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#createdAt");
41019
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#createdAt");
40866
41020
  (function(__wf_fn, __wf_id) {
40867
41021
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40868
41022
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40871,7 +41025,7 @@ var Run = class _Run {
40871
41025
  value: "startedAt",
40872
41026
  configurable: true
40873
41027
  });
40874
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#startedAt");
41028
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#startedAt");
40875
41029
  (function(__wf_fn, __wf_id) {
40876
41030
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40877
41031
  __wf_reg.set(__wf_id, __wf_fn);
@@ -40880,7 +41034,7 @@ var Run = class _Run {
40880
41034
  value: "completedAt",
40881
41035
  configurable: true
40882
41036
  });
40883
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.56//Run#completedAt");
41037
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.57//Run#completedAt");
40884
41038
  (function(__wf_cls, __wf_id) {
40885
41039
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
40886
41040
  __wf_reg.set(__wf_id, __wf_cls);
@@ -40890,7 +41044,7 @@ var Run = class _Run {
40890
41044
  enumerable: false,
40891
41045
  configurable: false
40892
41046
  });
40893
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.56//Run");
41047
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.57//Run");
40894
41048
 
40895
41049
  // ../workflow/dist/stdlib.js
40896
41050
  async function fetch2(...args) {