On Android, changes are lost or file is truncated when app is cleared from recent apps list

Steps to reproduce

  • On Android Obsidian, create a new file or open an existing file with contents.
  • At the end of the file, type something new.
  • Open the recent apps list and swipe Obsidian from the list (to terminate the app).

This causes Android to close the Obsidian app. If you’re on a low-memory device, when you switch apps Android can kill Obsidian even if you don’t swipe it from the recent apps list.

Did you follow the troubleshooting guide? [Y/N]

Yes.

Expected result

Changes are saved.

Actual result

The last few seconds of changes are lost and not saved.

If you edited a sufficiently long file (multiple megabytes), and close Obsidian at the right time after opening recent apps, you can close Obsidian while it’s saving the file non-atomically, leaving the file truncated on disk (and parts of the contents missing forever)! This happened once in the past and I had to restore the file from backup, and I replicated it twice in a few minutes on a 2.7 megabyte test file.

Environment

SYSTEM INFO:
Operating system: android 14 (Google Pixel 4a)
Obsidian version: 1.7.7 (171)
API version: v1.7.7
Login status: not logged in
Language: en
Live preview: on
Base theme: light
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none


Additional information

  • I’m running Lineage OS rather than stock Android.
  • The bug occurs both with Syncthing-Fork running and killed.

Video recording of lost changes and truncated file: https://youtube.com/watch?v=VwUwDQHxPxA

If you loss involves the just the last few words (two second edit), we are aware of it. I can’t find the related bug report right now.

If this causes the corruption of the note, we would like to know more.

The bug causes corruption (truncation) of the note on rare occasions, I’ve had three incidents so far (one on a real file and two while testing this bug).