Skip to content

Playbooks across devices: cross-device proof tests and the join-point contract test - #4290

Merged
mstomar125 merged 6 commits into
mainfrom
issue-4285-playbook-depth
Nov 17, 2026
Merged

mstomar125 merged 6 commits into
mainfrom
issue-4285-playbook-depth

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #4285 (the residual core work after the design pass found most of ADR-060 and ADR-073 already built). Tests and comments only; no behaviour change.

Proof tests (all passed on main, no bug found). Two NodeServices over separate databases, each with its own PlaybookEngine, and a relay applying each side's committed writes on the other with the playbook triggers on and invariants skipped:

  • A reactive flip-flop chain across the two devices runs to MAX_CHAIN_DEPTH on both, and the play that would take the next hop is suspended with the cycle limit.
  • Two devices running the same rule on the same trigger node derive the same node id, mint different write nonces, and converge by id; exchanging the copies keeps the chain at depth 1 and moves nothing further.

Contract test. One named test reads the join-point contract in one place: the backlog context (both skips set) fires no reactive rule and runs no invariant, the live context fires reactive rules but runs no invariant in the write's transaction, and an ordinary write is refused (control). Its doc comment says the join-point decision belongs to the apply layer.

The tests wait for a positive terminal state (up to 30 s) and only then check over a short window that no further writes happen, so a loaded machine cannot cause a false failure.

Relationship-event depth is deliberately not built. Today a chain through relationship triggers cannot hop devices, because the apply layer applies replicated changes with playbook triggers skipped. If live remote changes were ever allowed to fire triggers, such a chain would restart at depth 0 on each hop and would not be bounded by this mechanism, because edge properties do not cross the Sync wire (has_child keeps order only, mentions none, member_of permission only, custom relationships do not sync). A first version that stamped the depth on the edge was dropped for that reason, and because its reserved keys would surface in the relationship viewer. chain_depth_of_write and the relationship actions carry a comment stating this.

The ADR-060 and ADR-073 amendments follow in the docs repo.

Verification: bun run test:changed passed (rust and scripts tiers), clippy -D warnings and fmt clean; each new test was mutation-checked and run 15 times with no retries.

🤖 Generated with Claude Code

@mstomar125 mstomar125 changed the title Playbooks across devices: relationship add depth, cross-device proofs, join-point contract test Playbooks across devices: cross-device proof tests and the join-point contract test Nov 17, 2026
mstomar125 and others added 6 commits November 17, 2026 14:18
The invariant tests show the persisted depth bounds an exchange of repairs.
A reactive rule chain crosses devices through the live write context
instead (triggers on, invariants skipped), and nothing proved that path
stops. Two services, each with its own engine, and a relay applying each
side's local writes on the other now run a flip-flop chain to
MAX_CHAIN_DEPTH and suspend the play that would take the next hop.

A second test covers derived ids: two devices running the same rule on the
same trigger node derive the same id but mint different write nonces. They
converge by id, and applying each copy on the other reads as the same
one-hop chain and moves nothing further.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…across devices stop

A relationship_added rule that adds an edge restarted at depth 0 on every
device hop: chain_depth_of_write read only node writes, and the
add_relationship actions stamped nothing, so a cycle that crossed devices
through relationship triggers never reached MAX_CHAIN_DEPTH. The failing
test ran a remove-and-add-back cycle over two devices to over 30000 edge
writes.

The add paths (plain and in-transaction) now stamp the depth and a fresh
write nonce into the edge's properties, and chain_depth_of_write reads them
from a RelationshipCreated, which effective_chain_depth already consumes.
Edge ids are deterministic, so adding a stored edge again writes nothing
and emits no event; a chain stops there by itself, and only a created edge
carries a stamp onward. No schema change and no backfill: an edge without
the keys reads as depth 0, a fresh chain.

Removal chains stay unbounded by this mechanism: a deleted edge leaves no
row to carry a depth. That is stated at the removal actions and in
chain_depth_of_write.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Which context a pulled write is applied with is the apply layer's decision,
made at the join between catching up on history and following live changes.
Core only honours the context a service was built with, and that contract
was spread over tests that each covered one half. One test now reads it
whole: the backlog context fires no reactive rule and runs no invariant,
the live context fires reactive rules but runs no invariant in the write's
transaction, and an ordinary write is refused by the invariant (control).
No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… cycles across devices stop"

This reverts commit cf78539.
… state

The quiescence window (20 unchanged polls) could fail on a loaded gate
machine that was merely slow. The tests now wait up to 30 s for the state the
chain must reach (both devices at the depth limit and a suspended play; the
derived nodes present; the play active before the writes), and only then
check over a short window that no further writes happen. That window can only
turn a runaway into a pass on a slow machine, never a pass into a failure.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The comments said the wire facts alone made a cross-device relationship chain
impossible. The real reason is that the apply layer applies replicated
changes with playbook triggers skipped; the wire facts (edge properties do
not cross) matter only if live remote changes ever fire triggers. Comments
only.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4285-playbook-depth branch from 5d3223e to 1ee8936 Compare November 17, 2026 13:18
@mstomar125
mstomar125 merged commit b2f9891 into main Nov 17, 2026
@mstomar125
mstomar125 deleted the issue-4285-playbook-depth branch November 17, 2026 13:19
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