• v4.1.2 0a9d7ffa65

    v4.1.2 Stable

    dpsifr 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(), and import() 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 tracking
    • src/storage/adapters/baseStorageAdapter.ts - Fixed verb count deadlocks
    • src/brainy.ts - Added verb type to metadata

    Storage Adapter Cleanup:

    • src/storage/adapters/fileSystemStorage.ts
    • src/storage/adapters/gcsStorage.ts
    • src/storage/adapters/r2Storage.ts
    • src/storage/adapters/azureBlobStorage.ts
    • src/storage/adapters/memoryStorage.ts

    New Utilities:

    • src/utils/rebuildCounts.ts - Production utility to rebuild counts.json
    • tests/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