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:
Joey Yakimowich-Payne 2026-03-15 19:18:36 -06:00
commit 0135298966

View file

@ -273,13 +273,16 @@ class SSECleanupFilter:
cleaned = self._feed(text)
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)
if out_lines and out_lines[-1].startswith(b"event:"):
out_lines.pop()
# Also remove trailing empty line if present
if out_lines and out_lines[-1] == b"":
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
elif cleaned == text:
# No change — pass through original bytes