[GH-ISSUE #23066] issue: Infinite loop when streaming tool message #58544

Closed
opened 2026-05-05 23:23:23 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @lywongad on GitHub (Mar 26, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/23066

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

0.8.11

Ollama Version (if applicable)

No response

Operating System

Windows 11

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

Hi. I am trying to stream a text message and a tool message in OpenAI output format for testing purpose. The endpoint is an OpenAI endpoint hosted in local. No LLM involved, purely Python code. The endpoint streams a text counting number of messages received and show a get_weather tool result. It is expected that Open WebUI streams one text message and one tool message.

Actual Behavior

Open WebUI keep repeating the same text message and tool message. See the screen shot.

Steps to Reproduce

  1. Setup a FastAPI server. This server has only one endpoint that streams a simple text message and tool message:
import asyncio
import json
import random
import time

from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse


app = FastAPI()


@app.post("/v1/chat/completions")
async def chat_completions(request: Request):
    body = await request.json()
    model = body["model"]

    async def generate_stream():
        response_id = f"chatcmpl-{random.randint(10000, 99999)}"
        call_id = f"call_{random.randint(100000, 999999)}"
        num_messages = len(body.get("messages", []))

        for chunk_data in [
            {"role": "assistant", "content": ""},
            {"content": f"Number of messages received: {num_messages}"},
        ]:
            yield f'data: {json.dumps({
                "id": response_id,
                "object": "chat.completion.chunk",
                "created": int(time.time()),
                "model": model,
                "choices": [{"index": 0, "delta": chunk_data, "finish_reason": None}]
            })}\n\n'.encode()

        yield f'data: {json.dumps({
            "id": response_id,
            "object": "chat.completion.chunk",
            "created": int(time.time()),
            "model": model,
            "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]
        })}\n\n'.encode()

        yield f'data: {json.dumps({
            "id": response_id,
            "object": "chat.completion.chunk",
            "created": int(time.time()),
            "model": model,
            "choices": [{
                "index": 0,
                "delta": {
                    "role": "assistant",
                    "tool_calls": [{
                        "index": 0,
                        "id": call_id,
                        "type": "function",
                        "function": {"name": "get_weather", "arguments": ""}
                    }]
                },
                "finish_reason": None
            }]
        })}\n\n'.encode()

        arguments = '{"location": "Canada"}'
        chunk_size = 5
        for i in range(0, len(arguments), chunk_size):
            partial = arguments[i:i+chunk_size]
            yield f'data: {json.dumps({
                "id": response_id,
                "object": "chat.completion.chunk",
                "created": int(time.time()),
                "model": model,
                "choices": [{
                    "index": 0,
                    "delta": {
                        "tool_calls": [{
                            "index": 0,
                            "function": {"arguments": partial}
                        }]
                    },
                    "finish_reason": None
                }]
            })}\n\n'.encode()

        yield f'data: {json.dumps({
            "id": response_id,
            "object": "chat.completion.chunk",
            "created": int(time.time()),
            "model": model,
            "choices": [{
                "index": 0,
                "delta": {},
                "finish_reason": "tool_calls"
            }]
        })}\n\n'.encode()

    return StreamingResponse(
        generate_stream(),
        media_type="text/event-stream",
    )

@app.get("/v1/models")
async def list_models():
    return {"object": "list", "data": [
        {"id": "test-gpt", "object": "model", "owned_by": "local"},
    ]}

  1. Run the FastAPI server and setup a direct connection.
uv run fastapi run server.py --host 0.0.0.0 --port 8000

OpenAI API connection:
http://172.23.33.135:8000/v1

Logs & Screenshots

Image

Docker logs:

2026-03-26 09:01:23.972 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - 172.23.33.45:47060 - "GET / HTTP/1.1" 200
2026-03-26 09:01:26.221 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/v1/chats/524a2c8d-2fd9-4703-a033-da9a805372b4 HTTP/1.1" 200
2026-03-26 09:01:26.253 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200
2026-03-26 09:01:26.305 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/chat/completions HTTP/1.1" 200
2026-03-26 09:01:26.385 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200
2026-03-26 09:01:28.887 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/chat/completed HTTP/1.1" 200
2026-03-26 09:01:28.961 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/v1/chats/524a2c8d-2fd9-4703-a033-da9a805372b4 HTTP/1.1" 200
2026-03-26 09:01:29.008 | INFO     | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200

Additional Information

No response

Originally created by @lywongad on GitHub (Mar 26, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/23066 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version 0.8.11 ### Ollama Version (if applicable) _No response_ ### Operating System Windows 11 ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior Hi. I am trying to stream a text message and a tool message in OpenAI output format for testing purpose. The endpoint is an OpenAI endpoint hosted in local. No LLM involved, purely Python code. The endpoint streams a text counting number of messages received and show a get_weather tool result. It is expected that Open WebUI streams one text message and one tool message. ### Actual Behavior Open WebUI keep repeating the same text message and tool message. See the screen shot. ### Steps to Reproduce 1. Setup a FastAPI server. This server has only one endpoint that streams a simple text message and tool message: ```python import asyncio import json import random import time from fastapi import FastAPI, Request from fastapi.responses import StreamingResponse app = FastAPI() @app.post("/v1/chat/completions") async def chat_completions(request: Request): body = await request.json() model = body["model"] async def generate_stream(): response_id = f"chatcmpl-{random.randint(10000, 99999)}" call_id = f"call_{random.randint(100000, 999999)}" num_messages = len(body.get("messages", [])) for chunk_data in [ {"role": "assistant", "content": ""}, {"content": f"Number of messages received: {num_messages}"}, ]: yield f'data: {json.dumps({ "id": response_id, "object": "chat.completion.chunk", "created": int(time.time()), "model": model, "choices": [{"index": 0, "delta": chunk_data, "finish_reason": None}] })}\n\n'.encode() yield f'data: {json.dumps({ "id": response_id, "object": "chat.completion.chunk", "created": int(time.time()), "model": model, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}] })}\n\n'.encode() yield f'data: {json.dumps({ "id": response_id, "object": "chat.completion.chunk", "created": int(time.time()), "model": model, "choices": [{ "index": 0, "delta": { "role": "assistant", "tool_calls": [{ "index": 0, "id": call_id, "type": "function", "function": {"name": "get_weather", "arguments": ""} }] }, "finish_reason": None }] })}\n\n'.encode() arguments = '{"location": "Canada"}' chunk_size = 5 for i in range(0, len(arguments), chunk_size): partial = arguments[i:i+chunk_size] yield f'data: {json.dumps({ "id": response_id, "object": "chat.completion.chunk", "created": int(time.time()), "model": model, "choices": [{ "index": 0, "delta": { "tool_calls": [{ "index": 0, "function": {"arguments": partial} }] }, "finish_reason": None }] })}\n\n'.encode() yield f'data: {json.dumps({ "id": response_id, "object": "chat.completion.chunk", "created": int(time.time()), "model": model, "choices": [{ "index": 0, "delta": {}, "finish_reason": "tool_calls" }] })}\n\n'.encode() return StreamingResponse( generate_stream(), media_type="text/event-stream", ) @app.get("/v1/models") async def list_models(): return {"object": "list", "data": [ {"id": "test-gpt", "object": "model", "owned_by": "local"}, ]} ``` 2. Run the FastAPI server and setup a direct connection. ``` uv run fastapi run server.py --host 0.0.0.0 --port 8000 ``` OpenAI API connection: http://172.23.33.135:8000/v1 ### Logs & Screenshots <img width="1887" height="852" alt="Image" src="https://github.com/user-attachments/assets/49c2f190-907c-4197-9431-24549358f877" /> Docker logs: ``` 2026-03-26 09:01:23.972 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - 172.23.33.45:47060 - "GET / HTTP/1.1" 200 2026-03-26 09:01:26.221 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/v1/chats/524a2c8d-2fd9-4703-a033-da9a805372b4 HTTP/1.1" 200 2026-03-26 09:01:26.253 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200 2026-03-26 09:01:26.305 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/chat/completions HTTP/1.1" 200 2026-03-26 09:01:26.385 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200 2026-03-26 09:01:28.887 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/chat/completed HTTP/1.1" 200 2026-03-26 09:01:28.961 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "POST /api/v1/chats/524a2c8d-2fd9-4703-a033-da9a805372b4 HTTP/1.1" 200 2026-03-26 09:01:29.008 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - x.x.x.x:0 - "GET /api/v1/chats/?page=1 HTTP/1.1" 200 ``` ### Additional Information _No response_
GiteaMirror added the bug label 2026-05-05 23:23:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#58544