mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-22 17:50:03 +00:00
Description: Fixes a bug in RunnableRetry where .batch / .abatch could return misordered outputs (e.g. inputs [0,1,2] yielding [1,1,2]) when some items succeeded on an earlier attempt and others were retried. Root cause: successful results were stored keyed by the index within the shrinking “pending” subset rather than the original input index, causing collisions and reordered/duplicated outputs after retries. Fix updates _batch and _abatch to: - Track remaining original indices explicitly. - Call underlying batch/abatch only on remaining inputs. - Map results back to original indices. - Preserve final ordering by reconstructing outputs in original positional order. Issue: Fixes #21326 Tests: - Added regression tests: test_retry_batch_preserves_order and test_async_retry_batch_preserves_order asserting correct ordering after a single controlled failure + retry. - Existing retry tests still pass. Dependencies: - None added or changed. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>