Skip to content

Workflow (saga) timeouts #259

Closed
Closed

Description

@adenhertog

Context

Timeouts are the most common saga need: "if payment isn't received in 24h, cancel the order".

Messages sent from a workflow handler already carry stickyAttributes.workflowId, and the default when lookup maps it back to $workflowId. So once #258 lands, a delayed send from a workflow handler is already a timeout routed to its instance.

The gap is noise. A message for a completed workflow logs No existing workflow state found for message. Ignoring. at error level in WorkflowRegistry, and a timeout would trip that routinely.

Decisions

Answered by the maintainer:

  1. No timeout API. A timeout is ctx.send(new PaymentTimedOut(...), { deliverAfter }), handled with .when(PaymentTimedOut, ...). It's an ordinary message, type-checked by the existing workflow mapper checks.

Proposed:

  1. A message whose workflow instance has completed or been discarded is dropped and logged at debug. On a miss, the registry re-queries with includeCompleted to tell "completed" apart from "never existed". "Never existed" stays a warning or error.
  2. There's no cancellation: the timeout handler checks the state and ignores itself if the step already happened.
  3. Time control in tests is Handler and workflow test helpers #265's job: its workflow scenario runner records delayed sends and delivers them with advanceTime.

Non-goals

  • Cancelling a timeout.
  • A timeout-specific mapper method or a requestTimeout helper.
  • Fake clocks.

Approach

  • WorkflowRegistry: the miss handling described in decision 2. No new persistence methods; getWorkflowState(..., includeCompleted) already exists in every persistence.
  • Integration tests in bus-core for class workflows and defineWorkflow workflows, using the in-memory transport.
  • Docs page /guide/workflows/timeouts with snippets for both workflow styles.

Acceptance criteria

  • A delayed send from a workflow handler is handled by that workflow instance only
  • A timeout that arrives after the workflow completed is ignored, logged at debug, not error
  • Tests for class and function workflows
  • Docs page and snippets; changeset

Activity

  1. adenhertog commented on Oct 3, 2026

    @adenhertog
    ContributorAuthor

    When this lands, update the request/reply guide (docs/guide/workflows/request-reply.md, added in #330) to show timing out a reply that never arrives, and link to the timeouts page from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestroadmapPart of the project roadmap

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions