siyuan-note/siyuan · error

encrypted notebook snapshot document is plaintext

Error message

encrypted notebook snapshot document is plaintext [%s]

What it means

loadSnapshotDocVersion reads a snapshot document for history/version viewing. When the snapshot file's path indicates an encrypted notebook (IsEncryptedBox), the code expects the stored document to be ciphertext and to be decrypted with the notebook DEK via DecryptFile. If the snapshot document is stored as plaintext (no encrypted second path part / no decryption step applied), the code refuses to process it because silently reading plaintext in an encrypted notebook would break the authenticated-encryption compatibility guarantees.

Solutions

  1. Verify the notebook is actually meant to be encrypted (check IsEncryptedBox(boxID)); if it should be plaintext, correct the notebook encryption flag instead of reading the snapshot
  2. Recreate the history snapshot for that document so it is stored in the encrypted format, then retry
  3. If the snapshot path is malformed (missing the encrypted path part), repair or regenerate the history index for the notebook
  4. Do not attempt to bypass by patching out the check — existing encrypted data must remain readable only through authenticated decryption
Defensive patterns

Strategy: validation

Validate before calling

if model.IsEncryptedBox(boxID) { /* ensure snapshot was written after encryption was enabled */ }

Try / catch

if err := model.LoadDocVersion(file); err != nil && strings.Contains(err.Error(), "snapshot document is plaintext") { // regenerate or resync history snapshot for this box }

Prevention

When it happens

Trigger: Calling loadDocVersion/loadSnapshotDocVersion on a snapshot file belonging to a notebook registered as encrypted, where pathParts[1] is absent (document stored without an encrypted counterpart) so the plaintext branch of the decrypt-or-reject logic is reached.

Common situations: History snapshots created before encryption was enabled for the notebook, or after the notebook was switched to encrypted while old plaintext-format snapshots remain in the history index; also broken snapshot paths where the encrypted-part segment was lost.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/history_diff.go:437

		return nil, err
	}
	ciphertext := util.IsCiphertext(data)
	if ciphertext {
		if len(pathParts) < 2 || !ast.IsNodeIDPattern(pathParts[0]) || !IsEncryptedBox(pathParts[0]) {
			return nil, errors.New("encrypted snapshot document is missing valid notebook context")
		}
		HoldBoxReadLock(pathParts[0])
		defer ReleaseBoxReadLock(pathParts[0])
		dek, unlockErr := GetDEKIfUnlocked(pathParts[0])
		if unlockErr != nil {
			return nil, errors.New(Conf.Language(314))
		}
		data, err = DecryptFile(pathParts[0], pathParts[1], dek, data)
		if err != nil {
			return nil, err
		}
	} else if len(pathParts) > 0 && IsEncryptedBox(pathParts[0]) {
		return nil, fmt.Errorf("encrypted notebook snapshot document is plaintext [%s]", pathParts[0])
	}
	rootID := strings.TrimSuffix(filepath.Base(file.Path), filepath.Ext(file.Path))
	tree, err := parseDocVersionTree(data, rootID)
	boxID := ""
	if 0 < len(pathParts) && ast.IsNodeIDPattern(pathParts[0]) {
		boxID = pathParts[0]
	}
	if err != nil {
		return &loadedDocVersion{
			title:    rootID,
			rootID:   rootID,
			raw:      data,
			parseErr: err,
			large:    1024*1024 <= len(data),
			boxID:    boxID,
		}, nil
	}
	return &loadedDocVersion{

View on GitHub (pinned to 9f775e8a12)