alibaba/open-code-review · error

read session %q: %w

Error message

read session %q: %w

What it means

While streaming a session .jsonl file, walkSessionFile reads it line-by-line with bufio.Reader.ReadBytes. If a read fails for a reason other than clean io.EOF, the error is wrapped as 'read session %q: ...'. This indicates the file became unreadable mid-read or I/O failed — not malformed content per se, but an OS-level read error.

Source

Thrown at internal/session/list.go:216

	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)
		}
	}
}

func applyRecordToSummary(s *Summary, rec summaryRecord) {
	ts := parseRecordTime(rec.Timestamp)
	switch rec.Type {
	case "session_start":
		if rec.SessionID != "" {
			s.SessionID = rec.SessionID
		}
		if rec.Cwd != "" {
			s.RepoDir = rec.Cwd
		}
		s.GitBranch = rec.GitBranch
		s.Model = rec.Model
		s.ReviewMode = rec.ReviewMode
		s.DiffFrom = rec.DiffFrom

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Wait for any concurrent ocr run to finish, then retry reading the session.
  2. Verify disk health / remount the filesystem if I/O errors persist.
  3. Delete the corrupt session file and rely on a fresh session (or restore from backup).
  4. Check the wrapped cause (%w) for the exact errno (EIO, ESTALE, etc.).
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure no concurrent writer is holding the session open
if locked := isProcessWriting(sessionPath); locked {
    return fmt.Errorf("session file is being written; retry after the run finishes")
}

Try / catch

comments, err := session.LoadComments(repoDir, sessionID)
if err != nil {
    if strings.Contains(err.Error(), "read session") {
        time.Sleep(2 * time.Second) // transient I/O; retry once
        return session.LoadComments(repoDir, sessionID)
    }
    return err
}

Prevention

When it happens

Trigger: LoadComments/LoadDetail/loadSummaryFromFile → walkSessionFile when ReadBytes returns a non-EOF error: file truncated/modified concurrently, I/O error, or (depending on handling) an oversized line hitting the buffer limit.

Common situations: Session file being written by a concurrent ocr process; disk errors or failing NFS mount; file replaced (renamed) between open and read; corrupt filesystem.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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