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

RunnableRetry.Batch/Abatch Can Return Corrupted Outputs When Some Items Succeed On Retry And Others Still Fail

When using RunnableRetry.batch() with return_exceptions=True, a mix of immediately successful, retry-then-successful, and permanently failing inputs can lead to outputs being placed at incorrect indices, causing a failing item to be replaced by a successful item's output.

highConfidence 85%LangchainAgentsVector StoresAffected V1.2.16

Origin Analysis

The `_batch_with_retry` method in `langchain_core.runnables.retry.RunnableRetry` builds results as a flat list by appending successful outputs from each retry attempt and then appending any remaining exceptions at the end. It does not maintain a mapping from retry subsets back to the original input indices. When a batch contains a combination of immediate successes, eventual successes after retry, and permanent failures, the outputs are misaligned, and a failed input can receive the output of a different input that succeeded on retry.
Run the provided Python snippet with langchain-core 1.2.16. The batch returns [ok-result, retry-result] with the third element incorrectly being retry-result instead of an Exception, or otherwise misassigns positions.

Fixing Code Block

Edge Case Audit

This change alters the internal ordering and storage of batch results. While it fixes the reported corruption, it assumes `self._sleep` exists and behaves as in the current codebase. Rollback is straightforward by reverting to the original `_batch_with_retry` implementation, but that reintroduces the corruption bug. The async `abatch` path likely has the same issue and should be patched symmetrically. Multi-threaded or concurrent executions that share the retry state (e.g., global variables inside the runnable) may still produce non-deterministic outputs; users should avoid mutable shared state in retried functions. Test thoroughly with duplicate inputs, empty batches, and inputs that raise non-retryable exceptions.

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