MastraM
Mastra3d ago
Ariel

Critical memory leak in Mastra Agents - Mastra never releases run states

Our team has spent days trying to figure out what's going on... We were using Inngest + Mastra + Langfuse + Sentry. We've stripped our entire app down to just Mastra and ruled out everything else. We took some heap snapshots and it's pretty clear - Mastra holds on to memory after agent generation is complete. This causes our pods to crash regularly (OOM signal).

I cannot provide the raw heap snapshot, but what you see in my screenshot is a snapshot after generation. The Mastra related strings are in memory and accumulating up to 1.1 GB worth of memory. They don't seem to get garbage collected, even 15 mins post-generation on idle. This was a decent generation with ~30 steps and a dozen tool calls.

FWIW, we're running pure Mastra Agents (no workflow, no network) with Postgres memory. No working memory. Latest version on everything.
image.png
Was this page helpful?