Skip to content

state: replicate deletes, so a client's tree mirrors the relay's - #1473

Merged
transfix merged 1 commit into
masterfrom
feat/state-delete-replication
Nov 23, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/state-delete-replication

Conversation

@transfix

Copy link
Copy Markdown
Owner

Until now, a node removed on a replicated tree stayed on every peer. state_sync_adapter journaled values, data and metadata, but not removals. A WS relay's periodic diff dropped paths that left its tree without telling the client. A joiner's snapshot only says what is there. The only delete that ever reached a client was a read-scope retraction.

So every server-side removal left ghosts on clients:

  • a world's departed vehicles and spawn points;
  • the entries a document's (state-set-tree) drops (the way ARIADNE.md tells server documents to take entries out);
  • DSL list rows;
  • (state-delete).

What changes

Removals are journaled (state_sync_adapter)

  • A removal is journaled as one delete_subtree at the removed node. childChanged fires on every observed ancestor, and only the first finds the node still observed.
  • The delete is timed by the shard's clock (set_clock, wired by state_cluster_shard).
  • A remote delete is applied under the suppression guard, so it is never echoed back.

Tombstones stop resurrection (state_sync_adapter, state_cluster_shard)

  • Each delete applied, local or remote, leaves a tombstone: its path and time. Tombstones last 10 minutes, at most 4096 are kept, and a later delete above takes the older ones below it.
  • ingest_remote buries a remote write at or below a tombstone whose time is no later than the delete's. Its writer made it before it saw the delete. The write is recorded as seen, not applied, and reported as ingest_result::buried; neither relay transport forwards it.
  • A write made after its writer saw the delete is later on any clock that merged the delete's time, so it makes the node again.

Deletes reach subscribers below them (state_peer_registry)

  • A delete at a must reach a peer subscribed to a.b, or one whose filter delivers something below a.
  • should_deliver(node, path, subtree) and delivery_view::deliver(path, subtree) handle that case.
  • The WS, gRPC, inproc and IPC fan-outs and backfills use them for delete and reset ops. Read scopes already did this through read_scope_delivers.

Missed deletes are repaired (state_transport_ws, state_transport_grpc)

  • broadcast_snapshot sends a delete for each subtree a client was sent that has since left the tree, so a client that missed the live delete converges within one broadcast. Paths that only left the client's view are forgotten, as before. These deletes come from <shard>#sync and are untimed, so they leave the client no tombstone (state_transport::tree_removal).
  • A relay that does not backfill (S7's trimmed journal, arisrv's default) sends its remembered deletes after a joiner's admit snapshot, skipping any subtree that has come back (state_transport::missed_deletes). A client back from a dropped link loses what went while it was away. A relay that does backfill already replays the deletes with the rest of its journal.

The room gate admits own deletes (room_write_gate)

  • A participant may delete a node strictly inside its own subtree.
  • It may not delete the participant node itself, which is leaving and belongs to the relay.
  • It may not delete a node that would take a relay-owned key with it: profile, net, streams, streams.<kind>, pose, and so on.

Not done

  • state::reset(false) drops children without signalling, so it still replicates nothing (only tests call it).
  • A subtree deleted and made again while a client was away keeps whatever the client still holds below it from the old one. The relay cannot tell what that is.
  • Clients do not prune their own tree against a full snapshot. A client cannot tell its own paths from the relay's, and the relay-driven repeats above cover the same reconnect case.
  • The conference still leaves softly (presence.joined=0). Switching it to real deletes is a separate change.

Tests

  • state_sync_adapter_test:
    • a removal is journaled once and not under suppression;
    • the two-tree mirror probe from 2026-11-22;
    • tombstone burial rules (ties, above, beside, untimed);
    • the cap and ttl.
  • state_transport_inproc_test:
    • a removal reaches peers and is not echoed;
    • a delete above a subscription is delivered;
    • a write older than a delete is buried and a later one applies.
  • state_transport_ws_test:
    • a relay delete reaches its clients live;
    • the broadcast takes a subtree that left the tree (one delete, out-of-view paths kept);
    • an admit without backfill repeats a missed delete and keeps a subtree that came back.
  • state_transport_grpc_test: live delete, and the admit repeat.
  • room_intrinsics_test: the gate's delete rules.

A node removed from a replicated tree stayed on every peer:
- state_sync_adapter journaled values, data and metadata, but not removals;
- a WS relay's broadcast diff forgot paths that left its tree without telling the client;
- a joiner's snapshot only says what is there.
So a world's departed vehicles and spawn points, the entries a server document's
(state-set-tree) drops, and DSL list rows stayed on clients.

Removals are journaled (state_sync_adapter):
- A removal goes out as one delete_subtree at the removed node. Its childChanged fires on every
  observed ancestor; the first slot drops the subtree's observers, and only that slot journals.
- The delete is timed by the shard's clock (set_clock). A remote delete is applied, not echoed.

Tombstones and burial (state_sync_adapter, state_cluster_shard):
- Each timed delete applied leaves a tombstone: its path and time, for 10 min, at most 4096.
- ingest_remote buries a remote write at or below a tombstone whose time is no later than the
  delete's: its writer made it before it saw the delete. It is recorded as seen, not applied,
  and reported as ingest_result::buried. Relays do not forward it.

