fix(mcp): add early detection for multi-instance stdio contention#611
Merged
MaojiaSheng merged 1 commit intovolcengine:mainfrom Mar 15, 2026
Merged
Conversation
When multiple OpenViking processes share the same data directory (common with stdio MCP in multi-session hosts), they silently contend for AGFS and VectorDB resources. This produces misleading errors like "Collection 'context' does not exist" instead of pointing to the actual cause. Add a PID-based advisory lock in OpenVikingService.initialize() that: - Detects an existing live process using the same data directory - Raises DataDirectoryLocked with a clear error message explaining the contention and suggesting HTTP mode or separate data directories - Cleans up stale lock files from crashed processes - Releases the lock on normal exit via atexit The lock uses a .openviking.pid file in the data directory. HTTP mode (openviking-server) is unaffected since it handles concurrency natively. Relates to volcengine#473
MaojiaSheng
approved these changes
Mar 15, 2026
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
When multiple OpenViking processes share the same data directory (common with stdio MCP in multi-session hosts), they silently contend for AGFS and VectorDB resources. Users see misleading errors like
Collection 'context' does not existorTransport closedinstead of a clear contention diagnostic.This adds a PID-based advisory lock that detects the problem at startup and fails with an actionable error message.
Why this matters
Changes
New file:
openviking/utils/process_lock.pyacquire_data_dir_lock(data_dir)- PID-based advisory lockDataDirectoryLockedexception with clear error message suggesting HTTP modeatexitand SIGTERM handlerModified:
openviking/service/core.pyacquire_data_dir_lock()at the start ofinitialize(), before any storage accessNew test:
tests/misc/test_process_lock.pyError message when contention is detected
Testing
ruff format --checkandruff checkpass on all changed filesRelates to #473
This contribution was developed with AI assistance (Claude Code).