Skip to content

Fix failing Rust embedding service tests - #358

Merged
malibio merged 2 commits into
mainfrom
feature/issue-343-fix-embedding-tests
Oct 30, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-343-fix-embedding-tests

Conversation

@malibio

@malibio malibio commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

Closes #343

malibio and others added 2 commits October 30, 2025 15:35
**Problem:**
Four embedding service tests were failing with assertion errors where
embedding metadata wasn't being stored correctly in the database.

**Root Causes Identified:**

1. **JSON Metadata Storage Bug (3 tests)**
   - `store_embedding` method was passing metadata as a string to `json_set()`
   - SQLite's `json_set()` requires JSON type, not string type
   - This caused `properties["embedding_metadata"]["type"]` to be `Null` instead of expected values like `"complete_container"` or `"container_summary"`

2. **Database Transaction Isolation Issue (1 test)**
   - `test_re_embed_container` held a database connection across content update and re-embedding
   - This caused embeddings to appear identical when they should have been different
   - The second embedding was reading stale data from the open transaction

**Fixes Applied:**

1. **packages/core/src/services/embedding_service.rs:678**
   - Changed `json_set(properties, '$.embedding_metadata', ?)` to use `json(?)` wrapper
   - Now: `json_set(properties, '$.embedding_metadata', json(?))`
   - This ensures SQLite parses the JSON string into a proper JSON value

2. **packages/core/src/services/embedding_service_test.rs:247-290**
   - Refactored connection management to use scoped blocks
   - Each database operation now gets a fresh connection that is dropped immediately
   - Ensures transactions commit and data is visible to subsequent operations

**Test Results:**
- ✅ All 14 embedding service tests now pass (previously 10/14)
- ✅ Fixed tests: `test_chunking_strategy_small`, `test_chunking_strategy_medium`,
  `test_chunking_strategy_large`, `test_re_embed_container`
- ✅ No regressions in other tests

**Impact:**
- Embedding metadata is now correctly stored in the `properties` JSON field
- Re-embedding operations correctly detect content changes
- Test suite validates embedding functionality comprehensively

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

Co-Authored-By: Claude <[email protected]>
**Code Review Follow-up:**
Added inline documentation to clarify the subtle bug fixes from the previous commit.

**Changes:**

1. **embedding_service.rs:675-677** - Added comment explaining json() wrapper
   - Documents why json() is necessary for SQLite's json_set()
   - Prevents future regression of this subtle string-vs-JSON bug
   - Critical for maintainability since the bug causes silent data corruption

2. **embedding_service_test.rs** - Enhanced connection scoping comments
   - Line 260: "Drop connection to commit transaction and ensure data visibility"
   - Line 264: "Fresh connection for the update operation"
   - Line 272: "Drop connection to commit transaction"
   - Line 279: "Fresh connection ensures we see the committed content update"
   - Documents intentional pattern to prevent "simplification" refactors

**Rationale:**
These comments protect against future developers accidentally reverting the fix
or "optimizing" the test code by reusing connections, which would reintroduce
the transaction isolation bug.

**Impact:**
- No functional changes - documentation only
- Improves long-term maintainability
- All 14 embedding service tests still pass

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

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit f4cb87e into main Oct 30, 2025
@malibio
malibio deleted the feature/issue-343-fix-embedding-tests branch October 30, 2025 14:56
@malibio malibio mentioned this pull request Oct 30, 2025
4 tasks done
malibio added a commit that referenced this pull request Feb 4, 2026
* Fix: Resolve failing Rust embedding service tests (issue #343)

**Problem:**
Four embedding service tests were failing with assertion errors where
embedding metadata wasn't being stored correctly in the database.

**Root Causes Identified:**

1. **JSON Metadata Storage Bug (3 tests)**
   - `store_embedding` method was passing metadata as a string to `json_set()`
   - SQLite's `json_set()` requires JSON type, not string type
   - This caused `properties["embedding_metadata"]["type"]` to be `Null` instead of expected values like `"complete_container"` or `"container_summary"`

2. **Database Transaction Isolation Issue (1 test)**
   - `test_re_embed_container` held a database connection across content update and re-embedding
   - This caused embeddings to appear identical when they should have been different
   - The second embedding was reading stale data from the open transaction

**Fixes Applied:**

1. **packages/core/src/services/embedding_service.rs:678**
   - Changed `json_set(properties, '$.embedding_metadata', ?)` to use `json(?)` wrapper
   - Now: `json_set(properties, '$.embedding_metadata', json(?))`
   - This ensures SQLite parses the JSON string into a proper JSON value

2. **packages/core/src/services/embedding_service_test.rs:247-290**
   - Refactored connection management to use scoped blocks
   - Each database operation now gets a fresh connection that is dropped immediately
   - Ensures transactions commit and data is visible to subsequent operations

**Test Results:**
- ✅ All 14 embedding service tests now pass (previously 10/14)
- ✅ Fixed tests: `test_chunking_strategy_small`, `test_chunking_strategy_medium`,
  `test_chunking_strategy_large`, `test_re_embed_container`
- ✅ No regressions in other tests

**Impact:**
- Embedding metadata is now correctly stored in the `properties` JSON field
- Re-embedding operations correctly detect content changes
- Test suite validates embedding functionality comprehensively

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

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

* Docs: Add explanatory comments for embedding service fix (issue #343)

**Code Review Follow-up:**
Added inline documentation to clarify the subtle bug fixes from the previous commit.

**Changes:**

1. **embedding_service.rs:675-677** - Added comment explaining json() wrapper
   - Documents why json() is necessary for SQLite's json_set()
   - Prevents future regression of this subtle string-vs-JSON bug
   - Critical for maintainability since the bug causes silent data corruption

2. **embedding_service_test.rs** - Enhanced connection scoping comments
   - Line 260: "Drop connection to commit transaction and ensure data visibility"
   - Line 264: "Fresh connection for the update operation"
   - Line 272: "Drop connection to commit transaction"
   - Line 279: "Fresh connection ensures we see the committed content update"
   - Documents intentional pattern to prevent "simplification" refactors

**Rationale:**
These comments protect against future developers accidentally reverting the fix
or "optimizing" the test code by reusing connections, which would reintroduce
the transaction isolation bug.

**Impact:**
- No functional changes - documentation only
- Improves long-term maintainability
- All 14 embedding service tests still pass

🤖 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: Resolve failing Rust embedding service tests (issue #343)

**Problem:**
Four embedding service tests were failing with assertion errors where
embedding metadata wasn't being stored correctly in the database.

**Root Causes Identified:**

1. **JSON Metadata Storage Bug (3 tests)**
   - `store_embedding` method was passing metadata as a string to `json_set()`
   - SQLite's `json_set()` requires JSON type, not string type
   - This caused `properties["embedding_metadata"]["type"]` to be `Null` instead of expected values like `"complete_container"` or `"container_summary"`

2. **Database Transaction Isolation Issue (1 test)**
   - `test_re_embed_container` held a database connection across content update and re-embedding
   - This caused embeddings to appear identical when they should have been different
   - The second embedding was reading stale data from the open transaction

**Fixes Applied:**

1. **packages/core/src/services/embedding_service.rs:678**
   - Changed `json_set(properties, '$.embedding_metadata', ?)` to use `json(?)` wrapper
   - Now: `json_set(properties, '$.embedding_metadata', json(?))`
   - This ensures SQLite parses the JSON string into a proper JSON value

2. **packages/core/src/services/embedding_service_test.rs:247-290**
   - Refactored connection management to use scoped blocks
   - Each database operation now gets a fresh connection that is dropped immediately
   - Ensures transactions commit and data is visible to subsequent operations

**Test Results:**
- ✅ All 14 embedding service tests now pass (previously 10/14)
- ✅ Fixed tests: `test_chunking_strategy_small`, `test_chunking_strategy_medium`,
  `test_chunking_strategy_large`, `test_re_embed_container`
- ✅ No regressions in other tests

**Impact:**
- Embedding metadata is now correctly stored in the `properties` JSON field
- Re-embedding operations correctly detect content changes
- Test suite validates embedding functionality comprehensively

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

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

* Docs: Add explanatory comments for embedding service fix (issue #343)

**Code Review Follow-up:**
Added inline documentation to clarify the subtle bug fixes from the previous commit.

**Changes:**

1. **embedding_service.rs:675-677** - Added comment explaining json() wrapper
   - Documents why json() is necessary for SQLite's json_set()
   - Prevents future regression of this subtle string-vs-JSON bug
   - Critical for maintainability since the bug causes silent data corruption

2. **embedding_service_test.rs** - Enhanced connection scoping comments
   - Line 260: "Drop connection to commit transaction and ensure data visibility"
   - Line 264: "Fresh connection for the update operation"
   - Line 272: "Drop connection to commit transaction"
   - Line 279: "Fresh connection ensures we see the committed content update"
   - Documents intentional pattern to prevent "simplification" refactors

**Rationale:**
These comments protect against future developers accidentally reverting the fix
or "optimizing" the test code by reusing connections, which would reintroduce
the transaction isolation bug.

**Impact:**
- No functional changes - documentation only
- Improves long-term maintainability
- All 14 embedding service tests still pass

🤖 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: Resolve failing Rust embedding service tests (issue #343)

**Problem:**
Four embedding service tests were failing with assertion errors where
embedding metadata wasn't being stored correctly in the database.

**Root Causes Identified:**

1. **JSON Metadata Storage Bug (3 tests)**
   - `store_embedding` method was passing metadata as a string to `json_set()`
   - SQLite's `json_set()` requires JSON type, not string type
   - This caused `properties["embedding_metadata"]["type"]` to be `Null` instead of expected values like `"complete_container"` or `"container_summary"`

2. **Database Transaction Isolation Issue (1 test)**
   - `test_re_embed_container` held a database connection across content update and re-embedding
   - This caused embeddings to appear identical when they should have been different
   - The second embedding was reading stale data from the open transaction

**Fixes Applied:**

1. **packages/core/src/services/embedding_service.rs:678**
   - Changed `json_set(properties, '$.embedding_metadata', ?)` to use `json(?)` wrapper
   - Now: `json_set(properties, '$.embedding_metadata', json(?))`
   - This ensures SQLite parses the JSON string into a proper JSON value

2. **packages/core/src/services/embedding_service_test.rs:247-290**
   - Refactored connection management to use scoped blocks
   - Each database operation now gets a fresh connection that is dropped immediately
   - Ensures transactions commit and data is visible to subsequent operations

**Test Results:**
- ✅ All 14 embedding service tests now pass (previously 10/14)
- ✅ Fixed tests: `test_chunking_strategy_small`, `test_chunking_strategy_medium`,
  `test_chunking_strategy_large`, `test_re_embed_container`
- ✅ No regressions in other tests

**Impact:**
- Embedding metadata is now correctly stored in the `properties` JSON field
- Re-embedding operations correctly detect content changes
- Test suite validates embedding functionality comprehensively

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

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

* Docs: Add explanatory comments for embedding service fix (issue #343)

**Code Review Follow-up:**
Added inline documentation to clarify the subtle bug fixes from the previous commit.

**Changes:**

1. **embedding_service.rs:675-677** - Added comment explaining json() wrapper
   - Documents why json() is necessary for SQLite's json_set()
   - Prevents future regression of this subtle string-vs-JSON bug
   - Critical for maintainability since the bug causes silent data corruption

2. **embedding_service_test.rs** - Enhanced connection scoping comments
   - Line 260: "Drop connection to commit transaction and ensure data visibility"
   - Line 264: "Fresh connection for the update operation"
   - Line 272: "Drop connection to commit transaction"
   - Line 279: "Fresh connection ensures we see the committed content update"
   - Documents intentional pattern to prevent "simplification" refactors

**Rationale:**
These comments protect against future developers accidentally reverting the fix
or "optimizing" the test code by reusing connections, which would reintroduce
the transaction isolation bug.

**Impact:**
- No functional changes - documentation only
- Improves long-term maintainability
- All 14 embedding service tests still pass

🤖 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.

Fix failing Rust embedding service tests

1 participant