Fix #5162: Enhanced VS Code Language Model content filtering error handling #5259
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.
Summary
This PR fixes issue #5162 where VS Code Language Model API responses were getting filtered with unhelpful error messages like "response got filtered FIX!!".
Problem
The VS Code Language Model API applies content filtering/safety mechanisms that can reject responses, but the current error handling in the VS Code LM provider only specifically handled
vscode.CancellationError. When content filtering occurred, these errors were not properly detected and handled, leading to generic error messages instead of helpful guidance for users.Solution
Enhanced the error handling in the VS Code Language Model provider (
src/api/providers/vscode-lm.ts) by:Added content filtering detection: Implemented two new helper methods:
isContentFilteringError()- Detects filtering patterns in Error objectsisContentFilteringErrorObject()- Detects filtering patterns in error-like objectsPattern-based detection: Both methods check for keywords like:
Enhanced error messages: When content filtering is detected, provides clear, actionable error messages that:
Comprehensive test coverage: Added extensive test suite (
src/api/providers/__tests__/vscode-lm-content-filtering.test.ts) with 11 test cases covering:Changes
Modified:
src/api/providers/vscode-lm.tscreateMessage()method error handling (lines 456-504)isContentFilteringError()helper methodisContentFilteringErrorObject()helper methodAdded:
src/api/providers/__tests__/vscode-lm-content-filtering.test.tsTesting
All tests pass, including:
Impact
Fixes #5162
Important
Enhanced error handling for content filtering in VS Code Language Model API with new detection methods and improved error messages.
isContentFilteringError()andisContentFilteringErrorObject()invscode-lm.tsto detect content filtering errors.createMessage()invscode-lm.tsto provide clear error messages for content filtering.vscode-lm-content-filtering.test.tswith 11 test cases for content filtering detection and error message validation.This description was created by
for 186fe01. You can customize this summary. It will automatically update as commits are pushed.