Skip to content

fix(xai): reconnect STT stream on server-side error - #7279

Open
elly-zhu wants to merge 2 commits into
livekit:mainfrom
elly-zhu:fix/xai-stt-reconnect-on-error
Open

elly-zhu wants to merge 2 commits into
livekit:mainfrom
elly-zhu:fix/xai-stt-reconnect-on-error

Conversation

@elly-zhu

@elly-zhu elly-zhu commented Sep 14, 2026

Copy link
Copy Markdown

Problem

When the xAI STT WebSocket receives a server-side error message (e.g. {"type": "error", "message": "ASR stream timed out"}), the plugin logs the error but recv_task continues waiting for more messages. xAI sends no further events after this error — the stream is effectively dead, and transcription silently stops for the rest of the session.

Fix

Raise APIStatusError on "error" type messages so the exception propagates through recv_tasktasks_group → the existing while True reconnect loop in _run(), which opens a fresh WebSocket and resumes transcription.

This is consistent with how the plugin already handles unexpected connection closures (line 374).

@elly-zhu
elly-zhu requested a review from a team as a code owner September 14, 2026 22:30
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Devin Review

Comment thread livekit-plugins/livekit-plugins-xai/livekit/plugins/xai/stt.py
elif msg_type == "error":
logger.error("xAI STT error: %s", data.get("message", "unknown error"))
error_msg = data.get("message", "unknown error")
logger.error("xAI STT error: %s", error_msg)

@devin-ai-integration devin-ai-integration Bot Sep 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟥 Provider errors leak into log bodies

An xAI-controlled error_msg enters the log body without a PII marker. Provider errors can contain customer content that collectors cannot redact.

Devin Review

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

check again

error_msg = data.get("message", "unknown error")
logger.error("xAI STT error: %s", error_msg)
raise APIStatusError(
message=f"xAI STT error: {error_msg}",

@devin-ai-integration devin-ai-integration Bot Sep 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟥 Provider errors leak through exceptions

The new APIStatusError embeds xAI-controlled error_msg. Exception logs and telemetry can expose customer content without a redactable PII attribute.

Devin Review

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

check again

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