[PR #14713] readline: check errors from Flush and Close in history Save #14805

Open
opened 2026-04-13 01:02:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14713
Author: @alvinttang
Created: 3/8/2026
Status: 🔄 Open

Base: mainHead: fix/history-save-flush-error


📝 Commits (1)

  • 3b61a98 readline: check errors from Flush and Close in history Save

📊 Changes

1 file changed (+11 additions, -3 deletions)

View changed files

📝 readline/history.go (+11 -3)

📄 Description

What

Check errors from bufio.Writer.Flush(), fmt.Fprintln(), and os.File.Close() in History.Save().

Why

Currently Save() ignores errors from buf.Flush() (line 143) and f.Close() (line 144). If writing fails (disk full, I/O error), the buffered data is silently lost and the incomplete/empty temp file is renamed over the existing history file, corrupting or destroying the user's command history.

The f.Close() error is also important because on some filesystems (e.g., NFS), Close() can return write errors that were deferred from earlier Write() calls.

Change

  • Check the error from fmt.Fprintln() during each line write
  • Check the error from buf.Flush() before closing the file
  • Check the error from f.Close() before renaming
  • On any error, return early without renaming the temp file over the history

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14713 **Author:** [@alvinttang](https://github.com/alvinttang) **Created:** 3/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/history-save-flush-error` --- ### 📝 Commits (1) - [`3b61a98`](https://github.com/ollama/ollama/commit/3b61a98d7fc586aaa5afaeca1df9f07a9264f5d4) readline: check errors from Flush and Close in history Save ### 📊 Changes **1 file changed** (+11 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `readline/history.go` (+11 -3) </details> ### 📄 Description ## What Check errors from `bufio.Writer.Flush()`, `fmt.Fprintln()`, and `os.File.Close()` in `History.Save()`. ## Why Currently `Save()` ignores errors from `buf.Flush()` (line 143) and `f.Close()` (line 144). If writing fails (disk full, I/O error), the buffered data is silently lost and the incomplete/empty temp file is renamed over the existing history file, corrupting or destroying the user's command history. The `f.Close()` error is also important because on some filesystems (e.g., NFS), `Close()` can return write errors that were deferred from earlier `Write()` calls. ## Change - Check the error from `fmt.Fprintln()` during each line write - Check the error from `buf.Flush()` before closing the file - Check the error from `f.Close()` before renaming - On any error, return early without renaming the temp file over the history --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 01:02:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14805