From 5be3bb842dd7c9a88d332266ef14914aed72c71a Mon Sep 17 00:00:00 2001 From: ciregenz Date: Thu, 6 Aug 2026 22:40:49 -0700 Subject: [PATCH] [eric] telemetry: OPENSWARM_DIAG_SINK writes every diagnostic to a rotating local flight file --- backend/apps/service/client.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/apps/service/client.py b/backend/apps/service/client.py index 3a84ae29..705f340b 100644 --- a/backend/apps/service/client.py +++ b/backend/apps/service/client.py @@ -399,6 +399,18 @@ def submit_diagnostic(diagnostic: dict) -> None: diagnostic["recent_log"] = snapshot() except Exception: pass + # The local flight file: every diagnostic also lands in a rotating NDJSON when the sink is set, + # so support is "send me one file" and forced-failure tests can verify envelopes offline. + sink = os.environ.get("OPENSWARM_DIAG_SINK") + if sink: + try: + import json as p_json + if os.path.exists(sink) and os.path.getsize(sink) > 1_000_000: + os.replace(sink, sink + ".0") + with open(sink, "a", encoding="utf-8") as f: + f.write(p_json.dumps({"t": time.time(), **diagnostic}, default=str) + "\n") + except OSError: + pass submit("diagnostic", {"diagnostic": diagnostic})