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(meetings): dedupe transcript lines duplicated across endpoints after meeting ends (#4894)

Divanshud77f68c2a580
diff --git a/apps/screenpipe-app-tauri/lib/utils/meeting-context.test.ts b/apps/screenpipe-app-tauri/lib/utils/meeting-context.test.ts
index 1912c4fad..9e0a2ee15 100644
--- a/apps/screenpipe-app-tauri/lib/utils/meeting-context.test.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/meeting-context.test.ts
@@ -7,6 +7,8 @@ import type { MeetingRecord } from "./meeting-format";
import {
buildEnrichedSummarizePrompt,
extractImageDataUrlsFromMarkdown,
+ mergeMeetingAudioChunks,
+ type MeetingAudioChunk,
type MeetingContext,
} from "./meeting-context";
@@ -50,3 +52,78 @@ describe("meeting-context image notes", () => {
expect(prompt).toContain("1 image from the user's notes");
});
});
+
+function chunk(overrides: Partial<MeetingAudioChunk>): MeetingAudioChunk {
+ return {
+ audioChunkId: 1,
+ audioFilePath: "/audio/a.mp4",
+ speakerId: null,
+ speakerName: "",
+ deviceType: "output",
+ isInput: false,
+ transcription: "hello world",
+ timestamp: "2026-06-04T15:00:00.000Z",
+ source: "background",
+ ...overrides,
+ };
+}
+
+describe("mergeMeetingAudioChunks", () => {
+ it("collapses the same utterance across sources even when speaker labels differ", () => {
+ // After a meeting ends, the live segment is mirrored into
+ // audio_transcriptions with speaker_id NULL. The routed endpoint returns
+ // the live copy labeled "speaker 1" (Deepgram diarization); /search
+ // returns the mirrored copy with an empty speaker name. Both describe the
+ // same utterance and must render once.
+ const live = chunk({
+ audioChunkId: -10,
+ speakerName: "speaker 1",
+ source: "live",
+ });
+ const mirrored = chunk({ audioChunkId: 7, speakerName: "" });
+
+ const merged = mergeMeetingAudioChunks([live], [mirrored], 100);
+
+ expect(merged).toHaveLength(1);
+ expect(merged[0].speakerName).toBe("speaker 1");
+ expect(merged[0].source).toBe("live");
+ });
+
+ it("keeps the labeled live copy when /search returns first in time order", () => {
+ // sortAudioChunks ranks live before background on timestamp ties, so the
+ // labeled routed row survives regardless of input order.
+ const live = chunk({ speakerName: "speaker 2", source: "live" });
+ const mirrored = chunk({ speakerName: "speaker" });
+
+ const merged = mergeMeetingAudioChunks([live], [mirrored, chunk({ speakerName: "" })], 100);
+
+ expect(merged).toHaveLength(1);
+ expect(merged[0].speakerName).toBe("speaker 2");
+ });
+
+ it("does not collapse the same text across devices (mic echo vs remote)", () => {
+ const remote = chunk({ speakerName: "speaker 1", source: "live" });
+ const mic = chunk({
+ deviceType: "Input",
+ isInput: true,
+ speakerName: "me",
+ });
+
+ const merged = mergeMeetingAudioChunks([remote], [mic], 100);
+
+ expect(merged).toHaveLength(2);
+ });
+
+ it("does not collapse distinct utterances in different seconds", () => {
+ const first = chunk({ source: "live", speakerName: "speaker 1" });
+ const second = chunk({
+ source: "live",
+ speakerName: "speaker 1",
+ timestamp: "2026-06-04T15:00:05.000Z",
+ });
+
+ const merged = mergeMeetingAudioChunks([first, second], [], 100);
+
+ expect(merged).toHaveLength(2);
+ });
+});
diff --git a/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts b/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
index 16ccf5bac..be949bd56 100644
--- a/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
@@ -850,7 +850,7 @@ export async function fetchMeetingAudio(
return mergeMeetingAudioChunks(routedRows, out, cap);
}
-function mergeMeetingAudioChunks(
+export function mergeMeetingAudioChunks(
liveRows: MeetingAudioChunk[],
backgroundRows: MeetingAudioChunk[],
cap: number,
@@ -863,10 +863,15 @@ function mergeMeetingAudioChunks(
// /search returns DeviceType as "Input"/"Output" (PascalCase enum), while
// /meetings/:id/transcript returns the raw DB column "input"/"output".
// Lowercase both so the same chunk pulled from both endpoints collapses.
+ // Speaker label is deliberately NOT part of the key: the same utterance
+ // carries different labels across sources (Deepgram's live "speaker N" on
+ // the routed segment vs. NULL/global-speaker on the mirrored
+ // audio_transcriptions row /search returns), which used to double every
+ // line after a meeting ended. sortAudioChunks puts live rows first, so the
+ // labeled routed copy is the one that survives.
const key = [
Math.round(timestampMs(chunk.timestamp) / 1000),
chunk.deviceType.toLowerCase(),
- chunk.speakerName,
chunk.transcription.replace(/\s+/g, " ").trim().toLowerCase(),
].join("|");
if (seen.has(key)) continue;