siyuan-note/siyuan · error
read encrypted notebook history conf
Error message
read encrypted notebook history conf [%s] failed: %w
What it means
After confirming .siyuan/conf.json exists in a history box, it is read via filelock.ReadFile to inspect the box's Encrypted flag. This error is thrown when the stat succeeded but the read fails (e.g. the file disappeared between stat and read, permissions deny reading, or a locking/I/O error occurs), so the box's encryption status cannot be determined.
Solutions
- Re-run the scan — transient races with history cleanup often resolve on retry once nothing is mutating history
- Grant the kernel process read permission on the conf.json file
- Stop competing processes (backup, sync, antivirus) that delete or lock files under history/ and retry
- If the file is gone, restore .siyuan/conf.json from backup so the box can still be classified
Example fix
// before: single read with no retry
enc, err := isEncryptedHistoryBoxDir(boxDir)
// after: bounded retry for transient read failures
var enc bool
var err error
for i := 0; i < 3; i++ {
enc, err = isEncryptedHistoryBoxDir(boxDir)
if err == nil { break }
time.Sleep(100 * time.Millisecond)
} Defensive patterns
Strategy: retry
Validate before calling
confPath := filepath.Join(boxDir, ".siyuan", "conf.json")
if f, err := os.Open(confPath); err != nil {
// unreadable now — fix permissions or stop competing processes first
} else { f.Close() } Type guard
func fileReadableNow(path string) bool {
f, err := os.Open(path)
if err != nil { return false }
f.Close()
return true
} Try / catch
var enc bool
var err error
for i := 0; i < 3; i++ {
enc, err = isEncryptedHistoryBoxDir(boxDir)
if err == nil { break }
time.Sleep(100 * time.Millisecond) // handles races with cleanup
} Prevention
- Don't run history cleanup concurrently with recovery scans
- Exclude the workspace from file-locking indexers/AV
- Grant read ACLs to the kernel process user
- Retry transient reads before concluding corruption
When it happens
Trigger: os.Stat succeeds on <boxDir>/.siyuan/conf.json but filelock.ReadFile fails: file deleted or renamed by a concurrent history cleanup, read permission denied, sharing violation on Windows, or disk I/O error.
Common situations: Concurrent history cleanup running while recovery scans; workspace files copied with read-only-for-others ACLs; Windows indexer holding the file open; failing disk.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- stat encrypted notebook history conf
- cannot allocate a replacement history directory
- create history directory
- get history directory failed
- parse encrypted notebook history conf
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/716f6d09af9717d4.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:950
// 再 fallback 到 conf.json 的 Encrypted 标志。
func isEncryptedHistoryBoxDir(boxDir string) (bool, error) {
siyuanDir := filepath.Join(boxDir, ".siyuan")
backupPath := filepath.Join(siyuanDir, "notebook-crypto-backup.json")
if _, err := os.Stat(backupPath); err == nil {
return true, nil
} else if !os.IsNotExist(err) {
return false, fmt.Errorf("stat encrypted notebook history backup [%s] failed: %w", boxDir, err)
}
confPath := filepath.Join(siyuanDir, "conf.json")
if _, err := os.Stat(confPath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("stat encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
data, err := filelock.ReadFile(confPath)
if err != nil {
return false, fmt.Errorf("read encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
var boxConf conf.BoxConf
if err = gulu.JSON.UnmarshalJSON(data, &boxConf); err != nil {
return false, fmt.Errorf("parse encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
return boxConf.Encrypted, nil
}
// cachedDEKs 缓存已解锁加密笔记本的 DEK,按 boxID 索引。
// KEK 不全局缓存("严格每笔记本单独解锁"语义):UnlockBox 临时派生 KEK 解出 DEK 后即丢弃 KEK,
// 仅保留 per-box DEK 供后续读写加解密。
var (
cachedDEKs = map[string][]byte{}
cachedDEKsLock sync.RWMutex
)
// boxLastAccess 记录每个加密笔记本最近一次真实用户交互或显式保活时间(unix 纳秒),供自动锁定 cron 使用。
// key: boxID, value: *atomic.Int64。UnlockBox 成功时初始化,Unmount 时清理。View on GitHub (pinned to 9f775e8a12)