Repository navigation
Description
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_idhelper for playbook action outputs, following the existing pattern already proven elsewhere inpackages/core(deterministic_collection_id,deterministic_conflict_id, date nodes'YYYY-MM-DDids) — a stable hash over identifying inputs, no coordinating authority, safe offline. - Key derivation as
deterministic_id(rule_id, action_index, iteration_path), whereiteration_pathis the ordered sequence of real node ids identifying the path to this specific action execution:graph_eventtrigger, nofor_each:iteration_path = [trigger_node_id].scheduledtrigger scanning nodes, no further nesting:iteration_path = [scanned_node_id].- Nested
for_each(e.g. scan over cycles, thenfor_eachover each cycle's issues):iteration_path = [scanned_node_id, item_node_id], generalizing to arbitrary nesting depth.
- Thread
iteration_paththrough the action executor (packages/core/src/playbook/actions.rs) so nestedfor_eachexecution 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 currentNode::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_eachover 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_nodeand the action executor; whereiteration_pathneeds to be threaded throughpackages/core/src/playbook/types.rs— likely home for any newiteration_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_*_idimplementations elsewhere inpackages/core— the pattern to follow (exact call sites to be located during implementation; referenced in ADR-074 asdeterministic_collection_id,deterministic_conflict_id, and date-nodeYYYY-MM-DDids)
Dependencies
- None — this can be implemented independently of Wire playbook engine into daemon startup, hard-gated to local-only events #2562/Expose playbook lifecycle and get-workflow-state via CLI and skill guidance #2563, though it has no observable effect until the engine is actually running (Wire playbook engine into daemon startup, hard-gated to local-only events #2562) and a rule exercising
for_each-over-scan exists.
Related Issues
- Should be listed as a blocking dependency on any future issue that ships a scheduled rule with a
for_each-over-scan action (e.g. a "Linear-style" cycle-rollover playbook recipe) — not yet filed as of this issue's creation. - Related to Wire playbook engine into daemon startup, hard-gated to local-only events #2562 (playbook engine wiring) and Expose playbook lifecycle and get-workflow-state via CLI and skill guidance #2563 (CLI/skill exposure), though not a direct dependency of either.
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
malibio commentedon Sep 11, 2026
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 commit175836ffor the already-completed docs-side rename).This issue's description (and the
execute_create_node/packages/core/src/playbook/actions.rscode 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, expectnode_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.mstomar125 commentedon Sep 11, 2026
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)inexecute_create_node, withiteration_paththreaded through nestedfor_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.mstomar125 commentedon Sep 11, 2026
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 existingdeterministic_collection_id/deterministic_conflict_idpattern.iteration_pathstarts as[trigger_node.id]— this single slot already covers both thegraph_eventtrigger-node case and thescheduledtrigger's scanned-node case, since the engine hands the scanned node to the action executor astrigger_nodeeither way — and gains one more real node id per nestedfor_eachlevel entered (never a positional/loop index, so devices scanning in different orders still converge).execute_create_nodenow 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).for_eachitem with no resolvable real node id (not a bare id string, no object"id"field) hard-fails via a newActionError::IterationPathResolutionFailedrather than falling back to a scan-order-dependent index.Design deviation, called out for visibility:
rule_idis derived from(play_id, the rule's own action list)viarule_id_for, not a positionalrule_index.engine.rs/lifecycle.rs/cron_runner.rswere off-limits for this work (concurrent daemon-wiring in progress there), andexecute_actions's only call site is inengine.rs— threading a positional index in would have required touching it. The play id was already available viaPlaybookExecutionContext::source_playbook_id, andactions: &[ParsedAction]passed intoexecute_actionsalready is one rule's action list, so both trade-offs described below are self-contained toactions.rs/types.rs: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.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_two_executions_converge_to_one_nodefor_eachover N items → N distinct ids —scheduled_for_each_produces_one_distinct_id_per_itemfor_each(two levels) incorporating both levels' real ids —nested_for_each_incorporates_both_iteration_levelsscan_order_does_not_affect_the_resulting_id_setrule_id_for_changes_when_the_rule_is_editedfor_each_item_without_resolvable_id_fails_the_ruleAlso 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:allandbun run quality:fixboth pass clean; the pre-push gate (test:all +cargo build --bin nodespaced+ test:e2e) passed in full before pushing.