AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Tee Leaves Source Generator Open When A Child Iterator Is Never Started

The Tee context manager in langchain-core does not close the underlying source generator if one or more child iterators are never started, causing resource leaks.

highConfidence 95%LangchainMemoryChat ModelsAffected V1.6.6

Origin Analysis

Unstarted child iterators do not execute their finally blocks when closed, leaving their registered buffers active and preventing the source generator from being closed.
Run the provided sync and async reproduction code. Observe that 'sync source closed: False' and 'async source closed: False' are printed, indicating the source's finally block did not execute.

Fixing Code Block

Edge Case Audit

Ensure the source generator is not closed elsewhere before the Tee context exits, as this would cause a double-close. The fix may affect performance if many unstarted children exist. Rollback by reverting to the original __exit__/__aexit__ methods.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state