#16690·joplin

All: Sync auto-merge adds a blank line when one device deletes lines the other device edited

Author: InjoraCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbug

Operating system

macOS

Joplin version

dev branch @ 4c0e2bc0 (auto-merge from #16023 is not in any release yet, including 3.7.21)

Desktop version info

No response

Current behaviour

When a sync conflict is partially auto-merged and one device deleted lines that the other device edited, an empty line is inserted where the deleted lines were. The main note is then re-uploaded, so every device gets a blank line that neither device wrote.

Minimal reproduction (two clients, auto-merge enabled):

Body
Base A\nB\nC
Device 2 (syncs first) A\nC (deletes B)
Device 1 A\nX\nC (edits B)

After device 1 syncs:

  • Conflict note: A\nX\nC (correct)
  • Main note: A\n\nC (expected A\nC)
  • Main note updated_time is bumped past the remote's, so it is uploaded on the next sync, and device 2 then receives A\n\nC

Control: if both devices edit B differently (A\nY\nC / A\nX\nC), the main note stays A\nY\nC and is not re-uploaded. The problem only occurs when one side deleted the lines.

This is an unintended modification, not data loss: the local edit is kept in the conflict note and the remote deletion is applied.

Cause: buildBody() in packages/lib/services/conflict/autoMergeNote.ts joins all sections with '\n'. For a conflict section where one side deleted the lines, that side's text is '', but a separator is still emitted. The same happens at the start or end of the note (\nB\nC, A\nB\n) and on either side. In handleConflictAction.ts the rebuilt remote body then no longer equals the real remote body, so remoteUnchanged is false, updated_time is moved ahead and the note is uploaded even though nothing was merged into it.

Why it matters:

  • An edit nobody made is synced to all devices and creates an extra revision.
  • In Markdown a blank line changes meaning. For example, deleting a table row on one device while editing it on another would split the table.
  • When the local side is the one that deleted, the conflict copy gains the blank line instead.

This is related to the "both devices deleted the same line" blank-line case fixed during #16023's review, but it covers the case where only one side deleted. It may also explain the blank line at the top of the note reported during testing in #16023 that couldn't be reproduced at the time.

Expected behaviour

A side that deleted a conflicting region is rebuilt without an extra line, so each side's body matches what that device actually has. When nothing was merged into the remote side, the remote note is not modified or re-uploaded (as should not update the note when the merge changed nothing on the remote side already expects for title conflicts).

Possible direction: '' can't distinguish "zero lines" from "one blank line", so the section probably needs its line count. #16272 adds localLineCount/remoteLineCount to MergedSection for twoWayDiff, and its buildConflictDocument skips the separator for a side that holds no line. Something similar in the three-way merge may be enough.

Acceptance criteria

  • Deletion vs. edit at the start, middle and end of the note, on either side, rebuilds each side exactly.
  • A side that replaced lines with a single blank line keeps that line.
  • Two-client sync test: remote deletes a line that local edits → main note equals the remote body, its updated_time is unchanged, and one conflict note contains the local text.

I'd be happy to investigate and implement a fix if this is considered a bug.

Logs

Reproduced with a two-client Jest test in packages/lib (same harness as Synchronizer.autoMerge.test.ts), not through the app UI.

Bug case: base "A\nB\nC", remote (syncs first) "A\nC", local "A\nX\nC"
  mainBodyOnClient1AfterConflict: "A\n\nC"
  remoteUpdatedTime:        1790580828949
  mainUpdatedTimeOnClient1: 1790580829388   (bumped)
  conflictNoteBodies:       ["A\nX\nC"]
  client2BodyAfterResync:   "A\n\nC"         (uploaded and received by device 2)

Control: remote "A\nY\nC", local "A\nX\nC"
  mainBodyOnClient1AfterConflict: "A\nY\nC"
  updatedTimeBumped: false