Skip to content

feat: Single Instance Proxy Architecture & Non-blocking Search Engine#28

Merged
doITmagic merged 8 commits intodevfrom
feat/single-instance-proxy
Mar 6, 2026
Merged

feat: Single Instance Proxy Architecture & Non-blocking Search Engine#28
doITmagic merged 8 commits intodevfrom
feat/single-instance-proxy

Conversation

@doITmagic
Copy link
Owner

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:

  1. Proxy Mode Architecture:
    • Implemented a master-proxy architecture to ensure only a single instance of rag-code-mcp handles heavy processing (like Ollama/Qdrant interactions).
    • When multiple IDEs connect, subsequent instances detect the master process and act as lightweight Stdio-to-HTTP proxies, forwarding JSON-RPC messages to the master.
  2. Engine Search Fix (Non-blocking during indexing):
    • Fixed an issue where ErrIndexingInProgress completely blocked search queries while background indexing was active (preventing access even to already-indexed files).
    • Search queries now correctly proceed to Qdrant to retrieve files that have already been embedded, even during active full/incremental indexing.
    • Refined the "resume interrupted indexing" (crash recovery) mechanism to silently restart indexing in the background without blocking the immediate search request.
  3. Test Stability:
    • Fixed a TempDir race condition in Go 1.24 tests by ensuring background indexing jobs exit cleanly before the test finishes.
      Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have formatted my code with go fmt ./...
  • I have run tests go test ./... and they pass
  • I have verified integration with Ollama/Qdrant (if applicable)
  • I have updated the documentation accordingly

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
Copilot AI review requested due to automatic review settings March 6, 2026 17:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings March 6, 2026 17:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

…dation, response size limit, indexing throttle
@doITmagic doITmagic merged commit 1f21865 into dev Mar 6, 2026
5 checks passed
@doITmagic doITmagic deleted the feat/single-instance-proxy branch March 7, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants