Skip to content

fix: allow multi-connection to Any-typed pipeline sockets - #12362

Closed
Harsh23Kashyap wants to merge 1 commit into
deepset-ai:mainfrom
Harsh23Kashyap:fix/pipeline-any-typed-multi-connection
Closed

fix: allow multi-connection to Any-typed pipeline sockets#12362
Harsh23Kashyap wants to merge 1 commit into
deepset-ai:mainfrom
Harsh23Kashyap:fix/pipeline-any-typed-multi-connection

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

Related Issues

  • fixes deepset-ai/haystack-private#556

Proposed Changes:

Pipeline.connect rejected a second connection to an Any-typed input socket (e.g. PromptBuilder.documents, where every template variable is registered as Any via component.set_input_type(self, var, Any)) with a PipelineConnectError:

PipelineConnectError: Component 'prompt_builder' cannot accept multiple inputs to 'documents'. It is already connected to component 'retriever_1', and it can only accept inputs from multiple senders if its type is list, Optional[list], or union of list types.

This was the gap left after #10783. The merged PR's commit message explicitly claimed Any-type support ("We now allow a component's whose input type is typed as Any to allow multiple input connections as long as the input connections are all of type list"), but the actual _make_socket_auto_variadic only handled list / Optional[list] / union-of-list receivers — the Any case fell through to the raise error_type(...) branch. (The same branch that produced the error message above.)

The fix is one new branch in _make_socket_auto_variadic: when the receiver socket's type is Any, mark the socket is_lazy_variadic = True and leave wrap_input_in_list at the default True. The framework has no element-type information for Any, so it cannot safely flatten one level; the component receives [sender_1, sender_2, ...] and decides how to handle the type-erased inputs (a PromptBuilder-style component can flatten in its own run() if it always aggregates lists of lists).

This is the connection-eligibility half of deepset-ai/haystack-private#556. The rendering-side aggregation (flattening [[d1, d2], [d3, d4]] to a flat list in PromptBuilder.run()) is a natural follow-up — I left it out of this PR to keep the scope minimal: the framework now allows the multi-connection that the issue is fundamentally about, and a component that knows the intent can flatten internally.

How did you test it?

  • Direct unit test: TestMakeSocketAutoVariadic.test_successful_any_typed_socket — the new Any branch is exercised with the exact InputSocket(name="documents", type=Any, senders=["retriever_1"]) shape that PromptBuilder produces. Asserts is_variadic, is_lazy_variadic, and that wrap_input_in_list stays True (the safe default for an unknown element type).
  • End-to-end test: TestAnyTypedMultiConnection.test_prompt_builder_documents_accepts_multiple_retrievers — spins up a real InMemoryDocumentStore, two InMemoryBM25Retrievers, and a PromptBuilder, then asserts both connect calls succeed. This is the exact reproducer from the issue.
  • Updated TestValidateInput.test_validate_multiple_connections_to_non_variadic_input regex to match the extended error message ("or Any" appended).
  • The pre-existing TestMakeSocketAutoVariadic cases (list / union-of-lists / Optional[list]) all still pass — the new Any branch is added before the existing dispatch, not in place of it.
  • Full test/core/pipeline/ suite: 416 passed, no regressions. Broader test/core/ + test/components/builders/ (which exercises the component side of multi-connection): 1904 passed, no regressions. hatch run fmt clean. hatch run test:types reports 17 pre-existing errors in 9 unrelated files (azure, openai_counter, etc.) — confirmed pre-existing via git stash of this branch.

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the release note (reno note in releasenotes/notes/)
  • I have run hatch run fmt and hatch run test:types locally
  • 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
  • Any dependent changes have been merged and published in downstream modules

`Pipeline.connect` rejected a second connection to an `Any`-typed input
socket (e.g. `PromptBuilder.documents`, where every template variable is
registered as `Any` via `component.set_input_type(self, var, Any)`) with a
`PipelineConnectError`. The previous behaviour was the gap left after
deepset-ai#10783 — its commit message claimed `Any`-type support, but
`_make_socket_auto_variadic` only handled `list`, `Optional[list]`, and
union-of-list receivers.

The fix adds a dedicated branch for `Any`-typed receivers: when the second
connection arrives, the socket is marked lazy variadic. The framework has
no element-type information for an `Any`, so `wrap_input_in_list` is
left at the default `True` and the receiver gets `[sender_1, sender_2,
...]` at runtime — a list of the per-sender values. The component decides
how to handle the type-erased inputs (e.g. `PromptBuilder` can flatten the
list of lists in its own `run()` if desired).

Tests: added `TestMakeSocketAutoVariadic.test_successful_any_typed_socket`
(direct unit test on the new branch) and
`TestAnyTypedMultiConnection.test_prompt_builder_documents_accepts_multiple_retrievers`
(end-to-end via `PromptBuilder`). Updated the error message regex in
`TestValidateInput.test_validate_multiple_connections_to_non_variadic_input`
to match the extended message ("or Any" appended).

This is the connection-eligibility half of #10721; rendering-side
aggregation (e.g. flattening inside `PromptBuilder`) is a natural
follow-up since `Any` carries no list-element type to flatten against.

Fixes #10721
@Harsh23Kashyap
Harsh23Kashyap requested a review from a team as a code owner August 15, 2026 07:15
@Harsh23Kashyap
Harsh23Kashyap requested review from julian-risch and removed request for a team August 15, 2026 07:15
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

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

⚠️ You currently have 3 open pull requests in this repository (#12356, #12339 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.

@CLAassistant

CLAassistant commented Aug 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Harsh23Kashyap, 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 julian-risch August 15, 2026 08:29
@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 08:29
@sjrl

sjrl commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@sjrl sjrl closed this Aug 17, 2026
@Harsh23Kashyap
Harsh23Kashyap deleted the fix/pipeline-any-typed-multi-connection branch August 20, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:core topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants