From 5f07b1de8faa98788788586be1076b8b217536bc Mon Sep 17 00:00:00 2001 From: CowboyHat-exe <> Date: Thu, 28 May 2026 14:26:46 -0500 Subject: [PATCH] Fix crash when MCP plugins are persisted with Guid.Empty as Id KernelPluginCollection uses the plugin Id (formatted as 'N') as its dictionary key. When two or more McpChatPluginEntity entries are loaded from settings with Id == Guid.Empty, KernelPluginCollection.Add throws: ArgumentException: Argument_AddingDuplicateWithKey, 00000000000000000000000000000000 ToMcpChatPlugin() now assigns a fresh Guid.CreateVersion7() whenever it encounters a zero Id, matching the behaviour of the McpChatPlugin primary constructor. On next save the healed Id is written back to settings so the self-repair is permanent. Constraint: KernelPluginCollection uses the plugin Name as the dict key; Name is set from Id in the ctor so Guid.Empty produces the same key for every affected plugin Rejected: Initialize Id in [JsonConstructor] McpChatPluginEntity() | breaks round-trip: the ctor is called for every existing record including ones that already have a good Id Confidence: high Scope-risk: narrow Directive: Do not change the key used by KernelPluginCollection without verifying the dedup logic in ChatPluginManager Tested: manual restart with settings containing 8 Guid.Empty plugin entries; error no longer thrown Not-tested: automated --- .../Configuration/Settings/PluginSettings.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Everywhere.Core/Configuration/Settings/PluginSettings.cs b/src/Everywhere.Core/Configuration/Settings/PluginSettings.cs index 7ee600eb..24787076 100644 --- a/src/Everywhere.Core/Configuration/Settings/PluginSettings.cs +++ b/src/Everywhere.Core/Configuration/Settings/PluginSettings.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using CommunityToolkit.Mvvm.ComponentModel; using Everywhere.Chat.Plugins; using Everywhere.Collections; @@ -76,6 +76,11 @@ public McpChatPluginEntity(McpChatPlugin mcpChatPlugin) return null; } + // Self-heal persisted Guid.Empty IDs; they cause KernelPluginCollection to throw + // a duplicate-key ArgumentException when two or more zero-ID plugins are loaded. + if (Id == Guid.Empty) + Id = Guid.CreateVersion7(); + return new McpChatPlugin(Id, transportConfiguration); } } \ No newline at end of file