Skip to content

[Feature]: Expose the number of attempts to the operation context #526

Description

@zhongkechen

What would you like?

Expose the current operation attempt number to user code through the Python operation context.

For example, when processing an order, a workflow may need to place a backorder with one of several suppliers in preference order. If the first supplier is unavailable, the next retry should try the next supplier. The available suppliers and number of suppliers can vary by order, and this is much easier to implement if the step/check function can read the current attempt count from its context.

Today the SDK already tracks the attempt internally for retries, logging, plugins, and wait_for_condition strategies, but the attempt is not directly available on OperationContext, StepContext, or WaitForConditionCheckContext.

Possible Implementation

Extend OperationContext with an additional integer field, for example:

@dataclass(frozen=True)
class OperationContext:
    logger: LoggerInterface
    attempt: int

Then populate it when constructing concrete operation contexts such as StepContext and WaitForConditionCheckContext, using the same current-attempt value already passed to the replay-aware logger and wrap_user_function.

Open question: should this be named attempt, attempt_count, or another Python API name that matches the rest of the SDK conventions?

Is this a breaking change?

No

Does this require an RFC?

No

Additional Context

This mirrors the JavaScript SDK feature request: aws/aws-durable-execution-sdk-js#502

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions