Skip to content

Fix: Auto-embed new topic/container nodes on creation - #355

Merged
malibio merged 4 commits into
mainfrom
fix/auto-embed-new-containers
Oct 30, 2025
Merged

malibio merged 4 commits into
mainfrom
fix/auto-embed-new-containers

Conversation

@malibio

@malibio malibio commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed implementation gap where new topic/container nodes were not being marked as stale on creation
  • Background embedding processor now processes newly created containers
  • Enables semantic search for newly created containers via MCP

Problem

Issue #107 incorrectly marked automatic embedding of new nodes as complete, but the implementation only marked nodes as stale on UPDATE, not CREATE:

  • create_node() did not set embedding_stale = TRUE for new nodes
  • Background processor only processes nodes WHERE embedding_stale = TRUE
  • New containers were never embedded, breaking semantic search functionality

Solution

Modified create_node() in packages/core/src/services/node_service.rs:387-423:

  • Added conditional logic to detect topic/container nodes
  • For topic nodes: INSERT with embedding_stale = TRUE and last_content_update = CURRENT_TIMESTAMP
  • For non-topic nodes: Standard INSERT (no embedding needed)

Testing

  • Quality checks passed (no lint/format issues)
  • Pre-commit hooks successful
  • Background processor will pick up new containers in next 5-minute cycle

Impact

  • New containers created via MCP or UI will be automatically embedded
  • Semantic search (search_containers MCP tool) will work for new containers
  • No impact on non-topic nodes (text, task, date, etc.)

Related

🤖 Generated with Claude Code

**Problem:**
- New topic/container nodes were not being automatically embedded
- Background processor only processes nodes marked as stale
- CREATE operation did not mark new nodes as stale (only UPDATE did)
- Issue #107 incorrectly marked this as complete

**Solution:**
- Modified `create_node()` to mark new topic nodes as stale on creation
- Added `embedding_stale = TRUE` and `last_content_update = CURRENT_TIMESTAMP` to INSERT
- Non-topic nodes continue to use standard INSERT (no embedding needed)

**Impact:**
- New containers will now be discovered by background embedding processor
- Semantic search will work for newly created containers
- Background processor runs every 5 minutes to generate embeddings

**Related:** Issue #107 (Semantic search implementation)

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

Co-Authored-By: Claude <[email protected]>
**CRITICAL BUG:** Embedding system was completely broken - using non-existent 'topic' node type

**Problems Fixed:**

1. **Wrong Container Detection:**
   - Code checked `node_type == 'topic'` but NO topic nodes exist in database
   - Actual container nodes identified by `container_node_id IS NULL`
   - Result: ZERO containers were being embedded (search returned nothing)

2. **Missing Child Update Propagation:**
   - Child node updates did not mark parent container as stale
   - Container embeddings became stale when children changed
   - Result: Search results were outdated after editing container content

**Changes Made:**

**node_service.rs:**
- CREATE: Changed `node.node_type == "topic"` to `container_node_id_value.is_none()`
- UPDATE: Changed `updated.node_type == "topic"` to `is_container` check
- Added parent container stale marking when child content updates

**embedding_service.rs:**
- search_containers(): `WHERE n.node_type = 'topic'` → `WHERE n.container_node_id IS NULL`
- exact_search_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`
- get_all_stale_containers(): Fixed query to use container_node_id IS NULL

**embedding_processor.rs:**
- get_stale_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`

**Impact:**

✅ New containers auto-marked for embedding on creation
✅ Container updates trigger re-embedding
✅ Child updates trigger parent container re-embedding
✅ Semantic search now works (finds actual containers)
✅ Background processor processes real containers every 5 minutes

**Related:** Issue #107

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

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

Expanded Scope - Complete Embedding System Fix

After initial investigation, discovered the embedding system was completely broken due to using non-existent node_type = 'topic'.

Critical Bugs Found

1. Wrong Container Detection (CRITICAL):

  • All embedding code checked node_type == 'topic'
  • NO 'topic' nodes exist in database (only: text, header, date, code-block, etc.)
  • Actual containers identified by container_node_id IS NULL
  • Result: ZERO containers were being embedded, semantic search returned nothing

