Skip to content

Implement derived identity for playbook action outputs #2565

Closed

Description

@malibio

Overview

Playbook reactive-rule action outputs currently get random ids (execute_create_node in packages/core/src/playbook/actions.rs calls Node::new(...)). Under multi-device sync, N devices independently executing the same rule against the same trigger each create a distinct node with its own random id — sync merges all of them, producing N duplicates of one intended effect instead of one.

Problem Statement

../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md (ADR-060) §3 specifies the fix — derived identity: an action output's id should be a deterministic function of its inputs, so every device computing the same action independently arrives at the same id and the writes collapse to one row on sync. This has never been implemented; there is no derived-id formula anywhere in packages/core/src/playbook/.

../nodespace-docs/decisions/074-derived-identity-for-scan-based-triggers.md (ADR-074) generalizes ADR-060 §3's formula (originally specified only for graph_event triggers, which have exactly one triggering node) to also cover scheduled/cron triggers and nested for_each iteration, neither of which has a single trigger_node_id to key from. Without this generalization, a scheduled rule with a for_each action (e.g. a cycle-rollover rule migrating N issues to a new cycle) would collapse all N outputs onto a single derived id — the exact collision ADR-060 §3 warns against, just triggered by a different cause (fan-out from one wall-clock match, not one graph event).

Proposed Solution

Implement the generalized derived-identity formula from ADR-074, which is a strict superset of ADR-060 §3 (graph_event is the depth-1 case).

Architecture Impact

This issue implements ../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md §3 and ../nodespace-docs/decisions/074-derived-identity-for-scan-based-triggers.md in full. It does not reverse or supersede any ADR.

