Index: wp-includes/js/autosave-js.php
===================================================================
--- wp-includes/js/autosave-js.php	(revision 4753)
+++ wp-includes/js/autosave-js.php	(working copy)
@@ -85,6 +85,7 @@
 	form.submit ? form.submit.disabled = 'disabled' : null;
 	form.publish ? form.publish.disabled = 'disabled' : null;
 	form.deletepost ? form.deletepost.disabled = 'disabled' : null;
+	setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later.  Just gives autosave a head start to avoid collisions.
 }
 
 function autosave_enable_buttons() {
Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php	(revision 4753)
+++ wp-includes/script-loader.php	(working copy)
@@ -19,7 +19,7 @@
 		$mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
 		$this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20061113' );
 		$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0');
-		$this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '4508');
+		$this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116');
 		$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '4459');
 		$this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4583');
 		$this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.6.1');
Index: wp-admin/admin-ajax.php
===================================================================
--- wp-admin/admin-ajax.php	(revision 4753)
+++ wp-admin/admin-ajax.php	(working copy)
@@ -220,7 +220,7 @@
 	) );
 	$x->send();
 	break;
-case 'autosave' :
+case 'autosave' : // The name of this action is hardcoded in edit_post()
 	$_POST['post_content'] = $_POST['content'];
 	$_POST['post_excerpt'] = $_POST['excerpt'];
 	$_POST['post_status'] = 'draft';
Index: wp-admin/admin-functions.php
===================================================================
--- wp-admin/admin-functions.php	(revision 4753)
+++ wp-admin/admin-functions.php	(working copy)
@@ -20,6 +20,25 @@
 			return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
 	}
 
+
+	// Check for autosave collisions
+	if ( isset($_POST['temp_ID']) ) {
+		$temp_id = (int) $_POST['temp_ID'];
+		if ( !$draft_ids = get_option( 'autosave_draft_ids' ) )
+			$draft_ids = array();
+		foreach ( $draft_ids as $temp => $real )
+			if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
+				unset($draft_ids[$temp]);
+
+		if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
+			$_POST['post_ID'] = $draft_ids[$temp_id];
+			unset($_POST['temp_ID']);
+			relocate_children( $temp_id, $_POST['post_ID'] );
+			update_option( 'autosave_draft_ids', $draft_ids );
+			return edit_post();
+		}
+	}
+
 	// Rename.
 	$_POST['post_content'] = $_POST['content'];
 	$_POST['post_excerpt'] = $_POST['excerpt'];
@@ -88,12 +107,17 @@
 	}
 
 	// Create the post.
-	$post_ID = wp_insert_post( $_POST);
+	$post_ID = wp_insert_post( $_POST );
+
 	add_meta( $post_ID );
 
 	// Reunite any orphaned attachments with their parent
-	if ( $_POST['temp_ID'] )
+	// Update autosave collision detection
+	if ( $_POST['temp_ID'] ) {
 		relocate_children( $_POST['temp_ID'], $post_ID );
+		$draft_ids[$temp_id] = $post_ID;
+		update_option( 'autosave_draft_ids', $draft_ids );
+	}
 
 	// Now that we have an ID we can fix any attachment anchor hrefs
 	fix_attachment_links( $post_ID );
@@ -165,6 +189,16 @@
 			wp_die( __('You are not allowed to edit this post.' ));
 	}
 
+	// Autosave shouldn't save too soon after a real save
+	if ( 'autosave' == $_POST['action'] ) {
+		$post =& get_post( $post_ID );
+		$now = time();
+		$then = strtotime($post->post_date_gmt . ' +0000');
+		$delta = apply_filters( 'autosave_interval', 120 ) / 2;
+		if ( $now - $then < $delta )
+			return $post_ID;
+	}
+
 	// Rename.
 	$_POST['ID'] = (int) $_POST['post_ID'];
 	$_POST['post_content'] = $_POST['content'];
Index: wp-admin/edit-page-form.php
===================================================================
--- wp-admin/edit-page-form.php	(revision 4753)
+++ wp-admin/edit-page-form.php	(working copy)
@@ -5,7 +5,7 @@
 if (0 == $post_ID) {
 	$form_action = 'post';
 	$nonce_action = 'add-page';
-	$temp_ID = -1 * time();
+	$temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
 	$form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
 } else {
 	$form_action = 'editpost';
Index: wp-admin/edit-form-advanced.php
===================================================================
--- wp-admin/edit-form-advanced.php	(revision 4753)
+++ wp-admin/edit-form-advanced.php	(working copy)
@@ -17,7 +17,7 @@
 
 if (0 == $post_ID) {
 	$form_action = 'post';
-	$temp_ID = -1 * time();
+	$temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
 	$form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
 	wp_nonce_field('add-post');
 } else {
