feat: Single Instance Proxy Architecture & Non-blocking Search Engine#28
Merged
feat: Single Instance Proxy Architecture & Non-blocking Search Engine#28
Conversation
When a second rag-code-mcp instance starts (e.g. from another IDE): - If port 3000 is free → becomes the master (full Qdrant/Ollama/indexer) - If port 3000 is occupied and master version >= ours → enters lightweight Stdio-to-HTTP proxy mode (~1MB, no Qdrant/Ollama connections) - If port 3000 is occupied but our version is newer → kills old master, becomes the new master New package: internal/proxy (portutil.go + proxy.go) Also adds pkill to rebuild.sh for clean dev restarts.
- Replace string-based SSE parsing with JSON-first approach: try json.Unmarshal on body first, only fall back to SSE extraction if needed - All extracted SSE data validated through json.Unmarshal before forwarding - Return error instead of raw body if parsing fails (prevents garbled output) - Add comprehensive tests: SSE extraction, HTTP forwarding, error responses, port detection, version querying
- Move ErrIndexingInProgress early return so it only triggers when there is no active job (crash resume scenario). - During active indexing, search now correctly continues to Qdrant to return already-indexed files. - Update TestSearchCodeResumeInterruptedIndexing to expect success on interrupted indexing resume.
- Ensure background indexing job exits cleanly before returning from test to prevent TempDir 'directory not empty' errors
There was a problem hiding this comment.
Pull request overview
Introduces a single-instance “master + proxy” startup path for rag-code-mcp (one heavy master serving HTTP, extra instances proxy stdio→HTTP), and adjusts engine search behavior so queries can proceed during in-progress (or resumed) indexing.
Changes:
- Add proxy mode utilities (port detection, version probing, stdio→HTTP forwarding) and corresponding tests.
- Update engine search to resume interrupted indexing in the background without blocking searches when partial data exists.
- Add a rebuild convenience step to terminate running instances before overwriting binaries.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| rebuild.sh | Kills running instances before rebuild (dev convenience). |
| internal/service/engine/engine.go | Removes search blocking on interrupted indexing; resumes indexing async and continues search. |
| internal/service/engine/engine_searchcode_test.go | Updates resume-indexing test expectations and adds background-job wait. |
| cmd/rag-code-mcp/main.go | Implements single-instance enforcement and proxy-mode fallback based on port occupancy/version. |
| internal/proxy/proxy.go | Implements stdio→HTTP forwarding + SSE payload extraction and error mapping. |
| internal/proxy/portutil.go | Adds port occupancy checks, master version probing, and port-based process termination. |
| internal/proxy/proxy_test.go | Adds unit tests for proxy helpers and port/version utilities. |
… and search engine
…eck, rebuild.sh pkill
…dation, response size limit, indexing throttle
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.
Description
This Pull Request introduces the Single Instance Proxy Architecture and fixes a critical bug in the search engine regarding blocked queries during active indexing.
Key changes:
rag-code-mcphandles heavy processing (like Ollama/Qdrant interactions).TempDirrace condition in Go 1.24 tests by ensuring background indexing jobs exit cleanly before the test finishes.Fixes # (issue)
Type of change
Checklist:
go fmt ./...go test ./...and they pass