@rivetkit/workflow-engine 0.0.0-2-3-0-rc-rollback.f0e199e → 0.0.0-claude-edge-bundle-slim.fb63356

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.
@@ -1664,30 +1664,6 @@ function setEntry(storage, location, entry) {
1664
1664
  storage.history.entries.set(key, entry);
1665
1665
  }
1666
1666
 
1667
- // src/utils.ts
1668
- function sleep(ms) {
1669
- return new Promise((resolve) => setTimeout(resolve, ms));
1670
- }
1671
- var TIMEOUT_MAX = 2147483647;
1672
- function setLongTimeout(listener, after) {
1673
- let timeout;
1674
- function start(remaining) {
1675
- if (remaining <= TIMEOUT_MAX) {
1676
- timeout = setTimeout(listener, remaining);
1677
- } else {
1678
- timeout = setTimeout(() => {
1679
- start(remaining - TIMEOUT_MAX);
1680
- }, TIMEOUT_MAX);
1681
- }
1682
- }
1683
- start(after);
1684
- return {
1685
- abort: () => {
1686
- if (timeout !== void 0) clearTimeout(timeout);
1687
- }
1688
- };
1689
- }
1690
-
1691
1667
  // src/context.ts
1692
1668
  var DEFAULT_MAX_RETRIES = 3;
1693
1669
  var DEFAULT_RETRY_BACKOFF_BASE = 100;
@@ -1963,7 +1939,7 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
1963
1939
  * Throws HistoryDivergedError if duplicate detected.
1964
1940
  */
