Skip to content

Add a reject/validation action type so an invariant Play can veto a write, not just augment it #2642

Closed

Description

@malibio

Overview

../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md (ADR-060) establishes RuleClass::Invariant — a rule that runs synchronously, inside the same transaction as the triggering write, fail-closed on failure. ADR-060's own framing and every example given ("establishing a property the node must never be observable without" — access/membership, required classification) is about augmenting the triggering write: the invariant rule's action adds something, and if that add fails, the whole transaction rolls back. There is no action type, and no condition-as-gate semantic, for the different and equally real case of vetoing the triggering write outright based on a condition — e.g. "reject this status change to done if any has_child child is not itself done" or "reject this status change to in_progress if any blocked_by task is not done."

Problem Statement

Confirmed by direct inspection of packages/core/src/playbook/validation.rs's validate_invariant_eligibility (~line 632 onward): every enforced Invariant-rule restriction (local-writes-only, same-graph-scope, non-chaining) governs what an invariant rule's action may do — none of them describe a "reject with no action, or reject as the action" outcome. packages/core/src/playbook/types.rs's ActionType enum (CreateNode, UpdateNode, AddRelationship, RemoveRelationship) has no member meaning "fail the transaction." ADR-060 §2's "On failure, the triggering write fails" describes an action failing incidentally (e.g. a write conflict), not a condition being deliberately used as a validity gate that always aborts when true.

This blocks a concrete, real need: a Linear/Jira-style methodology wanting "can't close an issue while it has open sub-issues" or "can't start an issue while it has an open blocker" — both are natural fail-closed, in-transaction invariants (the same class of guarantee ADR-060 already designed for), but neither can be expressed with today's ActionType set.

Note this action type alone is not sufficient for either motivating case to work end-to-end. A separate, more fundamental gap exists: RuleClass::Invariant rules have no synchronous execution path at all today — NodeService::update_node only ever emits a post-commit event, so no invariant rule (reject or otherwise) actually runs before a write returns to its caller. That wiring gap is tracked separately in #2643, since it's a prerequisite for any invariant rule's synchronous guarantee, not specific to the reject action type this issue defines.

Proposed Solution

Add an explicit action type whose entire semantic is "if reached, fail the transaction with a message" — e.g. ActionType::Reject { message: String } (or RejectIf, exact naming TBD) — usable only inside an Invariant-class rule (a Reactive rule rejecting makes no sense; there is no transaction left to fail once execution is async/post-commit). The rule's existing condition mechanism becomes the gate: condition evaluates true → the reject action runs → the transaction fails, the same "triggering write fails" outcome ADR-060 §2 already specifies, just reached deliberately rather than incidentally.

This must respect every existing Invariant eligibility constraint: deterministic conditions only (no wall-clock functions — already enforced generically by validate_invariant_eligibility), and the reject action itself needs no target-node-scope check (unlike UpdateNode/AddRelationship, it addresses no node, so InvariantOutOfScopeTarget's existing check may not apply to it at all — confirm during implementation which existing checks need to explicitly exempt this action type versus which apply unchanged).

Architecture Impact

This extends ../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md (ADR-060) — it does not reverse anything in it, but ADR-060's action/eligibility model as written only anticipates augmenting actions, not a veto action. A companion nodespace-docs update to ADR-060 (or a short new ADR) should record this action type once implemented, since ADR-060 is the authoritative source for what an invariant rule's action set means.

Acceptance Criteria

  • New ActionType variant (or equivalent) whose execution deterministically fails the transaction with a caller-supplied message
  • Usable only inside RuleClass::Invariant rules — rejected at save time (new PlayValidationError variant, following the existing InvariantNonLocalAction/InvariantOutOfScopeTarget pattern) if declared on a Reactive rule
  • Existing Invariant eligibility checks (validate_invariant_eligibility) correctly apply to or explicitly exempt the new action type, decided and documented per check
  • End-to-end test: a Play using this action type actually causes the triggering update_node call to fail, with no partial write committed — this test necessarily depends on Wire RuleClass::Invariant rules into the write path so they actually run synchronously, in-transaction #2643's synchronous wiring existing, since there is no other way to observe a reject action's effect today
  • ../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md updated to document this action type as part of the invariant-rule model
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/core/src/playbook/types.rs — ActionType (~line 191), RuleClass (~line 137) — where the new variant is declared
  • packages/core/src/playbook/validation.rs — validate_invariant_eligibility (~line 632 onward) — existing eligibility checks to apply/exempt for the new action type
  • ../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md (ADR-060) — the model this issue extends; needs a companion doc update per Architecture Impact above

Dependencies

Related Issues

Non-Goals

Activity

  1. self-assigned this
    on Sep 16, 2026
  2. mstomar125 commented on Sep 16, 2026

    @mstomar125
    Contributor

    Merged via PR #2644. Both an initial adversarial review pass and an independent second pass found real issues before merge: a save-time-validation bypass at daemon startup (load_active_plays skipped validate_play, so an invalid reject-on-reactive rule could reactivate unvalidated and disable an entire play on first trigger), a reject+for_each silent no-op hazard, missing daemon error-mapping test coverage, and a message-binding type bug. All fixed and re-verified against the actual pushed diff before merge. This unblocks #2643, which wires the same mechanism into update_node.

  3. mstomar125 commented on Sep 16, 2026

    @mstomar125
    Contributor

    Shipped in #2644 (merged): ActionType::Reject adds the veto action type for invariant playbook rules per ADR-060 §2, plus a startup save-time re-validation gate, a for_each/reject validation restriction, non-string message-binding support, and daemon-layer gRPC mapping test coverage added during review. #2643 (synchronous update_node wiring) tracked and picked up separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions