fix: emit SSE keepalive comments while buffering cleanup tags
When the SSE filter suppresses text deltas (buffering inside a memory_cleanup/yuyay-response tag), no bytes reached the client, causing opencode's SSE read timeout to fire. Now emits ':keepalive' SSE comments during suppression to keep the connection alive.
This commit is contained in:
parent
3a970efd62
commit
0135298966
1 changed files with 5 additions and 2 deletions
|
|
@ -273,13 +273,16 @@ class SSECleanupFilter:
|
||||||
cleaned = self._feed(text)
|
cleaned = self._feed(text)
|
||||||
|
|
||||||
if cleaned is None or not cleaned:
|
if cleaned is None or not cleaned:
|
||||||
# Suppressed — also remove the preceding "event:" line
|
# Suppressed — remove the preceding "event:" line
|
||||||
# to avoid malformed SSE (event header with no data)
|
# to avoid malformed SSE (event header with no data)
|
||||||
if out_lines and out_lines[-1].startswith(b"event:"):
|
if out_lines and out_lines[-1].startswith(b"event:"):
|
||||||
out_lines.pop()
|
out_lines.pop()
|
||||||
# Also remove trailing empty line if present
|
|
||||||
if out_lines and out_lines[-1] == b"":
|
if out_lines and out_lines[-1] == b"":
|
||||||
out_lines.pop()
|
out_lines.pop()
|
||||||
|
# Emit an SSE comment to keep the connection alive.
|
||||||
|
# Without this, clients time out during long tag buffering.
|
||||||
|
out_lines.append(b": keepalive")
|
||||||
|
out_lines.append(b"")
|
||||||
continue
|
continue
|
||||||
elif cleaned == text:
|
elif cleaned == text:
|
||||||
# No change — pass through original bytes
|
# No change — pass through original bytes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue