siyuan-note/siyuan · error
unmarshal legacy AI editor actions failed
Error message
unmarshal legacy AI editor actions failed: %w
What it means
migrateLegacyAIEditorActions reads the legacy actions stored in localStorage and, when the stored value is a JSON string, unmarshals it into []*legacyAIEditorAction. This error wraps that unmarshal failure, meaning the legacy string payload is malformed or does not match the legacy schema. Thrown (via loadAIEditorActions) by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.
Solutions
- Inspect the wrapped error (%w) in the kernel log; then locate the legacy localStorage entry in the workspace storage JSON and fix or validate its JSON string.
- Clear/repair the legacy localStorage entry so migration skips it (empty values are ignored) and re-create actions in the new format via the UI.
- Restore the storage file from backup if the legacy data is important.
- Reproduce offline: gulu.JSON.UnmarshalJSON([]byte(legacyString), &[]*legacyAIEditorAction{}) with the stored string to see the exact schema error.
Example fix
// before: malformed legacy string in localStorage entry
"[{\"id\":\"20240101\",}]"
// after: valid legacy actions JSON
"[{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"Summarize\",\"action\":\"summarize\"}]" Defensive patterns
Strategy: fallback
Validate before calling
// pre-validate the legacy string before migration runs
try { JSON.parse(legacyString); } catch (e) { /* repair or clear the legacy entry */ } Try / catch
try {
const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});
} catch (e) {
if (/unmarshal legacy AI editor actions failed/.test(e.message)) {
// clear the corrupt legacy localStorage entry; recreate actions in new format
}
} Prevention
- Do not let third-party scripts rewrite localStorage-backed storage
- Back up storage files before major upgrades
- Validate legacy JSON after any manual merge
- Prefer recreating actions in the new format over repairing legacy data
When it happens
Trigger: Migrating on first access when the localStorage entry for AI editor actions is a string that fails to parse into the legacy action array — corrupted localStorage value, hand-edited sync/conf data, or a legacy format written by a much older frontend build.
Common situations: Upgrading an old workspace whose localStorage JSON was corrupted; third-party scripts rewriting the localStorage entry; partial data from an interrupted sync of localStorage-backed storage.
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
- marshal legacy AI editor actions failed
- marshal master password migration failed
- unmarshal master password migration failed
- attribute view spec is too new
- block ID must be text
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/cae76dfdae294da5.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/ai_editor.go:215
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)
if marshalErr != nil {
return fmt.Errorf("marshal legacy AI editor actions failed: %w", marshalErr)
}
if err = gulu.JSON.UnmarshalJSON(legacyJSON, &legacyActions); err != nil {
return fmt.Errorf("unmarshal legacy AI editor actions failed: %w", err)
}
}
type actionKey struct {
name string
action string
}
existing := make(map[actionKey]struct{}, len(data.Actions))
for _, action := range data.Actions {
existing[actionKey{name: action.Name, action: action.Action}] = struct{}{}View on GitHub (pinned to 9f775e8a12)