Skip to content

Implement conflict resolution UI for concurrent edits #642

Closed

Description

@malibio

Summary

When concurrent edits occur in multiple panes, the system applies Last-Write-Wins silently without notifying the user that their edit was overwritten.

Background

Identified in the multi-tab reactivity investigation (Issue #631).

Current Behavior

Pane A: Edit node:content → version 5
Pane B: Edit node:properties → version 5
Result: One wins (depends on timing)
User in losing pane: No indication their edit was rejected

The user has no visual feedback that their changes were discarded.

Acceptance Criteria

  • Detect when a conflict occurs (edit rejected due to version mismatch)
  • Provide visual feedback to the user in the affected pane
  • Choose appropriate notification method (see options below)
  • Add tests for conflict detection and user notification

Solution Options (Choose One)

  1. Show notification - Brief toast: "Your edit was overwritten by another pane"
  2. Highlight conflict field - Visual indicator in pane that lost conflict
  3. Merge strategy - Content and properties updated independently (not either-or)
  4. User choice - Show dialog when conflict detected, let user choose

Technical Notes

Priority

MEDIUM - User experience concern but not data loss (changes still applied somewhere)

Related

Activity

  1. added
    enhancement
    on Nov 23, 2025
  2. malibio commented on May 29, 2026

    @malibio
    CollaboratorAuthor

    Absorbed #303 (advanced conflict resolution UI) — this is now the single conflict-resolution issue.

    Architectural dependency (audit #1228, finding C5): conflict resolution is currently frontend Last-Write-Wins (shared-node-store.svelte.ts, hardcoded 5s detection window, silently discards local edits). The audit recommends moving adjudication into the daemon — return version + conflict marker in the RPC error — so this UI work should consume an authoritative daemon signal rather than extend the frontend LWW. Sequence the daemon-side change first.

  3. malibio commented on May 29, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 129 files, 3913 tests passed

  4. self-assigned this
    on May 29, 2026
  5. malibio commented on May 29, 2026

    @malibio
    CollaboratorAuthor

    Code Review — Issue #642: Conflict Resolution UI (commit 8efb9d0)

    Reviewed by: Principal Engineer
    Verdict: Approve with minor notes — this is a clean, net-positive implementation. All four acceptance criteria are satisfied, tests pass (3923/3923), and the code follows project conventions.


    Overall Assessment

    The implementation correctly threads the conflict signal from SharedNodeStore.handleConflict() through a rune-based singleton store to a fixed-position toast component rendered in app-shell. The architecture is intentionally minimal for this feature's scope, the separation of concerns is sound, and cleanup paths are handled correctly.


    Findings

    Suggested Improvements

    1. conflict-notifications.svelte.ts — Unbounded notification accumulation

    ConflictNotificationStore.add() imposes no upper bound on notifications. In a pathological scenario (e.g. rapid sync with many conflicting nodes), the array grows indefinitely until the component auto-dismisses entries after 4 seconds. For a singleton living for the application lifetime, consider capping at a reasonable maximum (e.g. 10), dropping the oldest when the cap is reached. This is not a memory leak in the traditional sense, but it avoids a visible pile-up of toasts on the screen before auto-dismiss fires.

    // Suggested guard in add():
    if (this.notifications.length >= 10) {
      this.notifications = this.notifications.slice(1); // drop oldest
    }

    2. conflict-toast.svelte — $effect does not clean up orphaned timer entries

    The $effect calls scheduleAutoDismiss for every notification on every reactive re-run (guarded by timers.has(id)). However, if a notification is dismissed externally via conflictNotifications.dismiss(id) (not through the local dismiss() wrapper), the corresponding setTimeout handle remains in timers indefinitely — the guard if (timers.has(id)) return will prevent rescheduling but the orphaned handle will still fire and call conflictNotifications.dismiss(id) on an already-removed entry (benign but unnecessary). A cleanup pass in the $effect would make this airtight:

    $effect(() => {
      const activeIds = new Set(conflictNotifications.notifications.map(n => n.id));
      // Cancel timers for notifications that were removed externally
      for (const [id, t] of timers) {
        if (!activeIds.has(id)) {
          clearTimeout(t);
          timers.delete(id);
        }
      }
      for (const n of conflictNotifications.notifications) {
        scheduleAutoDismiss(n.id);
      }
    });

    3. shared-node-store.svelte.ts:2318 — Hardcoded message ignores conflict type

    Both concurrent-edit and version-mismatch conflicts emit the same message: "Your edit was overwritten by another pane". The version-mismatch path is triggered by external sync (remote backend divergence), which is a subtly different user scenario from a local multi-pane conflict. This is acceptable for the current scope (issue #580 notes LWW is temporary), but a small messageForType() helper would make future differentiation easier and is low effort now:

    const MESSAGE: Record<ConflictNotification['conflictType'], string> = {
      'concurrent-edit':   'Your edit was overwritten by another pane',
      'version-mismatch':  'Your edit conflicted with a remote change',
      'deleted-node':      'The node you edited was deleted by another pane',
    };

    4. conflict-notifications.svelte.ts:17 — ID generation uses Date.now() twice per entry

    id is built with Date.now() and entry is built with a second Date.now() call. These are virtually always the same millisecond, but using the same timestamp for both is more correct and avoids the (theoretical) edge case of a clock tick between the two calls:

    const now = Date.now();
    const id = `conflict-${now}-${Math.random().toString(36).slice(2, 7)}`;
    const entry: ConflictNotification = { ...notification, id, createdAt: now };

    Nitpicks

    Nit: conflict-toast.svelte:47 — ⚠ vs ⚠️

    The HTML entity ⚠ renders the bare Unicode warning sign without the emoji variation selector. On some platforms/fonts this looks like a thin symbol rather than the warning emoji. Using the literal ⚠️ (or ⚠️) gives the colored emoji appearance consistently, or use an SVG icon from the design system if one exists.

    Nit: conflict-notification-integration.test.ts:131-133 — Conditional assertion weakens the test

    if (conflictNotifications.notifications.length > 0) {
      expect(metricsAfter.conflictCount).toBeGreaterThan(metricsBefore.conflictCount);
    }

    If the conflict is not detected (e.g. conflict window logic changes), this test silently passes with zero assertions. Replace with an unconditional expect(conflictNotifications.notifications.length).toBeGreaterThanOrEqual(1) first, then assert the metric. This makes the test fail loudly on regression rather than going green with no coverage.

    Nit: conflict-toast.svelte — No prefers-reduced-motion guard

    The toast-in animation runs unconditionally. Users who have enabled the OS reduced-motion preference will still see the slide animation. Adding @media (prefers-reduced-motion: reduce) { .conflict-toast { animation: none; } } is a one-liner accessibility improvement.


    Requirements Validation

    Acceptance Criterion Status
    Detect when a conflict occurs (edit rejected due to version mismatch) Satisfied — detectConflict covers both version-mismatch and concurrent-edit
    Provide visual feedback to the user in the affected pane Satisfied — fixed-position toast with warning border
    Choose appropriate notification method Satisfied — Option 1 (brief toast) chosen, well-suited for a non-blocking transient event
    Add tests for conflict detection and user notification Satisfied — 6 store unit tests + 4 integration tests, all passing

    Summary

    Ship it. The four improvements above are all low-risk follow-ups; none are blockers. The conditional assertion in the metrics test (Nit #2) is the highest-priority fix among the nits as it could mask a future regression silently. The notification cap (Improvement #1) is the most practically impactful addition for production use.

  6. added a commit that references this issue on May 29, 2026
    efd80b2
  7. added a commit that references this issue on May 29, 2026
    73c0c40
  8. added a commit that references this issue on Jun 22, 2026
    5e90b2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions