Skip to content

Order cross-playbook rules by play id, not created_at - #2605

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2577-stable-rule-ordering
Sep 14, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2577-stable-rule-ordering

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

  • OrderedRuleRef::cmp (packages/core/src/playbook/types.rs) previously keyed cross-play rule ordering on play_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's id, which the struct already carries for identity purposes.
  • Dropped the now-unused play_created_at: DateTime<Utc> field from OrderedRuleRef, and its construction sites in PlaybookLifecycleManager::activate_play (lifecycle.rs) and the cron_runner.rs test helpers. rule_index remains the within-play tiebreaker, unchanged.
  • PartialEq/Eq (used by lookup_rules's .sort().dedup() identity check) already keyed on (play_id, rule_index) and required no change.

Tests added

  • types.rs: unit tests on OrderedRuleRef's Ord/PartialEq directly — play_id is the primary sort key even when it contradicts rule_index; within-play ordering is still by rule_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 — two PlaybookLifecycleManager instances 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 existing test_rules_ordered_by_created_at_then_index (renamed test_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:skill 91/91; Rust workspace/core/libsql-linked/app-units tiers all passing)
  • bun run quality:fix — clean (cargo fmt, cargo clippy --all-targets -D warnings clean, eslint/tsc/svelte-check clean)
  • Pre-push gate (scripts/test-gate.ts) passed in full, including test:e2e and the Tauri-seam integration suite

Closes #2577
Addresses part of #1738

🤖 Generated with Claude Code

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]>
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.

Order cross-playbook rules by playbook id instead of created_at (ADR-060 §5)

1 participant