2. Missing Child Update Propagation:

  • Child node updates didn't mark parent container as stale
  • Container embeddings became outdated after editing children
  • Result: Search results were stale

Comprehensive Fix Applied

Files Updated:

  1. packages/core/src/services/node_service.rs

    • CREATE: Use container_node_id_value.is_none() instead of node_type == 'topic'
    • UPDATE: Use is_container check instead of node_type == 'topic'
    • Added parent container stale marking when child content updates
  2. packages/core/src/services/embedding_service.rs

    • search_containers(): WHERE container_node_id IS NULL
    • exact_search_containers(): WHERE container_node_id IS NULL
    • get_all_stale_containers(): WHERE container_node_id IS NULL
  3. packages/core/src/services/embedding_processor.rs

    • get_stale_containers(): WHERE container_node_id IS NULL

Verified Against Database

-- Confirmed: No 'topic' node types exist
SELECT DISTINCT node_type FROM nodes;
-- Returns: code-block, date, header, ordered-list, schema, text

-- Confirmed: Containers use NULL container_node_id  
SELECT * FROM nodes WHERE container_node_id IS NULL;
-- Returns: header containers, date containers, schema nodes

Impact

✅ Semantic search now works (finds actual containers)
✅ New containers auto-embedded on creation
✅ Container updates trigger re-embedding
✅ Child updates trigger parent container re-embedding
✅ Background processor processes real containers

malibio and others added 2 commits October 30, 2025 13:51
**Improvements Made:**

1. **Module-Level Documentation:**
   - Added comprehensive documentation about container node detection pattern
   - Clear warning against using `node_type == 'topic'` for detection
   - Examples showing correct vs incorrect detection methods

2. **Helper Function:**
   - Added `is_container_node()` public helper function
   - Note: Not used inline due to type complexity (Option<&str> vs Option<String>)
   - Kept as public API for future use and external callers

3. **Container Move Handling:**
   - Added logic to mark both old and new containers as stale when node moves
   - Prevents stale embeddings when nodes are reorganized
   - Non-blocking: Uses `.ok()` to avoid failing on missing containers

4. **Code Quality:**
   - Improved comments and inline documentation
   - Consistent container detection pattern throughout
   - Proper borrow handling with `ref` keyword

**Why These Changes:**
- Prevents future bugs by documenting the correct container detection approach
- Ensures embedding system stays fresh during node reorganization
- Improves code maintainability and clarity

**Ref:** Code review feedback on embedding system bug fix
**Related:** Issue #107 (Semantic search)

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

Co-Authored-By: Claude <[email protected]>
… stale marking

**Test Coverage (8 tests, all passing):**

1. **test_container_node_created_as_stale**
   - Verifies container nodes (container_node_id IS NULL) are marked as stale on creation
   - Ensures background embedding processor will pick up new containers

2. **test_child_node_not_created_as_stale**
   - Verifies child nodes (container_node_id IS NOT NULL) are NOT marked as stale
   - Only containers need embeddings, not child content nodes

3. **test_container_content_update_marks_stale**
   - Verifies container content updates trigger stale flag
   - Ensures embeddings regenerate when container content changes

4. **test_child_content_update_marks_parent_stale**
   - Verifies child content updates mark parent container as stale
   - Critical for keeping container embeddings fresh when children change

5. **test_node_move_marks_both_containers_stale**
   - Verifies moving a node between containers marks BOTH old and new containers
   - Ensures both containers' embeddings reflect the move

6. **test_child_non_content_update_does_not_mark_parent_stale**
   - Verifies non-content updates (properties, etc.) don't trigger stale flag
   - Prevents unnecessary embedding regeneration

7. **test_container_detection_is_null_based_not_type_based**
   - Critical regression test: verifies container detection uses NULL check
   - Prevents the original bug (using node_type == 'topic' instead)
   - Tests with "task" type to prove detection is NULL-based, not type-based

8. **test_multiple_children_updates_marks_parent_once**
   - Verifies multiple child updates each mark parent as stale
   - Ensures no race conditions or missed updates

**Why These Tests Matter:**
- Would have caught the original node_type == 'topic' bug immediately
- Prevent future regressions in container detection logic
- Validate all three fixes in the PR (creation, updates, moves)
- Cover edge cases (different node types, multiple children, non-content updates)

