fix(mcp): preserve concurrent MCP settings during initial creation (fixes #1371) - #30
Closed
easonLiangWorldedtech wants to merge 1 commit into
Closed
fix(mcp): preserve concurrent MCP settings during initial creation (fixes #1371)#30easonLiangWorldedtech wants to merge 1 commit into
easonLiangWorldedtech wants to merge 1 commit into
Conversation
…ixes Zoo-Code-Org#1371) getMcpSettingsFilePath() created the default mcp_settings.json with a check-then-write: fileExistsAtPath() followed by an unconditional fs.writeFile of the empty stub. Two windows racing at startup both saw the file as absent, and the second blind write truncated the first window's config to the 122-byte stub. The stub write now goes through safeWriteJson with a merge callback: the read happens under the advisory lock, and any config already on disk (written by a concurrent process after the existence check) is preserved instead of clobbered. The fast path (file exists -> no write) is unchanged, so no watcher-triggered reloads or write amplification. Test: regression test reproduces the interleaving (existence check sees absent file, locked read sees the concurrent config) and asserts the creation write carries the concurrent config, not the stub. The safeWriteJson spec mock now honors options.merge.
Owner
Author
|
opened as cross-repo upstream PR instead |
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
Fixes Zoo-Code-Org#1371 (part of epic Zoo-Code-Org#1375).
MCP settings initialization has a check-then-create race:
getMcpSettingsFilePath()didfileExistsAtPath()followed by an unconditionalfs.writeFileof the empty stub. Two VS Code windows (separate extension-host processes) racing at startup both see the file as absent, and the second blind write truncates the first window's config to the 122-byte stub — silent data loss of all configured MCP servers.Changes
src/services/mcp/McpHub.ts— the stub creation ingetMcpSettingsFilePath()now goes throughsafeWriteJsonwith amergecallback:mcpServersobject, it is preserved; otherwise the default stub is written;src/services/mcp/__tests__/McpHub.spec.ts:fs.writeFileimplementation.)safeWriteJsonspec mock now honorsoptions.merge(it previously ignored options, which masked merge semantics for every test in this file).Notes
safeWriteJsonwas already the established pattern for this file (used by the add/remove-server flows); this change removes the one remaining rawfs.writeFileinMcpHub.eslint --max-warnings=0clean on both touched files.pnpm --dir src exec vitest run services/mcp/__tests__/McpHub.spec.ts→ 64/64 passing.