From 27dc7917f258cf614d97a46786debb635dd6d936 Mon Sep 17 00:00:00 2001 From: ARIA Date: Sat, 22 Aug 2026 21:08:06 +0200 Subject: [PATCH] Added log handling for failed phone connection to the gateway --- gateway-plugin/http_server.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gateway-plugin/http_server.py b/gateway-plugin/http_server.py index 1b25c14..2d3d1e1 100644 --- a/gateway-plugin/http_server.py +++ b/gateway-plugin/http_server.py @@ -483,12 +483,18 @@ class HttpServer: # Register BEFORE the replay so a frame appended in between is # fanned out to us (and de-duped by cursor below) instead of lost. self._add_sub(sub) + reason = "eof" try: handler.send_response(200) handler.send_header("Content-Type", "text/event-stream") handler.send_header("Cache-Control", "no-cache") handler.send_header("X-Accel-Buffering", "no") handler.end_headers() + # INFO (not DEBUG like the per-request log): the stream + # lifecycle is the primary "is the device connected?" signal + # for debugging flaky links — a gap here is invisible at the + # gateway's default log level. + logger.info("android: SSE stream opened: %s (cursor=%d)", device_id, cursor) # 1. Catch-up from the outbox (id = cursor; the envelope also # carries the cursor for the app's push dedupe). max_cursor = cursor @@ -515,6 +521,7 @@ class HttpServer: self._write_raw(handler, ": hb\n\n") continue if item is _STOP: + reason = "stopped" break c, data = item if c is not None and c <= max_cursor: @@ -523,8 +530,9 @@ class HttpServer: except (BrokenPipeError, ConnectionResetError, OSError): # Client went away mid-stream: normal (the app reconnects with # Last-Event-ID and catches up from the outbox). - pass + reason = "client-gone" finally: + logger.info("android: SSE stream closed: %s (%s)", device_id, reason) self._remove_sub(sub) @staticmethod