@@ -170,21 +170,20 @@ fn ensure_pid_file(project_root: &Path) -> Result<PidFileGuard, Box<dyn std::err
170170 let instance_dir = ensure_instance_dir(project_root)?;
171171 let pid_path = instance_dir.join(VM_MANAGER_PID_NAME);
172172 let socket_path = instance_dir.join(VM_MANAGER_SOCKET_NAME);
173− if let Ok(content) = fs::read_to_string(&pid_path) {
174− if let Ok(pid) = content.trim().parse::<u32>() {
175− if pid_is_alive(pid) {
176− if is_socket_path(&socket_path) {
177− return Err(format!("vm manager already running (pid {pid})").into());
178− }
179− tracing::warn!(
180− pid,
181− path = %socket_path.display(),
182− "stale pid file detected with missing socket"
183− );
184− }
173+ if let Ok(content) = fs::read_to_string(&pid_path)
174+ && let Ok(pid) = content.trim().parse::<u32>()
175+ && pid_is_alive(pid)
176+ {
177+ if is_socket_path(&socket_path) {
178+ return Err(format!("vm manager already running (pid {pid})").into());
185179 }
186− let _ = fs::remove_file(&pid_path);
180+ tracing::warn!(
181+ pid,
182+ path = %socket_path.display(),
183+ "stale pid file detected with missing socket"
184+ );
187185 }
186+ let _ = fs::remove_file(&pid_path);
188187 fs::write(&pid_path, format!("{}\n", std::process::id()))?;
189188 let _ = fs::set_permissions(&pid_path, fs::Permissions::from_mode(0o600));
190189 Ok(PidFileGuard { path: pid_path })
@@ -192,12 +191,11 @@ fn ensure_pid_file(project_root: &Path) -> Result<PidFileGuard, Box<dyn std::err
192191
193192fn cleanup_stale_manager(instance_dir: &Path) {
194193 let pid_path = instance_dir.join(VM_MANAGER_PID_NAME);
195− if let Ok(content) = fs::read_to_string(&pid_path) {
196− if let Ok(pid) = content.trim().parse::<u32>() {
197− if pid_is_alive(pid) {
198− return;
199− }
200− }
194+ if let Ok(content) = fs::read_to_string(&pid_path)
195+ && let Ok(pid) = content.trim().parse::<u32>()
196+ && pid_is_alive(pid)
197+ {
198+ return;
201199 }
202200 let _ = fs::remove_file(&pid_path);
203201}
@@ -423,7 +421,7 @@ fn read_client_pid(stream: &UnixStream) -> Option<u32> {
423421 Ok(0) => break,
424422 Ok(n) => {
425423 len += n;
426− if buf[..len].iter().any(|b| *b == b'\n') || len == buf.len() {
424+ if buf[..len].contains(&b'\n') || len == buf.len() {
427425 break;
428426 }
429427 }
@@ -467,10 +465,10 @@ fn spawn_manager_io(
467465 let mut line_buf = String::new();
468466
469467 let on_output = move |bytes: &[u8]| {
470− if let Some(log) = &log_for_output {
471− if let Ok(mut file) = log.lock() {
472− let _ = file.write_all(bytes);
473− }
468+ if let Some(log) = &log_for_output
469+ && let Ok(mut file) = log.lock()
470+ {
471+ let _ = file.write_all(bytes);
474472 }
475473
476474 let text = String::from_utf8_lossy(bytes);
@@ -483,17 +481,16 @@ fn spawn_manager_io(
483481 }
484482 line_buf.drain(..=pos);
485483
486− let cleaned = line.trim_start_matches(|c: char| c == '\r' || c == ' ');
484+ let cleaned = line.trim_start_matches(['\r', ' ']);
487485 if let Some(pos) = cleaned.find("VIBEBOX_IPV4=") {
488486 let ip_raw = &cleaned[(pos + "VIBEBOX_IPV4=".len())..];
489487 let ip = extract_ipv4(ip_raw).unwrap_or_default();
490− if !ip.is_empty() {
491− if let Ok(mut cfg) = config_for_output.lock() {
492− if cfg.vm_ipv4.as_deref() != Some(ip.as_str()) {
493− cfg.vm_ipv4 = Some(ip.clone());
494− let _ = write_instance_config(&instance_path, &cfg);
495− }
496− }
488+ if !ip.is_empty()
489+ && let Ok(mut cfg) = config_for_output.lock()
490+ && cfg.vm_ipv4.as_deref() != Some(ip.as_str())
491+ {
492+ cfg.vm_ipv4 = Some(ip.clone());
493+ let _ = write_instance_config(&instance_path, &cfg);
497494 }
498495 }
499496 }
@@ -583,7 +580,7 @@ impl VmExecutor for RealVmExecutor {
583580 instance_dir: PathBuf,
584581 vm_input_tx: Arc<Mutex<Option<mpsc::Sender<VmInput>>>>,
585582 ) -> Result<(), Box<dyn std::error::Error>> {
586− let result = vm::run_with_args_and_extras(
583+ vm::run_with_args_and_extras(
587584 args,
588585 |output_monitor, vm_output_fd, vm_input_fd| {
589586 let io_ctx = spawn_manager_io(
@@ -598,8 +595,7 @@ impl VmExecutor for RealVmExecutor {
598595 },
599596 extra_login_actions,
600597 extra_shares,
601− );
602− result
598+ )
603599 }
604600}
605601
@@ -755,9 +751,7 @@ fn manager_event_loop(
755751 shutdown_sent = false;
756752 }
757753 Ok(ManagerEvent::Dec(pid)) => {
758− if ref_count > 0 {
759− ref_count -= 1;
760− }
754+ ref_count = ref_count.saturating_sub(1);
761755 tracing::info!(
762756 ref_count,
763757 pid = pid.unwrap_or(0),
@@ -776,15 +770,16 @@ fn manager_event_loop(
776770 break;
777771 }
778772 Err(mpsc::RecvTimeoutError::Timeout) => {
779− if let Some(deadline) = shutdown_deadline {
780− if Instant::now() >= deadline && !shutdown_sent {
781− if let Some(tx) = vm_input_tx.lock().unwrap().clone() {
782− let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
783− }
784− tracing::info!("shutdown command sent");
785− shutdown_sent = true;
786− shutdown_deadline = None;
773+ if let Some(deadline) = shutdown_deadline
774+ && Instant::now() >= deadline
775+ && !shutdown_sent
776+ {
777+ if let Some(tx) = vm_input_tx.lock().unwrap().clone() {
778+ let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
787779 }
780+ tracing::info!("shutdown command sent");
781+ shutdown_sent = true;
782+ shutdown_deadline = None;
788783 }
789784 }
790785 Err(mpsc::RecvTimeoutError::Disconnected) => break,