Skip to content

Conversation

VMinB12
Copy link
Contributor

@VMinB12 VMinB12 commented Aug 13, 2025

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.

@VMinB12 VMinB12 requested a review from eyurtsev as a code owner August 13, 2025 11:14
Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 11, 2025 7:55pm

Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed WallTime Performance Report

Merging #32526 will not alter performance

Comparing vincentmin:vmin/fix-retry-batch (ababe7b) with master (5795ec3)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched

Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Instrumentation Performance Report

Merging #32526 will not alter performance

Comparing vincentmin:vmin/fix-retry-batch (ababe7b) with master (bd76575)1

Summary

✅ 14 untouched

Footnotes

  1. No successful run was found on master (5795ec3) during the generation of this report, so bd76575 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mdrxy mdrxy added the core Related to the package `langchain-core` label Aug 13, 2025
@VMinB12
Copy link
Contributor Author

VMinB12 commented Aug 25, 2025

@eyurtsev Did you have a chance to look at this PR by any chance? I feel it is of quite high priority to get this bug fixed. Let me know if you have questions.

@eyurtsev eyurtsev self-assigned this Sep 11, 2025
@eyurtsev
Copy link
Collaborator

Thank you @VMinB12

@eyurtsev eyurtsev merged commit ff9f17b into langchain-ai:master Sep 11, 2025
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in retry runnable when called with batch() / abatch()
3 participants