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: pipe execution shows user prompt as output + silent LLM errors
Louis Beaumont815f52e6a97d
diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsxindex 22f7ebc10..e0cae3429 100644--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx@@ -235,6 +235,7 @@ function formatDuration(ms: number): string {* non-JSON lines as-is. */function cleanPipeStdout(raw: string): string {const parts: string[] = [];+ let errorMessage: string | null = null;for (const line of raw.split("\n")) {const trimmed = line.trim();if (!trimmed) continue;@@ -251,16 +252,25 @@ function cleanPipeStdout(raw: string): string {parts.push(evt.assistantMessageEvent.delta);continue;}- // message_start may contain initial text content- if (evt.type === "message_start" && evt.message?.content) {- for (const block of evt.message.content) {- if (block.type === "text" && block.text) {- parts.push(block.text);+ // message_start/message_end for assistant role only+ if (+ (evt.type === "message_start" || evt.type === "message_end") &&+ evt.message?.role === "assistant"+ ) {+ // Capture LLM-level errors (e.g. credits_exhausted)+ if (evt.message.stopReason === "error" && evt.message.errorMessage) {+ errorMessage = evt.message.errorMessage;+ }+ if (evt.message?.content) {+ for (const block of evt.message.content) {+ if (block.type === "text" && block.text) {+ parts.push(block.text);+ }}}continue;}- // Skip all other JSON events (session, agent_start, tool calls, etc.)+ // Skip all other JSON events (session, agent_start, user messages, tool calls, etc.)continue;} catch {// Not valid JSON — fall through to treat as plain text@@ -269,7 +279,11 @@ function cleanPipeStdout(raw: string): string {// Non-JSON line — keep as-isparts.push(trimmed);}- return parts.join("").trim();+ const text = parts.join("").trim();+ if (!text && errorMessage) {+ return `error: ${errorMessage}`;+ }+ return text;}function ElapsedTimer({ startedAt }: { startedAt: string }) {diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rsindex 6cd3fc0e9..ee7f28879 100644--- a/crates/screenpipe-core/src/agents/pi.rs+++ b/crates/screenpipe-core/src/agents/pi.rs@@ -452,9 +452,31 @@ impl PiExecutor {let mut reader = tokio::io::BufReader::new(child_stdout).lines();let mut stdout_buf = String::new();+ let mut llm_error: Option<String> = None;while let Some(line) = reader.next_line().await? {let _ = line_tx.send(line.clone());++ // Detect LLM-level errors (e.g. credits_exhausted) even when+ // the process exits 0. We look for assistant message events+ // with stopReason "error".+ if llm_error.is_none() {+ if let Ok(evt) = serde_json::from_str::<serde_json::Value>(&line) {+ let is_assistant = evt.get("message")+ .and_then(|m| m.get("role"))+ .and_then(|r| r.as_str()) == Some("assistant");+ let stop_reason = evt.get("message")+ .and_then(|m| m.get("stopReason"))+ .and_then(|r| r.as_str());+ if is_assistant && stop_reason == Some("error") {+ llm_error = evt.get("message")+ .and_then(|m| m.get("errorMessage"))+ .and_then(|e| e.as_str())+ .map(|s| s.to_string());+ }+ }+ }+stdout_buf.push_str(&line);stdout_buf.push('\n');}@@ -462,7 +484,7 @@ impl PiExecutor {let status = child.wait().await?;// Read remaining stderr- let stderr = if let Some(mut stderr_handle) = child.stderr.take() {+ let mut stderr = if let Some(mut stderr_handle) = child.stderr.take() {let mut buf = String::new();tokio::io::AsyncReadExt::read_to_string(&mut stderr_handle, &mut buf).await?;buf@@ -470,10 +492,24 @@ impl PiExecutor {String::new()};+ // If the process exited cleanly but the LLM returned an error+ // (e.g. 429 credits_exhausted), treat it as a failure.+ let success = if let Some(ref err) = llm_error {+ if stderr.is_empty() {+ stderr = err.clone();+ } else {+ stderr.push_str(&format!("\nLLM error: {}", err));+ }+ warn!("pi exited 0 but LLM returned error: {}", err);+ false+ } else {+ status.success()+ };+Ok(AgentOutput {stdout: stdout_buf,stderr,- success: status.success(),+ success,pid,})}