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