Skip to content

Replace _possible_duplicate with a generic conflict journal and resolution surface (ADR-066) #2377

Closed

Description

@malibio

Implements ADR-066: Convergence Conflicts Are Local-Only Records in a Generic Conflict Journal, Not Per-Node Boolean Flags (nodespace-docs/decisions/066-convergence-conflicts-are-records-not-flags.md), specified in nodespace-docs/components/conflict-journal-and-resolution.md.

Supersedes item 1 of #2374 (the design question, now answered). Items 2-4 of #2374 are unrelated contained bugs and stay there.


Why

_possible_duplicate is a boolean property on person that:

  • Can never become true on a local-only install. NodeService::mark_possible_duplicates has zero production callers; the only live writer is mark_collection_name_collision, which handles a different constraint. The person path depends on nodespace-sync.
  • Cannot name the counterparty. The badge re-derives it at render time with a second, independent findDuplicateFor lookup that can disagree with whatever set the flag.
  • Cannot be cleared. Per the badge's own header comment, dismissing "only closes this popover; the underlying marker is not cleared", so it reappears indefinitely.
  • Leaks into the data model. Being a SchemaField, it is an empty, uninterpretable column in the person table view. protection: System and local_only control who writes and whether it syncs — neither means "hide from views".
  • Does not generalize. Every future conflicting type would have to declare its own copy of the field. A schema-only extension type gets detection with nowhere to store the result. Collection-name collisions were bolted onto the same boolean because it was the only slot available.

ADR-066 replaces it with a local-only conflict table holding records that carry participants, evidence, and a resolution lifecycle. ADR-065's suggest-don't-block holding is unchanged — a colliding write is still never rejected, and sync apply still never errors, skips or rolls back on a collision. Only the representation of the indicator changes, plus merge is no longer deferred.

Recovered Items already implements the correct shape (a durable record with counterparty data and persistent dismissal) for a neighbouring conflict class, in a per-user JSONL file. It folds into this journal.


S1 — Journal, detection, and deletion of the flag (headless core)

  • Add the local-only conflict table (id, kind, node_ids, detail, status, detected_at, detected_by, occurrences, last_seen_at, resolved_at, resolution) plus a conflict_participant(conflict_id, node_id) companion table so the per-node lookup is an index hit rather than a JSON scan. No FK to node — see spec §2.1.
  • ConflictKind = UniqueFieldCollision | CollectionNameCollision | SupersededEdit | DuplicateReactiveCreate (last one reserved, no detection yet). ConflictStatus = open | resolved | dismissed.
  • Deterministic ids: uuidv5(ns, "{kind}|{sorted_node_ids}|{discriminator}"), discriminator per spec §2.3. Sorting participants makes the id symmetric so arrival order cannot produce two records.
  • record_conflict is upsert-by-derived-id: insert, or bump occurrences/last_seen_at. Never reopens a resolved/dismissed record — this is dismiss-persistence.
  • list_conflicts, conflicts_for_node, resolve_conflict on NodeService (spec §3).
  • Rewrite NodeService::mark_possible_duplicates as unique-field detection that journals, and wire it to a real caller in create/update. This is the defect that made the whole mechanism unreachable locally.
  • Rewrite SqliteStore::mark_collection_name_collision to journal CollectionNameCollision — its own kind, ending the conflation with duplicate-person under one boolean.
  • Scope find_conflicting_unique to lifecycle_status = 'active' (get_collection_by_name already does). Required for §5.3 self-resolution after a merge.
  • Detection stays post-commit, best-effort, error-swallowing at every site. A journal-write failure must never fail or undo the write it follows.
  • Delete POSSIBLE_DUPLICATE_FIELD, the _possible_duplicate SchemaField on person, is_possible_duplicate, possible-duplicate.ts, possible-duplicate-badge.svelte and their tests. Deletion, not deprecation (CLAUDE.md: zero users, no migrations).

Acceptance: two local person nodes with the same email produce exactly one UniqueFieldCollision record naming both — with no nodespace-sync. Re-detection bumps occurrences rather than adding a row. Dismiss then re-detect leaves it dismissed. A schema-only extension type with a unique field gets records with zero schema changes. grep -r _possible_duplicate packages/ returns nothing.

S2 — Conflicts surface; fold in Recovered Items (desktop)

  • Conflicts view: open records grouped by kind, participants as navigable node references, evidence rendered from detail (never re-derived by a second lookup), occurrences where > 1, resolved/dismissed behind a filter.
  • Non-destructive actions per spec §5.1: dismiss (persisted), adopt existing, rename (collection-name only), restore (superseded edits).
  • Fold Recovered Items in as SupersededEdit: delete commands/recovered_items.rs, recovered-items.svelte.ts, recovered-items-badge.svelte; the Pro daemon's record_recovered_item writes a journal record instead of a JSONL line. Same data, one surface, one dismiss mechanism.
  • One store on the canonical rune pattern (ADR-049) with records, hasOpenFor(nodeId), and the actions.
  • Inline indicator, if kept, is a derived read of the journal, not a stored property, and links into the Conflicts view rather than resolving in a popover.
  • Leave conflict-notifications.svelte.ts alone — transient OCC version-mismatch feedback is an interaction failure, not a durable conflict.

S3 — Merge (highest risk; land last)

merge_nodes(survivor, loser, conflict_id?), one transaction, spec §5.2:

  • Property union onto survivor; survivor wins ties and every overwritten loser value is snapshotted into resolution.superseded. Merge never silently discards user data.
  • Re-point every relationship row from loser to survivor. has_child properties.order travels with the re-point. A re-point that would violate the (in_node, out_node, relationship_type) unique constraint is dropped and counted, not an error. Self-edges dropped.
  • Tombstone the loser (lifecycle_status = 'deleted'). Not delete_subtree_atomic — it cascades over has_child descendants (ADR-041) that step 2 just re-pointed to the survivor.
  • Close the record as resolved with the merge resolution.
  • User-initiated only. No auto-merge at any confidence: email is a claim, not an identity key (ADR-065 §5), and a typo would destroy a distinct person's record and re-point their edges.

S4 — Reconciliation sweep

  • Close open records whose participants are gone or no longer collide; backstop for the accepted TOCTOU gap in pre-write-check/post-write-mark detection.

Out of scope

  • DuplicateReactiveCreate detection — lands with the playbook work (ADR-060).
  • Rejecting colliding writes. ADR-065 settled it; local-first forbids it and a rejection at sync apply is a stuck cursor.
  • Syncing the journal (ADR-066 §2).
  • A schema mechanism for hiding fields from table views — orthogonal, and does not resurrect the flag.

Requires verification in nodespace-sync

Not available in this checkout; asserted from nodespace-core doc comments (ADR-066, "Assumptions Requiring Verification"):

  • mark_possible_duplicate in the pulled-write apply path is the sole person.email marker writer — replace with a journal write.
  • The apply hook can reach NodeService, and its detection runs post-commit.
  • record_recovered_item in nodespaced-pro can write to the local DB rather than JSONL. If it cannot cross that boundary, keep the file as daemon-side transport and fold in on read.

Activity

  1. malibio commented on Sep 9, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 239 test files passed, 4929 tests passed (87.73s).

  2. self-assigned this
    on Sep 9, 2026
  3. malibio commented on Sep 9, 2026

    @malibio
    CollaboratorAuthor

    Closing to match board status (Done).

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions