fix assumptions with chat.exitAfterDelegation and chats in the sidebar (#281039)

This commit is contained in:
Josh Spicer
2025-12-03 11:44:45 -08:00
committed by GitHub
parent 4a04ab66fc
commit 683ba6378f
3 changed files with 17 additions and 8 deletions

View File

@@ -284,7 +284,7 @@ class CreateRemoteAgentJobAction {
});
if (requestData) {
await widget.handleDelegationExitIfNeeded(requestData.agent);
await widget.handleDelegationExitIfNeeded(defaultAgent, requestData.agent);
}
} catch (e) {
console.error('Error creating remote coding agent job', e);

View File

@@ -262,7 +262,7 @@ export interface IChatWidget {
clear(): Promise<void>;
getViewState(): IChatModelInputState | undefined;
lockToCodingAgent(name: string, displayName: string, agentId?: string): void;
handleDelegationExitIfNeeded(agent: IChatAgentData | undefined): Promise<void>;
handleDelegationExitIfNeeded(sourceAgent: Pick<IChatAgentData, 'id' | 'name'> | undefined, targetAgent: IChatAgentData | undefined): Promise<void>;
delegateScrollFromMouseWheelEvent(event: IMouseWheelEvent): void;
}

View File

@@ -1309,8 +1309,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
}
}
async handleDelegationExitIfNeeded(agent: IChatAgentData | undefined): Promise<void> {
if (!this._shouldExitAfterDelegation(agent)) {
async handleDelegationExitIfNeeded(sourceAgent: Pick<IChatAgentData, 'id' | 'name'> | undefined, targetAgent: IChatAgentData | undefined): Promise<void> {
if (!this._shouldExitAfterDelegation(sourceAgent, targetAgent)) {
return;
}
@@ -1321,20 +1321,29 @@ export class ChatWidget extends Disposable implements IChatWidget {
}
}
private _shouldExitAfterDelegation(agent: IChatAgentData | undefined): boolean {
private _shouldExitAfterDelegation(sourceAgent: Pick<IChatAgentData, 'id' | 'name'> | undefined, targetAgent: IChatAgentData | undefined): boolean {
if (!targetAgent) {
// Undefined behavior
return false;
}
if (!this.configurationService.getValue<boolean>(ChatConfiguration.ExitAfterDelegation)) {
return false;
}
if (!agent) {
// Never exit if the source and target are the same (that means that you're providing a follow up, etc.)
// NOTE: sourceAgent would be the chatWidget's 'lockedAgent'
if (sourceAgent && sourceAgent.id === targetAgent.id) {
return false;
}
if (!isIChatViewViewContext(this.viewContext)) {
return false;
}
const contribution = this.chatSessionsService.getChatSessionContribution(agent.id);
const contribution = this.chatSessionsService.getChatSessionContribution(targetAgent.id);
if (!contribution) {
return false;
}
@@ -2311,7 +2320,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
this.input.acceptInput(isUserQuery);
this._onDidSubmitAgent.fire({ agent: result.agent, slashCommand: result.slashCommand });
this.handleDelegationExitIfNeeded(result.agent);
this.handleDelegationExitIfNeeded(this._lockedAgent, result.agent);
this.currentRequest = result.responseCompletePromise.then(() => {
const responses = this.viewModel?.getItems().filter(isResponseVM);
const lastResponse = responses?.[responses.length - 1];