chenhg5/cc-connect · error

pi: read session dir

Error message

pi: read session dir: %w

What it means

Wraps a failed os.ReadDir of the pi agent's session directory during listing. Not-exist returns no sessions; this error fires only on other IO failures such as permission denial while scanning the pi storage directory.

Solutions

  1. Fix read permissions on the pi sessions directory
  2. Check for filesystem errors on the path
  3. Retry /sessions after repair
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at agent/pi/pi.go:173 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at agent/pi/pi.go:173

	// 优先生效(getenv 返回第一个匹配项)。
	extraEnv = append(extraEnv, core.InjectedAgentEnv(mode)...)
	rpc := a.rpc
	a.mu.Unlock()
	return newPiSession(ctx, a.cmd, extraArgs, a.workDir, model, mode, thinking, rpc, sessionID, extraEnv)
}

func (a *Agent) ListSessions(_ context.Context) ([]core.AgentSessionInfo, error) {
	sessDir := piSessionDir(a.workDir)
	if sessDir == "" {
		return nil, nil
	}

	entries, err := os.ReadDir(sessDir)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		}
		return nil, fmt.Errorf("pi: read session dir: %w", err)
	}

	var sessions []core.AgentSessionInfo
	for _, entry := range entries {
		name := entry.Name()
		if entry.IsDir() || !strings.HasSuffix(name, ".jsonl") {
			continue
		}

		info, err := entry.Info()
		if err != nil {
			continue
		}

		sessionID, summary, msgCount := scanPiSession(filepath.Join(sessDir, name))
		if sessionID == "" {
			continue
		}

View on GitHub (pinned to 4000b2338a)