{"record":{"id":"28fcf38c71f5ba77","repo":"siyuan-note/siyuan","slug":"invalid-ai-editor-action-data","errorCode":null,"errorMessage":"invalid AI editor action data","messagePattern":"invalid AI editor action data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":175,"sourceCode":"\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}\n\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)","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L157-L193","documentation":"After unmarshalling, loadAIEditorActions validates every stored action: it must be non-nil, its ID must match the SiYuan node-ID pattern (ast.IsNodeIDPattern), and it must have a non-empty Name or Action. Any violation aborts the load with this generic sentinel error. Thrown by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.","triggerScenarios":"The actions file contains an entry that is null, has an ID not matching the 14-char timestamp-random node ID pattern, or has both empty name and empty action — e.g. after manual editing or a partial write.","commonSituations":"Hand-editing data/storage JSON and adding an entry with a placeholder ID like \"1\" or \"\"; a script bulk-importing actions with missing fields; truncated/corrupted file yielding zero-value entries; copying entries from another app with different ID format.","solutions":["Open the actions file, locate the offending entry, and fix its ID to a valid node-ID pattern (e.g. 20240101120000-abcdefghijk format) and give it a Name or Action.","Remove invalid/null entries from the JSON array.","Prefer re-creating the actions through the SiYuan UI/API so IDs and required fields are generated correctly.","If unsure which entry is invalid, validate each offline: ast.IsNodeIDPattern(id) plus non-empty (name||action)."],"exampleFix":"// before: invalid entry\n{\"id\":\"my-action\",\"name\":\"\",\"action\":\"\"}\n// after: valid node ID and a non-empty field\n{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"Summarize\",\"action\":\"summarize\"}","handlingStrategy":"validation","validationCode":"const isNodeID = id => /^\\d{14}-[0-9a-f]{7}/.test(id); // approximate node-ID pattern\nfor (const a of data.actions) {\n  if (a == null || !isNodeID(a.id) || (!a.name && !a.action)) throw new Error('invalid action: ' + JSON.stringify(a));\n}","typeGuard":"function isValidAction(a) {\n  return a != null && typeof a.id === 'string' && /^\\d{14}-[0-9a-z]+/.test(a.id) && (a.name || a.action);\n}","tryCatchPattern":"try {\n  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});\n} catch (e) {\n  if (e.message === 'invalid AI editor action data') {\n    // locate and fix the offending entry in the actions file\n  }\n}","preventionTips":["Only create actions via the UI/API so IDs and fields are generated correctly","Validate entries before any scripted import","Keep IDs in SiYuan node-ID format","Always set at least one of name/action per entry"],"tags":["validation","schema","persistence","node-id"],"backgroundTag":"schema-validation-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"}