Skip to content

fix(telemetry): preserve client sync status on heartbeat ping - #124

Open
markusbrand wants to merge 1 commit into
masterfrom
fix/preserve-client-ping-sync-status
Open

markusbrand wants to merge 1 commit into
masterfrom
fix/preserve-client-ping-sync-status

Conversation

@markusbrand

Copy link
Copy Markdown
Owner

Overview

Fixes a bug where heartbeat or presence pings that omit sync outcome (last_sync_at and last_sync_ok, such as web app logins/pings or periodic client presence pings) overwrite previously recorded sync status in client_connections with NULL.

Problem & Root Cause

In backend/app/telemetry/service.py, upsert_client_ping used SQLite's ON CONFLICT DO UPDATE with unconditional assignment:

set_=dict(
    client_version=stmt.excluded.client_version,
    last_seen_at=stmt.excluded.last_seen_at,
    last_sync_at=stmt.excluded.last_sync_at,
    last_sync_ok=stmt.excluded.last_sync_ok,
    backend_version_at_ping=stmt.excluded.backend_version_at_ping,
)

When stmt.excluded.last_sync_at and stmt.excluded.last_sync_ok are null (the default when pings do not report sync results), the existing valid sync status was completely erased by NULL, causing admin telemetry and client connection views to lose sync history.

Solution

  • Wrapped last_sync_at and last_sync_ok in func.coalesce in backend/app/telemetry/service.py:
    last_sync_at=func.coalesce(stmt.excluded.last_sync_at, ClientConnection.last_sync_at),
    last_sync_ok=func.coalesce(stmt.excluded.last_sync_ok, ClientConnection.last_sync_ok),
  • Retains existing sync records when incoming ping fields are NULL, while still updating when actual sync results (including last_sync_ok = False) are reported.
  • Added regression test test_client_ping_preserves_sync_status in backend/tests/test_web_features.py.
  • Tracked via OpenSpec change preserve-client-ping-sync-status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant