siyuan-note/siyuan · error

encrypted notebook attribute view history is plaintext

Error message

encrypted notebook attribute view history is plaintext [%s]

What it means

For an encrypted notebook's AV history, the snapshot file must itself be ciphertext. If the path names an encrypted notebook but the file content is plaintext, the kernel refuses the rollback because silently writing plaintext into an encrypted notebook would break its confidentiality guarantees. The error names the offending notebook ID.

Solutions

  1. Re-create the AV history snapshot from the encrypted notebook so it is stored as ciphertext, then roll back.
  2. If the data is legitimately plaintext (pre-encryption era), restore it manually into the notebook rather than via RollbackAttributeViewHistory.
  3. Verify which notebook the snapshot belongs to; if it actually belongs to a non-encrypted notebook, correct the path.
Defensive patterns

Strategy: validation

Validate before calling

if (isEncryptedBox(boxID) && !isCiphertext(fileData)) {
  throw new Error("plaintext snapshot for encrypted notebook " + boxID);
}

Prevention

When it happens

Trigger: RollbackAttributeViewHistory called with a path under an encrypted notebook ID where the .json snapshot on disk is unencrypted (e.g. created before encryption was enabled, or written by a tool that bypassed encryption).

Common situations: History snapshots produced by an older SiYuan version before encrypted-notebook support; third-party sync/backup tools restoring plaintext copies; mixed plaintext/ciphertext history after toggling notebook encryption.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/history.go:713

	}

	from := historyPath
	// 从路径提取 boxID 判断是否加密笔记本的 AV
	relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
	relPath = strings.TrimPrefix(relPath, "/")
	pathParts := strings.SplitN(relPath, "/", 3)
	data, readErr := filelock.ReadFile(from)
	if readErr != nil {
		return readErr
	}
	ciphertext := util.IsCiphertext(data)
	if ciphertext && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {
		return errors.New("encrypted attribute view history is missing valid notebook context")
	}
	to := filepath.Join(util.DataDir, "storage", "av", filepath.Base(historyPath))
	if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
		if !ciphertext {
			return fmt.Errorf("encrypted notebook attribute view history is plaintext [%s]", pathParts[1])
		}
		// 加密笔记本的 AV 定义回滚到笔记本级目录
		to = filepath.Join(util.DataDir, pathParts[1], "storage", "av", filepath.Base(historyPath))
		if err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {
			return
		}
	}

	if err = filelock.CopyNewtimes(from, to); err != nil {
		logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
		return
	}
	avID := strings.TrimSuffix(filepath.Base(historyPath), ".json")
	cache.RemoveAVData(avID)
	avBoxID := ""
	if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
		avBoxID = pathParts[1]
	}

View on GitHub (pinned to 9f775e8a12)