siyuan-note/siyuan · error

create session dir failed

Error message

create session dir failed: %w

What it means

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.

Solutions

  1. Check that the session directory path is not blocked by an existing regular file and remove/rename it if so
  2. Verify write permission on the parent of the sessions directory for the kernel process user
  3. Ensure the data volume is mounted read-write
  4. Log the wrapped os.PathError to identify the exact failing path
Defensive patterns

Strategy: try-catch

Validate before calling

if fi, err := os.Stat(sessionsDir); err == nil && !fi.IsDir() { return fmt.Errorf("%s exists and is not a directory", sessionsDir) }

Try / catch

if err != nil && strings.Contains(err.Error(), "create session dir failed") {
    var pe *os.PathError
    if errors.As(err, &pe) {
        log.Printf("mkdir failed at %s: %v", pe.Path, pe.Err)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/8b75f48c1fc44953. Report an issue: GitHub.

Appendix: source

Thrown at kernel/agent/session.go:416

				return currentRevision, nil, err
			}
		} else if currentCommittedTurnID != commitTurnID {
			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
	}

View on GitHub (pinned to 9f775e8a12)