Repository navigation
feat(workflow): add new_guid to DaprWorkflowContext #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JeffreyJPZ
wants to merge
18
commits into
dapr:main
Choose a base branch
from
JeffreyJPZ:feat/workflow-context-new-guid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d66ba94
Expose a replay-safe new_guid on WorkflowContext
magic-peach 72e282b
Declare new_guid on the vendored OrchestrationContext interface
magic-peach fbc20f2
Update dapr/ext/workflow/_durabletask/worker.py
magic-peach 2bbc042
delegate to mixin
JeffreyJPZ 19ad02f
add unit test
JeffreyJPZ 4e03993
add integration tests for replay safety
JeffreyJPZ edc0668
format
JeffreyJPZ dd340b6
adjust comment
JeffreyJPZ f976ce3
use DaprWorkflowContext in unit test
JeffreyJPZ 42c69c7
add debug log
JeffreyJPZ e3dea64
comment consistency
JeffreyJPZ 4676553
update test comment
JeffreyJPZ 84d358d
remove unneeded sidecar param from helper
JeffreyJPZ bb0187f
make guid count local var
JeffreyJPZ 1efbae3
address comments
JeffreyJPZ 150a002
Merge branch 'main' into feat/workflow-context-new-guid
JeffreyJPZ bf6efef
Merge branch 'main' into feat/workflow-context-new-guid
JeffreyJPZ 50cb947
Merge branch 'main' into feat/workflow-context-new-guid
JeffreyJPZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Copyright 2026 The Dapr Authors | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """End-to-end verification of replay-safe workflow context behavior. | ||
|
|
||
| These tests run workflows through a real Dapr sidecar. After an activity | ||
| completes, the workflow is resumed by replaying its history, so the replay | ||
| assertions exercise ``DaprWorkflowContext`` rather than only the underlying | ||
| deterministic context. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import Any | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
|
|
||
| HOST = '127.0.0.1' | ||
| GRPC_PORT = '13501' | ||
| COMPLETION_TIMEOUT_S = 60 | ||
| GUID_COUNT = 3 | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def sidecar(dapr_env): | ||
| """Start the Dapr sidecar used by the workflow replay tests.""" | ||
| return dapr_env.start_sidecar(app_id='test-workflow-replay-safety') | ||
|
|
||
|
|
||
| def _run_workflow(workflow, *, activities: tuple[Any, ...] = ()) -> dict[str, Any] | list[str]: | ||
| """Run a workflow to completion through a real Dapr sidecar and decode its JSON output.""" | ||
| from dapr.ext.workflow import DaprWorkflowClient, WorkflowRuntime | ||
|
|
||
| runtime = WorkflowRuntime(host=HOST, port=GRPC_PORT) | ||
| runtime.register_workflow(workflow) | ||
| for activity in activities: | ||
| runtime.register_activity(activity) | ||
|
|
||
| client = DaprWorkflowClient(host=HOST, port=GRPC_PORT) | ||
| runtime.start() | ||
| try: | ||
| instance_id = client.schedule_new_workflow(workflow) | ||
| state = client.wait_for_workflow_completion( | ||
| instance_id, timeout_in_seconds=COMPLETION_TIMEOUT_S | ||
| ) | ||
| finally: | ||
| client.close() | ||
| runtime.shutdown() | ||
|
|
||
| assert state is not None, 'workflow did not reach a terminal state' | ||
| assert state.runtime_status.name == 'COMPLETED' | ||
| return json.loads(state.serialized_output) | ||
|
|
||
|
|
||
| def test_new_guid_generates_unique_guids_within_execution(sidecar): | ||
| """Each call to ``new_guid()`` produces a unique GUID within one execution.""" | ||
| from dapr.ext.workflow import DaprWorkflowContext, WorkflowActivityContext | ||
|
|
||
| def echo_guids(ctx: WorkflowActivityContext, values: list[str]) -> list[str]: | ||
| return values | ||
|
|
||
| def generate_guids(ctx: DaprWorkflowContext, _input: None): | ||
| generated_guids = [str(ctx.new_guid()) for _ in range(GUID_COUNT)] | ||
| yield ctx.call_activity(echo_guids, input=generated_guids) | ||
| return generated_guids | ||
|
|
||
| generated_guids = _run_workflow(generate_guids, activities=(echo_guids,)) | ||
|
|
||
| assert isinstance(generated_guids, list) | ||
|
|
||
| # Validate serialized GUIDs | ||
| for value in generated_guids: | ||
| UUID(value) | ||
|
|
||
| assert len(set(generated_guids)) == len(generated_guids) | ||
|
|
||
|
|
||
| def test_new_guid_is_deterministic_across_replays(sidecar): | ||
| """GUID sequences remain unchanged when the workflow replays its history. | ||
|
|
||
| The echo activity returns the GUIDS from the initial execution. | ||
| During replay, that result comes from history instead of executing the | ||
| activity again, so comparing the generated and echoed values detects if replay | ||
| produced different GUIDs than the initial execution. | ||
| """ | ||
| from dapr.ext.workflow import DaprWorkflowContext, WorkflowActivityContext | ||
|
|
||
| def echo_guids(ctx: WorkflowActivityContext, values: list[str]) -> list[str]: | ||
| return values | ||
|
|
||
| def generate_guids(ctx: DaprWorkflowContext, _input: None): | ||
| first_guids = [str(ctx.new_guid()) for _ in range(GUID_COUNT)] | ||
| first_echo = yield ctx.call_activity(echo_guids, input=first_guids) | ||
|
|
||
| second_guids = [str(ctx.new_guid()) for _ in range(GUID_COUNT)] | ||
| second_echo = yield ctx.call_activity(echo_guids, input=second_guids) | ||
|
|
||
| return { | ||
| 'first_guids': first_guids, | ||
| 'first_echo': first_echo, | ||
| 'second_guids': second_guids, | ||
| 'second_echo': second_echo, | ||
| } | ||
|
|
||
| result = _run_workflow(generate_guids, activities=(echo_guids,)) | ||
|
|
||
| assert isinstance(result, dict) | ||
| assert result['first_guids'] == result['first_echo'] | ||
| assert result['second_guids'] == result['second_echo'] | ||
|
|
||
| # Validate serialized GUIDs | ||
| for values in (result['first_guids'], result['second_guids']): | ||
| for value in values: | ||
| UUID(value) | ||
|
|
||
| all_guids = result['first_guids'] + result['second_guids'] | ||
| assert len(set(all_guids)) == len(all_guids) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.