{"record":{"id":"626e3d5232ecddb6","repo":"alibaba/open-code-review","slug":"load-resume-session-w-run-ocr-session-list-to-626e3d","errorCode":null,"errorMessage":"load resume session: %w (run 'ocr session list' to see available sessions)","messagePattern":"load resume session: %w \\(run 'ocr session list' to see available sessions\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/scan_cmd.go","lineNumber":255,"sourceCode":"\tif err != nil {\n\t\tspan.SetStatus(codes.Error, err.Error())\n\t\tspan.RecordError(err)\n\t\tif id := ag.SessionID(); id != \"\" {\n\t\t\tfmt.Fprintf(os.Stderr, \"[ocr] Session: %s (retry with: --resume %s)\\n\", id, id)\n\t\t}\n\t\treturn fmt.Errorf(\"scan failed: %w\", err)\n\t}\n\n\treturn emitRunResult(ctx, ag, comments, startTime, opts.outputFormat, opts.audience, q, llmIdentity, out, nil)\n}\n\nfunc loadScanResumeState(repoDir string, opts scanOptions, scanPaths []string) (*session.ResumeState, error) {\n\tif opts.resume == \"\" {\n\t\treturn nil, nil\n\t}\n\tstate, err := session.LoadResumeState(repoDir, opts.resume)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load resume session: %w (run 'ocr session list' to see available sessions)\", err)\n\t}\n\tif err := state.ValidateScanOptions(scanPaths); err != nil {\n\t\treturn nil, fmt.Errorf(\"%w (run 'ocr session list' to see available sessions)\", err)\n\t}\n\tif state.CompletedCount() == 0 {\n\t\treturn nil, fmt.Errorf(\"resume session %q has no completed scan items (run 'ocr session list' to see available sessions)\", opts.resume)\n\t}\n\treturn state, nil\n}\n\nfunc runScanPreview(cc *commonContext, scanTpl *template.ScanTemplate, scanPaths []string, outputFormat string, out io.Writer) error {\n\tpreview, err := scan.Preview(context.Background(), scan.Args{\n\t\tRepoDir:          cc.RepoDir,\n\t\tPaths:            scanPaths,\n\t\tFileFilter:       cc.FileFilter,\n\t\tGitRunner:        cc.GitRunner,\n\t\tMaxFileSizeBytes: scanTpl.MaxFileSizeBytes,\n\t\t// Template's prompt fields are unused by Preview; pass the same","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/scan_cmd.go#L237-L273","documentation":"`ocr scan --resume <id>` replays the stored session JSONL (~/.opencodereview/sessions/<encoded-repo>/<id>.jsonl) via session.LoadResumeState to build a checkpoint index. If the file cannot be opened (nonexistent session, wrong repo dir) or a record cannot be parsed (LoadResumeState is strict: unparseable lines fail the load, unlike the review variant), the CLI wraps it as \"load resume session: %w (run 'ocr session list' to see available sessions)\".","triggerScenarios":"Running `ocr scan --resume <id>` when the JSONL does not exist for this repo (typo'd id, different repository, cleaned ~/.opencodereview), or when the file contains a line that fails json.Unmarshal / is unknown to the parser (hand-edited or corrupted checkpoint).","commonSituations":"Resuming from another machine or after HOME changed; resuming a session created in a different repo directory; truncated/corrupted JSONL from a killed process mid-write; manually editing the session file.","solutions":["Run `ocr session list` in the same repo and copy the exact session id.","Confirm you are in the same repository directory the original scan ran from (sessions are keyed by repo path).","If the JSONL is corrupted, restore from backup or start a fresh scan instead of resuming.","Check ~/.opencodereview/sessions/<encoded-repo-path>/<id>.jsonl exists and every line is valid JSON (jq -c . file)."],"exampleFix":"// before\nocr scan --resume 3f9a\n// after\nocr session list          # find the full id\nocr scan --resume 3f9a1b2c-4d5e-6f70-...","handlingStrategy":"validation","validationCode":"id := opts.resume\npath := filepath.Join(home, \".opencodereview\", \"sessions\", encodeRepoPath(repoDir), id+\".jsonl\")\nif fi, err := os.Stat(path); err != nil || fi.Size() == 0 {\n    return fmt.Errorf(\"resume session %s not found in this repo; run 'ocr session list'\", id)\n}","typeGuard":"func resumeFileExists(repoDir, sessionID string) bool {\n    p, err := session.SessionFilePath(repoDir, sessionID)\n    if err != nil {\n        return false\n    }\n    fi, err := os.Stat(p)\n    return err == nil && !fi.IsDir() && fi.Size() > 0\n}","tryCatchPattern":"state, err := session.LoadResumeState(repoDir, opts.resume)\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        ids := mustListSessions(repoDir)\n        return fmt.Errorf(\"unknown session %q; did you mean one of %v?\", opts.resume, ids)\n    }\n    return err // corrupted line: surface, don't mask\n}","preventionTips":["Copy session ids from `ocr session list`, never retype them.","Resume from the same repository directory (store is keyed by repo path).","Don't hand-edit session JSONL files; a single invalid line fails the strict scan resume load.","Back up ~/.opencodereview/sessions before cleaning home directories."],"tags":["go","cli","session","resume"],"backgroundTag":"session-file-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}