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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: Pi agent race condition on Windows — wait for background install
Louis Beaumontdaf477f807df
diff --git a/apps/screenpipe-app-tauri/bun.lock b/apps/screenpipe-app-tauri/bun.lockindex 45c1cf8bf..cf1307570 100644--- a/apps/screenpipe-app-tauri/bun.lock+++ b/apps/screenpipe-app-tauri/bun.lock@@ -1,6 +1,5 @@{"lockfileVersion": 1,- "configVersion": 0,"workspaces": {"": {"name": "screenpipe-app",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 356400b5b..bc767d772 100755--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -9007,7 +9007,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.0.357"+version = "2.0.359"dependencies = ["anyhow","async-stream",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex da6eecc14..64c88cfde 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -199,8 +199,5 @@ incremental = true[profile.dev]opt-level = 0-[profile.dev.build-override]-debug-assertions = false-[profile.dev.package."*"]opt-level = 2diff --git a/apps/screenpipe-app-tauri/src-tauri/gen/schemas/windows-schema.json b/apps/screenpipe-app-tauri/src-tauri/gen/schemas/windows-schema.jsonindex 803619b34..8ce982d28 100644--- a/apps/screenpipe-app-tauri/src-tauri/gen/schemas/windows-schema.json+++ b/apps/screenpipe-app-tauri/src-tauri/gen/schemas/windows-schema.json@@ -1400,10 +1400,10 @@"markdownDescription": "This enables all index or metadata related commands without any pre-configured accessible paths."},{- "description": "An empty permission you can use to modify the global scope.",+ "description": "An empty permission you can use to modify the global scope.\n\n## Example\n\n```json\n{\n \"identifier\": \"read-documents\",\n \"windows\": [\"main\"],\n \"permissions\": [\n \"fs:allow-read\",\n {\n \"identifier\": \"fs:scope\",\n \"allow\": [\n \"$APPDATA/documents/**/*\"\n ],\n \"deny\": [\n \"$APPDATA/documents/secret.txt\"\n ]\n }\n ]\n}\n```\n","type": "string","const": "fs:scope",- "markdownDescription": "An empty permission you can use to modify the global scope."+ "markdownDescription": "An empty permission you can use to modify the global scope.\n\n## Example\n\n```json\n{\n \"identifier\": \"read-documents\",\n \"windows\": [\"main\"],\n \"permissions\": [\n \"fs:allow-read\",\n {\n \"identifier\": \"fs:scope\",\n \"allow\": [\n \"$APPDATA/documents/**/*\"\n ],\n \"deny\": [\n \"$APPDATA/documents/secret.txt\"\n ]\n }\n ]\n}\n```\n"},{"description": "This scope permits access to all files and list content of top level directories in the application folders.",@@ -1940,10 +1940,10 @@"identifier": {"anyOf": [{- "description": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-read-body`\n- `allow-fetch-send`",+ "description": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-send`\n- `allow-fetch-read-body`\n- `allow-fetch-cancel-body`","type": "string","const": "http:default",- "markdownDescription": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-read-body`\n- `allow-fetch-send`"+ "markdownDescription": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-send`\n- `allow-fetch-read-body`\n- `allow-fetch-cancel-body`"},{"description": "Enables the fetch command without any pre-configured scope.",@@ -1957,6 +1957,12 @@"const": "http:allow-fetch-cancel","markdownDescription": "Enables the fetch_cancel command without any pre-configured scope."},+ {+ "description": "Enables the fetch_cancel_body command without any pre-configured scope.",+ "type": "string",+ "const": "http:allow-fetch-cancel-body",+ "markdownDescription": "Enables the fetch_cancel_body command without any pre-configured scope."+ },{"description": "Enables the fetch_read_body command without any pre-configured scope.","type": "string",@@ -1981,6 +1987,12 @@"const": "http:deny-fetch-cancel","markdownDescription": "Denies the fetch_cancel command without any pre-configured scope."},+ {+ "description": "Denies the fetch_cancel_body command without any pre-configured scope.",+ "type": "string",+ "const": "http:deny-fetch-cancel-body",+ "markdownDescription": "Denies the fetch_cancel_body command without any pre-configured scope."+ },{"description": "Denies the fetch_read_body command without any pre-configured scope.","type": "string",@@ -2547,10 +2559,10 @@"markdownDescription": "Default core plugins set.\n#### This default permission set includes:\n\n- `core:path:default`\n- `core:event:default`\n- `core:window:default`\n- `core:webview:default`\n- `core:app:default`\n- `core:image:default`\n- `core:resources:default`\n- `core:menu:default`\n- `core:tray:default`"},{- "description": "Default permissions for the plugin.\n#### This default permission set includes:\n\n- `allow-version`\n- `allow-name`\n- `allow-tauri-version`\n- `allow-identifier`\n- `allow-bundle-type`",+ "description": "Default permissions for the plugin.\n#### This default permission set includes:\n\n- `allow-version`\n- `allow-name`\n- `allow-tauri-version`\n- `allow-identifier`\n- `allow-bundle-type`\n- `allow-register-listener`\n- `allow-remove-listener`","type": "string","const": "core:app:default",- "markdownDescription": "Default permissions for the plugin.\n#### This default permission set includes:\n\n- `allow-version`\n- `allow-name`\n- `allow-tauri-version`\n- `allow-identifier`\n- `allow-bundle-type`"+ "markdownDescription": "Default permissions for the plugin.\n#### This default permission set includes:\n\n- `allow-version`\n- `allow-name`\n- `allow-tauri-version`\n- `allow-identifier`\n- `allow-bundle-type`\n- `allow-register-listener`\n- `allow-remove-listener`"},{"description": "Enables the app_hide command without any pre-configured scope.",@@ -2594,12 +2606,24 @@"const": "core:app:allow-name","markdownDescription": "Enables the name command without any pre-configured scope."},+ {+ "description": "Enables the register_listener command without any pre-configured scope.",+ "type": "string",+ "const": "core:app:allow-register-listener",+ "markdownDescription": "Enables the register_listener command without any pre-configured scope."+ },{"description": "Enables the remove_data_store command without any pre-configured scope.","type": "string","const": "core:app:allow-remove-data-store","markdownDescription": "Enables the remove_data_store command without any pre-configured scope."},+ {+ "description": "Enables the remove_listener command without any pre-configured scope.",+ "type": "string",+ "const": "core:app:allow-remove-listener",+ "markdownDescription": "Enables the remove_listener command without any pre-configured scope."+ },{"description": "Enables the set_app_theme command without any pre-configured scope.","type": "string",@@ -2666,12 +2690,24 @@"const": "core:app:deny-name","markdownDescription": "Denies the name command without any pre-configured scope."},+ {+ "description": "Denies the register_listener command without any pre-configured scope.",+ "type": "string",+ "const": "core:app:deny-register-listener",+ "markdownDescription": "Denies the register_listener command without any pre-configured scope."+ },{"description": "Denies the remove_data_store command without any pre-configured scope.","type": "string","const": "core:app:deny-remove-data-store","markdownDescription": "Denies the remove_data_store command without any pre-configured scope."},+ {+ "description": "Denies the remove_listener command without any pre-configured scope.",+ "type": "string",+ "const": "core:app:deny-remove-listener",+ "markdownDescription": "Denies the remove_listener command without any pre-configured scope."+ },{"description": "Denies the set_app_theme command without any pre-configured scope.","type": "string",@@ -5865,10 +5901,10 @@"markdownDescription": "This enables all index or metadata related commands without any pre-configured accessible paths."},{- "description": "An empty permission you can use to modify the global scope.",+ "description": "An empty permission you can use to modify the global scope.\n\n## Example\n\n```json\n{\n \"identifier\": \"read-documents\",\n \"windows\": [\"main\"],\n \"permissions\": [\n \"fs:allow-read\",\n {\n \"identifier\": \"fs:scope\",\n \"allow\": [\n \"$APPDATA/documents/**/*\"\n ],\n \"deny\": [\n \"$APPDATA/documents/secret.txt\"\n ]\n }\n ]\n}\n```\n","type": "string","const": "fs:scope",- "markdownDescription": "An empty permission you can use to modify the global scope."+ "markdownDescription": "An empty permission you can use to modify the global scope.\n\n## Example\n\n```json\n{\n \"identifier\": \"read-documents\",\n \"windows\": [\"main\"],\n \"permissions\": [\n \"fs:allow-read\",\n {\n \"identifier\": \"fs:scope\",\n \"allow\": [\n \"$APPDATA/documents/**/*\"\n ],\n \"deny\": [\n \"$APPDATA/documents/secret.txt\"\n ]\n }\n ]\n}\n```\n"},{"description": "This scope permits access to all files and list content of top level directories in the application folders.",@@ -6399,10 +6435,10 @@"markdownDescription": "Denies the unregister_all command without any pre-configured scope."},{- "description": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-read-body`\n- `allow-fetch-send`",+ "description": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-send`\n- `allow-fetch-read-body`\n- `allow-fetch-cancel-body`","type": "string","const": "http:default",- "markdownDescription": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-read-body`\n- `allow-fetch-send`"+ "markdownDescription": "This permission set configures what kind of\nfetch operations are available from the http plugin.\n\nThis enables all fetch operations but does not\nallow explicitly any origins to be fetched. This needs to\nbe manually configured before usage.\n\n#### Granted Permissions\n\nAll fetch operations are enabled.\n\n\n#### This default permission set includes:\n\n- `allow-fetch`\n- `allow-fetch-cancel`\n- `allow-fetch-send`\n- `allow-fetch-read-body`\n- `allow-fetch-cancel-body`"},{"description": "Enables the fetch command without any pre-configured scope.",@@ -6416,6 +6452,12 @@"const": "http:allow-fetch-cancel","markdownDescription": "Enables the fetch_cancel command without any pre-configured scope."},+ {+ "description": "Enables the fetch_cancel_body command without any pre-configured scope.",+ "type": "string",+ "const": "http:allow-fetch-cancel-body",+ "markdownDescription": "Enables the fetch_cancel_body command without any pre-configured scope."+ },{"description": "Enables the fetch_read_body command without any pre-configured scope.","type": "string",@@ -6440,6 +6482,12 @@"const": "http:deny-fetch-cancel","markdownDescription": "Denies the fetch_cancel command without any pre-configured scope."},+ {+ "description": "Denies the fetch_cancel_body command without any pre-configured scope.",+ "type": "string",+ "const": "http:deny-fetch-cancel-body",+ "markdownDescription": "Denies the fetch_cancel_body command without any pre-configured scope."+ },{"description": "Denies the fetch_read_body command without any pre-configured scope.","type": "string",diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rsindex 7a008e3e8..cd45d231b 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs@@ -8,12 +8,16 @@ use specta::Type;use std::io::{BufRead, BufReader, Write};use std::path::PathBuf;use std::process::{Child, ChildStdin, Command, Stdio};+use std::sync::atomic::{AtomicBool, Ordering};use std::sync::Arc;use tauri::Emitter;use tauri::{AppHandle, State};use tokio::sync::Mutex;use tracing::{debug, error, info, warn};+/// Signals that the background Pi install has finished (success or failure).+static PI_INSTALL_DONE: AtomicBool = AtomicBool::new(false);+const PI_PACKAGE: &str = "@mariozechner/pi-coding-agent";const SCREENPIPE_API_URL: &str = "https://api.screenpi.pe/v1";@@ -399,9 +403,23 @@ pub async fn pi_start(}}- // Find pi executable- let pi_path = find_pi_executable()- .ok_or_else(|| format!("Pi not found. Install with: bun add -g {}", PI_PACKAGE))?;+ // Find pi executable — if not found, wait for background install (up to 60s)+ let pi_path = match find_pi_executable() {+ Some(p) => p,+ None => {+ if !PI_INSTALL_DONE.load(Ordering::SeqCst) {+ info!("Pi not found yet, waiting for background install to finish...");+ for _ in 0..60 {+ tokio::time::sleep(std::time::Duration::from_secs(1)).await;+ if PI_INSTALL_DONE.load(Ordering::SeqCst) {+ break;+ }+ }+ }+ find_pi_executable()+ .ok_or_else(|| format!("Pi not found. Install with: bun add -g {}", PI_PACKAGE))?+ }+ };info!("Starting pi from {} in dir: {}", pi_path, project_dir);@@ -692,8 +710,22 @@ pub async fn run() -> Result<String, String> {ensure_pi_config(user_token)?;- let pi_path = find_pi_executable()- .ok_or_else(|| format!("Pi not found. Install with: bun add -g {}", PI_PACKAGE))?;+ let pi_path = match find_pi_executable() {+ Some(p) => p,+ None => {+ if !PI_INSTALL_DONE.load(Ordering::SeqCst) {+ info!("Pi not found yet, waiting for background install to finish...");+ for _ in 0..60 {+ tokio::time::sleep(std::time::Duration::from_secs(1)).await;+ if PI_INSTALL_DONE.load(Ordering::SeqCst) {+ break;+ }+ }+ }+ find_pi_executable()+ .ok_or_else(|| format!("Pi not found. Install with: bun add -g {}", PI_PACKAGE))?+ }+ };let mut cmd = tokio::process::Command::new(&pi_path);cmd.current_dir(working_dir);@@ -792,18 +824,19 @@ fn find_bun_executable() -> Option<String> {/// Background Pi installation — call once from app setup./// Runs on a dedicated thread, never panics, never blocks the caller.+/// Sets `PI_INSTALL_DONE` when finished so `pi_start` can wait for it.pub fn ensure_pi_installed_background() {+ // If Pi is already installed, mark done immediately+ if find_pi_executable().is_some() {+ debug!("Pi already installed, skipping background install");+ PI_INSTALL_DONE.store(true, Ordering::SeqCst);+ return;+ }+match std::thread::Builder::new().name("pi-install".to_string()).spawn(move || {- // Catch any unexpected panic so it can never crash the applet result = std::panic::catch_unwind(|| {- // Already installed? Nothing to do.- if find_pi_executable().is_some() {- debug!("Pi already installed, skipping background install");- return;- }-let bun = match find_bun_executable() {Some(b) => b,None => {@@ -839,14 +872,17 @@ pub fn ensure_pi_installed_background() {});if let Err(e) = result {- // Panic was caught — log and move onerror!("Pi background install panicked (non-fatal): {:?}", e);}++ // Always mark done, even on failure, so pi_start stops waiting+ PI_INSTALL_DONE.store(true, Ordering::SeqCst);}){Ok(_) => { /* thread running */ }Err(e) => {error!("Failed to spawn pi-install thread (non-fatal): {}", e);+ PI_INSTALL_DONE.store(true, Ordering::SeqCst);}}}