feat(app): version handshake — GUI restarts a stale running daemon

The daemon outlives the GUI, so after an update an OLD daemon can keep serving
the socket and the new GUI just connects to it (stale code — e.g. the missing
TERM fix). Both binaries are now stamped with the git build id (build.rs):
the daemon reports it in `health.build`, and on connect the bridge compares it
to the GUI's own SPACESH_BUILD; on mismatch it shuts the daemon down and lets
ensure_daemon respawn the bundled (matching) one. No-op for unstamped dev
builds or daemons too old to report a build. Build id is shown in Settings.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-15 12:39:46 +07:00
parent 8f431eaa40
commit cf7410b46a
6 changed files with 84 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
use std::process::Command;
// Stamp the binary with the current git build id so the GUI can detect a stale
// running daemon (different code) and restart it. Matches app/src-tauri/build.rs.
fn main() {
println!("cargo:rustc-env=SPACESH_BUILD={}", git_build());
println!("cargo:rerun-if-changed=../../.git/HEAD");
println!("cargo:rerun-if-changed=../../.git/index");
}
fn git_build() -> String {
let sha = Command::new("git")
.args(["rev-parse", "--short=12", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.filter(|s| !s.is_empty());
let Some(sha) = sha else { return "dev".into() };
let dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()
.map(|o| !o.stdout.is_empty())
.unwrap_or(false);
if dirty { format!("{sha}-dirty") } else { sha }
}