Skip to content

fix: warm child Toolset before flattening in Toolset.add()#12036

Closed
mahesh-sadupalli wants to merge 1 commit into
deepset-ai:mainfrom
mahesh-sadupalli:fix/toolset-add-lazy-warmup
Closed

fix: warm child Toolset before flattening in Toolset.add()#12036
mahesh-sadupalli wants to merge 1 commit into
deepset-ai:mainfrom
mahesh-sadupalli:fix/toolset-add-lazy-warmup

Conversation

@mahesh-sadupalli

Copy link
Copy Markdown

Fixes #12009

Summary

Toolset.add() silently dropped all tools when a lazy child Toolset (one that materialises its tools in warm_up()) was added to a parent that had not yet been warmed up.

The guard was:

if self._is_warmed_up and hasattr(tool, "warm_up"):
    tool.warm_up()

new_tools = [tool] if isinstance(tool, Tool) else list(tool)

Because self._is_warmed_up was False for a cold parent, the child was never warmed before list(tool) flattened it. The list was empty and the tools were silently lost — no exception raised.

Fix: warm every child Toolset unconditionally before flattening. The child's warm_up() is idempotent, so calling it on an already-warm child is safe. Plain Tool objects retain the existing behaviour: warmed immediately only when the parent is already warm.

if isinstance(tool, Toolset):
    # Always warm a child Toolset before flattening so lazily-loaded tools
    # are available regardless of whether the parent has been warmed yet.
    tool.warm_up()
elif self._is_warmed_up and hasattr(tool, "warm_up"):
    tool.warm_up()

Tests

Three regression tests added to TestToolsetWarmUp:

Test Covers
test_add_lazy_toolset_to_cold_parent_retains_tools Main bug: lazy child added to cold parent retains its tools
test_add_lazy_toolset_warm_up_is_idempotent Already-warm child added to warm parent is not warmed again
test_add_plain_tool_to_cold_parent_does_not_warm_it Regression guard: plain Tool added to cold parent is still not warmed eagerly

All 34 tests in test/tools/test_toolset.py pass.

When a lazy Toolset (one that materialises its tools in warm_up()) was
added to a cold parent with add(), the guard on warm_up() was:

    if self._is_warmed_up and hasattr(tool, 'warm_up'):
        tool.warm_up()

So the child was never warmed before list(tool) flattened it. The
resulting list was empty and the tools were silently dropped.

Fix: warm every child Toolset before flattening unconditionally. The
child's warm_up() is idempotent, so calling it on an already-warm
child is safe. Plain Tool objects retain the existing behaviour: they
are only warmed immediately when the parent is already warm.

Three regression tests are added:
- lazy child added to cold parent retains its tools
- warm child added to warm parent is not warmed again (idempotency)
- plain Tool added to cold parent is still not warmed eagerly

Fixes: deepset-ai#12009
Signed-off-by: Mahesh Sadupalli <mahesh.sadupalli@gmail.com>
@mahesh-sadupalli
mahesh-sadupalli requested a review from a team as a code owner July 16, 2026 20:07
@mahesh-sadupalli
mahesh-sadupalli requested review from julian-risch and removed request for a team July 16, 2026 20:07
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

@mahesh-sadupalli 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.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @mahesh-sadupalli, 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.

@github-actions
github-actions Bot removed the request for review from julian-risch July 16, 2026 21:12
@github-actions github-actions Bot added the cla-pending PR is in draft until the contributor signs the CLA label Jul 16, 2026
@sjrl

sjrl commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Closing as duplicate of #12012

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:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toolset.add() silently drops tools from lazy Toolsets before parent warm-up

3 participants