From 12839b5ac9edc1d7819be1f6a207f91ee0df76d6 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Tue, 4 Nov 2025 07:42:06 -0800 Subject: [PATCH] fix: resolve disableAutoRebuild and fork() initialization issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix disableAutoRebuild being ignored when indexes are empty on startup - Add second check after needsRebuild to enable lazy loading properly - Auto-create initial commit in fork() if none exists, eliminating manual setup - Resolves Workshop team's 30-minute startup delays with large datasets (5.9M relationships) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/brainy.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/brainy.ts b/src/brainy.ts index 89406597..0a54742f 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -2159,7 +2159,20 @@ export class Brainy implements BrainyInterface { const refManager = (this.storage as any).refManager const currentBranch = (this.storage as any).currentBranch || 'main' - // Step 1: Copy storage ref (COW layer - instant!) + // Step 1: Ensure initial commit exists (required for fork) + const currentRef = await refManager.getRef(currentBranch) + if (!currentRef) { + // Auto-create initial commit if none exists + await this.commit(`Initial commit on ${currentBranch}`, { + author: options?.author || 'Brainy', + timestamp: Date.now() + }) + if (!this.config.silent) { + console.log(`📝 Auto-created initial commit on ${currentBranch} (required for fork)`) + } + } + + // Step 2: Copy storage ref (COW layer - instant!) await refManager.copyRef(currentBranch, branchName) // Step 2: Create new Brainy instance pointing to fork branch @@ -4348,14 +4361,22 @@ export class Brainy implements BrainyInterface { const needsRebuild = metadataStats.totalEntries === 0 || hnswIndexSize === 0 || - graphIndexSize === 0 || - this.config.disableAutoRebuild === false // Explicitly enabled + graphIndexSize === 0 if (!needsRebuild) { // All indexes already populated, no rebuild needed return } + // BUG FIX: If disableAutoRebuild === true, skip rebuild even if indexes are empty + // Indexes will load lazily on first query + if (this.config.disableAutoRebuild === true) { + if (!this.config.silent) { + console.log('⚡ Indexes empty but auto-rebuild disabled - using lazy loading') + } + return + } + // Small dataset: Rebuild all indexes for best performance if (totalCount < AUTO_REBUILD_THRESHOLD || this.config.disableAutoRebuild === false) { if (!this.config.silent) {