diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index a5f7f19b6b..458fe7db72 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -266,22 +266,28 @@ fn reduce_commit_entry( let action = action_wrapper.action(); let (entry, maybe_link_update_delete, provenances) = unwrap_to!(action => Action::Commit); - let result = create_new_chain_header( - &entry, - agent_state, - &StateWrapper::from(root_state.clone()), - &maybe_link_update_delete, - provenances, - ) - .and_then(|chain_header| { - agent_state.chain_store.add(entry)?; - agent_state.chain_store.add(&chain_header)?; - Ok((chain_header, entry.address())) - }) - .and_then(|(chain_header, address)| { - agent_state.top_chain_header = Some(chain_header); - Ok(address) - }); + // Only make a new header and link it if the entry isn't already in the chain + let entry_addres = entry.address(); + let result = match agent_state.chain_store().contains(&entry_addres) { + Ok(false) => create_new_chain_header( + &entry, + agent_state, + &StateWrapper::from(root_state.clone()), + &maybe_link_update_delete, + provenances, + ) + .and_then(|chain_header| { + agent_state.chain_store.add(entry)?; + agent_state.chain_store.add(&chain_header)?; + Ok(chain_header) + }) + .and_then(|chain_header| { + agent_state.top_chain_header = Some(chain_header); + Ok(entry_addres) + }), + Ok(true) => Ok(entry_addres), + Err(e) => Err(e), + }; agent_state.actions.insert( action_wrapper.clone(),