siyuan-note/siyuan · error

read AI editor actions failed

Error message

read AI editor actions failed: %w

What it means

loadAIEditorActions reads the persisted AI editor actions JSON file (aiEditorActionsPath) via filelock.ReadFile. This error wraps the underlying OS error when the file exists but cannot be read (permissions, IO failure, concurrent lock). It is surfaced by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.

Solutions

  1. Check file permissions/ownership of the AI editor actions file in the workspace data directory and restore read access (chmod/chown).
  2. Stop processes locking the file (sync/AV clients) and retry the API call.
  3. Verify the path is a regular file, not a directory; restore it from backup or delete it so it is recreated.
  4. Inspect the wrapped error (%w) in the kernel log for the exact OS-level cause (EACCES, EIO, EISDIR).

Example fix

// before: blindly calling API without checking file state
actions, err := GetAIEditorActions()
// after: check file readability first
if path, e := aiEditorActionsPath(); e == nil {
    if _, e := os.Stat(path); e != nil && !os.IsNotExist(e) { /* inspect e */ }
}
actions, err := GetAIEditorActions()
Defensive patterns

Strategy: try-catch

Validate before calling

const stat = await fetch('/api/filetree/getDocInfo'); // or check file exists/readable before mutating actions
if (stat && stat.err) console.warn('storage file state:', stat.err);

Try / catch

try {
  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});
  if (actions.code !== 0) throw new Error(actions.msg);
} catch (e) {
  if (/read AI editor actions failed/.test(e.message)) {
    // inspect file permissions/locks; fall back to defaults
  }
}

Prevention

When it happens

Trigger: Calling GetAIEditorActions/SaveAIEditorAction/RemoveAIEditorAction when data/storage/ai-editor-actions.json (or equivalent path) exists but ReadFile fails — e.g. permission change, disk error, file locked by another process, or the file was replaced by a directory.

Common situations: Workspace data directory permissions changed after backup/restore (rsync with wrong ownership); antivirus or sync tools (OneDrive/Dropbox) holding the file; disk full or I/O errors; the file path turned into a directory during a manual edit of the data folder.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/ai_editor.go:160

}

func aiEditorActionsPath() string {
	return filepath.Join(util.DataDir, "storage", "ai", "editor", "actions.json")
}

func loadAIEditorActions() (ret *aiEditorActionsData, err error) {
	ret = &aiEditorActionsData{
		Version: aiEditorActionsVersion,
		Actions: []*AIEditorAction{},
	}
	dataPath := aiEditorActionsPath()
	if !filelock.IsExist(dataPath) {
		return ret, nil
	}

	data, err := filelock.ReadFile(dataPath)
	if err != nil {
		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)

View on GitHub (pinned to 9f775e8a12)