← Back
Cloudflare
Cloudflare Workflows now expose retry attempt numbers in step context

Retry Attempt Access

Cloudflare Workflows now exposes the current retry attempt number through the step context parameter passed to step.do(). Developers can access this value via ctx.attempt, which is 1-indexed (1 on the first attempt, 2 on the first retry, and so forth).

Use Cases

This feature enables several powerful patterns:

  • Improved Observability: Log which attempt is executing for better debugging and monitoring
  • Progressive Backoff: Implement dynamic delays that increase with each retry attempt
  • Conditional Logic: Execute different code paths based on the current attempt number
  • Graceful Degradation: Fall back to simpler strategies on later retry attempts

Implementation

To access the retry attempt number, use the ctx.attempt property within your step handler:

await step.do("my-step", async (ctx) => {
  console.log(`Attempt ${ctx.attempt}`);
  // Implement custom logic based on ctx.attempt
});

For comprehensive information on Cloudflare Workflows' retry behavior and configuration options, refer to the Sleeping and Retrying documentation.