Repository navigation
Closed
Labels
Description
Overview
Implement sync infrastructure for SurrealDB Cloud integration, enabling multi-device access with local-first performance. This includes LIVE SELECT subscriptions, conflict detection, and offline operation queuing.
Architecture Reference
See docs/architecture/architecture-target-state.md Section 6: Sync Architecture
See docs/architecture/experiments/surrealdb-cloud-poc-plan.md for PoC details
Architecture
┌──────────────────┐ WebSocket ┌──────────────────┐
│ Desktop App │◄─────────────────────────►│ SurrealDB Cloud │
│ (Local RocksDB) │ LIVE SELECT │ (Coordination) │
└──────────────────┘ └──────────────────┘
│ │
│ Source of Truth │ RLS Enforcement
│ (user's data) │ Rate Limiting
▼ ▼
Full Offline Managed Scaling
Functionality (their problem)
Components
1. SurrealDB Cloud Connection
- WebSocket connection to cloud instance
- JWT authentication with
$authclaims - Automatic reconnection handling
2. LIVE SELECT Subscriptions
Real-time sync via SurrealDB's LIVE SELECT:
LIVE SELECT * FROM node;
LIVE SELECT * FROM edge;3. Conflict Resolution: Conflicted Copies
Using the Dropbox model—don't auto-merge, create copies:
- Detection: OCC via
versionfield - Rejection: If cloud version higher, update fails
- Resolution: Create new node with
(Conflicted Copy YYYY-MM-DD)suffix - User Action: Manual merge, user stays in control
4. Offline Operation Queue
Queue operations when offline, replay when reconnected:
struct OfflineOperation {
id: Uuid,
operation: Operation, // Create, Update, Delete
node_id: String,
payload: Value,
created_at: DateTime<Utc>,
retry_count: u32,
}Acceptance Criteria
Phase 1: Cloud Connection
- SurrealDB Cloud WebSocket connection
- JWT authentication flow
- Connection state management (connected, disconnected, reconnecting)
- Automatic reconnection with exponential backoff
Phase 2: LIVE SELECT Integration
- Subscribe to node changes
- Subscribe to edge changes
- Handle CREATE, UPDATE, DELETE events
- Apply remote changes to local DB
Phase 3: Conflict Detection
- Version field checked on every update
- OCC rejection when version mismatch
- Conflict event emitted for UI handling
Phase 4: Conflict Resolution
- Conflicted copy creation
- Naming convention:
{title} (Conflicted Copy {date}) - UI indicator for conflicted nodes
- Manual merge UI (future, can be separate issue)
Phase 5: Offline Queue
- Queue operations when offline
- Persist queue to survive app restart
- Replay queue on reconnection
- Handle replay failures gracefully
Phase 6: Quality
- Integration tests with mock cloud
- Conflict scenario tests
- Offline/online transition tests
- Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Notes
Authentication Flow
- User logs in via OAuth/email
- App receives JWT with claims:
id,role,type_grants - JWT used for SurrealDB Cloud connection
- RLS evaluated on every query/subscription
Sync Policy Integration
Sync behavior controlled by policies (#784):
- What to pull (lifecycle states, age, node types)
- What to push (immediate vs batched)
- Local eviction strategy
Prerequisites
- SurrealDB Cloud PoC completed (validates LIVE SELECT, ABAC)
- Security layer (Security Layer: ABAC, RLS, and Encryption #789) for authentication
Dependencies
- Security Layer: ABAC, RLS, and Encryption #789 - Security Layer (authentication)
- Sync Policy Infrastructure #784 - Sync Policy Infrastructure
- SurrealDB Cloud PoC (separate repo)
Related Issues
- Add lifecycle_status as Core Node Property with Semantic Search Exclusion #755 - Lifecycle Status (affects sync filtering)
- Policy Evaluation Engine #785 - Policy Evaluation Engine
Activity
docs: Add encryption strategy and expand backup section
malibio commentedon Feb 1, 2026
Race Condition Fix - Phase 1 Complete (PR #861)
We've implemented Phase 1 of the race condition fixes identified by senior architect review:
✅ Phase 1 - Completed
📋 Phase 2 - Operation Queue (Recommended for Phase 2 of Sync)
Problem: Current indent/outdent awaits each moveNode sequentially for OCC correctness. This serializes rapid operations.
Solution:
📋 Phase 3 - Cloud Sync Preparation
For proper multi-device sync:
These align with the existing acceptance criteria in this issue (Phases 2-5).
Fix: moveNode returns updated Node to prevent version conflicts
Fix: Treat insert_after_node_id as best-effort hint to prevent data loss
Fix: moveNode returns updated Node to prevent version conflicts
Fix: Treat insert_after_node_id as best-effort hint to prevent data loss
Perf: Optimize embedded SurrealDB for ~1000x faster node updates (#861)
docs: Add encryption strategy and expand backup section
Perf: Optimize embedded SurrealDB for ~1000x faster node updates (#861)
docs: Add encryption strategy and expand backup section
Perf: Optimize embedded SurrealDB for ~1000x faster node updates (#861)
Perf: Optimize embedded SurrealDB for ~1000x faster node updates (#861)
malibio commentedon May 18, 2026
Implementation of this feature belongs in the nodespace-sync repo (nodespace-pro). Architecture and technical decisions are documented in nodespace-docs: see ADR-025 (cloud sync architecture with Stamped ACL), ADR-017 (sync strategy), and architecture/cloud-sync.md. Closing in nodespace-core.