Repository navigation
Reject same-play rules with byte-identical action lists at save time - #2680
Conversation
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]>
|
Independent review found one real bug in the initial implementation: Fixed in 44ef6d6: Everything else from the review checked out: same-play scoping is correct at every Full pre-push gate (test:all + cargo build --bin nodespaced + test:e2e + Tauri-seam integration tests) green on both commits. 🤖 Generated with Claude Code |
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 samerule_id, and therefore the same derivedcreate_nodeoutput 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.rsthat 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: extractedaction_list_signature(pub(crate)) out ofrule_id_for— the action-list half of its hash seed, excludingplay_id— sovalidation.rscan compare rules using the exact same shaperule_id_forhashes, 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: addedPlayValidationError::DuplicateActionListandvalidate_no_duplicate_action_lists, wired intovalidate_play. Scoped to same-play only (everyvalidate_playcall already receives one play's rules) — cross-play collisions are already distinguished byplay_idinrule_id_forand 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.rshas no warning tier today — every existing save-time check (unknown node_type, version mismatch, all the ADR-060 §2 invariant-rule eligibility checks, thereject-action-class checks) is a hardPlayValidationErrorthat 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()(viaaction_list_signature), same asrule_id_foralways was. Verifiedserde_json'spreserve_orderfeature is NOT enabled anywhere in this workspace's dependency tree (noindexmapinCargo.lock), soserde_json::Mapis backed by aBTreeMapand 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
validate_no_duplicate_action_lists(no NodeService needed, matching the existinginvariant_eligibilitytest style): identical actions + different triggers → rejected (with rule names asserted in the error); slightly differentcontent→ allowed (negative control); empty action lists → not flagged; 3-rule case → each later duplicate reported once against the earliest match.tokio::testintegration tests throughvalidate_playend-to-end (matching the existinginvariant_rule_gated_through_validate_playstyle): 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-existingtwo_rules_with_identical_actions_silently_share_one_output_nodetest inactions.rs, which still passes — it exercisesexecute_actionsdirectly, bypassingvalidate_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).bun run test:allequivalent +cargo build --bin nodespaced+bun run test:e2e+ Tauri-seam integration tests) — all green.Test plan
play_id)content) → allowedbun run test:allpasses (pre-push gate),bun run quality:fixpassesCloses #2574
🤖 Generated with Claude Code