fix: resolve embedding and clustering bugs for large repos#6
Merged
Conversation
Three critical fixes for large-scale repositories: 1. Embedding worker graceful shutdown (internal/embedder/worker.go, cmd/mimir/analyze.go) - Added Close() method with WaitGroup to block until embeddings complete - Fixes issue where analyze exits before worker processes any batches - All embeddings now complete before analyze command exits 2. Embedding queue capacity increased (internal/embedder/worker.go) - Increased buffer from 1,000 to 100,000 jobs - Added warning log when jobs are dropped (queue full) - Handles repos with 100k+ symbols without silent drops 3. SetClusterForNodes SQLite variable limit fix (internal/store/clusters.go) - Batch UIDs into chunks of 500 to avoid SQLite ~999 variable limit - Executes multiple UPDATE queries within same transaction - Prevents "too many SQL variables" error on large clusters All existing tests pass. Fixes: #3, #4, #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes three critical bugs that affect large-scale repositories (100k+ symbols):
1. Embedding Worker Graceful Shutdown (#3)
Problem: The embedding worker started in a goroutine but the channel was never closed and
analyzenever waited for completion. The process exited before the worker could process even a single batch, leaving embeddings at 0%.Fix:
Close()method toWorkerthat closes the queue channel and waits viasync.WaitGroupanalyze.gonow callsw.Close()after enqueueing all jobs, blocking until embeddings complete2. Embedding Queue Capacity (#4)
Problem: Queue buffer was only 1,000 jobs with silent drop on full. Repos with >1,000 symbols had embeddings silently dropped (e.g., 133k symbols → only 1,000 embedded).
Fix:
log.Printf("embedder: job dropped for %s (queue full)", job.UID)3. SetClusterForNodes SQLite Variable Limit (#5)
Problem:
SetClusterForNodesbuilt a singleWHERE uid IN (?, ?, ...)query with one placeholder per UID. SQLite has a ~999 variable limit, causing "too many SQL variables" error on clusters with >998 members.Fix:
UPDATEqueries within the same transactionUpsertClusterMembersTesting
All existing tests pass:
Impact
mimir analyzewithout errorsanalyzeexits