Repository navigation
Root-Aggregate Embedding Architecture for Semantic Search - #734
Conversation
## Summary Implements proper embedding staleness tracking for all node operations using the root-aggregate model. Previously, new nodes created via MCP weren't triggering embedding generation, and child node changes weren't propagating staleness to their root. ## Changes ### NodeService (`services/node_service.rs`) - Added `queue_root_for_embedding()` helper that: - Finds the root node of any descendant - Checks if root is an embeddable type - Creates stale marker or marks existing embedding stale - Updated `create_node_with_parent()`: - Root creation: Creates stale embedding marker for embeddable types - Child creation: Queues root for embedding regeneration - Updated `update_node()`: - Replaced old `mark_embedding_stale()` with `queue_root_for_embedding()` - Updated `delete_node_with_occ()`: - Captures root ID before deletion - Queues root for embedding regeneration after child deletion ### SurrealStore (`db/surreal_store.rs`) - Removed obsolete `mark_embedding_stale()` method that set `node.embedding_stale` - Added comment explaining the new root-aggregate model methods ## Root-Aggregate Model Only root nodes (no parent) of embeddable types get embedded: - Embeddable types: text, header, code-block, schema - Non-embeddable: task, date, person, etc. When any node in a tree changes: 1. Find the root via graph traversal 2. Mark root's embedding as stale in `embedding` table 3. Background processor regenerates embedding within 30 seconds ## Durability Stale markers are persisted to SurrealDB immediately. If app shuts down before processing, markers remain and will be processed on next startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Replace 30-second polling interval with event-driven wake/sleep pattern: - Add EmbeddingWaker: lightweight, cloneable handle to wake processor - Processor sleeps until woken, then processes ALL stale embeddings - Multiple rapid wakes are coalesced into single processing run - Zero CPU/DB overhead when idle (no polling) Wire up NodeService to wake processor on embedding changes: - NodeService.set_embedding_waker() accepts optional waker - queue_root_for_embedding() calls waker.wake() after marking stale - Tauri db.rs connects waker during initialization The waker is fire-and-forget: non-blocking, no return value, tolerant of processor shutdown. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review SummaryReview Type: Initial Review Overall AssessmentThis PR implements a significant refactor of the embedding system from polling-based to event-driven architecture. The core design is sound - using an Verdict: The implementation is a net positive and improves overall code health. However, there are incomplete cleanup items that directly contradict the PR description and Issue #729's acceptance criteria. Requirements Check (Issue #729)
Code Review Findings🔴 Critical Issues (Must Fix Before Merge)1. [Critical/Blocker] Incomplete Old Code Removal - Multiple Methods Still Reference The PR description states "Old File:
Engineering Principle: Per CLAUDE.md's pre-release development rules: "Delete deprecated code immediately - no 'TODO: remove after migration'". The PR's own comment at line 3581-3585 acknowledges the removal but doesn't complete it. Required Action: Either:
🟡 Important Issues (Strong Recommendations)2. [Improvement] Test Coverage Gap - No Unit Tests for New Event-Driven Components The File: Engineering Principle: Test-Driven Development - critical business logic (especially async/concurrent code) should have automated tests to prevent regressions. Suggested Tests:
3. [Improvement] Missing Backpressure Handling in File: The
loop {
match service.process_stale_embeddings(Some(10)).await {
Ok(0) => { break; }
Ok(count) => { /* continues immediately */ }
Err(e) => { break; }
}
}Suggested Improvement: Add a small yield between batches: // After processing a batch, yield to allow other tasks
tokio::task::yield_now().await;4. [Improvement] File: The function signature returns pub async fn sync_embeddings(state: State<'_, EmbeddingState>) -> Result<usize, CommandError> {
state.processor.trigger_batch_embed().map_err(|e| { ... })?;
// For now, return 0 as we don't wait for completion
Ok(0)
}Engineering Principle: API contracts should be clear. Either:
🟢 Nitpicks (Optional Polish)5. Nit: Dead Code Warning Suppression File: #[allow(dead_code)]
embedding_service: Arc<NodeEmbeddingService>,Consider either using the field or removing it if truly unused. The suppression suggests incomplete refactoring. 6. Nit: Comment Inconsistency File: The top-level doc comment claims: /// - Removed `embedding_vector` and `embedding_stale` from node table
But these fields still exist in methods below. Update documentation to match actual state. 7. Nit: Hardcoded Batch Size File: match service.process_stale_embeddings(Some(10)).await {Consider making const BATCH_SIZE: usize = 10;Architecture AssessmentStrengths:
Concerns:
RecommendationThe critical issue (incomplete removal of old Minimum Required Actions:
Recommended Actions: Review generated by Principal Engineer AI Reviewer |
malibio
left a comment
There was a problem hiding this comment.
Requesting changes due to incomplete old code removal. See detailed review comment for specifics.
## Critical Issues Fixed
1. **Remove old node.embedding_vector methods from SurrealStore**
- Removed `get_nodes_without_embeddings()`, `update_embedding()`, `get_nodes_with_stale_embeddings()`
- These operated on deprecated node.embedding_vector and node.embedding_stale fields
- Updated `get_stale_root_count` command to use new `get_stale_embedding_root_ids()`
2. **Update test fixtures that use embedding_vector/embedding_stale**
- Removed `embedding_vector: []` and `embedding_stale: false` from CREATE node queries
- Node table no longer has these fields (per schema.surql)
- Removed 7 obsolete vector search tests that used deprecated methods:
- test_search_empty_database, test_search_with_similar_nodes,
- test_search_with_threshold_filter, test_search_respects_limit,
- test_search_performance_1k_nodes, test_search_with_real_nlp_embeddings,
- test_search_performance_10k_nodes
## Important Issues Fixed
3. **Add unit tests for EmbeddingWaker**
- test_waker_wake_sends_signal
- test_waker_coalesces_multiple_wakes
- test_waker_handles_closed_channel
- test_waker_is_cloneable
4. **Add yield_now() for backpressure handling**
- Added `tokio::task::yield_now().await` between batch processing
- Prevents starving other async tasks during large backlogs
- Added BATCH_SIZE constant for clarity
5. **Fix sync_embeddings return type**
- Changed from `Result<usize, CommandError>` to `Result<(), CommandError>`
- Return value was always 0 anyway (fire-and-forget semantics)
- Updated documentation to reflect async processing
## Nitpicks Fixed
6. **Remove dead_code suppression**
- Removed unused `embedding_service: Arc<NodeEmbeddingService>` field
- Background task holds its own clone, field was redundant
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Code Review ResponseAll reviewer recommendations have been addressed in commit ✅ Addressed (8 recommendations)
⏭️ Skipped (1 recommendation)
Test Results
|
The test file was disabled during SurrealDB migration (Issue #481) and tested the old per-node embedding model (node.embedding_stale field). The functionality is now covered by: - Unit tests for EmbeddingWaker in embedding_processor.rs - Integration tests in embedding_service.rs - Store tests for get_stale_embedding_root_ids(), mark_root_embedding_stale() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
These tests were ignored since Issue #481 with unimplemented!() bodies. They tested backfill of _schema_version for legacy nodes without it. No longer relevant because: - Issue #481 is closed - Pre-release project has no legacy data - All nodes created via NodeService automatically get _schema_version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The bullet roundtrip functionality was fixed in a previous PR. Removing the #[ignore] attribute since the test now passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Per pre-release development rules (no backward compatibility needed): Removed: - parse_timestamp() - unused dead code in node_service.rs - parse_record_id() - unused dead code in surreal_store.rs - search_by_embedding() deprecated stub in surreal_store.rs - search_by_embedding() deprecated wrapper in embedding_service.rs - embed_container() deprecated method in embedding_service.rs - Unnecessary #[allow(deprecated)] on test module - Unnecessary #[allow(unused_imports)] on used import - Unused chrono imports Added to CLAUDE.md: - NO #[deprecated] attributes - delete old code, don't deprecate - NO #[allow(dead_code)] - delete unused code, don't suppress warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Re-Review: PR #734 - Root-Aggregate Embedding ArchitectureReview Type: Re-Review Previous Review Summary
Previous Recommendations Status
Skipped Item (Justified):
New Issues Found
Verification ResultsRust Tests: ✅ 139 passed, 0 failed, 24 ignored Architectural AssessmentThe changes properly complete the transition to the root-aggregate embedding model:
Recommendation: APPROVEAll critical and important issues from the previous review have been properly addressed. The single The PR is ready to merge. |
malibio
left a comment
There was a problem hiding this comment.
Re-Review Complete: All 8 previous review recommendations have been properly addressed. Code cleanup is thorough and the root-aggregate embedding architecture is now cleanly implemented. Ready for merge.
Per pre-release rules - delete deprecated code, don't keep it around. This command was a no-op stub; not used in frontend. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
* Complete root-aggregate embedding staleness tracking (Issue #729) ## Summary Implements proper embedding staleness tracking for all node operations using the root-aggregate model. Previously, new nodes created via MCP weren't triggering embedding generation, and child node changes weren't propagating staleness to their root. ## Changes ### NodeService (`services/node_service.rs`) - Added `queue_root_for_embedding()` helper that: - Finds the root node of any descendant - Checks if root is an embeddable type - Creates stale marker or marks existing embedding stale - Updated `create_node_with_parent()`: - Root creation: Creates stale embedding marker for embeddable types - Child creation: Queues root for embedding regeneration - Updated `update_node()`: - Replaced old `mark_embedding_stale()` with `queue_root_for_embedding()` - Updated `delete_node_with_occ()`: - Captures root ID before deletion - Queues root for embedding regeneration after child deletion ### SurrealStore (`db/surreal_store.rs`) - Removed obsolete `mark_embedding_stale()` method that set `node.embedding_stale` - Added comment explaining the new root-aggregate model methods ## Root-Aggregate Model Only root nodes (no parent) of embeddable types get embedded: - Embeddable types: text, header, code-block, schema - Non-embeddable: task, date, person, etc. When any node in a tree changes: 1. Find the root via graph traversal 2. Mark root's embedding as stale in `embedding` table 3. Background processor regenerates embedding within 30 seconds ## Durability Stale markers are persisted to SurrealDB immediately. If app shuts down before processing, markers remain and will be processed on next startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor EmbeddingProcessor to event-driven model (Issue #729) Replace 30-second polling interval with event-driven wake/sleep pattern: - Add EmbeddingWaker: lightweight, cloneable handle to wake processor - Processor sleeps until woken, then processes ALL stale embeddings - Multiple rapid wakes are coalesced into single processing run - Zero CPU/DB overhead when idle (no polling) Wire up NodeService to wake processor on embedding changes: - NodeService.set_embedding_waker() accepts optional waker - queue_root_for_embedding() calls waker.wake() after marking stale - Tauri db.rs connects waker during initialization The waker is fire-and-forget: non-blocking, no return value, tolerant of processor shutdown. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback for Issue #729 ## Critical Issues Fixed 1. **Remove old node.embedding_vector methods from SurrealStore** - Removed `get_nodes_without_embeddings()`, `update_embedding()`, `get_nodes_with_stale_embeddings()` - These operated on deprecated node.embedding_vector and node.embedding_stale fields - Updated `get_stale_root_count` command to use new `get_stale_embedding_root_ids()` 2. **Update test fixtures that use embedding_vector/embedding_stale** - Removed `embedding_vector: []` and `embedding_stale: false` from CREATE node queries - Node table no longer has these fields (per schema.surql) - Removed 7 obsolete vector search tests that used deprecated methods: - test_search_empty_database, test_search_with_similar_nodes, - test_search_with_threshold_filter, test_search_respects_limit, - test_search_performance_1k_nodes, test_search_with_real_nlp_embeddings, - test_search_performance_10k_nodes ## Important Issues Fixed 3. **Add unit tests for EmbeddingWaker** - test_waker_wake_sends_signal - test_waker_coalesces_multiple_wakes - test_waker_handles_closed_channel - test_waker_is_cloneable 4. **Add yield_now() for backpressure handling** - Added `tokio::task::yield_now().await` between batch processing - Prevents starving other async tasks during large backlogs - Added BATCH_SIZE constant for clarity 5. **Fix sync_embeddings return type** - Changed from `Result<usize, CommandError>` to `Result<(), CommandError>` - Return value was always 0 anyway (fire-and-forget semantics) - Updated documentation to reflect async processing ## Nitpicks Fixed 6. **Remove dead_code suppression** - Removed unused `embedding_service: Arc<NodeEmbeddingService>` field - Background task holds its own clone, field was redundant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete node_service_root_test.rs The test file was disabled during SurrealDB migration (Issue #481) and tested the old per-node embedding model (node.embedding_stale field). The functionality is now covered by: - Unit tests for EmbeddingWaker in embedding_processor.rs - Integration tests in embedding_service.rs - Store tests for get_stale_embedding_root_ids(), mark_root_embedding_stale() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete schema version backfill tests These tests were ignored since Issue #481 with unimplemented!() bodies. They tested backfill of _schema_version for legacy nodes without it. No longer relevant because: - Issue #481 is closed - Pre-release project has no legacy data - All nodes created via NodeService automatically get _schema_version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Enable bullet roundtrip test - now passes The bullet roundtrip functionality was fixed in a previous PR. Removing the #[ignore] attribute since the test now passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated methods and dead code, add policy to CLAUDE.md Per pre-release development rules (no backward compatibility needed): Removed: - parse_timestamp() - unused dead code in node_service.rs - parse_record_id() - unused dead code in surreal_store.rs - search_by_embedding() deprecated stub in surreal_store.rs - search_by_embedding() deprecated wrapper in embedding_service.rs - embed_container() deprecated method in embedding_service.rs - Unnecessary #[allow(deprecated)] on test module - Unnecessary #[allow(unused_imports)] on used import - Unused chrono imports Added to CLAUDE.md: - NO #[deprecated] attributes - delete old code, don't deprecate - NO #[allow(dead_code)] - delete unused code, don't suppress warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated schedule_root_embedding_update command Per pre-release rules - delete deprecated code, don't keep it around. This command was a no-op stub; not used in frontend. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Complete root-aggregate embedding staleness tracking (Issue #729) ## Summary Implements proper embedding staleness tracking for all node operations using the root-aggregate model. Previously, new nodes created via MCP weren't triggering embedding generation, and child node changes weren't propagating staleness to their root. ## Changes ### NodeService (`services/node_service.rs`) - Added `queue_root_for_embedding()` helper that: - Finds the root node of any descendant - Checks if root is an embeddable type - Creates stale marker or marks existing embedding stale - Updated `create_node_with_parent()`: - Root creation: Creates stale embedding marker for embeddable types - Child creation: Queues root for embedding regeneration - Updated `update_node()`: - Replaced old `mark_embedding_stale()` with `queue_root_for_embedding()` - Updated `delete_node_with_occ()`: - Captures root ID before deletion - Queues root for embedding regeneration after child deletion ### SurrealStore (`db/surreal_store.rs`) - Removed obsolete `mark_embedding_stale()` method that set `node.embedding_stale` - Added comment explaining the new root-aggregate model methods ## Root-Aggregate Model Only root nodes (no parent) of embeddable types get embedded: - Embeddable types: text, header, code-block, schema - Non-embeddable: task, date, person, etc. When any node in a tree changes: 1. Find the root via graph traversal 2. Mark root's embedding as stale in `embedding` table 3. Background processor regenerates embedding within 30 seconds ## Durability Stale markers are persisted to SurrealDB immediately. If app shuts down before processing, markers remain and will be processed on next startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor EmbeddingProcessor to event-driven model (Issue #729) Replace 30-second polling interval with event-driven wake/sleep pattern: - Add EmbeddingWaker: lightweight, cloneable handle to wake processor - Processor sleeps until woken, then processes ALL stale embeddings - Multiple rapid wakes are coalesced into single processing run - Zero CPU/DB overhead when idle (no polling) Wire up NodeService to wake processor on embedding changes: - NodeService.set_embedding_waker() accepts optional waker - queue_root_for_embedding() calls waker.wake() after marking stale - Tauri db.rs connects waker during initialization The waker is fire-and-forget: non-blocking, no return value, tolerant of processor shutdown. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback for Issue #729 ## Critical Issues Fixed 1. **Remove old node.embedding_vector methods from SurrealStore** - Removed `get_nodes_without_embeddings()`, `update_embedding()`, `get_nodes_with_stale_embeddings()` - These operated on deprecated node.embedding_vector and node.embedding_stale fields - Updated `get_stale_root_count` command to use new `get_stale_embedding_root_ids()` 2. **Update test fixtures that use embedding_vector/embedding_stale** - Removed `embedding_vector: []` and `embedding_stale: false` from CREATE node queries - Node table no longer has these fields (per schema.surql) - Removed 7 obsolete vector search tests that used deprecated methods: - test_search_empty_database, test_search_with_similar_nodes, - test_search_with_threshold_filter, test_search_respects_limit, - test_search_performance_1k_nodes, test_search_with_real_nlp_embeddings, - test_search_performance_10k_nodes ## Important Issues Fixed 3. **Add unit tests for EmbeddingWaker** - test_waker_wake_sends_signal - test_waker_coalesces_multiple_wakes - test_waker_handles_closed_channel - test_waker_is_cloneable 4. **Add yield_now() for backpressure handling** - Added `tokio::task::yield_now().await` between batch processing - Prevents starving other async tasks during large backlogs - Added BATCH_SIZE constant for clarity 5. **Fix sync_embeddings return type** - Changed from `Result<usize, CommandError>` to `Result<(), CommandError>` - Return value was always 0 anyway (fire-and-forget semantics) - Updated documentation to reflect async processing ## Nitpicks Fixed 6. **Remove dead_code suppression** - Removed unused `embedding_service: Arc<NodeEmbeddingService>` field - Background task holds its own clone, field was redundant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete node_service_root_test.rs The test file was disabled during SurrealDB migration (Issue #481) and tested the old per-node embedding model (node.embedding_stale field). The functionality is now covered by: - Unit tests for EmbeddingWaker in embedding_processor.rs - Integration tests in embedding_service.rs - Store tests for get_stale_embedding_root_ids(), mark_root_embedding_stale() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete schema version backfill tests These tests were ignored since Issue #481 with unimplemented!() bodies. They tested backfill of _schema_version for legacy nodes without it. No longer relevant because: - Issue #481 is closed - Pre-release project has no legacy data - All nodes created via NodeService automatically get _schema_version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Enable bullet roundtrip test - now passes The bullet roundtrip functionality was fixed in a previous PR. Removing the #[ignore] attribute since the test now passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated methods and dead code, add policy to CLAUDE.md Per pre-release development rules (no backward compatibility needed): Removed: - parse_timestamp() - unused dead code in node_service.rs - parse_record_id() - unused dead code in surreal_store.rs - search_by_embedding() deprecated stub in surreal_store.rs - search_by_embedding() deprecated wrapper in embedding_service.rs - embed_container() deprecated method in embedding_service.rs - Unnecessary #[allow(deprecated)] on test module - Unnecessary #[allow(unused_imports)] on used import - Unused chrono imports Added to CLAUDE.md: - NO #[deprecated] attributes - delete old code, don't deprecate - NO #[allow(dead_code)] - delete unused code, don't suppress warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated schedule_root_embedding_update command Per pre-release rules - delete deprecated code, don't keep it around. This command was a no-op stub; not used in frontend. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Complete root-aggregate embedding staleness tracking (Issue #729) ## Summary Implements proper embedding staleness tracking for all node operations using the root-aggregate model. Previously, new nodes created via MCP weren't triggering embedding generation, and child node changes weren't propagating staleness to their root. ## Changes ### NodeService (`services/node_service.rs`) - Added `queue_root_for_embedding()` helper that: - Finds the root node of any descendant - Checks if root is an embeddable type - Creates stale marker or marks existing embedding stale - Updated `create_node_with_parent()`: - Root creation: Creates stale embedding marker for embeddable types - Child creation: Queues root for embedding regeneration - Updated `update_node()`: - Replaced old `mark_embedding_stale()` with `queue_root_for_embedding()` - Updated `delete_node_with_occ()`: - Captures root ID before deletion - Queues root for embedding regeneration after child deletion ### SurrealStore (`db/surreal_store.rs`) - Removed obsolete `mark_embedding_stale()` method that set `node.embedding_stale` - Added comment explaining the new root-aggregate model methods ## Root-Aggregate Model Only root nodes (no parent) of embeddable types get embedded: - Embeddable types: text, header, code-block, schema - Non-embeddable: task, date, person, etc. When any node in a tree changes: 1. Find the root via graph traversal 2. Mark root's embedding as stale in `embedding` table 3. Background processor regenerates embedding within 30 seconds ## Durability Stale markers are persisted to SurrealDB immediately. If app shuts down before processing, markers remain and will be processed on next startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor EmbeddingProcessor to event-driven model (Issue #729) Replace 30-second polling interval with event-driven wake/sleep pattern: - Add EmbeddingWaker: lightweight, cloneable handle to wake processor - Processor sleeps until woken, then processes ALL stale embeddings - Multiple rapid wakes are coalesced into single processing run - Zero CPU/DB overhead when idle (no polling) Wire up NodeService to wake processor on embedding changes: - NodeService.set_embedding_waker() accepts optional waker - queue_root_for_embedding() calls waker.wake() after marking stale - Tauri db.rs connects waker during initialization The waker is fire-and-forget: non-blocking, no return value, tolerant of processor shutdown. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback for Issue #729 ## Critical Issues Fixed 1. **Remove old node.embedding_vector methods from SurrealStore** - Removed `get_nodes_without_embeddings()`, `update_embedding()`, `get_nodes_with_stale_embeddings()` - These operated on deprecated node.embedding_vector and node.embedding_stale fields - Updated `get_stale_root_count` command to use new `get_stale_embedding_root_ids()` 2. **Update test fixtures that use embedding_vector/embedding_stale** - Removed `embedding_vector: []` and `embedding_stale: false` from CREATE node queries - Node table no longer has these fields (per schema.surql) - Removed 7 obsolete vector search tests that used deprecated methods: - test_search_empty_database, test_search_with_similar_nodes, - test_search_with_threshold_filter, test_search_respects_limit, - test_search_performance_1k_nodes, test_search_with_real_nlp_embeddings, - test_search_performance_10k_nodes ## Important Issues Fixed 3. **Add unit tests for EmbeddingWaker** - test_waker_wake_sends_signal - test_waker_coalesces_multiple_wakes - test_waker_handles_closed_channel - test_waker_is_cloneable 4. **Add yield_now() for backpressure handling** - Added `tokio::task::yield_now().await` between batch processing - Prevents starving other async tasks during large backlogs - Added BATCH_SIZE constant for clarity 5. **Fix sync_embeddings return type** - Changed from `Result<usize, CommandError>` to `Result<(), CommandError>` - Return value was always 0 anyway (fire-and-forget semantics) - Updated documentation to reflect async processing ## Nitpicks Fixed 6. **Remove dead_code suppression** - Removed unused `embedding_service: Arc<NodeEmbeddingService>` field - Background task holds its own clone, field was redundant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete node_service_root_test.rs The test file was disabled during SurrealDB migration (Issue #481) and tested the old per-node embedding model (node.embedding_stale field). The functionality is now covered by: - Unit tests for EmbeddingWaker in embedding_processor.rs - Integration tests in embedding_service.rs - Store tests for get_stale_embedding_root_ids(), mark_root_embedding_stale() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove obsolete schema version backfill tests These tests were ignored since Issue #481 with unimplemented!() bodies. They tested backfill of _schema_version for legacy nodes without it. No longer relevant because: - Issue #481 is closed - Pre-release project has no legacy data - All nodes created via NodeService automatically get _schema_version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Enable bullet roundtrip test - now passes The bullet roundtrip functionality was fixed in a previous PR. Removing the #[ignore] attribute since the test now passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated methods and dead code, add policy to CLAUDE.md Per pre-release development rules (no backward compatibility needed): Removed: - parse_timestamp() - unused dead code in node_service.rs - parse_record_id() - unused dead code in surreal_store.rs - search_by_embedding() deprecated stub in surreal_store.rs - search_by_embedding() deprecated wrapper in embedding_service.rs - embed_container() deprecated method in embedding_service.rs - Unnecessary #[allow(deprecated)] on test module - Unnecessary #[allow(unused_imports)] on used import - Unused chrono imports Added to CLAUDE.md: - NO #[deprecated] attributes - delete old code, don't deprecate - NO #[allow(dead_code)] - delete unused code, don't suppress warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove deprecated schedule_root_embedding_update command Per pre-release rules - delete deprecated code, don't keep it around. This command was a no-op stub; not used in frontend. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #729
Summary
Complete the root-aggregate embedding architecture that was incompletely implemented:
Fix embedding queue for MCP-created nodes
NodeService.create_node_with_parent()now queues embedding for root nodesFix child node changes propagating to root
update_node()usesqueue_root_for_embedding()to find and mark root as staledelete_node_with_occ()captures root ID before deletion, queues afterRefactor polling to event-driven model
EmbeddingWaker: lightweight, cloneable handle to wake processorClean up old implementation
mark_embedding_stale()method from SurrealStoreembedding_stalefield approach (node table)Key Changes
NodeService.queue_root_for_embedding()- Helper to find root and mark staleNodeService.set_embedding_waker()- Wire up wake notificationsEmbeddingWaker- Fire-and-forget wake handle (non-blocking, tolerant)db.rswires up waker during initializationTest plan
unused-asynclint🤖 Generated with Claude Code