**Test Results:**
✅ 8 passed; 0 failed; finished in 0.07s

**Related:** Issue #107 (Semantic search), Code review recommendations
**Ref:** packages/core/src/services/node_service.rs:426, 750, 802

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

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 76092d3 into main Oct 30, 2025
@malibio
malibio deleted the fix/auto-embed-new-containers branch October 30, 2025 14:06
malibio added a commit that referenced this pull request Feb 4, 2026
* Fix: Auto-embed new topic/container nodes on creation

**Problem:**
- New topic/container nodes were not being automatically embedded
- Background processor only processes nodes marked as stale
- CREATE operation did not mark new nodes as stale (only UPDATE did)
- Issue #107 incorrectly marked this as complete

**Solution:**
- Modified `create_node()` to mark new topic nodes as stale on creation
- Added `embedding_stale = TRUE` and `last_content_update = CURRENT_TIMESTAMP` to INSERT
- Non-topic nodes continue to use standard INSERT (no embedding needed)

**Impact:**
- New containers will now be discovered by background embedding processor
- Semantic search will work for newly created containers
- Background processor runs every 5 minutes to generate embeddings

**Related:** Issue #107 (Semantic search implementation)

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

Co-Authored-By: Claude <[email protected]>

* Fix: Complete embedding system overhaul - use container_node_id IS NULL

**CRITICAL BUG:** Embedding system was completely broken - using non-existent 'topic' node type

**Problems Fixed:**

1. **Wrong Container Detection:**
   - Code checked `node_type == 'topic'` but NO topic nodes exist in database
   - Actual container nodes identified by `container_node_id IS NULL`
   - Result: ZERO containers were being embedded (search returned nothing)

2. **Missing Child Update Propagation:**
   - Child node updates did not mark parent container as stale
   - Container embeddings became stale when children changed
   - Result: Search results were outdated after editing container content

**Changes Made:**

**node_service.rs:**
- CREATE: Changed `node.node_type == "topic"` to `container_node_id_value.is_none()`
- UPDATE: Changed `updated.node_type == "topic"` to `is_container` check
- Added parent container stale marking when child content updates

**embedding_service.rs:**
- search_containers(): `WHERE n.node_type = 'topic'` → `WHERE n.container_node_id IS NULL`
- exact_search_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`
- get_all_stale_containers(): Fixed query to use container_node_id IS NULL

**embedding_processor.rs:**
- get_stale_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`

**Impact:**

✅ New containers auto-marked for embedding on creation
✅ Container updates trigger re-embedding
✅ Child updates trigger parent container re-embedding
✅ Semantic search now works (finds actual containers)
✅ Background processor processes real containers every 5 minutes

**Related:** Issue #107

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

Co-Authored-By: Claude <[email protected]>

* Refactor: Implement code review recommendations for embedding system

**Improvements Made:**

1. **Module-Level Documentation:**
   - Added comprehensive documentation about container node detection pattern
   - Clear warning against using `node_type == 'topic'` for detection
   - Examples showing correct vs incorrect detection methods

2. **Helper Function:**
   - Added `is_container_node()` public helper function
   - Note: Not used inline due to type complexity (Option<&str> vs Option<String>)
   - Kept as public API for future use and external callers

3. **Container Move Handling:**
   - Added logic to mark both old and new containers as stale when node moves
   - Prevents stale embeddings when nodes are reorganized
   - Non-blocking: Uses `.ok()` to avoid failing on missing containers

4. **Code Quality:**
   - Improved comments and inline documentation
   - Consistent container detection pattern throughout
   - Proper borrow handling with `ref` keyword

**Why These Changes:**
- Prevents future bugs by documenting the correct container detection approach
- Ensures embedding system stays fresh during node reorganization
- Improves code maintainability and clarity

**Ref:** Code review feedback on embedding system bug fix
**Related:** Issue #107 (Semantic search)

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

Co-Authored-By: Claude <[email protected]>

* Test: Add comprehensive integration tests for container detection and stale marking

**Test Coverage (8 tests, all passing):**

1. **test_container_node_created_as_stale**
   - Verifies container nodes (container_node_id IS NULL) are marked as stale on creation
   - Ensures background embedding processor will pick up new containers

