Skip to content

SurrealDB Migration - Hybrid Architecture (Desktop-Only) - #467

Merged
malibio merged 2 commits into
mainfrom
feature/issue-461-surrealdb-hybrid-migration
Nov 11, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-461-surrealdb-hybrid-migration

Conversation

@malibio

@malibio malibio commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator

Closes #461

## Planning Documents Added

This commit adds comprehensive architectural planning for Epic #461
(SurrealDB Migration - Hybrid Architecture) Phase 1 implementation.

**Documents Created:**

1. **node-store-abstraction.md** - Complete architecture design
   - NodeStore trait definition (23 methods)
   - TursoStore wrapper implementation strategy
   - 3-step refactoring process (Extract → Wrap → Refactor)
   - Risk assessment and mitigation strategies
   - Testing strategy and success criteria

2. **surrealdb-migration-roadmap.md** - Complete migration roadmap
   - 4-phase implementation plan (6 weeks total)
   - Phase 1 (Current): Abstraction Layer (2 weeks)
   - Phase 2 (Future): SurrealDB Implementation (2 weeks)
   - Phase 3 (Future): A/B Testing Framework (1 week)
   - Phase 4 (Future): Gradual Rollout (1 week)
   - Decision points, rollback plans, success metrics

3. **surrealdb-migration-guide.md** - Step-by-step implementation guide
   - Day-by-day implementation checklist
   - Code examples for each step
   - Testing strategy and validation
   - Common pitfalls and troubleshooting
   - Performance benchmarking guidance

## Scope for Epic #461

**PHASE 1 ONLY** (This Epic):
- Issue #462: NodeStore Trait Abstraction Layer
- Issue #463: TursoStore Wrapper Implementation

**DEFERRED TO FUTURE EPICS:**
- Issue #464: SurrealDB Implementation → Epic #467
- Issue #465: A/B Testing Framework → Epic #468
- Issue #466: Gradual Rollout → Epic #469

## Key Architecture Decisions

**Abstraction Layer Location:**
NodeService (business logic) → NodeStore Trait → TursoStore → DatabaseService

**Why Phase 1 Only:**
- Risk mitigation: Validate abstraction before adding SurrealDB
- Incremental validation: Prove zero regressions first
- Escape hatch: Can revert if issues arise
- Confidence: 95% success rate (proven refactoring pattern)

## Success Criteria

- ✅ Zero new test failures (100% requirement)
- ✅ Performance overhead <5%
- ✅ Complete API coverage (23 trait methods)
- ✅ Comprehensive documentation

## Timeline

**Phase 1**: 2 weeks (14 days)
- Week 1: Trait definition + SQL extraction
- Week 2: TursoStore implementation + NodeService refactoring

## Next Steps

1. Architectural review (this planning PR)
2. Stakeholder approval
3. Begin Phase 1 implementation
4. 1-month stability validation
5. Decision Point: Proceed to Phase 2?

## References

- Epic #460: SurrealDB Feasibility PoC (completed - all GO criteria met)
- Epic #461: SurrealDB Migration - Hybrid Architecture (current)
- Senior Architect Analysis: See issue #461 comments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@malibio

malibio commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator Author

Architectural Review: PR #467 - SurrealDB Migration Planning

Executive Summary

Recommendation: REQUEST CHANGES

High-quality planning documentation with strong architectural foundation, but 3 critical issues require resolution before implementation begins.

Key Strengths:

  • Excellent 3-step incremental refactoring approach
  • Comprehensive risk assessment and mitigation strategies
  • Realistic 2-week timeline with daily breakdown
  • Strong emphasis on test-driven validation and zero regressions

Critical Blockers:

  • Transaction API design is fundamentally broken (non-async closure)
  • CASCADE DELETE semantics completely unspecified
  • Inconsistent method ownership patterns (owned vs borrowed)

Critical Issues (Blockers)

🔴 Issue 1: Transaction API Design Flaw

File: node-store-abstraction.md, lines 246-254

Problem: The transaction method signature cannot be implemented:

async fn transaction<F, T>(&self, f: F) -> Result<T>
where
    F: FnOnce(&dyn NodeStore) -> Result<T> + Send,  // ❌ Non-async closure
    T: Send;

Why this is broken:

  • All NodeStore methods are async, but the closure signature is synchronous
  • You cannot call .await inside a non-async closure
  • The example code at lines 313-319 won't compile

