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(app): recover from stuck screenpipe engine restart
Louis Beaumont0b5e36338bd2
diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsxindex 1e2ec3d1d..446b76b92 100644--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx@@ -966,6 +966,7 @@ export function PipesSection() {// Per-pipe recent executions (always fetched for all pipes)const [pipeExecutions, setPipeExecutions] = useState<Record<string, PipeExecution[]>>({});const [loading, setLoading] = useState(true);+ const [loadError, setLoadError] = useState<string | null>(null);const [runningPipe, setRunningPipe] = useState<string | null>(null);const [stoppingPipe, setStoppingPipe] = useState<string | null>(null);const [promptDrafts, setPromptDrafts] = useState<Record<string, string>>({});@@ -1140,6 +1141,7 @@ export function PipesSection() {const fetchPipes = useCallback(async () => {try {+ setLoadError(null);// Load pipes WITH recent executions inline so the list shows the real// last-run status. Without this the "last run" column always reads// "never run" for pipes that have actually run (the badge is driven by@@ -1149,7 +1151,13 @@ export function PipesSection() {// tab still loads lazily via /pipes/:name/executions.const controller = new AbortController();const timeout = setTimeout(() => controller.abort(), 5_000);- const res = await fetch(`${apiBase}/pipes?include_executions=true`, { signal: controller.signal }).finally(() => clearTimeout(timeout));+ const pipesEndpoint = isRemote+ ? `${apiBase}/pipes?include_executions=true`+ : "/pipes?include_executions=true";+ const res = await localFetch(pipesEndpoint, { signal: controller.signal }).finally(() => clearTimeout(timeout));+ if (!res.ok) {+ throw new Error(`pipes api returned ${res.status}`);+ }const data = await res.json();const rawItems: Array<PipeStatus & { recent_executions?: PipeExecution[] }> = data.data || [];const fetched: PipeStatus[] = [];@@ -1188,10 +1196,16 @@ export function PipesSection() {});} catch (e) {console.error("failed to fetch pipes:", e);+ const message = (e as any)?.name === "AbortError"+ ? `timed out connecting to ${apiBase}`+ : e instanceof Error+ ? e.message+ : "failed to fetch pipes";+ setLoadError(message);} finally {setLoading(false);}- }, [apiBase]);+ }, [apiBase, isRemote]);const fetchConnections = useCallback(async () => {try {@@ -2008,6 +2022,28 @@ export function PipesSection() {</Card>))}</div>+ ) : loadError ? (+ <Card>+ <CardContent className="py-8 text-center">+ <div className="mx-auto max-w-md space-y-4 text-muted-foreground">+ <AlertCircle className="h-7 w-7 mx-auto text-muted-foreground/70" />+ <div>+ <p className="text-foreground font-medium text-base">+ {isRemote ? "couldn't load pipes from this device" : "screenpipe backend is unavailable"}+ </p>+ <p className="text-sm mt-1">+ {isRemote+ ? `the remote API at ${apiBase} did not answer. check that screenpipe is running on that device.`+ : `your pipe files may still be installed, but the local API at ${apiBase} did not answer.`}+ </p>+ <p className="text-xs mt-2 font-mono text-muted-foreground/80">{loadError}</p>+ </div>+ <Button variant="outline" size="sm" onClick={() => void fetchPipes()}>+ retry+ </Button>+ </div>+ </CardContent>+ </Card>) : filteredPipes.length === 0 ? (<Card><CardContent className="py-8 text-center text-muted-foreground">diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording.rsindex 9144a6d07..95aa72025 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs@@ -841,9 +841,14 @@ pub async fn spawn_screenpipe(//// A 30-minute safety ceiling prevents a wedged start from hanging the app// forever; for context, even a 100GB migration finishes in ~1 minute.+ // If the phase is already "ready" but HTTP is unreachable, treat that as+ // stale state after a short grace period. This happens when a restart dies+ // before publishing a fresh boot phase, leaving "ready" from the previous+ // server instance behind.if state.is_starting.swap(true, Ordering::SeqCst) {info!("Server start already in progress, waiting for boot phase...");const MAX_WAIT_SECS: u64 = 1800; // 30 minutes+ const STALE_READY_TAKEOVER_SECS: u64 = 10;const POLL_MS: u64 = 500;let start_wait = std::time::Instant::now();loop {@@ -863,7 +868,21 @@ pub async fn spawn_screenpipe(match phase.phase.as_str() {"ready" => {// Phase says ready — HTTP may be binding right now. Loop- // once more without extra wait; it'll resolve on next poll.+ // briefly, but do not let stale "ready" state mask a dead+ // server forever.+ if start_wait.elapsed()+ > std::time::Duration::from_secs(STALE_READY_TAKEOVER_SECS)+ {+ warn!(+ "In-flight server start still unreachable after {}s despite boot phase=ready — taking over stale start",+ STALE_READY_TAKEOVER_SECS+ );+ state.is_starting.store(false, Ordering::SeqCst);+ if state.is_starting.swap(true, Ordering::SeqCst) {+ return Ok(());+ }+ break;+ }tokio::time::sleep(std::time::Duration::from_millis(POLL_MS)).await;continue;}@@ -959,8 +978,21 @@ pub async fn spawn_screenpipe(}}- // Kill orphaned processes- kill_process_on_port(port).await;+ // Kill orphaned processes. Bound the cleanup so a hung OS helper cannot+ // leak `is_starting=true` and wedge future restarts behind the+ // "start already in progress" guard.+ if tokio::time::timeout(+ std::time::Duration::from_secs(10),+ kill_process_on_port(port),+ )+ .await+ .is_err()+ {+ warn!(+ "Timed out while killing orphaned process(es) on port {}; continuing with port-release wait",+ port+ );+ }// Wait for port releaselet max_poll_iters = if cfg!(windows) { 40 } else { 20 };@@ -1178,6 +1210,8 @@ pub async fn spawn_screenpipe(match result_rx.await {Ok(Ok(())) => {info!("Screenpipe started successfully");+ state.is_starting.store(false, Ordering::SeqCst);+ state.is_starting_capture.store(false, Ordering::SeqCst);let spawn_epoch = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default()@@ -1195,6 +1229,7 @@ pub async fn spawn_screenpipe(}Err(_) => {state.is_starting.store(false, Ordering::SeqCst);+ state.is_starting_capture.store(false, Ordering::SeqCst);Err("Server startup channel dropped unexpectedly".to_string())}}