fix: remove duplicate command registration for agent-host-copilotcli (fixes #318223)#318231
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
Conversation
…utorun-based registration (fixes #318223) The static CommandsRegistry.registerCommand for openNewChatSessionInPlace.agent-host-copilotcli conflicted with the dynamic registerAction2 call in the ChatSessionsService autorun. The autorun (triggered by registerChatSessionContribution) attempts to register the same command via registerAction2, which throws if the command already exists. Remove the static registration since the autorun now handles it, and the stable openNewSessionSidebar/openNewSessionEditor commands remain for automation needs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🔧 Error Fix
Summary
The error
Cannot register two commands with the same id: workbench.action.chat.openNewChatSessionInPlace.agent-host-copilotclioccurs because the command is registered twice: once statically viaCommandsRegistry.registerCommandinelectron-browser/chat.contribution.ts, and once dynamically viaregisterAction2in theChatSessionsServiceautorun (triggered byregisterChatSessionContribution). TheregisterAction2function throws when a command with the same ID already exists.Fixes #318223
Recommended reviewer:
@meganroggeCulprit Commit
The static registration was introduced by
66ba7394("Add static commands for opening Agent Host chat sessions (#314187)") by@meganroggeon May 4. The conflict became observable in the regression window (b51c2a1...859cf8d, May 21-22) when theregisterChatSessionContributioncode path started firing_onDidChangeAvailabilityto trigger the autorun that dynamically registers the same command viaregisterAction2.Code Flow
sequenceDiagram participant AH as AgentHostContrib participant CSS as ChatSessionsService participant OBS as contributedSessionProviders participant AR as Autorun participant CR as CommandsRegistry participant RA as registerAction2 Note over CR: Static registration at startup (electron-browser) CR->>CR: registerCommand(openNewChatSessionInPlace.agent-host-copilotcli) AH->>AH: handleSnapshot fires rootState.onDidChange AH->>AH: _handleRootStateChange AH->>AH: _registerAgent(copilotcli) AH->>CSS: registerChatSessionContribution(type: agent-host-copilotcli) CSS->>CSS: _contributions.set, _contributionDisposables.set CSS->>OBS: _onDidChangeAvailability.fire() OBS->>OBS: recompute: includes agent-host-copilotcli OBS->>AR: trigger autorun AR->>AR: dispose old reader.store AR->>RA: registerNewSessionInPlaceAction(agent-host-copilotcli) RA->>CR: getCommand(openNewChatSessionInPlace.agent-host-copilotcli) CR-->>RA: command exists! RA->>RA: throw Error(Cannot register two commands with same id)Affected Files
src/vs/workbench/contrib/chat/electron-browser/chat.contribution.tssrc/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.tsregisterAction2src/vs/platform/actions/common/actions.ts:720registerAction2throws on duplicatesrc/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatContribution.tsregisterChatSessionContributionwhen agent host startsRepro Steps
AgentInfowithprovider: 'copilotcli'agentHostChatContribution._handleRootStateChangeregisters the agentregisterChatSessionContributionfires_onDidChangeAvailabilityregisterAction2for the command that was already statically registeredHow the Fix Works
Chosen approach (
src/vs/workbench/contrib/chat/electron-browser/chat.contribution.ts): Remove the staticCommandsRegistry.registerCommandforopenNewChatSessionInPlace.agent-host-copilotcli. This is the data producer — it creates the pre-existing command entry that causesregisterAction2to throw. The dynamic autorun-based registration (viaregisterChatSessionContribution+ the autorun inChatSessionsService) now handles this command, and stable automation commands (openNewSessionSidebar.agent-host-copilotcli,openNewSessionEditor.agent-host-copilotcli) remain registered for the pre-agent-host-start use case.Alternatives considered: Adding a guard in
registerNewSessionInPlaceActionto skip registration when the command exists — rejected because this would lose the fullAction2metadata (title, category, precondition, menu items) and is a consumer-side fallback that hides the conflict rather than fixing the producer.Recommended Owner
@meganrogge— authored the static command registration in PR #314187.