{"record":{"id":"1faee020d3ad5137","repo":"siyuan-note/siyuan","slug":"encrypted-attribute-view-history-is-missing-valid","errorCode":null,"errorMessage":"encrypted attribute view history is missing valid notebook context","messagePattern":"encrypted attribute view history is missing valid notebook context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":708,"sourceCode":"\t\treturn\n\t}\n\t// 验证目标文件必须是 AV 定义文件\n\tif !strings.HasSuffix(historyPath, \".json\") || !strings.Contains(filepath.ToSlash(historyPath), \"/storage/av/\") {\n\t\treturn fmt.Errorf(\"invalid AV history path [%s]\", historyPath)\n\t}\n\n\tfrom := historyPath\n\t// 从路径提取 boxID 判断是否加密笔记本的 AV\n\trelPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))\n\trelPath = strings.TrimPrefix(relPath, \"/\")\n\tpathParts := strings.SplitN(relPath, \"/\", 3)\n\tdata, readErr := filelock.ReadFile(from)\n\tif readErr != nil {\n\t\treturn readErr\n\t}\n\tciphertext := util.IsCiphertext(data)\n\tif ciphertext && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {\n\t\treturn errors.New(\"encrypted attribute view history is missing valid notebook context\")\n\t}\n\tto := filepath.Join(util.DataDir, \"storage\", \"av\", filepath.Base(historyPath))\n\tif len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\tif !ciphertext {\n\t\t\treturn fmt.Errorf(\"encrypted notebook attribute view history is plaintext [%s]\", pathParts[1])\n\t\t}\n\t\t// 加密笔记本的 AV 定义回滚到笔记本级目录\n\t\tto = filepath.Join(util.DataDir, pathParts[1], \"storage\", \"av\", filepath.Base(historyPath))\n\t\tif err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\tif err = filelock.CopyNewtimes(from, to); err != nil {\n\t\tlogging.LogErrorf(\"copy file [%s] to [%s] failed: %s\", from, to, err)\n\t\treturn\n\t}\n\tavID := strings.TrimSuffix(filepath.Base(historyPath), \".json\")","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L690-L726","documentation":"When the history AV snapshot file reads back as ciphertext (encrypted notebook data), the path must still identify an encrypted notebook: the path must have enough segments, segment 1 must be a node-ID-shaped box ID, and that box must be an encrypted notebook. If any of these fail, the kernel cannot determine where/how to decrypt and restore the snapshot, so it aborts with this error. This protects encrypted-notebook recovery paths from ambiguous or corrupted history paths.","triggerScenarios":"RollbackAttributeViewHistory called with a ciphertext AV history file whose path has fewer than 3 segments after trimming the history dir, whose second segment is not a valid node ID, or whose second segment is not a recognized encrypted notebook ID.","commonSituations":"History files copied/moved out of their per-notebook directory; manually restructured history folders; encrypted notebook removed or its encryption status changed after the snapshot was taken; path built by hand without the box ID segment.","solutions":["Restore the original directory layout history/<timestamp>/storage/av/... including the notebook ID segment.","Confirm the notebook ID in the path is an existing encrypted notebook (IsEncryptedBox true).","If the file is actually plaintext, ensure it is stored as plaintext; if it is ciphertext, re-create the snapshot from the encrypted notebook."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const parts = relPath.split(\"/\");\nif (isCiphertext(data) && (parts.length < 3 || !/^[0-9]{14}-[a-z0-9]{7}$/.test(parts[1]) || !isEncryptedBox(parts[1]))) {\n  throw new Error(\"ciphertext AV history lacks valid notebook context\");\n}","typeGuard":"function hasValidBoxContext(relPath, isEncryptedBox) {\n  const parts = relPath.split(\"/\");\n  return parts.length >= 3 && isEncryptedBox(parts[1]);\n}","tryCatchPattern":null,"preventionTips":["Never move or copy files out of the history/<stamp>/ storage/av/ layout.","Keep the notebook ID segment intact when migrating history data.","Re-derive paths from the history index after any restore."],"tags":["encryption","validation","path","attribute-view"],"backgroundTag":"invalid-state-transition","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"}