Skip to content

fix(github-copilot): Properly handle streaming errors and filter images from non-user messages#6212

Closed
albina-popova wants to merge 1 commit intoblock:mainfrom
albina-popova:fix/github-copilot-error-handling-5845
Closed

fix(github-copilot): Properly handle streaming errors and filter images from non-user messages#6212
albina-popova wants to merge 1 commit intoblock:mainfrom
albina-popova:fix/github-copilot-error-handling-5845

Conversation

@albina-popova
Copy link
Contributor

Summary

Fixes #5845 - Goose randomly becomes unresponsive when using GitHub Copilot provider.

This PR addresses two related issues:

  • Streaming error handling in GitHub Copilot provider: Added proper HTTP status code checking before processing streaming responses, error response parsing, and empty response detection. Previously, errors during streaming were silently ignored, causing Goose to appear unresponsive.

  • Image filtering for non-user messages: Many providers (including GitHub Copilot) don't support images in assistant or system messages. Added filtering to:

    • Replace MessageContent::Image in non-user messages with placeholder text
    • Only detect and load embedded images from text paths in user messages (prevents assistant messages mentioning image paths from accidentally loading images)

Changes

  1. crates/goose/src/providers/githubcopilot.rs - Added streaming error handling
  2. crates/goose/src/providers/formats/openai.rs - Added image filtering for non-user messages

Test plan

  • All existing tests pass (24 tests in openai module)
  • Added new tests for image filtering behavior:
    • test_format_messages_filters_images_in_non_user_messages
    • test_format_messages_assistant_text_with_image_path_no_image_loading
  • Manual testing with GitHub Copilot provider:
    1. Start Goose with GitHub Copilot provider
    2. Share an image and ask Goose to process it
    3. Ask follow-up questions involving image processing
    4. Ask unrelated questions - previously would fail with "image urls not allowed in non-user messages"
    5. Verified errors are now properly surfaced to the user instead of silent hangs

🤖 Generated with Claude Code

@albina-popova albina-popova force-pushed the fix/github-copilot-error-handling-5845 branch from 99ee20a to 669f6e9 Compare December 20, 2025 15:59
…es from non-user messages

Fixes block#5845 - Goose randomly becomes unresponsive when using GitHub Copilot provider.

This commit addresses two related issues:

1. Streaming error handling in GitHub Copilot provider:
   - Added proper HTTP status code checking before processing streaming responses
   - Added error response parsing to surface meaningful error messages
   - Added empty response detection

2. Image filtering for non-user messages:
   - Replace MessageContent::Image in non-user messages with placeholder text
   - Only detect and load embedded images from text paths in user messages
   - Prevents "image urls not allowed in non-user messages" errors

Added tests:
- test_format_messages_filters_images_in_non_user_messages
- test_format_messages_assistant_text_with_image_path_no_image_loading

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: albina-popova <97168987+albina-popova@users.noreply.github.com>
@albina-popova albina-popova force-pushed the fix/github-copilot-error-handling-5845 branch from 669f6e9 to 70d964e Compare December 20, 2025 16:14
Copy link
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

sorry for the delay in responding. can you check on the error handling and whether we can use the generalized handler there?

})
}

#[allow(clippy::too_many_lines)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's not

"GitHub Copilot API returned status {}: {}",
status, error_msg
)));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use handle_status_openai_compat here instead?

content_array.push(json!({"type": "text", "text": text.text}));
content_array.push(convert_image(&image, image_format));
// Only detect and load embedded images from text in user messages
// Many providers don't support images in assistant or system messages
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is the right thing to do, but not for this reason (only) - the whole extracting images from user messages is an outdated hack that should just never be randomly applied to assistant messages. can you drop the comment?

@zanesq
Copy link
Collaborator

zanesq commented Jan 26, 2026

@albina-popova mind merging in main and taking a look at the comments and we'll get it merged in!

@DOsinga
Copy link
Collaborator

DOsinga commented Jan 28, 2026

thanks for doing this. in order to move this along, I've copied over the changes and applied comments to: https://github.com/block/goose/pull/6771/changes which I will get merged soon. closing this one!

@DOsinga DOsinga closed this Jan 28, 2026
@albina-popova
Copy link
Contributor Author

@DOsinga apologies for a delay and thank you!

@DOsinga
Copy link
Collaborator

DOsinga commented Jan 28, 2026

no worries - it just struck me that in days of agents if I have a trivial change request for your PR and you have a merge conflict, I can just tell goose what I want changed and do the merge etc

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.

goose randomly stops responding

3 participants

Comments