{"record":{"id":"dac582fdebc661c6","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-lock-callbacks-are-not-initiali","errorCode":null,"errorMessage":"encrypted notebook lock callbacks are not initialized","messagePattern":"encrypted notebook lock callbacks are not initialized","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/encrypted_hook.go","lineNumber":53,"sourceCode":"var AVEncryptedBoxIDs func() []string\n\n// AVIsEncryptedBox 由 model 层注入，判断 boxID 是否为加密笔记本。\nvar AVIsEncryptedBox func(boxID string) bool\n\n// AVIsBoxUnlocked 由 model 层注入，判断加密笔记本是否仍持有 DEK。\nvar AVIsBoxUnlocked func(boxID string) bool\n\n// AVGetBlockBoxID 由 model 层注入，返回 blockID 所在的 boxID（查 blocktree）。\n// 用于镜像写入时校验源块与 AV 定义是否处于同一加密边界。\nvar AVGetBlockBoxID func(blockID string) string\n\nfunc holdAVBoxReadLock(boxID string) (release func(), err error) {\n\trelease = func() {}\n\tif boxID == \"\" || AVIsEncryptedBox == nil || !AVIsEncryptedBox(boxID) {\n\t\treturn\n\t}\n\tif AVLockAcquire == nil || AVLockRelease == nil || AVIsBoxUnlocked == nil {\n\t\treturn nil, errors.New(\"encrypted notebook lock callbacks are not initialized\")\n\t}\n\tAVLockAcquire(boxID)\n\tif !AVIsBoxUnlocked(boxID) {\n\t\tAVLockRelease(boxID)\n\t\treturn nil, errors.New(\"encrypted notebook is locked, please unlock it first\")\n\t}\n\treturn func() {\n\t\tAVLockRelease(boxID)\n\t}, nil\n}\n\n// pendingAVBox 记录首次创建的 AV 归属哪个加密 box。\n// handler 层创建 AV 前调 SetAVBoxID(avID, boxID)，SaveAttributeView 时\n// findAttributeViewPath 会先查 pending 映射，找到则写入对应加密笔记本路径。\nvar pendingAVBox = map[string]string{}\nvar pendingAVBoxLock = sync.RWMutex{}\n\n// SetAVBoxID 预设 AV 定义的归属 box。加密笔记本创建 AV 时调用，boxID 为空时清理映射。","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/encrypted_hook.go#L35-L71","documentation":"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.","triggerScenarios":"loadAttributeViewSearchInfoInBox or parseAttributeViewByPathInBoxWithOptions reading an AV in an encrypted box while AVLockAcquire/AVLockRelease/AVIsBoxUnlocked were never registered (hooks not initialized at startup).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if av.AVIsEncryptedBox != nil && av.AVIsEncryptedBox(boxID) {\n\tif av.AVLockAcquire == nil || av.AVLockRelease == nil || av.AVIsBoxUnlocked == nil {\n\t\t// hooks not initialized; skip AV access\n\t}\n}","typeGuard":null,"tryCatchPattern":"release, err := holdAVBoxReadLock(boxID)\nif err != nil {\n\treturn fmt.Errorf(\"cannot read AV in encrypted box: %w\", err)\n}\ndefer release()","preventionTips":["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"],"tags":["encryption","initialization","go"],"backgroundTag":"missing-dependency","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}