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

release-app: temporary fix for memory issues

Louis Beaumontaf461a6b0288
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 54d988195..c2c0f9acf 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -5289,7 +5289,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "0.32.12"
+version = "0.32.13"
dependencies = [
"anyhow",
"async-stream",
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 045f619de..96b6378fa 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.32.12"
+version = "0.32.13"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-server/src/resource_monitor.rs b/screenpipe-server/src/resource_monitor.rs
index e7e1dea21..766a1eac0 100644
--- a/screenpipe-server/src/resource_monitor.rs
+++ b/screenpipe-server/src/resource_monitor.rs
@@ -199,18 +199,51 @@ impl ResourceMonitor {
}
}
+ async fn send_audio_restart_signal() {
+ let client = Client::new();
+ match client
+ .post("http://localhost:3030/audio/restart")
+ .send()
+ .await
+ {
+ Ok(_) => info!("sent audio restart signal"),
+ Err(e) => error!("failed to send audio restart signal: {}", e),
+ }
+ }
+ async fn send_vision_restart_signal() {
+ let client = Client::new();
+ match client
+ .post("http://localhost:3030/vision/restart")
+ .send()
+ .await
+ {
+ Ok(_) => info!("sent vision restart signal"),
+ Err(e) => error!("failed to send vision restart signal: {}", e),
+ }
+ }
+
pub fn start_monitoring(self: &Arc<Self>, interval: Duration) {
- // Clone the Arc since we need to move it into the spawned task
let monitor = Arc::clone(self);
tokio::spawn(async move {
- let mut sys = System::new_all();
+ let mut sys = System::new_all();
+ let mut last_audio_restart = Instant::now();
+ let audio_restart_interval = Duration::from_secs(60 * 60 * 2); // TODO: change to 2 hours for release
loop {
tokio::select! {
_ = tokio::time::sleep(interval) => {
sys.refresh_all();
monitor.log_status(&sys).await;
+
+ // Check if it's time to send audio restart signal
+ if last_audio_restart.elapsed() >= audio_restart_interval {
+ tokio::join!(
+ Self::send_audio_restart_signal(),
+ Self::send_vision_restart_signal()
+ );
+ last_audio_restart = Instant::now();
+ }
}
}
}
diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rs
index ac382d164..f5412a948 100644
--- a/screenpipe-server/src/server.rs
+++ b/screenpipe-server/src/server.rs
@@ -18,7 +18,7 @@ use futures::{
SinkExt, StreamExt,
};
use image::ImageFormat::{self};
-use screenpipe_core::{AudioDevice, AudioDeviceType, DeviceControl, DeviceManager};
+use screenpipe_core::{AudioDevice, AudioDeviceType, DeviceControl, DeviceManager, DeviceType};
use screenpipe_events::{send_event, subscribe_to_all_events, Event as ScreenpipeEvent};
use crate::{
@@ -2048,6 +2048,8 @@ pub fn create_router() -> Router<Arc<AppState>> {
.route("/frames/:frame_id", get(get_frame_data))
.route("/vision/start", post(start_vision_device))
.route("/vision/stop", post(stop_vision_device))
+ .route("/audio/restart", post(restart_audio_devices))
+ .route("/vision/restart", post(restart_vision_devices))
.layer(cors);
#[cfg(feature = "experimental")]
@@ -2397,6 +2399,130 @@ struct MergeSpeakersRequest {
speaker_to_keep_id: i64,
speaker_to_merge_id: i64,
}
+
+#[derive(Serialize)]
+pub struct RestartAudioDevicesResponse {
+ success: bool,
+ message: String,
+ restarted_devices: Vec<String>,
+}
+
+async fn restart_audio_devices(
+ State(state): State<Arc<AppState>>,
+) -> Result<JsonResponse<RestartAudioDevicesResponse>, (StatusCode, JsonResponse<Value>)> {
+ debug!("restarting active audio devices");
+
+ // Get currently active devices from device manager
+ let active_devices = state.device_manager.get_active_devices().await;
+ let mut restarted_devices = Vec::new();
+
+ for (_, control) in active_devices {
+ debug!("restarting audio device: {:?}", control.device);
+
+ let audio_device = match control.device {
+ DeviceType::Audio(device) => device,
+ _ => continue,
+ };
+ // Stop the device
+ let _ = state
+ .device_manager
+ .update_device(DeviceControl {
+ device: screenpipe_core::DeviceType::Audio(audio_device.clone()),
+ is_running: false,
+ is_paused: false,
+ })
+ .await;
+
+ // Small delay to ensure clean shutdown
+ tokio::time::sleep(Duration::from_millis(1000)).await;
+
+ // Start the device again
+ let _ = state
+ .device_manager
+ .update_device(DeviceControl {
+ device: screenpipe_core::DeviceType::Audio(audio_device.clone()),
+ is_running: true,
+ is_paused: false,
+ })
+ .await;
+
+ restarted_devices.push(audio_device.name.clone());
+ }
+
+ if restarted_devices.is_empty() {
+ Ok(JsonResponse(RestartAudioDevicesResponse {
+ success: true,
+ message: "no active audio devices to restart".to_string(),
+ restarted_devices,
+ }))
+ } else {
+ Ok(JsonResponse(RestartAudioDevicesResponse {
+ success: true,
+ message: format!("restarted {} audio devices", restarted_devices.len()),
+ restarted_devices,
+ }))
+ }
+}
+
+#[derive(Serialize)]
+pub struct RestartVisionDevicesResponse {
+ success: bool,
+ message: String,
+ restarted_devices: Vec<u32>,
+}
+
+async fn restart_vision_devices(
+ State(state): State<Arc<AppState>>,
+) -> Result<JsonResponse<RestartVisionDevicesResponse>, (StatusCode, JsonResponse<Value>)> {
+ debug!("restarting active vision devices");
+
+ let active_devices = state.device_manager.get_active_devices().await;
+ let mut restarted_devices = Vec::new();
+
+ for (_, control) in active_devices {
+ let vision_device = match control.device {
+ DeviceType::Vision(device) => device,
+ _ => continue,
+ };
+
+ debug!("restarting vision device: {:?}", vision_device);
+
+ // Stop the device
+ let _ = state
+ .device_manager
+ .update_device(DeviceControl {
+ device: screenpipe_core::DeviceType::Vision(vision_device.clone()),
+ is_running: false,
+ is_paused: false,
+ })
+ .await;
+
+ tokio::time::sleep(Duration::from_millis(1000)).await;
+
+ // Start the device again
+ let _ = state
+ .device_manager
+ .update_device(DeviceControl {
+ device: screenpipe_core::DeviceType::Vision(vision_device.clone()),
+ is_running: true,
+ is_paused: false,
+ })
+ .await;
+
+ restarted_devices.push(vision_device.clone());
+ }
+
+ Ok(JsonResponse(RestartVisionDevicesResponse {
+ success: true,
+ message: if restarted_devices.is_empty() {
+ "no active vision devices to restart".to_string()
+ } else {
+ format!("restarted {} vision devices", restarted_devices.len())
+ },
+ restarted_devices,
+ }))
+}
+
/*
Curl commands for reference: