{"record":{"id":"9a0d255c3bdecb81","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-document-history-is-plaintext","errorCode":null,"errorMessage":"encrypted notebook document history is plaintext [%s]","messagePattern":"encrypted notebook document history is plaintext \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":204,"sourceCode":"\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}\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","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L186-L222","documentation":"GetDocHistoryContent detected that the history .sy file is plaintext while its parent path segment names an encrypted notebook. The encrypted-notebook design guarantees that document history for an encrypted box is stored as ciphertext, so a plaintext file there indicates corrupted, hand-moved, or wrongly-attributed history data. The call is aborted instead of decrypting or displaying plaintext content under an encrypted notebook identity.","triggerScenarios":"Calling model.GetDocHistoryContent (via the historyGet API) with a historyPath whose second path component is an encrypted notebook ID (IsEncryptedBox true) but whose file contents fail util.IsCiphertext, i.e. the .sy data parses as plaintext JSON.","commonSituations":"History files were copied out of an encrypted notebook into a plaintext notebook directory (or vice versa) via manual file moves or third-party sync; a notebook was converted to encrypted after its history was already written in plaintext; partial migration left stale plaintext history under the encrypted box ID.","solutions":["Verify the history file actually belongs to that notebook ID; if it was moved, put it back under the original notebook's history directory","If the notebook was recently switched to encrypted, note that old history remains plaintext and is intentionally inaccessible; delete the stale history entries via the history UI","Check that sync tooling is not merging history directories across different notebooks","If the file should be ciphertext, confirm the notebook is unlocked and the history was written after encryption was enabled; regenerate history by making a new edit"],"exampleFix":"// before: plaintext history copied under encrypted box directory\n// data/history/20260918/<encryptedBoxID>/20260918091234-abc123.sy (plaintext JSON)\n// after: restore to its originating plaintext box directory\n// data/history/20260918/<plainBoxID>/20260918091234-abc123.sy","handlingStrategy":"validation","validationCode":"const isEnc = await fetchPost('/api/notebook/lsNotebooks').then(r => r.data.notebooks.some(b => b.id === boxID && b.closed === false));\n// do not address history files under an encrypted box that were not produced by the kernel","typeGuard":null,"tryCatchPattern":"try { await historyGet({ historyPath }) } catch (e) { if (String(e.msg).includes('is plaintext')) { /* skip stale pre-encryption history entry */ } else { throw e } }","preventionTips":["Never move or copy files between data/history/<boxID> directories manually","Only rely on history written after the notebook was switched to encrypted","Exclude data/history from third-party sync merge tools that can cross notebooks"],"tags":["encryption","history","data-integrity"],"backgroundTag":"incompatible-source-type","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"}