Skip to content

fix(multimodal): detect data: URIs as DataUrl in tracker - #493

Merged
slin1237 merged 3 commits into
mainfrom
chang/mm-2
Feb 21, 2026
Merged

slin1237 merged 3 commits into
mainfrom
chang/mm-2

Conversation

@CatherineSue

@CatherineSue CatherineSue commented Feb 21, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

When a user sends an image via a data: URI (base64 inline image) through the image_url field in a chat message, the multimodal tracker incorrectly classifies it as MediaSource::Url and attempts to fetch it as a remote URL. This causes the request to fail since data: URIs are not valid HTTP endpoints.

Solution

Add a check in AsyncMultiModalTracker to detect data: URI prefixes in the image_url path and route them to MediaSource::DataUrl instead of MediaSource::Url.

Changes

  • In tracker.rs, added data: prefix detection in the ImageUrl handler to correctly dispatch to MediaSource::DataUrl

Test Plan

Tested with a chat completion request containing a base64-encoded image in image_url.url:

{
  "type": "image_url",
  "image_url": { "url": "data:image/png;base64,iVBOR..." }
}

Verified the image is decoded inline rather than triggering an HTTP fetch.

Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of image references in multimodal content to correctly recognize and treat embedded data URLs separately from external links.
    • Results in more reliable image enqueuing and rendering across varied content sources, reducing missed or misinterpreted images and improving overall media reliability.

@github-actions github-actions Bot added the multimodal Multimodal crate changes label Feb 21, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @CatherineSue, 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 addresses a critical bug where base64-encoded images provided as data: URIs within chat messages were erroneously processed as external URLs. The fix ensures that these inline images are now properly recognized and handled, resolving request failures and improving the robustness of multimodal chat completions.

Highlights

  • Data URI Handling: Implemented logic within AsyncMultiModalTracker to correctly identify data: URIs in image_url fields and classify them as MediaSource::DataUrl, preventing incorrect attempts to fetch them as remote URLs.
Changelog
  • multimodal/src/tracker.rs
    • Added a conditional check to distinguish data: URIs from standard URLs when processing ChatContentPart::ImageUrl.
Activity
  • No specific activity has been recorded for this pull request yet.
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. ↩

@coderabbitai

coderabbitai Bot commented Feb 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

AsyncMultiModalTracker::push_part now distinguishes data URLs from regular URLs for image parts by parsing the URL and mapping to MediaSource::DataUrl(url) or MediaSource::Url(url) before calling enqueue_image.

Changes

Cohort / File(s) Summary
Image URL Handling
multimodal/src/tracker.rs
In ChatContentPart::ImageUrl handling, parse the provided URL and map to MediaSource::DataUrl(url) when the scheme is a data URL, otherwise MediaSource::Url(url); pass the chosen variant to enqueue_image.
Media enum
multimodal/src/media.rs
Added public enum variant DataUrl(String) to MediaSource to represent data URLs separately from regular URLs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop through bytes and sniff each link,

If "data:" I find, I give a wink.
I sort the images, neat and true,
Data or web — I know what to do.
Tracker taps a rhythm, quick and pink.

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: detecting data: URIs and routing them to DataUrl in the multimodal tracker.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chang/mm-2

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

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

Copy link
Copy Markdown
Contributor

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 addresses an issue where data: URIs were incorrectly handled as remote URLs. The fix introduces a check to identify data: URIs and classify them as MediaSource::DataUrl, which is the correct approach. I have one suggestion to make this detection more robust by using the url crate for parsing instead of a simple prefix check. This will improve correctness by properly handling various URL formats and edge cases.

Comment thread multimodal/src/tracker.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@multimodal/src/tracker.rs`:
- Around line 74-78: The current check uses url.starts_with("data:") which is
case-sensitive and can misclassify valid RFC 2397 data URLs; update the branch
that builds the MediaSource (the code that sets source for the url variable) to
perform a case-insensitive prefix check (e.g., verify url has at least 5 chars
and use an ASCII case-insensitive comparison like eq_ignore_ascii_case("data:")
on the first 5 chars) so that MediaSource::DataUrl(...) is chosen for any case
variant of "data:" and otherwise fall back to MediaSource::Url(...).

Comment thread multimodal/src/tracker.rs Outdated
Problem: When an image_url content part contains a data: URI (e.g.
"data:image/jpeg;base64,..."), the tracker treated it as a regular URL
and attempted an HTTP fetch, which fails.

Fix: Check if the URL starts with "data:" and route to
MediaSource::DataUrl instead of MediaSource::Url.
Signed-off-by: Chang Su <chang.s.su@oracle.com>
Signed-off-by: Chang Su <chang.s.su@oracle.com>
Replace manual prefix check with url::Url::parse() scheme check.
This correctly handles edge cases like relative URLs starting with
"data:" and is more idiomatic since the url crate is already a dependency.

Signed-off-by: Chang Su <chang.s.su@oracle.com>
@slin1237
slin1237 merged commit 065c7d6 into main Feb 21, 2026
22 checks passed
@slin1237
slin1237 deleted the chang/mm-2 branch February 21, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multimodal Multimodal crate changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants