Repository navigation
Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) - #2649
Conversation
… fingerprint collision (#2647) ops_error_to_status's PlayRuleRejected arm parsed its JSON metadata payload as MetadataValue<Ascii>, silently dropping the whole payload (via `if let Ok(...)`) whenever the author-supplied rejection message contained a non-ASCII byte (em dash, curly quotes, accents, emoji). Switch to gRPC's binary-metadata convention: a `-bin`-suffixed key (x-play-rule-rejected-bin) carrying the payload via MetadataValue::<Binary>::from_bytes, which is infallible. Also rename the misnamed `rule_id` field (it has always held the rule's author-given name, not an id) to `rule_name` across OpsError, NodeServiceError, and their call sites. load_active_plays/handle_play_created/handle_play_updated each passed a constant rule_name="validation" and error_location_index=0 into create_or_update_log_node for every validate_play error on a play. error_fingerprint hashes (play_id, rule_name, error_location_index, error_type) and deliberately excludes the error message, so two structurally different errors on the same play collapsed onto the same fingerprint — the second error's text was silently discarded and the surviving log node's occurrences count misleadingly implied a repeat of one issue. Add PlayValidationError::location()/kind() accessors and fold "{location}:{kind}" into the fingerprint identity via a new shared log_validation_errors() helper used by all three call sites, so distinct errors produce distinct log nodes. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Adversarial review (manual pass, not
|
…alidate_play pass log_validation_errors folded each error's (location, kind) into its create_or_update_log_node fingerprint identity, but that pair isn't unique within a single validate_play call: a validator can legitimately push more than one same-kind error at the same location in one pass — e.g. InvariantOutOfScopeTarget checking both source_id and target_id on one add_relationship action, or a CEL condition referencing two broken dot-paths (BrokenPath is pushed once per path, with the location computed once per condition). Those still collided onto one fingerprint, silently discarding every error but the first at that spot — a narrower instance of the exact collision #2647 set out to fix. Suffix each error's identity with its ordinal among prior errors sharing its (location, kind) within the same errors slice (omitted for the first/only one, so the common case is unaffected). validate_play iterates rules/conditions/actions in a fixed order, so the ordinal is deterministic and stable across repeated validation passes over an unchanged play — re-validation still maps back to the same existing log nodes rather than spawning duplicates. Add a regression test covering the two-broken-paths-in-one-condition case end to end through the real engine; mutation-tested by reverting the fix and confirming the test fails against the unfixed code. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…hapes Covers the InvariantOutOfScopeTarget case (add_relationship with both source_id and target_id set to literal, non-binding node ids) and the InvariantNonDeterministic case (a condition calling two different non-deterministic functions), both exercising the ordinal-suffix disambiguation added in the prior commit through the real engine end to end. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Re-review (pragmatic-code-review) — full settled diff
|
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
…ey too grpc-error-mapping.ts (the gRPC-js/dev-proxy mirror of the Tauri layer's status_to_command_error) still read the old ASCII x-play-rule-rejected key and documented the payload's old rule_id field name. Unlike nodes.rs, this file shares no lines with anything #2649 touched, so it would have merged with no conflict marker and then silently never matched the daemon's real (binary, rule_name) metadata again — every PLAY_RULE_REJECTED refusal reached through `bun run dev:browser` would fall through to the generic GRPC_ERROR path. gRPC-js requires binary keys to end in '-bin' and hands back Buffer values for them, which firstMetadataString already decodes via toString('utf8'), so switching the key string is sufficient. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…e-issue-2643-update-node-invariant-wiring
…0 §2) (#2650) * Wire RuleClass::Invariant rules into update_node's write path (ADR-060 §2) Relaxes InvariantUnsupportedTrigger to accept property_changed triggers alongside node_created. Adds dispatch_invariant_rules_for_update_in_tx (the update_node twin of the existing create-path dispatch), reusing trigger_keys_for_event for exact/wildcard matching and the shared execute_matched_invariant_rules_in_tx execution core so the reject-action distinction holds identically for both call sites. Refactors update_with_version_check_returning_node to wrap a new tx-scoped twin in with_transaction, mirroring create_node's own wrapping of create_node_in_tx: read existing, validate, write version-checked (tx-scoped), compute the real changed_properties diff (_in_tx store methods bypass the notifier that normally computes this), buffer the NodeUpdated event, run synchronous invariant dispatch, then re-read the node's final tx-consistent state before returning (an invariant action can be a self-referential update on the same node, writing a second time inside the same transaction — returning the pre-dispatch snapshot silently omitted that write from the RPC response). A rejecting rule's Err rolls back everything, including the buffered event, never flushed on rollback. Also restores collection-name-collision pre-check/post-mark handling that the tx-scoped store primitive deliberately omits (same posture as create_node_in_tx) but the old non-tx path did internally — switching primitives had silently dropped it, caught by the existing collection_name_convergence_test suite. Adds isPlayRuleRejected (frontend type guard + shared-node-store wiring, Tauri command layer PLAY_RULE_REJECTED branding, and the dev-proxy gRPC-js mirror of the same daemon metadata mapping). Co-Authored-By: Claude Sonnet 5 <[email protected]> * Update Tauri PLAY_RULE_REJECTED reader to match the daemon's binary metadata status_to_command_error's PLAY_RULE_REJECTED branch (this branch's own addition) read the daemon's x-play-rule-rejected ASCII metadata key and the payload's rule_id field. Both are now stale against main: the non-ASCII-metadata fix switched the daemon to a binary x-play-rule-rejected-bin key (immune to non-ASCII rejection messages being silently dropped) and renamed the payload's rule_id field to rule_name. Update the Tauri reader and the frontend's PlayRuleRejectedData type to match, plus the one stale test still asserting the old field name. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Update dev-proxy's PLAY_RULE_REJECTED mirror to the binary metadata key too grpc-error-mapping.ts (the gRPC-js/dev-proxy mirror of the Tauri layer's status_to_command_error) still read the old ASCII x-play-rule-rejected key and documented the payload's old rule_id field name. Unlike nodes.rs, this file shares no lines with anything #2649 touched, so it would have merged with no conflict marker and then silently never matched the daemon's real (binary, rule_name) metadata again — every PLAY_RULE_REJECTED refusal reached through `bun run dev:browser` would fall through to the generic GRPC_ERROR path. gRPC-js requires binary keys to end in '-bin' and hands back Buffer values for them, which firstMetadataString already decodes via toString('utf8'), so switching the key string is sufficient. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Summary
Fixes both adversarial-review findings from #2644 that landed on
mainunaddressed (closes #2647, supersedes #2646):ops_error_to_status'sPlayRuleRejectedarm parsed its JSON metadata payload asMetadataValue<Ascii>, silently dropping the whole payload (viaif let Ok(...)) whenever the author-supplied rejection message contained a non-ASCII byte (em dash, curly quotes, accents, emoji). Switched to gRPC's binary-metadata convention:x-play-rule-rejected-bin, carrying the payload viaMetadataValue::<Binary>::from_bytes, which is infallible.load_active_plays/handle_play_created/handle_play_updatedeach logged everyvalidate_playerror with a constantrule_name="validation"anderror_location_index=0.error_fingerprinthashes(play_id, rule_name, error_location_index, error_type)and deliberately excludes the message text, so two structurally different validation errors on the same play collapsed onto one fingerprint — the second error's text was silently discarded. AddedPlayValidationError::location()/kind()accessors and a sharedlog_validation_errors()helper that folds"{location}:{kind}"into the fingerprint identity, so distinct errors produce distinct log nodes.Also renamed the misnamed
rule_idfield (it has always held the rule's author-given name, not an id) torule_nameacrossOpsError,NodeServiceError, and their call sites.Testing
cargo test -p nodespace-core --lib playbook::— 323 passedcargo test -p nodespace-daemon --lib error_mapping_play_rule_rejected— 3 passed (incl. new non-ASCII regression test)cargo test -p nodespace-core --test playbook_engine_integration_test distinct_validation_errors_on_the_same_play_produce_separate_log_nodes— 1 passedcargo fmt --all -- --check— cleancargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async— clean🤖 Generated with Claude Code