siyuan-note/siyuan · error

unmarshal AI editor actions failed

Error message

unmarshal AI editor actions failed: %w

What it means

After reading the AI editor actions file, loadAIEditorActions parses it with gulu.JSON.UnmarshalJSON into aiEditorActionsData. This error wraps the parse failure, meaning the file content is not valid JSON or does not match the expected schema. Thrown by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.

Solutions

  1. Open the actions file in the workspace data directory and fix or validate the JSON (e.g. with jq).
  2. Restore the file from backup; if not needed, delete it so a fresh empty file is recreated on next save.
  3. Check the wrapped error (%w) in the kernel log for the exact JSON offset/type error.
  4. Reproduce the parse locally: gulu.JSON.UnmarshalJSON with the file bytes to see the precise schema mismatch.

Example fix

// before: hand-edited file with trailing comma
{"version":1,"actions":[{"id":"20240101120000-abc",}]}
// after: valid JSON
{"version":1,"actions":[{"id":"20240101120000-abc","name":"Summarize","action":"summarize"}]}
Defensive patterns

Strategy: fallback

Validate before calling

// validate the file before letting the kernel read it
const fs = require('fs');
try { JSON.parse(fs.readFileSync(p, 'utf8')); } catch (e) { restoreFromBackup(p); }

Try / catch

try {
  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});
} catch (e) {
  if (/unmarshal AI editor actions failed/.test(e.message)) {
    // backup the corrupt file, then delete it so a fresh one is created
  }
}

Prevention

When it happens

Trigger: The persisted actions file contains malformed JSON (truncated write, manual edit) or a JSON value whose shape does not fit {version, actions} (e.g. a JSON array at top level).

Common situations: Crash or power loss during a previous save left a truncated file; user hand-edited data/storage JSON and broke syntax; file corrupted by sync conflict resolution; an older/experimental build wrote a different schema.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/ai_editor.go:163

	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)
		}
		ids[action.ID] = struct{}{}
	}

View on GitHub (pinned to 9f775e8a12)