{"record":{"id":"673846a1e87b6f8c","repo":"alibaba/open-code-review","slug":"flush-session-end-w","errorCode":null,"errorMessage":"flush session_end: %w","messagePattern":"flush session_end: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/session/persist.go","lineNumber":409,"sourceCode":"\tdata, err := json.Marshal(rec)\n\tif err != nil {\n\t\tif jw.writer != nil {\n\t\t\tjw.writer.Flush()\n\t\t}\n\t\tif jw.file != nil {\n\t\t\tjw.file.Close()\n\t\t}\n\t\treturn fmt.Errorf(\"marshal session_end: %w\", err)\n\t}\n\n\tvar writeErr error\n\tif jw.writer != nil {\n\t\tif _, err := jw.writer.Write(data); err != nil {\n\t\t\twriteErr = fmt.Errorf(\"write session_end: %w\", err)\n\t\t} else if err := jw.writer.WriteByte('\\n'); err != nil {\n\t\t\twriteErr = fmt.Errorf(\"write session_end: %w\", err)\n\t\t} else if err := jw.writer.Flush(); err != nil {\n\t\t\twriteErr = fmt.Errorf(\"flush session_end: %w\", err)\n\t\t}\n\t}\n\tif jw.file != nil {\n\t\tif err := jw.file.Close(); err != nil && writeErr == nil {\n\t\t\twriteErr = fmt.Errorf(\"close session file: %w\", err)\n\t\t}\n\t}\n\treturn writeErr\n}\n\nfunc (jw *jsonlWriter) flushAndClose() {\n\tjw.mu.Lock()\n\tdefer jw.mu.Unlock()\n\tif jw.writer != nil {\n\t\tjw.writer.Flush()\n\t}\n\tif jw.file != nil {\n\t\tjw.file.Close()","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/session/persist.go#L391-L427","documentation":"Raised when jw.writer.Flush() fails while finalizing the session_end record. The record body and newline were accepted into the buffer, but pushing the buffered bytes to the underlying file failed, so the session_end line may be partially written or missing on disk.","triggerScenarios":"WriteSessionEnd: after successful Write(data) and WriteByte('\\n'), bufio.Writer.Flush() returns the error stored by the underlying write to the file (commonly ENOSPC or EIO).","commonSituations":"Disk quota/space exhausted at flush time; filesystem I/O error (failing disk, network mount dropped); the file was closed underneath the buffered writer.","solutions":["Free disk space / resolve the underlying I/O condition reported by the wrapped error","Check dmesg/mount health if on NFS or flaky storage; move ~/.opencodereview to local disk","Inspect the tail of the session JSONL: a partial session_end line means the session was not finalized cleanly and replay (LoadResumeState) will fail parsing","Re-run the review to produce a complete session file"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := writer.WriteSessionEnd(); err != nil {\n    if strings.Contains(err.Error(), \"flush session_end\") {\n        if errors.Is(err, syscall.ENOSPC) {\n            log.Fatal(\"disk full at flush time\")\n        }\n        // verify session file integrity before resuming from it\n        if _, err := session.LoadResumeState(repoDir, sessionID); err != nil {\n            log.Printf(\"session file corrupt, starting fresh: %v\", err)\n        }\n    }\n}","preventionTips":["Keep sessions on reliable local storage rather than NFS","Validate the JSONL with LoadResumeState before relying on it after an error","Free disk headroom before long-running reviews"],"tags":["filesystem","io","buffered-writer"],"backgroundTag":"flush-failed-io-error","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}