siyuan-note/siyuan · error

create AI editor actions directory failed

Error message

create AI editor actions directory failed: %w

What it means

saveAIEditorActions persists the actions file and first ensures its parent directory exists via os.MkdirAll(dirPath, 0755). This error wraps the MkdirAll failure. Thrown by SaveAIEditorAction, RemoveAIEditorAction, and migrateLegacyAIEditorActions.

Solutions

  1. Check permissions on the workspace data directory and create the storage directory manually if needed (mkdir -p with correct ownership).
  2. Verify the target directory path is not occupied by a regular file; remove/rename that file.
  3. Ensure the volume is writable and not full; remount read-only filesystems read-write.
  4. Read the wrapped OS error (%w) in the kernel log for the exact errno (EACCES, EROFS, ENOTDIR).

Example fix

// before: running kernel with a read-only workspace mount
./siyuan --workspace /mnt/readonly/workspace
// after: writable workspace
mount -o remount,rw /mnt/readonly && ./siyuan --workspace /mnt/readonly/workspace
Defensive patterns

Strategy: retry

Validate before calling

// ensure the target directory can be created before calling the API
const fs = require('fs');
const dir = workspace + '/data/storage';
if (fs.existsSync(dir) && !fs.statSync(dir).isDirectory()) throw new Error('path occupied by a file');

Try / catch

try {
  await fetchSyncPost('/api/ai/editor/saveAIEditorAction', { id, name, action });
} catch (e) {
  if (/create AI editor actions directory failed/.test(e.message)) {
    // fix permissions/remount rw, then retry with backoff
  }
}

Prevention

When it happens

Trigger: Calling SaveAIEditorAction/RemoveAIEditorAction when the storage directory under the workspace data path cannot be created — read-only filesystem, missing parent with no write permission, or a file occupying the directory path.

Common situations: Workspace on a read-only mount or CD-ROM; data directory owned by another user after restore; a regular file named like the expected storage directory exists; full disk preventing inode allocation.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/ai_editor.go:193

			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 {
		return fmt.Errorf("marshal AI editor actions failed: %w", err)
	}
	if err = filelock.WriteFile(aiEditorActionsPath(), bytes); err != nil {
		return fmt.Errorf("write AI editor actions failed: %w", err)
	}
	return nil
}

func migrateLegacyAIEditorActions(data *aiEditorActionsData, persist bool) (err error) {
	localStorage := GetLocalStorage()
	legacyRaw, ok := localStorage[legacyAIEditorActionsStorageKey]
	if !ok {
		return nil
	}

View on GitHub (pinned to 9f775e8a12)