From aa8d28db34348d8de1a547cbcc5827f1148a31d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20P=C3=A9rez?= Date: Tue, 9 Jun 2026 12:01:43 -0400 Subject: [PATCH] fix(report): serve dashboard_state on connect and STATE_REQ Replace CONFIG_REQ/BRIDGE_REQ handlers with unified state push for monitor TCP clients. --- .../twisted_adapters/report_server.py | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/adn_server/infrastructure/twisted_adapters/report_server.py b/src/adn_server/infrastructure/twisted_adapters/report_server.py index f7ccb07..670c97e 100644 --- a/src/adn_server/infrastructure/twisted_adapters/report_server.py +++ b/src/adn_server/infrastructure/twisted_adapters/report_server.py @@ -57,8 +57,7 @@ class ReportProtocol(NetstringReceiver): addr = f"{peer.host}:{peer.port}" if peer else "?" logger.info("(REPORT) Client connected from %s (%s client(s))", addr, len(self._factory.clients)) self._factory._send_hello_to(self) - self._factory._send_config_to(self, full_snapshot=True) - self._factory._send_bridge_to(self, full_snapshot=True) + self._factory._send_state_to(self, force=True) def connectionLost(self, reason: Any = None) -> None: if self in self._factory.clients: @@ -66,10 +65,12 @@ class ReportProtocol(NetstringReceiver): logger.info("(REPORT) Client disconnected (%s client(s))", len(self._factory.clients)) def stringReceived(self, data: bytes) -> None: - if data[:1] == REPORT_OPCODES["CONFIG_REQ"]: - self._factory._send_config_to(self, full_snapshot=True) - elif data[:1] == REPORT_OPCODES["BRIDGE_REQ"]: - self._factory._send_bridge_to(self, full_snapshot=True) + if data[:1] in ( + REPORT_OPCODES["STATE_REQ"], + REPORT_OPCODES["CONFIG_REQ"], + REPORT_OPCODES["BRIDGE_REQ"], + ): + self._factory._send_state_to(self, force=True) class ReportServerFactory(Factory): @@ -138,25 +139,22 @@ class ReportServerFactory(Factory): except Exception as e: logger.warning("(REPORT) Failed to send HELLO: %s", e) - def _send_config_to(self, client: ReportProtocol, *, full_snapshot: bool) -> None: + def _send_state_to(self, client: ReportProtocol, *, force: bool) -> None: self._send_frames( client, - self._wire.config_frames(self._systems_for_report(), full_snapshot=full_snapshot), + self._wire.state_frames(self._systems_for_report(), force=force), ) - def _send_bridge_to(self, client: ReportProtocol, *, full_snapshot: bool) -> None: - self._send_frames(client, self._wire.bridge_frames(self._bridges, full_snapshot=full_snapshot)) - def send_config(self, *, incremental: bool = False) -> None: systems = self._systems_for_report() - frames = self._wire.config_frames(systems, full_snapshot=not incremental) + frames = self._wire.state_frames(systems, force=not incremental) self._broadcast_frames(frames) if self._mqtt is not None: self._mqtt.publish_dashboard(systems) def send_bridge(self, *, incremental: bool = False) -> None: - frames = self._wire.bridge_frames(self._bridges, full_snapshot=not incremental) - self._broadcast_frames(frames) + if self._mqtt is not None: + self._mqtt.publish_dashboard(self._systems_for_report()) def send_bridge_event(self, event: str) -> None: peer_slots = self._peer_slot_map() if self._peer_slot_map is not None else None