[Bug] non determinism when using `asyncio.gather` with local activities
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
test_workflow_concurrent_local_activity_replay の最小再現から始め、Replayer を通して実行し、asyncio.gather 内の execute_local_activity 呼び出しに焦点を当てます。初回実行時とリプレイ時のローカルアクティビティの完了順序を比較します。workflow が完了し、その履歴を NondeterminismError なしでリプレイできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
What are you really trying to do?
At a high level, our code is using some local activities at the beginning and end of some workflows parts. We got some reports of non determinism errors when those workflow parts are called using asyncio.gather.
Describe the bug
According to my understanding (might be wrong of course):
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.
Minimal Reproduction
Extracted from: https://github.com/temporalio/sdk-python/pull/1573
@activity.defn
async def local_activity_slow(index: int) -> None:
if index % 2 == 0:
await asyncio.sleep(0.05)
@activity.defn
async def local_activity_fast(index: int) -> None:
return None
@activity.defn
async def local_activity_gate() -> None:
await asyncio.sleep(0.05)
@workflow.defn
class ConcurrentLocalActivityReplayWorkflow:
"""Workflow that runs two concurrent coroutines with local activities.
This reproduces a replay nondeterminism bug: during first execution,
local activities take real time, creating a deterministic interleaving.
During replay, all local activities return instantly from markers, which
can reorder coroutine scheduling and produce a different command sequence.
"""
@workflow.run
async def run(self) -> list[int]:
async def lifecycle_a(index: int) -> int:
await workflow.execute_local_activity(
local_activity_slow,
args=[index * 2],
start_to_close_timeout=timedelta(seconds=5),
)
await workflow.execute_local_activity(
local_activity_fast,
args=[index * 2],
start_to_close_timeout=timedelta(seconds=5),
)
return index * 2
async def lifecycle_b(index: int) -> int:
await workflow.execute_local_activity(
local_activity_gate,
start_to_close_timeout=timedelta(seconds=5),
)
await workflow.execute_local_activity(
local_activity_slow,
args=[index * 2 + 1],
start_to_close_timeout=timedelta(seconds=5),
)
await workflow.execute_local_activity(
local_activity_fast,
args=[index * 2 + 1],
start_to_close_timeout=timedelta(seconds=5),
)
return index * 2 + 1
results: list[int] = []
for index in range(20):
results.extend(await asyncio.gather(lifecycle_a(index), lifecycle_b(index)))
return results
async def test_workflow_concurrent_local_activity_replay(client: Client):
"""Test that concurrent local activities replay deterministically.
Runs a workflow with two concurrent coroutines that each issue multiple
local activities, then replays the history. Without the fix, replay
fails with NondeterminismError because the local activity command order
diverges from the recorded marker order.
"""
async with new_worker(
client,
ConcurrentLocalActivityReplayWorkflow,
activities=[local_activity_slow, local_activity_fast, local_activity_gate],
) as worker:
handle = await client.start_workflow(
ConcurrentLocalActivityReplayWorkflow.run,
id=f"workflow-{uuid.uuid4()}",
task_queue=worker.task_queue,
)
expected = [v for i in range(20) for v in (i * 2, i * 2 + 1)]
assert await handle.result() == expected
history = await handle.fetch_history()
await Replayer(
workflows=[ConcurrentLocalActivityReplayWorkflow],
).replay_workflow(history)
Environment/Versions
- OS and processor: M1 Mac and Linux at least (I believe this is more general than that)
- Temporal Version: server=1.30.4, sdk=1.27.2, but also reproducing on main of
sdk-python - Building Temporal server from source
- 主要言語
- Python
- スター
- 1.2k
- フォーク
- 241
- 平均マージ
- 3日 2時間
- マージ済み PR(30日)
- 49
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
temporalio/sdk-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
temporalio/sdk-python#1517 · コメント 10 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
temporalio/sdk-python#496 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
temporalio/sdk-python#1890 ·
-
[Bug] Local activity resolutions regrouped on replay since 1.32.0, delivering the wrong payload オープン
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
temporalio/sdk-python#1881 · コメント 1 件 ·
-
bug
temporalio/sdk-python#1817 · コメント 1 件 · 担当者 1 名 ·
temporalio/sdk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100