siyuan-note/siyuan · error

write AI editor actions failed

Error message

write AI editor actions failed: %w

What it means

saveAIEditorActions writes the marshalled JSON with filelock.WriteFile(aiEditorActionsPath(), bytes). This error wraps the write failure — permission problems, full disk, the path being a directory, or lock contention. Thrown by SaveAIEditorAction, RemoveAIEditorAction, and migrateLegacyAIEditorActions.

Solutions

  1. Free disk space / check quota on the workspace volume and retry.
  2. Check and fix write permissions on the actions file and its directory (chmod/chown).
  3. Close other processes locking the file (sync/AV/second kernel instance) and retry.
  4. Inspect the wrapped OS error (%w) in the kernel log for the exact errno and act accordingly.

Example fix

// before: second kernel instance on same workspace corrupting locks
./siyuan-kernel --workspace /home/user/SiYuan  # already running
// after: single instance, or stop the first
pkill -f 'siyuan.*workspace /home/user/SiYuan' && ./siyuan-kernel --workspace /home/user/SiYuan
Defensive patterns

Strategy: retry

Validate before calling

const fs = require('fs');
try { fs.accessSync(actionsPath, fs.constants.W_OK); } catch (e) { /* fix perms before calling API */ }

Try / catch

try {
  await fetchSyncPost('/api/ai/editor/removeAIEditorAction', { id });
} catch (e) {
  if (/write AI editor actions failed/.test(e.message)) {
    // free disk / release locks / fix perms, then retry with backoff
  }
}

Prevention

When it happens

Trigger: Calling SaveAIEditorAction/RemoveAIEditorAction when the actions file (or its temp file during locked write) cannot be written: read-only filesystem, disk full, another process holding a conflicting lock, or the file path replaced by a directory.

Common situations: Disk quota/full disk while SiYuan runs; sync clients (Dropbox/OneDrive) or backup software locking the file; running multiple SiYuan instances on the same workspace; permissions changed by external tooling.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/ai_editor.go:200

	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
	}

	var legacyActions []*legacyAIEditorAction
	if legacyJSON, isString := legacyRaw.(string); isString {
		if err = gulu.JSON.UnmarshalJSON([]byte(legacyJSON), &legacyActions); err != nil {
			return fmt.Errorf("unmarshal legacy AI editor actions failed: %w", err)
		}
	} else {
		legacyJSON, marshalErr := gulu.JSON.MarshalJSON(legacyRaw)

View on GitHub (pinned to 9f775e8a12)