{"record":{"id":"97f9b54598edafa8","repo":"siyuan-note/siyuan","slug":"encrypted-snapshot-document-is-missing-valid-noteb","errorCode":null,"errorMessage":"encrypted snapshot document is missing valid notebook context","messagePattern":"encrypted snapshot document is missing valid notebook context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history_diff.go","lineNumber":424,"sourceCode":"\t\treturn nil, err\n\t}\n\tfile, err := repo.GetFile(fileID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !strings.HasSuffix(strings.ToLower(file.Path), \".sy\") {\n\t\treturn nil, errors.New(\"snapshot version is not a document\")\n\t}\n\trepoPath := strings.TrimPrefix(file.Path, \"/\")\n\tpathParts := strings.SplitN(repoPath, \"/\", 2)\n\tdata, err := repo.OpenFile(file)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tciphertext := util.IsCiphertext(data)\n\tif ciphertext {\n\t\tif len(pathParts) < 2 || !ast.IsNodeIDPattern(pathParts[0]) || !IsEncryptedBox(pathParts[0]) {\n\t\t\treturn nil, errors.New(\"encrypted snapshot document is missing valid notebook context\")\n\t\t}\n\t\tHoldBoxReadLock(pathParts[0])\n\t\tdefer ReleaseBoxReadLock(pathParts[0])\n\t\tdek, unlockErr := GetDEKIfUnlocked(pathParts[0])\n\t\tif unlockErr != nil {\n\t\t\treturn nil, errors.New(Conf.Language(314))\n\t\t}\n\t\tdata, err = DecryptFile(pathParts[0], pathParts[1], dek, data)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t} else if len(pathParts) > 0 && IsEncryptedBox(pathParts[0]) {\n\t\treturn nil, fmt.Errorf(\"encrypted notebook snapshot document is plaintext [%s]\", pathParts[0])\n\t}\n\trootID := strings.TrimSuffix(filepath.Base(file.Path), filepath.Ext(file.Path))\n\ttree, err := parseDocVersionTree(data, rootID)\n\tboxID := \"\"\n\tif 0 < len(pathParts) && ast.IsNodeIDPattern(pathParts[0]) {","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history_diff.go#L406-L442","documentation":"When snapshot bytes are detected as ciphertext, the loader needs the notebook ID as the first path segment of the repo file path (<boxID>/<relative path>) to look up the notebook DEK. If the path has fewer than 2 segments, the first segment is not a node-ID-style notebook ID, or that notebook is not a registered encrypted box, decryption context is missing and this error is thrown.","triggerScenarios":"loadDocVersion on an encrypted snapshot whose repo file path lacks the notebook-ID segment, has a malformed first segment, or references a notebook that is no longer (or never was) registered as encrypted (IsEncryptedBox false).","commonSituations":"Snapshot paths recorded by an older/foreign format; docs synced from a notebook whose encryption was toggled after snapshotting; corrupted repo index entries; manually imported snapshot data with wrong path layout.","solutions":["Verify the snapshot file's repo path is <boxID>/<relative doc path> with a valid node-ID notebook as the first segment.","Check that the notebook still exists and is flagged encrypted; if its encryption state changed, restore or re-encrypt consistently.","Rebuild/re-sync the snapshot index from the source workspace so paths are recorded correctly.","If the snapshot predates encryption support, load it via the legacy path or re-create it as a new snapshot."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Go: validate snapshot path has boxID/docPath with a valid encrypted box\nparts := strings.SplitN(strings.TrimPrefix(file.Path, \"/\"), \"/\", 2)\nif len(parts) < 2 || !ast.IsNodeIDPattern(parts[0]) || !model.IsEncryptedBox(parts[0]) {\n    return errors.New(\"snapshot lacks valid encrypted notebook context\")\n}","typeGuard":null,"tryCatchPattern":"catch (e) { if (e.message.includes(\"missing valid notebook context\")) { resyncRepoIndex(); } else { throw e; } }","preventionTips":["Keep snapshot paths in <boxID>/<relative doc path> form","Do not toggle notebook encryption after snapshots exist without migrating data","Rebuild corrupted repo indexes from the source workspace"],"tags":["encryption","snapshot","path-structure","notebook-context"],"backgroundTag":"invalid-argument-format","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"}