siyuan-note/siyuan · error
save session file failed
Error message
save session file failed: %w
What it means
SaveSessionState writes the marshaled session JSON through filelock.WriteFile, which takes the file lock and writes atomically. If the write fails, this wrapped error is returned, meaning the new revision was computed but NOT persisted — callers should not treat the returned revision as durable.
Solutions
- Check the wrapped cause: if it is a lock timeout, find/kill the process holding the file lock or remove the stale lock file
- Free disk space / raise quota on the data volume
- Verify the session file is writable by the kernel process user
- Retry the save after resolving the transient condition
Defensive patterns
Strategy: retry
Validate before calling
if df, err := diskFree(dataDir); err == nil && df < minRequiredBytes { return fmt.Errorf("insufficient disk space to save session") } Try / catch
for attempt := 0; attempt < 3; attempt++ {
rev, data, err = agent.SaveSessionState(meta, ...)
if err == nil || !isTransientWriteError(err) {
break
}
time.Sleep(backoff(attempt)) // transient lock/disk contention
} Prevention
- Monitor disk space and quotas on the data volume
- Avoid running backup/AV software that holds locks on workspace files
- Treat the returned revision as durable only when err == nil
When it happens
Trigger: filelock.WriteFile fails due to the file being locked by another process for too long, a full disk, permission errors on the existing session file, or underlying I/O errors.
Common situations: Disk quota/full disk on the data volume; a stale lock from a crashed kernel instance; antivirus or backup software holding the session file; permissions changed on the session file.
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
- map file [ ] failed
- read AI editor actions failed
- read session file failed
- truncate file [ ] failed
- check data.zip failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/6d80c824428b6b2c.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/session.go:419
return currentRevision, nil, ErrSessionConflict
}
}
newRevision := currentRevision + 1
newData["revision"] = newRevision
if commitTurnID != "" {
newData["lastCommittedTurnID"] = commitTurnID
}
data, err = gulu.JSON.MarshalIndentJSON(newData, "", "\t")
if err != nil {
return currentRevision, nil, fmt.Errorf("encode session data failed: %w", err)
}
if err := os.MkdirAll(dir, 0755); err != nil {
return currentRevision, nil, fmt.Errorf("create session dir failed: %w", err)
}
if err := filelock.WriteFile(path, data); err != nil {
return currentRevision, nil, fmt.Errorf("save session file failed: %w", err)
}
if commitTurnID != "" {
if err := markRuntimeCommittedLocked(meta.ID, commitTurnID); err != nil {
logging.LogWarnf("commit agent runtime failed: %s", err)
}
}
title, _ := newData["title"].(string)
if title == "" {
title = "AI Agent"
}
createdAt := meta.CreatedAt
if value := numberToInt64(newData["createdAt"]); value > 0 {
createdAt = value
}
updatedAt := meta.UpdatedAt
if value := numberToInt64(newData["updatedAt"]); value > 0 {
updatedAt = valueView on GitHub (pinned to 9f775e8a12)