Skip to content

fix: convert images off the event loop in LLMDocumentContentExtractor.run_async - #12359

Open
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/llm-content-extractor-async-image-conversion
Open

fix: convert images off the event loop in LLMDocumentContentExtractor.run_async#12359
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/llm-content-extractor-async-image-conversion

Conversation

@pcbeingused333

Copy link
Copy Markdown

Related Issues

  • No issue; found while reading the component.

Proposed Changes:

LLMDocumentContentExtractor.run_async converts the documents to images with a direct call:

image_contents = self._document_to_image_content.run(documents=documents)["image_contents"]

DocumentToImageContent reads every file from disk, renders the requested page of each PDF and base64-encodes the result, and it implements no run_async. So the whole batch is converted on the event loop before the first LLM call is even scheduled, and anything else sharing that loop waits for it.

The module already imports _execute_component_async and uses it for the chat generator, which is exactly the helper for this: it prefers run_async when a component has one and otherwise runs run in a thread. This change routes the conversion through it. If DocumentToImageContent grows a run_async later, this call site picks it up for free.

run is untouched.

How did you test it?

  • New unit test test_run_async_converts_images_off_the_event_loop: patches DocumentToImageContent.run to record the thread it executes on and asserts it is not the thread running the event loop. It fails on main, where the conversion runs on the main thread.
  • hatch run test:unit — 6116 passed, 10 skipped.
  • hatch run test:types and hatch run fmt clean.

Notes for the reviewer

I looked for the same pattern across the components with a run_async and this was the one remaining call that does blocking I/O; the other direct run calls in async methods are prompt builders, which are pure CPU and cheap.

I used an AI assistant while writing this change. I have reviewed it, reproduced the behaviour, and run the tests.

Checklist

….run_async

`run_async` calls `DocumentToImageContent.run` directly. That component reads
each file from disk, renders the requested page of every PDF and base64-encodes
the result, and it implements no `run_async` - so the whole batch is converted on
the event loop before the first LLM call is even scheduled. Everything else
sharing that loop waits.

Route it through `_execute_component_async`, which this module already imports
and uses for the chat generator: it prefers `run_async` when a component has one
and otherwise runs `run` in a thread.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner August 15, 2026 01:22
@pcbeingused333
pcbeingused333 requested review from bogdankostic and removed request for a team August 15, 2026 01:22
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Aug 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @pcbeingused333, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 3 open pull requests in this repository (#12358, #12357 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @pcbeingused333, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from bogdankostic August 15, 2026 02:37
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Aug 15, 2026
@HaystackBot
HaystackBot marked this pull request as draft August 15, 2026 02:37
@pcbeingused333

Copy link
Copy Markdown
Author

recheck

1 similar comment
@pcbeingused333

Copy link
Copy Markdown
Author

recheck

@pcbeingused333
pcbeingused333 marked this pull request as ready for review August 15, 2026 04:12
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @pcbeingused333! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants