chenhg5/cc-connect · error

kimi: read sessions dir: %w

Error message

kimi: read sessions dir: %w

What it means

listKimiSessions returns this when os.ReadDir on one of kimi's session base directories fails with an error other than NotExist (which is skipped). It means the sessions directory exists but could not be read — typically a permissions problem.

Source

Thrown at agent/kimi/kimi.go:358

		filepath.Join(homeDir, ".kimi", "sessions"),
		filepath.Join(homeDir, ".kimi-code", "sessions"),
	}
}

func listKimiSessions(workDir string) ([]core.AgentSessionInfo, error) {
	absWorkDir, err := filepath.Abs(workDir)
	if err != nil {
		absWorkDir = workDir
	}

	var sessions []core.AgentSessionInfo
	for _, sessionsBase := range kimiSessionsBaseDirs() {
		entries, err := os.ReadDir(sessionsBase)
		if err != nil {
			if os.IsNotExist(err) {
				continue
			}
			return nil, fmt.Errorf("kimi: read sessions dir: %w", err)
		}

		for _, entry := range entries {
			if !entry.IsDir() {
				continue
			}
			projectDir := filepath.Join(sessionsBase, entry.Name())
			sessionEntries, err := os.ReadDir(projectDir)
			if err != nil {
				continue
			}
			for _, se := range sessionEntries {
				if !se.IsDir() {
					continue
				}
				sessionDir := filepath.Join(projectDir, se.Name())
				info := parseKimiSessionDir(sessionDir, absWorkDir)
				if info != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix permissions: `chmod u+rx` the sessions directory and chown it to the daemon user
  2. Confirm the path is a directory (`ls -la`); remove/rename any file shadowing it
  3. Align the daemon's HOME with the user owning the kimi sessions
  4. Check mount health if sessions live on a network volume

Example fix

// before
# daemon user cannot read sessions
// after
sudo chown -R cc-connect:cc-connect ~/.kimi/sessions
sudo chmod -R u+rwX ~/.kimi/sessions
Defensive patterns

Strategy: try-catch

Validate before calling

for _, base := range kimiSessionsBaseDirs() {
    if st, err := os.Stat(base); err == nil && !st.IsDir() {
        return fmt.Errorf("%s is not a directory", base)
    }
}

Try / catch

sessions, err := agent.ListSessions(ctx)
if err != nil {
    if strings.Contains(err.Error(), "read sessions dir") {
        log.Printf("check permissions/ownership of kimi sessions dir: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ListSessions (or DeleteSession flows that enumerate) when a kimi sessions base dir exists but ReadDir fails: permission denied on the directory, it is not actually a directory, or an I/O error on the volume.

Common situations: Daemon runs as a different user than the one who owns ~/.kimi (or ~/.config/kimi); sessions path replaced by a file; NFS/sshfs mount hiccup; restrictive umask/ACLs after a restore or migration.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/af7b68347a66d25c. Report an issue: GitHub.