{"record":{"id":"ec10af8557645e5b","repo":"siyuan-note/siyuan","slug":"unmarshal-ai-editor-actions-failed-w","errorCode":null,"errorMessage":"unmarshal AI editor actions failed: %w","messagePattern":"unmarshal AI editor actions failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":163,"sourceCode":"\treturn filepath.Join(util.DataDir, \"storage\", \"ai\", \"editor\", \"actions.json\")\n}\n\nfunc loadAIEditorActions() (ret *aiEditorActionsData, err error) {\n\tret = &aiEditorActionsData{\n\t\tVersion: aiEditorActionsVersion,\n\t\tActions: []*AIEditorAction{},\n\t}\n\tdataPath := aiEditorActionsPath()\n\tif !filelock.IsExist(dataPath) {\n\t\treturn ret, nil\n\t}\n\n\tdata, err := filelock.ReadFile(dataPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read AI editor actions failed: %w\", err)\n\t}\n\tif err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal AI editor actions failed: %w\", err)\n\t}\n\tif ret.Version != aiEditorActionsVersion {\n\t\treturn nil, fmt.Errorf(\"unsupported AI editor actions version [%d]\", ret.Version)\n\t}\n\tif ret.Actions == nil {\n\t\tret.Actions = []*AIEditorAction{}\n\t}\n\n\tids := make(map[string]struct{}, len(ret.Actions))\n\tfor _, action := range ret.Actions {\n\t\tif action == nil || !ast.IsNodeIDPattern(action.ID) || (action.Name == \"\" && action.Action == \"\") {\n\t\t\treturn nil, errors.New(\"invalid AI editor action data\")\n\t\t}\n\t\tif _, ok := ids[action.ID]; ok {\n\t\t\treturn nil, fmt.Errorf(\"duplicate AI editor action ID [%s]\", action.ID)\n\t\t}\n\t\tids[action.ID] = struct{}{}\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L145-L181","documentation":"After reading the AI editor actions file, loadAIEditorActions parses it with gulu.JSON.UnmarshalJSON into aiEditorActionsData. This error wraps the parse failure, meaning the file content is not valid JSON or does not match the expected schema. Thrown by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.","triggerScenarios":"The persisted actions file contains malformed JSON (truncated write, manual edit) or a JSON value whose shape does not fit {version, actions} (e.g. a JSON array at top level).","commonSituations":"Crash or power loss during a previous save left a truncated file; user hand-edited data/storage JSON and broke syntax; file corrupted by sync conflict resolution; an older/experimental build wrote a different schema.","solutions":["Open the actions file in the workspace data directory and fix or validate the JSON (e.g. with jq).","Restore the file from backup; if not needed, delete it so a fresh empty file is recreated on next save.","Check the wrapped error (%w) in the kernel log for the exact JSON offset/type error.","Reproduce the parse locally: gulu.JSON.UnmarshalJSON with the file bytes to see the precise schema mismatch."],"exampleFix":"// before: hand-edited file with trailing comma\n{\"version\":1,\"actions\":[{\"id\":\"20240101120000-abc\",}]}\n// after: valid JSON\n{\"version\":1,\"actions\":[{\"id\":\"20240101120000-abc\",\"name\":\"Summarize\",\"action\":\"summarize\"}]}","handlingStrategy":"fallback","validationCode":"// validate the file before letting the kernel read it\nconst fs = require('fs');\ntry { JSON.parse(fs.readFileSync(p, 'utf8')); } catch (e) { restoreFromBackup(p); }","typeGuard":null,"tryCatchPattern":"try {\n  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});\n} catch (e) {\n  if (/unmarshal AI editor actions failed/.test(e.message)) {\n    // backup the corrupt file, then delete it so a fresh one is created\n  }\n}","preventionTips":["Never hand-edit workspace JSON without validating afterwards (jq)","Back up the data directory before upgrading SiYuan","Avoid killing the kernel mid-save; use clean shutdown","Run JSON schema validation after bulk imports"],"tags":["json","persistence","corruption","schema"],"backgroundTag":"json-unmarshal-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"}