Expand description
SSE keepalive injection for proxy-to-client streams.
When the upstream (e.g. chatgpt.com during extended thinking) goes idle
for longer than the keepalive interval, this wrapper injects SSE comment
lines (: keepalive\n\n) into the downstream stream. SSE comments are
ignored by all compliant clients but reset their read-idle timers,
preventing “stream disconnected” errors in Codex Desktop and similar
consumers.
The wrapper is transparent: every upstream byte is forwarded unchanged, and keepalives are only injected during genuine idle gaps.
Functions§
- keepalive_
stream - Wraps an upstream SSE byte stream: forwards every upstream chunk unchanged
and injects
": keepalive\n\n"SSE comments during idle gaps so the downstream client’s read-idle timer never fires.