2. **test_child_node_not_created_as_stale**
   - Verifies child nodes (container_node_id IS NOT NULL) are NOT marked as stale
   - Only containers need embeddings, not child content nodes

3. **test_container_content_update_marks_stale**
   - Verifies container content updates trigger stale flag
   - Ensures embeddings regenerate when container content changes

4. **test_child_content_update_marks_parent_stale**
   - Verifies child content updates mark parent container as stale
   - Critical for keeping container embeddings fresh when children change

5. **test_node_move_marks_both_containers_stale**
   - Verifies moving a node between containers marks BOTH old and new containers
   - Ensures both containers' embeddings reflect the move

6. **test_child_non_content_update_does_not_mark_parent_stale**
   - Verifies non-content updates (properties, etc.) don't trigger stale flag
   - Prevents unnecessary embedding regeneration

7. **test_container_detection_is_null_based_not_type_based**
   - Critical regression test: verifies container detection uses NULL check
   - Prevents the original bug (using node_type == 'topic' instead)
   - Tests with "task" type to prove detection is NULL-based, not type-based

8. **test_multiple_children_updates_marks_parent_once**
   - Verifies multiple child updates each mark parent as stale
   - Ensures no race conditions or missed updates

**Why These Tests Matter:**
- Would have caught the original node_type == 'topic' bug immediately
- Prevent future regressions in container detection logic
- Validate all three fixes in the PR (creation, updates, moves)
- Cover edge cases (different node types, multiple children, non-content updates)

**Test Results:**
✅ 8 passed; 0 failed; finished in 0.07s

**Related:** Issue #107 (Semantic search), Code review recommendations
**Ref:** packages/core/src/services/node_service.rs:426, 750, 802

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Fix: Auto-embed new topic/container nodes on creation

**Problem:**
- New topic/container nodes were not being automatically embedded
- Background processor only processes nodes marked as stale
- CREATE operation did not mark new nodes as stale (only UPDATE did)
- Issue #107 incorrectly marked this as complete

**Solution:**
- Modified `create_node()` to mark new topic nodes as stale on creation
- Added `embedding_stale = TRUE` and `last_content_update = CURRENT_TIMESTAMP` to INSERT
- Non-topic nodes continue to use standard INSERT (no embedding needed)

**Impact:**
- New containers will now be discovered by background embedding processor
- Semantic search will work for newly created containers
- Background processor runs every 5 minutes to generate embeddings

**Related:** Issue #107 (Semantic search implementation)

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

Co-Authored-By: Claude <[email protected]>

* Fix: Complete embedding system overhaul - use container_node_id IS NULL

**CRITICAL BUG:** Embedding system was completely broken - using non-existent 'topic' node type

**Problems Fixed:**

1. **Wrong Container Detection:**
   - Code checked `node_type == 'topic'` but NO topic nodes exist in database
   - Actual container nodes identified by `container_node_id IS NULL`
   - Result: ZERO containers were being embedded (search returned nothing)

2. **Missing Child Update Propagation:**
   - Child node updates did not mark parent container as stale
   - Container embeddings became stale when children changed
   - Result: Search results were outdated after editing container content

**Changes Made:**

**node_service.rs:**
- CREATE: Changed `node.node_type == "topic"` to `container_node_id_value.is_none()`
- UPDATE: Changed `updated.node_type == "topic"` to `is_container` check
- Added parent container stale marking when child content updates

**embedding_service.rs:**
- search_containers(): `WHERE n.node_type = 'topic'` → `WHERE n.container_node_id IS NULL`
- exact_search_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`
- get_all_stale_containers(): Fixed query to use container_node_id IS NULL

**embedding_processor.rs:**
- get_stale_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`

**Impact:**

✅ New containers auto-marked for embedding on creation
✅ Container updates trigger re-embedding
✅ Child updates trigger parent container re-embedding
✅ Semantic search now works (finds actual containers)
✅ Background processor processes real containers every 5 minutes

**Related:** Issue #107

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

Co-Authored-By: Claude <[email protected]>

* Refactor: Implement code review recommendations for embedding system

**Improvements Made:**

1. **Module-Level Documentation:**
   - Added comprehensive documentation about container node detection pattern
   - Clear warning against using `node_type == 'topic'` for detection
   - Examples showing correct vs incorrect detection methods

