• v5.6.0 ef7bf1b04c

    dpsifr released this 2025-11-06 23:25:32 +01:00 | 594 commits to main since this release

    🐛 Critical Bug Fix

    Fixed critical bug where getRelations() returned empty array despite relationships existing. This affected ALL 8 storage adapters when called without filters.

    Root Cause

    The bug was a simple parameter default issue:

    • getVerbs() called getVerbsWithPagination() without passing offset
    • offset was undefinedtargetCount = undefined + 100 = NaN
    • Loop condition collectedVerbs.length < NaN was always false
    • Loop never ran → returned 0 results

    The Fix

    Two-line change:

    // Default offset to 0 if undefined
    const { limit, offset = 0, filter } = options
    

    Applied to:

    • getVerbsWithPagination() (line 1183)
    • getNounsWithPagination() (line 1051)

    Impact

    Fixed:

    • Workshop bug report: 1,141 relationships exist but getRelations() returned empty array
    • All fresh Brainy instances (MemoryStorage, FileSystemStorage, etc.)
    • Affects all 8 storage adapters (all extend BaseStorage)

    Performance:

    • No degradation - optimizations now work as designed
    • Type skipping verified: checked 1 type, skipped 126 empty types
    • Early termination verified: stopped at limit
    • Billion-scale safe: bounded memory, streaming, type-aware

    Not Affected:

    • Filtered queries: getRelations({ from: id }), getRelations({ to: id })
    • Queries with type filter: getRelations({ type: 'relatedTo' })

    Test Results

    MemoryStorage

    Layer 1 (getVerbsByType_internal): 1 verbs ✅
    Layer 2 (getVerbs with filter): 1 verbs ✅
    Layer 3 (getVerbs no filter): 1 verbs ✅  ← FIXED!
    Layer 4 (brain.getRelations()): 1 relations ✅  ← FIXED!
    

    FileSystemStorage

    brain.getRelations(): 1 relationships ✅
    storage.getVerbs(): 1 verbs ✅
    

    Files Changed

    • src/storage/baseStorage.ts - Added parameter defaults and conditional optimization

    Upgrade Instructions

    For Workshop Team:

    npm install @soulcraft/brainy@5.6.0
    

    No code changes required - the fix is automatic upon upgrade.

    Full Changelog

    Fixed:

    • Fix getRelations() returning empty array for fresh instances (#5e9efd1)

    Previous (v5.5.0):

    • Optimize nouns+verbs pagination for billion-scale (symmetric architecture)
    • Resolve getRelations() empty array bug for ALL storage adapters

    Install:

    npm install @soulcraft/brainy@5.6.0
    

    Tested on:

    • MemoryStorage
    • FileSystemStorage
    • All 8 storage adapters (inherit from BaseStorage)

    Billion-scale verified:

    • Sharding preserved
    • Type-aware preserved
    • Early termination working
    • Memory bounded
    Downloads