{"record":{"id":"d01a67a9b13ed899","repo":"chenhg5/cc-connect","slug":"session-file-not-found-s-d01a67","errorCode":null,"errorMessage":"session file not found: %s","messagePattern":"session file not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/codex.go","lineNumber":535,"sourceCode":"\tworkDir := a.workDir\n\ta.mu.RUnlock()\n\treturn listCodexSessions(workDir, codexHome)\n}\n\nfunc (a *Agent) GetSessionHistory(_ context.Context, sessionID string, limit int) ([]core.HistoryEntry, error) {\n\ta.mu.RLock()\n\tcodexHome := a.codexHome\n\ta.mu.RUnlock()\n\treturn getSessionHistory(sessionID, codexHome, limit)\n}\n\nfunc (a *Agent) DeleteSession(_ context.Context, sessionID string) error {\n\ta.mu.RLock()\n\tcodexHome := a.codexHome\n\ta.mu.RUnlock()\n\tpath := findSessionFile(sessionID, codexHome)\n\tif path == \"\" {\n\t\treturn fmt.Errorf(\"session file not found: %s\", sessionID)\n\t}\n\treturn os.Remove(path)\n}\n\nfunc (a *Agent) Stop() error { return nil }\n\n// SetMode changes the approval mode for future sessions.\nfunc (a *Agent) SetMode(mode string) {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\ta.mode = normalizeMode(mode)\n\tslog.Info(\"codex: approval mode changed\", \"mode\", a.mode)\n}\n\nfunc (a *Agent) GetMode() string {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\treturn a.mode","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/codex.go#L517-L553","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the session ID is correct (list sessions first with ListSessions).","Check that CODEX_HOME / the agent's codexHome points to the directory that actually contains the rollout files.","If the file was already removed, treat the session as deleted and ignore the error (idempotent cleanup)."],"exampleFix":"// before\nif err := agent.DeleteSession(ctx, id); err != nil { return err }\n// after\nif err := agent.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"session file not found\") {\n        return nil // already gone; treat as idempotent success\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"ids, _ := agent.ListSessions(ctx)\nvar known bool\nfor _, s := range ids { if s.ID == sessionID { known = true } }\nif !known { return nil } // nothing to delete","typeGuard":null,"tryCatchPattern":"if err := agent.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"session file not found\") {\n        return nil // already deleted; idempotent\n    }\n    return fmt.Errorf(\"delete codex session: %w\", err)\n}","preventionTips":["Always source session IDs from ListSessions, never from stale user input.","Treat deletion as idempotent: swallow not-found errors.","Keep CODEX_HOME stable across restarts; do not change it between create and delete.","Avoid manual cleanup of ~/.codex/sessions while sessions are managed by cc-connect."],"tags":["session","file-not-found","cleanup"],"backgroundTag":"file-not-found","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}