{"record":{"id":"6d80c824428b6b2c","repo":"siyuan-note/siyuan","slug":"save-session-file-failed-w","errorCode":null,"errorMessage":"save session file failed: %w","messagePattern":"save session file failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/session.go","lineNumber":419,"sourceCode":"\t\t\treturn currentRevision, nil, ErrSessionConflict\n\t\t}\n\t}\n\n\tnewRevision := currentRevision + 1\n\tnewData[\"revision\"] = newRevision\n\tif commitTurnID != \"\" {\n\t\tnewData[\"lastCommittedTurnID\"] = commitTurnID\n\t}\n\tdata, err = gulu.JSON.MarshalIndentJSON(newData, \"\", \"\\t\")\n\tif err != nil {\n\t\treturn currentRevision, nil, fmt.Errorf(\"encode session data failed: %w\", err)\n\t}\n\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn currentRevision, nil, fmt.Errorf(\"create session dir failed: %w\", err)\n\t}\n\tif err := filelock.WriteFile(path, data); err != nil {\n\t\treturn currentRevision, nil, fmt.Errorf(\"save session file failed: %w\", err)\n\t}\n\tif commitTurnID != \"\" {\n\t\tif err := markRuntimeCommittedLocked(meta.ID, commitTurnID); err != nil {\n\t\t\tlogging.LogWarnf(\"commit agent runtime failed: %s\", err)\n\t\t}\n\t}\n\n\ttitle, _ := newData[\"title\"].(string)\n\tif title == \"\" {\n\t\ttitle = \"AI Agent\"\n\t}\n\tcreatedAt := meta.CreatedAt\n\tif value := numberToInt64(newData[\"createdAt\"]); value > 0 {\n\t\tcreatedAt = value\n\t}\n\tupdatedAt := meta.UpdatedAt\n\tif value := numberToInt64(newData[\"updatedAt\"]); value > 0 {\n\t\tupdatedAt = value","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/session.go#L401-L437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if df, err := diskFree(dataDir); err == nil && df < minRequiredBytes { return fmt.Errorf(\"insufficient disk space to save session\") }","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    rev, data, err = agent.SaveSessionState(meta, ...)\n    if err == nil || !isTransientWriteError(err) {\n        break\n    }\n    time.Sleep(backoff(attempt)) // transient lock/disk contention\n}","preventionTips":["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"],"tags":["io","filesystem","persistence","file-lock"],"backgroundTag":"file-write-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}