Skip to content

Fix get_terminal_output Invalid ID Handling and Clarify Background Terminal ID Contract#303255

Open
meganrogge wants to merge 3 commits intomainfrom
merogge/get-terminal-output-fix
Open

Fix get_terminal_output Invalid ID Handling and Clarify Background Terminal ID Contract#303255
meganrogge wants to merge 3 commits intomainfrom
merogge/get-terminal-output-fix

Conversation

@meganrogge
Copy link
Collaborator

fix #298433

  1. Makes it clear that GetTerminalOutputTool is for checking the output of background terminals.
  2. Prevents repeated bad id guesses by giving better instructions.
  3. Makes failures understandable and recoverable when an invalid id is used.
  4. Reduces agent looping/spinning caused by unclear invalid terminal id failures.

cc @Tyriar

Copilot AI review requested due to automatic review settings March 19, 2026 16:54
@meganrogge meganrogge self-assigned this Mar 19, 2026
@meganrogge meganrogge added this to the 1.113.0 milestone Mar 19, 2026
@meganrogge meganrogge enabled auto-merge (squash) March 19, 2026 16:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the terminal chat agent get_terminal_output tool to better communicate and enforce the “background terminal execution ID” contract and to return a recoverable error when an invalid/unknown ID is provided, reducing agent looping from unclear failures.

Changes:

  • Clarifies get_terminal_output model description and input schema to require the exact opaque ID returned by run_in_terminal with isBackground=true (including UUID pattern).
  • Updates tool invocation to look up the active execution and return an explicit error message when the ID is unknown, avoiding a thrown “Invalid terminal ID”.
  • Adds browser unit tests covering the updated schema/description and the new unknown-ID behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/getTerminalOutputTool.ts Tightens the ID contract via schema/description and returns explicit errors for unknown executions.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/getTerminalOutputTool.test.ts Adds tests for the updated contract and runtime behavior.
Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/getTerminalOutputTool.ts:28

  • The parameter description mixes “ID” and “id” ("exact opaque id returned..."). For consistency with the rest of the text and common acronym capitalization, consider using “ID” throughout (e.g. “exact opaque ID returned…”).
				description: `The ID of the background terminal to check (returned by ${TerminalToolId.RunInTerminal} when isBackground=true). This must be the exact opaque id returned by that tool; terminal names, labels, or integers are invalid.`,
				pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'

Comment on lines +56 to +88
test('returns explicit error for unknown terminal id', async () => {
RunInTerminalTool.getExecution = () => undefined;

const result = await tool.invoke(
createInvocation('pwsh'),
async () => 0,
{ report: () => { } },
CancellationToken.None,
);

assert.strictEqual(result.content.length, 1);
assert.strictEqual(result.content[0].kind, 'text');
const value = (result.content[0] as { value: string }).value;
assert.ok(value.includes('No active terminal execution found'));
assert.ok(value.includes('exact value returned by run_in_terminal'));
});

test('returns output for active terminal id', async () => {
RunInTerminalTool.getExecution = () => createMockExecution('line1\nline2');

const result = await tool.invoke(
createInvocation('abc'),
async () => 0,
{ report: () => { } },
CancellationToken.None,
);

assert.strictEqual(result.content.length, 1);
assert.strictEqual(result.content[0].kind, 'text');
const value = (result.content[0] as { value: string }).value;
assert.ok(value.includes('Output of terminal abc:'));
assert.ok(value.includes('line1\nline2'));
});
meganrogge and others added 2 commits March 19, 2026 13:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Agent] get_terminal_output accepts invalid IDs silently; ToolCallingLoop stops with reasons=undefined

2 participants