{"record":{"id":"58c6923f2bf7cb4d","repo":"siyuan-note/siyuan","slug":"encrypted-document-history-has-no-matching-noteboo","errorCode":null,"errorMessage":"encrypted document history has no matching notebook [%s]","messagePattern":"encrypted document history has no matching notebook \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":188,"sourceCode":"\tdata, err := filelock.ReadFile(historyPath)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"read file [%s] failed: %s\", historyPath, err)\n\t\treturn\n\t}\n\n\t// 加密笔记本的历史是密文，按路径里的 boxID 解密后解析\n\trelPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))\n\trelPath = strings.TrimPrefix(relPath, \"/\")\n\tpathParts := strings.SplitN(relPath, \"/\", 3)\n\tciphertext := util.IsCiphertext(data)\n\tif ciphertext {\n\t\tif len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) {\n\t\t\terr = errors.New(\"encrypted document history is missing notebook context\")\n\t\t\treturn\n\t\t}\n\t\thistBoxID := pathParts[1]\n\t\tif !IsEncryptedBox(histBoxID) {\n\t\t\terr = fmt.Errorf(\"encrypted document history has no matching notebook [%s]\", histBoxID)\n\t\t\treturn\n\t\t}\n\t\tHoldBoxReadLock(histBoxID)\n\t\tdefer ReleaseBoxReadLock(histBoxID)\n\t\tdek, dekErr := GetDEKIfUnlocked(histBoxID)\n\t\tif dekErr != nil {\n\t\t\terr = errors.New(Conf.Language(314))\n\t\t\treturn\n\t\t}\n\t\tdata, err = DecryptFile(histBoxID, pathParts[2], dek, data)\n\t\tif err != nil {\n\t\t\tlogging.LogErrorf(\"decrypt history [%s] failed: %s\", historyPath, err)\n\t\t\treturn\n\t\t}\n\t} else if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\terr = fmt.Errorf(\"encrypted notebook document history is plaintext [%s]\", pathParts[1])\n\t\treturn\n\t}","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L170-L206","documentation":"For a ciphertext history snapshot, GetDocHistoryContent extracts the notebook ID from the path and verifies that this notebook actually exists as an encrypted box in the workspace. If the ID is well-formed but no matching encrypted notebook is present (deleted notebook, foreign workspace, typo), decryption keys are unavailable and the reader returns \"encrypted document history has no matching notebook [<boxID>]\" rather than attempting a plaintext fallback.","triggerScenarios":"Calling GetDocHistoryContent for an encrypted snapshot whose path segment pathParts[1] is a valid node ID but IsEncryptedBox(histBoxID) is false — the notebook was deleted, the history was copied from another workspace, or the notebook was unencrypted/recreated with a new ID.","commonSituations":"Restoring history files into a workspace that no longer contains the original encrypted notebook; browsing another user's workspace history without their notebook; deleting a notebook then trying to view its old document history.","solutions":["Recreate or restore the original encrypted notebook (same notebook ID and key material) so IsEncryptedBox matches and the DEK can be resolved","Copy the encrypted notebook's data directory back into this workspace before reading its history","Read that history in the original workspace/backup where the notebook still exists"],"exampleFix":"// before\ncontent, err := model.GetDocHistoryContent(histPath) // box deleted from workspace\n// after\nif !model.IsEncryptedBox(extractBoxID(histPath)) {\n    return errors.New(\"restore the original encrypted notebook before viewing its history\")\n}\ncontent, err := model.GetDocHistoryContent(histPath)","handlingStrategy":"validation","validationCode":"histBoxID := extractBoxIDFromHistoryPath(historyPath)\nif !model.IsEncryptedBox(histBoxID) {\n    return fmt.Errorf(\"notebook %s not present in this workspace; restore it before reading history\", histBoxID)\n}","typeGuard":null,"tryCatchPattern":"content, err := model.GetDocHistoryContent(historyPath)\nif err != nil && strings.HasPrefix(err.Error(), \"encrypted document history has no matching notebook\") {\n    // guide user to restore the original encrypted notebook\n}","preventionTips":["Keep encrypted notebooks and their history in the same workspace; copy both together in backups","Do not delete an encrypted notebook if its history still needs to be read","Check notebook existence with IsEncryptedBox before offering history browsing for encrypted docs"],"tags":["history","encrypted-notebook","resource-not-found"],"backgroundTag":"resource-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"}