Skip to content

Make entity merges derive from the latest Zustand state #1158

Closed

Description

@d-oit

Problem

The current mergeEntities flow derives merged state from a snapshot captured before the Zustand setter executes. If state changes between snapshot capture and commit, the merge can operate on stale data and overwrite or omit concurrent changes.

Scope

  • Move all state-dependent merge calculation into the functional Zustand setter (or an equivalent serialized transaction that reads the latest state).
  • Keep merge behavior deterministic for entity fields, aliases, claims, links, tags and revision history.
  • Preserve referential integrity and existing deletion/merge rules.
  • Ensure the merge operation remains atomic from the UI/store perspective.
  • Audit callbacks that close over stale entity arrays in adjacent merge code.

Acceptance criteria

  • Merge calculation uses the latest state at commit time.
  • A regression test simulates an intervening state update and proves it is retained.
  • No claims, links, aliases or unrelated entity changes are silently lost.
  • Undo/redo and cross-tab merge behavior remain correct.
  • Export/import round-trip tests preserve the merged corpus.
  • Existing merge semantics are documented and unchanged except for the stale-state fix.

Related

Plan 214 code-review follow-up. Use the persistence-data-safety skill and real-corpus verification if the change affects canonical persistence.

Activity

  1. d-oit commented on Nov 19, 2026

    @d-oit
    OwnerAuthor

    Implemented in #1178 (90246d1).

    • mergeEntities derives from the latest store state at set() time (functional set + outcome container) so an intervening edit to the survivor is not clobbered (src/lib/studio/merge-entities).
    • Regression test merge-entities.test.ts ('does not overwrite an intervening edit'); comment states exactly what the test pins.
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions