Skip to content

state_sync cannot converge entities that changed while a peer was fully disconnected #27

Description

@Mearman

The state_sync receive path in handleDataMessage (src/core/mesh-store.ts) merges add-only: if (!this.agents.has(id)) (same shape for rooms, messages, dms). Since the dial-window broadcast fix (#25), patches are reliable while peers are connected, so this gap only bites when a peer is disconnected outright while an entity changes — a rename, status change, or room edit. The returning peer keeps its stale copy until some later patch about that entity happens to arrive, and any peer that syncs from it inherits the stale copy.

Reproducer shape: three TLS peers; C shuts down; A renames its agent and edits a room; C returns and reconnects. C still sees the old name and old room state, with no further patch coming to correct it.

Fix direction settled during the #23 investigation: per-entity monotonic versions. Every mutating store bumps the entity's version and embeds it in the entity record carried by patches and SerialisedState; state_sync and patch application take the higher version (ties keep the existing union semantics for room members and subscribedRooms, which also keeps concurrent joins race-safe). Owner-authority merging was considered and rejected: a rejoining peer can carry an old copy of a third peer's entity and would clobber it.

Also heals room-leave divergence, which the current member-union cannot (union only ever adds).

Found while verifying the persistent-identity work (#24) and the broadcast queue (#25).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions