prune_kv_values_updated_before emits actions in HashMap order; replay fails with `kv clear mismatch`
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- node.js, rust
調査の方向性
Start in src/lib.rs at prune_kv_values_updated_before (around lines 3411-3427), then inspect get_kv_all_keys around lines 3360-3362 and the kv_metadata declaration around line 1715. Reproduce the Node.js SDK scenario with multiple matching keys and verify that replay emits and consumes KV actions in a consistent order.
索引モデルが issue の本文から書いたものです。
説明
Summary
An orchestration that prunes two or more KV keys in one turn fails on a later replay with nondeterministic: kv clear mismatch. The orchestration code is deterministic. The order of the actions that the runtime emits is not.
Where
prune_kv_values_updated_beforeiterateskv_metadataand callsclear_kv_valuefor each key: https://github.com/microsoft/duroxide/blob/6a458861763a7aa5b78a7c1c97691a6f00489a8b/src/lib.rs#L3411-L3427kv_metadatais astd::collections::HashMap: https://github.com/microsoft/duroxide/blob/6a458861763a7aa5b78a7c1c97691a6f00489a8b/src/lib.rs#L1715get_kv_all_keysreturns the keys inHashMaporder as well: https://github.com/microsoft/duroxide/blob/6a458861763a7aa5b78a7c1c97691a6f00489a8b/src/lib.rs#L3360-L3362
A HashMap has a random seed per map. So the iteration order differs between two replays of the same turn, also inside one process.
How it fails
- Execution 1 writes the keys
atofand continues as new. - Execution 2 calls
prune_kv_values_updated_before(cutoff). All six keys match. The turn records sixKeyValueClearedevents in some order. - A later turn replays the same code. The six
ClearKeyValueactions come out in a different order. - The replay engine compares the first action with the first event, finds another key, and fails the orchestration.
Reproduction
Reproduced with duroxide 0.1.30 on SQLite, through the Node.js SDK:
runtime.registerOrchestration('Prune', function* (ctx, input) {
if (!input || !input.second) {
for (const k of ['a', 'b', 'c', 'd', 'e', 'f']) ctx.setValue(k, 'x');
yield ctx.continueAsNew({ second: true });
return '';
}
const now = yield ctx.utcNow();
const pruned = ctx.pruneKvValuesUpdatedBefore(now + 60_000); // clears all six keys
yield ctx.utcNow();
yield ctx.utcNow();
return `pruned ${pruned}`;
});
6 of 6 instances failed, for example with:
nondeterministic: kv clear mismatch: action=ClearKeyValue { key: "d" } vs event=KeyValueCleared { key: "a" }
Impact
- An orchestration that calls
prune_kv_values_updated_beforewith more than one matching key can fail for good. With n keys, two replays agree on the order with a chance of 1 in n!. get_kv_all_keysandget_kv_all_valueshand the same random order to orchestration code. Code that loops over the result and schedules work per key is nondeterministic for the same reason.
Suggested fix
- Sort the keys in
prune_kv_values_updated_beforebefore the actions are emitted. - Return sorted keys from
get_kv_all_keys, or keep the KV state in aBTreeMap.
Tracked in #55.
- 主要言語
- Rust
- スター
- 221
- フォーク
- 61
- 平均マージ
- 3日 5時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/duroxide のほかの issue
-
One failed session lock renewal loses the session: no retry, no log, no signal to running activitiesオープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
-
bug
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
microsoft/duroxide の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 1 日以内に返信
-
Markdown Preview Fonts Don't Show Selected Option対応中かも @RadhiRasho が今日担当しました。 オープンstate:needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 61/100
zed-industries/zed#65300 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信