1965
1941
  checkDuplicateName(name) {
1966
- const fullKey = locationToKey(this.storage, this.currentLocation) + "/" + name;
1942
+ const fullKey = `${locationToKey(this.storage, this.currentLocation)}/${name}`;
1967
1943
  if (this.usedNamesInExecution.has(fullKey)) {
1968
1944
  throw new HistoryDivergedError(
1969
1945
  `Duplicate entry name "${name}" at location "${locationToKey(this.storage, this.currentLocation)}". Each step/loop/sleep/queue.next/join/race must have a unique name within its scope.`
@@ -2017,7 +1993,7 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2017
1993
  validateComplete() {
2018
1994
  const prefix = locationToKey(this.storage, this.currentLocation);
2019
1995
  for (const key of this.storage.history.entries.keys()) {
2020
- const isUnderPrefix = prefix === "" ? true : key.startsWith(prefix + "/") || key === prefix;
1996
+ const isUnderPrefix = prefix === "" ? true : key.startsWith(`${prefix}/`) || key === prefix;
2021
1997
  if (isUnderPrefix) {
2022
1998
  if (!this.visitedKeys.has(key)) {
2023
1999
  throw new HistoryDivergedError(
@@ -2034,25 +2010,33 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2034
2010
  this.abortController.abort(new EvictedError());
2035
2011
  }
2036
2012
  /**
2037
- * Wait for eviction message.
2038
- *
2039
- * The event listener uses { once: true } to auto-remove after firing,
2040
- * preventing memory leaks if this method is called multiple times.
2013
+ * Wait for `ms`, rejecting early with EvictedError if the workflow is
2014
+ * evicted. Both the timer and the abort listener are torn down on either
2015
+ * outcome, so a completed sleep never leaves a dangling listener on the
2016
+ * long-lived run abort signal.
2041
2017
  */
2042
- waitForEviction() {
2043
- return new Promise((_, reject) => {
2044
- if (this.abortSignal.aborted) {
2045
- reject(new EvictedError());
2046
- return;
2018
+ async sleepOrEvict(ms) {
2019
+ if (this.abortSignal.aborted) {
2020
+ throw new EvictedError();
2021
+ }
2022
+ let timer;
2023
+ let onAbort;
2024
+ try {
2025
+ await new Promise((resolve, reject) => {
2026
+ timer = setTimeout(resolve, ms);
2027
+ onAbort = () => reject(new EvictedError());
2028
+ this.abortSignal.addEventListener("abort", onAbort, {
2029
+ once: true
2030
+ });
2031
+ });
2032
+ } finally {
2033
+ if (timer !== void 0) {
2034
+ clearTimeout(timer);
2047
2035
  }
2048
- this.abortSignal.addEventListener(
2049
- "abort",
2050
- () => {
2051
- reject(new EvictedError());
2052
- },
2053
- { once: true }
2054
- );
2055
- });
2036
+ if (onAbort) {
2037
+ this.abortSignal.removeEventListener("abort", onAbort);
2038
+ }
2039
+ }
2056
2040
  }
2057
2041
  // === Step ===
2058
2042
  async step(nameOrConfig, run) {
@@ -2294,7 +2278,7 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2294
2278
  entry.kind.data.error = String(error);
2295
2279
  }
2296
2280
  entry.dirty = true;
2297
- if (error instanceof StepTimeoutError) {
2281
+ if (error instanceof StepTimeoutError && !config2.retryOnTimeout) {
2298
2282
  metadata.status = "exhausted";
2299
2283
  metadata.error = String(error);
2300
2284
  await this.notifyStepError(config2, metadata.attempts, error, {
@@ -2350,7 +2334,7 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2350
2334
  attachTryStepFailure(
2351
2335
  new StepExhaustedError(config2.name, String(error)),
2352
2336
  {
2353
- kind: "exhausted",
2337
+ kind: error instanceof StepTimeoutError ? "timeout" : "exhausted",
2354
2338
  stepName: config2.name,
2355
2339
  attempts: metadata.attempts,
2356
2340
  error: extractErrorInfo(error)
@@ -2368,7 +2352,9 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2368
2352
  *
2369
2353
  * Note: This does NOT cancel the underlying operation. JavaScript Promises
2370
2354
  * cannot be cancelled once started. When a timeout occurs:
2371
- * - The step is marked as failed with StepTimeoutError
2355
+ * - The step is rejected with StepTimeoutError. By default this is treated
2356
+ * as a critical failure with no retry. Set retryOnTimeout: true on the
2357
+ * step config to retry timeouts like any other error.
2372
2358
  * - The underlying async operation continues running in the background
2373
2359
  * - Any side effects from the operation may still occur
2374
2360
  *
@@ -2693,7 +2679,7 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
2693
2679
  return;
2694
2680
  }
2695
2681
  if (remaining < this.driver.workerPollInterval) {
2696
- await Promise.race([sleep(remaining), this.waitForEviction()]);
2682
+ await this.sleepOrEvict(remaining);
2697
2683
  this.checkEvicted();
2698
2684
  if (entry.kind.type === "sleep") {
2699
2685
  entry.kind.data.state = "completed";
@@ -3504,6 +3490,30 @@ var WorkflowContextImpl = class _WorkflowContextImpl {
3504
3490
  }
3505
3491
  };
3506
3492
 
3493
+ // src/utils.ts
3494
+ function sleep(ms) {
3495
+ return new Promise((resolve) => setTimeout(resolve, ms));
3496
+ }
3497
+ var TIMEOUT_MAX = 2147483647;
3498
+ function setLongTimeout(listener, after) {
3499
+ let timeout;
3500
+ function start(remaining) {
3501
+ if (remaining <= TIMEOUT_MAX) {
3502
+ timeout = setTimeout(listener, remaining);
3503
+ } else {
3504
+ timeout = setTimeout(() => {
3505
+ start(remaining - TIMEOUT_MAX);
3506
+ }, TIMEOUT_MAX);
3507
+ }
3508
+ }
3509
+ start(after);
3510
+ return {
3511
+ abort: () => {
3512
+ if (timeout !== void 0) clearTimeout(timeout);
3513
+ }
3514
+ };
3515
+ }
3516
+
3507
3517
  // src/index.ts
3508
3518
  var Loop = {
3509
3519
  continue: (state) => ({
@@ -3727,25 +3737,41 @@ async function executeLiveWorkflow(workflowId, workflowFn, input, driver, messag
3727
3737
  const hasMessages = result.waitingForMessages !== void 0;
3728
3738
  const hasDeadline = result.sleepUntil !== void 0;
3729
3739
  if (hasMessages && hasDeadline) {
3740
+ const iterationAbort = new AbortController();
3741
+ const onRunAbort = () => iterationAbort.abort();
3742
+ if (abortController.signal.aborted) {
3743
+ iterationAbort.abort();
3744
+ } else {
3745
+ abortController.signal.addEventListener("abort", onRunAbort, {
3746
+ once: true
3747
+ });
3748
+ }
3749
+ const messagePromise = awaitWithEviction(
3750
+ driver.waitForMessages(
3751
+ result.waitingForMessages,
3752
+ iterationAbort.signal
3753
+ ),
3754
+ iterationAbort.signal
3755
+ );
3756
+ const sleepPromise = waitForSleep(
3757
+ runtime,
3758
+ result.sleepUntil,
3759
+ iterationAbort.signal
3760
+ );
3761
+ messagePromise.catch(() => {
3762
+ });
3763
+ sleepPromise.catch(() => {
3764
+ });
3730
3765
  try {
3731
- const messagePromise = awaitWithEviction(
3732
- driver.waitForMessages(
3733
- result.waitingForMessages,
3734
- abortController.signal
3735
- ),
3736
- abortController.signal
3737
- );
3738
- const sleepPromise = waitForSleep(
3739
- runtime,
3740
- result.sleepUntil,
3741
- abortController.signal
3742
- );
3743
3766
  await Promise.race([messagePromise, sleepPromise]);
3744
3767
  } catch (error) {
3745
3768
  if (error instanceof EvictedError) {
3746
3769
  return lastResult;
3747
3770
  }
3748
3771
  throw error;
3772
+ } finally {
3773
+ iterationAbort.abort();
3774
+ abortController.signal.removeEventListener("abort", onRunAbort);
3749
3775
  }
3750
3776
  continue;
3751
3777
  }
@@ -4188,15 +4214,15 @@ export {
4188
4214
  deleteEntriesWithPrefix,
4189
4215
  getEntry,
4190
4216
  setEntry,
4191
- sleep,
4192
4217
  DEFAULT_MAX_RETRIES,
4193
4218
  DEFAULT_RETRY_BACKOFF_BASE,
4194
4219
  DEFAULT_RETRY_BACKOFF_MAX,
4195
4220
  DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL,
4196
4221
  DEFAULT_STEP_TIMEOUT,
4197
4222
  WorkflowContextImpl,
4223
+ sleep,
4198
4224
  Loop,
4199
4225
  runWorkflow,
4200
4226
  replayWorkflowFromStep
4201
4227
  };
4202
- //# sourceMappingURL=chunk-EAAPMGGE.js.map
4228
+ //# sourceMappingURL=chunk-KA2T56AJ.js.map