{"record":{"id":"4a7374cf718462da","repo":"siyuan-note/siyuan","slug":"duplicate-ai-editor-action-id-s","errorCode":null,"errorMessage":"duplicate AI editor action ID [%s]","messagePattern":"duplicate AI editor action ID \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":178,"sourceCode":"\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)\n\t}\n\tbytes, err := gulu.JSON.MarshalIndentJSON(data, \"\", \"  \")\n\tif err != nil {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L160-L196","documentation":"loadAIEditorActions rejects an actions file in which two entries share the same ID. IDs are intended to be unique SiYuan node IDs, so a duplicate indicates corrupted or hand-merged data. Returned to GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.","triggerScenarios":"The persisted JSON contains two or more actions with an identical ID string — typically from copy-pasting an entry in the file, merging files, or a buggy external script appending entries with a fixed ID.","commonSituations":"Manual duplication of an entry to create a similar action without changing the ID; restoring two backups by concatenation; an external tool that bulk-imported actions using the same generated ID.","solutions":["Open the actions file and delete or re-ID the duplicate entries so every ID is unique (one entry per error-reported ID).","Keep the correct copy and remove the stale one; regenerate IDs in node-ID format for genuinely new actions.","Recreate the actions via the SiYuan UI so uniqueness is enforced at creation time.","Deduplicate offline before writing: track IDs in a set (mirroring the kernel's ids map) in any import script."],"exampleFix":"// before: duplicate ID\n[{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"A\"},{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"B\"}]\n// after: unique IDs\n[{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"A\"},{\"id\":\"20240101120001-b1c2d3e4f5g6\",\"name\":\"B\"}]","handlingStrategy":"validation","validationCode":"const ids = new Set();\nfor (const a of data.actions) {\n  if (ids.has(a.id)) throw new Error('duplicate ID: ' + a.id);\n  ids.add(a.id);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});\n} catch (e) {\n  if (/duplicate AI editor action ID/.test(e.message)) {\n    // parse the reported ID from the message and deduplicate the file entry\n  }\n}","preventionTips":["Never copy-paste entries in the actions JSON without changing the ID","Deduplicate imports with an ID set before writing","Generate fresh node IDs for every new action","Merge backups by choosing one entry per ID, not concatenating"],"tags":["validation","duplicate-id","persistence","uniqueness"],"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"}