Skip to content

Conversation

@murataslan1
Copy link

Fixes #10663. Filters out tool-approval-response messages before sending to Gateway API.

Copilot AI review requested due to automatic review settings January 2, 2026 13:37
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

This PR fixes issue #10663 by filtering out tool-approval-response messages from prompts before sending them to the Gateway API, preventing backend crashes when these internal message types are encountered.

Key Changes:

  • Added filtering logic to remove tool-approval-response content from tool messages in prompts
  • Created test suite to verify the filtering behavior

Reviewed changes

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

File Description
packages/gateway/src/gateway-tool-approval.test.ts New test file that verifies tool-approval-response messages are filtered from prompts before API calls
packages/gateway/src/gateway-language-model.ts Implements filterToolApprovalResponses method to remove tool-approval-response content from prompts; integrates filtering into the request pipeline

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'https://api.test.com/language-model': {},
});

it('should currently pass tool-approval-response through to the API', async () => {
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The test description says "should currently pass tool-approval-response through to the API" but the test actually verifies that the tool-approval-response is filtered out (removed). The description should be updated to reflect the actual behavior being tested, such as "should filter out tool-approval-response messages from the prompt".

Suggested change
it('should currently pass tool-approval-response through to the API', async () => {
it('should filter out tool-approval-response messages from the prompt', async () => {

Copilot uses AI. Check for mistakes.
});

const requestBody = await server.calls[0].requestBodyJson;
const toolMessage = requestBody.prompt[0];
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The variable 'toolMessage' is declared but never used. Since the test expects the prompt array to be empty after filtering, this variable assignment is unnecessary and should be removed.

Suggested change
const toolMessage = requestBody.prompt[0];

Copilot uses AI. Check for mistakes.
readonly modelId: GatewayModelId,
private readonly config: GatewayChatConfig,
) {}
) { }
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

There's an unnecessary space added between the closing parenthesis and the opening brace. This change should be reverted to maintain consistency with the existing code style.

Suggested change
) { }
) {}

Copilot uses AI. Check for mistakes.
Comment on lines 23 to 57
it('should currently pass tool-approval-response through to the API', async () => {
server.urls['https://api.test.com/language-model'].response = {
type: 'json-value',
body: {
content: [{ type: 'text', text: 'Response' }],
finish_reason: 'stop',
usage: { prompt_tokens: 10, completion_tokens: 5 },
},
};

const prompt: LanguageModelV3Prompt = [
{
role: 'tool',
content: [
{
type: 'tool-approval-response',
approvalId: 'approval-1',
approved: false,
reason: 'User denied',
},
],
},
];

await createTestModel().doGenerate({
prompt,
});

const requestBody = await server.calls[0].requestBodyJson;
const toolMessage = requestBody.prompt[0];

// This assertion confirms that the fix REMOVES the tool-approval-response
// which prevents the crash on the backend.
expect(requestBody.prompt).toHaveLength(0); // The tool message should be dropped completely as it becomes empty
});
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The test only covers the case where a tool message contains only tool-approval-response content. Consider adding test cases for:

  1. A tool message with both tool-approval-response and other content types (to verify partial filtering)
  2. Multiple tool messages with mixed content
  3. Prompts with non-tool messages mixed with tool messages
    This would ensure the filtering logic works correctly in all scenarios.

Copilot uses AI. Check for mistakes.
- Updated test description to reflect actual behavior\n- Removed unused variable in test\n- Reverted unnecessary code style change\n- Added comprehensive test cases for various scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: tool execution approval not working with gateway

1 participant