diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index b56659e721..2299ef84c4 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1836,7 +1836,7 @@ async def chat_completion( except HTTPException: raise except Exception as e: - log.debug(f'Error processing chat metadata: {e}') + log.warning(f'Error processing chat metadata: {e}') raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail=str(e), @@ -1908,6 +1908,15 @@ async def chat_completion( except Exception: pass + else: + # No chat_id/message_id → legacy/direct API path with no + # WebSocket error channel. We must surface the error as + # a proper HTTP response; without this the function would + # return None which FastAPI serializes as null. #23924 + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail=error_detail, + ) finally: # MCP cleanup — MUST run in the SAME asyncio task as # connect() because the MCP SDK's streamablehttp_client