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

fix(chat): persist user message on send + self-heal stuck streaming

Louis Beaumonta46b4ebe0c9f
diff --git a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
index 6b8e6c2ad..4e38ca798 100644
--- a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
+++ b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
@@ -400,8 +400,24 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
piStreamingTextRef.current = existing.streamingText ?? "";
piMessageIdRef.current = existing.streamingMessageId ?? null;
piContentBlocksRef.current = (existing.contentBlocks as any[]) ?? [];
- if (existing.isLoading) setIsLoading(true);
- if (existing.isStreaming) setIsStreaming(true);
+ // Self-heal a stuck `isStreaming` flag. The router bumps
+ // `updatedAt` on every token via patchMessage, so silence past
+ // STALE_MS means the stream is dead (Pi process died without
+ // firing agent_end, network cut mid-stream, etc.) — not just
+ // slow. Without this guard, returning to such a session shows
+ // the typing-cursor / loading dots forever.
+ const STALE_MS = 30_000;
+ const isStale =
+ !!existing.isStreaming && Date.now() - existing.updatedAt > STALE_MS;
+ if (isStale) {
+ store.actions.endTurn(conv.id);
+ piStreamingTextRef.current = "";
+ piMessageIdRef.current = null;
+ piContentBlocksRef.current = [];
+ } else {
+ if (existing.isLoading) setIsLoading(true);
+ if (existing.isStreaming) setIsStreaming(true);
+ }
store.actions.markHydrated(conv.id);
} else {
// Cold session — load from disk and seed the store.
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 6220db622..06a8653ae 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -3569,6 +3569,16 @@ export function StandaloneChat({
storeState.actions.patch(sidNow, { lastUserMessageAt: Date.now() });
}
+ // Persist user message to disk immediately so it survives a
+ // navigate-away-mid-stream or a Pi crash before agent_end. The
+ // existing save-on-isLoading-transition only fires when the stream
+ // completes cleanly — if anything kills the turn before then, the
+ // user's message would otherwise live only in the in-memory store
+ // and vanish on the next cold reload. Fire-and-forget: the next
+ // save (on agent_end) will overwrite the same file with the full
+ // conversation including the assistant reply.
+ void saveConversation([...messages, newUserMessage]);
+
posthog.capture("chat_message_sent", {
provider: activePreset?.provider,
model: activePreset?.model,
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 1c396a149..776e6929a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9726,7 +9726,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.4.98"
+version = "2.4.99"
dependencies = [
"anyhow",
"arboard",
@@ -9833,7 +9833,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"anyhow",
"audiopipe",
@@ -9889,7 +9889,7 @@ dependencies = [
[[package]]
name = "screenpipe-config"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -9901,7 +9901,7 @@ dependencies = [
[[package]]
name = "screenpipe-connect"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"anyhow",
"async-trait",
@@ -9932,7 +9932,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -9980,7 +9980,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"anyhow",
"chrono",
@@ -10005,7 +10005,7 @@ dependencies = [
[[package]]
name = "screenpipe-engine"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"anyhow",
"arc-swap",
@@ -10070,7 +10070,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"anyhow",
"chrono",
@@ -10086,7 +10086,7 @@ dependencies = [
[[package]]
name = "screenpipe-screen"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -10139,7 +10139,7 @@ dependencies = [
[[package]]
name = "screenpipe-vault"
-version = "0.3.302"
+version = "0.3.303"
dependencies = [
"argon2",
"chacha20poly1305",
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index edfaaafab..5d2b6aaa5 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.4.98"
+version = "2.4.99"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""