Engineering Principle: API Correctness - Type signatures must match intended usage

Solution:

async fn transaction<'a, F, Fut, T>(&'a self, f: F) -> Result<T>
where
    F: FnOnce(&'a dyn NodeStore) -> Fut + Send,
    Fut: Future<Output = Result<T>> + Send + 'a,
    T: Send;

// Usage:
store.transaction(|store| async move {
    store.create_node(&node1).await?;
    store.create_node(&node2).await?;
    Ok(())
}).await?;

Alternative: Remove transaction method from Phase 1, defer to Phase 2 when you have real usage patterns.


🔴 Issue 2: Missing CASCADE DELETE Specification

File: node-store-abstraction.md, lines 117-121

Problem: delete_node says "implementation must handle cascade deletion" but provides zero specification for:

  • Recursion depth limits (what about 10,000-level hierarchies?)
  • Transaction boundaries (atomic? rollback on child failure?)
  • Orphan handling (mentions pointing to deleted nodes?)
  • Performance characteristics (batch vs recursive deletes?)

Engineering Principle: Explicit Contracts - Critical behavior needs well-defined semantics

Impact: Different implementations will handle cascading differently, causing:

  • Data inconsistency between Turso and SurrealDB
  • Performance cliffs with deep hierarchies
  • Potential deadlocks

Solution: Add detailed specification:

#### Cascade Delete Semantics

**Behavior**: Recursively deletes target node and all descendants.

**Requirements**:
1. **Atomicity**: All deletes in single transaction (all-or-nothing)
2. **Traversal**: Depth-first, leaf-to-root to avoid FK violations
3. **Mention Cleanup**: Delete all mention relationships for deleted nodes
4. **Recursion Limit**: Support up to 1,000 levels (exceeding = validation error)
5. **Performance**: Use bulk delete queries where possible
6. **Error Handling**: Any child delete failure rolls back entire operation

🔴 Issue 3: Inconsistent Method Signatures

File: surrealdb-migration-guide.md, lines 228-246

Problem: Implementation shows db_create_node returning Ok(node.clone()) but:

  • Trait takes &Node (borrow) → implementation clones to return
  • Unnecessary performance overhead (cloning every node)
  • Unclear ownership semantics

Engineering Principle: YAGNI - Don't add complexity unless design requires it

Solution: Standardize ownership model:

Option A (Recommended): Owned nodes in/out

async fn create_node(&self, node: Node) -> Result<Node>;
// Implementation returns the same node

Option B: Borrowed in, owned out

async fn create_node(&self, node: &Node) -> Result<Node>;
// Implementation must clone if it modifies

Document the decision and ensure consistency across all 23 methods.


Important Issues (Strong Recommendations)

🟡 Issue 4: Incomplete Query Filtering Specification

File: node-store-abstraction.md, lines 127-140

Problem: query_nodes accepts NodeFilter but never defines:

  • What fields does NodeFilter support?
  • How are multiple filters combined (AND/OR)?
  • What operators (equals, contains, regex)?

Impact: TursoStore and SurrealStore will implement incompatible filtering semantics.

Solution: Add complete NodeFilter struct definition with combination rules.


🟡 Issue 5: Missing SQL Audit Process

File: node-store-abstraction.md, lines 380-415

Problem: Assumes all SQL is in NodeService, but:

  • Assumption not validated
  • No audit process to inventory SQL
  • What about SQL in other services?

Impact: If SQL scattered across multiple services, 2-week timeline unrealistic.

Solution: Add pre-implementation SQL audit:

grep -r "execute\|query\|prepare" packages/core/src/ > sql_audit.txt
# Verify SQL only in NodeService before starting

🟡 Issue 6: Embedding Operations Lack Detail

File: node-store-abstraction.md, lines 223-241

Problem: Embedding methods specified but missing:

  • Encoding format (what's the structure of &[u8]?)
  • Dimensions (384? 768? variable?)
  • Similarity metric (cosine? euclidean?)
  • Index requirements

Impact: Incompatible encoding/similarity breaks migration between backends.

Solution: Add embedding specification (format: f32 little-endian, dimensions: 384, metric: cosine similarity).


🟡 Issue 7: Incomplete Feature Flag Strategy

File: node-store-abstraction.md, lines 549-567

Problem: Feature flag mentioned but:

  • No testing strategy (how test both paths?)
  • No removal timeline (when remove legacy?)
  • No CI/CD implications

Impact: Feature flags become technical debt if not managed.

Solution: Add flag lifecycle, CI test matrix, removal criteria (3 months stability).


Suggestions (Nits)

🟢 Nit: Documentation Redundancy

~10% overlap between three docs (risk assessment appears in all three). Consider clearer separation of concerns.

🟢 Nit: Missing PoC Code Reference

Line 48-49 mentions "using PoC code" but doesn't specify WHERE it lives (packages/desktop-app/src-tauri/src/datastore/surreal/).

🟢 Nit: Benchmark Specificity

"<5% overhead" should specify: latency vs throughput, single vs batch, measurement methodology.

🟢 Nit: Timeline Arithmetic

Day 3-7 breakdown: verify it sums to 23 methods (currently: 3+2+3+5+5 = 18, not 23).


Positive Observations

Despite critical issues, this is excellent planning work with strong foundations:

  1. ✅ Incremental refactoring - Extract → Wrap → Refactor pattern is textbook correct
  2. ✅ Comprehensive risk management - Realistic mitigation, not just "test thoroughly"
  3. ✅ Realistic timeline - 2 weeks with daily breakdown shows careful planning
  4. ✅ Test-driven validation - Run tests after each method prevents regression accumulation
  5. ✅ Clear rationale - Explains WHY decisions made, not just WHAT
  6. ✅ Complete coverage - 23 methods cover all database operations
  7. ✅ Escape hatch - Feature flag for rollback shows defensive engineering
  8. ✅ Performance focus - Benchmarking with specific thresholds (<5%)

Recommendation: REQUEST CHANGES

Required before implementation:

  1. Fix transaction API (use async closures or defer to Phase 2)
  2. Specify CASCADE DELETE semantics completely
  3. Standardize method ownership (owned vs borrowed)

Strongly recommended:
4. Add NodeFilter specification
5. Add SQL audit process
6. Specify embedding format/dimensions/similarity
7. Complete feature flag lifecycle strategy

Once resolved, this will be excellent planning documentation that significantly reduces implementation risk.


Action Items:

  • Address 3 critical issues (blocking)
  • Address 4 important issues (recommended)
  • Update PR with changes
  • Request re-review
  • Do NOT begin implementation until planning approved

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architectural review complete. REQUEST CHANGES recommended - 3 critical issues and 4 important issues identified. See detailed review comment above for complete analysis and specific recommendations for each issue.

@malibio

malibio commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator Author

Response to Feature Flag Complexity Concern

You're absolutely right - we're overcomplicating this for early-stage development.

Current Approach (Overcomplicated)

  • Maintain two code paths (abstraction + legacy)
  • Test both paths in CI
  • Feature flag escape hatch
  • Complex removal timeline

Simplified Approach (Recommended)

Just commit to the abstraction layer directly:

  1. No feature flag needed - Remove all feature flag discussion from docs
  2. Single code path - NodeService uses NodeStore from Day 1
  3. Trust the incremental approach - The test-after-every-commit strategy IS the safety net
  4. If it breaks, just revert the PR - That's what git is for

Why This Makes Sense for Early Dev

✅ Early stage = low risk

  • Small user base (or none)
  • Can afford to revert if needed
  • No production SLAs to maintain

✅ Abstraction layer is low-risk anyway

  • TursoStore is just delegation (thin wrapper)
  • No behavior changes intended
  • Tests validate zero regressions

✅ Simpler = faster

  • No dual code paths to maintain
  • No CI matrix complexity
  • Less documentation to maintain

✅ Git is the escape hatch

  • Bad commit? git revert
  • Need to rollback? git reset
  • That's literally what version control is for

Updated Critical Issues

With this simplification:

🔴 Issue 3 (Method Ownership) - Still needs resolution (affects API design)
🔴 Issue 1 (Transaction API) - Still needs resolution (affects API design)
🔴 Issue 2 (CASCADE DELETE) - Still needs resolution (affects behavior)

🟡 Issue 7 (Feature Flag) - REMOVED - No feature flag needed
🟡 Issues 4-6 - Still important for backend interoperability

Recommended Doc Changes

  1. Remove all feature flag sections from node-store-abstraction.md
  2. Remove "Escape Hatch" discussion from risk mitigation
  3. Simplify rollback plan to: "If abstraction causes issues, revert the PR"
  4. Update testing strategy - Single code path only (simpler CI)

This reduces complexity significantly while maintaining safety through:

  • Incremental commits
  • Test-after-every-step
  • Small scope (Phase 1 only)
  • Git version control

Do you want me to update the review with this simplified approach?

## Changes Made

### 1. Method Ownership (Move Semantics)
- Changed `create_node`, `update_node`, `batch_create_nodes` to use owned parameters
- Rationale: Avoid unnecessary cloning, cleaner API
- Added documentation explaining ownership semantics

### 2. CASCADE DELETE Specification
- Added comprehensive specification with 6 implementation requirements:
  - Atomicity (all-or-nothing transaction)
  - Traversal order (depth-first, leaf-to-root)
  - Mention cleanup (orphaned reference prevention)
  - Recursion limit (1,000 levels)
  - Performance requirements (<5 seconds for 10K nodes)
  - Error handling (constraint violations, concurrent modification)
- Included 3 test cases for validation

### 3. Transaction Method Removed
- Removed broken `transaction()` method from trait (closure cannot be async)
- Updated design decisions to explain deferral to Phase 2
- Rationale: Phase 1 focuses on abstraction only, proper transaction API needs more design

### 4. NodeFilter Specification
- Added complete `NodeFilter` struct definition with 9 fields
- Documented query semantics (AND logic, None ignored)
- Added example usage for filtering

### 5. Embedding Specification
- Added comprehensive embedding documentation:
  - Format: BAAI/bge-small-en-v1.5, 384 dimensions, binary-encoded
  - Similarity metric: Cosine similarity
  - Binary encoding/decoding examples
  - Database storage (Turso BLOB, SurrealDB bytes)
  - Performance requirements

### 6. SQL Audit Process
- Added complete SQL audit checklist to migration guide
- Documented 3 migration patterns (CRUD, complex queries, transactions)
- Included audit report template
- Added continuous audit command for during implementation

### 7. Feature Flag Removal (User Feedback)
- Removed all feature flag references from roadmap and architecture
- Rationale: Early development, simpler to use git revert as escape hatch
- Updated rollback plans to use `git revert` instead of feature flags
- Added "Why No Feature Flag" sections explaining decision

### 8. Method Count Updates
- Updated all references from 23 methods to 22 methods
- Reflects removal of transaction method

## Review Items Addressed
- ✅ Issue 1 (Transaction API) - Removed, deferred to Phase 2
- ✅ Issue 2 (CASCADE DELETE) - Comprehensive spec added
- ✅ Issue 3 (Method Ownership) - Changed to move semantics
- ✅ Issue 4 (NodeFilter Spec) - Complete struct definition added
- ✅ Issue 5 (SQL Audit) - Process added to migration guide
- ✅ Issue 6 (Embedding Spec) - Comprehensive documentation added
- ✅ Issue 7 (Feature Flag) - Removed per user feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@malibio

malibio commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Feedback Addressed ✅

All review recommendations have been addressed in commit b51cd35.

Changes Made

1. Method Ownership (Move Semantics) ✅

  • Changed create_node(node: Node) - takes ownership, returns ownership
  • Changed update_node(update: NodeUpdate) - takes ownership
  • Changed batch_create_nodes(nodes: Vec<Node>) - takes ownership
  • Rationale: Avoid unnecessary cloning, cleaner API

2. CASCADE DELETE Specification ✅

Added comprehensive specification with 6 implementation requirements:

  • Atomicity: All-or-nothing transaction
  • Traversal order: Depth-first, leaf-to-root
  • Mention cleanup: Prevent orphaned references
  • Recursion limit: 1,000 levels deep (with validation error)
  • Performance: <5 seconds for 10K nodes
  • Error handling: Constraint violations, concurrent modification

Includes 3 test cases for validation.

3. Transaction Method Removed ✅

  • Removed broken transaction() method (closure cannot be async)
  • Updated design decisions explaining deferral to Phase 2
  • Rationale: Phase 1 focuses on abstraction only

4. NodeFilter Specification ✅

Added complete NodeFilter struct definition with 9 fields:

  • node_type, parent_id, container_id
  • created_after, updated_after
  • property_filters, content_contains
  • limit, offset

Documented query semantics (AND logic, None ignored).

5. Embedding Specification ✅

Added comprehensive documentation:

  • Format: BAAI/bge-small-en-v1.5, 384 dimensions, binary-encoded
  • Similarity metric: Cosine similarity
  • Binary encoding/decoding: Complete examples
  • Database storage: Turso BLOB, SurrealDB bytes
  • Performance: <100ms for 100K nodes

6. SQL Audit Process ✅

Added complete SQL audit checklist to migration guide:

  • 4-step audit checklist
  • 3 migration patterns (CRUD, complex queries, transactions)
  • Audit report template
  • Continuous audit command

7. Feature Flag Removal (Per User Feedback) ✅

Removed all feature flag references from roadmap and architecture:

  • User feedback: "overcomplicating it... I'm happy to just discard this feature flag if it doesn't work"
  • New approach: Use git revert as escape hatch (simpler, cleaner)
  • Updated rollback plans: No feature flags, single code path
  • Added "Why No Feature Flag" sections explaining rationale

8. Method Count Updates ✅

Updated all references from 23 methods → 22 methods (transaction method removed).


Review Status

All 7 recommendations addressed:

  • ✅ Issue 1 (Transaction API) - Removed, deferred to Phase 2
  • ✅ Issue 2 (CASCADE DELETE) - Comprehensive spec added
  • ✅ Issue 3 (Method Ownership) - Changed to move semantics
  • ✅ Issue 4 (NodeFilter Spec) - Complete struct definition
  • ✅ Issue 5 (SQL Audit) - Process added to migration guide
  • ✅ Issue 6 (Embedding Spec) - Comprehensive documentation
  • ✅ Issue 7 (Feature Flag) - Removed per user feedback

Status: Ready for final review and merge.

@malibio
malibio merged commit ebd4d89 into main Nov 11, 2025
@malibio
malibio deleted the feature/issue-461-surrealdb-hybrid-migration branch November 11, 2025 11:49
malibio added a commit that referenced this pull request Feb 4, 2026
* Add Epic #461 Phase 1 architectural planning documentation

## Planning Documents Added

This commit adds comprehensive architectural planning for Epic #461
(SurrealDB Migration - Hybrid Architecture) Phase 1 implementation.

**Documents Created:**

1. **node-store-abstraction.md** - Complete architecture design
   - NodeStore trait definition (23 methods)
   - TursoStore wrapper implementation strategy
   - 3-step refactoring process (Extract → Wrap → Refactor)
   - Risk assessment and mitigation strategies
   - Testing strategy and success criteria

2. **surrealdb-migration-roadmap.md** - Complete migration roadmap
   - 4-phase implementation plan (6 weeks total)
   - Phase 1 (Current): Abstraction Layer (2 weeks)
   - Phase 2 (Future): SurrealDB Implementation (2 weeks)
   - Phase 3 (Future): A/B Testing Framework (1 week)
   - Phase 4 (Future): Gradual Rollout (1 week)
   - Decision points, rollback plans, success metrics

3. **surrealdb-migration-guide.md** - Step-by-step implementation guide
   - Day-by-day implementation checklist
   - Code examples for each step
   - Testing strategy and validation
   - Common pitfalls and troubleshooting
   - Performance benchmarking guidance

## Scope for Epic #461

**PHASE 1 ONLY** (This Epic):
- Issue #462: NodeStore Trait Abstraction Layer
- Issue #463: TursoStore Wrapper Implementation

**DEFERRED TO FUTURE EPICS:**
- Issue #464: SurrealDB Implementation → Epic #467
- Issue #465: A/B Testing Framework → Epic #468
- Issue #466: Gradual Rollout → Epic #469

## Key Architecture Decisions

**Abstraction Layer Location:**
NodeService (business logic) → NodeStore Trait → TursoStore → DatabaseService

**Why Phase 1 Only:**
- Risk mitigation: Validate abstraction before adding SurrealDB
- Incremental validation: Prove zero regressions first
- Escape hatch: Can revert if issues arise
- Confidence: 95% success rate (proven refactoring pattern)

## Success Criteria

- ✅ Zero new test failures (100% requirement)
- ✅ Performance overhead <5%
- ✅ Complete API coverage (23 trait methods)
- ✅ Comprehensive documentation

## Timeline

**Phase 1**: 2 weeks (14 days)
- Week 1: Trait definition + SQL extraction
- Week 2: TursoStore implementation + NodeService refactoring

## Next Steps

1. Architectural review (this planning PR)
2. Stakeholder approval
3. Begin Phase 1 implementation
4. 1-month stability validation
5. Decision Point: Proceed to Phase 2?

## References

- Epic #460: SurrealDB Feasibility PoC (completed - all GO criteria met)
- Epic #461: SurrealDB Migration - Hybrid Architecture (current)
- Senior Architect Analysis: See issue #461 comments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address code review feedback for Epic #461 Phase 1 planning

## Changes Made

### 1. Method Ownership (Move Semantics)
- Changed `create_node`, `update_node`, `batch_create_nodes` to use owned parameters
- Rationale: Avoid unnecessary cloning, cleaner API
- Added documentation explaining ownership semantics

### 2. CASCADE DELETE Specification
- Added comprehensive specification with 6 implementation requirements:
  - Atomicity (all-or-nothing transaction)
  - Traversal order (depth-first, leaf-to-root)
  - Mention cleanup (orphaned reference prevention)
  - Recursion limit (1,000 levels)
  - Performance requirements (<5 seconds for 10K nodes)
  - Error handling (constraint violations, concurrent modification)
- Included 3 test cases for validation

### 3. Transaction Method Removed
- Removed broken `transaction()` method from trait (closure cannot be async)
- Updated design decisions to explain deferral to Phase 2
- Rationale: Phase 1 focuses on abstraction only, proper transaction API needs more design

### 4. NodeFilter Specification
- Added complete `NodeFilter` struct definition with 9 fields
- Documented query semantics (AND logic, None ignored)
- Added example usage for filtering

### 5. Embedding Specification
- Added comprehensive embedding documentation:
  - Format: BAAI/bge-small-en-v1.5, 384 dimensions, binary-encoded
  - Similarity metric: Cosine similarity
  - Binary encoding/decoding examples
  - Database storage (Turso BLOB, SurrealDB bytes)
  - Performance requirements

### 6. SQL Audit Process
- Added complete SQL audit checklist to migration guide
- Documented 3 migration patterns (CRUD, complex queries, transactions)
- Included audit report template
- Added continuous audit command for during implementation

### 7. Feature Flag Removal (User Feedback)
- Removed all feature flag references from roadmap and architecture
- Rationale: Early development, simpler to use git revert as escape hatch
- Updated rollback plans to use `git revert` instead of feature flags
- Added "Why No Feature Flag" sections explaining decision

### 8. Method Count Updates
- Updated all references from 23 methods to 22 methods
- Reflects removal of transaction method

## Review Items Addressed
- ✅ Issue 1 (Transaction API) - Removed, deferred to Phase 2
- ✅ Issue 2 (CASCADE DELETE) - Comprehensive spec added
- ✅ Issue 3 (Method Ownership) - Changed to move semantics
- ✅ Issue 4 (NodeFilter Spec) - Complete struct definition added
- ✅ Issue 5 (SQL Audit) - Process added to migration guide
- ✅ Issue 6 (Embedding Spec) - Comprehensive documentation added
- ✅ Issue 7 (Feature Flag) - Removed per user feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
malibio added a commit that referenced this pull request Feb 5, 2026
* Add Epic #461 Phase 1 architectural planning documentation

## Planning Documents Added

This commit adds comprehensive architectural planning for Epic #461
(SurrealDB Migration - Hybrid Architecture) Phase 1 implementation.

**Documents Created:**

1. **node-store-abstraction.md** - Complete architecture design
   - NodeStore trait definition (23 methods)
   - TursoStore wrapper implementation strategy
   - 3-step refactoring process (Extract → Wrap → Refactor)
   - Risk assessment and mitigation strategies
   - Testing strategy and success criteria

2. **surrealdb-migration-roadmap.md** - Complete migration roadmap
   - 4-phase implementation plan (6 weeks total)
   - Phase 1 (Current): Abstraction Layer (2 weeks)
   - Phase 2 (Future): SurrealDB Implementation (2 weeks)
   - Phase 3 (Future): A/B Testing Framework (1 week)
   - Phase 4 (Future): Gradual Rollout (1 week)
   - Decision points, rollback plans, success metrics

3. **surrealdb-migration-guide.md** - Step-by-step implementation guide
   - Day-by-day implementation checklist
   - Code examples for each step
   - Testing strategy and validation
   - Common pitfalls and troubleshooting
   - Performance benchmarking guidance

## Scope for Epic #461

**PHASE 1 ONLY** (This Epic):
- Issue #462: NodeStore Trait Abstraction Layer
- Issue #463: TursoStore Wrapper Implementation

**DEFERRED TO FUTURE EPICS:**
- Issue #464: SurrealDB Implementation → Epic #467
- Issue #465: A/B Testing Framework → Epic #468
- Issue #466: Gradual Rollout → Epic #469

## Key Architecture Decisions

**Abstraction Layer Location:**
NodeService (business logic) → NodeStore Trait → TursoStore → DatabaseService

**Why Phase 1 Only:**
- Risk mitigation: Validate abstraction before adding SurrealDB
- Incremental validation: Prove zero regressions first
- Escape hatch: Can revert if issues arise
- Confidence: 95% success rate (proven refactoring pattern)

## Success Criteria

- ✅ Zero new test failures (100% requirement)
- ✅ Performance overhead <5%
- ✅ Complete API coverage (23 trait methods)
- ✅ Comprehensive documentation

## Timeline

**Phase 1**: 2 weeks (14 days)
- Week 1: Trait definition + SQL extraction
- Week 2: TursoStore implementation + NodeService refactoring

## Next Steps

1. Architectural review (this planning PR)
2. Stakeholder approval
3. Begin Phase 1 implementation
4. 1-month stability validation
5. Decision Point: Proceed to Phase 2?

## References

- Epic #460: SurrealDB Feasibility PoC (completed - all GO criteria met)
- Epic #461: SurrealDB Migration - Hybrid Architecture (current)
- Senior Architect Analysis: See issue #461 comments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address code review feedback for Epic #461 Phase 1 planning

## Changes Made

### 1. Method Ownership (Move Semantics)
- Changed `create_node`, `update_node`, `batch_create_nodes` to use owned parameters
- Rationale: Avoid unnecessary cloning, cleaner API
- Added documentation explaining ownership semantics

### 2. CASCADE DELETE Specification
- Added comprehensive specification with 6 implementation requirements:
  - Atomicity (all-or-nothing transaction)
  - Traversal order (depth-first, leaf-to-root)
  - Mention cleanup (orphaned reference prevention)
  - Recursion limit (1,000 levels)
  - Performance requirements (<5 seconds for 10K nodes)
  - Error handling (constraint violations, concurrent modification)
- Included 3 test cases for validation

### 3. Transaction Method Removed
- Removed broken `transaction()` method from trait (closure cannot be async)
- Updated design decisions to explain deferral to Phase 2
- Rationale: Phase 1 focuses on abstraction only, proper transaction API needs more design

### 4. NodeFilter Specification
- Added complete `NodeFilter` struct definition with 9 fields
- Documented query semantics (AND logic, None ignored)
- Added example usage for filtering

### 5. Embedding Specification
- Added comprehensive embedding documentation:
  - Format: BAAI/bge-small-en-v1.5, 384 dimensions, binary-encoded
  - Similarity metric: Cosine similarity
  - Binary encoding/decoding examples
  - Database storage (Turso BLOB, SurrealDB bytes)
  - Performance requirements

### 6. SQL Audit Process
- Added complete SQL audit checklist to migration guide
- Documented 3 migration patterns (CRUD, complex queries, transactions)
- Included audit report template
- Added continuous audit command for during implementation

### 7. Feature Flag Removal (User Feedback)
- Removed all feature flag references from roadmap and architecture
- Rationale: Early development, simpler to use git revert as escape hatch
- Updated rollback plans to use `git revert` instead of feature flags
- Added "Why No Feature Flag" sections explaining decision

### 8. Method Count Updates
- Updated all references from 23 methods to 22 methods
- Reflects removal of transaction method

## Review Items Addressed
- ✅ Issue 1 (Transaction API) - Removed, deferred to Phase 2
- ✅ Issue 2 (CASCADE DELETE) - Comprehensive spec added
- ✅ Issue 3 (Method Ownership) - Changed to move semantics
- ✅ Issue 4 (NodeFilter Spec) - Complete struct definition added
- ✅ Issue 5 (SQL Audit) - Process added to migration guide
- ✅ Issue 6 (Embedding Spec) - Comprehensive documentation added
- ✅ Issue 7 (Feature Flag) - Removed per user feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SurrealDB Migration - Hybrid Architecture (Desktop-Only)

1 participant