@@ -272,11 +272,11 @@ impl BridgeShared {
272272 sessions. get_session_thread ( & session_id)
273273 } ;
274274
275- if thread_id . is_some ( ) {
275+ if let Some ( tid ) = thread_id {
276276 self . session_threads
277277 . write ( )
278278 . await
279- . insert ( session_id. clone ( ) , thread_id . unwrap ( ) as i32 ) ;
279+ . insert ( session_id. clone ( ) , tid as i32 ) ;
280280 } else if self . config . use_threads {
281281 let topic_name = format_topic_name (
282282 & session_id,
@@ -326,7 +326,7 @@ impl BridgeShared {
326326 } ;
327327
328328 if let Some ( session) = session {
329- let duration = ( chrono:: Utc :: now ( ) - session. started_at ) . num_milliseconds ( ) as u64 ;
329+ let duration = ( chrono:: Utc :: now ( ) - session. started_at ) . num_milliseconds ( ) . max ( 0 ) as u64 ;
330330 let thread_id = self . get_session_thread_id ( & msg. session_id ) . await ;
331331
332332 let _ = self
@@ -702,24 +702,29 @@ impl BridgeShared {
702702 None => return , // Unknown topic, ignore (multi-bot)
703703 } ;
704704
705- // Restore tmux target
706- let mut inj = self . injector . lock ( ) . await ;
705+ // Resolve tmux target BEFORE acquiring injector lock (prevent deadlock)
707706 let tmux_target = self . session_tmux_targets . read ( ) . await . get ( & session. id ) . cloned ( ) ;
708- if let Some ( target) = & tmux_target {
709- inj . set_target ( target, session. tmux_socket . as_deref ( ) ) ;
707+ let ( resolved_target , resolved_socket ) = if let Some ( target) = tmux_target {
708+ ( Some ( target) , session. tmux_socket . clone ( ) )
710709 } else {
711710 // Restore from database
712711 let ( db_target, db_socket) = {
713712 let sessions = self . sessions . lock ( ) . await ;
714713 sessions. get_tmux_info ( & session. id )
715714 } ;
716715 if let Some ( target) = & db_target {
717- inj. set_target ( target, db_socket. as_deref ( ) ) ;
718716 self . session_tmux_targets
719717 . write ( )
720718 . await
721719 . insert ( session. id . clone ( ) , target. clone ( ) ) ;
722720 }
721+ ( db_target, db_socket)
722+ } ;
723+
724+ // Now acquire injector lock with no other locks held
725+ let mut inj = self . injector . lock ( ) . await ;
726+ if let Some ( target) = & resolved_target {
727+ inj. set_target ( target, resolved_socket. as_deref ( ) ) ;
723728 }
724729
725730 // Check for cc command prefix
@@ -1064,11 +1069,11 @@ fn format_topic_name(session_id: &str, hostname: Option<&str>, project_dir: Opti
10641069 . chars ( )
10651070 . take ( 8 )
10661071 . collect :: < String > ( ) ;
1067- parts. push ( short_id. clone ( ) ) ;
10681072
10691073 if parts. is_empty ( ) {
10701074 format ! ( "Session {}" , short_id)
10711075 } else {
1076+ parts. push ( short_id) ;
10721077 parts. join ( " \u{2022} " )
10731078 }
10741079}
0 commit comments