siyuan-note/siyuan · error
encrypted notebook lock callbacks are not initialized
Error message
encrypted notebook lock callbacks are not initialized
What it means
holdAVBoxReadLock is the encrypted-notebook hook for attribute-view reads. When the box is identified as encrypted, it requires the kernel-side lock callbacks (AVLockAcquire, AVLockRelease, AVIsBoxUnlocked) to be wired; if any is nil it returns this error instead of reading unprotected.
Solutions
- Initialize the lock callbacks (register AVLockAcquire, AVLockRelease, AVIsBoxUnlocked) before any AV access in encrypted workspaces.
- Verify the startup path that installs the encrypted-notebook hooks actually runs in your build.
- Skip or gate AV reads on hook availability if the deployment intentionally lacks encryption support.
Defensive patterns
Strategy: validation
Validate before calling
if av.AVIsEncryptedBox != nil && av.AVIsEncryptedBox(boxID) {
if av.AVLockAcquire == nil || av.AVLockRelease == nil || av.AVIsBoxUnlocked == nil {
// hooks not initialized; skip AV access
}
} Try / catch
release, err := holdAVBoxReadLock(boxID)
if err != nil {
return fmt.Errorf("cannot read AV in encrypted box: %w", err)
}
defer release() Prevention
- Register all three encrypted-notebook lock callbacks at kernel startup
- Gate AV access on hook initialization in embedded/plugin contexts
- Add an init-order test that exercises an encrypted box early in boot
When it happens
Trigger: loadAttributeViewSearchInfoInBox or parseAttributeViewByPathInBoxWithOptions reading an AV in an encrypted box while AVLockAcquire/AVLockRelease/AVIsBoxUnlocked were never registered (hooks not initialized at startup).
Common situations: Running a kernel build without the encrypted-notebook hook registration; plugin/embedding code invoking the AV package before util.Boot-style initialization; regression after refactoring the hook wiring.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- initialize encrypted notebook document failed
- 26
- accessing assets in encrypted notebook
- Conf.Language(316) + " [box=" + id + "]"
- decrypt box [ ] failed: incorrect key or corrupted data
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/dac582fdebc661c6.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/encrypted_hook.go:53
var AVEncryptedBoxIDs func() []string
// AVIsEncryptedBox 由 model 层注入,判断 boxID 是否为加密笔记本。
var AVIsEncryptedBox func(boxID string) bool
// AVIsBoxUnlocked 由 model 层注入,判断加密笔记本是否仍持有 DEK。
var AVIsBoxUnlocked func(boxID string) bool
// AVGetBlockBoxID 由 model 层注入,返回 blockID 所在的 boxID(查 blocktree)。
// 用于镜像写入时校验源块与 AV 定义是否处于同一加密边界。
var AVGetBlockBoxID func(blockID string) string
func holdAVBoxReadLock(boxID string) (release func(), err error) {
release = func() {}
if boxID == "" || AVIsEncryptedBox == nil || !AVIsEncryptedBox(boxID) {
return
}
if AVLockAcquire == nil || AVLockRelease == nil || AVIsBoxUnlocked == nil {
return nil, errors.New("encrypted notebook lock callbacks are not initialized")
}
AVLockAcquire(boxID)
if !AVIsBoxUnlocked(boxID) {
AVLockRelease(boxID)
return nil, errors.New("encrypted notebook is locked, please unlock it first")
}
return func() {
AVLockRelease(boxID)
}, nil
}
// pendingAVBox 记录首次创建的 AV 归属哪个加密 box。
// handler 层创建 AV 前调 SetAVBoxID(avID, boxID),SaveAttributeView 时
// findAttributeViewPath 会先查 pending 映射,找到则写入对应加密笔记本路径。
var pendingAVBox = map[string]string{}
var pendingAVBoxLock = sync.RWMutex{}
// SetAVBoxID 预设 AV 定义的归属 box。加密笔记本创建 AV 时调用,boxID 为空时清理映射。View on GitHub (pinned to 9f775e8a12)