Skip to content

fix(db): upsert_client_sync: use ON CONFLICT DO UPDATE instead of INSERT OR REPLACE#6

Open
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-upsert
Open

fix(db): upsert_client_sync: use ON CONFLICT DO UPDATE instead of INSERT OR REPLACE#6
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-upsert

Conversation

@tjdownes
Copy link
Copy Markdown
Owner

@tjdownes tjdownes commented May 1, 2026

Summary

  • INSERT OR REPLACE deletes and re-inserts the row, resetting any columns not included in the statement
  • Replaced with INSERT ... ON CONFLICT DO UPDATE SET ... to safely update only the specified columns

Test plan

  • Device test: verify client sync state is preserved correctly across updates

…ERT OR REPLACE

INSERT OR REPLACE is not a true upsert — SQLite deletes the conflicting row
and inserts a brand-new one, resetting every column that was not supplied to
its default value.

The most visible consequence: add_post() calls

    upsert_client_sync(sync_since=X, last_activity=Y)

to prevent echoing a message back to its author.  Under the old code this also
silently zeroed push_failures for that client, defeating the push-failure
circuit breaker that is supposed to evict unreachable clients after
MAX_PUSH_FAILURES consecutive failures.

Fix: switch to INSERT … ON CONFLICT(room_hash, client_pubkey) DO UPDATE SET
<only caller-supplied columns>.  The INSERT path still supplies full defaults
for new rows; the UPDATE path only modifies what the caller explicitly passed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tjdownes tjdownes force-pushed the fix/room-server-upsert branch from 6630c19 to 1beb5bc Compare May 1, 2026 13:38
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