Skip to content

Wire RuleClass::Invariant rules into update_node's write path (ADR-060 §2) - #2650

Merged
mstomar125 merged 5 commits into
mainfrom
issue-2643-update-node-invariant-wiring
Sep 16, 2026
Merged

mstomar125 merged 5 commits into
mainfrom
issue-2643-update-node-invariant-wiring

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Wires RuleClass::Invariant rules into update_node's write path so they actually run synchronously, in-transaction — the prerequisite update_node half of ADR-060 §1/§2 that create_node already had (from #1739/#2632). Depends on core#2642 (the reject action type), already merged.

  • packages/core/src/playbook/validation.rs: relaxed InvariantUnsupportedTrigger to accept property_changed triggers, not just node_created — the whole point of this issue is giving that trigger a real synchronous join point. relationship_added/relationship_removed/scheduled remain unsupported (no equivalent transaction to join). Updated the one existing test that asserted property_changed was rejected (it's now accepted, same as node_created).
  • packages/core/src/services/node_service/invariants.rs: new dispatch_invariant_rules_for_update_in_tx, the update_node twin of the existing dispatch_invariant_rules_in_tx. Reuses playbook::lifecycle::trigger_keys_for_event — the exact same exact-key/wildcard-key dual lookup the reactive engine's event subscriber already uses — so save- and dispatch-time trigger matching can never silently diverge, and reuses the shared execute_matched_invariant_rules_in_tx execution core Add a reject/validation action type so an invariant Play can veto a write, not just augment it #2642 built, so the reject-action distinction (PlayRuleRejected vs generic InvariantRuleFailed) holds identically for both call sites by construction.
  • packages/core/src/services/node_service/crud.rs: the substantial change. update_with_version_check_returning_node now wraps a new tx-scoped twin (update_with_version_check_returning_node_in_tx) in with_transaction, mirroring how create_node already wraps create_node_in_tx. Inside the transaction: read existing (tx-consistent) → validate (behavior/schema/play-rules) → version-checked write (tx-scoped) → compute the real changed_properties diff (compute_property_changes, since _in_tx store methods bypass the store's own notifier that normally computes this) → buffer the NodeUpdated event → synchronous invariant dispatch → re-read the node's final tx-consistent state (see "self-referential augment" note below) before returning. A rejecting rule's Err propagates through the whole chain and rolls back everything, including the buffered event (never flushed on rollback). Post-commit side effects (embedding queue, mentions sync, collection-name-collision marking) stay outside the transaction, unchanged in behavior from before.

Two real bugs caught by the test suite during implementation (not by review — worth flagging)

  1. Self-referential augment returned stale data. The canonical invariant-rule shape (from Introduce invariant vs reactive playbook rule classes with synchronous pre-commit execution on the origin device #1739's own precedent) is a rule whose action updates the SAME node that triggered it — e.g. "on status change, stamp verified: true." My first pass returned the pre-dispatch node snapshot as update_node's result, silently omitting the invariant action's own write from the RPC response (even though it was genuinely, durably committed). Fixed by re-reading the node's tx-consistent final state after dispatch succeeds, rather than returning the captured pre-dispatch value.
  2. Dropped collection-name-collision detection. The non-tx SqliteStore::update_node_with_version_check did collision pre-check + post-commit marking internally; switching to the tx-scoped primitive (which deliberately omits this, same posture as create_node_in_tx) silently dropped that behavior. Caught by collection_name_convergence_test.rs's existing update_path_introducing_a_name_collision_is_now_marked test. Fixed by replicating create_node's own pre-check/post-mark pattern for the update path (pre-tx read-only detection, post-commit best-effort marking).

Both are exactly the kind of thing this repo's full-suite-before-push discipline exists to catch — glad the existing tests were doing their job.

Adversarial focus (per the task)

  • Zero partial state on a rejected write, verified by test: invariant_update_rule_reject_prevents_partial_write confirms both the property value AND the version stay at their pre-update values after a rejection.
  • No DomainEvent broadcast on rejection, verified by test: invariant_update_rule_reject_emits_no_domain_event subscribes before the write and asserts try_recv() is Empty after a rejected update.
  • RuleClass::Reactive completely unaffected: reactive_update_rule_still_fires_asynchronously_post_commit proves a reactive rule on the same trigger shape stays async/post-commit, requiring the real engine loop and wait_until — unlike every invariant test, which asserts synchronously on update_node's own return value.
  • Successful path broadcasts normally: invariant_update_rule_augmenting_action_commits_and_broadcasts_normally proves an augmenting action commits atomically AND a real NodeUpdated broadcast for the triggering write goes out.
  • Trigger-key specificity: invariant_update_rule_scoped_to_one_property_ignores_a_different_property_change proves a property_key-scoped rule doesn't fire on an unrelated property change (exercises the real trigger_keys_for_event exact/wildcard matching, not a blanket per-node-type match).

Frontend

Per the task's explicit instruction (this specific piece is listed as a desktop-app follow-up in the issue's own Non-Goals, but was requested directly): added isPlayRuleRejected type guard (packages/desktop-app/src/lib/types/errors.ts) and wired it into shared-node-store.svelte.ts's updateNode catch block (~line 2003), alongside the existing isVersionConflict branch, reusing the same rollbackUpdate() call and differing only in which toast message shows (the rule's own author-supplied message, not a generic one). Also updated:

  • packages/desktop-app/src-tauri/src/commands/nodes.rs's status_to_command_error — new PLAY_RULE_REJECTED branding gated on FAILED_PRECONDITION + x-play-rule-rejected metadata (mirrors the existing SUBTREE_ACCESS_DENIED pattern), with tests.
  • packages/dev-tools/src/grpc-error-mapping.ts — the dev-proxy/gRPC-js-side mirror of the same mapping, so bun run dev:browser sees the same code/conflictData shape as the Tauri path. No existing test infrastructure for this file (verified via tsc --noEmit, no pre-existing test suite to extend).

Known limitations (explicitly out of scope, flagging for visibility)

Two other write paths bypass update_with_version_check_returning_node entirely and therefore do not get synchronous invariant dispatch from this PR — only the generic update_node RPC path does. The issue's own reference files and Proposed Solution only name update_node/create_node, so both are treated as correctly out of scope rather than silently expanded; flagging so they're conscious, visible gaps rather than a surprise:

  • NodeService::update_task_node (packages/core/src/services/node_service/schema.rs) — a genuinely separate write path, calling SqliteStore::update_task_node directly with its own bespoke OCC handling via error-string matching. Reached via the dedicated updateTaskNode frontend method and UpdateTaskNode RPC.
  • NodeService::bulk_update (packages/core/src/services/node_service/bulk.rs) — calls SqliteStore::bulk_update, a single-SQL-statement batch primitive with no NodeServiceTx-composable hook point (not the with_transaction/NodeServiceTx machinery this PR's wiring depends on), so a property change delivered via a bulk update won't trigger a matching invariant rule either.

Both are pre-existing, independent write paths, not something this PR introduces or regresses — they simply don't (yet) share the transaction-wrapped pipeline this issue extends.

Test plan

  • cargo test -p nodespace-core --lib — 1396 passed.
  • cargo test -p nodespace-core --test playbook_invariant_integration_test — 22 passed (16 pre-existing + 6 new update-triggered invariant tests).
  • cargo test -p nodespace-core --test playbook_engine_integration_test — 4 passed.
  • cargo test -p nodespace-core --test collection_name_convergence_test — 11 passed (confirms the collision-detection fix).
  • cargo test -p nodespace-daemon --lib — 208 passed. --test grpc_round_trip — 25 passed (including update_increments_version, watch_nodes_receives_create_update_delete_events, watch_nodes_over_real_transport_suppresses_own_echo_and_delivers_foreign_writes).
  • cargo test -p nodespace-app --lib — 169 passed (including new status_to_command_error tests).
  • bun run test (frontend) — 4959 passed across 240 files, including new isPlayRuleRejected unit tests.
  • cargo clippy --all-targets -- -D warnings -D clippy::unused-async — clean across the whole workspace.
  • bun run test:all — green.

🤖 Generated with Claude Code

…0 §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]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Updated the PR description: found and disclosed a second known-limitation write path (bulk_update, alongside the already-noted update_task_node) that also bypasses this wiring — a batch property update via bulk_update won't trigger a matching invariant rule either, since it uses a separate SQL-level batch primitive with no NodeServiceTx-composable hook point. Both are pre-existing separate write paths, correctly out of scope per the issue's stated Proposed Solution (update_node/create_node only), not a regression introduced here.

…pdate-node-invariant-wiring

# Conflicts:
#	packages/desktop-app/src-tauri/src/commands/nodes.rs
@mstomar125

Copy link
Copy Markdown
Contributor Author

Adversarial review (manual pass, not /pragmatic-code-review)

Diff pulled from GitHub (gh pr diff 2650) rather than the local worktree, since this branch is currently mid-merge-conflict-resolution against main. Verified everything below against the actual current source (including packages/core/src/db/sqlite_store/mod.rs's notifier closure, packages/core/src/playbook/lifecycle.rs, and the pre-PR version of update_with_version_check_returning_node at e2f6de3f), not just the diff text.

Real, actionable finding: stale x-play-rule-rejected (ASCII) references in 3 frontend-facing files

This PR was developed before PR #2649 (core#2647) merged into main. #2649 renamed the daemon's structured play-rule-rejection metadata from an ASCII header (x-play-rule-rejected + JSON { ..., "rule_id": ... }) to a binary one (x-play-rule-rejected-bin, via MetadataValue<Binary> + insert_bin, JSON payload now { ..., "rule_name": ... }) — I independently verified #2649's daemon-side change is real and already reflected in current main in an earlier review pass today.

This PR's three new frontend-facing consumers all target the old, now-dead shape:

  • packages/desktop-app/src-tauri/src/commands/nodes.rs — status.metadata().get("x-play-rule-rejected") (ASCII get, not get_bin). This is exactly the file currently showing as a git conflict against main — whoever resolves it needs to update this to get_bin("x-play-rule-rejected-bin") + binary decode, not just pick one side.
  • packages/desktop-app/src/lib/types/errors.ts — PlayRuleRejectedData.rule_id: string (daemon now sends rule_name).
  • packages/dev-tools/src/grpc-error-mapping.ts — firstMetadataString(metadata, 'x-play-rule-rejected') (ASCII/string metadata lookup; the daemon no longer sends this key in the ASCII metadata space at all post-Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649, only the binary-encoded -bin key).

Why this is more dangerous than the git conflict alone suggests: nodes.rs will force attention because it's a literal merge conflict. But errors.ts and grpc-error-mapping.ts never touch anything main changed, so they'll merge cleanly with no conflict marker — and then silently never match the daemon's real metadata again. The entire PLAY_RULE_REJECTED frontend feature this PR adds (isPlayRuleRejected, the shared-node-store.svelte.ts wiring, the dev-proxy mirror) would ship dead: no toast, no rollback-with-message, just falling through to the generic write-failure/GRPC_ERROR path on every real rejection, via BOTH the Tauri path and the dev-proxy path. Please grep for x-play-rule-rejected (without -bin) and rule_id (in the new PlayRuleRejectedData/isPlayRuleRejected code specifically, not the unrelated rule_id_for playbook-actions machinery) across all three files and update to match #2649's shape before this merges.

Everything else checked and verified clean (not just trusted)

  • emit_event's metadata stamping is NOT a regression. I traced the full path: the non-tx path routed client_id/execution_context through StoreChange.source/.playbook_context → the store's notify closure → EventEnvelope.metadata. The new tx-scoped path instead calls NodeService::emit_event directly, which stamps source_client_id: self.client_id.clone() / playbook_context: self.execution_context.clone() from the SAME NodeService instance fields. Equivalent value, different plumbing — no dropped echo-prevention/origin metadata.
  • Re-read-after-dispatch is correctly a no-op when the invariant action targets a different node — the final re-read always re-reads the ORIGINAL trigger node's own id, never the action's target, so an action that wrote to a different node just produces a harmless re-read of an unchanged row.
  • with_transaction's discard-on-error is real, confirmed in mod.rs: if result.is_ok() { flush_envelopes(...) } with buffered events simply dropped on any Err — including the Err a reject action propagates through. Matches the "no broadcast on reject" claim exactly.
  • Reactive rules genuinely cannot be double-triggered or run synchronously. lookup_rules itself is class-agnostic (returns both Reactive and Invariant matches), but the SHARED execute_matched_invariant_rules_in_tx explicitly filters if rule_ref.rule.class != RuleClass::Invariant { continue; } before executing anything — confirmed this is the actual gate, not an assumption. A matched Reactive rule is silently skipped here and still fires normally via the independent post-commit broadcast + reactive engine subscriber, unchanged.
  • The property_changed namespacing is internally consistent. compute_property_changes produces "{node_type}.{field}" keys (confirmed in mod.rs), trigger_keys_for_event consumes prop.key verbatim for the exact-match TriggerKey, and the new test fixtures correctly declare property_key in that same namespaced form. No off-by-one.
  • bulk_update's exclusion is already flagged in the PR's own Known Limitations per your follow-up comment — agreed, correctly out of scope.

Minor, non-blocking observation

The collection-name-collision pre-check (previous = self.get_node(id).await?, read before the transaction opens) is computed only from the primary update's own content/node_type. If an invariant rule's OWN action were to rename the SAME node into a colliding collection name (rather than the primary update doing so directly), the pre-check would miss it and no collision marker would be written. This is an extremely narrow case, shares the identical posture create_node's own pre-check already has (not something this PR regresses), so not blocking — just flagging for awareness.

Overall: the transactional/invariant-wiring refactor itself is sound and well-tested; I could not find a gap beyond the two you already caught. The one real, mergeable-today problem is the stale ASCII header shape in the three frontend files above.

mstomar125 and others added 2 commits September 16, 2026 11:12
…etadata

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]>
…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]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Re-review of the FULL settled diff (git diff origin/main...HEAD, origin/main fetched fresh at bc33d376, branch head dfb2eef1). This re-review verified the prior review's two claims independently — (1) the three stale-ASCII-key fixes, and (2) the core transactional/invariant-wiring logic — plus ran the real test suites.

The core transactional/invariant-wiring logic (item 2) re-verifies clean. Read crud.rs's update_with_version_check_returning_node/_in_tx and invariants.rs's dispatch_invariant_rules_for_update_in_tx / shared execute_matched_invariant_rules_in_tx directly, and confirmed with with_transaction's implementation (node_service/mod.rs): the buffered NodeUpdated event is discarded (never flushed) whenever the closure returns Err, which is exactly what a reject action's propagated error produces; the RuleClass::Invariant filter (if rule_ref.rule.class != RuleClass::Invariant { continue; }) is the real, unconditional gate a matched Reactive rule is skipped by. All 22/22 playbook_invariant_integration_test cases pass, including the specific adversarial ones (invariant_update_rule_reject_prevents_partial_write, invariant_update_rule_reject_emits_no_domain_event, reactive_update_rule_still_fires_asynchronously_post_commit, invariant_update_rule_scoped_to_one_property_ignores_a_different_property_change). validation.rs's relaxation of InvariantUnsupportedTrigger to accept property_changed (while still rejecting relationship_added/relationship_removed/scheduled) is correctly scoped and the one updated test (invariant_property_changed_trigger_accepted) matches. No new gaps found beyond the two already-disclosed known limitations (update_task_node, bulk_update).

Item 1 (the three stale-ASCII-key fixes) is where this re-review found a critical, blocking problem that is NOT what it appears to be from the diff or commit messages alone.

