llamaIndex - ✅(Solved) Fix [Bug]: Breaking Change in Message Block Buffer Resolution [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#21338Fetched 2026-04-09 07:51:05
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2closed ×1cross-referenced ×1

Error Message

<_io.BytesIO object at 0x7eff800ccbd0> Traceback (most recent call last): File ".../main.py", line 10, in <module> print(image.resolve_image()) ^^^^^^^^^^^^^^^^^^^^^ File ".../.venv/lib/python3.12/site-packages/llama_index/core/base/llms/types.py", line 392, in resolve_image raise ValueError("resolve_image returned zero bytes") ValueError: resolve_image returned zero bytes

Root Cause

If a block already contains an IOBase buffer, the expected behavior (per #20153) is to return it directly without loading it into memory, which prevents unnecessary overhead. Furthermore, calling the resolve methods twice currently raises a ValueError because the buffer's pointer is never reset to 0.

Fix Action

Fixed

PR fix notes

PR #21339: Fix Breaking Change in Message Block Buffer Resolution

Description (problem / solution / changelog)

Description

This PR reverts the behavior of ImageBlock, AudioBlock, and VideoBlock resolution methods (per #20153) to fix a breaking change introduced in version 0.14.16.

Fixes #21338

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

Changed files

  • llama-index-core/llama_index/core/base/llms/types.py (modified, +3/-18)
  • llama-index-core/tests/base/llms/test_types.py (modified, +6/-0)

Code Example

from io import BytesIO

from llama_index.core.base.llms.types import ImageBlock

buffer = BytesIO(b"hello world")
image = ImageBlock(image=buffer)

for _ in range(2):
    print(image.resolve_image())

---

<_io.BytesIO object at 0x7eff800ccbd0>
Traceback (most recent call last):
  File ".../main.py", line 10, in <module>
    print(image.resolve_image())
          ^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/llama_index/core/base/llms/types.py", line 392, in resolve_image
    raise ValueError("resolve_image returned zero bytes")
ValueError: resolve_image returned zero bytes

---

<_io.BytesIO object at 0x7225d6117d80>
<_io.BytesIO object at 0x7225d6117d80>

---
RAW_BUFFERClick to expand / collapse

Bug Description

PR #20743 introduced a breaking change in how ImageBlock, AudioBlock, and VideoBlock resolve existing buffers.

If a block already contains an IOBase buffer, the expected behavior (per #20153) is to return it directly without loading it into memory, which prevents unnecessary overhead. Furthermore, calling the resolve methods twice currently raises a ValueError because the buffer's pointer is never reset to 0.

ImageBlock, AudioBlock and VideoBlock should be reverted to their previous behavior regarding IOBase buffers.

Version

>=0.14.16

Steps to Reproduce

from io import BytesIO

from llama_index.core.base.llms.types import ImageBlock

buffer = BytesIO(b"hello world")
image = ImageBlock(image=buffer)

for _ in range(2):
    print(image.resolve_image())

With llama-index-core>=0.14.16, it produces:

<_io.BytesIO object at 0x7eff800ccbd0>
Traceback (most recent call last):
  File ".../main.py", line 10, in <module>
    print(image.resolve_image())
          ^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/llama_index/core/base/llms/types.py", line 392, in resolve_image
    raise ValueError("resolve_image returned zero bytes")
ValueError: resolve_image returned zero bytes

With llama-index-core==0.14.15, it produced:

<_io.BytesIO object at 0x7225d6117d80>
<_io.BytesIO object at 0x7225d6117d80>

Relevant Logs/Tracebacks

extent analysis

TL;DR

Revert the changes introduced in PR #20743 to restore the previous behavior of ImageBlock, AudioBlock, and VideoBlock regarding IOBase buffers.

Guidance

  • Identify the specific changes made in PR #20743 and revert them to restore the original behavior of returning the IOBase buffer directly without loading it into memory.
  • Verify that the resolve_image method (and similar methods for AudioBlock and VideoBlock) no longer raises a ValueError when called twice.
  • Test the fix using the provided example code to ensure that it produces the expected output.
  • Consider adding a test case to prevent similar regressions in the future.

Example

from io import BytesIO

from llama_index.core.base.llms.types import ImageBlock

buffer = BytesIO(b"hello world")
image = ImageBlock(image=buffer)

for _ in range(2):
    print(image.resolve_image())

This code should output the IOBase buffer object twice without raising an error.

Notes

The fix assumes that the changes introduced in PR #20743 are the sole cause of the issue. If other factors are involved, additional debugging may be necessary.

Recommendation

Apply workaround: Revert the changes introduced in PR #20743 to restore the previous behavior of ImageBlock, AudioBlock, and VideoBlock regarding IOBase buffers, as this is the most straightforward way to resolve the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING