{"record":{"id":"8b75f48c1fc44953","repo":"siyuan-note/siyuan","slug":"create-session-dir-failed-w","errorCode":null,"errorMessage":"create session dir failed: %w","messagePattern":"create session dir failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/session.go","lineNumber":416,"sourceCode":"\t\t\t\treturn currentRevision, nil, err\n\t\t\t}\n\t\t} else if currentCommittedTurnID != commitTurnID {\n\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}","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/session.go#L398-L434","documentation":"Before writing the session file, SaveSessionState ensures the session directory exists with os.MkdirAll(dir, 0755). If directory creation fails (permissions, path conflicts, filesystem errors), the save aborts with this wrapped error.","triggerScenarios":"os.MkdirAll fails because a parent path component exists as a regular file, the process lacks write permission on the parent directory, the filesystem is read-only, or the path is too long.","commonSituations":"Workspace/data directory moved or mounted read-only; sessionsDir path misconfigured so a file blocks the directory path; running the kernel as a user without ownership of the data directory.","solutions":["Check that the session directory path is not blocked by an existing regular file and remove/rename it if so","Verify write permission on the parent of the sessions directory for the kernel process user","Ensure the data volume is mounted read-write","Log the wrapped os.PathError to identify the exact failing path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(sessionsDir); err == nil && !fi.IsDir() { return fmt.Errorf(\"%s exists and is not a directory\", sessionsDir) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create session dir failed\") {\n    var pe *os.PathError\n    if errors.As(err, &pe) {\n        log.Printf(\"mkdir failed at %s: %v\", pe.Path, pe.Err)\n    }\n}","preventionTips":["Ensure the data directory is mounted read-write","Never create a file where a session subdirectory is expected","Run the kernel under a user that owns the workspace data directory"],"tags":["io","filesystem","directory","permissions"],"backgroundTag":"mkdir-permission-denied","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"}