diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index f7964162127b0..1c88cba3cd95e 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -515,10 +515,6 @@ impl Application {
             }
         };
 
-        if doc_save_event.serialize_error {
-            self.editor.set_error("failed to serialize history");
-        }
-
         let doc = match self.editor.document_mut(doc_save_event.doc_id) {
             None => {
                 warn!(
@@ -570,6 +566,9 @@ impl Application {
             lines,
             bytes
         ));
+        if doc_save_event.serialize_error {
+            self.editor.set_error("failed to serialize history");
+        }
     }
 
     #[inline(always)]
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index e114076e2f2ab..a1131dd5b0670 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -20,6 +20,7 @@ use std::path::{Path, PathBuf};
 use std::str::FromStr;
 use std::sync::Arc;
 use std::time::SystemTime;
+use tokio::fs::OpenOptions;
 
 use helix_core::{
     encoding,
@@ -591,7 +592,7 @@ impl Document {
             .load()
             .persistent_undo
             .then(|| self.history.get_mut().clone());
-        let undo_file = self.undo_file(Some(&path))?.unwrap();
+        let undofile_path = self.undo_file(Some(&path))?.unwrap();
         // We encode the file according to the `Document`'s encoding.
         let future = async move {
             use tokio::{fs, fs::File};
@@ -624,16 +625,17 @@ impl Document {
             if let Some(history) = history {
                 let res = {
                     let path = path.clone();
+                    let mut undofile = OpenOptions::new()
+                        .write(true)
+                        .read(true)
+                        .create(true)
+                        .open(&undofile_path)
+                        .await?
+                        .into_std()
+                        .await;
                     tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
-                        use std::fs;
-                        let append =
-                            History::read_header(&mut fs::File::open(&undo_file)?, &path).is_ok();
-                        let mut undo_file = std::fs::OpenOptions::new()
-                            .write(true)
-                            .truncate(!append)
-                            .read(true)
-                            .open(&undo_file)?;
-                        history.serialize(&mut undo_file, &path, current_rev, append)?;
+                        let append = undofile.metadata()?.len() != 0;
+                        history.serialize(&mut undofile, &path, current_rev, append)?;
                         Ok(())
                     })
                     .await
@@ -719,6 +721,7 @@ impl Document {
 
         // TODO: Handle error
         if self.load_history().is_err() {
+            panic!();
             // Calculate the difference between the buffer and source text, and apply it.
             // This is not considered a modification of the contents of the file regardless
             // of the encoding.
@@ -727,6 +730,7 @@ impl Document {
             self.append_changes_to_history(view);
             self.reset_modified();
         }
+        log::info!("{:#?}", self.history.get_mut());
         self.last_saved_time = SystemTime::now();
 
         self.detect_indent_and_line_ending();
@@ -767,7 +771,7 @@ impl Document {
                 if self.history.get_mut().is_empty() {
                     self.history.set(history);
                 } else {
-                    let offset = self.get_last_saved_revision();
+                    let offset = self.get_last_saved_revision() + 1;
                     self.history.get_mut().merge(history, offset)?;
                 }
                 self.set_last_saved_revision(last_saved_revision);