From eafa229542a62b8b029f164b304928fafdaa3691 Mon Sep 17 00:00:00 2001 From: Finn Sheng Date: Sun, 8 Feb 2026 17:54:22 -0500 Subject: [PATCH] feat: now it has more timeout and better log (#6) --- src/instance.rs | 36 ++++++++++++++++++++++++++---------- src/vm.rs | 7 ------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 7f521f2..eae80bd 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -68,7 +68,7 @@ pub fn run_with_ssh(manager_conn: UnixStream) -> Result<(), Box Result<(), Box> { let start = Instant::now(); let mut next_log_at = start + Duration::from_secs(10); + let mut next_status_check = start; tracing::info!("waiting for vm ipv4"); let status_path = instance_dir.join(STATUS_FILE_NAME); let mut last_status: Option = None; + let mut status_missing = true; let mut once_hint = false; loop { let config = load_or_create_instance_config(instance_dir)?; if config.vm_ipv4.is_some() { + let _ = fs::remove_file(&status_path); return Ok(()); } if start.elapsed() > timeout { + let _ = fs::remove_file(&status_path); return Err("Timed out waiting for VM IPv4".into()); } - if Instant::now() >= next_log_at { + let now = Instant::now(); + if now >= next_status_check { + match fs::read_to_string(&status_path) { + Ok(status) => { + status_missing = false; + let status = status.trim().to_string(); + if !status.is_empty() && last_status.as_deref() != Some(status.as_str()) { + tracing::info!("[background]: {}", status); + last_status = Some(status); + next_log_at = now + Duration::from_secs(20); + } + } + Err(_) => { + status_missing = true; + } + } + next_status_check = now + Duration::from_millis(500); + } + if now >= next_log_at { let waited = start.elapsed(); if waited.as_secs() > 15 && !once_hint { tracing::info!( @@ -262,16 +284,10 @@ fn wait_for_vm_ipv4( ); once_hint = true; } - if let Ok(status) = fs::read_to_string(&status_path) { - let status = status.trim().to_string(); - if !status.is_empty() && last_status.as_deref() != Some(status.as_str()) { - tracing::info!("[background]: {}", status); - last_status = Some(status); - } - } else { + if status_missing { tracing::info!("still waiting for vm ipv4, {}s elapsed", waited.as_secs(),); } - next_log_at += Duration::from_secs(10); + next_log_at += Duration::from_secs(20); } thread::sleep(Duration::from_millis(200)); } diff --git a/src/vm.rs b/src/vm.rs index 21d5324..17c5716 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -57,12 +57,6 @@ impl StatusFile { fn update(&self, message: &str) { let _ = fs::write(&self.path, message); } - - fn clear(&self) { - if !self.cleared.swap(true, Ordering::SeqCst) { - let _ = fs::remove_file(&self.path); - } - } } impl Drop for StatusFile { @@ -1119,7 +1113,6 @@ where if let Some(status) = status { status.update("vm booting... go vibecoder!"); - status.clear(); } tracing::info!("vm booting");