Skip to content

Retry a 1:1 message's sync to our own swarm through the job queue - #2260

Merged
mpretty-cyro merged 4 commits into
session-foundation:devfrom
mpretty-cyro:fix/sync-to-self-retry
Nov 17, 2026
Merged

mpretty-cyro merged 4 commits into
session-foundation:devfrom
mpretty-cyro:fix/sync-to-self-retry

Conversation

@mpretty-cyro

@mpretty-cyro mpretty-cyro commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

After a 1:1 message reaches its recipient, a copy goes to your own swarm so your other devices get it. That copy was sent once from a coroutine. If the send failed, nothing retried it, and nothing could after a restart, because there was no job to resume. One transient network failure left a delivered message showing a red "Failed to sync" for good, and restarting the app didn't clear it. Reported in support ticket 28907.

Changes

  • MessageSender: a stored message's sync is now a MessageSendJob to our own swarm. It gets the same 10 attempts and backoff as any send, and JobQueue.resumePendingJobs resumes it after a restart, so no separate startup sweep is needed. A message with no stored record, such as call signalling, keeps the best-effort coroutine: it has no status to get stuck, and replaying call messages after a restart would be wrong.
  • MessageSendJob: a job can be marked as a sync of a message that was already sent, and that marker is persisted with the job. Such a job marks the message SYNCING on each attempt rather than SENDING. The destination can't tell the two apart, because Note to Self also sends to our own swarm and does need SENDING. Jobs persisted before this change have no marker and stay ordinary sends.
  • MessageSender / ExpiringMessageManager: a landed sync of an already-sent message no longer goes through onMessageSent. That restarted the disappearing-message timer from the moment the sync landed, which now that a sync can land minutes later would keep the message on the sending device for that much longer than anywhere else. onMessageSynced leaves the local timer alone and shortens the own-swarm copy to expire at its sent timestamp plus the timer, which is when linked devices expire it. Because the local timer is never restarted by a sync, a sync that runs at launch can't extend a message whose timer has already passed. Note to Self is still a first send and still starts its timer when it lands.
  • MessageSendJob: a job whose message was deleted, or had expired, before it ran now finishes instead of stopping without marking itself done. Before, its row stayed and was resumed at every launch only to stop again. The same applies when a send fails for a message deleted in the meantime: the job is removed rather than left behind. This affected first sends too, but sync jobs, one per stored 1:1 message, made it far more common.

Stored server hash. This doesn't change which hash is stored: a successful sync still replaces the recipient-swarm hash with the own-swarm one. What changes is when that happens. It can now be minutes later or after a restart, and far fewer messages are left with the recipient-swarm hash because their sync failed for good. See #2258.

In-flight sync vs UnsendRequest: won't be fixed in this client. It's low priority, and it is being tracked for Session 2.0 rather than this client. If a sync attempt is already in flight when the user deletes for everyone, the sync can land in our own swarm after the UnsendRequest, and a linked device may then show the message. Each attempt checks whether the message was deleted before it starts. That covers deletes during backoff and before a resumed job runs, so the remaining window is the flight time of the attempt that lands. That's normally one attempt, the same as before this change. The only addition is an attempt that stored the message but reported failure. This race exists on dev today, and the 1:1 delete marks the message deleted locally only after its own-swarm delete completes. A sync job can't close it alone: after landing it could remove its own copy, but a device that already fetched it would still show the message. A fix that doesn't depend on order belongs in the delete path or on the receiving side.

Open questions, not changed here

  • Messages already stuck. Messages that are already SYNC_FAILED, or SYNCING from a killed process, on existing installs are left as they are. A migration would have to rebuild messages from their records and could send old messages to our own swarm.
  • Resync doesn't sync. The Resync action builds its destination from the message record's recipient, which is the contact, and sends with isSyncMessage = true and no syncTarget. It re-sends to the recipient's swarm and marks the message sent. The label clears, but linked devices still don't get the message.
  • Label. Between retries the message shows "Failed to sync", just as a normal send shows as failed between its retries. Attempts made while offline count toward the 10, as for sends, so an outage longer than the backoff (about 4 minutes) still ends with "Failed to sync". Whether to keep it as "syncing" until the last attempt, or to make the failed state less alarming, is a product decision.

Testing

  • New SyncToSelfTest (10 tests). It drives the real MessageSender.scheduleSyncToSelf, JobQueue and MessageSendJob. The fake network sits at MessageSender.sendNonDurably, because encoding a message needs libsession's native library, which can't load in JVM tests. It covers:
    • a sync that fails 3 times and then succeeds ends SENT, with no SENDING in between;
    • a sync that never succeeds gives up after 10 attempts, still SYNC_FAILED;
    • a sync persisted before a restart is resumed and sent;
    • only a message with a stored record gets a durable job;
    • a Note to Self send still reports SENDING;
    • a landed sync of a sent message calls onMessageSynced, not onMessageSent, and a landed Note to Self send still calls onMessageSent;
    • a sync whose message was deleted before it ran, or no longer exists, sends nothing and its job is removed; one whose message is deleted during a failed attempt is removed rather than retried.
  • New ExpiringMessageManagerSyncTest (3 tests), with a five-minute after-send timer and a sync that lands four minutes late: the local timer isn't restarted and the own-swarm copy is shortened to the sent time plus five minutes; the same message as a first send starts its timer when it lands; a message with no timer shortens nothing.
  • I checked that the tests fail with each change reverted: the sync back to a coroutine, the job marking SENDING, the marker not restored on restart, a landed sync calling onMessageSent, the job not passing the marker to MessageSender, the copy shortened from the landing time, a sync restarting the local timer, and each of the three deleted-message exits leaving the job in place.
  • :app:testPlayDebugUnitTest --rerun-tasks: 435 tests, 0 failures. :app:assemblePlayDebug builds.
  • I have not run this on a device or against the live network.

A send job always marked its message as sending, so a job that only
copies an already-delivered message to our own swarm would show it as
unsent again. The job now carries whether it is such a sync, persisted
with it so a resumed job keeps it; jobs persisted without it are
ordinary sends.
After a 1:1 message reached its recipient, the copy to our own swarm
was a one-shot coroutine. Any transient failure left the delivered
message showing "Failed to sync" permanently: nothing retried it, and a
restart couldn't either because there was no job to resume. A stored
message's sync is now a send job with the same retry and backoff as
any send, and is resumed after a restart. Messages with no stored
record, such as call signalling, keep the best-effort sync.
A landed sync went through the same success handling as a first send,
which started the message's timer again from the moment it landed. Now
that a sync can land minutes later, on a retry or after a restart, a
disappearing message stayed on the sending device for that much longer
than on any other. A sync of an already-sent message now leaves the
timer alone and shortens its own-swarm copy to expire at the sent time
plus the timer, which is when linked devices expire it.
A send job whose message was deleted, or had expired, before it ran
stopped without marking itself done, so its row stayed and was resumed
at every launch only to stop again. The same happened when a send
failed for a message deleted in the meantime. Each of these now
finishes the job. Sync jobs made this far more common, since one is
queued for every stored 1:1 message.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mpretty-cyro
mpretty-cyro marked this pull request as ready for review November 17, 2026 23:11
@mpretty-cyro
mpretty-cyro merged commit aea2674 into session-foundation:dev Nov 17, 2026
11 of 14 checks passed
@mpretty-cyro
mpretty-cyro deleted the fix/sync-to-self-retry branch November 17, 2026 23:48
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