Repository navigation
Order cross-playbook rules by play id, not created_at - #2605
Merged
Merged
Conversation
OrderedRuleRef::cmp keyed on play_created_at, a wall-clock timestamp that isn't comparable across devices under multi-device sync (clock skew, differing install order). Per ADR-060 §5, cross-play ordering must be a stable, content-derived function of the data: key on play_id (already carried on the struct for identity) instead, keeping rule_index as the within-play tiebreaker. Dropped the now-unused play_created_at field from OrderedRuleRef and its construction sites in activate_play and the cron_runner tests. PartialEq/Eq (used by lookup_rules' sort().dedup()) already keyed on (play_id, rule_index) and is unaffected. Added tests: cross-play ordering follows play_id even when it contradicts creation-time order; two PlaybookLifecycleManager instances activating the same plays in opposite order (simulating devices with differing install order/clock skew) produce identical rule order; within-play rule_index ordering is unchanged; and sort().dedup() still collapses duplicate (play_id, rule_index) entries regardless of insertion order or rule content. Also strengthened an existing lifecycle test (test_rules_ordered_by_play_id_then_rule_index, renamed from test_rules_ordered_by_created_at_then_index) to prove play_id drives ordering independent of created_at rather than relying on the two happening to agree. Co-Authored-By: Claude Sonnet 5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
OrderedRuleRef::cmp(packages/core/src/playbook/types.rs) previously keyed cross-play rule ordering onplay_created_at, a wall-clock timestamp that two devices can disagree on under multi-device sync (clock skew, differing install order). Per ADR-060 §5 ("Stable ordering"), cross-play ordering must key on a stable, content-derived identifier instead — the play'sid, which the struct already carries for identity purposes.play_created_at: DateTime<Utc>field fromOrderedRuleRef, and its construction sites inPlaybookLifecycleManager::activate_play(lifecycle.rs) and thecron_runner.rstest helpers.rule_indexremains the within-play tiebreaker, unchanged.PartialEq/Eq(used bylookup_rules's.sort().dedup()identity check) already keyed on(play_id, rule_index)and required no change.Tests added
types.rs: unit tests onOrderedRuleRef'sOrd/PartialEqdirectly — play_id is the primary sort key even when it contradicts rule_index; within-play ordering is still byrule_index; identity equality ignores rule content;.sort().dedup()collapses duplicate(play_id, rule_index)entries regardless of insertion order.lifecycle.rs:cross_play_ordering_keys_on_play_id_not_created_at— two plays activated where wall-clock creation order and play-id order disagree; confirms play-id order wins.two_devices_different_install_order_produce_same_rule_order— twoPlaybookLifecycleManagerinstances given the same plays in opposite activation order (simulating differing install order/clock skew across devices) produce identical rule order.within_play_rule_order_by_rule_index_is_unchanged— a single play's rules stay in array order.tests.rs: strengthened the existingtest_rules_ordered_by_created_at_then_index(renamedtest_rules_ordered_by_play_id_then_rule_index) so the lexically-earlier play is also the later-created one, proving play_id — not creation time — drives the order, rather than relying on the two happening to coincide.Test plan
bun run test:all— clean (240/240 frontend test files, 4951/4951 tests;test:scripts;test:skill91/91; Rustworkspace/core/libsql-linked/app-unitstiers all passing)bun run quality:fix— clean (cargo fmt,cargo clippy --all-targets -D warningsclean, eslint/tsc/svelte-check clean)scripts/test-gate.ts) passed in full, includingtest:e2eand the Tauri-seam integration suiteCloses #2577
Addresses part of #1738
🤖 Generated with Claude Code