siyuan-note/siyuan · error
encrypted attribute view history is missing notebook context
Error message
encrypted attribute view history is missing notebook context [%s]
What it means
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.
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
Example fix
// before: AV JSON missing in history snapshot historyDir/<boxID>/storage/av/ (empty) // after: place the AV definition beside the document snapshot cp data/storage/av/<avID>.json history/<op>-<timestamp>/<boxID>/storage/av/<avID>.json
Defensive patterns
Strategy: validation
Validate before calling
const avPath = `history/${entryPath}/${boxID}/storage/av/${avID}.json`;
if (!fs.existsSync(avPath)) { throw new Error(`AV history ${avID} missing; restore snapshot first`); } Try / catch
try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('missing notebook context')) { await restoreAvIntoSnapshot(avID, boxID); await rollbackDocHistory(p); } else { throw e; } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- attribute view snapshot context is ambiguous
- can not get or create rollback box
- conditional replacement of encrypted attribute views is not…
- Conf.Language(314)
- Conf.Language(371)
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/bfc45eb116839914.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:389
}
if encrypted && tree.Root.ID+".sy" != filepath.Base(historyPath) {
return errors.New("encrypted document history root ID does not match its filename")
}
boundRecovery := &Transaction{trees: map[string]*parse.Tree{}}
defer func() { boundRecovery.finishAttributeViewMutation(err != nil) }()
if nil != tree {
historyDir := filepath.Join(util.HistoryDir, parts[0])
avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)
for _, avNode := range avNodes {
srcAvPath := filepath.Join(historyDir, "storage", "av", avNode.AttributeViewID+".json")
// 加密笔记本的 AV 定义在笔记本级目录
destAvPath := filepath.Join(util.DataDir, "storage", "av", avNode.AttributeViewID+".json")
if IsEncryptedBox(boxID) {
// 历史目录里 AV 也可能在 boxID 子目录下
boxSrcAvPath := filepath.Join(historyDir, boxID, "storage", "av", avNode.AttributeViewID+".json")
if !gulu.File.IsExist(boxSrcAvPath) {
return fmt.Errorf("encrypted attribute view history is missing notebook context [%s]", avNode.AttributeViewID)
}
srcAvPath = boxSrcAvPath
destAvPath = filepath.Join(util.DataDir, boxID, "storage", "av", avNode.AttributeViewID+".json")
}
if gulu.File.IsExist(destAvPath) {
avBoxID := ""
if encrypted {
avBoxID = boxID
}
if err = boundRecovery.restoreEmbeddedAttributeViewHistory(srcAvPath, avBoxID, avNode.AttributeViewID); err != nil {
return
}
}
avIDs = append(avIDs, avNode.AttributeViewID)
}
}
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)View on GitHub (pinned to 9f775e8a12)