alibaba/open-code-review · error
resolve home dir: %w
Error message
resolve home dir: %w
What it means
SessionFilePath resolves the user's home directory to construct the absolute JSONL path; a failure from os.UserHomeDir() is wrapped as 'resolve home dir'. Without a home directory the library cannot know where sessions are stored, so the lookup fails. This mirrors the same failure in persist.go's writer open path.
Source
Thrown at internal/session/resume.go:87
ScanPaths *[]string `json:"scanPaths"`
FilePath string `json:"filePath"`
OldPath string `json:"oldPath"`
NewPath string `json:"newPath"`
Fingerprint string `json:"fingerprint"`
SourceSessionID string `json:"sourceSessionId"`
Error string `json:"error"`
Comments []model.LlmComment `json:"comments"`
RunManifest *RunManifest `json:"run_manifest"`
}
// SessionFilePath returns the JSONL path for a persisted session.
func SessionFilePath(repoDir, sessionID string) (string, error) {
if sessionID == "" {
return "", fmt.Errorf("session id is required")
}
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolve home dir: %w", err)
}
return filepath.Join(home, ".opencodereview", sessionSubDir, encodeRepoPath(repoDir), sessionID+".jsonl"), nil
}
// LoadResumeState replays a previous session JSONL into a fingerprint index. A
// record that cannot be parsed fails the load: with nothing to arbitrate coverage,
// a dropped line is indistinguishable from a checkpoint that was never written,
// and the pair it may have belonged to — a review_item_failed retracting an
// earlier done record — cannot be reconstructed from the rest of the file.
func LoadResumeState(repoDir, sessionID string) (*ResumeState, error) {
return loadResumeState(repoDir, sessionID, false)
}
// LoadReviewResumeState replays a review session, dropping records it cannot
// parse. Review reuse is gated on the parent manifest rather than on these lines
// (see ReusableItem), so an unreadable checkpoint just means its file is reviewed
// again — which is what a corrupted checkpoint is supposed to do. Failing the
// whole load instead would turn one bad line into the loss of every other file'sView on GitHub (pinned to 5cf97d0d15)
Solutions
- Set HOME to the directory holding ~/.opencodereview (export HOME=/root or the user's real home) before running the tool
- Run as a user with a valid passwd entry and home directory
- In Docker, add ENV HOME=/root or pass -e HOME=...
- Confirm the session files exist under $HOME/.opencodereview/<sessions>/<encoded-repo>/ once HOME is correct
Example fix
// before (systemd unit) ExecStart=/usr/local/bin/ocr resume // after Environment=HOME=/root ExecStart=/usr/local/bin/ocr resume
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("HOME") == "" {
if _, err := os.UserHomeDir(); err != nil {
return fmt.Errorf("HOME not resolvable; sessions cannot be located: %w", err)
}
} Try / catch
path, err := session.SessionFilePath(repoDir, sessionID)
if err != nil {
if strings.Contains(err.Error(), "resolve home dir") {
log.Fatalf("set HOME to the directory containing ~/.opencodereview: %v", err)
}
} Prevention
- Export HOME in headless environments (cron, systemd, Docker)
- Run loaders as the same user that created the sessions
- Verify $HOME/.opencodereview exists before attempting resume
When it happens
Trigger: SessionFilePath (via LoadComments/LoadSummary/LoadDetail/loadResumeState) calls os.UserHomeDir() and it errors: HOME unset in the process environment and no passwd entry for the current user.
Common situations: Cron/systemd/CI environments without HOME; Docker containers running as a bare uid; su/sudo configurations stripping the environment.
Related errors
- resolve home dir: %w
- cannot determine home directory: %w
- read background file %q: %w
- background file %q is a directory, not a file
- resolve LLM endpoint: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/14f9b6eeb0259733.
Report an issue: GitHub.