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

With_retry().Batch() Returns Another Input'S Result When Only Some Inputs Recover On Retry

When using RunnableRetry with batch, if one input recovers after a retry while another input continues failing, the failing input's slot is incorrectly assigned the recovered input's output instead of the exception. This leads to silent wrong results when return_exceptions=False.

highConfidence 95%Langchain-CoreMemorylangchain-coreRetrieversAffected V1.6.9

Origin Analysis

In RunnableRetry._batch and _abatch, after the final attempt, any input not present in results_map is filled by popping from the last attempt's result list. However, that list contains outputs for inputs that succeeded on the final attempt (which are already in results_map), so a failed input can mistakenly receive a neighbor's success. The code does not track the latest exception per original input index.
Run the provided reproduction code: define a flaky function where input 'a' fails once then succeeds, input 'b' always fails, and input 'c' succeeds. Call runnable.batch(['a','b','c'], return_exceptions=True). Observed output is ['A', 'A', 'C'] instead of ['A', ValueError('b always fails'), 'C']. The same wrong output appears without return_exceptions and in abatch.

Fixing Code Block

Edge Case Audit

This change may surface exceptions that were previously silently masked when return_exceptions=False, which could break workflows relying on incorrect outputs. The async version introduces no shared mutable state beyond the local maps, so concurrency safety is preserved. Rollback: if this fix causes unexpected behavior, revert to the previous implementation, but be aware that wrong outputs will recur. Affected versions: 1.6.9 and earlier with with_retry batch methods. Upgrade to a version containing this fix is recommended.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state