2. **Helper Function:**
   - Added `is_container_node()` public helper function
   - Note: Not used inline due to type complexity (Option<&str> vs Option<String>)
   - Kept as public API for future use and external callers

3. **Container Move Handling:**
   - Added logic to mark both old and new containers as stale when node moves
   - Prevents stale embeddings when nodes are reorganized
   - Non-blocking: Uses `.ok()` to avoid failing on missing containers

4. **Code Quality:**
   - Improved comments and inline documentation
   - Consistent container detection pattern throughout
   - Proper borrow handling with `ref` keyword

**Why These Changes:**
- Prevents future bugs by documenting the correct container detection approach
- Ensures embedding system stays fresh during node reorganization
- Improves code maintainability and clarity

**Ref:** Code review feedback on embedding system bug fix
**Related:** Issue #107 (Semantic search)

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

Co-Authored-By: Claude <[email protected]>

* Test: Add comprehensive integration tests for container detection and stale marking

**Test Coverage (8 tests, all passing):**

1. **test_container_node_created_as_stale**
   - Verifies container nodes (container_node_id IS NULL) are marked as stale on creation
   - Ensures background embedding processor will pick up new containers

2. **test_child_node_not_created_as_stale**
   - Verifies child nodes (container_node_id IS NOT NULL) are NOT marked as stale
   - Only containers need embeddings, not child content nodes

3. **test_container_content_update_marks_stale**
   - Verifies container content updates trigger stale flag
   - Ensures embeddings regenerate when container content changes

4. **test_child_content_update_marks_parent_stale**
   - Verifies child content updates mark parent container as stale
   - Critical for keeping container embeddings fresh when children change

5. **test_node_move_marks_both_containers_stale**
   - Verifies moving a node between containers marks BOTH old and new containers
   - Ensures both containers' embeddings reflect the move

6. **test_child_non_content_update_does_not_mark_parent_stale**
   - Verifies non-content updates (properties, etc.) don't trigger stale flag
   - Prevents unnecessary embedding regeneration

7. **test_container_detection_is_null_based_not_type_based**
   - Critical regression test: verifies container detection uses NULL check
   - Prevents the original bug (using node_type == 'topic' instead)
   - Tests with "task" type to prove detection is NULL-based, not type-based

8. **test_multiple_children_updates_marks_parent_once**
   - Verifies multiple child updates each mark parent as stale
   - Ensures no race conditions or missed updates

**Why These Tests Matter:**
- Would have caught the original node_type == 'topic' bug immediately
- Prevent future regressions in container detection logic
- Validate all three fixes in the PR (creation, updates, moves)
- Cover edge cases (different node types, multiple children, non-content updates)

**Test Results:**
✅ 8 passed; 0 failed; finished in 0.07s

**Related:** Issue #107 (Semantic search), Code review recommendations
**Ref:** packages/core/src/services/node_service.rs:426, 750, 802

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Fix: Auto-embed new topic/container nodes on creation

**Problem:**
- New topic/container nodes were not being automatically embedded
- Background processor only processes nodes marked as stale
- CREATE operation did not mark new nodes as stale (only UPDATE did)
- Issue #107 incorrectly marked this as complete

**Solution:**
- Modified `create_node()` to mark new topic nodes as stale on creation
- Added `embedding_stale = TRUE` and `last_content_update = CURRENT_TIMESTAMP` to INSERT
- Non-topic nodes continue to use standard INSERT (no embedding needed)

**Impact:**
- New containers will now be discovered by background embedding processor
- Semantic search will work for newly created containers
- Background processor runs every 5 minutes to generate embeddings

**Related:** Issue #107 (Semantic search implementation)

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

Co-Authored-By: Claude <[email protected]>

* Fix: Complete embedding system overhaul - use container_node_id IS NULL

**CRITICAL BUG:** Embedding system was completely broken - using non-existent 'topic' node type

**Problems Fixed:**

1. **Wrong Container Detection:**
   - Code checked `node_type == 'topic'` but NO topic nodes exist in database
   - Actual container nodes identified by `container_node_id IS NULL`
   - Result: ZERO containers were being embedded (search returned nothing)

2. **Missing Child Update Propagation:**
   - Child node updates did not mark parent container as stale
   - Container embeddings became stale when children changed
   - Result: Search results were outdated after editing container content

