alibaba/open-code-review · error

load session %q: %w

Error message

load session %q: %w

What it means

`ocr session show <id>` loads the session summary plus per-file item records via session.LoadDetail. If the session file is missing for this repo, the id is wrong, or the JSONL cannot be parsed/walked, the CLI wraps it as "load session %q: %w".

Source

Thrown at cmd/opencodereview/session_cmd.go:183

		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
}

func runSessionShow(sessionID string) error {
	resolvedRepo, err := resolveWorkingDirForSession(sessionShowRepoDir)
	if err != nil {
		return err
	}
	summary, items, err := session.LoadDetail(resolvedRepo, sessionID)
	if err != nil {
		return fmt.Errorf("load session %q: %w", sessionID, err)
	}

	if sessionShowJSON {
		payload := struct {
			Summary *session.Summary     `json:"summary"`
			Items   []session.ItemDetail `json:"items"`
		}{Summary: summary, Items: items}
		enc := json.NewEncoder(os.Stdout)
		enc.SetIndent("", "  ")
		return enc.Encode(payload)
	}

	printSessionDetail(os.Stdout, summary, items)
	return nil
}

func runSessionComments(sessionID string) error {
	resolvedRepo, err := resolveWorkingDirForSession(sessionCommentsRepoDir)

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Run `ocr session list` in the same repo and use an exact id from the output.
  2. Verify you're in the repository where the session was created.
  3. If the JSONL is corrupted (inner parse error), restore from backup or treat the session as lost.
  4. Check ~/.opencodereview/sessions/<encoded-repo>/<id>.jsonl exists.

Example fix

// before
ocr session show 3f9a
// after
ocr session list
ocr session show 3f9a1b2c-4d5e-6f70-a1b2-c3d4e5f60718
Defensive patterns

Strategy: validation

Validate before calling

ids := mustListSessions(repoDir) // via session.ListSessions
if !contains(ids, sessionID) {
    return fmt.Errorf("session %q not found in this repo; available: %v", sessionID, ids)
}

Type guard

func sessionExists(repoDir, id string) bool {
    p, err := session.SessionFilePath(repoDir, id)
    if err != nil { return false }
    _, err = os.Stat(p)
    return err == nil
}

Try / catch

summary, items, err := session.LoadDetail(resolvedRepo, sessionID)
if err != nil {
    if errors.Is(err, fs.ErrNotExist) {
        return fmt.Errorf("no session %q here; try `ocr session list`", sessionID)
    }
    return fmt.Errorf("session file unreadable: %v", err) // parse failure path
}

Prevention

When it happens

Trigger: Running `ocr session show <id>` with an id that doesn't exist in this repo's session store, or whose JSONL is truncated/corrupted so LoadDetail fails mid-walk.

Common situations: Copy-pasting a partial session id; showing a session from a different repository (store is keyed by repo path); inspecting a session whose file was truncated by a hard kill.

Related errors


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