Skip to content

handleDelegationExit : do not clear if an error is being displayed#281066

Merged
joshspicer merged 2 commits intomainfrom
joshspicer/doNotSwapOnError
Dec 3, 2025
Merged

handleDelegationExit : do not clear if an error is being displayed#281066
joshspicer merged 2 commits intomainfrom
joshspicer/doNotSwapOnError

Conversation

@joshspicer
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings December 3, 2025 21:37
@joshspicer joshspicer changed the title handleDelegationExit : do not swap if an error is being displayed handleDelegationExit : do not clear if an error is being displayed Dec 3, 2025
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 enhances the _handleDelegationExit() function to prevent clearing the chat widget when a delegation completes with an error. Previously, the widget would always clear after delegation regardless of the response outcome. Now, it checks if the final response has error details and preserves the widget in error cases, allowing users to see what went wrong.

Key changes:

  • Added error detection logic to check result?.errorDetails before clearing
  • Renamed helper function from checkForComplete to checkIfShouldClear for clarity
  • Modified Promise flow to return boolean indicating whether to clear, rather than always clearing

Comment on lines +1385 to 1396
const result = checkIfShouldClear();
if (result) {
cleanup();
resolve();
resolve(true);
}
});
const timeout = setTimeout(() => {
cleanup();
resolve();
resolve(false);
}, 30_000); // 30 second timeout
const cleanup = () => {
clearTimeout(timeout);
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The function could be optimized to exit early when a response completes with an error. Currently, if a response completes with an error, the function will wait the full 30-second timeout before deciding not to clear, even though it already knows the response is complete and shouldn't be cleared. Consider modifying checkIfShouldClear() to return a tri-state value (e.g., 'clear' | 'dontClear' | 'keepWaiting') to distinguish between "response incomplete" and "response complete with error".

Copilot uses AI. Check for mistakes.
const lastItem = items[items.length - 1];
if (lastItem && isResponseVM(lastItem) && lastItem.model && lastItem.isComplete && !lastItem.model.isPendingConfirmation.get()) {
return true;
const hasError = Boolean(lastItem.result?.errorDetails);
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Consider using lastItem.errorDetails instead of lastItem.result?.errorDetails for consistency with the codebase. The errorDetails property is a getter that returns result?.errorDetails, making both equivalent, but using the direct property is more concise and follows the encapsulation pattern.

Suggested change
const hasError = Boolean(lastItem.result?.errorDetails);
const hasError = Boolean(lastItem.errorDetails);

Copilot uses AI. Check for mistakes.
@joshspicer joshspicer merged commit fc70040 into main Dec 3, 2025
28 checks passed
@joshspicer joshspicer deleted the joshspicer/doNotSwapOnError branch December 3, 2025 21:58
@joshspicer joshspicer restored the joshspicer/doNotSwapOnError branch December 3, 2025 22:54
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jan 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants