Synced preferences: send synced_preferences_base_hash and handle the conflict #308

Open
opened 2026-11-12 14:56:39 +00:00 by charles · 0 comments
Owner

Found while doing Text chat 14 (#264).

The original sends synced_preferences_base_hash (lowercase hex SHA-256 of the decoded snapshot the change was built on) with every PATCH /users/@me/settings {synced_preferences} (fluxer_app/src/features/user/state/UserSettings.ts:1001); the server then refuses a write built on a stale snapshot with 409 SYNCED_PREFERENCES_CONFLICT (fluxer_api/src/api/user/services/UserAccountSettingsService.ts:274).

fluxer-core cannot hash (it gains no dependency but fluxer-emoji), so Text chat 14 writes without the hash. The write is built on the last snapshot received and copies every field it did not change byte for byte, but if another device changes a non-picker field and this client writes before that USER_SETTINGS_UPDATE arrives (a window of the 1.5 s debounce plus latency), the other device's change is overwritten (last writer wins on the whole snapshot).

To do: compute the hash where hashing is allowed (in fluxer-proto's prefs codec with a small SHA-256 dependency, or in the runtime when it carries out PatchUserSettings), send it, and on 409 re-read the settings and re-apply the local change.

Found while doing Text chat 14 (#264). The original sends `synced_preferences_base_hash` (lowercase hex SHA-256 of the decoded snapshot the change was built on) with every `PATCH /users/@me/settings {synced_preferences}` (`fluxer_app/src/features/user/state/UserSettings.ts:1001`); the server then refuses a write built on a stale snapshot with 409 `SYNCED_PREFERENCES_CONFLICT` (`fluxer_api/src/api/user/services/UserAccountSettingsService.ts:274`). `fluxer-core` cannot hash (it gains no dependency but `fluxer-emoji`), so Text chat 14 writes without the hash. The write is built on the last snapshot received and copies every field it did not change byte for byte, but if another device changes a non-picker field and this client writes before that `USER_SETTINGS_UPDATE` arrives (a window of the 1.5 s debounce plus latency), the other device's change is overwritten (last writer wins on the whole snapshot). To do: compute the hash where hashing is allowed (in `fluxer-proto`'s prefs codec with a small SHA-256 dependency, or in the runtime when it carries out `PatchUserSettings`), send it, and on 409 re-read the settings and re-apply the local change.
charles added this to the Text chat milestone 2026-11-12 14:56:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/fluxer-native#308
No description provided.