siyuan-note/siyuan · error

encrypted document history root ID does not match its…

Error message

encrypted document history root ID does not match its filename

What it means

After successfully decrypting an encrypted history snapshot, GetDocHistoryContent validates that the tree's root block ID matches the filename (<rootID>.sy). A mismatch means the ciphertext file was renamed or its contents were transplanted into a differently-named file, breaking the integrity invariant that encrypted history filenames authenticate their content. The lookup fails closed rather than serving unverified content.

Solutions

  1. Restore the original filename by opening the (decrypted) tree and renaming the file to <root.ID>.sy
  2. If you know which snapshot the renamed file is, locate the matching entry in the history list UI instead of addressing the file directly
  3. Regenerate the history snapshot by editing the document and letting SiYuan write a new history entry
  4. Do not manually rename files under data/history/; treat that directory as managed by the kernel

Example fix

// before: renamed file breaks the ID-filename binding
// data/history/20260918/<boxID>/snapshot-old.sy  (root ID: 20260918091234-abc123)
// after: rename back to the root ID
// data/history/20260918/<boxID>/20260918091234-abc123.sy
Defensive patterns

Strategy: validation

Validate before calling

// filename must be <rootID>.sy; derive paths from history list APIs, never rename files
const ok = /^[0-9]{14}-[0-9a-f]{7}\.sy$/.test(baseName) || isKernelGenerated(historyPath);

Try / catch

try { await historyGet({ historyPath }) } catch (e) { if (String(e.msg).includes('root ID does not match')) { await refreshHistoryIndex(); } else { throw e } }

Prevention

When it happens

Trigger: Calling GetDocHistoryContent with a path to a ciphertext history .sy whose internal root document ID does not equal filepath.Base(historyPath) minus the .sy extension — typically after the file was renamed on disk.

Common situations: Users or backup tools renamed history files to deduplicate or reorganize; scripts that copy history snapshots and rename them by date; restoring partial backups where the index and filenames no longer correspond.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c62f046ec65c3a92. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history.go:224

	}
	isLargeDoc = 1024*1024*1 <= len(data)

	luteEngine := NewLute()
	if err = treenode.CheckSpecJSON(data); nil != err {
		return
	}
	historyTree, err := dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
	if err != nil {
		logging.LogErrorf("parse tree from file [%s] failed: %s", historyPath, err)
		return
	}
	if err = treenode.RefreshTableCellRichProjection(historyTree.Root); nil != err {
		return
	}
	id = historyTree.Root.ID
	rootID = historyTree.Root.ID
	if ciphertext && rootID+".sy" != filepath.Base(historyPath) {
		return "", "", "", false, errors.New("encrypted document history root ID does not match its filename")
	}

	if !isLargeDoc {
		renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}}
		keyword = strings.Join(strings.Split(keyword, " "), search.TermSep)
		keywords := search.SplitKeyword(keyword)

		var unlinks []*ast.Node
		ast.Walk(historyTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
			if !entering {
				return ast.WalkContinue
			}

			// 数据历史浏览时忽略内容块折叠状态 https://github.com/siyuan-note/siyuan/issues/5778
			n.RemoveIALAttr("heading-fold")
			n.RemoveIALAttr("fold")

			if highlight && 0 < len(keywords) {

View on GitHub (pinned to 9f775e8a12)