Fix crash when MCP plugins are persisted with Guid.Empty as Id#397
Fix crash when MCP plugins are persisted with Guid.Empty as Id#397CowboyHat-exe wants to merge 1 commit into
Conversation
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
|
Please read the following Contributor License Agreement (CLA). If you agree with the CLA, please comment with the following: I have read the CLA Document and I hereby sign the CLA CowboyHat-exe seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
|
Hey @CowboyHat-exe, thank you very much for this PR! The root cause, however, actually stems from The refactoring involved is fairly extensive — it includes converting both |
Problem
KernelPluginCollectionuses the pluginName(derived fromId.ToString("N")) as its dictionary key. When two or moreMcpChatPluginEntityrecords in settings haveId == Guid.Empty, the secondAddcall throws:Every chat request fails with "An unknown error occurred" until the app is restarted with healed settings.
Root cause
McpChatPluginEntity.ToMcpChatPlugin()passesIddirectly to theMcpChatPluginconstructor without checking forGuid.Empty. If settings were ever written with un-initialised IDs (e.g. by a migration or external edit), all such entries produce the same plugin name and the second one crashes the kernel builder.Fix
Self-heal on load: if
Id == Guid.Empty, assignGuid.CreateVersion7()before constructing the plugin. The healed value is written back to settings on the next save (via the existingSourceList → McpChatPluginEntitybinding inChatPluginManager), so the repair is permanent.Not changed: the
[JsonConstructor]path — initialisingIdthere would assign a fresh GUID to every record on every deserialization, breaking round-trips for records that already have a valid Id.