@Licat It is now 100% consistently reproducible in my case. Bug report filed to the corresponding plugin repository: [BUG] External file updates lost during Capture prompt · Issue #210 · chhoumann/quickadd · GitHub . Could really use some suggestions on how to fix that either on the Sync side or the plugin side.

In summary, it turns out a plugin (Quickadd) has a long running operation (prompt for user typing). It reads the file before that, and writes the updated file afterwards based on the version it read. The Obsidian Sync updates the same file during that prompt period.

this.app.vault.read(file)
const newFileContent: string = await this.formatter.formatContentWithFile(content, this.choice, fileContent, file);
    // the above function waits for user input. 
this.app.vault.modify(file, newFileContent);

I’m not sure what’s the best practice here, deferring the file read operation to after the user input finishes seems like a solution, but I don’t know much about Obsidian’s API / plugin dev.

1 Like

Ah yes, I see the bug report, and thank you!

There isn’t much we can do on Obsidian’s side unfortunately, but it should be fairly easy to fix it from the plugin’s perspective.

Most of the time, plugins are encouraged to read-process-write as quickly as possible to avoid conflicts. Reading and then waiting for user input is definitely before finally writing is definitely troublesome.

If a plugin requires user input, but must also read the file beforehand, we recommend reading again after user input just to verify the file hasn’t changed, and show a notice if the file has changed (or cancel the action) to avoid overwriting.

1 Like

I’ve been noticing this behavior as well, primarily with my Daily note, which I start on my desktop usually, and then later in the day may add something from my phone.

I have the Daily notes plugin setup with a Template, and the setting to “Open daily note on startup” enabled.

I believe what’s happening is that my phone starts Obsidian up, and goes to open the Daily note. It doesn’t seem like the Sync has happened (or completed) yet, so it creates a new file using the defined Template. Sync then runs and sees a more recent version of the Daily note file, and uploads that, overwriting the version from my desktop.

I can mitigate for myself for the time being by not using the “Open daily note on startup” option for the time being.

So repo steps for me at least (happens every time):

  1. Make sure Daily note hasn’t been created yet on either device
  2. Have Daily notes plugin setup with “Template” set and “Open daily note on startup” turned on for both Desktop and Phone
  3. Open Obsidian only on Desktop, so that Daily Note is created
  4. Make edits to Daily note (and ensure it Syncs)
  5. Open Obsidian on phone
  6. Edits are overwritten with newly created Daily note from phone with Template

Sync Log

Desktop:

2022-03-04 16:22 - Connecting to server
2022-03-04 16:22 - Connection successful. Detecting changes...
2022-03-04 16:22 - Uploading file Journal/2022-03-04.md
2022-03-04 16:22 - Upload complete Journal/2022-03-04.md
2022-03-04 16:22 - Server pushed [MARS] Journal/2022-03-04.md
2022-03-04 16:22 - Fully synced
2022-03-04 16:22 - Uploading file Journal/2022-03-04.md
2022-03-04 16:22 - Upload complete Journal/2022-03-04.md
2022-03-04 16:22 - Server pushed [MARS] Journal/2022-03-04.md
2022-03-04 16:22 - Fully synced
2022-03-04 16:22 - Server pushed [Pixel 3] Journal/2022-03-04.md
2022-03-04 16:22 - Downloading file Journal/2022-03-04.md
2022-03-04 16:22 - Downloading complete Journal/2022-03-04.md
2022-03-04 16:22 - Accepted Journal/2022-03-04.md
2022-03-04 16:22 - Fully synced

Phone:

2022-03-04 16:22 - Connecting to server
2022-03-04 16:22 - Connection successful. Detecting changes...
2022-03-04 16:22 - Server pushed [MARS] Journal/2022-03-04.md
2022-03-04 16:22 - Merging conflicted file Journal/2022-03-04.md
2022-03-04 16:22 - Accepted Journal/2022-03-04.md
2022-03-04 16:22 - Uploading file Journal/2022-03-04.md
2022-03-04 16:22 - Upload complete Journal/2022-03-04.md
2022-03-04 16:22 - Server pushed [Pixel 3] Journal/2022-03-04.md
2022-03-04 16:22 - Fully synced

I can see that a merge is happening, but maybe because the file is considered to be newly created (and so all edits are “newer”), it uses that as the source of truth?

Obsidian Desktop v0.13.23
Obsidian Mobile (Android): v1.1.0

2 Likes

that’s a different issue and will be fixed in 0.13.26 and 1.1.1

2 Likes