Skip to content

[Bug]: workflows: a run that pauses while a wake is being delivered runs its failed step again #42656

Done

Description

@juliusmarminge

What happens

wake in apps/server/src/workflows/WorkflowEngine.ts checks whether a run is paused and then delivers the wake in a separate step:

const wake = Effect.fnUntraced(function* (wait, value) {
  if (resuming.has(wait.run_id) || (yield* store.run(wait.run_id))?.status === "paused") return;
  yield* send(wait, value);
});

The comment above it says why the check exists: the engine would replay a paused run for the wake and run its failed step again unasked, so for a paused run the claim keeps the value and the resume sends it.

If a sibling step fails and pauses the run between the status read and send, the delivery still goes out. The engine then replays the run and runs the failed step again without anyone resuming it. This applies to every wake that goes through here: an answer, a timeout, a withdrawal, a signal.

Raised in review of #42506; the code predates that change.

Expected

A run that is paused when the wake is delivered is not resumed by it. The value stays with the claim and is sent on an explicit resume, as for a run that was already paused at the check.

Notes

  • Not reproduced in a running server; found by reading. A test needs a workflow with a failing step beside an open wait (the doubting fixture in Workflows.test.ts has that shape) and a way to make the step fail between the read and the send.
  • The review did not find an existing store operation that makes the check and the delivery atomic with respect to a pause. Either the pause is applied so a later delivery cannot resume the run, or the delivery is held until the explicit resume.

Acceptance

  • A test where the run pauses between the status read and the delivery: the failed step does not run again until the run is resumed, and the waited-on value is delivered on that resume.
  • Wakes for runs that are not paused behave as today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions