Replay copied history when forking ACP sessions

Co-Authored-By: siGit Code <noreply@sigit.si>

Seto Elkahfi committed Sep 17, 2026 at 08:14 UTC 9c65e610210f9a57f0958f9d18c6d69a6c001f24
1 file changed +29
src/main.rs
+29
@@ -1778,9 +1778,19 @@ impl SiGitAgent {
1778 session_store::load(&args.session_id.to_string()).map(backend::carryover_history)
1779 })
1780 .unwrap_or_default();
1781 + let copied = source.len();
1782 + let updates = history_replay_updates(&source);
1783 + let replayed = updates.len();
1784 + for update in updates {
1785 + cx.send_notification(SessionNotification::new(new_id.clone(), update))
1786 + .ok();
1787 + }
1788 let mut state = Self::session_state(&args.cwd, &args.additional_directories);
1789 state.conversation = source;
1790 self.open_session(&new_id, state).await;
1791 + log::info!(
1792 + "fork_session: copied {copied} message(s), replayed {replayed} update(s) for {new_id}"
1793 + );
1794
1795 let config_options = {
1796 let guard = self.current_model.lock().unwrap();
@@ -4690,6 +4700,25 @@ mod tests {
4700 assert!(matches!(updates[3], SessionUpdate::AgentMessageChunk(_)));
4701 }
4702
4703 + #[test]
4704 + fn history_replay_redraws_a_forked_conversation_without_system_context() {
4705 + let source = backend::carryover_history(vec![
4706 + serde_json::json!({ "role": "system", "content": "source project context" }),
4707 + serde_json::json!({ "role": "user", "content": "continue this thread" }),
4708 + serde_json::json!({ "role": "assistant", "content": "Ready to continue." }),
4709 + ]);
4710 +
4711 + let updates = history_replay_updates(&source);
4712 +
4713 + assert_eq!(updates.len(), 2, "{updates:#?}");
4714 + assert!(matches!(updates[0], SessionUpdate::UserMessageChunk(_)));
4715 + assert!(matches!(updates[1], SessionUpdate::AgentMessageChunk(_)));
4716 + assert!(
4717 + !format!("{updates:#?}").contains("source project context"),
4718 + "fork replay must not expose backend-only system context"
4719 + );
4720 + }
4721 +
4722 #[test]
4723 fn history_replay_renders_write_todos_as_a_plan() {
4724 let history = vec![serde_json::json!({