fix: avoid deepcopy of live State when injecting tool arguments #13980
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 245 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.329
Real PR Conversation Timeline
1 comments
"Review active on #13980"
general
weight: 0.35
1AbdullahButt
What
_inject_state_argsinhaystack/components/agents/tool_calling.pywas reading from state viaState.get(), which returnsdeepcopy(self._data.get(key, default)). Every tool invocation withinputs_from_statetherefore paid an unconditionaldeepcopyof the referenced value, and a non-deepcopyable value (a lock, DB connection, open file, or generator) raisedTypeErrorfrom argument injection rather than from the tool itself.This PR reads through
state.data.get(...)instead, matching the invariant documented inAGENTS.md:Repro
Tests
Two regression tests added to
TestCoreintest/components/agents/test_tool_calling.py:test_inject_state_args_does_not_deepcopy_non_picklable_state_values— asserts athreading.Locksurvives injection by identity.test_inject_state_args_injects_live_state_value_without_copy— asserts a sharedlist[Document]is passed by identity, not copied.Notes
Only the internal injector changes.
State.get()still deepcopies in its public contract, which is the right default for user code reading state; only the internal argument-injection path reads live.