alibaba/open-code-review · error

open session %q: %w

Error message

open session %q: %w

What it means

walkSessionFile opens a persisted .jsonl session file to apply records. If os.Open fails, the error is wrapped as 'open session %q: ...'. This is reached by LoadComments, LoadDetail, and loadSummaryFromFile when a specific session file cannot be opened.

Source

Thrown at internal/session/list.go:199

		FilePath:  path,
		RepoDir:   repoDir,
		Aborted:   true,
	}
	if err := walkSessionFile(path, func(rec summaryRecord) {
		applyRecordToSummary(summary, rec)
	}); err != nil {
		return nil, err
	}
	if summary.SessionID == "" {
		summary.SessionID = sessionID
	}
	return summary, nil
}

func walkSessionFile(path string, apply func(summaryRecord)) error {
	f, err := os.Open(path)
	if err != nil {
		return fmt.Errorf("open session %q: %w", path, err)
	}
	defer f.Close()

	reader := bufio.NewReader(f)
	for {
		line, readErr := reader.ReadBytes('\n')
		if len(line) > 0 {
			var rec summaryRecord
			if err := json.Unmarshal(line, &rec); err == nil {
				apply(rec)
			}
		}
		if readErr == io.EOF {
			return nil
		}
		if readErr != nil {
			return fmt.Errorf("read session %q: %w", path, readErr)
		}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Verify the session ID exists: `ocr session list` and use an ID from its output.
  2. Check file permissions on ~/.opencodereview/sessions/<repo>/<id>.jsonl and fix with chown/chmod.
  3. Re-create the session file by re-running the review/scan command if it was deleted.
  4. If the repo path changed, note the encoded directory name changes; run sessions from the new path.
Defensive patterns

Strategy: validation

Validate before calling

sessions, err := session.ListSessions(repoDir)
if err != nil {
    return err
}
found := false
for _, s := range sessions {
    if s.ID == wantedID {
        found = true
    }
}
if !found {
    return fmt.Errorf("session %s not found; pick an ID from session list", wantedID)
}

Try / catch

comments, err := session.LoadComments(repoDir, sessionID)
if err != nil {
    if strings.Contains(err.Error(), "open session") {
        return fmt.Errorf("session %s missing or unreadable; run `ocr session list`: %w", sessionID, err)
    }
    return err
}

Prevention

When it happens

Trigger: Loading a session by ID or path when the .jsonl file is missing (deleted or wrong session ID), unreadable (permissions), or the resolved path points elsewhere (repo re-encoded path mismatch).

Common situations: Session file deleted manually or by cleanup scripts; running as a different user than the one that created the session; typo'd or stale session ID; path traversal of an encoded repo path after the repo moved.

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 alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/9ecf34160506a87d. Report an issue: GitHub.