Skip to content

Fix concurrent local activity replay nondeterminism#1573

Draft
paulcacheux wants to merge 2 commits into
temporalio:mainfrom
paulcacheux:paulcacheux/fix-concurrent-local-activity-replay-nondeterminism
Draft

Fix concurrent local activity replay nondeterminism#1573
paulcacheux wants to merge 2 commits into
temporalio:mainfrom
paulcacheux:paulcacheux/fix-concurrent-local-activity-replay-nondeterminism

Conversation

@paulcacheux
Copy link
Copy Markdown

Problem

When multiple coroutines issue local activities concurrently (e.g. via asyncio.gather), replay can fail with NondeterminismError.

During first execution, local activity resolve_activity jobs 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_activity jobs 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:

  • Without concurrent local activities: sorting a single item is a no-op.
  • With concurrent local activities that replayed correctly (completion order happened to match seq order): the new code produces the same interleaving.
  • With concurrent local activities that already failed on replay: they were hitting NondeterminismError anyway.

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 with NondeterminismError.

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.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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