{"record":{"id":"57421fc21b3d3113","repo":"siyuan-note/siyuan","slug":"history-path-s-not-exist","errorCode":null,"errorMessage":"history path [%s] not exist","messagePattern":"history path \\[(.+?)\\] not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":609,"sourceCode":"\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\tIncSync()\n\tutil.PushMsg(Conf.Language(102), 3000)\n\treturn nil\n}\n\n// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。\n// 拒绝路径穿越攻击（..、绝对路径等）。返回规范化的绝对路径。\nfunc validateHistoryPath(historyPath string) (string, error) {\n\tp := filepath.Join(util.WorkspaceDir, historyPath)\n\tif !gulu.File.IsSubPath(util.WorkspaceDir, p) {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] is not in workspace\", historyPath)\n\t}\n\tif !gulu.File.IsExist(p) {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] not exist\", historyPath)\n\t}\n\trel, err := filepath.Rel(util.HistoryDir, p)\n\tif err != nil || strings.HasPrefix(rel, \"..\") {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] is not under history directory\", historyPath)\n\t}\n\treturn p, nil\n}\n\n// IsEncryptedHistoryPath 判断历史路径是否明确属于加密笔记本。\nfunc IsEncryptedHistoryPath(absPath string) bool {\n\tboxID := ExtractBoxIDFromHistoryPath(absPath)\n\tif boxID == \"\" {\n\t\treturn false\n\t}\n\tif IsEncryptedBox(boxID) {\n\t\treturn true\n\t}\n\trel, err := filepath.Rel(util.HistoryDir, absPath)","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L591-L627","documentation":"After confirming the path is inside the workspace, validateHistoryPath checks existence on disk. This error means the normalized history path does not point to an existing file or directory — the history entry was pruned, never created, or the path is mistyped.","triggerScenarios":"Calling any history read/rollback API with a path under the workspace whose joined absolute path does not exist — typically after history auto-cleanup deleted the snapshot or the caller reused a stale path from a previous session.","commonSituations":"Cached history paths used after the retention window elapsed and the kernel purged old history; workspaces switched between calls; typos in the timestamp or op segment.","solutions":["Re-list available history entries via the history APIs and use a fresh, currently existing path","Check the history retention settings — increase RetentionDays if snapshots are pruned too aggressively","Verify the workspace directory is the one that actually contains the history data"],"exampleFix":"// before\nrollbackDocHistory(staleHistoryPath) // snapshot already pruned\n// after\nhistories := getHistoryItems(); rollbackDocHistory(histories[0].path) // re-fetched live path","handlingStrategy":"validation","validationCode":"if (!fs.existsSync(path.join(workspaceDir, historyPath))) { const fresh = await fetchLatestHistoryEntries(); historyPath = fresh[0].path; }","typeGuard":null,"tryCatchPattern":"try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('not exist')) { await refreshHistoryList(); informUserSnapshotPruned(); } else { throw e; } }","preventionTips":["Re-fetch history listings instead of caching paths across sessions","Increase history retention (RetentionDays) for snapshots you plan to restore later","Check that the workspace directory matches the one containing the data"],"tags":["history","file-not-found","stale-path"],"backgroundTag":"file-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"}