@@ -2033,8 +2033,8 @@ async def parent(x: str, config: RunnableConfig) -> str:
20332033 "metadata" : {},
20342034 "name" : "grandchild" ,
20352035 "parent_ids" : [
2036- "00000000-0000-0000-0000-000000000008" ,
20372036 "00000000-0000-0000-0000-000000000007" ,
2037+ "00000000-0000-0000-0000-000000000008" ,
20382038 ],
20392039 "run_id" : "00000000-0000-0000-0000-000000000009" ,
20402040 "tags" : [],
@@ -2045,8 +2045,8 @@ async def parent(x: str, config: RunnableConfig) -> str:
20452045 "metadata" : {},
20462046 "name" : "grandchild" ,
20472047 "parent_ids" : [
2048- "00000000-0000-0000-0000-000000000008" ,
20492048 "00000000-0000-0000-0000-000000000007" ,
2049+ "00000000-0000-0000-0000-000000000008" ,
20502050 ],
20512051 "run_id" : "00000000-0000-0000-0000-000000000009" ,
20522052 "tags" : [],
@@ -2081,6 +2081,42 @@ async def parent(x: str, config: RunnableConfig) -> str:
20812081 ]
20822082
20832083
2084+ async def test_bad_parent_ids () -> None :
2085+ """Test handling of situation where a run id is duplicated in the run tree."""
2086+
2087+ # Type ignores in the code below need to be investigated.
2088+ # Looks like a typing issue when using RunnableLambda as a decorator
2089+ # with async functions.
2090+ @RunnableLambda # type: ignore
2091+ async def child (x : str ) -> str :
2092+ return x
2093+
2094+ @RunnableLambda # type: ignore
2095+ async def parent (x : str , config : RunnableConfig ) -> str :
2096+ config ["run_id" ] = uuid .UUID (int = 7 )
2097+ return await child .ainvoke (x , config ) # type: ignore
2098+
2099+ bond = uuid .UUID (int = 7 )
2100+ events = await _collect_events (
2101+ parent .astream_events ("hello" , {"run_id" : bond }, version = "v2" ),
2102+ with_nulled_ids = False ,
2103+ )
2104+ # Includes only a partial list of events since the run ID gets duplicated
2105+ # between parent and child run ID and the callback handler throws an exception.
2106+ # The exception does not get bubbled up to the user.
2107+ assert events == [
2108+ {
2109+ "data" : {"input" : "hello" },
2110+ "event" : "on_chain_start" ,
2111+ "metadata" : {},
2112+ "name" : "parent" ,
2113+ "parent_ids" : [],
2114+ "run_id" : "00000000-0000-0000-0000-000000000007" ,
2115+ "tags" : [],
2116+ }
2117+ ]
2118+
2119+
20842120async def test_runnable_generator () -> None :
20852121 """Test async events from sync lambda."""
20862122
0 commit comments