Skip to content

feat(sdk): expose retry attempt number on step context#707

Merged
ParidelPooya merged 2 commits into
mainfrom
feat/step-context-attempt
Jul 10, 2026
Merged

feat(sdk): expose retry attempt number on step context#707
ParidelPooya merged 2 commits into
mainfrom
feat/step-context-attempt

Conversation

@ParidelPooya

@ParidelPooya ParidelPooya commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Add attempt field to StepContext so step functions can read the current retry attempt. This enables attempt-aware logic such as failing over to an alternate resource on later attempts (issue #502).

  • Make StepContext an interface extending OperationContext with attempt: number; populate it in the step handler from the existing 1-based currentAttempt already used for retryStrategy and logging.
  • Keep 1-based numbering for consistency with the SDK logger (DurableLogData.attempt).
  • Update the step() TSDoc that described StepContext as logging-only.
  • Add unit tests covering the first-attempt and post-retry values.
  • Add a step/attempt-fallback example demonstrating supplier fail-over driven by stepContext.attempt.

Issue #, if available: #502

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add a 1-based `attempt` field to `StepContext` so step functions can read
the current retry attempt (1 on the first execution, incrementing by 1 on
each retry). This enables attempt-aware logic such as failing over to an
alternate resource on later attempts (issue #502).

- Make `StepContext` an interface extending `OperationContext` with
  `attempt: number`; populate it in the step handler from the existing
  1-based `currentAttempt` already used for `retryStrategy` and logging.
- Keep 1-based numbering for consistency with the SDK logger
  (`DurableLogData.attempt`).
- Update the `step()` TSDoc that described `StepContext` as logging-only
  and regenerate the API report entry accordingly.
- Add unit tests covering the first-attempt and post-retry values.
- Add a `step/attempt-fallback` example demonstrating supplier fail-over
  driven by `stepContext.attempt`.

Closes #502
@ParidelPooya
ParidelPooya force-pushed the feat/step-context-attempt branch from 90167ca to a18a585 Compare July 9, 2026 23:36
@ParidelPooya
ParidelPooya marked this pull request as ready for review July 10, 2026 17:43
@ParidelPooya
ParidelPooya merged commit d35c942 into main Jul 10, 2026
16 checks passed
@ParidelPooya
ParidelPooya deleted the feat/step-context-attempt branch July 10, 2026 17:44
ParidelPooya added a commit that referenced this pull request Jul 16, 2026
)

Add `attempt` field to `WaitForConditionContext` so check functions can
read the current retry attempt, mirroring the `StepContext.attempt`
field added for step() in #707 (and matching the Java SDK, where
waitForCondition's check function already reuses
StepContext.getAttempt()).

Previously only the wait strategy's positional `attempt` argument had
this information; the check function itself had no way to know which
attempt it was on without tracking state manually.

- Convert WaitForConditionContext from a type alias to an interface
extending OperationContext, adding attempt: number (1-based).
- Populate it in the wait-for-condition handler from the existing
currentAttempt already used for waitStrategy and logging.
- Update the waitForCondition() and WaitForConditionCheckFunc TSDoc.
- Add unit tests covering the first-attempt and post-retry values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants