From 4611394fa66a71575f7bcda21d7c4e9c81018746 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:08:46 +0200 Subject: [PATCH] refac: correct the ENABLE_CHAT_RESPONSE_STREAM_INPLACE_APPEND comments (#30066) The comments on the opt-in in-place append made it sound like the fast path can lose streamed text under normal operation. The only way the field can be emptied is an allocation failure, which means the host is already out of memory, and the default path (which copies the whole accumulated string on every chunk) raises in that situation as well. Reword both comments to state that condition so the flag is not read as unsafe. --- backend/open_webui/env.py | 3 ++- backend/open_webui/utils/middleware.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 4ce20dc023..9179f9a4b8 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -1043,7 +1043,8 @@ ENABLE_CHAT_RESPONSE_BASE64_IMAGE_URL_CONVERSION = ( ENABLE_API_OUTLET_FILTERS = os.getenv('ENABLE_API_OUTLET_FILTERS', 'True').lower() == 'true' # Opt in to CPython's in-place string append optimization for streamed responses. -# Disabled by default: allocation failure in the fast path can erase accumulated text. +# Off by default for a staged rollout. Only a host already out of memory can lose +# text here; the default path (a full copy per chunk) raises there too. ENABLE_CHAT_RESPONSE_STREAM_INPLACE_APPEND = os.getenv('ENABLE_CHAT_RESPONSE_STREAM_INPLACE_APPEND', 'False').lower() == 'true' # When enabled, uses a hardcoded extension-to-MIME dictionary as a last-resort diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 173f4a222e..3dca01d8bb 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -324,7 +324,7 @@ def append_to_text_field(item: dict, key: str, value: str) -> None: return # Opt-in: dropping the dict's reference lets CPython extend an unshared str - # in place. An allocation failure can leave the field empty. + # in place. Only a host that is already out of memory can leave the field empty. text = item[key] item[key] = '' text += value