Skip to content

Conversation

@hntrl
Copy link
Member

@hntrl hntrl commented Dec 18, 2025

ref langchain-ai/langchainjs#9665

Fixes trace persistence for iterator/generator inputs (like RunnableGenerator) where the full input isn't available at chain start. Instead of POSTing a run with incomplete inputs on start and PATCHing later, this defers the POST until chain end when inputs are fully realized.

@hntrl hntrl requested a review from eyurtsev as a code owner December 18, 2025 06:57
@github-actions github-actions bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix labels Dec 18, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 18, 2025

CodSpeed Performance Report

Merging #34416 will not alter performance

Comparing hunter/lct-deferred-inputs (6e545f0) with master (795e746)

⚠️ 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
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@hntrl hntrl requested a review from mdrxy December 18, 2025 19:29
@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Dec 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes trace persistence for iterator/generator inputs (like RunnableGenerator) by deferring the POST request until chain end when inputs are fully realized. Instead of POSTing a run with incomplete inputs on start and PATCHing later, it now skips the initial POST when defers_inputs=True is set and performs a single POST at completion.

Key changes:

  • Added conditional logic to defer trace persistence based on the defers_inputs flag
  • Modified RunnableGenerator.transform() and RunnableGenerator.atransform() to pass defers_inputs=True
  • Added comprehensive test coverage for the deferred inputs behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
libs/core/langchain_core/tracers/langchain.py Modified _on_chain_start, _on_chain_end, and _on_chain_error to check for defers_inputs flag and conditionally persist or update runs
libs/core/langchain_core/runnables/base.py Updated _transform_stream_with_config and _atransform_stream_with_config to extract and pass defers_inputs parameter, and modified RunnableGenerator.transform() and atransform() to pass defers_inputs=True
libs/core/tests/unit_tests/tracers/test_langchain.py Added six new test functions covering deferred and non-deferred input scenarios for chain start, end, and error cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mdrxy mdrxy merged commit 9225bff into master Dec 19, 2025
98 checks passed
@mdrxy mdrxy deleted the hunter/lct-deferred-inputs branch December 19, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs fix For PRs that implement a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants