-
Notifications
You must be signed in to change notification settings - Fork 20.2k
fix(core): defer persisting traces for iterator inputs #34416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CodSpeed Performance ReportMerging #34416 will not alter performanceComparing
|
There was a problem hiding this 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_inputsflag - Modified
RunnableGenerator.transform()andRunnableGenerator.atransform()to passdefers_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.
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.