📚 Encyclopedia

Web Development · updated 2026-10-13

Client/server sync pitfalls (deletes, timestamps, merge policies)

syncofflinetombstoneshard-deletepollingdraftslocal-storageconflict-resolution

Apps that keep user data locally (drafts, personal bests, settings) and sync it to a server accumulate the same handful of bugs. These were all found in Run (Flutter game with a PHP API) during 2026-07 and 2026-10 audits; the lessons are general.

Bugs and their fixes

Delete propagation without a tombstone table (tldr DM hard delete)

tldr v1.48.0 (2026-08-15) added sender-only hard delete of single DM messages. Design and the races review found: - DELETE /dm/messages/{id} does the ownership check inside the statement (WHERE id=? AND sender=?) and returns 404 for both unknown ids and other people's messages, so ids cannot be probed. The client treats 404 as success, which makes retries idempotent. - There is no tombstone table. Other clients learn of a delete only because the chat screen does a full fetch every 5th poll (about every 20 s) and removes ids that were known before the fetch but are absent from the snapshot. Do not optimize that full fetch away without adding a deleted_ids feed, or deletes silently stop propagating. - Capture "known ids" before the await: a stale snapshot must never judge messages that arrived during the fetch (that bug deleted just-sent messages). - Keep a session tombstone set of locally deleted ids so an in-flight poll cannot resurrect them. - Merge, never overwrite, in the final state update; dedupe the optimistic bubble at swap time. - The fetch must return null on failure and [] for a genuinely empty thread, or deleting the last message never propagates. - Attachments could not be deleted with the message: their URLs live inside E2E ciphertext and the server has no message-to-file ownership record. Never add delete-by-filename to an unauthenticated capability-URL route shared with public posts. - Known leftovers: a push already delivered is not retracted; deleting a thread's only message leaves its last-message date NULL and sinks it to the bottom of the list. - Terminology lesson: Justin's "delete a DM" meant one message, not a conversation.

Local data must be per user

Run's logout kept local PBs, drafts and skins, and the next account to log in on that browser uploaded the previous user's PBs as its own. Namespace local storage by user id (or wipe on logout, a product decision). Same class of bug as singleton caches surviving logout: Singleton services, session caches, and cross-user data leaks in Flutter.

Local storage hygiene

Auth expiry

Clear the session on 401 only (server uses 403 for permission denials), and only when the failing request actually carried a token; otherwise anonymous calls log people out.

See also

Linked from

Sources: message memory (tldr_dm_delete), run memory (architecture-audit-2026-10.md, improvement-cycles.md, session-v085.md)