chenhg5/cc-connect · error

session file not found for %s

Error message

session file not found for %s

What it means

getSessionHistory resolves a session ID to its rollout JSONL file with findSessionFile before parsing the transcript. If no file is found it returns this error instead of attempting os.Open on an empty path. It indicates the requested session's history does not exist on disk.

Source

Thrown at agent/codex/list.go:251

	var found string
	_ = filepath.Walk(sessionsDir, func(path string, info os.FileInfo, err error) error {
		if err != nil || info.IsDir() || found != "" {
			return nil
		}
		if strings.Contains(filepath.Base(path), sessionID) {
			found = path
		}
		return nil
	})
	return found
}

// getSessionHistory reads the JSONL transcript and returns user/assistant messages.
func getSessionHistory(sessionID, codexHome string, limit int) ([]core.HistoryEntry, error) {
	path := findSessionFile(sessionID, codexHome)
	if path == "" {
		return nil, fmt.Errorf("session file not found for %s", sessionID)
	}

	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	var entries []core.HistoryEntry

	scanner := bufio.NewScanner(f)
	scanner.Buffer(make([]byte, 256*1024), 256*1024)

	for scanner.Scan() {
		line := scanner.Text()
		if line == "" {
			continue
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. List sessions first and pass an ID returned by ListSessions.
  2. Verify codexHome points at the CODEX_HOME used when the session ran.
  3. Handle the not-found case gracefully in the UI (show 'no history') instead of surfacing an error.

Example fix

// before
history, err := agent.GetSessionHistory(ctx, id, 50)
if err != nil { return err }
// after
history, err := agent.GetSessionHistory(ctx, id, 50)
if err != nil {
    if strings.Contains(err.Error(), "session file not found") {
        return []core.HistoryEntry{}, nil
    }
    return err
}
Defensive patterns

Strategy: validation

Validate before calling

sessions, _ := agent.ListSessions(ctx)
valid := map[string]bool{}
for _, s := range sessions { valid[s.ID] = true }
if !valid[sessionID] {
    return nil, fmt.Errorf("unknown session %q; use ListSessions", sessionID)
}
history, err := agent.GetSessionHistory(ctx, sessionID, limit)

Try / catch

history, err := agent.GetSessionHistory(ctx, id, limit)
if err != nil {
    if strings.Contains(err.Error(), "session file not found") {
        return []core.HistoryEntry{}, nil // show empty history
    }
    return err
}

Prevention

When it happens

Trigger: GetSessionHistory(sessionID, ...) when findSessionFile returns "" — the session ID has no matching rollout file under codexHome.

Common situations: Requesting /history for a stale/deleted session; codexHome mismatch (CODEX_HOME changed); typo'd or foreign session ID; codex pruned old sessions automatically.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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