Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(pipes): baseline bun fallback + 0xC000001D diagnosis on non-AVX2 Windows CPUs

Ezra Elletteded5e92b8ef8
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
index 3babc1cae..f8dbd0bb2 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
@@ -3593,6 +3593,25 @@ pub async fn cleanup_pi(state: &PiState) {
/// Find bun executable (shared by pi_install and ensure_pi_installed_background)
fn find_bun_executable() -> Option<String> {
+ // Pre-AVX2 CPU: the bundled/stock bun.exe requires AVX2 and dies with
+ // 0xC000001D at spawn. Prefer the baseline build screenpipe-core
+ // downloads; if it isn't on disk yet, kick the background download and
+ // fall through to the stock bun for this run (the next spawn picks the
+ // baseline up). Mirrors screenpipe_core::agents::pi::find_bun_executable.
+ #[cfg(windows)]
+ if !screenpipe_core::cpu_features::has_avx2() {
+ if let Some(baseline) = screenpipe_core::agents::pi::baseline_bun_path() {
+ if baseline.exists() {
+ info!(
+ "Found baseline bun (non-AVX2 CPU) at: {}",
+ baseline.display()
+ );
+ return Some(baseline.to_string_lossy().to_string());
+ }
+ }
+ screenpipe_core::agents::pi::spawn_baseline_bun_download();
+ }
+
// First check next to our own executable (bundled bun in AppData/Local/screenpipe/)
if let Ok(exe_path) = std::env::current_exe() {
if let Some(exe_folder) = exe_path.parent() {
diff --git a/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh b/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
index 8e3bbdd4f..e6c0b7a17 100644
--- a/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
+++ b/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
@@ -75,6 +75,8 @@
!macro NSIS_HOOK_POSTUNINSTALL
; Clean up runtime-downloaded PortableGit (bash for AI chat)
RMDir /r "$LOCALAPPDATA\screenpipe\git-portable"
+ ; Clean up runtime-downloaded baseline bun (non-AVX2 CPU fallback)
+ RMDir /r "$LOCALAPPDATA\screenpipe\bun-baseline"
; Remove parent dir only if empty (preserves other screenpipe data)
RMDir "$LOCALAPPDATA\screenpipe"
!macroend
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 45a7d5bea..bcb767958 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -2144,6 +2144,22 @@ fn remove_screenpipe_auth_from_path(auth_path: &Path) -> Result<()> {
}
pub fn find_bun_executable() -> Option<String> {
+ // Pre-AVX2 CPU: the bundled/stock bun.exe requires AVX2 and dies with
+ // 0xC000001D (STATUS_ILLEGAL_INSTRUCTION) at spawn. Prefer the
+ // runtime-downloaded baseline build; if it isn't on disk yet, kick off
+ // the download in the background and fall through to the stock bun for
+ // this run (its failure is diagnosed by describe_exit_status_code; the
+ // next spawn picks up the baseline).
+ #[cfg(windows)]
+ if !crate::cpu_features::has_avx2() {
+ if let Some(baseline) = baseline_bun_path() {
+ if baseline.exists() {
+ return Some(baseline.to_string_lossy().to_string());
+ }
+ }
+ spawn_baseline_bun_download();
+ }
+
// Check next to our own executable (bundled bun)
if let Ok(exe_path) = std::env::current_exe() {
if let Some(exe_folder) = exe_path.parent() {
@@ -2183,7 +2199,7 @@ pub fn find_bun_executable() -> Option<String> {
/// the OOM killer) — exactly the case that used to log as an empty error.
pub fn describe_exit_status(status: &std::process::ExitStatus) -> String {
if let Some(code) = status.code() {
- return format!("exit code {}", code);
+ return describe_exit_status_code(code);
}
#[cfg(unix)]
{
@@ -2203,6 +2219,26 @@ pub fn describe_exit_status(status: &std::process::ExitStatus) -> String {
"terminated without exit code".to_string()
}
+/// Code→string mapping, factored out of [`describe_exit_status`] so it can
+/// be unit-tested (`ExitStatus` isn't constructible portably in tests) —
+/// mirrors the unix signal mapping above.
+pub fn describe_exit_status_code(code: i32) -> String {
+ #[cfg(windows)]
+ {
+ // 0xC000001D == STATUS_ILLEGAL_INSTRUCTION == exit code -1073741795.
+ // The stock bun.exe requires AVX2; on pre-AVX2 CPUs it dies with this
+ // code before writing a single byte to stderr — exactly the case that
+ // used to surface as an empty error. find_bun_executable downloads
+ // bun's official baseline build in the background on such CPUs.
+ if code == -1073741795i32 {
+ return format!(
+ "exit code {code} (0xC000001D, illegal instruction; this CPU may lack AVX2 — the stock bun build requires it; the baseline bun variant will be used after download)"
+ );
+ }
+ }
+ format!("exit code {code}")
+}
+
/// Last `max` bytes of a captured process stream, lossy-decoded and
/// char-boundary safe, with an "(empty)" placeholder so a silent subprocess
/// can never reduce an error message to nothing.
@@ -2946,6 +2982,209 @@ fn download_portable_git() -> std::result::Result<String, String> {
Ok(final_bash.to_string_lossy().to_string())
}
+/// Location of the runtime-downloaded baseline (non-AVX2) bun.exe. Preferred
+/// by [`find_bun_executable`] on CPUs without AVX2, where the stock/bundled
+/// bun dies with 0xC000001D. Cleaned up by the NSIS uninstall hook.
+#[cfg(windows)]
+pub fn baseline_bun_path() -> Option<PathBuf> {
+ let local_app_data = std::env::var("LOCALAPPDATA").ok()?;
+ Some(
+ PathBuf::from(local_app_data)
+ .join("screenpipe")
+ .join("bun-baseline")
+ .join("bun.exe"),
+ )
+}
+
+/// One-shot guard for the background baseline-bun download (per process).
+#[cfg(windows)]
+static BASELINE_BUN_DOWNLOAD_ONCE: std::sync::OnceLock<()> = std::sync::OnceLock::new();
+
+/// Kick off (at most once per process) a background download of bun's
+/// official baseline Windows build. Non-blocking on purpose: the caller
+/// falls through to the stock bun for the current run, and the next spawn
+/// picks up the baseline from disk.
+#[cfg(windows)]
+pub fn spawn_baseline_bun_download() {
+ BASELINE_BUN_DOWNLOAD_ONCE.get_or_init(|| {
+ std::thread::spawn(|| match download_baseline_bun() {
+ Ok(path) => info!("baseline bun installed at: {}", path),
+ Err(e) => warn!(
+ "baseline bun download failed (pipes/AI chat may not work on this pre-AVX2 CPU): {}",
+ e
+ ),
+ });
+ });
+}
+
+/// Download bun's official `windows-x64-baseline` build (runs on any x86-64,
+/// no AVX2 required) to `%LOCALAPPDATA%\screenpipe\bun-baseline\bun.exe`.
+/// Same structure as [`download_portable_git`], with one crucial difference:
+/// download via curl.exe ONLY — the bun-based download path is useless here
+/// because the whole point is that the stock bun cannot execute on this CPU.
+#[cfg(windows)]
+fn download_baseline_bun() -> std::result::Result<String, String> {
+ // Keep the version in lockstep with the Linux baseline sidecar pinned in
+ // apps/screenpipe-app-tauri/scripts/pre_build.js (bunVersion) — bump both
+ // together and refresh the SHA256 from the release's SHASUMS256.txt.
+ const BASELINE_BUN_VERSION: &str = "1.3.10";
+ const BASELINE_BUN_URL: &str =
+ "https://github.com/oven-sh/bun/releases/download/bun-v1.3.10/bun-windows-x64-baseline.zip";
+ const BASELINE_BUN_SHA256: &str =
+ "715709c69b176e20994533d3292bd0b7c32de9c0c5575b916746ec6b2aa38346";
+
+ let local_app_data =
+ std::env::var("LOCALAPPDATA").map_err(|_| "LOCALAPPDATA env var not set".to_string())?;
+ let screenpipe_dir = PathBuf::from(&local_app_data).join("screenpipe");
+ let bun_dir = screenpipe_dir.join("bun-baseline");
+ let bun_path = bun_dir.join("bun.exe");
+
+ // Already downloaded
+ if bun_path.exists() {
+ info!("baseline bun already present at {}", bun_dir.display());
+ return Ok(bun_path.to_string_lossy().to_string());
+ }
+
+ info!(
+ "Downloading baseline bun {} for non-AVX2 CPU support...",
+ BASELINE_BUN_VERSION
+ );
+
+ std::fs::create_dir_all(&screenpipe_dir)
+ .map_err(|e| format!("Failed to create screenpipe data dir: {}", e))?;
+
+ let temp_file = std::env::temp_dir().join(format!(
+ "bun-windows-x64-baseline-v{}.zip",
+ BASELINE_BUN_VERSION
+ ));
+
+ // curl.exe ships with Windows 10 1803+.
+ let download_result = {
+ let mut cmd = std::process::Command::new("curl.exe");
+ cmd.args(["-fSL", "-o", &temp_file.to_string_lossy(), BASELINE_BUN_URL]);
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x08000000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+ cmd.output()
+ };
+
+ match download_result {
+ Ok(output) if output.status.success() => {
+ info!("baseline bun downloaded to {}", temp_file.display());
+ }
+ Ok(output) => {
+ let stderr = String::from_utf8_lossy(&output.stderr).to_string();
+ let _ = std::fs::remove_file(&temp_file);
+ return Err(format!("baseline bun download failed: {}", stderr));
+ }
+ Err(e) => {
+ return Err(format!("Failed to run curl.exe: {}", e));
+ }
+ }
+
+ // Verify SHA256 using certutil (built into Windows) — same pattern as
+ // download_portable_git.
+ let digest = {
+ let mut cmd = std::process::Command::new("certutil");
+ cmd.args(["-hashfile", &temp_file.to_string_lossy(), "SHA256"]);
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x08000000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+ match cmd.output() {
+ Ok(output) if output.status.success() => {
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ // certutil output: line 0 = header, line 1 = hex hash, line 2 = status
+ stdout
+ .lines()
+ .nth(1)
+ .map(|l| l.trim().replace(' ', "").to_lowercase())
+ .unwrap_or_default()
+ }
+ _ => {
+ warn!("Could not verify SHA256 (certutil failed), proceeding with caution");
+ String::new()
+ }
+ }
+ };
+
+ if !digest.is_empty() && digest != BASELINE_BUN_SHA256 {
+ let _ = std::fs::remove_file(&temp_file);
+ return Err(format!(
+ "SHA256 mismatch: expected {}, got {}. Download may be corrupted.",
+ BASELINE_BUN_SHA256, digest
+ ));
+ }
+ if !digest.is_empty() {
+ info!("SHA256 verified: {}", digest);
+ }
+
+ // Extract with tar.exe (bsdtar ships with Windows 10 1803+; handles zip),
+ // into a temp dir first (atomic: rename on success).
+ let extract_temp = screenpipe_dir.join("bun-baseline-extracting");
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ std::fs::create_dir_all(&extract_temp)
+ .map_err(|e| format!("Failed to create extraction dir: {}", e))?;
+
+ {
+ let mut cmd = std::process::Command::new("tar.exe");
+ cmd.args([
+ "-xf",
+ &temp_file.to_string_lossy(),
+ "-C",
+ &extract_temp.to_string_lossy(),
+ ]);
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x08000000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+ match cmd.output() {
+ Ok(output) if output.status.success() => {
+ info!("baseline bun extracted successfully");
+ }
+ Ok(output) => {
+ let stderr = String::from_utf8_lossy(&output.stderr).to_string();
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ let _ = std::fs::remove_file(&temp_file);
+ return Err(format!("baseline bun extraction failed: {}", stderr));
+ }
+ Err(e) => {
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ let _ = std::fs::remove_file(&temp_file);
+ return Err(format!("Failed to run tar.exe: {}", e));
+ }
+ }
+ }
+
+ // The zip contains a bun-windows-x64-baseline/ folder holding bun.exe.
+ let extracted_dir = extract_temp.join("bun-windows-x64-baseline");
+ if !extracted_dir.join("bun.exe").exists() {
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ let _ = std::fs::remove_file(&temp_file);
+ return Err(
+ "Extraction completed but bun.exe not found in expected location".to_string(),
+ );
+ }
+
+ // Atomic rename: move extracted dir to final location
+ let _ = std::fs::remove_dir_all(&bun_dir);
+ std::fs::rename(&extracted_dir, &bun_dir).map_err(|e| {
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ format!("Failed to move baseline bun to final location: {}", e)
+ })?;
+
+ // Clean up temp artifacts
+ let _ = std::fs::remove_dir_all(&extract_temp);
+ let _ = std::fs::remove_file(&temp_file);
+
+ info!("baseline bun setup complete: {}", bun_path.display());
+ Ok(bun_path.to_string_lossy().to_string())
+}
+
/// Global guard: ensures only one download runs at a time and caches the result.
/// `None` inside means download was attempted but failed.
#[cfg(windows)]
@@ -2993,6 +3232,21 @@ pub fn ensure_bash_available() -> Option<String> {
mod tests {
use super::*;
+ #[cfg(windows)]
+ #[test]
+ fn describe_exit_status_flags_illegal_instruction() {
+ // 0xC000001D == STATUS_ILLEGAL_INSTRUCTION == exit code -1073741795
+ let s = describe_exit_status_code(-1073741795);
+ assert!(s.contains("illegal instruction"));
+ assert!(s.to_lowercase().contains("avx2"));
+ }
+
+ #[test]
+ fn describe_exit_status_code_plain_codes_unchanged() {
+ assert_eq!(describe_exit_status_code(0), "exit code 0");
+ assert_eq!(describe_exit_status_code(1), "exit code 1");
+ }
+
#[test]
fn clear_screenpipe_auth_preserves_other_provider_tokens() {
let dir = tempfile::tempdir().expect("tempdir");