@rivetkit/workflow-engine 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-sync-3-0-1-release.95f6e2d

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.
@@ -1994,6 +1994,37 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
1994
1994
  markVisited(key) {
1995
1995
  this.visitedKeys.add(key);
1996
1996
  }
1997
+ /**
1998
+ * Mark all retained history under `location` as visited.
1999
+ *
2000
+ * Replay does not re-enter a settled scope, but its entries stay in history.
2001
+ * Without this, an enclosing validateComplete or getVersion treats them as
2002
+ * leftovers from changed workflow code.
2003
+ */
2004
+ markSettledHistoryVisited(location) {
2005
+ for (const [key, entry] of this.storage.history.entries) {
2006
+ if (isLocationPrefix(location, entry.location)) {
2007
+ this.markVisited(key);
2008
+ }
2009
+ }
2010
+ }
2011
+ /**
2012
+ * Mark the retained history of a resumed loop's finished iterations as
2013
+ * visited, because the loop continues from `resumeIteration` without
2014
+ * replaying them.
2015
+ */
2016
+ markFinishedIterationsVisited(loopLocation, resumeIteration) {
2017
+ const loopSegment = loopLocation[loopLocation.length - 1];
2018
+ for (const [key, entry] of this.storage.history.entries) {
2019
+ if (!isLocationPrefix(loopLocation, entry.location)) {
2020
+ continue;
2021
+ }
2022
+ const iterationSegment = entry.location[loopLocation.length];
2023
+ if (iterationSegment && typeof iterationSegment !== "number" && iterationSegment.loop === loopSegment && iterationSegment.iteration < resumeIteration) {
2024
+ this.markVisited(key);
2025
+ }
2026
+ }
2027
+ }
1997
2028
  /**
1998
2029
  * Check if a name has already been used at the current location in this execution.
1999
2030
  * Throws HistoryDivergedError if duplicate detected.
@@ -2521,6 +2552,9 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
2521
2552
  this.driver,
2522
2553
  existing.id
2523
2554
  );
2555
+ if (metadata.status === "completed" || loopData.output !== void 0) {
2556
+ this.markSettledHistoryVisited(location);
2557
+ }
2524
2558
  if (rollbackMode) {
2525
2559
  if (loopData.output !== void 0) {
2526
2560
  return loopData.output;
@@ -2538,6 +2572,7 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
2538
2572
  entry = existing;
2539
2573
  state = loopData.state;
2540
2574
  iteration = loopData.iteration;
2575
+ this.markFinishedIterationsVisited(location, iteration);
2541
2576
  if (rollbackMode) {
2542
2577
  rollbackOutput = loopData.output;
2543
2578
  rollbackIterationRan = rollbackOutput !== void 0;
@@ -3208,19 +3243,21 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3208
3243
  `Expected join branch "${branchName}" in "${name}"`
3209
3244
  );
3210
3245
  }
3246
+ const branchLocation = appendName(
3247
+ this.storage,
3248
+ location,
3249
+ branchName
3250
+ );
3211
3251
  if (branchStatus.status === "completed") {
3252
+ this.markSettledHistoryVisited(branchLocation);
3212
3253
  results[branchName] = branchStatus.output;
3213
3254
  return;
3214
3255
  }
3215
3256
  if (branchStatus.status === "failed") {
3257
+ this.markSettledHistoryVisited(branchLocation);
3216
3258
  errors[branchName] = new Error(branchStatus.error);
3217
3259
  return;
3218
3260
  }
3219
- const branchLocation = appendName(
3220
- this.storage,
3221
- location,
3222
- branchName
3223
- );
3224
3261
  const branchCtx = this.createBranch(branchLocation);
3225
3262
  branchStatus.status = "running";
3226
3263
  branchStatus.error = void 0;
@@ -3312,6 +3349,7 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3312
3349
  entry = existing;
3313
3350
  const raceKind = existing.kind;
3314
3351
  if (raceKind.data.winner !== null) {
3352
+ this.markSettledHistoryVisited(location);
3315
3353
  const winnerStatus = raceKind.data.branches[raceKind.data.winner];
3316
3354
  return {
3317
3355
  winner: raceKind.data.winner,
@@ -3370,6 +3408,7 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3370
3408
  }
3371
3409
  }
3372
3410
  if (hasWinner && winnerName !== null) {
3411
+ this.markSettledHistoryVisited(location);
3373
3412
  return { winner: winnerName, value: winnerValue };
3374
3413
  }
3375
3414
  for (const branch of branches) {
@@ -3379,14 +3418,15 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3379
3418
  `Expected race branch "${branch.name}" in "${name}"`
3380
3419
  );
3381
3420
  }
3382
- if (branchStatus.status !== "pending" && branchStatus.status !== "running") {
3383
- continue;
3384
- }
3385
3421
  const branchLocation = appendName(
3386
3422
  this.storage,
3387
3423
  location,
3388
3424
  branch.name
3389
3425
  );
3426
+ if (branchStatus.status !== "pending" && branchStatus.status !== "running") {
3427
+ this.markSettledHistoryVisited(branchLocation);
3428
+ continue;
3429
+ }
3390
3430
  const branchCtx = this.createBranch(
3391
3431
  branchLocation,
3392
3432
  raceAbortController
@@ -3394,7 +3434,12 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3394
3434
  branchStatus.status = "running";
3395
3435
  branchStatus.error = void 0;
3396
3436
  entry.dirty = true;
3397
- const branchPromise = branch.run(branchCtx).then(
3437
+ const runBranch = async () => {
3438
+ const output = await branch.run(branchCtx);
3439
+ branchCtx.validateComplete();
3440
+ return output;
3441
+ };
3442
+ const branchPromise = runBranch().then(
3398
3443
  async (output) => {
3399
3444
  if (hasWinner) {
3400
3445
  branchStatus.status = "completed";
@@ -3413,7 +3458,6 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3413
3458
  hasWinner = true;
3414
3459
  winnerName = branch.name;
3415
3460
  winnerValue = output;
3416
- branchCtx.validateComplete();
3417
3461
  branchStatus.status = "completed";
3418
3462
  branchStatus.output = output;
3419
3463
  branchStatus.error = void 0;
@@ -3548,6 +3592,7 @@ var WorkflowContextImpl = (_class = class _WorkflowContextImpl {
3548
3592
  `Expected ${originalType} or removed at ${key}, found ${existing.kind.type}`
3549
3593
  );
3550
3594
  }
3595
+ this.markSettledHistoryVisited(location);
3551
3596
  return;
3552
3597
  }
3553
3598
  const entry = createEntry(location, {
@@ -4402,4 +4447,4 @@ async function executeWorkflow(workflowId, workflowFn, input, driver, messageDri
4402
4447
 
4403
4448
 
4404
4449
  exports.extractErrorInfo = extractErrorInfo; exports.CriticalError = CriticalError; exports.RollbackError = RollbackError; exports.RollbackCheckpointError = RollbackCheckpointError; exports.SleepError = SleepError; exports.MessageWaitError = MessageWaitError; exports.EvictedError = EvictedError; exports.HistoryDivergedError = HistoryDivergedError; exports.StepExhaustedError = StepExhaustedError; exports.StepFailedError = StepFailedError; exports.JoinError = JoinError; exports.RaceError = RaceError; exports.CancelledError = CancelledError; exports.EntryInProgressError = EntryInProgressError; exports.keyStartsWith = keyStartsWith; exports.compareKeys = compareKeys; exports.keyToHex = keyToHex; exports.isLoopIterationMarker = isLoopIterationMarker; exports.registerName = registerName; exports.resolveName = resolveName; exports.locationToKey = locationToKey; exports.appendName = appendName; exports.appendLoopIteration = appendLoopIteration; exports.emptyLocation = emptyLocation; exports.parentLocation = parentLocation; exports.isLocationPrefix = isLocationPrefix; exports.locationsEqual = locationsEqual; exports.createStorage = createStorage; exports.createHistorySnapshot = createHistorySnapshot; exports.generateId = generateId; exports.createEntry = createEntry; exports.getOrCreateMetadata = getOrCreateMetadata; exports.loadStorage = loadStorage; exports.loadMetadata = loadMetadata; exports.flush = flush; exports.deleteEntriesWithPrefix = deleteEntriesWithPrefix; exports.getEntry = getEntry; exports.setEntry = setEntry; exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES; exports.DEFAULT_RETRY_BACKOFF_BASE = DEFAULT_RETRY_BACKOFF_BASE; exports.DEFAULT_RETRY_BACKOFF_MAX = DEFAULT_RETRY_BACKOFF_MAX; exports.DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL = DEFAULT_LOOP_HISTORY_PRUNE_INTERVAL; exports.DEFAULT_STEP_TIMEOUT = DEFAULT_STEP_TIMEOUT; exports.WorkflowContextImpl = WorkflowContextImpl; exports.sleep = sleep; exports.Loop = Loop; exports.runWorkflow = runWorkflow; exports.replayWorkflowFromStep = replayWorkflowFromStep;
4405
- //# sourceMappingURL=chunk-XRITRTKT.cjs.map
4450
+ //# sourceMappingURL=chunk-AO3IZAQ4.cjs.map