Fix concurrent local activity replay nondeterminism#1573
Conversation
Add a regression test that runs two concurrent coroutines (via asyncio.gather) each issuing multiple sequential local activities, then replays the recorded history. Without a fix, replay fails with NondeterminismError because local activity markers are consumed in a different order than the original execution.
|
|
During first execution, local activity resolve_activity jobs arrive in completion order (wall-clock). During replay, they arrive in sequence number order. When multiple coroutines issue local activities concurrently, this ordering difference causes coroutines to resume in a different order, assigning different sequence numbers to subsequent commands and triggering NondeterminismError. Fix by sorting local activity resolutions by sequence number before processing. This ensures coroutines always resume in scheduling order regardless of execution mode.
78a4a1b to
02e2c5e
Compare
|
Thanks for the contribution! This is very likely not the right thing to do - resolutions need to come in the same order they were written in, which means whatever order they are in history, not sequence number order. Additionally, it's the responsibility of Core to do this all properly. Does the test you've written consistently reproduce an NDE without your fix? If so, something's definitely wrong, but I don't think this is the right solution. |
|
Your test reproduced locally for me, but given that the solution is not the one we would want to proceed with, could you open an issue instead, which we can use to track the problem? |
|
Yes I'm going to open an issue with the reproducer (that at least for me is reproducing every time) |
|
here is the issue #1578, thanks for taking a look ! |
Problem
When multiple coroutines issue local activities concurrently (e.g. via
asyncio.gather), replay can fail withNondeterminismError.During first execution, local activity
resolve_activityjobs arrive in completion order (wall-clock timing). During replay, they arrive in sequence number order. This ordering difference causes coroutines to resume in a different order, assigning different sequence numbers to subsequent commands, which no longer match the recorded markers.Fix
Sort local activity
resolve_activityjobs by sequence number before processing them in_WorkflowInstanceImpl.activate(). This ensures coroutines always resume in scheduling order regardless of execution mode (first-execution vs replay).The fix is safe for existing workflows:
NondeterminismErroranyway.Test
Added
test_workflow_concurrent_local_activity_replay: runs a workflow with two concurrent coroutines each issuing multiple sequential local activities, then replays the recorded history. Without the fix, replay fails withNondeterminismError.