✨ Add MCP Reindex & Auto-Reindex Capabilities#8
Open
brainnotincluded wants to merge 1 commit intokraklabs:mainfrom
Open
✨ Add MCP Reindex & Auto-Reindex Capabilities#8brainnotincluded wants to merge 1 commit intokraklabs:mainfrom
brainnotincluded wants to merge 1 commit intokraklabs:mainfrom
Conversation
This commit adds comprehensive reindexing functionality that works while the MCP server is running, solving the database locking issue. New Features: - cie_reindex MCP tool: Trigger full/incremental reindex with cancellation support - cie_index_config MCP tool: Configure auto-reindex behavior - File watcher with fsnotify: Auto-detect file changes and queue reindex jobs - Smart state machine: ready -> draining -> indexing -> reopening -> ready Architecture: - Cooperative lock/release mechanism: MCP server releases DB during reindex - Query draining: Waits for active queries before closing DB - Concurrent request handling: Other tools fail gracefully during reindex - Proper embedding dimension handling for different providers Files Added: - pkg/storage/reindex.go: ReindexCoordinator with state machine - pkg/ingestion/watcher.go: FileWatcher for auto-reindex - pkg/tools/reindex.go: cie_reindex tool implementation - pkg/tools/index_config.go: cie_index_config tool - pkg/storage/querier.go: Querier interface - docs/REINDEX_IMPLEMENTATION.md: Documentation Files Modified: - pkg/storage/embedded.go: Added CloseAndRelease, Reopen, query coordination - pkg/tools/status.go: Extended with indexing state - cmd/cie/mcp.go: Integrated new tools and watcher lifecycle - cmd/cie/config.go: Added AutoReindexConfig - go.mod: Added fsnotify dependency
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.
🎯 Overview
This PR adds comprehensive reindexing capabilities that work while the MCP server is running, solving the long-standing "database locked" issue when trying to reindex from Claude Code/Cursor.
The Problem
Previously, when running
cie --mcp, the database was locked by the MCP server process. Any attempt to runcie indexfrom another terminal would fail with "database locked" because RocksDB allows only one writer.The Solution
A cooperative lock/release mechanism with a proper state machine:
🚀 New Features
1.
cie_reindexMCP ToolTrigger reindex directly from AI assistants:
{ "name": "cie_reindex", "arguments": { "force": false, // incremental vs full reindex "paths": ["pkg/foo/bar.go"], // optional: specific files "cancel_job_id": "..." // optional: cancel running reindex } }Returns:
2.
cie_index_configMCP ToolConfigure auto-reindex behavior:
{ "name": "cie_index_config", "arguments": { "auto_reindex": true, "debounce_ms": 2000, "exclude_patterns": ["*.log", "temp/**"], "watch_extensions": [".go", ".js", ".ts"] } }3. File System Watcher (fsnotify)
4. Enhanced
cie_index_statusNow shows indexing state:
🏗️ Architecture
State Machine
readydrainingindexingreopeningConcurrency Safety
sync.WaitGrouptracks active queriescontext.WithCancelfor clean shutdownDatabase Lock Strategy
coordinator.StartReindex()drainingactiveQueries == 0📁 Files Changed
✅ Testing
Manual Test Results
Edge Cases Handled
📝 Configuration
Auto-reindex settings in
.cie/project.yaml:🎨 UX Improvements
🔒 Security & Safety
🚦 Ready for Review
Related Issues: Fixes database locking when running
cie --mcpDependencies:
github.com/fsnotify/fsnotify v1.7.0(file watching)