brainy/src
David Snelling e86f765f3d fix: resolve critical 378x pagination infinite loop bug (v5.7.11)
CRITICAL BUG FIX: Workshop team reported 1,360,000+ entities loaded instead of 3,593
(378x multiplier), causing 15-20 minute startup times making app completely unusable.

## Root Cause

Pagination implementation had fundamental cursor/offset mismatch across codebase:
1. HNSW/Graph rebuilds passed `cursor` parameter
2. Storage methods accepted `cursor` but never used it, defaulted offset=0
3. Every pagination call returned same first N entities infinitely
4. hasMore calculation bug (>= instead of >) caused true infinite loop

## Fixes Applied (15 bugs across 5 files)

### src/storage/baseStorage.ts (5 fixes)
- Line 1086: Document cursor parameter currently ignored (offset-based for now)
- Line 1191: Fix hasMore (>= to >) in getNounsWithPagination
- Line 1221: Document cursor parameter currently ignored
- Line 1305: Fix hasMore (>= to >) in getVerbsWithPagination
- Line 1631: Fix hasMore (>= to >) in getVerbs

### src/storage/adapters/optimizedS3Search.ts (2 fixes)
- Line 110: Fix hasMore (>= to >) for nouns
- Line 193: Fix hasMore (>= to >) for verbs

### src/hnsw/typeAwareHNSWIndex.ts (2 fixes)
- Line 455: Change cursor to offset-based pagination
- Line 533: Increment offset instead of updating cursor

### src/hnsw/hnswIndex.ts (2 fixes)
- Line 1095: Change cursor to offset-based pagination
- Line 1164: Increment offset instead of updating cursor

### src/utils/rebuildCounts.ts (4 fixes)
- Line 67: Change cursor to offset for nouns
- Line 85: Increment offset for nouns
- Line 98: Change cursor to offset for verbs
- Line 115: Increment offset for verbs

## Impact

BEFORE v5.7.11:
-  Loading 1,360,000+ entities (378x multiplier)
-  15-20 minute startup times
-  Application completely unusable
-  Workshop team blocked from using disableAutoRebuild

AFTER v5.7.11:
-  Loads correct entity count (3,593 entities)
-  Fast startup (< 10 seconds for 3,600 entities)
-  disableAutoRebuild works correctly
-  No more infinite pagination loops

## Verification

Test with 50 entities shows:
-  Correct count: 50 documents + 1 collection = 51 entities
-  No 378x multiplier
-  No infinite loop
-  Fast rebuild completion

Resolves critical production blocker for Workshop team.

## Phase 2 (Future: v5.8.0)

Implement proper cursor-based pagination for stateless billion-scale support.
Current fix uses offset-based pagination which is sufficient for datasets
up to 10M entities.

Related: BRAINY_STARTUP_PERFORMANCE_BUG.md, BRAINY_V5_7_9_HNSW_BUG.md
2025-11-13 14:20:19 -08:00
..
api feat: add ImageHandler with EXIF extraction and comprehensive MIME detection (v5.2.0) 2025-11-03 14:06:17 -08:00
augmentations fix: update tests for Stage 3 CANONICAL taxonomy (42 nouns, 127 verbs) 2025-11-11 10:09:01 -08:00
cli fix: update all Stage 2 references to Stage 3 CANONICAL type counts 2025-11-06 09:40:33 -08:00
config fix: enable GCS native storage with Application Default Credentials 2025-10-09 10:39:54 -07:00
cortex feat: Stage 3 CANONICAL taxonomy with 169 types (v5.5.0) 2025-11-06 09:02:23 -08:00
critical feat: add browser environment compatibility support 2025-09-17 15:48:02 -07:00
data feat: Phase 3 - Unified Semantic Type Inference (Nouns + Verbs) 2025-10-16 10:59:26 -07:00
distributed feat(v4.0.0): Complete metadata/vector separation architecture with Azure support 2025-10-17 12:29:27 -07:00
embeddings feat(v4.0.0): Complete metadata/vector separation architecture with Azure support 2025-10-17 12:29:27 -07:00
errors feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
graph perf: optimize imports with background deduplication (12-24x speedup) 2025-11-11 14:10:14 -08:00
hnsw fix: resolve critical 378x pagination infinite loop bug (v5.7.11) 2025-11-13 14:20:19 -08:00
import fix: resolve v5.7.3 race condition by persisting write-through cache (v5.7.4) 2025-11-12 13:18:53 -08:00
importers fix: update all Stage 2 references to Stage 3 CANONICAL type counts 2025-11-06 09:40:33 -08:00
interfaces feat: implement always-adaptive caching with getCacheStats monitoring 2025-10-10 14:09:30 -07:00
mcp refactor: streamline core API surface 2025-10-04 08:52:06 -07:00
neural fix: resolve getRelations() empty array bug for ALL storage adapters (v5.5.0) 2025-11-06 10:47:59 -08:00
patterns 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
query fix: update remaining 31x→42x speedup references in typeAwareQueryPlanner 2025-11-06 09:41:22 -08:00
scripts feat: add node: protocol to all Node.js built-in imports for bundler compatibility 2025-09-17 14:20:21 -07:00
shared refactor: remove deprecated BrainyData class completely 2025-09-30 16:04:00 -07:00
storage fix: resolve critical 378x pagination infinite loop bug (v5.7.11) 2025-11-13 14:20:19 -08:00
streaming feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
triple feat: Phase 3 - Unified Semantic Type Inference (Nouns + Verbs) 2025-10-16 10:59:26 -07:00
types feat: Stage 3 CANONICAL taxonomy with 169 types (v5.5.0) 2025-11-06 09:02:23 -08:00
universal fix: prevent fs adapter from throwing on import in browser 2025-09-17 16:22:02 -07:00
utils fix: resolve critical 378x pagination infinite loop bug (v5.7.11) 2025-11-13 14:20:19 -08:00
versioning fix: resolve critical COW ref resolution and versioning bugs 2025-11-04 13:05:59 -08:00
vfs fix: resolve HNSW race condition and verb weight extraction (v5.4.0) 2025-11-05 17:05:07 -08:00
augmentationManager.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
augmentationPipeline.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
brainy.ts docs: update index architecture documentation for v5.7.7 lazy loading 2025-11-13 10:10:39 -08:00
coreTypes.ts perf: 48-64× faster HNSW bulk imports via concurrent neighbor updates 2025-10-29 16:10:40 -07:00
cortex.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
index.ts feat: expose neural entity extraction APIs (v5.7.6 - Workshop request) 2025-11-13 09:01:56 -08:00
pipeline.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
setup.ts chore: enforce consistent coding style and semicolon removal 2025-09-29 09:50:59 -07:00
unified.ts chore: enforce consistent coding style and semicolon removal 2025-09-29 09:50:59 -07:00
worker.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00