Delivery and repair:
- state_peer_registry::should_deliver(node, path, subtree) delivers a delete above a peer's
  subscription. The WS, gRPC, inproc and IPC fan-outs and backfills use it.
- A WS relay's broadcast_snapshot sends a delete (state_transport::tree_removal: origin
  <shard>#sync, untimed) for each subtree a client was sent that has left the tree.
- A relay that does not backfill (arisrv's S7 default) repeats its tombstones after a joiner's
  admit snapshot, skipping subtrees that came back (state_transport::missed_deletes).

room_write_gate lets a participant delete inside its own subtree. It may not delete the
participant node itself, nor a node that would take a relay-owned key with it.

Docs: ARIADNE.md's state-set-tree and fleet notes; DISTRIBUTED_STATE_ROADMAP.md's known gaps.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 03:35
@transfix
transfix merged commit 5949edc into master Nov 23, 2026
31 checks passed
@transfix
transfix deleted the feat/state-delete-replication branch November 23, 2026 14:49
transfix added a commit that referenced this pull request Nov 23, 2026
… into p9/volume-grid-segment

INDEX.ari keeps both new entries (volume_grid_segmentation, http_cache).
volume_grid_contours.png conflicted (#1450 re-rendered it for rows that
flow); kept ours until CI renders the merged panel.
transfix added a commit that referenced this pull request Nov 24, 2026
…grace

A participant who left stayed in the room tree for good. The relay only marked it left
(presence.joined=0), since a delete did not replicate before #1473. So every
client held, and every join snapshot carried, a ghost of everyone who had ever joined.

The relay (arisrv) now removes them:
- When a connection ends, the participant is marked left at once, as before: the roster, the
  holon and the area of interest drop it.
- Once it has been away --leave-grace-s (default 300) without coming back, room_departures
  removes its subtree (room_remove): one delete, which every client applies.
- One back in time, joined again or holding a connection, is kept. A client that reconnects
  (it keeps its pid) finds what it published, its streams, avatar and device, still there.
- --leave-grace-s 0 removes it as its connection ends.

A bridged user leaves with a delete at once (room_bridge_absent). The relay is their only writer,
and one who comes back is written anew.

room_leave still only marks a participant left: a client's (room-leave) and a document's
teardown do that, and the relay removes it once its connection has gone.

Docs: the conference roadmap's switch table, reaping note and room-leave row;
DISTRIBUTED_STATE_ROADMAP.md's known gaps.
transfix added a commit that referenced this pull request Nov 24, 2026
…in, silent links, scene removals (#1483)

A participant who left stayed in the room tree for good: the relay only marked it left
(presence.joined=0), since a delete did not replicate before #1473. So every client
held, and every join snapshot carried, a ghost of everyone who had ever joined.

The relay (arisrv) now removes departed participants:
- When a connection ends, the participant is marked left at once, as before: the roster, the
  holon and the area of interest drop it.
- Once it has been away the grace without joining again, room_departures removes its subtree
  (room_remove): one delete, which every client applies. One whose connection is back has the
  whole grace from then to join; one marked left that keeps its connection (a document's
  (room-leave)) is removed after the grace too.
- The grace is per room: the server document's server: leave_grace_s:, which --leave-grace-s
  overrides; 300 when neither says; 0 removes it as its connection ends.

Back after the grace: room_own_state keeps what a participant published under its node (not the
relay's keys, its presence, intent, net readings or drive request), and room_reassert writes it
again. arigl takes it before it redials and writes it while it rejoins; a document's (room-join)
does it after its own (room-leave). The relay forgets the streams it relayed for a removed
participant, so one published again is relayed and marked ready afresh.

Silent connections: state_transport::reap_idle, now on the gRPC transport too. arisrv reaps both
transports each second after --idle-timeout-s (default 10; 0 = never), and arigl and
relay_session close a silent link to the relay, so they dial again.

A bridged user leaves with a delete at once (room_bridge_absent). Scene objects, lights and avatar
options the relay drops are removed (a delete each), not marked present = 0.

Docs: ARIADNE.md's server: block, the conference roadmap's switches and reaping note, and
DISTRIBUTED_STATE_ROADMAP.md's known gaps.
transfix added a commit that referenced this pull request Nov 24, 2026
… = 0 (#1525)

write_room_entities marked an entity the world no longer has present = 0, so the room tree, and
every client's copy and join snapshot, kept a subtree for every entity that ever ran. Deletes
replicate since #1473, and the room's scene objects, lights and avatar options are
removed that way since #1483; entities now are too.

- section_writer::remove takes an entry (a leaf or a subtree) out of a revisioned section: one
  delete, which every peer applies, and whose tombstone keeps a peer that still holds the entry
  from bringing it back. Never the section itself.
- write_room_entities removes each entity the section has that the world does not, before the
  commit that bumps the revision, so a reader that sees the new revision no longer finds it.
  Readers still take only entries with present = 1, which a write sets last.

Docs: room_entities.h, the conference roadmap's reaping note, ARIADNE_WORLDS.md's scene wire
format and old-relay note.
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