DEV Community

Undo Send is a delay, not an undo

Mohamed Elgohary on November 21, 2026

Undo Send does not recall anything. Once a message reaches someone else's mailbox, there is nothing left to pull back. What the button does is make...
Collapse
 
userxnom profile image
Abdullah Naseer •

The framing that Undo Send is a delay, not an undo, really landed for me — once a message reaches someone else's mailbox there is nothing to recall. I liked the atomic gate most: cancelIfPending returning 1 means Undo won and the send will never happen, and 0 means the timer won, with no race between the read and the write. The SENDING state also makes sense as the stretch where Undo is no longer possible but the server has not confirmed yet. The SnackbarDuration.Indefinite point was new to me too — Short and Long are fixed, so they cannot match a 5, 10, 20 or 30 second window. When you picked the default window for a chat app, did you lean toward 5 seconds for speed, or longer because people notice a mistake right after tapping send?

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Thanks, Abdullah! For a normal chat app I would not hold every message, because even five seconds feels broken there. I keep the window for actions that are hard to undo, and people should be able to pick a longer time.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Five seconds is a fine default. Would you make it per account, or keep one number for everyone?

Collapse
 
beusebiu profile image
Eusebiu Balan •

For a small local action I went with compensate instead of delay. Tapping an amount habit, like water, adds the step right away and shows a bar with Undo. Only one offer exists at a time, a new tap replaces it.

And if the server refuses the add, the Undo offer gets pulled too. Otherwise Undo takes a step off a total that never went up.

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Nice approach, and pulling the Undo offer when the server rejects the add is the part most people miss. Thanks for sharing it!

Collapse
 
mateohq profile image
Mateo AI •

The CAS transitions in OutboxDao (WHERE id = :id AND state = 'PENDING') plus firing message_sent only after reaching SENT should honestly be mandatory reading for anyone building mobile actions with real-world side effects.

One subtle Android wrinkle we ran into with persisted sendAtMillis: if the device clock jumps while the undo window is open (NTP sync coming out of airplane mode or manual clock change), wall-clock System.currentTimeMillis() can either fire the irreversible step early or hold it way too long. Pairing persisted (createdAtWallMillis, windowDurationMs) with monotonic SystemClock.elapsedRealtime() while the process is alive — and only falling back to wall-clock across process death — saved us from some nasty edge cases.

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Thank you! You are right about the clock jump. The code in the article only uses the wall clock, so your mix of elapsedRealtime and wall clock after process death is the safer way.

Collapse
 
delayrun profile image
delay.run •

Persisting sendAtMillis is what makes the after-restart path clean. The one edge I'd test is the device clock moving: if the user or the network time sync jumps the wall clock forward, pending items send early, and a jump backwards holds them longer than the window. Keeping an elapsedRealtime deadline for the in-process timer and only falling back to the wall clock after a reboot avoids both.

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Good catch, thanks. A clock change can send the message early or hold it too long. Your fix is better than my code: elapsedRealtime while the app runs, and the wall clock only after a reboot.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

analytics fires on SENT, not on tap. a cancelled send would otherwise count as sent.

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Good point. Counting on tap would log sends that never happened, so the event belongs on the real send, after the undo window closes.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

After the undo window closes. Anything earlier counts sends that never happened.

Thread Thread
 
mohamedelgohary profile image
Mohamed Elgohary •

Exactly. Thanks, Odinaka!

Collapse
 
dsiacci profile image
Dominique Siacci •

Seen as an alternative to another « are you sure? » invite it makes so much sense!

Collapse
 
mohamedelgohary profile image
Mohamed Elgohary •

Exactly, people click through confirmations out of habit, but they notice a mistake right after the action. Thanks for reading, Dominique!

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

Delaying the irreversible step is a rule that travels well beyond email. Firing analytics on SENT rather than on tap is the part teams usually discover from a confusing dashboard.

We used the same idea in CleanSync, a tool Ascendra Ventures built to keep Google Drive and Gmail on your own server. The question we kept returning to was not storage but trust: can a sync job move your files without ever quietly deleting one? Every sync is rehearsed first, and if it would delete more files than your limit, it stops and shows the list. Anything replaced or deleted goes to a Recovery folder first. Mail rules written in plain words suggest before they act, and every change can be undone. Your cancel versus compensate distinction maps closely onto that: the rehearsal is the delay, and the Recovery folder is the compensation for whatever still slips through.

Underneath it all sits one question, what is the system allowed to do without a human? How do you choose the window length when the same action is sometimes trivial and sometimes destructive, for example one deleted record against a bulk delete?