Skip to content

Workflow.SuspendOnFailure suspends on an activity's first failure, so Activity.retry never retries #10890

Todo

Description

@thewilkybarkid

What version of Effect is running?

4.1.2

What steps can reproduce the bug?

import { Effect, Layer, Schema } from "effect"
import { ClusterWorkflowEngine, TestRunner } from "effect/cluster"
import { Activity, Workflow } from "effect/workflow"

class Failed extends Schema.TaggedError<Failed>()("Failed", {}) {}

let calls = 0

const MyWorkflow = Workflow.make("MyWorkflow", {
  payload: { id: Schema.String },
  error: Failed,
  idempotencyKey: ({ id }) => id
}).annotate(Workflow.SuspendOnFailure, true)

const MyWorkflowLayer = MyWorkflow.toLayer(() =>
  Activity.make({
    name: "step",
    error: Failed,
    // Fails twice, then succeeds
    execute: Effect.suspend(() => (++calls <= 2 ? Effect.fail(new Failed()) : Effect.void))
  }).pipe(Activity.retry({ times: 3 }))
)

const program = Effect.gen(function*() {
  const executionId = yield* MyWorkflow.execute({ id: "a" }, { discard: true })
  yield* Effect.sleep("300 millis")
  const result = yield* MyWorkflow.poll(executionId)
  console.log(calls, result)
})

Effect.runFork(
  program.pipe(
    Effect.provide(
      MyWorkflowLayer.pipe(
        Layer.provideMerge(ClusterWorkflowEngine.layer),
        Layer.provide(TestRunner.layer)
      )
    )
  )
)

What is the expected behavior?

Activity.retry retries the activity, which succeeds on its third attempt, so the workflow completes successfully with calls === 3. SuspendOnFailure would only come into play if the retries were used up.

What do you see instead?

The workflow is Suspended after one call (calls === 1). The retries never run. Each MyWorkflow.resume(executionId) then makes exactly one more attempt.

Without the SuspendOnFailure annotation, the same workflow retries as expected.

Additional information

This seems to come from how ClusterWorkflowEngine runs activities. The activity handler runs entry.activity.executeEncoded through Workflow.intoResult with a WorkflowInstance for the same workflow:

return entry.activity.executeEncoded.pipe(
  Effect.provideContext(context),
  Workflow.intoResult,
  // ...
)

intoResult reads SuspendOnFailure from instance.workflow.annotations, so the activity's failure becomes a suspension (an interrupt) instead of a failure. Activity.retry only retries failures, so it never sees it.

This makes SuspendOnFailure hard to combine with retries: you'd want retries to handle transient failures, and the workflow to park only once they're used up, so it can be resumed after a longer outage.

I haven't checked whether WorkflowEngine.layerMemory behaves the same way.

Activity

  1. added
    bug
    on Nov 24, 2026
  2. self-assigned this
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions