Repository navigation
Description
Spun off from: architectural-audit tracking issue #1228, finding C5.
Priority: backend + ui (cross-layer). Failure mode is silent data loss — high-priority within those.
Finding (from #1228)
Last-Write-Wins conflict resolution is incomplete.
shared-node-store.svelte.tsalways discards local; hardcoded 5s detection window; nodeType-conversion special-case bypasses detection. Concurrent edits outside the window are silently lost.
Action: move conflict adjudication to the daemon (return version + conflict marker in RPC error); revisit OT/CRDT (already flagged "Phase 7" in code).
ADR grounding (read first)
- ADR-026: Write Flow & Conflict Resolution — OCC + Last-Write-Wins — the existing decision. C5 amends it. §"Conflict Detection: Version-Based OCC" (the OCC contract C5 honors) and §"Conflict Resolution: Last-Write-Wins" (the Recovered-Items / diff-merge flow that was never built and that C5 explicitly defers). ADR-026's "client detects empty SurrealDB result" detection model predates the daemon/gRPC architecture and is obsolete.
- ADR-027: Local-First Sync Service — confirms ADR-026's OCC+LWW mechanics "remain valid and unchanged"; the sync service is another writer through the same daemon OCC, so fixing the local path covers sync-originated conflicts. No
nodespace-syncchanges here. - ADR-031: Daemon-Client Architecture — the daemon owns OCC adjudication (it already does). ADR-026's client-side detection model is obsolete under this.
- Context: ADR-025, ADR-017.
Verified current state (the actual gap)
The daemon already detects version conflicts authoritatively (B6/#1257). The problem is the structured conflict is thrown away at two boundaries before it can drive client behavior, and a weaker client-only heuristic is layered on top.
- Ops layer populates
current_nodecorrectly:packages/core/src/ops/node_ops.rs:272-289— onVersionConflict, re-fetches and embedsOpsError::VersionConflict { node_id, expected, actual, current_node }(ops/mod.rs:29-33). - Daemon discards
current_nodeat the gRPC boundary:packages/daemon/src/services/node_service.rs:1365-1373uses{ node_id, expected, actual, .. }— the..dropscurrent_node; everything collapses to a flatStatus::abortedstring. Testerror_mapping_version_conflict_returns_aborted(:1668) only asserts the code, not the payload. - Tauri command carries no structured data:
packages/desktop-app/src-tauri/src/commands/nodes.rs:108-122→CommandError { code: "VERSION_CONFLICT", message, details: "Aborted" }. Noexpected/actual/current_node. - Frontend OCC branch is DEAD CODE:
shared-node-store.svelte.ts:1237,1858callisVersionConflict(dbError)to trigger rollback +resyncNodeFromServer. ButisVersionConflict(types/errors.ts:124-134) checks for the MCP/JSON-RPC shapecode === -32005+data.type === 'VersionConflict'— the removed in-process MCP layer. The gRPC daemon produces{ code: "VERSION_CONFLICT" }(string), which never matches, so the rollback/resync path never fires; the conflict falls through to the generic catch. - The 5s heuristic can't detect cross-client conflicts at all:
detectConflict(:2301-2353) compares against the client's ownpendingUpdateswithinconflictWindowMs = 5000(:514,:2325-2326).pendingUpdatesonly holds this client's updates → structurally blind to other writers. The window is also a guess: two real edits 6s apart are declared "not a conflict" and LWW silently drops the earlier (the exact Architectural audit (post-daemon + post-SQLite): structural findings & improvement plan #1228 failure mode). - nodeType-conversion + computed-field bypasses (
:2335-2339,:864-869,:2290) exist only to suppress false positives from the broken time-window heuristic. - UI surface already exists (Implement conflict resolution UI for concurrent edits #1231):
conflictNotifications+CONFLICT_MESSAGE(:51-55,stores/conflict-notifications.svelte.ts) with'version-mismatch'. C5 feeds it real conflicts.
Target architecture
Daemon is the single adjudicator (ADR-031); client consumes the verdict, doesn't guess.
- Daemon carries the structured conflict across gRPC — stop flattening
VersionConflictto a string; surfacenode_id/expected/actual/current_node(add a protoVersionConflictmessage — preferred — or encode inStatusdetails). - Tauri command preserves the structured payload in
CommandError, keepingcode: "VERSION_CONFLICT". - Frontend consumes it and surfaces via the Implement conflict resolution UI for concurrent edits #1231 UI — on conflict: rollback optimistic update, hydrate from returned
current_node(fallbackresyncNodeFromServer), pushconflictNotifications('version-mismatch'). LWW stays the policy, but the losing edit is now visible, not silently dropped. - Delete the 5s heuristic —
conflictWindowMs,setConflictWindow, thetimeDiff < conflictWindowMs/'concurrent-edit'branch. - Remove the now-unnecessary bypasses — with detection version-based, pattern conversions / computed-field writes no longer false-positive; delete the
skipConflictDetectionauto-sets andnodeTypespecial-case (keepskipPersistencefor computed fields — separate concern). Verify no caller depends onskipConflictDetectionfor a non-conflict reason first.
OT/CRDT — explicitly DEFERRED
The "Phase 7: OT/CRDT" comment (:22) stays a comment. ADR-026 §"Why OCC + LWW Over CRDTs" already argues node-level (not character-level) editing makes CRDTs over-engineered for v1 — unchanged, no real-time co-editing driver pre-release. Correct target: honest LWW with visible version-conflict surfacing. No OT/CRDT/merge engine. Record the deferral in the ADR amendment.
Exact changes
Daemon (packages/core + packages/daemon): define a structured conflict carrier across gRPC; update the VersionConflict arm in daemon/.../node_service.rs:1365-1373 to stop dropping current_node. Confirm current_node is populated on all conflict paths (node update + task-node update).
Tauri (src-tauri/.../nodes.rs): extend status_to_command_error so Aborted preserves {expected, actual, current_node}; keep code: "VERSION_CONFLICT".
Frontend (packages/desktop-app/src/lib):
types/errors.ts: delete the MCP-32005/VersionConflictData/isVersionConflictmachinery (80-134); replace with a gRPC-shaped guard matchingCommandError { code: "VERSION_CONFLICT", … }carrying the structured fields. Updatetests/types/errors.test.ts.services/shared-node-store.svelte.ts: rewire the two OCC sites (:1237,:1858) to the new guard (rollback + hydrate fromcurrent_node+conflictNotifications.add); deleteconflictWindowMs/setConflictWindow/time-window branch; delete the bypasses (:864-869,:2290,:2335-2339) after confirming no non-conflict caller relies on them.- Verify
conflict-notifications.svelte.ts'version-mismatch'rendering is reached.createLoggernot console.
Acceptance criteria
- Two writers edit the same node concurrently; the second receives
VERSION_CONFLICT, the client rolls back, hydrates from authoritativecurrent_node, and surfaces aconflictNotificationsentry. No edit silently lost. - A concurrent edit outside the old 5s window (6s+ apart) is now correctly detected (version-based, not time-based).
-
conflictWindowMs/setConflictWindow/'concurrent-edit'branch removed; no references remain. -
skipConflictDetectionbypasses +nodeTypespecial-case removed; pattern conversions + computed-field writes still work and persist. - Daemon
VersionConflict→Statusno longer discardscurrent_node; Tauri command preserves the payload; frontend guard matches the real gRPC shape (old MCP-32005machinery deleted). - LWW remains the policy; the losing edit is surfaced via the Implement conflict resolution UI for concurrent edits #1231 UI, not dropped.
- ADR-026 amendment authored in nodespace-docs (
doc/branch): daemon-as-adjudicator, deletion of the unbuilt Recovered-Items/diff-merge flow, OT/CRDT deferred, consistency with ADR-027/031.
Testing
- Rust: daemon integration test —
update_nodewith stale version returnsAbortedAND the payload carriescurrent_node/expected/actual. Strengthenerror_mapping_version_conflict_returns_abortedto assert the payload.cargo test -p nodespace-core -p nodespaced. - Frontend (
bun run test, neverbun test): concurrent-edit test — mock the adapter to rejectupdate_nodewith the newVERSION_CONFLICTshape; assert rollback, hydration fromcurrent_node,conflictNotificationsentry. Regression: two edits >5s apart overlapping on a field now reconcile through the daemon verdict, not silent LWW. Updatetests/types/errors.test.ts. Mock Tauri withvi.mock('@tauri-apps/api/core'). bun run test:allbefore PR.
Risks
- Live-editing write path; failure mode is data loss — the concurrent-edit tests are mandatory gates.
- Hydrating from
current_nodemust not clobber newer local state — hydrate only after rollback of the conflicting optimistic update; re-apply queued non-conflicting edits via the existing resync flow. - Bypass-removal regressions — confirm pattern conversions don't reintroduce false conflicts now that detection is version-based.
- Two-repo: code in nodespace-core; ADR-026 amendment in nodespace-docs (
doc/branch). Cross-link PRs.
Standard NodeSpace startup / PR sequence
git status + git pull origin main, EnterWorktree({name: "issue-<N>-occ-conflict-adjudication"}), bun install, bun run test baseline, gh:comment/gh:assign/gh:status. createLogger not console; bun run test not bun test. Before PR: bun run test:all, bun run quality:fix + commit (revert unrelated reformats), bun run gh:pr <N>, /pragmatic-code-review, then ExitWorktree + gh pr merge --squash --delete-branch. ADR amendment is a separate small PR in nodespace-docs on a doc/ branch.
Spun off from #1228 (architectural audit), finding C5. Amends ADR-026.
Activity
malibio commentedon May 30, 2026
Frontend baseline: 133 test files, 3866 tests passed
C5: Replace client-side 5s conflict heuristic with daemon's authorita…
C5: Replace the client-side 5s conflict heuristic with the daemon's a…
C5: Replace the client-side 5s conflict heuristic with the daemon's a…