Skip to content

Conversation

@rafallezanko
Copy link
Contributor

@rafallezanko rafallezanko commented Feb 6, 2026

…ose (#1)

* Remove close_http_session flag from ElevenLabs TTS

* Fix logger warning message formatting

* Fix logging message format in tts.py
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment on lines 214 to +215
self._session = utils.http_context.http_session()
self._owns_session = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Incorrectly closing shared HTTP session obtained from http_context

When _ensure_session() is called and no custom session was provided, it obtains a session from utils.http_context.http_session() and sets self._owns_session = True. However, the session from http_context.http_session() is a shared session managed by the framework, not a session that this TTS instance should own or close.

Root Cause

The http_context.http_session() function returns a shared session that is managed by the framework and closed via _close_http_ctx() when the job context ends (see livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py:367). By setting _owns_session = True and then closing the session in aclose(), the ElevenLabs TTS plugin will prematurely close this shared session.

Impact: When TTS.aclose() is called, it will close the shared HTTP session at line 307-309. This will cause other plugins or components using the same shared session to fail with "Session is closed" errors. This is especially problematic in scenarios where multiple TTS/STT/LLM plugins share the same session.

Compare with the correct pattern used in OpenAI realtime model (livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py:606-612):

def _ensure_http_session(self) -> aiohttp.ClientSession:
    if not self._http_session:
        try:
            self._http_session = utils.http_context.http_session()
        except RuntimeError:
            self._http_session = aiohttp.ClientSession()
            self._http_session_owned = True  # Only set True when creating NEW session

The fix should be to NOT set _owns_session = True when using the shared session from http_context.http_session().

Suggested change
self._session = utils.http_context.http_session()
self._owns_session = True
self._session = utils.http_context.http_session()
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theomonnom , I see a comment added by Devin. I'm thinking how should we tackle a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants