fix: prevent None corruption in agent state when outputs_to_state source key is absent#10987
Closed
IgnazioDS wants to merge 2 commits intodeepset-ai:mainfrom
Closed
fix: prevent None corruption in agent state when outputs_to_state source key is absent#10987IgnazioDS wants to merge 2 commits intodeepset-ai:mainfrom
IgnazioDS wants to merge 2 commits intodeepset-ai:mainfrom
Conversation
|
@IgnazioDS is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
|
Contributor
|
@IgnazioDS thanks for jumping on this so quickly, but this was an issue we wanted to handle internally and did so in this PR #10990 so I'll be closing this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10981.
When a tool's result dict does not contain a key referenced by
outputs_to_state,result.get(source_key)silently returnsNone. ThatNonethen flows intostate.set(), and when the state field uses themerge_listshandler it gets wrapped into[None], corrupting the state list with a spuriousNoneentry.Root cause (two layers)
_merge_tool_outputs(haystack/components/tools/tool_invoker.py) — no guard onoutput_value is Nonebefore callingstate.set().merge_lists(haystack/components/agents/state/state_utils.py) —new if isinstance(new, list) else [new]wrapsNoneinto[None]instead of treating absent output as a no-op.Fix
tool_invoker.py— skipstate.set()when the tool didn't produce the mapped output:state_utils.py— treatNoneas "nothing to merge":Both layers are needed: the
tool_invokerfix is the primary guard; themerge_listsfix makes the function robust as a standalone utility.Test plan
outputs_to_statemaps a key that may be absent from the result dict — confirm state no longer containsNoneentriesmerge_liststests passmerge_lists(["a"], None)returns["a"](not["a", None])merge_lists(None, None)returns[]