Skip to content

Conversation

@dingyi222666
Copy link
Member

Summary

This PR improves error handling across all adapters when image fetching fails, ensuring that broken or inaccessible image URLs don't break message processing.

Bug fixes

  • Image fetch failures no longer break message processing: Returns null from image processing functions when fetch errors occur
  • Graceful degradation: Failed image content entries are filtered out, allowing chats to continue with text content
  • Consistent error handling: Added try-catch blocks around image URL fetching in Claude, Gemini, Ollama, Qwen, and Zhipu adapters
  • Hunyuan async handling: Converted langchainMessageToHunyuanMessage to async to properly handle image processing

Other Changes

  • Filter null values from processed content arrays across all adapters
  • Improved logging to use rawUrl variable instead of potentially undefined url
  • Better type safety with explicit null filtering in image content arrays

Improve error handling across all adapters when fetching images fails.
Changes ensure that failed image operations don't break message processing:

- Return null from image processing functions on fetch errors
- Filter out null values from processed content arrays
- Convert langchainMessageToHunyuanMessage to async for image processing
- Add try-catch blocks around image URL fetching in all adapters
- Remove image content entries when fetch fails instead of falling back

This allows the chat to continue with text content even if image fetching fails,
improving robustness when dealing with broken or inaccessible image URLs.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

Walkthrough

跨多个适配器包的图像URL处理改进。包括更好的错误处理(记录构建的rawUrl而非未定义变量)、过滤空值结果、改用Promise.all进行并行处理,以及在Hunyuan适配器中引入异步图像获取。

Changes

内聚体 / 文件 变更摘要
Claude适配器
packages/adapter-claude/src/utils.ts
图像获取失败时记录rawUrl并返回null;processMessageContent现在过滤掉null条目
Gemini适配器
packages/adapter-gemini/src/utils.ts
构建rawUrl处理字符串或对象形式;显式过滤掉null条目后返回
Hunyuan适配器
packages/adapter-hunyuan/src/requester.ts, packages/adapter-hunyuan/src/utils.ts
langchainMessageToHunyuanMessage改为异步,新增plugin参数;通过plugin异步获取图像URL,使用Promise.all并过滤失败
Ollama适配器
packages/adapter-ollama/src/utils.ts
过滤images字段中的null/undefined;失败时计算rawUrl并返回null
Qwen适配器
packages/adapter-qwen/src/utils.ts
添加MessageContentImageUrl导入;使用Promise.all并行处理图像URL;过滤失败结果
Zhipu适配器
packages/adapter-zhipu/src/utils.ts
添加MessageContentImageUrl导入;图像URL通过fetchImageUrl展开;使用Promise.all并过滤失败
共享适配器
packages/shared-adapter/src/utils.ts
用并行fetchImageUrl替代迭代处理;失败时返回null并过滤;使用Promise.all和spread语法

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Whiskers twitch with glee!
Images now fetch with grace,
Null entries flee and hide,
Promise.all races them with pride,
My gardens grow more fair! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: graceful handling of image fetch failures across adapters, which is the primary focus of this changeset.
Description check ✅ Passed The description is directly related to the changeset, detailing the bug fixes, improvements to error handling, and modifications across multiple adapter files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/adapter-image-read

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dingyi222666, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the resilience of the system's various adapters by introducing robust error handling mechanisms for image fetching operations. By ensuring that image fetch failures do not halt message processing and instead allow for graceful degradation, the changes improve the overall stability and user experience. The update also standardizes error handling practices and refines asynchronous operations where image processing is involved.

Highlights

  • Robust Image Fetching Error Handling: Implemented try-catch blocks across multiple adapters (Claude, Gemini, Ollama, Qwen, Zhipu, Shared) to gracefully handle failures when fetching image URLs.
  • Graceful Degradation: Image processing functions now return 'null' upon fetch errors, and subsequent content arrays are filtered to remove these 'null' entries, ensuring message processing continues with available text content.
  • Asynchronous Image Processing for Hunyuan: The 'langchainMessageToHunyuanMessage' function was converted to an asynchronous operation to properly integrate 'fetchImageUrl' and handle potential image processing delays or failures.
  • Improved Logging and Type Safety: Enhanced error logging to use 'rawUrl' for better context and introduced explicit null filtering for image content arrays to improve type safety.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves error handling for image fetching across various adapters, preventing crashes when an image URL is inaccessible. However, by systematically moving image fetching from LLM providers to the server side, it introduces Server-Side Request Forgery (SSRF) vulnerabilities in the OpenAI, Hunyuan, Qwen, and Zhipu adapters, as user-provided URLs are fetched without validation. It is highly recommended to implement URL validation (e.g., restricting to public IPs and allowed protocols) before performing network requests on the server. Furthermore, error logging was missed in some new try-catch blocks, which should be added to improve diagnostics and ensure all image fetch failures are visible.

@dingyi222666 dingyi222666 merged commit 6545a47 into v1-dev Jan 28, 2026
4 of 5 checks passed
@dingyi222666 dingyi222666 deleted the fix/adapter-image-read branch January 28, 2026 15:01
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.

1 participant