siyuan-note/siyuan · error
read agent runtime failed
Error message
read agent runtime failed: %w
What it means
After reading the session file, SaveSessionState may need to load the persisted agent runtime (when commitTurnID is set) via loadRuntimeLocked. If loading the runtime fails, the error is wrapped as 'read agent runtime failed' and the commit is aborted before any state is written.
Solutions
- Inspect the wrapped cause from loadRuntimeLocked (log it) and fix the underlying read error
- Restore or delete the corrupt runtime file so it can be recreated on next commit
- Verify the session was created with a compatible version of the runtime schema
- Ensure the runtime directory is readable by the kernel process user
Defensive patterns
Strategy: try-catch
Try / catch
rev, data, err := agent.SaveSessionState(meta, commitTurnID, ...)
if err != nil && strings.Contains(err.Error(), "read agent runtime failed") {
log.Printf("runtime load failed: %v; recovering by rebuilding runtime state", err)
} Prevention
- Never delete or hand-edit the agent runtime file while sessions are active
- Keep kernel versions consistent so runtime schema matches
- Include runtime files in workspace backups
When it happens
Trigger: Calling SaveSessionState with a non-empty commitTurnID whose runtime file cannot be read by loadRuntimeLocked: missing runtime file at an unexpected point, corrupt runtime JSON, or permission/IO error on the runtime file.
Common situations: The runtime file was deleted or corrupted by external tooling or a previous crash; the session was created by an older version writing a different runtime format; permissions on the agent runtime directory changed.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- read session file failed
- map file [ ] failed
- read AI editor actions failed
- save session file failed
- truncate file [ ] failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/bd4dcf633093b581.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/session.go:388
if _, ok := newData[k]; !ok {
// messages 是已废弃的旧会话字段,不再带入新格式;其他未知字段原样保留,
// 避免前后端版本不一致时擦除较新版本写入的数据。
if k != "messages" && k != "expectedRevision" && k != "commitTurnID" &&
k != "recoveryTurnID" && k != "recoveryState" && k != "recoveryRevision" && k != "agentRunning" {
newData[k] = v
}
}
}
}
} else if err != nil && !os.IsNotExist(err) {
return 0, nil, fmt.Errorf("read session file failed: %w", err)
} else if meta.ExpectedRevision != nil && *meta.ExpectedRevision != 0 {
return 0, nil, ErrSessionConflict
}
if commitTurnID != "" {
runtime, err := loadRuntimeLocked(meta.ID)
if err != nil {
return currentRevision, nil, fmt.Errorf("read agent runtime failed: %w", err)
}
if runtime.ActiveTurn != nil {
if runtime.ActiveTurn.TurnID != commitTurnID {
return currentRevision, nil, ErrSessionConflict
}
if !isRuntimeTurnTerminal(runtime.ActiveTurn) {
return currentRevision, nil, ErrRuntimeNotFinalized
}
if err := applyRuntimeTurnToSessionLocked(newData, runtime.ActiveTurn); err != nil {
return currentRevision, nil, err
}
} else if currentCommittedTurnID != commitTurnID {
return currentRevision, nil, ErrSessionConflict
}
}
newRevision := currentRevision + 1
newData["revision"] = newRevisionView on GitHub (pinned to 9f775e8a12)