Skip to content

feat(flare-workflow): implement saga rollback/compensation handlers - #499

Merged
getappz merged 1 commit into
masterfrom
task/119-feat-flare-workflow-implement-saga-rollb
Aug 15, 2026
Merged

feat(flare-workflow): implement saga rollback/compensation handlers#499
getappz merged 1 commit into
masterfrom
task/119-feat-flare-workflow-implement-saga-rollb

Conversation

@getappz

@getappz getappz commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Everything is clean: cargo fmt --check passes, cargo clippy -D warnings is clean, and all 62 tests pass (including the 4 new rollback tests), with the LOC gate hook accepting the commit.

Summary

Implemented saga rollback/compensation for crates/flare-workflow per item #118's approved design doc (which lived only on the unmerged task/118 branch — copied it into this branch since neither #117 nor #118 had landed on master yet, matching the item's own rebase-instruction fallback).

Changes:

  • types.rs: new JournalEntry::Rollback { step_id, attempt, result } variant with matching is_completed/entry_type arms.
  • definition.rs: StepDefinition.rollback/rollback_retry_policy fields, with_rollback() builder, ValidationError::RollbackUnsupportedMode rejected in validate() for Collect/Conditional/Sleep/WaitEvent.
  • events.rs: new WorkflowEvent::RollbackCompleted/RollbackStepFailed.
  • src/rollback.rs (new): run_rollback_phase — reverse-start-order unwind, context reconstruction from each step's journaled StepRun snapshot (empty output for the triggering failed step), retry via the existing Backoff/apply_jitter machinery, best-effort continue-on-exhaustion, exactly-once resumption via completed Rollback entries.
  • engine.rs: new finish_workflow_failed helper consolidating both failure-settlement points, running rollback before flipping status to Failed (status stays Running through the unwind so recover() needs no special-casing). Also fixed execute_loop's terminal journal entry to store the full serialized context instead of just the raw output string — the design doc assumed Loop already did this, but master's code didn't, which would have broken rollback context reconstruction for Loop steps.
  • tests/rollback_test.rs (new): all 6 acceptance-criteria scenarios (a)-(f), including a crash-mid-rollback + recover() test proving exactly-once compensation.

Committed as 840ef6c.

Implements item #118's approved design (ROLLBACK_COMPENSATION_DESIGN.md,
carried over from the unmerged design PR): StepDefinition::with_rollback
registers a compensation handler on Sequential/FanOut/Loop steps, rejected
at register_workflow time on unsupported modes via
ValidationError::RollbackUnsupportedMode. On workflow failure, a new
rollback phase (src/rollback.rs) unwinds every succeeded step with a
registered handler in reverse step-start order, reconstructing each
handler's context from that step's own journaled StepRun snapshot (the
failing step itself runs with an empty output, matching Cloudflare's
`output: undefined` case). Compensation is journaled via a new
JournalEntry::Rollback variant for exactly-once resumption across a crash
mid-unwind, and is best-effort: a handler that exhausts its retries is
journaled as failed and the sweep continues rather than aborting. Both
existing failure-settlement points in execute_workflow are consolidated
into one finish_workflow_failed helper that runs the rollback phase before
flipping status to Failed, keeping status at Running throughout the unwind
so recover() naturally resumes a crashed rollback with no new status
variant needed.

Loop's terminal StepRun entry now journals the full serialized context
(matching Sequential/FanOut) instead of just the raw output string, since
rollback context reconstruction depends on that snapshot existing for all
three supported modes.

Agentflare-Agent: claude-code
Agentflare-Branch: task/119-feat-flare-workflow-implement-saga-rollb
Agentflare-Item: 119
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ea4a743f-6839-4a1c-a173-a98b6ff16f6c

📥 Commits

Reviewing files that changed from the base of the PR and between ba59207 and 840ef6c.

📒 Files selected for processing (8)
  • crates/flare-workflow/ROLLBACK_COMPENSATION_DESIGN.md
  • crates/flare-workflow/src/definition.rs
  • crates/flare-workflow/src/engine.rs
  • crates/flare-workflow/src/events.rs
  • crates/flare-workflow/src/lib.rs
  • crates/flare-workflow/src/rollback.rs
  • crates/flare-workflow/src/types.rs
  • crates/flare-workflow/tests/rollback_test.rs

Comment @coderabbitai help to get the list of available commands.

@getappz
getappz merged commit 21f711b into master Aug 15, 2026
17 checks passed
@getappz
getappz deleted the task/119-feat-flare-workflow-implement-saga-rollb branch August 15, 2026 06:23
getappz pushed a commit that referenced this pull request Aug 15, 2026
…e match

The rollback-support check in WorkflowDefinition::validate() was added
by #499 before StepMode::SleepUntil existed on this branch's own #497,
so the merge left the match non-exhaustive. SleepUntil journals only a
timer marker like Sleep, not a context snapshot, so it's unsupported
for rollback the same way.

Agentflare-Agent: claude-code
Agentflare-Branch: task/117-feat-flare-workflow-durable-sleepuntil-s
Agentflare-Item: 117
getappz added a commit that referenced this pull request Aug 15, 2026
* feat(flare-workflow): add durable SleepUntil step mode

Add StepMode::SleepUntil { wake_at } alongside the existing relative
Sleep mode, for absolute-timestamp durable delays (Cloudflare Workflows'
step.sleepUntil() equivalent). Both modes now share execute_sleep via a
WakeAt enum that resolves relative-vs-absolute before the existing
journal-and-recover logic runs, so crash recovery keeps reusing the
originally journaled wake_at unchanged.

Agentflare-Agent: claude-code
Agentflare-Branch: task/117-feat-flare-workflow-durable-sleepuntil-s
Agentflare-Item: 117

* fix(flare-workflow): cover SleepUntil in the rollback-unsupported-mode match

The rollback-support check in WorkflowDefinition::validate() was added
by #499 before StepMode::SleepUntil existed on this branch's own #497,
so the merge left the match non-exhaustive. SleepUntil journals only a
timer marker like Sleep, not a context snapshot, so it's unsupported
for rollback the same way.

Agentflare-Agent: claude-code
Agentflare-Branch: task/117-feat-flare-workflow-durable-sleepuntil-s
Agentflare-Item: 117

---------

Co-authored-by: shiva <shiva@gosysinfo.tech>
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