siyuan-note/siyuan · error
marshal legacy AI editor actions failed
Error message
marshal legacy AI editor actions failed: %w
What it means
migrateLegacyAIEditorActions handles the case where the legacy localStorage value is not a string: it re-marshals the raw value with gulu.JSON.MarshalJSON before unmarshalling into []*legacyAIEditorAction. This error wraps the re-marshal failure, indicating the raw stored value cannot be serialized (unsupported type or internal inconsistency). Thrown via GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.
Solutions
- Check the wrapped error (%w) in the kernel log to identify the unsupported value/type.
- Repair or reset the legacy storage entry in the workspace storage JSON so migration sees either a valid string or a normal JSON value.
- If legacy data is unimportant, clear the legacy entry and recreate AI editor actions in the new format via the UI.
- Treat repeated occurrences as an internal bug: capture the value type and report with kernel version.
Example fix
// before: corrupt non-string legacy value in storage
"legacyKey": {"oops": function}
// after: normal decodable value
"legacyKey": [{"id":"20240101120000-a1b2c3d4e5f6","name":"Summarize","action":"summarize"}] Defensive patterns
Strategy: fallback
Validate before calling
// ensure the legacy value round-trips through JSON before migration
try { JSON.parse(JSON.stringify(legacyRaw)); } catch (e) { /* reset the legacy entry */ } Try / catch
try {
const actions = await fetchSyncPost('/api/ai/editor/saveAIEditorAction', { id, name, action });
} catch (e) {
if (/marshal legacy AI editor actions failed/.test(e.message)) {
// reset the legacy storage entry to a plain decodable value or clear it
}
} Prevention
- Keep legacy storage values as plain JSON arrays/strings
- Never inject non-JSON values into workspace storage files
- Clear unneeded legacy entries before upgrading
- Round-trip test storage data through JSON in maintenance scripts
When it happens
Trigger: Migration path where legacyRaw is a non-string (e.g. already-decoded array/object) and gulu.JSON.MarshalJSON fails — practically only when the in-memory decoded value contains non-JSON-safe data or the storage layer returned an unexpected type.
Common situations: Corrupted or hand-modified storage JSON producing an exotic decoded value; a kernel/storage-layer bug returning an unsupported runtime type; data injected by third-party tooling into the storage file.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- marshal master password migration failed
- unmarshal legacy AI editor actions failed
- encode session data failed
- marshal AI editor actions failed
- marshal box conf [ ] failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/71618d4f4ea2a5d1.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/ai_editor.go:220
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{}{}
}
changed := false
for _, legacyAction := range legacyActions {
if legacyAction == nil || (legacyAction.Name == "" && legacyAction.Memo == "") {View on GitHub (pinned to 9f775e8a12)