siyuan-note/siyuan · error

encrypted document history has no matching notebook

Error message

encrypted document history has no matching notebook [%s]

What it means

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.

Solutions

  1. Recreate or restore the original encrypted notebook (same notebook ID and key material) so IsEncryptedBox matches and the DEK can be resolved
  2. Copy the encrypted notebook's data directory back into this workspace before reading its history
  3. Read that history in the original workspace/backup where the notebook still exists

Example fix

// before
content, err := model.GetDocHistoryContent(histPath) // box deleted from workspace
// after
if !model.IsEncryptedBox(extractBoxID(histPath)) {
    return errors.New("restore the original encrypted notebook before viewing its history")
}
content, err := model.GetDocHistoryContent(histPath)
Defensive patterns

Strategy: validation

Validate before calling

histBoxID := extractBoxIDFromHistoryPath(historyPath)
if !model.IsEncryptedBox(histBoxID) {
    return fmt.Errorf("notebook %s not present in this workspace; restore it before reading history", histBoxID)
}

Try / catch

content, err := model.GetDocHistoryContent(historyPath)
if err != nil && strings.HasPrefix(err.Error(), "encrypted document history has no matching notebook") {
    // guide user to restore the original encrypted notebook
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/58c6923f2bf7cb4d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history.go:188

	data, err := filelock.ReadFile(historyPath)
	if err != nil {
		logging.LogErrorf("read file [%s] failed: %s", historyPath, err)
		return
	}

	// 加密笔记本的历史是密文,按路径里的 boxID 解密后解析
	relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
	relPath = strings.TrimPrefix(relPath, "/")
	pathParts := strings.SplitN(relPath, "/", 3)
	ciphertext := util.IsCiphertext(data)
	if ciphertext {
		if len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) {
			err = errors.New("encrypted document history is missing notebook context")
			return
		}
		histBoxID := pathParts[1]
		if !IsEncryptedBox(histBoxID) {
			err = fmt.Errorf("encrypted document history has no matching notebook [%s]", histBoxID)
			return
		}
		HoldBoxReadLock(histBoxID)
		defer ReleaseBoxReadLock(histBoxID)
		dek, dekErr := GetDEKIfUnlocked(histBoxID)
		if dekErr != nil {
			err = errors.New(Conf.Language(314))
			return
		}
		data, err = DecryptFile(histBoxID, pathParts[2], dek, data)
		if err != nil {
			logging.LogErrorf("decrypt history [%s] failed: %s", historyPath, err)
			return
		}
	} else if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
		err = fmt.Errorf("encrypted notebook document history is plaintext [%s]", pathParts[1])
		return
	}

View on GitHub (pinned to 9f775e8a12)