Skip to content

fix(rivetkit0: fix wf history diverged bug#4321

Draft
NathanFlurry wants to merge 1 commit intochore-website-addfrom
02-26-fix_rivetkit0_fix_wf_history_diverged_bug
Draft

fix(rivetkit0: fix wf history diverged bug#4321
NathanFlurry wants to merge 1 commit intochore-website-addfrom
02-26-fix_rivetkit0_fix_wf_history_diverged_bug

Conversation

@NathanFlurry
Copy link
Member

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
Copy link

railway-app bot commented Feb 27, 2026

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

Service Status Web Updated (UTC)
frontend-inspector 😴 Sleeping (View Logs) Web Feb 28, 2026 at 8:46 pm
frontend-cloud ✅ Success (View Logs) Web Feb 28, 2026 at 8:41 pm
website 😴 Sleeping (View Logs) Web Feb 27, 2026 at 1:04 am
mcp-hub ✅ Success (View Logs) Web Feb 27, 2026 at 12:53 am
ladle ❌ Build Failed (View Logs) Web Feb 27, 2026 at 12:52 am

Copy link
Member Author


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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 27, 2026

More templates

@rivetkit/cloudflare-workers

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/sqlite-vfs

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

@rivetkit/traces

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

@rivetkit/workflow-engine

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

@rivetkit/virtual-websocket

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: c34c1d0

@claude
Copy link

claude bot commented Feb 27, 2026

PR Review: fix(rivetkit): fix wf history diverged bug

Note: PR title has a typo fix(rivetkit0: — the 0 appears to be accidental.


Summary

This PR fixes a HistoryDivergedError that surfaces when workflow branches (in join, loop, and race) complete but their visited-key sets are not propagated back to the parent context, causing spurious diverge errors on replay.

The approach is sound: two new methods (mergeVisitedKeys and markAllEntriesVisited) ensure the parent context is aware of all entries touched by child branches, both freshly-executed and already-completed ones.


Issues

1. Race losers's keys are not marked as visited

In race, mergeVisitedKeys is called only for the winning branch. Losing branches that had already executed some steps before being cancelled will have entries in history that are never marked visited. If validateComplete is called on the parent after a race, those orphaned entries could still trigger a diverge error. Consider calling markAllEntriesVisited(branchLocation) for each losing branch, mirroring the already-completed/already-failed path in join.

2. Prefix collision risk in markAllEntriesVisited

The check key.startsWith(prefix + "/") || key === prefix is safe as long as / is the canonical separator from locationToKey/appendName. However, if prefix is ever an empty string (root level), key === "" would match every entry. Worth adding a guard or assertion that prefix is non-empty before the iteration.

3. Loose assertion in sequential test

expect(state.requestsCompleted).toBeGreaterThanOrEqual(2);

Two requests are sent; exactly 2 should complete. toBeGreaterThanOrEqual(2) would pass even if a phantom third completion occurred. Prefer toBe(2) to match the fixture semantics.

4. Explicit type annotation hints at inference gap

The branchCtx: WorkflowLoopContextOf<typeof workflowBatchJoinActor> annotation inside the join fixture should not be necessary if generics thread correctly through the run callback. Its presence suggests the branch context type is not being inferred from the enclosing actor. Not a blocker, but worth a follow-up issue.


Minor

  • Fixture uses index-based branch keys row-${i} rather than ID-based row-${rowId}. No functional problem, but a comment clarifying intent would help future readers.
  • markAllEntriesVisited does a full scan of history entries per already-completed branch. Fine for typical depths; not a concern in practice.

What's Good

  • Root cause diagnosis is correct: the parent visitedKeys set was blind to entries touched by child branches, causing false diverge errors on replay.
  • Calling markAllEntriesVisited for already-completed/failed branches correctly handles the fast-path during replay, not just fresh executions.
  • Test coverage is solid: the batch-join fixture exercises both single-request and multi-request sequential paths. Polling pattern is consistent with existing tests.
  • JSDoc on both new methods clearly explains intent and usage context.

Verdict: The core fix is correct and well-targeted. Main actionable items before merging: handle race losers (#1) and tighten the sequential test assertion (#3). The rest are low-priority follow-ups.

@NathanFlurry NathanFlurry changed the base branch from main to chore-website-add February 27, 2026 00:56
@NathanFlurry NathanFlurry force-pushed the 02-26-fix_rivetkit0_fix_wf_history_diverged_bug branch from 84d288e to c34c1d0 Compare February 27, 2026 00:56
@NathanFlurry
Copy link
Member Author

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.

1 participant