From 64504bd15a93a14a441866cb0d022e47364a0950 Mon Sep 17 00:00:00 2001 From: Adil Date: Sun, 22 Nov 2026 13:03:40 +0500 Subject: [PATCH 1/2] humd: the autoupdate installer outlives the humd it restarts humd ran the installer as its own child, in its own process group. The installer's `launchctl bootout gui/$uid/humd` killed that whole group, installer included, so it never reached `launchctl bootstrap` and humd stayed down until someone reinstalled by hand. The installer now leads its own process group, so the bootout spares it. On Linux, systemd stops the unit's whole cgroup either way, but `systemctl --user restart` is a single job, so humd came back there already. --- humd/src/lib.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/humd/src/lib.rs b/humd/src/lib.rs index ae1df819..db9d67c4 100644 --- a/humd/src/lib.rs +++ b/humd/src/lib.rs @@ -555,17 +555,23 @@ async fn autoupdate_check_once() -> Result { return Ok(false); } info!(local = %stamped, upstream = %upstream_trim, "autoupdate.newer.found"); - let status = tokio::process::Command::new("bash") - .arg("-c") - .arg("curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash") - .status() - .await?; + let status = installer_outliving_humd( + "curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash", + ) + .status() + .await?; if !status.success() { anyhow::bail!("installer exited with {status}"); } Ok(true) } +fn installer_outliving_humd(script: &str) -> tokio::process::Command { + let mut cmd = tokio::process::Command::new("bash"); + cmd.arg("-c").arg(script).process_group(0); + cmd +} + fn parse_tag_name(body: &str) -> Option { let needle = "\"tag_name\":"; let start = body.find(needle)? + needle.len(); @@ -2291,3 +2297,21 @@ const BREATH_EVERY: Duration = Duration::from_secs(2); fn parse_humd_id(s: &str) -> Option { ensemble::Hid::from_hex(s).ok() } + +#[cfg(test)] +mod autoupdate_tests { + use super::*; + + #[tokio::test] + async fn the_installer_leads_its_own_process_group_so_a_bootout_of_humd_spares_it() { + let out = installer_outliving_humd("echo $$ $(ps -o pgid= -p $$)") + .output() + .await + .unwrap(); + let said = String::from_utf8(out.stdout).unwrap(); + let mut words = said.split_whitespace(); + let pid = words.next().unwrap(); + let pgid = words.next().unwrap(); + assert_eq!(pid, pgid); + } +} From 24b2c24fa1d874fefc892949dbef059a449a6149 Mon Sep 17 00:00:00 2001 From: Adil Date: Sun, 22 Nov 2026 13:03:40 +0500 Subject: [PATCH 2/2] hum, humctl: the thrum probe listens for humd's greeting instead of saying hello `hum doctor` and `humctl health` sent a bare hello, which humd refused and logged at ERROR (`thrum.hello.proto-missing`). Adding protoVersion would only move the refusal to the hive check, which also logs at ERROR, and a hello that passed every check would nestle the probe as a bee. humd already breathes to every connection before any hello, and that breath was the reply the probe read. The probe now connects and waits for it, sending nothing. --- hum/src/main.rs | 4 +--- humctl/src/main.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hum/src/main.rs b/hum/src/main.rs index 466dc729..3f19df40 100644 --- a/hum/src/main.rs +++ b/hum/src/main.rs @@ -308,7 +308,7 @@ fn now_ms() -> u64 { } fn probe_thrum(sock: &Path) -> Result<()> { - use std::io::{Read, Write}; + use std::io::Read; use std::os::unix::net::UnixStream; use std::time::Duration; if !sock.exists() { @@ -317,8 +317,6 @@ fn probe_thrum(sock: &Path) -> Result<()> { let mut s = UnixStream::connect(sock) .map_err(|e| anyhow::anyhow!("connect refused ({e}) — stale socket, humd crashed"))?; s.set_read_timeout(Some(Duration::from_secs(1)))?; - s.set_write_timeout(Some(Duration::from_secs(1)))?; - s.write_all(b"{\"chi\":\"hello\",\"sid\":\"hum-doctor-probe\"}\n")?; let mut buf = [0u8; 256]; match s.read(&mut buf) { Ok(0) => anyhow::bail!("socket closed without breath"), diff --git a/humctl/src/main.rs b/humctl/src/main.rs index fe56ba18..342e0972 100644 --- a/humctl/src/main.rs +++ b/humctl/src/main.rs @@ -152,7 +152,7 @@ fn logs(lines: u32) -> Result<()> { fn health() -> Result<()> { let sock = hum_paths::thrum_sock_resolved(); - use std::io::{Read, Write}; + use std::io::Read; use std::os::unix::net::UnixStream; use std::time::Duration; if !sock.exists() { @@ -161,8 +161,6 @@ fn health() -> Result<()> { let mut s = UnixStream::connect(&sock).with_context(|| format!("connect {}", sock.display()))?; s.set_read_timeout(Some(Duration::from_secs(1)))?; - s.set_write_timeout(Some(Duration::from_secs(1)))?; - s.write_all(b"{\"chi\":\"hello\",\"sid\":\"humctl-health\"}\n")?; let mut buf = [0u8; 256]; match s.read(&mut buf) { Ok(0) => bail!("socket closed without breath"),