{"record":{"id":"21cf79cfc685431d","repo":"chenhg5/cc-connect","slug":"gemini-cannot-determine-home-dir-w","errorCode":null,"errorMessage":"gemini: cannot determine home dir: %w","messagePattern":"gemini: cannot determine home dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/gemini/gemini.go","lineNumber":237,"sourceCode":"\tif a.activeIdx >= 0 && a.activeIdx < len(a.providers) {\n\t\tif m := a.providers[a.activeIdx].Model; m != \"\" {\n\t\t\tmodel = m\n\t\t}\n\t}\n\ta.mu.Unlock()\n\n\treturn newGeminiSession(ctx, cmd, extraArgs, workDir, model, mode, sessionID, extraEnv, timeout)\n}\n\n// ListSessions reads sessions from ~/.gemini/tmp/<project_hash>/chats/.\nfunc (a *Agent) ListSessions(_ context.Context) ([]core.AgentSessionInfo, error) {\n\treturn listGeminiSessions(a.workDir)\n}\n\nfunc (a *Agent) DeleteSession(_ context.Context, sessionID string) error {\n\thomeDir, err := os.UserHomeDir()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"gemini: cannot determine home dir: %w\", err)\n\t}\n\tchatsDir := filepath.Join(homeDir, \".gemini\", \"tmp\", geminiProjectSlug(a.workDir), \"chats\")\n\t// Session files are named session-<timestamp>-<uuid_prefix>.json, not <uuid>.json.\n\t// Scan the directory to find the file containing the matching sessionId.\n\tentries, err := os.ReadDir(chatsDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"session file not found: %s\", sessionID)\n\t}\n\tfor _, entry := range entries {\n\t\tif entry.IsDir() || !strings.HasSuffix(entry.Name(), \".json\") {\n\t\t\tcontinue\n\t\t}\n\t\tfpath := filepath.Join(chatsDir, entry.Name())\n\t\tdata, err := os.ReadFile(fpath)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tvar sf struct {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/gemini/gemini.go#L219-L255","documentation":"DeleteSession needs the user's home directory to locate ~/.gemini/tmp/<slug>/chats. os.UserHomeDir() failed (usually $HOME unset), so the session cannot be deleted. The error wraps the underlying OS error.","triggerScenarios":"Calling Agent.DeleteSession(ctx, sessionID) in an environment where os.UserHomeDir() returns an error: $HOME (and on Windows USERPROFILE) is unset, e.g. daemons, containers, or services running with a scrubbed environment.","commonSituations":"systemd service with minimal env; Docker container running as non-root without HOME; cron jobs lacking HOME; running under a service manager with a restricted environment.","solutions":["Set HOME in the process environment (e.g. Environment=HOME=/home/user in the systemd unit)","Run cc-connect as a normal user with a valid home directory","Pass the home dir via env explicitly when launching the daemon in containers (ENV HOME=/root)","Log the wrapped inner error to confirm which env var is missing"],"exampleFix":"// before: docker run with no HOME\nCMD [\"/usr/local/bin/cc-connect\"]\n// after\ndocker run -e HOME=/home/ccuser ...","handlingStrategy":"validation","validationCode":"home, err := os.UserHomeDir()\nif err != nil || home == \"\" {\n  return fmt.Errorf(\"cannot manage gemini sessions: set $HOME for this process\")\n}","typeGuard":null,"tryCatchPattern":"if err := agent.DeleteSession(ctx, id); err != nil && strings.Contains(err.Error(), \"cannot determine home dir\") {\n  log.Printf(\"environment misconfigured (HOME unset): %v\", err)\n}","preventionTips":["Always set HOME (and USERPROFILE on Windows) for daemons/containers","Test the service under its real runtime env, not just an interactive shell","Prefer running services under a dedicated user with a valid home directory"],"tags":["home-dir","environment","filesystem"],"backgroundTag":"missing-env-var","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}