From 01352989664698492f2469587aa1cdc67c56d5e7 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 15 Mar 2026 19:18:36 -0600 Subject: [PATCH] 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. --- src/mnemosyne/gateway.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mnemosyne/gateway.py b/src/mnemosyne/gateway.py index a565a3c..46787c0 100644 --- a/src/mnemosyne/gateway.py +++ b/src/mnemosyne/gateway.py @@ -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