{"record":{"id":"bfc45eb116839914","repo":"siyuan-note/siyuan","slug":"encrypted-attribute-view-history-is-missing-notebo","errorCode":null,"errorMessage":"encrypted attribute view history is missing notebook context [%s]","messagePattern":"encrypted attribute view history is missing notebook context \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":389,"sourceCode":"\t}\n\tif encrypted && tree.Root.ID+\".sy\" != filepath.Base(historyPath) {\n\t\treturn errors.New(\"encrypted document history root ID does not match its filename\")\n\t}\n\tboundRecovery := &Transaction{trees: map[string]*parse.Tree{}}\n\tdefer func() { boundRecovery.finishAttributeViewMutation(err != nil) }()\n\tif nil != tree {\n\t\thistoryDir := filepath.Join(util.HistoryDir, parts[0])\n\n\t\tavNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)\n\t\tfor _, avNode := range avNodes {\n\t\t\tsrcAvPath := filepath.Join(historyDir, \"storage\", \"av\", avNode.AttributeViewID+\".json\")\n\t\t\t// 加密笔记本的 AV 定义在笔记本级目录\n\t\t\tdestAvPath := filepath.Join(util.DataDir, \"storage\", \"av\", avNode.AttributeViewID+\".json\")\n\t\t\tif IsEncryptedBox(boxID) {\n\t\t\t\t// 历史目录里 AV 也可能在 boxID 子目录下\n\t\t\t\tboxSrcAvPath := filepath.Join(historyDir, boxID, \"storage\", \"av\", avNode.AttributeViewID+\".json\")\n\t\t\t\tif !gulu.File.IsExist(boxSrcAvPath) {\n\t\t\t\t\treturn fmt.Errorf(\"encrypted attribute view history is missing notebook context [%s]\", avNode.AttributeViewID)\n\t\t\t\t}\n\t\t\t\tsrcAvPath = boxSrcAvPath\n\t\t\t\tdestAvPath = filepath.Join(util.DataDir, boxID, \"storage\", \"av\", avNode.AttributeViewID+\".json\")\n\t\t\t}\n\t\t\tif gulu.File.IsExist(destAvPath) {\n\t\t\t\tavBoxID := \"\"\n\t\t\t\tif encrypted {\n\t\t\t\t\tavBoxID = boxID\n\t\t\t\t}\n\t\t\t\tif err = boundRecovery.restoreEmbeddedAttributeViewHistory(srcAvPath, avBoxID, avNode.AttributeViewID); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tavIDs = append(avIDs, avNode.AttributeViewID)\n\t\t}\n\t}\n\tavIDs = gulu.Str.RemoveDuplicatedElem(avIDs)","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L371-L407","documentation":"RollbackDocHistory restores a deleted document from history. For encrypted notebooks, the attribute-view (AV) definition files live in a notebook-level storage/av directory, and the rollback requires the corresponding AV JSON to exist under the historyDir/boxID subdirectory. When the history snapshot for the encrypted notebook does not contain the AV definition, the rollback is aborted with this error naming the attribute view ID.","triggerScenarios":"Calling RollbackDocHistory on a document from an encrypted notebook whose history snapshot lacks storage/av/<avID>.json under historyDir/<boxID>/ — e.g. the AV was created after the history snapshot was taken, the snapshot was pruned, or the history was copied without the AV folder.","commonSituations":"Restoring an old snapshot of a document containing a database (attribute view) in an encrypted notebook where the AV was added or modified after the snapshot; manually trimmed or partially copied history directories; restoring history synced from another machine with incomplete AV capture.","solutions":["Locate the AV definition <avID>.json and copy it into historyDir/<boxID>/storage/av/ before retrying the rollback","Re-run document history capture for the encrypted notebook so the AV definition is included in a fresh snapshot","If the AV data is unrecoverable, roll back the document and recreate the attribute view manually"],"exampleFix":"// before: AV JSON missing in history snapshot\nhistoryDir/<boxID>/storage/av/  (empty)\n// after: place the AV definition beside the document snapshot\ncp data/storage/av/<avID>.json history/<op>-<timestamp>/<boxID>/storage/av/<avID>.json","handlingStrategy":"validation","validationCode":"const avPath = `history/${entryPath}/${boxID}/storage/av/${avID}.json`;\nif (!fs.existsSync(avPath)) { throw new Error(`AV history ${avID} missing; restore snapshot first`); }","typeGuard":null,"tryCatchPattern":"try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('missing notebook context')) { await restoreAvIntoSnapshot(avID, boxID); await rollbackDocHistory(p); } else { throw e; } }","preventionTips":["Never prune AV files independently of document snapshots in history directories","Copy whole history entry directories, not individual files","After creating a database in an encrypted notebook, take a fresh history snapshot before deleting the doc"],"tags":["history","attribute-view","encrypted-notebook","rollback"],"backgroundTag":"file-not-found","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"}