Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16177,6 +16177,7 @@ def _pause_typing_before_finalize(
}

# Parse SSE stream
_SSE_BUFFER_CAP = 1 << 20 # 1 MiB — reject boundary-less lines
buffer = ""
async for chunk in resp.content.iter_any():
if not _run_still_current():
Expand All @@ -16197,6 +16198,12 @@ def _pause_typing_before_finalize(
text = chunk.decode("utf-8", errors="replace")
buffer += text

if len(buffer) > _SSE_BUFFER_CAP:
raise RuntimeError(
f"Proxy SSE buffer exceeded {_SSE_BUFFER_CAP} bytes "
"without a line boundary — aborting"
)

# Process complete SSE lines
while "\n" in buffer:
line, buffer = buffer.split("\n", 1)
Expand Down