Skip to content

fix(super_component): only expose run_async when wrapped pipeline is AsyncPipeline#11194

Open
alvinttang wants to merge 1 commit intodeepset-ai:mainfrom
alvinttang:fix/super-component-async-only-when-async-pipeline
Open

fix(super_component): only expose run_async when wrapped pipeline is AsyncPipeline#11194
alvinttang wants to merge 1 commit intodeepset-ai:mainfrom
alvinttang:fix/super-component-async-only-when-async-pipeline

Conversation

@alvinttang
Copy link
Copy Markdown

Summary

SuperComponent declared async def run_async(...) at the class level, so ComponentMeta.__call__'s post-__init__ hasattr(instance, \"run_async\") check set __haystack_supports_async__ = True for every instance — including those wrapping a sync Pipeline. Two visible failures resulted:

  1. Calling wrapper.run_async(...) on a sync-pipeline-backed SuperComponent raised TypeError: Pipeline is not an AsyncPipeline....
  2. Putting such a SuperComponent inside an outer AsyncPipeline made AsyncPipeline._run_component_async dispatch to run_async, and the whole outer pipeline crashed with PipelineRuntimeError.

Fixes #9435

Fix

haystack/core/super_component/super_component.py:

  • Renamed the class-level method from run_async to _run_async. The metaclass no longer sees a class-level run_async and therefore no longer marks every SuperComponent as async-capable.
  • __init__ binds self.run_async = self._run_async per-instance only when isinstance(pipeline, AsyncPipeline). Sync-pipeline-backed instances simply do not have a run_async attribute.
  • Added a TYPE_CHECKING stub for run_async so the static typing surface (used by the existing tests and downstream users) is preserved while the runtime attribute is bound lazily.

Test

test/core/super_component/test_super_component.py:

  • test_sync_pipeline_does_not_advertise_async_support__haystack_supports_async__ is False and run_async attribute is absent.
  • test_async_pipeline_advertises_async_support — positive control.
  • test_super_component_with_sync_pipeline_inside_async_pipeline — the regression scenario, runs outer.run_async(...) and verifies it succeeds.

All three RED before the patch, GREEN after. Existing tests test_super_component_run_async and test_super_component_async_serialization_deserialization still pass.

Locally on darwin/arm64:

  • pytest test/core/super_component/ test/core/component/ → 123 passed.
  • Three pre-existing failures in test_pipeline_base.py (test_show_in_notebook, test_find_super_components, test_merge_super_component_pipelines) are unrelated and reproduce on main without this patch.

Risk notes

hasattr(super_component, \"run_async\") now returns False for sync-pipeline-backed SuperComponents. Any caller that previously hit the broken run_async (which always raised TypeError) will now hit AttributeError instead — strictly an improvement. The @super_component decorator path goes through _SuperComponent.__init__ so it inherits the fix automatically.

A SuperComponent wrapping a synchronous Pipeline used to advertise async
support because run_async was defined on the class. As a result:

- Calling run_async on such a SuperComponent raised
  TypeError('Pipeline is not an AsyncPipeline. run_async is not supported.')
- Adding such a SuperComponent to an outer AsyncPipeline made the outer
  pipeline route to run_async and crash with the same error, since
  AsyncPipeline._run_component_async dispatches based on
  __haystack_supports_async__.

run_async is now bound on the instance only when the wrapped pipeline is
an AsyncPipeline, so hasattr(super_component, 'run_async') and
__haystack_supports_async__ correctly reflect the wrapped pipeline.

Closes deepset-ai#9435
@alvinttang alvinttang requested a review from a team as a code owner April 25, 2026 12:47
@alvinttang alvinttang requested review from julian-risch and removed request for a team April 25, 2026 12:47
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 25, 2026

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

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


alvinttang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@julian-risch
Copy link
Copy Markdown
Member

Hi @alvinttang Thank you for opening this PR. We need you to agree to the CLA please. In particular, this commit was not done by a GitHub user: 73be582 Could you fix that please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_SuperComponent always define run_async even when the underlying Pipeline is sync

3 participants