-
v4.1.2 Stable
released this
2025-10-21 20:31:03 +02:00 | 745 commits to main since this release🐛 Bug Fixes
Critical: Count Synchronization Race Condition
Fixed critical bug affecting all storage adapters where entity and relationship counts were not tracked correctly during
add(),relate(), andimport()operations.Root Cause: Race condition where count increment code tried to read metadata before it was saved to storage.
Impact: This bug affected all storage backends (FileSystem, GCS, R2, Azure, Memory, OPFS, S3, TypeAware) in brainy v4.0.0+.
What Was Fixed
- ✅ Centralized count tracking in
baseStorage.ts(fixes ALL adapters automatically) - ✅ Added verb type to VerbMetadata for proper count tracking
- ✅ Refactored verb count methods to prevent mutex deadlocks
- ✅ Removed broken count increment code from 6 storage adapters
- ✅ Added
rebuildCounts()utility to repair corrupted counts from actual storage data - ✅ Added comprehensive integration tests (11 tests covering all operations)
Files Modified
Core Fixes:
src/storage/baseStorage.ts- Centralized noun/verb count trackingsrc/storage/adapters/baseStorageAdapter.ts- Fixed verb count deadlockssrc/brainy.ts- Added verb type to metadata
Storage Adapter Cleanup:
src/storage/adapters/fileSystemStorage.tssrc/storage/adapters/gcsStorage.tssrc/storage/adapters/r2Storage.tssrc/storage/adapters/azureBlobStorage.tssrc/storage/adapters/memoryStorage.ts
New Utilities:
src/utils/rebuildCounts.ts- Production utility to rebuild counts.jsontests/integration/count-synchronization.test.ts- Integration tests
Usage
For existing databases with corrupted counts, use the rebuild utility:
import { rebuildCounts } from '@soulcraft/brainy/utils/rebuildCounts' const brain = new Brainy({ storage: { type: 'filesystem', path: './brainy-data' } }) await brain.init() const result = await rebuildCounts(brain.storage) console.log(`Rebuilt: ${result.nounCount} entities, ${result.verbCount} relationships`)Full Changelog: https://github.com/soulcraftlabs/brainy/compare/v4.1.1...v4.1.2
Downloads
-
Source code (ZIP)
0 downloads
-
Source code (TAR.GZ)
1 download
- ✅ Centralized count tracking in