Skip to content

Reject same-play rules with byte-identical action lists at save time - #2680

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2574-dup-action-lists
Sep 17, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2574-dup-action-lists

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

rule_id_for(play_id, actions) (packages/core/src/playbook/actions.rs) derives a playbook rule's identity from (play_id, the rule's own parsed action list) per ADR-060 §3 / ADR-074. Two DIFFERENT rules in the SAME play with byte-identical action lists therefore collide onto the same rule_id, and therefore the same derived create_node output id for a given (action_index, iteration_path). execute_create_node's existing-node-at-derived-id convergence check can't tell "same rule re-firing" from "two different rules colliding," so it silently returns the wrong rule's node — no error, no log. Realistic trigger: copy-paste rule authoring (duplicate a rule, change its trigger/condition, leave the action list untouched).

This adds a save-time check in packages/core/src/playbook/validation.rs that rejects a play with two same-play rules whose action lists are byte-identical, naming both offending rules. rule_id_for's derivation itself is unchanged (explicit non-goal).

Changes

  • packages/core/src/playbook/actions.rs: extracted action_list_signature (pub(crate)) out of rule_id_for — the action-list half of its hash seed, excluding play_id — so validation.rs can compare rules using the exact same shape rule_id_for hashes, without reimplementing the logic. Updated the module doc's note (previously said this was "tracked as a separate follow-up") to point at the new check.
  • packages/core/src/playbook/validation.rs: added PlayValidationError::DuplicateActionList and validate_no_duplicate_action_lists, wired into validate_play. Scoped to same-play only (every validate_play call already receives one play's rules) — cross-play collisions are already distinguished by play_id in rule_id_for and are out of scope. Rules with an empty action list are excluded (nothing to derive an output id from, so no collision risk).

Severity: reject, not warn

validation.rs has no warning tier today — every existing save-time check (unknown node_type, version mismatch, all the ADR-060 §2 invariant-rule eligibility checks, the reject-action-class checks) is a hard PlayValidationError that blocks the save. This follows that precedent exactly rather than inventing a new severity level, and matches the issue's own steer ("reject is likely more correct given the failure mode is a silent data-loss-adjacent merge, not just a style issue").

Correctness note: JSON key ordering

The byte-identical comparison is action.params.to_string() (via action_list_signature), same as rule_id_for always was. Verified serde_json's preserve_order feature is NOT enabled anywhere in this workspace's dependency tree (no indexmap in Cargo.lock), so serde_json::Map is backed by a BTreeMap and serializes object keys in sorted order — two semantically-identical action lists with differently-ordered JSON keys still produce the same signature (no false negative), and no false positive can arise from ordering alone.

Testing

  • New unit tests directly against validate_no_duplicate_action_lists (no NodeService needed, matching the existing invariant_eligibility test style): identical actions + different triggers → rejected (with rule names asserted in the error); slightly different content → allowed (negative control); empty action lists → not flagged; 3-rule case → each later duplicate reported once against the earliest match.
  • New tokio::test integration tests through validate_play end-to-end (matching the existing invariant_rule_gated_through_validate_play style): duplicate action lists reject the whole play; distinct action lists pass.
  • cargo test -p nodespace-core --lib playbook:: — 329 passed, 0 failed (includes the pre-existing two_rules_with_identical_actions_silently_share_one_output_node test in actions.rs, which still passes — it exercises execute_actions directly, bypassing validate_play, and continues to document the executor-level behavior, which is unchanged by design).
  • bun run quality:fix — clean (cargo fmt + clippy -D warnings -D clippy::unused-async, eslint, tsc, svelte-check).
  • Full pre-push gate (bun run test:all equivalent + cargo build --bin nodespaced + bun run test:e2e + Tauri-seam integration tests) — all green.

Test plan

  • Saving a play with two rules whose action lists are byte-identical is caught at save time (rejected)
  • Scoped to rules within the SAME play only (cross-play untouched, already distinguished by play_id)
  • Test: two rules, identical actions, different triggers/conditions → rejected
  • Test: two rules, slightly different actions (different content) → allowed
  • bun run test:all passes (pre-push gate), bun run quality:fix passes

Closes #2574

🤖 Generated with Claude Code

mstomar125 and others added 2 commits September 17, 2026 07:02
rule_id_for derives a rule's identity from (play_id, its own parsed
action list) rather than a positional index. Two different rules in
the same play with byte-identical actions therefore collide onto the
same rule_id and the same derived create_node output id, and
execute_create_node's existing-node convergence check can't tell that
apart from a legitimate re-fire of the same rule -- it silently
returns the wrong rule's node.

Add validate_no_duplicate_action_lists to validation.rs, matching the
existing hard-error precedent for save-time Play checks (e.g. the
ADR-060 §2 invariant-rule eligibility checks) rather than introducing
a separate warning tier. It compares every rule pair's action-list
signature within a play (rules with no actions are excluded, since
there's no derived output to collide over) and rejects the save,
naming both the offending rule and the earlier one it duplicates.

Extract action_list_signature out of rule_id_for so validation.rs
hashes the exact same shape rule_id_for does, rather than
reimplementing it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The seed joined each action's action_type/for_each/params with a raw
'\u{1}' separator. for_each is parsed straight from user-authored
play JSON with no charset validation (unlike conditions, which must
compile as CEL), so a play author could set it to a string containing
that exact character and make an unrelated, differently-shaped action
list produce the identical seed -- both a false positive for the new
same-play duplicate-action-list check, and (pre-existing, since this
seed is shared with rule_id_for) a way for two genuinely different
rules to collide onto the same derived output id without their action
lists actually matching.

Replace the delimiter join with a canonical JSON array of
[action_type, for_each, params] triples per action: JSON's escaping
is structural, so no field's content can be crafted to look like an
array or string boundary.

Found by an independent review of PR #2574's implementation, which
mutation-tested and confirmed the collision with a concrete two-action
vs. one-action example before this fix.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Independent review found one real bug in the initial implementation: action_list_signature joined each action's action_type/for_each/params fields with a raw '\u{1}' separator. for_each is parsed straight from user-authored play JSON with no charset validation (unlike conditions, which must compile as CEL), so a play author could craft a for_each string containing that exact character and make an unrelated, differently-shaped action list produce the identical seed — a false positive for this PR's new check, and (since the seed is shared with rule_id_for) a pre-existing way for two genuinely different rules to collide at execution time without their action lists actually matching.

Fixed in 44ef6d6: action_list_signature now encodes each action as a JSON array ([action_type, for_each, params]) and serializes the whole action list as one JSON array, rather than delimiter-joining strings. JSON's escaping is structural, so no field's content can be crafted to look like an array/string boundary. Added a regression test (action_list_signature_is_not_confused_by_control_characters_in_for_each) reproducing the exact collision the reviewer found and asserting it no longer happens.

Everything else from the review checked out: same-play scoping is correct at every validate_play call site, the pairwise-comparison logic handles 0/1 rules and empty action lists correctly, the "reject" severity matches existing validation.rs precedent (no warning tier exists anywhere in that file), and the new tests were mutation-tested (temporarily no-opping the check causes the "should reject" tests to fail as expected) — confirmed real, not vacuous.

Full pre-push gate (test:all + cargo build --bin nodespaced + test:e2e + Tauri-seam integration tests) green on both commits.

🤖 Generated with Claude Code

@mstomar125
mstomar125 merged commit 9a0b707 into main Sep 17, 2026
@mstomar125
mstomar125 deleted the issue-2574-dup-action-lists branch September 17, 2026 05:31
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.

Reject or warn at save time on two same-play rules with byte-identical action lists

1 participant