siyuan-note/siyuan · error

encrypted notebook document history is plaintext

Error message

encrypted notebook document history is plaintext [%s]

What it means

GetDocHistoryContent detected that the history .sy file is plaintext while its parent path segment names an encrypted notebook. The encrypted-notebook design guarantees that document history for an encrypted box is stored as ciphertext, so a plaintext file there indicates corrupted, hand-moved, or wrongly-attributed history data. The call is aborted instead of decrypting or displaying plaintext content under an encrypted notebook identity.

Solutions

  1. Verify the history file actually belongs to that notebook ID; if it was moved, put it back under the original notebook's history directory
  2. If the notebook was recently switched to encrypted, note that old history remains plaintext and is intentionally inaccessible; delete the stale history entries via the history UI
  3. Check that sync tooling is not merging history directories across different notebooks
  4. If the file should be ciphertext, confirm the notebook is unlocked and the history was written after encryption was enabled; regenerate history by making a new edit

Example fix

// before: plaintext history copied under encrypted box directory
// data/history/20260918/<encryptedBoxID>/20260918091234-abc123.sy (plaintext JSON)
// after: restore to its originating plaintext box directory
// data/history/20260918/<plainBoxID>/20260918091234-abc123.sy
Defensive patterns

Strategy: validation

Validate before calling

const isEnc = await fetchPost('/api/notebook/lsNotebooks').then(r => r.data.notebooks.some(b => b.id === boxID && b.closed === false));
// do not address history files under an encrypted box that were not produced by the kernel

Try / catch

try { await historyGet({ historyPath }) } catch (e) { if (String(e.msg).includes('is plaintext')) { /* skip stale pre-encryption history entry */ } else { throw e } }

Prevention

When it happens

Trigger: Calling model.GetDocHistoryContent (via the historyGet API) with a historyPath whose second path component is an encrypted notebook ID (IsEncryptedBox true) but whose file contents fail util.IsCiphertext, i.e. the .sy data parses as plaintext JSON.

Common situations: History files were copied out of an encrypted notebook into a plaintext notebook directory (or vice versa) via manual file moves or third-party sync; a notebook was converted to encrypted after its history was already written in plaintext; partial migration left stale plaintext history under the encrypted box ID.

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/9a0d255c3bdecb81. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history.go:204

		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
	}
	isLargeDoc = 1024*1024*1 <= len(data)

	luteEngine := NewLute()
	if err = treenode.CheckSpecJSON(data); nil != err {
		return
	}
	historyTree, err := dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
	if err != nil {
		logging.LogErrorf("parse tree from file [%s] failed: %s", historyPath, err)
		return
	}
	if err = treenode.RefreshTableCellRichProjection(historyTree.Root); nil != err {
		return
	}
	id = historyTree.Root.ID
	rootID = historyTree.Root.ID

View on GitHub (pinned to 9f775e8a12)