siyuan-note/siyuan · error

Conf.Language(323)

Error message

Conf.Language(323)

What it means

DisableEncryptedNotebook refuses to disable when deleted-notebook history snapshots still depend on the current MasterSalt/KEKVerifier. Removing the key backup now would make that history permanently unrecoverable, so the operation returns localized message 323 telling the user to clear that history first.

Solutions

  1. Clear the encrypted-notebook history snapshots first (history UI: delete the deleted-notebook history entries), then retry disabling
  2. If recovery is no longer wanted, manually purge the relevant snapshots from data/history after backing up
  3. Then call DisableEncryptedNotebook again; it will zero MasterSalt/KEKVerifier and save

Example fix

// before: disable blocked by history
await fetchPost('/api/notebook/disableEncryptedNotebook')
// after: purge dependent history first, then disable
await fetchPost('/api/history/removeHistoryItems', {ids: deletedEncryptedHistoryIds})
await fetchPost('/api/notebook/disableEncryptedNotebook')
Defensive patterns

Strategy: validation

Validate before calling

// before disabling, confirm no deleted-encrypted-notebook history remains
hasHistory, _ := model.HasEncryptedNotebookHistory() // or equivalent scan helper
if hasHistory { /* purge history via history UI/API first */ }

Try / catch

if err := model.DisableEncryptedNotebook(); err != nil && strings.Contains(err.Error(), Conf.Language(323)) { /* prompt user to clear deleted-notebook history, then retry */ }

Prevention

When it happens

Trigger: Calling DisableEncryptedNotebook (or the corresponding UI/settings action) while scanEncryptedNotebookHistory finds history snapshots of previously deleted encrypted notebooks that are encrypted with the current key material.

Common situations: User deleted encrypted notebooks earlier (creating history snapshots) and now tries to turn the feature off without purging history; automated cleanup scripts that toggle the setting without history maintenance.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/crypto.go:1108

	notebookCryptoMu.Lock()
	defer notebookCryptoMu.Unlock()

	// 检查是否还有加密笔记本(含 conf 损坏但存在备份的)
	ids, listErr := listAllEncryptedBoxIDs()
	if listErr != nil {
		return fmt.Errorf("list encrypted notebooks failed: %w", listErr)
	}
	if len(ids) > 0 {
		return errors.New("cannot disable encrypted notebook feature while encrypted notebooks exist, remove them first")
	}
	// 检查历史目录中是否存在已删除加密笔记本的历史快照:其恢复仍依赖当前 MasterSalt/KEKVerifier,
	// 删除备份前必须先清除这些历史(详见设计 §19)
	hasHistory, historyErr := scanEncryptedNotebookHistory()
	if historyErr != nil {
		return fmt.Errorf("check encrypted notebook history failed: %w", historyErr)
	}
	if hasHistory {
		return errors.New(Conf.Language(323))
	}

	Conf.m.Lock()
	Conf.NotebookCrypto.Enabled = false
	Conf.NotebookCrypto.MasterSalt = nil
	Conf.NotebookCrypto.KEKVerifier = nil
	Conf.NotebookCrypto.VerifierNonce = nil
	Conf.m.Unlock()

	Conf.Save()
	removeNotebookCryptoBackup() // 禁用时清理备份,避免残留旧密钥材料
	IncSync()
	return nil
}

// restoreNotebookCryptoConfigFromBackup 把备份里的 NotebookCrypto 配置装回本机 conf.json(不需主密码)。
// 用于数据同步/导入 Data.zip 后:备份文件随 DataDir 到达新设备,但本机 conf.json 的 NotebookCrypto 还是空的。
// 此时把 salt/verifier/KDFParams 装回并置 Enabled=true,让 UI 显示"已启用",笔记本显示为锁定(解锁仍需主密码)。

View on GitHub (pinned to 9f775e8a12)