← Back
Cloudflare
Cloudflare Workflows exposes retry attempt numbers in step context

Retry Attempt Context Now Available

Cloudflare Workflows has introduced a new capability that exposes the current retry attempt number to workflow steps. This enhancement allows developers to access which retry attempt is currently executing through the step context parameter.

How It Works

When executing steps with step.do(), the step context object (ctx) now includes an attempt property that tracks the current retry attempt number:

await step.do("my-step", async (ctx) => {
  // ctx.attempt is 1 on first try, 2 on first retry, etc.
  console.log(`Attempt ${ctx.attempt}`);
});

The attempt number is 1-indexed, meaning the initial execution starts at 1, the first retry is 2, and so on.

Use Cases

This new feature enables several improved workflow patterns:

  • Enhanced Observability: Log which retry attempt is currently executing for better debugging and monitoring
  • Progressive Backoff: Implement custom backoff strategies that vary based on the attempt number
  • Conditional Logic: Execute different logic branches depending on whether this is the initial attempt or a retry

Getting Started

The feature is immediately available to all Cloudflare Workflows users. For detailed information on configuring retry behavior and timeout handling, refer to the Sleeping and Retrying documentation.