# Upgrading python livekit-agents to 1.5.6 causing memory issues

**URL:** <https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976>\
**Category:** Agents\
**Tags:** python, agent-deployment\
**Created:** [April 28, 2026, 4:28pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976 "2026-04-28T16:28:54Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [April 28, 2026, 4:28pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/1 "2026-04-28T16:28:54Z")

</div>

Hello,

We have recently upgraded python livekit-agents from 1.5.1 to 1.5.6, and it caused massive spikes in memory. Here is the AWS graph before and after deployment.

NOTE: The sudden drop in memory usage is due to auto horizontal scaling of the instance.

The pattern suggests that something is using memory and not releasing it. In the update, we just upgraded livekit-agent from 1.5.1 to 1.5.6 and added default Preamptive generation configs; nothing else.

 ![Screenshot 2026-04-28 at 9.57.45 PM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/0/04bd87012b2cbb50bccce791647f59f30fd4ab74.png)

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [April 28, 2026, 7:19pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/2 "2026-04-28T19:19:35Z")

</div>

I’ve not hear anyone report this but I will check with our team to see if they’ve seen this.

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [April 29, 2026, 5:15am UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/3 "2026-04-29T05:15:54Z")

</div>

After downgrading its working perfectly fine

 ![Screenshot 2026-04-29 at 10.43.45 AM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/9/90dd19b0e567ba1a354e648e797f8bd8cdaac07b.png)

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [April 29, 2026, 11:51am UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/4 "2026-04-29T11:51:13Z")

</div>

Thanks for this. I will pass that along to the team.

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [April 29, 2026, 4:39pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/5 "2026-04-29T16:39:41Z")

</div>

Our team ran a test of `1.5.6` (from `1.5.3`) and did not see any unusual memory usage. It was same memory usage in both cases.

Can you provide your agent configuration or other ways of reproducing this?

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [April 30, 2026, 7:06am UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/6 "2026-04-30T07:06:41Z")

</div>

Sure. Here are the configurations

```auto
#>>>>>>>>>>>>>>>>>>>>>>>>> BEFORE
[project]
name = "voicebot-livekit"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "aiohttp~=3.13",
    "livekit~=1.1.2",
    "livekit-agents[azure,cartesia,deepgram,elevenlabs,google,groq,inworld,openai,sarvam,silero,turn-detector]==1.5.1",
    "livekit-api~=1.1.0",
    "livekit-plugins-noise-cancellation~=0.2",
    "livekit-protocol~=1.1.2",
    "motor~=3.7",
    "pymongo>=4.12",
    "python-dotenv~=1.1",
]

#>>>>>>>>>>>>>>>>>>>>>>>>> AFTER
#>>>>>>>>>>>>>>>>>>>>>>>>> NOTE: Happens for the 1.5.2 as well. 
[project]
name = "voicebot-livekit"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "aiohttp~=3.13",
    "livekit~=1.1.2",
    "livekit-agents[azure,cartesia,deepgram,elevenlabs,google,groq,inworld,openai,sarvam,silero,turn-detector]==1.5.6", # Same result for 1.5.2 as seen in graph
    "livekit-api~=1.1.0",
    "livekit-plugins-noise-cancellation~=0.2",
    "livekit-protocol~=1.1.2",
    "motor~=3.7",
    "pymongo>=4.12",
    "python-dotenv~=1.1",
]

```

```python

# EXAMPLE CONFIG
session = AgentSession(
    vad=VAD, # << Prewarm silero.VAD.load()
    stt=deepgram.STT(model="nova-3-general"),
    llm=openai.LLM(model="gpt-4.1-mini"),
    tts=elevenlabs.TTS(model="eleven_flash_v2_5"),
    user_away_timeout=8.0,
    preemptive_generation=True,
    turn_handling=TurnHandlingOptions(
        turn_detection="vad",
        endpointing={
            "min_delay": 0.2, # 200ms
        },
        interruption={
            "mode": "vad",
            "enabled": True,
            "discard_audio_if_uninterruptible": True,
            "min_duration": 0.4, # 400ms
            "min_words": 1,
            "false_interruption_timeout": 2.0,
        },
    )
)

```

 ![Screenshot 2026-04-30 at 12.27.15 PM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/a/a7cd30ae3dffc0a148544178b607cf638745930c.png)

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [April 30, 2026, 3:02pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/7 "2026-04-30T15:02:42Z")

</div>

> [@nilkanth](#):
>
> `Happens for the 1.5.2 as well. `

Thanks for that. So looks like you are seeing the memory issue started in 1.5.2 instead of 1.5.6?

I will pass this along.

---

<div class="post-metadata">

**Author:** ![Cars\_Chandler](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cars_chandler/32/1182_2.png) [@Cars\_Chandler](https://community.livekit.io/u/Cars_Chandler)\
**Post date:** [May 1, 2026, 2:38pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/8 "2026-05-01T14:38:14Z")

</div>

Preemptive generation was added in 1.5.2 right? Shouldn’t benchmarks be between 1.5.1 and something post-1.5.2?

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [May 4, 2026, 4:53am UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/9 "2026-05-04T04:53:19Z")

</div>

Hello @CWilson , Any update on the issue? Let me know if I can help in any way.  
@Cars_Chandler , Preemptive generation was added in 1.5.0.

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [May 4, 2026, 4:24pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/10 "2026-05-04T16:24:44Z")

</div>

Can you try and disable premptive generation and see if that helps?

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [May 15, 2026, 7:05pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/11 "2026-05-15T19:05:43Z")

</div>

Hi @CWilson , I tried disabling premptive generation and it got worse. Here is a memory chart marked with versions.

 ![Screenshot 2026-05-16 at 12.31.06 AM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/d/da8ab24c5c78869d608a7a9e94bb32fcce861d46.png)

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [May 15, 2026, 7:12pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/12 "2026-05-15T19:12:08Z")

</div>

Even without any calls its getting increased. I am not sure whats happening. Can you help me as I am stuck on v1.5.1?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Usman\_Bashir](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/muhammad_usman_bashir/32/1149_2.png) [@Muhammad\_Usman\_Bashir](https://community.livekit.io/u/Muhammad_Usman_Bashir)\
**Post date:** [May 15, 2026, 7:42pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/13 "2026-05-15T19:42:01Z")

</div>

@CWilson, the “memory grows even without any calls” data point in `#12` narrows the suspect range. With no sessions active, leak candidates are worker-level:

- Heartbeat / signaling WebSocket
- Telemetry / metrics buffers
- Plugin import-time singletons
- Background asyncio tasks accumulating

@nilkanth, fastest path to a concrete root cause is an `allocator-level` snapshot diff. Run the worker idle (no calls) for `~30 minutes`, then capture with memray:

```python
  # pip install memray
  memray run -o profile.bin python your_worker.py start
  # stop after 30 min idle
  memray flamegraph profile.bin

```

Or in-process with `tracemalloc` snapshots at startup and 30 minutes in, then `snapshot.compare_to(start_snapshot, 'lineno')`. The top growers in the diff name the offending allocators directly, which is far more actionable for @CWilson’s team than memory graphs.

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [May 18, 2026, 7:41pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/14 "2026-05-18T19:41:14Z")

</div>

Our team was not able to reproduce this issue and I’ve not seen others having a similar issue.

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [May 21, 2026, 9:31pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/15 "2026-05-21T21:31:25Z")

</div>

I think I found the issue. There are multiple python3 processes that are not killed. Is this a normal behaviour? The server has minimal call volume now.

 ![Screenshot 2026-05-22 at 2.56.49 AM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/5/526b49101f9ee9ef4694f4590c104b3527ec4c29.jpeg)

I also tried `memray flamegraph` but the graph seems to be normal.

 ![Screenshot 2026-05-22 at 3.00.46 AM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/e/e8c8ea48d70f51c4bc4606e84a85d672b0f2621b.png)

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [May 21, 2026, 10:10pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/16 "2026-05-21T22:10:58Z")

</div>

Same code in 1.5.1 removes the python3 process after some time. Is it something related to session\_end\_timeout?

 ![Screenshot 2026-05-22 at 3.33.49 AM](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/4/4ad8c391eded62969cf579bdceda2da7c7fbd388.jpeg)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Usman\_Bashir](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/muhammad_usman_bashir/32/1149_2.png) [@Muhammad\_Usman\_Bashir](https://community.livekit.io/u/Muhammad_Usman_Bashir)\
**Post date:** [May 22, 2026, 6:05pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/17 "2026-05-22T18:05:46Z")

</div>

Cc: @nilkanth

The memray `flat-RSS` chart plus the top output (`20+ python3 each at 250-450 MB`) shifts the diagnosis away from the worker-level leak candidates identified earlier.

Your `session_end_timeout` instinct is on track. The default is `session_end_timeout: float = 300.0` (“Maximum amount of time to wait for `on_session_end` to complete (`default: 5 minutes`)”), as seen in [livekit/agents/livekit-agents/livekit/agents/worker.py](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/worker.py). If `on_session_end` blocks or hangs (e.g., network call, unreleased resource, pending task), the `JobProcess` stays alive for the full 5 minutes per session. Under sustained call volume, processes stack up faster than they exit.

Two things to try:

- Add an `enter/exit` log in `on_session_end` (or your equivalent close hook). If the enter log fires but the exit log doesn’t within 5 minutes, that’s the hang.

- Set `session_end_timeout=15` in `WorkerOptions` and rerun. If process accumulation stops, the close hook is the culprit. If it doesn’t, the leak is in `WorkerOptions` (the `num_idle_processes` prewarm pool, which defaults to `min(ceil(cpu_count()), 4)` in production [same file]) or in subprocess termination itself.

> Within a single process, RSS is steady. The accumulation is at the subprocess layer: JobProcess instances not being reaped after sessions end.

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [May 26, 2026, 1:31pm UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/18 "2026-05-26T13:31:50Z")

</div>

Based on the number of Python processes I see there (and assuming you’ve not changed the default), that looks like the normal number of Python processes to keep around.

See [num\_idle\_processes](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/worker.py#L205)

---

<div class="post-metadata">

**Author:** ![nilkanth](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@nilkanth](https://community.livekit.io/u/nilkanth)\
**Post date:** [June 12, 2026, 6:35am UTC](https://community.livekit.io/t/upgrading-python-livekit-agents-to-1-5-6-causing-memory-issues/976/19 "2026-06-12T06:35:10Z")

</div>

I have deployed the code to AWS EC2 switching from ECS and it seems to be working. I will monitor it for few days for any issues related to memory. Thanks.