Findings

Critical Issues

1. This branch never actually merged PR #2649 (bc33d376) — the three "fix" commits made the frontend match a scheme the branch's own daemon code does not emit.

Verified with git merge-base --is-ancestor bc33d376 HEAD → not an ancestor. The merge commit 8296bcee's two parents are ea0596d6 (this branch's own invariant-wiring commit) and 0eb68bfd — i.e. the merge picked up origin/main as of 0eb68bfd ("Add title to NodeData proto…", #2645), which predates #2649. PR #2649 (e7879691 → f5bb9ffd → 2c084564 → bc33d376) landed on main in parallel, after this branch's merge commit — confirmed by timestamps: 8296bcee at 08:05:54Z, bc33d376 at 09:17:01Z.

Concrete, verified consequence — the currently-committed state of this branch (not main) still has:

  • packages/core/src/ops/mod.rs / packages/core/src/services/error.rs: OpsError::PlayRuleRejected / NodeServiceError::PlayRuleRejected still carry the field rule_id, not rule_name.
  • packages/daemon/src/services/node_service.rs's ops_error_to_status still builds the payload as {"rule_id": ...} and inserts it as ASCII status.metadata_mut().insert("x-play-rule-rejected", val) via MetadataValue<Ascii> — the exact non-ASCII-message-silently-dropped bug Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649 exists to fix is still live on this branch, unfixed.

Meanwhile, this session's three follow-up commits (7bfe4e50, dfb2eef1) updated nodes.rs, errors.ts, and grpc-error-mapping.ts to read the binary x-play-rule-rejected-bin key and the rule_name field — a shape the branch's own daemon code, as actually committed, never sends.

Net effect: the daemon emits ASCII x-play-rule-rejected/rule_id; every frontend and dev-proxy consumer now looks for binary x-play-rule-rejected-bin/rule_name. The keys never match on this branch as committed. The entire PLAY_RULE_REJECTED frontend feature this PR adds — isPlayRuleRejected, the shared-node-store.svelte.ts rollback-with-message wiring, the dev-proxy mirror — still ships completely dead on both the Tauri path and the dev-proxy path: every real rejection silently falls through to the generic write-failure/GRPC_ERROR path. This is exactly the danger the prior review flagged, just recreated in the opposite direction (frontend now points at a scheme the branch's daemon doesn't implement, rather than the daemon's real scheme going unread).

The commit messages for 7bfe4e50/dfb2eef1 state the daemon "now" uses binary metadata / is "stale against main" — true of main itself at the time they were written, but never actually true of this branch's own merged copy of the daemon code, because the relevant merge never happened after #2649 landed.

This is straightforward to fix, not a design problem: git merge-tree --write-tree HEAD origin/main (read-only simulation, verified without touching the worktree) completes with zero conflicts — this PR's own commits never touch ops/mod.rs, error.rs, or node_service.rs, so a fresh merge (or rebase) of current origin/main (bc33d376) into this branch will cleanly adopt main's already-fixed binary/rule_name code, and the frontend/dev-proxy fixes already made will then be correct. But as currently committed, it is broken, and must be re-merged before this can land.

Test-coverage caveat worth flagging for whoever picks this up: the tests that currently pass do not catch this gap. status_to_command_error_maps_play_rule_rejected (nodes.rs, ran it — passes) constructs a synthetic tonic::Status directly via insert_bin(...), not by calling the daemon's real ops_error_to_status, so it never exercises the actual cross-crate contract. The daemon's own error_mapping_play_rule_rejected_returns_failed_precondition_with_metadata test (ran the full --lib suite, passes) is self-consistent with the daemon's own — currently stale — code, so it doesn't catch the mismatch either. There's no test in this diff that exercises the daemon → Tauri/dev-proxy round trip for this specific error end-to-end, which is exactly the seam that's currently broken.

Suggested Improvements

None beyond what the prior review already disclosed as acceptable (the narrow collection-name-collision edge case where an invariant action's own write, not the primary update, introduces the collision — same posture as create_node's pre-existing gap, not a regression).

Nitpicks

Nit: Once the branch is re-merged with current main, worth double-checking packages/dev-tools/src/grpc-error-mapping.ts's doc comment header (lines 6-25) still accurately describes the daemon's ASCII-vs-binary key split after the merge — it already correctly describes the binary scheme, so this should be a no-op, just worth a quick re-read post-merge rather than assumed.

Verification performed

  • git diff origin/main...HEAD / git log --no-decorate origin/main...HEAD read in full from the worktree.
  • Grepped the whole repo for bare x-play-rule-rejected (no -bin) and rule_id in the play-rule-rejection context: confirmed no 4th stale frontend/dev-proxy file exists — the only remaining bare-ASCII/rule_id references are in packages/core/src/ops/mod.rs, packages/core/src/services/error.rs, and packages/daemon/src/services/node_service.rs, which is the finding above (not a missed frontend file, but this branch's own daemon-side code not actually having Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649's fix yet).
  • Confirmed firstMetadataString's typeof value === 'string' ? value : value.toString('utf8') branch is technically correct for gRPC-js's -bin metadata handling (gRPC-js does hand back Buffer for -bin-suffixed keys) — the TS code itself is sound, it just currently has nothing real to decode on this branch.
  • Re-verified the reject-rollback and Invariant/Reactive class-filtering gate directly in crud.rs/invariants.rs/mod.rs, not just trusting the prior review.
  • git merge-base --is-ancestor bc33d376 HEAD and merge-commit parent inspection to establish the branch never absorbed Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649.
  • git merge-tree --write-tree HEAD origin/main (read-only) to confirm re-merging is conflict-free and correctly adopts main's fix.
  • cargo test -p nodespace-core --lib: 1396 passed, 1 failed. The failure (schema::schema_test::test_create_schema_empty_name_is_rejected_like_a_missing_one, "Failed to mark read connection query-only") is a pre-existing parallel-execution flake, not a regression — reran in isolation (--test-threads=1) and it passes cleanly.
  • cargo test -p nodespace-core --test playbook_invariant_integration_test --test playbook_engine_integration_test: 26 passed, 0 failed (22 + 4).
  • cargo test -p nodespace-app --lib status_to_command_error: 3 passed, 0 failed (see test-coverage caveat above on why this doesn't catch the real issue).

Recommendation: REQUEST CHANGES

The core update_node invariant-wiring logic (the actual substance of issue #2643) is sound and well-tested — no new issues found there on re-review. But the branch as currently committed genuinely does not have PR #2649's fix merged in, despite the PR description, the follow-up commit messages, and the prior review all believing it does. As committed, the daemon emits the old ASCII x-play-rule-rejected/rule_id shape while every frontend/dev-proxy consumer (including this PR's own new PLAY_RULE_REJECTED feature) now expects the new binary x-play-rule-rejected-bin/rule_name shape — a complete mismatch that ships the whole feature dead. Re-merge (or rebase onto) current origin/main — confirmed conflict-free — to pick up main's real fix, then re-run the test suites and this review's item-1 grep once more before merging.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above. Summary: core invariant-wiring logic (crud.rs/invariants.rs) re-verifies clean and is well-tested. Blocking issue: this branch never actually merged PR #2649 (bc33d37 is not an ancestor of HEAD — the branch's merge commit 8296bce only picked up main through 0eb68bf, which predates #2649). As a result the daemon (packages/daemon/src/services/node_service.rs) still emits the old ASCII x-play-rule-rejected/rule_id metadata shape, while this session's own follow-up commits (7bfe4e5, dfb2eef) updated every frontend/dev-proxy consumer to expect the new binary x-play-rule-rejected-bin/rule_name shape. The keys never match as currently committed, so the PLAY_RULE_REJECTED frontend feature this PR adds ships completely dead. Fix: re-merge (or rebase onto) current origin/main — confirmed conflict-free via a read-only git merge-tree simulation — before this can land.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Third-round re-review of PR #2650, focused specifically on verifying that the merge performed in response to round 2's REQUEST CHANGES actually landed correctly and completely — the exact failure category that round 2 caught. All checks below were run independently, from scratch, not trusted from the reported summary.

Findings

Critical Issues

None.

Suggested Improvements

None beyond what round 1/round 2 already disclosed as acceptable (the narrow collection-name-collision edge case sharing create_node's pre-existing posture, and the update_task_node/bulk_update known-limitation write paths correctly declared out of scope per the issue).

Nitpicks

None new.

Verification performed

1. Merge correctness (the core thing this round exists to check)

  • git fetch origin main fresh, then git rev-parse FETCH_HEAD → bc33d376a0844e3f00b17241a768d2a7546389b4 — the exact commit round 2 identified as missing.
  • git merge-base --is-ancestor bc33d376a0844e3f00b17241a768d2a7546389b4 HEAD → true. bc33d376 is also independently confirmed as an ancestor of HEAD via direct check.
  • HEAD (6ee495e7) is a genuine two-parent merge commit: parents are dfb2eef1 (this branch's prior tip) and bc33d376 (fresh origin/main, including Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649). This is the correct, complete merge round 2 asked for.

2. Repo-wide grep for the dead ASCII scheme

  • x-play-rule-rejected (bare, no -bin): only one remaining hit anywhere in the repo, packages/desktop-app/src-tauri/src/commands/nodes.rs:1194, which is a comment in a test (// No x-play-rule-rejected or x-subtree-inaccessible-count metadata present) describing an unrelated negative-case test — not a live reference to the old key. No production or type code anywhere still reads/writes the bare key.
  • rule_id (excluding rule_id_for): all remaining hits are in packages/core/src/playbook/actions.rs and validation.rs (rule_idx, deterministic_action_output_id(rule_id, ...)) — the legitimate, unrelated playbook-action-id-derivation concept, correctly out of scope per the task's own instruction. Zero hits in the play-rule-rejection payload/error-type context.
  • All 4 files carrying x-play-rule-rejected-bin are exactly the expected set: nodes.rs (Tauri), errors.ts, grpc-error-mapping.ts (dev-proxy), and node_service.rs (daemon).

3. Read the three previously-suspect files directly (not inferred from grep)

  • packages/core/src/ops/mod.rs and packages/core/src/services/error.rs: PlayRuleRejected variants now carry rule_name: String (not rule_id), used in both the Display format string and constructors.
  • packages/daemon/src/services/node_service.rs: ops_error_to_status builds {"rule_name": rule_name, ...} and inserts it via tonic::metadata::MetadataValue::<tonic::metadata::Binary>::from_bytes(...) + .insert_bin("x-play-rule-rejected-bin", val) — the real binary scheme, plus explanatory comments about why -bin/Binary is required for non-ASCII messages. The file's own tests (error_mapping_play_rule_rejected_*) round-trip via get_bin("x-play-rule-rejected-bin") and assert payload["rule_name"], including a dedicated non-ASCII-message case.

4. Confirmed the merge didn't touch the PR's own invariant-wiring logic

  • git diff dfb2eef1 6ee495e7 -- packages/core/src/services/node_service/crud.rs → empty. The merge was purely additive from origin/main; crud.rs (the actual substance of issue Wire RuleClass::Invariant rules into the write path so they actually run synchronously, in-transaction #2643) is byte-identical before and after.
  • Full git diff dfb2eef1 6ee495e7 --stat shows only files consistent with what origin/main brought in (ops/mod.rs, playbook/engine.rs, playbook/validation.rs, services/error.rs, playbook_engine_integration_test.rs, playbook_invariant_integration_test.rs, daemon/services/node_service.rs) — matches Fix x-play-rule-rejected non-ASCII metadata drop and validation-error fingerprint collision (post-#2644 follow-up) #2649 plus the other main commits already visible in the log, not anything invented by this branch.
  • git diff origin/main...HEAD --stat (the PR's actual three-dot diff) confirms the PR's own changes are confined to validation.rs, crud.rs, invariants.rs, the invariant integration test, nodes.rs, shared-node-store.svelte.ts, conflict-notifications.svelte.ts, errors.ts, errors.test.ts, grpc-error-mapping.ts — node_service.rs/ops/mod.rs/error.rs are correctly absent from this list, i.e. their new-scheme content is entirely main's, not duplicated/reintroduced by this branch.
  • No leftover <<<<<<</=======/>>>>>>> conflict markers anywhere in the repo.

5. Tests re-run for real, from a cold shell, not trusted from the reported numbers

  • cargo test -p nodespace-core --lib → 1398 passed, 0 failed (matches reported).
  • cargo test -p nodespace-core --test playbook_invariant_integration_test --test playbook_engine_integration_test → 22 + 8 = 30 passed, 0 failed (matches reported).
  • cargo test -p nodespace-app --lib status_to_command_error → 3 passed, 0 failed (matches reported).
  • cargo test -p nodespace-daemon --lib play_rule_rejected → 3 passed, 0 failed (matches reported).
  • svelte-check (bunx svelte-check --workspace packages/desktop-app) → 2330 files, 0 errors, 0 warnings (matches reported).
  • None of the runs hit the known test_create_schema_empty_name_is_rejected_like_a_missing_one parallel-execution flake this time; no other failures surfaced either.

6. Read the full prior-round comment/review history (gh pr view 2650 --json comments,reviews) — both rounds' reports read in full and match this task's summary of them accurately, including round 2's precise ancestor-check finding and its git merge-tree conflict-free confirmation.

Conclusion

The merge genuinely landed this time: bc33d376 (current origin/main, including #2649) is now a real ancestor of HEAD via a proper two-parent merge commit, the daemon and the three frontend/dev-proxy consumers now agree on the same binary x-play-rule-rejected-bin/rule_name scheme repo-wide, the merge was additive-only and did not disturb the PR's own crud.rs invariant-wiring logic (empty diff pre/post-merge), and all four requested test suites plus svelte-check pass with counts matching what was reported. No new issues found on this pass.

Recommendation: APPROVE

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 merged commit 6135efb into main Sep 16, 2026
@mstomar125
mstomar125 deleted the issue-2643-update-node-invariant-wiring branch September 16, 2026 09:45
mstomar125 added a commit that referenced this pull request Sep 16, 2026
…ected writes (#2654)

* Add PlayRuleRejected handling to updateTaskNode() and audit remaining write-failure call sites

updateNode()'s catch block, errors.ts's isPlayRuleRejected, and the
'play-rule-rejected' conflictType were already wired by core#2643/#2650.
updateTaskNode() was missing the equivalent branch even though it is the
primary path for a task status-change rejection — add it, following this
method's existing non-rollbackUpdate() recovery pattern.

Audit the other conflictNotifications.add({..., conflictType:
'write-failure'}) call sites in shared-node-store.svelte.ts and document
each one's reachability inline: deleteNode() is structurally unreachable
(delete_node never dispatches invariant rules); setNode() and
persistBatchedChanges()/commitAllBatches() are reachable but deliberately
keep their existing generic-failure handling, matching how each already
treats OCC conflicts.

Extend dev-proxy-grpc-error-mapping.test.ts, backend-adapter.test.ts, and
add play-rule-rejected-notification.test.ts covering both updateNode() and
updateTaskNode() call sites end to end (backend-adapter mock through to the
surfaced toast).

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

* Correct occConflictAlreadyNotified comments to cover PlayRuleRejected

Both outer-catch comments (updateNode(), updateTaskNode()) described the
shared flag as OCC-only, left stale once the PlayRuleRejected branches
started setting it too. Update the wording to name both cases.

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

---------

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.

1 participant