From a9ce8a945f08a22e476447589fcb168236cad6ce Mon Sep 17 00:00:00 2001 From: damocles Date: Wed, 3 Jun 2026 18:23:18 +0200 Subject: [PATCH] fix(#1160): restart agent on failed rebuild if it was running --- hive-c0re/src/lifecycle.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hive-c0re/src/lifecycle.rs b/hive-c0re/src/lifecycle.rs index 4441d0f4..cd4c0555 100644 --- a/hive-c0re/src/lifecycle.rs +++ b/hive-c0re/src/lifecycle.rs @@ -467,7 +467,26 @@ pub async fn rebuild_no_meta( priv_run("stop", name).await?; } on_step("nixos-container update"); - priv_run("update", name).await?; + let update_result = priv_run("update", name).await; + if let Err(ref update_err) = update_result { + // The update failed (e.g. nix build error). If the agent was + // running before we stopped it, try to bring it back up on the + // previous successful configuration so it doesn't stay dead. + // The start failure is logged but not promoted to an error — + // we always propagate the original update error (below). + if was_running { + tracing::warn!( + %name, + error = %update_err, + "nixos-container update failed; attempting restart on old config" + ); + on_step("nixos-container start (recovery)"); + if let Err(e) = priv_run("start", name).await { + tracing::warn!(%name, error = %e, "recovery start after failed update also failed"); + } + } + } + update_result?; if was_running { // Cold-start fallback on activation errors. // See `docs/coordinator.md::Cold-start fallback`.