Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions livekit-agents/livekit/agents/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from livekit.protocol import agent, models

from . import ipc, telemetry, utils
from ._exceptions import AssignmentTimeoutError
from ._exceptions import APIStatusError, AssignmentTimeoutError
from .inference_runner import _InferenceRunner
from .job import (
JobAcceptArguments,
Expand Down Expand Up @@ -1097,7 +1097,8 @@ async def _connection_task(self) -> None:
retry_count += 1

logger.warning(
f"failed to connect to livekit, retrying in {retry_delay}s", exc_info=e
f"failed to connect to livekit, retrying in {retry_delay}s",
extra={"retry_count": retry_count, "max_retry": self._max_retry, "error": e},
)
Comment on lines 1099 to 1102
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.

🟑 Removal of exc_info loses exception traceback in connection retry warning logs

The change from exc_info=e to extra={"error": e} removes the full exception traceback from the warning log. With exc_info=e, Python's logging framework includes the complete traceback (showing causal chain, file/line info, etc.), which is critical for debugging why connections fail (DNS resolution errors, TLS failures, connection refused, etc.). With extra={"error": e}, only str(e) is included via the JsonFormatter.JsonEncoder (cli/log.py:98-99), losing the traceback entirely. Both exc_info and extra can be passed simultaneously to logger.warning(), so the new structured fields (retry_count, max_retry) can be added without sacrificing the traceback.

Suggested change
logger.warning(
f"failed to connect to livekit, retrying in {retry_delay}s", exc_info=e
f"failed to connect to livekit, retrying in {retry_delay}s",
extra={"retry_count": retry_count, "max_retry": self._max_retry, "error": e},
)
logger.warning(
f"failed to connect to livekit, retrying in {retry_delay}s",
exc_info=e,
extra={"retry_count": retry_count, "max_retry": self._max_retry},
)
Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

await asyncio.sleep(retry_delay)
finally:
Expand Down Expand Up @@ -1136,10 +1137,24 @@ async def _recv_task() -> None:
if closing_ws:
return

raise Exception("worker connection closed unexpectedly")
raise APIStatusError(
message="worker connection closed unexpectedly",
status_code=ws.close_code or -1,
body=f"{msg.data=} {msg.extra=}",
)

if msg.type != aiohttp.WSMsgType.BINARY:
logger.warning("unexpected message type: %s", msg.type)
ws_data = str(msg.data)
if len(ws_data) > 128:
ws_data = ws_data[:128] + f"...(+{len(ws_data) - 128} more)"
logger.warning(
"unexpected message type: %s",
msg.type,
extra={
"type": msg.type.name,
"ws_data": ws_data,
},
)
continue

data = msg.data
Expand Down
Loading