siyuan-note/siyuan · critical

duplicate encrypted document ID [%s]

Error message

duplicate encrypted document ID [%s]

What it means

The encrypted index rebuild collects every document root ID in a set; if two .sy files decrypt to documents with the same root ID, the second occurrence aborts the rebuild with this error. The SQLite index keys blocks by ID, so duplicates would corrupt block resolution, making this a hard integrity failure.

Source

Thrown at kernel/model/encrypted_index.go:82

			return fmt.Errorf("encrypted document is a symbolic link [%s]", entry.Name())
		}
		data, err := filelock.ReadFile(filePath)
		if err != nil {
			return err
		}
		plain, err := DecryptFile(boxID, entry.Name(), dek, data)
		if err != nil {
			return err
		}
		tree, err := loadTreeByData0(plain)
		if err != nil {
			return err
		}
		if tree == nil || tree.Root == nil || tree.Root.ID+".sy" != entry.Name() {
			return fmt.Errorf("encrypted document root ID does not match filename [%s]", entry.Name())
		}
		if _, exists := ids[tree.Root.ID]; exists {
			return fmt.Errorf("duplicate encrypted document ID [%s]", tree.Root.ID)
		}
		ids[tree.Root.ID] = struct{}{}
		return nil
	})
}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Identify both files whose decrypted root IDs collide and delete or move out the stale/unwanted duplicate.
  2. If both copies are wanted, re-import the duplicate through the app so it receives a fresh root ID, then rebuild indexes.
  3. Restore the box data directory from a clean sync snapshot and retry the rebuild.

Example fix

// before
data/boxes/<box>/20240101120000-abc.sy
data/boxes/<box>/20240101120000-abc (copy).sy  // same root ID
// after
delete "20240101120000-abc (copy).sy" or re-import it in-app with a new ID
Defensive patterns

Strategy: validation

Validate before calling

seen := map[string]string{} // rootID -> filename
for _, f := range syFiles {
    id := rootIDFromTree(f)
    if prev, dup := seen[id]; dup {
        return fmt.Errorf("%s and %s share root ID %s", prev, f, id)
    }
    seen[id] = f
}

Prevention

When it happens

Trigger: Two files in the encrypted box's documents directory contain (decrypted) documents with identical root IDs — e.g. a document was duplicated by file copy (copy-of-<id>.sy) while the copy operation duplicated content instead of assigning a fresh ID, or a sync conflict left both the original and a byte-identical/mutated copy under different names.

Common situations: cp/duplicate file operations performed directly on the data directory instead of via the app (which assigns new IDs); restore of overlapping sync snapshots; manual merging of two workspaces containing the same document.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/91204753b1e79f69. Report an issue: GitHub.