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: prevent stuck writing... indicator when returning to a completed chat

Anshgrover230c18a794e9b9
diff --git a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
index 5cb2e70fb..e4f4ea32f 100644
--- a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
+++ b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
@@ -495,6 +495,16 @@ export const useChatStore = create<ChatStore>((set) => ({
const incomingMsgs = snapshot.messages ?? [];
const messages =
incomingMsgs.length >= existingMsgs.length ? incomingMsgs : existingMsgs;
+ // Guard: never let a stale React closure re-enable streaming that
+ // endTurn() already cleared. endTurn writes synchronously into
+ // Zustand, but setIsStreaming/setIsLoading are async React state
+ // updates — a fast nav right after agent_end can snapshot
+ // isStreaming=true from the old render while the store already
+ // holds false. If the store says false, it wins.
+ const isStreaming =
+ existing.isStreaming === false ? false : snapshot.isStreaming;
+ const isLoading =
+ existing.isLoading === false ? false : snapshot.isLoading;
return {
sessions: {
...s.sessions,
@@ -505,8 +515,8 @@ export const useChatStore = create<ChatStore>((set) => ({
streamingText: snapshot.streamingText,
streamingMessageId: snapshot.streamingMessageId,
contentBlocks: snapshot.contentBlocks,
- isStreaming: snapshot.isStreaming,
- isLoading: snapshot.isLoading,
+ isStreaming,
+ isLoading,
hydratedAt: existing.hydratedAt ?? Date.now(),
// No updatedAt bump — snapshot is plumbing, not user activity.
},