{"record":{"id":"84768d34f58d827b","repo":"siyuan-note/siyuan","slug":"write-ai-editor-actions-failed-w","errorCode":null,"errorMessage":"write AI editor actions failed: %w","messagePattern":"write AI editor actions failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":200,"sourceCode":"\treturn ret, nil\n}\n\nfunc saveAIEditorActions(data *aiEditorActionsData) (err error) {\n\tdata.Version = aiEditorActionsVersion\n\tif data.Actions == nil {\n\t\tdata.Actions = []*AIEditorAction{}\n\t}\n\n\tdirPath := filepath.Dir(aiEditorActionsPath())\n\tif err = os.MkdirAll(dirPath, 0755); err != nil {\n\t\treturn fmt.Errorf(\"create AI editor actions directory failed: %w\", err)\n\t}\n\tbytes, err := gulu.JSON.MarshalIndentJSON(data, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal AI editor actions failed: %w\", err)\n\t}\n\tif err = filelock.WriteFile(aiEditorActionsPath(), bytes); err != nil {\n\t\treturn fmt.Errorf(\"write AI editor actions failed: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc migrateLegacyAIEditorActions(data *aiEditorActionsData, persist bool) (err error) {\n\tlocalStorage := GetLocalStorage()\n\tlegacyRaw, ok := localStorage[legacyAIEditorActionsStorageKey]\n\tif !ok {\n\t\treturn nil\n\t}\n\n\tvar legacyActions []*legacyAIEditorAction\n\tif legacyJSON, isString := legacyRaw.(string); isString {\n\t\tif err = gulu.JSON.UnmarshalJSON([]byte(legacyJSON), &legacyActions); err != nil {\n\t\t\treturn fmt.Errorf(\"unmarshal legacy AI editor actions failed: %w\", err)\n\t\t}\n\t} else {\n\t\tlegacyJSON, marshalErr := gulu.JSON.MarshalJSON(legacyRaw)","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L182-L218","documentation":"saveAIEditorActions writes the marshalled JSON with filelock.WriteFile(aiEditorActionsPath(), bytes). This error wraps the write failure — permission problems, full disk, the path being a directory, or lock contention. Thrown by SaveAIEditorAction, RemoveAIEditorAction, and migrateLegacyAIEditorActions.","triggerScenarios":"Calling SaveAIEditorAction/RemoveAIEditorAction when the actions file (or its temp file during locked write) cannot be written: read-only filesystem, disk full, another process holding a conflicting lock, or the file path replaced by a directory.","commonSituations":"Disk quota/full disk while SiYuan runs; sync clients (Dropbox/OneDrive) or backup software locking the file; running multiple SiYuan instances on the same workspace; permissions changed by external tooling.","solutions":["Free disk space / check quota on the workspace volume and retry.","Check and fix write permissions on the actions file and its directory (chmod/chown).","Close other processes locking the file (sync/AV/second kernel instance) and retry.","Inspect the wrapped OS error (%w) in the kernel log for the exact errno and act accordingly."],"exampleFix":"// before: second kernel instance on same workspace corrupting locks\n./siyuan-kernel --workspace /home/user/SiYuan  # already running\n// after: single instance, or stop the first\npkill -f 'siyuan.*workspace /home/user/SiYuan' && ./siyuan-kernel --workspace /home/user/SiYuan","handlingStrategy":"retry","validationCode":"const fs = require('fs');\ntry { fs.accessSync(actionsPath, fs.constants.W_OK); } catch (e) { /* fix perms before calling API */ }","typeGuard":null,"tryCatchPattern":"try {\n  await fetchSyncPost('/api/ai/editor/removeAIEditorAction', { id });\n} catch (e) {\n  if (/write AI editor actions failed/.test(e.message)) {\n    // free disk / release locks / fix perms, then retry with backoff\n  }\n}","preventionTips":["Ensure a single kernel instance per workspace","Exclude the workspace from file-locking sync clients","Keep disk usage below quota","Verify write permissions before upgrades/migrations"],"tags":["filesystem","file-locking","write","persistence"],"backgroundTag":"file-write-failed","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"}