fix: prevent MCP servers from restarting repeatedly on settings save - #5817
Closed
markijbema wants to merge 2 commits into
Closed
fix: prevent MCP servers from restarting repeatedly on settings save#5817markijbema wants to merge 2 commits into
markijbema wants to merge 2 commits into
Conversation
Three root causes fixed: 1. Config deep-equal mismatch: stored injected config vs raw validated config always differed due to variable injection, causing spurious restarts. Fix: store rawConfig (pre-injection) on connections for accurate comparison. 2. isProgrammaticUpdate race condition: debounce callback only checked the flag at entry, not when the timer fires 500ms later. Fix: re-check isProgrammaticUpdate inside the debounced callback. 3. Fire-and-forget transport.close() triggered auto-reconnect: onclose handler called scheduleReconnect after cancelReconnect had already run. Fix: intentionalDisconnects guard prevents onclose from scheduling reconnect during programmatic disconnects.
🦋 Changeset detectedLatest commit: e0ba998 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
jeremylongshore
added a commit
to jeremylongshore/kilocode
that referenced
this pull request
Feb 15, 2026
jeremylongshore
added a commit
to jeremylongshore/kilocode
that referenced
this pull request
Feb 15, 2026
Mirror: fix: prevent MCP servers from restarting repeatedly on settings save (Kilo-Org#5817)
jeremylongshore
added a commit
to jeremylongshore/kilocode
that referenced
this pull request
Feb 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.
Problem
When saving settings, all MCP servers restart and keep restarting in a loop.
Root Causes & Fixes
1. Config deep-equal mismatch (stored injected config vs raw validated config)
updateServerConnections()compared the stored config (post-injectVariables()) against the incoming Zod-validated config (pre-injection). If any variable substitution occurred (${workspaceFolder},${env:*}, etc.), configs would never match — causing every server to restart on every config re-read.Fix: Added
rawConfigfield to connection types that stores the pre-injection validated config. Changed the comparison inupdateServerConnections()to userawConfigagainstvalidatedConfig.2.
isProgrammaticUpdateflag timing racedebounceConfigChange()checked the flag only at entry time. The debounced handler fires 500ms later, but the flag resets at 600ms. If a file system event arrives after the flag resets, the config change would be processed — restarting servers for config we wrote ourselves.Fix: Added a re-check of
isProgrammaticUpdateinside the debounced callback.3. Fire-and-forget
transport.close()triggering auto-reconnectdeleteConnection()calledcancelReconnect()then firedtransport.close()as fire-and-forget (not awaited). Theonclosehandler would run aftercancelReconnectcompleted, callingscheduleReconnect()again — racing with the normal restart flow.Fix: Added
intentionalDisconnectsset.deleteConnection()marks servers before closing. Allonclose/onerrorhandlers skipscheduleReconnect()for intentional disconnects.Testing
All 44 existing McpHub tests pass.