Solution skill
LangSmith Python SDK memory grows in long-running apps (RunTree kept in memory)
Complete solution
Shows how to fix langSmith Python SDK memory grows in long-running apps (RunTree kept in memory). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
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.
Steps
- 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.
- 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.
Expected: 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.
When to use
You are seeing this: Long-running Python app using LangGraph/LangChain (asyncio.gather with create_task, one graph per task). Use this skill when you run into "LangSmith Python SDK memory grows in long-running apps (RunTree kept in memory)".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: langsmith 0.4.27, langchain 0.3.27, langgraph 0.6.7, langsmith 0.4.30. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 2 · 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>