From fc6a32697f9e0704a6a52bbeb2edf34d92e0f05b Mon Sep 17 00:00:00 2001 From: Moritz Graf Date: Sun, 18 Oct 2026 20:31:45 +0200 Subject: [PATCH] fix(garmin): format sync payload with canonical list keys and verify synced counts --- skills/datastore/scripts/garmin_sync.py | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/skills/datastore/scripts/garmin_sync.py b/skills/datastore/scripts/garmin_sync.py index 14dd094..8508758 100755 --- a/skills/datastore/scripts/garmin_sync.py +++ b/skills/datastore/scripts/garmin_sync.py @@ -428,9 +428,11 @@ def sync_date_range( try: sync_payload = { "date": d, + "daily": [summary] if summary else [], + "sleep": [sleep] if sleep else [], + "activities": activities or [], "daily_summary": summary, "sleep_data": sleep, - "activities": activities, } sync_url = f"{target_backend}/garmin/sync" req = urllib.request.Request( @@ -440,9 +442,27 @@ def sync_date_range( method="POST", ) with urllib.request.urlopen(req, timeout=30) as resp: - if resp.status == 200: - logger.info(f"Successfully posted Garmin sync for {d} to backend") + resp_body = {} + try: + resp_body = json.loads(resp.read().decode("utf-8")) + except Exception: + pass + + expected_records = (1 if summary else 0) + (1 if sleep else 0) + (len(activities) if activities else 0) + synced_records = ( + resp_body.get("synced_daily", 0) + + resp_body.get("synced_sleep", 0) + + resp_body.get("synced_activities", 0) + ) + + if resp.status == 200 and (expected_records == 0 or synced_records > 0): + logger.info(f"Successfully posted Garmin sync for {d} to backend: {resp_body}") synced_via_backend = True + else: + logger.warning( + f"Backend returned HTTP {resp.status} for {d} but synced {synced_records} records " + f"(expected {expected_records}): {resp_body}. Falling back to local writer." + ) except Exception as e: logger.warning(f"Failed to sync via backend {target_backend} for {d}: {e}. Falling back to local writer if available.")