chenhg5/cc-connect · error

session file not found: %s

Error message

session file not found: %s

What it means

DeleteSession removes the codex rollout file backing a session. It first resolves the session ID to a file under $CODEX_HOME via findSessionFile; if no file matches, it returns this error rather than attempting os.Remove on an empty path. It signals the session record does not exist on disk.

Source

Thrown at agent/codex/codex.go:535

	workDir := a.workDir
	a.mu.RUnlock()
	return listCodexSessions(workDir, codexHome)
}

func (a *Agent) GetSessionHistory(_ context.Context, sessionID string, limit int) ([]core.HistoryEntry, error) {
	a.mu.RLock()
	codexHome := a.codexHome
	a.mu.RUnlock()
	return getSessionHistory(sessionID, codexHome, limit)
}

func (a *Agent) DeleteSession(_ context.Context, sessionID string) error {
	a.mu.RLock()
	codexHome := a.codexHome
	a.mu.RUnlock()
	path := findSessionFile(sessionID, codexHome)
	if path == "" {
		return fmt.Errorf("session file not found: %s", sessionID)
	}
	return os.Remove(path)
}

func (a *Agent) Stop() error { return nil }

// SetMode changes the approval mode for future sessions.
func (a *Agent) SetMode(mode string) {
	a.mu.Lock()
	defer a.mu.Unlock()
	a.mode = normalizeMode(mode)
	slog.Info("codex: approval mode changed", "mode", a.mode)
}

func (a *Agent) GetMode() string {
	a.mu.Lock()
	defer a.mu.Unlock()
	return a.mode

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify the session ID is correct (list sessions first with ListSessions).
  2. Check that CODEX_HOME / the agent's codexHome points to the directory that actually contains the rollout files.
  3. If the file was already removed, treat the session as deleted and ignore the error (idempotent cleanup).

Example fix

// before
if err := agent.DeleteSession(ctx, id); err != nil { return err }
// after
if err := agent.DeleteSession(ctx, id); err != nil {
    if strings.Contains(err.Error(), "session file not found") {
        return nil // already gone; treat as idempotent success
    }
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

ids, _ := agent.ListSessions(ctx)
var known bool
for _, s := range ids { if s.ID == sessionID { known = true } }
if !known { return nil } // nothing to delete

Try / catch

if err := agent.DeleteSession(ctx, id); err != nil {
    if strings.Contains(err.Error(), "session file not found") {
        return nil // already deleted; idempotent
    }
    return fmt.Errorf("delete codex session: %w", err)
}

Prevention

When it happens

Trigger: Calling DeleteSession(ctx, sessionID) with an ID that has no corresponding rollout file in codexHome (typically ~/.codex/sessions/**), e.g. a stale or already-deleted session ID, or when codexHome is wrong.

Common situations: User runs /sessions delete on a session whose rollout was cleaned up manually or by codex pruning; session ID from another machine's CODEX_HOME; CODEX_HOME changed between session creation and deletion.

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/d01a67a9b13ed899. Report an issue: GitHub.