The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(update): resolve the versioned core archive and stage its binary
obchain4de0c15324fb
diff --git a/crates/openhuman-core/src/platform/update/core.rs b/crates/openhuman-core/src/platform/update/core.rsindex 04a25b3c63..233470d5e3 100644--- a/crates/openhuman-core/src/platform/update/core.rs+++ b/crates/openhuman-core/src/platform/update/core.rs@@ -53,24 +53,138 @@ pub fn platform_triple() -> &'static str {}}+/// True if the asset name is an archive whose inner binary must be extracted,+/// rather than a raw executable that can be staged as downloaded.+fn is_archive_asset(name: &str) -> bool {+ name.ends_with(".tar.gz") || name.ends_with(".tgz") || name.ends_with(".zip")+}+/// Find the right asset for this platform from a list of release assets.///-/// Convention: assets are named `openhuman-core-{triple}` (or `.exe` on Windows).+/// The release workflow publishes the core as a versioned archive,+/// `openhuman-core-<version>-<triple>.tar.gz` (`.zip` on Windows) — the version+/// sits between the prefix and the triple. Matching on `openhuman-core-{triple}`+/// alone therefore never hits, on any platform, which is what left every update+/// check reporting `asset=(none)` (#6766). #908 fixed this once; the matcher was+/// reintroduced in its pre-#908 form when this module moved into the core, so the+/// shape below is restored from that fix.+///+/// The raw-binary form is kept as a fallback for older releases.fn find_platform_asset(assets: &[GitHubAsset]) -> Option<&GitHubAsset> {let triple = platform_triple();- let expected_name = format!("openhuman-core-{triple}");+ let archive_ext = if cfg!(windows) { ".zip" } else { ".tar.gz" };log::debug!(- "[update] looking for asset matching '{}' among {} assets",- expected_name,+ "[update] looking for an 'openhuman-core-*{}{}' asset among {} assets",+ triple,+ archive_ext,assets.len());- // Try exact match first, then prefix match.+ let archive_match = assets.iter().find(|a| {+ a.name.starts_with("openhuman-core-")+ && a.name.contains(triple)+ && a.name.ends_with(archive_ext)+ // The release publishes a checksum and a signature beside each+ // archive (`….tar.gz.sha256`, `….tar.gz.sig`). Both share the+ // prefix and the triple, so exclude them explicitly.+ && !a.name.ends_with(".sha256")+ && !a.name.ends_with(".sig")+ });+ if archive_match.is_some() {+ return archive_match;+ }++ // Legacy raw-binary releases.+ let legacy = format!("openhuman-core-{triple}");+ let legacy_exe = format!("{legacy}.exe");assets.iter()- .find(|a| a.name == expected_name || a.name == format!("{expected_name}.exe"))- .or_else(|| assets.iter().find(|a| a.name.starts_with(&expected_name)))+ .find(|a| a.name == legacy || a.name == legacy_exe)+}++/// Name the staged executable is written under.+///+/// The archive carries the binary as plain `openhuman-core` (`.exe` on+/// Windows), which is the name the shell restarts, so the extracted file keeps+/// it rather than inheriting the archive's `.tar.gz` name.+fn staged_binary_name() -> &'static str {+ if cfg!(windows) {+ "openhuman-core.exe"+ } else {+ "openhuman-core"+ }+}++/// Make `tmp` executable and move it onto `dest` atomically, cleaning up `tmp`+/// if the rename fails.+fn finalize_executable(tmp: &std::path::Path, dest: &std::path::Path) -> Result<(), String> {+ #[cfg(unix)]+ {+ std::fs::set_permissions(tmp, std::fs::Permissions::from_mode(0o755))+ .map_err(|e| format!("failed to set executable permission: {e}"))?;+ }+ std::fs::rename(tmp, dest).map_err(|e| {+ let _ = std::fs::remove_file(tmp);+ format!("failed to move update to {}: {e}", dest.display())+ })+}++/// Extract the inner `openhuman-core` executable from a downloaded archive to+/// `dest`.+///+/// Without this the archive itself was written to the staging path and marked+/// executable, so a restart would try to exec a tarball. Restored from #908,+/// which added it for exactly that reason.+fn extract_core_binary(archive_path: &std::path::Path, dest: &std::path::Path) -> Result<(), String> {+ let inner_name = staged_binary_name();+ let archive_name = archive_path+ .file_name()+ .and_then(|s| s.to_str())+ .unwrap_or_default();+ let tmp_path = dest.with_extension("staging-tmp");++ let file = std::fs::File::open(archive_path).map_err(|e| format!("open archive: {e}"))?;++ if archive_name.ends_with(".zip") {+ let mut zip = zip::ZipArchive::new(file).map_err(|e| format!("read zip: {e}"))?;+ let mut entry = zip+ .by_name(inner_name)+ .map_err(|e| format!("archive has no '{inner_name}' entry: {e}"))?;+ {+ let mut out =+ std::fs::File::create(&tmp_path).map_err(|e| format!("create staging temp: {e}"))?;+ std::io::copy(&mut entry, &mut out).map_err(|e| format!("extract zip entry: {e}"))?;+ out.flush().map_err(|e| format!("flush extracted binary: {e}"))?;+ }+ return finalize_executable(&tmp_path, dest);+ }++ let decoder = flate2::read::GzDecoder::new(file);+ let mut archive = tar::Archive::new(decoder);+ let entries = archive+ .entries()+ .map_err(|e| format!("read tar entries: {e}"))?;+ for entry in entries {+ let mut entry = entry.map_err(|e| format!("read tar entry: {e}"))?;+ let path = entry.path().map_err(|e| format!("read tar entry path: {e}"))?;+ let is_core = path+ .file_name()+ .and_then(|s| s.to_str())+ .is_some_and(|name| name == inner_name);+ if !is_core {+ continue;+ }+ {+ let mut out =+ std::fs::File::create(&tmp_path).map_err(|e| format!("create staging temp: {e}"))?;+ std::io::copy(&mut entry, &mut out).map_err(|e| format!("extract tar entry: {e}"))?;+ out.flush().map_err(|e| format!("flush extracted binary: {e}"))?;+ }+ return finalize_executable(&tmp_path, dest);+ }++ Err(format!("archive has no '{inner_name}' entry"))}/// Compare two semver-ish version strings.@@ -318,7 +432,14 @@ pub async fn download_and_stage_with_version(.map_err(|e| format!("failed to create staging dir {}: {e}", dir.display()))?;}- let staged_path = dir.join(asset_name);+ // An archive stages as the executable it contains, not as itself: marking a+ // `.tar.gz` 0755 and restarting into it cannot work (#6766).+ let is_archive = is_archive_asset(asset_name);+ let staged_path = if is_archive {+ dir.join(staged_binary_name())+ } else {+ dir.join(asset_name)+ };// Write to a temp file first, then rename for atomicity.let tmp_path = dir.join(format!(".{asset_name}.tmp"));@@ -331,17 +452,15 @@ pub async fn download_and_stage_with_version(.map_err(|e| format!("failed to flush update binary: {e}"))?;}- // Set executable permission on Unix.- #[cfg(unix)]- {- std::fs::set_permissions(&tmp_path, std::fs::Permissions::from_mode(0o755))- .map_err(|e| format!("failed to set executable permission: {e}"))?;+ if is_archive {+ let extracted = extract_core_binary(&tmp_path, &staged_path);+ // The archive is scratch either way.+ let _ = std::fs::remove_file(&tmp_path);+ extracted?;+ } else {+ finalize_executable(&tmp_path, &staged_path)?;}- // Atomic rename (same filesystem).- std::fs::rename(&tmp_path, &staged_path)- .map_err(|e| format!("failed to move update to {}: {e}", staged_path.display()))?;-let installed_version = target_version.unwrap_or_else(|| current_version()).to_string();diff --git a/crates/openhuman-core/src/platform/update/core_tests.rs b/crates/openhuman-core/src/platform/update/core_tests.rsindex 6628cc0a78..97312742c3 100644--- a/crates/openhuman-core/src/platform/update/core_tests.rs+++ b/crates/openhuman-core/src/platform/update/core_tests.rs@@ -1,4 +1,6 @@use super::*;+#[cfg(unix)]+use std::os::unix::fs::PermissionsExt as _;#[test]fn is_newer_detects_update() {@@ -165,3 +167,214 @@ fn the_default_origin_is_still_the_pinned_github_api() {"the URL check_available() builds must be byte-identical to the pre-refactor literal");}+++// ---------------------------------------------------------------------------+// #6766: the release publishes the core as `openhuman-core-<version>-<triple>`+// with the version BETWEEN the prefix and the triple, so matching on+// `openhuman-core-{triple}` never hit — on any platform, which is why every+// check reported `asset=(none)`. #908 fixed this once; the pre-#908 matcher came+// back when this module moved into the core. These pin both halves of that fix:+// selecting the versioned archive, and staging the binary out of it rather than+// marking the archive itself executable.+// ---------------------------------------------------------------------------++/// The archive extension the release workflow publishes for this platform.+fn archive_ext() -> &'static str {+ if cfg!(windows) { ".zip" } else { ".tar.gz" }+}++fn asset(name: &str) -> GitHubAsset {+ GitHubAsset {+ name: name.to_string(),+ browser_download_url: format!("https://example.invalid/{name}"),+ size: 1,+ }+}++#[test]+fn find_platform_asset_matches_the_versioned_archive() {+ let triple = platform_triple();+ let ext = archive_ext();+ let wanted = format!("openhuman-core-0.64.7-{triple}{ext}");+ let assets = vec![+ asset(&format!("openhuman-core-0.64.7-some-other-triple{ext}")),+ asset(&wanted),+ ];++ let picked = find_platform_asset(&assets).expect("the versioned archive must be selected");++ assert_eq!(picked.name, wanted, "another triple's archive must not be selected");+}++#[test]+fn find_platform_asset_ignores_the_checksum_and_signature_siblings() {+ // The release publishes `….sha256` and `….sig` next to the archive. Both+ // start with the prefix and contain the triple, so a looser match would+ // stage a 65-byte checksum file as the new core binary.+ let triple = platform_triple();+ let ext = archive_ext();+ let archive = format!("openhuman-core-0.64.7-{triple}{ext}");+ let assets = vec![+ asset(&format!("{archive}.sha256")),+ asset(&format!("{archive}.sig")),+ asset(&archive),+ ];++ let picked = find_platform_asset(&assets).expect("the archive itself must be selected");+ assert_eq!(picked.name, archive);++ // And with the archive absent, neither sibling is an acceptable substitute.+ let siblings_only = vec![+ asset(&format!("{archive}.sha256")),+ asset(&format!("{archive}.sig")),+ ];+ assert!(+ find_platform_asset(&siblings_only).is_none(),+ "a checksum or signature must never be selected as the binary"+ );+}++#[test]+fn find_platform_asset_falls_back_to_a_legacy_raw_binary() {+ // Older releases shipped an unversioned raw binary. Keep resolving those.+ let triple = platform_triple();+ let legacy = if cfg!(windows) {+ format!("openhuman-core-{triple}.exe")+ } else {+ format!("openhuman-core-{triple}")+ };+ let assets = vec![asset("openhuman-core-some-other-triple"), asset(&legacy)];++ let picked = find_platform_asset(&assets).expect("the legacy raw binary must still resolve");++ assert_eq!(picked.name, legacy);+}++#[test]+fn find_platform_asset_returns_none_when_no_core_asset_is_published() {+ // What macOS and Windows actually see today: the release carries desktop+ // bundles but no `openhuman-core-*` archive for them. `None` is the correct+ // answer, and `ops::validate_asset_name` is why a bundle must not be+ // substituted — it requires the `openhuman-core-` prefix.+ let assets = vec![+ asset("OpenHuman_0.64.7_aarch64-apple-darwin.app.tar.gz"),+ asset("OpenHuman_0.64.7_x64-setup.exe"),+ asset("latest.json"),+ ];++ assert!(find_platform_asset(&assets).is_none());+}++#[test]+fn is_archive_asset_classifies_the_published_shapes() {+ assert!(is_archive_asset("openhuman-core-0.64.7-x86_64-unknown-linux-gnu.tar.gz"));+ assert!(is_archive_asset("openhuman-core-0.64.7-x86_64-pc-windows-msvc.zip"));+ assert!(is_archive_asset("core.tgz"));+ assert!(!is_archive_asset("openhuman-core-x86_64-unknown-linux-gnu"));+ assert!(!is_archive_asset("openhuman-core.exe"));+}++#[tokio::test]+async fn check_available_picks_the_versioned_archive() {+ // The reported symptom, end to end through the check path: a release shaped+ // like the real one must resolve an asset instead of `asset=(none)`.+ let triple = platform_triple();+ let ext = archive_ext();+ let archive = format!("openhuman-core-0.64.7-{triple}{ext}");+ let body = format!(+ r#"{{+ "tag_name": "v99.0.0",+ "body": "notes",+ "published_at": "2026-09-29T00:00:00Z",+ "assets": [+ {{"name": "latest.json", "browser_download_url": "https://example.invalid/latest.json", "size": 1}},+ {{"name": "{archive}.sha256", "browser_download_url": "https://example.invalid/sha", "size": 65}},+ {{"name": "{archive}", "browser_download_url": "https://example.invalid/{archive}", "size": 2}}+ ]+ }}"#+ );+ let server = releases_mock(200, &body).await;++ let info = check_available_with_base_url(&server.uri())+ .await+ .expect("mocked release must parse");++ assert!(info.update_available);+ assert_eq!(+ info.asset_name.as_deref(),+ Some(archive.as_str()),+ "the versioned archive must resolve — `asset=(none)` is the bug"+ );+ assert_eq!(+ info.download_url.as_deref(),+ Some(format!("https://example.invalid/{archive}").as_str())+ );+}++/// Build a `.tar.gz` holding one entry named `entry_name`, with `body` as its+/// contents, and return its path.+#[cfg(unix)]+fn write_tar_gz(dir: &std::path::Path, archive_name: &str, entry_name: &str, body: &[u8]) -> std::path::PathBuf {+ let archive_path = dir.join(archive_name);+ let file = std::fs::File::create(&archive_path).expect("create archive");+ let encoder = flate2::write::GzEncoder::new(file, flate2::Compression::fast());+ let mut builder = tar::Builder::new(encoder);+ let mut header = tar::Header::new_gnu();+ header.set_size(body.len() as u64);+ header.set_mode(0o755);+ header.set_cksum();+ builder+ .append_data(&mut header, entry_name, body)+ .expect("append entry");+ builder.into_inner().expect("finish tar").finish().expect("finish gz");+ archive_path+}++#[cfg(unix)]+#[test]+fn staging_extracts_the_core_binary_out_of_the_archive() {+ // Without extraction the `.tar.gz` itself was written to the staging path+ // and marked 0755, so a restart would exec a tarball.+ let dir = tempfile::TempDir::new().expect("temp dir");+ let archive = write_tar_gz(+ dir.path(),+ "openhuman-core-0.64.7-triple.tar.gz",+ "openhuman-core",+ b"#!/bin/sh\nexit 0\n",+ );+ let dest = dir.path().join(staged_binary_name());++ extract_core_binary(&archive, &dest).expect("the inner binary must extract");++ assert_eq!(+ std::fs::read(&dest).expect("read staged binary"),+ b"#!/bin/sh\nexit 0\n",+ "the staged file must be the inner binary, not the archive"+ );+ let mode = std::fs::metadata(&dest).expect("stat staged binary").permissions().mode();+ assert_eq!(mode & 0o111, 0o111, "the staged binary must be executable, mode was {mode:o}");+}++#[cfg(unix)]+#[test]+fn staging_refuses_an_archive_without_the_core_binary() {+ // A release that renames the inner file must fail loudly rather than leave a+ // half-staged update behind.+ let dir = tempfile::TempDir::new().expect("temp dir");+ let archive = write_tar_gz(+ dir.path(),+ "openhuman-core-0.64.7-triple.tar.gz",+ "something-else",+ b"not the core\n",+ );+ let dest = dir.path().join(staged_binary_name());++ let err = extract_core_binary(&archive, &dest).expect_err("a wrong-named entry must fail");++ assert!(+ err.contains(staged_binary_name()),+ "the error must name the entry it looked for, got: {err}"+ );+ assert!(!dest.exists(), "nothing may be staged when extraction fails");+}