Skip to content

fix(rivetkit/wf): replay successful result mechanism#4310

Merged
NathanFlurry merged 1 commit intomainfrom
02-25-fix_rivetkit_wf_replay_successful_result_mechanism
Feb 26, 2026
Merged

fix(rivetkit/wf): replay successful result mechanism#4310
NathanFlurry merged 1 commit intomainfrom
02-25-fix_rivetkit_wf_replay_successful_result_mechanism

Conversation

@abcxff
Copy link
Contributor

@abcxff abcxff commented Feb 25, 2026

FIXES RVT-6000

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4310 February 25, 2026 15:05 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 25, 2026

🚅 Deployed to the rivet-pr-4310 environment in rivet-frontend

Service Status Web Updated (UTC)
website 😴 Sleeping (View Logs) Web Feb 25, 2026 at 3:19 pm
frontend-inspector 😴 Sleeping (View Logs) Web Feb 25, 2026 at 3:18 pm
frontend-cloud 😴 Sleeping (View Logs) Web Feb 25, 2026 at 3:15 pm
mcp-hub ✅ Success (View Logs) Web Feb 25, 2026 at 3:06 pm
ladle ❌ Build Failed (View Logs) Web Feb 25, 2026 at 3:06 pm

Copy link
Contributor Author

abcxff commented Feb 25, 2026


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@abcxff abcxff requested a review from NathanFlurry February 25, 2026 15:06
@linear
Copy link

linear bot commented Feb 25, 2026

@abcxff abcxff marked this pull request as ready for review February 25, 2026 15:07
@claude
Copy link

claude bot commented Feb 25, 2026

PR Review: fix(rivetkit/wf): replay successful result mechanism

The fix correctly addresses a real bug: void steps/loops (those returning undefined) were being re-executed on workflow restart because the old replay guard stepData.output \!== undefined treats undefined outputs as "not yet run." Using metadata.status === "completed" as the authoritative source is the right fix.


What's good

  • Core fix is sound. metadata.status === "completed" correctly captures completion regardless of the return value.
  • Redundant fallback preserved. The legacy loopData.output \!== undefined check remains as a backwards-compatibility guard for loop entries persisted before metadata tracking was introduced.
  • Test coverage is solid. Both void-step and void-loop restart scenarios are tested independently across all driver modes.

Issues / suggestions

1. Missing debug log after refactor (minor)

The original code logged when a step was replayed from history:

this.log("debug", { msg: "replaying step from history", step: config.name, key });

This was silently dropped in the refactor. This log is useful for diagnosing replay issues. Consider restoring it inside the new guard:

if (metadata.status === "completed" || stepData.output \!== undefined) {
    this.log("debug", { msg: "replaying step from history", step: config.name, key });
    return stepData.output as T;
}

2. loadMetadata now always called on step replay (minor performance regression)

Before the fix, non-void steps had a fast path — they returned immediately without loading metadata. Now loadMetadata is always called first, adding an I/O round-trip for every historical non-void step replay too. The fix is necessary for correctness, but a comment noting the tradeoff (or an optimized path like checking output first and skipping metadata load) would help future maintainers understand why the order changed.

3. Rollback mode behavior change for completed void loops (needs confirmation)

In the original code, a completed void loop in rollback mode fell through to re-execute one iteration (because both guards evaluated false):

// rollback guard: loopData.output === undefined → no early return
// completion guard: loopData.output === undefined → no early return
// → rollbackSingleIteration = true, loop re-runs

After the fix, metadata.status === "completed" causes an early return before the loop re-executes. This is arguably more correct (a completed loop doesn't need a rollback iteration), but it's an implicit behavior change worth documenting with a comment, and ideally a test covering a void loop inside a rollback-mode workflow.

4. metadata.status = "running" reset for an already-completed loop with undefined output (subtle)

If metadata.status \!== "completed" but loopData.output \!== undefined, the code returns early at the legacy guard (line 663) — so the if (metadata) { metadata.status = "running"; ... } block is never reached. That's fine. But if both are false (loop in progress, no output yet), the code proceeds to set metadata.status = "running", which correctly restores the running state. The control flow is correct, but non-obvious — a brief comment at the `if (metadata)" block explaining "only reached when loop is resuming from an incomplete state" would help.


CI workflow change

Removal of \!@rivetkit/example-registry from the turbo build filter looks intentional (restoring a previously excluded package). Worth confirming this doesn't break the pkg-pr-new publish step if @rivetkit/example-registry has no publishable build output.


Summary

The bug fix is correct and the test coverage is appropriate. The four items above are minor (one log, one perf note, one rollback edge case needing a test, one readability comment). None are blockers, but item 3 (rollback behavior for void loops) is worth a quick sanity check.

@abcxff abcxff force-pushed the 02-25-fix_rivetkit_wf_replay_successful_result_mechanism branch from d5f9531 to 2841137 Compare February 25, 2026 15:11
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4310 February 25, 2026 15:11 Destroyed
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@4310

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@4310

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@4310

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@4310

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@4310

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@4310

@rivetkit/sqlite-vfs

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sqlite-vfs@4310

@rivetkit/traces

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/traces@4310

@rivetkit/workflow-engine

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/workflow-engine@4310

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@4310

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@4310

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@4310

commit: 2841137

@NathanFlurry NathanFlurry merged commit dad1242 into main Feb 26, 2026
15 of 24 checks passed
@NathanFlurry NathanFlurry deleted the 02-25-fix_rivetkit_wf_replay_successful_result_mechanism branch February 26, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants