Originally created by @xmcp on GitHub (Feb 13, 2025).
Bug Report
Installation Method
docker
Environment
Open WebUI Version: v0.5.11
Ollama (if applicable): N/A
Operating System: Ubuntu 24.04
Browser (if applicable): N/A
Confirmation:
I have read and followed all the instructions provided in the README.md.
I am on 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 the exact steps to reproduce the bug in the "Steps to Reproduce" section below.
Expected Behavior:
The code interpreter repeatedly fails, causing a dead loop for the model.
Actual Behavior:
The code interpreter should work.
Description
Bug Summary:
I have an OpenAI endpoint that uses fake streaming, i.e., it will put the whole output into a single text/event-stream chunk when stream=True. In this setup, when using the code interpreter feature, Open WebUI cannot end the <code_interpreter> block successfully, leading to errors when executing the code.
Reproduction Details
Steps to Reproduce:
Have an OpenAI endpoint that uses fake streaming by putting the whole output into a single text/event-stream chunk
Use Open WebUI to ask it print the current python version.
See the screenshots below, where we can see that </code_interpreter> and contents after that are considered part of the code block, leading to a SyntaxError.
Logs and Screenshots
Browser Console Logs:
Docker Container Logs:
[{'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.', 'started_at': 1739447846.2873282, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.', 'started_at': 1739447909.5165014, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.', 'started_at': 1739447972.9585047, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.', 'started_at': 1739448037.8162143, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThis code imports the sys module and prints the current Python version along with additional build details (such as build date and compiler information) from sys.version. When executed in the Python environment, you\'ll see the full version information displayed.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThis code imports the sys module and prints the current Python version along with additional build details (such as build date and compiler information) from sys.version. When executed in the Python environment, you\'ll see the full version information displayed.', 'started_at': 1739448102.314626, 'output': ''}, {'type': 'text', 'content': ''}] <details type="code_interpreter" done="false">
<summary>Analyzing...</summary>
```python
import sys
print("Current Python version:")
print(sys.version)
</code_interpreter>
The code above prints the current Python version being used in this environment. After running it, you'll see detailed output including version number and additional build details.
```
</details>
I think I know the root cause of this issue, and can contribute a PR for it. I will elaborate in a separate comment below.
Originally created by @xmcp on GitHub (Feb 13, 2025).
# Bug Report
## Installation Method
docker
## Environment
- **Open WebUI Version:** v0.5.11
- **Ollama (if applicable):** N/A
- **Operating System:** Ubuntu 24.04
- **Browser (if applicable):** N/A
**Confirmation:**
- [x] I have read and followed all the instructions provided in the README.md.
- [x] I am on 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 the exact steps to reproduce the bug in the "Steps to Reproduce" section below.
## Expected Behavior:
The code interpreter repeatedly fails, causing a dead loop for the model.
## Actual Behavior:
The code interpreter should work.
## Description
**Bug Summary:**
I have an OpenAI endpoint that uses fake streaming, i.e., it will put the whole output into a single `text/event-stream` chunk when stream=True. In this setup, when using the code interpreter feature, Open WebUI cannot end the `<code_interpreter>` block successfully, leading to errors when executing the code.
## Reproduction Details
**Steps to Reproduce:**
- Have an OpenAI endpoint that uses fake streaming by putting the whole output into a single `text/event-stream` chunk
- Use Open WebUI to ask it `print the current python version`.
- See the screenshots below, where we can see that `</code_interpreter>` and contents after that are considered part of the code block, leading to a `SyntaxError`.
## Logs and Screenshots
**Browser Console Logs:**

**Docker Container Logs:**
[{'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.', 'started_at': 1739447846.2873282, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.', 'started_at': 1739447909.5165014, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.', 'started_at': 1739447972.9585047, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.', 'started_at': 1739448037.8162143, 'output': ''}, {'type': 'text', 'content': '<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThis code imports the sys module and prints the current Python version along with additional build details (such as build date and compiler information) from sys.version. When executed in the Python environment, you\'ll see the full version information displayed.'}, {'type': 'code_interpreter', 'tag': 'code_interpreter', 'attributes': {'type': 'code', 'lang': 'python'}, 'content': '\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used in this environment. After running it, you\'ll see detailed output including version number and additional build details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the current Python version being used, along with additional build details provided by the sys.version attribute. When executed, you\'ll see information such as the version number, build date, and compiler details, which can help you verify the Python environment.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above prints the Python version installed in the current environment. Running it will display detailed information such as the Python version number, build date, and other relevant details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThe code above imports the sys module and prints the current Python version installed in this environment, including detailed build information such as the version number, build date, and compiler details.<code_interpreter type="code" lang="python">\nimport sys\nprint("Current Python version:")\nprint(sys.version)\n</code_interpreter>\n\nThis code imports the sys module and prints the current Python version along with additional build details (such as build date and compiler information) from sys.version. When executed in the Python environment, you\'ll see the full version information displayed.', 'started_at': 1739448102.314626, 'output': ''}, {'type': 'text', 'content': ''}] <details type="code_interpreter" done="false">
<summary>Analyzing...</summary>
```python
import sys
print("Current Python version:")
print(sys.version)
</code_interpreter>
The code above prints the current Python version being used in this environment. After running it, you'll see detailed output including version number and additional build details.
```
</details>
The above log seems to be printed at [middleware.py:1794](https://github.com/open-webui/open-webui/blob/v0.5.11/backend/open_webui/utils/middleware.py#L1794).
**Screenshots/Screen Recordings (if applicable):**

## Additional Information
I think I know the root cause of this issue, and can contribute a PR for it. I will elaborate in a separate comment below.
The root cause seems to be the tag_content_handler function in middleware.py, which looks like:
deftag_content_handler(content_type,tags,content,content_blocks):ifcontent_blocks[-1]["type"]=="text":...# checks for start tag, i.e., `<code_interpreter attrs>`elifcontent_blocks[-1]["type"]==content_type:...# checks for end tag, i.e., `</code_interpreter>`returncontent,content_blocks,end_flag
This function will be called once for each streamed chunk. If <code_interpreter>...</code_interpreter> is returned within a single chunk, only the code path for the start tag is executed, skipping the code path for the end tag.
Therefore, the whole chunk including the content after </code_interpreter> is incorrectly considered the content in the code block.
@xmcp commented on GitHub (Feb 13, 2025):
The root cause seems to be the `tag_content_handler` function in `middleware.py`, which looks like:
```python
def tag_content_handler(content_type, tags, content, content_blocks):
if content_blocks[-1]["type"] == "text":
... # checks for start tag, i.e., `<code_interpreter attrs>`
elif content_blocks[-1]["type"] == content_type:
... # checks for end tag, i.e., `</code_interpreter>`
return content, content_blocks, end_flag
```
This function will be called once for each streamed chunk. If `<code_interpreter>...</code_interpreter>` is returned within a single chunk, only the code path for the start tag is executed, skipping the code path for the end tag.
Therefore, the whole chunk including the content after `</code_interpreter>` is incorrectly considered the content in the code block.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @xmcp on GitHub (Feb 13, 2025).
Bug Report
Installation Method
docker
Environment
Open WebUI Version: v0.5.11
Ollama (if applicable): N/A
Operating System: Ubuntu 24.04
Browser (if applicable): N/A
Confirmation:
Expected Behavior:
The code interpreter repeatedly fails, causing a dead loop for the model.
Actual Behavior:
The code interpreter should work.
Description
Bug Summary:
I have an OpenAI endpoint that uses fake streaming, i.e., it will put the whole output into a single
text/event-streamchunk when stream=True. In this setup, when using the code interpreter feature, Open WebUI cannot end the<code_interpreter>block successfully, leading to errors when executing the code.Reproduction Details
Steps to Reproduce:
text/event-streamchunkprint the current python version.</code_interpreter>and contents after that are considered part of the code block, leading to aSyntaxError.Logs and Screenshots
Browser Console Logs:

Docker Container Logs:
The above log seems to be printed at middleware.py:1794.
Screenshots/Screen Recordings (if applicable):
Additional Information
I think I know the root cause of this issue, and can contribute a PR for it. I will elaborate in a separate comment below.
@xmcp commented on GitHub (Feb 13, 2025):
The root cause seems to be the
tag_content_handlerfunction inmiddleware.py, which looks like:This function will be called once for each streamed chunk. If
<code_interpreter>...</code_interpreter>is returned within a single chunk, only the code path for the start tag is executed, skipping the code path for the end tag.Therefore, the whole chunk including the content after
</code_interpreter>is incorrectly considered the content in the code block.@xmcp commented on GitHub (Feb 13, 2025):
FYI, the below patch solves this issue in my setup
@tjbck commented on GitHub (Feb 13, 2025):
PR Welcome!
@tjbck commented on GitHub (Feb 14, 2025):
I highly suspect the issue is caused from the model-end. Suggested PR does not resolve the issue entirely.