Skip to content
← Back to activity

Immutable solution version

LangSmith Python SDK memory grows in long-running apps (RunTree kept in memory)

Version 1Sign in to save

Complete solution

How to fix langsmith: langsmith python sdk memory grows in long-running apps (runtree kept in memory).

Problem

Long-running Python app using LangGraph/LangChain (asyncio.gather with create_task, one graph per task). Memory grows steadily over time, but only when LangSmith tracing is enabled. tracemalloc and objgraph show RunTree objects accumulating in memory long after their traces were flushed to the API. langsmith 0.4.27, langchain 0.3.27, langgraph 0.6.7.

Verified fix

A maintainer confirmed this is expected behavior rather than a leak: the Python SDK keeps the whole run tree (parents, children, inputs/outputs, metadata) in memory while a trace is live, so RSS grows with concurrency and only releases when the root run finishes. For wide fan-outs or long-running apps, reduce pressure by: upgrading to langsmith 0.4.30+ and setting LANGSMITHEXCLUDECHILDRUNS=true (shipped mitigation, feature-flagged because it can affect custom tracing setups that traverse childruns); limiting concurrency with max_concurrency or an asyncio semaphore; or splitting work into multiple traces under the same LangSmith thread.

Source: https://github.com/langchain-ai/langsmith-sdk/issues/2009

Evidence

Question: Long-running Python app using LangGraph/LangChain (asyncio.gather with create_task, one graph per task). Memory grows steadily over time, but only when LangSmith tracing is enabled. tracemalloc and objgraph show RunTree objects accumulating in memory long after their traces were flushed to the API. langsmith 0.4.27, langchain 0.3.27, langgraph 0.6.7.

Verified resolution: A maintainer confirmed this is expected behavior rather than a leak: the Python SDK keeps the whole run tree (parents, children, inputs/outputs, metadata) in memory while a trace is live, so RSS grows with concurrency and only releases when the root run finishes. For wide fan-outs or long-running apps, reduce pressure by: upgrading to langsmith 0.4.30+ and setting LANGSMITHEXCLUDECHILDRUNS=true (shipped mitigation, feature-flagged because it can affect custom tracing setups that traverse childruns); limiting concurrency with max_concurrency or an asyncio semaphore; or splitting work into multiple traces under the same LangSmith thread.

Source: https://github.com/langchain-ai/langsmith-sdk/issues/2009

Thread: https://vectle.com/threads/thr_VrP7M6p3mPVhGVb9KMw7Nw

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_luijb4_a4NBF8jSpB3E4QA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">LangSmith Python SDK memory grows in long-running apps (RunTree kept in memory) <span>— Vectle</span></a>