AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

AddableDict Silently Drops Data On Type-Incompatible Merge (Langchain_core.Runnables.Utils)

Merging two AddableDict instances with different value types for the same key silently discards the left-hand value and replaces it with the right-hand value, potentially causing hidden data loss in LCEL stream aggregation.

highConfidence 95%LangchainAffected V1.4.9

Origin Analysis

AddableDict.__add__ catches TypeError when evaluating chunk[key] + other[key] and falls back to other[key] without re-raising or validating, treating incompatible types as if the right operand should override the left. This hides type errors and discards data.
1. Install langchain-core 1.4.9. 2. Run: from langchain_core.runnables.utils import AddableDict a = AddableDict({'count': 1}) b = AddableDict({'count': 'some_string'}) result = a + b print(result) 3. Expected: a clear TypeError or a correct merge. 4. Actual: no error; result is {'count': 'some_string'}, and the integer 1 is silently lost.

Fixing Code Block

Edge Case Audit

This change is intentionally breaking: code that relies on the old behavior where a mismatched type was silently overwritten by the right-hand value will now raise TypeError. Before upgrading, audit all places where AddableDict is used (especially RunnablePassthrough and LCEL streaming aggregation) for keys that may legitimately have mixed types (e.g., optional fields that switch from None to int across chunks); normalize upstream if needed. Rollback guidance: if this causes regressions, downgrade langchain-core to the last version before the fix, or introduce a configurable merge strategy that preserves the fallback for specific keys. Also verify __radd__ with non-dict left operands; current implementation assumes dict-like iteration and may need additional guards.

Ecosystem Topology