• v6.2.5 e4bbd7fb0e

    dpsifr released this 2025-12-02 20:45:22 +01:00 | 509 commits to main since this release

    Bug Fix

    Critical fix for brain.counts.byType() returning inflated/incorrect values

    Problem

    brain.counts.byType() returned wildly incorrect counts that could be 100x inflated:

    // Actual entities: 68
    // counts.byType() returned:
    {
      "collection": 4186,
      "document": 6480,
      "person": 812,
      // ... ~100x inflated
    }
    

    Root Cause

    Two accumulation bugs:

    1. MetadataIndex.lazyLoadCounts() - Added counts to existing Map instead of replacing:

      // BUG: Each restart doubled the counts
      const currentCount = this.totalEntitiesByType.get(type) || 0
      this.totalEntitiesByType.set(type, currentCount + bitmap.size)
      
    2. MetadataIndex.rebuild() and GraphAdjacencyIndex.rebuild() - Did not clear count Maps before rebuilding

    Fix

    • Clear totalEntitiesByType, entityCountsByTypeFixed, verbCountsByTypeFixed at start of lazyLoadCounts()
    • Clear counts in MetadataIndex.rebuild() before rebuilding
    • Clear relationshipCountsByType in GraphAdjacencyIndex.rebuild()

    Affected Features

    • brain.counts.byType() Fixed
    • brain.counts.entities() Fixed
    • brain.counts.byRelationshipType() Fixed
    • All storage adapters (Memory, FileSystem, S3, GCS, R2, Azure, OPFS) Fixed

    Upgrade

    npm install @soulcraft/brainy@6.2.5
    

    After upgrading, counts will be correct on next restart - no manual action needed.


    Reported by: Soulcraft Workshop Team

    🤖 Generated with Claude Code

    Downloads