Implementation Approach

  • Add a deterministic_id helper for playbook action outputs, following the existing pattern already proven elsewhere in packages/core (deterministic_collection_id, deterministic_conflict_id, date nodes' YYYY-MM-DD ids) — a stable hash over identifying inputs, no coordinating authority, safe offline.
  • Key derivation as deterministic_id(rule_id, action_index, iteration_path), where iteration_path is the ordered sequence of real node ids identifying the path to this specific action execution:
    • graph_event trigger, no for_each: iteration_path = [trigger_node_id].
    • scheduled trigger scanning nodes, no further nesting: iteration_path = [scanned_node_id].
    • Nested for_each (e.g. scan over cycles, then for_each over each cycle's issues): iteration_path = [scanned_node_id, item_node_id], generalizing to arbitrary nesting depth.
  • Thread iteration_path through the action executor (packages/core/src/playbook/actions.rs) so nested for_each execution carries the real node id at each depth, not just the outermost trigger/scan node.
  • Wire the derived id into execute_create_node (replacing the current Node::new(...) random-id assignment for playbook-originated creates).
  • Non-idempotent actions (output depends on model inference, network response, or wall-clock time) are explicitly out of scope — they cannot be collapsed by derived identity regardless of trigger type, and require the single-writer election ADR-060 §4 scopes to Pro tier with sync-provided coordinating authority, which does not exist yet. Do not attempt to solve this here.
  • Document (in code comments or a test) that divergent scan results across devices (ADR-060 failure mode 5 — a device mid-catch-up computing a different match set than a fully-synced device) remain a separate, unclosed gap: derived identity guarantees convergence of whatever outputs are produced, not that the same number of outputs are produced by every device.

Acceptance Criteria

  • Playbook action outputs (starting with create_node) get deterministic ids per the ADR-074 formula, not random ones
  • Test: two independent executions of the same graph_event-triggered rule against the same trigger node produce the same derived id (graph_event / depth-1 case, matching ADR-060 §3 as originally specified)
  • Test: two independent executions of a scheduled rule with a for_each over a scanned set (e.g. N items) produce N distinct derived ids, one per item — not one collapsed id for the whole batch
  • Test: nested for_each (two iteration levels) produces distinct ids per leaf item, correctly incorporating both levels' real node ids
  • Test: scan order differing across two simulated "devices" does not change the resulting set of derived ids (content-keyed, not position-keyed)
  • A rule edit that changes action order or nesting structure is understood to change derived identity from that point on — covered by a test or explicit doc note, per ADR-060 §3's and ADR-074's stated trade-off
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/core/src/playbook/actions.rs — execute_create_node and the action executor; where iteration_path needs to be threaded through
  • packages/core/src/playbook/types.rs — likely home for any new iteration_path/binding-context types
  • ../nodespace-docs/decisions/060-playbook-execution-under-multi-device-sync.md §3 — original derived-identity design (graph_event case)
  • ../nodespace-docs/decisions/074-derived-identity-for-scan-based-triggers.md — the generalized formula this issue implements
  • Existing deterministic_*_id implementations elsewhere in packages/core — the pattern to follow (exact call sites to be located during implementation; referenced in ADR-074 as deterministic_collection_id, deterministic_conflict_id, and date-node YYYY-MM-DD ids)

Dependencies

Related Issues

Non-Goals

  • Single-writer election or any other handling for genuinely non-idempotent actions under multi-device sync (ADR-060 §4, deferred — requires Pro-tier sync-provided coordinating authority that does not exist yet)
  • Resolving divergent scan results across devices mid-catch-up (ADR-060 failure mode 5) — a separate, pre-existing, unclosed gap this issue does not attempt to close

Activity

  1. self-assigned this
    on Sep 11, 2026
  2. malibio commented on Sep 11, 2026

    @malibio
    CollaboratorAuthor

    Dependency note: #2569 has been filed to rename node_type: "playbook" → "play" and instance-level identifiers in code (the engine/subsystem itself keeps the name "Playbook" — see #2569 for the full explanation, and nodespace-docs commit 175836f for the already-completed docs-side rename).

    This issue's description (and the execute_create_node/packages/core/src/playbook/actions.rs code it targets) predates that rename and is unaffected in substance — derived identity applies the same way regardless of what the node type string is called. But if #2569 lands first, expect node_type: "playbook" references in the surrounding code to read as "play" by the time this work merges. Sequencing between the two is not strict (no functional dependency), just flagging so the terminology doesn't look inconsistent mid-implementation.

  3. mstomar125 commented on Sep 11, 2026

    @mstomar125
    Contributor

    Pausing this pick per Michael — he's mid-refactor on the playbook node area with more renaming coming (#2569 confirmed, plus likely follow-on changes not yet filed). Re-read the issue and both comments before stopping.

    Status: an implementation of the ADR-060 §3 / ADR-074 derived-id formula (deterministic_id(rule_id, action_index, iteration_path) in execute_create_node, with iteration_path threaded through nested for_each) was drafted and committed locally, but not pushed as a PR — parked instead on a backup branch (paused-2565-derived-identity) so the work isn't lost, but nothing merges or builds on names that are about to change.

    Will pick this back up once Michael's refactor lands (rebasing onto whatever node_type/instance-naming shape #2569 and the rest of his changes leave behind), rather than risk a collision mid-flight.

  4. mstomar125 commented on Sep 11, 2026

    @mstomar125
    Contributor

    Implemented and opened for review: #2573.

    Formula: derived_id = deterministic_id(rule_id, action_index, iteration_path) — a UUIDv5 hash over a fixed namespace, following the existing deterministic_collection_id/deterministic_conflict_id pattern.

    • iteration_path starts as [trigger_node.id] — this single slot already covers both the graph_event trigger-node case and the scheduled trigger's scanned-node case, since the engine hands the scanned node to the action executor as trigger_node either way — and gains one more real node id per nested for_each level entered (never a positional/loop index, so devices scanning in different orders still converge).
    • execute_create_node now checks for an existing node at the derived id before inserting; a second firing computing the same id converges onto the existing row instead of erroring (which would otherwise disable the whole play).
    • A for_each item with no resolvable real node id (not a bare id string, no object "id" field) hard-fails via a new ActionError::IterationPathResolutionFailed rather than falling back to a scan-order-dependent index.

    Design deviation, called out for visibility: rule_id is derived from (play_id, the rule's own action list) via rule_id_for, not a positional rule_index. engine.rs/lifecycle.rs/cron_runner.rs were off-limits for this work (concurrent daemon-wiring in progress there), and execute_actions's only call site is in engine.rs — threading a positional index in would have required touching it. The play id was already available via PlaybookExecutionContext::source_playbook_id, and actions: &[ParsedAction] passed into execute_actions already is one rule's action list, so both trade-offs described below are self-contained to actions.rs/types.rs:

    • Editing a rule's actions changes rule_id, and therefore every id derived from it, from that edit onward — the same trade-off ADR-060 §3 already names for a positional index.
    • Two different rules in the same play with byte-identical action lists would collide onto the same rule_id — an accepted, narrow gap (near-exact duplicate rule).

    Acceptance criteria — all covered by real, passing tests (packages/core/src/playbook/actions.rs, mod tests / mod derived_identity_integration):

    • graph_event / depth-1 convergence — graph_event_depth_1_two_executions_converge_to_one_node
    • scheduled for_each over N items → N distinct ids — scheduled_for_each_produces_one_distinct_id_per_item
    • nested for_each (two levels) incorporating both levels' real ids — nested_for_each_incorporates_both_iteration_levels
    • scan-order independence (content-keyed, not position-keyed) — scan_order_does_not_affect_the_resulting_id_set
    • rule edit changes derived identity — rule_id_for_changes_when_the_rule_is_edited
    • (bonus) for_each item with no resolvable id hard-fails — for_each_item_without_resolvable_id_fails_the_rule

    Also documented in the module doc (not solved here, per the issue's own non-goals): ADR-060 failure mode 5 (divergent scan results across devices mid-catch-up) remains a separate, unclosed gap — derived identity guarantees convergence of whatever outputs are produced, not that every device produces the same number of outputs. Single-writer election for non-idempotent actions (ADR-060 §4) is also out of scope, as specified.

    bun run test:all and bun run quality:fix both pass clean; the pre-push gate (test:all + cargo build --bin nodespaced + test:e2e) passed in full before pushing.

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