@@ -26,7 +26,7 @@ use crate::{
28const SSH_KEY_NAME: &str = "ssh_key";
28const SSH_KEY_NAME: &str = "ssh_key";
29−pub(crate) const SERIAL_LOG_NAME: &str = "serial.log";
29+pub(crate) const VM_ROOT_LOG_NAME: &str = "vm_root.log";
30pub(crate) const DEFAULT_SSH_USER: &str = "vibecoder";
30pub(crate) const DEFAULT_SSH_USER: &str = "vibecoder";
31const SSH_CONNECT_RETRIES: usize = 30;
31const SSH_CONNECT_RETRIES: usize = 30;
32const SSH_CONNECT_DELAY_MS: u64 = 500;
32const SSH_CONNECT_DELAY_MS: u64 = 500;
@@ -118,7 +118,7 @@ pub(crate) fn ensure_ssh_keypair(
118 "vibebox",
118 "vibebox",
120 .stdin(Stdio::null())
120 .stdin(Stdio::null())
121− .stdout(Stdio::null())
121+ .stdout(Stdio::inherit())
122 .stderr(Stdio::inherit())
122 .stderr(Stdio::inherit())
123 .status()?;
123 .status()?;
@@ -246,6 +246,8 @@ fn wait_for_vm_ipv4(
246 timeout: Duration,
246 timeout: Duration,
247) -> Result<(), Box<dyn std::error::Error>> {
247) -> Result<(), Box<dyn std::error::Error>> {
248 let start = Instant::now();
248 let start = Instant::now();
249+ let mut next_log_at = start + Duration::from_secs(10);
250+ tracing::debug!("waiting for vm ipv4");
250 let config = load_or_create_instance_config(instance_dir)?;
252 let config = load_or_create_instance_config(instance_dir)?;
251 if config.vm_ipv4.is_some() {
253 if config.vm_ipv4.is_some() {
@@ -254,8 +256,10 @@ fn wait_for_vm_ipv4(
254 if start.elapsed() > timeout {
256 if start.elapsed() > timeout {
255 return Err("Timed out waiting for VM IPv4".into());
257 return Err("Timed out waiting for VM IPv4".into());
259+ if Instant::now() >= next_log_at {
257− if start.elapsed().as_secs() % 5 == 0 {
260+ let waited = start.elapsed();
258− tracing::debug!("still waiting for vm ipv4");
261+ tracing::debug!("still waiting for vm ipv4, {}s elapsed", waited.as_secs(),);
262+ next_log_at += Duration::from_secs(10);
260 thread::sleep(Duration::from_millis(200));
264 thread::sleep(Duration::from_millis(200));
@@ -270,9 +274,13 @@ fn run_ssh_session(
271 attempts += 1;
275 attempts += 1;
272 if !ssh_port_open(&ip) {
276 if !ssh_port_open(&ip) {
273− tracing::debug!(attempts, "ssh port not open yet");
277+ tracing::debug!(attempts, "ssh port doesn't open yet");
274− eprintln!(
278+ tracing::info!(
281+ "waiting for ssh port ({}/{})",
275− "[vibebox] waiting for ssh port on {ip} (attempt {attempts}/{SSH_CONNECT_RETRIES})"
283+ SSH_CONNECT_RETRIES
277 if attempts >= SSH_CONNECT_RETRIES {
285 if attempts >= SSH_CONNECT_RETRIES {
278 return Err(
286 return Err(
@@ -283,10 +291,14 @@ fn run_ssh_session(
283 continue;
291 continue;
286− eprintln!(
294+ tracing::info!(
298+ "starting ssh ({}/{})",
287− "[vibebox] starting ssh to {ssh_user}@{ip} (attempt {attempts}/{SSH_CONNECT_RETRIES})"
300+ SSH_CONNECT_RETRIES
289− tracing::info!(attempts, user = %ssh_user, ip = %ip, "starting ssh");
290 let status = Command::new("ssh")
302 let status = Command::new("ssh")
@@ -319,21 +331,22 @@ fn run_ssh_session(
320 match status {
332 match status {
321 Ok(status) if status.success() => {
333 Ok(status) if status.success() => {
322− eprintln!("[vibebox] ssh exited with status: {status}");
334+ tracing::info!(status = %status, "ssh exited");
325 Ok(status) if status.code() == Some(255) => {
337 Ok(status) if status.code() == Some(255) => {
326− eprintln!("[vibebox] ssh connection failed: {status}");
338+ tracing::warn!(status = %status, "ssh connection failed");
327 if attempts >= SSH_CONNECT_RETRIES {
339 if attempts >= SSH_CONNECT_RETRIES {
328 return Err(format!("ssh failed after {SSH_CONNECT_RETRIES} attempts").into());
340 return Err(format!("ssh failed after {SSH_CONNECT_RETRIES} attempts").into());
330 thread::sleep(Duration::from_millis(500));
342 thread::sleep(Duration::from_millis(500));
332 Ok(status) => {
344 Ok(status) => {
333− eprintln!("[vibebox] ssh exited with status: {status}");
345+ tracing::info!(status = %status, "ssh exited");
336 Err(err) => {
348 Err(err) => {
349+ tracing::error!(error = %err, "failed to start ssh");
337 return Err(format!("failed to start ssh: {err}").into());
350 return Err(format!("failed to start ssh: {err}").into());
@@ -404,7 +417,7 @@ fn spawn_ssh_io(
404) -> vm::IoContext {
417) -> vm::IoContext {
405 let io_control = vm::IoControl::new();
418 let io_control = vm::IoControl::new();
407− let log_path = instance_dir.join(SERIAL_LOG_NAME);
420+ let log_path = instance_dir.join(VM_ROOT_LOG_NAME);
408 let log_file = fs::OpenOptions::new()
421 let log_file = fs::OpenOptions::new()
409 .create(true)
422 .create(true)
410 .write(true)
423 .write(true)
@@ -458,7 +471,7 @@ fn spawn_ssh_io(
458 if cfg.vm_ipv4.as_deref() != Some(ip.as_str()) {
471 if cfg.vm_ipv4.as_deref() != Some(ip.as_str()) {
459 cfg.vm_ipv4 = Some(ip.clone());
472 cfg.vm_ipv4 = Some(ip.clone());
460 let _ = write_instance_config(&instance_path, &cfg);
473 let _ = write_instance_config(&instance_path, &cfg);
461− eprintln!("[vibebox] detected vm IPv4: {ip}");
474+ tracing::info!(ip = %ip, "detected vm ipv4");
@@ -466,7 +479,7 @@ fn spawn_ssh_io(
467 if cleaned.contains("VIBEBOX_SSH_READY") {
480 if cleaned.contains("VIBEBOX_SSH_READY") {
468 ssh_ready_for_output.store(true, Ordering::SeqCst);
481 ssh_ready_for_output.store(true, Ordering::SeqCst);
469− eprintln!("[vibebox] sshd ready");
482+ tracing::info!("sshd ready");
@@ -517,7 +530,7 @@ fn spawn_ssh_io(
520− eprintln!("[vibebox] starting ssh to {ssh_user}@{ip}");
533+ tracing::info!(user = %ssh_user, ip = %ip, "starting ssh");
521 io_control_for_thread.request_terminal_restore();
534 io_control_for_thread.request_terminal_restore();
522 io_control_for_thread.set_forward_output(false);
535 io_control_for_thread.set_forward_output(false);
523 io_control_for_thread.set_forward_input(false);
536 io_control_for_thread.set_forward_input(false);
@@ -527,13 +540,19 @@ fn spawn_ssh_io(
528 attempts += 1;
541 attempts += 1;
529 if !ssh_port_open(&ip) {
542 if !ssh_port_open(&ip) {
530− eprintln!(
543+ tracing::info!(
546+ "waiting for ssh port ({}/{})",
531− "[vibebox] waiting for ssh port on {ip} (attempt {attempts}/{SSH_CONNECT_RETRIES})"
548+ SSH_CONNECT_RETRIES
533 if attempts >= SSH_CONNECT_RETRIES {
550 if attempts >= SSH_CONNECT_RETRIES {
534 ssh_connected_for_thread.store(false, Ordering::SeqCst);
551 ssh_connected_for_thread.store(false, Ordering::SeqCst);
535− eprintln!(
552+ tracing::warn!(
536− "[vibebox] ssh port not ready after {SSH_CONNECT_RETRIES} attempts"
554+ "ssh port not ready after {} attempts",
@@ -541,8 +560,13 @@ fn spawn_ssh_io(
541 continue;
560 continue;
544− eprintln!(
563+ tracing::info!(
567+ "starting ssh ({}/{})",
545− "[vibebox] starting ssh to {ssh_user}@{ip} (attempt {attempts}/{SSH_CONNECT_RETRIES})"
569+ SSH_CONNECT_RETRIES
547 let status = Command::new("ssh")
571 let status = Command::new("ssh")
@@ -577,18 +601,20 @@ fn spawn_ssh_io(
577 match status {
601 match status {
578 Ok(status) if status.success() => {
602 Ok(status) if status.success() => {
579 ssh_connected_for_thread.store(false, Ordering::SeqCst);
603 ssh_connected_for_thread.store(false, Ordering::SeqCst);
580− eprintln!("[vibebox] ssh exited with status: {status}");
604+ tracing::info!(status = %status, "ssh exited");
581 if let Some(tx) = input_tx_holder_for_thread.lock().unwrap().clone() {
605 if let Some(tx) = input_tx_holder_for_thread.lock().unwrap().clone() {
582 let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
606 let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
586 Ok(status) if status.code() == Some(255) => {
610 Ok(status) if status.code() == Some(255) => {
587− eprintln!("[vibebox] ssh connection failed: {status}");
611+ tracing::warn!(status = %status, "ssh connection failed");
588 if attempts >= SSH_CONNECT_RETRIES {
612 if attempts >= SSH_CONNECT_RETRIES {
589 ssh_connected_for_thread.store(false, Ordering::SeqCst);
613 ssh_connected_for_thread.store(false, Ordering::SeqCst);
590− eprintln!(
614+ tracing::warn!(
591− "[vibebox] ssh failed after {SSH_CONNECT_RETRIES} attempts"
616+ "ssh failed after {} attempts",
@@ -597,7 +623,7 @@ fn spawn_ssh_io(
598 Ok(status) => {
624 Ok(status) => {
599 ssh_connected_for_thread.store(false, Ordering::SeqCst);
625 ssh_connected_for_thread.store(false, Ordering::SeqCst);
600− eprintln!("[vibebox] ssh exited with status: {status}");
626+ tracing::info!(status = %status, "ssh exited");
601 if let Some(tx) = input_tx_holder_for_thread.lock().unwrap().clone() {
627 if let Some(tx) = input_tx_holder_for_thread.lock().unwrap().clone() {
602 let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
628 let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
@@ -605,7 +631,7 @@ fn spawn_ssh_io(
606 Err(err) => {
632 Err(err) => {
607 ssh_connected_for_thread.store(false, Ordering::SeqCst);
633 ssh_connected_for_thread.store(false, Ordering::SeqCst);
608− eprintln!("[vibebox] failed to start ssh: {err}");
634+ tracing::error!(error = %err, "failed to start ssh");