**Changes Made:**

**node_service.rs:**
- CREATE: Changed `node.node_type == "topic"` to `container_node_id_value.is_none()`
- UPDATE: Changed `updated.node_type == "topic"` to `is_container` check
- Added parent container stale marking when child content updates

**embedding_service.rs:**
- search_containers(): `WHERE n.node_type = 'topic'` → `WHERE n.container_node_id IS NULL`
- exact_search_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`
- get_all_stale_containers(): Fixed query to use container_node_id IS NULL

**embedding_processor.rs:**
- get_stale_containers(): `WHERE node_type = 'topic'` → `WHERE container_node_id IS NULL`

**Impact:**

✅ New containers auto-marked for embedding on creation
✅ Container updates trigger re-embedding
✅ Child updates trigger parent container re-embedding
✅ Semantic search now works (finds actual containers)
✅ Background processor processes real containers every 5 minutes

**Related:** Issue #107

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

Co-Authored-By: Claude <[email protected]>

* Refactor: Implement code review recommendations for embedding system

**Improvements Made:**

1. **Module-Level Documentation:**
   - Added comprehensive documentation about container node detection pattern
   - Clear warning against using `node_type == 'topic'` for detection
   - Examples showing correct vs incorrect detection methods

2. **Helper Function:**
   - Added `is_container_node()` public helper function
   - Note: Not used inline due to type complexity (Option<&str> vs Option<String>)
   - Kept as public API for future use and external callers

3. **Container Move Handling:**
   - Added logic to mark both old and new containers as stale when node moves
   - Prevents stale embeddings when nodes are reorganized
   - Non-blocking: Uses `.ok()` to avoid failing on missing containers

4. **Code Quality:**
   - Improved comments and inline documentation
   - Consistent container detection pattern throughout
   - Proper borrow handling with `ref` keyword

**Why These Changes:**
- Prevents future bugs by documenting the correct container detection approach
- Ensures embedding system stays fresh during node reorganization
- Improves code maintainability and clarity

**Ref:** Code review feedback on embedding system bug fix
**Related:** Issue #107 (Semantic search)

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

Co-Authored-By: Claude <[email protected]>

* Test: Add comprehensive integration tests for container detection and stale marking

**Test Coverage (8 tests, all passing):**

1. **test_container_node_created_as_stale**
   - Verifies container nodes (container_node_id IS NULL) are marked as stale on creation
   - Ensures background embedding processor will pick up new containers

2. **test_child_node_not_created_as_stale**
   - Verifies child nodes (container_node_id IS NOT NULL) are NOT marked as stale
   - Only containers need embeddings, not child content nodes

3. **test_container_content_update_marks_stale**
   - Verifies container content updates trigger stale flag
   - Ensures embeddings regenerate when container content changes

4. **test_child_content_update_marks_parent_stale**
   - Verifies child content updates mark parent container as stale
   - Critical for keeping container embeddings fresh when children change

5. **test_node_move_marks_both_containers_stale**
   - Verifies moving a node between containers marks BOTH old and new containers
   - Ensures both containers' embeddings reflect the move

6. **test_child_non_content_update_does_not_mark_parent_stale**
   - Verifies non-content updates (properties, etc.) don't trigger stale flag
   - Prevents unnecessary embedding regeneration

7. **test_container_detection_is_null_based_not_type_based**
   - Critical regression test: verifies container detection uses NULL check
   - Prevents the original bug (using node_type == 'topic' instead)
   - Tests with "task" type to prove detection is NULL-based, not type-based

8. **test_multiple_children_updates_marks_parent_once**
   - Verifies multiple child updates each mark parent as stale
   - Ensures no race conditions or missed updates

**Why These Tests Matter:**
- Would have caught the original node_type == 'topic' bug immediately
- Prevent future regressions in container detection logic
- Validate all three fixes in the PR (creation, updates, moves)
- Cover edge cases (different node types, multiple children, non-content updates)

**Test Results:**
✅ 8 passed; 0 failed; finished in 0.07s

**Related:** Issue #107 (Semantic search), Code review recommendations
**Ref:** packages/core/src/services/node_service.rs:426, 750, 802

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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.

1 participant