@@ -607,44 +607,55 @@ impl ChatSession {
607607 mcp_enabled : bool ,
608608 wrap : Option < WrapMode > ,
609609 ) -> Result < Self > {
610- // Reload prior conversation
610+ // Only load prior conversation if we need to resume
611611 let mut existing_conversation = false ;
612- let previous_conversation = std:: env:: current_dir ( )
613- . ok ( )
614- . and_then ( |cwd| os. database . get_conversation_by_path ( cwd) . ok ( ) )
615- . flatten ( ) ;
616-
617- // Only restore conversations where there were actual messages.
618- // Prevents edge case where user clears conversation then exits without chatting.
619- let conversation = match resume_conversation
620- && previous_conversation
621- . as_ref ( )
622- . is_some_and ( |cs| !cs. history ( ) . is_empty ( ) )
623- {
612+ let conversation = match resume_conversation {
624613 true => {
625- let mut cs = previous_conversation. unwrap ( ) ;
626- existing_conversation = true ;
627- input = Some ( input. unwrap_or ( "In a few words, summarize our conversation so far." . to_owned ( ) ) ) ;
628- cs. tool_manager = tool_manager;
629- if let Some ( profile) = cs. current_profile ( ) {
630- if agents. switch ( profile) . is_err ( ) {
631- execute ! (
632- stderr,
633- StyledText :: error_fg( ) ,
634- style:: Print ( "Error" ) ,
635- StyledText :: reset( ) ,
636- style:: Print ( format!(
637- ": cannot resume conversation with {profile} because it no longer exists. Using default.\n "
638- ) )
639- ) ?;
640- let _ = agents. switch ( DEFAULT_AGENT_NAME ) ;
641- }
614+ let previous_conversation = std:: env:: current_dir ( )
615+ . ok ( )
616+ . and_then ( |cwd| os. database . get_conversation_by_path ( cwd) . ok ( ) )
617+ . flatten ( ) ;
618+
619+ // Only restore conversations where there were actual messages
620+ // Prevents edge case where user clears conversation then exits without chatting.
621+ match previous_conversation. filter ( |cs| !cs. history ( ) . is_empty ( ) ) {
622+ Some ( mut cs) => {
623+ existing_conversation = true ;
624+ input = Some ( input. unwrap_or ( "In a few words, summarize our conversation so far." . to_owned ( ) ) ) ;
625+ cs. tool_manager = tool_manager;
626+ if let Some ( profile) = cs. current_profile ( ) {
627+ if agents. switch ( profile) . is_err ( ) {
628+ execute ! (
629+ stderr,
630+ StyledText :: error_fg( ) ,
631+ style:: Print ( "Error" ) ,
632+ StyledText :: reset( ) ,
633+ style:: Print ( format!(
634+ ": cannot resume conversation with {profile} because it no longer exists. Using default.\n "
635+ ) )
636+ ) ?;
637+ let _ = agents. switch ( DEFAULT_AGENT_NAME ) ;
638+ }
639+ }
640+ cs. agents = agents;
641+ cs. mcp_enabled = mcp_enabled;
642+ cs. update_state ( true ) . await ;
643+ cs. enforce_tool_use_history_invariants ( ) ;
644+ cs
645+ } ,
646+ None => {
647+ ConversationState :: new (
648+ conversation_id,
649+ agents,
650+ tool_config,
651+ tool_manager,
652+ model_id,
653+ os,
654+ mcp_enabled,
655+ )
656+ . await
657+ } ,
642658 }
643- cs. agents = agents;
644- cs. mcp_enabled = mcp_enabled;
645- cs. update_state ( true ) . await ;
646- cs. enforce_tool_use_history_invariants ( ) ;
647- cs
648659 } ,
649660 false => {
650661 ConversationState :: new (
0 commit comments