#293 — Log WebSocketDisconnect when raised while processing LLM engine response

Repo: Twill-AI/facade State: closed | Status: done Assignee: Unassigned

Created: 2025-02-26 · Updated: 2025-09-15

Description

Request

Caused by https://twill-network.slack.com/archives/C07TPN6FCBX/p1740406229960489

In order to ignore WebSocketDisconnect from the alerts that are reported to Slack, we need to include some reference to that exception to the logged message.

STR

One easy way to reproduce is by using tools/client_ws.html in Facade’s repo:

  1. Go to file://{path_to_facade}/tools/client_ws.html in your web browser.
  2. Create a WS ticket and connect.
  3. Send some prompt to the LLM.
  4. Close the tab.

Expected

An error message is logged stating that it failed to process LLM Engine response in a given LLM Chat. That same line should contain the exception that is the reason of that error.

Actual

An error message like the one below is logged. Note that it doesn't mention the exception name in the first line.
2025-02-24 14:09:07.459|ERROR|newOrgbnq1|websockets_router:506|e4d97383-32f0-48af-92f4-a670b1232136: Failed to handle LLM Engine response in LLM Chat 2. Reason: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send
    await self.send(data)  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 620, in send
    await self.ensure_open()
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 921, in ensure_open
    raise 

## Notes

_Add implementation notes, blockers, and context here_

## Related

_Add wikilinks to related people, meetings, or other tickets_