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: kill and restart Pi on new chat to prevent "already processing" error
Louis Beaumont05296f8c6c67
diff --git a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.tsindex e0caa2bb2..d7cd070ef 100644--- a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts+++ b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts@@ -295,22 +295,20 @@ export function useChatConversations(opts: UseChatConversationsOpts) {// ---- startNewConversation ----const startNewConversation = async () => {- // Abort any ongoing Pi processing and start a fresh session- if (piInfo?.running) {+ // If Pi is running and idle (not busy), just reset the session+ if (piInfo?.running && !isLoading && !isStreaming) {try {- if (isLoading || isStreaming) {- await commands.piAbort(PI_CHAT_SESSION);- }await commands.piNewSession(PI_CHAT_SESSION);} catch (e) {console.warn("[Pi] Failed to reset session:", e);}- piStreamingTextRef.current = "";- piMessageIdRef.current = null;- piContentBlocksRef.current = [];- setIsLoading(false);- setIsStreaming(false);}+ // Clear frontend state (Pi kill+restart is handled by the caller when busy)+ piStreamingTextRef.current = "";+ piMessageIdRef.current = null;+ piContentBlocksRef.current = [];+ setIsLoading(false);+ setIsStreaming(false);setMessages([]);setConversationId(null);setInput("");diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex 367b17b02..3f8d3753e 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -2621,8 +2621,31 @@ export function StandaloneChat({ className }: { className?: string } = {}) {<Buttonvariant="default"size="sm"- onClick={(e) => {+ onClick={async (e) => {e.stopPropagation();+ // Kill Pi process if busy, then restart fresh+ if (piInfo?.running && (isLoading || isStreaming)) {+ piStoppedIntentionallyRef.current = true;+ try { await commands.piStop(PI_CHAT_SESSION); } catch {}+ piStreamingTextRef.current = "";+ piMessageIdRef.current = null;+ piContentBlocksRef.current = [];+ setIsLoading(false);+ setIsStreaming(false);+ // Restart Pi fresh+ try {+ const providerConfig = buildProviderConfig();+ const home = await homeDir();+ const dir = await join(home, ".screenpipe", "pi-chat");+ const result = await commands.piStart(PI_CHAT_SESSION, dir, settings.user?.token ?? null, providerConfig);+ if (result.status === "ok") {+ setPiInfo(result.data);+ piSessionSyncedRef.current = true;+ }+ } catch (err) {+ console.warn("[Pi] Failed to restart after new chat:", err);+ }+ }startNewConversation();}}className="h-7 px-3 gap-1.5 text-xs bg-foreground text-background hover:bg-background hover:text-foreground transition-colors duration-150"