Skip to content

Commit b320e7e

Browse files
authored
Skip redundant steering message when kill_terminal disposes terminal (#314130)
1 parent 656fbbc commit b320e7e

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/killTerminalTool.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export class KillTerminalTool extends Disposable implements IToolImpl {
6161
// Get the final output before killing
6262
const finalOutput = execution.getOutput();
6363

64+
// Mark as killed by this tool so the onDisposed handler in
65+
// _registerCompletionNotification skips the redundant steering
66+
// message (the agent receives output through this tool result).
67+
RunInTerminalTool.markKilledByTool(args.id);
68+
6469
// Dispose the terminal instance (this kills the process)
6570
execution.instance.dispose();
6671

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
484484
protected readonly _osBackend: Promise<OperatingSystem>;
485485

486486
private static readonly _activeExecutions = new Map<string, IActiveTerminalExecution & { dispose(): void }>();
487+
488+
/**
489+
* Terminal IDs currently being disposed by `kill_terminal`. Used to
490+
* suppress redundant steering messages in `_registerCompletionNotification`'s
491+
* `onDisposed` handler — the agent already receives the output through the
492+
* `kill_terminal` tool result.
493+
*/
494+
private static readonly _killedByTool = new Set<string>();
487495
public static getBackgroundOutput(id: string): string {
488496
const execution = RunInTerminalTool._activeExecutions.get(id);
489497
if (!execution) {
@@ -514,6 +522,15 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
514522
return true;
515523
}
516524

525+
/**
526+
* Marks a terminal ID as being killed by the `kill_terminal` tool so that
527+
* the `onDisposed` handler in `_registerCompletionNotification` skips the
528+
* redundant steering message.
529+
*/
530+
public static markKilledByTool(id: string): void {
531+
RunInTerminalTool._killedByTool.add(id);
532+
}
533+
517534
private _resolveExecutionOptions(args: IRunInTerminalInputParams): IResolvedExecutionOptions {
518535
const mode = args.mode ?? (args.isBackground ? 'async' : 'sync');
519536
switch (mode) {
@@ -2320,6 +2337,13 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
23202337
// _activeExecutions.
23212338
const executionForDisposal = RunInTerminalTool._activeExecutions.get(termId);
23222339
store.add(terminalInstance.onDisposed(() => {
2340+
// If kill_terminal is disposing this terminal, the agent will
2341+
// receive the output through the normal tool-result flow —
2342+
// skip the redundant steering message.
2343+
if (RunInTerminalTool._killedByTool.has(termId)) {
2344+
disposeNotification();
2345+
return;
2346+
}
23232347
if (handleSessionCancelled()) {
23242348
return;
23252349
}

0 commit comments

Comments
 (0)