{"record":{"id":"c62f046ec65c3a92","repo":"siyuan-note/siyuan","slug":"encrypted-document-history-root-id-does-not-match","errorCode":null,"errorMessage":"encrypted document history root ID does not match its filename","messagePattern":"encrypted document history root ID does not match its filename","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":224,"sourceCode":"\t}\n\tisLargeDoc = 1024*1024*1 <= len(data)\n\n\tluteEngine := NewLute()\n\tif err = treenode.CheckSpecJSON(data); nil != err {\n\t\treturn\n\t}\n\thistoryTree, err := dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"parse tree from file [%s] failed: %s\", historyPath, err)\n\t\treturn\n\t}\n\tif err = treenode.RefreshTableCellRichProjection(historyTree.Root); nil != err {\n\t\treturn\n\t}\n\tid = historyTree.Root.ID\n\trootID = historyTree.Root.ID\n\tif ciphertext && rootID+\".sy\" != filepath.Base(historyPath) {\n\t\treturn \"\", \"\", \"\", false, errors.New(\"encrypted document history root ID does not match its filename\")\n\t}\n\n\tif !isLargeDoc {\n\t\trenderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}}\n\t\tkeyword = strings.Join(strings.Split(keyword, \" \"), search.TermSep)\n\t\tkeywords := search.SplitKeyword(keyword)\n\n\t\tvar unlinks []*ast.Node\n\t\tast.Walk(historyTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {\n\t\t\tif !entering {\n\t\t\t\treturn ast.WalkContinue\n\t\t\t}\n\n\t\t\t// 数据历史浏览时忽略内容块折叠状态 https://github.com/siyuan-note/siyuan/issues/5778\n\t\t\tn.RemoveIALAttr(\"heading-fold\")\n\t\t\tn.RemoveIALAttr(\"fold\")\n\n\t\t\tif highlight && 0 < len(keywords) {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L206-L242","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Restore the original filename by opening the (decrypted) tree and renaming the file to <root.ID>.sy","If you know which snapshot the renamed file is, locate the matching entry in the history list UI instead of addressing the file directly","Regenerate the history snapshot by editing the document and letting SiYuan write a new history entry","Do not manually rename files under data/history/; treat that directory as managed by the kernel"],"exampleFix":"// before: renamed file breaks the ID-filename binding\n// data/history/20260918/<boxID>/snapshot-old.sy  (root ID: 20260918091234-abc123)\n// after: rename back to the root ID\n// data/history/20260918/<boxID>/20260918091234-abc123.sy","handlingStrategy":"validation","validationCode":"// filename must be <rootID>.sy; derive paths from history list APIs, never rename files\nconst ok = /^[0-9]{14}-[0-9a-f]{7}\\.sy$/.test(baseName) || isKernelGenerated(historyPath);","typeGuard":null,"tryCatchPattern":"try { await historyGet({ historyPath }) } catch (e) { if (String(e.msg).includes('root ID does not match')) { await refreshHistoryIndex(); } else { throw e } }","preventionTips":["Always obtain history paths from the history query API","Never rename files inside data/history/","Let the kernel regenerate snapshots rather than transplanting content between entries"],"tags":["encryption","history","integrity-check"],"backgroundTag":"checksum-mismatch","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}