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.
This commit is contained in:
Classic298 2026-09-16 16:08:46 +02:00 committed by GitHub
parent 3394a10b76
commit 4611394fa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -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

View file

@ -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