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): preserve pipe-run title + drop history-sync echo

Louis Beaumont3a592d241660
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 206b35e10..05e4455fe 100644
--- a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
+++ b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
@@ -345,13 +345,25 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
if (!historyEnabled) return;
const convId = conversationId || crypto.randomUUID();
- const firstUserMsg = msgs.find(m => m.role === "user");
- const title = firstUserMsg?.content.slice(0, 50) || "New Chat";
- // Try to load existing conversation to preserve createdAt
+ // Try to load existing conversation to preserve createdAt + title + kind.
const { loadConversationFile } = await import("@/lib/chat-storage");
const existing = await loadConversationFile(convId);
+ // Derive a title from the first user message, but skip messages that are
+ // the chat panel's own injected `<conversation_history>...` sync prompt
+ // (Pi can echo that back as a message_start (user) event, leaking it into
+ // the messages array — see the prompt construction at the piPrompt call).
+ const firstUserMsg = msgs.find(
+ (m) => m.role === "user" && !m.content.startsWith("<conversation_history>")
+ );
+ const derivedTitle = firstUserMsg?.content.slice(0, 50) || "New Chat";
+ // Preserve any previously-persisted title (user renames, pipe-run titles
+ // like `pipe-opportunity-scout-gpt55 #8209`). Only fall through to the
+ // derived title when the file has no title yet. Mirrors the router's
+ // background-save logic in pi-event-router.ts.
+ const title = existing?.title || derivedTitle;
+
const conversation: ChatConversation = {
id: convId,
title,
@@ -402,6 +414,11 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
}),
createdAt: existing?.createdAt ?? Date.now(),
updatedAt: Date.now(),
+ // Preserve pipe-run identity across follow-up saves. Without this, the
+ // first user-typed follow-up to a pipe-run silently demoted it to a
+ // plain chat (kind/pipeContext dropped on disk).
+ ...(existing?.kind ? { kind: existing.kind } : {}),
+ ...(existing?.pipeContext ? { pipeContext: existing.pipeContext } : {}),
// Preserve sort key across reloads. Source of truth: the in-memory
// chat-store, which is bumped exactly once per user-send.
...(await (async () => {
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index dc46d832a..902723d16 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -4730,6 +4730,17 @@ export function StandaloneChat({
})();
const eventImages = imageDataUrlsFromPiContent(data.message?.content);
+ // Skip the chat panel's own injected `<conversation_history>...`
+ // sync prompt (see promptMessage construction at the piPrompt call).
+ // Pi echoes it back as a message_start (user) event; we've already
+ // stored the real user-typed message locally via sendPiMessage, so
+ // adding this would create a phantom user bubble whose first 50
+ // chars look like `<conversation_history>\nassistant: [tool: ...`
+ // and corrupt the chat title on next save.
+ if (text.startsWith("<conversation_history>")) {
+ return;
+ }
+
if (!piMessageIdRef.current) {
const sidForStartedUser = piSessionIdRef.current;
const pendingDisplay = pendingNextPiUserDisplayRef.current;