alibaba/open-code-review · error

list sessions: %w

Error message

list sessions: %w

What it means

`ocr session list` enumerates persisted session summaries for the resolved repository directory via session.ListSessions. Any error reading/decoding the session store (unreadable ~/.opencodereview/sessions/<repo>/ directory, corrupted JSONL preventing summary extraction) is wrapped as "list sessions: %w".

Source

Thrown at cmd/opencodereview/session_cmd.go:156

	sessionCommentsCmd.RegisterFlagCompletionFunc("category", completeEnum("bug", "security", "performance", "maintainability", "test", "style", "documentation", "other"))

	sessionCompareCmd.Flags().StringVar(&sessionCompareRepoDir, "repo", "", "root directory of the git repository (default: current dir)")
	sessionCompareCmd.Flags().BoolVar(&sessionCompareJSON, "json", false, "emit the comparison as JSON")

	sessionCmd.AddCommand(sessionListCmd)
	sessionCmd.AddCommand(sessionShowCmd)
	sessionCmd.AddCommand(sessionCommentsCmd)
	sessionCmd.AddCommand(sessionCompareCmd)
}

func runSessionList() error {
	resolvedRepo, err := resolveWorkingDirForSession(sessionListRepoDir)
	if err != nil {
		return err
	}
	summaries, err := session.ListSessions(resolvedRepo)
	if err != nil {
		return fmt.Errorf("list sessions: %w", err)
	}
	if sessionListLimit > 0 && len(summaries) > sessionListLimit {
		summaries = summaries[:sessionListLimit]
	}

	if sessionListJSON {
		enc := json.NewEncoder(os.Stdout)
		enc.SetIndent("", "  ")
		return enc.Encode(summaries)
	}

	if len(summaries) == 0 {
		fmt.Printf("No sessions found for %s\n", resolvedRepo)
		return nil
	}
	printSessionTable(os.Stdout, summaries)
	return nil
}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Inspect the wrapped cause: fix filesystem permissions on ~/.opencodereview/sessions or set HOME correctly.
  2. Delete or repair the specific corrupted <id>.jsonl named in the inner error (move it aside and retry).
  3. Recreate the sessions directory empty if contents are unrecoverable (old sessions are then lost).
  4. Run from the same repository so the encoded repo path matches; a different cwd changes which store is read.

Example fix

// before (unreadable store)
ls: ~/.opencodereview/sessions: Permission denied
// after
chmod u+rx ~/.opencodereview ~/.opencodereview/sessions && ocr session list
Defensive patterns

Strategy: try-catch

Validate before calling

if home, err := os.UserHomeDir(); err != nil || !writable(filepath.Join(home, ".opencodereview", "sessions")) {
    return fmt.Errorf("session store unavailable; fix $HOME or permissions")
}

Try / catch

summaries, err := session.ListSessions(resolvedRepo)
if err != nil {
    // Surface the inner cause (permissions vs corrupted file) to the user
    return fmt.Errorf("list sessions: %v (check ~/.opencodereview/sessions)", err)
}

Prevention

When it happens

Trigger: Running `ocr session list` when the sessions directory cannot be read (permissions, HOME unresolved) or one or more stored session JSONL files fail to parse while building summaries.

Common situations: $HOME not writable/resolvable (containers, sudo); sessions dir manually deleted mid-read or partially copied; corrupted JSONL files from a killed ocr process.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/ea3b2b75f4dd006b. Report an issue: GitHub.