|
| 1 | +# Enrich workflow activity context |
| 2 | + |
| 3 | +* Author(s): Javier Aliaga (@javier-aliaga) |
| 4 | +* State: Draft |
| 5 | +* Updated: 2025-05-26 |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +This is a proposal to enrich workflow activity context by introducing new fields. This will make it easier for users to control the workflow's state within activities. They are particularly useful for: |
| 10 | + |
| 11 | +1. **Idempotency**: Ensuring activities are not executed multiple times for the same task |
| 12 | +2. **State Management**: Tracking the state of activity execution |
| 13 | + |
| 14 | +## Background |
| 15 | + |
| 16 | +Workflow users have raised concerns about controlling and preventing an activity from being invoked more than once or tracking the state of the execution. Input parameters can be used to control the workflow's state, but certain scenarios do not have enough data to do it. Some examples are: |
| 17 | + |
| 18 | +- A notification activity where the message content alone isn't enough to determine uniqueness |
| 19 | +- An external service call where idempotency can't be guaranteed by the input parameters |
| 20 | + |
| 21 | +The current implementations of the activity context do not expose any valuable field for this purpose. |
| 22 | +- [GO-SDK](https://github.com/dapr/go-sdk/blob/main/workflow/activity_context.go) |
| 23 | +- [JAVA-SDK](https://github.com/dapr/java-sdk/blob/master/sdk-workflows/src/main/java/io/dapr/workflows/WorkflowActivityContext.java) |
| 24 | +- etc... |
| 25 | + |
| 26 | +This limitation creates the need to extend the activity context with additional fields that can track execution uniqueness and state. By introducing these new fields to the activity context, users will have a better mechanism to ensure activities are not invoked multiple times, even in cases where input parameters are not enough for this purpose. |
| 27 | + |
| 28 | + |
| 29 | +## Related Items |
| 30 | + |
| 31 | +### Related proposals |
| 32 | + |
| 33 | +N/A |
| 34 | + |
| 35 | +### Related issues |
| 36 | + |
| 37 | +An attempt to solve this problem has been tried in the JAVA-SDK. However, the solution is not consistent with scenarios where the same task is executed multiple times as the task execution key is built using the workflow instance id and the task name. |
| 38 | + |
| 39 | +- https://github.com/dapr/durabletask-java/pull/18 |
| 40 | +- https://github.com/dapr/java-sdk/pull/1352 |
| 41 | + |
| 42 | +## Expectations and alternatives |
| 43 | + |
| 44 | +* What is in scope for this proposal? |
| 45 | + * Workflow runtime |
| 46 | + * SDKs |
| 47 | +* What advantages / disadvantages does this proposal have? |
| 48 | + * Uniform across all SDKs |
| 49 | + |
| 50 | +## Implementation Details |
| 51 | + |
| 52 | +### Design |
| 53 | + |
| 54 | +The proposed fields introduced in this document are: |
| 55 | + |
| 56 | +- WorkflowInstanceId: This field will provide a unique identifier for the workflow instance. It is already available in the orchestration context but will now be propagated to the activity context. |
| 57 | + |
| 58 | +- TaskInstanceId: This field will provide a unique identifier for the same activity among retries. This new field will be part of the [Activity Request](https://github.com/dapr/durabletask-protobuf/blob/main/protos/orchestrator_service.proto) and needs to be populated in the runtime. |
| 59 | + |
| 60 | +- RetryAttempt: This field will contain the current retry count for the activity execution. |
| 61 | + |
| 62 | + |
| 63 | +### Feature lifecycle outline |
| 64 | + |
| 65 | +* Expectations |
| 66 | +* Compatability guarantees |
| 67 | +* Deprecation / co-existence with existing functionality |
| 68 | +* Feature flags |
| 69 | + |
| 70 | +### Acceptance Criteria |
| 71 | + |
| 72 | +How will success be measured? |
| 73 | + |
| 74 | +* Integration and unit tests will be added to verify the new functionality. |
| 75 | + |
| 76 | + |
| 77 | +## Completion Checklist |
| 78 | + |
| 79 | +What changes or actions are required to make this proposal complete? Some examples: |
| 80 | + |
| 81 | +* Code changes |
| 82 | +* Tests added (e2e, unit) |
| 83 | +* SDK changes (if needed) |
| 84 | +* Documentation |
| 85 | + |
0 commit comments