siyuan-note/siyuan · error

duplicate AI editor action ID

Error message

duplicate AI editor action ID [%s]

What it means

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.

Solutions

  1. Open the actions file and delete or re-ID the duplicate entries so every ID is unique (one entry per error-reported ID).
  2. Keep the correct copy and remove the stale one; regenerate IDs in node-ID format for genuinely new actions.
  3. Recreate the actions via the SiYuan UI so uniqueness is enforced at creation time.
  4. Deduplicate offline before writing: track IDs in a set (mirroring the kernel's ids map) in any import script.

Example fix

// before: duplicate ID
[{"id":"20240101120000-a1b2c3d4e5f6","name":"A"},{"id":"20240101120000-a1b2c3d4e5f6","name":"B"}]
// after: unique IDs
[{"id":"20240101120000-a1b2c3d4e5f6","name":"A"},{"id":"20240101120001-b1c2d3e4f5g6","name":"B"}]
Defensive patterns

Strategy: validation

Validate before calling

const ids = new Set();
for (const a of data.actions) {
  if (ids.has(a.id)) throw new Error('duplicate ID: ' + a.id);
  ids.add(a.id);
}

Try / catch

try {
  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});
} catch (e) {
  if (/duplicate AI editor action ID/.test(e.message)) {
    // parse the reported ID from the message and deduplicate the file entry
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/4a7374cf718462da. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/ai_editor.go:178

		return nil, fmt.Errorf("read AI editor actions failed: %w", err)
	}
	if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
		return nil, fmt.Errorf("unmarshal AI editor actions failed: %w", err)
	}
	if ret.Version != aiEditorActionsVersion {
		return nil, fmt.Errorf("unsupported AI editor actions version [%d]", ret.Version)
	}
	if ret.Actions == nil {
		ret.Actions = []*AIEditorAction{}
	}

	ids := make(map[string]struct{}, len(ret.Actions))
	for _, action := range ret.Actions {
		if action == nil || !ast.IsNodeIDPattern(action.ID) || (action.Name == "" && action.Action == "") {
			return nil, errors.New("invalid AI editor action data")
		}
		if _, ok := ids[action.ID]; ok {
			return nil, fmt.Errorf("duplicate AI editor action ID [%s]", action.ID)
		}
		ids[action.ID] = struct{}{}
	}
	return ret, nil
}

func saveAIEditorActions(data *aiEditorActionsData) (err error) {
	data.Version = aiEditorActionsVersion
	if data.Actions == nil {
		data.Actions = []*AIEditorAction{}
	}

	dirPath := filepath.Dir(aiEditorActionsPath())
	if err = os.MkdirAll(dirPath, 0755); err != nil {
		return fmt.Errorf("create AI editor actions directory failed: %w", err)
	}
	bytes, err := gulu.JSON.MarshalIndentJSON(data, "", "  ")
	if err != nil {

View on GitHub (pinned to 9f775e8a12)