{"record":{"id":"f80e68470d75975d","repo":"alibaba/open-code-review","slug":"open-session-file-w","errorCode":null,"errorMessage":"open session file: %w","messagePattern":"open session file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/session/persist.go","lineNumber":117,"sourceCode":"\t}\n\treturn result\n}\n\nfunc (jw *jsonlWriter) open() error {\n\thome, err := os.UserHomeDir()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"resolve home dir: %w\", err)\n\t}\n\n\tsessionDir := filepath.Join(home, \".opencodereview\", sessionSubDir, encodeRepoPath(jw.repoDir))\n\tif err := os.MkdirAll(sessionDir, 0700); err != nil {\n\t\treturn fmt.Errorf(\"create session dir: %w\", err)\n\t}\n\n\tfilename := filepath.Join(sessionDir, jw.sessionID+\".jsonl\")\n\tf, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open session file: %w\", err)\n\t}\n\n\tjw.file = f\n\tjw.writer = bufio.NewWriter(f)\n\treturn nil\n}\n\nfunc (jw *jsonlWriter) writeRecordLocked(rec map[string]any) {\n\tdata, err := json.Marshal(rec)\n\tif err != nil {\n\t\tfmt.Printf(\"[ocr session] failed to marshal record: %v\\n\", err)\n\t\treturn\n\t}\n\tjw.writer.Write(data)\n\tjw.writer.WriteByte('\\n')\n}\n\n// WriteSessionStart writes the initial session_start record.","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/session/persist.go#L99-L135","documentation":"Thrown when os.OpenFile cannot create/open the session JSONL file <sessionDir>/<sessionID>.jsonl with flags O_CREATE|O_WRONLY|O_TRUNC and mode 0600. The session directory was created successfully but the file itself could not be opened, so session persistence cannot start.","triggerScenarios":"newJSONLWriter -> open() after MkdirAll succeeds: os.OpenFile on <sessionID>.jsonl fails due to disk full, path too long, or another component becoming unwritable between mkdir and open.","commonSituations":"Disk quota exceeded while writing to $HOME; sessionID containing pathological characters creating an overly long filename; filesystem turned read-only (remounted) mid-run; antivirus/EDR blocking new files in $HOME.","solutions":["Free disk space / check quota on the volume holding $HOME (df -h ~; quota -s)","Inspect the wrapped PathError for the exact path; verify parent dir is still writable","Check that sessionID is a sane short identifier (no path separators, reasonable length)","If the volume is read-only, point HOME at a writable location"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"home, _ := os.UserHomeDir()\nsessionDir := filepath.Join(home, \".opencodereview\")\nif fi, err := os.Stat(sessionDir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"session dir not usable: %s\", sessionDir)\n}\nif unix.Statfs(sessionDir) reports full, fail early // or check df output externally","typeGuard":null,"tryCatchPattern":"if err := runOCR(); err != nil {\n    if strings.Contains(err.Error(), \"open session file\") {\n        var pe *fs.PathError\n        if errors.As(err, &pe) {\n            log.Fatalf(\"cannot open %s: %v\", pe.Path, pe.Err)\n        }\n    }\n}","preventionTips":["Keep session IDs short and free of path separators","Ensure free disk space on $HOME's filesystem","Do not mount $HOME read-only for the tool's user"],"tags":["filesystem","permissions","file-open"],"backgroundTag":"file-open-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}