Fix duplicate command registration crash on .vswift load/reload - #7
Merged
Merged
Conversation
Root cause: command Disposables were tracked per-host but a host whose start() threw partway through registration leaked its already-registered commands and was never added to , so dispose() never ran — every subsequent loadAll() failed permanently with 'command already exists'. The same bundle discovered via workspace glob AND vswift-installed also double-registered identical command ids. - New CommandRegistry (commands.ts): tracks registrations by command id and by owning script; registerFor() disposes a previous registration for the same id before registering (idempotent), unregisterOwner() cleans up all of a script's commands on stop/reload/deactivate. - SwiftScriptHost uses the shared registry via owner key name@binaryPath; failed start() rolls back partial registrations. - loadAll dedupes bundles by manifest name@version across sources. - Registry disposed on deactivate; added to context.subscriptions. - test/commands.test.mjs: 12 checks (idempotent re-register, duplicate source takeover, owner cleanup, dispose) with a fake vscode that throws on live duplicates like the real API. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Sep 19, 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
Fixes
Failed to load .vswift bundle: Error: command 'swiftCopilot.generate' already exists.Root causes:
SwiftScriptHost.start()pushed command Disposables intothis.disposables, but ifregisterCommandthrew partway (duplicate id), the host was never added tohosts, sodispose()never ran → leaked registrations made every subsequentloadAll()fail permanently..vswiftdiscovered via both the workspace glob andvswift-installed/spawned two hosts registering identical command ids.New
CommandRegistry(commands.ts): tracks registrations by command id and owning script (name@binaryPath).registerFor()disposes the previous registration for an id before registering (idempotent reload),unregisterOwner()cleans a script's whole command set on stop/remove/deactivate.SwiftScriptHost.start()rolls back partial registrations on failure;loadAlldedupes bundles byname@version; registry is disposed on deactivate.test/commands.test.mjs(12 checks, runs against compiledout/): idempotent re-register, duplicate-source takeover, owner cleanup, dispose — with a fakevscode.commandsthat throws on live duplicates like the real API. Added to CI extension job.