langchain/libs/core/langchain_core
WU LIFU ad16eed119
core[patch]: runnable config ensure_config deep copy from var_child_runnable… (#24862)
**issue**: #24660 
RunnableWithMessageHistory.stream result in error because the
[evaluation](https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/runnables/branch.py#L220)
of the branch
[condition](99eb31ec41/libs/core/langchain_core/runnables/history.py (L328C1-L329C1))
unexpectedly trigger the
"[on_end](99eb31ec41/libs/core/langchain_core/runnables/history.py (L332))"
(exit_history) callback of the default branch


**descriptions**
After a lot of investigation I'm convinced that the root cause is that
1. during the execution of the runnable, the
[var_child_runnable_config](99eb31ec41/libs/core/langchain_core/runnables/config.py (L122))
is shared between the branch
[condition](99eb31ec41/libs/core/langchain_core/runnables/history.py (L328C1-L329C1))
runnable and the [default branch
runnable](99eb31ec41/libs/core/langchain_core/runnables/history.py (L332))
within the same context
2. when the default branch runnable runs, it gets the
[var_child_runnable_config](99eb31ec41/libs/core/langchain_core/runnables/config.py (L163))
and may unintentionally [add more handlers
](99eb31ec41/libs/core/langchain_core/runnables/config.py (L325))to
the callback manager of this config
3. when it is again the turn for the
[condition](99eb31ec41/libs/core/langchain_core/runnables/history.py (L328C1-L329C1))
to run, it gets the `var_child_runnable_config` whose callback manager
has the handlers added by the default branch. When it runs that handler
(`exit_history`) it leads to the error
   
with the assumption that, the `ensure_config` function actually does
want to create a immutable copy from `var_child_runnable_config` because
it starts with an [`empty` variable
](99eb31ec41/libs/core/langchain_core/runnables/config.py (L156)),
i go ahead to do a deepcopy to ensure that future modification to the
returned value won't affect the `var_child_runnable_config` variable
   
   Having said that I actually 
1. don't know if this is a proper fix
2. don't know whether it will lead to other unintended consequence 
3. don't know why only "stream" runs into this issue while "invoke" runs
without problem

so @nfcampos @hwchase17 please help review, thanks!

---------

Co-authored-by: Lifu Wu <lifu@nextbillion.ai>
Co-authored-by: Nuno Campos <nuno@langchain.dev>
Co-authored-by: Bagatur <baskaryan@gmail.com>
2024-08-01 17:30:32 -07:00
..
_api infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
beta
callbacks Docs: Add how to dispatch custom callback events (#24278) 2024-07-16 17:38:32 -04:00
document_loaders infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
documents core: docstrings documents (#23506) 2024-07-16 10:43:54 -04:00
embeddings core: docstrings documents (#23506) 2024-07-16 10:43:54 -04:00
example_selectors core: docstrings example_selectors (#23542) 2024-06-26 17:10:40 -04:00
graph_vectorstores community[minor]: add document transformer for extracting links (#24186) 2024-07-22 22:01:21 -04:00
indexing core[patch]: Clarify upsert response semantics (#23921) 2024-07-05 15:59:47 -04:00
language_models core[patch], integrations[patch]: convert TypedDict to tool schema support (#24641) 2024-07-31 18:27:24 +00:00
load core: docstrings load (#23787) 2024-07-05 12:23:19 -04:00
messages core[patch]: introduce ToolMessage.status (#24628) 2024-07-29 14:01:53 -07:00
output_parsers core[minor]: Relax constraints on type checking for tools and parsers (#24459) 2024-07-19 21:47:34 -04:00
outputs core: Move json parsing in base chat model / output parser to bg thread (#24031) 2024-07-09 12:26:36 -07:00
prompts Add type() in error msg (#24723) 2024-07-26 16:48:45 -07:00
pydantic_v1 multiple: get rid of pyproject extras (#22581) 2024-06-06 15:45:22 -07:00
runnables core[patch]: runnable config ensure_config deep copy from var_child_runnable… (#24862) 2024-08-01 17:30:32 -07:00
tracers core[patch]: core lint fix (#24447) 2024-07-19 09:01:22 -07:00
utils core[minor]: Add support for pydantic 2 to utility to get fields (#24899) 2024-07-31 19:11:07 +00:00
vectorstores core[minor]: Support asynchronous in InMemoryVectorStore (#24472) 2024-07-25 11:36:55 -04:00
__init__.py
agents.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
caches.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
chat_history.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
chat_loaders.py core: chat_* docstrings (#23412) 2024-06-27 17:29:38 -04:00
chat_sessions.py core: chat_* docstrings (#23412) 2024-06-27 17:29:38 -04:00
env.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
exceptions.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
globals.py core[patch]: Fix word spelling error in globals.py (#24532) 2024-07-23 14:27:16 +00:00
memory.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
prompt_values.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
py.typed
rate_limiters.py core[patch]: Correct doc-string for InMemoryRateLimiter (#24730) 2024-07-26 22:17:22 +00:00
retrievers.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
stores.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
structured_query.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
sys_info.py core[patch]: docstrings langchain_core/ files update (#24285) 2024-07-16 09:21:51 -04:00
tools.py core[patch]: stringify tool non-content blocks (#24626) 2024-07-31 16:42:38 -07:00