Repository navigation
C5: Replace the client-side 5s conflict heuristic with the daemon's authoritative OCC version conflict (amends ADR-026) - #1273
Conversation
Code Review — C5: Daemon-Authoritative OCC Conflict Adjudication (#1268)Overall assessment: This is a well-executed, high-value change that closes a meaningful data-loss gap. The core pipeline — daemon embeds Findings[Improvement] Task-node OCC conflict path silently loses
|
| Criterion | Status |
|---|---|
Daemon no longer drops current_node; header carries full payload |
PASS |
Tauri command preserves structured payload; old MCP -32005 machinery deleted |
PASS |
| Frontend guard matches real gRPC shape | PASS |
Rollback + hydrate from current_node + notification on conflict |
PASS (regular nodes); fallback resync for task nodes |
conflictWindowMs/setConflictWindow/'concurrent-edit' removed |
PASS |
skipConflictDetection auto-sets and nodeType special-case removed |
PASS |
| LWW remains policy; losing edit surfaced via #1231 UI | PASS |
| ADR-026 amendment | MISSING — required before/after merge |
Verdict: Approve with required follow-up. The code change is correct and safe to merge. File the ADR-026 amendment PR before closing the issue, and track the task-node current_node hydration as a follow-up issue.
…C test - `packages/core/src/ops/mod.rs`: add comment to the `current_node: None` in `From<NodeServiceError> for OpsError` explaining why it's None for the task-node path and pointing to the follow-up issue - `packages/daemon/src/services/node_service.rs`: extend `error_mapping_version_conflict_returns_aborted` to also assert `json["current_node"] == null`, documenting the expected shape for the task-node / direct-service-call path and guarding against future regressions Addresses review recommendations from PR #1273. Co-Authored-By: Claude <[email protected]>
Review Recommendations — Addressed✅ Addressed🟡 Nitpick: 🟢 Nitpick: Assert 🟡 ADR-026 amendment (required AC)
🟡 Task-node ⏭️ Skipped🟢 Integration tests: real wall-clock → fake timers Commits added: |
Follow-up: #1274 resolved inlineThe task-node
The frontend task-node OCC site already handles Commit: |
…tive OCC version conflict (closes #1268) **Daemon (`packages/daemon/src/services/node_service.rs`)** - `ops_error_to_status`: stop dropping `current_node` from `OpsError::VersionConflict`; encode `{node_id, expected, actual, current_node}` as JSON in the `x-version-conflict` metadata header on the `Aborted` gRPC Status so clients can hydrate without a second round-trip - Strengthen `error_mapping_version_conflict_returns_aborted` to assert the header is present and carries the correct payload (previously only checked the code) **Tauri command (`packages/desktop-app/src-tauri/src/commands/nodes.rs`)** - `CommandError`: add `conflict_data: Option<serde_json::Value>` field (serialised as `conflictData`) - `status_to_command_error`: extract the `x-version-conflict` header when the gRPC code is `Aborted` and populate `conflict_data`; all other `CommandError` literals updated with `conflict_data: None` **Frontend types (`packages/desktop-app/src/lib/types/errors.ts`)** - Delete MCP `-32005`/`MCPError`/`VersionConflictData`/`isVersionConflict` machinery (obsolete since the in-process MCP layer was removed) - Add `VersionConflictData` (gRPC shape: `{node_id, expected, actual, current_node}`) and `VersionConflictCommandError` (`code: 'VERSION_CONFLICT'` + `conflictData`) - Rewrite `isVersionConflict` to match the real `CommandError` shape from the daemon **Frontend store (`packages/desktop-app/src/lib/services/shared-node-store.svelte.ts`)** - Both OCC catch sites (regular node + task node) now check `isVersionConflict(dbError)` against the new gRPC guard; on match: rollback, hydrate from `conflictData.current_node` (or fallback resync), add `conflictNotifications` entry with `'version-mismatch'` - Delete `conflictWindowMs` field and `setConflictWindow()` method - Delete time-window heuristic branch (`'concurrent-edit'`) and `nodeType` special-case from `detectConflict`; only the authoritative version-mismatch branch remains - Remove `skipConflictDetection: true` auto-set in `isComputedField` path (no longer needed without the heuristic generating false positives) - Remove explicit `skipConflictDetection: false` no-op at external-update site - Remove `'concurrent-edit'` from `CONFLICT_MESSAGE` map **Types (`packages/desktop-app/src/lib/types/update-protocol.ts`, `packages/desktop-app/src/lib/stores/conflict-notifications.svelte.ts`)** - Remove `'concurrent-edit'` from `Conflict.conflictType` and `ConflictNotification.conflictType` unions; `'version-mismatch'` and `'deleted-node'` remain **Tests** - `errors.test.ts`: rewritten for gRPC guard; old MCP tests replaced with `isVersionConflict` tests covering the new `{ code: 'VERSION_CONFLICT', conflictData }` shape - `conflict-notification-integration.test.ts`: replaced time-window heuristic tests with OCC integration tests that mock `backendAdapter.updateNode` to reject with `VERSION_CONFLICT`; assert rollback, hydration from `current_node`, notification emission, and rollback metric increment - `conflict-notifications.test.ts`: `'concurrent-edit'` → `'version-mismatch'` throughout - `shared-node-store.test.ts` / `shared-node-store-extended.test.ts`: remove `setConflictWindow` calls, replace heuristic-dependent tests with plain LWW / no-false-positive assertions Co-Authored-By: Claude <[email protected]>
…C test - `packages/core/src/ops/mod.rs`: add comment to the `current_node: None` in `From<NodeServiceError> for OpsError` explaining why it's None for the task-node path and pointing to the follow-up issue - `packages/daemon/src/services/node_service.rs`: extend `error_mapping_version_conflict_returns_aborted` to also assert `json["current_node"] == null`, documenting the expected shape for the task-node / direct-service-call path and guarding against future regressions Addresses review recommendations from PR #1273. Co-Authored-By: Claude <[email protected]>
Before this commit the `update_task_node` RPC handler used a single
`.map_err(service_error_to_status)?` call, which converted
`NodeServiceError::VersionConflict` via `From<NodeServiceError> for OpsError`
with `current_node: None`. The client always had to make a second round-trip
via `resyncNodeFromServer` to recover the authoritative state.
After this commit, the handler intercepts `VersionConflict`, calls
`self.node_service.get_node()` to fetch the current authoritative node, and
constructs an `OpsError::VersionConflict { current_node: Some(...) }` before
calling `ops_error_to_status` — mirroring the pattern used by
`node_ops::update_node` for regular-node conflicts since C5.
The existing `error_mapping_version_conflict_returns_aborted` test now has an
updated comment clarifying it tests the generic `From<NodeServiceError>` path
(where `current_node` is still null), not the task-node handler path.
New async integration test `update_task_node_version_conflict_embeds_current_node`:
- Creates a task node at version 1
- Simulates a concurrent remote write via the core service (version 1 → 2)
- Attempts `UpdateTaskNode` with stale version 1 via the RPC handler
- Asserts Aborted status, `x-version-conflict` header present, and
`current_node.content` reflects the remote winner
Frontend: the task-node OCC site in `shared-node-store.svelte.ts` already
checks `occError.conflictData.current_node` and hydrates directly when non-null
(implemented in C5) — no frontend changes needed.
Co-Authored-By: Claude <[email protected]>
61711df to
7b344af
Compare
…uthoritative OCC version conflict (amends ADR-026) (#1273) * C5: Replace client-side 5s conflict heuristic with daemon's authoritative OCC version conflict (closes #1268) **Daemon (`packages/daemon/src/services/node_service.rs`)** - `ops_error_to_status`: stop dropping `current_node` from `OpsError::VersionConflict`; encode `{node_id, expected, actual, current_node}` as JSON in the `x-version-conflict` metadata header on the `Aborted` gRPC Status so clients can hydrate without a second round-trip - Strengthen `error_mapping_version_conflict_returns_aborted` to assert the header is present and carries the correct payload (previously only checked the code) **Tauri command (`packages/desktop-app/src-tauri/src/commands/nodes.rs`)** - `CommandError`: add `conflict_data: Option<serde_json::Value>` field (serialised as `conflictData`) - `status_to_command_error`: extract the `x-version-conflict` header when the gRPC code is `Aborted` and populate `conflict_data`; all other `CommandError` literals updated with `conflict_data: None` **Frontend types (`packages/desktop-app/src/lib/types/errors.ts`)** - Delete MCP `-32005`/`MCPError`/`VersionConflictData`/`isVersionConflict` machinery (obsolete since the in-process MCP layer was removed) - Add `VersionConflictData` (gRPC shape: `{node_id, expected, actual, current_node}`) and `VersionConflictCommandError` (`code: 'VERSION_CONFLICT'` + `conflictData`) - Rewrite `isVersionConflict` to match the real `CommandError` shape from the daemon **Frontend store (`packages/desktop-app/src/lib/services/shared-node-store.svelte.ts`)** - Both OCC catch sites (regular node + task node) now check `isVersionConflict(dbError)` against the new gRPC guard; on match: rollback, hydrate from `conflictData.current_node` (or fallback resync), add `conflictNotifications` entry with `'version-mismatch'` - Delete `conflictWindowMs` field and `setConflictWindow()` method - Delete time-window heuristic branch (`'concurrent-edit'`) and `nodeType` special-case from `detectConflict`; only the authoritative version-mismatch branch remains - Remove `skipConflictDetection: true` auto-set in `isComputedField` path (no longer needed without the heuristic generating false positives) - Remove explicit `skipConflictDetection: false` no-op at external-update site - Remove `'concurrent-edit'` from `CONFLICT_MESSAGE` map **Types (`packages/desktop-app/src/lib/types/update-protocol.ts`, `packages/desktop-app/src/lib/stores/conflict-notifications.svelte.ts`)** - Remove `'concurrent-edit'` from `Conflict.conflictType` and `ConflictNotification.conflictType` unions; `'version-mismatch'` and `'deleted-node'` remain **Tests** - `errors.test.ts`: rewritten for gRPC guard; old MCP tests replaced with `isVersionConflict` tests covering the new `{ code: 'VERSION_CONFLICT', conflictData }` shape - `conflict-notification-integration.test.ts`: replaced time-window heuristic tests with OCC integration tests that mock `backendAdapter.updateNode` to reject with `VERSION_CONFLICT`; assert rollback, hydration from `current_node`, notification emission, and rollback metric increment - `conflict-notifications.test.ts`: `'concurrent-edit'` → `'version-mismatch'` throughout - `shared-node-store.test.ts` / `shared-node-store-extended.test.ts`: remove `setConflictWindow` calls, replace heuristic-dependent tests with plain LWW / no-false-positive assertions Co-Authored-By: Claude <[email protected]> * Address review: document task-node current_node gap and strengthen OCC test - `packages/core/src/ops/mod.rs`: add comment to the `current_node: None` in `From<NodeServiceError> for OpsError` explaining why it's None for the task-node path and pointing to the follow-up issue - `packages/daemon/src/services/node_service.rs`: extend `error_mapping_version_conflict_returns_aborted` to also assert `json["current_node"] == null`, documenting the expected shape for the task-node / direct-service-call path and guarding against future regressions Addresses review recommendations from PR #1273. Co-Authored-By: Claude <[email protected]> * Hydrate task-node OCC conflicts from current_node (closes #1274) Before this commit the `update_task_node` RPC handler used a single `.map_err(service_error_to_status)?` call, which converted `NodeServiceError::VersionConflict` via `From<NodeServiceError> for OpsError` with `current_node: None`. The client always had to make a second round-trip via `resyncNodeFromServer` to recover the authoritative state. After this commit, the handler intercepts `VersionConflict`, calls `self.node_service.get_node()` to fetch the current authoritative node, and constructs an `OpsError::VersionConflict { current_node: Some(...) }` before calling `ops_error_to_status` — mirroring the pattern used by `node_ops::update_node` for regular-node conflicts since C5. The existing `error_mapping_version_conflict_returns_aborted` test now has an updated comment clarifying it tests the generic `From<NodeServiceError>` path (where `current_node` is still null), not the task-node handler path. New async integration test `update_task_node_version_conflict_embeds_current_node`: - Creates a task node at version 1 - Simulates a concurrent remote write via the core service (version 1 → 2) - Attempts `UpdateTaskNode` with stale version 1 via the RPC handler - Asserts Aborted status, `x-version-conflict` header present, and `current_node.content` reflects the remote winner Frontend: the task-node OCC site in `shared-node-store.svelte.ts` already checks `occError.conflictData.current_node` and hydrates directly when non-null (implemented in C5) — no frontend changes needed. Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Closes #1268