{"record":{"id":"4ba4e18055013639","repo":"siyuan-note/siyuan","slug":"invalid-ai-editor-action-id","errorCode":null,"errorMessage":"invalid AI editor action ID","messagePattern":"invalid AI editor action ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/ai_editor.go","lineNumber":75,"sourceCode":"\taiEditorActionsLock.Lock()\n\tdefer aiEditorActionsLock.Unlock()\n\n\tdata, err := loadAIEditorActions()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err = migrateLegacyAIEditorActions(data, !util.ReadOnly); err != nil {\n\t\treturn nil, err\n\t}\n\treturn data.Actions, nil\n}\n\nfunc SaveAIEditorAction(action *AIEditorAction) (ret *AIEditorAction, err error) {\n\tif action == nil || (action.Name == \"\" && action.Action == \"\") {\n\t\treturn nil, errors.New(\"AI editor action must not be empty\")\n\t}\n\tif action.ID != \"\" && !ast.IsNodeIDPattern(action.ID) {\n\t\treturn nil, errors.New(\"invalid AI editor action ID\")\n\t}\n\n\twaitForSyncingStorages()\n\taiEditorActionsLock.Lock()\n\tdefer aiEditorActionsLock.Unlock()\n\n\tdata, err := loadAIEditorActions()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err = migrateLegacyAIEditorActions(data, true); err != nil {\n\t\treturn nil, err\n\t}\n\n\tret = &AIEditorAction{\n\t\tID:     action.ID,\n\t\tName:   action.Name,\n\t\tAction: action.Action,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L57-L93","documentation":"SaveAIEditorAction validates a caller-supplied ID against ast.IsNodeIDPattern (SiYuan's node-ID format, e.g. timestamp-based digit groups). A non-empty ID that does not match this pattern is rejected with \"invalid AI editor action ID\" so that auto-generated IDs and stored references stay consistent.","triggerScenarios":"Calling SaveAIEditorAction with action.ID set to a UUID, slug, numeric string, or any value not matching the SiYuan node-ID pattern; copying an ID from another system; typos when hardcoding an ID.","commonSituations":"Plugins generating their own IDs (uuid v4) instead of omitting ID to let the kernel generate one; hand-crafted API payloads with placeholder IDs like \"test\" or \"1\".","solutions":["Omit the `id` field entirely when creating a new action — the kernel assigns a valid node ID","When updating, use the exact ID returned by the list API (GetAIEditorActions), not a hand-made value","Regenerate/convert your identifier into SiYuan node-ID format if you must control IDs"],"exampleFix":"// before\nsaveAIEditorAction(&AIEditorAction{ID: \"550e8400-e29b-41d4-a716-446655440000\", Name: \"Summarize\"})\n// after\nsaveAIEditorAction(&AIEditorAction{Name: \"Summarize\", Action: \"Summarize this text\"}) // ID left empty, kernel assigns one","handlingStrategy":"validation","validationCode":"const isNodeID = (id) => typeof id === \"string\" && /^\\d{14}-[0-9a-z]{7}$/.test(id); // siyuan node-ID shape\nif (action.id && !isNodeID(action.id)) throw new Error(\"id must be a SiYuan node ID or omitted\");","typeGuard":"const hasValidID = (a) => !a.id || /^\\d{14}-[0-9a-z]{7}$/.test(a.id);","tryCatchPattern":"try {\n  await saveAIEditorAction(action);\n} catch (e) {\n  if (e.message.includes(\"invalid AI editor action ID\")) { delete action.id; await saveAIEditorAction(action); } // create new\n}","preventionTips":["Omit ID when creating actions","Only reuse IDs returned by the kernel","Never generate action IDs yourself"],"tags":["validation","identifier","api"],"backgroundTag":"invalid-identifier-format","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"}