I was seeing a strange memory increase during the agent is idle – there were webRTC sessions but no audio input, not actively used (i.e. the client opens up a webrtc session with text-chat only, stays the window open forever). Eventually I got alert logs for the memory use for the agent process.
Here is the graph of memory increase at that time:
I fortunately succeeded to reproduce the memory increase on my local machine, and checked different code paths and configurations to track down where the source of the memory leak, then found out that the memory leak is due to Google STT in livekit SDK/plugin. If I disabled STT, or switched to another one (I tried Elevenlabs), the memory increase is just gone.
Seemingly it is due to lack of the cleanup of the resources for the STT session timeout/recreation, this is also reported as Google STT has a memory leak when an agent session is running with no audio input from the user · Issue #5590 · livekit/agents · GitHub and a PR was made as Fix the memory leak of Google STT when no audio input. by jmuk · Pull Request #5591 · livekit/agents · GitHub. Can anyone take a look at this?
